Bladeren bron

new C code generator now generates first function implementations ...

terfloth@itemis.de 13 jaren geleden
bovenliggende
commit
0adf84a24c

+ 238 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/ActionCode.xtend

@@ -0,0 +1,238 @@
+package org.yakindu.sct.generator.c
+
+import org.yakindu.sct.model.sgraph.Statement
+import org.yakindu.sct.model.stext.stext.Literal
+import org.yakindu.sct.model.stext.stext.StringLiteral
+import org.yakindu.sct.model.stext.stext.BoolLiteral
+import org.yakindu.sct.model.stext.stext.IntLiteral
+import org.yakindu.sct.model.stext.stext.RealLiteral
+import org.yakindu.sct.model.stext.stext.HexLiteral
+import org.yakindu.sct.model.stext.stext.PrimitiveValueExpression
+import org.yakindu.sct.model.stext.stext.AssignmentExpression
+import org.yakindu.sct.model.stext.stext.ElementReferenceExpression
+import org.yakindu.sct.model.stext.stext.VariableDefinition
+import org.eclipse.emf.ecore.EObject
+import com.google.inject.Inject
+import org.yakindu.sct.model.stext.stext.EventDefinition
+import org.yakindu.sct.model.stext.stext.LogicalOrExpression
+import org.yakindu.sct.model.sexec.TimeEvent
+
+class ActionCode {
+	
+	@Inject extension Naming
+	@Inject extension Navigation
+	
+	
+		/** todo externalize */
+	def dispatch access (VariableDefinition it) 
+		'''«scHandle»->«scope.instance».«name.asIdentifier»'''
+		
+	/** todo externalize */
+	def dispatch access (EventDefinition it) 
+		'''«scHandle»->«scope.instance».«name.asIdentifier»_raised'''
+		
+	/** todo externalize */
+	def dispatch access (TimeEvent it) 
+		'''«scHandle»->«scope.instance».«name.asIdentifier»_raised'''
+		
+	def dispatch access (EObject it) 
+		'''#warning can't access elements of type «getClass().name»'''
+		
+	
+	
+	def dispatch code (Statement it) 
+		'''#error TODO: generate code for «getClass().name»'''
+
+	
+	def dispatch code (Literal it)
+		'''#error unknown literal type «getClass().name» '''
+	
+	def dispatch code (StringLiteral it) 
+		'''"«value»"'''	
+
+	def dispatch code (BoolLiteral it) 
+		'''«IF value»bool_true«ELSE»bool_false«ENDIF»'''	
+
+	def dispatch code (IntLiteral it) 
+		'''«value.toString»'''	
+
+	def dispatch code (RealLiteral it) 
+		'''«value.toString»'''	
+		
+	def dispatch code (HexLiteral it) 
+		'''«value.toString»'''	
+
+	def dispatch code (PrimitiveValueExpression it) 
+		'''«value.code»'''	
+
+		
+	def dispatch code (ElementReferenceExpression it) 
+		'''«reference.access»'''
+		
+		
+	def dispatch code (AssignmentExpression it)
+		'''«varRef.code» «operator.literal» «expression.code»'''
+		
+
+
+	/* Logical Expressions */
+	
+	def dispatch code (LogicalOrExpression it)
+		'''«rightOperand.code» || «leftOperand.code»'''
+		
+	
+///* EventRaising */
+//String toCCode(EventRaisingExpression eventRaising) :
+//	((eventRaising.value == null)?"":
+//	"((" + eventRaising.event.getEventName() + "*)" + eventRaising.statemachineHandleName() + "->" + eventRaising.getInterfaceName() + "." + eventRaising.event.getEventName() + ")->value = " 
+//	+ eventRaising.value.toCCode() + ";") + 
+//	" statemachine_cy_setEvent(&" + eventRaising.statemachineHandleName() + 
+//	"->base, " + eventRaising.statemachineHandleName() + "->" + 
+//	eventRaising.getInterfaceName() + "." + 
+//	eventRaising.event.getEventName() + "); ";
+//
+//String addValue(EventRaisingExpression event) :
+//  ( (event.value == null)?"":("((" +event.event.getEventName() + "*)ev)->value = " + event.value.toCCode() + "; ") );
+//
+///* Logical Expressions */
+//String toCCode(LogicalOrExpression expression) :
+//  	" ( " + expression.leftOperand.toCCode() + " ) " + " || " + " ( " + expression.rightOperand.toCCode() + " ) ";
+//  	
+//String toCCode(LogicalAndExpression expression) :
+//  	" ( " + expression.leftOperand.toCCode() + " ) " + " && " + " ( " + expression.rightOperand.toCCode() + " ) ";
+//
+//String toCCode(LogicalNotExpression expression) :
+//  	" ~" + " ( " + expression.operand.toCCode() + " ) ";
+//
+//String toCCode(LogicalRelationExpression expression) :
+//	if (expression.leftOperand.inferType().isString()) then
+//		"("+expression.leftOperand.toCCode()+"==NULL?"+expression.rightOperand.toCCode()+"==NULL:strcmp("+expression.leftOperand.toCCode()+", "+expression.rightOperand.toCCode()+")==0)"
+//	else
+//		" ( " + expression.leftOperand.toCCode() + " ) " + getOperator(expression.operator) + " ( " + expression.rightOperand.toCCode() + " ) ";
+//    
+//String toCCode(BitwiseAndExpression expression) :
+//  	" ( " + expression.leftOperand.toCCode() + " ) " + " & " + " ( " + expression.rightOperand.toCCode() + " ) ";
+//
+//String toCCode(BitwiseOrExpression expression) :
+//  	" ( " + expression.leftOperand.toCCode() + " ) " + " | " + " ( " + expression.rightOperand.toCCode() + " ) ";
+//
+//String toCCode(BitwiseXorExpression expression) :
+//  	" ( " + expression.leftOperand.toCCode() + " ) " + " ^ " + " ( " + expression.rightOperand.toCCode() + " ) ";
+//
+//String toCCode(NumericalAddSubtractExpression expression) :
+//  	" ( " + expression.leftOperand.toCCode() + " ) " + getOperator(expression.operator) + " ( " + expression.rightOperand.toCCode() + " ) ";
+//  	
+//String toCCode(NumericalMultiplyDivideExpression expression) :
+//  	" ( " + expression.leftOperand.toCCode() + " ) " + getOperator(expression.operator) + " ( " + expression.rightOperand.toCCode() + " ) ";
+//
+//
+//String toCCode(NumericalUnaryExpression expression) :
+//    getOperator(expression.operator) + " ( " + expression.operand.toCCode() + " ) ";
+//
+///* can not handle internal scope  */
+//
+//ExecutionFlow getExecutionFlow(InterfaceScope this) : ((ExecutionFlow)this.eContainer);
+//String interfaceObjectName(InterfaceScope this) : "iface" + ((this.name == null)?"":this.name.toFirstUpper());
+//
+//String getOperator(AdditiveOperator operator) : 
+//    switch(operator) {
+//    	case(AdditiveOperator::plus) : " + "
+//    	case(AdditiveOperator::minus) : " - "
+//    	default : ""
+//    };
+//
+//String getOperator(MultiplicativeOperator operator) : 
+//    switch(operator) {
+//    	case(MultiplicativeOperator::mul) : " * "
+//    	case(MultiplicativeOperator::div) : " / "
+//    	case(MultiplicativeOperator::mod) : " % "
+//    	default : ""
+//    };
+//
+//String getOperator(RelationalOperator operator) :
+//	switch (operator) {
+//	  case (RelationalOperator::greater) : " > "
+//	  case (RelationalOperator::greaterEqual) : " >= "
+//	  case (RelationalOperator::smaller) : " < "
+//	  case (RelationalOperator::smallerEqual) : " <= "
+//	  case (RelationalOperator::equals) : " == "
+//	  case (RelationalOperator::notEquals) : " != "
+//	  default : ""
+//	};
+//
+//String getOperator(UnaryOperator operator) :
+//	switch (operator) {
+//	  case (UnaryOperator::negative) : " -"
+//	  case (UnaryOperator::positive) : " + "
+//	  case (UnaryOperator::complement) : " ~ "
+//	  default : ""
+//	};
+//
+//Set[EventDefinition] getInEvents(Scope interface) : 
+//	{};
+//
+//Set[EventDefinition] getOutEvents(Scope interface) : 
+//	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::OUT);
+//
+//Set[EventDefinition] getLocalEvents(Scope interface) : 
+//	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::LOCAL);
+//  
+//Set[EventDefinition] getInEvents(InterfaceScope interface) : 
+//	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::IN);
+//
+//Set[EventDefinition] getOutEvents(InterfaceScope interface) : 
+//	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::OUT);
+//
+//Set[EventDefinition] getLocalEvents(InterfaceScope interface) : 
+//	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::LOCAL);
+//
+//Set[EventDefinition] getInEvents(InternalScope interface) : 
+//	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::IN);
+//
+//Set[EventDefinition] getOutEvents(InternalScope interface) : 
+//	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::OUT);
+//
+//Set[EventDefinition] getLocalEvents(InternalScope interface) : 
+//	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::LOCAL);
+//
+//// is this just relevant for events?
+//String toCCode(ElementReferenceExpression ref) :
+//	ref.reference.toCCode()+ (if (ref.operationCall) then "("+ref.getInterfaceCallComma()+ref.args.toCCode().toString(",")+")" else "");
+//
+//String toCCode(EObject ref) :
+//	"/* toCode not defined for: "+ref+" */";
+//String toCCode(Feature ref) :
+//	"/* toCode not defined for: "+ref+" */";
+//String toCCode(FeatureCall ref) :
+//	ref.feature.toCCode()+ (if (ref.operationCall) then "("+ref.getInterfaceCallComma()+ref.args.toCCode().toString(",")+")" else "");
+//
+//String toCCode(Declaration dec) :
+//	"Declartion type not specified";
+//
+//String toCCode(OperationDefinition dec) :
+//	" " +dec.getMethodName();
+//
+//String toCCode(TimeEvent time_ev) :
+//    " ( eventSet_check( &"+time_ev.statemachineHandleName()+"->base.eventSet, " + time_ev.getEventEnumName() + ") ) ";
+//
+//String toCCode(VariableDefinition var) :
+//    " " + var.statemachineHandleName() + "->" + var.getInterface() + 
+//    "." + var.getName() + " ";
+//	
+//String toCCode(EventDefinition evDef) :
+//    " ( eventSet_check( &" + evDef.statemachineHandleName() + "->base.eventSet, " + evDef.getEventEnumName() + ") ) ";
+//
+///*
+//String toCCode(EventRaisedReferenceExpression errExp) :
+//	" eventSet_check( &" + errExp.statemachineHandleName() + "->base.eventSet, " + errExp.value.getEventEnumName() + ")";
+//*/
+//String toCCode(EventValueReferenceExpression evrExp) :
+//	"((" +evrExp.value.getEventName() + "*)" + evrExp.statemachineHandleName() + "->base.eventList[" + evrExp.value.getEventEnumName() + "])->value";
+//
+//String toCCode(ActiveStateReferenceExpression asrExp) :
+//	"isActive("+asrExp.value.StateEnumName()+") /* function not implemented yet */";
+//
+//List[Scope] getUsableScopes(List[Scope] scList) :
+//	scList.select(e| InterfaceScope.isInstance(e) || InternalScope.isInstance(e));
+	
+}

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

