Package org.python.pydev.parser.jython

Examples of org.python.pydev.parser.jython.SimpleNode


     * Opens a new scope and returns a node to be used in this scope. This same node will later be called
     * in {@link #closeNode(SimpleNode, int)} to have its scope closed (and at that time it may be changed
     * for a new node that represents the scope more accurately.
     */
    public final SimpleNode openNode(final int id) {
        SimpleNode ret;

        switch (id) {

            case JJTFILE_INPUT:
                ret = new Module(null);
                break;

            case JJTFALSE:
                ret = new Name("False", Name.Load, true);
                break;

            case JJTTRUE:
                ret = new Name("True", Name.Load, true);
                break;

            case JJTNONE:
                ret = new Name("None", Name.Load, true);
                break;

            case JJTNAME:
            case JJTDOTTED_NAME:
                //the actual name will be set during the parsing (token image) -- see Name construct
                ret = new Name(null, Name.Load, false);
                break;

            case JJTNUM://the actual number will be set during the parsing (token image) -- see Num construct
                ret = new Num(null, -1, null);
                break;

            case JJTSTRING:
            case JJTUNICODE:
            case JJTBINARY:
                //the actual number will be set during the parsing (token image) -- see Num construct
                ret = new Str(null, -1, false, false, false);
                break;

            case JJTFOR_STMT:
                ret = new For(null, null, null, null);
                break;

            case JJTEXEC_STMT:
                ret = new Exec(null, null, null);
                break;

            case JJTPASS_STMT:
                ret = new Pass();
                break;

            case JJTBREAK_STMT:
                ret = new Break();
                break;

            case JJTCONTINUE_STMT:
                ret = new Continue();
                break;

            case JJTBEGIN_DECORATOR:
                ret = new decoratorsType(null, null, null, null, null, false);
                break;

            case JJTIF_STMT:
                ret = new If(null, null, null);
                break;

            case JJTAUG_PLUS:
                ret = new AugAssign(null, AugAssign.Add, null);
                break;
            case JJTAUG_MINUS:
                ret = new AugAssign(null, AugAssign.Sub, null);
                break;
            case JJTAUG_MULTIPLY:
                ret = new AugAssign(null, AugAssign.Mult, null);
                break;
            case JJTAUG_DIVIDE:
                ret = new AugAssign(null, AugAssign.Div, null);
                break;
            case JJTAUG_MODULO:
                ret = new AugAssign(null, AugAssign.Mod, null);
                break;
            case JJTAUG_AND:
                ret = new AugAssign(null, AugAssign.BitAnd, null);
                break;
            case JJTAUG_OR:
                ret = new AugAssign(null, AugAssign.BitOr, null);
                break;
            case JJTAUG_XOR:
                ret = new AugAssign(null, AugAssign.BitXor, null);
                break;
            case JJTAUG_LSHIFT:
                ret = new AugAssign(null, AugAssign.LShift, null);
                break;
            case JJTAUG_RSHIFT:
                ret = new AugAssign(null, AugAssign.RShift, null);
                break;
            case JJTAUG_POWER:
                ret = new AugAssign(null, AugAssign.Pow, null);
                break;
            case JJTAUG_FLOORDIVIDE:
                ret = new AugAssign(null, AugAssign.FloorDiv, null);
                break;

            case JJTOR_2OP:
                ret = new BinOp(null, BinOp.BitOr, null);
                break;
            case JJTXOR_2OP:
                ret = new BinOp(null, BinOp.BitXor, null);
                break;
            case JJTAND_2OP:
                ret = new BinOp(null, BinOp.BitAnd, null);
                break;
            case JJTLSHIFT_2OP:
                ret = new BinOp(null, BinOp.LShift, null);
                break;
            case JJTRSHIFT_2OP:
                ret = new BinOp(null, BinOp.RShift, null);
                break;
            case JJTADD_2OP:
                ret = new BinOp(null, BinOp.Add, null);
                break;
            case JJTSUB_2OP:
                ret = new BinOp(null, BinOp.Sub, null);
                break;
            case JJTMUL_2OP:
                ret = new BinOp(null, BinOp.Mult, null);
                break;
            case JJTDIV_2OP:
                ret = new BinOp(null, BinOp.Div, null);
                break;
            case JJTMOD_2OP:
                ret = new BinOp(null, BinOp.Mod, null);
                break;
            case JJTPOW_2OP:
                ret = new BinOp(null, BinOp.Pow, null);
                break;
            case JJTFLOORDIV_2OP:
                ret = new BinOp(null, BinOp.FloorDiv, null);
                break;

            case JJTPOS_1OP:
                ret = new UnaryOp(UnaryOp.UAdd, null);
                break;
            case JJTNEG_1OP:
                ret = new UnaryOp(UnaryOp.USub, null);
                break;
            case JJTINVERT_1OP:
                ret = new UnaryOp(UnaryOp.Invert, null);
                break;
            case JJTNOT_1OP:
                ret = new UnaryOp(UnaryOp.Not, null);
                break;

            case JJTIMPORT:
                ret = new Import(null);
                break;
            case JJTDOT_OP:
                ret = new Attribute(null, null, Attribute.Load);
                break;
            case JJTSTAR_EXPR:
                ret = new Starred(null, Starred.Store);
                break;

            default:
                ret = new IdentityNode(id);
                break;
        }
        ret.setId(id);
        lastOpened = ret;
        return ret;
    }
View Full Code Here


                return n; //it's already the correct node (and it's value is already properly set)

            case JJTSUITE:
                stmtType[] stmts = new stmtType[arity];
                for (int i = arity - 1; i >= 0; i--) {
                    SimpleNode yield_or_stmt = stack.popNode();
                    if (yield_or_stmt instanceof Yield) {
                        stmts[i] = new Expr((Yield) yield_or_stmt);

                    } else {
                        try {
                            stmts[i] = (stmtType) yield_or_stmt;
                        } catch (ClassCastException e) {
                            recoverFromClassCastException(yield_or_stmt, e);
                            stmts[i] = new Pass(); //recover from it with a valid node!
                        }
                    }
                }
                return new Suite(stmts);

            case JJTFOR_STMT:
                orelseSuite = null;
                if (stack.nodeArity() == 5) {
                    orelseSuite = popSuiteAndSuiteType();
                }

                body = popSuite();
                iter = (exprType) stack.popNode();
                target = (exprType) stack.popNode();
                ctx.setStore(target);

                For forStmt = (For) n;
                forStmt.target = target;
                forStmt.iter = iter;
                forStmt.body = body;
                forStmt.orelse = orelseSuite;
                return forStmt;

            case JJTBEGIN_ELIF_STMT:
                return new If(null, null, null);

            case JJTIF_STMT:
                return handleIfConstruct(n, arity);

            case JJTEXEC_STMT:
                exprType locals = arity >= 3 ? ((exprType) stack.popNode()) : null;
                exprType globals = arity >= 2 ? ((exprType) stack.popNode()) : null;
                value = (exprType) stack.popNode();
                Exec exec = (Exec) n;
                exec.body = value;
                exec.locals = locals;
                exec.globals = globals;
                return exec;

            case JJTDECORATORS:
                ArrayList<SimpleNode> list2 = new ArrayList<SimpleNode>();
                ArrayList<SimpleNode> listArgs = new ArrayList<SimpleNode>();
                while (stack.nodeArity() > 0) {
                    SimpleNode node = stack.popNode();
                    while (!(node instanceof decoratorsType)) {
                        if (node instanceof comprehensionType) {
                            listArgs.add(node);
                            listArgs.add(stack.popNode()); //target
                        } else if (node instanceof ComprehensionCollection) {
                            listArgs.add(((ComprehensionCollection) node).getGenerators()[0]);
                            listArgs.add(stack.popNode()); //target

                        } else {
                            listArgs.add(node);
                        }
                        node = stack.popNode();
                    }
                    listArgs.add(node);//the decoratorsType
                    list2.add(0, makeDecorator(listArgs));
                    listArgs.clear();
                }
                return new Decorators((decoratorsType[]) list2.toArray(new decoratorsType[0]), JJTDECORATORS);

            case JJTSUBSCRIPTLIST:
                sliceType[] dims = new sliceType[arity];
                for (int i = arity - 1; i >= 0; i--) {
                    SimpleNode sliceNode = stack.popNode();
                    if (sliceNode instanceof sliceType) {
                        dims[i] = (sliceType) sliceNode;

                    } else if (sliceNode instanceof IdentityNode) {
                        //this should be ignored...
                        //this happens when parsing something like a[1,], whereas a[1,2] would not have this.

                    } else {
                        throw new RuntimeException("Expected a sliceType or an IdentityNode. Received :"
                                + sliceNode.getClass());
                    }
                }
                return new ExtSlice(dims);

            case JJTAUG_PLUS:
            case JJTAUG_MINUS:
            case JJTAUG_MULTIPLY:
            case JJTAUG_DIVIDE:
            case JJTAUG_MODULO:
            case JJTAUG_AND:
            case JJTAUG_OR:
            case JJTAUG_XOR:
            case JJTAUG_LSHIFT:
            case JJTAUG_RSHIFT:
            case JJTAUG_POWER:
            case JJTAUG_FLOORDIVIDE:
                AugAssign augAssign = (AugAssign) n;
                exprType value1 = (exprType) stack.popNode();
                exprType target1 = (exprType) stack.popNode();
                ctx.setAugStore(target1);
                augAssign.target = target1;
                augAssign.value = value1;
                return n;

            case JJTOR_BOOLEAN:
                return new BoolOp(BoolOp.Or, makeExprs());
            case JJTAND_BOOLEAN:
                return new BoolOp(BoolOp.And, makeExprs());
            case JJTCOMPARISION:
                if (arity <= 2) {
                    throw new ParseException("Internal error: To make a compare, at least 3 nodes are needed.", n);
                }
                int l = arity / 2;
                exprType[] comparators = new exprType[l];
                int[] ops = new int[l];
                for (int i = l - 1; i >= 0; i--) {
                    comparators[i] = (exprType) stack.popNode();
                    SimpleNode op = stack.popNode();
                    switch (op.getId()) {
                        case JJTLESS_CMP:
                            ops[i] = Compare.Lt;
                            break;
                        case JJTGREATER_CMP:
                            ops[i] = Compare.Gt;
                            break;
                        case JJTEQUAL_CMP:
                            ops[i] = Compare.Eq;
                            break;
                        case JJTGREATER_EQUAL_CMP:
                            ops[i] = Compare.GtE;
                            break;
                        case JJTLESS_EQUAL_CMP:
                            ops[i] = Compare.LtE;
                            break;
                        case JJTNOTEQUAL_CMP:
                            ops[i] = Compare.NotEq;
                            break;
                        case JJTIN_CMP:
                            ops[i] = Compare.In;
                            break;
                        case JJTNOT_IN_CMP:
                            ops[i] = Compare.NotIn;
                            break;
                        case JJTIS_NOT_CMP:
                            ops[i] = Compare.IsNot;
                            break;
                        case JJTIS_CMP:
                            ops[i] = Compare.Is;
                            break;
                        default:
                            throw new RuntimeException("Unknown cmp op:" + op.getId());
                    }
                }
                return new Compare(((exprType) stack.popNode()), ops, comparators);
            case JJTLESS_CMP:
            case JJTGREATER_CMP:
View Full Code Here

            col = new ComprehensionCollection();
        }

        ArrayList<exprType> ifs = new ArrayList<exprType>();
        for (int i = arity - 3; i >= 0; i--) {
            SimpleNode ifsNode = stack.popNode();
            ifs.add((exprType) ifsNode);
        }
        exprType iter = (exprType) stack.popNode();
        exprType target = (exprType) stack.popNode();
        ctx.setStore(target);
