Some cleanup of output stream opening.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 15 Mar 2009 13:47:53 +0000 (13:47 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 15 Mar 2009 13:47:53 +0000 (13:47 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@736 052ea7fc-9027-0410-9066-f65837a77df0

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

index f60320f..6965c09 100644 (file)
@@ -68,51 +68,6 @@ extern bool graphvizDone;
 extern int numSplitPartitions;
 extern bool noLineDirectives;
 
-/* Invoked by the parser when the root element is opened. */
-ostream *cdOpenOutput( const char *inputFile )
-{
-       if ( hostLang->lang != HostLang::C && hostLang->lang != HostLang::D ) {
-               error() << "this code generator is for C and D only" << endl;
-               exit(1);
-       }
-
-       /* If the output format is code and no output file name is given, then
-        * make a default. */
-       if ( outputFileName == 0 ) {
-               const char *ext = findFileExtension( inputFile );
-               if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
-                       outputFileName = fileNameFromStem( inputFile, ".h" );
-               else {
-                       const char *defExtension = 0;
-                       switch ( hostLang->lang ) {
-                               case HostLang::C: defExtension = ".c"; break;
-                               case HostLang::D: defExtension = ".d"; break;
-                               default: break;
-                       }
-                       outputFileName = fileNameFromStem( inputFile, defExtension );
-               }
-       }
-
-       /* Make sure we are not writing to the same file as the input file. */
-       if ( outputFileName != 0 && strcmp( inputFile, outputFileName  ) == 0 ) {
-               error() << "output file \"" << outputFileName  << 
-                               "\" is the same as the input file" << endl;
-       }
-
-       if ( outputFileName != 0 ) {
-               /* Create the filter on the output and open it. */
-               outFilter = new output_filter( outputFileName );
-
-               /* Open the output stream, attaching it to the filter. */
-               outStream = new ostream( outFilter );
-       }
-       else {
-               /* Writing out ot std out. */
-               outStream = &cout;
-       }
-       return outStream;
-}
-
 /* Invoked by the parser when a ragel definition is opened. */
 CodeGenData *cdMakeCodeGen( const char *sourceFileName, const char *fsmName, 
                ostream &out, bool wantComplete )
index c653010..e0c032b 100644 (file)
@@ -55,44 +55,6 @@ using std::cout;
 using std::cerr;
 using std::endl;
 
-/* Invoked by the parser when the root element is opened. */
-ostream *csharpOpenOutput( const char *inputFile )
-{
-       if ( hostLang->lang != HostLang::CSharp ) {
-               error() << "this code generator is for C# only" << endl;
-               exit(1);
-       }
-
-       /* If the output format is code and no output file name is given, then
-        * make a default. */
-       if ( outputFileName == 0 ) {
-               const char *ext = findFileExtension( inputFile );
-               if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
-                       outputFileName = fileNameFromStem( inputFile, ".h" );
-               else
-                       outputFileName = fileNameFromStem( inputFile, ".cs" );
-       }
-
-       /* Make sure we are not writing to the same file as the input file. */
-       if ( outputFileName != 0 && strcmp( inputFile, outputFileName  ) == 0 ) {
-               error() << "output file \"" << outputFileName  << 
-                               "\" is the same as the input file" << endl;
-       }
-
-       if ( outputFileName != 0 ) {
-               /* Create the filter on the output and open it. */
-               outFilter = new output_filter( outputFileName );
-
-               /* Open the output stream, attaching it to the filter. */
-               outStream = new ostream( outFilter );
-       }
-       else {
-               /* Writing out ot std out. */
-               outStream = &cout;
-       }
-       return outStream;
-}
-
 /* Invoked by the parser when a ragel definition is opened. */
 CodeGenData *csharpMakeCodeGen( const char *sourceFileName, const char *fsmName, 
                ostream &out, bool wantComplete )
index 572bc72..1332667 100644 (file)
@@ -32,29 +32,6 @@ using std::cout;
 using std::cerr;
 using std::endl;
 
-/* Invoked by the parser when the root element is opened. */
-ostream *dotOpenOutput( const char *inputFile )
-{
-       /* Make sure we are not writing to the same file as the input file. */
-       if ( outputFileName != 0 && strcmp( inputFile, outputFileName  ) == 0 ) {
-               error() << "output file \"" << outputFileName  << 
-                               "\" is the same as the input file" << endl;
-       }
-
-       if ( outputFileName != 0 ) {
-               /* Create the filter on the output and open it. */
-               outFilter = new output_filter( outputFileName );
-
-               /* Open the output stream, attaching it to the filter. */
-               outStream = new ostream( outFilter );
-       }
-       else {
-               /* Writing out ot std out. */
-               outStream = &cout;
-       }
-       return outStream;
-}
-
 /* Invoked by the parser when a ragel definition is opened. */
 CodeGenData *dotMakeCodeGen( const char *sourceFileName, const char *fsmName, 
                ostream &out, bool wantComplete )
index aeb2c71..aa336c6 100644 (file)
@@ -69,23 +69,96 @@ void InputData::generateSpecificReduced()
        writeOutput();
 }
 
+/* Invoked by the parser when the root element is opened. */
+void InputData::dotDefaultFileName( const char *inputFile )
+{
+}
+
+
+/* Invoked by the parser when the root element is opened. */
+void InputData::cdDefaultFileName( const char *inputFile )
+{
+       /* If the output format is code and no output file name is given, then
+        * make a default. */
+       if ( outputFileName == 0 ) {
+               const char *ext = findFileExtension( inputFile );
+               if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
+                       outputFileName = fileNameFromStem( inputFile, ".h" );
+               else {
+                       const char *defExtension = 0;
+                       switch ( hostLang->lang ) {
+                               case HostLang::C: defExtension = ".c"; break;
+                               case HostLang::D: defExtension = ".d"; break;
+                               default: break;
+                       }
+                       outputFileName = fileNameFromStem( inputFile, defExtension );
+               }
+       }
+}
+
+/* Invoked by the parser when the root element is opened. */
+void InputData::javaDefaultFileName( const char *inputFile )
+{
+       /* If the output format is code and no output file name is given, then
+        * make a default. */
+       if ( outputFileName == 0 )
+               outputFileName = fileNameFromStem( inputFile, ".java" );
+}
+
+/* Invoked by the parser when the root element is opened. */
+void InputData::rubyDefaultFileName( const char *inputFile )
+{
+       /* If the output format is code and no output file name is given, then
+        * make a default. */
+       if ( outputFileName == 0 )
+               outputFileName = fileNameFromStem( inputFile, ".rb" );
+}
+
+/* Invoked by the parser when the root element is opened. */
+void InputData::csharpDefaultFileName( const char *inputFile )
+{
+       /* If the output format is code and no output file name is given, then
+        * make a default. */
+       if ( outputFileName == 0 ) {
+               const char *ext = findFileExtension( inputFile );
+               if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
+                       outputFileName = fileNameFromStem( inputFile, ".h" );
+               else
+                       outputFileName = fileNameFromStem( inputFile, ".cs" );
+       }
+}
 
 void InputData::openOutput()
 {
        if ( generateDot )
-               outStream = dotOpenOutput( inputFileName );
+               dotDefaultFileName( inputFileName );
        else if ( hostLang->lang == HostLang::C )
-               outStream = cdOpenOutput( inputFileName );
+               cdDefaultFileName( inputFileName );
        else if ( hostLang->lang == HostLang::D )
-               outStream = cdOpenOutput( inputFileName );
+               cdDefaultFileName( inputFileName );
        else if ( hostLang->lang == HostLang::Java )
-               outStream = javaOpenOutput( inputFileName );
+               javaDefaultFileName( inputFileName );
        else if ( hostLang->lang == HostLang::Ruby )
-               outStream = rubyOpenOutput( inputFileName );
+               rubyDefaultFileName( inputFileName );
        else if ( hostLang->lang == HostLang::CSharp )
-               outStream = csharpOpenOutput( inputFileName );
+               csharpDefaultFileName( inputFileName );
+
+       /* Make sure we are not writing to the same file as the input file. */
+       if ( outputFileName != 0 && strcmp( inputFileName, outputFileName  ) == 0 ) {
+               error() << "output file \"" << outputFileName  << 
+                               "\" is the same as the input file" << endl;
+       }
+
+       if ( outputFileName != 0 ) {
+               /* Create the filter on the output and open it. */
+               outFilter = new output_filter( outputFileName );
+
+               /* Open the output stream, attaching it to the filter. */
+               outStream = new ostream( outFilter );
+       }
        else {
-               assert( false );
+               /* Writing out ot std out. */
+               outStream = &cout;
        }
 }
 
index de2f8de..ad774b4 100644 (file)
@@ -47,6 +47,12 @@ struct InputData
        void openOutput2();
        void generateReduced();
        void prepareMachineGen();
+
+       void dotDefaultFileName( const char *inputFile );
+       void cdDefaultFileName( const char *inputFile );
+       void javaDefaultFileName( const char *inputFile );
+       void rubyDefaultFileName( const char *inputFile );
+       void csharpDefaultFileName( const char *inputFile );
 };
 
 #endif
