From: thurston Date: Mon, 12 Mar 2007 03:53:03 +0000 (+0000) Subject: All machine instantiations are now implicitly referenced and always generated, X-Git-Tag: 2.0_alpha~354 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=df5c2c21ff782a891df5b5907a6cbbdb733a664e;p=external%2Fragel.git All machine instantiations are now implicitly referenced and always generated, even if they are not referenced. In the backend, entry points will be written out alongside start, error and first final states. This is currently implemented in tabcodegen.cpp in rlgen-cd. The entry keyword (introduced in the last revision) was removed as it will not be used. More name changes writeOut* => write*. git-svn-id: http://svn.complang.org/ragel/trunk@136 052ea7fc-9027-0410-9066-f65837a77df0 --- diff --git a/ragel.vim b/ragel.vim index 88a5c31..9f88280 100644 --- a/ragel.vim +++ b/ragel.vim @@ -98,7 +98,7 @@ syntax match rlOtherOps "<:" contained " Keywords " FIXME: Enable the range keyword post 5.17. " syntax keyword rlKeywords machine action context include range contained -syntax keyword rlKeywords machine action context include export entry contained +syntax keyword rlKeywords machine action context include export contained syntax keyword rlExprKeywords when err lerr eof from to contained " Case Labels diff --git a/ragel/parsedata.cpp b/ragel/parsedata.cpp index 6b417e4..4550fb3 100644 --- a/ragel/parsedata.cpp +++ b/ragel/parsedata.cpp @@ -540,6 +540,7 @@ void ParseData::unsetObsoleteEntries( FsmAp *graph ) if ( name->numUses == name->numRefs ) { assert( graph->entryPoints.find( name->id ) != 0 ); graph->unsetEntry( name->id ); + assert( graph->entryPoints.find( name->id ) == 0 ); } } } @@ -803,6 +804,7 @@ void ParseData::makeNameTree( GraphDictEl *dictEl ) nameIndex = new NameInst*[nextNameId]; memset( nameIndex, 0, sizeof(NameInst*)*nextNameId ); fillNameIndex( rootName ); + fillNameIndex( exportsRootName ); } @@ -899,7 +901,8 @@ void ParseData::printNameInst( NameInst *nameInst, int level ) cerr << " "; cerr << (nameInst->name != 0 ? nameInst->name : "") << " id: " << nameInst->id << - " refs: " << nameInst->numRefs << endl; + " refs: " << nameInst->numRefs << + " uses: " << nameInst->numUses << endl; for ( NameVect::Iter name = nameInst->childVect; name.lte(); name++ ) printNameInst( *name, level+1 ); } @@ -1111,6 +1114,8 @@ FsmAp *ParseData::makeSpecific( GraphDictEl *gdNode ) * is okay since generating part of the graph is usually only done when * inspecting the compiled machine. */ + /* Same story for extern entry point references. */ + /* Flag this case so that the XML code generator is aware that we haven't * looked up name references in actions. It can then avoid segfaulting. */ generatingSectionSubset = true; @@ -1135,6 +1140,10 @@ FsmAp *ParseData::makeAll() /* Resolve action code name references. */ resolveActionNameRefs(); + /* Force name references to the top level instantiations. */ + for ( NameVect::Iter inst = rootName->childVect; inst.lte(); inst++ ) + (*inst)->numRefs += 1; + FsmAp *mainGraph = 0; FsmAp **graphs = new FsmAp*[instanceList.length()]; int numOthers = 0; @@ -1147,15 +1156,8 @@ FsmAp *ParseData::makeAll() mainGraph = makeInstance( glel ); } else { - /* Check to see if the instance is ever referenced. */ - NameInst *nameInst = nextNameScope(); - if ( nameInst->anyRefsRec() ) - graphs[numOthers++] = makeInstance( glel ); - else { - /* Need to walk over the name tree item. */ - NameFrame nameFrame = enterNameScope( true, 1 ); - popNameScope( nameFrame ); - } + /* Instantiate and store in others array. */ + graphs[numOthers++] = makeInstance( glel ); } } diff --git a/ragel/parsetree.h b/ragel/parsetree.h index 84fa9e0..8ef84f9 100644 --- a/ragel/parsetree.h +++ b/ragel/parsetree.h @@ -209,7 +209,7 @@ struct PriorityAug struct VarDef { VarDef( char *name, JoinOrLm *joinOrLm ) - : name(name), joinOrLm(joinOrLm) { } + : name(name), joinOrLm(joinOrLm), isExport(false) { } /* Parse tree traversal. */ FsmAp *walk( ParseData *pd ); @@ -218,9 +218,7 @@ struct VarDef char *name; JoinOrLm *joinOrLm; - bool isExport; - bool isEntry; }; diff --git a/ragel/rlparse.kh b/ragel/rlparse.kh index 3af05b9..efa3b5e 100644 --- a/ragel/rlparse.kh +++ b/ragel/rlparse.kh @@ -79,7 +79,7 @@ struct Parser # Keywords. token KW_Action, KW_AlphType, KW_Range, KW_GetKey, KW_Include, KW_Write, KW_Machine, KW_When, KW_Eof, KW_Err, KW_Lerr, KW_To, KW_From, - KW_Export, KW_Entry; + KW_Export; # Specials in code blocks. token KW_Break, KW_Exec, KW_Hold, KW_PChar, KW_Char, KW_Goto, KW_Call, @@ -102,7 +102,6 @@ struct Parser { pd = new ParseData( fileName, sectionName, sectionLoc ); exportContext.append( false ); - entryContext.append( false ); } int token( InputLoc &loc, int tokId, char *tokstart, int toklen ); @@ -121,7 +120,6 @@ struct Parser NameRefList nameRefList; Vector exportContext; - Vector entryContext; }; %% write token_defs; diff --git a/ragel/rlparse.kl b/ragel/rlparse.kl index 051bcc0..a6889a9 100644 --- a/ragel/rlparse.kl +++ b/ragel/rlparse.kl @@ -54,7 +54,6 @@ statement: getkey_spec commit; statement: access_spec commit; statement: variable_spec commit; statement: export_block commit; -statement: entry_block commit; export_open: KW_Export final { @@ -74,53 +73,31 @@ export_block: export_open '{' statement_list '}' exportContext.remove( exportContext.length()-1 ); }; -nonterm opt_entry -{ - bool isSet; -}; - -entry_open: KW_Entry - final { - entryContext.append( true ); - }; - -opt_entry: entry_open final { $$->isSet = true; }; -opt_entry: final { $$->isSet = false; }; - -entry_block: entry_open '{' statement_list '}' - final { - entryContext.remove( entryContext.length()-1 ); - }; - assignment: - opt_export opt_entry machine_name '=' join ';' final { + opt_export machine_name '=' join ';' final { /* Main machine must be an instance. */ bool isInstance = false; - if ( strcmp($3->token.data, machineMain) == 0 ) { - warning($3->token.loc) << + if ( strcmp($2->token.data, machineMain) == 0 ) { + warning($2->token.loc) << "main machine will be implicitly instantiated" << endl; isInstance = true; } /* Generic creation of machine for instantiation and assignment. */ - JoinOrLm *joinOrLm = new JoinOrLm( $5->join ); - tryMachineDef( $3->token.loc, $3->token.data, joinOrLm, isInstance ); + JoinOrLm *joinOrLm = new JoinOrLm( $4->join ); + tryMachineDef( $2->token.loc, $2->token.data, joinOrLm, isInstance ); if ( $1->isSet ) exportContext.remove( exportContext.length()-1 ); - if ( $2->isSet ) - entryContext.remove( entryContext.length()-1 ); }; instantiation: - opt_export opt_entry machine_name TK_ColonEquals join_or_lm ';' final { + opt_export machine_name TK_ColonEquals join_or_lm ';' final { /* Generic creation of machine for instantiation and assignment. */ - tryMachineDef( $3->token.loc, $3->token.data, $5->joinOrLm, true ); + tryMachineDef( $2->token.loc, $2->token.data, $4->joinOrLm, true ); if ( $1->isSet ) exportContext.remove( exportContext.length()-1 ); - if ( $2->isSet ) - entryContext.remove( entryContext.length()-1 ); }; type token_type @@ -1418,7 +1395,6 @@ void Parser::tryMachineDef( InputLoc &loc, char *name, newEl->isInstance = isInstance; newEl->loc = loc; newEl->value->isExport = exportContext[exportContext.length()-1]; - newEl->value->isEntry = entryContext[entryContext.length()-1]; /* It it is an instance, put on the instance list. */ if ( isInstance ) diff --git a/ragel/rlscan.rl b/ragel/rlscan.rl index f19536a..fd68aae 100644 --- a/ragel/rlscan.rl +++ b/ragel/rlscan.rl @@ -675,7 +675,6 @@ void Scanner::endSection( ) 'to' => { token( KW_To ); }; 'from' => { token( KW_From ); }; 'export' => { token( KW_Export ); }; - 'entry' => { token( KW_Entry ); }; # Identifiers. ident => { token( TK_Word, tokstart, tokend ); } ; diff --git a/ragel/xmlcodegen.cpp b/ragel/xmlcodegen.cpp index b07c82a..0c315f3 100644 --- a/ragel/xmlcodegen.cpp +++ b/ragel/xmlcodegen.cpp @@ -557,11 +557,26 @@ void XMLCodeGen::writeStateList() if ( !st.last() ) out << "\n"; - } out << " \n"; } +bool XMLCodeGen::writeNameInst( NameInst *nameInst ) +{ + bool written = false; + if ( nameInst->parent != 0 ) + written = writeNameInst( nameInst->parent ); + + if ( nameInst->name != 0 ) { + if ( written ) + out << '_'; + out << nameInst->name; + written = true; + } + + return written; +} + void XMLCodeGen::writeEntryPoints() { /* List of entry points other than start state. */ @@ -574,8 +589,9 @@ void XMLCodeGen::writeEntryPoints() /* Get the name instantiation from nameIndex. */ NameInst *nameInst = pd->nameIndex[en->key]; StateAp *state = en->value; - out << " name << "\">" << - state->alg.stateNum << "\n"; + out << " " << state->alg.stateNum << "\n"; } out << " \n"; } diff --git a/ragel/xmlcodegen.h b/ragel/xmlcodegen.h index c93b4a8..99b9853 100644 --- a/ragel/xmlcodegen.h +++ b/ragel/xmlcodegen.h @@ -105,6 +105,7 @@ private: void writeLmOnLagBehind( InlineItem *item ); void writeExports(); + bool writeNameInst( NameInst *nameInst ); void writeEntryPoints(); void writeGetKeyExpr(); void writeAccessExpr(); diff --git a/rlgen-cd/fsmcodegen.cpp b/rlgen-cd/fsmcodegen.cpp index 3ef4eea..06407b4 100644 --- a/rlgen-cd/fsmcodegen.cpp +++ b/rlgen-cd/fsmcodegen.cpp @@ -510,6 +510,15 @@ string FsmCodeGen::WIDE_ALPH_TYPE() return ret; } +void FsmCodeGen::ENTRY_POINTS() +{ + for ( EntryNameVect::Iter en = entryPointNames; en.lte(); en++ ) { + STATIC_VAR( "int", DATA_PREFIX() + "en_" + *en ) << + " = " << entryPointIds[en.pos()] << ";\n"; + } + out << "\n"; +} + void FsmCodeGen::writeExports() { if ( exportList.length() > 0 ) { diff --git a/rlgen-cd/fsmcodegen.h b/rlgen-cd/fsmcodegen.h index 615fa36..efb3d79 100644 --- a/rlgen-cd/fsmcodegen.h +++ b/rlgen-cd/fsmcodegen.h @@ -150,6 +150,7 @@ protected: void GET_TOKEND( ostream &ret, InlineItem *item ); void SUB_ACTION( ostream &ret, InlineItem *item, int targState, bool inFinish ); + void ENTRY_POINTS(); string ERROR_STATE(); string FIRST_FINAL_STATE(); diff --git a/rlgen-cd/tabcodegen.cpp b/rlgen-cd/tabcodegen.cpp index d377dc9..bd4ce6f 100644 --- a/rlgen-cd/tabcodegen.cpp +++ b/rlgen-cd/tabcodegen.cpp @@ -797,6 +797,8 @@ void TabCodeGen::writeData() STATIC_VAR( "int", ERROR() ) << " = " << ERROR_STATE() << ";\n" "\n"; } + + ENTRY_POINTS(); } void TabCodeGen::COND_TRANSLATE() diff --git a/rlgen-java/javacodegen.cpp b/rlgen-java/javacodegen.cpp index a5d02fe..c6f1ba9 100644 --- a/rlgen-java/javacodegen.cpp +++ b/rlgen-java/javacodegen.cpp @@ -769,7 +769,7 @@ std::ostream &JavaTabCodeGen::TRANS_ACTIONS_WI() } -void JavaTabCodeGen::writeOutData() +void JavaTabCodeGen::writeData() { /* If there are any transtion functions then output the array. If there * are none, don't bother emitting an empty array that won't be used. */ @@ -895,7 +895,7 @@ void JavaTabCodeGen::writeOutData() } -void JavaTabCodeGen::writeOutExec() +void JavaTabCodeGen::writeExec() { out << " {\n" @@ -1015,7 +1015,7 @@ void JavaTabCodeGen::writeOutExec() out << " }\n"; } -void JavaTabCodeGen::writeOutEOF() +void JavaTabCodeGen::writeEOF() { if ( redFsm->anyEofActions() ) { out << @@ -1366,7 +1366,7 @@ string JavaTabCodeGen::FIRST_FINAL_STATE() return ret.str(); } -void JavaTabCodeGen::writeOutInit() +void JavaTabCodeGen::writeInit() { out << " {\n"; out << "\t" << CS() << " = " << START() << ";\n"; diff --git a/rlgen-java/javacodegen.h b/rlgen-java/javacodegen.h index e7cc0e5..07be8cc 100644 --- a/rlgen-java/javacodegen.h +++ b/rlgen-java/javacodegen.h @@ -73,10 +73,10 @@ struct JavaTabCodeGen : public CodeGenData void COND_TRANSLATE(); void LOCATE_TRANS(); - virtual void writeOutExec(); - virtual void writeOutEOF(); - virtual void writeOutData(); - virtual void writeOutInit(); + virtual void writeExec(); + virtual void writeEOF(); + virtual void writeData(); + virtual void writeInit(); virtual void finishRagelDef(); void NEXT( ostream &ret, int nextDest, bool inFinish ); diff --git a/rlgen-ruby/rubycodegen.cpp b/rlgen-ruby/rubycodegen.cpp index e1f2d96..8df51bf 100644 --- a/rlgen-ruby/rubycodegen.cpp +++ b/rlgen-ruby/rubycodegen.cpp @@ -200,7 +200,7 @@ void RubyCodeGen::LOCATE_TRANS() << INDENT_D() << "end # cc _match" ; } -void RubyCodeGen::writeOutExec() +void RubyCodeGen::writeExec() { out << INDENT_U() << "callcc do |_out|" << INDENT_S() << "_klen, _trans, _keys"; @@ -297,7 +297,7 @@ void RubyCodeGen::writeOutExec() out << INDENT_D() << "end # cc _out" ; } -void RubyCodeGen::writeOutEOF() +void RubyCodeGen::writeEOF() { if ( redFsm->anyEofActions() ) { out << INDENT_S() << "_acts = " << EA() << "[" << CS() << "]" @@ -380,7 +380,7 @@ std::ostream &RubyCodeGen::ACTION_SWITCH() } -void RubyCodeGen::writeOutInit() +void RubyCodeGen::writeInit() { out << INDENT_U() << "begin" << INDENT_S() << CS() << " = " << START(); @@ -1022,7 +1022,7 @@ std::ostream &RubyCodeGen::TRANS_ACTIONS_WI() } -void RubyCodeGen::writeOutData() +void RubyCodeGen::writeData() { /* If there are any transtion functions then output the array. If there * are none, don't bother emitting an empty array that won't be used. */ diff --git a/rlgen-ruby/rubycodegen.h b/rlgen-ruby/rubycodegen.h index f4890b3..2599094 100644 --- a/rlgen-ruby/rubycodegen.h +++ b/rlgen-ruby/rubycodegen.h @@ -52,10 +52,10 @@ public: void COND_TRANSLATE(); void LOCATE_TRANS(); - virtual void writeOutExec(); - virtual void writeOutEOF(); - virtual void writeOutInit(); - virtual void writeOutData(); + virtual void writeExec(); + virtual void writeEOF(); + virtual void writeInit(); + virtual void writeData(); virtual void finishRagelDef(); protected: