public void Visit(PyAst.IfStatement node) { var isFirst = true; foreach (var ifTest in node.Tests) { AppendLineWithIndentation($"{(isFirst ? "if" : "elif")} {Visit(ifTest.Test)}:"); using (new Indenter(this)) { Visit(ifTest.Body); } isFirst = false; } if (node.ElseStatement != null) { AppendLineWithIndentation("else:"); using (new Indenter(this)) { Visit(node.ElseStatement); } } }
public override bool Walk(IfStatement node) { _iterators.Add(new ComprehensionIf(node.Tests[0].Test)); node.Tests[0].Body.Walk(this); return false; }
public override void PostWalk(IfStatement node) { string ifFalse = node.ElseStatement != null ? Content() : null; string ifTrue = Content(); string test = Content(); StringBuilder sb = new StringBuilder(); sb.Append(Indent()); sb.AppendFormat("if ({0}) {{", test); sb.AppendLine(); sb.AppendLine(ifTrue); sb.Append(Indent()); sb.Append("}"); if (!String.IsNullOrWhiteSpace(ifFalse)) { sb.AppendLine(); sb.Append(Indent()); sb.AppendFormat("else {{", test); sb.AppendLine(); sb.AppendLine(ifFalse); sb.Append(Indent()); sb.Append("}"); } Content(sb.ToString()); CommonPostWalk(node, true); }
public override bool Walk(IfStatement node) { CommonWalk(node); return true; }
// IfStatement public bool Walk(IfStatement node) { return Process(node); }
public void PostWalk(IfStatement node) { PostProcess(node); }
public override bool Walk(IfStatement node) { Emit(node); return false; }
// if_stmt: 'if' expression ':' suite ('elif' expression ':' suite)* ['else' ':' suite] private IfStatement ParseIfStmt() { Eat(TokenKind.KeywordIf); var start = GetStart(); List<IfStatementTest> l = new List<IfStatementTest>(); l.Add(ParseIfStmtTest()); while (MaybeEat(TokenKind.KeywordElseIf)) { l.Add(ParseIfStmtTest()); } Statement else_ = null; if (MaybeEat(TokenKind.KeywordElse)) { else_ = ParseSuite(); } IfStatementTest[] tests = l.ToArray(); IfStatement ret = new IfStatement(tests, else_); ret.SetLoc(_globalParent, start, GetEnd()); return ret; }
public virtual void PostWalk(IfStatement node) { }
public override bool Walk(IfStatement node) { return true; }
// IfStatement public virtual bool Walk(IfStatement node) { return true; }
public override bool Walk(IfStatement node) { node.Parent = _currentScope; return(base.Walk(node)); }
// 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; }
internal If(IfStatement stmt) : this() { If current = this; If parent = null; foreach (IfStatementTest ifTest in stmt.Tests) { if (parent != null) { current = new If(); parent._orelse = PythonOps.MakeListNoCopy(current); } current.Initialize(ifTest); parent = current; } current._orelse = ConvertStatements(stmt.ElseStatement, true); }
// IfStmt public override bool Walk(IfStatement node) { BitArray result = new BitArray(_bits.Length, true); BitArray save = _bits; _bits = new BitArray(_bits.Length); foreach (IfStatementTest ist in node.Tests) { // Set the initial branch value to bits _bits.SetAll(false); _bits.Or(save); // Flow the test first ist.Test.Walk(this); // Flow the body ist.Body.Walk(this); // Intersect result.And(_bits); } // Set the initial branch value to bits _bits.SetAll(false); _bits.Or(save); if (node.ElseStatement != null) { // Flow the else_ node.ElseStatement.Walk(this); } // Intersect result.And(_bits); _bits = save; // Remember the result _bits.SetAll(false); _bits.Or(result); return false; }
// 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; }
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); }
// 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 override bool Walk(IfStatement node) { writer.WriteLine("If"); return base.Walk(node); }