private MSAst.Expression ReduceWorker(bool optimizeDynamicConvert) { MSAst.Expression result; if (_else != null) { result = _else; } else { result = AstUtils.Empty(); } // Now build from the inside out int i = _tests.Length; while (i-- > 0) { IfStatementTest ist = _tests[i]; result = GlobalParent.AddDebugInfoAndVoid( Ast.Condition( optimizeDynamicConvert ? TransformAndDynamicConvert(ist.Test, typeof(bool)) : GlobalParent.Convert(typeof(bool), Microsoft.Scripting.Actions.ConversionResultKind.ExplicitCast, ist.Test), TransformMaybeSingleLineSuite(ist.Body, ist.Test.Start), result ), new SourceSpan(ist.Start, ist.Header) ); } return(result); }
public IfStatement(IfStatementTest[] tests, Statement else_) { this.tests = tests; this.elseStmt = else_; }
// IfStatementTest public override bool Walk(IfStatementTest node) { node.Parent = _currentScope; return(base.Walk(node)); }
public override void PostWalk(IfStatementTest node) { CommonPostWalk(node); }
public override bool Walk(IfStatementTest node) { CommonWalk(node); return true; }
// Python 2.5 -> genexpr_if ::= "if" old_test private IfStatement ParseGenExprIf() { Location start = GetStart(); Eat(TokenKind.KeywordIf); Expression test = ParseOldTest(); IfStatementTest ist = new IfStatementTest(test, null); Location end = GetEnd(); ist.Header = end; ist.SetLoc(GetExternal(), start, end); IfStatement gei = new IfStatement(new IfStatementTest[] { ist }, null); gei.SetLoc(GetExternal(), start, end); return gei; }
private IfStatementTest ParseIfStmtTest() { var start = GetStart(); Expression expr = ParseExpression(); var header = GetEnd(); Statement suite = ParseSuite(); IfStatementTest ret = new IfStatementTest(expr, suite); ret.SetLoc(_globalParent, start, suite.EndIndex); ret.HeaderIndex = header; return ret; }
private IfStatementTest ParseIfStmtTest() { SourceLocation start = GetStart(); Expression expr = ParseExpression(); SourceLocation header = GetEnd(); Statement suite = ParseSuite(); IfStatementTest ret = new IfStatementTest(expr, suite); ret.SetLoc(start, suite.End); ret.Header = header; return ret; }
private MSAst.Expression ReduceWorker(bool optimizeDynamicConvert) { MSAst.Expression result; if (_tests.Length > 100) { // generate: // if(x) { // body // goto end // } else { // } // elseBody // end: // // to avoid deeply recursive trees which can stack overflow. var builder = new ReadOnlyCollectionBuilder <MSAst.Expression>(); var label = Ast.Label(); for (int i = 0; i < _tests.Length; i++) { IfStatementTest ist = _tests[i]; builder.Add( Ast.Condition( optimizeDynamicConvert ? TransformAndDynamicConvert(ist.Test, typeof(bool)) : GlobalParent.Convert(typeof(bool), Microsoft.Scripting.Actions.ConversionResultKind.ExplicitCast, ist.Test), Ast.Block( TransformMaybeSingleLineSuite(ist.Body, ist.Test.Start), Ast.Goto(label) ), AstUtils.Empty() ) ); } if (_else != null) { builder.Add(_else); } builder.Add(Ast.Label(label)); result = Ast.Block(builder); } else { // Now build from the inside out if (_else != null) { result = _else; } else { result = AstUtils.Empty(); } int i = _tests.Length; while (i-- > 0) { IfStatementTest ist = _tests[i]; result = GlobalParent.AddDebugInfoAndVoid( Ast.Condition( optimizeDynamicConvert ? TransformAndDynamicConvert(ist.Test, typeof(bool)) : GlobalParent.Convert(typeof(bool), Microsoft.Scripting.Actions.ConversionResultKind.ExplicitCast, ist.Test), TransformMaybeSingleLineSuite(ist.Body, ist.Test.Start), result ), new SourceSpan(ist.Start, ist.Header) ); } } return(result); }
public static string Format(IfStatementTest node) { return("if " + Format(node.Test) + ":" + Environment.NewLine + Format(node.Body)); }
public virtual void PostWalk(IfStatementTest node) { }
// IfStatementTest public virtual bool Walk(IfStatementTest node) { return true; }
private IfStatementTest ParseIfStmtTest() { Location start = GetStart(); Expression test = ParseTest(); Location header = GetEnd(); Statement suite = ParseSuite(); IfStatementTest ret = new IfStatementTest(test, suite); ret.SetLoc(GetExternal(), start, suite.End); ret.Header = header; return ret; }
public IfStatement(IfStatementTest[] tests, Statement else_) { _tests = tests; _else = else_; }
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); }
internal void Initialize(IfStatementTest ifTest) { _test = Convert(ifTest.Test); _body = ConvertStatements(ifTest.Body); }
public void PostWalk(IfStatementTest node) { PostProcess(node); }
// genexpr_if: "if" old_test private IfStatement ParseGenExprIf() { SourceLocation start = GetStart(); Eat(TokenKind.KeywordIf); Expression expr = ParseOldExpression(); IfStatementTest ist = new IfStatementTest(expr, null); SourceLocation end = GetEnd(); ist.Header = end; ist.SetLoc(start, end); IfStatement gei = new IfStatement(new IfStatementTest[] { ist }, null); gei.SetLoc(start, end); return gei; }
// IfStatementTest public bool Walk(IfStatementTest node) { return Process(node); }
// genexpr_if: "if" old_test private IfStatement ParseGenExprIf() { var start = GetStart(); Eat(TokenKind.KeywordIf); Expression expr = ParseOldExpression(); IfStatementTest ist = new IfStatementTest(expr, null); var end = GetEnd(); ist.HeaderIndex = end; ist.SetLoc(_globalParent, start, end); IfStatement gei = new IfStatement(new IfStatementTest[] { ist }, null); gei.SetLoc(_globalParent, start, end); return gei; }
public void Visit(PyAst.IfStatementTest node) => throw CreateNotImplementedEx();