瀏覽代碼

* Changed Event naming at several places
* changed hard-coded boolean names into generic ones

jos.itemis@gmail.com 13 年之前
父節點
當前提交
7df4da215a

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

@@ -25,8 +25,12 @@ uint32_t getSizeofEvent(uint32_t evid)
 	switch((EventID) evid) {
 
 «FOREACH this.declaredEvents() AS ev -»
-  case ev_«((EventDefinition)ev).name.toLowerCase()»:
+  case «((EventDefinition)ev).getEventEnumName()»:
     return sizeof(«((EventDefinition)ev).name»);
+«ENDFOREACH -»
+«FOREACH this.declaredTimerEvents() AS ev -»
+  case «((TimeEvent)ev).getEventEnumName()»:
+    return sizeof(«((TimeEvent)ev).name»);
 «ENDFOREACH -»
 	default:
 		break;

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

@@ -22,12 +22,17 @@ Templates for the main statechart cpp file.
 
 #include "Event.h"
 
+«REM» lost things:
+  ev_«((EventDefinition)ev).name.toLowerCase()»,
+  ev_«((TimeEvent)ev).name.toLowerCase()»,
+«ENDREM»
+
 typedef enum {
 «FOREACH this.declaredEvents() AS ev -»
-  ev_«((EventDefinition)ev).name.toLowerCase()»,
+  «((EventDefinition)ev).getEventEnumName()»,
 «ENDFOREACH -»
 «FOREACH this.declaredTimerEvents() AS ev -»
-  ev_«((TimeEvent)ev).name.toLowerCase()»,
+  «((TimeEvent)ev).getEventEnumName()»,
 «ENDFOREACH -»
   event_last
 } EventID;

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

@@ -40,13 +40,13 @@ Templates for the main statechart c file.
 «IF this.comment != null»
 /* «this.comment» */
 «ENDIF»
-	(*((StatemachineBase*)handle)->timer->setTimer)(ev_«this.timeEvent.name.toFirstLower()», «this.timeValue.toCCode()», «IF this.timeEvent.periodic == true -»bool_true«ELSE -»bool_false«ENDIF -»);
+	(*((StatemachineBase*)handle)->timer->setTimer)(«this.timeEvent.getEventEnumName()», «this.timeValue.toCCode()», «IF this.timeEvent.periodic == true -» «getBoolTrue()» «ELSE -» «getBoolFalse()» «ENDIF -»);
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR UnscheduleTimeEvent»
 «IF this.comment != null»
 /* «this.comment» */
-	(*((StatemachineBase*)handle->timer->unsetTimer)(ev_«this.name.toFirstLower()»);
+	(*((StatemachineBase*)handle->timer->unsetTimer)(«this.timeEvent.getEventEnumName()»);
 «ENDIF»
 
 «ENDDEFINE»
@@ -67,7 +67,7 @@ Templates for the main statechart c file.
   «IF this != null -»
 «this.condition.toCCode() -»
   «ELSE -»
- bool_true «
+ «getBoolTrue()» «
  ENDIF -»«
   ENDDEFINE»
 
@@ -75,7 +75,7 @@ Templates for the main statechart c file.
   «IF this.check != null -»
   «this.check.functionName()»(handle) «
   ELSE -»
- bool_true «
+ «getBoolTrue()» «
   ENDIF -»«
 ENDDEFINE»
 
@@ -113,9 +113,9 @@ static boolean 
   «FOREACH reactions AS r -»
   «IF r.check != null -»
 boolean «r.check.functionName()»(«StName()»* handle) {
-  boolean retValue = bool_false;
+  boolean retValue = «getBoolFalse()»;
   if («r.check.condition.toCCode()»)
-    retValue = bool_true;
+    retValue = «getBoolTrue()»;
   
   return retValue;
 }

+ 18 - 4
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Expression.ext

@@ -15,11 +15,24 @@ String toCCode(Expression statement) :
  
 String toCCode(Statement statement) : 
 	null; //polymorphic placeholder (abstract rule)
+
+String toCCode(Literal lit) :
+   "Unknown Literal Type" ;
+
+String toCCode(BoolLiteral bLit) :
+   (bLit.value == true) ? "bool_true" : "bool_false"; 
+
+String toCCode(IntLiteral iLit) :
+	iLit.value.toString();
  
+String toCCode(RealLiteral rLit) :
+	rLit.value.toString();
+
+String toCCode(HexLiteral hLit) :
+	hLit.value.toString();
+
 String toCCode(PrimitiveValueExpression primValue) :
-	(primValue.value == "true" ? "bool_true" :
-	(primValue.value == "false" ? "bool_false" :
-	primValue.value ));
+	primValue.value.toCCode();
 
 /* Assignment */
 String toCCode(Assignment assignment) :
@@ -41,7 +54,8 @@ String toCCode(Assignment assignment) :
 /* EventRaising */
 String toCCode(EventRaising eventRaising) :
 	((eventRaising.value == null)?"":
-	"((" + eventRaising.event.name + "*) handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.name + ")->value = " + eventRaising.value.toCCode() + ";") + 
+	"((" + eventRaising.event.name + "*) handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.name + ")->value = " 
+	+ eventRaising.value.toCCode() + ";") + 
 	" statemachine_cy_setEvent(&handle->base, handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.name + "); ";
 //  "{ _Event* ev = eventPool_createEvent(handle->base.eventPool, ev_"+eventRaising.event.name+"); if (ev) { " + eventRaising.addValue() + "statemachine_cy_setEvent(&handle->base, ev); } }";
 

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

@@ -105,13 +105,14 @@ void 
 	handle->eventSet = eventSet;
 	/* initial values */
 	
+	/* TODO: This should be done by sexec */
 «FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
 «IF variable.initialValue != null»
 «REM»change to correctLValue«ENDREM»
-	handle->«variable.name» = «variable.initialValue.correctLValue()»;
+	handle->«variable.name» = «variable.initialValue.toCCode()»;
 «ENDIF»
 «ENDFOREACH»
-
+	/* */ 
 	«interface.interfaceName()»_reset_event(handle);
 
 	handle->statemachine = statemachine;

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

@@ -55,9 +55,14 @@ String interfaceClassName(InterfaceScope this) : this.getExecutionFlow().name.to
 String interfaceObjectName(InterfaceScope this) : "interface" + ((this.name == null)?"":this.name.toFirstUpper());
 
 String getEventEnumName(EventDefinition this) : "ev_" + this.name.toFirstLower();
+String getEventEnumName(TimeEvent this) : "ev_" + this.name.toFirstLower();
 
+String getBoolTrue() : "bool_true";
+String getBoolFalse() : "bool_false";
+
+/*
 String correctLValue(String literal) :
     (literal == "true" ? "bool_true" :
 	(literal == "false" ? "bool_false" :
 	literal ));
-    
+*/