X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=ragel%2Fxmlcodegen.cpp;h=8cbe73875d5b0f6a548b8b18f9c0554a09117ae6;hb=6f464c641200198eb35dbfc2429fa0acda37c2a9;hp=a12c56bcc0fafccd3fd3afebce158673e2622d23;hpb=57cb26d46765f060331be6f86885e345e18c33c6;p=external%2Fragel.git diff --git a/ragel/xmlcodegen.cpp b/ragel/xmlcodegen.cpp index a12c56b..8cbe738 100644 --- a/ragel/xmlcodegen.cpp +++ b/ragel/xmlcodegen.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2005-2007 Adrian Thurston + * Copyright 2005-2007 Adrian Thurston */ /* This file is part of Ragel. @@ -175,6 +175,26 @@ void XMLCodeGen::writeTransList( StateAp *state ) out << " \n"; } +void XMLCodeGen::writeEofTrans( StateAp *state ) +{ + RedActionTable *eofActions = 0; + if ( state->eofActionTable.length() > 0 ) + eofActions = actionTableMap.find( state->eofActionTable ); + + /* The is used when there is an eof target, otherwise the eof + * action goes into state actions. */ + if ( state->eofTarget != 0 ) { + out << " " << state->eofTarget->alg.stateNum; + + if ( eofActions != 0 ) + out << " " << eofActions->id; + else + out << " x"; + + out << "" << endl; + } +} + void XMLCodeGen::writeText( InlineItem *item ) { if ( item->prev == 0 || item->prev->type != InlineItem::Text ) @@ -184,82 +204,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 ) -{ - if ( isLmItem( context ) ) { - out << ""; - out << ""; - } - - 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; - } - - if ( isLmItem( context ) ) - out << ""; -} - -void XMLCodeGen::writePtrMod( InlineItem *item, InlineItem *context ) -{ - if ( isLmItem( context ) ) { - switch ( item->type ) { - case InlineItem::Hold: - out << ""; - break; - case InlineItem::Exec: - writeActionExecTE( item ); - break; - default: break; - } - } - else { - 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"; @@ -269,7 +214,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"; @@ -279,7 +224,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"; @@ -289,28 +234,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"; @@ -323,83 +268,118 @@ 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 << ""; } - out << ""; } void XMLCodeGen::writeLmOnNext( InlineItem *item ) { out << "0"; + out << ""; + if ( item->longestMatchPart->action != 0 ) { out << ""; - writeInlineList( item->longestMatchPart->action->inlineList, item ); + writeInlineList( item->longestMatchPart->action->inlineList ); out << ""; } - out << ""; } void XMLCodeGen::writeLmOnLagBehind( InlineItem *item ) { + out << ""; + if ( item->longestMatchPart->action != 0 ) { out << ""; - writeInlineList( item->longestMatchPart->action->inlineList, item ); + writeInlineList( item->longestMatchPart->action->inlineList ); out << ""; } - out << ""; } void XMLCodeGen::writeLmSwitch( InlineItem *item ) { LongestMatch *longestMatch = item->longestMatch; + out << "\n"; + + /* We can't put the here because we may need to handle the error + * case and in that case p should not be changed. Instead use a default + * label in the switch to adjust p when user actions are not set. An id of + * -1 indicates the default. */ - out << "lmSwitchHandlesError ) - out << " handles_error=\"t\""; - out << ">\n"; + if ( longestMatch->lmSwitchHandlesError ) { + /* If the switch handles error then we should have also forced the + * error state. */ + assert( fsm->errState != 0 ); + + out << " "; + out << "" << fsm->errState->alg.stateNum << ""; + out << "\n"; + } + bool needDefault = false; for ( LmPartList::Iter lmi = *longestMatch->longestMatchList; lmi.lte(); lmi++ ) { - if ( lmi->inLmSelect && lmi->action != 0 ) { - /* Open the action. Write it with the context that sets up _p - * when doing control flow changes from inside the machine. */ - out << " longestMatchId << "\">"; - writeInlineList( lmi->action->inlineList, item ); - out << "\n"; + if ( lmi->inLmSelect ) { + if ( lmi->action == 0 ) + needDefault = true; + else { + /* Open the action. Write it with the context that sets up _p + * when doing control flow changes from inside the machine. */ + out << " longestMatchId << "\">"; + out << ""; + writeInlineList( lmi->action->inlineList ); + out << "\n"; + } } } - out << " "; + if ( needDefault ) { + out << " " + "\n"; + } + + 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 << ""; @@ -418,8 +398,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: @@ -463,7 +445,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"; } @@ -491,8 +473,10 @@ void XMLCodeGen::writeStateActions( StateAp *state ) if ( state->fromStateActionTable.length() > 0 ) fromStateActions = actionTableMap.find( state->fromStateActionTable ); + /* EOF actions go out here only if the state has no eof target. If it has + * an eof target then an eof transition will be used instead. */ RedActionTable *eofActions = 0; - if ( state->eofActionTable.length() > 0 ) + if ( state->eofTarget == 0 && state->eofActionTable.length() > 0 ) eofActions = actionTableMap.find( state->eofActionTable ); if ( toStateActions != 0 || fromStateActions != 0 || eofActions != 0 ) { @@ -510,7 +494,9 @@ void XMLCodeGen::writeStateActions( StateAp *state ) if ( eofActions != 0 ) out << " " << eofActions->id; else - out << " x"; out << "\n"; + out << " x"; + + out << "\n"; } } @@ -542,6 +528,7 @@ void XMLCodeGen::writeStateList() out << ">\n"; writeStateActions( st ); + writeEofTrans( st ); writeStateConditions( st ); writeTransList( st ); @@ -662,69 +649,95 @@ 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"; } + /* PrePush expression. */ + if ( pd->prePushExpr != 0 ) { + out << " "; + writeInlineList( pd->prePushExpr ); + out << "\n"; + } + + /* PostPop expression. */ + if ( pd->postPopExpr != 0 ) { + out << " "; + writeInlineList( pd->postPopExpr ); + out << "\n"; + } + /* * Variable expressions. */ 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->eofExpr != 0 ) { + out << " "; + writeInlineList( pd->eofExpr ); + 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"; } + if ( pd->dataExpr != 0 ) { + out << " "; + writeInlineList( pd->dataExpr ); + out << "\n"; + } + writeExports(); writeMachine();