use of org.mvel2.ast.TypedVarNode in project mvel by mikebrock.
the class AbstractParser method procTypedNode.
/**
* Process the current typed node
*
* @param decl node is a declaration or not
* @return and ast node
*/
private ASTNode procTypedNode(boolean decl) {
while (true) {
if (lastNode.getLiteralValue() instanceof String) {
char[] tmp = ((String) lastNode.getLiteralValue()).toCharArray();
TypeDescriptor tDescr = new TypeDescriptor(tmp, 0, tmp.length, 0);
try {
lastNode.setLiteralValue(getClassReference(pCtx, tDescr));
lastNode.discard();
} catch (Exception e) {
// fall through;
}
}
if (lastNode.isLiteral() && lastNode.getLiteralValue() instanceof Class) {
lastNode.discard();
captureToEOS();
if (decl) {
splitAccumulator.add(new DeclTypedVarNode(new String(expr, st, cursor - st), expr, st, cursor - st, (Class) lastNode.getLiteralValue(), fields | ASTNode.ASSIGN, pCtx));
} else {
captureToEOS();
splitAccumulator.add(new TypedVarNode(expr, st, cursor - st - 1, fields | ASTNode.ASSIGN, (Class) lastNode.getLiteralValue(), pCtx));
}
} else if (lastNode instanceof Proto) {
captureToEOS();
if (decl) {
splitAccumulator.add(new DeclProtoVarNode(new String(expr, st, cursor - st), (Proto) lastNode, fields | ASTNode.ASSIGN, pCtx));
} else {
splitAccumulator.add(new ProtoVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Proto) lastNode, pCtx));
}
} else // this redundant looking code is needed to work with the interpreter and MVELSH properly.
if ((fields & ASTNode.COMPILE_IMMEDIATE) == 0) {
if (stk.peek() instanceof Class) {
captureToEOS();
if (decl) {
splitAccumulator.add(new DeclTypedVarNode(new String(expr, st, cursor - st), expr, st, cursor - st, (Class) stk.pop(), fields | ASTNode.ASSIGN, pCtx));
} else {
splitAccumulator.add(new TypedVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Class) stk.pop(), pCtx));
}
} else if (stk.peek() instanceof Proto) {
captureToEOS();
if (decl) {
splitAccumulator.add(new DeclProtoVarNode(new String(expr, st, cursor - st), (Proto) stk.pop(), fields | ASTNode.ASSIGN, pCtx));
} else {
splitAccumulator.add(new ProtoVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Proto) stk.pop(), pCtx));
}
} else {
throw new CompileException("unknown class or illegal statement: " + lastNode.getLiteralValue(), expr, cursor);
}
} else {
throw new CompileException("unknown class or illegal statement: " + lastNode.getLiteralValue(), expr, cursor);
}
skipWhitespace();
if (cursor < end && expr[cursor] == ',') {
st = ++cursor;
splitAccumulator.add(new EndOfStatement());
} else {
return (ASTNode) splitAccumulator.pop();
}
}
}
use of org.mvel2.ast.TypedVarNode in project mvel by mvel.
the class AbstractParser method procTypedNode.
/**
* Process the current typed node
*
* @param decl node is a declaration or not
* @return and ast node
*/
private ASTNode procTypedNode(boolean decl) {
while (true) {
if (lastNode.getLiteralValue() instanceof String) {
char[] tmp = ((String) lastNode.getLiteralValue()).toCharArray();
TypeDescriptor tDescr = new TypeDescriptor(tmp, 0, tmp.length, 0);
try {
lastNode.setLiteralValue(getClassReference(pCtx, tDescr));
lastNode.discard();
} catch (Exception e) {
// fall through;
}
}
if (lastNode.isLiteral() && lastNode.getLiteralValue() instanceof Class) {
lastNode.discard();
captureToEOS();
if (decl) {
splitAccumulator.add(new DeclTypedVarNode(new String(expr, st, cursor - st), expr, st, cursor - st, (Class) lastNode.getLiteralValue(), fields | ASTNode.ASSIGN, pCtx));
} else {
captureToEOS();
splitAccumulator.add(new TypedVarNode(expr, st, cursor - st - 1, fields | ASTNode.ASSIGN, (Class) lastNode.getLiteralValue(), pCtx));
}
} else if (lastNode instanceof Proto) {
captureToEOS();
if (decl) {
splitAccumulator.add(new DeclProtoVarNode(new String(expr, st, cursor - st), (Proto) lastNode, fields | ASTNode.ASSIGN, pCtx));
} else {
splitAccumulator.add(new ProtoVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Proto) lastNode, pCtx));
}
} else // this redundant looking code is needed to work with the interpreter and MVELSH properly.
if ((fields & ASTNode.COMPILE_IMMEDIATE) == 0) {
if (stk.peek() instanceof Class) {
captureToEOS();
if (decl) {
splitAccumulator.add(new DeclTypedVarNode(new String(expr, st, cursor - st), expr, st, cursor - st, (Class) stk.pop(), fields | ASTNode.ASSIGN, pCtx));
} else {
splitAccumulator.add(new TypedVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Class) stk.pop(), pCtx));
}
} else if (stk.peek() instanceof Proto) {
captureToEOS();
if (decl) {
splitAccumulator.add(new DeclProtoVarNode(new String(expr, st, cursor - st), (Proto) stk.pop(), fields | ASTNode.ASSIGN, pCtx));
} else {
splitAccumulator.add(new ProtoVarNode(expr, st, cursor - st, fields | ASTNode.ASSIGN, (Proto) stk.pop(), pCtx));
}
} else {
throw new CompileException("unknown class or illegal statement: " + lastNode.getLiteralValue(), expr, cursor);
}
} else {
throw new CompileException("unknown class or illegal statement: " + lastNode.getLiteralValue(), expr, cursor);
}
skipWhitespace();
if (cursor < end && expr[cursor] == ',') {
st = ++cursor;
splitAccumulator.add(new EndOfStatement(pCtx));
} else {
return (ASTNode) splitAccumulator.pop();
}
}
}
Aggregations