Prechádzať zdrojové kódy

OPEN - issue YAKHMI-895: Create new SCT C++ Code generator
https://intern.itemis.de/jira/browse/YAKHMI-895

markus.muehlbrandt@gmail.com 12 rokov pred
rodič
commit
55a1998442

+ 2 - 2
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/FlowCode.xtend

@@ -53,12 +53,12 @@ class FlowCode extends org.yakindu.sct.generator.c.FlowCode {
 
 	override dispatch CharSequence code(ScheduleTimeEvent it) '''
 		«stepComment»
-		«timerServiceInstance»->setTimer(this, (sc_eventid) &«timeEventsInstance»[«timeEvent.indexOf»] , «timeValue.code», «IF timeEvent.periodic»true«ELSE»false«ENDIF»);
+		«timerServiceInstance»->setTimer(this, &«timeEventsInstance»[«timeEvent.indexOf»], «timeValue.code», «IF timeEvent.periodic»true«ELSE»false«ENDIF»);
 	'''
 
 	override dispatch CharSequence code(UnscheduleTimeEvent it) '''
 		«stepComment»
-		«timerServiceInstance»->unsetTimer(this, (sc_eventid) &«timeEventsInstance»[«timeEvent.indexOf»]);		
+		«timerServiceInstance»->unsetTimer(this, &«timeEventsInstance»[«timeEvent.indexOf»]);
 	'''
 	
 	override dispatch CharSequence code(Execution it) 

+ 15 - 5
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/Naming.xtend

@@ -121,18 +121,28 @@ class Naming extends org.yakindu.sct.generator.c.Naming {
 		"isActive"
 	}
 	
-	override dispatch access (VariableDefinition it) 
-		'''«scope.instance»->«name.asEscapedIdentifier»'''
 
 	override dispatch access (OperationDefinition it) 
 		'''«asFunction»'''
 		
-	override dispatch access (Event it) 
-		'''«scope.instance»->«name.asIdentifier.raised»'''
-	
 	def dispatch access(TimeEvent it)
 		'''«timeEventsInstance»[«indexOf»]'''
+		
+	override dispatch access (VariableDefinition it) 
+		'''«scope.instance»->«name.asEscapedIdentifier»'''
+	
+	override dispatch access (Event it) 
+		'''«scope.instance»->«name.asIdentifier.raised»'''
 	
 	override valueAccess(Event it) 
 		'''«scope.instance»->«name.asIdentifier.value»'''
+		
+	def dispatch localAccess (VariableDefinition it) 
+		'''«name.asEscapedIdentifier»'''
+	
+	def dispatch localAccess (Event it) 
+		'''«name.asIdentifier.raised»'''
+	
+	def localValueAccess(Event it) 
+		'''«name.asIdentifier.value»'''
 }

+ 6 - 3
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineHeader.xtend

