Package org.jboss.byteman.rule.grammar

Examples of org.jboss.byteman.rule.grammar.ParseNode


    public static Expression createTernaryExpression(Rule rule, Bindings bindings, ParseNode exprTree, Type type)
            throws TypeException
    {
        // we only expect ^(TERNOP ternary_oper simple_expr expr expr)

        ParseNode child0 = (ParseNode) exprTree.getChild(0);
        ParseNode child1 = (ParseNode) exprTree.getChild(1);
        ParseNode child2 = (ParseNode) exprTree.getChild(2);
        Expression expr;
        int oper = exprTree.getTag();

        switch (oper)
        {
View Full Code Here


        // we allow assignment to identifiers or dollar symbols
        int tag = exprTree.getTag();
        switch(tag) {
            case FIELD:
            {
                ParseNode child0 = (ParseNode) exprTree.getChild(0);
                ParseNode child1 = (ParseNode) exprTree.getChild(1);
                expr = createFieldExpression(rule, bindings, child0, child1, type);
            }
            break;
            case IDENTIFIER:
            {
                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, name);
                } 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.createAssignableExpression : unexpected IDENTIFIER " + exprTree.getText() + " in "  + exprTree.getPos());
                }
            }
            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 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);

View Full Code Here

                switch (exprTree.getTag())
                {
                    case SEMI:
                    case COMMA:
                    {
                        ParseNode child0 = (ParseNode) exprTree.getChild(0);
                        // assign tree before we risk an exception
                        exprTree = (ParseNode) exprTree.getChild(1);
                        Expression expr = createExpression(rule, bindings, child0, type);
                        exprList.add(expr);
                    }
                    break;
                    default:
                    {
                        // assign tree before we risk an exception
                        ParseNode saveTree = exprTree;
                        exprTree = null;
                        Expression expr = createExpression(rule, bindings, saveTree, type);
                        exprList.add(expr);
                    }
                    break;
View Full Code Here

        int emptyDimCount = 0;

        while (exprTree != null)
        {
            try {
                ParseNode saveTree = exprTree;
                ParseNode child;
                if (exprTree.getTag() == COMMA) {
                    child = (ParseNode) exprTree.getChild(0);
                    exprTree = (ParseNode) exprTree.getChild(1);
                } else {
                    child = exprTree;
                    exprTree = null;
                }
                // count an extra array dimension
                arrayDimCount++;

                if (child.getTag() == NOTHING) {
                    //  this is an empty array dimension
                    emptyDimCount++;
                    foundEmptyDim = true;
                    // append null to the list to represent the empty dimension
                    exprList.add(null);
                } else  if (!foundEmptyDim){
                    Expression expr = createExpression(rule, bindings, child, Type.I);
                    exprList.add(expr);
                } else {
                    // once we see an empty dim we expect to see al empty dims
                    throw new TypeException("ExpressionHelper.createNewExpressionIndexList : invalid array dimension " + child.getPos());
                }
            } catch (TypeException te) {
                exceptions.add(te);
            }
        }
View Full Code Here

            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);
                ParseNode child2 = (ParseNode) exprTree.getChild(2);
                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, child2);
                }
            }
            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);

View Full Code Here

    }

    public static String[] createPathList(ParseNode pathTree)
    {
        int l = 0;
        ParseNode p = pathTree;

        while (p != null) {
            l++;
            p = (ParseNode)p.getChild(1);
        }

        String[] pathList = new String[l];

        p = pathTree;
        while (p != null) {
            l--;
            pathList[l] = (String)p.getText();
            p = (ParseNode)p.getChild(1);
        }

        return pathList;
    }
