"Fossies" - the Fresh Open Source Software Archive  

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

tabvar.cc  (ragel-7.0.0.11):tabvar.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 "flatvar.h" #include "flatvar.h"
#include "binvar.h" #include "binvar.h"
std::string TabVar::BREAK( GotoLabel &label )
{
return "{ _cont = 0; _again = 0; }";
}
std::string TabVar::CONTINUE( GotoLabel &label )
{
return "{ _cont = 0; _again = 1; }";
}
std::string TabVar::BREAK_LABEL( GotoLabel &label )
{
return "";
}
void TabVar::GOTO( ostream &ret, int gotoDest, bool inFinish ) void TabVar::GOTO( ostream &ret, int gotoDest, bool inFinish )
{ {
ret << OPEN_GEN_BLOCK() << vCS() << " = " << gotoDest << ";" << CLOSE_GEN _BLOCK(); ret << OPEN_GEN_BLOCK() << vCS() << " = " << gotoDest << ";" << CLOSE_GEN _BLOCK();
} }
void TabVar::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) void TabVar::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish )
{ {
ret << OPEN_GEN_BLOCK() << vCS() << " = " << OPEN_HOST_EXPR( "-", 1 ); ret << OPEN_GEN_BLOCK() << vCS() << " = " << OPEN_HOST_EXPR( "-", 1 );
INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); INLINE_LIST( ret, ilItem->children, 0, inFinish, false );
ret << CLOSE_HOST_EXPR() << ";" << CLOSE_GEN_BLOCK(); ret << CLOSE_HOST_EXPR() << ";" << CLOSE_GEN_BLOCK();
skipping to change at line 111 skipping to change at line 126
} }
void TabVar::BREAK( ostream &ret, int targState, bool csForced ) void TabVar::BREAK( ostream &ret, int targState, bool csForced )
{ {
red->id->error() << "cannot use fbreak in -B mode" << std::endl; red->id->error() << "cannot use fbreak in -B mode" << std::endl;
red->id->abortCompile( 1 ); red->id->abortCompile( 1 );
} }
void TabVar::NBREAK( ostream &ret, int targState, bool csForced ) void TabVar::NBREAK( ostream &ret, int targState, bool csForced )
{ {
outLabelUsed = true; ret <<
ret << OPEN_GEN_BLOCK() << P() << "+= 1; _cont = 0; " << CLOSE_GEN_BLOCK( OPEN_GEN_BLOCK() <<
); P() << "+= 1;\n" <<
nbreak << " = 1;" <<
CLOSE_GEN_BLOCK();
} }
void TabVar::NFA_POP() void TabVar::writeExec()
{ {
if ( redFsm->anyNfaStates() ) { out <<
out << "{\n";
" _nfa_repeat = 1;\n"
" while ( _nfa_repeat ) {\n"
" _nfa_repeat = 0;\n"
" if ( nfa_len > 0 ) {\n"
" int _pop_test = 1;\n"
" nfa_count += 1;\n"
" nfa_len -= 1;\n"
" " << P() << " = nfa_bp[nfa_len].p;\n"
;
if ( redFsm->bAnyNfaPops ) { DECLARE( INT(), ps );
NFA_FROM_STATE_ACTION_EXEC(); DECLARE( INT(), cpc );
DECLARE( INT(), nbreak );
DECLARE( INT(), klen );
DECLARE( INDEX( ARR_TYPE( condKeys ) ), ckeys );
DECLARE( INDEX( ARR_TYPE( eofCondKeys ) ), cekeys );
DECLARE( UINT(), trans, " = 0" );
DECLARE( UINT(), cond, " = 0" );
DECLARE( INDEX( ALPH_TYPE() ), keys );
DECLARE( INDEX( ARR_TYPE( actions ) ), acts );
DECLARE( INDEX( ARR_TYPE( indicies ) ), inds );
DECLARE( UINT(), nacts );
DECLARE( INT(), have );
DECLARE( INT(), pop_test );
DECLARE( INT(), new_recs );
DECLARE( INT(), alt );
DECLARE( INT(), ic );
out << UINT() << " _have = 0;\n";
out << UINT() << " _cont = 1;\n";
out << UINT() << " _again = 1;\n";
out << UINT() << " _bsc = 1;\n";
out << out << BREAK_LABEL( _resume );
" switch ( " << ARR_REF( nfaPopTran
s ) <<
"[nfa_bp[nfa_len].popTran
s] ) {\n";
/* Loop the actions. */ /* Do we break out on no more input. */
for ( GenActionTableMap::Iter redAct = redFsm->actionMap; bool eof = redFsm->anyEofActivity() || redFsm->anyNfaStates();
redAct.lte(); redAct++ ) if ( !noEnd ) {
{ if ( eof ) {
if ( redAct->numNfaPopTestRefs > 0 ) { out <<
/* Write the entry label. */ " while ( _again == 1 && ( " << P() << " !=
out << "\t " << CASE( STR( redAct->actLis " << PE() << " || " << P() << " == " << vEOF() << " ) ) {\n";
tId+1 ) ) << " {\n"; }
else {
/* Write each action in the list of actio out <<
n items. */ " while ( _again == 1 && " << P() << " != "
for ( GenActionTable::Iter item = redAct- << PE() << " ) {\n";
>key; item.lte(); item++ ) }
NFA_CONDITION( out, item->value, }
item.last() ); else {
out <<
" while ( _again == 1 ) {\n";
out << "\n\t" << CEND() << "}\n"; }
}
}
out << out << "_cont = 1;\n";
" }\n"; out << "_again = 1;\n";
out << NFA_PUSH( vCS() );
" if ( _pop_test ) {\n"
" " << vCS() << " = nfa_bp[
nfa_len].state;\n";
if ( red->nfaPostPopExpr != 0 ) { FROM_STATE_ACTIONS();
out << OPEN_HOST_BLOCK( red->nfaPostPopExpr );
INLINE_LIST( out, red->nfaPostPopExpr->inlineList
, 0, false, false );
out << CLOSE_HOST_BLOCK();
}
out << if ( !noEnd && eof ) {
// " goto _resume;\n" out <<
" _nfa_cont = 1;\n" "if ( " << P() << " == " << vEOF() << " ) {\n";
" _nfa_repeat = 0;\n"
" }\n";
if ( red->nfaPostPopExpr != 0 ) { if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
out << if ( redFsm->anyEofTrans() ) {
" else {\n"
" " << OPEN_HOST_BLOCK( red
->nfaPostPopExpr );
INLINE_LIST( out, red->nfaPostPopExpr->inlineList
, 0, false, false );
out << CLOSE_HOST_BLOCK() << "\n"
// " goto _out;\n"
" _nfa_cont = 0;\n"
" _nfa_repeat = 1;\
n"
" }\n";
}
else {
out << out <<
" else {\n" " if ( " << ARR_REF( eofTrans ) <<
// " goto _out;\n" "[" << vCS() << "] > 0 ) {\n"
" _nfa_cont = 0;\n" " " << trans << " = " <<
" _nfa_repeat = 1;\ CAST(UINT()) << A
n" RR_REF( eofTrans ) << "[" << vCS() << "] - 1;\n"
" }\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"
" _nfa_cont = 1;\n"
" _nfa_repeat = 0;\n"
;
} }
out << out <<
" }\n"
" else {\n"
" _nfa_cont = 0;\n"
" _nfa_repeat = 0;\n"
" }\n"
"}\n" "}\n"
; "else {\n";
} }
}
void TabVar::writeExec() LOCATE_TRANS();
{
testEofUsed = false;
outLabelUsed = false;
matchCondLabelUsed = false;
if ( redFsm->anyNfaStates() ) { if ( !noEnd && eof ) {
out << out <<
"{\n" "}\n";
" " << UINT() << " _nfa_cont = 1;\n"
" " << UINT() << " _nfa_repeat = 1;\n"
" while ( _nfa_cont != 0 )\n";
} }
out << LOCATE_COND();
" {\n";
if ( redFsm->anyRegCurStateRef() ) if ( redFsm->anyRegCurStateRef() )
out << " int _ps;\n"; out << " " << ps << " = " << vCS() << ";\n";
out <<
" " << UINT() << " " << trans << " = 0;\n"
" " << UINT() << " _have = 0;\n"
" " << UINT() << " _cont = 1;\n";
DECLARE( "int", klen ); string condVar =
DECLARE( UINT(), cond, " = 0" ); red->condSpaceList.length() != 0 ? string(cond) : string(
DECLARE( "int", cpc ); trans);
DECLARE( INDEX( ALPH_TYPE() ), keys );
DECLARE( INDEX( ARR_TYPE( actions ) ), acts );
DECLARE( UINT(), nacts );
DECLARE( INDEX( ARR_TYPE( condKeys ) ), ckeys );
DECLARE( INDEX( ARR_TYPE( eofCondKeys ) ), cekeys );
DECLARE( INDEX( ARR_TYPE( indicies ) ), inds );
out <<
" while ( _cont == 1 ) {\n"
"\n";
if ( redFsm->errState != 0 ) {
outLabelUsed = true;
out <<
" if ( " << vCS() << " == " << redFsm->errState->id
<< " )\n"
" _cont = 0;\n";
}
out << out <<
"_have = 0;\n"; " " << vCS() << " = " << CAST(INT()) << ARR_REF( condTargs ) << "[" << condVar << "];\n\n";
if ( !noEnd ) { if ( redFsm->anyRegActions() ) {
out << out <<
" if ( " << P() << " == " << PE() << " ) {\n"; " if ( " << ARR_REF( condActions ) << "[" << condVa
r << "] != 0 ) {\n"
if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { "\n";
out <<
" if ( " << P() << " == " << vEOF() << " )\
n"
" {\n";
NFA_PUSH( vCS() );
out << UINT() << " _eofcont = 0;\n";
out <<
" if ( " << ARR_REF( eofCondSpaces ) << "["
<< vCS() << "] != -1 ) {\n"
" " << cekeys << " = " << OFFSET( A
RR_REF( eofCondKeys ),
/*CAST( UINT() ) + */ ARR
_REF( eofCondKeyOffs ) + "[" + vCS() + "]" ) << ";\n"
" " << klen << " = " << CAST( "int"
) << ARR_REF( eofCondKeyLens ) + "[" + vCS() + "]" << ";\n"
" " << cpc << " = 0;\n"
;
if ( red->condSpaceList.length() > 0 ) if ( redFsm->anyRegNbreak() )
COND_EXEC( ARR_REF( eofCondSpaces ) + "[" + vCS() out << " " << nbreak << " = 0;\n";
+ "]" );
out << REG_ACTIONS( condVar );
" {\n"
" " << INDEX( ARR_TYPE( eofCondKeys
), "_lower" ) << " = " << cekeys << ";\n"
" " << INDEX( ARR_TYPE( eofCondKeys
), "_upper" ) << " = " << cekeys << " + " << klen << " - 1;\n"
" " << INDEX( ARR_TYPE( eofCondKeys
), "_mid" ) << ";\n"
" while ( _eofcont == 0 && _lower <
= _upper ) {\n"
" _mid = _lower + ((_upper-
_lower) >> 1);\n"
" if ( " << cpc << " < " <<
CAST( "int" ) << DEREF( ARR_REF( eofCondKeys ), "_mid" ) << " )\n"
" _upper = _mid - 1
;\n"
" else if ( " << cpc << " >
" << CAST("int" ) << DEREF( ARR_REF( eofCondKeys ), "_mid" ) << " )\n"
" _lower = _mid + 1
;\n"
" else {\n"
" _eofcont = 1;\n"
" }\n"
" }\n"
" if ( _eofcont == 0 ) {\n"
" " << vCS() << " = " << ER
ROR_STATE() << ";\n"
" }\n"
" }\n"
;
if ( redFsm->anyRegNbreak() ) {
out << out <<
" }\n" " if ( " << nbreak << " == 1 )\n"
" else { _eofcont = 1; }\n" " " << BREAK( _resume ) << "\n";
; }
out << "if ( _eofcont == 1 ) {\n";
EOF_ACTIONS();
out << " }\n"; out << "}\n";
}
out << "if ( _eofcont == 1 ) {\n"; out << "if ( _cont == 1 ) {\n";
if ( redFsm->anyEofTrans() ) { out << "\n" << EMIT_LABEL( _again );
out <<
" if ( " << ARR_REF( eofTrans ) <<
"[" << vCS() << "] > 0 ) {\n";
EOF_TRANS(); if ( !noEnd && eof ) {
out <<
" if ( " << P() << " == " << vEOF() << " ) {\n"
" if ( " << vCS() << " >= " << FIRST_FINAL_
STATE() << " )\n"
" " << BREAK( _resume ) << "\n"
" }\n"
" else {\n";
}
out << TO_STATE_ACTIONS();
" _have = 1;\n"
" }\n";
matchCondLabelUsed = true; if ( redFsm->errState != 0 ) {
} out <<
" if ( " << vCS() << " != " << redFsm->errState->id
<< " ) {\n";
}
out << "}\n"; out <<
out << "}\n"; " " << P() << " += 1;\n"
} " " << CONTINUE( _resume ) << "\n";
if ( redFsm->errState != 0 ) {
out << out <<
" if ( _have == 0 )\n"
" _cont = 0;\n"
" }\n"; " }\n";
} }
out << if ( !noEnd && eof ) {
" if ( _cont == 1 ) {\n" out <<
" if ( _have == 0 ) {\n"; " }\n";
}
FROM_STATE_ACTIONS();
NFA_PUSH( vCS() ); out << "if ( _cont == 1 ) {\n";
LOCATE_TRANS(); if ( redFsm->anyNfaStates() ) {
out <<
" if ( nfa_len == 0 )\n"
" " << BREAK ( _resume ) << "\n"
"\n";
out << "}\n"; out << "if ( _cont == 1 ) {\n";
out << "if ( _cont == 1 ) {\n"; out <<
" nfa_count += 1;\n"
" nfa_len -= 1;\n"
" " << P() << " = nfa_bp[nfa_len].p;\n"
;
if ( redFsm->anyRegCurStateRef() ) if ( redFsm->bAnyNfaPops ) {
out << " _ps = " << vCS() << ";\n"; NFA_FROM_STATE_ACTION_EXEC();
string condVar = NFA_POP_TEST_EXEC();
red->condSpaceList.length() != 0 ? string(cond) : string(
trans);
out << out <<
" " << vCS() << " = " << CAST("int") << ARR_REF( condTargs " if ( " << pop_test << " )\n"
) << "[" << condVar << "];\n" " " << vCS() << " = nfa_bp[nfa_len]
"\n"; .state;\n"
" else\n"
" " << vCS() << " = " << ERROR_STAT
E() << ";\n";
}
else {
out <<
" " << vCS() << " = nfa_bp[nfa_len].state;\
n";
if ( redFsm->anyRegActions() ) { }
out <<
" if ( " << ARR_REF( condActions ) << "[" << condVa
r << "] != 0 ) {\n";
REG_ACTIONS( condVar ); NFA_POST_POP();
out << /* cont */
" }\n"; out << "}\n";
} }
else {
TO_STATE_ACTIONS();
if ( redFsm->errState != 0 ) {
outLabelUsed = true;
out << out <<
" if ( " << vCS() << " == " << redFsm->errState->id " " << BREAK( _resume ) << "\n";
<< " )\n"
" _cont = 0;\n";
} }
out << /* cont */
" if ( _cont == 1 )\n" out << "}}\n";
" " << P() << " += 1;\n";
out << "}\n"; /* P loop. */
out << "}\n";
out << "}\n"; out << "}\n";
NFA_POP(); out << EMIT_LABEL( _out );
/* Variable decl. */
out << "}\n"; out << "}\n";
if ( redFsm->anyNfaStates() )
out << "}\n";
} }
 End of changes. 58 change blocks. 
267 lines changed or deleted 165 lines changed or added

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