Browse Source

Moved const definitions to .c file

Markus Mühlbrandt 9 years ago
parent
commit
d738c143d4

+ 90 - 92
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Statemachine.xtend

@@ -25,96 +25,96 @@ import org.yakindu.sct.model.stext.stext.EventDefinition
 import org.yakindu.sct.model.stext.stext.InterfaceScope
 import org.yakindu.sct.model.stext.stext.StatechartScope
 import org.yakindu.sct.model.stext.stext.VariableDefinition
+import org.yakindu.sct.model.stext.stext.InternalScope
+import static org.eclipse.xtext.util.Strings.*
 
 class Statemachine {
-	
+
 	@Inject extension Naming cNaming
 	@Inject extension Navigation
 	@Inject extension ICodegenTypeSystemAccess
 	@Inject extension GenmodelEntries
 	@Inject extension INamingService
-	@Inject extension ConstantInitializationResolver
-	
+
 	def generateStatemachineH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
-		 flow.initializeNamingService
-		 fsa.generateFile(flow.module.h, flow.statemachineHContent(entry) )
+		flow.initializeNamingService
+		fsa.generateFile(flow.module.h, flow.statemachineHContent(entry))
 	}
-	
-	def statemachineHContent(ExecutionFlow it,  GeneratorEntry entry) '''
-			«entry.licenseText»
-			
-			#ifndef «module.define»_H_
-			#define «module.define»_H_
-
-			#include "«typesModule.h»"
-			
-			#ifdef __cplusplus
-			extern "C" { 
-			#endif 
-
-			/*! \file Header of the state machine '«name»'.
-			*/
-			
-			«statesEnumDecl»
-			
-			«FOR s : it.scopes»«s.scopeTypeDecl»«ENDFOR»
-			
-			«statemachineTypeDecl»
 
-			/*! Initializes the «type» state machine data structures. Must be called before first usage.*/
-			extern void «functionPrefix»init(«scHandleDecl»);
-			
-			/*! Activates the state machine */
-			extern void «functionPrefix»enter(«scHandleDecl»);
-			
-			/*! Deactivates the state machine */
-			extern void «functionPrefix»exit(«scHandleDecl»);
-			
-			/*! Performs a 'run to completion' step. */
-			extern void «functionPrefix»runCycle(«scHandleDecl»);
-
-			«IF timed»
-				/*! Raises a time event. */
-				extern void «raiseTimeEventFctID»(«scHandleDecl», sc_eventid evid);
-			«ENDIF»
-			
-			«FOR s : it.scopes.filter( typeof(InterfaceScope) )»
-				«s.scopeFunctionPrototypes»
-			«ENDFOR»
-			
-			/*!
-			 * Checks if the statemachine is active (until 2.4.1 this method was used for states).
-			 * A statemachine is active if it was entered. It is inactive if it has not been entered at all or if it was exited.
-			 */
-			extern sc_boolean «isActiveFctID»(const «scHandleDecl»);
-			
-			/*!
-			 * Checks if all active states are final. 
-			 * If there are no active states then the statemachine is considered as inactive and this method returns false.
-			 */
-			extern sc_boolean «isFinalFctID»(const «scHandleDecl»);
-			
-			/*! Checks if the specified state is active (until 2.4.1 the used method for states was calles isActive()). */
-			extern sc_boolean «stateActiveFctID»(const «scHandleDecl», «statesEnumType» state);
-			
-			#ifdef __cplusplus
-			}
-			#endif 
-			
-			#endif /* «module.define»_H_ */
+	def statemachineHContent(ExecutionFlow it, GeneratorEntry entry) '''
+		«entry.licenseText»
+		
+		#ifndef «module.define»_H_
+		#define «module.define»_H_
+		
+		#include "«typesModule.h»"
+		
+		#ifdef __cplusplus
+		extern "C" { 
+		#endif 
+		
+		/*! \file Header of the state machine '«name»'.
+		*/
+		
+		«statesEnumDecl»
+		
+		«FOR s : it.scopes»«s.scopeTypeDecl»«ENDFOR»
+		
+		«statemachineTypeDecl»
+		
+		/*! Initializes the «type» state machine data structures. Must be called before first usage.*/
+		extern void «functionPrefix»init(«scHandleDecl»);
+		
+		/*! Activates the state machine */
+		extern void «functionPrefix»enter(«scHandleDecl»);
+		
+		/*! Deactivates the state machine */
+		extern void «functionPrefix»exit(«scHandleDecl»);
+		
+		/*! Performs a 'run to completion' step. */
+		extern void «functionPrefix»runCycle(«scHandleDecl»);
+		
+		«IF timed»
+			/*! Raises a time event. */
+			extern void «raiseTimeEventFctID»(«scHandleDecl», sc_eventid evid);
+		«ENDIF»
+		
+		«FOR s : it.scopes.filter( typeof(InterfaceScope) )»
+			«s.scopeFunctionPrototypes»
+		«ENDFOR»
+		
+		/*!
+		 * Checks if the statemachine is active (until 2.4.1 this method was used for states).
+		 * A statemachine is active if it was entered. It is inactive if it has not been entered at all or if it was exited.
+		 */
+		extern sc_boolean «isActiveFctID»(const «scHandleDecl»);
+		
+		/*!
+		 * Checks if all active states are final. 
+		 * If there are no active states then the statemachine is considered as inactive and this method returns false.
+		 */
+		extern sc_boolean «isFinalFctID»(const «scHandleDecl»);
+		
+		/*! Checks if the specified state is active (until 2.4.1 the used method for states was calles isActive()). */
+		extern sc_boolean «stateActiveFctID»(const «scHandleDecl», «statesEnumType» state);
+		
+		#ifdef __cplusplus
+		}
+		#endif 
+		
+		#endif /* «module.define»_H_ */
 	'''
 
 	def statesEnumDecl(ExecutionFlow it) '''
 		/*! Enumeration of all states */ 
 		typedef enum {
-			«FOR state : states »
-			«state.shortName»,
+			«FOR state : states»
+				«state.shortName»,
 			«ENDFOR»
 			«null_state»
 		} «statesEnumType»;
 	'''
 
-
 	def dispatch structDeclaration(EventDefinition it) '''
 		sc_boolean «name.asIdentifier»_raised;
 		«IF type != null && type.name != 'void'»«type.targetLanguageName» «name.asIdentifier»_value;«ENDIF»
