Inheritance: Statement
Esempio n. 1
0
 public void Visit(PyAst.ForStatement node)
 {
     AppendLineWithIndentation($"for {Visit(node.Left)} in {Visit(node.List)}:");
     using (new Indenter(this)) {
         Visit(node.Body);
     }
 }
 // ForStatement
 public override bool Walk(ForStatement node)
 {
     forAnalyzer.Analyze(node);
     return true;
 }
 // ForStatement
 public bool Walk(ForStatement node)
 {
     return Process(node);
 }
Esempio n. 4
0
        //for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
        private ForStatement ParseForStmt()
        {
            Eat(TokenKind.KeywordFor);
            Location start = GetStart();
            List<Expression> l = ParseExprList(); //TokenKind.KeywordIn);

            // expr list is something like:
            //  ()
            //  a
            //  a,b
            //  a,b,c
            // we either want just () or a or we want (a,b) and (a,b,c)
            // so we can do tupleExpr.EmitSet() or loneExpr.EmitSet()

            Expression lhs = MakeTupleOrExpr(l, false);
            Eat(TokenKind.KeywordIn);
            Expression list = ParseTestListAsExpr(false);
            Location header = GetEnd();
            Statement body = ParseSuite();
            Statement else_ = null;
            if (MaybeEat(TokenKind.KeywordElse)) {
                else_ = ParseSuite();
            }
            ForStatement ret = new ForStatement(lhs, list, body, else_);
            ret.Header = header;
            ret.SetLoc(GetExternal(), start, GetEnd());
            return ret;
        }
Esempio n. 5
0
        //for_stmt: 'for' target_list 'in' expression_list ':' suite ['else' ':' suite]
        private ForStatement ParseForStmt() {
            Eat(TokenKind.KeywordFor);
            var start = GetStart();

            bool trailingComma;
            List<Expression> l = ParseTargetList(out trailingComma);

            // expr list is something like:
            //  ()
            //  a
            //  a,b
            //  a,b,c
            // we either want just () or a or we want (a,b) and (a,b,c)
            // so we can do tupleExpr.EmitSet() or loneExpr.EmitSet()

            Expression lhs = MakeTupleOrExpr(l, trailingComma);
            Eat(TokenKind.KeywordIn);
            Expression list = ParseTestListAsExpr();
            var header = GetEnd();
            Statement body = ParseLoopSuite();
            Statement else_ = null;
            if (MaybeEat(TokenKind.KeywordElse)) {
                else_ = ParseSuite();
            }
            ForStatement ret = new ForStatement(lhs, list, body, else_);
            ret.HeaderIndex = header;
            ret.SetLoc(_globalParent, start, GetEnd());
            return ret;
        }
Esempio n. 6
0
 internal For(ForStatement stmt)
     : this() {
     _target = Convert(stmt.Left, Store.Instance);
     _iter = Convert(stmt.List);
     _body = ConvertStatements(stmt.Body);
     _orelse = ConvertStatements(stmt.Else, true);
 }
Esempio n. 7
0
 public override bool Walk(ForStatement node)
 {
     loopCount++;
     return true;
 }
Esempio n. 8
0
        public override void PostWalk(ForStatement node)
        {
            string elseSt = node.Else != null
                ? Content()
                : null;
            string body = Content();
            string list = Content();
            string variable = Content();

            string listVar = String.Format(LIST, variable);
            string cntVar = String.Format(COUNTER, variable);

            StringBuilder sb = new StringBuilder();
            sb.Append(Indent());
            sb.AppendFormat("var {0} = _.toArray({1});", listVar, list);
            sb.AppendLine();

            sb.Append(Indent());
            sb.AppendFormat("for (var {0} = 0; {0} < {1}.length; {0}++) {{",
                cntVar,
                listVar
            );
            sb.AppendLine();

            sb.Append(Indent(indent + 1));
            sb.AppendFormat("var {0} = {1}[{2}];", variable, listVar, cntVar);
            sb.AppendLine();
            sb.AppendLine();

            sb.AppendLine(body);

            if (elseSt != null)
            {
                sb.AppendLine();

                sb.Append(Indent(indent + 1));
                sb.AppendFormat("if ({0} == {1}.length - 1) {{", cntVar, listVar);
                sb.AppendLine();

                sb.AppendLine(elseSt);

                sb.Append(Indent(indent + 1));
                sb.AppendLine("}");
            }

            sb.Append(Indent());
            sb.AppendLine("}");

            Content(sb.ToString());

            CommonPostWalk(node, true);
        }
 public override bool Walk(ForStatement node)
 {
     Emit(node); return false;
 }
 public override bool Walk(ForStatement node)
 {
     return true;
 }
 public virtual void PostWalk(ForStatement node)
 {
 }
 // ForStatement
 public virtual bool Walk(ForStatement node)
 {
     return true;
 }
Esempio n. 13
0
 // ForStmt
 public override bool Walk(ForStatement node)
 {
     node.Left.Walk(define);
     // Add locals
     Debug.Assert(current != null);
     current.TempsCount += ForStatement.LocalSlots;
     return true;
 }