View Full Code Here

    public static Expression createUnaryExpression(Rule rule, Bindings bindings, ParseNode exprTree, Type type)
            throws TypeException
    {
        // we expect ^(UNOP unary_oper expr)

        ParseNode child0 = (ParseNode) exprTree.getChild(0);
        ParseNode child1 = (ParseNode) exprTree.getChild(1);
        Expression expr;
        int tag = child0.getTag();

        switch (tag)
        {
            case TWIDDLE:
            {
                // the argument must be a numeric expression
                if (!type.isUndefined() && !type.isVoid() && !type.isNumeric()) {
                    throw new TypeException("ExpressionHelper.createUnaryExpression : invalid numeric expression" + exprTree.getPos());
                }
                Expression operand = createExpression(rule, bindings, child1, Type.NUMBER);
                expr = new TwiddleExpression(rule, exprTree, operand);
            }
            break;
            case NOT:
            {
                // the argument must be a boolean expression
                if (!type.isUndefined() && !type.isVoid() && !type.isBoolean()) {
                    throw new TypeException("ExpressionHelper.createUnaryExpression : invalid boolean expression" + exprTree.getPos());
                }
                Expression operand = createExpression(rule, bindings, child1, Type.BOOLEAN);
                expr = new NotExpression(rule, exprTree, operand);
            }
            break;
            case UMINUS:
            {
                // the argument must be a numeric expression
                if (!type.isUndefined() && !type.isVoid() && !type.isBoolean()) {
                    throw new TypeException("ExpressionHelper.createUnaryExpression : invalid boolean expression" + exprTree.getPos());
                }
                Expression operand = createExpression(rule, bindings, child1, Type.NUMBER);
                expr = new MinusExpression(rule, exprTree, operand);
            }
            break;
            case DOLLAR:
            {
                if (child1.getTag() == IDENTIFIER) {
                    if (child1.getText().equals("!")) {
                        expr = new DollarExpression(rule, type, exprTree, DollarExpression.RETURN_VALUE_IDX);
                    } else if (child1.getText().equals("^")) {
                        expr = new DollarExpression(rule, type, exprTree, DollarExpression.THROWABLE_VALUE_IDX);
                    } else if (child1.getText().equals("#")) {
                        expr = new DollarExpression(rule, Type.I, exprTree, DollarExpression.PARAM_COUNT_IDX);
                    } else if (child1.getText().equals("*")) {
                        expr = new DollarExpression(rule, rule.getTypeGroup().createArray(Type.OBJECT), exprTree, DollarExpression.PARAM_ARRAY_IDX);
                    } else if (child1.getText().equals("@")) {
                        expr = new DollarExpression(rule, rule.getTypeGroup().createArray(Type.OBJECT), exprTree, DollarExpression.INVOKE_PARAM_ARRAY_IDX);
                    } else {
                        expr = new DollarExpression(rule, type, exprTree, child1.getText());
                    }
                } else if (child1.getTag() == INTEGER_LITERAL) {
                    Integer intObject = (Integer) child1.getChild(0);
                    expr = new DollarExpression(rule, type, exprTree, intObject.intValue());
                } else {
                    throw new TypeException("ExpressionHelper.createUnaryExpression : unexpected token type " + child1.getTag() + " for dollar expression tree " + child1.getText() + "" + child1.getPos());
                }
            }
            break;
            default:
            {
View Full Code Here

        String fullText = "BIND\n" + text + "\nIF TRUE DO NOTHING";
        try {
            ECATokenLexer lexer = new ECATokenLexer(new StringReader(fullText));
            ECAGrammarParser parser = new ECAGrammarParser(lexer);
            Symbol event_parse = parser.parse();
            ParseNode eventTree = (ParseNode)event_parse.value;
            Event event = new Event(rule, eventTree);
            return event;
        } catch (Exception e) {
            throw new ParseException("org.jboss.byteman.rule.Event : error parsing event\n" + text, e);
        }
View Full Code Here

                int tag = eventTree.getTag();
                switch (tag) {
                    case COMMA:
                    {
                        // update before we risk an exception
                        ParseNode child0 = (ParseNode)eventTree.getChild(0);
                        eventTree = (ParseNode)eventTree.getChild(1);
                        addBinding(bindings, child0);
                    }
                    break;
                    case ASSIGN:
                    {
                        // update before we risk an exception
                        ParseNode saveTree = eventTree;
                        eventTree = null;
                        addBinding(bindings, saveTree);
                    }
                    break;
                    default:
View Full Code Here

        if (tag != ASSIGN) {
            String message = "Event.createBindings : unexpected token Type in binding " + tag + " for token " + bindingTree.getText() + bindingTree.getPos();
            throw new TypeException(message);
        }

        ParseNode varTree = (ParseNode)bindingTree.getChild(0);
        ParseNode exprTree = (ParseNode)bindingTree.getChild(1);
        Binding binding;

        binding = createBinding(varTree);

        // don't allow current binding to be used when parsing the expression
View Full Code Here

TOP

Related Classes of org.jboss.byteman.rule.grammar.ParseNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.