Forráskód Böngészése

Added new functions to code generator

jos.itemis@gmail.com 14 éve
szülő
commit
5a05adb39f

+ 15 - 22
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomEventH.xpt

@@ -10,40 +10,33 @@ Templates for the main statechart cpp file.
 «IMPORT stext»
 «IMPORT sgraph»
 
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Naming»
+
 
 «DEFINE file FOR ExecutionFlow»
 
-«FILE 'MyEvents.h'»
-#ifndef MYEVENTS_H_
-#define MYEVENTS_H_
+«FILE name.toFirstUpper()+'Event.h'»
+#ifndef «name.toUpperCase()»EVENTS_H_
+#define «name.toUpperCase()»EVENTS_H_
 
 #include "Event.h"
 
 enum EventID {
-	event1,
-	event2,
-	event3,
-	event4,
-	event5,
+«FOREACH this.declaredEvents() AS ev»
+  _«((EventDefinition)ev).name.toLowerCase()»,
+«ENDFOREACH»
 	event_last
 };
 
-class Event1 : public _Event { public: Event1() : _Event((uint32_t)event1) {} };
-class Event2 : public _Event { public: Event2() : _Event((uint32_t)event2) {} };
-class Event3 : public _Event { public: Event3() : _Event((uint32_t)event3) {} };
-
-/* Event with internal variable */
-class Event4 : public _Event {
- public:
-	Event4() : _Event((uint32_t)event4) {}
-
-	uint32_t eventVar1;
-};
-
-class Event5 : public _Event { public: Event5() : _Event((uint32_t)event5) {} };
+«FOREACH this.declaredEvents() AS ev»
+  class «((EventDefinition)ev).name» : public _Event { public: Event1() : _Event((uint32_t)_«((EventDefinition)ev).name.toLowerCase()») {} };
+  // internal variables unhandled
+«ENDFOREACH»
+ 
 
+#endif /* «name.toUpperCase()»EVENTS_H_ */
 
-#endif /* MYEVENTS_H_ */
 «ENDFILE»
 
 «ENDDEFINE»

+ 51 - 21
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomRepositoryH.xpt

@@ -10,43 +10,73 @@ Templates for the main statechart cpp file.
 «IMPORT stext»
 «IMPORT sgraph»
 
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::cpp::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 'MyDataRepository.h'»
-#ifndef MYDATAREPOSITORY_H_
-#define MYDATAREPOSITORY_H_
+«FILE DRName()+'.h'»
+#ifndef «DRNAME()»_H_
+#define «DRNAME()»_H_
 
 #include "definition.h"
 
