Stmt failedStmt = Jimple.v().newNopStmt();
Stmt satisfiedStmt = Jimple.v().newNopStmt();
// Determine if we are doing AND or OR
Constant conditionConstant = node.isLogicalAnd() ? IntConstant.v(1)
: IntConstant.v(0);
_units.insertBefore(Jimple.v().newAssignStmt(conditionLocal,
conditionConstant), _insertPoint);
for (int i = 0; i < numChildren; i++) {
_generateChild(node, i);
Local childLocal = (Local) _nodeToLocal.get(node.jjtGetChild(i));
// Check the condition
_units.insertBefore(Jimple.v().newAssignStmt(
booleanTokenLocal,
Jimple.v().newCastExpr(childLocal,
RefType.v(PtolemyUtilities.booleanTokenClass))),
_insertPoint);
_units.insertBefore(Jimple.v().newAssignStmt(
flagLocal,
Jimple.v().newVirtualInvokeExpr(booleanTokenLocal,
PtolemyUtilities.booleanValueMethod.makeRef())),
_insertPoint);
// If condition is true then skip to start of true branch.
_units.insertBefore(Jimple.v().newIfStmt(
Jimple.v().newNeExpr(flagLocal, conditionConstant),
failedStmt), _insertPoint);
}
// If we fall through, then must be satisfied.
_units
.insertBefore(Jimple.v().newGotoStmt(satisfiedStmt),
_insertPoint);
_units.insertBefore(failedStmt, _insertPoint);
Constant notConditionConstant = node.isLogicalAnd() ? IntConstant.v(0)
: IntConstant.v(1);
_units.insertBefore(Jimple.v().newAssignStmt(conditionLocal,
notConditionConstant), _insertPoint);
_units.insertBefore(satisfiedStmt, _insertPoint);