From 3702e9a17992d19892491bc600bdaa85974f2dcd Mon Sep 17 00:00:00 2001 From: thurston Date: Sun, 10 Jun 2007 17:21:26 +0000 Subject: [PATCH] Can cleanup the xml code generation and remove the holdte and execte tags following the previous commit. git-svn-id: http://svn.complang.org/ragel/trunk@239 052ea7fc-9027-0410-9066-f65837a77df0 --- ragel/xmlcodegen.cpp | 147 ++++++++++++++++----------------------------- ragel/xmlcodegen.h | 17 +++--- redfsm/redfsm.h | 2 +- redfsm/xmlparse.kh | 7 +-- redfsm/xmlparse.kl | 15 ----- redfsm/xmltags.gperf | 2 - rlgen-cd/fsmcodegen.cpp | 19 ------ rlgen-cd/fsmcodegen.h | 1 - rlgen-java/javacodegen.cpp | 18 ------ rlgen-ruby/rubycodegen.cpp | 18 ------ 10 files changed, 64 insertions(+), 182 deletions(-) diff --git a/ragel/xmlcodegen.cpp b/ragel/xmlcodegen.cpp index f5d210a..f4570a9 100644 --- a/ragel/xmlcodegen.cpp +++ b/ragel/xmlcodegen.cpp @@ -184,61 +184,7 @@ void XMLCodeGen::writeText( InlineItem *item ) out << ""; } -bool isLmItem( InlineItem *context ) -{ - return context != 0 && ( - context->type == InlineItem::LmOnLast || - context->type == InlineItem::LmOnNext || - context->type == InlineItem::LmOnLagBehind || - context->type == InlineItem::LmSwitch ); -} - -void XMLCodeGen::writeCtrlFlow( InlineItem *item, InlineItem *context ) -{ - switch ( item->type ) { - case InlineItem::Goto: - writeGoto( item, context ); - break; - case InlineItem::GotoExpr: - writeGotoExpr( item, context ); - break; - case InlineItem::Call: - writeCall( item, context ); - break; - case InlineItem::CallExpr: - writeCallExpr( item, context ); - break; - case InlineItem::Next: - writeNext( item, context ); - break; - case InlineItem::NextExpr: - writeNextExpr( item, context ); - break; - case InlineItem::Break: - out << ""; - break; - case InlineItem::Ret: - out << ""; - break; - default: break; - } -} - -void XMLCodeGen::writePtrMod( InlineItem *item, InlineItem * ) -{ - switch ( item->type ) { - case InlineItem::Hold: - out << ""; - break; - case InlineItem::Exec: - writeActionExec( item ); - break; - default: break; - } -} - - -void XMLCodeGen::writeGoto( InlineItem *item, InlineItem *context ) +void XMLCodeGen::writeGoto( InlineItem *item ) { if ( pd->generatingSectionSubset ) out << "-1"; @@ -248,7 +194,7 @@ void XMLCodeGen::writeGoto( InlineItem *item, InlineItem *context ) } } -void XMLCodeGen::writeCall( InlineItem *item, InlineItem *context ) +void XMLCodeGen::writeCall( InlineItem *item ) { if ( pd->generatingSectionSubset ) out << "-1"; @@ -258,7 +204,7 @@ void XMLCodeGen::writeCall( InlineItem *item, InlineItem *context ) } } -void XMLCodeGen::writeNext( InlineItem *item, InlineItem *context ) +void XMLCodeGen::writeNext( InlineItem *item ) { if ( pd->generatingSectionSubset ) out << "-1"; @@ -268,28 +214,28 @@ void XMLCodeGen::writeNext( InlineItem *item, InlineItem *context ) } } -void XMLCodeGen::writeGotoExpr( InlineItem *item, InlineItem *context ) +void XMLCodeGen::writeGotoExpr( InlineItem *item ) { out << ""; - writeInlineList( item->children, 0 ); + writeInlineList( item->children ); out << ""; } -void XMLCodeGen::writeCallExpr( InlineItem *item, InlineItem *context ) +void XMLCodeGen::writeCallExpr( InlineItem *item ) { out << ""; - writeInlineList( item->children, 0 ); + writeInlineList( item->children ); out << ""; } -void XMLCodeGen::writeNextExpr( InlineItem *item, InlineItem *context ) +void XMLCodeGen::writeNextExpr( InlineItem *item ) { out << ""; - writeInlineList( item->children, 0 ); + writeInlineList( item->children ); out << ""; } -void XMLCodeGen::writeEntry( InlineItem * item ) +void XMLCodeGen::writeEntry( InlineItem *item ) { if ( pd->generatingSectionSubset ) out << "-1"; @@ -302,24 +248,17 @@ void XMLCodeGen::writeEntry( InlineItem * item ) void XMLCodeGen::writeActionExec( InlineItem *item ) { out << ""; - writeInlineList( item->children, 0 ); + writeInlineList( item->children ); out << ""; } -void XMLCodeGen::writeActionExecTE( InlineItem *item ) -{ - out << ""; - writeInlineList( item->children, 0 ); - out << ""; -} - void XMLCodeGen::writeLmOnLast( InlineItem *item ) { out << "1"; if ( item->longestMatchPart->action != 0 ) { out << ""; - writeInlineList( item->longestMatchPart->action->inlineList, item ); + writeInlineList( item->longestMatchPart->action->inlineList ); out << ""; } } @@ -331,7 +270,7 @@ void XMLCodeGen::writeLmOnNext( InlineItem *item ) if ( item->longestMatchPart->action != 0 ) { out << ""; - writeInlineList( item->longestMatchPart->action->inlineList, item ); + writeInlineList( item->longestMatchPart->action->inlineList ); out << ""; } } @@ -342,7 +281,7 @@ void XMLCodeGen::writeLmOnLagBehind( InlineItem *item ) if ( item->longestMatchPart->action != 0 ) { out << ""; - writeInlineList( item->longestMatchPart->action->inlineList, item ); + writeInlineList( item->longestMatchPart->action->inlineList ); out << ""; } } @@ -369,7 +308,7 @@ void XMLCodeGen::writeLmSwitch( InlineItem *item ) * when doing control flow changes from inside the machine. */ out << " longestMatchId << "\">"; out << ""; - writeInlineList( lmi->action->inlineList, item ); + writeInlineList( lmi->action->inlineList ); out << "\n"; } } @@ -377,18 +316,36 @@ void XMLCodeGen::writeLmSwitch( InlineItem *item ) out << " "; } -void XMLCodeGen::writeInlineList( InlineList *inlineList, InlineItem *context ) +void XMLCodeGen::writeInlineList( InlineList *inlineList ) { for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { case InlineItem::Text: writeText( item ); break; - case InlineItem::Goto: case InlineItem::GotoExpr: - case InlineItem::Call: case InlineItem::CallExpr: - case InlineItem::Next: case InlineItem::NextExpr: - case InlineItem::Break: case InlineItem::Ret: - writeCtrlFlow( item, context ); + case InlineItem::Goto: + writeGoto( item ); + break; + case InlineItem::GotoExpr: + writeGotoExpr( item ); + break; + case InlineItem::Call: + writeCall( item ); + break; + case InlineItem::CallExpr: + writeCallExpr( item ); + break; + case InlineItem::Next: + writeNext( item ); + break; + case InlineItem::NextExpr: + writeNextExpr( item ); + break; + case InlineItem::Break: + out << ""; + break; + case InlineItem::Ret: + out << ""; break; case InlineItem::PChar: out << ""; @@ -407,8 +364,10 @@ void XMLCodeGen::writeInlineList( InlineList *inlineList, InlineItem *context ) break; case InlineItem::Hold: + out << ""; + break; case InlineItem::Exec: - writePtrMod( item, context ); + writeActionExec( item ); break; case InlineItem::LmSetActId: @@ -452,7 +411,7 @@ void XMLCodeGen::writeAction( Action *action ) if ( action->name != 0 ) out << " name=\"" << action->name << "\""; out << " line=\"" << action->loc.line << "\" col=\"" << action->loc.col << "\">"; - writeInlineList( action->inlineList, 0 ); + writeInlineList( action->inlineList ); out << "\n"; } @@ -651,14 +610,14 @@ void XMLCodeGen::writeXML() /* Getkey expression. */ if ( pd->getKeyExpr != 0 ) { out << " "; - writeInlineList( pd->getKeyExpr, 0 ); + writeInlineList( pd->getKeyExpr ); out << "\n"; } /* Access expression. */ if ( pd->accessExpr != 0 ) { out << " "; - writeInlineList( pd->accessExpr, 0 ); + writeInlineList( pd->accessExpr ); out << "\n"; } @@ -668,49 +627,49 @@ void XMLCodeGen::writeXML() if ( pd->pExpr != 0 ) { out << " "; - writeInlineList( pd->pExpr, 0 ); + writeInlineList( pd->pExpr ); out << "\n"; } if ( pd->peExpr != 0 ) { out << " "; - writeInlineList( pd->peExpr, 0 ); + writeInlineList( pd->peExpr ); out << "\n"; } if ( pd->csExpr != 0 ) { out << " "; - writeInlineList( pd->csExpr, 0 ); + writeInlineList( pd->csExpr ); out << "\n"; } if ( pd->topExpr != 0 ) { out << " "; - writeInlineList( pd->topExpr, 0 ); + writeInlineList( pd->topExpr ); out << "\n"; } if ( pd->stackExpr != 0 ) { out << " "; - writeInlineList( pd->stackExpr, 0 ); + writeInlineList( pd->stackExpr ); out << "\n"; } if ( pd->actExpr != 0 ) { out << " "; - writeInlineList( pd->actExpr, 0 ); + writeInlineList( pd->actExpr ); out << "\n"; } if ( pd->tokstartExpr != 0 ) { out << " "; - writeInlineList( pd->tokstartExpr, 0 ); + writeInlineList( pd->tokstartExpr ); out << "\n"; } if ( pd->tokendExpr != 0 ) { out << " "; - writeInlineList( pd->tokendExpr, 0 ); + writeInlineList( pd->tokendExpr ); out << "\n"; } diff --git a/ragel/xmlcodegen.h b/ragel/xmlcodegen.h index 6f4823b..f366029 100644 --- a/ragel/xmlcodegen.h +++ b/ragel/xmlcodegen.h @@ -90,14 +90,12 @@ private: void writeKey( Key key ); void writeText( InlineItem *item ); - void writeCtrlFlow( InlineItem *item, InlineItem *context ); - void writePtrMod( InlineItem *item, InlineItem *context ); - void writeGoto( InlineItem *item, InlineItem *context ); - void writeGotoExpr( InlineItem *item, InlineItem *context ); - void writeCall( InlineItem *item, InlineItem *context ); - void writeCallExpr( InlineItem *item, InlineItem *context ); - void writeNext( InlineItem *item, InlineItem *context ); - void writeNextExpr( InlineItem *item, InlineItem *context ); + void writeGoto( InlineItem *item ); + void writeGotoExpr( InlineItem *item ); + void writeCall( InlineItem *item ); + void writeCallExpr( InlineItem *item ); + void writeNext( InlineItem *item ); + void writeNextExpr( InlineItem *item ); void writeEntry( InlineItem *item ); void writeLmSetActId( InlineItem *item ); void writeLmOnLast( InlineItem *item ); @@ -108,7 +106,7 @@ private: bool writeNameInst( NameInst *nameInst ); void writeEntryPoints(); void writeConditions(); - void writeInlineList( InlineList *inlineList, InlineItem *context ); + void writeInlineList( InlineList *inlineList ); void writeActionList(); void writeActionTableList(); void reduceTrans( TransAp *trans ); @@ -119,7 +117,6 @@ private: void writeLmSwitch( InlineItem *item ); void writeMachine(); void writeActionExec( InlineItem *item ); - void writeActionExecTE( InlineItem *item ); char *fsmName; ParseData *pd; diff --git a/redfsm/redfsm.h b/redfsm/redfsm.h index 85e49f4..64d73e7 100644 --- a/redfsm/redfsm.h +++ b/redfsm/redfsm.h @@ -65,7 +65,7 @@ struct InlineItem enum Type { Text, Goto, Call, Next, GotoExpr, CallExpr, NextExpr, Ret, - PChar, Char, Hold, Exec, HoldTE, ExecTE, Curs, Targs, Entry, + PChar, Char, Hold, Exec, Curs, Targs, Entry, LmSwitch, LmSetActId, LmSetTokEnd, LmGetTokEnd, LmInitTokStart, LmInitAct, LmSetTokStart, SubAction, Break }; diff --git a/redfsm/xmlparse.kh b/redfsm/xmlparse.kh index 7b1d2a1..2e29db5 100644 --- a/redfsm/xmlparse.kh +++ b/redfsm/xmlparse.kh @@ -109,10 +109,9 @@ struct Parser # Inline block tokens. token TAG_text, TAG_goto, TAG_call, TAG_next, TAG_goto_expr, TAG_call_expr, TAG_next_expr, TAG_ret, TAG_pchar, TAG_char, - TAG_hold, TAG_exec, TAG_holdte, TAG_execte, TAG_curs, TAG_targs, - TAG_entry, TAG_data, TAG_lm_switch, TAG_init_act, TAG_set_act, - TAG_set_tokend, TAG_get_tokend, TAG_init_tokstart, - TAG_set_tokstart; + TAG_hold, TAG_exec, TAG_curs, TAG_targs, TAG_entry, TAG_data, + TAG_lm_switch, TAG_init_act, TAG_set_act, TAG_set_tokend, + TAG_get_tokend, TAG_init_tokstart, TAG_set_tokstart; token TAG_write, TAG_access, TAG_break, TAG_arg, TAG_cs_expr; diff --git a/redfsm/xmlparse.kl b/redfsm/xmlparse.kl index cf3be17..3f4d926 100644 --- a/redfsm/xmlparse.kl +++ b/redfsm/xmlparse.kl @@ -530,8 +530,6 @@ inline_item: tag_pchar final { $$->inlineItem = $1->inlineItem; }; inline_item: tag_char final { $$->inlineItem = $1->inlineItem; }; inline_item: tag_hold final { $$->inlineItem = $1->inlineItem; }; inline_item: tag_exec final { $$->inlineItem = $1->inlineItem; }; -inline_item: tag_holdte final { $$->inlineItem = $1->inlineItem; }; -inline_item: tag_execte final { $$->inlineItem = $1->inlineItem; }; inline_item: tag_curs final { $$->inlineItem = $1->inlineItem; }; inline_item: tag_targs final { $$->inlineItem = $1->inlineItem; }; inline_item: tag_il_entry final { $$->inlineItem = $1->inlineItem; }; @@ -557,8 +555,6 @@ nonterm tag_pchar uses inline_item_type; nonterm tag_char uses inline_item_type; nonterm tag_hold uses inline_item_type; nonterm tag_exec uses inline_item_type; -nonterm tag_holdte uses inline_item_type; -nonterm tag_execte uses inline_item_type; nonterm tag_curs uses inline_item_type; nonterm tag_targs uses inline_item_type; nonterm tag_il_entry uses inline_item_type; @@ -647,17 +643,6 @@ tag_exec: TAG_exec inline_list '/' TAG_exec $$->inlineItem->children = $2->inlineList; }; -tag_holdte: TAG_holdte '/' TAG_holdte - final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::HoldTE ); - }; - -tag_execte: TAG_execte inline_list '/' TAG_execte - final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::ExecTE ); - $$->inlineItem->children = $2->inlineList; - }; - tag_curs: TAG_curs '/' TAG_curs final { $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Curs ); diff --git a/redfsm/xmltags.gperf b/redfsm/xmltags.gperf index be4374e..85ad4be 100644 --- a/redfsm/xmltags.gperf +++ b/redfsm/xmltags.gperf @@ -57,8 +57,6 @@ pchar, TAG_pchar char, TAG_char hold, TAG_hold exec, TAG_exec -holdte, TAG_holdte -execte, TAG_execte curs, TAG_curs targs, TAG_targs entry, TAG_entry diff --git a/rlgen-cd/fsmcodegen.cpp b/rlgen-cd/fsmcodegen.cpp index 93a5150..1fbeba5 100644 --- a/rlgen-cd/fsmcodegen.cpp +++ b/rlgen-cd/fsmcodegen.cpp @@ -314,19 +314,6 @@ void FsmCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFini ret << "))-1;}"; } -void FsmCodeGen::EXECTE( ostream &ret, InlineItem *item, int targState, int inFinish ) -{ - /* Tokend version of exec. */ - - /* The parser gives fexec two children. The double brackets are for D - * code. If the inline list is a single word it will get interpreted as a - * C-style cast by the D compiler. */ - ret << "{" << TOKEND() << " = (("; - INLINE_LIST( ret, item->children, targState, inFinish ); - ret << "));}"; -} - - void FsmCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, int targState, int inFinish ) { @@ -431,12 +418,6 @@ void FsmCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, case InlineItem::Exec: EXEC( ret, item, targState, inFinish ); break; - case InlineItem::HoldTE: - ret << TOKEND() << "--;"; - break; - case InlineItem::ExecTE: - EXECTE( ret, item, targState, inFinish ); - break; case InlineItem::Curs: CURS( ret, inFinish ); break; diff --git a/rlgen-cd/fsmcodegen.h b/rlgen-cd/fsmcodegen.h index e0834fc..1bd0a24 100644 --- a/rlgen-cd/fsmcodegen.h +++ b/rlgen-cd/fsmcodegen.h @@ -139,7 +139,6 @@ protected: 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 ); - void EXECTE( ostream &ret, InlineItem *item, int targState, int inFinish ); void LM_SWITCH( ostream &ret, InlineItem *item, int targState, int inFinish ); void SET_ACT( ostream &ret, InlineItem *item ); void INIT_TOKSTART( ostream &ret, InlineItem *item ); diff --git a/rlgen-java/javacodegen.cpp b/rlgen-java/javacodegen.cpp index c941ea7..8dc4dca 100644 --- a/rlgen-java/javacodegen.cpp +++ b/rlgen-java/javacodegen.cpp @@ -119,18 +119,6 @@ void JavaTabCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int in ret << "))-1;}"; } -void JavaTabCodeGen::EXECTE( ostream &ret, InlineItem *item, int targState, int inFinish ) -{ - /* Tokend version of exec. */ - - /* The parser gives fexec two children. The double brackets are for D - * code. If the inline list is a single word it will get interpreted as a - * C-style cast by the D compiler. */ - ret << "{" << TOKEND() << " = (("; - INLINE_LIST( ret, item->children, targState, inFinish ); - ret << "));}"; -} - /* 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 JavaTabCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, @@ -165,12 +153,6 @@ void JavaTabCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, case InlineItem::Exec: EXEC( ret, item, targState, inFinish ); break; - case InlineItem::HoldTE: - ret << TOKEND() << "--;"; - break; - case InlineItem::ExecTE: - EXECTE( ret, item, targState, inFinish ); - break; case InlineItem::Curs: ret << "(_ps)"; break; diff --git a/rlgen-ruby/rubycodegen.cpp b/rlgen-ruby/rubycodegen.cpp index 1f68925..e91e63f 100644 --- a/rlgen-ruby/rubycodegen.cpp +++ b/rlgen-ruby/rubycodegen.cpp @@ -502,18 +502,6 @@ void RubyCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFin ret << "))-1; end\n"; } -void RubyCodeGen::EXECTE( ostream &ret, InlineItem *item, int targState, int inFinish ) -{ - /* Tokend version of exec. */ - - /* The parser gives fexec two children. The double brackets are for D - * code. If the inline list is a single word it will get interpreted as a - * C-style cast by the D compiler. */ - ret << " begin " << TOKEND() << " = (("; - INLINE_LIST( ret, item->children, targState, inFinish ); - ret << ")); end\n"; -} - /* 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 RubyCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, @@ -548,12 +536,6 @@ void RubyCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, case InlineItem::Exec: EXEC( ret, item, targState, inFinish ); break; - case InlineItem::HoldTE: - ret << TOKEND() << " = " << TOKEND() << " - 1;"; - break; - case InlineItem::ExecTE: - EXECTE( ret, item, targState, inFinish ); - break; case InlineItem::Curs: ret << "(_ps)"; break; -- 2.7.4