@@ -127,30 +127,30 @@ class Statemachine {
 	def dispatch structDeclaration(VariableDefinition it) '''
 		«IF type.name != 'void' && !isConst»«type.targetLanguageName» «name.asEscapedIdentifier»;«ENDIF»
 	'''
-	
+
 	def dispatch structDeclaration(Declaration it) ''''''
-	
-	
+
 	def scopeTypeDecl(Scope it) '''
 		/*! Type definition of the data structure for the «type» interface scope. */
 		typedef struct {
-			«FOR d : declarations »
-			«d.structDeclaration»
+			«FOR d : declarations»
+				«d.structDeclaration»
 			«ENDFOR»
 		} «it.type»;
 		
-		/* Declaration of constants for scope «type». */
-		«FOR d : declarations.filter(typeof(VariableDefinition)).filter[const]»
-			«IF d.type.name != 'void'»static const «d.type.targetLanguageName» «d.constantName» = «d.initialValue.resolveConstants»;«ENDIF»
-		«ENDFOR»
-
+		«IF !(it instanceof InternalScope)»
+			/* Declaration of constants for scope «type». */
+			«FOR d : declarations.filter(typeof(VariableDefinition)).filter[const] AFTER newLine»
+				«IF d.type.name != 'void'»extern const «d.type.targetLanguageName» «d.constantName»;«ENDIF»
+			«ENDFOR»
+		«ENDIF»
 	'''
 
 	def statemachineTypeDecl(ExecutionFlow it) '''
 		/*! Define dimension of the state configuration vector for orthogonal states. */
 		#define «type.toUpperCase»_MAX_ORTHOGONAL_STATES «stateVector.size»
 		«IF hasHistory»
-		/*! Define dimension of the state configuration vector for history states. */
+			/*! Define dimension of the state configuration vector for history states. */
 		#define «type.toUpperCase»_MAX_HISTORY_STATES «historyVector.size»«ENDIF»
 		
 		/*! 
@@ -162,29 +162,27 @@ class Statemachine {
 			«IF hasHistory»«statesEnumType» historyVector[«type.toUpperCase»_MAX_HISTORY_STATES];«ENDIF»
 			sc_ushort stateConfVectorPosition; 
 			
-			«FOR iScope : scopes »
-			«iScope.type» «iScope.instance»;
+			«FOR iScope : scopes»
+				«iScope.type» «iScope.instance»;
 			«ENDFOR»			
 		} «type»;
 	'''
 
-
 	def dispatch scopeFunctionPrototypes(StatechartScope it) '''
-		«FOR d : declarations »
-		«d.functionPrototypes »
+		«FOR d : declarations»
+			«d.functionPrototypes »
 		«ENDFOR»
-	'''	
+	'''
 
-	def dispatch scopeFunctionPrototypes(Object it) ''''''	
-	
+	def dispatch scopeFunctionPrototypes(Object it) ''''''
 
 	def dispatch functionPrototypes(Declaration it) ''''''
 
 	def dispatch functionPrototypes(EventDefinition it) '''
 		«IF direction == Direction::IN»
-		/*! Raises the in event '«name»' that is defined in the «scope.scopeDescription». */ 
-		extern void «asRaiser»(«scHandleDecl»«valueParams»);
-		
+			/*! Raises the in event '«name»' that is defined in the «scope.scopeDescription». */ 
+			extern void «asRaiser»(«scHandleDecl»«valueParams»);
+			
 		«ELSE»
 			/*! Checks if the out event '«name»' that is defined in the «scope.scopeDescription» has been raised. */ 
 			extern sc_boolean «asRaised»(const «scHandleDecl»);

+ 14 - 4
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineC.xtend

@@ -21,6 +21,8 @@ import org.yakindu.sct.model.sexec.extensions.StateVectorExtensions
 import org.yakindu.sct.model.sexec.naming.INamingService
 import org.yakindu.sct.model.sgen.GeneratorEntry
 import org.yakindu.sct.model.sgraph.Statechart
+import org.yakindu.sct.model.stext.stext.VariableDefinition
+import org.yakindu.sct.model.stext.stext.StatechartScope
 
 class StatemachineC {
 	
@@ -30,6 +32,7 @@ class StatemachineC {
 	@Inject extension ICodegenTypeSystemAccess
 	@Inject extension INamingService
 	@Inject extension FlowCode
+	@Inject extension ConstantInitializationResolver
 	@Inject protected extension StateVectorExtensions
 	
 	def generateStatemachineC(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
@@ -54,6 +57,8 @@ class StatemachineC {
 		
 		«functionPrototypes»
 		
+		«constantDefinitions»
+		
 		«initFunction»
 		
 		«enterFunction»
@@ -278,7 +283,6 @@ class StatemachineC {
 	/** */
 	def functionPrototypes(ExecutionFlow it) '''
 		/* prototypes of all internal functions */
-		
 		«checkFunctions.toPrototypes»
 		«effectFunctions.toPrototypes»
 		«entryActionFunctions.toPrototypes»
@@ -287,10 +291,16 @@ class StatemachineC {
 		«exitSequenceFunctions.toPrototypes»
 		«reactFunctions.toPrototypes»
 		static void «clearInEventsFctID»(«scHandleDecl»);
-		static void «clearOutEventsFctID»(«scHandleDecl»);
-		
+		static void «clearOutEventsFctID»(«scHandleDecl»);	
+	'''
+	
+	def constantDefinitions(ExecutionFlow it) '''
+		«FOR scope : scopes.filter(typeof(StatechartScope))»
+			«FOR d : scope.declarations.filter(typeof(VariableDefinition)).filter[const]»
+				«IF d.type.name != 'void'»const «d.type.targetLanguageName» «d.access» = «d.initialValue.resolveConstants»;«ENDIF»
+			«ENDFOR»
+		«ENDFOR»
 	'''
-	 
 	 
 	def toPrototypes(List<Step> steps) '''
 		«FOR s : steps»

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

@@ -25,6 +25,7 @@ import org.yakindu.sct.model.sgraph.Statechart
 import org.yakindu.sct.model.stext.stext.InterfaceScope
 import org.yakindu.sct.model.stext.stext.StatechartScope
 import org.yakindu.sct.model.stext.stext.VariableDefinition
+import static org.eclipse.xtext.util.Strings.*
 
 class StatemachineImplementation {
 	
@@ -256,14 +257,9 @@ class StatemachineImplementation {
 		}'''
 	}
 	
-	
-	/* ===================================================================================
-	 * Implementation of interface element access functions
-	 */
-	 
 	def constantDefinitions(ExecutionFlow it) '''
 		«FOR scope : statechartScopes»
-			«FOR d : scope.declarations.filter(typeof(VariableDefinition)).filter[const]»
+			«FOR d : scope.declarations.filter(typeof(VariableDefinition)).filter[const] AFTER newLine»
 				«IF d.type.name != 'void'»const «d.type.targetLanguageName» «d.access» = «d.initialValue.code»;«ENDIF»
 			«ENDFOR»
 		«ENDFOR»