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