"Fossies" - the Fresh Open Source Software Archive  

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

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

goto.cc  (ragel-7.0.0.10):goto.cc  (ragel-7.0.0.11)
/* /*
* Copyright 2001-2014 Adrian Thurston <thurston@colm.net> * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the * deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is * sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in al l * The above copyright notice and this permission notice shall be included in al l
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
skipping to change at line 33 skipping to change at line 33
#include "ragel.h" #include "ragel.h"
#include "goto.h" #include "goto.h"
#include "redfsm.h" #include "redfsm.h"
#include "bstmap.h" #include "bstmap.h"
#include "gendata.h" #include "gendata.h"
#include <sstream> #include <sstream>
using std::ostringstream; using std::ostringstream;
Goto::Goto( const CodeGenArgs &args )
:
CodeGen( args ),
actions( "actions", *this ),
toStateActions( "to_state_actions", *this ),
fromStateActions( "from_state_actions", *this ),
eofActions( "eof_actions", *this ),
nfaTargs( "nfa_targs", *this ),
nfaOffsets( "nfa_offsets", *this ),
nfaPushActions( "nfa_push_actions", *this ),
nfaPopTrans( "nfa_pop_trans", *this )
{}
void Goto::setTableState( TableArray::State state ) void Goto::setTableState( TableArray::State state )
{ {
for ( ArrayVector::Iter i = arrayVector; i.lte(); i++ ) { for ( ArrayVector::Iter i = arrayVector; i.lte(); i++ ) {
TableArray *tableArray = *i; TableArray *tableArray = *i;
tableArray->setState( state ); tableArray->setState( state );
} }
} }
/* Emit the goto to take for a given transition. */ /* Emit the goto to take for a given transition. */
std::ostream &Goto::COND_GOTO( RedCondPair *cond, int level ) std::ostream &Goto::COND_GOTO( RedCondPair *cond, int level )
skipping to change at line 110 skipping to change at line 97
/* Write out the length, which will never be the last character. */ /* Write out the length, which will never be the last character. */
actions.value( act->key.length() ); actions.value( act->key.length() );
for ( GenActionTable::Iter item = act->key; item.lte(); item++ ) for ( GenActionTable::Iter item = act->key; item.lte(); item++ )
actions.value( item->value->actionId ); actions.value( item->value->actionId );
} }
actions.finish(); actions.finish();
} }
void Goto::NFA_PUSH()
{
if ( redFsm->anyNfaStates() ) {
out <<
" if ( " << ARR_REF( nfaOffsets ) << "[" << vCS() <
< "] ) {\n"
" int alt = 0; \n"
" int new_recs = " << ARR_REF( nfaTargs ) <
< "[" << CAST("int") <<
ARR_REF( nfaOffsets ) << "[" << v
CS() << "]];\n";
if ( red->nfaPrePushExpr != 0 ) {
out << OPEN_HOST_BLOCK( red->nfaPrePushExpr );
INLINE_LIST( out, red->nfaPrePushExpr->inlineList, 0, fal
se, false );
out << CLOSE_HOST_BLOCK();
}
out <<
" while ( alt < new_recs ) { \n";
out <<
" nfa_bp[nfa_len].state = " << ARR_
REF( nfaTargs ) << "[" << CAST("int") <<
ARR_REF( nfaOffsets ) <<
"[" << vCS() << "] + 1 + alt];\n"
" nfa_bp[nfa_len].p = " << P() << "
;\n";
if ( redFsm->bAnyNfaPops ) {
out <<
" nfa_bp[nfa_len].popTrans
= " << CAST("long") <<
ARR_REF( nfaOffse
ts ) << "[" << vCS() << "] + 1 + alt;\n"
"\n"
;
}
if ( redFsm->bAnyNfaPushes ) {
out <<
" switch ( " << ARR_REF( nf
aPushActions ) << "[" << CAST("int") <<
ARR_REF( nfaOffse
ts ) << "[" << vCS() << "] + 1 + alt] ) {\n";
/* Loop the actions. */
for ( GenActionTableMap::Iter redAct = redFsm->actionMap;
redAct.lte(); redAct++ )
{
if ( redAct->numNfaPushRefs > 0 ) {
/* Write the entry label. */
out << "\t " << CASE( STR( redAct->actLis
tId+1 ) ) << " {\n";
/* Write each action in the list of actio
n items. */
for ( GenActionTable::Iter item = redAct-
>key; item.lte(); item++ )
ACTION( out, item->value, IlOpts(
0, false, false ) );
out << "\n\t" << CEND() << "}\n";
}
}
out <<
" }\n";
}
out <<
" nfa_len += 1;\n"
" alt += 1;\n"
" }\n"
" }\n"
;
}
}
void Goto::NFA_POP() void Goto::NFA_POP()
{ {
if ( redFsm->anyNfaStates() ) { if ( redFsm->anyNfaStates() ) {
out << out <<
" if ( nfa_len > 0 ) {\n"; " if ( nfa_len > 0 ) {\n";
if ( redFsm->bAnyNfaCondRefs ) if ( redFsm->bAnyNfaCondRefs )
out << " int _cpc;\n"; out << " int " << cpc << ";\n";
out << out <<
" nfa_count += 1;\n" " nfa_count += 1;\n"
" nfa_len -= 1;\n" " nfa_len -= 1;\n"
" " << P() << " = nfa_bp[nfa_len].p;\n" " " << P() << " = nfa_bp[nfa_len].p;\n"
; ;
if ( redFsm->bAnyNfaPops ) { if ( redFsm->bAnyNfaPops ) {
out << out <<
" int _pop_test = 1;\n" " int _pop_test = 1;\n"
skipping to change at line 906 skipping to change at line 828
{ {
outLabelUsed = true; outLabelUsed = true;
ret << OPEN_GEN_BLOCK() << P() << " += 1; " << "goto _out; " << CLOSE_GEN _BLOCK(); ret << OPEN_GEN_BLOCK() << P() << " += 1; " << "goto _out; " << CLOSE_GEN _BLOCK();
} }
void Goto::NBREAK( ostream &ret, int targState, bool csForced ) void Goto::NBREAK( ostream &ret, int targState, bool csForced )
{ {
outLabelUsed = true; outLabelUsed = true;
ret << OPEN_GEN_BLOCK() << P() << " += 1; " << " _nbreak = 1; " << CLOSE_ GEN_BLOCK(); ret << OPEN_GEN_BLOCK() << P() << " += 1; " << " _nbreak = 1; " << CLOSE_ GEN_BLOCK();
} }
void Goto::tableDataPass()
{
if ( type == Loop )
taActions();
taToStateActions();
taFromStateActions();
taEofActions();
taNfaTargs();
taNfaOffsets();
taNfaPushActions();
taNfaPopTrans();
}
void Goto::genAnalysis()
{
/* For directly executable machines there is no required state
* ordering. Choose a depth-first ordering to increase the
* potential for fall-throughs. */
redFsm->depthFirstOrdering();
/* Choose default transitions and the single transition. */
redFsm->chooseDefaultSpan();
/* Choose single. */
redFsm->moveSelectTransToSingle();
/* If any errors have occured in the input file then don't write anything
. */
if ( red->id->errorCount > 0 )
return;
/* Anlayze Machine will find the final action reference counts, among oth
er
* things. We will use these in reporting the usage of fsm directives in
* action code. */
red->analyzeMachine();
/* Run the analysis pass over the table data. */
setTableState( TableArray::AnalyzePass );
tableDataPass();
/* Switch the tables over to the code gen mode. */
setTableState( TableArray::GeneratePass );
}
void Goto::writeData()
{
if ( type == Loop ) {
if ( redFsm->anyActions() )
taActions();
}
if ( redFsm->anyToStateActions() )
taToStateActions();
if ( redFsm->anyFromStateActions() )
taFromStateActions();
if ( redFsm->anyEofActions() )
taEofActions();
taNfaTargs();
taNfaOffsets();
taNfaPushActions();
taNfaPopTrans();
STATE_IDS();
}
void Goto::writeExec()
{
testEofUsed = false;
outLabelUsed = false;
out << " {\n";
if ( type == Loop ) {
if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
|| redFsm->anyFromStateActions() )
{
out <<
" " << INDEX( ARR_TYPE( actions ), "" + str
ing(acts) + "" ) << ";\n"
" " << UINT() << " " << nacts << ";\n";
}
}
if ( redFsm->anyRegCurStateRef() )
out << " int _ps = 0;\n";
out << "\n";
if ( redFsm->anyRegNbreak() ) {
out << " int _nbreak;\n";
}
if ( !noEnd ) {
testEofUsed = true;
out <<
" if ( " << P() << " == " << PE() << " )\n"
" goto _test_eof;\n";
}
if ( redFsm->errState != 0 ) {
outLabelUsed = true;
out <<
" if ( " << vCS() << " == " << redFsm->errState->id
<< " )\n"
" goto _out;\n";
}
out << "_resume:\n";
FROM_STATE_ACTIONS();
NFA_PUSH( vCS() );
out <<
" switch ( " << vCS() << " ) {\n";
STATE_GOTOS() <<
" }\n"
"\n";
TRANSITIONS() <<
"\n";
if ( redFsm->anyRegActions() )
EXEC_FUNCS() << "\n";
out << "_again:\n";
TO_STATE_ACTIONS();
if ( redFsm->errState != 0 ) {
outLabelUsed = true;
out <<
" if ( " << vCS() << " == " << redFsm->errState->id
<< " )\n"
" goto _out;\n";
}
if ( !noEnd ) {
out <<
" " << P() << " += 1;\n"
" if ( " << P() << " != " << PE() << " )\n"
" goto _resume;\n";
}
else {
out <<
" " << P() << " += 1;\n"
" goto _resume;\n";
}
if ( testEofUsed )
out << " _test_eof: {}\n";
if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
out <<
" if ( " << P() << " == " << vEOF() << " )\n"
" {\n";
NFA_PUSH( vCS() );
out <<
" switch ( " << vCS() << " ) {\n";
bool okeydokey = false;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
{
if ( st->outCondSpace != 0 ) {
out << " case " << st->id << ": {\n";
out << "int ck = 0;\n";
for ( GenCondSet::Iter csi = st->outCondSpace->co
ndSet; csi.lte(); csi++ ) {
out << "if ( ";
CONDITION( out, *csi );
Size condValOffset = (1 << csi.pos());
out << " ) ck += " << condValOffset << ";
\n";
}
out << " switch ( ck ) {\n";
for ( CondKeySet::Iter k = st->outCondKeys; k.lte
(); k++ ) {
out << "case " << *k << ": goto _okeydoke
y;\n";
okeydokey = true;
}
out << "}\n";
out << vCS() << " = " << ERROR_STATE() << ";\n";
out << "goto _out;\n";
out << "}\n";
}
}
out <<
" }\n";
if ( okeydokey ) {
out <<
"_okeydokey: {}\n";
}
EOF_ACTIONS();
if ( redFsm->anyEofTrans() ) {
out <<
" switch ( " << vCS() << " ) {\n";
for ( RedStateList::Iter st = redFsm->stateList; st.lte()
; st++ ) {
if ( st->eofTrans != 0 ) {
RedCondPair *cond = st->eofTrans->outCond
( 0 );
out << " case " << st->id << ": go
to ctr" << cond->id << ";\n";
}
}
out <<
" }\n";
}
out <<
" }\n"
"\n";
}
if ( outLabelUsed )
out << " _out: {}\n";
NFA_POP();
out << " }\n";
}
 End of changes. 5 change blocks. 
95 lines changed or deleted 2 lines changed or added

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