Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.generator/src')
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DefaultTranslationProvider.java65
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DetailCodeTranslator.java11
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ITranslationProvider.java35
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/RoomExtensions.xtend52
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend27
5 files changed, 146 insertions, 44 deletions
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DefaultTranslationProvider.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DefaultTranslationProvider.java
new file mode 100644
index 000000000..7bbee1bca
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DefaultTranslationProvider.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.Operation;
+
+public class DefaultTranslationProvider implements ITranslationProvider {
+
+ @Override
+ public boolean translateMembers() {
+ return false;
+ }
+
+ @Override
+ public String getAttributeText(Attribute att, String orig) {
+ return orig;
+ }
+
+ @Override
+ public String getOperationText(Operation op, ArrayList<String> args, String orig) {
+ return orig;
+ }
+
+ @Override
+ public String getInterfaceItemMessageText(InterfaceItem item, Message msg, ArrayList<String> args, String orig) {
+ return orig;
+ }
+
+ @Override
+ public String getInterfaceItemMessageValue(InterfaceItem item, Message msg, String orig) {
+ return orig;
+ }
+
+ @Override
+ public boolean translateTags() {
+ return false;
+ }
+
+ @Override
+ public String translateTag(String tag, DetailCode code) {
+ return DetailCodeTranslator.TAG_START+tag+DetailCodeTranslator.TAG_END;
+ }
+
+ @Override
+ public void setActorClass(ActorClass ac) {
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DetailCodeTranslator.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DetailCodeTranslator.java
index de63454f3..88b164205 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DetailCodeTranslator.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/DetailCodeTranslator.java
@@ -33,17 +33,6 @@ public class DetailCodeTranslator {
public static final String TAG_START = "<|";
public static final String TAG_END = "|>";
- public static interface ITranslationProvider {
- boolean translateMembers();
- String getAttributeText(Attribute att, String orig);
- String getOperationText(Operation op, ArrayList<String> args, String orig);
- String getInterfaceItemMessageText(InterfaceItem item, Message msg, ArrayList<String> args, String orig);
- String getInterfaceItemMessageValue(InterfaceItem item, Message msg, String orig);
-
- boolean translateTags();
- String translateTag(String tag, DetailCode code);
- }
-
private static class Position {
int pos = 0;
}
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ITranslationProvider.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ITranslationProvider.java
new file mode 100644
index 000000000..bc42b4b2b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ITranslationProvider.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.base;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.Operation;
+
+public interface ITranslationProvider {
+ void setActorClass(ActorClass ac);
+
+ boolean translateMembers();
+ String getAttributeText(Attribute att, String orig);
+ String getOperationText(Operation op, ArrayList<String> args, String orig);
+ String getInterfaceItemMessageText(InterfaceItem item, Message msg, ArrayList<String> args, String orig);
+ String getInterfaceItemMessageValue(InterfaceItem item, Message msg, String orig);
+
+ boolean translateTags();
+ String translateTag(String tag, DetailCode code);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/RoomExtensions.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/RoomExtensions.xtend
index 34e418d15..eca848fea 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/RoomExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/RoomExtensions.xtend
@@ -45,6 +45,7 @@ import org.eclipse.etrice.core.room.RoomModel
import org.eclipse.etrice.generator.etricegen.ActiveTrigger
import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
import org.eclipse.etrice.generator.etricegen.TransitionChain
+import org.eclipse.etrice.generator.base.DetailCodeTranslator
import static extension org.eclipse.etrice.generator.extensions.RoomNameProv.*
@@ -63,6 +64,13 @@ class RoomExtensions {
ret.addAll(l2)
return ret
}
+
+ def <T> Iterable<T> union(Iterable<T> l1, Iterable<T> l2) {
+ var ret = new ArrayList<T>()
+ ret.addAll(l1)
+ ret.addAll(l2)
+ return ret
+ }
def List<Port> punion(List<Port> in1, List<ExternalPort> in2){
var ret=new ArrayList<Port>();
@@ -192,21 +200,15 @@ class RoomExtensions {
// protocol related methods
def String getPortClassName(ProtocolClass p, boolean conj) {
- var ret=p.name
- if(conj) {
- ret=ret+"ConjPort"
- }else{
- ret=ret+"Port"
- }
- return ret
+ getPortClassName(p, conj, false)
+ }
+
+ def String getPortClassName(ProtocolClass p, boolean conj, boolean repl) {
+ p.name + (if (conj) "Conj" else "") + (if (repl) "Repl" else "") +"Port"
}
def String getPortClassName(Port p){
- var ret=p.protocol.getPortClassName(p.conjugated)
- if (p.replicated){
- ret = ret+"Repl"
- }
- return ret
+ p.protocol.getPortClassName(p.conjugated, p.replicated)
}
def String getPortClassName(ExternalPort p){
@@ -446,37 +448,39 @@ class RoomExtensions {
return hasGuard
}
+ // TODO. in the following methods handle inheritance language independent and proper
+
def boolean hasEntryCode(State s) {
- return s.entryCode!=null && s.entryCode.commands.size>0
+ s.entryCode!=null && s.entryCode.commands.size>0
}
def boolean hasExitCode(State s) {
- return s.exitCode!=null && s.exitCode.commands.size>0
+ s.exitCode!=null && s.exitCode.commands.size>0
}
- def String getEntryCode(ExpandedActorClass ac, State s) {
+ def String getEntryCode(ExpandedActorClass ac, State s, DetailCodeTranslator dct) {
if (s instanceof RefinedState)
- return "super."+s.getEntryCodeOperationName()+"();\n"+ac.getCode(s.entryCode)
+ "super."+s.getEntryCodeOperationName()+"();\n"+ac.getCode(s.entryCode)
else
- return ac.getCode(s.entryCode)
+ dct.translateDetailCode(s.entryCode)
}
- def String getExitCode(ExpandedActorClass ac, State s) {
+ def String getExitCode(ExpandedActorClass ac, State s, DetailCodeTranslator dct) {
if (s instanceof RefinedState)
- return ac.getCode(s.exitCode)+"super."+s.getEntryCodeOperationName()+"();\n"
+ ac.getCode(s.exitCode)+"super."+s.getEntryCodeOperationName()+"();\n"
else
- ac.getCode(s.exitCode)
+ dct.translateDetailCode(s.exitCode)
}
def boolean hasActionCode(Transition t) {
- return t.action!=null && t.action.commands.size>0
+ t.action!=null && t.action.commands.size>0
}
- def String getActionCode(ExpandedActorClass ac, Transition t) {
- return ac.getCode(t.action)
+ def String getActionCode(ExpandedActorClass ac, Transition t, DetailCodeTranslator dct) {
+ dct.translateDetailCode(t.action)
}
def String getContextId(TransitionChain tc) {
- return tc.getStateContext().getStateId()
+ tc.getStateContext().getStateId()
}
def Transition getInitTransition(StateGraph sg) {
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 bf81f38b3..2dbb1de1a 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
@@ -20,6 +20,8 @@ import org.eclipse.etrice.core.room.TriggeredTransition
import org.eclipse.etrice.core.room.NonInitialTransition
import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
import org.eclipse.etrice.generator.extensions.RoomExtensions
+import org.eclipse.etrice.generator.base.DetailCodeTranslator
+import org.eclipse.etrice.generator.base.ITranslationProvider
import static extension org.eclipse.etrice.generator.extensions.RoomNameProv.*
import org.eclipse.xtext.util.Pair
import static org.eclipse.xtext.util.Tuples.*
@@ -30,6 +32,7 @@ class GenericStateMachineGenerator {
@Inject public extension RoomExtensions roomExt
@Inject public extension GenericProtocolClassGenerator pcGen
@Inject public extension LanguageGenerator languageGen
+ @Inject public ITranslationProvider translator
def private genStateIdConstants(ExpandedActorClass xpac, ActorClass ac) {
// with inheritance we exclude inherited base states
@@ -80,7 +83,11 @@ class GenericStateMachineGenerator {
return langExt.genEnumeration("triggers", list)
}
- def genStateMachine(ExpandedActorClass xpac, ActorClass ac) {'''
+ def genStateMachine(ExpandedActorClass xpac, ActorClass ac) {
+ translator.setActorClass(ac)
+ var dct = new DetailCodeTranslator(ac, translator)
+
+ '''
/* state IDs */
«genStateIdConstants(xpac, ac)»
@@ -98,12 +105,12 @@ class GenericStateMachineGenerator {
«IF xpac.isOwnObject(state)»
«IF state.hasEntryCode()»
«langExt.accessLevelProtected»void «state.getEntryCodeOperationName()»(«langExt.selfPointer(ac.name, false)») {
- «xpac.getEntryCode(state)»
+ «xpac.getEntryCode(state, dct)»
}
«ENDIF»
«IF state.hasExitCode()»
«langExt.accessLevelProtected»void «state.getExitCodeOperationName()»(«langExt.selfPointer(ac.name, false)») {
- «xpac.getExitCode(state)»
+ «xpac.getExitCode(state, dct)»
}
«ENDIF»
«ENDIF»
@@ -113,7 +120,7 @@ class GenericStateMachineGenerator {
«FOR tr : xpac.stateMachine.getTransitionList()»
«IF xpac.isOwnObject(tr) && tr.hasActionCode()»
«langExt.accessLevelProtected»void «tr.getActionCodeOperationName()»(«langExt.selfPointer(ac.name, tr instanceof NonInitialTransition)»«IF tr instanceof NonInitialTransition»InterfaceItemBase ifitem«languageGen.getArgumentList(xpac, tr)»«ENDIF») {
- «xpac.getActionCode(tr)»
+ «xpac.getActionCode(tr, dct)»
}
«ENDIF»
«ENDFOR»
@@ -230,7 +237,7 @@ class GenericStateMachineGenerator {
«IF needData»{ «at.msg.getTypedDataDefinition()»«ENDIF»
«FOR tt : at.transitions SEPARATOR " else "»
«var chain = xpac.getChain(tt)»
- «guard(chain.transition, at.trigger, xpac)»
+ «guard(chain.transition, at.trigger, xpac, dct)»
{
chain = «chain.getChainId()»;
catching_state = «chain.getContextId()»;
@@ -262,15 +269,17 @@ class GenericStateMachineGenerator {
def genExtra(ExpandedActorClass xpac, ActorClass ac) {''''''}
- def private dispatch guard(TriggeredTransition tt, String trigger, ExpandedActorClass ac) {'''
- «var tr = tt.triggers.findFirst(e|ac.isMatching(e, trigger))»
+ def private dispatch guard(TriggeredTransition tt, String trigger, ExpandedActorClass ac, DetailCodeTranslator dct) {
+ var tr = tt.triggers.findFirst(e|ac.isMatching(e, trigger))
+ '''
«IF tr.hasGuard()»
- if («ac.getCode(tr.guard.guard)»)
+ if («dct.translateDetailCode(tr.guard.guard)»)
«ENDIF»
'''
}
- def private dispatch guard(Transition t, String trigger, ExpandedActorClass ac) {'''
+ def private dispatch guard(Transition t, String trigger, ExpandedActorClass ac, DetailCodeTranslator dct) {
+ '''
/* error */
'''
}

Back to the top