"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/fsmnfa.cc" between
ragel-7.0.0.11.tar.gz and ragel-7.0.0.12.tar.gz

About: Ragel compiles executable finite state machines from regular languages (C, C++, Obj-C, C#, D, Java, Go and Ruby). Development version.

fsmnfa.cc  (ragel-7.0.0.11):fsmnfa.cc  (ragel-7.0.0.12)
skipping to change at line 132 skipping to change at line 132
} }
/* /*
* WRT action ordering. * WRT action ordering.
* *
* All the pop restore actions get an ordering of -2 to cause them to always * All the pop restore actions get an ordering of -2 to cause them to always
* execute first. This is the action that restores the state and we need that * execute first. This is the action that restores the state and we need that
* to happen before any user actions. * to happen before any user actions.
*/ */
const int ORD_PUSH = 0; const int ORD_PUSH = 0;
const int ORD_RESTORE = -2; const int ORD_RESTORE = -3;
const int ORD_COND = -1; const int ORD_COND = -1;
const int ORD_COND2 = -2;
const int ORD_TEST = 1073741824; const int ORD_TEST = 1073741824;
void FsmAp::transferOutToNfaTrans( NfaTrans *trans, StateAp *state ) void FsmAp::transferOutToNfaTrans( NfaTrans *trans, StateAp *state )
{ {
trans->popAction.setActions( state->outActionTable ); trans->popFrom = state->fromStateActionTable;
trans->popCondSpace = state->outCondSpace; trans->popCondSpace = state->outCondSpace;
trans->popCondKeys = state->outCondKeys; trans->popCondKeys = state->outCondKeys;
trans->priorTable.setPriors( state->outPriorTable ); trans->priorTable.setPriors( state->outPriorTable );
trans->popAction.setActions( state->outActionTable );
}
FsmRes FsmAp::nfaWrap( FsmAp *fsm, Action *push, Action *pop, Action *init,
Action *stay, Action *exit, NfaRepeatMode mode )
{
/*
* First Concat.
*/
StateSet origFinals = fsm->finStateSet;
/* Get the orig start state. */
StateAp *origStartState = fsm->startState;
/* New start state. */
StateAp *newStart = fsm->addState();
newStart->nfaOut = new NfaTransList;
const int orderInit = 0;
const int orderStay = mode == NfaGreedy ? 3 : 1;
const int orderExit = mode == NfaGreedy ? 1 : 3;
NfaTrans *trans;
if ( init ) {
/* Transition into the repetition. Doesn't make much sense to fli
p this
* statically false, but provided for consistency of interface. A
llows
* an init so we can have only local state manipulation. */
trans = new NfaTrans( orderInit );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, init );
newStart->nfaOut->append( trans );
fsm->attachToNfa( newStart, origStartState, trans );
}
StateAp *newFinal = fsm->addState();
for ( StateSet::Iter orig = origFinals; orig.lte(); orig++ ) {
/* For every final state, we place a new final state in front of
it,
* with an NFA transition to the original. This is the "stay" cho
ice. */
StateAp *repl = fsm->addState();
fsm->moveInwardTrans( repl, *orig );
repl->nfaOut = new NfaTransList;
if ( stay != 0 ) {
/* Transition to original final state. Represents staying
. */
trans = new NfaTrans( orderStay );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, stay );
repl->nfaOut->append( trans );
fsm->attachToNfa( repl, *orig, trans );
}
if ( exit != 0 ) {
/* Transition to thew new final. Represents exiting. */
trans = new NfaTrans( orderExit );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, exit );
fsm->transferOutToNfaTrans( trans, *orig );
repl->fromStateActionTable.setActions( (*orig)->fromState
ActionTable );
repl->nfaOut->append( trans );
fsm->attachToNfa( repl, newFinal, trans );
}
fsm->unsetFinState( *orig );
}
fsm->unsetStartState();
fsm->setStartState( newStart );
fsm->setFinState( newFinal );
return FsmRes( FsmRes::Fsm(), fsm );
}
FsmRes FsmAp::nfaRepeatOp2( FsmAp *fsm, Action *push, Action *pop, Action *init,
Action *stay, Action *repeat, Action *exit, NfaRepeatMode mode )
{
/*
* First Concat.
*/
StateSet origFinals = fsm->finStateSet;
/* Get the orig start state. */
StateAp *origStartState = fsm->startState;
StateAp *repStartState = fsm->dupStartState();
/* New start state. */
StateAp *newStart1 = fsm->addState();
StateAp *newStart2 = fsm->addState();
newStart1->nfaOut = new NfaTransList;
newStart2->nfaOut = new NfaTransList;
const int orderInit = 0;
const int orderStay = mode == NfaGreedy ? 3 : 1;
const int orderRepeat = mode == NfaGreedy ? 2 : 2;
const int orderExit = mode == NfaGreedy ? 1 : 3;
NfaTrans *trans;
if ( init ) {
/* Transition into the repetition. Doesn't make much sense to fli
p this
* statically false, but provided for consistency of interface. A
llows
* an init so we can have only local state manipulation. */
trans = new NfaTrans( orderInit );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, init );
newStart1->nfaOut->append( trans );
fsm->attachToNfa( newStart1, newStart2, trans );
}
StateAp *newFinal = fsm->addState();
if ( exit ) {
trans = new NfaTrans( orderExit );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, exit );
newStart2->nfaOut->append( trans );
fsm->attachToNfa( newStart1, newFinal, trans );
}
if ( repeat ) {
trans = new NfaTrans( orderRepeat );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, repeat );
newStart2->nfaOut->append( trans );
fsm->attachToNfa( newStart1, origStartState, trans );
}
for ( StateSet::Iter orig = origFinals; orig.lte(); orig++ ) {
/* For every final state, we place a new final state in front of
it,
* with an NFA transition to the original. This is the "stay" cho
ice. */
StateAp *repl = fsm->addState();
fsm->moveInwardTrans( repl, *orig );
repl->nfaOut = new NfaTransList;
if ( stay != 0 ) {
/* Transition to original final state. Represents staying
. */
trans = new NfaTrans( orderStay );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, stay );
repl->nfaOut->append( trans );
fsm->attachToNfa( repl, *orig, trans );
}
/* Transition back to the start. Represents repeat. */
if ( repeat != 0 ) {
trans = new NfaTrans( orderRepeat );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, repeat );
fsm->transferOutToNfaTrans( trans, *orig );
repl->fromStateActionTable.setActions( (*orig)->fromState
ActionTable );
repl->nfaOut->append( trans );
fsm->attachToNfa( repl, repStartState, trans );
}
if ( exit != 0 ) {
/* Transition to thew new final. Represents exiting. */
trans = new NfaTrans( orderExit );
trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, exit );
fsm->transferOutToNfaTrans( trans, *orig );
repl->fromStateActionTable.setActions( (*orig)->fromState
ActionTable );
repl->nfaOut->append( trans );
fsm->attachToNfa( repl, newFinal, trans );
}
fsm->unsetFinState( *orig );
}
fsm->unsetStartState();
fsm->setStartState( newStart1 );
fsm->setFinState( newFinal );
return FsmRes( FsmRes::Fsm(), fsm );
} }
/* This version contains the init, increment and test in the nfa pop actions. /* This version contains the init, increment and test in the nfa pop actions.
* This is a compositional operator since it doesn't leave any actions to * This is a compositional operator since it doesn't leave any actions to
* trailing characters, where they may interact with other actions that use the * trailing characters, where they may interact with other actions that use the
* same variables. */ * same variables. */
FsmRes FsmAp::nfaRepeatOp( FsmAp *fsm, Action *push, Action *pop, Action *init, FsmRes FsmAp::nfaRepeatOp( FsmAp *fsm, Action *push, Action *pop, Action *init,
Action *stay, Action *repeat, Action *exit ) Action *stay, Action *repeat, Action *exit )
{ {
/* /*
skipping to change at line 168 skipping to change at line 375
StateAp *repStartState = fsm->dupStartState(); StateAp *repStartState = fsm->dupStartState();
/* New start state. */ /* New start state. */
StateAp *newStart = fsm->addState(); StateAp *newStart = fsm->addState();
newStart->nfaOut = new NfaTransList; newStart->nfaOut = new NfaTransList;
NfaTrans *trans; NfaTrans *trans;
if ( init ) { if ( init ) {
/* Transition into the repetition. Doesn't make much sense to fli p this /* Transition into the repetition. Doesn't make much sense to fli p this
* statically false, but provided for consistency of interface. * * statically false, but provided for consistency of interface. A
/ llows
* an init so we can have only local state manipulation. */
trans = new NfaTrans( 1 ); trans = new NfaTrans( 1 );
trans->pushTable.setAction( ORD_PUSH, push ); trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop ); trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, init ); trans->popTest.setAction( ORD_TEST, init );
newStart->nfaOut->append( trans ); newStart->nfaOut->append( trans );
fsm->attachToNfa( newStart, origStartState, trans ); fsm->attachToNfa( newStart, origStartState, trans );
} }
StateAp *newFinal = fsm->addState(); StateAp *newFinal = fsm->addState();
for ( StateSet::Iter orig = origFinals; orig.lte(); orig++ ) { for ( StateSet::Iter orig = origFinals; orig.lte(); orig++ ) {
/* For every final state, we place a new final state in front of it, /* For every final state, we place a new final state in front of it,
* with an NFA transition to the original. This is the "stay" cho ice. */ * with an NFA transition to the original. This is the "stay" cho ice. */
StateAp *repl = fsm->addState(); StateAp *repl = fsm->addState();
fsm->moveInwardTrans( repl, *orig ); fsm->moveInwardTrans( repl, *orig );
repl->nfaOut = new NfaTransList; repl->nfaOut = new NfaTransList;
const int orderStay = 3;
const int orderRepeat = 2;
const int orderExit = 1;
if ( stay != 0 ) { if ( stay != 0 ) {
/* Transition to original final state. Represents staying . */ /* Transition to original final state. Represents staying . */
trans = new NfaTrans( 3 ); trans = new NfaTrans( orderStay );
trans->pushTable.setAction( ORD_PUSH, push ); trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop ); trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, stay ); trans->popTest.setAction( ORD_TEST, stay );
repl->nfaOut->append( trans ); repl->nfaOut->append( trans );
fsm->attachToNfa( repl, *orig, trans ); fsm->attachToNfa( repl, *orig, trans );
} }
/* Transition back to the start. Represents repeat. */ /* Transition back to the start. Represents repeat. */
if ( repeat != 0 ) { if ( repeat != 0 ) {
trans = new NfaTrans( 2 ); trans = new NfaTrans( orderRepeat );
trans->pushTable.setAction( ORD_PUSH, push ); trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop ); trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, repeat ); trans->popTest.setAction( ORD_TEST, repeat );
fsm->transferOutToNfaTrans( trans, *orig ); fsm->transferOutToNfaTrans( trans, *orig );
repl->fromStateActionTable.setActions( (*orig)->fromState ActionTable ); repl->fromStateActionTable.setActions( (*orig)->fromState ActionTable );
repl->nfaOut->append( trans ); repl->nfaOut->append( trans );
fsm->attachToNfa( repl, repStartState, trans ); fsm->attachToNfa( repl, repStartState, trans );
} }
if ( exit != 0 ) { if ( exit != 0 ) {
/* Transition to thew new final. Represents exiting. */ /* Transition to thew new final. Represents exiting. */
trans = new NfaTrans( 1 ); trans = new NfaTrans( orderExit );
trans->pushTable.setAction( ORD_PUSH, push ); trans->pushTable.setAction( ORD_PUSH, push );
trans->restoreTable.setAction( ORD_RESTORE, pop ); trans->restoreTable.setAction( ORD_RESTORE, pop );
trans->popTest.setAction( ORD_TEST, exit ); trans->popTest.setAction( ORD_TEST, exit );
fsm->transferOutToNfaTrans( trans, *orig ); fsm->transferOutToNfaTrans( trans, *orig );
repl->fromStateActionTable.setActions( (*orig)->fromState ActionTable ); repl->fromStateActionTable.setActions( (*orig)->fromState ActionTable );
repl->nfaOut->append( trans ); repl->nfaOut->append( trans );
fsm->attachToNfa( repl, newFinal, trans ); fsm->attachToNfa( repl, newFinal, trans );
skipping to change at line 380 skipping to change at line 592
if ( fsm->ctx->printStatistics ) { if ( fsm->ctx->printStatistics ) {
stats << "post-min\t" << fsm->stateList.length() << std:: endl; stats << "post-min\t" << fsm->stateList.length() << std:: endl;
stats << std::endl; stats << std::endl;
} }
} }
return FsmRes( FsmRes::Fsm(), fsm ); return FsmRes( FsmRes::Fsm(), fsm );
} }
FsmRes FsmAp::nfaUnion( const NfaRoundVect &roundsList, FsmAp **machines, int nu FsmRes FsmAp::nfaUnion( const NfaRoundVect &roundsList,
mMachines, std::ostream &stats, bool printStatistics ) FsmAp **machines, int numMachines,
std::ostream &stats, bool printStatistics )
{ {
long sumPlain = 0, sumMin = 0; long sumPlain = 0, sumMin = 0;
for ( int i = 0; i < numMachines; i++ ) { for ( int i = 0; i < numMachines; i++ ) {
sumPlain += machines[i]->stateList.length(); sumPlain += machines[i]->stateList.length();
machines[i]->removeUnreachableStates(); machines[i]->removeUnreachableStates();
machines[i]->minimizePartition2(); machines[i]->minimizePartition2();
sumMin += machines[i]->stateList.length(); sumMin += machines[i]->stateList.length();
} }
 End of changes. 10 change blocks. 
9 lines changed or deleted 235 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)