index 14d98eb..60b1042 100644 (file)
@@ -55,44 +55,6 @@ using std::cout;
 using std::cerr;
 using std::endl;
 
-/* Invoked by the parser when the root element is opened. */
-ostream *javaOpenOutput( const char *inputFile )
-{
-       if ( hostLang->lang != HostLang::Java ) {
-               error() << "this code generator is for Java only" << endl;
-               exit(1);
-       }
-
-       /* If the output format is code and no output file name is given, then
-        * make a default. */
-       if ( outputFileName == 0 ) {
-               const char *ext = findFileExtension( inputFile );
-               if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
-                       outputFileName = fileNameFromStem( inputFile, ".h" );
-               else
-                       outputFileName = fileNameFromStem( inputFile, ".java" );
-       }
-
-       /* Make sure we are not writing to the same file as the input file. */
-       if ( outputFileName != 0 && strcmp( inputFile, outputFileName  ) == 0 ) {
-               error() << "output file \"" << outputFileName  << 
-                               "\" is the same as the input file" << endl;
-       }
-
-       if ( outputFileName != 0 ) {
-               /* Create the filter on the output and open it. */
-               outFilter = new output_filter( outputFileName );
-
-               /* Open the output stream, attaching it to the filter. */
-               outStream = new ostream( outFilter );
-       }
-       else {
-               /* Writing out ot std out. */
-               outStream = &cout;
-       }
-       return outStream;
-}
-
 /* Invoked by the parser when a ragel definition is opened. */
 CodeGenData *javaMakeCodeGen( const char *sourceFileName, const char *fsmName, 
                ostream &out, bool wantComplete )
