Просмотр исходного кода

Initial setup for code generator for c

jos.itemis@gmail.com 14 лет назад
Родитель
Сommit
f9c8fc4aa8
48 измененных файлов с 2644 добавлено и 0 удалено
  1. 7 0
      plugins/org.yakindu.sct.generator.c/.classpath
  2. 34 0
      plugins/org.yakindu.sct.generator.c/.project
  3. 4 0
      plugins/org.yakindu.sct.generator.c/.settings/org.eclipse.core.resources.prefs
  4. 2 0
      plugins/org.yakindu.sct.generator.c/.settings/org.eclipse.xtend.shared.ui.prefs
  5. 23 0
      plugins/org.yakindu.sct.generator.c/META-INF/MANIFEST.MF
  6. 31 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CMakeLists.xpt
  7. 42 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CustomEventH.xpt
  8. 83 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CustomRepositoryH.xpt
  9. 169 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CustomStatemachineCPP.xpt
  10. 94 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CustomStatemachineH.xpt
  11. 25 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/EventC.xpt
  12. 31 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/EventH.xpt
  13. 69 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/EventSetC.xpt
  14. 43 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/EventSetH.xpt
  15. 84 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Expression.ext
  16. 57 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Main.xpt
  17. 44 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Naming.ext
  18. 49 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/StatemachineBaseC.xpt
  19. 46 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/StatemachineBaseH.xpt
  20. 51 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/StatemachineH.xpt
  21. 93 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Statemachine_cyC.xpt
  22. 55 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Statemachine_cyH.xpt
  23. 112 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/TestMain.xpt
  24. 33 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/TimerC.xpt
  25. 38 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/TimerH.xpt
  26. 37 0
      plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/definitionH.xpt
  27. 2 0
      plugins/org.yakindu.sct.generator.c/build.properties
  28. 31 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CMakeLists.xpt
  29. 42 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomEventH.xpt
  30. 83 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomRepositoryH.xpt
  31. 169 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineCPP.xpt
  32. 94 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineH.xpt
  33. 25 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventC.xpt
  34. 31 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventH.xpt
  35. 69 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventSetC.xpt
  36. 43 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventSetH.xpt
  37. 84 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Expression.ext
  38. 57 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Main.xpt
  39. 44 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Naming.ext
  40. 49 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/StatemachineBaseC.xpt
  41. 46 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/StatemachineBaseH.xpt
  42. 51 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/StatemachineH.xpt
  43. 93 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyC.xpt
  44. 55 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyH.xpt
  45. 112 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/TestMain.xpt
  46. 33 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/TimerC.xpt
  47. 38 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/TimerH.xpt
  48. 37 0
      plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/definitionH.xpt

+ 7 - 0
plugins/org.yakindu.sct.generator.c/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 34 - 0
plugins/org.yakindu.sct.generator.c/.project

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.generator.c</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.xtend.shared.ui.xtendBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.xtend.shared.ui.xtendXPandNature</nature>
+	</natures>
+</projectDescription>

+ 4 - 0
plugins/org.yakindu.sct.generator.c/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,4 @@
+#Fri Sep 09 10:16:39 CEST 2011
+eclipse.preferences.version=1
+encoding//.settings/org.eclipse.xtend.shared.ui.prefs=Cp1252
+encoding/<project>=Cp1252

+ 2 - 0
plugins/org.yakindu.sct.generator.c/.settings/org.eclipse.xtend.shared.ui.prefs

@@ -0,0 +1,2 @@
+metamodelContributor=org.eclipse.xtend.typesystem.emf.ui.EmfMetamodelContributor
+project.specific.metamodel=true

+ 23 - 0
plugins/org.yakindu.sct.generator.c/META-INF/MANIFEST.MF

@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Yakindu SCT C++ Generator
+Bundle-SymbolicName: org.yakindu.sct.generator.cpp; singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Require-Bundle: org.yakindu.sct.model.sexec,
+ org.eclipse.jdt.core,
+ org.eclipse.xtend.profiler;resolution:=optional,
+ org.apache.commons.logging,
+ org.apache.log4j;resolution:=optional,
+ com.ibm.icu,
+ org.antlr.runtime,
+ org.eclipse.core.runtime,
+ org.eclipse.emf.mwe.utils,
+ org.eclipse.emf.ecore.xmi,
+ org.eclipse.jface.text,
+ org.eclipse.xpand,
+ org.eclipse.xtend,
+ org.eclipse.xtend.typesystem.emf,
+ org.yakindu.sct.model.stext
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.yakindu.sct.generator.cpp.templates
+Bundle-Vendor: YAKINDU

+ 31 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CMakeLists.xpt

@@ -0,0 +1,31 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'CMakeLists.txt'»
+cmake_minimum_required(VERSION 2.8)
+
+set(SRC
+	Statemachine.cpp
+	«StName()».cpp
+	main.cpp
+)
+
+add_definitions( -Wall -O0 -g)
+add_executable(«StName()»Main ${SRC})
+«ENDFILE»
+
+«ENDDEFINE»

+ 42 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CustomEventH.xpt

@@ -0,0 +1,42 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE EvName()+'.h'»
+#ifndef «EVNAME()»_H_
+#define «EVNAME()»_H_
+
+#include "Event.h"
+
+enum EventID {
+«FOREACH this.declaredEvents() AS ev»
+  _«((EventDefinition)ev).name.toLowerCase()»,
+«ENDFOREACH»
+	event_last
+};
+
+«FOREACH this.declaredEvents() AS ev»
+  class «((EventDefinition)ev).name» : public _Event { public: «((EventDefinition)ev).name»() : _Event((uint32_t)_«((EventDefinition)ev).name.toLowerCase()») {} };
+  // internal variables unhandled
+«ENDFOREACH»
+ 
+
+#endif /* «name.toUpperCase()»_H_ */
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 83 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CustomRepositoryH.xpt

@@ -0,0 +1,83 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+
+«DEFINE interfaces FOR ExecutionFlow»
+«EXPAND scope FOREACH this.scopes»
+«ENDDEFINE»
+
+«DEFINE scope FOR Scope -»
+«ENDDEFINE»
+
+«DEFINE scope FOR InterfaceScope»
+«EXPAND declaration FOREACH this.declarations»
+«ENDDEFINE»
+
+«DEFINE scope FOR InternalScope»
+«EXPAND declaration FOREACH this.declarations»
+«ENDDEFINE»
+
+«DEFINE declaration FOR Declaration -»
+	// unknown declaration «name»
+«ENDDEFINE»
+
+«DEFINE declaration FOR EventDefinition -»
+«ENDDEFINE»
+
+«DEFINE declaration FOR VariableDefinition -»
+	«type» «name»; 
+«ENDDEFINE»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE DRName()+'.h'»
+#ifndef «DRNAME()»_H_
+#define «DRNAME()»_H_
+
+#include "definition.h"
+#include "DataRepository.h"
+
+class «DRName()» : public DataRepository {
+
+«FOREACH this.declaredVariables() AS variable»
+    «((VariableDefinition)variable).type» «((VariableDefinition)variable).name»;
+«ENDFOREACH»
+
+public:
+
+	«DRName()»() : 
+«FOREACH this.declaredVariables() AS variable SEPARATOR ','-»
+ «((VariableDefinition)variable).name»(0)«
+ENDFOREACH»
+	{};
+	virtual ~«DRName()»() {};
+	
+«FOREACH this.declaredVariables() AS variable»
+    «((VariableDefinition)variable).type» get_«((VariableDefinition)variable).name»()
+    { «((VariableDefinition)variable).type» value; lock(); value = «((VariableDefinition)variable).name»; unlock(); return value; }
+«ENDFOREACH»
+
+«FOREACH this.declaredVariables() AS variable»
+    void set_«((VariableDefinition)variable).name»(const «((VariableDefinition)variable).type»& value)
+    { lock(); «((VariableDefinition)variable).name» =  value; unlock(); }
+«ENDFOREACH»
+
+};
+
+#endif /* «DRNAME()»_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 169 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CustomStatemachineCPP.xpt

