Example #1
0
            public override ControlFlowNode VisitIfElseStatement(IfElseStatement ifElseStatement, ControlFlowNode data)
            {
                bool?cond = builder.EvaluateCondition(ifElseStatement.Condition);

                ControlFlowNode trueBegin = builder.CreateStartNode(ifElseStatement.TrueStatement);

                if (cond != false)
                {
                    Connect(data, trueBegin, ControlFlowEdgeType.ConditionTrue);
                }
                ControlFlowNode trueEnd = ifElseStatement.TrueStatement.AcceptVisitor(this, trueBegin);

                ControlFlowNode falseBegin = builder.CreateStartNode(ifElseStatement.FalseStatement);

                if (cond != true)
                {
                    Connect(data, falseBegin, ControlFlowEdgeType.ConditionFalse);
                }
                ControlFlowNode falseEnd = ifElseStatement.FalseStatement.AcceptVisitor(this, falseBegin);
                // (if no else statement exists, both falseBegin and falseEnd will be null)

                ControlFlowNode end = builder.CreateEndNode(ifElseStatement);

                Connect(trueEnd, end);
                if (falseEnd != null)
                {
                    Connect(falseEnd, end);
                }
                else if (cond != true)
                {
                    Connect(data, end, ControlFlowEdgeType.ConditionFalse);
                }
                return(end);
            }
Example #2
0
            public override ControlFlowNode VisitIfElseStatement(IfElseStatement ifElseStatement, ControlFlowNode data)
            {
                bool?cond = ifElseStatement.Condition.IsNull ? true : builder.EvaluateCondition(ifElseStatement.Condition);

                if (ifElseStatement.TrueStatement.IsNull)
                {
                    return(data);
                }
                ControlFlowNode trueBegin;

                if (ifElseStatement.TrueStatement.IsNull)
                {
                    trueBegin = null;
                }
                else
                {
                    trueBegin = builder.CreateStartNode(ifElseStatement.TrueStatement);
                }
                if (cond != false && trueBegin != null)
                {
                    Connect(data, trueBegin, ControlFlowEdgeType.ConditionTrue);
                }
                ControlFlowNode trueEnd = trueBegin != null?ifElseStatement.TrueStatement.AcceptVisitor(this, trueBegin) : null;

                ControlFlowNode falseEnd;

                if (ifElseStatement.FalseStatement.IsNull)
                {
                    falseEnd = null;
                }
                else
                {
                    ControlFlowNode falseBegin = builder.CreateStartNode(ifElseStatement.FalseStatement);
                    if (cond != true)
                    {
                        Connect(data, falseBegin, ControlFlowEdgeType.ConditionFalse);
                    }
                    falseEnd = ifElseStatement.FalseStatement.AcceptVisitor(this, falseBegin);
                }
                ControlFlowNode end = builder.CreateEndNode(ifElseStatement);

                if (trueEnd != null)
                {
                    Connect(trueEnd, end);
                }
                if (falseEnd != null)
                {
                    Connect(falseEnd, end);
                }
                else if (cond != true)
                {
                    Connect(data, end, ControlFlowEdgeType.ConditionFalse);
                }
                return(end);
            }