index eb27ac7..06902fd 100644 (file)
@@ -74,44 +74,6 @@ extern int numSplitPartitions;
  * Callbacks invoked by the XML data parser.
  */
 
-/* Invoked by the parser when the root element is opened. */
-ostream *rubyOpenOutput( const char *inputFile )
-{
-       if ( hostLang->lang != HostLang::Ruby ) {
-               error() << "this code generator is for Ruby only" << endl;
-               exit(1);
-       }
-
-       /* If the output format is code and no output file name is given, then
-        * make a default. */
-       if ( outputFileName == 0 ) {
-               const char *ext = findFileExtension( inputFile );
-               if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
-                       outputFileName = fileNameFromStem( inputFile, ".h" );
-               else
-                       outputFileName = fileNameFromStem( inputFile, ".rb" );
-       }
-
-       /* Make sure we are not writing to the same file as the input file. */
-       if ( outputFileName != 0 && strcmp( inputFile, outputFileName  ) == 0 ) {
-               error() << "output file \"" << outputFileName  << 
-                               "\" is the same as the input file" << endl;
-       }
-
-       if ( outputFileName != 0 ) {
-               /* Create the filter on the output and open it. */
-               outFilter = new output_filter( outputFileName );
-
-               /* Open the output stream, attaching it to the filter. */
-               outStream = new ostream( outFilter );
-       }
-       else {
-               /* Writing out ot std out. */
-               outStream = &cout;
-       }
-       return outStream;
-}
-
 /* Invoked by the parser when a ragel definition is opened. */
 CodeGenData *rubyMakeCodeGen( const char *sourceFileName, const char *fsmName, 
                ostream &out, bool wantComplete )