Exemple #1
0
        // if_stmt: 'if' expression ':' suite ('elif' expression ':' suite)* ['else' ':' suite]
        private IfStatement ParseIfStmt()
        {
            Eat(TokenKind.KeywordIf);
            var itemWhiteSpace = MakeWhiteSpaceList();
            if (itemWhiteSpace != null) {
                itemWhiteSpace.Add(_tokenWhiteSpace);
            }

            var start = GetStart();
            List<IfStatementTest> l = new List<IfStatementTest>();
            l.Add(ParseIfStmtTest());

            while (MaybeEat(TokenKind.KeywordElseIf)) {
                if (itemWhiteSpace != null) {
                    itemWhiteSpace.Add(_tokenWhiteSpace);
                }
                l.Add(ParseIfStmtTest());
            }

            Statement else_ = null;
            string elseWhiteSpace = null;
            if (MaybeEat(TokenKind.KeywordElse)) {
                elseWhiteSpace = _tokenWhiteSpace;
                else_ = ParseSuite();
            }

            IfStatementTest[] tests = l.ToArray();
            IfStatement ret = new IfStatement(tests, else_);
            if (_verbatim) {
                if(elseWhiteSpace != null) {
                    AddPreceedingWhiteSpace(ret, elseWhiteSpace);
                }
                if (itemWhiteSpace != null) {
                    AddListWhiteSpace(ret, itemWhiteSpace.ToArray());
                }
            }
            ret.SetLoc(start, else_ != null ? else_.EndIndex : tests[tests.Length - 1].EndIndex);
            return ret;
        }
Exemple #2
0
        // 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;
        }
Exemple #3
0
        public override bool Walk(IfStatement node)
        {
            UpdateChildRanges(node);
            if (node.Tests != null) {
                foreach (var test in node.Tests) {
                    var isInstanceNames = GetIsInstanceNamesAndExpressions(test.Test);
                    if (isInstanceNames != null) {
                        if (test.Test != null) {
                            test.Test.Walk(this);
                        }

                        if (test.Body != null && !(test.Body is ErrorStatement)) {
                            Debug.Assert(test.Body is SuiteStatement);

                            PushIsInstanceScope(test, isInstanceNames, (SuiteStatement)test.Body);

                            test.Body.Walk(this);
                        }
                    } else {
                        test.Walk(this);
                    }
                }
            }
            if (node.ElseStatement != null) {
                node.ElseStatement.Walk(this);
            }
            return false;
        }
Exemple #4
0
 // IfStatement
 public override bool Walk(IfStatement node)
 {
     return ShouldWalkWorker(node);
 }
Exemple #5
0
 public override void PostWalk(IfStatement node)
 {
     PostWalkWorker(node);
 }
Exemple #6
0
            public override bool Walk(IfStatement node)
            {
                bool allReturn = true;
                for (int i = 0; i < node.Tests.Count; i++) {
                    _raises = Returns = false;
                    node.Tests[i].Body.Walk(this);

                    allReturn &= Returns || _raises;
                }

                _raises = Returns = false;
                if (node.ElseStatement != null) {
                    node.ElseStatement.Walk(this);

                    allReturn &= Returns || _raises;
                } else {
                    allReturn = false;
                }

                Returns = allReturn;
                return false;
            }