Exemple #1
0
        public static void RemoveRedundantReturns(RootStatement root)
        {
            DummyExitStatement dummyExit = root.GetDummyExit();

            foreach (StatEdge edge in dummyExit.GetAllPredecessorEdges())
            {
                if (!edge.@explicit)
                {
                    Statement      source  = edge.GetSource();
                    List <Exprent> lstExpr = source.GetExprents();
                    if (lstExpr != null && !(lstExpr.Count == 0))
                    {
                        Exprent expr = lstExpr[lstExpr.Count - 1];
                        if (expr.type == Exprent.Exprent_Exit)
                        {
                            ExitExprent ex = (ExitExprent)expr;
                            if (ex.GetExitType() == ExitExprent.Exit_Return && ex.GetValue() == null)
                            {
                                // remove redundant return
                                dummyExit.AddBytecodeOffsets(ex.bytecode);
                                lstExpr.RemoveAtReturningValue(lstExpr.Count - 1);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        private static void SetRetEdgesUnlabeled(RootStatement root)
        {
            Statement exit = root.GetDummyExit();

            foreach (StatEdge edge in exit.GetAllPredecessorEdges())
            {
                List <Exprent> lst = edge.GetSource().GetExprents();
                if (edge.GetType() == StatEdge.Type_Finallyexit || (lst != null && !(lst.Count == 0) &&
                                                                    lst[lst.Count - 1].type == Exprent.Exprent_Exit))
                {
                    edge.labeled = false;
                }
            }
        }
Exemple #3
0
        // statement.id, node.id(direct), node.id(continue)
        // node.id(source), statement.id(destination), edge type
        // node.id(exit), [node.id(source), statement.id(destination)]
        // node.id(exit), [node.id(source), statement.id(destination)]
        // positive if branches
        public virtual DirectGraph BuildDirectGraph(RootStatement root)
        {
            this.root = root;
            graph     = new DirectGraph();
            FlattenStatement();
            // dummy exit node
            Statement  dummyexit = root.GetDummyExit();
            DirectNode node      = new DirectNode(DirectNode.Node_Direct, dummyexit, dummyexit.id.
                                                  ToString());

            node.exprents = new List <Exprent>();
            graph.nodes.AddWithKey(node, node.id);
            Sharpen.Collections.Put(mapDestinationNodes, dummyexit.id, new string[] { node.id
                                                                                      , null });
            SetEdges();
            graph.first = graph.nodes.GetWithKey(mapDestinationNodes.GetOrNull(root.id)[0]);
            graph.SortReversePostOrder();
            return(graph);
        }