Browse Source

#382 : correcting the formatter of C generator

Dominik Tesch 9 years ago
parent
commit
1c6440d52e

+ 14 - 7
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/FlowCode.xtend

@@ -73,9 +73,11 @@ class FlowCode {
 	
 	def dispatch CharSequence code(HistoryEntry it) '''
 		«stepComment»
-		if («scHandle»->historyVector[«region.historyVector.offset»] != «null_state») {
+		if («scHandle»->historyVector[«region.historyVector.offset»] != «null_state»)
+		{
 			«historyStep.code»
-		} «IF initialStep != null»else {
+		} «IF initialStep != null»else
+		{
 			«initialStep.code»
 		} «ENDIF»
 	'''
@@ -83,12 +85,15 @@ class FlowCode {
 	def dispatch CharSequence code(StateSwitch it) '''
 		«stepComment»
 		«IF historyRegion != null»
-			switch(«scHandle»->historyVector[ «historyRegion.historyVector.offset» ]) {
+			switch(«scHandle»->historyVector[ «historyRegion.historyVector.offset» ])
+			{
 		«ELSE»
-			switch(«scHandle»->stateConfVector[ «stateConfigurationIdx» ]) {
+			switch(«scHandle»->stateConfVector[ «stateConfigurationIdx» ])
+			{
 		«ENDIF»
 			«FOR caseid : cases»
-				case «caseid.state.shortName» : {
+				case «caseid.state.shortName» :
+				{
 					«caseid.step.code»
 					break;
 				}
@@ -128,9 +133,11 @@ class FlowCode {
 
 	def dispatch CharSequence code(If it) '''
 		«stepComment»
-		if («check.code» == bool_true) { 
+		if («check.code» == bool_true)
+		{ 
 			«thenStep.code»
-		} «IF (elseStep != null)» else {
+		} «IF (elseStep != null)» else
+		{
 			«elseStep.code»
 		}
 		«ENDIF»

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

@@ -111,7 +111,8 @@ class StatemachineHeader {
 
 	def statesEnumDecl(ExecutionFlow it) '''
 		/*! Enumeration of all states */ 
-		typedef enum {
+		typedef enum
+		{
 			«FOR state : states»
 				«state.shortName»,
 			«ENDFOR»
@@ -138,7 +139,8 @@ class StatemachineHeader {
 		«val typeRelevantDeclarations = scope.typeRelevantDeclarations.toList»
 		«IF !typeRelevantDeclarations.empty»
 			/*! Type definition of the data structure for the «scope.type» interface scope. */
-			typedef struct {
+			typedef struct
+			{
 				«FOR d : typeRelevantDeclarations»
 					«d.scopeTypeDeclMember»
 				«ENDFOR»
@@ -175,7 +177,8 @@ class StatemachineHeader {
 		 * Type definition of the data structure for the «type» state machine.
 		 * This data structure has to be allocated by the client code. 
 		 */
-		typedef struct {
+		typedef struct
+		{
 			«statesEnumType» stateConfVector[«type.toUpperCase»_MAX_ORTHOGONAL_STATES];
 			«IF hasHistory»«statesEnumType» historyVector[«type.toUpperCase»_MAX_HISTORY_STATES];«ENDIF»
 			sc_ushort stateConfVectorPosition; 

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

@@ -43,7 +43,8 @@ class StatemachineRequiredHeader {
 			«IF timed || operations.size > 0»#include "«module.h»"«ENDIF»
 
 			#ifdef __cplusplus
-			extern "C" {
+			extern "C"
+			{
 			#endif 
 			
 			/*! \file This header defines prototypes for all functions that are required by the state machine implementation.

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

@@ -90,12 +90,14 @@ class StatemachineSource {
 		{
 			sc_integer i;
 
-			for (i = 0; i < «type.toUpperCase»_MAX_ORTHOGONAL_STATES; ++i) {
+			for (i = 0; i < «type.toUpperCase»_MAX_ORTHOGONAL_STATES; ++i)
+			{
 				«scHandle»->stateConfVector[i] = «null_state»;
 			}
 			
 			«IF hasHistory»
-			for (i = 0; i < «type.toUpperCase»_MAX_HISTORY_STATES; ++i) {
+			for (i = 0; i < «type.toUpperCase»_MAX_HISTORY_STATES; ++i)
+			{
 				«scHandle»->historyVector[i] = «null_state»;
 			}
 			«ENDIF»
@@ -125,7 +127,8 @@ class StatemachineSource {
 	'''
 	
 	def clearInEventsFunction(ExecutionFlow it) '''
-		static void «clearInEventsFctID»(«scHandleDecl») {
+		static void «clearInEventsFctID»(«scHandleDecl»)
+		{
 			«FOR scope : it.scopes»
 				«FOR event : scope.incomingEvents»
 				«event.access» = bool_false;
@@ -145,7 +148,8 @@ class StatemachineSource {
 	'''
 	
 	def clearOutEventsFunction(ExecutionFlow it) '''
-		static void «clearOutEventsFctID»(«scHandleDecl») {
+		static void «clearOutEventsFctID»(«scHandleDecl»)
+		{
 			«FOR scope : it.scopes»
 				«FOR event : scope.outgoingEvents»
 				«event.access» = bool_false;
@@ -155,18 +159,22 @@ class StatemachineSource {
 	'''
 	
 	def runCycleFunction(ExecutionFlow it) '''
-		void «functionPrefix»runCycle(«scHandleDecl») {
+		void «functionPrefix»runCycle(«scHandleDecl»)
+		{
 			
 			«clearOutEventsFctID»(«scHandle»);
 			
 			for («scHandle»->stateConfVectorPosition = 0;
 				«scHandle»->stateConfVectorPosition < «type.toUpperCase»_MAX_ORTHOGONAL_STATES;
-				«scHandle»->stateConfVectorPosition++) {
+				«scHandle»->stateConfVectorPosition++)
+				{
 					
-				switch («scHandle»->stateConfVector[handle->stateConfVectorPosition]) {
+				switch («scHandle»->stateConfVector[handle->stateConfVectorPosition])
+				{
 				«FOR state : states»
 					«IF state.reactSequence!=null»
-					case «state.shortName» : {
+					case «state.shortName» :
+					{
 						«state.reactSequence.shortName»(«scHandle»);
 						break;
 					}
@@ -183,9 +191,11 @@ class StatemachineSource {
 	
 	def raiseTimeEventFunction(ExecutionFlow it) '''
 		«IF timed»
-			void «raiseTimeEventFctID»(const «type»* handle, sc_eventid evid) {
+			void «raiseTimeEventFctID»(const «type»* handle, sc_eventid evid)
+			{
 				if ( ((sc_intptr_t)evid) >= ((sc_intptr_t)&(«scHandle»->timeEvents))
-					&&  ((sc_intptr_t)evid) < ((sc_intptr_t)&(«scHandle»->timeEvents)) + sizeof(«timeEventScope.type»)) {
+					&&  ((sc_intptr_t)evid) < ((sc_intptr_t)&(«scHandle»->timeEvents)) + sizeof(«timeEventScope.type»))
+					{
 					*(sc_boolean*)evid = bool_true;
 				}		
 			}
@@ -193,9 +203,11 @@ class StatemachineSource {
 	'''
 	
 	def isStateActiveFunction(ExecutionFlow it) '''
-		sc_boolean «stateActiveFctID»(const «scHandleDecl», «statesEnumType» state) {
+		sc_boolean «stateActiveFctID»(const «scHandleDecl», «statesEnumType» state)
+		{
 			sc_boolean result = bool_false;
-			switch (state) {
+			switch (state)
+			{
 				«FOR s : states»
 				case «s.shortName» : 
 					result = (sc_boolean) («IF s.leaf»«scHandle»->stateConfVector[«s.stateVector.offset»] == «s.shortName»
@@ -212,7 +224,8 @@ class StatemachineSource {
 	'''
 	
 	def isActiveFunction(ExecutionFlow it) '''
-		sc_boolean «isActiveFctID»(const «scHandleDecl») {
+		sc_boolean «isActiveFctID»(const «scHandleDecl»)
+		{
 			sc_boolean result;
 			if («FOR i : 0 ..< stateVector.size SEPARATOR ' || '»«scHandle»->stateConfVector[«i»] != «null_state»«ENDFOR»)
 			{
@@ -235,7 +248,8 @@ class StatemachineSource {
 			 * Always returns 'false' since this state machine can never become final.
 			 */
 			«ENDIF»
-			sc_boolean «isFinalFctID»(const «scHandleDecl»){
+			sc_boolean «isFinalFctID»(const «scHandleDecl») 
+			{
 		''' +
 		// only if the impact vector is completely covered by final states the state machine 
 		// can become final
@@ -253,7 +267,8 @@ class StatemachineSource {
 	def interfaceFunctions(ExecutionFlow it) '''
 		«FOR scope : interfaceScopes»
 			«FOR event : scope.incomingEvents»
-				void «event.asRaiser»(«scHandleDecl»«event.valueParams») {
+				void «event.asRaiser»(«scHandleDecl»«event.valueParams»)
+				{
 					«IF event.hasValue»
 					«event.valueAccess» = value;
 					«ENDIF»
@@ -262,22 +277,26 @@ class StatemachineSource {
 			«ENDFOR»
 			
 			«FOR event : scope.outgoingEvents»
-				sc_boolean «event.asRaised»(const «scHandleDecl») {
+				sc_boolean «event.asRaised»(const «scHandleDecl»)
+				{
 					return «event.access»;
 				}
 				«IF event.hasValue» 
-					«event.type.targetLanguageName» «event.asGetter»(const «scHandleDecl») {
+					«event.type.targetLanguageName» «event.asGetter»(const «scHandleDecl»)
+					{
 						return «event.valueAccess»;
 					}
 				«ENDIF»
 			«ENDFOR»
 			
 			«FOR variable : scope.variableDefinitions»
-				«IF variable.const»const «ENDIF»«variable.type.targetLanguageName» «variable.asGetter»(const «scHandleDecl») {
+				«IF variable.const»const «ENDIF»«variable.type.targetLanguageName» «variable.asGetter»(const «scHandleDecl»)
+				{
 					return «variable.access»;
 				}
 				«IF !variable.readonly && !variable.const»
-				void «variable.asSetter»(«scHandleDecl», «variable.type.targetLanguageName» value) {
+				void «variable.asSetter»(«scHandleDecl», «variable.type.targetLanguageName» value)
+				{
 					«variable.access» = value;
 				}
 				«ENDIF»
@@ -353,7 +372,8 @@ class StatemachineSource {
 	
 	def dispatch functionImplementation(Check it) '''
 		«stepComment»
-		static sc_boolean «shortName»(const «scHandleDecl») {
+		static sc_boolean «shortName»(const «scHandleDecl»)
+		{
 			return «code»;
 		}
 		
@@ -361,7 +381,8 @@ class StatemachineSource {
 	
 	def dispatch functionImplementation(Step it) '''
 		«stepComment»
-		static void «shortName»(«scHandleDecl») {
+		static void «shortName»(«scHandleDecl»)
+		{
 			«code»
 		}
 		

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

@@ -35,13 +35,15 @@ class Timer {
 		#include "«typesModule.h»"
 		
 		#ifdef __cplusplus
-		extern "C" {
+		extern "C"
+		{
 		#endif 
 		
 		typedef void(*setTimerFPtr)(uint32_t evid, const uint32_t time_ms, sc_boolean periodic);
 		typedef void(*unsetTimerFPtr)(const uint32_t evid);
 		
-		typedef struct {
+		typedef struct
+		{
 		
 			/* callback functions */
 			setTimerFPtr   setTimer;

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

@@ -55,7 +55,8 @@ class Types {
 		#define «typesModule.define»_H_
 		
 		#ifdef __cplusplus
-		extern "C" {
+		extern "C"
+		{
 		#endif 
 		
 		#include <stdint.h>