Exemplo n.º 1
0
        private static IfHelper.IfNode BuildGraph(IfStatement stat, bool stsingle)
        {
            if (stat.iftype == IfStatement.Iftype_Ifelse)
            {
                return(null);
            }
            IfHelper.IfNode res = new IfHelper.IfNode(stat);
            // if branch
            Statement ifchild = stat.GetIfstat();

            if (ifchild == null)
            {
                StatEdge edge = stat.GetIfEdge();
                res.AddChild(new IfHelper.IfNode(edge.GetDestination()), 1);
            }
            else
            {
                IfHelper.IfNode ifnode = new IfHelper.IfNode(ifchild);
                res.AddChild(ifnode, 0);
                if (ifchild.type == Statement.Type_If && ((IfStatement)ifchild).iftype == IfStatement
                    .Iftype_If)
                {
                    IfStatement stat2    = (IfStatement)ifchild;
                    Statement   ifchild2 = stat2.GetIfstat();
                    if (ifchild2 == null)
                    {
                        StatEdge edge = stat2.GetIfEdge();
                        ifnode.AddChild(new IfHelper.IfNode(edge.GetDestination()), 1);
                    }
                    else
                    {
                        ifnode.AddChild(new IfHelper.IfNode(ifchild2), 0);
                    }
                }
                if (!(ifchild.GetAllSuccessorEdges().Count == 0))
                {
                    ifnode.AddChild(new IfHelper.IfNode(ifchild.GetAllSuccessorEdges()[0].GetDestination
                                                            ()), 1);
                }
            }
            // else branch
            StatEdge  edge_1    = stat.GetAllSuccessorEdges()[0];
            Statement elsechild = edge_1.GetDestination();

            IfHelper.IfNode elsenode = new IfHelper.IfNode(elsechild);
            if (stsingle || edge_1.GetType() != StatEdge.Type_Regular)
            {
                res.AddChild(elsenode, 1);
            }
            else
            {
                res.AddChild(elsenode, 0);
                if (elsechild.type == Statement.Type_If && ((IfStatement)elsechild).iftype == IfStatement
                    .Iftype_If)
                {
                    IfStatement stat2    = (IfStatement)elsechild;
                    Statement   ifchild2 = stat2.GetIfstat();
                    if (ifchild2 == null)
                    {
                        elsenode.AddChild(new IfHelper.IfNode(stat2.GetIfEdge().GetDestination()), 1);
                    }
                    else
                    {
                        elsenode.AddChild(new IfHelper.IfNode(ifchild2), 0);
                    }
                }
                if (!(elsechild.GetAllSuccessorEdges().Count == 0))
                {
                    elsenode.AddChild(new IfHelper.IfNode(elsechild.GetAllSuccessorEdges()[0].GetDestination
                                                              ()), 1);
                }
            }
            return(res);
        }