«IMPORT sc» «DEFINE root FOR StateMachine»«FILE this.name+".h"»enum «this.name»_states { «EXPAND enum_decl FOR this» }; struct «this.name» { enum «this.name»_states current; }; «EXPAND init_sign FOR this»; «EXPAND run_sign FOR this»; «ENDFILE» «FILE this.name+".c"»#include "«this.name+".h"»" #include «EXPAND init FOR this» «EXPAND run FOR this» «ENDFILE»«ENDDEFINE» «DEFINE init_sign FOR StateMachine»void «this.name»_init(«EXPAND type FOR this» *a)«ENDDEFINE» «DEFINE run_sign FOR StateMachine»void «this.name»_run(«EXPAND type FOR this» *a, char *msg)«ENDDEFINE» «DEFINE init FOR StateMachine» «EXPAND init_sign FOR this» { «EXPAND goto FOR this»; }«ENDDEFINE» «DEFINE type FOR StateMachine»struct «this.name»«ENDDEFINE» «DEFINE goto FOR AbstractState»a->current = «EXPAND enum FOR this»«ENDDEFINE» «DEFINE goto FOR CompositeState»«EXPAND goto FOR this.states.select(e|InitialState.isInstance(e)).first().outgoing.first().to»«ENDDEFINE» «DEFINE run FOR AbstractState»«ENDDEFINE» «DEFINE run FOR StateMachine» «EXPAND run_sign FOR this» { //State Machine «this.name» «EXPAND run_output FOREACH this.states.select(e|!e.outgoing.isEmpty) SEPARATOR" "» «EXPAND run FOREACH this.states» }«ENDDEFINE» «DEFINE run FOR CompositeState»«EXPAND run FOREACH this.states» //Composite State «this.name» «EXPAND run_output FOREACH this.states.select(e|!e.outgoing.isEmpty) SEPARATOR" "»«ENDDEFINE» «DEFINE enum_cont FOR AbstractState»«ENDDEFINE» «DEFINE enum_cont FOR CompositeState»«this.name»_«ENDDEFINE» «DEFINE enum_cont FOR StateMachine»«ENDDEFINE» «DEFINE enum_decl FOR AbstractState» «EXPAND enum FOR this»«ENDDEFINE» «DEFINE enum_decl FOR CompositeState»«EXPAND enum_decl FOREACH this.states.reject(e|InitialState.isInstance(e)) SEPARATOR ", "»«ENDDEFINE» «DEFINE enum FOR AbstractState»«EXPAND enum_cont FOR (AbstractState)this.eContainer»«this.name»_state«ENDDEFINE» «DEFINE enum FOR InitialState»«IF this.name != null && this.name.length != 0»«this.name»_«ENDIF»«EXPAND enum_cont FOR (AbstractState)this.eContainer»initial_state«ENDDEFINE» «DEFINE enum FOR FinalState»«IF this.name != null && this.name.length != 0»«this.name»_«ENDIF»«EXPAND enum_cont FOR (AbstractState)this.eContainer»final_state«ENDDEFINE» «DEFINE is_in_state FOR AbstractState»a->current == «EXPAND enum FOR this»«ENDDEFINE» «DEFINE is_in_state FOR CompositeState»«EXPAND is_in_state FOREACH this.states.reject(e|InitialState.isInstance(e)) SEPARATOR " || "»«ENDDEFINE» «DEFINE run_output FOR AbstractState» if(«EXPAND is_in_state FOR this») {«EXPAND run_output FOREACH this.outgoing» }«ENDDEFINE» «DEFINE run_output FOR InitialState»«ENDDEFINE» «DEFINE run_output FOR FinalState» if(«EXPAND is_in_state FOR this») return;«ENDDEFINE» «DEFINE run_output FOR Transition» if(strcmp(msg, "«this.event»") == 0) { «EXPAND goto FOR this.to»; return; }«ENDDEFINE»