#include "xmlcodegen.h"
#include "version.h"
#include "xmlparse.h"
+#include "inputdata.h"
using namespace std;
sectionGraph->setStateNumbers( 0 );
}
-void ParseData::generateReduced( XmlParser &xmlParser )
+void ParseData::generateReduced( InputData &inputData )
{
beginProcessing();
/* Make the generator. */
- BackendGen backendGen( sectionName, this, sectionGraph, xmlParser );
+ BackendGen backendGen( sectionName, this, sectionGraph, inputData );
/* Write out with it. */
backendGen.makeBackend();
out << "\"";
}
-void ParseData::generateXML( ostream &out, XmlParser &xmlParser )
+void ParseData::generateXML( ostream &out, InputData &inputData )
{
beginProcessing();
/* Make the generator. */
- XMLCodeGen codeGen( sectionName, this, sectionGraph, out, xmlParser );
+ XMLCodeGen codeGen( sectionName, this, sectionGraph, out, inputData );
/* Write out with it. */
codeGen.writeXML();
}
void writeMachines( std::ostream &out, std::string hostData,
- const char *inputFileName, XmlParser &xmlParser )
+ const char *inputFileName, InputData &inputData )
{
if ( machineSpec == 0 && machineName == 0 ) {
/* No machine spec or machine name given. Generate everything. */
for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
ParseData *pd = parser->value->pd;
if ( pd->instanceList.length() > 0 )
- pd->generateXML( out, xmlParser );
+ pd->generateXML( out, inputData );
}
out << hostData;
out << "</ragel>\n";
out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
writeLanguage( out );
out << ">\n";
- parseData->generateXML( out, xmlParser );
+ parseData->generateXML( out, inputData );
out << hostData;
out << "</ragel>\n";
}
}
}
-void generateSpecificReduced( XmlParser &xmlParser )
+void generateSpecificReduced( InputData &inputData )
{
if ( parserDict.length() > 0 ) {
/* There is either a machine spec or machine name given. */
/* Section/Machine to emit was found. Prepare and emit it. */
parseData->prepareMachineGen( graphDictEl );
if ( gblErrorCount == 0 )
- parseData->generateReduced( xmlParser );
+ parseData->generateReduced( inputData );
}
}
for ( InputItemList::Iter ii = inputItems; ii.lte(); ii++ ) {
if ( ii->type == InputItem::Write ) {
- CodeGenMapEl *mapEl = xmlParser.codeGenMap.find( (char*)ii->name.c_str() );
- xmlParser.cgd = mapEl->value;
- ::keyOps = &xmlParser.cgd->thisKeyOps;
+ CodeGenMapEl *mapEl = inputData.codeGenMap.find( (char*)ii->name.c_str() );
+ inputData.cgd = mapEl->value;
+ ::keyOps = &inputData.cgd->thisKeyOps;
- xmlParser.cgd->writeStatement( ii->loc, ii->writeArgs.length()-1, ii->writeArgs.data );
+ inputData.cgd->writeStatement( ii->loc, ii->writeArgs.length()-1, ii->writeArgs.data );
}
else
- xmlParser.cgd->out << ii->data.str();
+ inputData.cgd->out << ii->data.str();
+ }
+}
+
+void InputData::openOutput()
+{
+ if ( generateDot )
+ outStream = dotOpenOutput( sourceFileName );
+ else if ( hostLang->lang == HostLang::C )
+ outStream = cdOpenOutput( sourceFileName );
+ else if ( hostLang->lang == HostLang::D )
+ outStream = cdOpenOutput( sourceFileName );
+ else if ( hostLang->lang == HostLang::Java )
+ outStream = javaOpenOutput( sourceFileName );
+ else if ( hostLang->lang == HostLang::Ruby )
+ outStream = rubyOpenOutput( sourceFileName );
+ else if ( hostLang->lang == HostLang::CSharp )
+ outStream = csharpOpenOutput( sourceFileName );
+ else {
+ assert( false );
}
}
pd->prepareMachineGen( 0 );
}
- XmlParser xmlParser( sourceFileName, xmlFileName, outputActive, wantComplete );
- xmlParser.init();
- xmlParser.openOutput();
+ InputData inputData( sourceFileName, xmlFileName, outputActive, wantComplete );
+ inputData.openOutput();
if ( gblErrorCount > 0 )
return;
for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
ParseData *pd = parser->value->pd;
if ( pd->instanceList.length() > 0 )
- pd->generateReduced( xmlParser );
+ pd->generateReduced( inputData );
}
for ( InputItemList::Iter ii = inputItems; ii.lte(); ii++ ) {
if ( ii->type == InputItem::Write ) {
- CodeGenMapEl *mapEl = xmlParser.codeGenMap.find( (char*)ii->name.c_str() );
- xmlParser.cgd = mapEl->value;
- ::keyOps = &xmlParser.cgd->thisKeyOps;
+ CodeGenMapEl *mapEl = inputData.codeGenMap.find( (char*)ii->name.c_str() );
+ inputData.cgd = mapEl->value;
+ ::keyOps = &inputData.cgd->thisKeyOps;
- xmlParser.cgd->writeStatement( ii->loc, ii->writeArgs.length()-1, ii->writeArgs.data );
+ inputData.cgd->writeStatement( ii->loc, ii->writeArgs.length()-1, ii->writeArgs.data );
}
else
- xmlParser.cgd->out << ii->data.str();
+ inputData.cgd->out << ii->data.str();
}
}