diff options
Diffstat (limited to 'examples/org.eclipse.etrice.tutorials.c/src-gen/RemoveComment/ACParser.c')
-rw-r--r-- | examples/org.eclipse.etrice.tutorials.c/src-gen/RemoveComment/ACParser.c | 325 |
1 files changed, 325 insertions, 0 deletions
diff --git a/examples/org.eclipse.etrice.tutorials.c/src-gen/RemoveComment/ACParser.c b/examples/org.eclipse.etrice.tutorials.c/src-gen/RemoveComment/ACParser.c new file mode 100644 index 000000000..61e44a287 --- /dev/null +++ b/examples/org.eclipse.etrice.tutorials.c/src-gen/RemoveComment/ACParser.c @@ -0,0 +1,325 @@ +/** + * @author generated by eTrice + * + * Source File of ActorClass ACParser + * + */ + +#include "ACParser.h" + +#include "modelbase/etActor.h" +#include "debugging/etLogger.h" +#include "debugging/etMSCLogger.h" +#include "etUnit/etUnit.h" +#include "platform/etMemory.h" + +#include "FileReaderProtocol.h" + + +/* interface item IDs */ +enum interface_items { + IFITEM_readerPort = 1 +}; + + +/* state IDs */ +enum state_ids { + NO_STATE = 0, + STATE_TOP = 1, + STATE_code = 2, + STATE_firstSlash = 3, + STATE_blockComment = 4, + STATE_firstStar = 5, + STATE_lineComment = 6 +}; + +/* transition chains */ +enum chain_ids { + CHAIN_TRANS_INITIAL_TO__code = 1, + CHAIN_TRANS_tr0_FROM_code_TO_cp0_BY_nextCharreaderPort = 2, + CHAIN_TRANS_tr3_FROM_firstSlash_TO_cp1_BY_nextCharreaderPort = 3, + CHAIN_TRANS_tr6_FROM_blockComment_TO_cp2_BY_nextCharreaderPort = 4, + CHAIN_TRANS_tr9_FROM_firstStar_TO_cp3_BY_nextCharreaderPort = 5, + CHAIN_TRANS_tr15_FROM_lineComment_TO_cp5_BY_nextCharreaderPort = 6 +}; + +/* triggers */ +enum triggers { + POLLING = 0, + TRIG_readerPort__nextChar = IFITEM_readerPort + EVT_SHIFT*FileReaderProtocol_OUT_nextChar +}; + + +static void setState(ACParser* self, int new_state) { + self->state = new_state; +} + +/* Entry and Exit Codes */ + +/* Action Codes */ +static void action_TRANS_INITIAL_TO__code(ACParser* self) { + FileReaderProtocolConjPort_getNextChar(&self->constData->readerPort) /* ORIG: readerPort.getNextChar() */; +} +static void action_TRANS_tr0_FROM_code_TO_cp0_BY_nextCharreaderPort(ACParser* self, InterfaceItemBase ifitem, char c) { + FileReaderProtocolConjPort_getNextChar(&self->constData->readerPort) /* ORIG: readerPort.getNextChar() */; +} +static void action_TRANS_tr1_FROM_cp0_TO_code(ACParser* self, InterfaceItemBase ifitem, char c) { + printf("%c",c); +} +static void action_TRANS_tr3_FROM_firstSlash_TO_cp1_BY_nextCharreaderPort(ACParser* self, InterfaceItemBase ifitem, char c) { + FileReaderProtocolConjPort_getNextChar(&self->constData->readerPort) /* ORIG: readerPort.getNextChar() */; +} +static void action_TRANS_tr6_FROM_blockComment_TO_cp2_BY_nextCharreaderPort(ACParser* self, InterfaceItemBase ifitem, char c) { + FileReaderProtocolConjPort_getNextChar(&self->constData->readerPort) /* ORIG: readerPort.getNextChar() */; +} +static void action_TRANS_tr9_FROM_firstStar_TO_cp3_BY_nextCharreaderPort(ACParser* self, InterfaceItemBase ifitem, char c) { + FileReaderProtocolConjPort_getNextChar(&self->constData->readerPort) /* ORIG: readerPort.getNextChar() */; +} +static void action_TRANS_tr12_FROM_cp4_TO_code(ACParser* self, InterfaceItemBase ifitem, char c) { + printf("%c%c",'/',c); +} +static void action_TRANS_tr15_FROM_lineComment_TO_cp5_BY_nextCharreaderPort(ACParser* self, InterfaceItemBase ifitem, char c) { + FileReaderProtocolConjPort_getNextChar(&self->constData->readerPort) /* ORIG: readerPort.getNextChar() */; +} + +/** + * calls exit codes while exiting from the current state to one of its + * parent states while remembering the history + * @param current - the current state + * @param to - the final parent state + * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints) + */ +static void exitTo(ACParser* self, int current, int to, boolean handler) { + while (current!=to) { + switch (current) { + case STATE_code: + self->history[STATE_TOP] = STATE_code; + current = STATE_TOP; + break; + case STATE_firstSlash: + self->history[STATE_TOP] = STATE_firstSlash; + current = STATE_TOP; + break; + case STATE_blockComment: + self->history[STATE_TOP] = STATE_blockComment; + current = STATE_TOP; + break; + case STATE_firstStar: + self->history[STATE_TOP] = STATE_firstStar; + current = STATE_TOP; + break; + case STATE_lineComment: + self->history[STATE_TOP] = STATE_lineComment; + current = STATE_TOP; + break; + } + } +} + +/** + * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data + * matching the trigger of this chain. The ID of the final state is returned + * @param chain - the chain ID + * @param generic_data - the generic data pointer + * @return the ID of the final state + */ +static int executeTransitionChain(ACParser* self, int chain, InterfaceItemBase ifitem, void* generic_data) { + switch (chain) { + case CHAIN_TRANS_INITIAL_TO__code: + { + action_TRANS_INITIAL_TO__code(self); + return STATE_code; + } + case CHAIN_TRANS_tr0_FROM_code_TO_cp0_BY_nextCharreaderPort: + { + char c = *((char*) generic_data); + action_TRANS_tr0_FROM_code_TO_cp0_BY_nextCharreaderPort(self, ifitem, c); + if (c=='/') { + return STATE_firstSlash;} + else { + action_TRANS_tr1_FROM_cp0_TO_code(self, ifitem, c); + return STATE_code;} + } + case CHAIN_TRANS_tr3_FROM_firstSlash_TO_cp1_BY_nextCharreaderPort: + { + char c = *((char*) generic_data); + action_TRANS_tr3_FROM_firstSlash_TO_cp1_BY_nextCharreaderPort(self, ifitem, c); + if (c=='*') { + return STATE_blockComment;} + else { + if (c=='/') { + return STATE_lineComment;} + else { + action_TRANS_tr12_FROM_cp4_TO_code(self, ifitem, c); + return STATE_code;} + } + } + case CHAIN_TRANS_tr6_FROM_blockComment_TO_cp2_BY_nextCharreaderPort: + { + char c = *((char*) generic_data); + action_TRANS_tr6_FROM_blockComment_TO_cp2_BY_nextCharreaderPort(self, ifitem, c); + if (c=='*') { + return STATE_firstStar;} + else { + return STATE_blockComment;} + } + case CHAIN_TRANS_tr9_FROM_firstStar_TO_cp3_BY_nextCharreaderPort: + { + char c = *((char*) generic_data); + action_TRANS_tr9_FROM_firstStar_TO_cp3_BY_nextCharreaderPort(self, ifitem, c); + if (c=='/') { + return STATE_code;} + else { + return STATE_blockComment;} + } + case CHAIN_TRANS_tr15_FROM_lineComment_TO_cp5_BY_nextCharreaderPort: + { + char c = *((char*) generic_data); + action_TRANS_tr15_FROM_lineComment_TO_cp5_BY_nextCharreaderPort(self, ifitem, c); + if (c=='\n') { + return STATE_code;} + else { + return STATE_lineComment;} + } + } + return NO_STATE; +} + +/** + * calls entry codes while entering a state's history. The ID of the final leaf state is returned + * @param state - the state which is entered + * @param handler - entry code is executed if not handler + * @return - the ID of the final leaf state + */ +static int enterHistory(ACParser* self, int state, boolean handler, boolean skip_entry) { + while (TRUE) { + switch (state) { + case STATE_code: + // in leaf state: return state id + return STATE_code; + case STATE_firstSlash: + // in leaf state: return state id + return STATE_firstSlash; + case STATE_blockComment: + // in leaf state: return state id + return STATE_blockComment; + case STATE_firstStar: + // in leaf state: return state id + return STATE_firstStar; + case STATE_lineComment: + // in leaf state: return state id + return STATE_lineComment; + case STATE_TOP: + state = self->history[STATE_TOP]; + break; + } + skip_entry = FALSE; + } + //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true) +} + +static void executeInitTransition(ACParser* self) { + int chain = CHAIN_TRANS_INITIAL_TO__code; + int next = executeTransitionChain(self, chain, NULL, NULL); + next = enterHistory(self, next, FALSE, FALSE); + setState(self, next); +} + +/* receiveEvent contains the main implementation of the FSM */ +static void receiveEvent(ACParser* self, InterfaceItemBase ifitem, int evt, void* generic_data) { + int trigger = ifitem->localId + EVT_SHIFT*evt; + int chain = NOT_CAUGHT; + int catching_state = NO_STATE; + boolean is_handler = FALSE; + boolean skip_entry = FALSE; + + if (!handleSystemEvent(ifitem, evt, generic_data)) { + switch (self->state) { + case STATE_code: + switch(trigger) { + case TRIG_readerPort__nextChar: + { + chain = CHAIN_TRANS_tr0_FROM_code_TO_cp0_BY_nextCharreaderPort; + catching_state = STATE_TOP; + } + break; + } + break; + case STATE_firstSlash: + switch(trigger) { + case TRIG_readerPort__nextChar: + { + chain = CHAIN_TRANS_tr3_FROM_firstSlash_TO_cp1_BY_nextCharreaderPort; + catching_state = STATE_TOP; + } + break; + } + break; + case STATE_blockComment: + switch(trigger) { + case TRIG_readerPort__nextChar: + { + chain = CHAIN_TRANS_tr6_FROM_blockComment_TO_cp2_BY_nextCharreaderPort; + catching_state = STATE_TOP; + } + break; + } + break; + case STATE_firstStar: + switch(trigger) { + case TRIG_readerPort__nextChar: + { + chain = CHAIN_TRANS_tr9_FROM_firstStar_TO_cp3_BY_nextCharreaderPort; + catching_state = STATE_TOP; + } + break; + } + break; + case STATE_lineComment: + switch(trigger) { + case TRIG_readerPort__nextChar: + { + chain = CHAIN_TRANS_tr15_FROM_lineComment_TO_cp5_BY_nextCharreaderPort; + catching_state = STATE_TOP; + } + break; + } + break; + } + } + if (chain != NOT_CAUGHT) { + exitTo(self, self->state, catching_state, is_handler); + int next = executeTransitionChain(self, chain, ifitem, generic_data); + next = enterHistory(self, next, is_handler, skip_entry); + setState(self, next); + } +} + +//****************************************** +// END of generated code for FSM +//****************************************** + +void ACParser_init(ACParser* self){ + ET_MSC_LOGGER_SYNC_ENTRY("ACParser", "init") + self->state = STATE_TOP; + { + int i; + for (i=0; i<ACPARSER_HISTORY_SIZE; ++i) + self->history[i] = NO_STATE; + } + executeInitTransition(self); + ET_MSC_LOGGER_SYNC_EXIT +} + + +void ACParser_receiveMessage(void* self, void* ifitem, const etMessage* msg){ + ET_MSC_LOGGER_SYNC_ENTRY("ACParser", "_receiveMessage") + + receiveEvent(self, (etPort*)ifitem, msg->evtID, (void*)(((char*)msg)+MEM_CEIL(sizeof(etMessage)))); + + ET_MSC_LOGGER_SYNC_EXIT +} + + +/*--------------------- operations ---------------------*/ + |