"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/tabgoto.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.

tabgoto.cc  (ragel-7.0.0.11):tabgoto.cc  (ragel-7.0.0.12)
skipping to change at line 27 skipping to change at line 27
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
#include "tables.h" #include "tables.h"
#include "binary.h" #include "binary.h"
#include "flat.h" #include "flat.h"
void TabGoto::CONTROL_JUMP( ostream &ret, bool inFinish )
{
ret << "goto " << _again << ";";
}
void TabGoto::GOTO( ostream &ret, int gotoDest, bool inFinish ) void TabGoto::GOTO( ostream &ret, int gotoDest, bool inFinish )
{ {
ret << OPEN_GEN_BLOCK() << vCS() << " = " << gotoDest << ";"; ret << OPEN_GEN_BLOCK() << vCS() << " = " << gotoDest << ";";
CONTROL_JUMP( ret, inFinish );
if ( inFinish && !noEnd )
EOF_CHECK( ret );
ret << "goto _again;";
ret << CLOSE_GEN_BLOCK(); ret << CLOSE_GEN_BLOCK();
} }
void TabGoto::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) void TabGoto::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish )
{ {
ret << OPEN_GEN_BLOCK() << vCS() << " = " << OPEN_HOST_EXPR(); ret << OPEN_GEN_BLOCK() << vCS() << " = " << OPEN_HOST_EXPR();
INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); INLINE_LIST( ret, ilItem->children, 0, inFinish, false );
ret << CLOSE_HOST_EXPR() << ";"; ret << CLOSE_HOST_EXPR() << ";";
if ( inFinish && !noEnd ) CONTROL_JUMP( ret, inFinish );
EOF_CHECK( ret );
ret << " goto _again;";
ret << CLOSE_GEN_BLOCK(); ret << CLOSE_GEN_BLOCK();
} }
void TabGoto::CALL( ostream &ret, int callDest, int targState, bool inFinish ) void TabGoto::CALL( ostream &ret, int callDest, int targState, bool inFinish )
{ {
ret << OPEN_GEN_BLOCK(); ret << OPEN_GEN_BLOCK();
if ( red->prePushExpr != 0 ) { if ( red->prePushExpr != 0 ) {
ret << OPEN_HOST_BLOCK( red->prePushExpr ); ret << OPEN_HOST_BLOCK( red->prePushExpr );
INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false ) ; INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false ) ;
ret << CLOSE_HOST_BLOCK(); ret << CLOSE_HOST_BLOCK();
} }
ret << STACK() << "[" << TOP() << "] = " << ret << STACK() << "[" << TOP() << "] = " <<
vCS() << "; " << TOP() << " += 1;" << vCS() << " = " << vCS() << "; " << TOP() << " += 1;" << vCS() << " = " <<
callDest << ";"; callDest << ";";
if ( inFinish && !noEnd ) CONTROL_JUMP( ret, inFinish );
EOF_CHECK( ret );
ret << " goto _again;";
ret << CLOSE_GEN_BLOCK(); ret << CLOSE_GEN_BLOCK();
} }
void TabGoto::NCALL( ostream &ret, int callDest, int targState, bool inFinish ) void TabGoto::NCALL( ostream &ret, int callDest, int targState, bool inFinish )
{ {
ret << OPEN_GEN_BLOCK(); ret << OPEN_GEN_BLOCK();
if ( red->prePushExpr != 0 ) { if ( red->prePushExpr != 0 ) {
ret << OPEN_HOST_BLOCK( red->prePushExpr ); ret << OPEN_HOST_BLOCK( red->prePushExpr );
INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false ) ; INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false ) ;
skipping to change at line 105 skipping to change at line 98
INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false ) ; INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false ) ;
ret << CLOSE_HOST_BLOCK(); ret << CLOSE_HOST_BLOCK();
} }
ret << STACK() << "[" << TOP() << "] = " << ret << STACK() << "[" << TOP() << "] = " <<
vCS() << "; " << TOP() << " += 1;" << vCS() << vCS() << "; " << TOP() << " += 1;" << vCS() <<
" = " << OPEN_HOST_EXPR(); " = " << OPEN_HOST_EXPR();
INLINE_LIST( ret, ilItem->children, targState, inFinish, false ); INLINE_LIST( ret, ilItem->children, targState, inFinish, false );
ret << CLOSE_HOST_EXPR() << ";"; ret << CLOSE_HOST_EXPR() << ";";
if ( inFinish && !noEnd ) CONTROL_JUMP( ret, inFinish );
EOF_CHECK( ret );
ret << "goto _again;";
ret << CLOSE_GEN_BLOCK(); ret << CLOSE_GEN_BLOCK();
} }
void TabGoto::NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bo ol inFinish ) void TabGoto::NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bo ol inFinish )
{ {
ret << OPEN_GEN_BLOCK(); ret << OPEN_GEN_BLOCK();
if ( red->prePushExpr != 0 ) { if ( red->prePushExpr != 0 ) {
ret << OPEN_HOST_BLOCK( red->prePushExpr ); ret << OPEN_HOST_BLOCK( red->prePushExpr );
INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false ) ; INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false ) ;
skipping to change at line 139 skipping to change at line 128
void TabGoto::RET( ostream &ret, bool inFinish ) void TabGoto::RET( ostream &ret, bool inFinish )
{ {
ret << OPEN_GEN_BLOCK() << TOP() << " -= 1;" << vCS() << " = " << STACK() << "[" << TOP() << "];"; ret << OPEN_GEN_BLOCK() << TOP() << " -= 1;" << vCS() << " = " << STACK() << "[" << TOP() << "];";
if ( red->postPopExpr != 0 ) { if ( red->postPopExpr != 0 ) {
ret << OPEN_HOST_BLOCK( red->postPopExpr ); ret << OPEN_HOST_BLOCK( red->postPopExpr );
INLINE_LIST( ret, red->postPopExpr->inlineList, 0, false, false ) ; INLINE_LIST( ret, red->postPopExpr->inlineList, 0, false, false ) ;
ret << CLOSE_HOST_BLOCK(); ret << CLOSE_HOST_BLOCK();
} }
if ( inFinish && !noEnd ) CONTROL_JUMP( ret, inFinish );
EOF_CHECK( ret ); ret << CLOSE_GEN_BLOCK();
ret << "goto _again;" << CLOSE_GEN_BLOCK();
} }
void TabGoto::NRET( ostream &ret, bool inFinish ) void TabGoto::NRET( ostream &ret, bool inFinish )
{ {
ret << OPEN_GEN_BLOCK() << TOP() << " -= 1;" << vCS() << " = " << STACK() << "[" << TOP() << "];"; ret << OPEN_GEN_BLOCK() << TOP() << " -= 1;" << vCS() << " = " << STACK() << "[" << TOP() << "];";
if ( red->postPopExpr != 0 ) { if ( red->postPopExpr != 0 ) {
ret << OPEN_HOST_BLOCK( red->postPopExpr ); ret << OPEN_HOST_BLOCK( red->postPopExpr );
INLINE_LIST( ret, red->postPopExpr->inlineList, 0, false, false ) ; INLINE_LIST( ret, red->postPopExpr->inlineList, 0, false, false ) ;
ret << CLOSE_HOST_BLOCK(); ret << CLOSE_HOST_BLOCK();
} }
/* FIXME: ws in front of } will cause rlhc failure. */
ret << CLOSE_GEN_BLOCK(); ret << CLOSE_GEN_BLOCK();
} }
void TabGoto::BREAK( ostream &ret, int targState, bool csForced ) void TabGoto::BREAK( ostream &ret, int targState, bool csForced )
{ {
outLabelUsed = true; ret <<
ret << OPEN_GEN_BLOCK() << P() << " += 1; " << "goto _out; " << CLOSE_GEN OPEN_GEN_BLOCK() <<
_BLOCK(); P() << " += 1; " <<
"goto " << _out << "; " <<
CLOSE_GEN_BLOCK();
} }
void TabGoto::NBREAK( ostream &ret, int targState, bool csForced ) void TabGoto::NBREAK( ostream &ret, int targState, bool csForced )
{ {
outLabelUsed = true; ret <<
ret << OPEN_GEN_BLOCK() << P() << " += 1; " << " _nbreak = 1;" << CLOSE_G OPEN_GEN_BLOCK() <<
EN_BLOCK(); P() << " += 1; " <<
} nbreak << " = 1;" <<
CLOSE_GEN_BLOCK();
void TabGoto::NFA_POP()
{
if ( redFsm->anyNfaStates() ) {
out <<
" if ( nfa_len > 0 ) {\n"
" nfa_count += 1;\n"
" nfa_len -= 1;\n"
" " << P() << " = nfa_bp[nfa_len].p;\n"
;
if ( redFsm->bAnyNfaPops ) {
NFA_FROM_STATE_ACTION_EXEC();
out <<
" int _pop_test = 1;\n"
" switch ( " << ARR_REF( nfaPopTran
s ) <<
"[nfa_bp[nfa_len].popTran
s] ) {\n";
/* Loop the actions. */
for ( GenActionTableMap::Iter redAct = redFsm->actionMap;
redAct.lte(); redAct++ )
{
if ( redAct->numNfaPopTestRefs > 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++ )
NFA_CONDITION( out, item->value,
item.last() );
out << CEND() << "}\n";
}
}
out <<
" }\n";
out <<
" if ( _pop_test ) {\n"
" " << vCS() << " = nfa_bp[
nfa_len].state;\n";
if ( red->nfaPostPopExpr != 0 ) {
out << OPEN_HOST_BLOCK( red->nfaPostPopExpr );
INLINE_LIST( out, red->nfaPostPopExpr->inlineList
, 0, false, false );
out << CLOSE_HOST_BLOCK();
}
out <<
" goto _resume;\n"
" }\n";
if ( red->nfaPostPopExpr != 0 ) {
out <<
" else {\n"
" " << OPEN_HOST_BLOCK( red
->nfaPostPopExpr );
INLINE_LIST( out, red->nfaPostPopExpr->inlineList
, 0, false, false );
out << CLOSE_HOST_BLOCK() << "\n"
" }\n";
}
}
else {
out <<
" " << vCS() << " = nfa_bp[nfa_len]
.state;\n";
if ( red->nfaPostPopExpr != 0 ) {
out << OPEN_HOST_BLOCK( red->nfaPostPopExpr );
INLINE_LIST( out, red->nfaPostPopExpr->inlineList
, 0, false, false );
out << CLOSE_HOST_BLOCK();
}
out <<
" goto _resume;\n";
}
out <<
" goto _out;\n"
" }\n";
}
} }
void TabGoto::writeExec() void TabGoto::writeExec()
{ {
testEofUsed = false;
outLabelUsed = false;
out << out <<
" {\n"; " {\n";
if ( redFsm->anyRegCurStateRef() ) DECLARE( INT(), ps );
out << " int _ps;\n"; DECLARE( INT(), cpc );
DECLARE( INT(), nbreak );
if ( redFsm->anyEofTrans() || redFsm->anyEofActions() || red->condSpaceLi DECLARE( INT(), klen );
st.length() > 0 )
out << " int " << cpc << ";\n";
if ( redFsm->anyRegNbreak() )
out << " int _nbreak;\n";
DECLARE( "int", klen );
DECLARE( INDEX( ARR_TYPE( condKeys ) ), ckeys ); DECLARE( INDEX( ARR_TYPE( condKeys ) ), ckeys );
DECLARE( INDEX( ARR_TYPE( eofCondKeys ) ), cekeys ); DECLARE( INDEX( ARR_TYPE( eofCondKeys ) ), cekeys );
DECLARE( UINT(), trans, " = 0" ); DECLARE( UINT(), trans, " = 0" );
DECLARE( UINT(), cond, " = 0" ); DECLARE( UINT(), cond, " = 0" );
DECLARE( INDEX( ALPH_TYPE() ), keys ); DECLARE( INDEX( ALPH_TYPE() ), keys );
DECLARE( INDEX( ARR_TYPE( actions ) ), acts ); DECLARE( INDEX( ARR_TYPE( actions ) ), acts );
DECLARE( INDEX( ARR_TYPE( indicies ) ), inds ); DECLARE( INDEX( ARR_TYPE( indicies ) ), inds );
DECLARE( UINT(), nacts ); DECLARE( UINT(), nacts );
DECLARE( INT(), pop_test );
DECLARE( INT(), new_recs );
DECLARE( INT(), alt );
DECLARE( INT(), ic );
out << out << EMIT_LABEL( _resume );
" " << ENTRY() << " {\n";
/* Do we break out on no more input. */
bool eof = redFsm->anyEofActivity() || redFsm->anyNfaStates();
if ( !noEnd ) { if ( !noEnd ) {
testEofUsed = true; if ( eof ) {
out << out <<
" if ( " << P() << " == " << PE() << " )\n" " if ( " << P() << " == " << PE() << " && "
" goto _test_eof;\n"; << P() << " != " << vEOF() << " )\n"
} " goto " << _out << ";\n";
}
if ( redFsm->errState != 0 ) { else {
outLabelUsed = true; out <<
out << " if ( " << P() << " == " << PE() << " )\n"
" if ( " << vCS() << " == " << redFsm->errState->id " goto " << _out << ";\n";
<< " )\n" }
" goto _out;\n";
} }
out << LABEL( "_resume" ) << " {\n"; NFA_PUSH( vCS() );
FROM_STATE_ACTIONS(); FROM_STATE_ACTIONS();
NFA_PUSH( vCS() ); if ( !noEnd && eof ) {
out <<
"if ( " << P() << " == " << vEOF() << " ) {\n";
if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
if ( redFsm->anyEofTrans() ) {
out <<
" if ( " << ARR_REF( eofTrans ) <<
"[" << vCS() << "] > 0 ) {\n"
" " << trans << " = " <<
CAST(UINT()) << A
RR_REF( eofTrans ) << "[" << vCS() << "] - 1;\n"
" }\n";
}
}
out <<
"}\n"
"else {\n";
}
LOCATE_TRANS(); LOCATE_TRANS();
out << "}\n"; if ( !noEnd && eof ) {
out << LABEL( "_match_cond" ) << " {\n"; out <<
"}\n";
}
LOCATE_COND();
if ( redFsm->anyRegCurStateRef() ) if ( redFsm->anyRegCurStateRef() )
out << " _ps = " << vCS() << ";\n"; out << " " << ps << " = " << vCS() << ";\n";
string condVar = string condVar =
red->condSpaceList.length() != 0 ? string(cond) : string( trans); red->condSpaceList.length() != 0 ? string(cond) : string( trans);
out << out <<
" " << vCS() << " = " << CAST("int") << ARR_REF( condTargs ) << "[" << condVar << "];\n\n"; " " << vCS() << " = " << CAST(INT()) << ARR_REF( condTargs ) << "[" << condVar << "];\n\n";
if ( redFsm->anyRegActions() ) { if ( redFsm->anyRegActions() ) {
out << out <<
" if ( " << ARR_REF( condActions ) << "[" << condVa " if ( " << ARR_REF( condActions ) << "[" << condVa
r << "] == 0 )\n" r << "] != 0 ) {\n"
" goto _again;\n"
"\n"; "\n";
if ( redFsm->anyRegNbreak() ) if ( redFsm->anyRegNbreak() )
out << " _nbreak = 0;\n"; out << " " << nbreak << " = 0;\n";
REG_ACTIONS( condVar ); REG_ACTIONS( condVar );
if ( redFsm->anyRegNbreak() ) { if ( redFsm->anyRegNbreak() ) {
out << out <<
" if ( _nbreak == 1 )\n" " if ( " << nbreak << " == 1 )\n"
" goto _out;\n"; " goto " << _out << ";\n";
outLabelUsed = true;
} }
out << "\n"; out << "}\n";
} }
if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || out << "\n" << EMIT_LABEL( _again );
redFsm->anyActionCalls() || redFsm->anyActionRets() )
out << "}\n" << LABEL( "_again" ) << " {\n";
TO_STATE_ACTIONS();
if ( redFsm->errState != 0 ) { if ( !noEnd && eof ) {
outLabelUsed = true;
out << out <<
" if ( " << vCS() << " == " << redFsm->errState->id " if ( " << P() << " == " << vEOF() << " ) {\n"
<< " )\n" " if ( " << vCS() << " >= " << FIRST_FINAL_
" goto _out;\n"; STATE() << " )\n"
" goto " << _out << ";\n"
" }\n"
" else {\n";
} }
if ( !noEnd ) { TO_STATE_ACTIONS();
out <<
" " << P() << " += 1;\n" if ( redFsm->errState != 0 ) {
" if ( " << P() << " != " << PE() << " )\n"
" goto _resume;\n";
}
else {
out << out <<
" " << P() << " += 1;\n" " if ( " << vCS() << " != " << redFsm->errState->id
" goto _resume;\n"; << " ) {\n";
} }
if ( testEofUsed ) out <<
out << "}\n" << LABEL( "_test_eof" ) << " { {}\n"; " " << P() << " += 1;\n"
" goto " << _resume << ";\n";
if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { if ( redFsm->errState != 0 ) {
out << out <<
" if ( " << P() << " == " << vEOF() << " )\n" " }\n";
" {\n"; }
NFA_PUSH( vCS() );
if ( !noEnd && eof ) {
out << out <<
" if ( " << ARR_REF( eofCondSpaces ) << "[" << vCS( " }\n";
) << "] != -1 ) {\n" }
" " << cekeys << " = " << OFFSET( ARR_REF(
eofCondKeys ),
/*CAST( UINT() ) + */ ARR_REF( eo
fCondKeyOffs ) + "[" + vCS() + "]" ) << ";\n"
" " << klen << " = " << CAST( "int" ) << AR
R_REF( eofCondKeyLens ) + "[" + vCS() + "]" << ";\n"
" " << cpc << " = 0;\n"
;
if ( red->condSpaceList.length() > 0 )
COND_EXEC( ARR_REF( eofCondSpaces ) + "[" + vCS() + "]" )
;
COND_BIN_SEARCH( cekeys, eofCondKeys, "goto _ok;", "goto _out;" )
;
if ( redFsm->anyNfaStates() ) {
out << out <<
" _ok: {}\n" " if ( nfa_len == 0 )\n"
" }\n" " goto " << _out << ";\n"
; "\n"
" nfa_count += 1;\n"
outLabelUsed = true; " nfa_len -= 1;\n"
" " << P() << " = nfa_bp[nfa_len].p;\n"
EOF_ACTIONS(); ;
if ( redFsm->anyEofTrans() ) { if ( redFsm->bAnyNfaPops ) {
out << NFA_FROM_STATE_ACTION_EXEC();
" if ( " << ARR_REF( eofTrans ) << "[" << v
CS() << "] > 0 ) {\n";
EOF_TRANS(); NFA_POP_TEST_EXEC();
out << out <<
" goto _match_cond;\n" " if ( " << pop_test << " )\n"
" }\n"; " " << vCS() << " = nfa_bp[nfa_len]
.state;\n"
" else\n"
" " << vCS() << " = " << ERROR_STAT
E() << ";\n";
} }
else {
out <<
" " << vCS() << " = nfa_bp[nfa_len].state;\
n";
out << }
" }\n"
"\n";
}
if ( outLabelUsed )
out << "}\n" << LABEL( "_out" ) << " { {}\n";
out << "}\n"; NFA_POST_POP();
out << "}\n"; out << "goto " << _resume << ";\n";
}
NFA_POP(); out << EMIT_LABEL( _out );
out << " }\n"; out << " }\n";
} }
 End of changes. 44 change blocks. 
232 lines changed or deleted 126 lines changed or added

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