@@ -60,7 +60,9 @@ class StatemachineHeader extends Statemachine {
 		class «module()» : «interfaceExtensions» {
 			
 			public:
-			
+				
+				«flow.module()»();
+				
 				«statesEnumDecl»
 				
 				«FOR s : it.scopes»«s.createScope()»«ENDFOR»
@@ -82,7 +84,7 @@ class StatemachineHeader extends Statemachine {
 		#endif /* «module().define»_H_ */
 	'''
 	
-	def getInterfaceExtensions(ExecutionFlow flow) {
+	def private getInterfaceExtensions(ExecutionFlow flow) {
 
 		var String interfaces = "";
 
@@ -122,6 +124,7 @@ class StatemachineHeader extends Statemachine {
 				«ENDFOR»
 				
 			private:
+				friend class «scope.execution_flow.module()»;
 				«FOR d : scope.declarations»
 				 «d.structDeclaration»
 				«ENDFOR»
@@ -187,7 +190,7 @@ class StatemachineHeader extends Statemachine {
 		sc_ushort stateConfVectorPosition;
 		
 		«FOR s : scopes.filter(typeof(StatechartScope))»
-			const «s.interfaceName»* «s.instance»;
+			«s.interfaceName»* «s.instance»;
 		«ENDFOR»
 	'''
 	

+ 48 - 19
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineImplementation.xtend

@@ -19,8 +19,8 @@ import org.yakindu.sct.model.sexec.Step
 import org.yakindu.sct.model.sgraph.Statechart
 import org.yakindu.sct.model.sgen.GeneratorEntry
 import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess
-import org.yakindu.sct.generator.c.GenmodelEntries
-
+import org.yakindu.sct.generator.c.GenmodelEntries
import org.yakindu.sct.model.stext.stext.StatechartScope
+
 class StatemachineImplementation {
 	
 	@Inject extension Naming
@@ -39,6 +39,8 @@ class StatemachineImplementation {
 		#include "«module.hpp»"
 		/*! \file Implementation of the state machine '«name»'
 		*/
+		
+		«constructorDecl»
 		
 		«initFunction»
 		
@@ -46,11 +48,11 @@ class StatemachineImplementation {
 		
 		«exitFunction»
 		
+		«runCycleFunction»
+		
 		«clearInEventsFunction»
 		
 		«clearOutEventsFunction»
-		
-		«runCycleFunction»
 
 		«raiseTimeEventFunction»
 
@@ -60,7 +62,26 @@ class StatemachineImplementation {
 				
 		«functionImplementations»
 	'''
-	
+	
+	def constructorDecl(ExecutionFlow it) '''
+		«module»::«module»() {
+			
+			«FOR s : scopes.filter(typeof(StatechartScope))»
+			«s.instance» = new «s.interfaceName»();
+		«ENDFOR»
+		«IF hasHistory»
+			
+			for (i = 0; i < «historyStatesConst»; ++i)
+				historyVector[i] = «last_state»;
+			«ENDIF»
+			
+			stateConfVectorPosition = 0;
+			
+			«IF timed»
+			timerService = NULL;
+			«ENDIF»
+		}
+	'''
 	
 	def initFunction(ExecutionFlow it) '''
 		void «module»::init()
@@ -160,11 +181,19 @@ class StatemachineImplementation {
 	
 	def raiseTimeEventFunction(ExecutionFlow it) '''
 		«IF timed»
+			
+			void «module»::setTimerService(«timerServiceInterface»* timerService){
+				this->timerService = timerService;
+			}
+			
+			«timerServiceInterface»* «module»::getTimerService(){
+				return timerService;
+			}
+			
 			void «module»::«nameOfRaiseTimeEventFunction»(sc_eventid evid) {
-				if ( ((intptr_t)evid) >= ((intptr_t)&(timeEvents))
-					&&  ((intptr_t)evid) < ((intptr_t)&(timeEvents)) + sizeof(timeEvents)) {
-					*(sc_boolean*)evid = true;
-				}		
+				if ((evid >= &timeEvents) && (evid < &timeEvents + sizeof(timeEvents))) {
+					*(sc_boolean*)evid = true;
+				}
 			}
 		«ENDIF»
 	'''
@@ -192,20 +221,20 @@ class StatemachineImplementation {
 			«FOR event : scope.incomingEvents»
 				void «module»::«scope.interfaceName»::«event.asRaiser»(«event.valueParams») {
 					«IF event.hasValue»
-					«event.valueAccess» = value;
+					«event.localValueAccess» = value;
 					«ENDIF»
-					«event.access» = true;
+					«event.localAccess» = true;
 				}
 			«ENDFOR»
 			
 			«FOR event : scope.outgoingEvents»
 				sc_boolean «module»::«scope.interfaceName»::«event.asRaised»() {
-					return «event.access»;
+					return «event.localAccess»;
 				}
 				«IF event.hasValue» 
 					«event.type.targetLanguageName» «module»::«scope.interfaceName»::«event.asGetter»() {
 						//TODO: Check if event is not raised
-						return «event.valueAccess»;
+						return «event.localValueAccess»;
 					}
 				«ENDIF»
 			«ENDFOR»
@@ -213,29 +242,29 @@ class StatemachineImplementation {
 			«FOR event : scope.localEvents»
 				void «module»::«scope.interfaceName»::«event.asRaiser»(«event.valueParams») {
 					«IF event.hasValue»
-					«event.valueAccess» = value;
+					«event.localValueAccess» = value;
 					«ENDIF»
-					«event.access» = true;
+					«event.localAccess» = true;
 				}
 				
 				sc_boolean «module»::«scope.interfaceName»::«event.asRaised»() {
-					return «event.access»;
+					return «event.localAccess»;
 				}
 				«IF event.hasValue» 
 					«event.type.targetLanguageName» «module»::«scope.interfaceName»::«event.asGetter»() {
 						//TODO: Check if event is not raised
-						return «event.valueAccess»;
+						return «event.localValueAccess»;
 					}
 				«ENDIF»
 			«ENDFOR»
 			
 			«FOR variable : scope.variableDefinitions»
 				«variable.type.targetLanguageName» «module»::«scope.interfaceName»::«variable.asGetter»() {
-					return «variable.access»;
+					return «variable.localAccess»;
 				}
 				«IF !variable.readonly »
 				void «module»::«scope.interfaceName»::«variable.asSetter»(«variable.type.targetLanguageName» value) {
-					«variable.access» = value;
+					«variable.localAccess» = value;
 				}
 				«ENDIF»
 			«ENDFOR»

+ 1 - 2
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/Types.xtend

@@ -32,13 +32,12 @@ class Types {
 		#ifndef «typesModule.define»_H_
 		#define «typesModule.define»_H_
 		
-		#include <cstdint>
 		#include <string>
 		
 		typedef unsigned char	sc_ushort;
 		typedef int				sc_integer;  
 		typedef double			sc_real;
-		typedef string			sc_string;
+		typedef std::string		sc_string;
 		typedef bool			sc_boolean;
 		
 		typedef void*			sc_eventid;

BIN
plugins/org.yakindu.sct.generator.cpp/xtend-gen/org/yakindu/sct/generator/cpp/.Naming.java._trace


BIN
plugins/org.yakindu.sct.generator.cpp/xtend-gen/org/yakindu/sct/generator/cpp/.Types.java._trace