From 0fabc27aed6223eb76006dda94afb47ea69ebe14 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 21 Jan 2009 13:45:44 +0000 Subject: [PATCH] trunk preprocessor: added option to remove @#line statements in output of macro-processor git-svn-id: https://www.dynare.org/svn/dynare/trunk@2361 ac1d8469-bf42-47a9-8791-bf33cf982152 --- DynareMain.cc | 7 +++++-- macro/MacroBison.yy | 2 -- macro/MacroDriver.cc | 10 ++++++++-- macro/MacroDriver.hh | 8 ++++++-- macro/MacroFlex.ll | 10 ++++++---- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/DynareMain.cc b/DynareMain.cc index 574c4964..bb42e8d7 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -37,7 +37,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool void usage() { - cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [notmpterms]" << endl; + cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms]" << endl; exit(EXIT_FAILURE); } @@ -56,6 +56,7 @@ main(int argc, char** argv) bool debug = false; bool no_tmp_terms = false; bool only_macro = false; + bool no_line_macro = false; // Parse options for (int arg = 2; arg < argc; arg++) @@ -79,6 +80,8 @@ main(int argc, char** argv) save_macro_file = string(argv[arg] + 10); } } + else if (!strcmp(argv[arg], "nolinemacro")) + no_line_macro = true; else if (!strcmp(argv[arg], "notmpterms")) no_tmp_terms = true; else @@ -101,7 +104,7 @@ main(int argc, char** argv) MacroDriver m; stringstream macro_output; - m.parse(argv[1], macro_output, debug); + m.parse(argv[1], macro_output, debug, no_line_macro); if (save_macro) { if (save_macro_file.empty()) diff --git a/macro/MacroBison.yy b/macro/MacroBison.yy index 8caa736c..a045ff44 100644 --- a/macro/MacroBison.yy +++ b/macro/MacroBison.yy @@ -40,8 +40,6 @@ class MacroDriver; { // Initialize the location filenames @$.begin.filename = @$.end.filename = &driver.file; - // Output first @#line statement - out << "@#line \"" << driver.file << "\" 1" << endl; }; %debug diff --git a/macro/MacroDriver.cc b/macro/MacroDriver.cc index b8d6f9d4..da1654b7 100644 --- a/macro/MacroDriver.cc +++ b/macro/MacroDriver.cc @@ -35,7 +35,7 @@ MacroDriver::~MacroDriver() } void -MacroDriver::parse(const string &f, ostream &out, bool debug) +MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro) { file = f; @@ -46,11 +46,17 @@ MacroDriver::parse(const string &f, ostream &out, bool debug) exit(EXIT_FAILURE); } - lexer = new MacroFlex(&in, &out); + lexer = new MacroFlex(&in, &out, no_line_macro); lexer->set_debug(debug); Macro::parser parser(*this, out); parser.set_debug_level(debug); + + // Output first @#line statement + if (!no_line_macro) + out << "@#line \"" << file << "\" 1" << endl; + + // Launch macro-processing parser.parse(); delete lexer; diff --git a/macro/MacroDriver.hh b/macro/MacroDriver.hh index 1b95a9f3..eb547360 100644 --- a/macro/MacroDriver.hh +++ b/macro/MacroDriver.hh @@ -72,6 +72,9 @@ private: /*! Kept for deletion at end of current scanning buffer */ istream *input; + //! Should we omit the @#line statements ? + const bool no_line_macro; + //! If current context is the body of a loop, contains the string of the loop body. Empty otherwise. string for_body; //! If current context is the body of a loop, contains the location of the beginning of the body @@ -129,7 +132,7 @@ private: and initialise a new scanning context with the loop body */ bool iter_loop(MacroDriver &driver, Macro::parser::location_type *yylloc); public: - MacroFlex(istream* in = 0, ostream* out = 0); + MacroFlex(istream* in, ostream* out, bool no_line_macro_arg); //! The main lexing function Macro::parser::token_type lex(Macro::parser::semantic_type *yylval, @@ -166,7 +169,8 @@ public: virtual ~MacroDriver(); //! Starts parsing a file, returns output in out - void parse(const string &f, ostream &out, bool debug); + /*! \param no_line_macro should we omit the @#line statements ? */ + void parse(const string &f, ostream &out, bool debug, bool no_line_macro); //! Name of main file being parsed string file; diff --git a/macro/MacroFlex.ll b/macro/MacroFlex.ll index 291d30df..2ac103c8 100644 --- a/macro/MacroFlex.ll +++ b/macro/MacroFlex.ll @@ -311,16 +311,18 @@ CONT \\\\ <*>. { driver.error(*yylloc, "Macro lexer error: '" + string(yytext) + "'"); } %% -MacroFlex::MacroFlex(istream* in, ostream* out) - : MacroFlexLexer(in, out), input(in), reading_for_statement(false), reading_if_statement(false) +MacroFlex::MacroFlex(istream* in, ostream* out, bool no_line_macro_arg) + : MacroFlexLexer(in, out), input(in), no_line_macro(no_line_macro_arg), + reading_for_statement(false), reading_if_statement(false) { } void MacroFlex::output_line(Macro::parser::location_type *yylloc) const { - *yyout << endl << "@#line \"" << *yylloc->begin.filename << "\" " - << yylloc->begin.line << endl; + if (!no_line_macro) + *yyout << endl << "@#line \"" << *yylloc->begin.filename << "\" " + << yylloc->begin.line << endl; } void