Search in sources :

Example 1 with TypedVarNode

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();
        }
    }
}
Also used : CompileException(org.mvel2.CompileException) CompileException(org.mvel2.CompileException)

Example 2 with TypedVarNode

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();
        }
    }
}
Also used : ProtoVarNode(org.mvel2.ast.ProtoVarNode) DeclProtoVarNode(org.mvel2.ast.DeclProtoVarNode) EndOfStatement(org.mvel2.ast.EndOfStatement) CompileException(org.mvel2.CompileException) RedundantCodeException(org.mvel2.ast.RedundantCodeException) TypeDescriptor(org.mvel2.ast.TypeDescriptor) Proto(org.mvel2.ast.Proto) DeclProtoVarNode(org.mvel2.ast.DeclProtoVarNode) IndexedDeclTypedVarNode(org.mvel2.ast.IndexedDeclTypedVarNode) DeclTypedVarNode(org.mvel2.ast.DeclTypedVarNode) ASTNode(org.mvel2.ast.ASTNode) CompileException(org.mvel2.CompileException) IndexedDeclTypedVarNode(org.mvel2.ast.IndexedDeclTypedVarNode) TypedVarNode(org.mvel2.ast.TypedVarNode) DeclTypedVarNode(org.mvel2.ast.DeclTypedVarNode)

Aggregations

CompileException (org.mvel2.CompileException)2 ASTNode (org.mvel2.ast.ASTNode)1 DeclProtoVarNode (org.mvel2.ast.DeclProtoVarNode)1 DeclTypedVarNode (org.mvel2.ast.DeclTypedVarNode)1 EndOfStatement (org.mvel2.ast.EndOfStatement)1 IndexedDeclTypedVarNode (org.mvel2.ast.IndexedDeclTypedVarNode)1 Proto (org.mvel2.ast.Proto)1 ProtoVarNode (org.mvel2.ast.ProtoVarNode)1 RedundantCodeException (org.mvel2.ast.RedundantCodeException)1 TypeDescriptor (org.mvel2.ast.TypeDescriptor)1 TypedVarNode (org.mvel2.ast.TypedVarNode)1