Esempio n. 1
0
        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; }
Esempio n. 7
0
 protected internal virtual void PostWalk(IfStatementTest node) { }
Esempio n. 8
0
 // IfStatementTest
 protected internal virtual bool Walk(IfStatementTest node) { return true; }
Esempio n. 9
0
 public IfStatement(IfStatementTest[] tests, Statement else_) {
     _tests = tests;
     _else = else_;
 }
Esempio n. 10
0
 // 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);
 }