Пример #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);
        }
Пример #3
0
 public override void PostWalk(IfStatementTest node) { }
Пример #4
0
 // IfStatementTest
 public override bool Walk(IfStatementTest node) { return false; }
Пример #5
0
 public virtual void PostWalk(IfStatementTest node) { }
Пример #6
0
 // IfStatementTest
 public virtual bool Walk(IfStatementTest node) { return true; }
Пример #7
0
 protected internal virtual void PostWalk(IfStatementTest node) { }
Пример #8
0
 // IfStatementTest
 protected internal virtual bool Walk(IfStatementTest node) { return true; }
Пример #9
0
 public IfStatement(IfStatementTest[] tests, Statement else_) {
     _tests = tests;
     _else = else_;
 }
Пример #10
0
 // IfStatementTest
 public override bool Walk(IfStatementTest node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
Пример #11
0
 // IfStatementTest
 public override bool Walk(IfStatementTest node) {
     node.Parent = _currentScope;
     return base.Walk(node);
 }