@@ -0,0 +1,169 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+«IMPORT ecore»
+
+«IMPORT org::yakindu::sct::generator::c::templates»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+«DEFINE ActionCode FOR Step»
+// ActionCode for Step not defined
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Execution»
+	«this.statement.toCppCode()»
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Call»
+«this.step.functionName()»();
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Sequence»
+  «EXPAND ActionCode FOREACH this.steps»
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Check -»
+  «IF this != null -»
+«this.condition.toCppCode() -»
+  «ELSE -»
+ true «
+ ENDIF -»«
+  ENDDEFINE»
+
+«DEFINE ActionCode FOR CheckRef -»
+  «IF this.check != null -»
+  «this.check.functionName()»(ev) «
+  ELSE -»
+ true «
+  ENDIF -»«
+ENDDEFINE»
+
+«DEFINE ActionCode FOR Reaction»
+  «EXPAND ActionCode FOR this.effect» 
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR If»
+if («EXPAND ActionCode FOR this.check») { 
+  «EXPAND ActionCode FOR this.thenStep»
+}
+else {
+  «EXPAND ActionCode FOR this.elseStep»
+}
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR EnterState»
+state[0] = _«this.state.simpleName»;
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR ExitState»
+state[0] = last_state;
+«ENDDEFINE»
+
+«DEFINE ConditionMethodsImplement FOR ExecutionState»
+  «FOREACH reactions AS r»
+  «IF r.check != null -»
+bool «StName()»::«r.check.functionName()»(const _Event& ev) {
+  return (	«r.check.condition.toCppCode()» );
+}
+  «ENDIF -»
+  «ENDFOREACH»
+«ENDDEFINE»
+
+«DEFINE StatementMethodsImplement FOR ExecutionState»
+  «FOREACH reactions AS r»
+void «this.StName()»::«r.effect.functionName()»() {
+  «EXPAND ActionCode FOR r.effect»
+}
+  «ENDFOREACH»
+«ENDDEFINE»
+
+«DEFINE CycleCode FOR Cycle» 
+«EXPAND ActionCode FOREACH this.steps»
+«ENDDEFINE»
+
+«DEFINE CycleMethodsImplement FOR ExecutionState»
+void «StName()»::cycle_«this.simpleName»(const _Event& ev)
+{
+	«EXPAND CycleCode FOR cycle»
+}
+«ENDDEFINE»
+
+«DEFINE EnterMethodImplement FOR ExecutionState»
+«IF this.entryAction != null»
+void «StName()»::«this.entryAction.entryActionFunctionName()»()
+{
+«EXPAND ActionCode FOR this.entryAction»
+}
+«ENDIF»
+«ENDDEFINE»
+
+«DEFINE ExitMethodImplement FOR ExecutionState»
+«IF this.exitAction != null»
+void «StName()»::«this.exitAction.exitActionFunctionName()»()
+{
+«EXPAND ActionCode FOR this.exitAction»
+}
+«ENDIF»
+«ENDDEFINE»
+
+«DEFINE file FOR ExecutionFlow»
+«FILE StName()+'.cpp'»
+#include <iostream>
+#include "«StName()».h"
+
+«StName()»::«StName()»() : Statemachine(«((ExecutionFlow)this.eRootContainer).stateVector.size») {
+}
+
+«StName()»::~«StName()»() {
+}
+
+«EXPAND ConditionMethodsImplement FOREACH this.states»
+
+«EXPAND StatementMethodsImplement FOREACH this.states»
+
+«EXPAND CycleMethodsImplement FOREACH this.states»
+
+«EXPAND EnterMethodImplement FOREACH this.states»
+
+«EXPAND ExitMethodImplement FOREACH this.states»
+
+
+void «StName()»::init()
+{
+	«EXPAND ActionCode FOREACH this.enterSequence.steps»
+}
+
+/* Yet unimplemented
+void «StName()»::exit()
+{
+}
+*/
+
+void «StName()»::_runCycle(Event ev)
+{
+	for (int i=0; i<MAX_PARALLEL_STATES; ++i) {
+		switch(state[i]) {
+	«FOREACH this.states AS state»
+	    case _«state.simpleName»:
+	        cycle_«state.simpleName»(*ev);
+	        break;
+	«ENDFOREACH»
+		default:
+			/* no state found */
+			break;
+		}
+	}
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 94 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/CustomStatemachineH.xpt

@@ -0,0 +1,94 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE StName()+'.h'»
+#ifndef «STNAME()»_H_
+#define «STNAME()»_H_
+
+#include "Statemachine.h"
+#include "«DRName()».h"
+#include "«EvName()».h"
+
+
+#define MAX_PARALLEL_STATES «this.stateVector.size»
+
+class «StName()»: public Statemachine, public «DRName()» {
+
+public:
+	enum States {
+	    «FOREACH this.states AS exState-»
+	      _«exState.simpleName»,
+	    «ENDFOREACH»
+		last_state
+	};
+
+protected:
+	/* conditions */
+	«FOREACH states AS state -»
+	  «FOREACH state.reactions AS reaction -»
+	  «IF reaction.check != null -»
+	bool «reaction.check.functionName()»(const _Event& event);
+	  «ENDIF»
+	  «ENDFOREACH»
+	«ENDFOREACH»
+	
+	/* actions */
+	«FOREACH states AS state -»
+	  «FOREACH state.reactions AS reaction -»
+	void «reaction.effect.functionName()»();
+	  «ENDFOREACH»
+	«ENDFOREACH»
+
+	/* cycles */
+	«FOREACH states AS state -»
+	void cycle_«state.simpleName»(const _Event& ev);
+	«ENDFOREACH»
+	
+	/* entrys */
+	«FOREACH states AS state -»
+	«IF state.entryAction != null»
+	void «state.entryAction.entryActionFunctionName()»();
+	«ENDIF»
+	«ENDFOREACH»
+	
+	/*exits */
+	«FOREACH states AS state -»
+	«IF state.exitAction != null»
+	void «state.exitAction.exitActionFunctionName()»();
+	«ENDIF»
+	«ENDFOREACH»
+	
+	virtual void _runCycle(Event ev);
+
+public:
+
+	«StName()»();
+	virtual ~«StName()»();
+
+	virtual void init();
+
+	//virtual void queueEvent(const Event& ev);
+
+};
+
+//}; // namespace
+#endif /* «STNAME()»_H_ */
+
+«ENDFILE»
+
+«ENDDEFINE»
+

+ 25 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/EventC.xpt

@@ -0,0 +1,25 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Event.c'»
+#include "Event.h"
+
+void _event_init(_Event* handle, uint32_t id)
+{
+	handle->id = id;
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 31 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/EventH.xpt

@@ -0,0 +1,31 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Event.h'»
+#ifndef EVENT_H_
+#define EVENT_H_
+
+#include "definition.h"
+
+typedef struct {
+  uint32_t id;
+} _Event;
+
+extern void _event_init(_Event* handle, uint32_t id);
+
+#endif /* EVENT_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 69 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/EventSetC.xpt

@@ -0,0 +1,69 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'EventSet.c'»
+#include "EventSet.h"
+#include <stdlib.h>
+
+void eventSet_init(EventSet* handle, const uint32_t _maxEvents) {
+	handle->isStaticData = bool_false;
+	handle->maxEvents = _maxEvents;
+	handle->_set = malloc(sizeof(boolean) * _maxEvents);
+	eventSet_clean(handle);
+}
+
+void eventSet_init_staticData(EventSet* handle, const uint32_t _maxEvents,
+		boolean* _dataSet) {
+	handle->isStaticData = bool_true;
+	handle->maxEvents = _maxEvents;
+	handle->_set = _dataSet;
+}
+
+void eventSet_exit(EventSet* handle) {
+	if (!handle->isStaticData)
+		free(handle->_set);
+	handle->maxEvents = 0;
+}
+
+boolean eventSet_check(EventSet* handle, const uint32_t evid) {
+	if (evid < handle->maxEvents) {
+		return handle->_set[evid];
+	}
+	return (bool_false);
+}
+
+void eventSet_clean(EventSet* handle) {
+	uint32_t i;
+	for (i = 0; i < handle->maxEvents; ++i)
+		handle->_set[i] = bool_false;
+}
+
+void eventSet_set(EventSet* handle, const uint32_t evid) {
+	if (evid < handle->maxEvents) {
+		handle->_set[evid] = bool_true;
+	}
+}
+
+boolean eventSet_isAny(EventSet* handle) {
+	uint32_t i;
+	for (i = 0; i < handle->maxEvents; ++i)
+		if (handle->_set[i])
+			return (bool_true);
+	return (bool_false);
+}
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 43 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/EventSetH.xpt

@@ -0,0 +1,43 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'EventSet.h'»
+#ifndef EVENTSET_H_
+#define EVENTSET_H_
+
+#include "definition.h"
+
+typedef struct {
+	boolean* _set;
+	uint32_t maxEvents;
+	boolean isStaticData;
+} EventSet;
+
+/* constructor and destructor */
+extern void eventSet_init(EventSet* handle, const uint32_t maxEvents);
+extern void eventSet_init_staticData(EventSet* handle, const uint32_t maxEvents,
+		boolean* _dataSet);
+extern void eventSet_exit(EventSet* handle);
+
+
+extern boolean eventSet_check(EventSet* handle, const uint32_t evid);
+extern void eventSet_clean(EventSet* handle);
+extern void eventSet_set(EventSet* handle, const uint32_t evid);
+extern boolean eventSet_isAny(EventSet* handle);
+
+#endif /* EVENTSET_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 84 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Expression.ext

@@ -0,0 +1,84 @@
+import stext;
+import sexec;
+import ecore;
+import sgraph;
+toCppCode(Void void) :
+	"/*toCppCode() called with NULL element. Polymorphic resolver could not match callable method!*/";
+String toCppCode(Void o, String statechartReference) : 
+	""; //polymorphic placeholder (abstract rule)
+
+String toCppCode(Expression statement) : 
+	null; //polymorphic placeholder (abstract rule)
+ 
+String toCppCode(Statement statement) : 
+	null; //polymorphic placeholder (abstract rule)
+ 
+String toCppCode(PrimitiveValueExpression primValue) :
+	primValue.value;
+
+/* Assignment */
+String toCppCode(Assignment assignment) :
+  switch (assignment.operator) {
+  case (AssignmentOperator::assign) : "set_" + assignment.varRef.name + "(" + assignment.expression.toCppCode() + ");"  
+  case (AssignmentOperator::multAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() * (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::divAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() / (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::modAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() % (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::addAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() + (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::subAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() - (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::leftShiftAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() << ("+ assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::rightShiftAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() >> (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::andAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() & (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::xorAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() ^ (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::orAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() ^ (" + assignment.expression.toCppCode() + "));"
+  default : ""
+  };
+		
+/* EventRaising */
+
+/* Logical Expressions */
+String toCppCode(LogicalOrExpression expression) :
+  	expression.leftOperand.toCppCode() + " || " + expression.rightOperand.toCppCode();
+  	
+String toCppCode(LogicalAndExpression expression) :
+  	expression.leftOperand.toCppCode() + " && " + expression.rightOperand.toCppCode();
+
+String toCppCode(LogicalNotExpression expression) :
+  	" ^" + expression.operand.toCppCode();
+
+String toCppCode(LogicalRelationExpression expression) :
+   expression.leftOperand.toCppCode() + " ??? " + expression.rightOperand.toCppCode();
+    
+String toCppCode(BitwiseAndExpression expression) :
+  	expression.leftOperand.toCppCode() + " & " + expression.rightOperand.toCppCode();
+
+String toCppCode(BitwiseOrExpression expression) :
+  	expression.leftOperand.toCppCode() + " | " + expression.rightOperand.toCppCode();
+
+String toCppCode(BitwiseXorExpression expression) :
+  	expression.leftOperand.toCppCode() + " ^ " + expression.rightOperand.toCppCode();
+
+String toCppCode(NumericalAddSubtractExpression expression) :
+  	expression.leftOperand.toCppCode() + getOperator(expression.operator) + expression.rightOperand.toCppCode();
+  	
+String toCppCode(NumericalMultiplyDivideExpression expression) :
+  	expression.leftOperand.toCppCode() + getOperator(expression.operator) + expression.rightOperand.toCppCode();
+
+// is this just relevant for events?
+String toCppCode(ElementReferenceExpression ev) :
+    " ( _" + ev.value.name.toLowerCase() + " == ev.getID() ) ";
+
+String getOperator(AdditiveOperator operator) : 
+    switch(operator) {
+    	case(AdditiveOperator::plus) : " + "
+    	case(AdditiveOperator::minus) : " - "
+    	default : ""
+    };
+
+String getOperator(MultiplicativeOperator operator) : 
+    switch(operator) {
+    	case(MultiplicativeOperator::mul) : " * "
+    	case(MultiplicativeOperator::div) : " / "
+    	case(MultiplicativeOperator::mod) : " % "
+    	default : ""
+    };
+

+ 57 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Main.xpt

@@ -0,0 +1,57 @@
+«REM»
+
+Contais the root templates that call the different file templates.
+
+@author andreas muelder
+@auther axel terfloth
+@author joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«IMPORT org::yakindu::sct::generator::c::templates»
+
+«DEFINE main FOR ExecutionFlow»
+
+	«REM» basis files «ENDREM»
+	«EXPAND EventH::file FOR this»
+	«EXPAND EventC::file FOR this»
+
+	«EXPAND TimerH::file FOR this»
+	«EXPAND TimerC::file FOR this»
+
+	«EXPAND EventSetH::file FOR this»
+	«EXPAND EventSetC::file FOR this»
+
+	«EXPAND StatemachineBaseH::file FOR this»
+	«EXPAND StatemachineBaseC::file FOR this»
+
+	«EXPAND Statemachine_cyH::file FOR this»
+	«EXPAND Statemachine_cyC::file FOR this»
+
+
+
+    «REM» code that is created by the model «ENDREM»
+	«EXPAND definitionH::file FOR this»
+
+	«EXPAND EventPoolH::file FOR this»
+	«EXPAND EventPoolC::file FOR this»
+
+	«EXPAND CustomStatemachineH::file FOR this»
+	«EXPAND CustomStatemachineCPP::file FOR this»
+	«EXPAND CustomRepositoryH::file FOR this»
+	«EXPAND CustomEventH::file FOR this»
+	
+	«EXPAND CMakeLists::file FOR this»
+	«EXPAND TestMain::file FOR this»
+
+
+	«EXPAND Dump::file FOR this»
+	
+«ENDDEFINE»
+
+
+

+ 44 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Naming.ext

@@ -0,0 +1,44 @@
+import stext;
+import sexec;
+import ecore;
+import sgraph;
+
+
+String scName(Expression statement) : ((ExecutionFlow)statement.eRootContainer).name ;
+
+List declaredEvents(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(EventDefinition);
+
+List declaredVariables(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(VariableDefinition);
+
+String test(NamedElement obj) :  "";
+String StName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Statemachine";
+String STNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "STATEMACHINE";
+
+String DRName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "DataRepository";
+String DRNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "DATAREPOSITORY";
+
+String EvName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Event";
+String EVNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "EVENT";
+
+cached String functionName(Step step) : 
+	(step.isEffect()) ? step.actionFunctionName() : (
+	(step.isReactionCheck()) ? step.checkFunctionName() : (
+	(step.isEntryAction()) ? step.entryActionFunctionName() : ( 
+	(step.isExitAction()) ? step.exitActionFunctionName() : 
+	" !! unknown function type !!" )));
+ 
+String actionFunctionName(Step this) : "actions_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
+String checkFunctionName(Step this) : "condition_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
+String entryActionFunctionName(Step this) : "entryActions_" + this.state().simpleName; 
+String exitActionFunctionName(Step this) : "exitActions_" + this.state().simpleName; 
+
+boolean isEffect(Step step) : (! Check.isInstance(step)) && Reaction.isInstance(step.eContainer) ;
+boolean isReactionCheck(Step step) : Reaction.isInstance(step.eContainer) && Check.isInstance(step);
+boolean isEntryAction(Step step) : ExecutionState.isInstance(step.eContainer) && step.state().entryAction == step;
+boolean isExitAction(Step step) : ExecutionState.isInstance(step.eContainer) && step.state().exitAction == step;
+
+Reaction reaction(Step this) : (Reaction) this.eContainer ;
+ExecutionState state(Reaction this) : (ExecutionState) eContainer;
+ExecutionState state(Step this) : (ExecutionState) eContainer;
+
+

+ 49 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/StatemachineBaseC.xpt

@@ -0,0 +1,49 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'StatemachineBase.c'»
+#include "StatemachineBase.h"
+#include <stdlib.h>
+
+void statemachineBase_init(StatemachineBase* handle, uint16_t maxStates, Timer* _timer)
+{
+	handle->isStaticData = bool_false;
+	handle->timer = _timer;
+	handle->state = malloc(sizeof(uint32_t)*maxStates); /* memory allocation for all states */
+	handle->statePtr = 0; /* actual state referencer */
+}
+
+void statemachineBase_init_staticData(StatemachineBase* handle, uint32_t* staticData, Timer* _timer)
+{
+	handle->isStaticData = bool_true;
+	handle->timer = _timer;
+	handle->state = staticData;
+	handle->statePtr = 0; /* actual state referencer */
+}
+
+void statemachineBase_exit(StatemachineBase* handle) {
+	if (!handle->isStaticData)
+		free(handle->state);
+	if (handle->timer)
+		timer_exit(handle->timer);
+}
+
+uint32_t statemachineBase_getState(StatemachineBase* handle, uint16_t pos)
+{
+    return (handle->state[pos]);
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 46 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/StatemachineBaseH.xpt

@@ -0,0 +1,46 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'StatemachineBase.h'»
+#ifndef STATEMACHINEBASE_H_
+#define STATEMACHINEBASE_H_
+
+#include "definition.h"
+#include "Timer.h"
+
+typedef struct {
+
+	uint32_t* state;
+	uint16_t statePtr;
+
+	Timer* timer;
+	boolean isStaticData;
+
+} StatemachineBase;
+
+
+extern void statemachineBase_init(StatemachineBase* handle, uint16_t maxStates, Timer* timer);
+extern void statemachineBase_init_staticData(StatemachineBase* handle,
+		uint32_t* staticData, Timer* timer);
+
+extern void statemachineBase_exit(StatemachineBase* handle);
+
+extern uint32_t statemachineBase_getState(StatemachineBase* handle, uint16_t pos);
+
+
+#endif /* STATEMACHINEBASE_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 51 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/StatemachineH.xpt

@@ -0,0 +1,51 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine.h'»
+#ifndef STATEMACHINE_H_
+#define STATEMACHINE_H_
+
+#include <deque>
+#include "Event.h"
+
+class Statemachine {
+
+protected:
+	uint32_t* state;
+	uint16_t statePtr;
+
+	std::deque<Event> eventList;
+
+	Event getEvent();
+
+	virtual void _runCycle(Event ev) = 0;
+
+public:
+	Statemachine(uint16_t maxStates);
+	virtual ~Statemachine();
+
+	virtual void init() = 0;
+	void runCycle();
+	void queueEvent(Event ev);
+	bool eventWaiting() const;
+
+	uint32_t getState(uint16_t pos) { return(state[pos]); }
+
+};
+
+#endif /* STATEMACHINE_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 93 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Statemachine_cyC.xpt

@@ -0,0 +1,93 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine_cy.c'»
+#include <stdlib.h>
+#include "definition.h"
+#include "Statemachine_cy.h"
+
+void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
+		uint16_t maxEvents, Timer* timer, EventPool* eventPool) {
+
+	statemachineBase_init((StatemachineBase*) handle, maxStates, timer);
+	eventSet_init(&handle->eventSet, maxEvents);
+
+	/* This is only a place for the pointers to the actual Events */
+	handle->eventList = malloc(sizeof(_Event*) * maxEvents);
+
+	/* eventPool must be initialized at this point */
+	handle->eventPool = eventPool;
+
+}
+
+
+void statemachine_cy_init_staticData(Statemachine_cy* handle,
+		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
+		boolean* staticEventSet, _Event** staticListPtr, EventPool* eventPool) {
+	statemachineBase_init_staticData((StatemachineBase*) handle,
+			staticStateData, timer);
+	eventSet_init_staticData(&handle->eventSet, maxEvents, staticEventSet);
+
+	/* Hand out event List */
+	handle->eventList = staticListPtr;
+
+	/* eventPool must be initialized at this point */
+	handle->eventPool = eventPool;
+
+}
+
+void statemachine_cy_exit(Statemachine_cy* handle) {
+
+	uint32_t i;
+	// the active events, which are not been handled need to be freed
+	for (i = 0; i < handle->eventSet.maxEvents; ++i) {
+		if (eventSet_check(&handle->eventSet, i))
+			eventPool_freeEvent(handle->eventPool, handle->eventList[i]);
+	}
+
+	if (handle->base.isStaticData == bool_false)
+		free(handle->eventList);
+
+	eventSet_exit(&handle->eventSet);
+	statemachineBase_exit((StatemachineBase*) handle);
+
+}
+
+void statemachine_cy_runCycle(Statemachine_cy* handle) {
+
+	/* call internal cycle */
+	statemachine_cy__runCycle(handle);
+
+	/* cleanup all events */
+	eventSet_clean(&handle->eventSet);
+
+}
+
+void statemachine_cy_setEvent(Statemachine_cy* handle, _Event* ev) {
+
+	eventSet_set(&handle->eventSet,ev->id);
+	handle->eventList[ev->id] = ev;
+
+}
+
+boolean statemachine_cy_eventWaiting(Statemachine_cy* handle) {
+
+	return eventSet_isAny(&handle->eventSet);
+}
+
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 55 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/Statemachine_cyH.xpt

@@ -0,0 +1,55 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine_cy.h'»
+#ifndef STATEMACHINE_CY_H_
+#define STATEMACHINE_CY_H_
+
+#include "EventSet.h"
+#include "StatemachineBase.h"
+#include "generatedSource/VariableData.h"
+#include "Timer.h"
+#include "EventPool.h"
+
+typedef struct {
+  StatemachineBase base;
+  EventSet eventSet;
+  _Event** eventList;
+  EventPool* eventPool;
+} Statemachine_cy ;
+
+extern void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
+		uint16_t maxEvents,	Timer* timer, EventPool* eventPool);
+
+extern void statemachine_cy_init_staticData(Statemachine_cy* handle,
+		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
+		boolean* staticEventSet, _Event** staticListPtr, EventPool* eventPool);
+
+extern void statemachine_cy_exit(Statemachine_cy* handle);
+
+/* implement me */
+extern void statemachine_cy_runCycle(Statemachine_cy* handle);
+
+extern void statemachine_cy_setEvent(Statemachine_cy* handle, _Event* ev);
+extern boolean statemachine_cy_eventWaiting(Statemachine_cy* handle);
+
+/* implement me in derived codegeneration */
+extern void statemachine_cy__runCycle(Statemachine_cy* handle);
+
+#endif /* STATEMACHINE_CY_H_ */
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 112 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/TestMain.xpt

@@ -0,0 +1,112 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'main.cpp'»
+
+/*
+ * main.cpp
+ *
+ *  Created on: 10.09.2011
+ *      Author: seger
+ */
+
+#include <cstdio>
+#include <iostream>
+#include "«StName()».h"
+// #include "«DRName()».h"
+#include "«EvName()».h"
+
+int main()
+{
+
+	char* stateName[6] = {"State1", "State2", "State3", "State4", "State5", "State6"};
+	«StName()» machine;
+
+	// initialize the initial states 
+	machine.init();
+	
+	/* Example code 
+	// create one event and enqueue it 
+	Event e = createEvent<Event1>();
+	machine.queueEvent(e);
+
+	// run the cycle 
+	machine.runCycle();
+
+	// check the state 
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	e = createEvent<Event2>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State1") == 0);
+
+	// does event queuing work?
+	e = createEvent<Event1>();
+	machine.queueEvent(e);
+	e = createEvent<Event3>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	// run second cycle
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State4") == 0);
+
+	e = createEvent<Event4>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	e = createEvent<Event3>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State4") == 0);
+
+	e = createEvent<Event5>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State1") == 0);
+
+	*/
+	
+	return(0);
+	
+}
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 33 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/TimerC.xpt

@@ -0,0 +1,33 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Timer.c'»
+#include "Timer.h"
+
+void timer_setFPtr(Timer* handle, setTimerFPtr stfptr, unsetTimerFPtr utfptr)
+{
+
+	handle->setTimer = stfptr;
+	handle->unsetTimer = utfptr;
+
+}
+
+void timer_exit(Timer* handle)
+{
+
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 38 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/TimerH.xpt

@@ -0,0 +1,38 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Timer.h'»
+#ifndef TIMER_H_
+#define TIMER_H_
+
+#include "definition.h"
+
+typedef void(*setTimerFPtr)(uint32_t evid, const uint32_t time_ms, boolean periodic);
+typedef void(*unsetTimerFPtr)(const uint32_t evid);
+
+typedef struct {
+
+	/* callback functions */
+	setTimerFPtr   setTimer;
+	unsetTimerFPtr unsetTimer;
+
+}  Timer;
+
+extern void timer_setFPtr(Timer* handle, setTimerFPtr stfptr, unsetTimerFPtr utfptr);
+extern void timer_exit(Timer* handle);
+#endif /* TIMER_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 37 - 0
plugins/org.yakindu.sct.generator.c/bin/org/yakindu/sct/generator/c/templates/definitionH.xpt

@@ -0,0 +1,37 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'definition.h'»
+#ifndef DEFINITION_H_
+#define DEFINITION_H_
+
+/* platform/compiler specific additions (#includes) */
+/* temporarly set to fix values */ 
+
+typedef unsigned int uint32_t;
+typedef unsigned short uint16_t;
+
+typedef int int32_t;
+typedef short int16_t;
+
+typedef int32_t integer; 
+typedef bool boolean;
+typedef float real;
+//typedef string char*;
+ 
+#endif /* DEFINITION_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 2 - 0
plugins/org.yakindu.sct.generator.c/build.properties

@@ -0,0 +1,2 @@
+source.. = src/
+bin.includes = META-INF/,.

+ 31 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CMakeLists.xpt

@@ -0,0 +1,31 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'CMakeLists.txt'»
+cmake_minimum_required(VERSION 2.8)
+
+set(SRC
+	Statemachine.cpp
+	«StName()».cpp
+	main.cpp
+)
+
+add_definitions( -Wall -O0 -g)
+add_executable(«StName()»Main ${SRC})
+«ENDFILE»
+
+«ENDDEFINE»

+ 42 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomEventH.xpt

@@ -0,0 +1,42 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE EvName()+'.h'»
+#ifndef «EVNAME()»_H_
+#define «EVNAME()»_H_
+
+#include "Event.h"
+
+enum EventID {
+«FOREACH this.declaredEvents() AS ev»
+  _«((EventDefinition)ev).name.toLowerCase()»,
+«ENDFOREACH»
+	event_last
+};
+
+«FOREACH this.declaredEvents() AS ev»
+  class «((EventDefinition)ev).name» : public _Event { public: «((EventDefinition)ev).name»() : _Event((uint32_t)_«((EventDefinition)ev).name.toLowerCase()») {} };
+  // internal variables unhandled
+«ENDFOREACH»
+ 
+
+#endif /* «name.toUpperCase()»_H_ */
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 83 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomRepositoryH.xpt

@@ -0,0 +1,83 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+
+«DEFINE interfaces FOR ExecutionFlow»
+«EXPAND scope FOREACH this.scopes»
+«ENDDEFINE»
+
+«DEFINE scope FOR Scope -»
+«ENDDEFINE»
+
+«DEFINE scope FOR InterfaceScope»
+«EXPAND declaration FOREACH this.declarations»
+«ENDDEFINE»
+
+«DEFINE scope FOR InternalScope»
+«EXPAND declaration FOREACH this.declarations»
+«ENDDEFINE»
+
+«DEFINE declaration FOR Declaration -»
+	// unknown declaration «name»
+«ENDDEFINE»
+
+«DEFINE declaration FOR EventDefinition -»
+«ENDDEFINE»
+
+«DEFINE declaration FOR VariableDefinition -»
+	«type» «name»; 
+«ENDDEFINE»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE DRName()+'.h'»
+#ifndef «DRNAME()»_H_
+#define «DRNAME()»_H_
+
+#include "definition.h"
+#include "DataRepository.h"
+
+class «DRName()» : public DataRepository {
+
+«FOREACH this.declaredVariables() AS variable»
+    «((VariableDefinition)variable).type» «((VariableDefinition)variable).name»;
+«ENDFOREACH»
+
+public:
+
+	«DRName()»() : 
+«FOREACH this.declaredVariables() AS variable SEPARATOR ','-»
+ «((VariableDefinition)variable).name»(0)«
+ENDFOREACH»
+	{};
+	virtual ~«DRName()»() {};
+	
+«FOREACH this.declaredVariables() AS variable»
+    «((VariableDefinition)variable).type» get_«((VariableDefinition)variable).name»()
+    { «((VariableDefinition)variable).type» value; lock(); value = «((VariableDefinition)variable).name»; unlock(); return value; }
+«ENDFOREACH»
+
+«FOREACH this.declaredVariables() AS variable»
+    void set_«((VariableDefinition)variable).name»(const «((VariableDefinition)variable).type»& value)
+    { lock(); «((VariableDefinition)variable).name» =  value; unlock(); }
+«ENDFOREACH»
+
+};
+
+#endif /* «DRNAME()»_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 169 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineCPP.xpt

@@ -0,0 +1,169 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+«IMPORT ecore»
+
+«IMPORT org::yakindu::sct::generator::c::templates»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+«DEFINE ActionCode FOR Step»
+// ActionCode for Step not defined
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Execution»
+	«this.statement.toCppCode()»
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Call»
+«this.step.functionName()»();
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Sequence»
+  «EXPAND ActionCode FOREACH this.steps»
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Check -»
+  «IF this != null -»
+«this.condition.toCppCode() -»
+  «ELSE -»
+ true «
+ ENDIF -»«
+  ENDDEFINE»
+
+«DEFINE ActionCode FOR CheckRef -»
+  «IF this.check != null -»
+  «this.check.functionName()»(ev) «
+  ELSE -»
+ true «
+  ENDIF -»«
+ENDDEFINE»
+
+«DEFINE ActionCode FOR Reaction»
+  «EXPAND ActionCode FOR this.effect» 
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR If»
+if («EXPAND ActionCode FOR this.check») { 
+  «EXPAND ActionCode FOR this.thenStep»
+}
+else {
+  «EXPAND ActionCode FOR this.elseStep»
+}
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR EnterState»
+state[0] = _«this.state.simpleName»;
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR ExitState»
+state[0] = last_state;
+«ENDDEFINE»
+
+«DEFINE ConditionMethodsImplement FOR ExecutionState»
+  «FOREACH reactions AS r»
+  «IF r.check != null -»
+bool «StName()»::«r.check.functionName()»(const _Event& ev) {
+  return (	«r.check.condition.toCppCode()» );
+}
+  «ENDIF -»
+  «ENDFOREACH»
+«ENDDEFINE»
+
+«DEFINE StatementMethodsImplement FOR ExecutionState»
+  «FOREACH reactions AS r»
+void «this.StName()»::«r.effect.functionName()»() {
+  «EXPAND ActionCode FOR r.effect»
+}
+  «ENDFOREACH»
+«ENDDEFINE»
+
+«DEFINE CycleCode FOR Cycle» 
+«EXPAND ActionCode FOREACH this.steps»
+«ENDDEFINE»
+
+«DEFINE CycleMethodsImplement FOR ExecutionState»
+void «StName()»::cycle_«this.simpleName»(const _Event& ev)
+{
+	«EXPAND CycleCode FOR cycle»
+}
+«ENDDEFINE»
+
+«DEFINE EnterMethodImplement FOR ExecutionState»
+«IF this.entryAction != null»
+void «StName()»::«this.entryAction.entryActionFunctionName()»()
+{
+«EXPAND ActionCode FOR this.entryAction»
+}
+«ENDIF»
+«ENDDEFINE»
+
+«DEFINE ExitMethodImplement FOR ExecutionState»
+«IF this.exitAction != null»
+void «StName()»::«this.exitAction.exitActionFunctionName()»()
+{
+«EXPAND ActionCode FOR this.exitAction»
+}
+«ENDIF»
+«ENDDEFINE»
+
+«DEFINE file FOR ExecutionFlow»
+«FILE StName()+'.cpp'»
+#include <iostream>
+#include "«StName()».h"
+
+«StName()»::«StName()»() : Statemachine(«((ExecutionFlow)this.eRootContainer).stateVector.size») {
+}
+
+«StName()»::~«StName()»() {
+}
+
+«EXPAND ConditionMethodsImplement FOREACH this.states»
+
+«EXPAND StatementMethodsImplement FOREACH this.states»
+
+«EXPAND CycleMethodsImplement FOREACH this.states»
+
+«EXPAND EnterMethodImplement FOREACH this.states»
+
+«EXPAND ExitMethodImplement FOREACH this.states»
+
+
+void «StName()»::init()
+{
+	«EXPAND ActionCode FOREACH this.enterSequence.steps»
+}
+
+/* Yet unimplemented
+void «StName()»::exit()
+{
+}
+*/
+
+void «StName()»::_runCycle(Event ev)
+{
+	for (int i=0; i<MAX_PARALLEL_STATES; ++i) {
+		switch(state[i]) {
+	«FOREACH this.states AS state»
+	    case _«state.simpleName»:
+	        cycle_«state.simpleName»(*ev);
+	        break;
+	«ENDFOREACH»
+		default:
+			/* no state found */
+			break;
+		}
+	}
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 94 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineH.xpt

@@ -0,0 +1,94 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE StName()+'.h'»
+#ifndef «STNAME()»_H_
+#define «STNAME()»_H_
+
+#include "Statemachine.h"
+#include "«DRName()».h"
+#include "«EvName()».h"
+
+
+#define MAX_PARALLEL_STATES «this.stateVector.size»
+
+class «StName()»: public Statemachine, public «DRName()» {
+
+public:
+	enum States {
+	    «FOREACH this.states AS exState-»
+	      _«exState.simpleName»,
+	    «ENDFOREACH»
+		last_state
+	};
+
+protected:
+	/* conditions */
+	«FOREACH states AS state -»
+	  «FOREACH state.reactions AS reaction -»
+	  «IF reaction.check != null -»
+	bool «reaction.check.functionName()»(const _Event& event);
+	  «ENDIF»
+	  «ENDFOREACH»
+	«ENDFOREACH»
+	
+	/* actions */
+	«FOREACH states AS state -»
+	  «FOREACH state.reactions AS reaction -»
+	void «reaction.effect.functionName()»();
+	  «ENDFOREACH»
+	«ENDFOREACH»
+
+	/* cycles */
+	«FOREACH states AS state -»
+	void cycle_«state.simpleName»(const _Event& ev);
+	«ENDFOREACH»
+	
+	/* entrys */
+	«FOREACH states AS state -»
+	«IF state.entryAction != null»
+	void «state.entryAction.entryActionFunctionName()»();
+	«ENDIF»
+	«ENDFOREACH»
+	
+	/*exits */
+	«FOREACH states AS state -»
+	«IF state.exitAction != null»
+	void «state.exitAction.exitActionFunctionName()»();
+	«ENDIF»
+	«ENDFOREACH»
+	
+	virtual void _runCycle(Event ev);
+
+public:
+
+	«StName()»();
+	virtual ~«StName()»();
+
+	virtual void init();
+
+	//virtual void queueEvent(const Event& ev);
+
+};
+
+//}; // namespace
+#endif /* «STNAME()»_H_ */
+
+«ENDFILE»
+
+«ENDDEFINE»
+

+ 25 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventC.xpt

@@ -0,0 +1,25 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Event.c'»
+#include "Event.h"
+
+void _event_init(_Event* handle, uint32_t id)
+{
+	handle->id = id;
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 31 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventH.xpt

@@ -0,0 +1,31 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Event.h'»
+#ifndef EVENT_H_
+#define EVENT_H_
+
+#include "definition.h"
+
+typedef struct {
+  uint32_t id;
+} _Event;
+
+extern void _event_init(_Event* handle, uint32_t id);
+
+#endif /* EVENT_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 69 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventSetC.xpt

@@ -0,0 +1,69 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'EventSet.c'»
+#include "EventSet.h"
+#include <stdlib.h>
+
+void eventSet_init(EventSet* handle, const uint32_t _maxEvents) {
+	handle->isStaticData = bool_false;
+	handle->maxEvents = _maxEvents;
+	handle->_set = malloc(sizeof(boolean) * _maxEvents);
+	eventSet_clean(handle);
+}
+
+void eventSet_init_staticData(EventSet* handle, const uint32_t _maxEvents,
+		boolean* _dataSet) {
+	handle->isStaticData = bool_true;
+	handle->maxEvents = _maxEvents;
+	handle->_set = _dataSet;
+}
+
+void eventSet_exit(EventSet* handle) {
+	if (!handle->isStaticData)
+		free(handle->_set);
+	handle->maxEvents = 0;
+}
+
+boolean eventSet_check(EventSet* handle, const uint32_t evid) {
+	if (evid < handle->maxEvents) {
+		return handle->_set[evid];
+	}
+	return (bool_false);
+}
+
+void eventSet_clean(EventSet* handle) {
+	uint32_t i;
+	for (i = 0; i < handle->maxEvents; ++i)
+		handle->_set[i] = bool_false;
+}
+
+void eventSet_set(EventSet* handle, const uint32_t evid) {
+	if (evid < handle->maxEvents) {
+		handle->_set[evid] = bool_true;
+	}
+}
+
+boolean eventSet_isAny(EventSet* handle) {
+	uint32_t i;
+	for (i = 0; i < handle->maxEvents; ++i)
+		if (handle->_set[i])
+			return (bool_true);
+	return (bool_false);
+}
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 43 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventSetH.xpt

@@ -0,0 +1,43 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'EventSet.h'»
+#ifndef EVENTSET_H_
+#define EVENTSET_H_
+
+#include "definition.h"
+
+typedef struct {
+	boolean* _set;
+	uint32_t maxEvents;
+	boolean isStaticData;
+} EventSet;
+
+/* constructor and destructor */
+extern void eventSet_init(EventSet* handle, const uint32_t maxEvents);
+extern void eventSet_init_staticData(EventSet* handle, const uint32_t maxEvents,
+		boolean* _dataSet);
+extern void eventSet_exit(EventSet* handle);
+
+
+extern boolean eventSet_check(EventSet* handle, const uint32_t evid);
+extern void eventSet_clean(EventSet* handle);
+extern void eventSet_set(EventSet* handle, const uint32_t evid);
+extern boolean eventSet_isAny(EventSet* handle);
+
+#endif /* EVENTSET_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 84 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Expression.ext

@@ -0,0 +1,84 @@
+import stext;
+import sexec;
+import ecore;
+import sgraph;
+toCppCode(Void void) :
+	"/*toCppCode() called with NULL element. Polymorphic resolver could not match callable method!*/";
+String toCppCode(Void o, String statechartReference) : 
+	""; //polymorphic placeholder (abstract rule)
+
+String toCppCode(Expression statement) : 
+	null; //polymorphic placeholder (abstract rule)
+ 
+String toCppCode(Statement statement) : 
+	null; //polymorphic placeholder (abstract rule)
+ 
+String toCppCode(PrimitiveValueExpression primValue) :
+	primValue.value;
+
+/* Assignment */
+String toCppCode(Assignment assignment) :
+  switch (assignment.operator) {
+  case (AssignmentOperator::assign) : "set_" + assignment.varRef.name + "(" + assignment.expression.toCppCode() + ");"  
+  case (AssignmentOperator::multAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() * (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::divAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() / (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::modAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() % (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::addAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() + (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::subAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() - (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::leftShiftAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() << ("+ assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::rightShiftAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() >> (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::andAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() & (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::xorAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() ^ (" + assignment.expression.toCppCode() + "));"
+  case (AssignmentOperator::orAssign) : "set_" + assignment.varRef.name + "(get_"+ assignment.varRef.name+ "() ^ (" + assignment.expression.toCppCode() + "));"
+  default : ""
+  };
+		
+/* EventRaising */
+
+/* Logical Expressions */
+String toCppCode(LogicalOrExpression expression) :
+  	expression.leftOperand.toCppCode() + " || " + expression.rightOperand.toCppCode();
+  	
+String toCppCode(LogicalAndExpression expression) :
+  	expression.leftOperand.toCppCode() + " && " + expression.rightOperand.toCppCode();
+
+String toCppCode(LogicalNotExpression expression) :
+  	" ^" + expression.operand.toCppCode();
+
+String toCppCode(LogicalRelationExpression expression) :
+   expression.leftOperand.toCppCode() + " ??? " + expression.rightOperand.toCppCode();
+    
+String toCppCode(BitwiseAndExpression expression) :
+  	expression.leftOperand.toCppCode() + " & " + expression.rightOperand.toCppCode();
+
+String toCppCode(BitwiseOrExpression expression) :
+  	expression.leftOperand.toCppCode() + " | " + expression.rightOperand.toCppCode();
+
+String toCppCode(BitwiseXorExpression expression) :
+  	expression.leftOperand.toCppCode() + " ^ " + expression.rightOperand.toCppCode();
+
+String toCppCode(NumericalAddSubtractExpression expression) :
+  	expression.leftOperand.toCppCode() + getOperator(expression.operator) + expression.rightOperand.toCppCode();
+  	
+String toCppCode(NumericalMultiplyDivideExpression expression) :
+  	expression.leftOperand.toCppCode() + getOperator(expression.operator) + expression.rightOperand.toCppCode();
+
+// is this just relevant for events?
+String toCppCode(ElementReferenceExpression ev) :
+    " ( _" + ev.value.name.toLowerCase() + " == ev.getID() ) ";
+
+String getOperator(AdditiveOperator operator) : 
+    switch(operator) {
+    	case(AdditiveOperator::plus) : " + "
+    	case(AdditiveOperator::minus) : " - "
+    	default : ""
+    };
+
+String getOperator(MultiplicativeOperator operator) : 
+    switch(operator) {
+    	case(MultiplicativeOperator::mul) : " * "
+    	case(MultiplicativeOperator::div) : " / "
+    	case(MultiplicativeOperator::mod) : " % "
+    	default : ""
+    };
+

+ 57 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Main.xpt

@@ -0,0 +1,57 @@
+«REM»
+
+Contais the root templates that call the different file templates.
+
+@author andreas muelder
+@auther axel terfloth
+@author joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«IMPORT org::yakindu::sct::generator::c::templates»
+
+«DEFINE main FOR ExecutionFlow»
+
+	«REM» basis files «ENDREM»
+	«EXPAND EventH::file FOR this»
+	«EXPAND EventC::file FOR this»
+
+	«EXPAND TimerH::file FOR this»
+	«EXPAND TimerC::file FOR this»
+
+	«EXPAND EventSetH::file FOR this»
+	«EXPAND EventSetC::file FOR this»
+
+	«EXPAND StatemachineBaseH::file FOR this»
+	«EXPAND StatemachineBaseC::file FOR this»
+
+	«EXPAND Statemachine_cyH::file FOR this»
+	«EXPAND Statemachine_cyC::file FOR this»
+
+
+
+    «REM» code that is created by the model «ENDREM»
+	«EXPAND definitionH::file FOR this»
+
+	«EXPAND EventPoolH::file FOR this»
+	«EXPAND EventPoolC::file FOR this»
+
+	«EXPAND CustomStatemachineH::file FOR this»
+	«EXPAND CustomStatemachineCPP::file FOR this»
+	«EXPAND CustomRepositoryH::file FOR this»
+	«EXPAND CustomEventH::file FOR this»
+	
+	«EXPAND CMakeLists::file FOR this»
+	«EXPAND TestMain::file FOR this»
+
+
+	«EXPAND Dump::file FOR this»
+	
+«ENDDEFINE»
+
+
+

+ 44 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Naming.ext

@@ -0,0 +1,44 @@
+import stext;
+import sexec;
+import ecore;
+import sgraph;
+
+
+String scName(Expression statement) : ((ExecutionFlow)statement.eRootContainer).name ;
+
+List declaredEvents(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(EventDefinition);
+
+List declaredVariables(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(VariableDefinition);
+
+String test(NamedElement obj) :  "";
+String StName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Statemachine";
+String STNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "STATEMACHINE";
+
+String DRName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "DataRepository";
+String DRNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "DATAREPOSITORY";
+
+String EvName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Event";
+String EVNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "EVENT";
+
+cached String functionName(Step step) : 
+	(step.isEffect()) ? step.actionFunctionName() : (
+	(step.isReactionCheck()) ? step.checkFunctionName() : (
+	(step.isEntryAction()) ? step.entryActionFunctionName() : ( 
+	(step.isExitAction()) ? step.exitActionFunctionName() : 
+	" !! unknown function type !!" )));
+ 
+String actionFunctionName(Step this) : "actions_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
+String checkFunctionName(Step this) : "condition_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
+String entryActionFunctionName(Step this) : "entryActions_" + this.state().simpleName; 
+String exitActionFunctionName(Step this) : "exitActions_" + this.state().simpleName; 
+
+boolean isEffect(Step step) : (! Check.isInstance(step)) && Reaction.isInstance(step.eContainer) ;
+boolean isReactionCheck(Step step) : Reaction.isInstance(step.eContainer) && Check.isInstance(step);
+boolean isEntryAction(Step step) : ExecutionState.isInstance(step.eContainer) && step.state().entryAction == step;
+boolean isExitAction(Step step) : ExecutionState.isInstance(step.eContainer) && step.state().exitAction == step;
+
+Reaction reaction(Step this) : (Reaction) this.eContainer ;
+ExecutionState state(Reaction this) : (ExecutionState) eContainer;
+ExecutionState state(Step this) : (ExecutionState) eContainer;
+
+

+ 49 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/StatemachineBaseC.xpt

@@ -0,0 +1,49 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'StatemachineBase.c'»
+#include "StatemachineBase.h"
+#include <stdlib.h>
+
+void statemachineBase_init(StatemachineBase* handle, uint16_t maxStates, Timer* _timer)
+{
+	handle->isStaticData = bool_false;
+	handle->timer = _timer;
+	handle->state = malloc(sizeof(uint32_t)*maxStates); /* memory allocation for all states */
+	handle->statePtr = 0; /* actual state referencer */
+}
+
+void statemachineBase_init_staticData(StatemachineBase* handle, uint32_t* staticData, Timer* _timer)
+{
+	handle->isStaticData = bool_true;
+	handle->timer = _timer;
+	handle->state = staticData;
+	handle->statePtr = 0; /* actual state referencer */
+}
+
+void statemachineBase_exit(StatemachineBase* handle) {
+	if (!handle->isStaticData)
+		free(handle->state);
+	if (handle->timer)
+		timer_exit(handle->timer);
+}
+
+uint32_t statemachineBase_getState(StatemachineBase* handle, uint16_t pos)
+{
+    return (handle->state[pos]);
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 46 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/StatemachineBaseH.xpt

@@ -0,0 +1,46 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'StatemachineBase.h'»
+#ifndef STATEMACHINEBASE_H_
+#define STATEMACHINEBASE_H_
+
+#include "definition.h"
+#include "Timer.h"
+
+typedef struct {
+
+	uint32_t* state;
+	uint16_t statePtr;
+
+	Timer* timer;
+	boolean isStaticData;
+
+} StatemachineBase;
+
+
+extern void statemachineBase_init(StatemachineBase* handle, uint16_t maxStates, Timer* timer);
+extern void statemachineBase_init_staticData(StatemachineBase* handle,
+		uint32_t* staticData, Timer* timer);
+
+extern void statemachineBase_exit(StatemachineBase* handle);
+
+extern uint32_t statemachineBase_getState(StatemachineBase* handle, uint16_t pos);
+
+
+#endif /* STATEMACHINEBASE_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 51 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/StatemachineH.xpt

@@ -0,0 +1,51 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine.h'»
+#ifndef STATEMACHINE_H_
+#define STATEMACHINE_H_
+
+#include <deque>
+#include "Event.h"
+
+class Statemachine {
+
+protected:
+	uint32_t* state;
+	uint16_t statePtr;
+
+	std::deque<Event> eventList;
+
+	Event getEvent();
+
+	virtual void _runCycle(Event ev) = 0;
+
+public:
+	Statemachine(uint16_t maxStates);
+	virtual ~Statemachine();
+
+	virtual void init() = 0;
+	void runCycle();
+	void queueEvent(Event ev);
+	bool eventWaiting() const;
+
+	uint32_t getState(uint16_t pos) { return(state[pos]); }
+
+};
+
+#endif /* STATEMACHINE_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 93 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyC.xpt

@@ -0,0 +1,93 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine_cy.c'»
+#include <stdlib.h>
+#include "definition.h"
+#include "Statemachine_cy.h"
+
+void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
+		uint16_t maxEvents, Timer* timer, EventPool* eventPool) {
+
+	statemachineBase_init((StatemachineBase*) handle, maxStates, timer);
+	eventSet_init(&handle->eventSet, maxEvents);
+
+	/* This is only a place for the pointers to the actual Events */
+	handle->eventList = malloc(sizeof(_Event*) * maxEvents);
+
+	/* eventPool must be initialized at this point */
+	handle->eventPool = eventPool;
+
+}
+
+
+void statemachine_cy_init_staticData(Statemachine_cy* handle,
+		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
+		boolean* staticEventSet, _Event** staticListPtr, EventPool* eventPool) {
+	statemachineBase_init_staticData((StatemachineBase*) handle,
+			staticStateData, timer);
+	eventSet_init_staticData(&handle->eventSet, maxEvents, staticEventSet);
+
+	/* Hand out event List */
+	handle->eventList = staticListPtr;
+
+	/* eventPool must be initialized at this point */
+	handle->eventPool = eventPool;
+
+}
+
+void statemachine_cy_exit(Statemachine_cy* handle) {
+
+	uint32_t i;
+	// the active events, which are not been handled need to be freed
+	for (i = 0; i < handle->eventSet.maxEvents; ++i) {
+		if (eventSet_check(&handle->eventSet, i))
+			eventPool_freeEvent(handle->eventPool, handle->eventList[i]);
+	}
+
+	if (handle->base.isStaticData == bool_false)
+		free(handle->eventList);
+
+	eventSet_exit(&handle->eventSet);
+	statemachineBase_exit((StatemachineBase*) handle);
+
+}
+
+void statemachine_cy_runCycle(Statemachine_cy* handle) {
+
+	/* call internal cycle */
+	statemachine_cy__runCycle(handle);
+
+	/* cleanup all events */
+	eventSet_clean(&handle->eventSet);
+
+}
+
+void statemachine_cy_setEvent(Statemachine_cy* handle, _Event* ev) {
+
+	eventSet_set(&handle->eventSet,ev->id);
+	handle->eventList[ev->id] = ev;
+
+}
+
+boolean statemachine_cy_eventWaiting(Statemachine_cy* handle) {
+
+	return eventSet_isAny(&handle->eventSet);
+}
+
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 55 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyH.xpt

@@ -0,0 +1,55 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine_cy.h'»
+#ifndef STATEMACHINE_CY_H_
+#define STATEMACHINE_CY_H_
+
+#include "EventSet.h"
+#include "StatemachineBase.h"
+#include "generatedSource/VariableData.h"
+#include "Timer.h"
+#include "EventPool.h"
+
+typedef struct {
+  StatemachineBase base;
+  EventSet eventSet;
+  _Event** eventList;
+  EventPool* eventPool;
+} Statemachine_cy ;
+
+extern void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
+		uint16_t maxEvents,	Timer* timer, EventPool* eventPool);
+
+extern void statemachine_cy_init_staticData(Statemachine_cy* handle,
+		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
+		boolean* staticEventSet, _Event** staticListPtr, EventPool* eventPool);
+
+extern void statemachine_cy_exit(Statemachine_cy* handle);
+
+/* implement me */
+extern void statemachine_cy_runCycle(Statemachine_cy* handle);
+
+extern void statemachine_cy_setEvent(Statemachine_cy* handle, _Event* ev);
+extern boolean statemachine_cy_eventWaiting(Statemachine_cy* handle);
+
+/* implement me in derived codegeneration */
+extern void statemachine_cy__runCycle(Statemachine_cy* handle);
+
+#endif /* STATEMACHINE_CY_H_ */
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 112 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/TestMain.xpt

@@ -0,0 +1,112 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'main.cpp'»
+
+/*
+ * main.cpp
+ *
+ *  Created on: 10.09.2011
+ *      Author: seger
+ */
+
+#include <cstdio>
+#include <iostream>
+#include "«StName()».h"
+// #include "«DRName()».h"
+#include "«EvName()».h"
+
+int main()
+{
+
+	char* stateName[6] = {"State1", "State2", "State3", "State4", "State5", "State6"};
+	«StName()» machine;
+
+	// initialize the initial states 
+	machine.init();
+	
+	/* Example code 
+	// create one event and enqueue it 
+	Event e = createEvent<Event1>();
+	machine.queueEvent(e);
+
+	// run the cycle 
+	machine.runCycle();
+
+	// check the state 
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	e = createEvent<Event2>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State1") == 0);
+
+	// does event queuing work?
+	e = createEvent<Event1>();
+	machine.queueEvent(e);
+	e = createEvent<Event3>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	// run second cycle
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State4") == 0);
+
+	e = createEvent<Event4>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	e = createEvent<Event3>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State4") == 0);
+
+	e = createEvent<Event5>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State1") == 0);
+
+	*/
+	
+	return(0);
+	
+}
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 33 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/TimerC.xpt

@@ -0,0 +1,33 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Timer.c'»
+#include "Timer.h"
+
+void timer_setFPtr(Timer* handle, setTimerFPtr stfptr, unsetTimerFPtr utfptr)
+{
+
+	handle->setTimer = stfptr;
+	handle->unsetTimer = utfptr;
+
+}
+
+void timer_exit(Timer* handle)
+{
+
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 38 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/TimerH.xpt

@@ -0,0 +1,38 @@
+«REM»
+
+Templates for the main statechart c file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Timer.h'»
+#ifndef TIMER_H_
+#define TIMER_H_
+
+#include "definition.h"
+
+typedef void(*setTimerFPtr)(uint32_t evid, const uint32_t time_ms, boolean periodic);
+typedef void(*unsetTimerFPtr)(const uint32_t evid);
+
+typedef struct {
+
+	/* callback functions */
+	setTimerFPtr   setTimer;
+	unsetTimerFPtr unsetTimer;
+
+}  Timer;
+
+extern void timer_setFPtr(Timer* handle, setTimerFPtr stfptr, unsetTimerFPtr utfptr);
+extern void timer_exit(Timer* handle);
+#endif /* TIMER_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 37 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/definitionH.xpt

@@ -0,0 +1,37 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'definition.h'»
+#ifndef DEFINITION_H_
+#define DEFINITION_H_
+
+/* platform/compiler specific additions (#includes) */
+/* temporarly set to fix values */ 
+
+typedef unsigned int uint32_t;
+typedef unsigned short uint16_t;
+
+typedef int int32_t;
+typedef short int16_t;
+
+typedef int32_t integer; 
+typedef bool boolean;
+typedef float real;
+//typedef string char*;
+ 
+#endif /* DEFINITION_H_ */
+«ENDFILE»
+
+«ENDDEFINE»