Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-02-14 13:29:46 +0000
committerHenrik Rentz-Reichert2013-02-14 13:29:46 +0000
commitcc4fb988b0bfb262646f9d7141d3c26397d08e71 (patch)
treeef67b9745972828c52cfa7f1fa68df5a00027cf3
parent8b47b881dd9f6406dacfabb1fb6031943601e3a7 (diff)
downloadorg.eclipse.etrice-cc4fb988b0bfb262646f9d7141d3c26397d08e71.tar.gz
org.eclipse.etrice-cc4fb988b0bfb262646f9d7141d3c26397d08e71.tar.xz
org.eclipse.etrice-cc4fb988b0bfb262646f9d7141d3c26397d08e71.zip
[generator] bug 400288: [core.genmodel][generator] special situation with transition point and choice point not handled properly
https://bugs.eclipse.org/400288 Needed to further improve this because the state type may be unsigned. Also shifted the evaluation of the skip flag to enterHistory. This way less parameters have to be passed.
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend24
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java5
-rw-r--r--plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java112
3 files changed, 77 insertions, 64 deletions
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
index 908054f5e..838cf1b74 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
@@ -72,6 +72,7 @@ class GenericStateMachineGenerator {
list.add(pair(state.getGenStateId, offset.toString))
offset = offset+1;
}
+ list.add(pair("STATE_MAX", offset.toString))
return langExt.genEnumeration("state_ids", list)
}
@@ -259,7 +260,12 @@ class GenericStateMachineGenerator {
«ENDIF»
* @return - the ID of the final leaf state
*/
- «privAccess»«stateType» «opScopePriv»enterHistory(«self»«stateType» state, «IF usesHdlr»«boolType» handler, «ENDIF»«boolType» skip_entry) {
+ «privAccess»«stateType» «opScopePriv»enterHistory(«self»«stateType» state«IF usesHdlr», «boolType» handler«ENDIF») {
+ «boolType» skip_entry = «langExt.booleanConstant(false)»;
+ if (state >= STATE_MAX) {
+ state = state - STATE_MAX;
+ skip_entry = «langExt.booleanConstant(true)»;
+ }
while («langExt.booleanConstant(true)») {
switch (state) {
«FOR state : xpac.stateMachine.getBaseStateList()»
@@ -302,7 +308,7 @@ class GenericStateMachineGenerator {
«var initt = xpac.stateMachine.getInitTransition()»
int chain = «xpac.getChain(initt).genChainId»;
«stateType» next = «opScopePriv»executeTransitionChain(«langExt.selfPointer(true)»chain«IF handleEvents», «langExt.nullPointer», «langExt.nullPointer»«ENDIF»);
- next = «opScopePriv»enterHistory(«langExt.selfPointer(true)»next, «IF usesHdlr»«langExt.booleanConstant(false)», «ENDIF»«langExt.booleanConstant(false)»);
+ next = «opScopePriv»enterHistory(«langExt.selfPointer(true)»next«IF usesHdlr», «langExt.booleanConstant(false)»«ENDIF»);
setState(«langExt.selfPointer(true)»next);
}
@@ -328,14 +334,11 @@ class GenericStateMachineGenerator {
«ENDIF»
if (chain != NOT_CAUGHT) {
«opScopePriv»exitTo(«langExt.selfPointer(true)»getState(«langExt.selfPointer(false)»), catching_state«IF usesHdlr», is_handler«ENDIF»);
- «stateType» next = «opScopePriv»executeTransitionChain(«langExt.selfPointer(true)»chain«IF handleEvents», ifitem, generic_data«ENDIF»);
- «boolType» skip_entry = «langExt.booleanConstant(false)»;
- if(next < 0){
- next = -next;
- skip_entry = «langExt.booleanConstant(true)»;
+ {
+ «stateType» next = «opScopePriv»executeTransitionChain(«langExt.selfPointer(true)»chain«IF handleEvents», ifitem, generic_data«ENDIF»);
+ next = «opScopePriv»enterHistory(«langExt.selfPointer(true)»next«IF usesHdlr», is_handler«ENDIF»);
+ setState(«langExt.selfPointer(true)»next);
}
- next = «opScopePriv»enterHistory(«langExt.selfPointer(true)»next, «IF usesHdlr»is_handler, «ENDIF»skip_entry);
- setState(«langExt.selfPointer(true)»next);
}
}
'''}
@@ -478,6 +481,7 @@ class GenericStateMachineGenerator {
/**
* @return the type of (temporary) state variables (defaults to "int")
+ * and has to be signed
*/
def protected stateType() {
"int"
@@ -726,7 +730,7 @@ class GenericStateMachineGenerator {
«ENDIF»
* @return - the ID of the final leaf state
*/
- int enterHistory(«self»int state, «IF usesHdlr»«boolType» handler, «ENDIF»«boolType» skip_entry);
+ int enterHistory(«self»int state«IF usesHdlr», «boolType» handler«ENDIF»);
public:
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java
index 611959644..647469872 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java
@@ -107,7 +107,10 @@ public class TransitionChainVisitor implements ITransitionChainVisitor {
}
public String genReturnState(State state, boolean executeEntryCode) {
- return "return " + ((executeEntryCode)?"":"-") + CodegenHelpers.getGenStateId(state) + ";";
+ if (executeEntryCode)
+ return "return " + CodegenHelpers.getGenStateId(state) + ";";
+ else
+ return "return " + CodegenHelpers.getGenStateId(state) + " + STATE_MAX;";
}
public String genTypedData(TransitionChain tc) {
diff --git a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
index d13b9a117..7e9d4e914 100644
--- a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
+++ b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
@@ -110,6 +110,9 @@ public class GenericStateMachineGenerator {
offset = _plus;
}
}
+ String _string = Integer.valueOf(offset).toString();
+ Pair<String,String> _pair_2 = Tuples.<String, String>pair("STATE_MAX", _string);
+ list.add(_pair_2);
return this.langExt.genEnumeration("state_ids", list);
}
@@ -638,22 +641,44 @@ public class GenericStateMachineGenerator {
_builder.append(self, "");
String _stateType_4 = this.stateType();
_builder.append(_stateType_4, "");
- _builder.append(" state, ");
+ _builder.append(" state");
{
if (usesHdlr) {
+ _builder.append(", ");
String _boolType_1 = this.boolType();
_builder.append(_boolType_1, "");
- _builder.append(" handler, ");
+ _builder.append(" handler");
}
}
+ _builder.append(") {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
String _boolType_2 = this.boolType();
- _builder.append(_boolType_2, "");
- _builder.append(" skip_entry) {");
+ _builder.append(_boolType_2, " ");
+ _builder.append(" skip_entry = ");
+ String _booleanConstant = this.langExt.booleanConstant(false);
+ _builder.append(_booleanConstant, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if (state >= STATE_MAX) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("state = state - STATE_MAX;");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("skip_entry = ");
+ String _booleanConstant_1 = this.langExt.booleanConstant(true);
+ _builder.append(_booleanConstant_1, " ");
+ _builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
_builder.append("while (");
- String _booleanConstant = this.langExt.booleanConstant(true);
- _builder.append(_booleanConstant, " ");
+ String _booleanConstant_2 = this.langExt.booleanConstant(true);
+ _builder.append(_booleanConstant_2, " ");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
@@ -822,8 +847,8 @@ public class GenericStateMachineGenerator {
_builder.newLine();
_builder.append("\t\t");
_builder.append("skip_entry = ");
- String _booleanConstant_1 = this.langExt.booleanConstant(false);
- _builder.append(_booleanConstant_1, " ");
+ String _booleanConstant_3 = this.langExt.booleanConstant(false);
+ _builder.append(_booleanConstant_3, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
@@ -881,16 +906,14 @@ public class GenericStateMachineGenerator {
_builder.append("enterHistory(");
String _selfPointer_5 = this.langExt.selfPointer(true);
_builder.append(_selfPointer_5, " ");
- _builder.append("next, ");
+ _builder.append("next");
{
if (usesHdlr) {
- String _booleanConstant_2 = this.langExt.booleanConstant(false);
- _builder.append(_booleanConstant_2, " ");
_builder.append(", ");
+ String _booleanConstant_4 = this.langExt.booleanConstant(false);
+ _builder.append(_booleanConstant_4, " ");
}
}
- String _booleanConstant_3 = this.langExt.booleanConstant(false);
- _builder.append(_booleanConstant_3, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
@@ -956,8 +979,8 @@ public class GenericStateMachineGenerator {
String _boolType_3 = this.boolType();
_builder.append(_boolType_3, " ");
_builder.append(" is_handler = ");
- String _booleanConstant_4 = this.langExt.booleanConstant(false);
- _builder.append(_booleanConstant_4, " ");
+ String _booleanConstant_5 = this.langExt.booleanConstant(false);
+ _builder.append(_booleanConstant_5, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
@@ -1004,13 +1027,16 @@ public class GenericStateMachineGenerator {
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t\t\t");
String _stateType_7 = this.stateType();
- _builder.append(_stateType_7, " ");
+ _builder.append(_stateType_7, " ");
_builder.append(" next = ");
- _builder.append(opScopePriv, " ");
+ _builder.append(opScopePriv, " ");
_builder.append("executeTransitionChain(");
String _selfPointer_10 = this.langExt.selfPointer(true);
- _builder.append(_selfPointer_10, " ");
+ _builder.append(_selfPointer_10, " ");
_builder.append("chain");
{
if (handleEvents) {
@@ -1019,49 +1045,29 @@ public class GenericStateMachineGenerator {
}
_builder.append(");");
_builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- String _boolType_4 = this.boolType();
- _builder.append(_boolType_4, " ");
- _builder.append(" skip_entry = ");
- String _booleanConstant_5 = this.langExt.booleanConstant(false);
- _builder.append(_booleanConstant_5, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("if(next < 0){");
- _builder.newLine();
_builder.append("\t\t\t");
- _builder.append("next = -next;");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("skip_entry = ");
- String _booleanConstant_6 = this.langExt.booleanConstant(true);
- _builder.append(_booleanConstant_6, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
_builder.append("next = ");
- _builder.append(opScopePriv, " ");
+ _builder.append(opScopePriv, " ");
_builder.append("enterHistory(");
String _selfPointer_11 = this.langExt.selfPointer(true);
- _builder.append(_selfPointer_11, " ");
- _builder.append("next, ");
+ _builder.append(_selfPointer_11, " ");
+ _builder.append("next");
{
if (usesHdlr) {
- _builder.append("is_handler, ");
+ _builder.append(", is_handler");
}
}
- _builder.append("skip_entry);");
+ _builder.append(");");
_builder.newLineIfNotEmpty();
- _builder.append("\t\t");
+ _builder.append("\t\t\t");
_builder.append("setState(");
String _selfPointer_12 = this.langExt.selfPointer(true);
- _builder.append(_selfPointer_12, " ");
+ _builder.append(_selfPointer_12, " ");
_builder.append("next);");
_builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
@@ -1438,6 +1444,7 @@ public class GenericStateMachineGenerator {
/**
* @return the type of (temporary) state variables (defaults to "int")
+ * and has to be signed
*/
protected String stateType() {
return "int";
@@ -2015,17 +2022,16 @@ public class GenericStateMachineGenerator {
_builder.append("\t");
_builder.append("int enterHistory(");
_builder.append(self, " ");
- _builder.append("int state, ");
+ _builder.append("int state");
{
if (usesHdlr) {
+ _builder.append(", ");
String _boolType_1 = this.boolType();
_builder.append(_boolType_1, " ");
- _builder.append(" handler, ");
+ _builder.append(" handler");
}
}
- String _boolType_2 = this.boolType();
- _builder.append(_boolType_2, " ");
- _builder.append(" skip_entry);");
+ _builder.append(");");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("public:");

Back to the top