From 2d51a0615cc1b00d84a526b3ca7fbc1aaf3ad9c9 Mon Sep 17 00:00:00 2001 From: thurston Date: Sat, 12 Apr 2008 17:10:56 +0000 Subject: [PATCH] An fnext followed by an fbreak in -G2 did not work. The fbreak was not aware that the fnext causes the cs variable to be forced active. In this case fbreak does not need to save cs because it is already current. git-svn-id: http://svn.complang.org/ragel/trunk@429 052ea7fc-9027-0410-9066-f65837a77df0 --- rlgen-cd/fflatcodegen.cpp | 8 ++++---- rlgen-cd/fgotocodegen.cpp | 8 ++++---- rlgen-cd/flatcodegen.cpp | 22 +++++++++++----------- rlgen-cd/flatcodegen.h | 2 +- rlgen-cd/fsmcodegen.cpp | 39 ++++++++++++++++++++------------------- rlgen-cd/fsmcodegen.h | 8 +++++--- rlgen-cd/ftabcodegen.cpp | 8 ++++---- rlgen-cd/gotocodegen.cpp | 22 +++++++++++----------- rlgen-cd/gotocodegen.h | 2 +- rlgen-cd/ipgotocodegen.cpp | 40 ++++++++++++++++++++++++---------------- rlgen-cd/ipgotocodegen.h | 2 +- rlgen-cd/splitcodegen.cpp | 24 ++++++++++++++++-------- rlgen-cd/tabcodegen.cpp | 22 +++++++++++----------- rlgen-cd/tabcodegen.h | 2 +- rlgen-csharp/ipgotocodegen.cpp | 2 ++ 15 files changed, 116 insertions(+), 95 deletions(-) diff --git a/rlgen-cd/fflatcodegen.cpp b/rlgen-cd/fflatcodegen.cpp index 71975e8..806d732 100644 --- a/rlgen-cd/fflatcodegen.cpp +++ b/rlgen-cd/fflatcodegen.cpp @@ -75,7 +75,7 @@ std::ostream &FFlatCodeGen::TO_STATE_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tbreak;\n"; } @@ -97,7 +97,7 @@ std::ostream &FFlatCodeGen::FROM_STATE_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tbreak;\n"; } @@ -117,7 +117,7 @@ std::ostream &FFlatCodeGen::EOF_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, true ); + ACTION( out, item->value, 0, true, false ); out << "\tbreak;\n"; } @@ -139,7 +139,7 @@ std::ostream &FFlatCodeGen::ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tbreak;\n"; } diff --git a/rlgen-cd/fgotocodegen.cpp b/rlgen-cd/fgotocodegen.cpp index 2e1f195..0a353f3 100644 --- a/rlgen-cd/fgotocodegen.cpp +++ b/rlgen-cd/fgotocodegen.cpp @@ -37,7 +37,7 @@ std::ostream &FGotoCodeGen::EXEC_ACTIONS() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tgoto _again;\n"; } @@ -57,7 +57,7 @@ std::ostream &FGotoCodeGen::TO_STATE_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tbreak;\n"; } @@ -79,7 +79,7 @@ std::ostream &FGotoCodeGen::FROM_STATE_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tbreak;\n"; } @@ -99,7 +99,7 @@ std::ostream &FGotoCodeGen::EOF_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, true ); + ACTION( out, item->value, 0, true, false ); out << "\tbreak;\n"; } diff --git a/rlgen-cd/flatcodegen.cpp b/rlgen-cd/flatcodegen.cpp index 6273f75..783cde3 100644 --- a/rlgen-cd/flatcodegen.cpp +++ b/rlgen-cd/flatcodegen.cpp @@ -71,7 +71,7 @@ std::ostream &FlatCodeGen::TO_STATE_ACTION_SWITCH() if ( act->numToStateRefs > 0 ) { /* Write the case label, the action and the case break */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -88,7 +88,7 @@ std::ostream &FlatCodeGen::FROM_STATE_ACTION_SWITCH() if ( act->numFromStateRefs > 0 ) { /* Write the case label, the action and the case break */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -105,7 +105,7 @@ std::ostream &FlatCodeGen::EOF_ACTION_SWITCH() if ( act->numEofRefs > 0 ) { /* Write the case label, the action and the case break */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, true ); + ACTION( out, act, 0, true, false ); out << "\tbreak;\n"; } } @@ -123,7 +123,7 @@ std::ostream &FlatCodeGen::ACTION_SWITCH() if ( act->numTransRefs > 0 ) { /* Write the case label, the action and the case break */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -456,7 +456,7 @@ void FlatCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) void FlatCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << "); " << CTRL_FLOW() << "goto _again;}"; } @@ -478,7 +478,7 @@ void FlatCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) void FlatCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << ");"; } @@ -486,7 +486,7 @@ void FlatCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish { if ( prePushExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, prePushExpr, 0, false ); + INLINE_LIST( ret, prePushExpr, 0, false, false ); } ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " << @@ -501,11 +501,11 @@ void FlatCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bo { if ( prePushExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, prePushExpr, 0, false ); + INLINE_LIST( ret, prePushExpr, 0, false, false ); } ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, targState, inFinish ); + INLINE_LIST( ret, ilItem->children, targState, inFinish, false ); ret << "); " << CTRL_FLOW() << "goto _again;}"; if ( prePushExpr != 0 ) @@ -519,14 +519,14 @@ void FlatCodeGen::RET( ostream &ret, bool inFinish ) if ( postPopExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, postPopExpr, 0, false ); + INLINE_LIST( ret, postPopExpr, 0, false, false ); ret << "}"; } ret << CTRL_FLOW() << "goto _again;}"; } -void FlatCodeGen::BREAK( ostream &ret, int targState ) +void FlatCodeGen::BREAK( ostream &ret, int targState, bool csForced ) { outLabelUsed = true; ret << "{" << P() << "++; " << CTRL_FLOW() << "goto _out; }"; diff --git a/rlgen-cd/flatcodegen.h b/rlgen-cd/flatcodegen.h index 651f30c..d132bec 100644 --- a/rlgen-cd/flatcodegen.h +++ b/rlgen-cd/flatcodegen.h @@ -74,7 +74,7 @@ protected: void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); - void BREAK( ostream &ret, int targState ); + void BREAK( ostream &ret, int targState, bool csForced ); virtual std::ostream &TO_STATE_ACTION( RedStateAp *state ); virtual std::ostream &FROM_STATE_ACTION( RedStateAp *state ); diff --git a/rlgen-cd/fsmcodegen.cpp b/rlgen-cd/fsmcodegen.cpp index 78faafb..c45be49 100644 --- a/rlgen-cd/fsmcodegen.cpp +++ b/rlgen-cd/fsmcodegen.cpp @@ -140,7 +140,7 @@ string FsmCodeGen::ACCESS() { ostringstream ret; if ( accessExpr != 0 ) - INLINE_LIST( ret, accessExpr, 0, false ); + INLINE_LIST( ret, accessExpr, 0, false, false ); return ret.str(); } @@ -152,7 +152,7 @@ string FsmCodeGen::P() ret << "p"; else { ret << "("; - INLINE_LIST( ret, pExpr, 0, false ); + INLINE_LIST( ret, pExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -165,7 +165,7 @@ string FsmCodeGen::PE() ret << "pe"; else { ret << "("; - INLINE_LIST( ret, peExpr, 0, false ); + INLINE_LIST( ret, peExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -178,7 +178,7 @@ string FsmCodeGen::EOFV() ret << "eof"; else { ret << "("; - INLINE_LIST( ret, eofExpr, 0, false ); + INLINE_LIST( ret, eofExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -192,7 +192,7 @@ string FsmCodeGen::CS() else { /* Emit the user supplied method of retrieving the key. */ ret << "("; - INLINE_LIST( ret, csExpr, 0, false ); + INLINE_LIST( ret, csExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -205,7 +205,7 @@ string FsmCodeGen::TOP() ret << ACCESS() + "top"; else { ret << "("; - INLINE_LIST( ret, topExpr, 0, false ); + INLINE_LIST( ret, topExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -218,7 +218,7 @@ string FsmCodeGen::STACK() ret << ACCESS() + "stack"; else { ret << "("; - INLINE_LIST( ret, stackExpr, 0, false ); + INLINE_LIST( ret, stackExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -231,7 +231,7 @@ string FsmCodeGen::ACT() ret << ACCESS() + "act"; else { ret << "("; - INLINE_LIST( ret, actExpr, 0, false ); + INLINE_LIST( ret, actExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -244,7 +244,7 @@ string FsmCodeGen::TOKSTART() ret << ACCESS() + "ts"; else { ret << "("; - INLINE_LIST( ret, tokstartExpr, 0, false ); + INLINE_LIST( ret, tokstartExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -257,7 +257,7 @@ string FsmCodeGen::TOKEND() ret << ACCESS() + "te"; else { ret << "("; - INLINE_LIST( ret, tokendExpr, 0, false ); + INLINE_LIST( ret, tokendExpr, 0, false, false ); ret << ")"; } return ret.str(); @@ -285,7 +285,7 @@ string FsmCodeGen::GET_KEY() if ( getKeyExpr != 0 ) { /* Emit the user supplied method of retrieving the key. */ ret << "("; - INLINE_LIST( ret, getKeyExpr, 0, false ); + INLINE_LIST( ret, getKeyExpr, 0, false, false ); ret << ")"; } else { @@ -323,7 +323,7 @@ void FsmCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFini * code. If the inline list is a single word it will get interpreted as a * C-style cast by the D compiler. */ ret << "{" << P() << " = (("; - INLINE_LIST( ret, item->children, targState, inFinish ); + INLINE_LIST( ret, item->children, targState, inFinish, false ); ret << "))-1;}"; } @@ -339,7 +339,7 @@ void FsmCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, /* Write the block and close it off. */ ret << " {"; - INLINE_LIST( ret, lma->children, targState, inFinish ); + INLINE_LIST( ret, lma->children, targState, inFinish, false ); ret << "}\n"; ret << " break;\n"; @@ -391,7 +391,7 @@ void FsmCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, if ( item->children->length() > 0 ) { /* Write the block and close it off. */ ret << "{"; - INLINE_LIST( ret, item->children, targState, inFinish ); + INLINE_LIST( ret, item->children, targState, inFinish, false ); ret << "}"; } } @@ -400,7 +400,7 @@ void FsmCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, /* Write out an inline tree structure. Walks the list and possibly calls out * to virtual functions than handle language specific items in the tree. */ void FsmCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, - int targState, bool inFinish ) + int targState, bool inFinish, bool csForced ) { for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { @@ -474,7 +474,7 @@ void FsmCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, SUB_ACTION( ret, item, targState, inFinish ); break; case InlineItem::Break: - BREAK( ret, targState ); + BREAK( ret, targState, csForced ); break; } } @@ -492,14 +492,15 @@ string FsmCodeGen::LDIR_PATH( char *path ) return ret.str(); } -void FsmCodeGen::ACTION( ostream &ret, Action *action, int targState, bool inFinish ) +void FsmCodeGen::ACTION( ostream &ret, Action *action, int targState, + bool inFinish, bool csForced ) { /* Write the preprocessor line info for going into the source file. */ lineDirective( ret, sourceFileName, action->loc.line ); /* Write the block and close it off. */ ret << "\t{"; - INLINE_LIST( ret, action->inlineList, targState, inFinish ); + INLINE_LIST( ret, action->inlineList, targState, inFinish, csForced ); ret << "}\n"; } @@ -507,7 +508,7 @@ void FsmCodeGen::CONDITION( ostream &ret, Action *condition ) { ret << "\n"; lineDirective( ret, sourceFileName, condition->loc.line ); - INLINE_LIST( ret, condition->inlineList, 0, false ); + INLINE_LIST( ret, condition->inlineList, 0, false, false ); } string FsmCodeGen::ERROR_STATE() diff --git a/rlgen-cd/fsmcodegen.h b/rlgen-cd/fsmcodegen.h index 30eaa8f..a7d2244 100644 --- a/rlgen-cd/fsmcodegen.h +++ b/rlgen-cd/fsmcodegen.h @@ -76,7 +76,8 @@ protected: string TABS( int level ); string KEY( Key key ); string LDIR_PATH( char *path ); - void ACTION( ostream &ret, Action *action, int targState, bool inFinish ); + void ACTION( ostream &ret, Action *action, int targState, + bool inFinish, bool csForced ); void CONDITION( ostream &ret, Action *condition ); string ALPH_TYPE(); string WIDE_ALPH_TYPE(); @@ -128,7 +129,8 @@ protected: string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; } string CTXDATA() { return DATA_PREFIX() + "ctxdata"; } - void INLINE_LIST( ostream &ret, InlineList *inlineList, int targState, bool inFinish ); + void INLINE_LIST( ostream &ret, InlineList *inlineList, + int targState, bool inFinish, bool csForced ); virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0; virtual void CALL( ostream &ret, int callDest, int targState, bool inFinish ) = 0; virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0; @@ -137,7 +139,7 @@ protected: virtual void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) = 0; virtual void RET( ostream &ret, bool inFinish ) = 0; - virtual void BREAK( ostream &ret, int targState ) = 0; + virtual void BREAK( ostream &ret, int targState, bool csForced ) = 0; virtual void CURS( ostream &ret, bool inFinish ) = 0; virtual void TARGS( ostream &ret, bool inFinish, int targState ) = 0; void EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ); diff --git a/rlgen-cd/ftabcodegen.cpp b/rlgen-cd/ftabcodegen.cpp index f2c484c..32c8635 100644 --- a/rlgen-cd/ftabcodegen.cpp +++ b/rlgen-cd/ftabcodegen.cpp @@ -104,7 +104,7 @@ std::ostream &FTabCodeGen::TO_STATE_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tbreak;\n"; } @@ -126,7 +126,7 @@ std::ostream &FTabCodeGen::FROM_STATE_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tbreak;\n"; } @@ -146,7 +146,7 @@ std::ostream &FTabCodeGen::EOF_ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, true ); + ACTION( out, item->value, 0, true, false ); out << "\tbreak;\n"; } @@ -168,7 +168,7 @@ std::ostream &FTabCodeGen::ACTION_SWITCH() /* Write each action in the list of action items. */ for ( ActionTable::Iter item = redAct->key; item.lte(); item++ ) - ACTION( out, item->value, 0, false ); + ACTION( out, item->value, 0, false, false ); out << "\tbreak;\n"; } diff --git a/rlgen-cd/gotocodegen.cpp b/rlgen-cd/gotocodegen.cpp index 8ad4af5..aa779b9 100644 --- a/rlgen-cd/gotocodegen.cpp +++ b/rlgen-cd/gotocodegen.cpp @@ -42,7 +42,7 @@ std::ostream &GotoCodeGen::TO_STATE_ACTION_SWITCH() if ( act->numToStateRefs > 0 ) { /* Write the case label, the action and the case break. */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -59,7 +59,7 @@ std::ostream &GotoCodeGen::FROM_STATE_ACTION_SWITCH() if ( act->numFromStateRefs > 0 ) { /* Write the case label, the action and the case break. */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -76,7 +76,7 @@ std::ostream &GotoCodeGen::EOF_ACTION_SWITCH() if ( act->numEofRefs > 0 ) { /* Write the case label, the action and the case break. */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, true ); + ACTION( out, act, 0, true, false ); out << "\tbreak;\n"; } } @@ -93,7 +93,7 @@ std::ostream &GotoCodeGen::ACTION_SWITCH() if ( act->numTransRefs > 0 ) { /* Write the case label, the action and the case break. */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -550,7 +550,7 @@ void GotoCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) void GotoCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << "); " << CTRL_FLOW() << "goto _again;}"; } @@ -572,7 +572,7 @@ void GotoCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) void GotoCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << ");"; } @@ -580,7 +580,7 @@ void GotoCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish { if ( prePushExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, prePushExpr, 0, false ); + INLINE_LIST( ret, prePushExpr, 0, false, false ); } ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " << @@ -594,11 +594,11 @@ void GotoCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bo { if ( prePushExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, prePushExpr, 0, false ); + INLINE_LIST( ret, prePushExpr, 0, false, false ); } ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, targState, inFinish ); + INLINE_LIST( ret, ilItem->children, targState, inFinish, false ); ret << "); " << CTRL_FLOW() << "goto _again;}"; if ( prePushExpr != 0 ) @@ -611,14 +611,14 @@ void GotoCodeGen::RET( ostream &ret, bool inFinish ) if ( postPopExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, postPopExpr, 0, false ); + INLINE_LIST( ret, postPopExpr, 0, false, false ); ret << "}"; } ret << CTRL_FLOW() << "goto _again;}"; } -void GotoCodeGen::BREAK( ostream &ret, int targState ) +void GotoCodeGen::BREAK( ostream &ret, int targState, bool csForced ) { outLabelUsed = true; ret << "{" << P() << "++; " << CTRL_FLOW() << "goto _out; }"; diff --git a/rlgen-cd/gotocodegen.h b/rlgen-cd/gotocodegen.h index 7f58bbd..b083d09 100644 --- a/rlgen-cd/gotocodegen.h +++ b/rlgen-cd/gotocodegen.h @@ -59,7 +59,7 @@ public: void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); - void BREAK( ostream &ret, int targState ); + void BREAK( ostream &ret, int targState, bool csForced ); virtual unsigned int TO_STATE_ACTION( RedStateAp *state ); virtual unsigned int FROM_STATE_ACTION( RedStateAp *state ); diff --git a/rlgen-cd/ipgotocodegen.cpp b/rlgen-cd/ipgotocodegen.cpp index 69f9da7..f12824a 100644 --- a/rlgen-cd/ipgotocodegen.cpp +++ b/rlgen-cd/ipgotocodegen.cpp @@ -43,7 +43,7 @@ void IpGotoCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFini { if ( prePushExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, prePushExpr, 0, false ); + INLINE_LIST( ret, prePushExpr, 0, false, false ); } ret << "{" << STACK() << "[" << TOP() << "++] = " << targState << @@ -57,11 +57,11 @@ void IpGotoCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, { if ( prePushExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, prePushExpr, 0, false ); + INLINE_LIST( ret, prePushExpr, 0, false, false ); } ret << "{" << STACK() << "[" << TOP() << "++] = " << targState << "; " << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << "); " << CTRL_FLOW() << "goto _again;}"; if ( prePushExpr != 0 ) @@ -74,7 +74,7 @@ void IpGotoCodeGen::RET( ostream &ret, bool inFinish ) if ( postPopExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, postPopExpr, 0, false ); + INLINE_LIST( ret, postPopExpr, 0, false, false ); ret << "}"; } @@ -84,7 +84,7 @@ void IpGotoCodeGen::RET( ostream &ret, bool inFinish ) void IpGotoCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << "); " << CTRL_FLOW() << "goto _again;}"; } @@ -96,7 +96,7 @@ void IpGotoCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) void IpGotoCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << ");"; } @@ -110,11 +110,13 @@ void IpGotoCodeGen::TARGS( ostream &ret, bool inFinish, int targState ) ret << targState; } -void IpGotoCodeGen::BREAK( ostream &ret, int targState ) +void IpGotoCodeGen::BREAK( ostream &ret, int targState, bool csForced ) { outLabelUsed = true; - ret << "{" << P() << "++; " << CS() << " = " << targState << - "; " << CTRL_FLOW() << "goto _out;}"; + ret << "{" << P() << "++; "; + if ( !csForced ) + ret << CS() << " = " << targState << "; "; + ret << CTRL_FLOW() << "goto _out;}"; } bool IpGotoCodeGen::IN_TRANS_ACTIONS( RedStateAp *state ) @@ -138,8 +140,10 @@ bool IpGotoCodeGen::IN_TRANS_ACTIONS( RedStateAp *state ) out << " " << CS() << " = " << trans->targ->id << ";\n"; /* Write each action in the list. */ - for ( ActionTable::Iter item = trans->action->key; item.lte(); item++ ) - ACTION( out, item->value, trans->targ->id, false ); + for ( ActionTable::Iter item = trans->action->key; item.lte(); item++ ) { + ACTION( out, item->value, trans->targ->id, false, + trans->action->anyNextStmt() ); + } /* If the action contains a next then we need to reload, otherwise * jump directly to the target state. */ @@ -165,8 +169,10 @@ void IpGotoCodeGen::GOTO_HEADER( RedStateAp *state ) if ( state->toStateAction != 0 ) { /* Remember that we wrote an action. Write every action in the list. */ anyWritten = true; - for ( ActionTable::Iter item = state->toStateAction->key; item.lte(); item++ ) - ACTION( out, item->value, state->id, false ); + for ( ActionTable::Iter item = state->toStateAction->key; item.lte(); item++ ) { + ACTION( out, item->value, state->id, false, + state->toStateAction->anyNextStmt() ); + } } /* Advance and test buffer pos. */ @@ -188,8 +194,10 @@ void IpGotoCodeGen::GOTO_HEADER( RedStateAp *state ) if ( state->fromStateAction != 0 ) { /* Remember that we wrote an action. Write every action in the list. */ anyWritten = true; - for ( ActionTable::Iter item = state->fromStateAction->key; item.lte(); item++ ) - ACTION( out, item->value, state->id, false ); + for ( ActionTable::Iter item = state->fromStateAction->key; item.lte(); item++ ) { + ACTION( out, item->value, state->id, false, + state->fromStateAction->anyNextStmt() ); + } } if ( anyWritten ) @@ -284,7 +292,7 @@ std::ostream &IpGotoCodeGen::FINISH_CASES() /* Write each action in the eof action list. */ for ( ActionTable::Iter item = act->key; item.lte(); item++ ) - ACTION( out, item->value, STATE_ERR_STATE, true ); + ACTION( out, item->value, STATE_ERR_STATE, true, false ); out << "\tbreak;\n"; } } diff --git a/rlgen-cd/ipgotocodegen.h b/rlgen-cd/ipgotocodegen.h index 2664e3b..1a452ae 100644 --- a/rlgen-cd/ipgotocodegen.h +++ b/rlgen-cd/ipgotocodegen.h @@ -52,7 +52,7 @@ public: void RET( ostream &ret, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); - void BREAK( ostream &ret, int targState ); + void BREAK( ostream &ret, int targState, bool csForced ); virtual void writeData(); virtual void writeExec(); diff --git a/rlgen-cd/splitcodegen.cpp b/rlgen-cd/splitcodegen.cpp index f43362e..22918a5 100644 --- a/rlgen-cd/splitcodegen.cpp +++ b/rlgen-cd/splitcodegen.cpp @@ -68,8 +68,10 @@ void SplitCodeGen::GOTO_HEADER( RedStateAp *state, bool stateInPartition ) if ( state->toStateAction != 0 ) { /* Remember that we wrote an action. Write every action in the list. */ anyWritten = true; - for ( ActionTable::Iter item = state->toStateAction->key; item.lte(); item++ ) - ACTION( out, item->value, state->id, false ); + for ( ActionTable::Iter item = state->toStateAction->key; item.lte(); item++ ) { + ACTION( out, item->value, state->id, false, + state->toStateAction->anyNextStmt() ); + } } /* Advance and test buffer pos. */ @@ -91,8 +93,10 @@ void SplitCodeGen::GOTO_HEADER( RedStateAp *state, bool stateInPartition ) if ( state->fromStateAction != 0 ) { /* Remember that we wrote an action. Write every action in the list. */ anyWritten = true; - for ( ActionTable::Iter item = state->fromStateAction->key; item.lte(); item++ ) - ACTION( out, item->value, state->id, false ); + for ( ActionTable::Iter item = state->fromStateAction->key; item.lte(); item++ ) { + ACTION( out, item->value, state->id, false, + state->fromStateAction->anyNextStmt() ); + } } if ( anyWritten ) @@ -154,8 +158,10 @@ std::ostream &SplitCodeGen::PART_TRANS( int partition ) out << " " << CS() << " = " << trans->targ->id << ";\n"; /* Write each action in the list. */ - for ( ActionTable::Iter item = trans->action->key; item.lte(); item++ ) - ACTION( out, item->value, trans->targ->id, false ); + for ( ActionTable::Iter item = trans->action->key; item.lte(); item++ ) { + ACTION( out, item->value, trans->targ->id, false, + trans->action->anyNextStmt() ); + } } out << @@ -172,8 +178,10 @@ std::ostream &SplitCodeGen::PART_TRANS( int partition ) if ( st->toStateAction != 0 ) { /* Remember that we wrote an action. Write every action in the list. */ - for ( ActionTable::Iter item = st->toStateAction->key; item.lte(); item++ ) - ACTION( out, item->value, st->id, false ); + for ( ActionTable::Iter item = st->toStateAction->key; item.lte(); item++ ) { + ACTION( out, item->value, st->id, false, + st->toStateAction->anyNextStmt() ); + } genLineDirective( out ); } diff --git a/rlgen-cd/tabcodegen.cpp b/rlgen-cd/tabcodegen.cpp index b7e6b28..94d5c08 100644 --- a/rlgen-cd/tabcodegen.cpp +++ b/rlgen-cd/tabcodegen.cpp @@ -100,7 +100,7 @@ std::ostream &TabCodeGen::TO_STATE_ACTION_SWITCH() if ( act->numToStateRefs > 0 ) { /* Write the case label, the action and the case break. */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -117,7 +117,7 @@ std::ostream &TabCodeGen::FROM_STATE_ACTION_SWITCH() if ( act->numFromStateRefs > 0 ) { /* Write the case label, the action and the case break. */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -134,7 +134,7 @@ std::ostream &TabCodeGen::EOF_ACTION_SWITCH() if ( act->numEofRefs > 0 ) { /* Write the case label, the action and the case break. */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, true ); + ACTION( out, act, 0, true, false ); out << "\tbreak;\n"; } } @@ -152,7 +152,7 @@ std::ostream &TabCodeGen::ACTION_SWITCH() if ( act->numTransRefs > 0 ) { /* Write the case label, the action and the case break. */ out << "\tcase " << act->actionId << ":\n"; - ACTION( out, act, 0, false ); + ACTION( out, act, 0, false, false ); out << "\tbreak;\n"; } } @@ -645,7 +645,7 @@ void TabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) void TabCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << "); " << CTRL_FLOW() << "goto _again;}"; } @@ -667,7 +667,7 @@ void TabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) void TabCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); + INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); ret << ");"; } @@ -675,7 +675,7 @@ void TabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish { if ( prePushExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, prePushExpr, 0, false ); + INLINE_LIST( ret, prePushExpr, 0, false, false ); } ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " << @@ -689,11 +689,11 @@ void TabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, boo { if ( prePushExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, prePushExpr, 0, false ); + INLINE_LIST( ret, prePushExpr, 0, false, false ); } ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, targState, inFinish ); + INLINE_LIST( ret, ilItem->children, targState, inFinish, false ); ret << "); " << CTRL_FLOW() << "goto _again;}"; if ( prePushExpr != 0 ) @@ -707,14 +707,14 @@ void TabCodeGen::RET( ostream &ret, bool inFinish ) if ( postPopExpr != 0 ) { ret << "{"; - INLINE_LIST( ret, postPopExpr, 0, false ); + INLINE_LIST( ret, postPopExpr, 0, false, false ); ret << "}"; } ret << CTRL_FLOW() << "goto _again;}"; } -void TabCodeGen::BREAK( ostream &ret, int targState ) +void TabCodeGen::BREAK( ostream &ret, int targState, bool csForced ) { outLabelUsed = true; ret << "{" << P() << "++; " << CTRL_FLOW() << "goto _out; }"; diff --git a/rlgen-cd/tabcodegen.h b/rlgen-cd/tabcodegen.h index 177896e..c8a4a21 100644 --- a/rlgen-cd/tabcodegen.h +++ b/rlgen-cd/tabcodegen.h @@ -81,7 +81,7 @@ protected: void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); - void BREAK( ostream &ret, int targState ); + void BREAK( ostream &ret, int targState, bool csForced ); virtual std::ostream &TO_STATE_ACTION( RedStateAp *state ); virtual std::ostream &FROM_STATE_ACTION( RedStateAp *state ); diff --git a/rlgen-csharp/ipgotocodegen.cpp b/rlgen-csharp/ipgotocodegen.cpp index c5f6ace..8118a3d 100644 --- a/rlgen-csharp/ipgotocodegen.cpp +++ b/rlgen-csharp/ipgotocodegen.cpp @@ -112,6 +112,8 @@ void CSharpIpGotoCodeGen::TARGS( ostream &ret, bool inFinish, int targState ) void CSharpIpGotoCodeGen::BREAK( ostream &ret, int targState ) { + /* FIXME: If this code generator is made active then BREAK generation + * needs to check csForced. */ outLabelUsed = true; ret << "{" << P() << "++; " << CS() << " = " << targState << "; " << CTRL_FLOW() << "goto _out;}"; -- 2.7.4