#include <string>
#include <assert.h>
-/* Code generators. */
-#include "cdtable.h"
-#include "cdftable.h"
-#include "cdflat.h"
-#include "cdfflat.h"
-#include "cdgoto.h"
-#include "cdfgoto.h"
-#include "cdipgoto.h"
-#include "cdsplit.h"
using std::ostream;
using std::ostringstream;
using std::cerr;
using std::endl;
-/* Target language and output style. */
-extern CodeStyleEnum codeStyle;
-
-/* Io globals. */
-extern istream *inStream;
-extern ostream *outStream;
-extern output_filter *outFilter;
-extern const char *outputFileName;
-
-/* Graphviz dot file generation. */
-extern bool graphvizDone;
extern int numSplitPartitions;
extern bool noLineDirectives;
-/* Invoked by the parser when the root element is opened. */
-ostream *cdOpenOutput( const char *inputFile )
-{
- if ( hostLang->lang != HostLang::C && hostLang->lang != HostLang::D ) {
- error() << "this code generator is for C and D only" << endl;
- exit(1);
- }
-
- /* If the output format is code and no output file name is given, then
- * make a default. */
- if ( outputFileName == 0 ) {
- const char *ext = findFileExtension( inputFile );
- if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
- outputFileName = fileNameFromStem( inputFile, ".h" );
- else {
- const char *defExtension = 0;
- switch ( hostLang->lang ) {
- case HostLang::C: defExtension = ".c"; break;
- case HostLang::D: defExtension = ".d"; break;
- default: break;
- }
- outputFileName = fileNameFromStem( inputFile, defExtension );
- }
- }
-
- /* Make sure we are not writing to the same file as the input file. */
- if ( outputFileName != 0 && strcmp( inputFile, outputFileName ) == 0 ) {
- error() << "output file \"" << outputFileName <<
- "\" is the same as the input file" << endl;
- }
-
- if ( outputFileName != 0 ) {
- /* Create the filter on the output and open it. */
- outFilter = new output_filter( outputFileName );
-
- /* Open the output stream, attaching it to the filter. */
- outStream = new ostream( outFilter );
- }
- else {
- /* Writing out ot std out. */
- outStream = &cout;
- }
- return outStream;
-}
-
-/* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *cdMakeCodeGen( const char *sourceFileName, const char *fsmName,
- ostream &out, bool wantComplete )
-{
- CodeGenData *codeGen = 0;
- switch ( hostLang->lang ) {
- case HostLang::C:
- switch ( codeStyle ) {
- case GenTables:
- codeGen = new CTabCodeGen(out);
- break;
- case GenFTables:
- codeGen = new CFTabCodeGen(out);
- break;
- case GenFlat:
- codeGen = new CFlatCodeGen(out);
- break;
- case GenFFlat:
- codeGen = new CFFlatCodeGen(out);
- break;
- case GenGoto:
- codeGen = new CGotoCodeGen(out);
- break;
- case GenFGoto:
- codeGen = new CFGotoCodeGen(out);
- break;
- case GenIpGoto:
- codeGen = new CIpGotoCodeGen(out);
- break;
- case GenSplit:
- codeGen = new CSplitCodeGen(out);
- break;
- }
- break;
-
- case HostLang::D:
- switch ( codeStyle ) {
- case GenTables:
- codeGen = new DTabCodeGen(out);
- break;
- case GenFTables:
- codeGen = new DFTabCodeGen(out);
- break;
- case GenFlat:
- codeGen = new DFlatCodeGen(out);
- break;
- case GenFFlat:
- codeGen = new DFFlatCodeGen(out);
- break;
- case GenGoto:
- codeGen = new DGotoCodeGen(out);
- break;
- case GenFGoto:
- codeGen = new DFGotoCodeGen(out);
- break;
- case GenIpGoto:
- codeGen = new DIpGotoCodeGen(out);
- break;
- case GenSplit:
- codeGen = new DSplitCodeGen(out);
- break;
- }
- break;
-
- default: break;
- }
-
- codeGen->sourceFileName = sourceFileName;
- codeGen->fsmName = fsmName;
- codeGen->wantComplete = wantComplete;
-
- return codeGen;
-}
-
-
void cdLineDirective( ostream &out, const char *fileName, int line )
{
if ( noLineDirectives )
return ret.str();
}
-string FsmCodeGen::EOFV()
+string FsmCodeGen::vEOF()
{
ostringstream ret;
if ( eofExpr == 0 )
return ret.str();
}
-string FsmCodeGen::CS()
+string FsmCodeGen::vCS()
{
ostringstream ret;
if ( csExpr == 0 )
bool inFinish, bool csForced )
{
/* Write the preprocessor line info for going into the source file. */
- cdLineDirective( ret, sourceFileName, action->loc.line );
+ cdLineDirective( ret, action->loc.fileName, action->loc.line );
/* Write the block and close it off. */
ret << "\t{";
void FsmCodeGen::CONDITION( ostream &ret, GenAction *condition )
{
ret << "\n";
- cdLineDirective( ret, sourceFileName, condition->loc.line );
+ cdLineDirective( ret, condition->loc.fileName, condition->loc.line );
INLINE_LIST( ret, condition->inlineList, 0, false, false );
}
out << " {\n";
if ( !noCS )
- out << "\t" << CS() << " = " << START() << ";\n";
+ out << "\t" << vCS() << " = " << START() << ";\n";
/* If there are any calls, then the stack top needs initialization. */
if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )