Don't segfault when there are no machine instantiations.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sat, 1 Aug 2009 03:48:51 +0000 (03:48 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sat, 1 Aug 2009 03:48:51 +0000 (03:48 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@976 052ea7fc-9027-0410-9066-f65837a77df0

ragel/inputdata.cpp
ragel/inputdata.h
ragel/main.cpp
ragel/rlscan.rl

index 29d02eb..ac837d5 100644 (file)
@@ -207,12 +207,22 @@ void InputData::terminateAllParsers( )
                pdel->value->token( loc, Parser_tk_eof, 0, 0 );
 }
 
+void InputData::verifyWritesHaveData()
+{
+       if ( !generateXML && !generateDot ) {
+               for ( InputItemList::Iter ii = inputItems; ii.lte(); ii++ ) {
+                       if ( ii->type == InputItem::Write ) {
+                               if ( ii->pd->cgd == 0 )
+                                       error( ii->loc ) << "no machine instantiations to write" << endl;
+                       }
+               }
+       }
+}
 
 void InputData::writeOutput()
 {
-       if ( generateXML ) {
+       if ( generateXML )
                writeXML( *outStream );
-       }
        else if ( generateDot )
                static_cast<GraphvizDotGen*>(dotGenParser->pd->cgd)->writeDotFile();
        else {
index a2c9ae8..045be56 100644 (file)
@@ -83,6 +83,8 @@ struct InputData
 
        ArgsVector includePaths;
 
+       void verifyWritesHaveData();
+
        void writeOutput();
        void makeOutputStream();
        void openOutput();
index 5894c3c..2b54b51 100644 (file)
@@ -450,6 +450,7 @@ void process( InputData &id )
        /* Make the first input item. */
        InputItem *firstInputItem = new InputItem;
        firstInputItem->type = InputItem::HostData;
+       firstInputItem->loc.fileName = id.inputFileName;
        firstInputItem->loc.line = 1;
        firstInputItem->loc.col = 1;
        id.inputItems.append( firstInputItem );
@@ -484,7 +485,11 @@ void process( InputData &id )
                if ( gblErrorCount > 0 )
                        exit(1);
        }
-       
+
+       id.verifyWritesHaveData();
+       if ( gblErrorCount > 0 )
+               exit(1);
+
        /*
         * From this point on we should not be reporting any errors.
         */
index 3c325c3..3ec0469 100644 (file)
@@ -413,6 +413,7 @@ void Scanner::handleImport()
                if ( active() && machineSpec == 0 && machineName == 0 ) {
                        InputItem *inputItem = new InputItem;
                        inputItem->type = InputItem::Write;
+                       inputItem->loc.fileName = fileName;
                        inputItem->loc.line = line;
                        inputItem->loc.col = column;
                        inputItem->name = parser->sectionName;