[jboss-svn-commits] JBL Code SVN: r23239 - in labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule: binding and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Oct 1 06:49:12 EDT 2008
Author: adinn
Date: 2008-10-01 06:49:10 -0400 (Wed, 01 Oct 2008)
New Revision: 23239
Modified:
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Action.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Condition.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Event.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/RuleElement.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/binding/Binding.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArithmeticExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArrayExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BinaryOperExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BitExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BooleanExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BooleanLiteral.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ComparisonExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ConditionalEvalExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/DollarExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/Expression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ExpressionHelper.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/FieldExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/LogicalExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/MethodExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/NotExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/NumericLiteral.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/OperExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/PlusExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ReturnExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StaticExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StringLiteral.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StringPlusExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/TernaryOperExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ThrowExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/TwiddleExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/UnaryOperExpression.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/Variable.java
Log:
fixed NPE caused when trigger method had a null exceptions list (doh). also reorganized type check code so all rule elements are created with a reference to the rule, giving them automatic access to the bindings and type group and obviating the need to pas these as parameters to bind() and typecheck()
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Action.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Action.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Action.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -53,7 +53,7 @@
if (actionTree.getToken().getType() == ECAGrammarParser.NOTHING) {
this.action = new ArrayList<Expression>();
} else {
- this.action = ExpressionHelper.createExpressionList(this.getBindings(), actionTree, Type.VOID);
+ this.action = ExpressionHelper.createExpressionList(rule, this.getBindings(), actionTree, Type.VOID);
}
}
@@ -63,12 +63,14 @@
this.action = null;
}
- public void typeCheck() throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
+ // expected must be Type.VOID
if (action != null) {
for (Expression expr : action) {
- expr.typeCheck(getBindings(), getTypeGroup(), Type.VOID);
+ expr.typeCheck(Type.VOID);
}
}
+ return Type.VOID;
}
public void interpret(Rule.BasicHelper helper)
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Condition.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Condition.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Condition.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -55,11 +55,11 @@
super(rule);
Token token = conditionTree.getToken();
if (token.getType() == ECAGrammarParser.TRUE) {
- this.condition = new BooleanLiteral(token, true);
+ this.condition = new BooleanLiteral(rule, token, true);
} else if (token.getType() == ECAGrammarParser.FALSE) {
- this.condition = new BooleanLiteral(token, false);
+ this.condition = new BooleanLiteral(rule, token, false);
} else {
- this.condition = ExpressionHelper.createExpression(rule.getBindings(), conditionTree, Type.BOOLEAN);
+ this.condition = ExpressionHelper.createExpression(rule, rule.getBindings(), conditionTree, Type.BOOLEAN);
}
}
@@ -69,10 +69,12 @@
this.condition = null;
}
- public void typeCheck() throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
+ // expected must be Type.Z
if (condition != null) {
- condition.typeCheck(getBindings(), getTypeGroup(), Type.Z);
+ condition.typeCheck(Type.Z);
}
+ return Type.Z;
}
public boolean interpret(Rule.BasicHelper helper)
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Event.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Event.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Event.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -76,19 +76,21 @@
return rule.getBindings();
}
- public void typeCheck() throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
+ // expected must be Type.VOID
Iterator<Binding> iterator = getBindings().iterator();
while (iterator.hasNext()) {
Binding binding = iterator.next();
typeCheck(binding);
}
+ return Type.VOID;
}
private void typeCheck(Binding binding)
throws TypeException
{
- binding.typeCheck(getBindings(), getTypeGroup());
+ binding.typeCheck(Type.UNDEFINED);
}
private void createBindings(CommonTree eventTree) throws TypeException
@@ -171,7 +173,7 @@
Expression expr;
- expr = ExpressionHelper.createExpression(bindings, exprTree, binding.getType());
+ expr = ExpressionHelper.createExpression(rule, bindings, exprTree, binding.getType());
if (bindings.lookup(binding.getName()) != null) {
// oops rebinding not allowed
@@ -196,7 +198,7 @@
switch (tokenType) {
case SYMBOL:
{
- return new Binding(token.getText());
+ return new Binding(rule, token.getText());
}
case COLON:
{
@@ -212,7 +214,7 @@
if (type == null) {
throw new TypeException("Event.createBindings : incompatible type in declaration of variable " + child1.getToken().getText() + " @ " + token.getLine() + "." + token.getCharPositionInLine());
}
- return new Binding(child0.getText(), type);
+ return new Binding(rule, child0.getText(), type);
}
default:
{
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -339,9 +339,11 @@
public void typeCheck()
throws TypeException
{
- // ensure that the type group includes the exception types
- typeGroup.addExceptionTypes(triggerExceptions);
-
+ if (triggerExceptions != null) {
+ // ensure that the type group includes the exception types
+ typeGroup.addExceptionTypes(triggerExceptions);
+ }
+
// try to resolve all types in the type group to classes
typeGroup.resolveTypes();
@@ -350,9 +352,9 @@
// in the bindings list
installParameters((triggerAccess & Opcodes.ACC_STATIC) != 0, triggerClass, triggerDescriptor);
- event.typeCheck();
- condition.typeCheck();
- action.typeCheck();
+ event.typeCheck(Type.VOID);
+ condition.typeCheck(Type.Z);
+ action.typeCheck(Type.VOID);
checked = true;
}
@@ -363,7 +365,7 @@
Type type;
// add a binding for the rule so we can call builting static methods
type = typeGroup.create("org.jboss.jbossts.orchestration.rule.Rule$Helper");
- Binding ruleBinding = new Binding("-1", type);
+ Binding ruleBinding = new Binding(this, "-1", type);
parameterBindings.add(ruleBinding);
if (!isStatic) {
@@ -371,7 +373,7 @@
if (type.isUndefined()) {
throw new TypeException("Rule.installParameters : Rule " + name + " unable to load class " + className);
}
- Binding binding = new Binding("0", type);
+ Binding binding = new Binding(this, "0", type);
parameterBindings.add(binding);
}
List<String> parameterTypenames = Type.parseDescriptor(descriptor, true);
@@ -391,9 +393,9 @@
}
if (paramIdx == last) {
// we also add a special binding to allow us to identify the return type
- binding = new Binding("$!", paramType);
+ binding = new Binding(this, "$!", paramType);
} else {
- binding = new Binding(Integer.toString(paramIdx++), paramType);
+ binding = new Binding(this, Integer.toString(paramIdx++), paramType);
}
parameterBindings.add(binding);
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/RuleElement.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/RuleElement.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/RuleElement.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -2,6 +2,7 @@
import org.jboss.jbossts.orchestration.rule.binding.Bindings;
import org.jboss.jbossts.orchestration.rule.type.TypeGroup;
+import org.jboss.jbossts.orchestration.rule.type.Type;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
import java.io.StringWriter;
@@ -28,7 +29,7 @@
return rule.getBindings();
}
- public abstract void typeCheck() throws TypeException;
+ public abstract Type typeCheck(Type expected) throws TypeException;
public String toString()
{
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/binding/Binding.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/binding/Binding.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/binding/Binding.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -1,9 +1,10 @@
package org.jboss.jbossts.orchestration.rule.binding;
import org.jboss.jbossts.orchestration.rule.type.Type;
-import org.jboss.jbossts.orchestration.rule.type.TypeGroup;
import org.jboss.jbossts.orchestration.rule.expression.Expression;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
+import org.jboss.jbossts.orchestration.rule.Rule;
+import org.jboss.jbossts.orchestration.rule.RuleElement;
import java.io.StringWriter;
@@ -11,20 +12,22 @@
* Class used to store a binding of a named variable to a value of some given type
*/
-public class Binding {
+public class Binding extends RuleElement
+{
- public Binding(String name)
+ public Binding(Rule rule, String name)
{
- this(name, Type.UNDEFINED, null);
+ this(rule, name, Type.UNDEFINED, null);
}
- public Binding(String name, Type type)
+ public Binding(Rule rule, String name, Type type)
{
- this(name, type, null);
+ this(rule, name, type, null);
}
- public Binding(String name, Type type, Expression value)
+ public Binding(Rule rule, String name, Type type, Expression value)
{
+ super(rule);
this.name = name;
this.type = (type != null ? type : Type.UNDEFINED);
this.value = value;
@@ -39,22 +42,23 @@
}
}
- public void typeCheck(Bindings bindings, TypeGroup typeGroup)
+ public Type typeCheck(Type expected)
throws TypeException
{
// value can be null if this is a rule method parameter
if (value != null) {
- // type check the binding expression, using the bound variable's type if it is known
+ // type check the binding expression, using the bound variable's expected if it is known
- Type valueType = value.typeCheck(bindings, typeGroup, type);
+ Type valueType = value.typeCheck(expected);
if (type.isUndefined()) {
type = valueType;
}
} else if (type.isUndefined()) {
- // can we have no type for a method parameter?
+ // can we have no expected for a method parameter?
throw new TypeException("Binding.typecheck unknown type for binding " + name);
}
+ return type;
}
public String getName()
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArithmeticExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArithmeticExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArithmeticExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -14,14 +14,14 @@
*/
public class ArithmeticExpression extends BinaryOperExpression
{
- public ArithmeticExpression(int oper, Token token, Expression left, Expression right)
+ public ArithmeticExpression(Rule rule, int oper, Token token, Expression left, Expression right)
{
- super(oper, Type.promote(left.getType(), right.getType()), token, left, right);
+ super(rule, oper, Type.promote(left.getType(), right.getType()), token, left, right);
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
- Type type1 = getOperand(0).typeCheck(bindings, typegroup, Type.N);
- Type type2 = getOperand(1).typeCheck(bindings, typegroup, Type.N);
+ public Type typeCheck(Type expected) throws TypeException {
+ Type type1 = getOperand(0).typeCheck(Type.N);
+ Type type2 = getOperand(1).typeCheck(Type.N);
type = Type.promote(type1, type2);
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type) ) {
throw new TypeException("ArithmenticExpression.typeCheck : invalid expected result type " + expected.getName() + getPos());
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArrayExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArrayExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ArrayExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -21,9 +21,9 @@
public class ArrayExpression extends Expression
{
- public ArrayExpression(Type type, Token token, Expression arrayRef, List<Expression> idxList)
+ public ArrayExpression(Rule rule, Type type, Token token, Expression arrayRef, List<Expression> idxList)
{
- super(type, token);
+ super(rule, type, token);
this.arrayRef = arrayRef;
this.idxList = idxList;
}
@@ -33,35 +33,34 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// we have to make sure that any names occuring in the array reference are bound
// and that the index expressions contain valid bindings
boolean valid = true;
- valid = arrayRef.bind(bindings);
+ valid = arrayRef.bind();
Iterator<Expression> iterator = idxList.iterator();
while (iterator.hasNext()) {
- valid &= iterator.next().bind(bindings);
+ valid &= iterator.next().bind();
}
return valid;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
- Type arrayType = arrayRef.typeCheck(bindings, typegroup, Type.UNDEFINED);
+ public Type typeCheck(Type expected) throws TypeException {
+ Type arrayType = arrayRef.typeCheck(Type.UNDEFINED);
Type nextType = arrayType;
for (Expression expr : idxList) {
if (!nextType.isArray()) {
throw new TypeException("ArrayExpression.typeCheck : invalid type for array dereference " + nextType.getName() + getPos());
}
nextType = nextType.getBaseType();
- expr.typeCheck(bindings, typegroup, Type.N);
+ expr.typeCheck(Type.N);
}
type = nextType;
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BinaryOperExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BinaryOperExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BinaryOperExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -3,6 +3,7 @@
import org.jboss.jbossts.orchestration.rule.type.Type;
import org.jboss.jbossts.orchestration.rule.binding.Bindings;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
+import org.jboss.jbossts.orchestration.rule.Rule;
import org.antlr.runtime.Token;
/**
@@ -10,9 +11,9 @@
*/
public abstract class BinaryOperExpression extends OperExpression
{
- public BinaryOperExpression(int oper, Type type, Token token, Expression operand1, Expression operand2)
+ public BinaryOperExpression(Rule rule, int oper, Type type, Token token, Expression operand1, Expression operand2)
{
- super(oper, type, token);
+ super(rule, oper, type, token);
this.operand1 = operand1;
this.operand2 = operand2;
}
@@ -22,16 +23,15 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// we just need to ensure that the operands can find their bindings
// run both so we get as many errors as possible
- boolean success = operand1.bind(bindings);
- success &= operand2.bind(bindings);
+ boolean success = operand1.bind();
+ success &= operand2.bind();
return success;
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BitExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BitExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BitExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -13,16 +13,16 @@
*/
public class BitExpression extends BinaryOperExpression
{
- public BitExpression(int oper, Token token, Expression left, Expression right)
+ public BitExpression(Rule rule, int oper, Token token, Expression left, Expression right)
{
// n.b. left and right must be of integral type
- super(oper, Type.promote(left.getType(), right.getType()), token, left, right);
+ super(rule, oper, Type.promote(left.getType(), right.getType()), token, left, right);
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
- Type type1 = getOperand(0).typeCheck(bindings, typegroup, Type.N);
- Type type2 = getOperand(1).typeCheck(bindings, typegroup, Type.N);
+ public Type typeCheck(Type expected) throws TypeException {
+ Type type1 = getOperand(0).typeCheck(Type.N);
+ Type type2 = getOperand(1).typeCheck(Type.N);
type = Type.promote(type1, type2);
// if either arg is float or double we will convert it to long and generate a long
// result so correct the promotion here
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BooleanExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BooleanExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BooleanExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -1,6 +1,7 @@
package org.jboss.jbossts.orchestration.rule.expression;
import org.jboss.jbossts.orchestration.rule.type.Type;
+import org.jboss.jbossts.orchestration.rule.Rule;
import org.antlr.runtime.Token;
/**
@@ -8,8 +9,8 @@
*/
public abstract class BooleanExpression extends BinaryOperExpression
{
- public BooleanExpression(int oper, Token token, Expression left, Expression right)
+ public BooleanExpression(Rule rule, int oper, Token token, Expression left, Expression right)
{
- super(oper, Type.Z, token, left, right);
+ super(rule, oper, Type.Z, token, left, right);
}
}
\ No newline at end of file
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BooleanLiteral.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BooleanLiteral.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/BooleanLiteral.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -17,9 +17,9 @@
{
private boolean value;
- public BooleanLiteral(Token token, Boolean value)
+ public BooleanLiteral(Rule rule, Token token, Boolean value)
{
- super(Type.Z, token);
+ super(rule, Type.Z, token);
this.value = value;
}
@@ -29,15 +29,14 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ public boolean bind() {
+ return false;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
type = Type.Z;
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
throw new TypeException("BooleanLiteral.typeCheck : invalid expected result type " + expected.getName() + getPos());
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ComparisonExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ComparisonExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ComparisonExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -13,16 +13,16 @@
*/
public class ComparisonExpression extends BooleanExpression
{
- public ComparisonExpression(int oper, Token token, Expression left, Expression right)
+ public ComparisonExpression(Rule rule, int oper, Token token, Expression left, Expression right)
{
- super(oper, token, left, right);
+ super(rule, oper, token, left, right);
comparisonType = Type.UNDEFINED;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// TODO allow comparison of non-numeric values
- Type type1 = getOperand(0).typeCheck(bindings, typegroup, Type.N);
- Type type2 = getOperand(1).typeCheck(bindings, typegroup, Type.N);
+ Type type1 = getOperand(0).typeCheck(Type.N);
+ Type type2 = getOperand(1).typeCheck(Type.N);
comparisonType = Type.promote(type1, type2);
type = Type.Z;
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ConditionalEvalExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ConditionalEvalExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ConditionalEvalExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -13,15 +13,15 @@
*/
public class ConditionalEvalExpression extends TernaryOperExpression
{
- public ConditionalEvalExpression(Type type, Token token, Expression cond, Expression if_expr, Expression else_expr)
+ public ConditionalEvalExpression(Rule rule, Type type, Token token, Expression cond, Expression if_expr, Expression else_expr)
{
- super(TERNARY, type, token, cond, if_expr, else_expr);
+ super(rule, TERNARY, type, token, cond, if_expr, else_expr);
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
- Type condType = getOperand(0).typeCheck(bindings, typegroup, Type.Z);
- Type type1 = getOperand(1).typeCheck(bindings, typegroup, expected);
- Type type2 = getOperand(2).typeCheck(bindings, typegroup, expected);
+ public Type typeCheck(Type expected) throws TypeException {
+ Type condType = getOperand(0).typeCheck(Type.Z);
+ Type type1 = getOperand(1).typeCheck(expected);
+ Type type2 = getOperand(2).typeCheck(expected);
// type1 must be defined and type2 must be the same as type 1 or assignable
// to/from it.
if (type2 != type1) {
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/DollarExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/DollarExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/DollarExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -25,9 +25,9 @@
*/
public class DollarExpression extends Expression
{
- public DollarExpression(Type type, Token token)
+ public DollarExpression(Rule rule, Type type, Token token)
{
- super(type, token);
+ super(rule, type, token);
String text = token.getText();
this.name = text.substring(1, text.length());
char first = name.charAt(0);
@@ -41,9 +41,9 @@
}
}
- public DollarExpression(Type type, Token token, String text)
+ public DollarExpression(Rule rule, Type type, Token token, String text)
{
- super(type, token);
+ super(rule, type, token);
this.name = text.substring(1, text.length());
try {
index = Integer.decode(name);
@@ -58,12 +58,11 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
if (index < 0) {
System.err.println("DollarExpression.bind : invalid bound parameter $" + name + getPos());
return false;
@@ -74,9 +73,9 @@
}
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// ensure there is a parameter with the relevant name in the bindings
- Binding binding = bindings.lookup(Integer.toString(index));
+ Binding binding = getBindings().lookup(Integer.toString(index));
if (binding == null) {
throw new TypeException("DollarExpression.typeCheck : invalid bound parameter $" + name + getPos());
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/Expression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/Expression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/Expression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -10,6 +10,7 @@
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
import org.jboss.jbossts.orchestration.rule.exception.ExecuteException;
import org.jboss.jbossts.orchestration.rule.Rule;
+import org.jboss.jbossts.orchestration.rule.RuleElement;
import java.io.StringWriter;
@@ -19,14 +20,16 @@
* as the condition expression of an ECA rule condition;and as an element of the actions list in an
* ECA rule action.
*/
-public abstract class Expression
+public abstract class Expression extends RuleElement
{
/**
* Create a new expression.
* @param type the current type for this expression.
*/
- protected Expression(Type type, Token token)
+ protected Expression(Rule rule, Type type, Token token)
{
+ super(rule);
+ this.rule = rule;
this.type = type;
this.token = token;
if (token != null) {
@@ -39,15 +42,12 @@
}
/**
- * verify that variables mentioned in this expression are actually available in the supplied
- * bindings list and infer/validate the type of this expression or its subexpressions
- * where possible
- *
- * @param bindings the set of bindings in place at the point of evaluation of this expression
+ * verify that variables mentioned in this expression are actually available in the rule
+ * bindings list
* @return true if all variables in this expression are bound and no type mismatches have
- * been detected during inference/validation.
+ * been detected during validation.
*/
- public abstract boolean bind(Bindings bindings);
+ public abstract boolean bind();
public String getPos()
{
@@ -63,15 +63,12 @@
* ensure that all type references in the expression and its component expressions
* can be resolved, that the type of the expression is well-defined and that it is
* compatible with the type expected in the context in which it occurs.
- * @param bindings the bound variable in scope at the point where the expression is
- * to be evaluate
- * @param typegroup the set of types employed by the rule
* @param expected the type expected for the expression in the contxt in which it occurs. this
* may be void but shoudl not be undefined at the point where type checking is performed.
* @return
* @throws TypeException
*/
- public abstract Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected)
+ public abstract Type typeCheck(Type expected)
throws TypeException;
/**
@@ -88,6 +85,7 @@
public abstract void writeTo(StringWriter stringWriter);
+ protected Rule rule;
protected Type type;
protected int charPos;
protected int line;
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ExpressionHelper.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ExpressionHelper.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ExpressionHelper.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -5,6 +5,7 @@
import static org.jboss.jbossts.orchestration.rule.grammar.ECAGrammarParser.*;
import org.jboss.jbossts.orchestration.rule.type.Type;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
+import org.jboss.jbossts.orchestration.rule.Rule;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.Token;
@@ -16,13 +17,13 @@
*/
public class ExpressionHelper
{
- public static Expression createExpression(Bindings bindings, CommonTree exprTree)
+ public static Expression createExpression(Rule rule, Bindings bindings, CommonTree exprTree)
throws TypeException
{
- return createExpression(bindings, exprTree, Type.UNDEFINED);
+ return createExpression(rule, bindings, exprTree, Type.UNDEFINED);
}
- public static Expression createExpression(Bindings bindings, CommonTree exprTree, Type type)
+ public static Expression createExpression(Rule rule, Bindings bindings, CommonTree exprTree, Type type)
throws TypeException
{
// we expect expr = simple_expr |
@@ -49,7 +50,7 @@
switch (tokenType) {
case DOLLARSYM:
{
- expr = new DollarExpression(type, token);
+ expr = new DollarExpression(rule, type, token);
}
break;
case SYMBOL:
@@ -65,7 +66,7 @@
int dotIdx = text.lastIndexOf('.');
if (dotIdx < 0) {
// direct variable reference
- expr = new Variable(type, token);
+ expr = new Variable(rule, type, token);
} else {
// field reference either to an instance named by a binding or or a static
@@ -83,9 +84,9 @@
int l = parts.length - 1;
String[] fields = new String[l];
System.arraycopy(parts, 1, fields, 0, l);
- expr = new FieldExpression(type, token, prefix, fields);
+ expr = new FieldExpression(rule, type, token, prefix, fields);
} else {
- expr = new StaticExpression(type, token, parts);
+ expr = new StaticExpression(rule, type, token, parts);
}
}
}
@@ -106,7 +107,7 @@
int dotIdx = text.lastIndexOf('.');
if (dotIdx < 0) {
// array name is direct variable reference
- arrayRef = new Variable(type, token);
+ arrayRef = new Variable(rule, type, token);
} else {
// field reference either to an instance named by a binding or or a static
@@ -124,15 +125,15 @@
int l = parts.length - 1;
String[] fields = new String[l];
System.arraycopy(parts, 1, fields, 0, l);
- arrayRef = new FieldExpression(type, token, prefix, fields);
+ arrayRef = new FieldExpression(rule, type, token, prefix, fields);
} else {
- arrayRef = new StaticExpression(type, token, parts);
+ arrayRef = new StaticExpression(rule, type, token, parts);
}
}
}
- List<Expression> indices = createExpressionList(bindings, child1, Type.INTEGER);
+ List<Expression> indices = createExpressionList(rule, bindings, child1, Type.INTEGER);
if (indices != null) {
- expr = new ArrayExpression(type, token, arrayRef, indices);
+ expr = new ArrayExpression(rule, type, token, arrayRef, indices);
} else {
throw new TypeException("ExpressionHelper.createExpression : invalid array index expression @ " + token.getLine() + "." + token.getCharPositionInLine());
}
@@ -151,7 +152,7 @@
if (token.getType() != SYMBOL) {
throw new TypeException("ExpressionHelper.createExpression : unexpected token Type in method expression tree " + tokenType + " for token " + token.getText() + " @ " + token.getLine() + "." + token.getCharPositionInLine());
} else {
- expr = createCallExpression(bindings, token, child1, type);
+ expr = createCallExpression(rule, bindings, token, child1, type);
}
}
break;
@@ -168,18 +169,18 @@
if (token.getType() != SYMBOL) {
throw new TypeException("ExpressionHelper.createExpression : unexpected token Type in throw expression tree " + tokenType + " for token " + token.getText() + " @ " + token.getLine() + "." + token.getCharPositionInLine());
} else {
- expr = createThrowExpression(bindings, token, child1, type);
+ expr = createThrowExpression(rule, bindings, token, child1, type);
}
}
break;
case NUMBER:
{
- expr = new NumericLiteral(token);
+ expr = new NumericLiteral(rule, token);
}
break;
case STRING:
{
- expr = new StringLiteral(token);
+ expr = new StringLiteral(rule, token);
}
break;
case RETURN:
@@ -187,26 +188,26 @@
Expression returnValue;
if (exprTree.getChildCount() > 0) {
CommonTree child0 = (CommonTree) exprTree.getChild(0);
- returnValue = createExpression(bindings,child0);
+ returnValue = createExpression(rule, bindings,child0);
} else {
returnValue = null;
}
- expr = new ReturnExpression(token, returnValue);
+ expr = new ReturnExpression(rule, token, returnValue);
}
break;
case UNOP:
{
- expr = createUnaryExpression(bindings, exprTree, type);
+ expr = createUnaryExpression(rule, bindings, exprTree, type);
}
break;
case BINOP:
{
- expr = createBinaryExpression(bindings, exprTree, type);
+ expr = createBinaryExpression(rule, bindings, exprTree, type);
}
break;
case TERNOP:
{
- expr = createTernaryExpression(bindings, exprTree, type);
+ expr = createTernaryExpression(rule, bindings, exprTree, type);
}
break;
default:
@@ -224,14 +225,14 @@
// we already know this is an invalid type so notify an error and return null
throw new TypeException("ExpressionHelper.createExpression : invalid expression type " + exprType.getName() + " expecting " + targetType.getName() + " @ " + token.getLine() + "." + token.getCharPositionInLine());
}
- if (!expr.bind(bindings)) {
+ if (!expr.bind()) {
throw new TypeException("ExpressionHelper.createExpression : unknown reference in expression @ " + token.getLine() + "." + token.getCharPositionInLine());
}
return expr;
}
- public static Expression createCallExpression(Bindings bindings, Token token, CommonTree argTree, Type type)
+ public static Expression createCallExpression(Rule rule, Bindings bindings, Token token, CommonTree argTree, Type type)
throws TypeException
{
Expression expr;
@@ -272,18 +273,18 @@
// many extra path elenments there are
if (pathLength == 1) {
// method call on bound variable
- recipient = new Variable(binding.getType(), token, binding.getName());
+ recipient = new Variable(rule, binding.getType(), token, binding.getName());
} else {
// method call on field of bound variable
String[] fields = new String[pathLength - 1];
System.arraycopy(path, 1, fields, 0, pathLength - 1);
- recipient = new FieldExpression(Type.UNDEFINED, token, prefix, fields);
+ recipient = new FieldExpression(rule, Type.UNDEFINED, token, prefix, fields);
}
} else {
// ok, we need a version of the path without the method name on the end
String[] realPath = new String[pathLength];
System.arraycopy(path, 0, realPath, 0, pathLength);
- recipient = new StaticExpression(Type.UNDEFINED, token, realPath);
+ recipient = new StaticExpression(rule, Type.UNDEFINED, token, realPath);
}
}
}
@@ -291,15 +292,15 @@
if (argTree == null) {
args = new ArrayList<Expression>();
} else {
- args = createExpressionList(bindings, argTree);
+ args = createExpressionList(rule, bindings, argTree);
}
- expr = new MethodExpression(type, token, callName, recipient, args);
+ expr = new MethodExpression(rule, type, token, callName, recipient, args);
return expr;
}
- public static Expression createThrowExpression(Bindings bindings, Token token, CommonTree argTree, Type type)
+ public static Expression createThrowExpression(Rule rule, Bindings bindings, Token token, CommonTree argTree, Type type)
throws TypeException
{
Expression expr;
@@ -311,15 +312,15 @@
if (argTree == null) {
args = new ArrayList<Expression>();
} else {
- args = createExpressionList(bindings, argTree);
+ args = createExpressionList(rule, bindings, argTree);
}
- expr = new ThrowExpression(typeName, token, args);
+ expr = new ThrowExpression(rule, typeName, token, args);
return expr;
}
- public static Expression createUnaryExpression(Bindings bindings, CommonTree exprTree, Type type)
+ public static Expression createUnaryExpression(Rule rule, Bindings bindings, CommonTree exprTree, Type type)
throws TypeException
{
// we expect ^(UNOP unary_oper expr)
@@ -337,8 +338,8 @@
if (!type.isUndefined() && !type.isVoid() && !type.isNumeric()) {
throw new TypeException("ExpressionHelper.createUnaryExpression : invalid numeric expression @ " + token.getLine() + "." + token.getCharPositionInLine());
}
- Expression operand = createExpression(bindings, child1, Type.NUMBER);
- expr = new TwiddleExpression(token, operand);
+ Expression operand = createExpression(rule, bindings, child1, Type.NUMBER);
+ expr = new TwiddleExpression(rule, token, operand);
}
break;
case NOT:
@@ -347,8 +348,8 @@
if (!type.isUndefined() && !type.isVoid() && !type.isBoolean()) {
throw new TypeException("ExpressionHelper.createUnaryExpression : invalid boolean expression @ " + token.getLine() + "." + token.getCharPositionInLine());
}
- Expression operand = createExpression(bindings, child1, Type.BOOLEAN);
- expr = new NotExpression( token, operand);
+ Expression operand = createExpression(rule, bindings, child1, Type.BOOLEAN);
+ expr = new NotExpression(rule, token, operand);
}
break;
default:
@@ -360,7 +361,7 @@
return expr;
}
- public static Expression createBinaryExpression(Bindings bindings, CommonTree exprTree, Type type)
+ public static Expression createBinaryExpression(Rule rule, Bindings bindings, CommonTree exprTree, Type type)
throws TypeException
{
// we expect ^(BINOP infix_oper simple_expr expr)
@@ -381,30 +382,30 @@
Expression operand2;
if (type == Type.STRING) {
// must be doing String concatenation
- operand1 = createExpression(bindings, child1, Type.STRING);
- operand2 = createExpression(bindings, child2, Type.UNDEFINED);
- expr = new StringPlusExpression(token, operand1, operand2);
+ operand1 = createExpression(rule, bindings, child1, Type.STRING);
+ operand2 = createExpression(rule, bindings, child2, Type.UNDEFINED);
+ expr = new StringPlusExpression(rule, token, operand1, operand2);
} else if (type.isNumeric()) {
// must be doing arithmetic
- operand1 = createExpression(bindings, child1, Type.NUMBER);
- operand2 = createExpression(bindings, child2, Type.NUMBER);
+ operand1 = createExpression(rule, bindings, child1, Type.NUMBER);
+ operand2 = createExpression(rule, bindings, child2, Type.NUMBER);
int convertedOper = OperExpression.convertOper(oper);
- expr = new ArithmeticExpression(convertedOper, token, operand1, operand2);
+ expr = new ArithmeticExpression(rule, convertedOper, token, operand1, operand2);
} else {
// see if the operand gives us any type info
- operand1 = createExpression(bindings, child1, Type.UNDEFINED);
+ operand1 = createExpression(rule, bindings, child1, Type.UNDEFINED);
if (operand1.getType().isNumeric()) {
- operand2 = createExpression(bindings, child2, Type.NUMBER);
+ operand2 = createExpression(rule, bindings, child2, Type.NUMBER);
int convertedOper = OperExpression.convertOper(oper);
- expr = new ArithmeticExpression(convertedOper, token, operand1, operand2);
+ expr = new ArithmeticExpression(rule, convertedOper, token, operand1, operand2);
} else if (operand1.getType() == Type.STRING) {
- operand2 = createExpression(bindings, child2, Type.UNDEFINED);
- expr = new StringPlusExpression(token, operand1, operand2);
+ operand2 = createExpression(rule, bindings, child2, Type.UNDEFINED);
+ expr = new StringPlusExpression(rule, token, operand1, operand2);
} else {
- operand2 = createExpression(bindings, child2, Type.UNDEFINED);
+ operand2 = createExpression(rule, bindings, child2, Type.UNDEFINED);
// create as generic plus expression which we will replace later during type
// checking
- expr = new PlusExpression(token, operand1, operand2);
+ expr = new PlusExpression(rule, token, operand1, operand2);
}
}
}
@@ -414,32 +415,32 @@
case DIV:
case MOD:
{
- Expression operand1 = createExpression(bindings, child1, Type.NUMBER);
- Expression operand2 = createExpression(bindings, child2, Type.NUMBER);
+ Expression operand1 = createExpression(rule, bindings, child1, Type.NUMBER);
+ Expression operand2 = createExpression(rule, bindings, child2, Type.NUMBER);
int convertedOper = OperExpression.convertOper(oper);
- expr = new ArithmeticExpression(convertedOper, token, operand1, operand2);
+ expr = new ArithmeticExpression(rule, convertedOper, token, operand1, operand2);
}
break;
case BAND:
case BOR:
case BXOR:
{
- Expression operand1 = createExpression(bindings, child1, Type.NUMBER);
- Expression operand2 = createExpression(bindings, child2, Type.NUMBER);
+ Expression operand1 = createExpression(rule, bindings, child1, Type.NUMBER);
+ Expression operand2 = createExpression(rule, bindings, child2, Type.NUMBER);
int convertedOper = OperExpression.convertOper(oper);
- expr = new BitExpression(convertedOper, token, operand1, operand2);
+ expr = new BitExpression(rule, convertedOper, token, operand1, operand2);
}
break;
case AND:
case OR:
{
- Expression operand1 = createExpression(bindings, child1, Type.BOOLEAN);
- Expression operand2 = createExpression(bindings, child2, Type.BOOLEAN);
+ Expression operand1 = createExpression(rule, bindings, child1, Type.BOOLEAN);
+ Expression operand2 = createExpression(rule, bindings, child2, Type.BOOLEAN);
int convertedOper = OperExpression.convertOper(oper);
- expr = new LogicalExpression(convertedOper, token, operand1, operand2);
+ expr = new LogicalExpression(rule, convertedOper, token, operand1, operand2);
}
break;
case EQ:
@@ -449,11 +450,11 @@
case GEQ:
case LEQ:
{
- Expression operand1 = createExpression(bindings, child1, Type.NUMBER);
- Expression operand2 = createExpression(bindings, child2, Type.NUMBER);
+ Expression operand1 = createExpression(rule, bindings, child1, Type.NUMBER);
+ Expression operand2 = createExpression(rule, bindings, child2, Type.NUMBER);
int convertedOper = OperExpression.convertOper(oper);
- expr = new ComparisonExpression(convertedOper, token, operand1, operand2);
+ expr = new ComparisonExpression(rule, convertedOper, token, operand1, operand2);
}
break;
default:
@@ -465,7 +466,7 @@
return expr;
}
- public static Expression createTernaryExpression(Bindings bindings, CommonTree exprTree, Type type)
+ public static Expression createTernaryExpression(Rule rule, Bindings bindings, CommonTree exprTree, Type type)
throws TypeException
{
// we expect ^(TERNOP ternary_oper simple_expr expr expr)
@@ -482,28 +483,28 @@
case TERN_IF:
{
// the argument must be a numeric expression
- Expression operand1 = createExpression(bindings, child1, Type.BOOLEAN);
- Expression operand2 = createExpression(bindings, child2, type);
- Expression operand3 = createExpression(bindings, child3, type);
+ Expression operand1 = createExpression(rule, bindings, child1, Type.BOOLEAN);
+ Expression operand2 = createExpression(rule, bindings, child2, type);
+ Expression operand3 = createExpression(rule, bindings, child3, type);
Type type2 = Type.dereference(operand2.getType());
Type type3 = Type.dereference(operand3.getType());
if (type2.isNumeric() || type3.isNumeric()) {
if (!type.isUndefined() && !type.isVoid() && !type.isNumeric()) {
throw new TypeException("ExpressionHelper.createUnaryExpression : invalid numeric expression @ " + token.getLine() + "." + token.getCharPositionInLine());
}
- expr = new ConditionalEvalExpression(Type.promote(type2, type3), token, operand1, operand2, operand3);
+ expr = new ConditionalEvalExpression(rule, Type.promote(type2, type3), token, operand1, operand2, operand3);
} else if (type2.isDefined() && type3.isDefined()) {
// since they are not numeric we have to have the same type
if (type2 == type3) {
// use this type
- expr = new ConditionalEvalExpression(type2, token, operand1, operand2, operand3);
+ expr = new ConditionalEvalExpression(rule, type2, token, operand1, operand2, operand3);
} else {
// mismatched types so don't generate a result
throw new TypeException("ExpressionHelper.createTernaryExpression : mismatched types " + type2.getName() + " and " + type3.getName() + " in conditional expression " + token.getType() + " for token " + token.getText() + " @ " + token.getLine() + "." + token.getCharPositionInLine());
}
} else {
// have to wait for type check to resolve types
- expr = new ConditionalEvalExpression(Type.UNDEFINED, token, operand1, operand2, operand3);
+ expr = new ConditionalEvalExpression(rule, Type.UNDEFINED, token, operand1, operand2, operand3);
}
}
break;
@@ -516,13 +517,13 @@
return expr;
}
- public static List<Expression> createExpressionList(Bindings bindings, CommonTree exprTree)
+ public static List<Expression> createExpressionList(Rule rule, Bindings bindings, CommonTree exprTree)
throws TypeException
{
- return createExpressionList(bindings, exprTree, Type.UNDEFINED);
+ return createExpressionList(rule, bindings, exprTree, Type.UNDEFINED);
}
- public static List<Expression> createExpressionList(Bindings bindings, CommonTree exprTree, Type type)
+ public static List<Expression> createExpressionList(Rule rule, Bindings bindings, CommonTree exprTree, Type type)
throws TypeException
{
// we expect expr_list = ^(EXPR) |
@@ -541,7 +542,7 @@
CommonTree child0 = (CommonTree) exprTree.getChild(0);
// assign tree before we risk an exception
exprTree = (CommonTree) exprTree.getChild(1);
- Expression expr = createExpression(bindings, child0, type);
+ Expression expr = createExpression(rule, bindings, child0, type);
exprList.add(expr);
}
break;
@@ -550,7 +551,7 @@
// assign tree before we risk an exception
CommonTree saveTree = exprTree;
exprTree = null;
- Expression expr = createExpression(bindings, saveTree, type);
+ Expression expr = createExpression(rule, bindings, saveTree, type);
exprList.add(expr);
}
break;
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/FieldExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/FieldExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/FieldExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -17,11 +17,11 @@
*/
public class FieldExpression extends Expression
{
- public FieldExpression(Type type, Token token, String ref, String[] fieldNames) {
+ public FieldExpression(Rule rule, Type type, Token token, String ref, String[] fieldNames) {
// type is the type of last field
// ownerType[i] is the type of the owner of field[i]
// so ownerType[0] is the type of ref;
- super(type, token);
+ super(rule, type, token);
this.ref = ref;
this.fieldNames = fieldNames;
int len = fieldNames.length;
@@ -36,14 +36,13 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// ensure that there is a binding with this name
- Binding binding = bindings.lookup(ref);
+ Binding binding = getBindings().lookup(ref);
if (binding == null) {
System.err.println("FieldExpresssion.bind : unbound instance " + ref + getPos());
@@ -53,11 +52,11 @@
return true;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// check the owner type is defined and then start searching for
// the types of each field referenced from it
- Binding binding = bindings.lookup(ref);
+ Binding binding = getBindings().lookup(ref);
Type bindingType = binding.getType();
ownerType[0] = Type.dereference(bindingType);
@@ -85,7 +84,7 @@
}
valueClass = fields[i].getType();
- valueType = typegroup.ensureType(valueClass);
+ valueType = getTypeGroup().ensureType(valueClass);
}
type = valueType;
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/LogicalExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/LogicalExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/LogicalExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -13,14 +13,14 @@
*/
public class LogicalExpression extends BooleanExpression
{
- public LogicalExpression(int oper, Token token, Expression left, Expression right)
+ public LogicalExpression(Rule rule, int oper, Token token, Expression left, Expression right)
{
- super(oper, token, left, right);
+ super(rule, oper, token, left, right);
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
- Type type1 = getOperand(0).typeCheck(bindings, typegroup, Type.Z);
- Type type2 = getOperand(1).typeCheck(bindings, typegroup, Type.Z);
+ public Type typeCheck(Type expected) throws TypeException {
+ Type type1 = getOperand(0).typeCheck(Type.Z);
+ Type type2 = getOperand(1).typeCheck(Type.Z);
type = Type.Z;
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
throw new TypeException("LogicalExpression.typeCheck : invalid expected result type " + expected.getName() + getPos());
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/MethodExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/MethodExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/MethodExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -19,8 +19,8 @@
*/
public class MethodExpression extends Expression
{
- public MethodExpression(Type type, Token token, String name, Expression recipient, List<Expression> arguments) {
- super(type, token);
+ public MethodExpression(Rule rule, Type type, Token token, String name, Expression recipient, List<Expression> arguments) {
+ super(rule, type, token);
this.name = name;
this.recipient = recipient;
this.arguments = arguments;
@@ -32,39 +32,39 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// check that the recipient and argument expressions have valid bindings
boolean valid = true;
if (recipient != null) {
- valid &= recipient.bind(bindings);
+ valid &= recipient.bind();
}
Iterator<Expression> iterator = arguments.iterator();
while (valid && iterator.hasNext()) {
- valid &= iterator.next().bind(bindings);
+ valid &= iterator.next().bind();
}
return valid;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// if we have no recipient then we use the rule's helper as a target via a binding
// to $-1. this means we can type check the call against methods of class Rule$Helper
// without having to do any special case processing.
+ TypeGroup typeGroup = getTypeGroup();
if (recipient == null) {
- Type ruleType = typegroup.create("org.jboss.jbossts.orchestration.rule.Rule$Helper");
- recipient = new DollarExpression(ruleType, token, "$-1");
+ Type ruleType = typeGroup.create("org.jboss.jbossts.orchestration.rule.Rule$Helper");
+ recipient = new DollarExpression(rule, ruleType, token, "$-1");
}
// check the recipient type is defined and then look for a relevant method
- Type recipientType = recipient.typeCheck(bindings, typegroup, Type.UNDEFINED);
+ Type recipientType = recipient.typeCheck(Type.UNDEFINED);
Class clazz = recipientType.getTargetClass();
// if we can find a unique method then we can use it to type the parameters
// otherwise we do it the hard way
@@ -97,11 +97,11 @@
Class candidateClass = getCandidateArgClass(candidates, i);
Type candidateType;
if (candidateClass != null) {
- candidateType = typegroup.ensureType(candidateClass);
+ candidateType = typeGroup.ensureType(candidateClass);
} else {
candidateType = Type.UNDEFINED;
}
- Type argType = arguments.get(i).typeCheck(bindings, typegroup, candidateType);
+ Type argType = arguments.get(i).typeCheck(candidateType);
argumentTypes.add(argType);
if (candidateType == Type.UNDEFINED) {
// we had several methods to choose from
@@ -119,7 +119,7 @@
method = candidates.get(0);
- type = typegroup.ensureType(method.getReturnType());
+ type = typeGroup.ensureType(method.getReturnType());
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
throw new TypeException("MethodExpression.typeCheck : invalid expected type " + expected.getName() + getPos());
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/NotExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/NotExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/NotExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -12,14 +12,14 @@
*/
public class NotExpression extends UnaryOperExpression
{
- public NotExpression(Token token, Expression operand)
+ public NotExpression(Rule rule, Token token, Expression operand)
{
- super(NOT, Type.BOOLEAN, token, operand);
+ super(rule, NOT, Type.BOOLEAN, token, operand);
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected)
+ public Type typeCheck(Type expected)
throws TypeException {
- type = getOperand(0).typeCheck(bindings, typegroup, Type.Z);
+ type = getOperand(0).typeCheck(Type.Z);
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
throw new TypeException("NotExpression.typeCheck() : invalid result type : " + expected.getName() + getPos());
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/NumericLiteral.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/NumericLiteral.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/NumericLiteral.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -15,8 +15,8 @@
public class NumericLiteral extends Expression
{
- public NumericLiteral(Token token) {
- super(check(token.getText()), token);
+ public NumericLiteral(Rule rule, Token token) {
+ super(rule, check(token.getText()), token);
this.text = token.getText();
}
@@ -26,11 +26,10 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// no bindings to check but stash a valid value to help with type checking
if (type == Type.FLOAT) {
value = Float.valueOf(text);
@@ -49,7 +48,7 @@
return true;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
if (!expected.isNumeric()) {
throw new TypeException("NumericLiteral.typeCheck : invalid expected type " + expected.getName() + getPos());
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/OperExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/OperExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/OperExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -4,6 +4,7 @@
import org.jboss.jbossts.orchestration.rule.type.Type;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
import org.jboss.jbossts.orchestration.rule.exception.ParseException;
+import org.jboss.jbossts.orchestration.rule.Rule;
import java.util.Iterator;
import java.io.StringWriter;
@@ -13,9 +14,9 @@
*/
public abstract class OperExpression extends Expression
{
- OperExpression(int oper, Type type, Token token)
+ OperExpression(Rule rule, int oper, Type type, Token token)
{
- super(type, token);
+ super(rule, type, token);
this.oper = oper;
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/PlusExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/PlusExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/PlusExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -15,24 +15,24 @@
*/
public class PlusExpression extends BinaryOperExpression
{
- public PlusExpression(Token token, Expression left, Expression right)
+ public PlusExpression(Rule rule, Token token, Expression left, Expression right)
{
- super(PLUS, Type.UNDEFINED, token, left, right);
+ super(rule, PLUS, Type.UNDEFINED, token, left, right);
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// if the expected type is numeric then we know this must be an arithmetic plus
// if it is string then this could still be an arithmetic plus so we will
// have to rely on the type of the first argument to guide us
- Type type1 = getOperand(0).typeCheck(bindings, typegroup, (expected.isNumeric() ? expected : Type.UNDEFINED));
+ Type type1 = getOperand(0).typeCheck((expected.isNumeric() ? expected : Type.UNDEFINED));
Type type2;
if (type1.isNumeric()) {
- type2 = getOperand(1).typeCheck(bindings, typegroup, Type.N);
+ type2 = getOperand(1).typeCheck(Type.N);
type = Type.promote(type1, type2);
} else if (type1.isString()) {
- type2 = getOperand(1).typeCheck(bindings, typegroup, Type.STRING);
+ type2 = getOperand(1).typeCheck(Type.STRING);
} else {
throw new TypeException("PlusExpression.typeCheck : invalid argument type " + type1.getName() + getPos());
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ReturnExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ReturnExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ReturnExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -21,12 +21,12 @@
{
private Expression returnValue;
- public ReturnExpression(Token token, Expression returnValue)
+ public ReturnExpression(Rule rule, Token token, Expression returnValue)
{
// the trigger method may return any old tyep but the return expression can only occur
// at the top level in a rule action seuqence so it is actually a VOID expression
- super(Type.VOID, token);
+ super(rule, Type.VOID, token);
this.returnValue = returnValue;
}
@@ -35,14 +35,13 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
if (returnValue != null) {
// ensure the return value expression has all its bindings
- return returnValue.bind(bindings);
+ return returnValue.bind();
}
return true;
}
@@ -52,18 +51,15 @@
* can be resolved, that the type of the expression is well-defined and that it is
* compatible with the type expected in the context in which it occurs.
*
- * @param bindings the bound variable in scope at the point where the expression is
- * to be evaluate
- * @param typegroup the set of types employed by the rule
* @param expected the type expected for the expression in the contxt in which it occurs. this
* may be void but shoudl not be undefined at the point where type checking is performed.
* @return
* @throws org.jboss.jbossts.orchestration.rule.exception.TypeException
*
*/
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// we need to check the returnValue expression against the type of the trigger method
- Binding returnBinding = bindings.lookup("$!");
+ Binding returnBinding = getBindings().lookup("$!");
Type returnBindingType = (returnBinding != null ? returnBinding.getType() : Type.VOID);
if (returnValue == null && !returnBindingType.isVoid()) {
throw new TypeException("ReturnExpression.typeCheck : return expression must supply argument when triggered from method with return type " + returnBindingType.getName() + getPos());
@@ -71,7 +67,7 @@
if (returnBindingType.isVoid()) {
throw new TypeException("ReturnExpression.typeCheck : return expression must not supply argument when triggered from void method" + getPos());
}
- returnValue.typeCheck(bindings, typegroup, returnBindingType);
+ returnValue.typeCheck(returnBindingType);
}
return type;
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StaticExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StaticExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StaticExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -16,9 +16,9 @@
*/
public class StaticExpression extends Expression
{
- public StaticExpression(Type type, Token token, String[] path) {
+ public StaticExpression(Rule rule, Type type, Token token, String[] path) {
// type is the type of static field
- super(type, token);
+ super(rule, type, token);
this.path = path;
this.fieldNames = null;
this.ownerTypes = null;
@@ -29,19 +29,19 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// nothing to verify
return true;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// look for a class whose name matches some initial segment of path
- Type rootType = typegroup.match(path);
+ TypeGroup typeGroup = getTypeGroup();
+ Type rootType = typeGroup.match(path);
if (rootType == null) {
throw new TypeException("StaticExpression.typeCheck : invalid path to static field " + getPath(path.length) + getPos());
}
@@ -84,7 +84,7 @@
throw new TypeException("StaticExpression.typeCheck : invalid field name " + fieldNames[idx] + getPos());
}
clazz = fields[idx].getType();
- valueType = typegroup.ensureType(clazz);
+ valueType = typeGroup.ensureType(clazz);
}
type = valueType;
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StringLiteral.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StringLiteral.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StringLiteral.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -15,9 +15,9 @@
*/
public class StringLiteral extends Expression
{
- public StringLiteral(Token token)
+ public StringLiteral(Rule rule, Token token)
{
- super(Type.STRING, token);
+ super(rule, Type.STRING, token);
this.text = token.getText();
}
@@ -27,15 +27,14 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
return true;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
return type;
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StringPlusExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StringPlusExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/StringPlusExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -13,16 +13,16 @@
*/
public class StringPlusExpression extends BinaryOperExpression
{
- public StringPlusExpression(Token token, Expression left, Expression right)
+ public StringPlusExpression(Rule rule, Token token, Expression left, Expression right)
{
- super(PLUS, Type.STRING, token, left, right);
+ super(rule, PLUS, Type.STRING, token, left, right);
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// first type must be a string -- second may be anything but expect
// a string to indicate that it must be assignable evn if only by conversion
- Type type1 = getOperand(0).typeCheck(bindings, typegroup, Type.STRING);
- Type type2 = getOperand(1).typeCheck(bindings, typegroup, Type.STRING);
+ Type type1 = getOperand(0).typeCheck(Type.STRING);
+ Type type2 = getOperand(1).typeCheck(Type.STRING);
// result will always be a String
if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(Type.STRING)) {
throw new TypeException("StringPlusExpression.typeCheck : invalid expected result type " + expected.getName() + getPos());
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/TernaryOperExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/TernaryOperExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/TernaryOperExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -3,6 +3,7 @@
import org.jboss.jbossts.orchestration.rule.type.Type;
import org.jboss.jbossts.orchestration.rule.binding.Bindings;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
+import org.jboss.jbossts.orchestration.rule.Rule;
import org.antlr.runtime.Token;
/**
@@ -10,10 +11,10 @@
*/
public abstract class TernaryOperExpression extends OperExpression
{
- public TernaryOperExpression(int oper, Type type, Token token, Expression operand1,
+ public TernaryOperExpression(Rule rule, int oper, Type type, Token token, Expression operand1,
Expression operand2, Expression operand3)
{
- super(oper, type, token);
+ super(rule, oper, type, token);
this.operand1 = operand1;
this.operand2 = operand2;
this.operand3 = operand3;
@@ -24,17 +25,16 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// we just need to ensure that the operands can find their bindings
// run both so we get as many errors as possible
- boolean success = operand1.bind(bindings);
- success &= operand2.bind(bindings);
- success &= operand3.bind(bindings);
+ boolean success = operand1.bind();
+ success &= operand2.bind();
+ success &= operand3.bind();
return success;
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ThrowExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ThrowExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/ThrowExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -32,8 +32,8 @@
private List<Type> argumentTypes;
private Constructor constructor;
- public ThrowExpression(String typeName, Token token, List<Expression> arguments) {
- super(Type.UNDEFINED, token);
+ public ThrowExpression(Rule rule, String typeName, Token token, List<Expression> arguments) {
+ super(rule, Type.UNDEFINED, token);
this.typeName = typeName;
this.arguments = arguments;
this.argumentTypes = null;
@@ -44,18 +44,17 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// check that the recipient and argument expressions have valid bindings
boolean valid = true;
Iterator<Expression> iterator = arguments.iterator();
while (valid && iterator.hasNext()) {
- valid &= iterator.next().bind(bindings);
+ valid &= iterator.next().bind();
}
return valid;
@@ -66,20 +65,19 @@
* can be resolved, that the type of the expression is well-defined and that it is
* compatible with the type expected in the context in which it occurs.
*
- * @param bindings the bound variable in scope at the point where the expression is
- * to be evaluate
- * @param typegroup the set of types employed by the rule
* @param expected the type expected for the expression in the contxt in which it occurs. this
* may be void but shoudl not be undefined at the point where type checking is performed.
* @return
* @throws org.jboss.jbossts.orchestration.rule.exception.TypeException
*
*/
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// check the exception type is defined and then look for a relevant constructor
- type = Type.dereference(typegroup.create(typeName));
+ TypeGroup typeGroup = getTypeGroup();
+ type = Type.dereference(typeGroup.create(typeName));
+
if (type.isUndefined()) {
throw new TypeException("ThrowExpression.typeCheck : unknown exception type " + typeName + getPos());
}
@@ -119,11 +117,11 @@
Class candidateClass = getCandidateArgClass(candidates, i);
Type candidateType;
if (candidateClass != null) {
- candidateType = typegroup.ensureType(candidateClass);
+ candidateType = typeGroup.ensureType(candidateClass);
} else {
candidateType = Type.UNDEFINED;
}
- Type argType = arguments.get(i).typeCheck(bindings, typegroup, candidateType);
+ Type argType = arguments.get(i).typeCheck(candidateType);
argumentTypes.add(argType);
if (candidateType == Type.UNDEFINED) {
// we had several constructors to choose from
@@ -148,7 +146,7 @@
if (RuntimeException.class.isAssignableFrom(type.getTargetClass())) {
return type;
} else {
- Iterator<Type> iterator = typegroup.getExceptionTypes().iterator();
+ Iterator<Type> iterator = typeGroup.getExceptionTypes().iterator();
while (iterator.hasNext()) {
Type exceptionType = iterator.next();
if (Type.dereference(exceptionType).isAssignableFrom(type)) {
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/TwiddleExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/TwiddleExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/TwiddleExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -12,14 +12,14 @@
*/
public class TwiddleExpression extends UnaryOperExpression
{
- public TwiddleExpression(Token token, Expression operand)
+ public TwiddleExpression(Rule rule, Token token, Expression operand)
{
- super(TWIDDLE, operand.getType(), token, operand);
+ super(rule, TWIDDLE, operand.getType(), token, operand);
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected)
+ public Type typeCheck(Type expected)
throws TypeException {
- type = getOperand(0).typeCheck(bindings, typegroup, Type.N);
+ type = getOperand(0).typeCheck(Type.N);
if (type == Type.F || type == Type.D) {
type = Type.J;
}
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/UnaryOperExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/UnaryOperExpression.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/UnaryOperExpression.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -3,6 +3,7 @@
import org.jboss.jbossts.orchestration.rule.type.Type;
import org.jboss.jbossts.orchestration.rule.binding.Bindings;
import org.jboss.jbossts.orchestration.rule.exception.TypeException;
+import org.jboss.jbossts.orchestration.rule.Rule;
import org.antlr.runtime.Token;
import java.io.StringWriter;
@@ -14,9 +15,9 @@
*/
public abstract class UnaryOperExpression extends OperExpression
{
- public UnaryOperExpression(int oper, Type type, Token token, Expression operand)
+ public UnaryOperExpression(Rule rule, int oper, Type type, Token token, Expression operand)
{
- super(oper, type, token);
+ super(rule, oper, type, token);
this.operand = operand;
}
@@ -25,13 +26,12 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// we just need to ensure that the operand can find its bindings
- return operand.bind(bindings);
+ return operand.bind();
}
/**
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/Variable.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/Variable.java 2008-10-01 10:46:51 UTC (rev 23238)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/expression/Variable.java 2008-10-01 10:49:10 UTC (rev 23239)
@@ -18,13 +18,13 @@
*/
public class Variable extends Expression
{
- public Variable(Type type, Token token) {
- super(type, token);
+ public Variable(Rule rule, Type type, Token token) {
+ super(rule, type, token);
this.name = token.getText();
}
- public Variable(Type type, Token token, String name) {
- super(type, token);
+ public Variable(Rule rule, Type type, Token token, String name) {
+ super(rule, type, token);
this.name = name;
}
@@ -33,14 +33,13 @@
* bindings list and infer/validate the type of this expression or its subexpressions
* where possible
*
- * @param bindings the set of bindings in place at the point of evaluation of this expression
* @return true if all variables in this expression are bound and no type mismatches have
* been detected during inference/validation.
*/
- public boolean bind(Bindings bindings) {
+ public boolean bind() {
// ensure that there is a binding with this name
- Binding binding = bindings.lookup(name);
+ Binding binding = getBindings().lookup(name);
if (binding == null) {
System.err.println("Variable.bind : unbound variable " + name + getPos());
@@ -53,10 +52,10 @@
return true;
}
- public Type typeCheck(Bindings bindings, TypeGroup typegroup, Type expected) throws TypeException {
+ public Type typeCheck(Type expected) throws TypeException {
// type must be defined by now or we are in trouble
- Binding binding = bindings.lookup(name);
+ Binding binding = getBindings().lookup(name);
type = Type.dereference(binding.getType());
More information about the jboss-svn-commits
mailing list