diff options
author | Adrian Thurston <thurston@colm.net> | 2021-11-07 14:27:00 -0800 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2021-11-07 14:27:00 -0800 |
commit | 8f4f87b3aa48cccfc7f7c9badf0f6dbef7c8f3df (patch) | |
tree | cc4b1c40e4d88bb453aa8e8a9adf375662ed568d /src/inputdata.cc | |
parent | b798427d8b569b1e6bf5fa433ed1f1a14593a0c7 (diff) | |
download | ragel-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.
Diffstat (limited to 'src/inputdata.cc')
-rw-r--r-- | src/inputdata.cc | 87 |
1 files changed, 86 insertions, 1 deletions
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; } |