use of soot.dava.internal.asg.AugmentedStmt in project soot by Sable.
the class ShortcutArrayInit method secondPattern.
/*
* Maybe its a multi-D array then we need to look for a DAssignStmt followed
* by a definition Stmt
*/
public void secondPattern(ASTStatementSequenceNode node) {
boolean success = false;
ArrayList<AugmentedStmt> toRemove = new ArrayList<AugmentedStmt>();
for (AugmentedStmt as : node.getStatements()) {
success = false;
Stmt s = as.get_Stmt();
if (!(s instanceof DefinitionStmt))
continue;
DefinitionStmt ds = (DefinitionStmt) s;
ValueBox right = ds.getRightOpBox();
Value rightValue = right.getValue();
if (!(rightValue instanceof NewArrayExpr))
continue;
if (DEBUG) {
System.out.println("Found a new ArrayExpr" + rightValue);
System.out.println("Type of array is:" + rightValue.getType());
}
// get type out
Type arrayType = rightValue.getType();
// get size....need to know this statically for sure!!!
Value size = ((NewArrayExpr) rightValue).getSize();
if (!(size instanceof IntConstant))
continue;
if (((IntConstant) size).value == 0) {
debug("Found value to be 0 doing nothing");
continue;
}
if (DEBUG)
System.out.println("Size of array is: " + ((IntConstant) size).value);
Iterator<AugmentedStmt> tempIt = node.getStatements().iterator();
// get to the array creation stmt
while (tempIt.hasNext()) {
AugmentedStmt tempAs = (AugmentedStmt) tempIt.next();
Stmt tempS = tempAs.get_Stmt();
if (tempS.equals(s))
break;
}
// have the size have the type, tempIt is poised at the current def
// stmt
ValueBox[] array = new ValueBox[((IntConstant) size).value];
success = true;
for (int i = 0; i < ((IntConstant) size).value; i++) {
// a DefinitionStmt
if (!tempIt.hasNext()) {
// since its end of the stmt seq node just return
if (DEBUG)
System.out.println("returning");
return;
}
AugmentedStmt augOne = tempIt.next();
Stmt augSOne = augOne.get_Stmt();
if (!tempIt.hasNext()) {
// since its end of the stmt seq node just return
if (DEBUG)
System.out.println("returning");
return;
}
AugmentedStmt augTwo = tempIt.next();
Stmt augSTwo = augTwo.get_Stmt();
if (!isInSequenceAssignmentPatternTwo(augSOne, augSTwo, ds.getLeftOp(), i)) {
// initializations
if (DEBUG)
System.out.println("Out of order assignment aborting attempt");
success = false;
break;
} else {
if (DEBUG)
System.out.println("Assignment stmt in order adding to array");
// the RHS of augSOne is the next assignment in the sequence
// add to ValueBox array
array[i] = ((DShortcutAssignStmt) augSOne).getRightOpBox();
toRemove.add(augOne);
toRemove.add(augTwo);
}
}
if (success) {
DArrayInitExpr tempExpr = new DArrayInitExpr(array, arrayType);
DArrayInitValueBox tempValueBox = new DArrayInitValueBox(tempExpr);
DAssignStmt newStmt = new DAssignStmt(ds.getLeftOpBox(), tempValueBox);
// stmt
if (DEBUG)
System.out.println("Created new DAssignStmt and replacing it");
InitializationDeclarationShortcut shortcutChecker = new InitializationDeclarationShortcut(as);
methodNode.apply(shortcutChecker);
boolean possible = shortcutChecker.isShortcutPossible();
if (possible) {
if (DEBUG)
System.out.println("Shortcut is possible");
// create shortcut stmt
DShortcutAssignStmt newShortcutStmt = new DShortcutAssignStmt(newStmt, arrayType);
as.set_Stmt(newShortcutStmt);
// make sure to mark the local in the DVariableDeclarations
// so that its not printed
markLocal(ds.getLeftOp());
}
break;
}
}
// end going through stmt seq node
if (success) {
// means we did a transformation remove the stmts
List<AugmentedStmt> newStmtList = new ArrayList<AugmentedStmt>();
for (AugmentedStmt as : node.getStatements()) {
if (toRemove.contains(as)) {
toRemove.remove(as);
} else {
newStmtList.add(as);
}
}
node.setStatements(newStmtList);
// make sure any other possible simplifications are done
inASTStatementSequenceNode(node);
G.v().ASTTransformations_modified = true;
}
}
use of soot.dava.internal.asg.AugmentedStmt in project soot by Sable.
the class SETNode method find_StatementSequences.
public void find_StatementSequences(SequenceFinder sf, DavaBody davaBody) {
Iterator<IterableSet> sbit = subBodies.iterator();
while (sbit.hasNext()) {
IterableSet body = sbit.next();
IterableSet children = body2childChain.get(body);
HashSet<AugmentedStmt> childUnion = new HashSet<AugmentedStmt>();
Iterator cit = children.iterator();
while (cit.hasNext()) {
SETNode child = (SETNode) cit.next();
child.find_StatementSequences(sf, davaBody);
childUnion.addAll(child.get_Body());
}
sf.find_StatementSequences(this, body, childUnion, davaBody);
}
}
use of soot.dava.internal.asg.AugmentedStmt in project soot by Sable.
the class SuperFirstStmtHandler method finalizePreInitMethod.
// method should return false if the PreInit body(ASTBody that is) is empty
// meaning there is no need to create it all
private boolean finalizePreInitMethod() {
// set davaBody...totally redundant but have to do as this is checked by
// toString of ASTMethodNode
newASTPreInitMethod.setDavaBody(newPreInitDavaBody);
// newPreInitDavaBody is the active body
newPreInitDavaBody.getUnits().clear();
newPreInitDavaBody.getUnits().addLast(newASTPreInitMethod);
// check whether there is something in side the ASTBody
// if its empty (maybe there were only declarations and that got removed
// then no point in creating the preInit method
List<Object> subBodies = newASTPreInitMethod.get_SubBodies();
if (subBodies.size() != 1)
return false;
List body = (List) subBodies.get(0);
// body is NOT allowed to contain one declaration node with whatever in
// it
// after that it is NOT allowed all ASTStatement nodes with empty bodies
Iterator it = body.iterator();
// indicating that method is empty
boolean empty = true;
while (it.hasNext()) {
ASTNode tempNode = (ASTNode) it.next();
if (!(tempNode instanceof ASTStatementSequenceNode)) {
// found some node other than stmtseq...body not empty return
// true
empty = false;
break;
}
List<AugmentedStmt> stmts = ((ASTStatementSequenceNode) tempNode).getStatements();
// all declaration stmts are allowed
for (AugmentedStmt as : stmts) {
Stmt s = as.get_Stmt();
if (!(s instanceof DVariableDeclarationStmt)) {
empty = false;
break;
}
}
if (!empty)
break;
}
if (empty) {
// should not be creating the method
return false;
}
// about to return true enter all DavaSuperHandler stmts to make it part
// of the preinit method
createDavaStoreStmts();
return true;
}
use of soot.dava.internal.asg.AugmentedStmt in project soot by Sable.
the class TypeCastingError method inASTStatementSequenceNode.
public void inASTStatementSequenceNode(ASTStatementSequenceNode node) {
for (AugmentedStmt as : node.getStatements()) {
Stmt s = as.get_Stmt();
if (!(s instanceof DefinitionStmt))
continue;
DefinitionStmt ds = (DefinitionStmt) s;
if (myDebug)
System.out.println("Definition stmt" + ds);
ValueBox rightBox = ds.getRightOpBox();
ValueBox leftBox = ds.getLeftOpBox();
Value right = rightBox.getValue();
Value left = leftBox.getValue();
if (!(left.getType() instanceof PrimType && right.getType() instanceof PrimType)) {
// only interested in prim type casting errors
if (myDebug)
System.out.println("\tDefinition stmt does not contain prims no need to modify");
continue;
}
Type leftType = left.getType();
Type rightType = right.getType();
if (myDebug)
System.out.println("Left type is: " + leftType);
if (myDebug)
System.out.println("Right type is: " + rightType);
if (leftType.equals(rightType)) {
if (myDebug)
System.out.println("\tTypes are the same");
if (myDebug)
System.out.println("Right value is of instance" + right.getClass());
}
if (!leftType.equals(rightType)) {
if (myDebug)
System.out.println("\tDefinition stmt has to be modified");
/*
* byte Byte-length integer 8-bit two's complement
* short Short integer 16-bit two's complement
* int Integer 32-bit two's complement
* long Long integer 64-bit two's complement
* float Single-precision floating point 32-bit IEEE 754
* double Double-precision floating point 64-bit IEEE 754
*/
if (leftType instanceof ByteType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof IntType || rightType instanceof LongType || rightType instanceof ShortType)) {
if (DEBUG)
System.out.println("Explicit casting to BYTE required");
rightBox.setValue(new GCastExpr(right, ByteType.v()));
if (DEBUG)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
if (leftType instanceof ShortType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof IntType || rightType instanceof LongType)) {
if (DEBUG)
System.out.println("Explicit casting to SHORT required");
rightBox.setValue(new GCastExpr(right, ShortType.v()));
if (DEBUG)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
if (leftType instanceof IntType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof LongType)) {
if (myDebug)
System.out.println("Explicit casting to INT required");
rightBox.setValue(new GCastExpr(right, IntType.v()));
if (myDebug)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
if (leftType instanceof LongType && (rightType instanceof DoubleType || rightType instanceof FloatType)) {
if (DEBUG)
System.out.println("Explicit casting to LONG required");
rightBox.setValue(new GCastExpr(right, LongType.v()));
if (DEBUG)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
if (leftType instanceof FloatType && rightType instanceof DoubleType) {
if (DEBUG)
System.out.println("Explicit casting to FLOAT required");
rightBox.setValue(new GCastExpr(right, FloatType.v()));
if (DEBUG)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
}
}
}
use of soot.dava.internal.asg.AugmentedStmt in project soot by Sable.
the class ExceptionNode method get_CatchExits.
public List<AugmentedStmt> get_CatchExits() {
if (catchBody == null)
return null;
if (dirty) {
exitList = new LinkedList<AugmentedStmt>();
dirty = false;
for (AugmentedStmt as : catchBody) {
for (AugmentedStmt succ : as.bsuccs) if (catchBody.contains(succ) == false) {
exitList.add(as);
break;
}
}
}
return exitList;
}
Aggregations