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

* Added internal interface
* created functions to explicitly accessing the interface pointers

jos.itemis@gmail.com 14 лет назад
Родитель
Сommit
c1a16c459b

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

@@ -1,4 +1,4 @@
-#Tue Nov 29 07:52:23 CET 2011
-eclipse.preferences.version=1
-encoding//.settings/org.eclipse.xtend.shared.ui.prefs=Cp1252
-encoding/<project>=Cp1252
+#Thu Dec 01 08:03:54 CET 2011
+eclipse.preferences.version=1
+encoding//.settings/org.eclipse.xtend.shared.ui.prefs=Cp1252
+encoding/<project>=Cp1252

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

@@ -24,7 +24,7 @@ set( SRC
 	EventPool.c
 	«StName()».c
 	«EvName()».c
-«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface -»
+«FOREACH this.scopes.getUsableScopes() AS interface -»
 	«interface.interfaceClassName()».c
 «ENDFOREACH»
 	Timer.c

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

@@ -26,7 +26,7 @@ uint32_t 
 
 «FOREACH this.declaredEvents() AS ev -»
   case «((EventDefinition)ev).getEventEnumName()»:
-    return sizeof(«((EventDefinition)ev).name»);
+    return sizeof(«((EventDefinition)ev).getEventName()»);
 «ENDFOREACH -»
 «FOREACH this.declaredTimerEvents() AS ev -»
   case «((TimeEvent)ev).getEventEnumName()»:

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

@@ -43,7 +43,7 @@ typedef struct {
   «IF ((EventDefinition)ev).type != Type::void -»
   «eventTypeToString(((EventDefinition)ev).type)» value;    
   «ENDIF -»
-} «((EventDefinition)ev).name»;
+} «((EventDefinition)ev).getEventName()»;
 «ENDFOREACH -»
 «FOREACH this.declaredTimerEvents() AS ev»
 typedef struct { 

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

@@ -142,11 +142,11 @@ void 
 «ENDDEFINE»
 
 «DEFINE ReactMethodsProto FOR ExecutionState»
-static void «StName().toFirstLower()»_react_«this.simpleName»(«StName()»* handle);
+static void «stName()»_react_«this.simpleName»(«StName()»* handle);
 «ENDDEFINE»
 
 «DEFINE ReactMethodsImplement FOR ExecutionState»
-void «StName().toFirstLower()»_react_«this.simpleName»(«StName()»* handle)
+void «stName()»_react_«this.simpleName»(«StName()»* handle)
 {
 	«EXPAND ReactCode FOR reactSequence»
 }
@@ -262,8 +262,9 @@ void 
 	statemachine_cy_init(&handle->base, MAX_PARALLEL_STATES,
 			event_last, timer, eventPool);
 			
-«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface -»
+«FOREACH this.scopes.getUsableScopes() AS interface -»
 	«interface.interfaceName()»_init(&handle->«interface.interfaceObjectName().toFirstLower()», &handle->base, &handle->base.eventSet, eventPool);
+
 «FOREACH interface.getInEvents() AS event -»
 	eventSet_set_type(&handle->base.eventSet, «event.getEventEnumName()», ev_type_input); 
 «ENDFOREACH -»
@@ -280,6 +281,14 @@ void 
 	«EXPAND ActionCode FOREACH this.enterSequence.steps»
 }
 
+«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface»
+extern «interface.interfaceClassName()»* «stName()»_get_«interface.interfaceObjectName().toFirstLower()»(«StName()»* handle)
+{
+  return &handle->«interface.interfaceObjectName()»;
+}
+«ENDFOREACH»
+
+
 void «stName()»_exit(«StName()»* handle)
 {
 	statemachine_cy_exit(&handle->base);
@@ -297,7 +306,7 @@ void 
 	statemachine_cy_setEvent(&handle->base, ev);
 }
 
-boolean «StName().toFirstLower()»_eventWaiting(«StName()»* handle)
+boolean «stName()»_eventWaiting(«StName()»* handle)
 {
 	return statemachine_cy_eventWaiting(&handle->base);
 }

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

@@ -19,7 +19,7 @@ Templates for the main statechart cpp file.
 #ifndef «STNAME()»_H_
 #define «STNAME()»_H_
 
-«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface -»
+«FOREACH this.scopes.getUsableScopes() AS interface -»
 #include "«interface.interfaceClassName()».h"
 «ENDFOREACH»
 #include "Statemachine_cy.h"
