/*
- * Copyright 2005-2006 Adrian Thurston <thurston@cs.queensu.ca>
+ * Copyright 2005-2007 Adrian Thurston <thurston@cs.queensu.ca>
*/
/* This file is part of Ragel.
/* Set the maximums of various values used for deciding types. */
setValueLimits();
}
-
-
-
-void lineDirective( ostream &out, char *fileName, int line )
-{
- if ( hostLangType != JavaCode ) {
- /* Write the preprocessor line info for to the input file. */
- out << "#line " << line << " \"";
- for ( char *pc = fileName; *pc != 0; pc++ ) {
- if ( *pc == '\\' )
- out << "\\\\";
- else
- out << *pc;
- }
- out << "\"\n";
- }
-}
-
/*
- * Copyright 2005-2006 Adrian Thurston <thurston@cs.queensu.ca>
+ * Copyright 2005-2007 Adrian Thurston <thurston@cs.queensu.ca>
*/
/* This file is part of Ragel.
typedef AvlMap<char *, CodeGenData*, CmpStr> CodeGenMap;
typedef AvlMapEl<char *, CodeGenData*> CodeGenMapEl;
+/*
+ * The interface to the parser
+ */
+
+/* These two 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,
+ char *fsmName, ostream &out, bool wantComplete );
+
struct CodeGenData
{
+ /*
+ * The interface to the code generator.
+ */
+ virtual void finishRagelDef() {}
+ virtual void writeStatement( InputLoc &loc, int nargs, char **args ) {}
+
+ /********************/
+
CodeGenData( ostream &out );
virtual ~CodeGenData() {}
void prepareMachine();
bool hasBeenPrepared;
- /* The interface to the code generator. */
- virtual void finishRagelDef() {}
- virtual void writeStatement( InputLoc &loc, int nargs, char **args ) {}
};
void lineDirective( ostream &out, char *fileName, int line );
void genLineDirective( ostream &out );
-/* These two 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, char *language );
-CodeGenData *makeCodeGen( char *sourceFileName,
- char *fsmName, ostream &out, bool wantComplete );
-
#endif /* _GENDATA_H */
if ( langAttr == 0 )
error($1->loc) << "tag <ragel> requires a lang attribute" << endl;
else {
- outStream = openOutput( sourceFileName, langAttr->value );
+ if ( strcmp( langAttr->value, "C" ) == 0 ) {
+ hostLangType = CCode;
+ hostLang = &hostLangC;
+ }
+ else if ( strcmp( langAttr->value, "D" ) == 0 ) {
+ hostLangType = DCode;
+ hostLang = &hostLangD;
+ }
+ else if ( strcmp( langAttr->value, "Java" ) == 0 ) {
+ hostLangType = JavaCode;
+ hostLang = &hostLangJava;
+ }
+ else if ( strcmp( langAttr->value, "Ruby" ) == 0 ) {
+ hostLangType = RubyCode;
+ hostLang = &hostLangRuby;
+ }
+ else {
+ error($1->loc) << "expecting lang attribute to be "
+ "one of C, D, Java or Ruby" << endl;
+ }
+
+ outStream = openOutput( sourceFileName );
}
}
};
using std::cerr;
using std::endl;
+void lineDirective( ostream &out, char *fileName, int line )
+{
+ /* Write the preprocessor line info for to the input file. */
+ out << "#line " << line << " \"";
+ for ( char *pc = fileName; *pc != 0; pc++ ) {
+ if ( *pc == '\\' )
+ out << "\\\\";
+ else
+ out << *pc;
+ }
+ out << "\"\n";
+}
+
+void genLineDirective( ostream &out )
+{
+ assert( outputFormat == OutCode );
+ std::streambuf *sbuf = out.rdbuf();
+ output_filter *filter = static_cast<output_filter*>(sbuf);
+ lineDirective( out, filter->fileName, filter->line + 1 );
+}
+
/* Init code gen with in parameters. */
FsmCodeGen::FsmCodeGen( ostream &out )
return cerr;
}
-void genLineDirective( ostream &out )
-{
- assert( outputFormat == OutCode );
- std::streambuf *sbuf = out.rdbuf();
- output_filter *filter = static_cast<output_filter*>(sbuf);
- lineDirective( out, filter->fileName, filter->line + 1 );
-}
-
*/
/* Invoked by the parser when the root element is opened. */
-ostream *openOutput( char *inputFile, char *language )
+ostream *openOutput( char *inputFile )
{
- if ( strcmp( language, "C" ) == 0 ) {
- hostLangType = CCode;
- hostLang = &hostLangC;
- }
- else if ( strcmp( language, "D" ) == 0 ) {
- hostLangType = DCode;
- hostLang = &hostLangD;
- }
- else {
- error() << PROGNAME " generates code for C and D only, you "
- "need a diferent code generator for " << language << endl;
- }
+ if ( hostLangType != CCode && hostLangType != DCode )
+ error() << PROGNAME " generates code for C and D only" << endl;
/* If the output format is code and no output file name is given, then
* make a default. */
using std::cerr;
using std::endl;
+void lineDirective( ostream &out, char *fileName, int line )
+{
+ /* Write the preprocessor line info for to the input file. */
+ out << "// line " << line << " \"";
+ for ( char *pc = fileName; *pc != 0; pc++ ) {
+ if ( *pc == '\\' )
+ out << "\\\\";
+ else
+ out << *pc;
+ }
+ out << "\"\n";
+}
+
void genLineDirective( ostream &out )
{
std::streambuf *sbuf = out.rdbuf();
lineDirective( out, filter->fileName, filter->line + 1 );
}
-
void JavaTabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
{
ret << "{" << CS() << " = " << gotoDest << "; " <<
*/
/* Invoked by the parser when the root element is opened. */
-ostream *openOutput( char *inputFile, char *language )
+ostream *openOutput( char *inputFile )
{
- if ( strcmp( language, "Java" ) != 0 )
+ if ( hostLangType != JavaCode )
error() << "this code generator is for Java only" << endl;
/* If the output format is code and no output file name is given, then
*/
/* Invoked by the parser when the root element is opened. */
-ostream *openOutput( char *inputFile, char *language )
+ostream *openOutput( char *inputFile )
{
- if ( strcmp( language, "Ruby" ) != 0 )
+ if ( hostLangType != RubyCode )
error() << "this code generator is for Ruby only" << endl;
/* If the output format is code and no output file name is given, then
using std::cerr;
using std::endl;
+void lineDirective( ostream &out, char *fileName, int line )
+{
+ if ( hostLangType != JavaCode ) {
+ /* Write a comment containing line info. */
+ out << "# line " << line << " \"";
+ for ( char *pc = fileName; *pc != 0; pc++ ) {
+ if ( *pc == '\\' )
+ out << "\\\\";
+ else
+ out << *pc;
+ }
+ out << "\"\n";
+ }
+}
+
void genLineDirective( ostream &out )
{
std::streambuf *sbuf = out.rdbuf();