Bläddra i källkod

Added Support for event value access using valueof expression in generated C Code YAKHMI-327

jos.itemis@gmail.com 13 år sedan
förälder
incheckning
d219d1300c

+ 0 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineC.xpt

@@ -275,7 +275,6 @@ void 
 
 «ENDFOREACH»	
 	
-	//((StatemachineBase*)handle)->state[0] = st_State1;
 
 	«EXPAND ActionCode FOREACH this.enterSequence.steps»
 }

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

@@ -45,6 +45,13 @@ typedef struct {
 «ENDFOREACH»
 	raiseEventFPtr raiseEvent;
 	
+«REM» no plain variables in structure
+«FOREACH this.declaredEvents() AS ev»
+  «IF (((EventDefinition)ev).direction != Direction::OUT) && (((EventDefinition)ev).type != Type::void) -»
+  «eventTypeToString(((EventDefinition)ev).type)» «ev.name»_value;    
+  «ENDIF -»
+«ENDFOREACH -»
+«ENDREM»		
 } «StName()»;
 
 /* Explicit Constructor & Destructor */

+ 1 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventPoolC.xpt

@@ -41,7 +41,7 @@ void eventPool_freeEvent(EventPool* handle, _Event* delEvent) {
 	uint32_t i;
 	TypePool* pool = 0;
 
-	if (delEvent->id >= handle->maxTypeEventMemElements)
+	if ((delEvent == 0) || (delEvent->id >= handle->maxTypeEventMemElements))
 		return;
 
 	pool = &handle->typePoolMemPtr[delEvent->id];

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

@@ -3,6 +3,8 @@ import sexec;
 import ecore;
 import sgraph;
 
+extension org::yakindu::sct::generator::c::templates::Naming;
+
 InterfaceScope getInterfaceScope(Assignment this) : ((InterfaceScope)this.varRef.eContainer);
 
 toCCode(Void void) :
@@ -163,6 +165,9 @@ String toCCode(VariableDefinition var) :
 String toCCode(EventDefinition evDef) :
     " ( eventSet_check( &handle->base.eventSet, ev_" + evDef.name.toLowerCase() + ") ) ";
 
+String toCCode(EventValueReferenceExpression evrExp) :
+	"((" +evrExp.value.name + "*)handle->base.eventList[" + evrExp.value.getEventEnumName() + "])->value";
+
 /*
 String getScope(EObject eo) :
 "unkownScope";

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

@@ -55,6 +55,7 @@ String interfaceObjectName(InterfaceScope this) : "interface" + ((this.name == n
 
 String getEventEnumName(EventDefinition this) : "ev_" + this.name.toFirstLower();
 String getEventEnumName(TimeEvent this) : "ev_" + this.name.toFirstLower();
+String getEventEnumName(Event this) : "ev_" + this.name.toFirstLower();
 
 String getBoolTrue() : "bool_true";
 String getBoolFalse() : "bool_false";

+ 14 - 13
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyC.xpt

@@ -28,17 +28,17 @@ Templates for the main statechart c file.
 void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
 		uint16_t maxEvents, Timer* timer, EventPool* eventPool) {
 
-//	uint32_t i;
+	uint32_t i;
 
 	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);
+	handle->eventList = malloc(sizeof(_Event*) * maxEvents);
 
 	//memset(); <- do we have string.h?
-//	for (i=0; i<maxEvents; ++i)
-//		handle->eventList[i] = 0;
+	for (i=0; i<maxEvents; ++i)
+		handle->eventList[i] = 0;
 
 	/* eventPool must be initialized at this point */
 	handle->eventPool = eventPool;
@@ -48,13 +48,13 @@ void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
 
 void statemachine_cy_init_staticData(Statemachine_cy* handle,
 		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
-		boolean* staticEventSet, EventType* eventTypes, /*_Event** staticListPtr,*/ EventPool* eventPool) {
+		boolean* staticEventSet, EventType* eventTypes, _Event** staticListPtr, EventPool* eventPool) {
 	statemachineBase_init_staticData((StatemachineBase*) handle,
 			staticStateData, timer);
 	eventSet_init_staticData(&handle->eventSet, maxEvents, staticEventSet, eventTypes);
 
 	/* Hand out event List */
-//	handle->eventList = staticListPtr;
+	handle->eventList = staticListPtr;
 
 	/* eventPool must be initialized at this point */
 	handle->eventPool = eventPool;
@@ -62,16 +62,16 @@ void statemachine_cy_init_staticData(Statemachine_cy* handle,
 }
 
 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_is_type(&handle->eventSet, i, ev_type_input) && eventSet_check(&handle->eventSet, i))
+		if (eventSet_is_type(&handle->eventSet, i, ev_type_input) || eventSet_is_type(&handle->eventSet, i, ev_type_local))
 			eventPool_freeEvent(handle->eventPool, handle->eventList[i]);
 	}
-*/
-//	if (handle->base.isStaticData == bool_false)
-//		free(handle->eventList);
+
+	if (handle->base.isStaticData == bool_false)
+		free(handle->eventList);
 
 	eventSet_exit(&handle->eventSet);
 	statemachineBase_exit((StatemachineBase*) handle);
@@ -84,7 +84,7 @@ void statemachine_cy_runCycle(Statemachine_cy* handle) {
 
 	/* delete all outgoing events */
 	for (i=0; i<handle->eventSet.maxEvents; ++i) {
-		// only delete events, that where marked as out
+		// only delete events, that were marked as out
 		if (eventSet_is_type(&handle->eventSet,i,ev_type_output) && eventSet_check(&handle->eventSet, i)) {
 			// output events are out of our control
 		    // eventPool_freeEvent(handle->eventPool, handle->eventList[i]);
@@ -111,7 +111,8 @@ void statemachine_cy_runCycle(Statemachine_cy* handle) {
 void statemachine_cy_setEvent(Statemachine_cy* handle, _Event* ev) {
 
 	eventSet_set(&handle->eventSet,ev->id);
-//	handle->eventList[ev->id] = ev;
+	eventPool_freeEvent(handle->eventPool, handle->eventList[ev->id]); 
+	handle->eventList[ev->id] = ev;
 
 }
 

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

@@ -25,7 +25,7 @@ Templates for the main statechart c file.
 typedef struct {
   StatemachineBase base;
   EventSet eventSet;
-//  _Event** eventList;
+  _Event** eventList;
   EventPool* eventPool;
 } Statemachine_cy ;
 
@@ -34,7 +34,7 @@ extern void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
 
 extern void statemachine_cy_init_staticData(Statemachine_cy* handle,
 		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
-		boolean* staticEventSet, EventType* eventTypes,/* _Event** staticListPtr,*/ EventPool* eventPool);
+		boolean* staticEventSet, EventType* eventTypes, _Event** staticListPtr, EventPool* eventPool);
 
 extern void statemachine_cy_exit(Statemachine_cy* handle);