We don't need to create allocate the outpute file stream and open the file at
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 15 Mar 2009 01:19:07 +0000 (01:19 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 15 Mar 2009 01:19:07 +0000 (01:19 +0000)
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

ragel/cdcodegen.cpp
ragel/cscodegen.cpp
ragel/dotcodegen.cpp
ragel/inputdata.cpp
ragel/inputdata.h
ragel/javacodegen.cpp
ragel/main.cpp
ragel/rubycodegen.cpp

index afb1410..f60320f 100644 (file)
@@ -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 );
index eddae7d..c653010 100644 (file)
@@ -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 );
index 3043e15..572bc72 100644 (file)
@@ -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 );
index 4b8446b..aeb2c71 100644 (file)
@@ -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. */
index d40bc5d..de2f8de 100644 (file)
@@ -44,6 +44,7 @@ struct InputData
        void writeOutput();
        void generateSpecificReduced();
        void openOutput();
+       void openOutput2();
        void generateReduced();
        void prepareMachineGen();
 };
index 6936aa3..14d98eb 100644 (file)
@@ -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 );
index 28b2126..120fae7 100644 (file)
@@ -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. */
index f285c58..eb27ac7 100644 (file)
@@ -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 );