More work on the direct connection between frontend and backend. Now appears to
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 26 Oct 2008 01:36:54 +0000 (01:36 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 26 Oct 2008 01:36:54 +0000 (01:36 +0000)
work. Test suite is passing.

git-svn-id: http://svn.complang.org/ragel/trunk@497 052ea7fc-9027-0410-9066-f65837a77df0

31 files changed:
common/common.h
ragel/main.cpp
ragel/parsedata.cpp
ragel/parsedata.h
ragel/ragel.h
ragel/rlparse.kl
ragel/rlscan.h
ragel/rlscan.rl
ragel/xmlcodegen.cpp
ragel/xmlcodegen.h
redfsm/gendata.cpp
redfsm/gendata.h
redfsm/redfsm.h
redfsm/xmlparse.kh
redfsm/xmlparse.kl
rlgen-cd/fsmcodegen.cpp
rlgen-cd/fsmcodegen.h
rlgen-cd/rlgen-cd.h
rlgen-csharp/fsmcodegen.cpp
rlgen-csharp/fsmcodegen.h
rlgen-csharp/main.cpp
rlgen-csharp/rlgen-csharp.h
rlgen-dot/gvdotgen.cpp
rlgen-dot/gvdotgen.h
rlgen-dot/rlgen-dot.h
rlgen-java/javacodegen.cpp
rlgen-java/javacodegen.h
rlgen-java/rlgen-java.h
rlgen-ruby/rlgen-ruby.h
rlgen-ruby/ruby-codegen.cpp
rlgen-ruby/ruby-codegen.h

index 4185a82..0f0cf1b 100644 (file)
 #include <climits>
 #include "dlist.h"
 
+/* Location in an input file. */
+struct InputLoc
+{
+       const char *fileName;
+       long line;
+       long col;
+};
+
+
 typedef unsigned long long Size;
 
 struct Key
index 0f76f7b..40fc456 100644 (file)
@@ -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 << "<host line=\"1\" col=\"1\">";
-
-       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 << "</host>\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. */
index 0918cf5..b9579d2 100644 (file)
@@ -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();
        }
 }
index 605264b..8149b15 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <iostream>
 #include <limits.h>
+#include <sstream>
 #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<char *> 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<char*, Parser *, CmpStr> ParserDict;
 typedef AvlMapEl<char*, Parser *> ParserDictEl;
 
-extern ParserDict parserDict;
+typedef DList<InputItem> InputItemList;
 
+extern ParserDict parserDict;
+extern InputItemList inputItems;
 
 #endif /* _PARSEDATA_H */
index 54a93b2..e49aefc 100644 (file)
@@ -28,6 +28,7 @@
 #include <string>
 #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<const char *> ArgsVector;
index ece1786..c6731de 100644 (file)
@@ -30,6 +30,7 @@ using std::cerr;
 using std::endl;
 
 ParserDict parserDict;
+InputItemList inputItems;
 
 %%{
 
index 4c07bf8..553a5c8 100644 (file)
@@ -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;
index 40bb918..f31dd37 100644 (file)
@@ -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 << "<write"
-                                       " def_name=\"" << parser->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 << "<arg>" << tokdata << "</arg>";
+                       inputItems.tail->writeArgs.append( strdup(tokdata) );
        }
 
        action write_close
        {
                if ( active() && machineSpec == 0 && machineName == 0 )
-                       output << "</write>\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 << "</host>\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 << "<host line=\"" << line << "\">";
+                       InputItem *inputItem = new InputItem;
+                       inputItem->type = InputItem::HostData;
+                       inputItem->loc.line = line;
+                       inputItem->loc.col = column;
+                       inputItems.append( inputItem );
                }
        }
 }
index 66bddca..0d0f223 100644 (file)
 
 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()
                "</ragel_def>\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();
 }
 
 
index 3afd4d5..22d6dec 100644 (file)
@@ -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;
 };
 
 
index b544a60..14124eb 100644 (file)
@@ -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 );
index 4036cc7..d107202 100644 (file)
@@ -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 );
 };
 
 
index 257d581..a1164f9 100644 (file)
@@ -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;
index 143bcdb..1590e20 100644 (file)
@@ -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;
index b9b7f18..1c22651 100644 (file)
@@ -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 );
index 2e28e0c..cbe2501 100644 (file)
@@ -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 );
index 853a38e..4f1561d 100644 (file)
@@ -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 );
 
index c11903b..4ed66d1 100644 (file)
@@ -30,8 +30,6 @@
 #include "config.h"
 #include "common.h"
 
-#define PROGNAME "rlgen-cd"
-
 extern CodeStyleEnum codeStyle;
 
 /* IO filenames and stream. */
index 32e2e6f..a1b1c5d 100644 (file)
@@ -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 );
index 33c8694..6b996ce 100644 (file)
@@ -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 );
 
index cad29b2..121a2d7 100644 (file)
@@ -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 <file>             Write output to <file>\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);
                }
 
index de69af4..a586d16 100644 (file)
@@ -30,8 +30,6 @@
 #include "config.h"
 #include "common.h"
 
-#define PROGNAME "rlgen-csharp"
-
 extern CodeStyleEnum codeStyle;
 
 
index 57898b2..b02ef74 100644 (file)
@@ -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 ** )
 {
 }
 
index 5f1af60..62ac583 100644 (file)
@@ -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. */
index cbd55f7..709c4e3 100644 (file)
@@ -29,8 +29,6 @@
 #include "vector.h"
 #include "config.h"
 
-#define PROGNAME "rlgen-dot"
-
 /* IO filenames and stream. */
 extern bool displayPrintables;
 extern bool graphvizDone;
index 7f68ae7..763c495 100644 (file)
@@ -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 );
index 78b7cde..decb4bd 100644 (file)
@@ -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 );
 
index 7e5e07b..0a9d5cd 100644 (file)
@@ -25,8 +25,6 @@
 #include <iostream>
 #include "config.h"
 
-#define PROGNAME "rlgen-java"
-
 extern int gblErrorCount;
 std::ostream &error();
 
index 77ebc69..ad64226 100644 (file)
@@ -27,8 +27,6 @@
 #include "config.h"
 #include "common.h"
 
-#define PROGNAME "rlgen-ruby"
-
 extern RubyImplEnum rubyImpl;
 extern CodeStyleEnum codeStyle;
 
index f69606e..8974af6 100644 (file)
@@ -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 );
index f9fdf1b..1b62856 100644 (file)
@@ -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 */