From 4cdf35ba26656f5d77a5602439553c18dcf8ed25 Mon Sep 17 00:00:00 2001 From: thurston Date: Sun, 26 Oct 2008 01:36:54 +0000 Subject: [PATCH] More work on the direct connection between frontend and backend. Now appears to work. Test suite is passing. git-svn-id: http://svn.complang.org/ragel/trunk@497 052ea7fc-9027-0410-9066-f65837a77df0 --- common/common.h | 9 ++ ragel/main.cpp | 37 ++++---- ragel/parsedata.cpp | 33 ++++--- ragel/parsedata.h | 55 +++++------- ragel/ragel.h | 12 +-- ragel/rlparse.kl | 1 + ragel/rlscan.h | 5 +- ragel/rlscan.rl | 36 ++++---- ragel/xmlcodegen.cpp | 211 ++++++++++++++++++++++++-------------------- ragel/xmlcodegen.h | 41 ++++++--- redfsm/gendata.cpp | 6 +- redfsm/gendata.h | 6 +- redfsm/redfsm.h | 14 +-- redfsm/xmlparse.kh | 21 +++-- redfsm/xmlparse.kl | 100 +++++++++++---------- rlgen-cd/fsmcodegen.cpp | 4 +- rlgen-cd/fsmcodegen.h | 4 +- rlgen-cd/rlgen-cd.h | 2 - rlgen-csharp/fsmcodegen.cpp | 4 +- rlgen-csharp/fsmcodegen.h | 4 +- rlgen-csharp/main.cpp | 42 +-------- rlgen-csharp/rlgen-csharp.h | 2 - rlgen-dot/gvdotgen.cpp | 2 +- rlgen-dot/gvdotgen.h | 2 +- rlgen-dot/rlgen-dot.h | 2 - rlgen-java/javacodegen.cpp | 4 +- rlgen-java/javacodegen.h | 4 +- rlgen-java/rlgen-java.h | 2 - rlgen-ruby/rlgen-ruby.h | 2 - rlgen-ruby/ruby-codegen.cpp | 4 +- rlgen-ruby/ruby-codegen.h | 4 +- 31 files changed, 324 insertions(+), 351 deletions(-) diff --git a/common/common.h b/common/common.h index 4185a82..0f0cf1b 100644 --- a/common/common.h +++ b/common/common.h @@ -26,6 +26,15 @@ #include #include "dlist.h" +/* Location in an input file. */ +struct InputLoc +{ + const char *fileName; + long line; + long col; +}; + + typedef unsigned long long Size; struct Key diff --git a/ragel/main.cpp b/ragel/main.cpp index 0f76f7b..40fc456 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -456,10 +456,14 @@ void process( const char *inputFileName, const char *intermed ) /* Used for just a few things. */ std::ostringstream hostData; - if ( machineSpec == 0 && machineName == 0 ) - hostData << ""; - - Scanner scanner( inputFileName, *inFile, hostData, 0, 0, 0, false ); + /* Make the first input item. */ + InputItem *firstInputItem = new InputItem; + firstInputItem->type = InputItem::HostData; + firstInputItem->loc.line = 1; + firstInputItem->loc.col = 1; + inputItems.append( firstInputItem ); + + Scanner scanner( inputFileName, *inFile, 0, 0, 0, false ); scanner.do_scan(); /* Finished, final check for errors.. */ @@ -473,17 +477,6 @@ void process( const char *inputFileName, const char *intermed ) if ( gblErrorCount > 0 ) exit(1); - if ( machineSpec == 0 && machineName == 0 ) - hostData << "\n"; - - /* Open the XML file for writing. */ - ostream *xmlOutFile = new ofstream( xmlFileName ); - - /* Open the XML file for reading. */ - ifstream *xmlInFile = new ifstream( xmlFileName ); - if ( ! xmlInFile->is_open() ) - error() << "could not open " << xmlFileName << " for reading" << endl; - /* Bail on above error. */ if ( gblErrorCount > 0 ) exit(1); @@ -494,16 +487,16 @@ void process( const char *inputFileName, const char *intermed ) outputActive = false; } - XmlScanner xmlScanner( xmlFileName, *xmlInFile ); - XmlParser xmlParser( xmlFileName, outputActive, wantComplete ); + XmlScanner xmlScanner( xmlFileName, cin ); + XmlParser xmlParser( inputFileName, xmlFileName, outputActive, wantComplete ); xmlParser.init(); + xmlParser.openOutput(); + /* Write the machines, then the surrounding code. */ - //writeMachines( *xmlOutFile, hostData.str(), inputFileName, xmlParser ); - generate( *xmlOutFile, hostData.str(), inputFileName, xmlParser ); + generate( xmlParser ); /* Close the input and the intermediate file. */ - delete xmlOutFile; delete inFile; /* Bail on above error. */ @@ -593,7 +586,7 @@ const char *openIntermed( const char *inputFileName, const char *outputFileName void cleanExit( const char *intermed, int status ) { - unlink( intermed ); + //unlink( intermed ); exit( status ); } @@ -627,7 +620,7 @@ int main( int argc, const char **argv ) "\" is the same as the input file" << endp; } - const char *intermed = openIntermed( inputFileName, outputFileName ); + const char *intermed = 0; //openIntermed( inputFileName, outputFileName ); process( inputFileName, intermed ); /* Clean up the intermediate. */ diff --git a/ragel/parsedata.cpp b/ragel/parsedata.cpp index 0918cf5..b9579d2 100644 --- a/ragel/parsedata.cpp +++ b/ragel/parsedata.cpp @@ -1427,15 +1427,15 @@ void ParseData::prepareMachineGenTBWrapped( GraphDictEl *graphDictEl ) sectionGraph->setStateNumbers( 0 ); } -void ParseData::generate( ostream &out, XmlParser &xmlParser ) +void ParseData::genBackend( XmlParser &xmlParser ) { beginProcessing(); /* Make the generator. */ - XMLCodeGen codeGen( sectionName, this, sectionGraph, out, xmlParser ); + BackendGen backendGen( sectionName, this, sectionGraph, xmlParser ); /* Write out with it. */ - codeGen.makeBackend(); + backendGen.makeBackend(); if ( printStatistics ) { cerr << "fsm name : " << sectionName << endl; @@ -1551,8 +1551,7 @@ void writeMachines( std::ostream &out, std::string hostData, } } -void generate( std::ostream &out, std::string hostData, - const char *inputFileName, XmlParser &xmlParser ) +void generate( XmlParser &xmlParser ) { if ( machineSpec == 0 && machineName == 0 ) { /* No machine spec or machine name given. Generate everything. */ @@ -1563,13 +1562,11 @@ void generate( std::ostream &out, std::string hostData, } if ( gblErrorCount == 0 ) { - xmlParser.open_ragel( inputFileName ); for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) { ParseData *pd = parser->value->pd; if ( pd->instanceList.length() > 0 ) - pd->generate( out, xmlParser ); + pd->genBackend( xmlParser ); } - out << hostData; } } else if ( parserDict.length() > 0 ) { @@ -1600,11 +1597,21 @@ void generate( std::ostream &out, std::string hostData, else { /* Section/Machine to emit was found. Prepare and emit it. */ parseData->prepareMachineGen( graphDictEl ); - if ( gblErrorCount == 0 ) { - xmlParser.open_ragel( inputFileName ); - parseData->generate( out, xmlParser ); - out << hostData; - } + if ( gblErrorCount == 0 ) + parseData->genBackend( xmlParser ); + } + } + + + for ( InputItemList::Iter ii = inputItems; ii.lte(); ii++ ) { + if ( ii->type == InputItem::Write ) { + CodeGenMapEl *mapEl = xmlParser.codeGenMap.find( (char*)ii->name.c_str() ); + xmlParser.cgd = mapEl->value; + ::keyOps = &xmlParser.cgd->thisKeyOps; + + xmlParser.cgd->writeStatement( ii->loc, ii->writeArgs.length()-1, ii->writeArgs.data ); } + else + xmlParser.cgd->out << ii->data.str(); } } diff --git a/ragel/parsedata.h b/ragel/parsedata.h index 605264b..8149b15 100644 --- a/ragel/parsedata.h +++ b/ragel/parsedata.h @@ -24,6 +24,7 @@ #include #include +#include #include "avlmap.h" #include "bstmap.h" #include "vector.h" @@ -216,7 +217,7 @@ struct ParseData void prepareMachineGen( GraphDictEl *graphDictEl ); void prepareMachineGenTBWrapped( GraphDictEl *graphDictEl ); void generateXML( ostream &out, XmlParser &xmlParser ); - void generate( ostream &out, XmlParser &xmlParser ); + void genBackend( XmlParser &xmlParser ); FsmAp *sectionGraph; bool generatingSectionSubset; @@ -370,51 +371,35 @@ FsmAp *dotStarFsm( ParseData *pd ); void errorStateLabels( const NameSet &locations ); -/* Data used by the parser specific to the current file. Supports the include - * system, since a new parser is executed for each included file. */ -struct InputData +struct InputItem { - InputData( char *fileName, char *includeSpec, char *includeTo ) : - pd(0), sectionName(0), defaultParseData(0), - first_line(1), first_column(1), - last_line(1), last_column(0), - fileName(fileName), includeSpec(includeSpec), - includeTo(includeTo), active(true) - {} - - /* For collecting a name references. */ - NameRef nameRef; - NameRefList nameRefList; - - /* The parse data. For each fsm spec, the parser collects things that it parses - * in data structures in here. */ - ParseData *pd; + enum Type { + HostData, + Write, + }; - char *sectionName; - ParseData *defaultParseData; - - int first_line; - int first_column; - int last_line; - int last_column; - - char *fileName; + Type type; + std::ostringstream data; + std::string name; + Vector writeArgs; - /* If this is an included file, this contains the specification to search - * for. IncludeTo will contain the spec name that does the includng. */ - char *includeSpec; - char *includeTo; + InputLoc loc; - bool active; - InputLoc sectionLoc; + InputItem *prev, *next; }; +/* + * Global data. + */ + struct Parser; typedef AvlMap ParserDict; typedef AvlMapEl ParserDictEl; -extern ParserDict parserDict; +typedef DList InputItemList; +extern ParserDict parserDict; +extern InputItemList inputItems; #endif /* _PARSEDATA_H */ diff --git a/ragel/ragel.h b/ragel/ragel.h index 54a93b2..e49aefc 100644 --- a/ragel/ragel.h +++ b/ragel/ragel.h @@ -28,6 +28,7 @@ #include #include "vector.h" #include "config.h" +#include "common.h" #define PROGNAME "ragel" @@ -64,14 +65,6 @@ extern ErrorFormat errorFormat; extern int gblErrorCount; extern char mainMachine[]; -/* Location in an input file. */ -struct InputLoc -{ - const char *fileName; - int line; - int col; -}; - InputLoc makeInputLoc( const char *fileName, int line = 0, int col = 0 ); std::ostream &operator<<( std::ostream &out, const InputLoc &loc ); @@ -85,8 +78,7 @@ struct XmlParser; void terminateAllParsers( ); void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName, XmlParser &xmlParser ); -void generate( std::ostream &out, std::string hostData, - const char *inputFileName, XmlParser &xmlParser ); +void generate( XmlParser &xmlParser ); void xmlEscapeHost( std::ostream &out, char *data, long len ); typedef Vector ArgsVector; diff --git a/ragel/rlparse.kl b/ragel/rlparse.kl index ece1786..c6731de 100644 --- a/ragel/rlparse.kl +++ b/ragel/rlparse.kl @@ -30,6 +30,7 @@ using std::cerr; using std::endl; ParserDict parserDict; +InputItemList inputItems; %%{ diff --git a/ragel/rlscan.h b/ragel/rlscan.h index 4c07bf8..553a5c8 100644 --- a/ragel/rlscan.h +++ b/ragel/rlscan.h @@ -37,11 +37,11 @@ extern char *Parser_lelNames[]; struct Scanner { - Scanner( const char *fileName, istream &input, ostream &output, + Scanner( const char *fileName, istream &input, Parser *inclToParser, char *inclSectionTarg, int includeDepth, bool importMachines ) : - fileName(fileName), input(input), output(output), + fileName(fileName), input(input), inclToParser(inclToParser), inclSectionTarg(inclSectionTarg), includeDepth(includeDepth), @@ -84,7 +84,6 @@ struct Scanner const char *fileName; istream &input; - ostream &output; Parser *inclToParser; char *inclSectionTarg; int includeDepth; diff --git a/ragel/rlscan.rl b/ragel/rlscan.rl index 40bb918..f31dd37 100644 --- a/ragel/rlscan.rl +++ b/ragel/rlscan.rl @@ -202,7 +202,7 @@ void Scanner::pass() /* If no errors and we are at the bottom of the include stack (the * source file listed on the command line) then write out the data. */ if ( includeDepth == 0 && machineSpec == 0 && machineName == 0 ) - xmlEscapeHost( output, ts, te-ts ); + inputItems.tail->data.write( ts, te-ts ); } /* @@ -336,7 +336,7 @@ void Scanner::handleInclude() parser->includeHistory.append( IncludeHistoryItem( includeChecks[found], inclSectionName ) ); - Scanner scanner( includeChecks[found], *inFile, output, parser, + Scanner scanner( includeChecks[found], *inFile, parser, inclSectionName, includeDepth+1, false ); scanner.do_scan( ); delete inFile; @@ -361,7 +361,7 @@ void Scanner::handleImport() scan_error() << "import: attempted: \"" << *tried++ << '\"' << endl; } - Scanner scanner( importChecks[found], *inFile, output, parser, + Scanner scanner( importChecks[found], *inFile, parser, 0, includeDepth+1, true ); scanner.do_scan( ); scanner.importToken( 0, 0, 0 ); @@ -409,24 +409,25 @@ void Scanner::handleImport() action write_command { if ( active() && machineSpec == 0 && machineName == 0 ) { - output << "sectionName << "\"" - " line=\"" << line << "\"" - " col=\"" << column << "\"" - ">"; + InputItem *inputItem = new InputItem; + inputItem->type = InputItem::Write; + inputItem->loc.line = line; + inputItem->loc.col = column; + inputItem->name = parser->sectionName; + inputItems.append( inputItem ); } } action write_arg { if ( active() && machineSpec == 0 && machineName == 0 ) - output << "" << tokdata << ""; + inputItems.tail->writeArgs.append( strdup(tokdata) ); } action write_close { if ( active() && machineSpec == 0 && machineName == 0 ) - output << "\n"; + inputItems.tail->writeArgs.append( 0 ); } write_stmt = @@ -507,14 +508,9 @@ void Scanner::startSection( ) { parserExistsError = false; - if ( includeDepth == 0 ) { - if ( machineSpec == 0 && machineName == 0 ) - output << "\n"; - } - sectionLoc.fileName = fileName; sectionLoc.line = line; - sectionLoc.col = 0; + sectionLoc.col = column; } void Scanner::endSection( ) @@ -527,7 +523,7 @@ void Scanner::endSection( ) InputLoc loc; loc.fileName = fileName; loc.line = line; - loc.col = 0; + loc.col = column; parser->token( loc, TK_EndSection, 0, 0 ); } @@ -536,7 +532,11 @@ void Scanner::endSection( ) if ( machineSpec == 0 && machineName == 0 ) { /* The end section may include a newline on the end, so * we use the last line, which will count the newline. */ - output << ""; + InputItem *inputItem = new InputItem; + inputItem->type = InputItem::HostData; + inputItem->loc.line = line; + inputItem->loc.col = column; + inputItems.append( inputItem ); } } } diff --git a/ragel/xmlcodegen.cpp b/ragel/xmlcodegen.cpp index 66bddca..0d0f223 100644 --- a/ragel/xmlcodegen.cpp +++ b/ragel/xmlcodegen.cpp @@ -30,18 +30,65 @@ using namespace std; -XMLCodeGen::XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, - std::ostream &out, XmlParser &xmlParser ) +GenBase::GenBase( char *fsmName, ParseData *pd, FsmAp *fsm, XmlParser &xmlParser ) : fsmName(fsmName), pd(pd), fsm(fsm), - out(out), xmlParser(xmlParser), nextActionTableId(0) { } +void GenBase::appendTrans( TransListVect &outList, Key lowKey, + Key highKey, TransAp *trans ) +{ + if ( trans->toState != 0 || trans->actionTable.length() > 0 ) + outList.append( TransEl( lowKey, highKey, trans ) ); +} + +void GenBase::reduceActionTables() +{ + /* Reduce the actions tables to a set. */ + for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) { + RedActionTable *actionTable = 0; + + /* Reduce To State Actions. */ + if ( st->toStateActionTable.length() > 0 ) { + if ( actionTableMap.insert( st->toStateActionTable, &actionTable ) ) + actionTable->id = nextActionTableId++; + } + + /* Reduce From State Actions. */ + if ( st->fromStateActionTable.length() > 0 ) { + if ( actionTableMap.insert( st->fromStateActionTable, &actionTable ) ) + actionTable->id = nextActionTableId++; + } + + /* Reduce EOF actions. */ + if ( st->eofActionTable.length() > 0 ) { + if ( actionTableMap.insert( st->eofActionTable, &actionTable ) ) + actionTable->id = nextActionTableId++; + } + + /* Loop the transitions and reduce their actions. */ + for ( TransList::Iter trans = st->outList; trans.lte(); trans++ ) { + if ( trans->actionTable.length() > 0 ) { + if ( actionTableMap.insert( trans->actionTable, &actionTable ) ) + actionTable->id = nextActionTableId++; + } + } + } +} + +XMLCodeGen::XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, + std::ostream &out, XmlParser &xmlParser ) +: + GenBase(fsmName, pd, fsm, xmlParser), + out(out) +{ +} + void XMLCodeGen::writeActionList() { @@ -85,47 +132,6 @@ void XMLCodeGen::writeActionTableList() delete[] tables; } -void XMLCodeGen::reduceActionTables() -{ - /* Reduce the actions tables to a set. */ - for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) { - RedActionTable *actionTable = 0; - - /* Reduce To State Actions. */ - if ( st->toStateActionTable.length() > 0 ) { - if ( actionTableMap.insert( st->toStateActionTable, &actionTable ) ) - actionTable->id = nextActionTableId++; - } - - /* Reduce From State Actions. */ - if ( st->fromStateActionTable.length() > 0 ) { - if ( actionTableMap.insert( st->fromStateActionTable, &actionTable ) ) - actionTable->id = nextActionTableId++; - } - - /* Reduce EOF actions. */ - if ( st->eofActionTable.length() > 0 ) { - if ( actionTableMap.insert( st->eofActionTable, &actionTable ) ) - actionTable->id = nextActionTableId++; - } - - /* Loop the transitions and reduce their actions. */ - for ( TransList::Iter trans = st->outList; trans.lte(); trans++ ) { - if ( trans->actionTable.length() > 0 ) { - if ( actionTableMap.insert( trans->actionTable, &actionTable ) ) - actionTable->id = nextActionTableId++; - } - } - } -} - -void XMLCodeGen::appendTrans( TransListVect &outList, Key lowKey, - Key highKey, TransAp *trans ) -{ - if ( trans->toState != 0 || trans->actionTable.length() > 0 ) - outList.append( TransEl( lowKey, highKey, trans ) ); -} - void XMLCodeGen::writeKey( Key key ) { if ( keyOps->isSigned ) @@ -442,36 +448,39 @@ void XMLCodeGen::writeInlineList( InlineList *inlineList ) } } -void XMLCodeGen::makeKey( GenInlineList *outList, Key key ) +BackendGen::BackendGen( char *fsmName, ParseData *pd, FsmAp *fsm, XmlParser &xmlParser ) +: + GenBase(fsmName, pd, fsm, xmlParser) { } -void XMLCodeGen::makeText( GenInlineList *outList, InlineItem *item ) + +void BackendGen::makeText( GenInlineList *outList, InlineItem *item ) { - GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Text ); + GenInlineItem *inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Text ); inlineItem->data = item->data; outList->append( inlineItem ); } -void XMLCodeGen::makeTargetItem( GenInlineList *outList, long targetId, GenInlineItem::Type type ) +void BackendGen::makeTargetItem( GenInlineList *outList, long entryId, GenInlineItem::Type type ) { long targetState; if ( pd->generatingSectionSubset ) targetState = -1; else { - EntryMapEl *targ = fsm->entryPoints.find( targetId ); + EntryMapEl *targ = fsm->entryPoints.find( entryId ); targetState = targ->value->alg.stateNum; } /* Make the item. */ - GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), type ); + GenInlineItem *inlineItem = new GenInlineItem( InputLoc(), type ); inlineItem->targId = targetState; outList->append( inlineItem ); } /* Make a sublist item with a given type. */ -void XMLCodeGen::makeSubList( GenInlineList *outList, +void BackendGen::makeSubList( GenInlineList *outList, InlineList *inlineList, GenInlineItem::Type type ) { /* Fill the sub list. */ @@ -479,12 +488,12 @@ void XMLCodeGen::makeSubList( GenInlineList *outList, makeGenInlineList( subList, inlineList ); /* Make the item. */ - GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), type ); + GenInlineItem *inlineItem = new GenInlineItem( InputLoc(), type ); inlineItem->children = subList; outList->append( inlineItem ); } -void XMLCodeGen::makeLmOnLast( GenInlineList *outList, InlineItem *item ) +void BackendGen::makeLmOnLast( GenInlineList *outList, InlineItem *item ) { makeSetTokend( outList, 1 ); @@ -495,10 +504,10 @@ void XMLCodeGen::makeLmOnLast( GenInlineList *outList, InlineItem *item ) } } -void XMLCodeGen::makeLmOnNext( GenInlineList *outList, InlineItem *item ) +void BackendGen::makeLmOnNext( GenInlineList *outList, InlineItem *item ) { makeSetTokend( outList, 0 ); - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Hold ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::Hold ) ); if ( item->longestMatchPart->action != 0 ) { makeSubList( outList, @@ -507,20 +516,20 @@ void XMLCodeGen::makeLmOnNext( GenInlineList *outList, InlineItem *item ) } } -void XMLCodeGen::makeExecGetTokend( GenInlineList *outList ) +void BackendGen::makeExecGetTokend( GenInlineList *outList ) { /* Make the Exec item. */ - GenInlineItem *execItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Exec ); + GenInlineItem *execItem = new GenInlineItem( InputLoc(), GenInlineItem::Exec ); execItem->children = new GenInlineList; /* Make the GetTokEnd */ - GenInlineItem *getTokend = new GenInlineItem( GenInputLoc(), GenInlineItem::LmGetTokEnd ); + GenInlineItem *getTokend = new GenInlineItem( InputLoc(), GenInlineItem::LmGetTokEnd ); execItem->children->append( getTokend ); outList->append( execItem ); } -void XMLCodeGen::makeLmOnLagBehind( GenInlineList *outList, InlineItem *item ) +void BackendGen::makeLmOnLagBehind( GenInlineList *outList, InlineItem *item ) { /* Jump to the tokend. */ makeExecGetTokend( outList ); @@ -532,9 +541,9 @@ void XMLCodeGen::makeLmOnLagBehind( GenInlineList *outList, InlineItem *item ) } } -void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item ) +void BackendGen::makeLmSwitch( GenInlineList *outList, InlineItem *item ) { - GenInlineItem *lmSwitch = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSwitch ); + GenInlineItem *lmSwitch = new GenInlineItem( InputLoc(), GenInlineItem::LmSwitch ); GenInlineList *lmList = lmSwitch->children = new GenInlineList; LongestMatch *longestMatch = item->longestMatch; @@ -548,12 +557,14 @@ void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item ) * error state. */ assert( fsm->errState != 0 ); - GenInlineItem *errCase = new GenInlineItem( GenInputLoc(), GenInlineItem::SubAction ); + GenInlineItem *errCase = new GenInlineItem( InputLoc(), GenInlineItem::SubAction ); errCase->lmId = 0; errCase->children = new GenInlineList; - makeTargetItem( errCase->children, - fsm->errState->alg.stateNum, GenInlineItem::Goto ); + /* Make the item. */ + GenInlineItem *gotoItem = new GenInlineItem( InputLoc(), GenInlineItem::Goto ); + gotoItem->targId = fsm->errState->alg.stateNum; + errCase->children->append( gotoItem ); lmList->append( errCase ); } @@ -566,7 +577,7 @@ void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item ) else { /* Open the action. Write it with the context that sets up _p * when doing control flow changes from inside the machine. */ - GenInlineItem *lmCase = new GenInlineItem( GenInputLoc(), + GenInlineItem *lmCase = new GenInlineItem( InputLoc(), GenInlineItem::SubAction ); lmCase->lmId = lmi->longestMatchId; lmCase->children = new GenInlineList; @@ -580,7 +591,7 @@ void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item ) } if ( needDefault ) { - GenInlineItem *defCase = new GenInlineItem( GenInputLoc(), + GenInlineItem *defCase = new GenInlineItem( InputLoc(), GenInlineItem::SubAction ); defCase->lmId = -1; defCase->children = new GenInlineList; @@ -593,21 +604,21 @@ void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item ) outList->append( lmSwitch ); } -void XMLCodeGen::makeSetTokend( GenInlineList *outList, long offset ) +void BackendGen::makeSetTokend( GenInlineList *outList, long offset ) { - GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetTokEnd ); + GenInlineItem *inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmSetTokEnd ); inlineItem->offset = offset; outList->append( inlineItem ); } -void XMLCodeGen::makeSetAct( GenInlineList *outList, long lmId ) +void BackendGen::makeSetAct( GenInlineList *outList, long lmId ) { - GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetActId ); + GenInlineItem *inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmSetActId ); inlineItem->lmId = lmId; outList->append( inlineItem ); } -void XMLCodeGen::makeGenInlineList( GenInlineList *outList, InlineList *inList ) +void BackendGen::makeGenInlineList( GenInlineList *outList, InlineList *inList ) { for ( InlineList::Iter item = *inList; item.lte(); item++ ) { switch ( item->type ) { @@ -633,29 +644,29 @@ void XMLCodeGen::makeGenInlineList( GenInlineList *outList, InlineList *inList ) makeSubList( outList, item->children, GenInlineItem::NextExpr ); break; case InlineItem::Break: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Break ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::Break ) ); break; case InlineItem::Ret: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Ret ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::Ret ) ); break; case InlineItem::PChar: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::PChar ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::PChar ) ); break; case InlineItem::Char: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Char ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::Char ) ); break; case InlineItem::Curs: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Curs ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::Curs ) ); break; case InlineItem::Targs: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Targs ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::Targs ) ); break; case InlineItem::Entry: makeTargetItem( outList, item->nameTarg->id, GenInlineItem::Entry ); break; case InlineItem::Hold: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Hold ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::Hold ) ); break; case InlineItem::Exec: makeSubList( outList, item->children, GenInlineItem::Exec ); @@ -682,13 +693,13 @@ void XMLCodeGen::makeGenInlineList( GenInlineList *outList, InlineList *inList ) break; case InlineItem::LmInitAct: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::LmInitAct ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::LmInitAct ) ); break; case InlineItem::LmInitTokStart: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::LmInitTokStart ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::LmInitTokStart ) ); break; case InlineItem::LmSetTokStart: - outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetTokStart ) ); + outList->append( new GenInlineItem( InputLoc(), GenInlineItem::LmSetTokStart ) ); xmlParser.cgd->hasLongestMatch = true; break; } @@ -1003,13 +1014,13 @@ void XMLCodeGen::writeXML() "\n"; } -void XMLCodeGen::makeExports() +void BackendGen::makeExports() { for ( ExportList::Iter exp = pd->exportList; exp.lte(); exp++ ) xmlParser.cgd->exportList.append( new Export( exp->name, exp->key ) ); } -void XMLCodeGen::makeAction( Action *action ) +void BackendGen::makeAction( Action *action ) { GenInlineList *genList = new GenInlineList; makeGenInlineList( genList, action->inlineList ); @@ -1019,7 +1030,7 @@ void XMLCodeGen::makeAction( Action *action ) } -void XMLCodeGen::makeActionList() +void BackendGen::makeActionList() { /* Determine which actions to write. */ int nextActionId = 0; @@ -1038,7 +1049,7 @@ void XMLCodeGen::makeActionList() } } -void XMLCodeGen::makeActionTableList() +void BackendGen::makeActionTableList() { /* Must first order the action tables based on their id. */ int numTables = nextActionTableId; @@ -1063,13 +1074,16 @@ void XMLCodeGen::makeActionTableList() atel->value->actionId; } + /* Insert into the action table map. */ + xmlParser.cgd->redFsm->actionMap.insert( redAct ); + xmlParser.curActionTable += 1; } delete[] tables; } -void XMLCodeGen::makeConditions() +void BackendGen::makeConditions() { if ( condData->condSpaceMap.length() > 0 ) { long nextCondSpaceId = 0; @@ -1090,7 +1104,7 @@ void XMLCodeGen::makeConditions() } } -bool XMLCodeGen::makeNameInst( std::string &res, NameInst *nameInst ) +bool BackendGen::makeNameInst( std::string &res, NameInst *nameInst ) { bool written = false; if ( nameInst->parent != 0 ) @@ -1106,7 +1120,7 @@ bool XMLCodeGen::makeNameInst( std::string &res, NameInst *nameInst ) return written; } -void XMLCodeGen::makeEntryPoints() +void BackendGen::makeEntryPoints() { /* List of entry points other than start state. */ if ( fsm->entryPoints.length() > 0 || pd->lmRequiresErrorState ) { @@ -1124,7 +1138,7 @@ void XMLCodeGen::makeEntryPoints() } } -void XMLCodeGen::makeStateActions( StateAp *state ) +void BackendGen::makeStateActions( StateAp *state ) { RedActionTable *toStateActions = 0; if ( state->toStateActionTable.length() > 0 ) @@ -1157,7 +1171,7 @@ void XMLCodeGen::makeStateActions( StateAp *state ) } } -void XMLCodeGen::makeEofTrans( StateAp *state ) +void BackendGen::makeEofTrans( StateAp *state ) { RedActionTable *eofActions = 0; if ( state->eofActionTable.length() > 0 ) @@ -1175,7 +1189,7 @@ void XMLCodeGen::makeEofTrans( StateAp *state ) } } -void XMLCodeGen::makeStateConditions( StateAp *state ) +void BackendGen::makeStateConditions( StateAp *state ) { if ( state->stateCondList.length() > 0 ) { long length = state->stateCondList.length(); @@ -1189,7 +1203,7 @@ void XMLCodeGen::makeStateConditions( StateAp *state ) } } -void XMLCodeGen::makeTrans( Key lowKey, Key highKey, TransAp *trans ) +void BackendGen::makeTrans( Key lowKey, Key highKey, TransAp *trans ) { /* First reduce the action. */ RedActionTable *actionTable = 0; @@ -1207,8 +1221,7 @@ void XMLCodeGen::makeTrans( Key lowKey, Key highKey, TransAp *trans ) xmlParser.cgd->newTrans( xmlParser.curState, xmlParser.curTrans++, lowKey, highKey, targ, action ); } - -void XMLCodeGen::makeTransList( StateAp *state ) +void BackendGen::makeTransList( StateAp *state ) { TransListVect outList; @@ -1231,7 +1244,7 @@ void XMLCodeGen::makeTransList( StateAp *state ) } -void XMLCodeGen::makeStateList() +void BackendGen::makeStateList() { /* Write the list of states. */ long length = fsm->stateList.length(); @@ -1254,7 +1267,7 @@ void XMLCodeGen::makeStateList() } -void XMLCodeGen::makeMachine() +void BackendGen::makeMachine() { xmlParser.cgd->createMachine(); @@ -1274,9 +1287,11 @@ void XMLCodeGen::makeMachine() makeEntryPoints(); makeStateList(); + + xmlParser.cgd->closeMachine(); } -void XMLCodeGen::makeBackend() +void BackendGen::makeBackend() { /* Open the definition. */ xmlParser.open_ragel_def( fsmName ); @@ -1364,6 +1379,8 @@ void XMLCodeGen::makeBackend() makeExports(); makeMachine(); + + xmlParser.close_ragel_def(); } diff --git a/ragel/xmlcodegen.h b/ragel/xmlcodegen.h index 3afd4d5..22d6dec 100644 --- a/ragel/xmlcodegen.h +++ b/ragel/xmlcodegen.h @@ -78,16 +78,31 @@ struct NextRedTrans } }; -class XMLCodeGen +struct GenBase +{ + GenBase( char *fsmName, ParseData *pd, FsmAp *fsm, XmlParser &xmlParser ); + + void appendTrans( TransListVect &outList, Key lowKey, Key highKey, TransAp *trans ); + void reduceActionTables(); + + char *fsmName; + ParseData *pd; + FsmAp *fsm; + XmlParser &xmlParser; + + ActionTableMap actionTableMap; + int nextActionTableId; +}; + +class XMLCodeGen : protected GenBase { public: XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, std::ostream &out, XmlParser &xmlParser ); + void writeXML( ); - void makeBackend( ); private: - void appendTrans( TransListVect &outList, Key lowKey, Key highKey, TransAp *trans ); void writeStateActions( StateAp *state ); void writeStateList(); void writeStateConditions( StateAp *state ); @@ -113,7 +128,6 @@ private: void writeActionList(); void writeActionTableList(); void reduceTrans( TransAp *trans ); - void reduceActionTables(); void writeTransList( StateAp *state ); void writeEofTrans( StateAp *state ); void writeTrans( Key lowKey, Key highKey, TransAp *defTrans ); @@ -122,6 +136,16 @@ private: void writeMachine(); void writeActionExec( InlineItem *item ); + std::ostream &out; +}; + +class BackendGen : protected GenBase +{ +public: + BackendGen( char *fsmName, ParseData *pd, FsmAp *fsm, XmlParser &xmlParser ); + void makeBackend( ); + +private: void makeGenInlineList( GenInlineList *outList, InlineList *inList ); void makeKey( GenInlineList *outList, Key key ); void makeText( GenInlineList *outList, InlineItem *item ); @@ -151,15 +175,6 @@ private: void makeStateConditions( StateAp *state ); void makeTransList( StateAp *state ); void makeTrans( Key lowKey, Key highKey, TransAp *trans ); - - char *fsmName; - ParseData *pd; - FsmAp *fsm; - std::ostream &out; - XmlParser &xmlParser; - - ActionTableMap actionTableMap; - int nextActionTableId; }; diff --git a/redfsm/gendata.cpp b/redfsm/gendata.cpp index b544a60..14124eb 100644 --- a/redfsm/gendata.cpp +++ b/redfsm/gendata.cpp @@ -668,7 +668,7 @@ void CodeGenData::analyzeMachine() setValueLimits(); } -void CodeGenData::writeStatement( GenInputLoc &loc, int nargs, char **args ) +void CodeGenData::writeStatement( InputLoc &loc, int nargs, char **args ) { /* FIXME: This should be moved to the virtual functions in the code * generators. @@ -728,13 +728,13 @@ void CodeGenData::writeStatement( GenInputLoc &loc, int nargs, char **args ) } } -ostream &CodeGenData::source_warning( const GenInputLoc &loc ) +ostream &CodeGenData::source_warning( const InputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &CodeGenData::source_error( const GenInputLoc &loc ) +ostream &CodeGenData::source_error( const InputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/redfsm/gendata.h b/redfsm/gendata.h index 4036cc7..d107202 100644 --- a/redfsm/gendata.h +++ b/redfsm/gendata.h @@ -90,7 +90,7 @@ struct CodeGenData /* This can also be overwridden to modify the processing of write * statements. */ - virtual void writeStatement( GenInputLoc &loc, int nargs, char **args ); + virtual void writeStatement( InputLoc &loc, int nargs, char **args ); /********************/ @@ -193,8 +193,8 @@ struct CodeGenData void setValueLimits(); void assignActionIds(); - ostream &source_warning( const GenInputLoc &loc ); - ostream &source_error( const GenInputLoc &loc ); + ostream &source_warning( const InputLoc &loc ); + ostream &source_error( const InputLoc &loc ); }; diff --git a/redfsm/redfsm.h b/redfsm/redfsm.h index 257d581..a1164f9 100644 --- a/redfsm/redfsm.h +++ b/redfsm/redfsm.h @@ -40,6 +40,7 @@ #include "sbstset.h" #include "sbsttable.h" + #define TRANS_ERR_TRANS 0 #define STATE_ERR_STATE 0 #define FUNC_NO_FUNC 0 @@ -50,13 +51,6 @@ struct RedStateAp; struct GenInlineList; struct GenAction; -/* Location in an input file. */ -struct GenInputLoc -{ - int line; - int col; -}; - /* * Inline code tree */ @@ -70,12 +64,12 @@ struct GenInlineItem LmInitAct, LmSetTokStart, SubAction, Break }; - GenInlineItem( const GenInputLoc &loc, Type type ) : + GenInlineItem( const InputLoc &loc, Type type ) : loc(loc), data(0), targId(0), targState(0), lmId(0), children(0), offset(0), type(type) { } - GenInputLoc loc; + InputLoc loc; char *data; int targId; RedStateAp *targState; @@ -109,7 +103,7 @@ struct GenAction } /* Data collected during parse. */ - GenInputLoc loc; + InputLoc loc; const char *name; GenInlineList *inlineList; int actionId; diff --git a/redfsm/xmlparse.kh b/redfsm/xmlparse.kh index 143bcdb..1590e20 100644 --- a/redfsm/xmlparse.kh +++ b/redfsm/xmlparse.kh @@ -156,28 +156,33 @@ struct XmlParser void init(); int parseLangEl( int type, const Token *token ); - XmlParser( const char *fileName, bool outputActive, bool wantComplete ) : - fileName(fileName), sourceFileName(0), outStream(0), - outputActive(outputActive), wantComplete(wantComplete), + XmlParser( const char *sourceFileName, const char *xmlFileName, bool outputActive, bool wantComplete ) : + sourceFileName(sourceFileName), + fileName(xmlFileName), + outStream(0), + outputActive(outputActive), + wantComplete(wantComplete), cgd(0) { } int token( int tokenId, Token &token ); int token( int tokenId, int col, int line ); int token( XMLTag *tag, int col, int line ); - void open_ragel( const char *fileName ); void open_ragel_def( char *fsmName ); + void close_ragel_def(); + + void openOutput(); /* Report an error encountered by the parser. */ - ostream &warning( const GenInputLoc &loc ); + ostream &warning( const InputLoc &loc ); ostream &error(); - ostream &error( const GenInputLoc &loc ); + ostream &error( const InputLoc &loc ); ostream &parser_error( int tokId, Token &token ); - ostream &source_error( const GenInputLoc &loc ); + ostream &source_error( const InputLoc &loc ); /* The name of the root section, this does not change during an include. */ - const char *fileName; const char *sourceFileName; + const char *fileName; ostream *outStream; bool outputActive; bool wantComplete; diff --git a/redfsm/xmlparse.kl b/redfsm/xmlparse.kl index b9b7f18..1c22651 100644 --- a/redfsm/xmlparse.kl +++ b/redfsm/xmlparse.kl @@ -39,7 +39,7 @@ unsigned long readLength( char *td ); struct Token { XMLTag *tag; - GenInputLoc loc; + InputLoc loc; }; CodeGenData *makeCodeGen( const char *sourceFileName, const char *fsmName, @@ -84,33 +84,20 @@ void genLineDirective( ostream &out ) lineDirective( out, filter->fileName, filter->line + 1 ); } -void XmlParser::open_ragel( const char *fileName ) +void XmlParser::openOutput() { - /* Check for file name attribute. */ - sourceFileName = fileName; - if ( generateDot ) outStream = dotOpenOutput( sourceFileName ); - else if ( hostLang->lang == HostLang::C ) { - hostLang = &hostLangC; + else if ( hostLang->lang == HostLang::C ) outStream = cdOpenOutput( sourceFileName ); - } - else if ( hostLang->lang == HostLang::D ) { - hostLang = &hostLangD; + else if ( hostLang->lang == HostLang::D ) outStream = cdOpenOutput( sourceFileName ); - } - else if ( hostLang->lang == HostLang::Java ) { - hostLang = &hostLangJava; + else if ( hostLang->lang == HostLang::Java ) outStream = javaOpenOutput( sourceFileName ); - } - else if ( hostLang->lang == HostLang::Ruby ) { - hostLang = &hostLangRuby; + else if ( hostLang->lang == HostLang::Ruby ) outStream = rubyOpenOutput( sourceFileName ); - } - else if ( hostLang->lang == HostLang::CSharp ) { - hostLang = &hostLangCSharp; + else if ( hostLang->lang == HostLang::CSharp ) outStream = csharpOpenOutput( sourceFileName ); - } else { assert( false ); } @@ -127,6 +114,21 @@ void XmlParser::open_ragel_def( char *fsmName ) } } +void XmlParser::close_ragel_def() +{ + /* Do this before distributing transitions out to singles and defaults + * makes life easier. */ + cgd->redFsm->maxKey = cgd->findMaxKey(); + + cgd->redFsm->assignActionLocs(); + + /* Find the first final state (The final state with the lowest id). */ + cgd->redFsm->findFirstFinState(); + + /* Call the user's callback. */ + cgd->finishRagelDef(); +} + %%{ parser XmlParser; @@ -354,7 +356,7 @@ tag_write: tag_write_head write_option_list '/' TAG_write nonterm tag_write_head { - GenInputLoc loc; + InputLoc loc; }; tag_write_head: TAG_write @@ -702,140 +704,140 @@ nonterm tag_lm_switch uses inline_item_type; tag_text: TAG_text '/' TAG_text final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Text ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Text ); $$->inlineItem->data = $3->tag->content; }; tag_goto: TAG_goto '/' TAG_goto final { int targ = strtol( $3->tag->content, 0, 10 ); - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Goto ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Goto ); $$->inlineItem->targId = targ; }; tag_call: TAG_call '/' TAG_call final { int targ = strtol( $3->tag->content, 0, 10 ); - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Call ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Call ); $$->inlineItem->targId = targ; }; tag_next: TAG_next '/' TAG_next final { int targ = strtol( $3->tag->content, 0, 10 ); - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Next ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Next ); $$->inlineItem->targId = targ; }; tag_goto_expr: TAG_goto_expr inline_list '/' TAG_goto_expr final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::GotoExpr ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::GotoExpr ); $$->inlineItem->children = $2->inlineList; }; tag_call_expr: TAG_call_expr inline_list '/' TAG_call_expr final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::CallExpr ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::CallExpr ); $$->inlineItem->children = $2->inlineList; }; tag_next_expr: TAG_next_expr inline_list '/' TAG_next_expr final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::NextExpr ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::NextExpr ); $$->inlineItem->children = $2->inlineList; }; tag_ret: TAG_ret '/' TAG_ret final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Ret ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Ret ); }; tag_break: TAG_break '/' TAG_break final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Break ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Break ); }; tag_pchar: TAG_pchar '/' TAG_pchar final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::PChar ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::PChar ); }; tag_char: TAG_char '/' TAG_char final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Char ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Char ); }; tag_hold: TAG_hold '/' TAG_hold final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Hold ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Hold ); }; tag_exec: TAG_exec inline_list '/' TAG_exec final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Exec ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Exec ); $$->inlineItem->children = $2->inlineList; }; tag_curs: TAG_curs '/' TAG_curs final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Curs ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Curs ); }; tag_targs: TAG_targs '/' TAG_targs final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Targs ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Targs ); }; tag_il_entry: TAG_entry '/' TAG_entry final { int targ = strtol( $3->tag->content, 0, 10 ); - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Entry ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::Entry ); $$->inlineItem->targId = targ; }; tag_init_tokstart: TAG_init_tokstart '/' TAG_init_tokstart final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmInitTokStart ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmInitTokStart ); }; tag_init_act: TAG_init_act '/' TAG_init_act final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmInitAct ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmInitAct ); }; tag_get_tokend: TAG_get_tokend '/' TAG_get_tokend final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmGetTokEnd ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmGetTokEnd ); }; tag_set_tokstart: TAG_set_tokstart '/' TAG_set_tokstart final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetTokStart ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmSetTokStart ); cgd->hasLongestMatch = true; }; tag_set_tokend: TAG_set_tokend '/' TAG_set_tokend final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetTokEnd ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmSetTokEnd ); $$->inlineItem->offset = strtol( $3->tag->content, 0, 10 ); }; tag_set_act: TAG_set_act '/' TAG_set_act final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetActId ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmSetActId ); $$->inlineItem->lmId = strtol( $3->tag->content, 0, 10 ); }; tag_sub_action: TAG_sub_action inline_list '/' TAG_sub_action final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::SubAction ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::SubAction ); $$->inlineItem->children = $2->inlineList; }; # Action switches. tag_lm_switch: TAG_lm_switch lm_action_list '/' TAG_lm_switch final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSwitch ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::LmSwitch ); $$->inlineItem->children = $2->inlineList; }; @@ -858,7 +860,7 @@ nonterm tag_inline_action uses inline_item_type; tag_inline_action: TAG_sub_action inline_list '/' TAG_sub_action final { - $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::SubAction ); + $$->inlineItem = new GenInlineItem( InputLoc(), GenInlineItem::SubAction ); $$->inlineItem->children = $2->inlineList; Attribute *idAttr = $1->tag->findAttr( "id" ); @@ -1016,13 +1018,13 @@ long readOffsetPtr( char *td, char **end ) return strtol( td, end, 10 ); } -ostream &XmlParser::warning( const GenInputLoc &loc ) +ostream &XmlParser::warning( const InputLoc &loc ) { cerr << fileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &XmlParser::error( const GenInputLoc &loc ) +ostream &XmlParser::error( const InputLoc &loc ) { gblErrorCount += 1; assert( fileName != 0 ); @@ -1047,7 +1049,7 @@ ostream &XmlParser::parser_error( int tokId, Token &token ) return cerr; } -ostream &XmlParser::source_error( const GenInputLoc &loc ) +ostream &XmlParser::source_error( const InputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-cd/fsmcodegen.cpp b/rlgen-cd/fsmcodegen.cpp index 2e28e0c..cbe2501 100644 --- a/rlgen-cd/fsmcodegen.cpp +++ b/rlgen-cd/fsmcodegen.cpp @@ -814,13 +814,13 @@ void FsmCodeGen::finishRagelDef() calcIndexSize(); } -ostream &FsmCodeGen::source_warning( const GenInputLoc &loc ) +ostream &FsmCodeGen::source_warning( const InputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &FsmCodeGen::source_error( const GenInputLoc &loc ) +ostream &FsmCodeGen::source_error( const InputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-cd/fsmcodegen.h b/rlgen-cd/fsmcodegen.h index 853a38e..4f1561d 100644 --- a/rlgen-cd/fsmcodegen.h +++ b/rlgen-cd/fsmcodegen.h @@ -165,8 +165,8 @@ protected: virtual string CTRL_FLOW() = 0; - ostream &source_warning(const GenInputLoc &loc); - ostream &source_error(const GenInputLoc &loc); + ostream &source_warning(const InputLoc &loc); + ostream &source_error(const InputLoc &loc); unsigned int arrayTypeSize( unsigned long maxVal ); diff --git a/rlgen-cd/rlgen-cd.h b/rlgen-cd/rlgen-cd.h index c11903b..4ed66d1 100644 --- a/rlgen-cd/rlgen-cd.h +++ b/rlgen-cd/rlgen-cd.h @@ -30,8 +30,6 @@ #include "config.h" #include "common.h" -#define PROGNAME "rlgen-cd" - extern CodeStyleEnum codeStyle; /* IO filenames and stream. */ diff --git a/rlgen-csharp/fsmcodegen.cpp b/rlgen-csharp/fsmcodegen.cpp index 32e2e6f..a1b1c5d 100644 --- a/rlgen-csharp/fsmcodegen.cpp +++ b/rlgen-csharp/fsmcodegen.cpp @@ -777,13 +777,13 @@ void CSharpFsmCodeGen::finishRagelDef() calcIndexSize(); } -ostream &CSharpFsmCodeGen::source_warning( const GenInputLoc &loc ) +ostream &CSharpFsmCodeGen::source_warning( const InputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &CSharpFsmCodeGen::source_error( const GenInputLoc &loc ) +ostream &CSharpFsmCodeGen::source_error( const InputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-csharp/fsmcodegen.h b/rlgen-csharp/fsmcodegen.h index 33c8694..6b996ce 100644 --- a/rlgen-csharp/fsmcodegen.h +++ b/rlgen-csharp/fsmcodegen.h @@ -164,8 +164,8 @@ protected: virtual string CTRL_FLOW() = 0; - ostream &source_warning(const GenInputLoc &loc); - ostream &source_error(const GenInputLoc &loc); + ostream &source_warning(const InputLoc &loc); + ostream &source_error(const InputLoc &loc); unsigned int arrayTypeSize( unsigned long maxVal ); diff --git a/rlgen-csharp/main.cpp b/rlgen-csharp/main.cpp index cad29b2..121a2d7 100644 --- a/rlgen-csharp/main.cpp +++ b/rlgen-csharp/main.cpp @@ -67,42 +67,6 @@ extern bool graphvizDone; extern int numSplitPartitions; extern bool noLineDirectives; -/* Print a summary of the options. */ -void csharp_usage() -{ - cout << -"usage: " PROGNAME " [options] file\n" -"general:\n" -" -h, -H, -?, --help Print this usage and exit\n" -" -v, --version Print version information and exit\n" -" -o Write output to \n" -"code generation options:\n" -" -L Inhibit writing of #line directives\n" -"generated code style:\n" -" -T0 Table driven FSM (default)\n" -" -T1 Faster table driven FSM\n" -" -F0 Flat table driven FSM\n" -" -F1 Faster flat table-driven FSM\n" -" -G0 Goto-driven FSM\n" -" -G1 Faster goto-driven FSM\n" - ; -} - -/* Print version information. */ -void csharp_version() -{ - cout << "Ragel Code Generator for C#" << endl << - "Version " VERSION << ", " PUBDATE << endl << - "Copyright (c) 2001-2007 by Adrian Thurston" << endl; -} - -ostream &csharp_error() -{ - gblErrorCount += 1; - cerr << PROGNAME ": "; - return cerr; -} - /* * Callbacks invoked by the XML data parser. */ @@ -111,7 +75,7 @@ ostream &csharp_error() ostream *csharpOpenOutput( const char *inputFile ) { if ( hostLang->lang != HostLang::CSharp ) { - csharp_error() << "this code generator is for C# only" << endl; + error() << "this code generator is for C# only" << endl; exit(1); } @@ -127,7 +91,7 @@ ostream *csharpOpenOutput( const char *inputFile ) /* Make sure we are not writing to the same file as the input file. */ if ( outputFileName != 0 && strcmp( inputFile, outputFileName ) == 0 ) { - csharp_error() << "output file \"" << outputFileName << + error() << "output file \"" << outputFileName << "\" is the same as the input file" << endl; } @@ -136,7 +100,7 @@ ostream *csharpOpenOutput( const char *inputFile ) outFilter = new output_filter( outputFileName ); outFilter->open( outputFileName, ios::out|ios::trunc ); if ( !outFilter->is_open() ) { - csharp_error() << "error opening " << outputFileName << " for writing" << endl; + error() << "error opening " << outputFileName << " for writing" << endl; exit(1); } diff --git a/rlgen-csharp/rlgen-csharp.h b/rlgen-csharp/rlgen-csharp.h index de69af4..a586d16 100644 --- a/rlgen-csharp/rlgen-csharp.h +++ b/rlgen-csharp/rlgen-csharp.h @@ -30,8 +30,6 @@ #include "config.h" #include "common.h" -#define PROGNAME "rlgen-csharp" - extern CodeStyleEnum codeStyle; diff --git a/rlgen-dot/gvdotgen.cpp b/rlgen-dot/gvdotgen.cpp index 57898b2..b02ef74 100644 --- a/rlgen-dot/gvdotgen.cpp +++ b/rlgen-dot/gvdotgen.cpp @@ -26,7 +26,7 @@ using namespace std; /* Override this so that write statement processing is ignored */ -void GraphvizDotGen::writeStatement( GenInputLoc &, int, char ** ) +void GraphvizDotGen::writeStatement( InputLoc &, int, char ** ) { } diff --git a/rlgen-dot/gvdotgen.h b/rlgen-dot/gvdotgen.h index 5f1af60..62ac583 100644 --- a/rlgen-dot/gvdotgen.h +++ b/rlgen-dot/gvdotgen.h @@ -35,7 +35,7 @@ public: void writeDotFile( ); virtual void finishRagelDef(); - virtual void writeStatement( GenInputLoc &, int, char ** ); + virtual void writeStatement( InputLoc &, int, char ** ); private: /* Writing labels and actions. */ diff --git a/rlgen-dot/rlgen-dot.h b/rlgen-dot/rlgen-dot.h index cbd55f7..709c4e3 100644 --- a/rlgen-dot/rlgen-dot.h +++ b/rlgen-dot/rlgen-dot.h @@ -29,8 +29,6 @@ #include "vector.h" #include "config.h" -#define PROGNAME "rlgen-dot" - /* IO filenames and stream. */ extern bool displayPrintables; extern bool graphvizDone; diff --git a/rlgen-java/javacodegen.cpp b/rlgen-java/javacodegen.cpp index 7f68ae7..763c495 100644 --- a/rlgen-java/javacodegen.cpp +++ b/rlgen-java/javacodegen.cpp @@ -1642,13 +1642,13 @@ void JavaTabCodeGen::finishRagelDef() calcIndexSize(); } -ostream &JavaTabCodeGen::source_warning( const GenInputLoc &loc ) +ostream &JavaTabCodeGen::source_warning( const InputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &JavaTabCodeGen::source_error( const GenInputLoc &loc ) +ostream &JavaTabCodeGen::source_error( const InputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-java/javacodegen.h b/rlgen-java/javacodegen.h index 78b7cde..decb4bd 100644 --- a/rlgen-java/javacodegen.h +++ b/rlgen-java/javacodegen.h @@ -179,8 +179,8 @@ public: string ERROR_STATE(); string FIRST_FINAL_STATE(); - ostream &source_warning(const GenInputLoc &loc); - ostream &source_error(const GenInputLoc &loc); + ostream &source_warning(const InputLoc &loc); + ostream &source_error(const InputLoc &loc); unsigned int arrayTypeSize( unsigned long maxVal ); diff --git a/rlgen-java/rlgen-java.h b/rlgen-java/rlgen-java.h index 7e5e07b..0a9d5cd 100644 --- a/rlgen-java/rlgen-java.h +++ b/rlgen-java/rlgen-java.h @@ -25,8 +25,6 @@ #include #include "config.h" -#define PROGNAME "rlgen-java" - extern int gblErrorCount; std::ostream &error(); diff --git a/rlgen-ruby/rlgen-ruby.h b/rlgen-ruby/rlgen-ruby.h index 77ebc69..ad64226 100644 --- a/rlgen-ruby/rlgen-ruby.h +++ b/rlgen-ruby/rlgen-ruby.h @@ -27,8 +27,6 @@ #include "config.h" #include "common.h" -#define PROGNAME "rlgen-ruby" - extern RubyImplEnum rubyImpl; extern CodeStyleEnum codeStyle; diff --git a/rlgen-ruby/ruby-codegen.cpp b/rlgen-ruby/ruby-codegen.cpp index f69606e..8974af6 100644 --- a/rlgen-ruby/ruby-codegen.cpp +++ b/rlgen-ruby/ruby-codegen.cpp @@ -639,13 +639,13 @@ int RubyCodeGen::TRANS_ACTION( RedTransAp *trans ) return act; } -ostream &RubyCodeGen::source_warning( const GenInputLoc &loc ) +ostream &RubyCodeGen::source_warning( const InputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &RubyCodeGen::source_error( const GenInputLoc &loc ) +ostream &RubyCodeGen::source_error( const InputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-ruby/ruby-codegen.h b/rlgen-ruby/ruby-codegen.h index f9fdf1b..1b62856 100644 --- a/rlgen-ruby/ruby-codegen.h +++ b/rlgen-ruby/ruby-codegen.h @@ -155,8 +155,8 @@ protected: void SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish ); protected: - ostream &source_warning(const GenInputLoc &loc); - ostream &source_error(const GenInputLoc &loc); + ostream &source_warning(const InputLoc &loc); + ostream &source_error(const InputLoc &loc); /* fields */ -- 2.7.4