// generate code for transition refinement
Actor[] actors = transition.getRefinement();
if (actors != null) {
for (int i = 0; i < actors.length; i++) {
CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper((NamedObj) actors[i]);
// fire the actor
if (inline) {
codeBuffer.append(helper.generateFireCode());
codeBuffer.append(helper
.generateTypeConvertFireCode());
} else {
codeBuffer
.append(generateName((NamedObj) actors[i])
+ "();" + _eol);
}
}
}
// generate code for commit action
actions = transition.commitActionList().iterator();
while (actions.hasNext()) {
AbstractActionsAttribute action = (AbstractActionsAttribute) actions
.next();
Iterator destinationNameList = action
.getDestinationNameList().iterator();
Iterator channelNumberList = action.getChannelNumberList()
.iterator();
Iterator parseTreeList = action.getParseTreeList()
.iterator();
while (destinationNameList.hasNext()) {
String destinationName = (String) destinationNameList
.next();
Integer channelNumber = (Integer) channelNumberList
.next();
ASTPtRootNode parseTree = (ASTPtRootNode) parseTreeList
.next();
NamedObj destination = action
.getDestination(destinationName);
int channel = -1;
if (channelNumber != null) {
channel = channelNumber.intValue();
}
codeBuffer.append(_getIndentPrefix(depth));
if (destination instanceof IOPort) {
if (channel >= 0) {
codeBuffer.append("$ref(" + destinationName
+ "#" + channel + ") = ");
} else { // broadcast
int width = ((IOPort) action
.getDestination(destinationName))
.getWidth();
for (int i = 0; i < width; i++) {
codeBuffer.append("$ref(" + destinationName
+ "#" + i + ") = ");
}
}
} else if (destination instanceof Variable) {
codeBuffer
.append(_codeGenerator
.generateVariableName((Variable) destination)
+ " = ");
}
ParseTreeCodeGenerator parseTreeCodeGenerator = getParseTreeCodeGenerator();
parseTreeCodeGenerator.evaluateParseTree(parseTree,
_scope);
codeBuffer.append(parseTreeCodeGenerator
.generateFireCode());
codeBuffer.append(";" + _eol);
}
}
// generate code for updating current state
State destinationState = transition.destinationState();
_updateCurrentState(codeBuffer, destinationState, depth);
// generate code for reinitialization if reset is
// true. we assume the value of reset itself cannot
// be changed dynamically
BooleanToken resetToken = (BooleanToken) transition.reset
.getToken();
if (resetToken.booleanValue()) {
actors = destinationState.getRefinement();
if (actors != null) {
for (int i = 0; i < actors.length; ++i) {
ActorCodeGenerator helper = (ActorCodeGenerator) _getHelper((NamedObj) actors[i]);
codeBuffer.append(helper.generateInitializeCode());
}
}
}
// Generate code for updating configuration number of