@@ -41,7 +41,7 @@ typedef void(*raiseEventFPtr)(_Event* evPtr);
 typedef struct {
 
 	Statemachine_cy  base;
-«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface»
+«FOREACH this.scopes.getUsableScopes() AS interface»
 	«interface.interfaceClassName()» «interface.interfaceObjectName().toFirstLower()»;
 «ENDFOREACH»
 	raiseEventFPtr raiseEvent;
@@ -56,13 +56,17 @@ typedef struct {
 } «StName()»;
 
 /* Explicit Constructor & Destructor */
-extern void «StName().toFirstLower()»_init(«StName()»* handle, Timer* timer, EventPool* eventPool);
-extern void «StName().toFirstLower()»_exit(«StName()»* handle);
+extern void «stName()»_init(«StName()»* handle, Timer* timer, EventPool* eventPool);
+extern void «stName()»_exit(«StName()»* handle);
+
+extern void «stName()»_setEvent(«StName()»* handle, _Event* ev);
+extern void «stName()»_runCycle(«StName()»* handle);
 
-extern void «StName().toFirstLower()»_setEvent(«StName()»* handle, _Event* ev);
-extern void «StName().toFirstLower()»_runCycle(«StName()»* handle);
+extern boolean «stName()»_eventWaiting(«StName()»* handle);
 
-extern boolean «StName().toFirstLower()»_eventWaiting(«StName()»* handle);
+«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface»
+extern «interface.interfaceClassName()»* «stName()»_get_«interface.interfaceObjectName()»(«StName()»* handle);
+«ENDFOREACH»
 
 	/* virtual function form state machine must be implemented here */
 extern void statemachine_cy__runCycle(Statemachine_cy* handle);

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

@@ -56,16 +56,26 @@ String toCCode(Assignment assignment) :
 /* EventRaising */
 String toCCode(EventRaising eventRaising) :
 	((eventRaising.value == null)?"":
-	"((" + eventRaising.event.name + "*) handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.name + ")->value = " 
+	"((" + eventRaising.event.getEventName() + "*) handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.getEventName() + ")->value = " 
 	+ eventRaising.value.toCCode() + ";") + 
-	" statemachine_cy_setEvent(&handle->base, handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.name + "); ";
+	" statemachine_cy_setEvent(&handle->base, handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.getEventName() + "); ";
 //  "{ _Event* ev = eventPool_createEvent(handle->base.eventPool, ev_"+eventRaising.event.name+"); if (ev) { " + eventRaising.addValue() + "statemachine_cy_setEvent(&handle->base, ev); } }";
 
+String getScopeName(emf::EObject o) :
+  "unknownScopeName";
+  
+String getScopeName(InterfaceScope is) :
+  is.name;
+  
+String getScopeName(InternalScope inls) :
+  "internal";
+
 String getInterfaceName(EventRaising event) :
-	"interface" + (( ((InterfaceScope)event.event.eContainer).name == null)?"":((InterfaceScope)event.event.eContainer).name.toFirstUpper());
+	"interface" + (( event.event.eContainer.getScopeName() == null)?"":event.event.eContainer.getScopeName().toFirstUpper());
+//	"interface" + (( ((InterfaceScope)event.event.eContainer).name == null)?"":((InterfaceScope)event.event.eContainer).name.toFirstUpper());
 
 String addValue(EventRaising event) :
-  ( (event.value == null)?"":("((" +event.event.name + "*)ev)->value = " + event.value.toCCode() + "; ") );
+  ( (event.value == null)?"":("((" +event.event.getEventName() + "*)ev)->value = " + event.value.toCCode() + "; ") );
 
 /* Logical Expressions */
 String toCCode(LogicalOrExpression expression) :
@@ -139,6 +149,15 @@ String eventTypeToString(Type type) :
   case (Type::string)  : "string"
   default : "unknownType"
  };
+
+Set[EventDefinition] getInEvents(Scope interface) : 
+	{};
+
+Set[EventDefinition] getOutEvents(Scope interface) : 
+	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::OUT);
+
+Set[EventDefinition] getLocalEvents(Scope interface) : 
+	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::LOCAL);
   
 Set[EventDefinition] getInEvents(InterfaceScope interface) : 
 	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::IN);
@@ -149,6 +168,15 @@ Set[EventDefinition] getOutEvents(InterfaceScope interface) :
 Set[EventDefinition] getLocalEvents(InterfaceScope interface) : 
 	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::LOCAL);
 
+Set[EventDefinition] getInEvents(InternalScope interface) : 
+	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::IN);
+
+Set[EventDefinition] getOutEvents(InternalScope interface) : 
+	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::OUT);
+
+Set[EventDefinition] getLocalEvents(InternalScope interface) : 
+	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::LOCAL);
+
 // is this just relevant for events?
 String toCCode(ElementReferenceExpression ref) :
 	ref.value.toCCode();
@@ -171,6 +199,9 @@ String toCCode(EventRaisedReferenceExpression errExp) :
 String toCCode(EventValueReferenceExpression evrExp) :
 	"((" +evrExp.value.name + "*)handle->base.eventList[" + evrExp.value.getEventEnumName() + "])->value";
 
