public Node VisitStatement(IfStatement stmt) { var newCode = stmt; var newTests = new List <IfStatementTest>(); foreach (var ifStatementTest in newCode.Tests) { var newTest = new IfStatementTest(VisitExpression(ifStatementTest.Test), VisitStatement(ifStatementTest.Body)); newTests.Add(newTest); } return(new IfStatement(newTests.ToArray(), VisitStatement(newCode.ElseStatement))); }
public static ConditionTestResult TryHandleBigLittleEndian(this IfStatementTest test, bool isLittleEndian) { if (test.Test is BinaryExpression cmp && cmp.Left is MemberExpression me && (me.Target as NameExpression)?.Name == "sys" && me.Name == "byteorder" && cmp.Right is ConstantExpression cex && cex.GetStringValue() is string s) { switch (cmp.Operator) { case PythonOperator.Equals when s == "little" && isLittleEndian: return(ConditionTestResult.WalkBody); case PythonOperator.Equals when s == "big" && !isLittleEndian: return(ConditionTestResult.WalkBody); case PythonOperator.NotEquals when s == "little" && !isLittleEndian: return(ConditionTestResult.WalkBody); case PythonOperator.NotEquals when s == "big" && isLittleEndian: return(ConditionTestResult.WalkBody); } return(ConditionTestResult.DontWalkBody); } return(ConditionTestResult.Unrecognized); }
public override void PostWalk(IfStatementTest node) { }
// IfStatementTest public override bool Walk(IfStatementTest node) { return false; }
public virtual void PostWalk(IfStatementTest node) { }
// IfStatementTest public virtual bool Walk(IfStatementTest node) { return true; }
protected internal virtual void PostWalk(IfStatementTest node) { }
// IfStatementTest protected internal virtual bool Walk(IfStatementTest node) { return true; }
public IfStatement(IfStatementTest[] tests, Statement else_) { _tests = tests; _else = else_; }
// IfStatementTest public override bool Walk(IfStatementTest node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
// IfStatementTest public override bool Walk(IfStatementTest node) { node.Parent = _currentScope; return base.Walk(node); }