From 3f821f1f45be7f0d131455cb671cef64e9f81d08 Mon Sep 17 00:00:00 2001 From: thurston Date: Sat, 30 Aug 2008 22:17:10 +0000 Subject: [PATCH] Started on the move back to a single executable. The backend programs are now a part of the ragel program, with the the frontend and and backend components now function calls. The intermediate file is still used but eventually it will be removed. git-svn-id: http://svn.complang.org/ragel/trunk@462 052ea7fc-9027-0410-9066-f65837a77df0 --- Makefile.in | 4 +- common/common.cpp | 2 +- common/common.h | 4 +- common/pcheck.h | 11 ++- ragel/Makefile.in | 8 +- ragel/main.cpp | 63 ++++++++++------ ragel/parsedata.cpp | 4 +- ragel/parsedata.h | 4 +- ragel/parsetree.cpp | 6 +- ragel/parsetree.h | 2 +- ragel/ragel.h | 4 +- ragel/rlparse.kh | 8 +- ragel/rlscan.h | 8 +- ragel/rlscan.rl | 5 +- redfsm/gendata.cpp | 48 ++++++------ redfsm/gendata.h | 61 +++++++++------ redfsm/redfsm.cpp | 2 +- redfsm/redfsm.h | 20 ++--- redfsm/xmlparse.kh | 22 +++--- redfsm/xmlparse.kl | 143 +++++++++++++++++++++++------------ redfsm/xmlscan.rl | 26 +++---- rlgen-cd/Makefile.in | 16 ++-- rlgen-cd/flatcodegen.cpp | 6 +- rlgen-cd/flatcodegen.h | 6 +- rlgen-cd/fsmcodegen.cpp | 88 +++++++++++----------- rlgen-cd/fsmcodegen.h | 36 ++++----- rlgen-cd/gotocodegen.cpp | 6 +- rlgen-cd/gotocodegen.h | 6 +- rlgen-cd/ipgotocodegen.cpp | 12 +-- rlgen-cd/ipgotocodegen.h | 8 +- rlgen-cd/main.cpp | 52 +++++++------ rlgen-cd/splitcodegen.cpp | 6 +- rlgen-cd/splitcodegen.h | 2 +- rlgen-cd/tabcodegen.cpp | 6 +- rlgen-cd/tabcodegen.h | 6 +- rlgen-csharp/Makefile.in | 16 ++-- rlgen-csharp/fflatcodegen.h | 2 +- rlgen-csharp/fgotocodegen.h | 2 +- rlgen-csharp/flatcodegen.cpp | 6 +- rlgen-csharp/flatcodegen.h | 10 +-- rlgen-csharp/fsmcodegen.cpp | 156 +++++++++++++++++++-------------------- rlgen-csharp/fsmcodegen.h | 48 ++++++------ rlgen-csharp/ftabcodegen.h | 2 +- rlgen-csharp/gotocodegen.cpp | 6 +- rlgen-csharp/gotocodegen.h | 10 +-- rlgen-csharp/ipgotocodegen.cpp | 12 +-- rlgen-csharp/ipgotocodegen.h | 10 +-- rlgen-csharp/main.cpp | 66 ++++++++--------- rlgen-csharp/splitcodegen.cpp | 6 +- rlgen-csharp/splitcodegen.h | 4 +- rlgen-csharp/tabcodegen.cpp | 6 +- rlgen-csharp/tabcodegen.h | 10 +-- rlgen-java/Makefile.in | 16 ++-- rlgen-java/javacodegen.cpp | 94 +++++++++++------------ rlgen-java/javacodegen.h | 34 +++++---- rlgen-java/main.cpp | 57 +++++++------- rlgen-ruby/Makefile.in | 18 +++-- rlgen-ruby/main.cpp | 64 ++++++++-------- rlgen-ruby/rbx-gotocodegen.cpp | 6 +- rlgen-ruby/rbx-gotocodegen.h | 6 +- rlgen-ruby/ruby-codegen.cpp | 90 +++++++++++----------- rlgen-ruby/ruby-codegen.h | 31 ++++---- rlgen-ruby/ruby-fflatcodegen.cpp | 4 +- rlgen-ruby/ruby-fflatcodegen.h | 4 +- rlgen-ruby/ruby-flatcodegen.cpp | 6 +- rlgen-ruby/ruby-flatcodegen.h | 6 +- rlgen-ruby/ruby-ftabcodegen.cpp | 4 +- rlgen-ruby/ruby-ftabcodegen.h | 4 +- rlgen-ruby/ruby-tabcodegen.cpp | 6 +- rlgen-ruby/ruby-tabcodegen.h | 26 +++---- 70 files changed, 825 insertions(+), 734 deletions(-) diff --git a/Makefile.in b/Makefile.in index dbf4751..1324f37 100644 --- a/Makefile.in +++ b/Makefile.in @@ -18,8 +18,8 @@ # along with Ragel; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -BUILD_COMMON = common redfsm -BUILD_SUBDIRS = ragel rlgen-cd rlgen-java rlgen-ruby rlgen-dot rlgen-csharp +BUILD_COMMON = common redfsm rlgen-cd rlgen-java rlgen-ruby rlgen-csharp +BUILD_SUBDIRS = ragel ALL_SUBDIRS = $(BUILD_COMMON) $(BUILD_SUBDIRS) test examples doc #************************************* diff --git a/common/common.cpp b/common/common.cpp index 40b392b..360108b 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -148,7 +148,7 @@ HostType *findAlphTypeInternal( char *s1 ) } /* Construct a new parameter checker with for paramSpec. */ -ParamCheck::ParamCheck( const char *paramSpec, int argc, char **argv ) +ParamCheck::ParamCheck( const char *paramSpec, int argc, const char **argv ) : state(noparam), argOffset(0), diff --git a/common/common.h b/common/common.h index ce06028..0bda125 100644 --- a/common/common.h +++ b/common/common.h @@ -294,12 +294,12 @@ inline Key operator/(const Key key1, const Key key2) class output_filter : public std::filebuf { public: - output_filter( char *fileName ) : fileName(fileName), line(1) { } + output_filter( const char *fileName ) : fileName(fileName), line(1) { } virtual int sync(); virtual std::streamsize xsputn(const char* s, std::streamsize n); - char *fileName; + const char *fileName; int line; }; diff --git a/common/pcheck.h b/common/pcheck.h index 70a7ce4..dac8811 100644 --- a/common/pcheck.h +++ b/common/pcheck.h @@ -25,25 +25,24 @@ class ParamCheck { public: - ParamCheck( const char *paramSpec, int argc, char **argv); + ParamCheck( const char *paramSpec, int argc, const char **argv); bool check(); - char *paramArg; /* The argument to the parameter. */ + const char *paramArg; /* The argument to the parameter. */ char parameter; /* The parameter matched. */ enum { match, invalid, noparam } state; - char *argOffset; /* If we are reading params inside an + const char *argOffset; /* If we are reading params inside an * arg this points to the offset. */ - char *curArg; /* Pointer to the current arg. */ + const char *curArg; /* Pointer to the current arg. */ int iCurArg; /* Index to the current arg. */ private: const char *paramSpec; /* Parameter spec supplied by the coder. */ int argc; /* Arguement data from the command line. */ - char **argv; - + const char **argv; }; #endif /* _PCHECK_H */ diff --git a/ragel/Makefile.in b/ragel/Makefile.in index 8bff749..018283f 100644 --- a/ragel/Makefile.in +++ b/ragel/Makefile.in @@ -31,7 +31,13 @@ CC_SRCS = \ GEN_SRC = rlscan.cpp rlparse.h rlparse.cpp -RAGEL_LIBS = ../common/common.a +RAGEL_LIBS = ../common/common.a \ + ../rlgen-cd/rlgen-cd.a \ + ../rlgen-java/rlgen-java.a \ + ../rlgen-ruby/rlgen-ruby.a \ + ../rlgen-csharp/rlgen-csharp.a \ + ../redfsm/redfsm.a + LIBS = $(RAGEL_LIBS) MINGW_LIBS = -lpsapi diff --git a/ragel/main.cpp b/ragel/main.cpp index 4b2a2a1..6e539ba 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -73,7 +73,7 @@ MinimizeLevel minimizeLevel = MinimizePartition2; MinimizeOpt minimizeOpt = MinimizeMostOps; /* Graphviz dot file generation. */ -char *machineSpec = 0, *machineName = 0; +const char *machineSpec = 0, *machineName = 0; bool machineSpecFound = false; bool wantDupsRemoved = true; @@ -208,7 +208,8 @@ void escapeLineDirectivePath( std::ostream &out, char *path ) } } -void processArgs( int argc, char **argv, char *&inputFileName, char *&outputFileName ) +void processArgs( int argc, const char **argv, + const char *&inputFileName, const char *&outputFileName ) { ParamCheck pc("xo:dnmleabjkS:M:I:CDJRAvHh?-:sT:F:G:P:LpV", argc, argv); @@ -426,7 +427,7 @@ void processArgs( int argc, char **argv, char *&inputFileName, char *&outputFile } } -int frontend( char *inputFileName, char *outputFileName ) +int frontend( const char *inputFileName, const char *outputFileName ) { /* Open the input file for reading. */ assert( inputFileName != 0 ); @@ -477,7 +478,7 @@ int frontend( char *inputFileName, char *outputFileName ) return gblErrorCount > 0; } -char *makeIntermedTemplate( char *baseFileName ) +char *makeIntermedTemplate( const char *baseFileName ) { char *result = 0; const char *templ = "ragel-XXXXXX.xml"; @@ -495,16 +496,16 @@ char *makeIntermedTemplate( char *baseFileName ) return result; }; -char *openIntermed( char *inputFileName, char *outputFileName ) +const char *openIntermed( const char *inputFileName, const char *outputFileName ) { srand(time(0)); - char *result = 0; + const char *result = 0; /* Which filename do we use as the base? */ - char *baseFileName = outputFileName != 0 ? outputFileName : inputFileName; + const char *baseFileName = outputFileName != 0 ? outputFileName : inputFileName; /* The template for the intermediate file name. */ - char *intermedFileName = makeIntermedTemplate( baseFileName ); + const char *intermedFileName = makeIntermedTemplate( baseFileName ); /* Randomize the name and try to open. */ char fnChars[] = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -538,7 +539,7 @@ char *openIntermed( char *inputFileName, char *outputFileName ) } -void cleanExit( char *intermed, int status ) +void cleanExit( const char *intermed, int status ) { unlink( intermed ); exit( status ); @@ -588,10 +589,17 @@ char **makePathChecksUnix( const char *argv0, const char *progName ) return result; } +int main(int argc, const char **argv); +int cd_main(int argc, const char **argv); +int java_main(int argc, const char **argv); +int ruby_main(int argc, const char **argv); +int csharp_main(int argc, const char **argv); + void forkAndExec( const char *progName, char **pathChecks, - ArgsVector &args, char *intermed ) + ArgsVector &args, const char *intermed ) { +#if 0 pid_t pid = fork(); if ( pid < 0 ) { /* Error, no child created. */ @@ -609,7 +617,20 @@ void forkAndExec( const char *progName, char **pathChecks, error() << "failed to exec " << progName << endl; cleanExit( intermed, 1 ); } +#endif + if ( strcmp( progName, "ragel" ) == 0 ) + main( args.length()-1, args.data ); + else if ( strcmp( progName, "rlgen-cd" ) == 0 ) + cd_main( args.length()-1, args.data ); + else if ( strcmp( progName, "rlgen-java" ) == 0 ) + java_main( args.length()-1, args.data ); + else if ( strcmp( progName, "rlgen-ruby" ) == 0 ) + ruby_main( args.length()-1, args.data ); + else if ( strcmp( progName, "rlgen-csharp" ) == 0 ) + csharp_main( args.length()-1, args.data ); + +#if 0 /* Parent process, wait for the child. */ int status; wait( &status ); @@ -622,6 +643,7 @@ void forkAndExec( const char *progName, char **pathChecks, if ( WEXITSTATUS(status) != 0 ) cleanExit( intermed, WEXITSTATUS(status) ); +#endif } #else @@ -686,7 +708,7 @@ void spawn( const char *progName, char **pathChecks, #endif -void execFrontend( const char *argv0, char *inputFileName, char *intermed ) +void execFrontend( const char *argv0, const char *inputFileName, const char *intermed ) { /* The frontend program name. */ const char *progName = "ragel"; @@ -707,7 +729,7 @@ void execFrontend( const char *argv0, char *inputFileName, char *intermed ) #endif } -void execBackend( const char *argv0, char *intermed, char *outputFileName ) +void execBackend( const char *argv0, const char *intermed, const char *outputFileName ) { /* Locate the backend program */ const char *progName = 0; @@ -748,10 +770,10 @@ void execBackend( const char *argv0, char *intermed, char *outputFileName ) } /* Main, process args and call yyparse to start scanning input. */ -int main(int argc, char **argv) +int main(int argc, const char **argv) { - char *inputFileName = 0; - char *outputFileName = 0; + const char *inputFileName = 0; + const char *outputFileName = 0; processArgs( argc, argv, inputFileName, outputFileName ); @@ -779,15 +801,8 @@ int main(int argc, char **argv) "\" is the same as the input file" << endp; } - if ( frontendOnly ) - return frontend( inputFileName, outputFileName ); - - char *intermed = openIntermed( inputFileName, outputFileName ); - - /* From here on in the cleanExit function should be used to exit. */ - - /* Run the frontend, then the backend processes. */ - execFrontend( argv[0], inputFileName, intermed ); + const char *intermed = openIntermed( inputFileName, outputFileName ); + frontend( inputFileName, intermed ); execBackend( argv[0], intermed, outputFileName ); /* Clean up the intermediate. */ diff --git a/ragel/parsedata.cpp b/ragel/parsedata.cpp index 6e2558b..8d862cd 100644 --- a/ragel/parsedata.cpp +++ b/ragel/parsedata.cpp @@ -416,7 +416,7 @@ bool NameInst::anyRefsRec() /* Initialize the structure that will collect info during the parse of a * machine. */ -ParseData::ParseData( char *fileName, char *sectionName, +ParseData::ParseData( const char *fileName, char *sectionName, const InputLoc §ionLoc ) : sectionGraph(0), @@ -1470,7 +1470,7 @@ void writeLanguage( std::ostream &out ) } -void writeMachines( std::ostream &out, std::string hostData, char *inputFileName ) +void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName ) { if ( machineSpec == 0 && machineName == 0 ) { /* No machine spec or machine name given. Generate everything. */ diff --git a/ragel/parsedata.h b/ragel/parsedata.h index fc2b9c0..b806c42 100644 --- a/ragel/parsedata.h +++ b/ragel/parsedata.h @@ -154,7 +154,7 @@ struct ParseData { /* Create a new parse data object. This is done at the beginning of every * fsm specification. */ - ParseData( char *fileName, char *sectionName, const InputLoc §ionLoc ); + ParseData( const char *fileName, char *sectionName, const InputLoc §ionLoc ); ~ParseData(); /* @@ -283,7 +283,7 @@ struct ParseData InputLoc rangeLowLoc, rangeHighLoc; /* The name of the file the fsm is from, and the spec name. */ - char *fileName; + const char *fileName; char *sectionName; InputLoc sectionLoc; diff --git a/ragel/parsetree.cpp b/ragel/parsetree.cpp index 443c565..72e84ea 100644 --- a/ragel/parsetree.cpp +++ b/ragel/parsetree.cpp @@ -38,14 +38,14 @@ ostream &operator<<( ostream &out, const NameInst &nameInst ); * characters with escapes and options interpreted. Also null terminates the * string. Though this null termination should not be relied on for * interpreting literals in the parser because the string may contain \0 */ -char *prepareLitString( const InputLoc &loc, char *data, long length, +char *prepareLitString( const InputLoc &loc, const char *data, long length, long &resLen, bool &caseInsensitive ) { char *resData = new char[length+1]; caseInsensitive = false; - char *src = data + 1; - char *end = data + length - 1; + const char *src = data + 1; + const char *end = data + length - 1; while ( *end != '\'' && *end != '\"' ) { if ( *end == 'i' ) diff --git a/ragel/parsetree.h b/ragel/parsetree.h index 66a4d68..c3a1e21 100644 --- a/ragel/parsetree.h +++ b/ragel/parsetree.h @@ -202,7 +202,7 @@ struct Token void set( const char *str, int len ); }; -char *prepareLitString( const InputLoc &loc, char *src, long length, +char *prepareLitString( const InputLoc &loc, const char *src, long length, long &resLen, bool &caseInsensitive ); /* Store the value and type of a priority augmentation. */ diff --git a/ragel/ragel.h b/ragel/ragel.h index dc9b2f4..942f3d2 100644 --- a/ragel/ragel.h +++ b/ragel/ragel.h @@ -49,7 +49,7 @@ enum MinimizeOpt { /* Options. */ extern MinimizeLevel minimizeLevel; extern MinimizeOpt minimizeOpt; -extern char *machineSpec, *machineName; +extern const char *machineSpec, *machineName; extern bool printStatistics; extern bool wantDupsRemoved; @@ -80,7 +80,7 @@ std::ostream &error( const InputLoc &loc ); std::ostream &warning( const InputLoc &loc ); void terminateAllParsers( ); -void writeMachines( std::ostream &out, std::string hostData, char *inputFileName ); +void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName ); void xmlEscapeHost( std::ostream &out, char *data, long len ); typedef Vector ArgsVector; diff --git a/ragel/rlparse.kh b/ragel/rlparse.kh index 0359c50..e840f8a 100644 --- a/ragel/rlparse.kh +++ b/ragel/rlparse.kh @@ -36,11 +36,11 @@ /* This is used for tracking the include files/machine pairs. */ struct IncludeHistoryItem { - IncludeHistoryItem( char *fileName, char *sectionName ) + IncludeHistoryItem( const char *fileName, const char *sectionName ) : fileName(fileName), sectionName(sectionName) {} - char *fileName; - char *sectionName; + const char *fileName; + const char *sectionName; }; typedef Vector IncludeHistory; @@ -106,7 +106,7 @@ struct Parser void init(); int parseLangEl( int type, const Token *token ); - Parser( char *fileName, char *sectionName, InputLoc §ionLoc ) + Parser( const char *fileName, char *sectionName, InputLoc §ionLoc ) : sectionName(sectionName) { pd = new ParseData( fileName, sectionName, sectionLoc ); diff --git a/ragel/rlscan.h b/ragel/rlscan.h index 756312d..430bef6 100644 --- a/ragel/rlscan.h +++ b/ragel/rlscan.h @@ -37,7 +37,7 @@ extern char *Parser_lelNames[]; struct Scanner { - Scanner( char *fileName, istream &input, ostream &output, + Scanner( const char *fileName, istream &input, ostream &output, Parser *inclToParser, char *inclSectionTarg, int includeDepth, bool importMachines ) : @@ -57,7 +57,7 @@ struct Scanner bool duplicateInclude( char *inclFileName, char *inclSectionName ); /* Make a list of places to look for an included file. */ - char **makeIncludePathChecks( char *curFileName, char *fileName, int len ); + char **makeIncludePathChecks( const char *curFileName, const char *fileName, int len ); std::ifstream *tryOpenInclude( char **pathChecks, long &found ); void handleMachine(); @@ -69,7 +69,7 @@ struct Scanner void token( int type, char c ); void token( int type ); void processToken( int type, char *tokdata, int toklen ); - void directToParser( Parser *toParser, char *tokFileName, int tokLine, + void directToParser( Parser *toParser, const char *tokFileName, int tokLine, int tokColumn, int type, char *tokdata, int toklen ); void flushImport( ); void importToken( int type, char *start, char *end ); @@ -82,7 +82,7 @@ struct Scanner bool active(); ostream &scan_error(); - char *fileName; + const char *fileName; istream &input; ostream &output; Parser *inclToParser; diff --git a/ragel/rlscan.rl b/ragel/rlscan.rl index 5a02105..9c96ef1 100644 --- a/ragel/rlscan.rl +++ b/ragel/rlscan.rl @@ -147,7 +147,7 @@ void Scanner::flushImport() } } -void Scanner::directToParser( Parser *toParser, char *tokFileName, int tokLine, +void Scanner::directToParser( Parser *toParser, const char *tokFileName, int tokLine, int tokColumn, int type, char *tokdata, int toklen ) { InputLoc loc; @@ -550,7 +550,8 @@ bool isAbsolutePath( const char *path ) #endif } -char **Scanner::makeIncludePathChecks( char *thisFileName, char *fileName, int fnlen ) +char **Scanner::makeIncludePathChecks( const char *thisFileName, + const char *fileName, int fnlen ) { char **checks = new char*[2]; long nextCheck = 0; diff --git a/redfsm/gendata.cpp b/redfsm/gendata.cpp index 49d8fe4..8598aaa 100644 --- a/redfsm/gendata.cpp +++ b/redfsm/gendata.cpp @@ -26,7 +26,7 @@ using std::cerr; using std::endl; /* Total error count. */ -int gblErrorCount = 0; +/* int gblErrorCount = 0; */ CodeGenData::CodeGenData( ostream &out ) : @@ -79,7 +79,7 @@ void CodeGenData::initActionList( unsigned long length ) } void CodeGenData::newAction( int anum, char *name, int line, - int col, InlineList *inlineList ) + int col, GenInlineList *inlineList ) { allActions[anum].actionId = anum; allActions[anum].name = name; @@ -255,12 +255,12 @@ void CodeGenData::setEofTrans( int snum, long eofTarget, long actId ) curState->eofTrans = redFsm->allocateTrans( targState, eofAct ); } -void CodeGenData::resolveTargetStates( InlineList *inlineList ) +void CodeGenData::resolveTargetStates( GenInlineList *inlineList ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Goto: case InlineItem::Call: - case InlineItem::Next: case InlineItem::Entry: + case GenInlineItem::Goto: case GenInlineItem::Call: + case GenInlineItem::Next: case GenInlineItem::Entry: item->targState = allStates + item->targId; break; default: @@ -437,38 +437,38 @@ void CodeGenData::findFinalActionRefs() } } -void CodeGenData::analyzeAction( Action *act, InlineList *inlineList ) +void CodeGenData::analyzeAction( Action *act, GenInlineList *inlineList ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { /* Only consider actions that are referenced. */ if ( act->numRefs() > 0 ) { - if ( item->type == InlineItem::Goto || item->type == InlineItem::GotoExpr ) + if ( item->type == GenInlineItem::Goto || item->type == GenInlineItem::GotoExpr ) redFsm->bAnyActionGotos = true; - else if ( item->type == InlineItem::Call || item->type == InlineItem::CallExpr ) + else if ( item->type == GenInlineItem::Call || item->type == GenInlineItem::CallExpr ) redFsm->bAnyActionCalls = true; - else if ( item->type == InlineItem::Ret ) + else if ( item->type == GenInlineItem::Ret ) redFsm->bAnyActionRets = true; } /* Check for various things in regular actions. */ if ( act->numTransRefs > 0 || act->numToStateRefs > 0 || act->numFromStateRefs > 0 ) { /* Any returns in regular actions? */ - if ( item->type == InlineItem::Ret ) + if ( item->type == GenInlineItem::Ret ) redFsm->bAnyRegActionRets = true; /* Any next statements in the regular actions? */ - if ( item->type == InlineItem::Next || item->type == InlineItem::NextExpr ) + if ( item->type == GenInlineItem::Next || item->type == GenInlineItem::NextExpr ) redFsm->bAnyRegNextStmt = true; /* Any by value control in regular actions? */ - if ( item->type == InlineItem::CallExpr || item->type == InlineItem::GotoExpr ) + if ( item->type == GenInlineItem::CallExpr || item->type == GenInlineItem::GotoExpr ) redFsm->bAnyRegActionByValControl = true; /* Any references to the current state in regular actions? */ - if ( item->type == InlineItem::Curs ) + if ( item->type == GenInlineItem::Curs ) redFsm->bAnyRegCurStateRef = true; - if ( item->type == InlineItem::Break ) + if ( item->type == GenInlineItem::Break ) redFsm->bAnyRegBreak = true; } @@ -477,18 +477,18 @@ void CodeGenData::analyzeAction( Action *act, InlineList *inlineList ) } } -void CodeGenData::analyzeActionList( RedAction *redAct, InlineList *inlineList ) +void CodeGenData::analyzeActionList( RedAction *redAct, GenInlineList *inlineList ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { /* Any next statements in the action table? */ - if ( item->type == InlineItem::Next || item->type == InlineItem::NextExpr ) + if ( item->type == GenInlineItem::Next || item->type == GenInlineItem::NextExpr ) redAct->bAnyNextStmt = true; /* Any references to the current state. */ - if ( item->type == InlineItem::Curs ) + if ( item->type == GenInlineItem::Curs ) redAct->bAnyCurStateRef = true; - if ( item->type == InlineItem::Break ) + if ( item->type == GenInlineItem::Break ) redAct->bAnyBreakStmt = true; if ( item->children != 0 ) @@ -668,7 +668,7 @@ void CodeGenData::analyzeMachine() setValueLimits(); } -void CodeGenData::writeStatement( InputLoc &loc, int nargs, char **args ) +void CodeGenData::writeStatement( GenInputLoc &loc, int nargs, char **args ) { /* FIXME: This should be moved to the virtual functions in the code * generators. @@ -728,13 +728,13 @@ void CodeGenData::writeStatement( InputLoc &loc, int nargs, char **args ) } } -ostream &CodeGenData::source_warning( const InputLoc &loc ) +ostream &CodeGenData::source_warning( const GenInputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &CodeGenData::source_error( const InputLoc &loc ) +ostream &CodeGenData::source_error( const GenInputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/redfsm/gendata.h b/redfsm/gendata.h index b61c207..7c68c6e 100644 --- a/redfsm/gendata.h +++ b/redfsm/gendata.h @@ -48,11 +48,24 @@ typedef AvlMapEl CodeGenMapEl; /* 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 *openOutput( char *inputFile ); -CodeGenData *makeCodeGen( char *sourceFileName, +std::ostream *cdOpenOutput( char *inputFile ); +std::ostream *javaOpenOutput( char *inputFile ); +std::ostream *rubyOpenOutput( char *inputFile ); +std::ostream *csharpOpenOutput( char *inputFile ); + +CodeGenData *cdMakeCodeGen( char *sourceFileName, + char *fsmName, ostream &out, bool wantComplete ); +CodeGenData *javaMakeCodeGen( char *sourceFileName, + char *fsmName, ostream &out, bool wantComplete ); +CodeGenData *rubyMakeCodeGen( char *sourceFileName, + char *fsmName, ostream &out, bool wantComplete ); +CodeGenData *csharpMakeCodeGen( char *sourceFileName, char *fsmName, ostream &out, bool wantComplete ); -void lineDirective( ostream &out, char *fileName, int line ); +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 ); +void csharpLineDirective( ostream &out, const char *fileName, int line ); void genLineDirective( ostream &out ); /*********************************/ @@ -72,7 +85,7 @@ struct CodeGenData /* This can also be overwridden to modify the processing of write * statements. */ - virtual void writeStatement( InputLoc &loc, int nargs, char **args ); + virtual void writeStatement( GenInputLoc &loc, int nargs, char **args ); /********************/ @@ -98,22 +111,22 @@ struct CodeGenData ActionList actionList; ConditionList conditionList; CondSpaceList condSpaceList; - InlineList *getKeyExpr; - InlineList *accessExpr; - InlineList *prePushExpr; - InlineList *postPopExpr; + GenInlineList *getKeyExpr; + GenInlineList *accessExpr; + GenInlineList *prePushExpr; + GenInlineList *postPopExpr; /* Overriding variables. */ - InlineList *pExpr; - InlineList *peExpr; - InlineList *eofExpr; - InlineList *csExpr; - InlineList *topExpr; - InlineList *stackExpr; - InlineList *actExpr; - InlineList *tokstartExpr; - InlineList *tokendExpr; - InlineList *dataExpr; + GenInlineList *pExpr; + GenInlineList *peExpr; + GenInlineList *eofExpr; + GenInlineList *csExpr; + GenInlineList *topExpr; + GenInlineList *stackExpr; + GenInlineList *actExpr; + GenInlineList *tokstartExpr; + GenInlineList *tokendExpr; + GenInlineList *dataExpr; KeyOps thisKeyOps; bool wantComplete; @@ -131,7 +144,7 @@ struct CodeGenData void createMachine(); void initActionList( unsigned long length ); - void newAction( int anum, char *name, int line, int col, InlineList *inlineList ); + void newAction( int anum, char *name, int line, int col, GenInlineList *inlineList ); void initActionTableList( unsigned long length ); void initStateList( unsigned long length ); void setStartState( unsigned long startState ); @@ -162,12 +175,12 @@ struct CodeGenData bool setAlphType( char *data ); - void resolveTargetStates( InlineList *inlineList ); + void resolveTargetStates( GenInlineList *inlineList ); Key findMaxKey(); /* Gather various info on the machine. */ - void analyzeActionList( RedAction *redAct, InlineList *inlineList ); - void analyzeAction( Action *act, InlineList *inlineList ); + void analyzeActionList( RedAction *redAct, GenInlineList *inlineList ); + void analyzeAction( Action *act, GenInlineList *inlineList ); void findFinalActionRefs(); void analyzeMachine(); @@ -175,8 +188,8 @@ struct CodeGenData void setValueLimits(); void assignActionIds(); - ostream &source_warning( const InputLoc &loc ); - ostream &source_error( const InputLoc &loc ); + ostream &source_warning( const GenInputLoc &loc ); + ostream &source_error( const GenInputLoc &loc ); }; diff --git a/redfsm/redfsm.cpp b/redfsm/redfsm.cpp index 658ef90..72f7660 100644 --- a/redfsm/redfsm.cpp +++ b/redfsm/redfsm.cpp @@ -27,7 +27,7 @@ using std::ostringstream; -KeyOps *keyOps = 0; +/* KeyOps *keyOps = 0; */ string Action::nameOrLoc() { diff --git a/redfsm/redfsm.h b/redfsm/redfsm.h index 47906f7..eb8d4d9 100644 --- a/redfsm/redfsm.h +++ b/redfsm/redfsm.h @@ -47,11 +47,11 @@ using std::string; struct RedStateAp; -struct InlineList; +struct GenInlineList; struct Action; /* Location in an input file. */ -struct InputLoc +struct GenInputLoc { int line; int col; @@ -60,7 +60,7 @@ struct InputLoc /* * Inline code tree */ -struct InlineItem +struct GenInlineItem { enum Type { @@ -70,26 +70,26 @@ struct InlineItem LmInitAct, LmSetTokStart, SubAction, Break }; - InlineItem( const InputLoc &loc, Type type ) : + GenInlineItem( const GenInputLoc &loc, Type type ) : loc(loc), data(0), targId(0), targState(0), lmId(0), children(0), offset(0), type(type) { } - InputLoc loc; + GenInputLoc loc; char *data; int targId; RedStateAp *targState; int lmId; - InlineList *children; + GenInlineList *children; int offset; Type type; - InlineItem *prev, *next; + GenInlineItem *prev, *next; }; /* Normally this would be atypedef, but that would entail including DList from * ptreetypes, which should be just typedef forwards. */ -struct InlineList : public DList { }; +struct GenInlineList : public DList { }; /* Element in list of actions. Contains the string for the code to exectute. */ struct Action @@ -109,9 +109,9 @@ struct Action } /* Data collected during parse. */ - InputLoc loc; + GenInputLoc loc; char *name; - InlineList *inlineList; + GenInlineList *inlineList; int actionId; string nameOrLoc(); diff --git a/redfsm/xmlparse.kh b/redfsm/xmlparse.kh index 48b861d..431e329 100644 --- a/redfsm/xmlparse.kh +++ b/redfsm/xmlparse.kh @@ -84,19 +84,19 @@ struct XMLTagHashPair struct Token { XMLTag *tag; - InputLoc loc; + GenInputLoc loc; }; -struct InlineItem; -struct InlineList; +struct GenInlineItem; +struct GenInlineList; struct LmSwitchVect; struct LmSwitchAction; -struct Parser +struct XmlParser { %%{ - parser Parser; + parser XmlParser; token TAG_unknown, TAG_ragel, TAG_ragel_def, TAG_host, TAG_state_list, TAG_state, TAG_trans_list, TAG_t, TAG_machine, TAG_start_state, @@ -125,7 +125,7 @@ struct Parser void init(); int parseLangEl( int type, const Token *token ); - Parser( char *fileName, bool outputActive, bool wantComplete ) : + XmlParser( const char *fileName, bool outputActive, bool wantComplete ) : fileName(fileName), sourceFileName(0), outStream(0), outputActive(outputActive), wantComplete(wantComplete), cgd(0) { } @@ -135,14 +135,14 @@ struct Parser int token( XMLTag *tag, int col, int line ); /* Report an error encountered by the parser. */ - ostream &warning( const InputLoc &loc ); + ostream &warning( const GenInputLoc &loc ); ostream &error(); - ostream &error( const InputLoc &loc ); + ostream &error( const GenInputLoc &loc ); ostream &parser_error( int tokId, Token &token ); - ostream &source_error( const InputLoc &loc ); + ostream &source_error( const GenInputLoc &loc ); /* The name of the root section, this does not change during an include. */ - char *fileName; + const char *fileName; char *sourceFileName; ostream *outStream; bool outputActive; @@ -166,7 +166,7 @@ struct Parser %% write token_defs; -int xml_parse( std::istream &input, char *fileName, +int xml_parse( std::istream &input, const char *fileName, bool outputActive, bool wantComplete ); #endif /* _XMLPARSE_H */ diff --git a/redfsm/xmlparse.kl b/redfsm/xmlparse.kl index 424bbd2..cd4d69d 100644 --- a/redfsm/xmlparse.kl +++ b/redfsm/xmlparse.kl @@ -36,9 +36,48 @@ Key readKey( char *td, char **end ); long readOffsetPtr( char *td, char **end ); unsigned long readLength( char *td ); +CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, + ostream &out, bool wantComplete ) +{ + CodeGenData *cgd = 0; + if ( hostLang == &hostLangC ) + cgd = cdMakeCodeGen( sourceFileName, fsmName, out, wantComplete ); + else if ( hostLang == &hostLangD ) + cgd = cdMakeCodeGen( sourceFileName, fsmName, out, wantComplete ); + else if ( hostLang == &hostLangJava ) + cgd = javaMakeCodeGen( sourceFileName, fsmName, out, wantComplete ); + else if ( hostLang == &hostLangRuby ) + cgd = rubyMakeCodeGen( sourceFileName, fsmName, out, wantComplete ); + else if ( hostLang == &hostLangCSharp ) + cgd = csharpMakeCodeGen( sourceFileName, fsmName, out, wantComplete ); + return cgd; +} + +void lineDirective( ostream &out, const char *fileName, int line ) +{ + CodeGenData *cgd = 0; + if ( hostLang == &hostLangC ) + cdLineDirective( out, fileName, line ); + else if ( hostLang == &hostLangD ) + cdLineDirective( out, fileName, line ); + else if ( hostLang == &hostLangJava ) + javaLineDirective( out, fileName, line ); + else if ( hostLang == &hostLangRuby ) + rubyLineDirective( out, fileName, line ); + else if ( hostLang == &hostLangCSharp ) + csharpLineDirective( out, fileName, line ); +} + +void genLineDirective( ostream &out ) +{ + std::streambuf *sbuf = out.rdbuf(); + output_filter *filter = static_cast(sbuf); + lineDirective( out, filter->fileName, filter->line + 1 ); +} + %%{ -parser Parser; +parser XmlParser; include "xmlparse.kh"; @@ -73,22 +112,30 @@ tag_ragel_head: TAG_ragel if ( langAttr == 0 ) error($1->loc) << "tag requires a lang attribute" << endp; - if ( strcmp( langAttr->value, "C" ) == 0 ) + if ( strcmp( langAttr->value, "C" ) == 0 ) { hostLang = &hostLangC; - else if ( strcmp( langAttr->value, "D" ) == 0 ) + outStream = cdOpenOutput( sourceFileName ); + } + else if ( strcmp( langAttr->value, "D" ) == 0 ) { hostLang = &hostLangD; - else if ( strcmp( langAttr->value, "Java" ) == 0 ) + outStream = cdOpenOutput( sourceFileName ); + } + else if ( strcmp( langAttr->value, "Java" ) == 0 ) { hostLang = &hostLangJava; - else if ( strcmp( langAttr->value, "Ruby" ) == 0 ) + outStream = javaOpenOutput( sourceFileName ); + } + else if ( strcmp( langAttr->value, "Ruby" ) == 0 ) { hostLang = &hostLangRuby; - else if ( strcmp( langAttr->value, "C#" ) == 0 ) + outStream = rubyOpenOutput( sourceFileName ); + } + else if ( strcmp( langAttr->value, "C#" ) == 0 ) { hostLang = &hostLangCSharp; + outStream = csharpOpenOutput( sourceFileName ); + } else { error($1->loc) << "expecting lang attribute to be " "one of C, D, Java, Ruby or C#" << endp; } - - outStream = openOutput( sourceFileName ); }; ragel_def_list: ragel_def_list ragel_def; @@ -253,7 +300,7 @@ tag_write: tag_write_head write_option_list '/' TAG_write nonterm tag_write_head { - InputLoc loc; + GenInputLoc loc; }; tag_write_head: TAG_write @@ -525,7 +572,7 @@ tag_action: TAG_action inline_list '/' TAG_action nonterm inline_list { - InlineList *inlineList; + GenInlineList *inlineList; }; @@ -539,12 +586,12 @@ inline_list: inline_list inline_item inline_list: final { /* Start with empty list. */ - $$->inlineList = new InlineList; + $$->inlineList = new GenInlineList; }; nonterm inline_item_type { - InlineItem *inlineItem; + GenInlineItem *inlineItem; }; nonterm inline_item uses inline_item_type; @@ -601,146 +648,146 @@ nonterm tag_lm_switch uses inline_item_type; tag_text: TAG_text '/' TAG_text final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Text ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Text ); $$->inlineItem->data = $3->tag->content; }; tag_goto: TAG_goto '/' TAG_goto final { int targ = strtol( $3->tag->content, 0, 10 ); - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Goto ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Goto ); $$->inlineItem->targId = targ; }; tag_call: TAG_call '/' TAG_call final { int targ = strtol( $3->tag->content, 0, 10 ); - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Call ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Call ); $$->inlineItem->targId = targ; }; tag_next: TAG_next '/' TAG_next final { int targ = strtol( $3->tag->content, 0, 10 ); - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Next ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Next ); $$->inlineItem->targId = targ; }; tag_goto_expr: TAG_goto_expr inline_list '/' TAG_goto_expr final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::GotoExpr ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::GotoExpr ); $$->inlineItem->children = $2->inlineList; }; tag_call_expr: TAG_call_expr inline_list '/' TAG_call_expr final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::CallExpr ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::CallExpr ); $$->inlineItem->children = $2->inlineList; }; tag_next_expr: TAG_next_expr inline_list '/' TAG_next_expr final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::NextExpr ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::NextExpr ); $$->inlineItem->children = $2->inlineList; }; tag_ret: TAG_ret '/' TAG_ret final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Ret ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Ret ); }; tag_break: TAG_break '/' TAG_break final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Break ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Break ); }; tag_pchar: TAG_pchar '/' TAG_pchar final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::PChar ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::PChar ); }; tag_char: TAG_char '/' TAG_char final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Char ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Char ); }; tag_hold: TAG_hold '/' TAG_hold final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Hold ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Hold ); }; tag_exec: TAG_exec inline_list '/' TAG_exec final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Exec ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Exec ); $$->inlineItem->children = $2->inlineList; }; tag_curs: TAG_curs '/' TAG_curs final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Curs ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Curs ); }; tag_targs: TAG_targs '/' TAG_targs final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Targs ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Targs ); }; tag_il_entry: TAG_entry '/' TAG_entry final { int targ = strtol( $3->tag->content, 0, 10 ); - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Entry ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Entry ); $$->inlineItem->targId = targ; }; tag_init_tokstart: TAG_init_tokstart '/' TAG_init_tokstart final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmInitTokStart ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmInitTokStart ); }; tag_init_act: TAG_init_act '/' TAG_init_act final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmInitAct ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmInitAct ); }; tag_get_tokend: TAG_get_tokend '/' TAG_get_tokend final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmGetTokEnd ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmGetTokEnd ); }; tag_set_tokstart: TAG_set_tokstart '/' TAG_set_tokstart final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmSetTokStart ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetTokStart ); cgd->hasLongestMatch = true; }; tag_set_tokend: TAG_set_tokend '/' TAG_set_tokend final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmSetTokEnd ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetTokEnd ); $$->inlineItem->offset = strtol( $3->tag->content, 0, 10 ); }; tag_set_act: TAG_set_act '/' TAG_set_act final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmSetActId ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetActId ); $$->inlineItem->lmId = strtol( $3->tag->content, 0, 10 ); }; tag_sub_action: TAG_sub_action inline_list '/' TAG_sub_action final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::SubAction ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::SubAction ); $$->inlineItem->children = $2->inlineList; }; # Action switches. tag_lm_switch: TAG_lm_switch lm_action_list '/' TAG_lm_switch final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmSwitch ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSwitch ); $$->inlineItem->children = $2->inlineList; }; nonterm lm_action_list { - InlineList *inlineList; + GenInlineList *inlineList; }; lm_action_list: lm_action_list tag_inline_action @@ -750,14 +797,14 @@ lm_action_list: lm_action_list tag_inline_action }; lm_action_list: final { - $$->inlineList = new InlineList; + $$->inlineList = new GenInlineList; }; nonterm tag_inline_action uses inline_item_type; tag_inline_action: TAG_sub_action inline_list '/' TAG_sub_action final { - $$->inlineItem = new InlineItem( InputLoc(), InlineItem::SubAction ); + $$->inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::SubAction ); $$->inlineItem->children = $2->inlineList; Attribute *idAttr = $1->tag->findAttr( "id" ); @@ -876,12 +923,12 @@ tag_cond_space: TAG_cond_space '/' TAG_cond_space write data; }%% -void Parser::init() +void XmlParser::init() { %% write init; } -int Parser::parseLangEl( int type, const Token *token ) +int XmlParser::parseLangEl( int type, const Token *token ) { %% write exec; return errCount == 0 ? 0 : -1; @@ -915,13 +962,13 @@ long readOffsetPtr( char *td, char **end ) return strtol( td, end, 10 ); } -ostream &Parser::warning( const InputLoc &loc ) +ostream &XmlParser::warning( const GenInputLoc &loc ) { cerr << fileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &Parser::error( const InputLoc &loc ) +ostream &XmlParser::error( const GenInputLoc &loc ) { gblErrorCount += 1; assert( fileName != 0 ); @@ -930,7 +977,7 @@ ostream &Parser::error( const InputLoc &loc ) } -ostream &Parser::parser_error( int tokId, Token &token ) +ostream &XmlParser::parser_error( int tokId, Token &token ) { gblErrorCount += 1; assert( fileName != 0 ); @@ -946,7 +993,7 @@ ostream &Parser::parser_error( int tokId, Token &token ) return cerr; } -ostream &Parser::source_error( const InputLoc &loc ) +ostream &XmlParser::source_error( const GenInputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); @@ -955,7 +1002,7 @@ ostream &Parser::source_error( const InputLoc &loc ) } -int Parser::token( int tokenId, Token &tok ) +int XmlParser::token( int tokenId, Token &tok ) { int res = parseLangEl( tokenId, &tok ); if ( res < 0 ) @@ -963,7 +1010,7 @@ int Parser::token( int tokenId, Token &tok ) return res; } -int Parser::token( int tokenId, int col, int line ) +int XmlParser::token( int tokenId, int col, int line ) { Token tok; tok.loc.col = col; @@ -972,7 +1019,7 @@ int Parser::token( int tokenId, int col, int line ) return token( tokenId, tok ); } -int Parser::token( XMLTag *tag, int col, int line ) +int XmlParser::token( XMLTag *tag, int col, int line ) { Token tok; tok.loc.col = col; diff --git a/redfsm/xmlscan.rl b/redfsm/xmlscan.rl index d1eeb72..0835699 100644 --- a/redfsm/xmlscan.rl +++ b/redfsm/xmlscan.rl @@ -32,7 +32,7 @@ using std::endl; #define BUFSIZE 4096 %%{ - machine Scanner; + machine XmlScanner; write data; }%% @@ -45,9 +45,9 @@ public: static struct XMLTagHashPair *in_word_set (const char *str, unsigned int len); }; -struct Scanner +struct XmlScanner { - Scanner( char *fileName, istream &input ) : + XmlScanner( const char *fileName, istream &input ) : fileName(fileName), input(input), curline(1), @@ -58,7 +58,7 @@ struct Scanner value(0) { %%{ - machine Scanner; + machine XmlScanner; write init; }%% } @@ -67,7 +67,7 @@ struct Scanner void adjustAttrPointers( int distance ); std::ostream &error(); - char *fileName; + const char *fileName; istream &input; /* Scanner State. */ @@ -99,7 +99,7 @@ struct Scanner #define ret_tok( _tok ) token = (_tok); data = ts -void Scanner::adjustAttrPointers( int distance ) +void XmlScanner::adjustAttrPointers( int distance ) { for ( AttrMkList::Iter attr = attrMkList; attr.lte(); attr++ ) { attr->id -= distance; @@ -110,7 +110,7 @@ void Scanner::adjustAttrPointers( int distance ) /* There is no claim that this is a proper XML parser, but it is good * enough for our purposes. */ %%{ - machine Scanner; + machine XmlScanner; action colup { curcol++; } action start_tok { token_col = curcol; token_line = curline; } @@ -177,7 +177,7 @@ void Scanner::adjustAttrPointers( int distance ) *|; }%% -int Scanner::scan( ) +int XmlScanner::scan( ) { int token = TK_NO_TOKEN; int space = 0, readlen = 0; @@ -237,7 +237,7 @@ int Scanner::scan( ) %% write exec; - if ( cs == Scanner_error ) + if ( cs == XmlScanner_error ) return TK_ERR; if ( token != TK_NO_TOKEN ) { @@ -247,11 +247,11 @@ int Scanner::scan( ) } } -int xml_parse( std::istream &input, char *fileName, +int xml_parse( std::istream &input, const char *fileName, bool outputActive, bool wantComplete ) { - Scanner scanner( fileName, input ); - Parser parser( fileName, outputActive, wantComplete ); + XmlScanner scanner( fileName, input ); + XmlParser parser( fileName, outputActive, wantComplete ); parser.init(); @@ -341,7 +341,7 @@ int xml_parse( std::istream &input, char *fileName, return 0; } -std::ostream &Scanner::error() +std::ostream &XmlScanner::error() { gblErrorCount += 1; cerr << fileName << ":" << curline << ":" << curcol << ": "; diff --git a/rlgen-cd/Makefile.in b/rlgen-cd/Makefile.in index 2ef727c..6d4a293 100644 --- a/rlgen-cd/Makefile.in +++ b/rlgen-cd/Makefile.in @@ -38,6 +38,8 @@ LIBS = ../common/common.a ../redfsm/redfsm.a prefix = @prefix@ EXEEXT = @EXEEXT@ CXX = @CXX@ +AR = @AR@ +RANLIB = @RANLIB@ # Get objects and dependencies from sources. OBJS = $(CC_SRCS:%.cpp=%.o) @@ -47,10 +49,11 @@ DEPS = $(CC_SRCS:%.cpp=.%.d) include ../version.mk # Rules. -all: rlgen-cd$(EXEEXT) +all: rlgen-cd.a -rlgen-cd$(EXEEXT): $(LIBS) $(OBJS) - $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) +rlgen-cd.a: $(LIBS) $(OBJS) + $(AR) -cr $@ $(OBJS) + $(RANLIB) $@ %.o: %.cpp @$(CXX) -M $(DEFS) $(INCS) $< > .$*.d @@ -60,10 +63,9 @@ distclean: clean rm -f Makefile clean: - rm -f tags .*.d *.o rlgen-cd $(EXTRA_CLEAN) + rm -f tags .*.d *.o rlgen-cd.a $(EXTRA_CLEAN) -install: all - install -d $(prefix)/bin - install -s rlgen-cd $(prefix)/bin/rlgen-cd +install: + @true -include $(DEPS) diff --git a/rlgen-cd/flatcodegen.cpp b/rlgen-cd/flatcodegen.cpp index 55a6642..b9cdfca 100644 --- a/rlgen-cd/flatcodegen.cpp +++ b/rlgen-cd/flatcodegen.cpp @@ -458,7 +458,7 @@ void FlatCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) CTRL_FLOW() << "goto _again;}"; } -void FlatCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void FlatCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); @@ -480,7 +480,7 @@ void FlatCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void FlatCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void FlatCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); @@ -502,7 +502,7 @@ void FlatCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish } -void FlatCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void FlatCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; diff --git a/rlgen-cd/flatcodegen.h b/rlgen-cd/flatcodegen.h index d132bec..ad5674e 100644 --- a/rlgen-cd/flatcodegen.h +++ b/rlgen-cd/flatcodegen.h @@ -68,9 +68,9 @@ protected: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); diff --git a/rlgen-cd/fsmcodegen.cpp b/rlgen-cd/fsmcodegen.cpp index 2d4a14c..ab8f4ad 100644 --- a/rlgen-cd/fsmcodegen.cpp +++ b/rlgen-cd/fsmcodegen.cpp @@ -36,14 +36,14 @@ using std::string; using std::cerr; using std::endl; -void lineDirective( ostream &out, char *fileName, int line ) +void cdLineDirective( ostream &out, const char *fileName, int line ) { if ( noLineDirectives ) out << "/* "; /* Write the preprocessor line info for to the input file. */ out << "#line " << line << " \""; - for ( char *pc = fileName; *pc != 0; pc++ ) { + for ( const char *pc = fileName; *pc != 0; pc++ ) { if ( *pc == '\\' ) out << "\\\\"; else @@ -57,11 +57,11 @@ void lineDirective( ostream &out, char *fileName, int line ) out << '\n'; } -void genLineDirective( ostream &out ) +void FsmCodeGen::genLineDirective( ostream &out ) { std::streambuf *sbuf = out.rdbuf(); output_filter *filter = static_cast(sbuf); - lineDirective( out, filter->fileName, filter->line + 1 ); + cdLineDirective( out, filter->fileName, filter->line + 1 ); } @@ -317,7 +317,7 @@ string FsmCodeGen::KEY( Key key ) return ret.str(); } -void FsmCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ) +void FsmCodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ) { /* The parser gives fexec two children. The double brackets are for D * code. If the inline list is a single word it will get interpreted as a @@ -327,14 +327,14 @@ void FsmCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFini ret << "))-1;}"; } -void FsmCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, +void FsmCodeGen::LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish, bool csForced ) { ret << " switch( " << ACT() << " ) {\n"; bool haveDefault = false; - for ( InlineList::Iter lma = *item->children; lma.lte(); lma++ ) { + for ( GenInlineList::Iter lma = *item->children; lma.lte(); lma++ ) { /* Write the case label, the action and the case break. */ if ( lma->lmId < 0 ) { ret << " default:\n"; @@ -359,12 +359,12 @@ void FsmCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, "\t"; } -void FsmCodeGen::SET_ACT( ostream &ret, InlineItem *item ) +void FsmCodeGen::SET_ACT( ostream &ret, GenInlineItem *item ) { ret << ACT() << " = " << item->lmId << ";"; } -void FsmCodeGen::SET_TOKEND( ostream &ret, InlineItem *item ) +void FsmCodeGen::SET_TOKEND( ostream &ret, GenInlineItem *item ) { /* The tokend action sets tokend. */ ret << TOKEND() << " = " << P(); @@ -373,27 +373,27 @@ void FsmCodeGen::SET_TOKEND( ostream &ret, InlineItem *item ) out << ";"; } -void FsmCodeGen::GET_TOKEND( ostream &ret, InlineItem *item ) +void FsmCodeGen::GET_TOKEND( ostream &ret, GenInlineItem *item ) { ret << TOKEND(); } -void FsmCodeGen::INIT_TOKSTART( ostream &ret, InlineItem *item ) +void FsmCodeGen::INIT_TOKSTART( ostream &ret, GenInlineItem *item ) { ret << TOKSTART() << " = " << NULL_ITEM() << ";"; } -void FsmCodeGen::INIT_ACT( ostream &ret, InlineItem *item ) +void FsmCodeGen::INIT_ACT( ostream &ret, GenInlineItem *item ) { ret << ACT() << " = 0;"; } -void FsmCodeGen::SET_TOKSTART( ostream &ret, InlineItem *item ) +void FsmCodeGen::SET_TOKSTART( ostream &ret, GenInlineItem *item ) { ret << TOKSTART() << " = " << P() << ";"; } -void FsmCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, +void FsmCodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish, bool csForced ) { if ( item->children->length() > 0 ) { @@ -407,81 +407,81 @@ void FsmCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, /* Write out an inline tree structure. Walks the list and possibly calls out * to virtual functions than handle language specific items in the tree. */ -void FsmCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, +void FsmCodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish, bool csForced ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Text: + case GenInlineItem::Text: ret << item->data; break; - case InlineItem::Goto: + case GenInlineItem::Goto: GOTO( ret, item->targState->id, inFinish ); break; - case InlineItem::Call: + case GenInlineItem::Call: CALL( ret, item->targState->id, targState, inFinish ); break; - case InlineItem::Next: + case GenInlineItem::Next: NEXT( ret, item->targState->id, inFinish ); break; - case InlineItem::Ret: + case GenInlineItem::Ret: RET( ret, inFinish ); break; - case InlineItem::PChar: + case GenInlineItem::PChar: ret << P(); break; - case InlineItem::Char: + case GenInlineItem::Char: ret << GET_KEY(); break; - case InlineItem::Hold: + case GenInlineItem::Hold: ret << P() << "--;"; break; - case InlineItem::Exec: + case GenInlineItem::Exec: EXEC( ret, item, targState, inFinish ); break; - case InlineItem::Curs: + case GenInlineItem::Curs: CURS( ret, inFinish ); break; - case InlineItem::Targs: + case GenInlineItem::Targs: TARGS( ret, inFinish, targState ); break; - case InlineItem::Entry: + case GenInlineItem::Entry: ret << item->targState->id; break; - case InlineItem::GotoExpr: + case GenInlineItem::GotoExpr: GOTO_EXPR( ret, item, inFinish ); break; - case InlineItem::CallExpr: + case GenInlineItem::CallExpr: CALL_EXPR( ret, item, targState, inFinish ); break; - case InlineItem::NextExpr: + case GenInlineItem::NextExpr: NEXT_EXPR( ret, item, inFinish ); break; - case InlineItem::LmSwitch: + case GenInlineItem::LmSwitch: LM_SWITCH( ret, item, targState, inFinish, csForced ); break; - case InlineItem::LmSetActId: + case GenInlineItem::LmSetActId: SET_ACT( ret, item ); break; - case InlineItem::LmSetTokEnd: + case GenInlineItem::LmSetTokEnd: SET_TOKEND( ret, item ); break; - case InlineItem::LmGetTokEnd: + case GenInlineItem::LmGetTokEnd: GET_TOKEND( ret, item ); break; - case InlineItem::LmInitTokStart: + case GenInlineItem::LmInitTokStart: INIT_TOKSTART( ret, item ); break; - case InlineItem::LmInitAct: + case GenInlineItem::LmInitAct: INIT_ACT( ret, item ); break; - case InlineItem::LmSetTokStart: + case GenInlineItem::LmSetTokStart: SET_TOKSTART( ret, item ); break; - case InlineItem::SubAction: + case GenInlineItem::SubAction: SUB_ACTION( ret, item, targState, inFinish, csForced ); break; - case InlineItem::Break: + case GenInlineItem::Break: BREAK( ret, targState, csForced ); break; } @@ -504,7 +504,7 @@ void FsmCodeGen::ACTION( ostream &ret, Action *action, int targState, bool inFinish, bool csForced ) { /* Write the preprocessor line info for going into the source file. */ - lineDirective( ret, sourceFileName, action->loc.line ); + cdLineDirective( ret, sourceFileName, action->loc.line ); /* Write the block and close it off. */ ret << "\t{"; @@ -515,7 +515,7 @@ void FsmCodeGen::ACTION( ostream &ret, Action *action, int targState, void FsmCodeGen::CONDITION( ostream &ret, Action *condition ) { ret << "\n"; - lineDirective( ret, sourceFileName, condition->loc.line ); + cdLineDirective( ret, sourceFileName, condition->loc.line ); INLINE_LIST( ret, condition->inlineList, 0, false, false ); } @@ -814,13 +814,13 @@ void FsmCodeGen::finishRagelDef() calcIndexSize(); } -ostream &FsmCodeGen::source_warning( const InputLoc &loc ) +ostream &FsmCodeGen::source_warning( const GenInputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &FsmCodeGen::source_error( const InputLoc &loc ) +ostream &FsmCodeGen::source_error( const GenInputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-cd/fsmcodegen.h b/rlgen-cd/fsmcodegen.h index 9088370..5fa9bfb 100644 --- a/rlgen-cd/fsmcodegen.h +++ b/rlgen-cd/fsmcodegen.h @@ -42,8 +42,8 @@ struct RedStateAp; struct CodeGenData; struct Action; struct NameInst; -struct InlineItem; -struct InlineList; +struct GenInlineItem; +struct GenInlineList; struct RedAction; struct LongestMatch; struct LongestMatchPart; @@ -129,29 +129,29 @@ protected: string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; } string CTXDATA() { return DATA_PREFIX() + "ctxdata"; } - void INLINE_LIST( ostream &ret, InlineList *inlineList, + void INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish, bool csForced ); virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0; virtual void CALL( ostream &ret, int callDest, int targState, bool inFinish ) = 0; virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0; - virtual void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) = 0; - virtual void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) = 0; - virtual void CALL_EXPR( ostream &ret, InlineItem *ilItem, + virtual void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0; + virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0; + virtual void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) = 0; virtual void RET( ostream &ret, bool inFinish ) = 0; virtual void BREAK( ostream &ret, int targState, bool csForced ) = 0; virtual void CURS( ostream &ret, bool inFinish ) = 0; virtual void TARGS( ostream &ret, bool inFinish, int targState ) = 0; - void EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ); - void LM_SWITCH( ostream &ret, InlineItem *item, int targState, + void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish, bool csForced ); - void SET_ACT( ostream &ret, InlineItem *item ); - void INIT_TOKSTART( ostream &ret, InlineItem *item ); - void INIT_ACT( ostream &ret, InlineItem *item ); - void SET_TOKSTART( ostream &ret, InlineItem *item ); - void SET_TOKEND( ostream &ret, InlineItem *item ); - void GET_TOKEND( ostream &ret, InlineItem *item ); - void SUB_ACTION( ostream &ret, InlineItem *item, + void SET_ACT( ostream &ret, GenInlineItem *item ); + void INIT_TOKSTART( ostream &ret, GenInlineItem *item ); + void INIT_ACT( ostream &ret, GenInlineItem *item ); + void SET_TOKSTART( ostream &ret, GenInlineItem *item ); + void SET_TOKEND( ostream &ret, GenInlineItem *item ); + void GET_TOKEND( ostream &ret, GenInlineItem *item ); + void SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish, bool csForced ); void STATE_IDS(); @@ -165,8 +165,8 @@ protected: virtual string CTRL_FLOW() = 0; - ostream &source_warning(const InputLoc &loc); - ostream &source_error(const InputLoc &loc); + ostream &source_warning(const GenInputLoc &loc); + ostream &source_error(const GenInputLoc &loc); unsigned int arrayTypeSize( unsigned long maxVal ); @@ -175,6 +175,8 @@ protected: bool againLabelUsed; bool useIndicies; + void genLineDirective( ostream &out ); + public: /* Determine if we should use indicies. */ virtual void calcIndexSize() {} diff --git a/rlgen-cd/gotocodegen.cpp b/rlgen-cd/gotocodegen.cpp index aa779b9..0309f76 100644 --- a/rlgen-cd/gotocodegen.cpp +++ b/rlgen-cd/gotocodegen.cpp @@ -547,7 +547,7 @@ void GotoCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) CTRL_FLOW() << "goto _again;}"; } -void GotoCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void GotoCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); @@ -569,7 +569,7 @@ void GotoCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void GotoCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void GotoCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); @@ -590,7 +590,7 @@ void GotoCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish ret << "}"; } -void GotoCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void GotoCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; diff --git a/rlgen-cd/gotocodegen.h b/rlgen-cd/gotocodegen.h index b083d09..dace568 100644 --- a/rlgen-cd/gotocodegen.h +++ b/rlgen-cd/gotocodegen.h @@ -53,9 +53,9 @@ public: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); diff --git a/rlgen-cd/ipgotocodegen.cpp b/rlgen-cd/ipgotocodegen.cpp index f12824a..220df53 100644 --- a/rlgen-cd/ipgotocodegen.cpp +++ b/rlgen-cd/ipgotocodegen.cpp @@ -53,7 +53,7 @@ void IpGotoCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFini ret << "}"; } -void IpGotoCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void IpGotoCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; @@ -81,7 +81,7 @@ void IpGotoCodeGen::RET( ostream &ret, bool inFinish ) ret << CTRL_FLOW() << "goto _again;}"; } -void IpGotoCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void IpGotoCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); @@ -93,7 +93,7 @@ void IpGotoCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void IpGotoCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void IpGotoCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); @@ -302,11 +302,11 @@ std::ostream &IpGotoCodeGen::FINISH_CASES() return out; } -void IpGotoCodeGen::setLabelsNeeded( InlineList *inlineList ) +void IpGotoCodeGen::setLabelsNeeded( GenInlineList *inlineList ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Goto: case InlineItem::Call: { + case GenInlineItem::Goto: case GenInlineItem::Call: { /* Mark the target as needing a label. */ item->targState->labelNeeded = true; break; diff --git a/rlgen-cd/ipgotocodegen.h b/rlgen-cd/ipgotocodegen.h index 1a452ae..caff0d7 100644 --- a/rlgen-cd/ipgotocodegen.h +++ b/rlgen-cd/ipgotocodegen.h @@ -46,9 +46,9 @@ public: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void RET( ostream &ret, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); @@ -67,7 +67,7 @@ protected: void STATE_GOTO_ERROR(); /* Set up labelNeeded flag for each state. */ - void setLabelsNeeded( InlineList *inlineList ); + void setLabelsNeeded( GenInlineList *inlineList ); void setLabelsNeeded(); }; diff --git a/rlgen-cd/main.cpp b/rlgen-cd/main.cpp index 13ed991..4de2bce 100644 --- a/rlgen-cd/main.cpp +++ b/rlgen-cd/main.cpp @@ -59,7 +59,7 @@ CodeStyleEnum codeStyle = GenTables; istream *inStream = 0; ostream *outStream = 0; output_filter *outFilter = 0; -char *outputFileName = 0; +const char *outputFileName = 0; /* Graphviz dot file generation. */ bool graphvizDone = false; @@ -69,7 +69,7 @@ bool noLineDirectives = false; bool printPrintables = false; /* Print a summary of the options. */ -void usage() +void cd_usage() { cout << "usage: " PROGNAME " [options] file\n" @@ -92,14 +92,14 @@ void usage() } /* Print version information. */ -void version() +void cd_version() { cout << "Ragel Code Generator for C, C++, Objective-C and D" << endl << "Version " VERSION << ", " PUBDATE << endl << "Copyright (c) 2001-2007 by Adrian Thurston" << endl; } -ostream &error() +ostream &cd_error() { gblErrorCount += 1; cerr << PROGNAME ": "; @@ -111,10 +111,10 @@ ostream &error() */ /* Invoked by the parser when the root element is opened. */ -ostream *openOutput( char *inputFile ) +ostream *cdOpenOutput( char *inputFile ) { if ( hostLang->lang != HostLang::C && hostLang->lang != HostLang::D ) { - error() << "this code generator is for C and D only" << endl; + cd_error() << "this code generator is for C and D only" << endl; exit(1); } @@ -137,7 +137,7 @@ ostream *openOutput( 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 << + cd_error() << "output file \"" << outputFileName << "\" is the same as the input file" << endl; } @@ -146,7 +146,7 @@ ostream *openOutput( char *inputFile ) outFilter = new output_filter( outputFileName ); outFilter->open( outputFileName, ios::out|ios::trunc ); if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; + cd_error() << "error opening " << outputFileName << " for writing" << endl; exit(1); } @@ -161,7 +161,7 @@ ostream *openOutput( char *inputFile ) } /* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, +CodeGenData *cdMakeCodeGen( char *sourceFileName, char *fsmName, ostream &out, bool wantComplete ) { CodeGenData *codeGen = 0; @@ -234,13 +234,11 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, return codeGen; } - - /* Main, process args and call yyparse to start scanning input. */ -int main(int argc, char **argv) +int cd_main(int argc, const char **argv) { ParamCheck pc("-:Hh?vLo:T:F:G:P:", argc, argv); - char *xmlInputFileName = 0; + const char *xmlInputFileName = 0; while ( pc.check() ) { switch ( pc.state ) { @@ -249,9 +247,9 @@ int main(int argc, char **argv) /* Output. */ case 'o': if ( *pc.paramArg == 0 ) - error() << "a zero length output file name was given" << endl; + cd_error() << "a zero length output file name was given" << endl; else if ( outputFileName != 0 ) - error() << "more than one output file name was given" << endl; + cd_error() << "more than one output file name was given" << endl; else { /* Ok, remember the output file name. */ outputFileName = pc.paramArg; @@ -269,7 +267,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '1' ) codeStyle = GenFTables; else { - error() << "-T" << pc.paramArg[0] << + cd_error() << "-T" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -280,7 +278,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '1' ) codeStyle = GenFFlat; else { - error() << "-F" << pc.paramArg[0] << + cd_error() << "-F" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -293,7 +291,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '2' ) codeStyle = GenIpGoto; else { - error() << "-G" << pc.paramArg[0] << + cd_error() << "-G" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -305,22 +303,22 @@ int main(int argc, char **argv) /* Version and help. */ case 'v': - version(); + cd_version(); exit(0); case 'H': case 'h': case '?': - usage(); + cd_usage(); exit(0); case '-': if ( strcmp(pc.paramArg, "help") == 0 ) { - usage(); + cd_usage(); exit(0); } else if ( strcmp(pc.paramArg, "version") == 0 ) { - version(); + cd_version(); exit(0); } else { - error() << "--" << pc.paramArg << + cd_error() << "--" << pc.paramArg << " is an invalid argument" << endl; break; } @@ -328,14 +326,14 @@ int main(int argc, char **argv) break; case ParamCheck::invalid: - error() << "-" << pc.parameter << " is an invalid argument" << endl; + cd_error() << "-" << pc.parameter << " is an invalid argument" << endl; break; case ParamCheck::noparam: if ( *pc.curArg == 0 ) - error() << "a zero length input file name was given" << endl; + cd_error() << "a zero length input file name was given" << endl; else if ( xmlInputFileName != 0 ) - error() << "more than one input file name was given" << endl; + cd_error() << "more than one input file name was given" << endl; else { /* OK, Remember the filename. */ xmlInputFileName = pc.curArg; @@ -354,7 +352,7 @@ int main(int argc, char **argv) ifstream *inFile = new ifstream( xmlInputFileName ); inStream = inFile; if ( ! inFile->is_open() ) - error() << "could not open " << xmlInputFileName << " for reading" << endl; + cd_error() << "could not open " << xmlInputFileName << " for reading" << endl; } else { xmlInputFileName = strdup(""); diff --git a/rlgen-cd/splitcodegen.cpp b/rlgen-cd/splitcodegen.cpp index 22918a5..d4fc07d 100644 --- a/rlgen-cd/splitcodegen.cpp +++ b/rlgen-cd/splitcodegen.cpp @@ -434,11 +434,11 @@ void SplitCodeGen::writeExec() ALL_PARTITIONS(); } -void SplitCodeGen::setLabelsNeeded( RedStateAp *fromState, InlineList *inlineList ) +void SplitCodeGen::setLabelsNeeded( RedStateAp *fromState, GenInlineList *inlineList ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Goto: case InlineItem::Call: { + case GenInlineItem::Goto: case GenInlineItem::Call: { /* In split code gen we only need labels for transitions across * partitions. */ if ( fromState->partition == item->targState->partition ){ diff --git a/rlgen-cd/splitcodegen.h b/rlgen-cd/splitcodegen.h index 82fc371..abba1ab 100644 --- a/rlgen-cd/splitcodegen.h +++ b/rlgen-cd/splitcodegen.h @@ -43,7 +43,7 @@ public: void writeExec(); void writeParts(); - void setLabelsNeeded( RedStateAp *fromState, InlineList *inlineList ); + void setLabelsNeeded( RedStateAp *fromState, GenInlineList *inlineList ); void setLabelsNeeded( RedStateAp *fromState, RedTransAp *trans ); void setLabelsNeeded(); diff --git a/rlgen-cd/tabcodegen.cpp b/rlgen-cd/tabcodegen.cpp index cc6d670..a46e997 100644 --- a/rlgen-cd/tabcodegen.cpp +++ b/rlgen-cd/tabcodegen.cpp @@ -670,7 +670,7 @@ void TabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) CTRL_FLOW() << "goto _again;}"; } -void TabCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void TabCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); @@ -692,7 +692,7 @@ void TabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void TabCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void TabCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish, false ); @@ -713,7 +713,7 @@ void TabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish ret << "}"; } -void TabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void TabCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; diff --git a/rlgen-cd/tabcodegen.h b/rlgen-cd/tabcodegen.h index c8a4a21..79f1864 100644 --- a/rlgen-cd/tabcodegen.h +++ b/rlgen-cd/tabcodegen.h @@ -75,9 +75,9 @@ protected: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); diff --git a/rlgen-csharp/Makefile.in b/rlgen-csharp/Makefile.in index 78c5a58..24d992b 100644 --- a/rlgen-csharp/Makefile.in +++ b/rlgen-csharp/Makefile.in @@ -38,6 +38,8 @@ LIBS = ../common/common.a ../redfsm/redfsm.a prefix = @prefix@ EXEEXT = @EXEEXT@ CXX = @CXX@ +AR = @AR@ +RANLIB = @RANLIB@ # Get objects and dependencies from sources. OBJS = $(CC_SRCS:%.cpp=%.o) @@ -47,10 +49,11 @@ DEPS = $(CC_SRCS:%.cpp=.%.d) include ../version.mk # Rules. -all: rlgen-csharp$(EXEEXT) +all: rlgen-csharp.a -rlgen-csharp$(EXEEXT): $(LIBS) $(OBJS) - $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) +rlgen-csharp.a: $(LIBS) $(OBJS) + $(AR) -cr $@ $(OBJS) + $(RANLIB) $@ %.o: %.cpp @$(CXX) -M $(DEFS) $(INCS) $< > .$*.d @@ -60,10 +63,9 @@ distclean: clean rm -f Makefile clean: - rm -f tags .*.d *.o rlgen-csharp $(EXTRA_CLEAN) + rm -f tags .*.d *.o rlgen-csharp.a $(EXTRA_CLEAN) -install: all - install -d $(prefix)/bin - install -s rlgen-csharp $(prefix)/bin/rlgen-csharp +install: + @true -include $(DEPS) diff --git a/rlgen-csharp/fflatcodegen.h b/rlgen-csharp/fflatcodegen.h index fc828f4..c45885a 100644 --- a/rlgen-csharp/fflatcodegen.h +++ b/rlgen-csharp/fflatcodegen.h @@ -36,7 +36,7 @@ struct CodeGenData; class CSharpFFlatCodeGen : public CSharpFlatCodeGen { public: - CSharpFFlatCodeGen( ostream &out ) : FsmCodeGen(out), CSharpFlatCodeGen(out) {} + CSharpFFlatCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpFlatCodeGen(out) {} private: std::ostream &TO_STATE_ACTION_SWITCH(); std::ostream &FROM_STATE_ACTION_SWITCH(); diff --git a/rlgen-csharp/fgotocodegen.h b/rlgen-csharp/fgotocodegen.h index 47f400e..53a039f 100644 --- a/rlgen-csharp/fgotocodegen.h +++ b/rlgen-csharp/fgotocodegen.h @@ -37,7 +37,7 @@ struct CodeGenData; class CSharpFGotoCodeGen : public CSharpGotoCodeGen { public: - CSharpFGotoCodeGen( ostream &out ) : FsmCodeGen(out), CSharpGotoCodeGen(out) {} + CSharpFGotoCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpGotoCodeGen(out) {} std::ostream &EXEC_ACTIONS(); std::ostream &TO_STATE_ACTION_SWITCH(); diff --git a/rlgen-csharp/flatcodegen.cpp b/rlgen-csharp/flatcodegen.cpp index ca3ce89..bb25d17 100644 --- a/rlgen-csharp/flatcodegen.cpp +++ b/rlgen-csharp/flatcodegen.cpp @@ -459,7 +459,7 @@ void CSharpFlatCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) CTRL_FLOW() << "goto _again;}"; } -void CSharpFlatCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void CSharpFlatCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -481,7 +481,7 @@ void CSharpFlatCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void CSharpFlatCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void CSharpFlatCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -503,7 +503,7 @@ void CSharpFlatCodeGen::CALL( ostream &ret, int callDest, int targState, bool in } -void CSharpFlatCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void CSharpFlatCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; diff --git a/rlgen-csharp/flatcodegen.h b/rlgen-csharp/flatcodegen.h index aad84ae..b9c9ee3 100644 --- a/rlgen-csharp/flatcodegen.h +++ b/rlgen-csharp/flatcodegen.h @@ -36,10 +36,10 @@ struct RedStateAp; /* * CSharpFlatCodeGen */ -class CSharpFlatCodeGen : virtual public FsmCodeGen, public CSharpCodeGen +class CSharpFlatCodeGen : virtual public CSharpFsmCodeGen, public CSharpCodeGen { public: - CSharpFlatCodeGen( ostream &out ) : FsmCodeGen(out), CSharpCodeGen(out) {} + CSharpFlatCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpCodeGen(out) {} virtual ~CSharpFlatCodeGen() { } protected: @@ -68,9 +68,9 @@ protected: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); diff --git a/rlgen-csharp/fsmcodegen.cpp b/rlgen-csharp/fsmcodegen.cpp index dafb4bc..2dc8a2d 100644 --- a/rlgen-csharp/fsmcodegen.cpp +++ b/rlgen-csharp/fsmcodegen.cpp @@ -37,14 +37,14 @@ using std::string; using std::cerr; using std::endl; -void lineDirective( ostream &out, char *fileName, int line ) +void csharpLineDirective( ostream &out, const char *fileName, int line ) { if ( noLineDirectives ) out << "/* "; /* Write the preprocessor line info for to the input file. */ out << "#line " << line << " \""; - for ( char *pc = fileName; *pc != 0; pc++ ) { + for ( const char *pc = fileName; *pc != 0; pc++ ) { if ( *pc == '\\' ) out << "\\\\"; else @@ -58,22 +58,22 @@ void lineDirective( ostream &out, char *fileName, int line ) out << '\n'; } -void genLineDirective( ostream &out ) +void CSharpFsmCodeGen::genLineDirective( ostream &out ) { std::streambuf *sbuf = out.rdbuf(); output_filter *filter = static_cast(sbuf); - lineDirective( out, filter->fileName, filter->line + 1 ); + csharpLineDirective( out, filter->fileName, filter->line + 1 ); } /* Init code gen with in parameters. */ -FsmCodeGen::FsmCodeGen( ostream &out ) +CSharpFsmCodeGen::CSharpFsmCodeGen( ostream &out ) : CodeGenData(out) { } -unsigned int FsmCodeGen::arrayTypeSize( unsigned long maxVal ) +unsigned int CSharpFsmCodeGen::arrayTypeSize( unsigned long maxVal ) { long long maxValLL = (long long) maxVal; HostType *arrayType = keyOps->typeSubsumes( maxValLL ); @@ -81,12 +81,12 @@ unsigned int FsmCodeGen::arrayTypeSize( unsigned long maxVal ) return arrayType->size; } -string FsmCodeGen::ARRAY_TYPE( unsigned long maxVal ) +string CSharpFsmCodeGen::ARRAY_TYPE( unsigned long maxVal ) { return ARRAY_TYPE( maxVal, false ); } -string FsmCodeGen::ARRAY_TYPE( unsigned long maxVal, bool forceSigned ) +string CSharpFsmCodeGen::ARRAY_TYPE( unsigned long maxVal, bool forceSigned ) { long long maxValLL = (long long) maxVal; HostType *arrayType; @@ -105,13 +105,13 @@ string FsmCodeGen::ARRAY_TYPE( unsigned long maxVal, bool forceSigned ) } /* Write out the fsm name. */ -string FsmCodeGen::FSM_NAME() +string CSharpFsmCodeGen::FSM_NAME() { return fsmName; } /* Emit the offset of the start state as a decimal integer. */ -string FsmCodeGen::START_STATE_ID() +string CSharpFsmCodeGen::START_STATE_ID() { ostringstream ret; ret << redFsm->startState->id; @@ -119,7 +119,7 @@ string FsmCodeGen::START_STATE_ID() }; /* Write out the array of actions. */ -std::ostream &FsmCodeGen::ACTIONS_ARRAY() +std::ostream &CSharpFsmCodeGen::ACTIONS_ARRAY() { out << "\t0, "; int totalActions = 1; @@ -145,7 +145,7 @@ std::ostream &FsmCodeGen::ACTIONS_ARRAY() } -string FsmCodeGen::ACCESS() +string CSharpFsmCodeGen::ACCESS() { ostringstream ret; if ( accessExpr != 0 ) @@ -154,7 +154,7 @@ string FsmCodeGen::ACCESS() } -string FsmCodeGen::P() +string CSharpFsmCodeGen::P() { ostringstream ret; if ( pExpr == 0 ) @@ -167,7 +167,7 @@ string FsmCodeGen::P() return ret.str(); } -string FsmCodeGen::PE() +string CSharpFsmCodeGen::PE() { ostringstream ret; if ( peExpr == 0 ) @@ -180,7 +180,7 @@ string FsmCodeGen::PE() return ret.str(); } -string FsmCodeGen::EOFV() +string CSharpFsmCodeGen::EOFV() { ostringstream ret; if ( eofExpr == 0 ) @@ -193,7 +193,7 @@ string FsmCodeGen::EOFV() return ret.str(); } -string FsmCodeGen::CS() +string CSharpFsmCodeGen::CS() { ostringstream ret; if ( csExpr == 0 ) @@ -207,7 +207,7 @@ string FsmCodeGen::CS() return ret.str(); } -string FsmCodeGen::TOP() +string CSharpFsmCodeGen::TOP() { ostringstream ret; if ( topExpr == 0 ) @@ -220,7 +220,7 @@ string FsmCodeGen::TOP() return ret.str(); } -string FsmCodeGen::STACK() +string CSharpFsmCodeGen::STACK() { ostringstream ret; if ( stackExpr == 0 ) @@ -233,7 +233,7 @@ string FsmCodeGen::STACK() return ret.str(); } -string FsmCodeGen::ACT() +string CSharpFsmCodeGen::ACT() { ostringstream ret; if ( actExpr == 0 ) @@ -246,7 +246,7 @@ string FsmCodeGen::ACT() return ret.str(); } -string FsmCodeGen::TOKSTART() +string CSharpFsmCodeGen::TOKSTART() { ostringstream ret; if ( tokstartExpr == 0 ) @@ -259,7 +259,7 @@ string FsmCodeGen::TOKSTART() return ret.str(); } -string FsmCodeGen::TOKEND() +string CSharpFsmCodeGen::TOKEND() { ostringstream ret; if ( tokendExpr == 0 ) @@ -272,7 +272,7 @@ string FsmCodeGen::TOKEND() return ret.str(); } -string FsmCodeGen::GET_WIDE_KEY() +string CSharpFsmCodeGen::GET_WIDE_KEY() { if ( redFsm->anyConditions() ) return "_widec"; @@ -280,7 +280,7 @@ string FsmCodeGen::GET_WIDE_KEY() return GET_KEY(); } -string FsmCodeGen::GET_WIDE_KEY( RedStateAp *state ) +string CSharpFsmCodeGen::GET_WIDE_KEY( RedStateAp *state ) { if ( state->stateCondList.length() > 0 ) return "_widec"; @@ -288,7 +288,7 @@ string FsmCodeGen::GET_WIDE_KEY( RedStateAp *state ) return GET_KEY(); } -string FsmCodeGen::GET_KEY() +string CSharpFsmCodeGen::GET_KEY() { ostringstream ret; if ( getKeyExpr != 0 ) { @@ -306,7 +306,7 @@ string FsmCodeGen::GET_KEY() /* Write out level number of tabs. Makes the nested binary search nice * looking. */ -string FsmCodeGen::TABS( int level ) +string CSharpFsmCodeGen::TABS( int level ) { string result; while ( level-- > 0 ) @@ -316,7 +316,7 @@ string FsmCodeGen::TABS( int level ) /* Write out a key from the fsm code gen. Depends on wether or not the key is * signed. */ -string FsmCodeGen::KEY( Key key ) +string CSharpFsmCodeGen::KEY( Key key ) { ostringstream ret; if ( keyOps->isSigned || !hostLang->explicitUnsigned ) @@ -326,7 +326,7 @@ string FsmCodeGen::KEY( Key key ) return ret.str(); } -string FsmCodeGen::ALPHA_KEY( Key key ) +string CSharpFsmCodeGen::ALPHA_KEY( Key key ) { ostringstream ret; if (key.getVal() > 0xFFFF) { @@ -339,7 +339,7 @@ string FsmCodeGen::ALPHA_KEY( Key key ) return ret.str(); } -void FsmCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ) +void CSharpFsmCodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ) { /* The parser gives fexec two children. The double brackets are for D * code. If the inline list is a single word it will get interpreted as a @@ -349,13 +349,13 @@ void FsmCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFini ret << "))-1;}"; } -void FsmCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, +void CSharpFsmCodeGen::LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish ) { ret << " switch( " << ACT() << " ) {\n"; - for ( InlineList::Iter lma = *item->children; lma.lte(); lma++ ) { + for ( GenInlineList::Iter lma = *item->children; lma.lte(); lma++ ) { /* Write the case label, the action and the case break. */ if ( lma->lmId < 0 ) ret << " default:\n"; @@ -375,12 +375,12 @@ void FsmCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, "\t"; } -void FsmCodeGen::SET_ACT( ostream &ret, InlineItem *item ) +void CSharpFsmCodeGen::SET_ACT( ostream &ret, GenInlineItem *item ) { ret << ACT() << " = " << item->lmId << ";"; } -void FsmCodeGen::SET_TOKEND( ostream &ret, InlineItem *item ) +void CSharpFsmCodeGen::SET_TOKEND( ostream &ret, GenInlineItem *item ) { /* The tokend action sets tokend. */ ret << TOKEND() << " = " << P(); @@ -389,27 +389,27 @@ void FsmCodeGen::SET_TOKEND( ostream &ret, InlineItem *item ) out << ";"; } -void FsmCodeGen::GET_TOKEND( ostream &ret, InlineItem *item ) +void CSharpFsmCodeGen::GET_TOKEND( ostream &ret, GenInlineItem *item ) { ret << TOKEND(); } -void FsmCodeGen::INIT_TOKSTART( ostream &ret, InlineItem *item ) +void CSharpFsmCodeGen::INIT_TOKSTART( ostream &ret, GenInlineItem *item ) { ret << TOKSTART() << " = " << NULL_ITEM() << ";"; } -void FsmCodeGen::INIT_ACT( ostream &ret, InlineItem *item ) +void CSharpFsmCodeGen::INIT_ACT( ostream &ret, GenInlineItem *item ) { ret << ACT() << " = 0;"; } -void FsmCodeGen::SET_TOKSTART( ostream &ret, InlineItem *item ) +void CSharpFsmCodeGen::SET_TOKSTART( ostream &ret, GenInlineItem *item ) { ret << TOKSTART() << " = " << P() << ";"; } -void FsmCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, +void CSharpFsmCodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish ) { if ( item->children->length() > 0 ) { @@ -423,88 +423,88 @@ void FsmCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, /* Write out an inline tree structure. Walks the list and possibly calls out * to virtual functions than handle language specific items in the tree. */ -void FsmCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, +void CSharpFsmCodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Text: + case GenInlineItem::Text: ret << item->data; break; - case InlineItem::Goto: + case GenInlineItem::Goto: GOTO( ret, item->targState->id, inFinish ); break; - case InlineItem::Call: + case GenInlineItem::Call: CALL( ret, item->targState->id, targState, inFinish ); break; - case InlineItem::Next: + case GenInlineItem::Next: NEXT( ret, item->targState->id, inFinish ); break; - case InlineItem::Ret: + case GenInlineItem::Ret: RET( ret, inFinish ); break; - case InlineItem::PChar: + case GenInlineItem::PChar: ret << P(); break; - case InlineItem::Char: + case GenInlineItem::Char: ret << GET_KEY(); break; - case InlineItem::Hold: + case GenInlineItem::Hold: ret << P() << "--;"; break; - case InlineItem::Exec: + case GenInlineItem::Exec: EXEC( ret, item, targState, inFinish ); break; - case InlineItem::Curs: + case GenInlineItem::Curs: CURS( ret, inFinish ); break; - case InlineItem::Targs: + case GenInlineItem::Targs: TARGS( ret, inFinish, targState ); break; - case InlineItem::Entry: + case GenInlineItem::Entry: ret << item->targState->id; break; - case InlineItem::GotoExpr: + case GenInlineItem::GotoExpr: GOTO_EXPR( ret, item, inFinish ); break; - case InlineItem::CallExpr: + case GenInlineItem::CallExpr: CALL_EXPR( ret, item, targState, inFinish ); break; - case InlineItem::NextExpr: + case GenInlineItem::NextExpr: NEXT_EXPR( ret, item, inFinish ); break; - case InlineItem::LmSwitch: + case GenInlineItem::LmSwitch: LM_SWITCH( ret, item, targState, inFinish ); break; - case InlineItem::LmSetActId: + case GenInlineItem::LmSetActId: SET_ACT( ret, item ); break; - case InlineItem::LmSetTokEnd: + case GenInlineItem::LmSetTokEnd: SET_TOKEND( ret, item ); break; - case InlineItem::LmGetTokEnd: + case GenInlineItem::LmGetTokEnd: GET_TOKEND( ret, item ); break; - case InlineItem::LmInitTokStart: + case GenInlineItem::LmInitTokStart: INIT_TOKSTART( ret, item ); break; - case InlineItem::LmInitAct: + case GenInlineItem::LmInitAct: INIT_ACT( ret, item ); break; - case InlineItem::LmSetTokStart: + case GenInlineItem::LmSetTokStart: SET_TOKSTART( ret, item ); break; - case InlineItem::SubAction: + case GenInlineItem::SubAction: SUB_ACTION( ret, item, targState, inFinish ); break; - case InlineItem::Break: + case GenInlineItem::Break: BREAK( ret, targState ); break; } } } /* Write out paths in line directives. Escapes any special characters. */ -string FsmCodeGen::LDIR_PATH( char *path ) +string CSharpFsmCodeGen::LDIR_PATH( char *path ) { ostringstream ret; for ( char *pc = path; *pc != 0; pc++ ) { @@ -516,10 +516,10 @@ string FsmCodeGen::LDIR_PATH( char *path ) return ret.str(); } -void FsmCodeGen::ACTION( ostream &ret, Action *action, int targState, bool inFinish ) +void CSharpFsmCodeGen::ACTION( ostream &ret, Action *action, int targState, bool inFinish ) { /* Write the preprocessor line info for going into the source file. */ - lineDirective( ret, sourceFileName, action->loc.line ); + csharpLineDirective( ret, sourceFileName, action->loc.line ); /* Write the block and close it off. */ ret << "\t{"; @@ -527,14 +527,14 @@ void FsmCodeGen::ACTION( ostream &ret, Action *action, int targState, bool inFin ret << "}\n"; } -void FsmCodeGen::CONDITION( ostream &ret, Action *condition ) +void CSharpFsmCodeGen::CONDITION( ostream &ret, Action *condition ) { ret << "\n"; - lineDirective( ret, sourceFileName, condition->loc.line ); + csharpLineDirective( ret, sourceFileName, condition->loc.line ); INLINE_LIST( ret, condition->inlineList, 0, false ); } -string FsmCodeGen::ERROR_STATE() +string CSharpFsmCodeGen::ERROR_STATE() { ostringstream ret; if ( redFsm->errState != 0 ) @@ -544,7 +544,7 @@ string FsmCodeGen::ERROR_STATE() return ret.str(); } -string FsmCodeGen::FIRST_FINAL_STATE() +string CSharpFsmCodeGen::FIRST_FINAL_STATE() { ostringstream ret; if ( redFsm->firstFinState != 0 ) @@ -554,7 +554,7 @@ string FsmCodeGen::FIRST_FINAL_STATE() return ret.str(); } -void FsmCodeGen::writeInit() +void CSharpFsmCodeGen::writeInit() { out << " {\n"; @@ -574,7 +574,7 @@ void FsmCodeGen::writeInit() out << " }\n"; } -string FsmCodeGen::DATA_PREFIX() +string CSharpFsmCodeGen::DATA_PREFIX() { if ( dataPrefix ) return FSM_NAME() + "_"; @@ -582,7 +582,7 @@ string FsmCodeGen::DATA_PREFIX() } /* Emit the alphabet data type. */ -string FsmCodeGen::ALPH_TYPE() +string CSharpFsmCodeGen::ALPH_TYPE() { string ret = keyOps->alphType->data1; if ( keyOps->alphType->data2 != 0 ) { @@ -593,7 +593,7 @@ string FsmCodeGen::ALPH_TYPE() } /* Emit the alphabet data type. */ -string FsmCodeGen::WIDE_ALPH_TYPE() +string CSharpFsmCodeGen::WIDE_ALPH_TYPE() { string ret; if ( redFsm->maxKey <= keyOps->maxKey ) @@ -612,7 +612,7 @@ string FsmCodeGen::WIDE_ALPH_TYPE() return ret; } -void FsmCodeGen::STATE_IDS() +void CSharpFsmCodeGen::STATE_IDS() { if ( redFsm->startState != 0 ) STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n"; @@ -733,7 +733,7 @@ void CSharpCodeGen::writeExports() * End C#-specific code. */ -void FsmCodeGen::finishRagelDef() +void CSharpFsmCodeGen::finishRagelDef() { if ( codeStyle == GenGoto || codeStyle == GenFGoto || codeStyle == GenIpGoto || codeStyle == GenSplit ) @@ -777,13 +777,13 @@ void FsmCodeGen::finishRagelDef() calcIndexSize(); } -ostream &FsmCodeGen::source_warning( const InputLoc &loc ) +ostream &CSharpFsmCodeGen::source_warning( const GenInputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &FsmCodeGen::source_error( const InputLoc &loc ) +ostream &CSharpFsmCodeGen::source_error( const GenInputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-csharp/fsmcodegen.h b/rlgen-csharp/fsmcodegen.h index d29d551..ab85679 100644 --- a/rlgen-csharp/fsmcodegen.h +++ b/rlgen-csharp/fsmcodegen.h @@ -42,8 +42,8 @@ struct RedStateAp; struct CodeGenData; struct Action; struct NameInst; -struct InlineItem; -struct InlineList; +struct GenInlineItem; +struct GenInlineList; struct RedAction; struct LongestMatch; struct LongestMatchPart; @@ -56,13 +56,13 @@ inline string itoa( int i ) } /* - * class FsmCodeGen + * class CSharpFsmCodeGen */ -class FsmCodeGen : public CodeGenData +class CSharpFsmCodeGen : public CodeGenData { public: - FsmCodeGen( ostream &out ); - virtual ~FsmCodeGen() {} + CSharpFsmCodeGen( ostream &out ); + virtual ~CSharpFsmCodeGen() {} virtual void finishRagelDef(); virtual void writeInit(); @@ -130,27 +130,27 @@ protected: string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; } string CTXDATA() { return DATA_PREFIX() + "ctxdata"; } - void INLINE_LIST( ostream &ret, InlineList *inlineList, int targState, bool inFinish ); + void INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish ); virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0; virtual void CALL( ostream &ret, int callDest, int targState, bool inFinish ) = 0; virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0; - virtual void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) = 0; - virtual void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) = 0; - virtual void CALL_EXPR( ostream &ret, InlineItem *ilItem, + virtual void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0; + virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0; + virtual void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) = 0; virtual void RET( ostream &ret, bool inFinish ) = 0; virtual void BREAK( ostream &ret, int targState ) = 0; virtual void CURS( ostream &ret, bool inFinish ) = 0; virtual void TARGS( ostream &ret, bool inFinish, int targState ) = 0; - void EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ); - void LM_SWITCH( ostream &ret, InlineItem *item, int targState, int inFinish ); - void SET_ACT( ostream &ret, InlineItem *item ); - void INIT_TOKSTART( ostream &ret, InlineItem *item ); - void INIT_ACT( ostream &ret, InlineItem *item ); - void SET_TOKSTART( ostream &ret, InlineItem *item ); - void SET_TOKEND( ostream &ret, InlineItem *item ); - void GET_TOKEND( ostream &ret, InlineItem *item ); - void SUB_ACTION( ostream &ret, InlineItem *item, + void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void SET_ACT( ostream &ret, GenInlineItem *item ); + void INIT_TOKSTART( ostream &ret, GenInlineItem *item ); + void INIT_ACT( ostream &ret, GenInlineItem *item ); + void SET_TOKSTART( ostream &ret, GenInlineItem *item ); + void SET_TOKEND( ostream &ret, GenInlineItem *item ); + void GET_TOKEND( ostream &ret, GenInlineItem *item ); + void SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish ); void STATE_IDS(); @@ -164,8 +164,8 @@ protected: virtual string CTRL_FLOW() = 0; - ostream &source_warning(const InputLoc &loc); - ostream &source_error(const InputLoc &loc); + ostream &source_warning(const GenInputLoc &loc); + ostream &source_error(const GenInputLoc &loc); unsigned int arrayTypeSize( unsigned long maxVal ); @@ -177,12 +177,14 @@ protected: public: /* Determine if we should use indicies. */ virtual void calcIndexSize() {} + + void genLineDirective( ostream &out ); }; -class CSharpCodeGen : virtual public FsmCodeGen +class CSharpCodeGen : virtual public CSharpFsmCodeGen { public: - CSharpCodeGen( ostream &out ) : FsmCodeGen(out) {} + CSharpCodeGen( ostream &out ) : CSharpFsmCodeGen(out) {} virtual string GET_KEY(); virtual string NULL_ITEM(); diff --git a/rlgen-csharp/ftabcodegen.h b/rlgen-csharp/ftabcodegen.h index d72a82f..46101ee 100644 --- a/rlgen-csharp/ftabcodegen.h +++ b/rlgen-csharp/ftabcodegen.h @@ -37,7 +37,7 @@ struct CodeGenData; class CSharpFTabCodeGen : public CSharpTabCodeGen { public: - CSharpFTabCodeGen( ostream &out ) : FsmCodeGen(out), CSharpTabCodeGen(out) {} + CSharpFTabCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpTabCodeGen(out) {} private: std::ostream &TO_STATE_ACTION_SWITCH(); std::ostream &FROM_STATE_ACTION_SWITCH(); diff --git a/rlgen-csharp/gotocodegen.cpp b/rlgen-csharp/gotocodegen.cpp index 330b608..0875aad 100644 --- a/rlgen-csharp/gotocodegen.cpp +++ b/rlgen-csharp/gotocodegen.cpp @@ -547,7 +547,7 @@ void CSharpGotoCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) CTRL_FLOW() << "goto _again;}"; } -void CSharpGotoCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void CSharpGotoCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -569,7 +569,7 @@ void CSharpGotoCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void CSharpGotoCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void CSharpGotoCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -590,7 +590,7 @@ void CSharpGotoCodeGen::CALL( ostream &ret, int callDest, int targState, bool in ret << "}"; } -void CSharpGotoCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void CSharpGotoCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; diff --git a/rlgen-csharp/gotocodegen.h b/rlgen-csharp/gotocodegen.h index 2d0ac9b..565627e 100644 --- a/rlgen-csharp/gotocodegen.h +++ b/rlgen-csharp/gotocodegen.h @@ -37,10 +37,10 @@ struct StateCond; /* * Goto driven fsm. */ -class CSharpGotoCodeGen : virtual public FsmCodeGen, public CSharpCodeGen +class CSharpGotoCodeGen : virtual public CSharpFsmCodeGen, public CSharpCodeGen { public: - CSharpGotoCodeGen( ostream &out ) : FsmCodeGen(out), CSharpCodeGen(out) {} + CSharpGotoCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpCodeGen(out) {} std::ostream &TO_STATE_ACTION_SWITCH(); std::ostream &FROM_STATE_ACTION_SWITCH(); std::ostream &EOF_ACTION_SWITCH(); @@ -53,9 +53,9 @@ public: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); diff --git a/rlgen-csharp/ipgotocodegen.cpp b/rlgen-csharp/ipgotocodegen.cpp index 8118a3d..10413ac 100644 --- a/rlgen-csharp/ipgotocodegen.cpp +++ b/rlgen-csharp/ipgotocodegen.cpp @@ -53,7 +53,7 @@ void CSharpIpGotoCodeGen::CALL( ostream &ret, int callDest, int targState, bool ret << "}"; } -void CSharpIpGotoCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void CSharpIpGotoCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; @@ -81,7 +81,7 @@ void CSharpIpGotoCodeGen::RET( ostream &ret, bool inFinish ) ret << CTRL_FLOW() << "goto _again;}"; } -void CSharpIpGotoCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void CSharpIpGotoCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -93,7 +93,7 @@ void CSharpIpGotoCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void CSharpIpGotoCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void CSharpIpGotoCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -296,11 +296,11 @@ std::ostream &CSharpIpGotoCodeGen::FINISH_CASES() return out; } -void CSharpIpGotoCodeGen::setLabelsNeeded( InlineList *inlineList ) +void CSharpIpGotoCodeGen::setLabelsNeeded( GenInlineList *inlineList ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Goto: case InlineItem::Call: { + case GenInlineItem::Goto: case GenInlineItem::Call: { /* Mark the target as needing a label. */ item->targState->labelNeeded = true; break; diff --git a/rlgen-csharp/ipgotocodegen.h b/rlgen-csharp/ipgotocodegen.h index 3c370f6..21af6d1 100644 --- a/rlgen-csharp/ipgotocodegen.h +++ b/rlgen-csharp/ipgotocodegen.h @@ -36,7 +36,7 @@ struct CodeGenData; class CSharpIpGotoCodeGen : public CSharpGotoCodeGen { public: - CSharpIpGotoCodeGen( ostream &out ) : FsmCodeGen(out), + CSharpIpGotoCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpGotoCodeGen(out) {} std::ostream &EXIT_STATES(); @@ -47,9 +47,9 @@ public: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void RET( ostream &ret, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); @@ -68,7 +68,7 @@ protected: void STATE_GOTO_ERROR(); /* Set up labelNeeded flag for each state. */ - void setLabelsNeeded( InlineList *inlineList ); + void setLabelsNeeded( GenInlineList *inlineList ); void setLabelsNeeded(); }; diff --git a/rlgen-csharp/main.cpp b/rlgen-csharp/main.cpp index 0b52c0a..ab2dc1c 100644 --- a/rlgen-csharp/main.cpp +++ b/rlgen-csharp/main.cpp @@ -53,23 +53,23 @@ using std::cerr; using std::endl; /* Target language and output style. */ -CodeStyleEnum codeStyle = GenTables; +extern CodeStyleEnum codeStyle; /* Io globals. */ -istream *inStream = 0; -ostream *outStream = 0; -output_filter *outFilter = 0; -char *outputFileName = 0; +extern istream *inStream; +extern ostream *outStream; +extern output_filter *outFilter; +extern const char *outputFileName; /* Graphviz dot file generation. */ -bool graphvizDone = false; +extern bool graphvizDone; -int numSplitPartitions = 0; -bool noLineDirectives = false; -bool printPrintables = false; +extern int numSplitPartitions; +extern bool noLineDirectives; +extern bool printPrintables; /* Print a summary of the options. */ -void usage() +void csharp_usage() { cout << "usage: " PROGNAME " [options] file\n" @@ -90,14 +90,14 @@ void usage() } /* Print version information. */ -void version() +void csharp_version() { cout << "Ragel Code Generator for C#" << endl << "Version " VERSION << ", " PUBDATE << endl << "Copyright (c) 2001-2007 by Adrian Thurston" << endl; } -ostream &error() +ostream &csharp_error() { gblErrorCount += 1; cerr << PROGNAME ": "; @@ -109,10 +109,10 @@ ostream &error() */ /* Invoked by the parser when the root element is opened. */ -ostream *openOutput( char *inputFile ) +ostream *csharpOpenOutput( char *inputFile ) { if ( hostLang->lang != HostLang::CSharp ) { - error() << "this code generator is for C# only" << endl; + csharp_error() << "this code generator is for C# only" << endl; exit(1); } @@ -128,7 +128,7 @@ ostream *openOutput( 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 << + csharp_error() << "output file \"" << outputFileName << "\" is the same as the input file" << endl; } @@ -137,7 +137,7 @@ ostream *openOutput( char *inputFile ) outFilter = new output_filter( outputFileName ); outFilter->open( outputFileName, ios::out|ios::trunc ); if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; + csharp_error() << "error opening " << outputFileName << " for writing" << endl; exit(1); } @@ -152,7 +152,7 @@ ostream *openOutput( char *inputFile ) } /* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, +CodeGenData *csharpMakeCodeGen( char *sourceFileName, char *fsmName, ostream &out, bool wantComplete ) { CodeGenData *codeGen = 0; @@ -194,11 +194,11 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, /* Main, process args and call yyparse to start scanning input. */ -int main(int argc, char **argv) +int csharp_main(int argc, const char **argv) { // ParamCheck pc("-:Hh?vLo:T:F:G:P:", argc, argv); ParamCheck pc("-:Hh?vLo:T:F:G:", argc, argv); - char *xmlInputFileName = 0; + const char *xmlInputFileName = 0; while ( pc.check() ) { switch ( pc.state ) { @@ -207,9 +207,9 @@ int main(int argc, char **argv) /* Output. */ case 'o': if ( *pc.paramArg == 0 ) - error() << "a zero length output file name was given" << endl; + csharp_error() << "a zero length output file name was given" << endl; else if ( outputFileName != 0 ) - error() << "more than one output file name was given" << endl; + csharp_error() << "more than one output file name was given" << endl; else { /* Ok, remember the output file name. */ outputFileName = pc.paramArg; @@ -227,7 +227,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '1' ) codeStyle = GenFTables; else { - error() << "-T" << pc.paramArg[0] << + csharp_error() << "-T" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -238,7 +238,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '1' ) codeStyle = GenFFlat; else { - error() << "-F" << pc.paramArg[0] << + csharp_error() << "-F" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -251,7 +251,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '2' ) codeStyle = GenIpGoto; else { - error() << "-G" << pc.paramArg[0] << + csharp_error() << "-G" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -263,22 +263,22 @@ int main(int argc, char **argv) /* Version and help. */ case 'v': - version(); + csharp_version(); exit(0); case 'H': case 'h': case '?': - usage(); + csharp_usage(); exit(0); case '-': if ( strcmp(pc.paramArg, "help") == 0 ) { - usage(); + csharp_usage(); exit(0); } else if ( strcmp(pc.paramArg, "version") == 0 ) { - version(); + csharp_version(); exit(0); } else { - error() << "--" << pc.paramArg << + csharp_error() << "--" << pc.paramArg << " is an invalid argument" << endl; break; } @@ -286,14 +286,14 @@ int main(int argc, char **argv) break; case ParamCheck::invalid: - error() << "-" << pc.parameter << " is an invalid argument" << endl; + csharp_error() << "-" << pc.parameter << " is an invalid argument" << endl; break; case ParamCheck::noparam: if ( *pc.curArg == 0 ) - error() << "a zero length input file name was given" << endl; + csharp_error() << "a zero length input file name was given" << endl; else if ( xmlInputFileName != 0 ) - error() << "more than one input file name was given" << endl; + csharp_error() << "more than one input file name was given" << endl; else { /* OK, Remember the filename. */ xmlInputFileName = pc.curArg; @@ -312,7 +312,7 @@ int main(int argc, char **argv) ifstream *inFile = new ifstream( xmlInputFileName ); inStream = inFile; if ( ! inFile->is_open() ) - error() << "could not open " << xmlInputFileName << " for reading" << endl; + csharp_error() << "could not open " << xmlInputFileName << " for reading" << endl; } else { xmlInputFileName = strdup(""); diff --git a/rlgen-csharp/splitcodegen.cpp b/rlgen-csharp/splitcodegen.cpp index 1189351..0c6444f 100644 --- a/rlgen-csharp/splitcodegen.cpp +++ b/rlgen-csharp/splitcodegen.cpp @@ -426,11 +426,11 @@ void CSharpSplitCodeGen::writeExec() ALL_PARTITIONS(); } -void CSharpSplitCodeGen::setLabelsNeeded( RedStateAp *fromState, InlineList *inlineList ) +void CSharpSplitCodeGen::setLabelsNeeded( RedStateAp *fromState, GenInlineList *inlineList ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Goto: case InlineItem::Call: { + case GenInlineItem::Goto: case GenInlineItem::Call: { /* In split code gen we only need labels for transitions across * partitions. */ if ( fromState->partition == item->targState->partition ){ diff --git a/rlgen-csharp/splitcodegen.h b/rlgen-csharp/splitcodegen.h index cb13aa9..8118643 100644 --- a/rlgen-csharp/splitcodegen.h +++ b/rlgen-csharp/splitcodegen.h @@ -27,7 +27,7 @@ class CSharpSplitCodeGen : public CSharpIpGotoCodeGen { public: - CSharpSplitCodeGen( ostream &out ) : FsmCodeGen(out), CSharpIpGotoCodeGen(out) {} + CSharpSplitCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpIpGotoCodeGen(out) {} bool ptOutLabelUsed; @@ -43,7 +43,7 @@ public: void writeExec(); void writeParts(); - void setLabelsNeeded( RedStateAp *fromState, InlineList *inlineList ); + void setLabelsNeeded( RedStateAp *fromState, GenInlineList *inlineList ); void setLabelsNeeded( RedStateAp *fromState, RedTransAp *trans ); void setLabelsNeeded(); diff --git a/rlgen-csharp/tabcodegen.cpp b/rlgen-csharp/tabcodegen.cpp index 8c8e113..c209d47 100644 --- a/rlgen-csharp/tabcodegen.cpp +++ b/rlgen-csharp/tabcodegen.cpp @@ -614,7 +614,7 @@ void CSharpTabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) CTRL_FLOW() << "goto _again;}"; } -void CSharpTabCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void CSharpTabCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -636,7 +636,7 @@ void CSharpTabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void CSharpTabCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void CSharpTabCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -657,7 +657,7 @@ void CSharpTabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inF ret << "}"; } -void CSharpTabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void CSharpTabCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; diff --git a/rlgen-csharp/tabcodegen.h b/rlgen-csharp/tabcodegen.h index f1bbdb3..e1f5f41 100644 --- a/rlgen-csharp/tabcodegen.h +++ b/rlgen-csharp/tabcodegen.h @@ -36,10 +36,10 @@ struct RedStateAp; /* * TabCodeGen */ -class CSharpTabCodeGen : virtual public FsmCodeGen, public CSharpCodeGen +class CSharpTabCodeGen : virtual public CSharpFsmCodeGen, public CSharpCodeGen { public: - CSharpTabCodeGen( ostream &out ) : FsmCodeGen(out), CSharpCodeGen(out) {} + CSharpTabCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpCodeGen(out) {} virtual ~CSharpTabCodeGen() { } virtual void writeData(); virtual void writeExec(); @@ -76,9 +76,9 @@ protected: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); diff --git a/rlgen-java/Makefile.in b/rlgen-java/Makefile.in index 00e7fda..e242a64 100644 --- a/rlgen-java/Makefile.in +++ b/rlgen-java/Makefile.in @@ -33,8 +33,10 @@ LIBS += @LIBS@ #************************************* prefix = @prefix@ -CXX = @CXX@ EXEEXT = @EXEEXT@ +CXX = @CXX@ +AR = @AR@ +RANLIB = @RANLIB@ # Get objects and dependencies from sources. OBJS = $(CC_SRCS:%.cpp=%.o) @@ -44,10 +46,11 @@ DEPS = $(CC_SRCS:%.cpp=.%.d) include ../version.mk # Rules. -all: rlgen-java$(EXEEXT) +all: rlgen-java.a -rlgen-java$(EXEEXT): $(LIBS) $(OBJS) - $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) +rlgen-java.a: $(LIBS) $(OBJS) + $(AR) -cr $@ $(OBJS) + $(RANLIB) $@ %.o: %.cpp @$(CXX) -M $(DEFS) $(INCS) $< > .$*.d @@ -57,10 +60,9 @@ distclean: clean rm -f Makefile clean: - rm -f tags .*.d *.o rlgen-java + rm -f tags .*.d *.o rlgen-java.a install: all - install -d $(prefix)/bin - install -s rlgen-java $(prefix)/bin/rlgen-java + @true -include $(DEPS) diff --git a/rlgen-java/javacodegen.cpp b/rlgen-java/javacodegen.cpp index fdd4899..a5789f7 100644 --- a/rlgen-java/javacodegen.cpp +++ b/rlgen-java/javacodegen.cpp @@ -46,11 +46,11 @@ using std::ostringstream; using std::string; using std::cerr; -void lineDirective( ostream &out, char *fileName, int line ) +void javaLineDirective( ostream &out, const char *fileName, int line ) { /* Write the preprocessor line info for to the input file. */ out << "// line " << line << " \""; - for ( char *pc = fileName; *pc != 0; pc++ ) { + for ( const char *pc = fileName; *pc != 0; pc++ ) { if ( *pc == '\\' ) out << "\\\\"; else @@ -59,11 +59,11 @@ void lineDirective( ostream &out, char *fileName, int line ) out << "\"\n"; } -void genLineDirective( ostream &out ) +void JavaTabCodeGen::genLineDirective( ostream &out ) { std::streambuf *sbuf = out.rdbuf(); output_filter *filter = static_cast(sbuf); - lineDirective( out, filter->fileName, filter->line + 1 ); + javaLineDirective( out, filter->fileName, filter->line + 1 ); } void JavaTabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) @@ -72,7 +72,7 @@ void JavaTabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) CTRL_FLOW() << "continue _goto;}"; } -void JavaTabCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void JavaTabCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "{" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -93,7 +93,7 @@ void JavaTabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFin ret << "}"; } -void JavaTabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void JavaTabCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; @@ -132,14 +132,14 @@ void JavaTabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void JavaTabCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void JavaTabCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); ret << ");"; } -void JavaTabCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ) +void JavaTabCodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ) { /* The parser gives fexec two children. The double brackets are for D * code. If the inline list is a single word it will get interpreted as a @@ -151,81 +151,81 @@ void JavaTabCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int in /* Write out an inline tree structure. Walks the list and possibly calls out * to virtual functions than handle language specific items in the tree. */ -void JavaTabCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, +void JavaTabCodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Text: + case GenInlineItem::Text: ret << item->data; break; - case InlineItem::Goto: + case GenInlineItem::Goto: GOTO( ret, item->targState->id, inFinish ); break; - case InlineItem::Call: + case GenInlineItem::Call: CALL( ret, item->targState->id, targState, inFinish ); break; - case InlineItem::Next: + case GenInlineItem::Next: NEXT( ret, item->targState->id, inFinish ); break; - case InlineItem::Ret: + case GenInlineItem::Ret: RET( ret, inFinish ); break; - case InlineItem::PChar: + case GenInlineItem::PChar: ret << P(); break; - case InlineItem::Char: + case GenInlineItem::Char: ret << GET_KEY(); break; - case InlineItem::Hold: + case GenInlineItem::Hold: ret << P() << "--;"; break; - case InlineItem::Exec: + case GenInlineItem::Exec: EXEC( ret, item, targState, inFinish ); break; - case InlineItem::Curs: + case GenInlineItem::Curs: ret << "(_ps)"; break; - case InlineItem::Targs: + case GenInlineItem::Targs: ret << "(" << CS() << ")"; break; - case InlineItem::Entry: + case GenInlineItem::Entry: ret << item->targState->id; break; - case InlineItem::GotoExpr: + case GenInlineItem::GotoExpr: GOTO_EXPR( ret, item, inFinish ); break; - case InlineItem::CallExpr: + case GenInlineItem::CallExpr: CALL_EXPR( ret, item, targState, inFinish ); break; - case InlineItem::NextExpr: + case GenInlineItem::NextExpr: NEXT_EXPR( ret, item, inFinish ); break; - case InlineItem::LmSwitch: + case GenInlineItem::LmSwitch: LM_SWITCH( ret, item, targState, inFinish ); break; - case InlineItem::LmSetActId: + case GenInlineItem::LmSetActId: SET_ACT( ret, item ); break; - case InlineItem::LmSetTokEnd: + case GenInlineItem::LmSetTokEnd: SET_TOKEND( ret, item ); break; - case InlineItem::LmGetTokEnd: + case GenInlineItem::LmGetTokEnd: GET_TOKEND( ret, item ); break; - case InlineItem::LmInitTokStart: + case GenInlineItem::LmInitTokStart: INIT_TOKSTART( ret, item ); break; - case InlineItem::LmInitAct: + case GenInlineItem::LmInitAct: INIT_ACT( ret, item ); break; - case InlineItem::LmSetTokStart: + case GenInlineItem::LmSetTokStart: SET_TOKSTART( ret, item ); break; - case InlineItem::SubAction: + case GenInlineItem::SubAction: SUB_ACTION( ret, item, targState, inFinish ); break; - case InlineItem::Break: + case GenInlineItem::Break: BREAK( ret, targState ); break; } @@ -1488,13 +1488,13 @@ string JavaTabCodeGen::INT( int i ) return ret.str(); } -void JavaTabCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, +void JavaTabCodeGen::LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish ) { ret << " switch( " << ACT() << " ) {\n"; - for ( InlineList::Iter lma = *item->children; lma.lte(); lma++ ) { + for ( GenInlineList::Iter lma = *item->children; lma.lte(); lma++ ) { /* Write the case label, the action and the case break. */ if ( lma->lmId < 0 ) ret << " default:\n"; @@ -1514,12 +1514,12 @@ void JavaTabCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, "\t"; } -void JavaTabCodeGen::SET_ACT( ostream &ret, InlineItem *item ) +void JavaTabCodeGen::SET_ACT( ostream &ret, GenInlineItem *item ) { ret << ACT() << " = " << item->lmId << ";"; } -void JavaTabCodeGen::SET_TOKEND( ostream &ret, InlineItem *item ) +void JavaTabCodeGen::SET_TOKEND( ostream &ret, GenInlineItem *item ) { /* The tokend action sets tokend. */ ret << TOKEND() << " = " << P(); @@ -1528,27 +1528,27 @@ void JavaTabCodeGen::SET_TOKEND( ostream &ret, InlineItem *item ) out << ";"; } -void JavaTabCodeGen::GET_TOKEND( ostream &ret, InlineItem *item ) +void JavaTabCodeGen::GET_TOKEND( ostream &ret, GenInlineItem *item ) { ret << TOKEND(); } -void JavaTabCodeGen::INIT_TOKSTART( ostream &ret, InlineItem *item ) +void JavaTabCodeGen::INIT_TOKSTART( ostream &ret, GenInlineItem *item ) { ret << TOKSTART() << " = " << NULL_ITEM() << ";"; } -void JavaTabCodeGen::INIT_ACT( ostream &ret, InlineItem *item ) +void JavaTabCodeGen::INIT_ACT( ostream &ret, GenInlineItem *item ) { ret << ACT() << " = 0;"; } -void JavaTabCodeGen::SET_TOKSTART( ostream &ret, InlineItem *item ) +void JavaTabCodeGen::SET_TOKSTART( ostream &ret, GenInlineItem *item ) { ret << TOKSTART() << " = " << P() << ";"; } -void JavaTabCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, +void JavaTabCodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish ) { if ( item->children->length() > 0 ) { @@ -1562,7 +1562,7 @@ void JavaTabCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, void JavaTabCodeGen::ACTION( ostream &ret, Action *action, int targState, bool inFinish ) { /* Write the preprocessor line info for going into the source file. */ - lineDirective( ret, sourceFileName, action->loc.line ); + javaLineDirective( ret, sourceFileName, action->loc.line ); /* Write the block and close it off. */ ret << "\t{"; @@ -1573,7 +1573,7 @@ void JavaTabCodeGen::ACTION( ostream &ret, Action *action, int targState, bool i void JavaTabCodeGen::CONDITION( ostream &ret, Action *condition ) { ret << "\n"; - lineDirective( ret, sourceFileName, condition->loc.line ); + javaLineDirective( ret, sourceFileName, condition->loc.line ); INLINE_LIST( ret, condition->inlineList, 0, false ); } @@ -1642,13 +1642,13 @@ void JavaTabCodeGen::finishRagelDef() calcIndexSize(); } -ostream &JavaTabCodeGen::source_warning( const InputLoc &loc ) +ostream &JavaTabCodeGen::source_warning( const GenInputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &JavaTabCodeGen::source_error( const InputLoc &loc ) +ostream &JavaTabCodeGen::source_error( const GenInputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-java/javacodegen.h b/rlgen-java/javacodegen.h index 2626153..1dd3a99 100644 --- a/rlgen-java/javacodegen.h +++ b/rlgen-java/javacodegen.h @@ -66,9 +66,9 @@ struct JavaTabCodeGen : public CodeGenData void BREAK( ostream &ret, int targState ); void GOTO( ostream &ret, int gotoDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void RET( ostream &ret, bool inFinish ); void COND_TRANSLATE(); @@ -81,7 +81,7 @@ struct JavaTabCodeGen : public CodeGenData virtual void finishRagelDef(); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); int TO_STATE_ACTION( RedStateAp *state ); int FROM_STATE_ACTION( RedStateAp *state ); @@ -163,30 +163,32 @@ public: string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; } string CTXDATA() { return DATA_PREFIX() + "ctxdata"; } - void INLINE_LIST( ostream &ret, InlineList *inlineList, int targState, bool inFinish ); - void EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ); - void EXECTE( ostream &ret, InlineItem *item, int targState, int inFinish ); - void LM_SWITCH( ostream &ret, InlineItem *item, int targState, int inFinish ); - void SET_ACT( ostream &ret, InlineItem *item ); - void INIT_TOKSTART( ostream &ret, InlineItem *item ); - void INIT_ACT( ostream &ret, InlineItem *item ); - void SET_TOKSTART( ostream &ret, InlineItem *item ); - void SET_TOKEND( ostream &ret, InlineItem *item ); - void GET_TOKEND( ostream &ret, InlineItem *item ); - void SUB_ACTION( ostream &ret, InlineItem *item, + void INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish ); + void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void EXECTE( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void SET_ACT( ostream &ret, GenInlineItem *item ); + void INIT_TOKSTART( ostream &ret, GenInlineItem *item ); + void INIT_ACT( ostream &ret, GenInlineItem *item ); + void SET_TOKSTART( ostream &ret, GenInlineItem *item ); + void SET_TOKEND( ostream &ret, GenInlineItem *item ); + void GET_TOKEND( ostream &ret, GenInlineItem *item ); + void SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish ); string ERROR_STATE(); string FIRST_FINAL_STATE(); - ostream &source_warning(const InputLoc &loc); - ostream &source_error(const InputLoc &loc); + ostream &source_warning(const GenInputLoc &loc); + ostream &source_error(const GenInputLoc &loc); unsigned int arrayTypeSize( unsigned long maxVal ); bool outLabelUsed; bool againLabelUsed; bool useIndicies; + + void genLineDirective( ostream &out ); }; diff --git a/rlgen-java/main.cpp b/rlgen-java/main.cpp index 0585ecb..9294a52 100644 --- a/rlgen-java/main.cpp +++ b/rlgen-java/main.cpp @@ -44,19 +44,16 @@ using std::cerr; using std::endl; /* Io globals. */ -istream *inStream = 0; -ostream *outStream = 0; -output_filter *outFilter = 0; -char *outputFileName = 0; +extern istream *inStream; +extern ostream *outStream; +extern output_filter *outFilter; +extern const char *outputFileName; -/* Graphviz dot file generation. */ -bool graphvizDone = false; - -int numSplitPartitions = 0; -bool printPrintables = false; +extern int numSplitPartitions; +extern bool printPrintables; /* Print a summary of the options. */ -void usage() +void java_usage() { cout << "usage: " PROGNAME " [options] file\n" @@ -68,14 +65,14 @@ void usage() } /* Print version information. */ -void version() +void java_version() { cout << "Ragel Code Generator for Java" << endl << "Version " VERSION << ", " PUBDATE << endl << "Copyright (c) 2001-2007 by Adrian Thurston" << endl; } -ostream &error() +ostream &java_error() { gblErrorCount += 1; cerr << PROGNAME ": "; @@ -87,10 +84,10 @@ ostream &error() */ /* Invoked by the parser when the root element is opened. */ -ostream *openOutput( char *inputFile ) +ostream *javaOpenOutput( char *inputFile ) { if ( hostLang->lang != HostLang::Java ) { - error() << "this code generator is for Java only" << endl; + java_error() << "this code generator is for Java only" << endl; exit(1); } @@ -106,7 +103,7 @@ ostream *openOutput( 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 << + java_error() << "output file \"" << outputFileName << "\" is the same as the input file" << endl; } @@ -115,7 +112,7 @@ ostream *openOutput( char *inputFile ) outFilter = new output_filter( outputFileName ); outFilter->open( outputFileName, ios::out|ios::trunc ); if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; + java_error() << "error opening " << outputFileName << " for writing" << endl; exit(1); } @@ -130,7 +127,7 @@ ostream *openOutput( char *inputFile ) } /* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, +CodeGenData *javaMakeCodeGen( char *sourceFileName, char *fsmName, ostream &out, bool wantComplete ) { CodeGenData *codeGen = new JavaTabCodeGen(out); @@ -143,10 +140,10 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, } /* Main, process args and call yyparse to start scanning input. */ -int main(int argc, char **argv) +int java_main(int argc, const char **argv) { ParamCheck pc("o:vHh?-:", argc, argv); - char *xmlInputFileName = 0; + const char *xmlInputFileName = 0; while ( pc.check() ) { switch ( pc.state ) { @@ -155,9 +152,9 @@ int main(int argc, char **argv) /* Output. */ case 'o': if ( *pc.paramArg == 0 ) - error() << "a zero length output file name was given" << endl; + java_error() << "a zero length output file name was given" << endl; else if ( outputFileName != 0 ) - error() << "more than one output file name was given" << endl; + java_error() << "more than one output file name was given" << endl; else { /* Ok, remember the output file name. */ outputFileName = pc.paramArg; @@ -166,22 +163,22 @@ int main(int argc, char **argv) /* Version and help. */ case 'v': - version(); + java_version(); exit(0); case 'H': case 'h': case '?': - usage(); + java_usage(); exit(0); case '-': if ( strcmp(pc.paramArg, "help") == 0 ) { - usage(); + java_usage(); exit(0); } else if ( strcmp(pc.paramArg, "version") == 0 ) { - version(); + java_version(); exit(0); } else { - error() << "--" << pc.paramArg << + java_error() << "--" << pc.paramArg << " is an invalid argument" << endl; break; } @@ -189,14 +186,14 @@ int main(int argc, char **argv) break; case ParamCheck::invalid: - error() << "-" << pc.parameter << " is an invalid argument" << endl; + java_error() << "-" << pc.parameter << " is an invalid argument" << endl; break; case ParamCheck::noparam: if ( *pc.curArg == 0 ) - error() << "a zero length input file name was given" << endl; + java_error() << "a zero length input file name was given" << endl; else if ( xmlInputFileName != 0 ) - error() << "more than one input file name was given" << endl; + java_error() << "more than one input file name was given" << endl; else { /* OK, Remember the filename. */ xmlInputFileName = pc.curArg; @@ -215,7 +212,7 @@ int main(int argc, char **argv) ifstream *inFile = new ifstream( xmlInputFileName ); inStream = inFile; if ( ! inFile->is_open() ) - error() << "could not open " << xmlInputFileName << " for reading" << endl; + java_error() << "could not open " << xmlInputFileName << " for reading" << endl; } else { xmlInputFileName = strdup(""); diff --git a/rlgen-ruby/Makefile.in b/rlgen-ruby/Makefile.in index 249eeb7..c9bd4f1 100644 --- a/rlgen-ruby/Makefile.in +++ b/rlgen-ruby/Makefile.in @@ -34,8 +34,10 @@ LIBS += @LIBS@ #************************************* prefix = @prefix@ -CXX = @CXX@ EXEEXT = @EXEEXT@ +CXX = @CXX@ +AR = @AR@ +RANLIB = @RANLIB@ # Get objects and dependencies from sources. OBJS = $(CC_SRCS:%.cpp=%.o) @@ -45,10 +47,11 @@ DEPS = $(CC_SRCS:%.cpp=.%.d) include ../version.mk # Rules. -all: rlgen-ruby$(EXEEXT) +all: rlgen-ruby.a -rlgen-ruby$(EXEEXT): $(LIBS) $(OBJS) - $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) +rlgen-ruby.a: $(LIBS) $(OBJS) + $(AR) -cr $@ $(OBJS) + $(RANLIB) $@ %.o: %.cpp @$(CXX) -M $(DEFS) $(INCS) $< > .$*.d @@ -58,10 +61,9 @@ distclean: clean rm -f Makefile clean: - rm -f tags .*.d *.o rlgen-ruby + rm -f tags .*.d *.o rlgen-ruby.a -install: all - install -d $(prefix)/bin - install -s rlgen-ruby $(prefix)/bin/rlgen-ruby +install: + @true -include $(DEPS) diff --git a/rlgen-ruby/main.cpp b/rlgen-ruby/main.cpp index 62c348e..1e50d9f 100644 --- a/rlgen-ruby/main.cpp +++ b/rlgen-ruby/main.cpp @@ -52,22 +52,22 @@ using std::endl; RubyImplEnum rubyImpl = MRI; /* Target language and output style. */ -CodeStyleEnum codeStyle = GenTables; +extern CodeStyleEnum codeStyle; /* Io globals. */ -istream *inStream = 0; -ostream *outStream = 0; -output_filter *outFilter = 0; -char *outputFileName = 0; +extern istream *inStream; +extern ostream *outStream; +extern output_filter *outFilter; +extern const char *outputFileName; /* Graphviz dot file generation. */ -bool graphvizDone = false; +extern bool graphvizDone; -int numSplitPartitions = 0; -bool printPrintables = false; +extern int numSplitPartitions; +extern bool printPrintables; /* Print a summary of the options. */ -void usage() +void ruby_usage() { cout << "usage: " PROGNAME " [options] file\n" @@ -86,7 +86,7 @@ void usage() } /* Print version information. */ -void version() +void ruby_version() { cout << "Ragel Code Generator for Ruby" << endl << "Version " VERSION << ", " PUBDATE << endl << @@ -94,7 +94,7 @@ void version() "Copyright (c) 2007 by Victor Hugo Borja" << endl; } -ostream &error() +ostream &ruby_error() { gblErrorCount += 1; cerr << PROGNAME ": "; @@ -106,10 +106,10 @@ ostream &error() */ /* Invoked by the parser when the root element is opened. */ -ostream *openOutput( char *inputFile ) +ostream *rubyOpenOutput( char *inputFile ) { if ( hostLang->lang != HostLang::Ruby ) { - error() << "this code generator is for Ruby only" << endl; + ruby_error() << "this code generator is for Ruby only" << endl; exit(1); } @@ -125,7 +125,7 @@ ostream *openOutput( 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 << + ruby_error() << "output file \"" << outputFileName << "\" is the same as the input file" << endl; } @@ -134,7 +134,7 @@ ostream *openOutput( char *inputFile ) outFilter = new output_filter( outputFileName ); outFilter->open( outputFileName, ios::out|ios::trunc ); if ( !outFilter->is_open() ) { - error() << "error opening " << outputFileName << " for writing" << endl; + ruby_error() << "error opening " << outputFileName << " for writing" << endl; exit(1); } @@ -149,7 +149,7 @@ ostream *openOutput( char *inputFile ) } /* Invoked by the parser when a ragel definition is opened. */ -CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, +CodeGenData *rubyMakeCodeGen( char *sourceFileName, char *fsmName, ostream &out, bool wantComplete ) { CodeGenData *codeGen = 0; @@ -190,10 +190,10 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, } /* Main, process args and call yyparse to start scanning input. */ -int main(int argc, char **argv) +int ruby_main(int argc, const char **argv) { ParamCheck pc("-:Hlh?vo:T:F:G:P:", argc, argv); - char *xmlInputFileName = 0; + const char *xmlInputFileName = 0; while ( pc.check() ) { switch ( pc.state ) { @@ -202,9 +202,9 @@ int main(int argc, char **argv) /* Output. */ case 'o': if ( *pc.paramArg == 0 ) - error() << "a zero length output file name was given" << endl; + ruby_error() << "a zero length output file name was given" << endl; else if ( outputFileName != 0 ) - error() << "more than one output file name was given" << endl; + ruby_error() << "more than one output file name was given" << endl; else { /* Ok, remember the output file name. */ outputFileName = pc.paramArg; @@ -218,7 +218,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '1' ) codeStyle = GenFTables; else { - error() << "-T" << pc.paramArg[0] << + ruby_error() << "-T" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -229,7 +229,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '1' ) codeStyle = GenFFlat; else { - error() << "-F" << pc.paramArg[0] << + ruby_error() << "-F" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -242,7 +242,7 @@ int main(int argc, char **argv) else if ( pc.paramArg[0] == '2' ) codeStyle = GenIpGoto; else { - error() << "-G" << pc.paramArg[0] << + ruby_error() << "-G" << pc.paramArg[0] << " is an invalid argument" << endl; exit(1); } @@ -254,40 +254,40 @@ int main(int argc, char **argv) /* Version and help. */ case 'v': - version(); + ruby_version(); exit(0); case 'H': case 'h': case '?': - usage(); + ruby_usage(); exit(0); case '-': if ( strcmp(pc.paramArg, "help") == 0 ) { - usage(); + ruby_usage(); exit(0); } else if ( strcmp(pc.paramArg, "version") == 0 ) { - version(); + ruby_version(); exit(0); } else if ( strcmp(pc.paramArg, "rbx") == 0 ) { rubyImpl = Rubinius; } else { - error() << "--" << pc.paramArg << + ruby_error() << "--" << pc.paramArg << " is an invalid argument" << endl; } } break; case ParamCheck::invalid: - error() << "-" << pc.parameter << " is an invalid argument" << endl; + ruby_error() << "-" << pc.parameter << " is an invalid argument" << endl; break; case ParamCheck::noparam: if ( *pc.curArg == 0 ) - error() << "a zero length input file name was given" << endl; + ruby_error() << "a zero length input file name was given" << endl; else if ( xmlInputFileName != 0 ) - error() << "more than one input file name was given" << endl; + ruby_error() << "more than one input file name was given" << endl; else { /* OK, Remember the filename. */ xmlInputFileName = pc.curArg; @@ -306,7 +306,7 @@ int main(int argc, char **argv) ifstream *inFile = new ifstream( xmlInputFileName ); inStream = inFile; if ( ! inFile->is_open() ) - error() << "could not open " << xmlInputFileName << " for reading" << endl; + ruby_error() << "could not open " << xmlInputFileName << " for reading" << endl; } else { xmlInputFileName = strdup(""); diff --git a/rlgen-ruby/rbx-gotocodegen.cpp b/rlgen-ruby/rbx-gotocodegen.cpp index 0476c35..4bcf0df 100644 --- a/rlgen-ruby/rbx-gotocodegen.cpp +++ b/rlgen-ruby/rbx-gotocodegen.cpp @@ -571,7 +571,7 @@ void RbxGotoCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) "\nend\n"; } -void RbxGotoCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void RbxGotoCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << "begin\n" << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -595,7 +595,7 @@ void RbxGotoCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void RbxGotoCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void RbxGotoCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); @@ -619,7 +619,7 @@ void RbxGotoCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFin ret << "}"; } -void RbxGotoCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) +void RbxGotoCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { ret << "{"; diff --git a/rlgen-ruby/rbx-gotocodegen.h b/rlgen-ruby/rbx-gotocodegen.h index f460919..5ec9f5c 100644 --- a/rlgen-ruby/rbx-gotocodegen.h +++ b/rlgen-ruby/rbx-gotocodegen.h @@ -47,9 +47,9 @@ public: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); diff --git a/rlgen-ruby/ruby-codegen.cpp b/rlgen-ruby/ruby-codegen.cpp index c7e923c..1a8693c 100644 --- a/rlgen-ruby/ruby-codegen.cpp +++ b/rlgen-ruby/ruby-codegen.cpp @@ -34,11 +34,11 @@ using std::cerr; using std::endl; -void lineDirective( ostream &out, char *fileName, int line ) +void rubyLineDirective( ostream &out, const char *fileName, int line ) { /* Write a comment containing line info. */ out << "# line " << line << " \""; - for ( char *pc = fileName; *pc != 0; pc++ ) { + for ( const char *pc = fileName; *pc != 0; pc++ ) { if ( *pc == '\\' ) out << "\\\\"; else @@ -47,11 +47,11 @@ void lineDirective( ostream &out, char *fileName, int line ) out << "\"\n"; } -void genLineDirective( ostream &out ) +void RubyCodeGen::genLineDirective( ostream &out ) { std::streambuf *sbuf = out.rdbuf(); output_filter *filter = static_cast(sbuf); - lineDirective( out, filter->fileName, filter->line + 1 ); + rubyLineDirective( out, filter->fileName, filter->line + 1 ); } string RubyCodeGen::DATA_PREFIX() @@ -241,13 +241,13 @@ string RubyCodeGen::FSM_NAME() void RubyCodeGen::ACTION( ostream &ret, Action *action, int targState, bool inFinish ) { /* Write the preprocessor line info for going into the source file. */ - lineDirective( ret, sourceFileName, action->loc.line ); + rubyLineDirective( ret, sourceFileName, action->loc.line ); /* Write the block and close it off. */ ret << " begin\n"; INLINE_LIST( ret, action->inlineList, targState, inFinish ); ret << " end\n"; - lineDirective( ret, sourceFileName, action->loc.line ); + rubyLineDirective( ret, sourceFileName, action->loc.line ); } @@ -315,7 +315,7 @@ string RubyCodeGen::INT( int i ) void RubyCodeGen::CONDITION( ostream &ret, Action *condition ) { ret << "\n"; - lineDirective( ret, sourceFileName, condition->loc.line ); + rubyLineDirective( ret, sourceFileName, condition->loc.line ); INLINE_LIST( ret, condition->inlineList, 0, false ); } @@ -470,81 +470,81 @@ string RubyCodeGen::ACCESS() /* Write out an inline tree structure. Walks the list and possibly calls out * to virtual functions than handle language specific items in the tree. */ -void RubyCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, +void RubyCodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish ) { - for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) { + for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { switch ( item->type ) { - case InlineItem::Text: + case GenInlineItem::Text: ret << item->data; break; - case InlineItem::Goto: + case GenInlineItem::Goto: GOTO( ret, item->targState->id, inFinish ); break; - case InlineItem::Call: + case GenInlineItem::Call: CALL( ret, item->targState->id, targState, inFinish ); break; - case InlineItem::Next: + case GenInlineItem::Next: NEXT( ret, item->targState->id, inFinish ); break; - case InlineItem::Ret: + case GenInlineItem::Ret: RET( ret, inFinish ); break; - case InlineItem::PChar: + case GenInlineItem::PChar: ret << P(); break; - case InlineItem::Char: + case GenInlineItem::Char: ret << GET_KEY(); break; - case InlineItem::Hold: + case GenInlineItem::Hold: ret << P() << " = " << P() << " - 1;"; break; - case InlineItem::Exec: + case GenInlineItem::Exec: EXEC( ret, item, targState, inFinish ); break; - case InlineItem::Curs: + case GenInlineItem::Curs: ret << "(_ps)"; break; - case InlineItem::Targs: + case GenInlineItem::Targs: ret << "(" << CS() << ")"; break; - case InlineItem::Entry: + case GenInlineItem::Entry: ret << item->targState->id; break; - case InlineItem::GotoExpr: + case GenInlineItem::GotoExpr: GOTO_EXPR( ret, item, inFinish ); break; - case InlineItem::CallExpr: + case GenInlineItem::CallExpr: CALL_EXPR( ret, item, targState, inFinish ); break; - case InlineItem::NextExpr: + case GenInlineItem::NextExpr: NEXT_EXPR( ret, item, inFinish ); break; - case InlineItem::LmSwitch: + case GenInlineItem::LmSwitch: LM_SWITCH( ret, item, targState, inFinish ); break; - case InlineItem::LmSetActId: + case GenInlineItem::LmSetActId: SET_ACT( ret, item ); break; - case InlineItem::LmSetTokEnd: + case GenInlineItem::LmSetTokEnd: SET_TOKEND( ret, item ); break; - case InlineItem::LmGetTokEnd: + case GenInlineItem::LmGetTokEnd: GET_TOKEND( ret, item ); break; - case InlineItem::LmInitTokStart: + case GenInlineItem::LmInitTokStart: INIT_TOKSTART( ret, item ); break; - case InlineItem::LmInitAct: + case GenInlineItem::LmInitAct: INIT_ACT( ret, item ); break; - case InlineItem::LmSetTokStart: + case GenInlineItem::LmSetTokStart: SET_TOKSTART( ret, item ); break; - case InlineItem::SubAction: + case GenInlineItem::SubAction: SUB_ACTION( ret, item, targState, inFinish ); break; - case InlineItem::Break: + case GenInlineItem::Break: BREAK( ret, targState ); break; } @@ -552,7 +552,7 @@ void RubyCodeGen::INLINE_LIST( ostream &ret, InlineList *inlineList, } -void RubyCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ) +void RubyCodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ) { /* The parser gives fexec two children. The double brackets are for D * code. If the inline list is a single word it will get interpreted as a @@ -562,13 +562,13 @@ void RubyCodeGen::EXEC( ostream &ret, InlineItem *item, int targState, int inFin ret << "))-1; end\n"; } -void RubyCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, +void RubyCodeGen::LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish ) { ret << " case " << ACT() << "\n"; - for ( InlineList::Iter lma = *item->children; lma.lte(); lma++ ) { + for ( GenInlineList::Iter lma = *item->children; lma.lte(); lma++ ) { /* Write the case label, the action and the case break. */ if ( lma->lmId < 0 ) ret << " else\n"; @@ -585,27 +585,27 @@ void RubyCodeGen::LM_SWITCH( ostream &ret, InlineItem *item, ret << "end \n\t"; } -void RubyCodeGen::SET_ACT( ostream &ret, InlineItem *item ) +void RubyCodeGen::SET_ACT( ostream &ret, GenInlineItem *item ) { ret << ACT() << " = " << item->lmId << ";"; } -void RubyCodeGen::INIT_TOKSTART( ostream &ret, InlineItem *item ) +void RubyCodeGen::INIT_TOKSTART( ostream &ret, GenInlineItem *item ) { ret << TOKSTART() << " = " << NULL_ITEM() << ";"; } -void RubyCodeGen::INIT_ACT( ostream &ret, InlineItem *item ) +void RubyCodeGen::INIT_ACT( ostream &ret, GenInlineItem *item ) { ret << ACT() << " = 0\n"; } -void RubyCodeGen::SET_TOKSTART( ostream &ret, InlineItem *item ) +void RubyCodeGen::SET_TOKSTART( ostream &ret, GenInlineItem *item ) { ret << TOKSTART() << " = " << P() << "\n"; } -void RubyCodeGen::SET_TOKEND( ostream &ret, InlineItem *item ) +void RubyCodeGen::SET_TOKEND( ostream &ret, GenInlineItem *item ) { /* The tokend action sets tokend. */ ret << TOKEND() << " = " << P(); @@ -614,12 +614,12 @@ void RubyCodeGen::SET_TOKEND( ostream &ret, InlineItem *item ) out << "\n"; } -void RubyCodeGen::GET_TOKEND( ostream &ret, InlineItem *item ) +void RubyCodeGen::GET_TOKEND( ostream &ret, GenInlineItem *item ) { ret << TOKEND(); } -void RubyCodeGen::SUB_ACTION( ostream &ret, InlineItem *item, +void RubyCodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish ) { if ( item->children->length() > 0 ) { @@ -639,13 +639,13 @@ int RubyCodeGen::TRANS_ACTION( RedTransAp *trans ) return act; } -ostream &RubyCodeGen::source_warning( const InputLoc &loc ) +ostream &RubyCodeGen::source_warning( const GenInputLoc &loc ) { cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: "; return cerr; } -ostream &RubyCodeGen::source_error( const InputLoc &loc ) +ostream &RubyCodeGen::source_error( const GenInputLoc &loc ) { gblErrorCount += 1; assert( sourceFileName != 0 ); diff --git a/rlgen-ruby/ruby-codegen.h b/rlgen-ruby/ruby-codegen.h index 21034ff..5a7aae2 100644 --- a/rlgen-ruby/ruby-codegen.h +++ b/rlgen-ruby/ruby-codegen.h @@ -53,7 +53,7 @@ protected: string START_STATE_ID(); string ERROR_STATE(); string FIRST_FINAL_STATE(); - void INLINE_LIST(ostream &ret, InlineList *inlineList, int targState, bool inFinish); + void INLINE_LIST(ostream &ret, GenInlineList *inlineList, int targState, bool inFinish); string ACCESS(); void ACTION( ostream &ret, Action *action, int targState, bool inFinish ); @@ -129,14 +129,14 @@ protected: virtual void BREAK( ostream &ret, int targState ) = 0; virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0; - virtual void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) = 0; + virtual void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0; virtual void CALL( ostream &ret, int callDest, int targState, bool inFinish ) = 0; - virtual void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) = 0; + virtual void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) = 0; virtual void RET( ostream &ret, bool inFinish ) = 0; virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0; - virtual void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) = 0; + virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0; virtual int TO_STATE_ACTION( RedStateAp *state ) = 0; virtual int FROM_STATE_ACTION( RedStateAp *state ) = 0; @@ -144,19 +144,19 @@ protected: virtual int TRANS_ACTION( RedTransAp *trans ); - void EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ); - void LM_SWITCH( ostream &ret, InlineItem *item, int targState, int inFinish ); - void SET_ACT( ostream &ret, InlineItem *item ); - void INIT_TOKSTART( ostream &ret, InlineItem *item ); - void INIT_ACT( ostream &ret, InlineItem *item ); - void SET_TOKSTART( ostream &ret, InlineItem *item ); - void SET_TOKEND( ostream &ret, InlineItem *item ); - void GET_TOKEND( ostream &ret, InlineItem *item ); - void SUB_ACTION( ostream &ret, InlineItem *item, int targState, bool inFinish ); + void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void SET_ACT( ostream &ret, GenInlineItem *item ); + void INIT_TOKSTART( ostream &ret, GenInlineItem *item ); + void INIT_ACT( ostream &ret, GenInlineItem *item ); + void SET_TOKSTART( ostream &ret, GenInlineItem *item ); + void SET_TOKEND( ostream &ret, GenInlineItem *item ); + void GET_TOKEND( ostream &ret, GenInlineItem *item ); + void SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish ); protected: - ostream &source_warning(const InputLoc &loc); - ostream &source_error(const InputLoc &loc); + ostream &source_warning(const GenInputLoc &loc); + ostream &source_error(const GenInputLoc &loc); /* fields */ @@ -164,6 +164,7 @@ protected: bool againLabelUsed; bool useIndicies; + void genLineDirective( ostream &out ); }; /* diff --git a/rlgen-ruby/ruby-fflatcodegen.cpp b/rlgen-ruby/ruby-fflatcodegen.cpp index 89cab90..d2eca2e 100644 --- a/rlgen-ruby/ruby-fflatcodegen.cpp +++ b/rlgen-ruby/ruby-fflatcodegen.cpp @@ -32,7 +32,7 @@ void RubyFFlatCodeGen::GOTO( ostream &out, int gotoDest, bool inFinish ) " end\n"; } -void RubyFFlatCodeGen::GOTO_EXPR( ostream &out, InlineItem *ilItem, bool inFinish ) +void RubyFFlatCodeGen::GOTO_EXPR( ostream &out, GenInlineItem *ilItem, bool inFinish ) { out << " begin\n" @@ -65,7 +65,7 @@ void RubyFFlatCodeGen::CALL( ostream &out, int callDest, int targState, bool inF out << "end\n"; } -void RubyFFlatCodeGen::CALL_EXPR(ostream &out, InlineItem *ilItem, +void RubyFFlatCodeGen::CALL_EXPR(ostream &out, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { diff --git a/rlgen-ruby/ruby-fflatcodegen.h b/rlgen-ruby/ruby-fflatcodegen.h index b952841..5319b3a 100644 --- a/rlgen-ruby/ruby-fflatcodegen.h +++ b/rlgen-ruby/ruby-fflatcodegen.h @@ -39,9 +39,9 @@ protected: std::ostream &ACTION_SWITCH(); void GOTO( ostream &out, int gotoDest, bool inFinish ); - void GOTO_EXPR( ostream &out, InlineItem *ilItem, bool inFinish ); + void GOTO_EXPR( ostream &out, GenInlineItem *ilItem, bool inFinish ); void CALL( ostream &out, int callDest, int targState, bool inFinish ); - void CALL_EXPR(ostream &out, InlineItem *ilItem, int targState, bool inFinish ); + void CALL_EXPR(ostream &out, GenInlineItem *ilItem, int targState, bool inFinish ); void RET( ostream &out, bool inFinish ); void BREAK( ostream &out, int targState ); diff --git a/rlgen-ruby/ruby-flatcodegen.cpp b/rlgen-ruby/ruby-flatcodegen.cpp index a9346a9..d95ddac 100644 --- a/rlgen-ruby/ruby-flatcodegen.cpp +++ b/rlgen-ruby/ruby-flatcodegen.cpp @@ -434,7 +434,7 @@ void RubyFlatCodeGen::CALL( ostream &out, int callDest, int targState, bool inFi out << "end\n"; } -void RubyFlatCodeGen::CALL_EXPR(ostream &out, InlineItem *ilItem, int targState, bool inFinish ) +void RubyFlatCodeGen::CALL_EXPR(ostream &out, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { out << "begin\n"; @@ -484,7 +484,7 @@ void RubyFlatCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void RubyFlatCodeGen::GOTO_EXPR( ostream &out, InlineItem *ilItem, bool inFinish ) +void RubyFlatCodeGen::GOTO_EXPR( ostream &out, GenInlineItem *ilItem, bool inFinish ) { out << " begin\n" @@ -498,7 +498,7 @@ void RubyFlatCodeGen::GOTO_EXPR( ostream &out, InlineItem *ilItem, bool inFinish " end\n"; } -void RubyFlatCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void RubyFlatCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); diff --git a/rlgen-ruby/ruby-flatcodegen.h b/rlgen-ruby/ruby-flatcodegen.h index ad81d70..81c20a5 100644 --- a/rlgen-ruby/ruby-flatcodegen.h +++ b/rlgen-ruby/ruby-flatcodegen.h @@ -68,9 +68,9 @@ protected: void GOTO( ostream &ret, int gotoDest, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); void NEXT( ostream &ret, int nextDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void CURS( ostream &ret, bool inFinish ); void TARGS( ostream &ret, bool inFinish, int targState ); void RET( ostream &ret, bool inFinish ); diff --git a/rlgen-ruby/ruby-ftabcodegen.cpp b/rlgen-ruby/ruby-ftabcodegen.cpp index ae4701f..61eba5d 100644 --- a/rlgen-ruby/ruby-ftabcodegen.cpp +++ b/rlgen-ruby/ruby-ftabcodegen.cpp @@ -43,7 +43,7 @@ void RubyFTabCodeGen::GOTO( ostream &out, int gotoDest, bool inFinish ) " end\n"; } -void RubyFTabCodeGen::GOTO_EXPR( ostream &out, InlineItem *ilItem, bool inFinish ) +void RubyFTabCodeGen::GOTO_EXPR( ostream &out, GenInlineItem *ilItem, bool inFinish ) { out << " begin\n" @@ -76,7 +76,7 @@ void RubyFTabCodeGen::CALL( ostream &out, int callDest, int targState, bool inFi out << "end\n"; } -void RubyFTabCodeGen::CALL_EXPR(ostream &out, InlineItem *ilItem, +void RubyFTabCodeGen::CALL_EXPR(ostream &out, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { diff --git a/rlgen-ruby/ruby-ftabcodegen.h b/rlgen-ruby/ruby-ftabcodegen.h index 9e0881c..b2d9095 100644 --- a/rlgen-ruby/ruby-ftabcodegen.h +++ b/rlgen-ruby/ruby-ftabcodegen.h @@ -36,9 +36,9 @@ protected: std::ostream &ACTION_SWITCH(); void GOTO( ostream &out, int gotoDest, bool inFinish ); - void GOTO_EXPR( ostream &out, InlineItem *ilItem, bool inFinish ); + void GOTO_EXPR( ostream &out, GenInlineItem *ilItem, bool inFinish ); void CALL( ostream &out, int callDest, int targState, bool inFinish ); - void CALL_EXPR(ostream &out, InlineItem *ilItem, int targState, bool inFinish ); + void CALL_EXPR(ostream &out, GenInlineItem *ilItem, int targState, bool inFinish ); void RET( ostream &out, bool inFinish ); void BREAK( ostream &out, int targState ); diff --git a/rlgen-ruby/ruby-tabcodegen.cpp b/rlgen-ruby/ruby-tabcodegen.cpp index 105c44d..3d39ae1 100644 --- a/rlgen-ruby/ruby-tabcodegen.cpp +++ b/rlgen-ruby/ruby-tabcodegen.cpp @@ -46,7 +46,7 @@ void RubyTabCodeGen::GOTO( ostream &out, int gotoDest, bool inFinish ) " end\n"; } -void RubyTabCodeGen::GOTO_EXPR( ostream &out, InlineItem *ilItem, bool inFinish ) +void RubyTabCodeGen::GOTO_EXPR( ostream &out, GenInlineItem *ilItem, bool inFinish ) { out << " begin\n" @@ -81,7 +81,7 @@ void RubyTabCodeGen::CALL( ostream &out, int callDest, int targState, bool inFin out << "end\n"; } -void RubyTabCodeGen::CALL_EXPR(ostream &out, InlineItem *ilItem, int targState, bool inFinish ) +void RubyTabCodeGen::CALL_EXPR(ostream &out, GenInlineItem *ilItem, int targState, bool inFinish ) { if ( prePushExpr != 0 ) { out << "begin\n"; @@ -512,7 +512,7 @@ void RubyTabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish ) ret << CS() << " = " << nextDest << ";"; } -void RubyTabCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) +void RubyTabCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) { ret << CS() << " = ("; INLINE_LIST( ret, ilItem->children, 0, inFinish ); diff --git a/rlgen-ruby/ruby-tabcodegen.h b/rlgen-ruby/ruby-tabcodegen.h index dd9be73..7ce99af 100644 --- a/rlgen-ruby/ruby-tabcodegen.h +++ b/rlgen-ruby/ruby-tabcodegen.h @@ -47,9 +47,9 @@ public: public: void BREAK( ostream &ret, int targState ); void GOTO( ostream &ret, int gotoDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); + void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); void CALL( ostream &ret, int callDest, int targState, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); + void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ); void RET( ostream &ret, bool inFinish ); void COND_TRANSLATE(); @@ -85,7 +85,7 @@ public: void NEXT( ostream &ret, int nextDest, bool inFinish ); - void NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); + void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ); virtual int TO_STATE_ACTION( RedStateAp *state ); virtual int FROM_STATE_ACTION( RedStateAp *state ); @@ -97,16 +97,16 @@ private: public: - void EXEC( ostream &ret, InlineItem *item, int targState, int inFinish ); - void EXECTE( ostream &ret, InlineItem *item, int targState, int inFinish ); - void LM_SWITCH( ostream &ret, InlineItem *item, int targState, int inFinish ); - void SET_ACT( ostream &ret, InlineItem *item ); - void INIT_TOKSTART( ostream &ret, InlineItem *item ); - void INIT_ACT( ostream &ret, InlineItem *item ); - void SET_TOKSTART( ostream &ret, InlineItem *item ); - void SET_TOKEND( ostream &ret, InlineItem *item ); - void GET_TOKEND( ostream &ret, InlineItem *item ); - void SUB_ACTION( ostream &ret, InlineItem *item, + void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void EXECTE( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish ); + void SET_ACT( ostream &ret, GenInlineItem *item ); + void INIT_TOKSTART( ostream &ret, GenInlineItem *item ); + void INIT_ACT( ostream &ret, GenInlineItem *item ); + void SET_TOKSTART( ostream &ret, GenInlineItem *item ); + void SET_TOKEND( ostream &ret, GenInlineItem *item ); + void GET_TOKEND( ostream &ret, GenInlineItem *item ); + void SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish ); -- 2.7.4