View Full Code Here

    protected final SimpleNode makeDictionaryOrSet(int arity) {
        if (arity == 0) {
            return new Dict(new exprType[0], new exprType[0]);
        }

        SimpleNode dictNode0 = stack.popNode();

        if (dictNode0 instanceof Set) {
            Set set = (Set) dictNode0;
            exprType[] elts = new exprType[arity - 1]; //-1 because the set was already taken from there
            for (int i = arity - 2; i >= 0; i--) { //same thing here
                elts[i] = (exprType) stack.popNode();
            }
            set.elts = elts;
            return set;
        }

        if (dictNode0 instanceof ComprehensionCollection) {
            if (arity == 2) {
                ComprehensionCollection comp = (ComprehensionCollection) dictNode0;
                return new SetComp((exprType) stack.popNode(), comp.getGenerators());

            } else if (arity == 3) {
                SimpleNode dictNode1 = stack.popNode(); //we must inverse things here...
                ComprehensionCollection comp = (ComprehensionCollection) dictNode0;
                return new DictComp((exprType) stack.popNode(), (exprType) dictNode1, comp.getGenerators());
            }
        }
View Full Code Here

    private void deduceParameters(List<SimpleAdapter> before, List<SimpleAdapter> selected) {
        Set<String> globalVariableNames = new HashSet<String>(moduleAdapter.getGlobalVariableNames());

        for (SimpleAdapter adapter : before) {
            SimpleNode astNode = adapter.getASTNode();
            String id;
            if (astNode instanceof Name) {
                Name variable = (Name) astNode;
                id = variable.id;
            } else if (astNode instanceof NameTok) {
View Full Code Here

        }
    }

    private void deduceReturns(List<SimpleAdapter> after, List<SimpleAdapter> selected) {
        for (SimpleAdapter adapter : after) {
            SimpleNode astNode = adapter.getASTNode();
            String id;
            if (astNode instanceof Name) {
                Name variable = (Name) astNode;
                id = variable.id;
            } else if (astNode instanceof NameTok) {
View Full Code Here

    /**
     * Fix (fabioz): to check if it is used, it must be in a load context
     */
    private boolean isUsed(String var, List<SimpleAdapter> scopeVariables) {
        for (SimpleAdapter adapter : scopeVariables) {
            SimpleNode astNode = adapter.getASTNode();
            if (astNode instanceof Name) {
                Name scopeVar = (Name) astNode;
                if ((scopeVar.ctx == Name.Load || scopeVar.ctx == Name.AugLoad) && scopeVar.id.equals(var)) {
                    return true;
                }
View Full Code Here

    private boolean isStored(String var, List<SimpleAdapter> scopeVariables) {
        boolean isStored = false;
        // must traverse all variables, because a
        // variable may be used in other context!
        for (SimpleAdapter adapter : scopeVariables) {
            SimpleNode astNode = adapter.getASTNode();
            if (astNode instanceof Name) {
                Name scopeVar = (Name) astNode;
                if (scopeVar.id.equals(var)) {
                    isStored = (scopeVar.ctx != Name.Load && scopeVar.ctx != Name.AugLoad);
                }
View Full Code Here

    }

    protected final void addSpecialToArgDef(Object str) {
        Token token = (Token) str;
        SimpleNode peeked = jjtree.peekNode();
        if (peeked instanceof JfpDef) {
            JfpDef jfpdef = (JfpDef) peeked;
            if (jfpdef.typeDef != null) {
                jfpdef.typeDef.getSpecialsAfter().add(token.asSpecialStr());
            } else {
                jfpdef.nameNode.getSpecialsAfter().add(token.asSpecialStr());
            }
        } else if (peeked != null) {
            peeked.getSpecialsAfter().add(token.asSpecialStr());
        }

    }
View Full Code Here

    }

    //file_input: (NEWLINE | stmt)* ENDMARKER
    final public modType file_input() throws ParseException {
        /*@bgen(jjtree) file_input */
        SimpleNode jjtn000 = builder.openNode(JJTFILE_INPUT);
        boolean jjtc000 = true;
        jjtree.openNodeScope(jjtn000);
        jjtreeOpenNodeScope(jjtn000);
        try {
            label_1: while (true) {
View Full Code Here

TOP

Related Classes of org.python.pydev.parser.jython.SimpleNode

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.