int numberOfStates = entity.entityList().size();
// Figure out what state we are in.
for (Iterator states = entity.entityList().iterator(); states
.hasNext();) {
State state = (State) states.next();
Stmt startStmt = Jimple.v().newNopStmt();
stateToStartStmt.put(state, startStmt);
stateStmtList.add(startStmt);
}
Local currentStateLocal = Jimple.v().newLocal("currentStateLocal",
IntType.v());
body.getLocals().add(currentStateLocal);
Local nextStateLocal = Jimple.v().newLocal("nextStateLocal",
IntType.v());
body.getLocals().add(nextStateLocal);
Local flagLocal = Jimple.v().newLocal("flagLocal", BooleanType.v());
body.getLocals().add(flagLocal);
Local transitionTakenLocal = Jimple.v().newLocal(
"transitionTakenLocal", BooleanType.v());
body.getLocals().add(transitionTakenLocal);
Local nextTransitionLocal = Jimple.v().newLocal(
"nextTransitionLocal", IntType.v());
body.getLocals().add(nextTransitionLocal);
units.add(Jimple.v().newAssignStmt(
currentStateLocal,
Jimple.v().newInstanceFieldRef(thisLocal,
currentStateField.makeRef())));
// Start by doing nothing.
units.add(Jimple.v().newAssignStmt(transitionTakenLocal,
IntConstant.v(0)));
units.add(Jimple.v().newAssignStmt(nextTransitionLocal,
IntConstant.v(-1)));
// If no transition is taken, then stay in this state.
units.add(Jimple.v().newAssignStmt(nextStateLocal,
currentStateLocal));
Stmt finishedStmt = Jimple.v().newNopStmt();
Stmt errorStmt = Jimple.v().newNopStmt();
// Get the current state.
units.add(Jimple.v().newTableSwitchStmt(currentStateLocal, 0,
numberOfStates - 1, stateStmtList, errorStmt));
// Generate code for each state.
for (Iterator states = entity.entityList().iterator(); states
.hasNext();) {
State state = (State) states.next();
System.out.println("state " + state.getName());
Stmt startStmt = (Stmt) stateToStartStmt.get(state);
units.add(startStmt);
// Fire the refinement actor.
TypedActor[] refinements = null;
try {
refinements = state.getRefinement();
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage());
}
if (refinements != null) {