use of polyglot.ast.FieldDecl in project soot by Sable.
the class JimpleBodyBuilder method handleStaticFieldInits.
/**
* adds any needed static field inits
*/
private void handleStaticFieldInits(soot.SootMethod sootMethod) {
ArrayList<FieldDecl> staticFieldInits = ((soot.javaToJimple.PolyglotMethodSource) sootMethod.getSource()).getStaticFieldInits();
if (staticFieldInits != null) {
Iterator<FieldDecl> staticFieldInitsIt = staticFieldInits.iterator();
while (staticFieldInitsIt.hasNext()) {
polyglot.ast.FieldDecl field = staticFieldInitsIt.next();
String fieldName = field.name();
polyglot.ast.Expr initExpr = field.init();
soot.SootClass currentClass = body.getMethod().getDeclaringClass();
soot.SootFieldRef sootField = soot.Scene.v().makeFieldRef(currentClass, fieldName, Util.getSootType(field.type().type()), field.flags().isStatic());
soot.jimple.FieldRef fieldRef = soot.jimple.Jimple.v().newStaticFieldRef(sootField);
// System.out.println("initExpr: "+initExpr);
soot.Value sootExpr;
if (initExpr instanceof polyglot.ast.ArrayInit) {
sootExpr = getArrayInitLocal((polyglot.ast.ArrayInit) initExpr, field.type().type());
} else {
// System.out.println("field init expr: "+initExpr);
sootExpr = base().createAggressiveExpr(initExpr, false, false);
if (sootExpr instanceof soot.jimple.ConditionExpr) {
sootExpr = handleCondBinExpr((soot.jimple.ConditionExpr) sootExpr);
}
}
soot.jimple.Stmt assign = soot.jimple.Jimple.v().newAssignStmt(fieldRef, sootExpr);
body.getUnits().add(assign);
Util.addLnPosTags(assign, initExpr.position());
}
}
}
use of polyglot.ast.FieldDecl in project soot by Sable.
the class ClassResolver method createFieldDecl.
/**
* Field Declaration Creation
*/
private void createFieldDecl(polyglot.ast.FieldDecl field) {
// System.out.println("field decl: "+field);
int modifiers = Util.getModifier(field.fieldInstance().flags());
String name = field.fieldInstance().name();
soot.Type sootType = Util.getSootType(field.fieldInstance().type());
soot.SootField sootField = Scene.v().makeSootField(name, sootType, modifiers);
sootClass.addField(sootField);
if (field.fieldInstance().flags().isStatic()) {
if (field.init() != null) {
if (field.flags().isFinal() && (field.type().type().isPrimitive() || (field.type().type().toString().equals("java.lang.String"))) && field.fieldInstance().isConstant()) {
// System.out.println("adding constantValtag: to field:
// "+sootField);
addConstValTag(field, sootField);
} else {
if (staticFieldInits == null) {
staticFieldInits = new ArrayList<FieldDecl>();
}
staticFieldInits.add(field);
}
}
} else {
if (field.init() != null) {
if (fieldInits == null) {
fieldInits = new ArrayList<FieldDecl>();
}
fieldInits.add(field);
}
}
Util.addLnPosTags(sootField, field.position());
}
use of polyglot.ast.FieldDecl in project soot by Sable.
the class JimpleBodyBuilder method handleFieldInits.
protected void handleFieldInits(ArrayList<FieldDecl> fieldInits) {
Iterator<FieldDecl> fieldInitsIt = fieldInits.iterator();
while (fieldInitsIt.hasNext()) {
polyglot.ast.FieldDecl field = fieldInitsIt.next();
String fieldName = field.name();
polyglot.ast.Expr initExpr = field.init();
soot.SootClass currentClass = body.getMethod().getDeclaringClass();
soot.SootFieldRef sootField = soot.Scene.v().makeFieldRef(currentClass, fieldName, Util.getSootType(field.type().type()), field.flags().isStatic());
soot.Local base = specialThisLocal;
soot.jimple.FieldRef fieldRef = soot.jimple.Jimple.v().newInstanceFieldRef(base, sootField);
soot.Value sootExpr;
if (initExpr instanceof polyglot.ast.ArrayInit) {
sootExpr = getArrayInitLocal((polyglot.ast.ArrayInit) initExpr, field.type().type());
} else {
// System.out.println("field init expr: "+initExpr);
sootExpr = base().createAggressiveExpr(initExpr, false, false);
// System.out.println("soot expr: "+sootExpr);
}
if (sootExpr instanceof soot.jimple.ConditionExpr) {
sootExpr = handleCondBinExpr((soot.jimple.ConditionExpr) sootExpr);
}
soot.jimple.AssignStmt assign;
if (sootExpr instanceof soot.Local) {
assign = soot.jimple.Jimple.v().newAssignStmt(fieldRef, sootExpr);
} else if (sootExpr instanceof soot.jimple.Constant) {
assign = soot.jimple.Jimple.v().newAssignStmt(fieldRef, sootExpr);
} else {
throw new RuntimeException("fields must assign to local or constant only");
}
body.getUnits().add(assign);
Util.addLnPosTags(assign, initExpr.position());
Util.addLnPosTags(assign.getRightOpBox(), initExpr.position());
}
}