Search in sources :

Example 1 with UselessAbruptStmtRemover

use of soot.dava.toolkits.base.AST.transformations.UselessAbruptStmtRemover in project soot by Sable.

the class DavaBody method applyASTAnalyses.

private void applyASTAnalyses(ASTNode AST) {
    debug("applyASTAnalyses", "initial one time analyses started");
    /*
		 Nomair A. Naeem
		 Transformations on the AST
		 */
    // The BooleanConditionSimplification changes flag==false to just flag
    // AST.apply(new DepthFirstAdapter(true));
    AST.apply(new BooleanConditionSimplification());
    AST.apply(new DecrementIncrementStmtCreation());
    debug("applyASTAnalyses", "initial one time analyses completed");
    boolean flag = true;
    G.v().ASTTransformations_modified = false;
    G.v().ASTIfElseFlipped = false;
    int countFlipping = 0;
    if (flag) {
        // perform transformations on the AST
        do {
            debug("applyASTAnalyses", "ITERATION");
            G.v().ASTTransformations_modified = false;
            AST.apply(new AndAggregator());
            debug("applyASTAnalyses", "after AndAggregator" + G.v().ASTTransformations_modified);
            /*
				 The OrAggregatorOne internally calls UselessLabelFinder which sets the label to null
				 Always apply a UselessLabeledBlockRemover in the end to remove such labeled blocks
				 */
            AST.apply(new OrAggregatorOne());
            debug("applyASTAnalyses", "after OraggregatorOne" + G.v().ASTTransformations_modified);
            /*
				 Note OrAggregatorTwo should always be followed by an emptyElseRemover 
				 since orAggregatorTwo can create empty else bodies and the ASTIfElseNode 
				 can be replaced by ASTIfNodes
				 OrAggregator has two patterns see the class for them
				 */
            AST.apply(new OrAggregatorTwo());
            debug("applyASTAnalyses", "after OraggregatorTwo" + G.v().ASTTransformations_modified);
            debug("applyASTAnalyses", "after OraggregatorTwo ifElseFlipped is" + G.v().ASTIfElseFlipped);
            AST.apply(new OrAggregatorFour());
            debug("applyASTAnalyses", "after OraggregatorFour" + G.v().ASTTransformations_modified);
            /*
				 * ASTCleaner currently does the following tasks:
				 * 1, Remove empty Labeled Blocks UselessLabeledBlockRemover
				 * 2, convert ASTIfElseNodes with empty else bodies to ASTIfNodes
				 * 3, Apply OrAggregatorThree
				 */
            AST.apply(new ASTCleaner());
            debug("applyASTAnalyses", "after ASTCleaner" + G.v().ASTTransformations_modified);
            /*
				 * PushLabeledBlockIn should not be called unless we are sure
				 * that all labeledblocks have non null labels.
				 * A good way of ensuring this is to run the ASTCleaner directly
				 * before calling this
				 */
            AST.apply(new PushLabeledBlockIn());
            debug("applyASTAnalyses", "after PushLabeledBlockIn" + G.v().ASTTransformations_modified);
            AST.apply(new LoopStrengthener());
            debug("applyASTAnalyses", "after LoopStrengthener" + G.v().ASTTransformations_modified);
            /*
				 * Pattern two carried out in OrAggregatorTwo restricts some patterns in for loop creation.
				 * Pattern two was implemented to give loopStrengthening a better chance
				 * SEE IfElseBreaker
				 */
            AST.apply(new ASTCleanerTwo());
            debug("applyASTAnalyses", "after ASTCleanerTwo" + G.v().ASTTransformations_modified);
            AST.apply(new ForLoopCreator());
            debug("applyASTAnalyses", "after ForLoopCreator" + G.v().ASTTransformations_modified);
            AST.apply(new NewStringBufferSimplification());
            debug("applyASTAnalyses", "after NewStringBufferSimplification" + G.v().ASTTransformations_modified);
            AST.apply(new ShortcutArrayInit());
            debug("applyASTAnalyses", "after ShortcutArrayInit" + G.v().ASTTransformations_modified);
            AST.apply(new UselessLabeledBlockRemover());
            debug("applyASTAnalyses", "after UselessLabeledBlockRemover" + G.v().ASTTransformations_modified);
            if (!G.v().ASTTransformations_modified) {
                AST.apply(new IfElseSplitter());
                debug("applyASTAnalyses", "after IfElseSplitter" + G.v().ASTTransformations_modified);
            }
            if (!G.v().ASTTransformations_modified) {
                AST.apply(new UselessAbruptStmtRemover());
                debug("applyASTAnalyses", "after UselessAbruptStmtRemover" + G.v().ASTTransformations_modified);
            }
            AST.apply(new ShortcutIfGenerator());
            debug("applyASTAnalyses", "after ShortcutIfGenerator" + G.v().ASTTransformations_modified);
            AST.apply(new TypeCastingError());
            debug("applyASTAnalyses", "after TypeCastingError" + G.v().ASTTransformations_modified);
            /*
				 * if we matched some useful pattern we reserve the 
				 * right to flip conditions again
				 */
            if (G.v().ASTTransformations_modified) {
                G.v().ASTIfElseFlipped = false;
                countFlipping = 0;
                debug("applyASTanalyses", "Transformation modified was true hence will reiterate. set flipped to false");
            } else {
                // check if only the ifelse was flipped
                if (G.v().ASTIfElseFlipped) {
                    debug("", "ifelseflipped and transformations NOT modified");
                    // we couldnt transform but we did flip
                    if (countFlipping == 0) {
                        debug("", "ifelseflipped and transformations NOT modified count is 0");
                        // let this go on just once more in the hope of some other pattern being matched
                        G.v().ASTIfElseFlipped = false;
                        countFlipping++;
                        G.v().ASTTransformations_modified = true;
                    } else {
                        debug("", "ifelseflipped and transformations NOT modified count is not 0 TERMINATE");
                    }
                }
            }
        // if ASTTransformations was not modified
        } while (G.v().ASTTransformations_modified);
    // System.out.println("The AST trasnformations has run"+times);
    }
    /*
		 * ClosestAbruptTargetFinder should be reinitialized everytime there is a change to the AST
		 * This is utilized internally by the DavaFlowSet implementation to handle Abrupt Implicit Stmts
		 */
    AST.apply(ClosestAbruptTargetFinder.v());
    debug("applyASTAnalyses", "after ClosestAbruptTargetFinder" + G.v().ASTTransformations_modified);
    // 29th Jan 2006
    // make sure when recompiling there is no variable might not be initialized error
    Map<String, String> options = PhaseOptions.v().getPhaseOptions("db.force-recompile");
    boolean force = PhaseOptions.getBoolean(options, "enabled");
    if (force) {
        debug("applyASTAnalyses", "before FinalFieldDefinition" + G.v().ASTTransformations_modified);
        new FinalFieldDefinition((ASTMethodNode) AST);
        debug("applyASTAnalyses", "after FinalFieldDefinition" + G.v().ASTTransformations_modified);
    }
    // this analysis has to be after ShortcutArrayInit to give that analysis more chances
    AST.apply(new DeInliningFinalFields());
    debug("applyASTAnalyses", "end applyASTAnlayses" + G.v().ASTTransformations_modified);
}
Also used : TypeCastingError(soot.dava.toolkits.base.AST.transformations.TypeCastingError) DecrementIncrementStmtCreation(soot.dava.toolkits.base.AST.transformations.DecrementIncrementStmtCreation) LoopStrengthener(soot.dava.toolkits.base.AST.transformations.LoopStrengthener) ShortcutIfGenerator(soot.dava.toolkits.base.AST.transformations.ShortcutIfGenerator) PushLabeledBlockIn(soot.dava.toolkits.base.AST.transformations.PushLabeledBlockIn) OrAggregatorTwo(soot.dava.toolkits.base.AST.transformations.OrAggregatorTwo) DeInliningFinalFields(soot.dava.toolkits.base.AST.transformations.DeInliningFinalFields) BooleanConditionSimplification(soot.dava.toolkits.base.AST.transformations.BooleanConditionSimplification) NewStringBufferSimplification(soot.dava.toolkits.base.AST.transformations.NewStringBufferSimplification) IfElseSplitter(soot.dava.toolkits.base.AST.transformations.IfElseSplitter) AndAggregator(soot.dava.toolkits.base.AST.transformations.AndAggregator) OrAggregatorOne(soot.dava.toolkits.base.AST.transformations.OrAggregatorOne) ASTCleanerTwo(soot.dava.toolkits.base.AST.transformations.ASTCleanerTwo) FinalFieldDefinition(soot.dava.toolkits.base.AST.transformations.FinalFieldDefinition) ASTCleaner(soot.dava.toolkits.base.AST.transformations.ASTCleaner) UselessLabeledBlockRemover(soot.dava.toolkits.base.AST.transformations.UselessLabeledBlockRemover) OrAggregatorFour(soot.dava.toolkits.base.AST.transformations.OrAggregatorFour) ShortcutArrayInit(soot.dava.toolkits.base.AST.transformations.ShortcutArrayInit) UselessAbruptStmtRemover(soot.dava.toolkits.base.AST.transformations.UselessAbruptStmtRemover) ForLoopCreator(soot.dava.toolkits.base.AST.transformations.ForLoopCreator)

