use of soot.jimple.NullConstant in project soot by Sable.
the class CollectConstants method addInitializingValue.
private void addInitializingValue(SootClass sc, SootField f, Constant constant) {
if (constant instanceof NullConstant) {
return;
} else if (constant instanceof IntConstant) {
if (((IntConstant) constant).value == 0)
return;
} else if (constant instanceof LongConstant) {
if (((LongConstant) constant).value == 0)
return;
} else if (constant instanceof StringConstant) {
if (((StringConstant) constant).value == null)
return;
} else if (constant instanceof DoubleConstant) {
if (((DoubleConstant) constant).value == 0)
return;
} else if (constant instanceof FloatConstant) {
if (((FloatConstant) constant).value == 0)
return;
}
Body b;
boolean newInit = false;
if (!sc.declaresMethodByName(SootMethod.staticInitializerName)) {
SootMethod m = Scene.v().makeSootMethod(SootMethod.staticInitializerName, emptyList(), VoidType.v(), Modifier.STATIC);
sc.addMethod(m);
b = Jimple.v().newBody(m);
m.setActiveBody(b);
newInit = true;
} else {
SootMethod m = sc.getMethodByName(SootMethod.staticInitializerName);
if (!m.hasActiveBody()) {
b = Jimple.v().newBody(m);
m.setActiveBody(b);
newInit = true;
} else {
b = m.getActiveBody();
}
}
PatchingChain<Unit> units = b.getUnits();
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(f.makeRef()), constant));
if (newInit)
units.addLast(Jimple.v().newReturnVoidStmt());
}
use of soot.jimple.NullConstant in project soot by Sable.
the class PAG method addCallTarget.
/**
* Adds method target as a possible target of the invoke expression in s. If
* target is null, only creates the nodes for the call site, without actually
* connecting them to any target method.
*/
public final void addCallTarget(MethodPAG srcmpag, MethodPAG tgtmpag, Stmt s, Context srcContext, Context tgtContext, Edge e) {
MethodNodeFactory srcnf = srcmpag.nodeFactory();
MethodNodeFactory tgtnf = tgtmpag.nodeFactory();
InvokeExpr ie = s.getInvokeExpr();
boolean virtualCall = callAssigns.containsKey(ie);
int numArgs = ie.getArgCount();
for (int i = 0; i < numArgs; i++) {
Value arg = ie.getArg(i);
if (!(arg.getType() instanceof RefLikeType))
continue;
if (arg instanceof NullConstant)
continue;
Node argNode = srcnf.getNode(arg);
argNode = srcmpag.parameterize(argNode, srcContext);
argNode = argNode.getReplacement();
Node parm = tgtnf.caseParm(i);
parm = tgtmpag.parameterize(parm, tgtContext);
parm = parm.getReplacement();
addEdge(argNode, parm);
Pair<Node, Node> pval = addInterproceduralAssignment(argNode, parm, e);
callAssigns.put(ie, pval);
callToMethod.put(ie, srcmpag.getMethod());
}
if (ie instanceof InstanceInvokeExpr) {
InstanceInvokeExpr iie = (InstanceInvokeExpr) ie;
Node baseNode = srcnf.getNode(iie.getBase());
baseNode = srcmpag.parameterize(baseNode, srcContext);
baseNode = baseNode.getReplacement();
Node thisRef = tgtnf.caseThis();
thisRef = tgtmpag.parameterize(thisRef, tgtContext);
thisRef = thisRef.getReplacement();
addEdge(baseNode, thisRef);
Pair<Node, Node> pval = addInterproceduralAssignment(baseNode, thisRef, e);
callAssigns.put(ie, pval);
callToMethod.put(ie, srcmpag.getMethod());
if (virtualCall && !virtualCallsToReceivers.containsKey(ie)) {
virtualCallsToReceivers.put(ie, baseNode);
}
}
if (s instanceof AssignStmt) {
Value dest = ((AssignStmt) s).getLeftOp();
if (dest.getType() instanceof RefLikeType && !(dest instanceof NullConstant)) {
Node destNode = srcnf.getNode(dest);
destNode = srcmpag.parameterize(destNode, srcContext);
destNode = destNode.getReplacement();
Node retNode = tgtnf.caseRet();
retNode = tgtmpag.parameterize(retNode, tgtContext);
retNode = retNode.getReplacement();
addEdge(retNode, destNode);
Pair<Node, Node> pval = addInterproceduralAssignment(retNode, destNode, e);
callAssigns.put(ie, pval);
callToMethod.put(ie, srcmpag.getMethod());
}
}
}
Aggregations