soot.dava.toolkits.base.AST.transformations.ForLoopCreationHelper Maven / Gradle / Ivy
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.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import soot.Value;
import soot.dava.internal.AST.ASTAggregatedCondition;
import soot.dava.internal.AST.ASTBinaryCondition;
import soot.dava.internal.AST.ASTCondition;
import soot.dava.internal.AST.ASTForLoopNode;
import soot.dava.internal.AST.ASTLabeledNode;
import soot.dava.internal.AST.ASTNode;
import soot.dava.internal.AST.ASTStatementSequenceNode;
import soot.dava.internal.AST.ASTUnaryCondition;
import soot.dava.internal.AST.ASTWhileNode;
import soot.dava.internal.SET.SETNodeLabel;
import soot.dava.internal.asg.AugmentedStmt;
import soot.jimple.ConditionExpr;
import soot.jimple.DefinitionStmt;
import soot.jimple.Stmt;
public class ForLoopCreationHelper {
ASTStatementSequenceNode stmtSeqNode;
ASTWhileNode whileNode;
ASTStatementSequenceNode newStmtSeqNode;
ASTForLoopNode forNode;
Map varToStmtMap;
/*
* Bug Reported by Steffen Pingel on the soot mailing list (january 2006) Fixed by Nomair February 6th, 2006
*
* There was a bug in the getUpdate method since it removed the update statement whenver it found one Later on if the
* ForLoop Creation terminated the update stmt had been removed We delay the removal of the update stmt until we are sure
* that the for loop is being created This is done by storing the list of stmts from which to remove the update statement
* in the following field. The boolean (although redundant) indicates when such an update stmt should be removed
*/
List myStmts;// stores the statementseq list of statements whose
// last stmt has to be removed
boolean removeLast = false;// the last stmt in the above stmts is removed if
// this boolean is true
public ForLoopCreationHelper(ASTStatementSequenceNode stmtSeqNode, ASTWhileNode whileNode) {
this.stmtSeqNode = stmtSeqNode;
this.whileNode = whileNode;
varToStmtMap = new HashMap();
}
/*
* The purpose of this method is to replace the statement sequence node given by the var nodeNumber with the new statement
* sequence node and to replace the next node (which sould be a while node with the for loop node
*
* The new body is then returned;
*/
public List