-class MyDataRepository {
-
-	uint32_t var1;      /* variable in the main region */
-	uint32_t counter;   /* counter in the main region */
-	float sub_counter;  /* counter in a sub region */
+class «DRName()» : public DataRepository {
 
-	virtual void lock(){};
-	virtual void unlock(){};
+«FOREACH this.declaredVariables() AS variable»
+    «((VariableDefinition)variable).type» «((VariableDefinition)variable).name»;
+«ENDFOREACH»
 
 public:
 
-	MyDataRepository() {};
-	virtual ~MyDataRepository() {};
+	«DRName()»() {};
+	virtual ~«DRName()»() {};
 
-	void init_data(uint32_t _var1, uint32_t _counter, float _sub_counter)
-	{ var1 = _var1; counter = _counter; sub_counter = _sub_counter; }
+//	void init_data(uint32_t _var1, uint32_t _counter, float _sub_counter)
+//	{ var1 = _var1; counter = _counter; sub_counter = _sub_counter; }
 
-	uint32_t get_var1() { uint32_t value; lock(); value=var1; unlock(); return(value); }
-	uint32_t get_counter() { uint32_t value; lock(); value=counter; unlock(); return(value); }
-	float get_sub_counter() { float value; lock(); value=sub_counter; unlock(); return(value); }
+	
+«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»
 
-	void set_var1(const uint32_t value) { lock(); var1 = value; unlock(); }
-	void set_counter(const uint32_t value) { lock(); counter = value; unlock(); }
-	void set_sub_counter(const float value) { lock(); sub_counter = value; unlock(); }
+«FOREACH this.declaredVariables() AS variable»
+    void set_«((VariableDefinition)variable).name»(const «((VariableDefinition)variable).type»& value)
+    { lock(); «((VariableDefinition)variable).name» =  value; unlock(); }
+«ENDFOREACH»
 
 };
 
-#endif /* MYDATAREPOSITORY_H_ */
+#endif /* «DRNAME()»_H_ */
 «ENDFILE»
 
 «ENDDEFINE»

+ 23 - 40
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachineH.xpt

@@ -10,59 +10,60 @@ Templates for the main statechart cpp file.
 «IMPORT stext»
 «IMPORT sgraph»
 
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Naming»
 
 «DEFINE file FOR ExecutionFlow»
 
-«FILE 'MyStatemachine.h'»
-#ifndef MYSTATEMACHINE_H_
-#define MYSTATEMACHINE_H_
+«FILE StName()+'.h'»
+#ifndef «STNAME()»_H_
+#define «STNAME()»_H_
 
 #include "Statemachine.h"
-#include "MyDataRepository.h"
-#include "MyEvents.h"
+#include "«DRName()».h"
+#include "«EvName()».h"
 
-//namespace MyStatemachineNS {
 
-#define MAX_PARALLEL_STATES 1
+#define MAX_PARALLEL_STATES «this.stateVector.size»
 
-class MyStatemachine: public Statemachine, public MyDataRepository {
+class «StName()»: public Statemachine, public «DRName()» {
 
 public:
 	enum States {
-	    «FOREACH this.states AS exState»
-	      «exState.simpleName»,
+	    «FOREACH this.states AS exState-»
+	      _«exState.simpleName»,
 	    «ENDFOREACH»
 		last_state
 	};
 
 protected:
 	/* conditions */
-	«FOREACH states AS conStates»
-	  «FOREACH conStates.reactions AS state»
-	void condition_«conStates.simpleName»_«state.name»(const _Event& event);
+	«FOREACH states AS conStates -»
+	  «FOREACH conStates.reactions AS state -»
+	  «IF state.check != null -»
+	void «state.check.functionName()»(const _Event& event);
+	  «ENDIF»
 	  «ENDFOREACH»
 	«ENDFOREACH»
 	
 	/* actions */
-	«FOREACH states AS conStates»
-	  «FOREACH conStates.reactions AS state»
-	void actions_«conStates.simpleName»_«state.name»();
+	«FOREACH states AS conStates -»
+	  «FOREACH conStates.reactions AS state -»
+	void «state.effect.functionName()»();
 	  «ENDFOREACH»
 	«ENDFOREACH»
 
 	/* cycles */
-	«FOREACH states AS conStates»
-	  «FOREACH conStates.reactions AS state»
+	«FOREACH states AS conStates -»
 	void cycle_«conStates.simpleName»();
-	  «ENDFOREACH»
 	«ENDFOREACH»
 
 	virtual void _runCycle(Event ev);
 
 public:
 
-	MyStatemachine();
-	virtual ~MyStatemachine();
+	«StName()»();
+	virtual ~«StName()»();
 
 	virtual void init();
 
@@ -71,27 +72,9 @@ public:
 };
 
 //}; // namespace
-#endif /* MYSTATEMACHINE_H_ */
+#endif /* «STNAME()»_H_ */
 
 «ENDFILE»
 
 «ENDDEFINE»
 
-
-«DEFINE codeMethodPrototype FOR If»
-
-  condition_STATENAME_TRANSITIONPRIO_HERE(const _Event& event, const MyDataRepository& data);
-«ENDDEFINE»
-
-«DEFINE codeMethodPrototype FOR Cycle»
-  //NONE run through cycles
-  «EXPAND codeMethodPrototype FOREACH this.steps»
-«ENDDEFINE»
-
-«DEFINE codeMethodPrototype FOR Step»
-  //NONE Step
-«ENDDEFINE»
-
-«DEFINE codeMethodPrototype FOR Sequence»
-  «EXPAND codeMethodPrototype FOREACH this.steps»
-«ENDDEFINE»

+ 4 - 3
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Expression.ext

@@ -1,9 +1,11 @@
-import sgraph;
 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)
@@ -79,4 +81,3 @@ String getOperator(MultiplicativeOperator operator) :
     	default : ""
     };
 
-String scName(Expression statement) : ((ExecutionFlow)statement.eRootContainer).name ;

+ 0 - 51
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/MyEvents.xpt

@@ -1,51 +0,0 @@
-«REM»
-
-Templates for the main statechart cpp file.
-
-@auther joern seger
-
-«ENDREM»
-
-«IMPORT sexec»
-«IMPORT stext»
-«IMPORT sgraph»
-
-
-«DEFINE file FOR ExecutionFlow»
-
-«FILE 'MyEvent.h'»
-#ifndef MYEVENTS_H_
-#define MYEVENTS_H_
-
-#include "Event.h"
-
-enum EventID {
-	event1,
-	event2,
-	event3,
-	event4,
-	event5,
-	timerEvent1,
-	event_last
-};
-
-class Event1 : public _Event { public: Event1() : _Event((uint32_t)event1) {} };
-class Event2 : public _Event { public: Event2() : _Event((uint32_t)event2) {} };
-class Event3 : public _Event { public: Event3() : _Event((uint32_t)event3) {} };
-
-/* Event with internal variable */
-class Event4 : public _Event {
- public:
-	Event4() : _Event((uint32_t)event4) {}
-
-	uint32_t eventVar1;
-};
-
-class Event5 : public _Event { public: Event5() : _Event((uint32_t)event5) {} };
-class TimerEvent1 : public _Event { public: TimerEvent1() : _Event((uint32_t)timerEvent1) {} };
-
-#endif /* MYEVENTS_H_ */
-
-«ENDFILE»
-
-«ENDDEFINE»

+ 44 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/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.reaction().state().simpleName + "_" + this.reaction().name; 
+String exitActionFunctionName(Step this) : "exitActions_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
+
+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;
+
+

+ 5 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/definitionH.xpt

@@ -23,6 +23,11 @@ Templates for the main statechart cpp file.
 typedef unsigned int uint32_t;
 typedef unsigned short uint16_t;
 
+typedef int int32_t;
+typedef short int16_t;
+
+typedef int32_t integer; 
+
 #endif /* DEFINITION_H_ */
 «ENDFILE»