コード例 #1
0
            public override void AddYieldTarget(YieldStatement ys, YieldTarget yt, CodeGen cg)
            {
                switch (state) {
                    case State.Try:
                        if (isPython24TryFinallyStmt)
                            cg.Context.AddError("cannot yield from try block with finally", ys);
                        else
                            stmt.AddTryYieldTarget(yt.FixForTryCatchFinally(cg));
                        break;
                    case State.Handler:
                        stmt.AddCatchYieldTarget(yt.FixForTryCatchFinally(cg));
                        break;
                    case State.Finally:
                        stmt.AddFinallyYieldTarget(yt.FixForTryCatchFinally(cg));
                        break;
                    case State.Else:
                        stmt.AddElseYieldTarget(yt.FixForTryCatchFinally(cg));
                        break;

                }
                ys.Label = yt.YieldContinuationTarget;
            }
コード例 #2
0
 public override void AddYieldTarget(YieldStatement ys, YieldTarget yt, CodeGen cg)
 {
     stmt.AddYieldTarget(yt.FixForTryCatchFinally(cg));
     ys.Label = yt.YieldContinuationTarget;
 }
コード例 #3
0
        public override void PostWalk(YieldStatement node)
        {
            topYields[node.Index] = new YieldTarget(cg.DefineLabel());

            if (tryBlocks.Count == 0) {
                node.Label = topYields[node.Index].TopBranchTarget;
            } else if (tryBlocks.Count == 1) {
                ExceptionBlock eb = tryBlocks.Peek();
                eb.AddYieldTarget(node, topYields[node.Index], cg);
            } else {
                bool isYieldInNestedWith = false;
                foreach (ExceptionBlock e in tryBlocks) {
                    if (e is WithBlock)
                        isYieldInNestedWith = true;
                }

                if (Options.Python25 && isYieldInNestedWith)
                    cg.Context.AddError("yield in nested Try and/or With blocks", node);
                else
                    cg.Context.AddError("yield in more than one try blocks", node);
            }
        }
コード例 #4
0
 public abstract void AddYieldTarget(YieldStatement ys, YieldTarget yt, CodeGen cg);
コード例 #5
0
 public void PostWalk(YieldStatement node)
 {
     PostProcess(node);
 }
コード例 #6
0
 // YieldStatement
 public bool Walk(YieldStatement node)
 {
     return Process(node);
 }
コード例 #7
0
 public override bool Walk(YieldStatement node)
 {
     Emit(node); return false;
 }
コード例 #8
0
 public virtual void PostWalk(YieldStatement node)
 {
 }
コード例 #9
0
 // YieldStatement
 public virtual bool Walk(YieldStatement node)
 {
     return true;
 }
コード例 #10
0
ファイル: Parser.cs プロジェクト: FabioNascimento/DICommander
 private Statement ParseYieldStmt()
 {
     NextToken();
     Location start = GetStart();
     FunctionDefinition current = CurrentFunction;
     int yieldId = 0;
     if (current == null) {
         ReportSyntaxError("'yield' outside function");
     } else {
         yieldId = current.YieldCount++;
     }
     Expression e = ParseTestListAsExpr(false);
     YieldStatement ret = new YieldStatement(e, yieldId);
     ret.SetLoc(GetExternal(), start, GetEnd());
     return ret;
 }
コード例 #11
0
ファイル: Parser.cs プロジェクト: FabioNascimento/DICommander
        private Expression ParseGeneratorExpression(Expression test)
        {
            ForStatement root = ParseGenExprFor();
            Statement current = root;

            for (; ; ) {
                if (PeekToken(Tokens.KeywordForToken)) {
                    current = NestGenExpr(current, ParseGenExprFor());
                } else if (PeekToken(Tokens.KeywordIfToken)) {
                    current = NestGenExpr(current, ParseGenExprIf());
                } else {
                    YieldStatement ys = new YieldStatement(test, 0);
                    ys.SetLoc(GetExternal(), test.Start, test.End);
                    NestGenExpr(current, ys);
                    break;
                }
            }

            SymbolId fname = SymbolTable.StringToId("__gen_" + System.Threading.Interlocked.Increment(ref genexp_counter));
            NameExpression pname = new NameExpression(SymbolTable.GeneratorParmName);
            FunctionDefinition func = new FunctionDefinition(fname, new Expression[] { pname }, new Expression[] { }, FunctionAttributes.None, root, context.SourceFile);
            func.YieldCount = 1;
            func.SetLoc(GetExternal(), root.Start, GetEnd());
            func.Header = root.End;

            //  Transform the root "for" statement
            Expression outermost = root.List;
            root.List = pname;

            CallExpression gexp = FinishCallExpr(new NameExpression(fname), new Arg(outermost));
            CallExpression iter = FinishCallExpr(new NameExpression(SymbolTable.Iter), new Arg(gexp));

            GeneratorExpression ret = new GeneratorExpression(func, iter);
            ret.SetLoc(GetExternal(), root.Start, GetEnd());
            return ret;
        }