summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2021-11-07 14:27:00 -0800
committerAdrian Thurston <thurston@colm.net>2021-11-07 14:27:00 -0800
commit8f4f87b3aa48cccfc7f7c9badf0f6dbef7c8f3df (patch)
treecc4b1c40e4d88bb453aa8e8a9adf375662ed568d
parentb798427d8b569b1e6bf5fa433ed1f1a14593a0c7 (diff)
downloadragel-8f4f87b3aa48cccfc7f7c9badf0f6dbef7c8f3df.tar.gz
moved writeStatement into InputData
This code was present in ragel, but the colm version was used. Deleted the dead code here an moved the real impl into InputData.
-rw-r--r--src/gendata.cc85
-rw-r--r--src/inputdata.cc87
-rw-r--r--src/inputdata.h2
3 files changed, 88 insertions, 86 deletions
diff --git a/src/gendata.cc b/src/gendata.cc
index c44f7049..10420f09 100644
--- a/src/gendata.cc
+++ b/src/gendata.cc
@@ -1646,88 +1646,3 @@ void CodeGenData::collectReferences()
out.rdbuf( filt );
}
}
-
-void CodeGenData::writeStatement( InputLoc &loc, int nargs,
- std::vector<std::string> &args, bool generateDot, const HostLang *hostLang )
-{
- /* Start write generation on a fresh line. */
- out << '\n';
-
- if ( cleared ) {
- red->id->error(loc) << "write statement following a clear is invalid" << std::endl;
- return;
- }
-
- genOutputLineDirective( out );
-
- if ( args[0] == "data" ) {
- for ( int i = 1; i < nargs; i++ ) {
- if ( args[i] == "noerror" )
- noError = true;
- else if ( args[i] == "noprefix" )
- noPrefix = true;
- else if ( args[i] == "nofinal" )
- noFinal = true;
- else
- write_option_error( loc, args[i] );
- }
-
- if ( red->id->printStatistics ) {
- red->id->stats() << "fsm-name\t" << fsmName << std::endl;
- red->id->stats() << "fsm-states\t" << redFsm->stateList.length() << std::endl;
- }
-
- collectReferences();
- writeData();
- statsSummary();
- }
- else if ( args[0] == "init" ) {
- for ( int i = 1; i < nargs; i++ ) {
- if ( args[i] == "nocs" )
- noCS = true;
- else
- write_option_error( loc, args[i] );
- }
- writeInit();
- }
- else if ( args[0] == "exec" ) {
- for ( int i = 1; i < nargs; i++ ) {
- if ( args[i] == "noend" )
- noEnd = true;
- else
- write_option_error( loc, args[i] );
- }
- collectReferences();
- writeExec();
- }
- else if ( args[0] == "exports" ) {
- for ( int i = 1; i < nargs; i++ )
- write_option_error( loc, args[i] );
- writeExports();
- }
- else if ( args[0] == "start" ) {
- for ( int i = 1; i < nargs; i++ )
- write_option_error( loc, args[i] );
- writeStart();
- }
- else if ( args[0] == "first_final" ) {
- for ( int i = 1; i < nargs; i++ )
- write_option_error( loc, args[i] );
- writeFirstFinal();
- }
- else if ( args[0] == "error" ) {
- for ( int i = 1; i < nargs; i++ )
- write_option_error( loc, args[i] );
- writeError();
- }
- else if ( args[0] == "clear" ) {
- for ( int i = 1; i < nargs; i++ )
- write_option_error( loc, args[i] );
- writeClear();
- }
- else {
- /* EMIT An error here. */
- red->id->error(loc) << "unrecognized write command \"" <<
- args[0] << "\"" << std::endl;
- }
-}
diff --git a/src/inputdata.cc b/src/inputdata.cc
index a47b63a3..7805c9c2 100644
--- a/src/inputdata.cc
+++ b/src/inputdata.cc
@@ -219,6 +219,91 @@ void InputData::verifyWritesHaveData()
verifyWriteHasData( ii );
}
+void InputData::writeStatement( CodeGenData *cgd, InputLoc &loc, int nargs,
+ std::vector<std::string> &args, bool generateDot, const HostLang *hostLang )
+{
+ /* Start write generation on a fresh line. */
+ *outStream << '\n';
+
+ if ( cgd->cleared ) {
+ cgd->red->id->error(loc) << "write statement following a clear is invalid" << std::endl;
+ return;
+ }
+
+ cgd->genOutputLineDirective( *outStream );
+
+ if ( args[0] == "data" ) {
+ for ( int i = 1; i < nargs; i++ ) {
+ if ( args[i] == "noerror" )
+ cgd->noError = true;
+ else if ( args[i] == "noprefix" )
+ cgd->noPrefix = true;
+ else if ( args[i] == "nofinal" )
+ cgd->noFinal = true;
+ else
+ cgd->write_option_error( loc, args[i] );
+ }
+
+ if ( cgd->red->id->printStatistics ) {
+ cgd->red->id->stats() << "fsm-name\t" << cgd->fsmName << std::endl;
+ cgd->red->id->stats() << "fsm-states\t" << cgd->redFsm->stateList.length() << std::endl;
+ }
+
+ cgd->collectReferences();
+ cgd->writeData();
+ cgd->statsSummary();
+ }
+ else if ( args[0] == "init" ) {
+ for ( int i = 1; i < nargs; i++ ) {
+ if ( args[i] == "nocs" )
+ cgd->noCS = true;
+ else
+ cgd->write_option_error( loc, args[i] );
+ }
+ cgd->writeInit();
+ }
+ else if ( args[0] == "exec" ) {
+ for ( int i = 1; i < nargs; i++ ) {
+ if ( args[i] == "noend" )
+ cgd->noEnd = true;
+ else
+ cgd->write_option_error( loc, args[i] );
+ }
+ cgd->collectReferences();
+ cgd->writeExec();
+ }
+ else if ( args[0] == "exports" ) {
+ for ( int i = 1; i < nargs; i++ )
+ cgd->write_option_error( loc, args[i] );
+ cgd->writeExports();
+ }
+ else if ( args[0] == "start" ) {
+ for ( int i = 1; i < nargs; i++ )
+ cgd->write_option_error( loc, args[i] );
+ cgd->writeStart();
+ }
+ else if ( args[0] == "first_final" ) {
+ for ( int i = 1; i < nargs; i++ )
+ cgd->write_option_error( loc, args[i] );
+ cgd->writeFirstFinal();
+ }
+ else if ( args[0] == "error" ) {
+ for ( int i = 1; i < nargs; i++ )
+ cgd->write_option_error( loc, args[i] );
+ cgd->writeError();
+ }
+ else if ( args[0] == "clear" ) {
+ for ( int i = 1; i < nargs; i++ )
+ cgd->write_option_error( loc, args[i] );
+ cgd->writeClear();
+ }
+ else {
+ /* EMIT An error here. */
+ cgd->red->id->error(loc) << "unrecognized write command \"" <<
+ args[0] << "\"" << std::endl;
+ }
+}
+
void InputData::writeOutput( InputItem *ii )
{
/* If it is the first input item then check if we need to write the BOM. */
@@ -228,7 +313,7 @@ void InputData::writeOutput( InputItem *ii )
switch ( ii->type ) {
case InputItem::Write: {
CodeGenData *cgd = ii->pd->cgd;
- cgd->writeStatement( ii->loc, ii->writeArgs.size(),
+ writeStatement( cgd, ii->loc, ii->writeArgs.size(),
ii->writeArgs, generateDot, hostLang );
break;
}
diff --git a/src/inputdata.h b/src/inputdata.h
index 44199ac1..6793acd1 100644
--- a/src/inputdata.h
+++ b/src/inputdata.h
@@ -310,6 +310,8 @@ struct InputData
void makeTranslateOutputFileName();
void flushRemaining();
void makeFirstInputItem();
+ void writeStatement( CodeGenData *cgd, InputLoc &loc, int nargs,
+ std::vector<std::string> &args, bool generateDot, const HostLang *hostLang );
void writeOutput();
void makeDefaultFileName();
void createOutputStream();