コード例 #1
0
ファイル: TryFlowAnalyzer.cs プロジェクト: tylike/IronScheme
 protected internal override void PostWalk(SwitchStatement node)
 {
     _switch--;
 }
コード例 #2
0
 protected internal override bool Walk(SwitchStatement node) {
     _hasUnsupportedNodes = true;
     return false;
 }
コード例 #3
0
ファイル: FlowChecker.cs プロジェクト: robertlj/IronScheme
        // SwitchStatement
        protected internal override bool Walk(SwitchStatement node)
        {
            // The expression is evaluated always.
            // Then each case clause expression is evaluated until match is found.
            // Therefore, the effects of the case clause expressions accumulate.
            // Default clause is evaluated last (so all case clause expressions must
            // accumulate first)
            WalkNode(node.TestValue);

            // Flow all the cases, they all start with the same initial state
            int count;
            IList<SwitchCase> cases = node.Cases;
            if (cases != null && (count = cases.Count) > 0) {
                SwitchCase @default = null;
                // Save the initial state
                BitArray entry = _bits;
                // The state to progressively accumualte effects of the case clause expressions
                BitArray values = new BitArray(entry);
                // State to flow the case clause bodies.
                BitArray caseFlow = new BitArray(_bits.Length);
                // The state to accumulate results into
                BitArray result = new BitArray(_bits.Length, true);

                PushStatement(result);

                for (int i = 0; i < count; i++) {
                    if (cases[i].IsDefault) {
                        Debug.Assert(@default == null);

                        // postpone the default case
                        @default = cases[i];
                        continue;
                    }

                    // Set the state for the walking of the body
                    caseFlow.SetAll(false);
                    caseFlow.Or(values);

                    // Walk the body
                    _bits = caseFlow;
                    WalkNode(cases[i].Body);

                    // Accumulate the result into the overall case statement result.
                    result.And(caseFlow);
                }

                // Walk the default at the end.
                if (@default != null) {
                    // Initialize
                    caseFlow.SetAll(false);
                    caseFlow.Or(values);

                    // Walk the default body
                    _bits = caseFlow;
                    WalkNode(@default.Body);

                    // Accumulate.
                    result.And(caseFlow);

                    // If there's a default clause, exactly one case got executed.
                    // The final state is 'and' across all cases, stored in 'result'
                    entry.SetAll(false);
                    entry.Or(result);
                } else {
                    // In the absence of default clause, we may have executed case,
                    // but didn't have to, so the result is an 'and' between the cases
                    // and the initial state.
                    entry.And(result);
                }

                PopStatement();

                // Restore the original state.
                _bits = entry;
            }

            return false;
        }
コード例 #4
0
ファイル: TryFlowAnalyzer.cs プロジェクト: tylike/IronScheme
 protected internal override bool Walk(SwitchStatement node)
 {
     _switch++;
     return(true);
 }
コード例 #5
0
ファイル: FlowChecker.cs プロジェクト: JamesTryand/IronScheme
        // SwitchStatement
        protected internal override bool Walk(SwitchStatement node)
        {
            // The expression is evaluated always.
            // Then each case clause expression is evaluated until match is found.
            // Therefore, the effects of the case clause expressions accumulate.
            // Default clause is evaluated last (so all case clause expressions must
            // accumulate first)
            WalkNode(node.TestValue);

            // Flow all the cases, they all start with the same initial state
            int count;
            IList <SwitchCase> cases = node.Cases;

            if (cases != null && (count = cases.Count) > 0)
            {
                SwitchCase @default = null;
                // Save the initial state
                BitArray entry = _bits;
                // The state to progressively accumualte effects of the case clause expressions
                BitArray values = new BitArray(entry);
                // State to flow the case clause bodies.
                BitArray caseFlow = new BitArray(_bits.Length);
                // The state to accumulate results into
                BitArray result = new BitArray(_bits.Length, true);

                PushStatement(result);

                for (int i = 0; i < count; i++)
                {
                    if (cases[i].IsDefault)
                    {
                        Debug.Assert(@default == null);

                        // postpone the default case
                        @default = cases[i];
                        continue;
                    }

                    // Set the state for the walking of the body
                    caseFlow.SetAll(false);
                    caseFlow.Or(values);

                    // Walk the body
                    _bits = caseFlow;
                    WalkNode(cases[i].Body);

                    // Accumulate the result into the overall case statement result.
                    result.And(caseFlow);
                }

                // Walk the default at the end.
                if (@default != null)
                {
                    // Initialize
                    caseFlow.SetAll(false);
                    caseFlow.Or(values);

                    // Walk the default body
                    _bits = caseFlow;
                    WalkNode(@default.Body);

                    // Accumulate.
                    result.And(caseFlow);

                    // If there's a default clause, exactly one case got executed.
                    // The final state is 'and' across all cases, stored in 'result'
                    entry.SetAll(false);
                    entry.Or(result);
                }
                else
                {
                    // In the absence of default clause, we may have executed case,
                    // but didn't have to, so the result is an 'and' between the cases
                    // and the initial state.
                    entry.And(result);
                }

                PopStatement();

                // Restore the original state.
                _bits = entry;
            }

            return(false);
        }
コード例 #6
0
ファイル: Walker.cs プロジェクト: robertlj/IronScheme
 // SwitchStatement
 private void DefaultWalk(SwitchStatement node)
 {
     if (Walk(node)) {
         WalkNode(node.TestValue);
         foreach (SwitchCase sc in node.Cases) {
             WalkNode(sc.Body);
         }
     }
     PostWalk(node);
 }
コード例 #7
0
 protected internal override bool Walk(SwitchStatement node)
 {
     _switch++;
     return true;
 }
コード例 #8
0
 protected internal override void PostWalk(SwitchStatement node)
 {
     _switch--;
 }
コード例 #9
0
 protected internal override bool Walk(SwitchStatement node)
 {
     _hasUnsupportedNodes = true;
     return(false);
 }