From: thurston Date: Wed, 8 Oct 2008 18:06:42 +0000 (+0000) Subject: Need preserve xml code generation and duplicate+migrate to direct backend data X-Git-Tag: 2.0_alpha~98 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11fc1e20b0538c300a5c47edb861ffda1afd9bd2;p=external%2Fragel.git Need preserve xml code generation and duplicate+migrate to direct backend data generation. This commit brings back some of the xml code generation code that was migrated to direct. git-svn-id: http://svn.complang.org/ragel/trunk@488 052ea7fc-9027-0410-9066-f65837a77df0 --- diff --git a/ragel/main.cpp b/ragel/main.cpp index 51e0a29..b5c026c 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -500,6 +500,7 @@ void process( const char *inputFileName, const char *intermed ) /* Write the machines, then the surrounding code. */ writeMachines( *xmlOutFile, hostData.str(), inputFileName, xmlParser ); + //generate( *xmlOutFile, hostData.str(), inputFileName, xmlParser ); /* Close the input and the intermediate file. */ delete xmlOutFile; diff --git a/ragel/parsedata.cpp b/ragel/parsedata.cpp index 8a37481..27badee 100644 --- a/ragel/parsedata.cpp +++ b/ragel/parsedata.cpp @@ -1427,7 +1427,7 @@ void ParseData::prepareMachineGenTBWrapped( GraphDictEl *graphDictEl ) sectionGraph->setStateNumbers( 0 ); } -void ParseData::generateXML( ostream &out, XmlParser &xmlParser ) +void ParseData::generate( ostream &out, XmlParser &xmlParser ) { beginProcessing(); @@ -1457,6 +1457,36 @@ void terminateAllParsers( ) pdel->value->token( loc, Parser_tk_eof, 0, 0 ); } +void writeLanguage( std::ostream &out ) +{ + out << " lang=\""; + switch ( hostLang->lang ) { + case HostLang::C: out << "C"; break; + case HostLang::D: out << "D"; break; + case HostLang::Java: out << "Java"; break; + case HostLang::Ruby: out << "Ruby"; break; + case HostLang::CSharp: out << "C#"; break; + } + out << "\""; +} + +void ParseData::generateXML( ostream &out, XmlParser &xmlParser ) +{ + beginProcessing(); + + /* Make the generator. */ + XMLCodeGen codeGen( sectionName, this, sectionGraph, out, xmlParser ); + + /* Write out with it. */ + codeGen.writeXML(); + + if ( printStatistics ) { + cerr << "fsm name : " << sectionName << endl; + cerr << "num states: " << sectionGraph->stateList.length() << endl; + cerr << endl; + } +} + void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName, XmlParser &xmlParser ) { @@ -1469,13 +1499,16 @@ void writeMachines( std::ostream &out, std::string hostData, } if ( gblErrorCount == 0 ) { - xmlParser.open_ragel( inputFileName ); + out << "\n"; for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) { ParseData *pd = parser->value->pd; if ( pd->instanceList.length() > 0 ) pd->generateXML( out, xmlParser ); } out << hostData; + out << "\n"; } } else if ( parserDict.length() > 0 ) { @@ -1507,9 +1540,70 @@ void writeMachines( std::ostream &out, std::string hostData, /* Section/Machine to emit was found. Prepare and emit it. */ parseData->prepareMachineGen( graphDictEl ); if ( gblErrorCount == 0 ) { - xmlParser.open_ragel( inputFileName ); + out << "\n"; parseData->generateXML( out, xmlParser ); out << hostData; + out << "\n"; + } + } + } +} + +void generate( std::ostream &out, std::string hostData, + const char *inputFileName, XmlParser &xmlParser ) +{ + 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->prepareMachineGen( 0 ); + } + + if ( gblErrorCount == 0 ) { + xmlParser.open_ragel( inputFileName ); + for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) { + ParseData *pd = parser->value->pd; + if ( pd->instanceList.length() > 0 ) + pd->generate( out, xmlParser ); + } + out << hostData; + } + } + else if ( parserDict.length() > 0 ) { + /* There is either a machine spec or machine name given. */ + ParseData *parseData = 0; + GraphDictEl *graphDictEl = 0; + + /* Traverse the sections, break out when we find a section/machine + * that matches the one specified. */ + for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) { + ParseData *checkPd = parser->value->pd; + if ( machineSpec == 0 || strcmp( checkPd->sectionName, machineSpec ) == 0 ) { + GraphDictEl *checkGdEl = 0; + if ( machineName == 0 || (checkGdEl = + checkPd->graphDict.find( machineName )) != 0 ) + { + /* Have a machine spec and/or machine name that matches + * the -M/-S options. */ + parseData = checkPd; + graphDictEl = checkGdEl; + break; + } + } + } + + if ( parseData == 0 ) + error() << "could not locate machine specified with -S and/or -M" << endl; + else { + /* Section/Machine to emit was found. Prepare and emit it. */ + parseData->prepareMachineGen( graphDictEl ); + if ( gblErrorCount == 0 ) { + xmlParser.open_ragel( inputFileName ); + parseData->generate( out, xmlParser ); + out << hostData; } } } diff --git a/ragel/parsedata.h b/ragel/parsedata.h index bea22f0..605264b 100644 --- a/ragel/parsedata.h +++ b/ragel/parsedata.h @@ -216,6 +216,7 @@ struct ParseData void prepareMachineGen( GraphDictEl *graphDictEl ); void prepareMachineGenTBWrapped( GraphDictEl *graphDictEl ); void generateXML( ostream &out, XmlParser &xmlParser ); + void generate( ostream &out, XmlParser &xmlParser ); FsmAp *sectionGraph; bool generatingSectionSubset; diff --git a/ragel/ragel.h b/ragel/ragel.h index 715e69a..54a93b2 100644 --- a/ragel/ragel.h +++ b/ragel/ragel.h @@ -85,6 +85,8 @@ struct XmlParser; void terminateAllParsers( ); void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName, XmlParser &xmlParser ); +void generate( std::ostream &out, std::string hostData, + const char *inputFileName, XmlParser &xmlParser ); void xmlEscapeHost( std::ostream &out, char *data, long len ); typedef Vector ArgsVector;