if (debug) {
System.out
.println("handling as assignment to Field");
}
FieldRef oldFieldRef = (FieldRef) stmt.getLeftOp();
SootField field = oldFieldRef.getField();
Map fieldToReplacementField = (Map) entityFieldToTokenFieldToReplacementField
.get(field);
Map fieldToReplacementLocal = (Map) localToFieldToLocal
.get(stmt.getRightOp());
// System.out.println("fieldToReplacementField = " + fieldToReplacementField);
// System.out.println("fieldToReplacementLocal = " + fieldToReplacementLocal);
if ((fieldToReplacementLocal != null)
&& (fieldToReplacementField != null)) {
doneSomething = true;
// Replace references to fields with token types.
{
SootField replacementField = (SootField) entityFieldToIsNotNullField
.get(field);
//System.out.println("replacementField = " + replacementField);
FieldRef isNotNullFieldRef;
if (oldFieldRef instanceof InstanceFieldRef) {
isNotNullFieldRef = Jimple
.v()
.newInstanceFieldRef(
((InstanceFieldRef) oldFieldRef)
.getBase(),
replacementField
.makeRef());
} else {
isNotNullFieldRef = Jimple.v()
.newStaticFieldRef(
replacementField
.makeRef());
}
body
.getUnits()
.insertBefore(
Jimple
.v()
.newAssignStmt(
isNotNullFieldRef,
(Local) localToIsNotNullLocal
.get(stmt
.getRightOp())),
unit);
}
if (debug) {
System.out.println("local = "
+ stmt.getLeftOp());
}
for (Iterator tokenFields = fieldToReplacementField
.keySet().iterator(); tokenFields
.hasNext();) {
SootField tokenField = (SootField) tokenFields
.next();
if (debug) {
System.out.println("tokenField = "
+ tokenField);
}
SootField replacementField = (SootField) fieldToReplacementField
.get(tokenField);
Local replacementLocal = (Local) fieldToReplacementLocal
.get(tokenField);
if (debug) {
System.out
.println("replacementLocal = "
+ replacementLocal);
}
FieldRef fieldRef;
if (stmt.getLeftOp() instanceof InstanceFieldRef) {
Local base = (Local) ((InstanceFieldRef) stmt
.getLeftOp()).getBase();
fieldRef = Jimple.v()
.newInstanceFieldRef(
base,
replacementField
.makeRef());
} else {
fieldRef = Jimple.v()
.newStaticFieldRef(
replacementField
.makeRef());
}
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(fieldRef,
replacementLocal), unit);
}
stmt.getRightOpBox().setValue(NullConstant.v());
// body.getUnits().remove(unit);
}
} else if (stmt.getLeftOp() instanceof Local
&& stmt.getRightOp() instanceof FieldRef) {
if (debug) {
System.out
.println("handling as assignment from Field");
}
FieldRef oldFieldRef = (FieldRef) stmt.getRightOp();
Map fieldToReplacementLocal = (Map) localToFieldToLocal
.get(stmt.getLeftOp());
SootField field = oldFieldRef.getField();
Map fieldToReplacementField = (Map) entityFieldToTokenFieldToReplacementField
.get(field);
// There are some fields that represent
// singleton tokens. Deal with them
// specially.
// This is awkward, but it is simpler than
// doing a dataflow analysis of the static
// initializer of the token class to
// figure out what the value is.
boolean isSingleton = false;
if (field.getName().equals("TRUE")
|| field.getName().equals("FALSE")
|| field.getName().equals("ZERO")
|| field.getName().equals("ONE")) {
isSingleton = true;
}
if ((isSingleton)
&& (fieldToReplacementLocal != null)) {
doneSomething = true;
// Replace references to fields with
// token types. The special fields
// should never be null
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
(Local) localToIsNotNullLocal
.get(stmt.getLeftOp()),
IntConstant.v(1)), unit);
if (debug) {
System.out.println("local = "
+ stmt.getLeftOp());
}
for (Iterator localFields = fieldToReplacementLocal
.keySet().iterator(); localFields
.hasNext();) {
SootField localField = (SootField) localFields
.next();
if (debug) {
System.out.println("localField = "
+ localField);
}
// if (localField.getName().equals("_isNil")) {
// Local replacementLocal = (Local) fieldToReplacementLocal
// .get(localField);
// body
// .getUnits()
// .insertBefore(
// Jimple
// .v()
// .newAssignStmt(
// replacementLocal,
// IntConstant
// .v(1)),
// unit);
// } else
if (localField.getName().equals(
"_unitCategoryExponents")) {
Local replacementLocal = (Local) fieldToReplacementLocal
.get(localField);
body
.getUnits()
.insertBefore(
Jimple
.v()
.newAssignStmt(
replacementLocal,
NullConstant
.v()),
unit);
} else if (localField.getName().equals(
"_value")) {
Local replacementLocal = (Local) fieldToReplacementLocal
.get(localField);
if (field
.getSignature()
.equals(
"<ptolemy.data.BooleanToken: ptolemy.data.BooleanToken TRUE>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
IntConstant.v(1)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.BooleanToken: ptolemy.data.BooleanToken FALSE>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
IntConstant.v(0)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.UnsignedByteToken: ptolemy.data.UnsignedByteToken ONE>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
IntConstant.v(1)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.UnsignedByteToken: ptolemy.data.UnsignedByteToken ZERO>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
IntConstant.v(0)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.IntToken: ptolemy.data.IntToken ONE>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
IntConstant.v(1)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.IntToken: ptolemy.data.IntToken ZERO>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
IntConstant.v(0)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.LongToken: ptolemy.data.LongToken ONE>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
LongConstant.v(1)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.LongToken: ptolemy.data.LongToken ZERO>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
LongConstant.v(0)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.DoubleToken: ptolemy.data.DoubleToken ONE>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
DoubleConstant
.v(1.0)),
unit);
} else if (field
.getSignature()
.equals(
"<ptolemy.data.DoubleToken: ptolemy.data.DoubleToken ZERO>")) {
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
replacementLocal,
DoubleConstant
.v(0.0)),
unit);
}
} else {
throw new RuntimeException(
"Unknown Field in Token: "
+ localField
.getSignature());
}
}
stmt.getRightOpBox().setValue(NullConstant.v());
//body.getUnits().remove(unit);
} else if ((fieldToReplacementLocal != null)
&& (fieldToReplacementField != null)) {
doneSomething = true;
// Replace references to fields with token types.
// FIXME properly handle isNotNull field?
{
SootField replacementField = (SootField) entityFieldToIsNotNullField
.get(field);
// System.out.println("replacementField = " + replacementField);
FieldRef isNotNullFieldRef;
if (oldFieldRef instanceof InstanceFieldRef) {
isNotNullFieldRef = Jimple
.v()
.newInstanceFieldRef(
((InstanceFieldRef) oldFieldRef)
.getBase(),
replacementField
.makeRef());
} else {
isNotNullFieldRef = Jimple.v()
.newStaticFieldRef(
replacementField
.makeRef());
}
body
.getUnits()
.insertBefore(
Jimple
.v()
.newAssignStmt(
(Local) localToIsNotNullLocal
.get(stmt
.getLeftOp()),
isNotNullFieldRef),
unit);
}
if (debug) {
System.out.println("local = "
+ stmt.getLeftOp());
}
for (Iterator tokenFields = fieldToReplacementField
.keySet().iterator(); tokenFields
.hasNext();) {
SootField tokenField = (SootField) tokenFields
.next();
if (debug) {
System.out.println("tokenField = "
+ tokenField);
}
SootField replacementField = (SootField) fieldToReplacementField
.get(tokenField);
Local replacementLocal = (Local) fieldToReplacementLocal
.get(tokenField);
FieldRef fieldRef;
if (stmt.getRightOp() instanceof InstanceFieldRef) {
Local base = (Local) ((InstanceFieldRef) stmt
.getRightOp()).getBase();
fieldRef = Jimple.v()