Aggregations

ASTCleaner (soot.dava.toolkits.base.AST.transformations.ASTCleaner)1 ASTCleanerTwo (soot.dava.toolkits.base.AST.transformations.ASTCleanerTwo)1 AndAggregator (soot.dava.toolkits.base.AST.transformations.AndAggregator)1 BooleanConditionSimplification (soot.dava.toolkits.base.AST.transformations.BooleanConditionSimplification)1 DeInliningFinalFields (soot.dava.toolkits.base.AST.transformations.DeInliningFinalFields)1 DecrementIncrementStmtCreation (soot.dava.toolkits.base.AST.transformations.DecrementIncrementStmtCreation)1 FinalFieldDefinition (soot.dava.toolkits.base.AST.transformations.FinalFieldDefinition)1 ForLoopCreator (soot.dava.toolkits.base.AST.transformations.ForLoopCreator)1 IfElseSplitter (soot.dava.toolkits.base.AST.transformations.IfElseSplitter)1 LoopStrengthener (soot.dava.toolkits.base.AST.transformations.LoopStrengthener)1 NewStringBufferSimplification (soot.dava.toolkits.base.AST.transformations.NewStringBufferSimplification)1 OrAggregatorFour (soot.dava.toolkits.base.AST.transformations.OrAggregatorFour)1 OrAggregatorOne (soot.dava.toolkits.base.AST.transformations.OrAggregatorOne)1 OrAggregatorTwo (soot.dava.toolkits.base.AST.transformations.OrAggregatorTwo)1 PushLabeledBlockIn (soot.dava.toolkits.base.AST.transformations.PushLabeledBlockIn)1 ShortcutArrayInit (soot.dava.toolkits.base.AST.transformations.ShortcutArrayInit)1 ShortcutIfGenerator (soot.dava.toolkits.base.AST.transformations.ShortcutIfGenerator)1 TypeCastingError (soot.dava.toolkits.base.AST.transformations.TypeCastingError)1 UselessAbruptStmtRemover (soot.dava.toolkits.base.AST.transformations.UselessAbruptStmtRemover)1 UselessLabeledBlockRemover (soot.dava.toolkits.base.AST.transformations.UselessLabeledBlockRemover)1