@@ -21,10 +21,9 @@ class FlowCode {
 	
 	@Inject extension Naming
 	@Inject extension Navigation
+	@Inject extension ActionCode
+	
 	
-	def expCode (Statement it) '''
-		#warning TODO: generate code for «getClass().name»
-	'''
  
 	def stepComment(Step it) '''
 		«IF comment != null && ! comment.empty»
@@ -70,7 +69,7 @@ class FlowCode {
 	def dispatch code(ScheduleTimeEvent it) '''
 		«stepComment»
 		// TODO: schedule time event id:
-		«flow.type.toFirstLower»_setTimer( EVID , «timeValue.expCode», «IF timeEvent.periodic»true«ELSE»false«ENDIF»);
+		«flow.type.toFirstLower»_setTimer( EVID , «timeValue.code», «IF timeEvent.periodic»true«ELSE»false«ENDIF»);
 	'''
 
 	def dispatch code(UnscheduleTimeEvent it) '''
@@ -79,26 +78,24 @@ class FlowCode {
 		«flow.type.toFirstLower»_unsetTimer( EVID );		
 	'''
 
-	def dispatch code(Execution it) '''
-		«statement.expCode»
-	'''
+	def dispatch code(Execution it) 
+		'''«statement.code»;'''
 	
-	def dispatch code(Call it) '''
-		#warning TODO: call function(handle)
-	'''
+	def dispatch code(Call it) 
+		'''«step.functionName»(«scHandle»);'''
 
 	def dispatch code(Sequence it) '''
 		«stepComment»
-		«FOR s : steps»«s.code»«ENDFOR»
+		«FOR s : steps»
+			«s.code»
+		«ENDFOR»
 	'''	
 
-	def dispatch code(Check it) '''
-		«IF condition != null»«condition.expCode»«ELSE»true«ENDIF»
-	'''
+	def dispatch code(Check it) 
+		'''«IF condition != null»«condition.code»«ELSE»bool_true«ENDIF»'''
 	
-	def dispatch code(CheckRef it) '''
-		«IF check != null»callcheckfunc(handle)«ELSE»true«ENDIF»
-	'''
+	def dispatch code(CheckRef it) 
+		'''«IF check != null»callcheckfunc(handle)«ELSE»bool_true«ENDIF»'''
 
 	def dispatch code(If it) '''
 		«stepComment»

+ 16 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Naming.xtend

@@ -110,6 +110,21 @@ class Naming {
 	}
 		
 	
+	def functionName(Step it) {
+		switch (it) {
+			case isEntryAction: asEntryActionFunction
+			case isExitAction : asExitActionFunction
+			case isEffect : asEffectFunction
+			case isEnterSequence : asEnterSequenceFunction
+			case isDeepEnterSequence : asDeepEnterSequenceFunction
+			case isShallowEnterSequence : asShallowEnterSequenceFunction
+			case isExitSequence : asExitSequenceFunction
+			case isReactSequence : asReactFunction
+			default : ""
+		} 
+	}
+	
+	
 	def asCheckFunction(Check it) { functionName(newArrayList('check', elementName, reaction.name)) }
 	 
 	def asEffectFunction(Step it) { functionName(newArrayList('effect', elementName, reaction.name)) }
@@ -165,5 +180,5 @@ class Naming {
 	
 	def scHandleDecl(EObject it) { flow.type + '* ' + scHandle }
 	
-	def scHandle() { 'handle_' }
+	def scHandle() { 'handle' }
 }

+ 99 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Navigation.xtend

@@ -16,6 +16,10 @@ import org.yakindu.sct.model.sexec.Check
 import org.yakindu.sct.model.sexec.Reaction
 import org.yakindu.sct.model.sexec.ExecutionNode
 import org.yakindu.sct.model.sexec.Step
+import org.yakindu.sct.model.sexec.ExecutionScope
+import org.yakindu.sct.model.sexec.ExecutionRegion
+import java.util.List
+import org.yakindu.sct.model.sexec.ExecutionState
 
 class Navigation {
 	
@@ -71,5 +75,100 @@ class Navigation {
 	}
 
 	def isCalled(Step it) { it != null && caller.size > 0 }
+	
+	
+	def List<Step> checkFunctions(ExecutionFlow it) {
+		val funcs = new ArrayList<Step>()
+		funcs += referencedChecks
+		states.forEach( s | funcs += s.referencedChecks )
+		nodes.forEach( n | funcs += n.referencedChecks )
+		return funcs
+	}
+	 
+	def List<Step> effectFunctions(ExecutionFlow it) {
+		val funcs = new ArrayList<Step>()
+		funcs += referencedEffects
+		states.forEach( s | funcs += s.referencedEffects )
+		nodes.forEach( n | funcs += n.referencedEffects )
+		return funcs
+	}
+	 
+	def List<Step> entryActionFunctions(ExecutionFlow it) {
+		val funcs = new ArrayList<Step>()
+		if (entryAction.called) funcs.add(entryAction) 
+		states.forEach( s | if (s.entryAction.called) funcs += s.entryAction )
+		return funcs
+	}
+	
+	def List<Step> exitActionFunctions(ExecutionFlow it) {
+		val funcs = new ArrayList<Step>()
+		if (exitAction.called) funcs.add(exitAction) 
+		states.forEach( s | if (s.exitAction.called) funcs += s.exitAction )
+		return funcs
+	}
+	 
+	def List<Step> enterSequenceFunctions(ExecutionFlow it) {
+		val funcs = new ArrayList<Step>()
+		if (enterSequence.called) funcs.add(enterSequence) 
+		states.forEach( s | if (s.enterSequence.called) funcs += s.enterSequence )
+		regions.forEach( s | {
+			if (s.enterSequence.called) funcs += s.enterSequence
+			if (s.deepEnterSequence.called) funcs += s.deepEnterSequence
+			if (s.shallowEnterSequence.called) funcs += s.shallowEnterSequence
+		})
+		return funcs
+	}
+	 
+	def List<Step> exitSequenceFunctions(ExecutionFlow it) {
+		val funcs = new ArrayList<Step>()
+		if (exitSequence.called) funcs.add(exitSequence) 
+		states.forEach( s | if (s.exitSequence.called) funcs += s.exitSequence )
+		regions.forEach( s | if (s.exitSequence.called) funcs += s.exitSequence )
+		return funcs
+	}
+	 
+	def List<Step> reactFunctions(ExecutionFlow it) {
+		val funcs = new ArrayList<Step>()
+		if (reactSequence.called) funcs.add(reactSequence) 
+		states.forEach( s | if (s.reactSequence.called) funcs += s.reactSequence )
+		nodes.forEach( s | if (s.reactSequence.called) funcs += s.reactSequence )
+		return funcs
+	}
+	
+	
+	def isEntryAction(Step it) { eContainer.isEntryAction(it) }
+	def dispatch isEntryAction(ExecutionFlow it, Step s) { entryAction == s }
+	def dispatch isEntryAction(ExecutionState it, Step s) { entryAction == s }
+	def dispatch isEntryAction(EObject it, Step s) { false }
+	
+	def isExitAction(Step it) { eContainer.isExitAction(it) }
+	def dispatch isExitAction(ExecutionFlow it, Step s) { exitAction == s }
+	def dispatch isExitAction(ExecutionState it, Step s) { exitAction == s }
+	def dispatch isExitAction(EObject it, Step s) { false }
+	
+	def isEffect(Step it) { eContainer.isEffect(it) }
+	def dispatch isEffect(Reaction it, Step s) { effect == s }
+	def dispatch isEffect(EObject it, Step s) { false }
+	
+	def isEnterSequence(Step it) { eContainer.isEnterSequence(it) }
+	def dispatch isEnterSequence(ExecutionScope it, Step s) { enterSequence == s }
+	def dispatch isEnterSequence(EObject it, Step s) { false }
+	
+	def isDeepEnterSequence(Step it) { eContainer.isDeepEnterSequence(it) }
+	def dispatch isDeepEnterSequence(ExecutionRegion it, Step s) { deepEnterSequence == s }
+	def dispatch isDeepEnterSequence(EObject it, Step s) { false }
+	
+	def isShallowEnterSequence(Step it) { eContainer.isShallowEnterSequence(it) }
+	def dispatch isShallowEnterSequence(ExecutionRegion it, Step s) { shallowEnterSequence == s }
+	def dispatch isShallowEnterSequence(EObject it, Step s) { false }
+
+	def isExitSequence(Step it) { eContainer.isExitSequence(it) }
+	def dispatch isExitSequence(ExecutionScope it, Step s) { exitSequence == s }
+	def dispatch isExitSequence(EObject it, Step s) { false }
+	
+	def isReactSequence(Step it) { eContainer.isReactSequence(it) }
+	def dispatch isReactSequence(ExecutionNode it, Step s) { reactSequence == s }
+	def dispatch isReactSequence(EObject it, Step s) { false }
+	
 
 }

+ 59 - 91
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineC.xtend

@@ -1,19 +1,17 @@
 package org.yakindu.sct.generator.c
 
 import com.google.inject.Inject
-import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sgraph.Statechart
+import java.util.List
 import org.eclipse.xtext.generator.IFileSystemAccess
-import org.yakindu.sct.model.sexec.ExecutionNode
 import org.yakindu.sct.model.sexec.Check
-import java.util.List
+import org.yakindu.sct.model.sexec.ExecutionFlow
 import org.yakindu.sct.model.sexec.Step
+import org.yakindu.sct.model.sgraph.Statechart
 
 class StatemachineC {
 	
 	@Inject extension Naming
 	@Inject extension Navigation
-	@Inject extension Base
 	@Inject extension FlowCode
 	
 	
@@ -25,6 +23,7 @@ class StatemachineC {
 	
 	def statemachineCContent(ExecutionFlow it) '''
 		#include "«module.h»"
+		#include "«typesModule.h»"
 		#include <stdlib.h>
 		#include <string.h>
 
@@ -33,13 +32,13 @@ class StatemachineC {
 		
 		«functionPrototypes»
 		
-		// function implementations
-
 		«initFunction»
 		
 		«enterFunction»
 		
 		«exitFunction»
+		
+		«functionImplementations»
 	'''
 	
 	
@@ -78,112 +77,81 @@ class StatemachineC {
 		}
 	'''
 	
+	
+	/* ===================================================================================
+	 * Handling decralartion of function prototypes
+	 */
+	 
+	/** */
 	def functionPrototypes(ExecutionFlow it) '''
 		// prototypes of all internal functions
 		
-		«checkFunctionPrototypes»
-		«effectFunctionPrototypes»
-		«entryActionFunctionPrototypes»
-		«exitActionFunctionPrototypes»
-		«enterSequenceFunctionPrototypes»
-		«exitSequenceFunctionPrototypes»
-		«reactFunctionPrototypes»
+		«checkFunctions.toPrototypes»
+		«effectFunctions.toPrototypes»
+		«entryActionFunctions.toPrototypes»
+		«exitActionFunctions.toPrototypes»
+		«enterSequenceFunctions.toPrototypes»
+		«exitSequenceFunctions.toPrototypes»
+		«reactFunctions.toPrototypes»
 		
 	'''
 	 
 	 
-	def checkFunctionPrototypes(ExecutionFlow it) '''
-		«referencedChecks.checkFunctionPrototypes»
-		«FOR s : states»«s.referencedChecks.checkFunctionPrototypes»«ENDFOR»
-		«FOR n : nodes»«n.referencedChecks.checkFunctionPrototypes»«ENDFOR»
-	'''
-	
-	def checkFunctionPrototypes(Iterable<Check> it) '''
-		«FOR c : it»«c.checkFunctionPrototype»«ENDFOR»
+	def toPrototypes(List<Step> steps) '''
+		«FOR s : steps»
+			«s.functionPrototype»
+		«ENDFOR»
 	'''
 	
-	def checkFunctionPrototype(Check it) '''
+	def dispatch functionPrototype(Check it) '''
 		static sc_boolean «asCheckFunction»(«scHandleDecl»);
 	'''
 	
+	def dispatch functionPrototype(Step it) '''
+		static void «functionName»(«scHandleDecl»);
+	'''	
 	
 	
-	def effectFunctionPrototypes(ExecutionFlow it) '''
-		«referencedEffects.effectFunctionPrototypes»
-		«FOR s : states»«s.referencedEffects.effectFunctionPrototypes»«ENDFOR»
-		«FOR n : nodes»«n.referencedEffects.effectFunctionPrototypes»«ENDFOR»
-	'''
-	
-	def effectFunctionPrototypes(Iterable<Step> it) '''
-		«FOR c : it»«c.effectFunctionPrototype»«ENDFOR»
-	'''
-	
-	def effectFunctionPrototype(Step it) '''
-		static sc_boolean «asEffectFunction»(«scHandleDecl»);
-	'''
-	
-	
-	
-	def entryActionFunctionPrototypes(ExecutionFlow it) '''
-		«if (entryAction.called) entryAction.entryActionFunctionPrototype»
-		«FOR s : states»«if (s.entryAction.called) s.entryAction.entryActionFunctionPrototype»«ENDFOR»
-	'''
-	
-	def entryActionFunctionPrototype(Step it) '''
-		static void «asEntryActionFunction»(«scHandleDecl»);
-	'''
-	
-	
-	def exitActionFunctionPrototypes(ExecutionFlow it) '''
-		«if (exitAction.called) exitAction.exitActionFunctionPrototype»
-		«FOR s : states»«if (s.exitAction.called) s.exitAction.exitActionFunctionPrototype»«ENDFOR»
-	'''
 	
-	def exitActionFunctionPrototype(Step it) '''
-		static void «asExitActionFunction»(«scHandleDecl»);
+	/* ===================================================================================
+	 * Handling implementation of internal functions
+	 */
+	 
+	/** */
+	def functionImplementations(ExecutionFlow it) '''
+		// implementations of all internal functions
+		
+		«checkFunctions.toImplementation»
+		«effectFunctions.toImplementation»
+		«entryActionFunctions.toImplementation»
+		«exitActionFunctions.toImplementation»
+		«enterSequenceFunctions.toImplementation»
+		«exitSequenceFunctions.toImplementation»
+		«reactFunctions.toImplementation»
+		
 	'''
-	
-	
-	def enterSequenceFunctionPrototypes(ExecutionFlow it) '''
-		«if (enterSequence.called) enterSequence.enterSequenceFunctionPrototype»
-		«FOR s : states»«if (s.enterSequence.called) s.enterSequence.enterSequenceFunctionPrototype»«ENDFOR»
-		«FOR r : regions»
-			«if (r.enterSequence.called) r.enterSequence.enterSequenceFunctionPrototype»
-			«if (r.deepEnterSequence.called) r.enterSequence.deepEnterSequenceFunctionPrototype»
-			«if (r.shallowEnterSequence.called) r.enterSequence.shallowEnterSequenceFunctionPrototype»
+	 
+	def toImplementation(List<Step> steps) '''
+		«FOR s : steps»
+			«s.functionImplementation»
 		«ENDFOR»
 	'''
 	
-	def enterSequenceFunctionPrototype(Step it) '''
-		static void «asEnterSequenceFunction»(«scHandleDecl»);
-	'''
-	
-	def deepEnterSequenceFunctionPrototype(Step it) '''
-		static void «asDeepEnterSequenceFunction»(«scHandleDecl»);
-	'''
-	
-	def shallowEnterSequenceFunctionPrototype(Step it) '''
-		static void «asShallowEnterSequenceFunction»(«scHandleDecl»);
-	'''
-	
-	
-	def exitSequenceFunctionPrototypes(ExecutionFlow it) '''
-		«if (enterSequence.called) exitSequence.exitSequenceFunctionPrototype»
-		«FOR s : states»«if (s.exitSequence.called) s.exitSequence.exitSequenceFunctionPrototype»«ENDFOR»
-		«FOR r : regions»«if (r.exitSequence.called) r.exitSequence.exitSequenceFunctionPrototype»«ENDFOR»
+	def dispatch functionImplementation(Check it) '''
+		«stepComment»
+		static sc_boolean «asCheckFunction»(«scHandleDecl») {
+			return «code»;
+		}
+		
 	'''
 	
-	def exitSequenceFunctionPrototype(Step it) '''
-		static void «asExitSequenceFunction»(«scHandleDecl»);
+	def dispatch functionImplementation(Step it) '''
+		«stepComment»
+		static void «functionName»(«scHandleDecl») {
+			«code»
+		}
+		
 	'''
 	
-	def reactFunctionPrototypes(ExecutionFlow it) '''
-		«if (reactSequence.called) reactSequence.reactFunctionPrototype»
-		«FOR s : states»«if (s.reactSequence.called) s.reactSequence.reactFunctionPrototype»«ENDFOR»
-		«FOR n : nodes»«if (n.reactSequence.called) n.reactSequence.reactFunctionPrototype»«ENDFOR»
-	'''
 	
-	def reactFunctionPrototype(Step it) '''
-		static void «asReactFunction»(«scHandleDecl»);
-	'''	
 }