if (debug) {
System.out
.println("handling as assignment to Array");
}
ArrayRef arrayRef = (ArrayRef) stmt.getLeftOp();
Local baseLocal = (Local) arrayRef.getBase();
Map fieldToReplacementArrayLocal = (Map) localToFieldToLocal
.get(baseLocal);
Map fieldToReplacementLocal = (Map) localToFieldToLocal
.get(stmt.getRightOp());
if (debug) {
System.out
.println("fieldToReplacementArrayLocal = "
+ fieldToReplacementArrayLocal);
}
if (debug) {
System.out.println("fieldToReplacementLocal = "
+ fieldToReplacementLocal);
}
if ((fieldToReplacementLocal != null)
&& (fieldToReplacementArrayLocal != null)) {
doneSomething = true;
body
.getUnits()
.insertBefore(
Jimple
.v()
.newAssignStmt(
Jimple
.v()
.newArrayRef(
(Local) localToIsNotNullLocal
.get(baseLocal),
arrayRef
.getIndex()),
(Local) localToIsNotNullLocal
.get(stmt
.getRightOp())),
unit);
if (debug) {
System.out.println("local = "
+ stmt.getLeftOp());
}
for (Iterator tokenFields = fieldToReplacementLocal
.keySet().iterator(); tokenFields
.hasNext();) {
SootField tokenField = (SootField) tokenFields
.next();
if (debug) {
System.out.println("tokenField = "
+ tokenField);
}
Local replacementArrayLocal = (Local) fieldToReplacementArrayLocal
.get(tokenField);
Local replacementLocal = (Local) fieldToReplacementLocal
.get(tokenField);
body
.getUnits()
.insertBefore(
Jimple
.v()
.newAssignStmt(
Jimple
.v()
.newArrayRef(
replacementArrayLocal,
arrayRef
.getIndex()),
replacementLocal),
unit);
}
// Have to remove here, because otherwise we'll try to
// index into a null array.
//stmt.getRightOpBox().setValue(NullConstant.v());
body.getUnits().remove(unit);
}
} else if (stmt.getLeftOp() instanceof Local
&& stmt.getRightOp() instanceof ArrayRef) {
if (debug) {
System.out
.println("handling as assignment from Array");
}
ArrayRef arrayRef = (ArrayRef) stmt.getRightOp();
Map fieldToReplacementLocal = (Map) localToFieldToLocal
.get(stmt.getLeftOp());
Local baseLocal = (Local) arrayRef.getBase();
Map fieldToReplacementArrayLocal = (Map) localToFieldToLocal
.get(baseLocal);
if ((fieldToReplacementLocal != null)
&& (fieldToReplacementArrayLocal != null)) {
doneSomething = true;
body
.getUnits()
.insertBefore(
Jimple
.v()
.newAssignStmt(
(Local) localToIsNotNullLocal
.get(stmt
.getLeftOp()),
Jimple
.v()
.newArrayRef(
(Local) localToIsNotNullLocal
.get(baseLocal),
arrayRef
.getIndex())),
unit);
if (debug) {
System.out.println("local = "
+ stmt.getLeftOp());
}
for (Iterator tokenFields = fieldToReplacementLocal
.keySet().iterator(); tokenFields
.hasNext();) {
SootField tokenField = (SootField) tokenFields
.next();
if (debug) {
System.out.println("tokenField = "
+ tokenField);
}
Local replacementArrayLocal = (Local) fieldToReplacementArrayLocal
.get(tokenField);
Local replacementLocal = (Local) fieldToReplacementLocal
.get(tokenField);
if (debug) {
System.out
.println("replacementLocal = "
+ replacementLocal);
}
if (debug) {
System.out
.println("replacementArrayLocal = "
+ replacementArrayLocal);
}
body
.getUnits()
.insertBefore(
Jimple
.v()
.newAssignStmt(
replacementLocal,
Jimple
.v()
.newArrayRef(
replacementArrayLocal,
arrayRef
.getIndex())),
unit);
}
stmt.getRightOpBox().setValue(NullConstant.v());