From ed400726cb1384e8b15ba031eccae322605600a5 Mon Sep 17 00:00:00 2001 From: thurston Date: Sat, 21 Mar 2009 20:23:13 +0000 Subject: [PATCH] The main inputData (id) is no longer a global. It is allocated in main() before processing arguments. git-svn-id: http://svn.complang.org/ragel/trunk@752 052ea7fc-9027-0410-9066-f65837a77df0 --- ragel/inputdata.h | 5 +++-- ragel/main.cpp | 17 +++++++---------- ragel/rlscan.h | 6 ++++-- ragel/rlscan.rl | 4 ++-- ragel/xmlcodegen.cpp | 12 ++++++------ 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ragel/inputdata.h b/ragel/inputdata.h index 0420a29..f072bb7 100644 --- a/ragel/inputdata.h +++ b/ragel/inputdata.h @@ -94,8 +94,9 @@ struct InputData void javaDefaultFileName( const char *inputFile ); void rubyDefaultFileName( const char *inputFile ); void csharpDefaultFileName( const char *inputFile ); -}; -extern InputData id; + void writeLanguage( std::ostream &out ); + void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName ); +}; #endif diff --git a/ragel/main.cpp b/ragel/main.cpp index 4e7f676..3a5e3df 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -71,8 +71,6 @@ using std::streamsize; MinimizeLevel minimizeLevel = MinimizePartition2; MinimizeOpt minimizeOpt = MinimizeMostOps; -InputData id; - /* Graphviz dot file generation. */ const char *machineSpec = 0, *machineName = 0; bool machineSpecFound = false; @@ -217,7 +215,7 @@ void escapeLineDirectivePath( std::ostream &out, char *path ) } } -void processArgs( int argc, const char **argv ) +void processArgs( int argc, const char **argv, InputData &id ) { ParamCheck pc("xo:dnmleabjkS:M:I:CDJRAvHh?-:sT:F:G:P:LpV", argc, argv); @@ -436,7 +434,7 @@ void processArgs( int argc, const char **argv ) } } -void process() +void process( InputData &id ) { /* Open the input file for reading. */ assert( id.inputFileName != 0 ); @@ -454,7 +452,7 @@ void process() firstInputItem->loc.col = 1; id.inputItems.append( firstInputItem ); - Scanner scanner( id.inputFileName, *inFile, 0, 0, 0, false ); + Scanner scanner( id, id.inputFileName, *inFile, 0, 0, 0, false ); scanner.do_scan(); /* Finished, final check for errors.. */ @@ -528,7 +526,9 @@ char *makeIntermedTemplate( const char *baseFileName ) /* Main, process args and call yyparse to start scanning input. */ int main( int argc, const char **argv ) { - processArgs( argc, argv ); + InputData id; + + processArgs( argc, argv, id ); /* If -M or -S are given and we're not generating a dot file then invoke * the frontend. These options are not useful with code generators. */ @@ -554,10 +554,7 @@ int main( int argc, const char **argv ) "\" is the same as the input file" << endp; } - process(); - - /* Clean up the intermediate. */ - exit( 0 ); + process( id ); return 0; } diff --git a/ragel/rlscan.h b/ragel/rlscan.h index c15c009..b56bd60 100644 --- a/ragel/rlscan.h +++ b/ragel/rlscan.h @@ -37,11 +37,12 @@ extern char *Parser_lelNames[]; struct Scanner { - Scanner( const char *fileName, istream &input, + Scanner( InputData &id, const char *fileName, istream &input, Parser *inclToParser, char *inclSectionTarg, int includeDepth, bool importMachines ) : - fileName(fileName), input(input), + id(id), fileName(fileName), + input(input), inclToParser(inclToParser), inclSectionTarg(inclSectionTarg), includeDepth(includeDepth), @@ -82,6 +83,7 @@ struct Scanner bool active(); ostream &scan_error(); + InputData &id; const char *fileName; istream &input; Parser *inclToParser; diff --git a/ragel/rlscan.rl b/ragel/rlscan.rl index 6a99cc7..6dc2804 100644 --- a/ragel/rlscan.rl +++ b/ragel/rlscan.rl @@ -338,7 +338,7 @@ void Scanner::handleInclude() parser->includeHistory.append( IncludeHistoryItem( includeChecks[found], inclSectionName ) ); - Scanner scanner( includeChecks[found], *inFile, parser, + Scanner scanner( id, includeChecks[found], *inFile, parser, inclSectionName, includeDepth+1, false ); scanner.do_scan( ); delete inFile; @@ -363,7 +363,7 @@ void Scanner::handleImport() scan_error() << "import: attempted: \"" << *tried++ << '\"' << endl; } - Scanner scanner( importChecks[found], *inFile, parser, + Scanner scanner( id, importChecks[found], *inFile, parser, 0, includeDepth+1, true ); scanner.do_scan( ); scanner.importToken( 0, 0, 0 ); diff --git a/ragel/xmlcodegen.cpp b/ragel/xmlcodegen.cpp index bd4c2d0..91ee3f7 100644 --- a/ragel/xmlcodegen.cpp +++ b/ragel/xmlcodegen.cpp @@ -1398,7 +1398,7 @@ void BackendGen::makeBackend() close_ragel_def(); } -void writeLanguage( std::ostream &out ) +void InputData::writeLanguage( std::ostream &out ) { out << " lang=\""; switch ( hostLang->lang ) { @@ -1411,11 +1411,11 @@ void writeLanguage( std::ostream &out ) out << "\""; } -void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName ) +void InputData::writeMachines( std::ostream &out, std::string hostData, const char *inputFileName ) { if ( machineSpec == 0 && machineName == 0 ) { /* No machine spec or machine name given. Generate everything. */ - for ( ParserDict::Iter parser = id.parserDict; parser.lte(); parser++ ) { + for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) { ParseData *pd = parser->value->pd; if ( pd->instanceList.length() > 0 ) pd->prepareMachineGen( 0 ); @@ -1425,7 +1425,7 @@ void writeMachines( std::ostream &out, std::string hostData, const char *inputFi out << "\n"; - for ( ParserDict::Iter parser = id.parserDict; parser.lte(); parser++ ) { + for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) { ParseData *pd = parser->value->pd; if ( pd->instanceList.length() > 0 ) pd->generateXML( out ); @@ -1434,14 +1434,14 @@ void writeMachines( std::ostream &out, std::string hostData, const char *inputFi out << "\n"; } } - else if ( id.parserDict.length() > 0 ) { + else if ( parserDict.length() > 0 ) { /* There is either a machine spec or machine name given. */ ParseData *parseData = 0; GraphDictEl *graphDictEl = 0; /* Traverse the sections, break out when we find a section/machine * that matches the one specified. */ - for ( ParserDict::Iter parser = id.parserDict; parser.lte(); parser++ ) { + for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) { ParseData *checkPd = parser->value->pd; if ( machineSpec == 0 || strcmp( checkPd->sectionName, machineSpec ) == 0 ) { GraphDictEl *checkGdEl = 0; -- 2.7.4