case IDENTIFIER:
{
// check for path qualifier
String name = (String)exprTree.getChild(0);
ParseNode child1 = (ParseNode)exprTree.getChild(1);
if (child1 == null && bindings.lookup(name) != null) {
// a clear cut direct variable reference
expr = new Variable(rule, type, exprTree);
} else {
// we should only get these as identifiers for binding types or throw types which are
// explicitly caught by the bindings or throw processing case handlers so this is an error
throw new TypeException("ExpressionHelper.createExpression : unexpected IDENTIFIER " + exprTree.getText() + " in " + exprTree.getPos());
}
}
break;
case ARRAY:
{
ParseNode child0 = (ParseNode) exprTree.getChild(0);
ParseNode child1 = (ParseNode) exprTree.getChild(1);
Expression arrayRef = createExpression(rule, bindings, child0, Type.UNDEFINED);
List<Expression> indices = createExpressionList(rule, bindings, child1, Type.I);
if (indices != null) {
expr = new ArrayExpression(rule, type, exprTree, arrayRef, indices);
} else {
throw new TypeException("ExpressionHelper.createExpression : invalid array index expression " + exprTree.getPos());
}
}
break;
case FIELD:
{
ParseNode child0 = (ParseNode) exprTree.getChild(0);
ParseNode child1 = (ParseNode) exprTree.getChild(1);
expr = createFieldExpression(rule, bindings, child0, child1, type);
}
break;
case METH:
{
ParseNode child0 = (ParseNode) exprTree.getChild(0);
ParseNode child1 = (ParseNode) exprTree.getChild(1);
ParseNode child2 = (ParseNode) exprTree.getChild(2);
int tag0 = child0.getTag();
if (tag0 != IDENTIFIER) {
// uurgh we expected a method name
throw new TypeException("ExpressionHelper.createExpression : invalid method selector " + tag + " in expression " + child0.getText() + child0.getPos());
}
expr = createCallExpression(rule, bindings, child0, child1, child2, type);
}
break;
case THROW:
{
ParseNode child0 = (ParseNode) exprTree.getChild(0);
ParseNode child1 = (ParseNode) exprTree.getChild(1);
int tag0 = child0.getTag();
if (tag0 != IDENTIFIER) {
throw new TypeException("ExpressionHelper.createExpression : invalid throw type " + tag + " in expression " + child0.getText() + child0.getPos());
} else {
expr = createThrowExpression(rule, bindings, child0, child1);
}
}
break;
case NEW:
{
ParseNode child0 = (ParseNode) exprTree.getChild(0);
ParseNode child1 = (ParseNode) exprTree.getChild(1);
int tag0 = child0.getTag();
if (tag0 != IDENTIFIER) {
throw new TypeException("ExpressionHelper.createExpression : invalid new type " + tag + " in expression " + child0.getText() + child0.getPos());
} else {
expr = createNewExpression(rule, bindings, child0, child1);
}
}
break;
case INTEGER_LITERAL:
{
expr = new NumericLiteral(rule, Type.I, exprTree);
}
break;
case FLOAT_LITERAL:
{
expr = new NumericLiteral(rule, Type.F, exprTree);
}
break;
case STRING_LITERAL:
{
expr = new StringLiteral(rule, exprTree);
}
break;
case BOOLEAN_LITERAL:
{
expr = new BooleanLiteral(rule, exprTree);
}
break;
case NULL_LITERAL:
{
expr = new NullLiteral(rule, exprTree);
}
break;
case RETURN:
{
Expression returnValue;
ParseNode child0 = (ParseNode) exprTree.getChild(0);
if (child0 != null) {
returnValue = createExpression(rule, bindings, child0);
} else {
returnValue = null;
}
expr = new ReturnExpression(rule, exprTree, returnValue);
}
break;
case DOLLAR:
{
String text = (String)exprTree.getChild(0);
char leading = text.charAt(1);
if (Character.isDigit(leading)) {
int index = Integer.valueOf(text.substring(1));
expr = new DollarExpression(rule, type, exprTree, index);
} else if (text.equals("$!")) {
expr = new DollarExpression(rule, type, exprTree, DollarExpression.RETURN_VALUE_IDX);
} else if (text.equals("$^")) {
expr = new DollarExpression(rule, type, exprTree, DollarExpression.THROWABLE_VALUE_IDX);
} else if (text.equals("$#")) {
expr = new DollarExpression(rule, Type.I, exprTree, DollarExpression.PARAM_COUNT_IDX);
} else if (text.equals("$*")) {
expr = new DollarExpression(rule, rule.getTypeGroup().createArray(Type.OBJECT), exprTree, DollarExpression.PARAM_ARRAY_IDX);
} else if (text.equals("$@")) {
expr = new DollarExpression(rule, rule.getTypeGroup().createArray(Type.OBJECT), exprTree, DollarExpression.INVOKE_PARAM_ARRAY_IDX);
} else {
expr = new DollarExpression(rule, type, exprTree, text.substring(1));
}
}
break;
case ASSIGN:
{
ParseNode child0 = (ParseNode) exprTree.getChild(0);
ParseNode child1 = (ParseNode) exprTree.getChild(1);
// the left hand side is special but nay expression will do for the right hand side
AssignableExpression left = createAssignableExpression(rule, bindings, child0, type);;
Expression right = createExpression(rule, bindings, child1, type);