Browse Source

Extract more names into functions

René Beckmann 7 years ago
parent
commit
3544076cfe

+ 10 - 10
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineHeader.xtend

@@ -98,16 +98,16 @@ class StatemachineHeader implements IContentTemplate {
 		'''
 		'''
 		
 		
 		/*! Initializes the «type» state machine data structures. Must be called before first usage.*/
 		/*! Initializes the «type» state machine data structures. Must be called before first usage.*/
-		extern void «functionPrefix»init(«scHandleDecl»);
+		extern void «initFctID»(«scHandleDecl»);
 		
 		
 		/*! Activates the state machine */
 		/*! Activates the state machine */
-		extern void «functionPrefix»enter(«scHandleDecl»);
+		extern void «enterFctID»(«scHandleDecl»);
 		
 		
 		/*! Deactivates the state machine */
 		/*! Deactivates the state machine */
-		extern void «functionPrefix»exit(«scHandleDecl»);
+		extern void «exitFctID»(«scHandleDecl»);
 		
 		
 		/*! Performs a 'run to completion' step. */
 		/*! Performs a 'run to completion' step. */
-		extern void «functionPrefix»runCycle(«scHandleDecl»);
+		extern void «runCycleFctID»(«scHandleDecl»);
 		
 		
 		«IF timed»
 		«IF timed»
 			/*! Raises a time event. */
 			/*! Raises a time event. */
@@ -157,22 +157,22 @@ class StatemachineHeader implements IContentTemplate {
 		{
 		{
 			«null_state»,
 			«null_state»,
 			«FOR state : states SEPARATOR ","»
 			«FOR state : states SEPARATOR ","»
-				«state.shortName»
+				«state.stateName»
 			«ENDFOR»
 			«ENDFOR»
 		} «statesEnumType»;
 		} «statesEnumType»;
 	'''
 	'''
 
 
 	def dispatch scopeTypeDeclMember(EventDefinition it) '''
 	def dispatch scopeTypeDeclMember(EventDefinition it) '''
-		sc_boolean «name.asIdentifier»_raised;
-		«IF type != null && type.name != 'void'»«typeSpecifier.targetLanguageName» «name.asIdentifier»_value;«ENDIF»
+		«bool» «eventRaisedFlag»;
+		«IF type != null && type.name != 'void'»«typeSpecifier.targetLanguageName» «eventValueVariable»;«ENDIF»
 	'''
 	'''
 
 
 	def dispatch scopeTypeDeclMember(TimeEvent it) '''
 	def dispatch scopeTypeDeclMember(TimeEvent it) '''
-		sc_boolean «shortName.raised»;
+		«bool» «timeEventRaisedFlag»;
 	'''
 	'''
 
 
 	def dispatch scopeTypeDeclMember(VariableDefinition it) '''
 	def dispatch scopeTypeDeclMember(VariableDefinition it) '''
-		«IF type.name != 'void' && !isConst»«typeSpecifier.targetLanguageName» «name.asEscapedIdentifier»;«ENDIF»
+		«IF type.name != 'void' && !isConst»«typeSpecifier.targetLanguageName» «variable»;«ENDIF»
 	'''
 	'''
 	
 	
 	def dispatch scopeTypeDeclMember(Declaration it) ''''''
 	def dispatch scopeTypeDeclMember(Declaration it) ''''''
@@ -287,7 +287,7 @@ class StatemachineHeader implements IContentTemplate {
 
 
 	def dispatch functionPrototypes(VariableDefinition it) '''
 	def dispatch functionPrototypes(VariableDefinition it) '''
 		/*! Gets the value of the variable '«name»' that is defined in the «scope.scopeDescription». */ 
 		/*! Gets the value of the variable '«name»' that is defined in the «scope.scopeDescription». */ 
-		extern «IF const»const «ENDIF»«typeSpecifier.targetLanguageName» «it.asGetter»(const «scHandleDecl»);
+		extern «IF const»const «ENDIF»«typeSpecifier.targetLanguageName» «asGetter»(const «scHandleDecl»);
 		«IF !readonly && !const»
 		«IF !readonly && !const»
 			/*! Sets the value of the variable '«name»' that is defined in the «scope.scopeDescription». */ 
 			/*! Sets the value of the variable '«name»' that is defined in the «scope.scopeDescription». */ 
 			extern void «asSetter»(«scHandleDecl», «typeSpecifier.targetLanguageName» value);
 			extern void «asSetter»(«scHandleDecl», «typeSpecifier.targetLanguageName» value);

+ 6 - 6
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequiredHeader.xtend

@@ -50,8 +50,8 @@ class StatemachineRequiredHeader implements IContentTemplate {
 		
 		
 		«IF timed»
 		«IF timed»
 			This is a state machine uses time events which require access to a timing service. Thus the function prototypes:
 			This is a state machine uses time events which require access to a timing service. Thus the function prototypes:
-				- «type.toFirstLower»_setTimer and
-				- «type.toFirstLower»_unsetTimer
+				- «setTimerFctID» and
+				- «unsetTimerFctID»
 			are defined.
 			are defined.
 			
 			
 		«ENDIF»
 		«ENDIF»
@@ -85,14 +85,14 @@ class StatemachineRequiredHeader implements IContentTemplate {
 			\time_ms The time in milli seconds
 			\time_ms The time in milli seconds
 			\periodic Indicates the the time event must be raised periodically until the timer is unset 
 			\periodic Indicates the the time event must be raised periodically until the timer is unset 
 		*/
 		*/
-		extern void «type.toFirstLower»_setTimer(«scHandleDecl», const sc_eventid evid, const sc_integer time_ms, const sc_boolean periodic);
+		extern void «setTimerFctID»(«scHandleDecl», const sc_eventid evid, const sc_integer time_ms, const sc_boolean periodic);
 
 
 		/*! This function has to unset timers for the time events that are required by the state machine. */
 		/*! This function has to unset timers for the time events that are required by the state machine. */
 		/*! 
 		/*! 
 			This function will be called for each time event taht is relevant for a state when a state will be left.
 			This function will be called for each time event taht is relevant for a state when a state will be left.
 			\param evid An unique identifier of the event.
 			\param evid An unique identifier of the event.
 		*/
 		*/
-		extern void «type.toFirstLower»_unsetTimer(«scHandleDecl», const sc_eventid evid);
+		extern void «unsetTimerFctID»(«scHandleDecl», const sc_eventid evid);
 		«ENDIF»
 		«ENDIF»
 		
 		
 		
 		
@@ -102,12 +102,12 @@ class StatemachineRequiredHeader implements IContentTemplate {
 		 */
 		 */
 		«IF entry.tracingEnterState»
 		«IF entry.tracingEnterState»
 			/*! This function is called when a state is entered. */
 			/*! This function is called when a state is entered. */
-			extern void «type.toFirstLower»_stateEntered(«scHandleDecl», const «statesEnumType» state);
+			extern void «enterStateTracingFctID»(«scHandleDecl», const «statesEnumType» state);
 		«ENDIF»
 		«ENDIF»
 		
 		
 		«IF entry.tracingExitState»
 		«IF entry.tracingExitState»
 			/*! This function is called when a state is exited. */
 			/*! This function is called when a state is exited. */
-			extern void «type.toFirstLower»_stateExited(«scHandleDecl», const «statesEnumType» state);
+			extern void «exitStateTracingFctID»(«scHandleDecl», const «statesEnumType» state);
 		«ENDIF»
 		«ENDIF»
 		«ENDIF»
 		«ENDIF»
 		
 		

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

@@ -95,7 +95,7 @@ class StatemachineSource implements IContentTemplate {
 	'''
 	'''
 	
 	
 	def initFunction(ExecutionFlow it) '''
 	def initFunction(ExecutionFlow it) '''
-		void «functionPrefix»init(«scHandleDecl»)
+		void «initFctID»(«scHandleDecl»)
 		{
 		{
 			«initFunctionBody(it)»
 			«initFunctionBody(it)»
 		}
 		}
@@ -128,14 +128,14 @@ class StatemachineSource implements IContentTemplate {
 	
 	
 	
 	
 	def enterFunction(ExecutionFlow it) '''
 	def enterFunction(ExecutionFlow it) '''
-		void «functionPrefix»enter(«scHandleDecl»)
+		void «enterFctID»(«scHandleDecl»)
 		{
 		{
 			«enterSequences.defaultSequence.code»
 			«enterSequences.defaultSequence.code»
 		}
 		}
 	'''
 	'''
 	
 	
 	def exitFunction(ExecutionFlow it) '''
 	def exitFunction(ExecutionFlow it) '''
-		void «type.toFirstLower»_exit(«scHandleDecl»)
+		void «exitFctID»(«scHandleDecl»)
 		{
 		{
 			«exitSequence.code»
 			«exitSequence.code»
 		}
 		}
@@ -174,7 +174,7 @@ class StatemachineSource implements IContentTemplate {
 	'''
 	'''
 	
 	
 	def runCycleFunction(ExecutionFlow it) '''
 	def runCycleFunction(ExecutionFlow it) '''
-		void «functionPrefix»runCycle(«scHandleDecl»)
+		void «runCycleFctID»(«scHandleDecl»)
 		{
 		{
 			
 			
 			«clearOutEventsFctID»(«scHandle»);
 			«clearOutEventsFctID»(«scHandle»);

+ 58 - 2
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/extensions/Naming.xtend

@@ -150,11 +150,11 @@ class Naming {
 	}
 	}
 
 
 	def clearInEventsFctID(ExecutionFlow it) {
 	def clearInEventsFctID(ExecutionFlow it) {
-		functionPrefix + "clearInEvents"
+		"clearInEvents"
 	}
 	}
 
 
 	def clearOutEventsFctID(ExecutionFlow it) {
 	def clearOutEventsFctID(ExecutionFlow it) {
-		functionPrefix + "clearOutEvents"
+		"clearOutEvents"
 	}
 	}
 
 
 	def dispatch String null_state(ExecutionFlow it) {
 	def dispatch String null_state(ExecutionFlow it) {
@@ -185,6 +185,10 @@ class Naming {
 		}
 		}
 		return null;
 		return null;
 	}
 	}
+	
+	def bool() {
+		"sc_boolean"
+	}
 
 
 	def constantName(VariableDefinition it) {
 	def constantName(VariableDefinition it) {
 		(flow.type + separator + scope.type + separator + name.asEscapedIdentifier).toUpperCase
 		(flow.type + separator + scope.type + separator + name.asEscapedIdentifier).toUpperCase
@@ -205,7 +209,51 @@ class Naming {
 	def isFinalFctID(ExecutionFlow it) {
 	def isFinalFctID(ExecutionFlow it) {
 		functionPrefix + "isFinal"
 		functionPrefix + "isFinal"
 	}
 	}
+	
+	def initFctID(ExecutionFlow it) {
+		functionPrefix + "init"
+	}
+	
+	def enterFctID(ExecutionFlow it) {
+		functionPrefix + "enter"
+	}
 
 
+	def exitFctID(ExecutionFlow it) {
+		functionPrefix + "exit"
+	}
+	
+	def runCycleFctID(ExecutionFlow it) {
+		functionPrefix + "runCycle"
+	}
+	
+	def eventValueVariable(EventDefinition it) {
+		name.asIdentifier.value
+	}
+	
+	def timeEventRaisedFlag(TimeEvent it) {
+		shortName.raised
+	}
+	
+	def eventRaisedFlag(EventDefinition it) {
+		 name.asIdentifier.raised
+	}
+	
+	def setTimerFctID(ExecutionFlow it) {
+		functionPrefix + "setTimer"
+	}
+	
+	def unsetTimerFctID(ExecutionFlow it) {
+		functionPrefix + "unsetTimer"
+	}
+	
+	def enterStateTracingFctID(ExecutionFlow it) {
+		functionPrefix + "stateEntered"
+	}
+	
+	def exitStateTracingFctID(ExecutionFlow it) {
+		functionPrefix + "stateExited"
+	}
+ 
 	def asRaiser(EventDefinition it) {
 	def asRaiser(EventDefinition it) {
 		scope.functionPrefix(it) + separator + 'raise' + separator + name.asIdentifier.toFirstLower
 		scope.functionPrefix(it) + separator + 'raise' + separator + name.asIdentifier.toFirstLower
 	}
 	}
@@ -229,6 +277,14 @@ class Naming {
 	def asFunction(OperationDefinition it) {
 	def asFunction(OperationDefinition it) {
 		scope.functionPrefix(it) + separator + name.asIdentifier.toFirstLower
 		scope.functionPrefix(it) + separator + name.asIdentifier.toFirstLower
 	}
 	}
+	
+	def variable(VariableDefinition it) {
+		name.asEscapedIdentifier
+	}
+	
+	def stateName(ExecutionState it) {
+		shortName
+	}
 
 
 	def raised(CharSequence it) { it + separator + 'raised' }
 	def raised(CharSequence it) { it + separator + 'raised' }