soot.dava.toolkits.base.AST.transformations.UselessLabeledBlockRemover Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of soot Show documentation
Show all versions of soot Show documentation
A Java Optimization Framework
package soot.dava.toolkits.base.AST.transformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2005 Nomair A. Naeem
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import soot.G;
import soot.dava.internal.AST.ASTDoWhileNode;
import soot.dava.internal.AST.ASTForLoopNode;
import soot.dava.internal.AST.ASTIfElseNode;
import soot.dava.internal.AST.ASTIfNode;
import soot.dava.internal.AST.ASTLabeledBlockNode;
import soot.dava.internal.AST.ASTMethodNode;
import soot.dava.internal.AST.ASTNode;
import soot.dava.internal.AST.ASTSwitchNode;
import soot.dava.internal.AST.ASTSynchronizedBlockNode;
import soot.dava.internal.AST.ASTTryNode;
import soot.dava.internal.AST.ASTUnconditionalLoopNode;
import soot.dava.internal.AST.ASTWhileNode;
import soot.dava.internal.SET.SETNodeLabel;
import soot.dava.toolkits.base.AST.analysis.DepthFirstAdapter;
/*
* CHANGE LOG:
* Nomair A Naeem
* 17th April 2006
* The class was implemented all wrong since the case methods were being overriddern and hence
* the analysis was nto going into all children.
*
* changed this by overridding out methods instead of case
*
*
* Class serves two purposes.
* If you know there is a useless labeled block then its static methods can be invoked
* as done by the ASTCleaner
*
* It can also be used to apply the UselessLabelFinder to all nodes of the AST
* if that is done then make sure to set the ASTAnalysisModified
*/
public class UselessLabeledBlockRemover extends DepthFirstAdapter {
boolean changed = false;
public UselessLabeledBlockRemover() {
}
public UselessLabeledBlockRemover(boolean verbose) {
super(verbose);
}
public void outASTMethodNode(ASTMethodNode node) {
if (changed) {
G.v().ASTTransformations_modified = true;
}
}
public void inASTMethodNode(ASTMethodNode node) {
changed = UselessLabelFinder.v().findAndKill(node);
}
/*
* public void caseASTSynchronizedBlockNode(ASTSynchronizedBlockNode node){
* changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTLabeledBlockNode (ASTLabeledBlockNode node){
* changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTUnconditionalLoopNode (ASTUnconditionalLoopNode
* node){ changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTSwitchNode(ASTSwitchNode node){
* changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTIfNode(ASTIfNode node){
* changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTIfElseNode(ASTIfElseNode node){
* changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTWhileNode(ASTWhileNode node){
* changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTForLoopNode(ASTForLoopNode node){
* changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTDoWhileNode(ASTDoWhileNode node){
* changed=UselessLabelFinder.v().findAndKill(node); } public void caseASTTryNode(ASTTryNode node){
* changed=UselessLabelFinder.v().findAndKill(node); }
*/
public void outASTSynchronizedBlockNode(ASTSynchronizedBlockNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTLabeledBlockNode(ASTLabeledBlockNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTUnconditionalLoopNode(ASTUnconditionalLoopNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTSwitchNode(ASTSwitchNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTIfNode(ASTIfNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTIfElseNode(ASTIfElseNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTWhileNode(ASTWhileNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTForLoopNode(ASTForLoopNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTDoWhileNode(ASTDoWhileNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public void outASTTryNode(ASTTryNode node) {
boolean modified = UselessLabelFinder.v().findAndKill(node);
if (modified) {
changed = true;
}
}
public static void removeLabeledBlock(ASTNode node, ASTLabeledBlockNode labelBlock, int subBodyNumber, int nodeNumber) {
if (!(node instanceof ASTIfElseNode)) {
// these are the nodes which always have one subBody
List