From fa7ba07c21752babde000979dc44b00e302e1f07 Mon Sep 17 00:00:00 2001 From: thurston Date: Sat, 1 Aug 2009 03:48:51 +0000 Subject: [PATCH] Don't segfault when there are no machine instantiations. git-svn-id: http://svn.complang.org/ragel/trunk@976 052ea7fc-9027-0410-9066-f65837a77df0 --- ragel/inputdata.cpp | 14 ++++++++++++-- ragel/inputdata.h | 2 ++ ragel/main.cpp | 7 ++++++- ragel/rlscan.rl | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ragel/inputdata.cpp b/ragel/inputdata.cpp index 29d02eb..ac837d5 100644 --- a/ragel/inputdata.cpp +++ b/ragel/inputdata.cpp @@ -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(dotGenParser->pd->cgd)->writeDotFile(); else { diff --git a/ragel/inputdata.h b/ragel/inputdata.h index a2c9ae8..045be56 100644 --- a/ragel/inputdata.h +++ b/ragel/inputdata.h @@ -83,6 +83,8 @@ struct InputData ArgsVector includePaths; + void verifyWritesHaveData(); + void writeOutput(); void makeOutputStream(); void openOutput(); diff --git a/ragel/main.cpp b/ragel/main.cpp index 5894c3c..2b54b51 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -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. */ diff --git a/ragel/rlscan.rl b/ragel/rlscan.rl index 3c325c3..3ec0469 100644 --- a/ragel/rlscan.rl +++ b/ragel/rlscan.rl @@ -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; -- 2.7.4