From 7ead46f2a23c9c39b9ed4eff89584f55469672b1 Mon Sep 17 00:00:00 2001 From: thurston Date: Sun, 15 Mar 2009 14:34:17 +0000 Subject: [PATCH] Cleanup and code movement related to makeCodeGen. git-svn-id: http://svn.complang.org/ragel/trunk@739 052ea7fc-9027-0410-9066-f65837a77df0 --- ragel/cdcodegen.cpp | 85 ------------------- ragel/cdcodegen.h | 7 +- ragel/common.h | 20 ----- ragel/cscodegen.cpp | 50 ----------- ragel/cscodegen.h | 7 +- ragel/dotcodegen.cpp | 13 --- ragel/gendata.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++ ragel/gendata.h | 26 +----- ragel/javacodegen.cpp | 13 --- ragel/main.cpp | 2 +- ragel/ragel.h | 25 +++++- ragel/rubycodegen.cpp | 44 +--------- ragel/rubycodegen.h | 7 -- 13 files changed, 252 insertions(+), 270 deletions(-) diff --git a/ragel/cdcodegen.cpp b/ragel/cdcodegen.cpp index 6965c09..ceb0030 100644 --- a/ragel/cdcodegen.cpp +++ b/ragel/cdcodegen.cpp @@ -29,15 +29,6 @@ #include #include -/* Code generators. */ -#include "cdtable.h" -#include "cdftable.h" -#include "cdflat.h" -#include "cdfflat.h" -#include "cdgoto.h" -#include "cdfgoto.h" -#include "cdipgoto.h" -#include "cdsplit.h" using std::ostream; using std::ostringstream; @@ -54,7 +45,6 @@ using std::cerr; using std::endl; /* Target language and output style. */ -extern CodeStyleEnum codeStyle; /* Io globals. */ extern istream *inStream; @@ -68,81 +58,6 @@ extern bool graphvizDone; extern int numSplitPartitions; extern bool noLineDirectives; -/* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *cdMakeCodeGen( const char *sourceFileName, const char *fsmName, - ostream &out, bool wantComplete ) -{ - CodeGenData *codeGen = 0; - switch ( hostLang->lang ) { - case HostLang::C: - switch ( codeStyle ) { - case GenTables: - codeGen = new CTabCodeGen(out); - break; - case GenFTables: - codeGen = new CFTabCodeGen(out); - break; - case GenFlat: - codeGen = new CFlatCodeGen(out); - break; - case GenFFlat: - codeGen = new CFFlatCodeGen(out); - break; - case GenGoto: - codeGen = new CGotoCodeGen(out); - break; - case GenFGoto: - codeGen = new CFGotoCodeGen(out); - break; - case GenIpGoto: - codeGen = new CIpGotoCodeGen(out); - break; - case GenSplit: - codeGen = new CSplitCodeGen(out); - break; - } - break; - - case HostLang::D: - switch ( codeStyle ) { - case GenTables: - codeGen = new DTabCodeGen(out); - break; - case GenFTables: - codeGen = new DFTabCodeGen(out); - break; - case GenFlat: - codeGen = new DFlatCodeGen(out); - break; - case GenFFlat: - codeGen = new DFFlatCodeGen(out); - break; - case GenGoto: - codeGen = new DGotoCodeGen(out); - break; - case GenFGoto: - codeGen = new DFGotoCodeGen(out); - break; - case GenIpGoto: - codeGen = new DIpGotoCodeGen(out); - break; - case GenSplit: - codeGen = new DSplitCodeGen(out); - break; - } - break; - - default: break; - } - - codeGen->sourceFileName = sourceFileName; - codeGen->fsmName = fsmName; - codeGen->wantComplete = wantComplete; - - return codeGen; -} - - void cdLineDirective( ostream &out, const char *fileName, int line ) { if ( noLineDirectives ) diff --git a/ragel/cdcodegen.h b/ragel/cdcodegen.h index 6c4a92a..fe69cb2 100644 --- a/ragel/cdcodegen.h +++ b/ragel/cdcodegen.h @@ -48,12 +48,7 @@ struct RedAction; struct LongestMatch; struct LongestMatchPart; -inline string itoa( int i ) -{ - char buf[16]; - sprintf( buf, "%i", i ); - return buf; -} +string itoa( int i ); /* * class FsmCodeGen diff --git a/ragel/common.h b/ragel/common.h index 00f30a2..a9ec27a 100644 --- a/ragel/common.h +++ b/ragel/common.h @@ -375,24 +375,4 @@ struct exit_object { }; extern exit_object endp; void operator<<( std::ostream &out, exit_object & ); -/* Target output style. */ -enum CodeStyleEnum -{ - GenTables, - GenFTables, - GenFlat, - GenFFlat, - GenGoto, - GenFGoto, - GenIpGoto, - GenSplit -}; - -/* Target implementation */ -enum RubyImplEnum -{ - MRI, - Rubinius -}; - #endif diff --git a/ragel/cscodegen.cpp b/ragel/cscodegen.cpp index e0c032b..5527236 100644 --- a/ragel/cscodegen.cpp +++ b/ragel/cscodegen.cpp @@ -30,16 +30,6 @@ #include #include -/* Code generators. */ -#include "cstable.h" -#include "csftable.h" -#include "csflat.h" -#include "csfflat.h" -#include "csgoto.h" -#include "csfgoto.h" -#include "csipgoto.h" -#include "cssplit.h" - using std::ostream; using std::ostringstream; using std::string; @@ -55,46 +45,6 @@ using std::cout; using std::cerr; using std::endl; -/* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *csharpMakeCodeGen( const char *sourceFileName, const char *fsmName, - ostream &out, bool wantComplete ) -{ - CodeGenData *codeGen = 0; - - switch ( codeStyle ) { - case GenTables: - codeGen = new CSharpTabCodeGen(out); - break; - case GenFTables: - codeGen = new CSharpFTabCodeGen(out); - break; - case GenFlat: - codeGen = new CSharpFlatCodeGen(out); - break; - case GenFFlat: - codeGen = new CSharpFFlatCodeGen(out); - break; - case GenGoto: - codeGen = new CSharpGotoCodeGen(out); - break; - case GenFGoto: - codeGen = new CSharpFGotoCodeGen(out); - break; - case GenIpGoto: - codeGen = new CSharpIpGotoCodeGen(out); - break; - case GenSplit: - codeGen = new CSharpSplitCodeGen(out); - break; - } - - codeGen->sourceFileName = sourceFileName; - codeGen->fsmName = fsmName; - codeGen->wantComplete = wantComplete; - - return codeGen; -} - void csharpLineDirective( ostream &out, const char *fileName, int line ) { if ( noLineDirectives ) diff --git a/ragel/cscodegen.h b/ragel/cscodegen.h index fae7f4d..bcc2653 100644 --- a/ragel/cscodegen.h +++ b/ragel/cscodegen.h @@ -48,12 +48,7 @@ struct RedAction; struct LongestMatch; struct LongestMatchPart; -inline string itoa( int i ) -{ - char buf[16]; - sprintf( buf, "%i", i ); - return buf; -} +string itoa( int i ); /* * class CSharpFsmCodeGen diff --git a/ragel/dotcodegen.cpp b/ragel/dotcodegen.cpp index 1332667..4efcbab 100644 --- a/ragel/dotcodegen.cpp +++ b/ragel/dotcodegen.cpp @@ -32,19 +32,6 @@ using std::cout; using std::cerr; using std::endl; -/* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *dotMakeCodeGen( const char *sourceFileName, const char *fsmName, - ostream &out, bool wantComplete ) -{ - CodeGenData *codeGen = new GraphvizDotGen(out); - - codeGen->sourceFileName = sourceFileName; - codeGen->fsmName = fsmName; - codeGen->wantComplete = wantComplete; - - return codeGen; -} - /* Override this so that write statement processing is ignored */ void GraphvizDotGen::writeStatement( InputLoc &, int, char ** ) { diff --git a/ragel/gendata.cpp b/ragel/gendata.cpp index 86e3d0d..8801ef0 100644 --- a/ragel/gendata.cpp +++ b/ragel/gendata.cpp @@ -20,11 +20,234 @@ */ #include "gendata.h" +#include "ragel.h" #include +/* + * Code generators. + */ + +#include "cstable.h" +#include "csftable.h" +#include "csflat.h" +#include "csfflat.h" +#include "csgoto.h" +#include "csfgoto.h" +#include "csipgoto.h" +#include "cssplit.h" + +#include "cdtable.h" +#include "cdftable.h" +#include "cdflat.h" +#include "cdfflat.h" +#include "cdgoto.h" +#include "cdfgoto.h" +#include "cdipgoto.h" +#include "cdsplit.h" + +#include "dotcodegen.h" + +#include "javacodegen.h" + +#include "rubytable.h" +#include "rubyftable.h" +#include "rubyflat.h" +#include "rubyfflat.h" +#include "rbxgoto.h" + +string itoa( int i ) +{ + char buf[16]; + sprintf( buf, "%i", i ); + return buf; +} + +using std::cout; using std::cerr; using std::endl; +/* Invoked by the parser when a ragel definition is opened. */ +CodeGenData *dotMakeCodeGen( const char *sourceFileName, const char *fsmName, + ostream &out, bool wantComplete ) +{ + CodeGenData *codeGen = new GraphvizDotGen(out); + + codeGen->sourceFileName = sourceFileName; + codeGen->fsmName = fsmName; + codeGen->wantComplete = wantComplete; + + return codeGen; +} + +/* Invoked by the parser when a ragel definition is opened. */ +CodeGenData *cdMakeCodeGen( const char *sourceFileName, const char *fsmName, + ostream &out, bool wantComplete ) +{ + CodeGenData *codeGen = 0; + switch ( hostLang->lang ) { + case HostLang::C: + switch ( codeStyle ) { + case GenTables: + codeGen = new CTabCodeGen(out); + break; + case GenFTables: + codeGen = new CFTabCodeGen(out); + break; + case GenFlat: + codeGen = new CFlatCodeGen(out); + break; + case GenFFlat: + codeGen = new CFFlatCodeGen(out); + break; + case GenGoto: + codeGen = new CGotoCodeGen(out); + break; + case GenFGoto: + codeGen = new CFGotoCodeGen(out); + break; + case GenIpGoto: + codeGen = new CIpGotoCodeGen(out); + break; + case GenSplit: + codeGen = new CSplitCodeGen(out); + break; + } + break; + + case HostLang::D: + switch ( codeStyle ) { + case GenTables: + codeGen = new DTabCodeGen(out); + break; + case GenFTables: + codeGen = new DFTabCodeGen(out); + break; + case GenFlat: + codeGen = new DFlatCodeGen(out); + break; + case GenFFlat: + codeGen = new DFFlatCodeGen(out); + break; + case GenGoto: + codeGen = new DGotoCodeGen(out); + break; + case GenFGoto: + codeGen = new DFGotoCodeGen(out); + break; + case GenIpGoto: + codeGen = new DIpGotoCodeGen(out); + break; + case GenSplit: + codeGen = new DSplitCodeGen(out); + break; + } + break; + + default: break; + } + + codeGen->sourceFileName = sourceFileName; + codeGen->fsmName = fsmName; + codeGen->wantComplete = wantComplete; + + return codeGen; +} + +/* Invoked by the parser when a ragel definition is opened. */ +CodeGenData *javaMakeCodeGen( const char *sourceFileName, const char *fsmName, + ostream &out, bool wantComplete ) +{ + CodeGenData *codeGen = new JavaTabCodeGen(out); + + codeGen->sourceFileName = sourceFileName; + codeGen->fsmName = fsmName; + codeGen->wantComplete = wantComplete; + + return codeGen; +} + +/* Invoked by the parser when a ragel definition is opened. */ +CodeGenData *rubyMakeCodeGen( const char *sourceFileName, const char *fsmName, + ostream &out, bool wantComplete ) +{ + CodeGenData *codeGen = 0; + switch ( codeStyle ) { + case GenTables: + codeGen = new RubyTabCodeGen(out); + break; + case GenFTables: + codeGen = new RubyFTabCodeGen(out); + break; + case GenFlat: + codeGen = new RubyFlatCodeGen(out); + break; + case GenFFlat: + codeGen = new RubyFFlatCodeGen(out); + break; + case GenGoto: + if ( rubyImpl == Rubinius ) { + codeGen = new RbxGotoCodeGen(out); + } else { + cerr << "Goto style is still _very_ experimental " + "and only supported using Rubinius.\n" + "You may want to enable the --rbx flag " + " to give it a try.\n"; + exit(1); + } + break; + default: + cout << "Invalid code style\n"; + exit(1); + break; + } + codeGen->sourceFileName = sourceFileName; + codeGen->fsmName = fsmName; + codeGen->wantComplete = wantComplete; + + return codeGen; +} + +/* Invoked by the parser when a ragel definition is opened. */ +CodeGenData *csharpMakeCodeGen( const char *sourceFileName, const char *fsmName, + ostream &out, bool wantComplete ) +{ + CodeGenData *codeGen = 0; + + switch ( codeStyle ) { + case GenTables: + codeGen = new CSharpTabCodeGen(out); + break; + case GenFTables: + codeGen = new CSharpFTabCodeGen(out); + break; + case GenFlat: + codeGen = new CSharpFlatCodeGen(out); + break; + case GenFFlat: + codeGen = new CSharpFFlatCodeGen(out); + break; + case GenGoto: + codeGen = new CSharpGotoCodeGen(out); + break; + case GenFGoto: + codeGen = new CSharpFGotoCodeGen(out); + break; + case GenIpGoto: + codeGen = new CSharpIpGotoCodeGen(out); + break; + case GenSplit: + codeGen = new CSharpSplitCodeGen(out); + break; + } + + codeGen->sourceFileName = sourceFileName; + codeGen->fsmName = fsmName; + codeGen->wantComplete = wantComplete; + + return codeGen; +} + + CodeGenData *makeCodeGen( const char *sourceFileName, const char *fsmName, ostream &out, bool wantComplete ) { diff --git a/ragel/gendata.h b/ragel/gendata.h index e454b53..a0ec5b6 100644 --- a/ragel/gendata.h +++ b/ragel/gendata.h @@ -43,30 +43,6 @@ struct CodeGenData; typedef AvlMap CodeGenMap; typedef AvlMapEl CodeGenMapEl; -/* - * The interface to the parser - */ - -/* These functions must be implemented by the code generation executable. - * The openOutput function is invoked when the root element is opened. The - * makeCodeGen function is invoked when a ragel_def element is opened. */ -std::ostream *cdOpenOutput( const char *inputFile ); -std::ostream *javaOpenOutput( const char *inputFile ); -std::ostream *rubyOpenOutput( const char *inputFile ); -std::ostream *csharpOpenOutput( const char *inputFile ); -std::ostream *dotOpenOutput( const char *inputFile ); - -CodeGenData *cdMakeCodeGen( const char *sourceFileName, - const char *fsmName, ostream &out, bool wantComplete ); -CodeGenData *javaMakeCodeGen( const char *sourceFileName, - const char *fsmName, ostream &out, bool wantComplete ); -CodeGenData *rubyMakeCodeGen( const char *sourceFileName, - const char *fsmName, ostream &out, bool wantComplete ); -CodeGenData *csharpMakeCodeGen( const char *sourceFileName, - const char *fsmName, ostream &out, bool wantComplete ); -CodeGenData *dotMakeCodeGen( const char *sourceFileName, - const char *fsmName, ostream &out, bool wantComplete ); - void cdLineDirective( ostream &out, const char *fileName, int line ); void javaLineDirective( ostream &out, const char *fileName, int line ); void rubyLineDirective( ostream &out, const char *fileName, int line ); @@ -74,6 +50,8 @@ void csharpLineDirective( ostream &out, const char *fileName, int line ); void genLineDirective( ostream &out ); void lineDirective( ostream &out, const char *fileName, int line ); +string itoa( int i ); + /*********************************/ struct CodeGenData diff --git a/ragel/javacodegen.cpp b/ragel/javacodegen.cpp index 60b1042..1ae48a4 100644 --- a/ragel/javacodegen.cpp +++ b/ragel/javacodegen.cpp @@ -55,19 +55,6 @@ using std::cout; using std::cerr; using std::endl; -/* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *javaMakeCodeGen( const char *sourceFileName, const char *fsmName, - ostream &out, bool wantComplete ) -{ - CodeGenData *codeGen = new JavaTabCodeGen(out); - - codeGen->sourceFileName = sourceFileName; - codeGen->fsmName = fsmName; - codeGen->wantComplete = wantComplete; - - return codeGen; -} - void javaLineDirective( ostream &out, const char *fileName, int line ) { /* Write the preprocessor line info for to the input file. */ diff --git a/ragel/main.cpp b/ragel/main.cpp index 120fae7..24075d4 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -82,7 +82,7 @@ bool frontendOnly = false; bool generateDot = false; /* Target language and output style. */ -CodeStyleEnum codeStyle = GenTables; +CodeStyle codeStyle = GenTables; int numSplitPartitions = 0; bool noLineDirectives = false; diff --git a/ragel/ragel.h b/ragel/ragel.h index 434b9f9..7a5dcd0 100644 --- a/ragel/ragel.h +++ b/ragel/ragel.h @@ -32,6 +32,19 @@ #define PROGNAME "ragel" +/* Target output style. */ +enum CodeStyle +{ + GenTables, + GenFTables, + GenFlat, + GenFFlat, + GenGoto, + GenFGoto, + GenIpGoto, + GenSplit +}; + /* To what degree are machine minimized. */ enum MinimizeLevel { MinimizeApprox, @@ -47,6 +60,13 @@ enum MinimizeOpt { MinimizeEveryOp }; +/* Target implementation */ +enum RubyImplEnum +{ + MRI, + Rubinius +}; + /* Options. */ extern MinimizeLevel minimizeLevel; extern MinimizeOpt minimizeOpt; @@ -54,6 +74,7 @@ extern const char *machineSpec, *machineName; extern bool printStatistics; extern bool wantDupsRemoved; extern bool generateDot; +extern RubyImplEnum rubyImpl; /* Error reporting format. */ enum ErrorFormat { @@ -81,7 +102,7 @@ void xmlEscapeHost( std::ostream &out, char *data, long len ); typedef Vector ArgsVector; extern ArgsVector includePaths; -extern CodeStyleEnum codeStyle; +extern CodeStyle codeStyle; /* IO filenames and stream. */ extern bool displayPrintables; @@ -96,7 +117,7 @@ extern bool noLineDirectives; std::ostream &error(); /* Target language and output style. */ -extern CodeStyleEnum codeStyle; +extern CodeStyle codeStyle; /* Io globals. */ extern std::istream *inStream; diff --git a/ragel/rubycodegen.cpp b/ragel/rubycodegen.cpp index 06902fd..5b50346 100644 --- a/ragel/rubycodegen.cpp +++ b/ragel/rubycodegen.cpp @@ -54,10 +54,9 @@ using std::cerr; using std::endl; /* Target ruby impl */ -extern RubyImplEnum rubyImpl; /* Target language and output style. */ -extern CodeStyleEnum codeStyle; +extern CodeStyle codeStyle; /* Io globals. */ extern istream *inStream; @@ -74,47 +73,6 @@ extern int numSplitPartitions; * Callbacks invoked by the XML data parser. */ -/* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *rubyMakeCodeGen( const char *sourceFileName, const char *fsmName, - ostream &out, bool wantComplete ) -{ - CodeGenData *codeGen = 0; - switch ( codeStyle ) { - case GenTables: - codeGen = new RubyTabCodeGen(out); - break; - case GenFTables: - codeGen = new RubyFTabCodeGen(out); - break; - case GenFlat: - codeGen = new RubyFlatCodeGen(out); - break; - case GenFFlat: - codeGen = new RubyFFlatCodeGen(out); - break; - case GenGoto: - if ( rubyImpl == Rubinius ) { - codeGen = new RbxGotoCodeGen(out); - } else { - cout << "Goto style is still _very_ experimental " - "and only supported using Rubinius.\n" - "You may want to enable the --rbx flag " - " to give it a try.\n"; - exit(1); - } - break; - default: - cout << "Invalid code style\n"; - exit(1); - break; - } - codeGen->sourceFileName = sourceFileName; - codeGen->fsmName = fsmName; - codeGen->wantComplete = wantComplete; - - return codeGen; -} - void rubyLineDirective( ostream &out, const char *fileName, int line ) { diff --git a/ragel/rubycodegen.h b/ragel/rubycodegen.h index d671faa..d7e34e5 100644 --- a/ragel/rubycodegen.h +++ b/ragel/rubycodegen.h @@ -29,13 +29,6 @@ /* Integer array line length. */ #define IALL 8 -inline string itoa( int i ) -{ - char buf[16]; - sprintf( buf, "%i", i ); - return buf; -} - class RubyCodeGen : public CodeGenData { -- 2.7.4