# 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
#*************************************
}
/* 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),
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;
};
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 */
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
MinimizeOpt minimizeOpt = MinimizeMostOps;
/* Graphviz dot file generation. */
-char *machineSpec = 0, *machineName = 0;
+const char *machineSpec = 0, *machineName = 0;
bool machineSpecFound = false;
bool wantDupsRemoved = true;
}
}
-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);
}
}
-int frontend( char *inputFileName, char *outputFileName )
+int frontend( const char *inputFileName, const char *outputFileName )
{
/* Open the input file for reading. */
assert( inputFileName != 0 );
return gblErrorCount > 0;
}
-char *makeIntermedTemplate( char *baseFileName )
+char *makeIntermedTemplate( const char *baseFileName )
{
char *result = 0;
const char *templ = "ragel-XXXXXX.xml";
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";
}
-void cleanExit( char *intermed, int status )
+void cleanExit( const char *intermed, int status )
{
unlink( intermed );
exit( status );
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. */
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 );
if ( WEXITSTATUS(status) != 0 )
cleanExit( intermed, WEXITSTATUS(status) );
+#endif
}
#else
#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";
#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;
}
/* 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 );
"\" 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. */
/* 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),
}
-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. */
{
/* 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();
/*
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;
* 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' )
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. */
/* Options. */
extern MinimizeLevel minimizeLevel;
extern MinimizeOpt minimizeOpt;
-extern char *machineSpec, *machineName;
+extern const char *machineSpec, *machineName;
extern bool printStatistics;
extern bool wantDupsRemoved;
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<const char *> ArgsVector;
/* 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<IncludeHistoryItem> IncludeHistory;
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 );
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 )
:
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();
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 );
bool active();
ostream &scan_error();
- char *fileName;
+ const char *fileName;
istream &input;
ostream &output;
Parser *inclToParser;
}
}
-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;
#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;
using std::endl;
/* Total error count. */
-int gblErrorCount = 0;
+/* int gblErrorCount = 0; */
CodeGenData::CodeGenData( ostream &out )
:
}
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;
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:
}
}
-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;
}
}
}
-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 )
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.
}
}
-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 );
/* 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 );
/*********************************/
/* 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 );
/********************/
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;
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 );
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();
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 );
};
using std::ostringstream;
-KeyOps *keyOps = 0;
+/* KeyOps *keyOps = 0; */
string Action::nameOrLoc()
{
using std::string;
struct RedStateAp;
-struct InlineList;
+struct GenInlineList;
struct Action;
/* Location in an input file. */
-struct InputLoc
+struct GenInputLoc
{
int line;
int col;
/*
* Inline code tree
*/
-struct InlineItem
+struct GenInlineItem
{
enum Type
{
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<InlineItem> { };
+struct GenInlineList : public DList<GenInlineItem> { };
/* Element in list of actions. Contains the string for the code to exectute. */
struct Action
}
/* Data collected during parse. */
- InputLoc loc;
+ GenInputLoc loc;
char *name;
- InlineList *inlineList;
+ GenInlineList *inlineList;
int actionId;
string nameOrLoc();
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,
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) { }
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;
%% 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 */
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<output_filter*>(sbuf);
+ lineDirective( out, filter->fileName, filter->line + 1 );
+}
+
%%{
-parser Parser;
+parser XmlParser;
include "xmlparse.kh";
if ( langAttr == 0 )
error($1->loc) << "tag <ragel> 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;
nonterm tag_write_head
{
- InputLoc loc;
+ GenInputLoc loc;
};
tag_write_head: TAG_write
nonterm inline_list
{
- InlineList *inlineList;
+ GenInlineList *inlineList;
};
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;
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
};
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" );
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;
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 );
}
-ostream &Parser::parser_error( int tokId, Token &token )
+ostream &XmlParser::parser_error( int tokId, Token &token )
{
gblErrorCount += 1;
assert( fileName != 0 );
return cerr;
}
-ostream &Parser::source_error( const InputLoc &loc )
+ostream &XmlParser::source_error( const GenInputLoc &loc )
{
gblErrorCount += 1;
assert( sourceFileName != 0 );
}
-int Parser::token( int tokenId, Token &tok )
+int XmlParser::token( int tokenId, Token &tok )
{
int res = parseLangEl( tokenId, &tok );
if ( res < 0 )
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;
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;
#define BUFSIZE 4096
%%{
- machine Scanner;
+ machine XmlScanner;
write data;
}%%
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),
value(0)
{
%%{
- machine Scanner;
+ machine XmlScanner;
write init;
}%%
}
void adjustAttrPointers( int distance );
std::ostream &error();
- char *fileName;
+ const char *fileName;
istream &input;
/* Scanner State. */
#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;
/* 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; }
*|;
}%%
-int Scanner::scan( )
+int XmlScanner::scan( )
{
int token = TK_NO_TOKEN;
int space = 0, readlen = 0;
%% write exec;
- if ( cs == Scanner_error )
+ if ( cs == XmlScanner_error )
return TK_ERR;
if ( token != TK_NO_TOKEN ) {
}
}
-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();
return 0;
}
-std::ostream &Scanner::error()
+std::ostream &XmlScanner::error()
{
gblErrorCount += 1;
cerr << fileName << ":" << curline << ":" << curcol << ": ";
prefix = @prefix@
EXEEXT = @EXEEXT@
CXX = @CXX@
+AR = @AR@
+RANLIB = @RANLIB@
# Get objects and dependencies from sources.
OBJS = $(CC_SRCS:%.cpp=%.o)
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
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)
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 );
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 );
}
-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 << "{";
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 );
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
out << '\n';
}
-void genLineDirective( ostream &out )
+void FsmCodeGen::genLineDirective( ostream &out )
{
std::streambuf *sbuf = out.rdbuf();
output_filter *filter = static_cast<output_filter*>(sbuf);
- lineDirective( out, filter->fileName, filter->line + 1 );
+ cdLineDirective( out, filter->fileName, filter->line + 1 );
}
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
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";
"\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();
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 ) {
/* 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;
}
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{";
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 );
}
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 );
struct CodeGenData;
struct Action;
struct NameInst;
-struct InlineItem;
-struct InlineList;
+struct GenInlineItem;
+struct GenInlineList;
struct RedAction;
struct LongestMatch;
struct LongestMatchPart;
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();
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 );
bool againLabelUsed;
bool useIndicies;
+ void genLineDirective( ostream &out );
+
public:
/* Determine if we should use indicies. */
virtual void calcIndexSize() {}
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 );
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 );
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 << "{";
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 );
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 << "{";
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 );
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 );
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;
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 );
void STATE_GOTO_ERROR();
/* Set up labelNeeded flag for each state. */
- void setLabelsNeeded( InlineList *inlineList );
+ void setLabelsNeeded( GenInlineList *inlineList );
void setLabelsNeeded();
};
istream *inStream = 0;
ostream *outStream = 0;
output_filter *outFilter = 0;
-char *outputFileName = 0;
+const char *outputFileName = 0;
/* Graphviz dot file generation. */
bool graphvizDone = false;
bool printPrintables = false;
/* Print a summary of the options. */
-void usage()
+void cd_usage()
{
cout <<
"usage: " PROGNAME " [options] file\n"
}
/* 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 ": ";
*/
/* 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);
}
/* 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;
}
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);
}
}
/* 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;
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 ) {
/* 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;
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);
}
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);
}
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);
}
/* 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;
}
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;
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("<stdin>");
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 ){
void writeExec();
void writeParts();
- void setLabelsNeeded( RedStateAp *fromState, InlineList *inlineList );
+ void setLabelsNeeded( RedStateAp *fromState, GenInlineList *inlineList );
void setLabelsNeeded( RedStateAp *fromState, RedTransAp *trans );
void setLabelsNeeded();
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 );
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 );
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 << "{";
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 );
prefix = @prefix@
EXEEXT = @EXEEXT@
CXX = @CXX@
+AR = @AR@
+RANLIB = @RANLIB@
# Get objects and dependencies from sources.
OBJS = $(CC_SRCS:%.cpp=%.o)
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
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)
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();
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();
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 );
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 );
}
-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 << "{";
/*
* 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:
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 );
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
out << '\n';
}
-void genLineDirective( ostream &out )
+void CSharpFsmCodeGen::genLineDirective( ostream &out )
{
std::streambuf *sbuf = out.rdbuf();
output_filter *filter = static_cast<output_filter*>(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 );
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;
}
/* 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;
};
/* Write out the array of actions. */
-std::ostream &FsmCodeGen::ACTIONS_ARRAY()
+std::ostream &CSharpFsmCodeGen::ACTIONS_ARRAY()
{
out << "\t0, ";
int totalActions = 1;
}
-string FsmCodeGen::ACCESS()
+string CSharpFsmCodeGen::ACCESS()
{
ostringstream ret;
if ( accessExpr != 0 )
}
-string FsmCodeGen::P()
+string CSharpFsmCodeGen::P()
{
ostringstream ret;
if ( pExpr == 0 )
return ret.str();
}
-string FsmCodeGen::PE()
+string CSharpFsmCodeGen::PE()
{
ostringstream ret;
if ( peExpr == 0 )
return ret.str();
}
-string FsmCodeGen::EOFV()
+string CSharpFsmCodeGen::EOFV()
{
ostringstream ret;
if ( eofExpr == 0 )
return ret.str();
}
-string FsmCodeGen::CS()
+string CSharpFsmCodeGen::CS()
{
ostringstream ret;
if ( csExpr == 0 )
return ret.str();
}
-string FsmCodeGen::TOP()
+string CSharpFsmCodeGen::TOP()
{
ostringstream ret;
if ( topExpr == 0 )
return ret.str();
}
-string FsmCodeGen::STACK()
+string CSharpFsmCodeGen::STACK()
{
ostringstream ret;
if ( stackExpr == 0 )
return ret.str();
}
-string FsmCodeGen::ACT()
+string CSharpFsmCodeGen::ACT()
{
ostringstream ret;
if ( actExpr == 0 )
return ret.str();
}
-string FsmCodeGen::TOKSTART()
+string CSharpFsmCodeGen::TOKSTART()
{
ostringstream ret;
if ( tokstartExpr == 0 )
return ret.str();
}
-string FsmCodeGen::TOKEND()
+string CSharpFsmCodeGen::TOKEND()
{
ostringstream ret;
if ( tokendExpr == 0 )
return ret.str();
}
-string FsmCodeGen::GET_WIDE_KEY()
+string CSharpFsmCodeGen::GET_WIDE_KEY()
{
if ( redFsm->anyConditions() )
return "_widec";
return GET_KEY();
}
-string FsmCodeGen::GET_WIDE_KEY( RedStateAp *state )
+string CSharpFsmCodeGen::GET_WIDE_KEY( RedStateAp *state )
{
if ( state->stateCondList.length() > 0 )
return "_widec";
return GET_KEY();
}
-string FsmCodeGen::GET_KEY()
+string CSharpFsmCodeGen::GET_KEY()
{
ostringstream ret;
if ( getKeyExpr != 0 ) {
/* 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 )
/* 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 )
return ret.str();
}
-string FsmCodeGen::ALPHA_KEY( Key key )
+string CSharpFsmCodeGen::ALPHA_KEY( Key key )
{
ostringstream ret;
if (key.getVal() > 0xFFFF) {
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
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";
"\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();
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 ) {
/* 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++ ) {
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{";
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 )
return ret.str();
}
-string FsmCodeGen::FIRST_FINAL_STATE()
+string CSharpFsmCodeGen::FIRST_FINAL_STATE()
{
ostringstream ret;
if ( redFsm->firstFinState != 0 )
return ret.str();
}
-void FsmCodeGen::writeInit()
+void CSharpFsmCodeGen::writeInit()
{
out << " {\n";
out << " }\n";
}
-string FsmCodeGen::DATA_PREFIX()
+string CSharpFsmCodeGen::DATA_PREFIX()
{
if ( dataPrefix )
return FSM_NAME() + "_";
}
/* Emit the alphabet data type. */
-string FsmCodeGen::ALPH_TYPE()
+string CSharpFsmCodeGen::ALPH_TYPE()
{
string ret = keyOps->alphType->data1;
if ( keyOps->alphType->data2 != 0 ) {
}
/* Emit the alphabet data type. */
-string FsmCodeGen::WIDE_ALPH_TYPE()
+string CSharpFsmCodeGen::WIDE_ALPH_TYPE()
{
string ret;
if ( redFsm->maxKey <= keyOps->maxKey )
return ret;
}
-void FsmCodeGen::STATE_IDS()
+void CSharpFsmCodeGen::STATE_IDS()
{
if ( redFsm->startState != 0 )
STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
* End C#-specific code.
*/
-void FsmCodeGen::finishRagelDef()
+void CSharpFsmCodeGen::finishRagelDef()
{
if ( codeStyle == GenGoto || codeStyle == GenFGoto ||
codeStyle == GenIpGoto || codeStyle == GenSplit )
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 );
struct CodeGenData;
struct Action;
struct NameInst;
-struct InlineItem;
-struct InlineList;
+struct GenInlineItem;
+struct GenInlineList;
struct RedAction;
struct LongestMatch;
struct LongestMatchPart;
}
/*
- * 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();
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();
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 );
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();
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();
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 );
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 );
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 << "{";
/*
* 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();
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 );
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 << "{";
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 );
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 );
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;
class CSharpIpGotoCodeGen : public CSharpGotoCodeGen
{
public:
- CSharpIpGotoCodeGen( ostream &out ) : FsmCodeGen(out),
+ CSharpIpGotoCodeGen( ostream &out ) : CSharpFsmCodeGen(out),
CSharpGotoCodeGen(out) {}
std::ostream &EXIT_STATES();
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 );
void STATE_GOTO_ERROR();
/* Set up labelNeeded flag for each state. */
- void setLabelsNeeded( InlineList *inlineList );
+ void setLabelsNeeded( GenInlineList *inlineList );
void setLabelsNeeded();
};
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"
}
/* 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 ": ";
*/
/* 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);
}
/* 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;
}
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);
}
}
/* 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;
/* 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 ) {
/* 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;
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);
}
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);
}
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);
}
/* 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;
}
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;
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("<stdin>");
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 ){
class CSharpSplitCodeGen : public CSharpIpGotoCodeGen
{
public:
- CSharpSplitCodeGen( ostream &out ) : FsmCodeGen(out), CSharpIpGotoCodeGen(out) {}
+ CSharpSplitCodeGen( ostream &out ) : CSharpFsmCodeGen(out), CSharpIpGotoCodeGen(out) {}
bool ptOutLabelUsed;
void writeExec();
void writeParts();
- void setLabelsNeeded( RedStateAp *fromState, InlineList *inlineList );
+ void setLabelsNeeded( RedStateAp *fromState, GenInlineList *inlineList );
void setLabelsNeeded( RedStateAp *fromState, RedTransAp *trans );
void setLabelsNeeded();
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 );
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 );
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 << "{";
/*
* 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();
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 );
#*************************************
prefix = @prefix@
-CXX = @CXX@
EXEEXT = @EXEEXT@
+CXX = @CXX@
+AR = @AR@
+RANLIB = @RANLIB@
# Get objects and dependencies from sources.
OBJS = $(CC_SRCS:%.cpp=%.o)
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
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)
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
out << "\"\n";
}
-void genLineDirective( ostream &out )
+void JavaTabCodeGen::genLineDirective( ostream &out )
{
std::streambuf *sbuf = out.rdbuf();
output_filter *filter = static_cast<output_filter*>(sbuf);
- lineDirective( out, filter->fileName, filter->line + 1 );
+ javaLineDirective( out, filter->fileName, filter->line + 1 );
}
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 );
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 << "{";
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
/* 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;
}
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";
"\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();
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 ) {
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{";
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 );
}
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 );
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();
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 );
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 );
};
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"
}
/* 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 ": ";
*/
/* 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);
}
/* 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;
}
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);
}
}
/* 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);
}
/* 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 ) {
/* 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;
/* 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;
}
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;
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("<stdin>");
#*************************************
prefix = @prefix@
-CXX = @CXX@
EXEEXT = @EXEEXT@
+CXX = @CXX@
+AR = @AR@
+RANLIB = @RANLIB@
# Get objects and dependencies from sources.
OBJS = $(CC_SRCS:%.cpp=%.o)
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
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)
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"
}
/* Print version information. */
-void version()
+void ruby_version()
{
cout << "Ragel Code Generator for Ruby" << endl <<
"Version " VERSION << ", " PUBDATE << endl <<
"Copyright (c) 2007 by Victor Hugo Borja" << endl;
}
-ostream &error()
+ostream &ruby_error()
{
gblErrorCount += 1;
cerr << PROGNAME ": ";
*/
/* 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);
}
/* 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;
}
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);
}
}
/* 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;
}
/* 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 ) {
/* 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;
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);
}
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);
}
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);
}
/* 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;
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("<stdin>");
"\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 );
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 );
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 << "{";
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 );
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
out << "\"\n";
}
-void genLineDirective( ostream &out )
+void RubyCodeGen::genLineDirective( ostream &out )
{
std::streambuf *sbuf = out.rdbuf();
output_filter *filter = static_cast<output_filter*>(sbuf);
- lineDirective( out, filter->fileName, filter->line + 1 );
+ rubyLineDirective( out, filter->fileName, filter->line + 1 );
}
string RubyCodeGen::DATA_PREFIX()
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 );
}
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 );
}
/* 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;
}
}
-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
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";
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();
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 ) {
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 );
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 );
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;
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 */
bool againLabelUsed;
bool useIndicies;
+ void genLineDirective( ostream &out );
};
/*
" 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"
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 ) {
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 );
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";
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"
" 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 );
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 );
" 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"
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 ) {
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 );
" 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"
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";
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 );
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();
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 );
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 );