Esempio n. 14
0
        // Python 2.5 -> "for" expression_list "in" or_test
        private ForStatement ParseGenExprFor()
        {
            Location start = GetStart();
            Eat(TokenKind.KeywordFor);
            List<Expression> l = ParseExprList();
            Expression lhs = MakeTupleOrExpr(l, false);
            Eat(TokenKind.KeywordIn);

            Expression test = null;
            if (Options.Python25 == true) {
                test = ParseOrTest();
            } else {
                test = ParseTest();
            }

            ForStatement gef = new ForStatement(lhs, test, null, null);
            Location end = GetEnd();
            gef.SetLoc(GetExternal(), start, end);
            gef.Header = end;
            return gef;
        }
Esempio n. 15
0
 public void Analyze(ForStatement fs)
 {
     forStatement = fs;
     forStatement.Left.Walk(this);
 }
Esempio n. 16
0
        public override bool Walk(ForStatement node)
        {
            CommonWalk(node);

            return true;
        }
 public ForDefinition(ForStatement forStatement)
 {
     this.forStatement = forStatement;
 }
Esempio n. 18
0
 public override void PostWalk(ForStatement node)
 {
     loopCount--;
 }
Esempio n. 19
0
        // ForStmt
        public override bool Walk(ForStatement node) {
            // Walk the expression
            node.List.Walk(this);

            BitArray opte = new BitArray(_bits);
            BitArray exit = new BitArray(_bits.Length, true);
            PushLoop(exit);

            // Define the lhs
            node.Left.Walk(_fdef);
            // Walk the body
            node.Body.Walk(this);

            PopLoop();

            _bits.And(exit);

            if (node.Else != null) {
                // Flow the else
                BitArray save = _bits;
                _bits = opte;
                node.Else.Walk(this);
                // Restore the bits
                _bits = save;
            }

            // Intersect
            _bits.And(opte);

            return false;
        }
Esempio n. 20
0
        // ForEachStatement
        public override bool Walk(ForStatement node)
        {
            node.Parent = _currentScope;
            if (_currentScope is FunctionDefinition) {
                _currentScope.ShouldInterpret = false;
            }

            // we only push the loop for the body of the loop
            // so we need to walk the for statement ourselves
            node.Left.Walk(_define);

            if (node.Left != null) {
                node.Left.Walk(this);
            }
            if (node.List != null) {
                node.List.Walk(this);
            }

            PushLoop(node);

            if (node.Body != null) {
                node.Body.Walk(this);
            }

            PopLoop();

            if (node.Else != null) {
                node.Else.Walk(this);
            }

            return false;
        }
Esempio n. 21
0
 // ForEachStatement
 public override bool Walk(ForStatement node) {
     node.Left.Walk(_define);
     // Add locals
     return true;
 }
Esempio n. 22
0
 public override bool Walk(ForStatement node) {
     _iterators.Add(new ComprehensionFor(node.Left, node.List));
     node.Body.Walk(this);
     return false;
 }
Esempio n. 23
0
 internal override AstExpression Revert()
 {
     Statement stmt = new ExpressionStatement(new YieldExpression(expr.Revert(elt)));
     int comprehensionIdx = generators.Count - 1;
     AstExpression list;
     do {
         comprehension c = (comprehension)generators[comprehensionIdx];
         if (c.ifs != null && c.ifs.Count != 0) {
             int ifIdx = c.ifs.Count - 1;
             while (ifIdx >= 0) {
                 IfStatementTest ist = new IfStatementTest(expr.Revert(c.ifs[ifIdx]), stmt);
                 stmt = new IfStatement(new IfStatementTest[] { ist }, null);
                 ifIdx--;
             }
         }
         list = expr.Revert(c.iter);
         stmt = new ForStatement(expr.Revert(c.target), list, stmt, null);
         comprehensionIdx--;
     } while (comprehensionIdx >= 0);
     ((ForStatement)stmt).List = new NameExpression(generatorFnArgName);
     Parameter parameter = new Parameter(generatorFnArgName, 0);
     FunctionDefinition functionDefinition = new FunctionDefinition(generatorFnName, new Parameter[] { parameter }, stmt);
     functionDefinition.IsGenerator = true;
     return new GeneratorExpression(functionDefinition, list);
 }
Esempio n. 24
0
        // "for" target_list "in" or_test
        private ForStatement ParseGenExprFor() {
            var start = GetStart();
            Eat(TokenKind.KeywordFor);
            bool trailingComma;
            List<Expression> l = ParseTargetList(out trailingComma);
            Expression lhs = MakeTupleOrExpr(l, trailingComma);
            Eat(TokenKind.KeywordIn);

            Expression expr = null;
            expr = ParseOrTest();

            ForStatement gef = new ForStatement(lhs, expr, null, null);
            var end = GetEnd();
            gef.SetLoc(_globalParent, start, end);
            gef.HeaderIndex = end;
            return gef;
        }
 public void PostWalk(ForStatement node)
 {
     PostProcess(node);
 }