Browse Source

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

markus.muehlbrandt@gmail.com 12 years ago
parent
commit
1fcc66f668

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

@@ -26,7 +26,7 @@ class CppGenerator implements IExecutionFlowGenerator {
 	 
 	@Inject extension Types
 	@Inject extension TimedStatemachineInterface
-	@Inject extension TimerServiceInterface
+	@Inject extension TimerInterface
 	@Inject extension StatemachineInterface
 	@Inject extension StatemachineHeader
 	@Inject extension StatemachineImplementation

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

@@ -25,7 +25,6 @@ class Naming extends org.yakindu.sct.generator.c.Naming {
 	
 	@Inject extension Navigation;
 	
-	def hpp(String it) { it + ".hpp" }
 	def cpp(String it) { it + ".cpp" }
 	
 	def abstractModule(ExecutionFlow it) {
@@ -48,8 +47,8 @@ class Naming extends org.yakindu.sct.generator.c.Naming {
 		'TimedStatemachineInterface'
 	}
 	
-	def timerServiceInterface() {
-		'TimerServiceInterface'
+	def timerInterface() {
+		'TimerInterface'
 	}
 	
 	def timerServiceInstance() {

+ 9 - 7
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineHeader.xtend

@@ -39,7 +39,7 @@ class StatemachineHeader extends Statemachine {
 	@Inject extension GenmodelEntries
 	
 	def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
-		 fsa.generateFile(flow.module().hpp, flow.statemachineHContent(entry) )
+		 fsa.generateFile(flow.module().h, flow.statemachineHContent(entry) )
 	}
 	
 	override statemachineHContent(ExecutionFlow it,  GeneratorEntry entry) '''
@@ -48,10 +48,10 @@ class StatemachineHeader extends Statemachine {
 		#ifndef «module().define»_H_
 		#define «module().define»_H_
 
-		#include "«typesModule.hpp»"
-		#include "«statemachineInterface.hpp»"
+		#include "«typesModule.h»"
+		#include "«statemachineInterface.h»"
 		«IF timed»
-			#include "«timedStatemachineInterface.hpp»"
+			#include "«timedStatemachineInterface.h»"
 		«ENDIF»
 
 		/*! \file Header of the state machine '«name»'.
@@ -63,6 +63,8 @@ class StatemachineHeader extends Statemachine {
 				
 				«flow.module()»();
 				
+				~«flow.module()»();
+				
 				«statesEnumDecl»
 				
 				«FOR s : it.scopes»«s.createScope()»«ENDFOR»
@@ -180,7 +182,7 @@ class StatemachineHeader extends Statemachine {
 		static const sc_integer «historyStatesConst» = «historyVector.size»;«ENDIF»
 		
 		«IF timed»
-			«timerServiceInterface»* «timerServiceInstance»;
+			«timerInterface»* «timerServiceInstance»;
 			sc_boolean «timeEventsInstance»[«timeEvents.size»];
 		«ENDIF»
 		
@@ -213,9 +215,9 @@ class StatemachineHeader extends Statemachine {
 	'''
 	
 	def ITimedStatemachineFunctions(ExecutionFlow it) '''
-		void setTimerService(«timerServiceInterface»* timerService);
+		void setTimerService(«timerInterface»* timerService);
 		
-		«timerServiceInterface»* getTimerService();
+		«timerInterface»* getTimerService();
 		
 		void «nameOfRaiseTimeEventFunction»(sc_eventid event);
 	'''

+ 10 - 3
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineImplementation.xtend

@@ -36,11 +36,13 @@ class StatemachineImplementation {
 	def statemachineContent(ExecutionFlow it, GeneratorEntry entry) '''
 		«entry.licenseText»
 		
-		#include "«module.hpp»"
+		#include "«module.h»"
 		/*! \file Implementation of the state machine '«name»'
 		*/
 		
 		«constructorDecl»
+		
+		«destructorDecl»
 		
 		«initFunction»
 		
@@ -82,6 +84,11 @@ class StatemachineImplementation {
 			«ENDIF»
 		}
 	'''
+	
+	def destructorDecl(ExecutionFlow it) '''
+		«module»::~«module»() {
+		}
+	'''
 	
 	def initFunction(ExecutionFlow it) '''
 		void «module»::init()
@@ -182,11 +189,11 @@ class StatemachineImplementation {
 	def raiseTimeEventFunction(ExecutionFlow it) '''
 		«IF timed»
 			
-			void «module»::setTimerService(«timerServiceInterface»* timerService){
+			void «module»::setTimerService(«timerInterface»* timerService){
 				this->timerService = timerService;
 			}
 			
-			«timerServiceInterface»* «module»::getTimerService(){
+			«timerInterface»* «module»::getTimerService(){
 				return timerService;
 			}
 			

+ 3 - 1
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineInterface.xtend

@@ -24,7 +24,7 @@ class StatemachineInterface {
 	extension GenmodelEntries
 	
 	def generateIStatemachine(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		fsa.generateFile(statemachineInterface.hpp, flow.content(entry) )
+		fsa.generateFile(statemachineInterface.h, flow.content(entry) )
 	}
 	
 	def private content(ExecutionFlow it, GeneratorEntry entry) {
@@ -39,7 +39,9 @@ class StatemachineInterface {
 		 */
 		class «statemachineInterface» {
 			public:
+			
 				virtual ~«statemachineInterface»() = 0;
+				
 				/*
 				* Initializes the statemachine. Use to init internal variables etc.
 				*/

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

@@ -24,7 +24,7 @@ class TimedStatemachineInterface {
 	extension GenmodelEntries
 	
 	def generateITimedStatemachine(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		fsa.generateFile(timedStatemachineInterface.hpp, flow.content(entry) )
+		fsa.generateFile(timedStatemachineInterface.h, flow.content(entry) )
 	}
 	
 	def private content(ExecutionFlow it, GeneratorEntry entry) {
@@ -34,8 +34,8 @@ class TimedStatemachineInterface {
 		#ifndef «timedStatemachineInterface.define»_H_
 		#define «timedStatemachineInterface.define»_H_
 		
-		#include "«typesModule.hpp»"
-		#include "«timerServiceInterface.hpp»"
+		#include "«typesModule.h»"
+		#include "«timerInterface.h»"
 		
 		/*
 		* Interface for state machines which use timed event triggers.
@@ -50,12 +50,12 @@ class TimedStatemachineInterface {
 				* externally on a timed state machine before a run cycle can be correct
 				* executed.
 				*/
-				virtual void setTimerService(«timerServiceInterface»* timerService) = 0;
+				virtual void setTimerService(«timerInterface»* timerService) = 0;
 				
 				/*
 				* Returns the currently used timer service.
 				*/
-				virtual «timerServiceInterface»* getTimerService() = 0;
+				virtual «timerInterface»* getTimerService() = 0;
 				
 				/*
 				* Callback method if a time event occurred.

+ 9 - 9
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/TimerServiceInterface.xtend

@@ -15,7 +15,7 @@ import org.eclipse.xtext.generator.IFileSystemAccess
 import com.google.inject.Inject
 import org.yakindu.sct.generator.c.GenmodelEntries
 
-class TimerServiceInterface {
+class TimerInterface {
 	
 	@Inject
 	extension Naming
@@ -24,25 +24,25 @@ class TimerServiceInterface {
 	extension GenmodelEntries
 	
 	def generateITimerService(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		fsa.generateFile(timerServiceInterface.hpp, flow.content(entry) )
+		fsa.generateFile(timerInterface.h, flow.content(entry) )
 	}
 	
 	def private content(ExecutionFlow it, GeneratorEntry entry) {
 		'''
 		«entry.licenseText»
 		
-		#ifndef «timerServiceInterface.define»_H_
-		#define «timerServiceInterface.define»_H_
+		#ifndef «timerInterface.define»_H_
+		#define «timerInterface.define»_H_
 		
-		#include "«timedStatemachineInterface.hpp»"
+		#include "«timedStatemachineInterface.h»"
 		
 		/*
 		 * Basic interface for statemachines.
 		 */
-		class «timerServiceInterface» {
+		class «timerInterface» {
 			public:
-			
-				virtual ~«timerServiceInterface»() = 0;
+				
+				virtual ~«timerInterface»() = 0;
 			
 				/*
 				 * Starts the timing for a time event.
@@ -61,7 +61,7 @@ class TimerServiceInterface {
 				virtual void cancel() = 0;
 		};
 		
-		#endif /* «timerServiceInterface.define»_H_ */
+		#endif /* «timerInterface.define»_H_ */
 		'''
 	}
 }

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

@@ -23,7 +23,7 @@ class Types {
 	@Inject extension GenmodelEntries
 	 
 	def generateTypesHpp(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
-		 fsa.generateFile(flow.typesModule.hpp, flow.typesHContent(entry))
+		 fsa.generateFile(flow.typesModule.h, flow.typesHContent(entry))
 	}
 	
 	def typesHContent(ExecutionFlow it, GeneratorEntry entry) '''

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


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