From: thurston Date: Sun, 15 Mar 2009 01:19:07 +0000 (+0000) Subject: We don't need to create allocate the outpute file stream and open the file at X-Git-Tag: 2.0_alpha~65 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4dc524c6c03bece7f37b9d4befa78512f67007f6;p=external%2Fragel.git We don't need to create allocate the outpute file stream and open the file at the same time. Allocate the stream when the code generator is allocated, but open the output after the reduced machine is fully built, just before the write. git-svn-id: http://svn.complang.org/ragel/trunk@735 052ea7fc-9027-0410-9066-f65837a77df0 --- diff --git a/ragel/cdcodegen.cpp b/ragel/cdcodegen.cpp index afb1410..f60320f 100644 --- a/ragel/cdcodegen.cpp +++ b/ragel/cdcodegen.cpp @@ -102,11 +102,6 @@ ostream *cdOpenOutput( const char *inputFile ) if ( outputFileName != 0 ) { /* Create the filter on the output and open it. */ outFilter = new output_filter( outputFileName ); - outFilter->open( outputFileName, ios::out|ios::trunc ); - if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; - exit(1); - } /* Open the output stream, attaching it to the filter. */ outStream = new ostream( outFilter ); diff --git a/ragel/cscodegen.cpp b/ragel/cscodegen.cpp index eddae7d..c653010 100644 --- a/ragel/cscodegen.cpp +++ b/ragel/cscodegen.cpp @@ -82,11 +82,6 @@ ostream *csharpOpenOutput( const char *inputFile ) if ( outputFileName != 0 ) { /* Create the filter on the output and open it. */ outFilter = new output_filter( outputFileName ); - outFilter->open( outputFileName, ios::out|ios::trunc ); - if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; - exit(1); - } /* Open the output stream, attaching it to the filter. */ outStream = new ostream( outFilter ); diff --git a/ragel/dotcodegen.cpp b/ragel/dotcodegen.cpp index 3043e15..572bc72 100644 --- a/ragel/dotcodegen.cpp +++ b/ragel/dotcodegen.cpp @@ -44,11 +44,6 @@ ostream *dotOpenOutput( const char *inputFile ) if ( outputFileName != 0 ) { /* Create the filter on the output and open it. */ outFilter = new output_filter( outputFileName ); - outFilter->open( outputFileName, ios::out|ios::trunc ); - if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; - exit(1); - } /* Open the output stream, attaching it to the filter. */ outStream = new ostream( outFilter ); diff --git a/ragel/inputdata.cpp b/ragel/inputdata.cpp index 4b8446b..aeb2c71 100644 --- a/ragel/inputdata.cpp +++ b/ragel/inputdata.cpp @@ -29,6 +29,7 @@ using std::cout; using std::cerr; using std::endl; +using std::ios; void InputData::generateSpecificReduced() { @@ -88,6 +89,17 @@ void InputData::openOutput() } } +void InputData::openOutput2() +{ + if ( outFilter != 0 ) { + outFilter->open( outputFileName, ios::out|ios::trunc ); + if ( !outFilter->is_open() ) { + error() << "error opening " << outputFileName << " for writing" << endl; + exit(1); + } + } +} + void InputData::prepareMachineGen() { /* No machine spec or machine name given. Generate everything. */ diff --git a/ragel/inputdata.h b/ragel/inputdata.h index d40bc5d..de2f8de 100644 --- a/ragel/inputdata.h +++ b/ragel/inputdata.h @@ -44,6 +44,7 @@ struct InputData void writeOutput(); void generateSpecificReduced(); void openOutput(); + void openOutput2(); void generateReduced(); void prepareMachineGen(); }; diff --git a/ragel/javacodegen.cpp b/ragel/javacodegen.cpp index 6936aa3..14d98eb 100644 --- a/ragel/javacodegen.cpp +++ b/ragel/javacodegen.cpp @@ -82,11 +82,6 @@ ostream *javaOpenOutput( const char *inputFile ) if ( outputFileName != 0 ) { /* Create the filter on the output and open it. */ outFilter = new output_filter( outputFileName ); - outFilter->open( outputFileName, ios::out|ios::trunc ); - if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; - exit(1); - } /* Open the output stream, attaching it to the filter. */ outStream = new ostream( outFilter ); diff --git a/ragel/main.cpp b/ragel/main.cpp index 28b2126..120fae7 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -503,6 +503,7 @@ void process( const char *inputFileName ) if ( gblErrorCount > 0 ) exit(1); + inputData.openOutput2(); inputData.writeOutput(); /* Close the input and the intermediate file. */ diff --git a/ragel/rubycodegen.cpp b/ragel/rubycodegen.cpp index f285c58..eb27ac7 100644 --- a/ragel/rubycodegen.cpp +++ b/ragel/rubycodegen.cpp @@ -101,11 +101,6 @@ ostream *rubyOpenOutput( const char *inputFile ) if ( outputFileName != 0 ) { /* Create the filter on the output and open it. */ outFilter = new output_filter( outputFileName ); - outFilter->open( outputFileName, ios::out|ios::trunc ); - if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; - exit(1); - } /* Open the output stream, attaching it to the filter. */ outStream = new ostream( outFilter );