X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=ragel%2Fxmlcodegen.cpp;h=8cbe73875d5b0f6a548b8b18f9c0554a09117ae6;hb=6f464c641200198eb35dbfc2429fa0acda37c2a9;hp=021c97e87de931afab50cbc533725b8dfc42e205;hpb=8f952684e88b2e64103c5215bd1e7cf3c7bc0ac7;p=external%2Fragel.git diff --git a/ragel/xmlcodegen.cpp b/ragel/xmlcodegen.cpp index 021c97e..8cbe738 100644 --- a/ragel/xmlcodegen.cpp +++ b/ragel/xmlcodegen.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2005, 2006 Adrian Thurston + * Copyright 2005-2007 Adrian Thurston */ /* This file is part of Ragel. @@ -175,26 +175,24 @@ void XMLCodeGen::writeTransList( StateAp *state ) out << " \n"; } -void XMLCodeGen::writeLmSwitch( InlineItem *item ) +void XMLCodeGen::writeEofTrans( StateAp *state ) { - LongestMatch *longestMatch = item->longestMatch; - - out << "lmSwitchHandlesError ) - out << " handles_error=\"t\""; - out << ">\n"; + RedActionTable *eofActions = 0; + if ( state->eofActionTable.length() > 0 ) + eofActions = actionTableMap.find( state->eofActionTable ); - 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"; - } - } + /* 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; - out << " "; + if ( eofActions != 0 ) + out << " " << eofActions->id; + else + out << " x"; + + out << "" << endl; + } } void XMLCodeGen::writeText( InlineItem *item ) @@ -206,91 +204,7 @@ void XMLCodeGen::writeText( InlineItem *item ) out << ""; } -void XMLCodeGen::writeCtrlFlow( InlineItem *item, InlineItem *context ) -{ - if ( context != 0 ) { - out << ""; - - switch ( context->type ) { - case InlineItem::LmOnLast: - out << ""; - break; - case InlineItem::LmOnNext: - out << ""; - break; - case InlineItem::LmOnLagBehind: - out << ""; - break; - case InlineItem::LmSwitch: - out << ""; - break; - default: break; - } - } - - 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 ( context != 0 ) - out << ""; -} - -void XMLCodeGen::writePtrMod( InlineItem *item, InlineItem *context ) -{ - if ( context != 0 && ( context->type == InlineItem::LmOnNext || - context->type == InlineItem::LmOnLagBehind || - context->type == InlineItem::LmSwitch ) ) - { - 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"; @@ -300,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"; @@ -310,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"; @@ -320,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"; @@ -354,62 +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. */ -void XMLCodeGen::writeInlineList( InlineList *inlineList, InlineItem *context ) + 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 ) { + 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"; + } + } + } + + if ( needDefault ) { + out << " " + "\n"; + } + + out << " "; +} + +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 << ""; @@ -428,13 +398,12 @@ void XMLCodeGen::writeInlineList( InlineList *inlineList, InlineItem *context ) break; case InlineItem::Hold: + out << ""; + break; case InlineItem::Exec: - writePtrMod( item, context ); + writeActionExec( item ); break; - case InlineItem::LmSwitch: - writeLmSwitch( item ); - break; case InlineItem::LmSetActId: out << "" << item->longestMatchPart->longestMatchId << @@ -443,6 +412,7 @@ void XMLCodeGen::writeInlineList( InlineList *inlineList, InlineItem *context ) case InlineItem::LmSetTokEnd: out << "1"; break; + case InlineItem::LmOnLast: writeLmOnLast( item ); break; @@ -452,6 +422,10 @@ void XMLCodeGen::writeInlineList( InlineList *inlineList, InlineItem *context ) case InlineItem::LmOnLagBehind: writeLmOnLagBehind( item ); break; + case InlineItem::LmSwitch: + writeLmSwitch( item ); + break; + case InlineItem::LmInitAct: out << ""; break; @@ -471,11 +445,11 @@ 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"; } -void xmlEscapeHost( std::ostream &out, char *data, int len ) +void xmlEscapeHost( std::ostream &out, char *data, long len ) { char *end = data + len; while ( data != end ) { @@ -499,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 ) { @@ -518,7 +494,9 @@ void XMLCodeGen::writeStateActions( StateAp *state ) if ( eofActions != 0 ) out << " " << eofActions->id; else - out << " x"; out << "\n"; + out << " x"; + + out << "\n"; } } @@ -550,6 +528,7 @@ void XMLCodeGen::writeStateList() out << ">\n"; writeStateActions( st ); + writeEofTrans( st ); writeStateConditions( st ); writeTransList( st ); @@ -610,11 +589,8 @@ void XMLCodeGen::writeMachine() writeConditions(); /* Start state. */ - GraphDictEl *mainEl = pd->graphDict.find( mainMachine ); - if ( mainEl != 0 ) { - out << " " << fsm->startState->alg.stateNum << + out << " " << fsm->startState->alg.stateNum << "\n"; - } /* Error state. */ if ( fsm->errState != 0 ) { @@ -628,32 +604,6 @@ void XMLCodeGen::writeMachine() out << " \n"; } -void XMLCodeGen::writeAlphType() -{ - out << " " << - (keyOps->alphType - hostLang->hostTypes) << "\n"; -} - -void XMLCodeGen::writeGetKeyExpr() -{ - out << " "; - writeInlineList( pd->getKeyExpr, 0 ); - out << "\n"; -} - -void XMLCodeGen::writeAccessExpr() -{ - out << " "; - writeInlineList( pd->accessExpr, 0 ); - out << "\n"; -} - -void XMLCodeGen::writeCurStateExpr() -{ - out << " "; - writeInlineList( pd->curStateExpr, 0 ); - out << "\n"; -} void XMLCodeGen::writeConditions() { @@ -692,16 +642,101 @@ void XMLCodeGen::writeXML() { /* Open the definition. */ out << "\n"; - writeAlphType(); + + /* Alphabet type. */ + out << " " << keyOps->alphType->internalName << "\n"; - if ( pd->getKeyExpr != 0 ) - writeGetKeyExpr(); + /* Getkey expression. */ + if ( pd->getKeyExpr != 0 ) { + out << " "; + writeInlineList( pd->getKeyExpr ); + out << "\n"; + } - if ( pd->accessExpr != 0 ) - writeAccessExpr(); + /* Access expression. */ + if ( pd->accessExpr != 0 ) { + out << " "; + 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 ); + out << "\n"; + } + + if ( pd->peExpr != 0 ) { + out << " "; + writeInlineList( pd->peExpr ); + out << "\n"; + } - if ( pd->curStateExpr != 0 ) - writeCurStateExpr(); + if ( pd->eofExpr != 0 ) { + out << " "; + writeInlineList( pd->eofExpr ); + out << "\n"; + } + + if ( pd->csExpr != 0 ) { + out << " "; + writeInlineList( pd->csExpr ); + out << "\n"; + } + + if ( pd->topExpr != 0 ) { + out << " "; + writeInlineList( pd->topExpr ); + out << "\n"; + } + + if ( pd->stackExpr != 0 ) { + out << " "; + writeInlineList( pd->stackExpr ); + out << "\n"; + } + + if ( pd->actExpr != 0 ) { + out << " "; + writeInlineList( pd->actExpr ); + out << "\n"; + } + + if ( pd->tokstartExpr != 0 ) { + out << " "; + writeInlineList( pd->tokstartExpr ); + out << "\n"; + } + + if ( pd->tokendExpr != 0 ) { + out << " "; + writeInlineList( pd->tokendExpr ); + out << "\n"; + } + + if ( pd->dataExpr != 0 ) { + out << " "; + writeInlineList( pd->dataExpr ); + out << "\n"; + } writeExports();