+List[Scope] getUsableScopes(List[Scope] scList) :
+	scList.select(e| InterfaceScope.isInstance(e) || InternalScope.isInstance(e));
+
 /*
 String getScope(EObject eo) :
 "unkownScope";

+ 13 - 7
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Interfaces.xpt

@@ -15,7 +15,7 @@ Templates for the main statechart cpp file.
 
 
 «DEFINE file FOR ExecutionFlow»
-«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface»
+«FOREACH this.scopes.getUsableScopes() AS interface»
 «FILE interface.interfaceClassName()+".h"»
 
 #ifndef «interface.interfaceClassName().toUpperCase()»_H_
@@ -37,9 +37,15 @@ typedef struct {
 	handleEvent handleEventCallback;
 #else
 	EventPool* eventPool;
+«IF InternalScope.isInstance(interface) -»
+«FOREACH interface.declarations.typeSelect(EventDefinition) AS event -»
+    _Event* «event.getEventName()»;
+«ENDFOREACH -»
+«ELSE -»
 «FOREACH interface.getOutEvents() AS event -»
-    _Event* «event.name»;
-«ENDFOREACH»
+    _Event* «event.getEventName()»;
+«ENDFOREACH -»
+«ENDIF -»
 #endif // INTERFACE_LISTENER
 
 «FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
@@ -120,8 +126,8 @@ void 
 #ifndef INTERFACE_LISTENER
 	handle->eventPool = eventPool;
 «FOREACH interface.getOutEvents() AS event -»
-	handle->«event.name» = eventPool_createEvent(handle->eventPool, «event.getEventEnumName()»);
-	// ((«event.name»*)handle->«event.name»)->value = initial value for events is missing in model;
+	handle->«event.getEventName()» = eventPool_createEvent(handle->eventPool, «event.getEventEnumName()»);
+	// ((«event.getEventName()»*)handle->«event.getEventName()»)->value = initial value for events is missing in model;
 «ENDFOREACH»
 #endif
 
@@ -178,7 +184,7 @@ extern boolean 
 	boolean ret = bool_false;
 	if (eventSet_check(handle->eventSet,«event.getEventEnumName()»)) {
 «IF event.type != Type::void -»	
-		*value = ((«event.name»*)handle->«event.name»)->value;
+		*value = ((«event.getEventName()»*)handle->«event.getEventName()»)->value;
 «ENDIF»
 		ret = bool_true;
 	}
@@ -195,7 +201,7 @@ ENDIF
 	_Event* ev = eventPool_createEvent(handle->eventPool, «event.getEventEnumName()»);
 
 «IF event.type != Type::void -»
-	((«event.name»*)ev)->value = value;
+	((«event.getEventName()»*)ev)->value = value;
 «ENDIF»
 
 	if (ev != NULL)

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

@@ -4,6 +4,7 @@ import ecore;
 import sgraph;
 
 ExecutionFlow getExecutionFlow(InterfaceScope this) : ((ExecutionFlow)this.eContainer);
+ExecutionFlow getExecutionFlow(InternalScope this) : ((ExecutionFlow)this.eContainer);
 
 String scName(Expression statement) : ((ExecutionFlow)statement.eRootContainer).name;
 String scName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstLower();
@@ -13,7 +14,7 @@ List[EventDefinition] declaredEvents(ExecutionFlow flow) : flow.scopes.declarati
 List[TimeEvent] declaredTimerEvents(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(TimeEvent);
 List[VariableDefinition] declaredVariables(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(VariableDefinition);
 
-String test(NamedElement obj) :  "";
+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 stName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstLower() + "Statemachine";
@@ -51,14 +52,25 @@ Reaction reaction(Step this) : (Reaction) this.eContainer ;
 ExecutionState state(Reaction this) : (ExecutionState) eContainer;
 ExecutionState state(Step this) : (ExecutionState) eContainer;
 
+String interfaceName(Scope this) : "unknownScope";
+String interfaceClassName(Scope this) : "unknownScope";
+String interfaceObjectName(Scope this) : "unknownScope";
+
+
 String interfaceName(InterfaceScope this) : this.getExecutionFlow().name.toFirstLower() + ((this.name == null) ? "_if" : "_if_" + this.name);
 String interfaceClassName(InterfaceScope this) : this.getExecutionFlow().name.toFirstUpper() + "If" + ((this.name == null)?"":this.name.toFirstUpper());
 String interfaceObjectName(InterfaceScope this) : "interface" + ((this.name == null)?"":this.name.toFirstUpper());
 
+String interfaceName(InternalScope this) : this.getExecutionFlow().name.toFirstLower() + "internal";
+String interfaceClassName(InternalScope this) : this.getExecutionFlow().name.toFirstUpper() + "Internal";
+String interfaceObjectName(InternalScope this) : "interfaceInternal";
+
 //String getEventEnumName(EventDefinition this) : "ev_"+ ((InterfaceScope)this.eContainer).name + this.name.toFirstLower();
 String getEventEnumName(TimeEvent this) : "ev_" + this.name.toFirstLower();
 String getEventEnumName(Event this) : "ev_" + this.eContainer.getScopeName() + "_" + this.name.toFirstLower();
 
+String getEventName(Event this) : this.eContainer.getScopeName().toFirstUpper() + this.name.toFirstUpper();
+
 String getScopeName(emf::EObject eo) :
 	"<scope not defined>";