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
issue#70
sebastien 2009-01-21 13:45:44 +00:00
parent b5f2d0d763
commit 0fabc27aed
5 changed files with 25 additions and 12 deletions

View File

@ -37,7 +37,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool
void void
usage() 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); exit(EXIT_FAILURE);
} }
@ -56,6 +56,7 @@ main(int argc, char** argv)
bool debug = false; bool debug = false;
bool no_tmp_terms = false; bool no_tmp_terms = false;
bool only_macro = false; bool only_macro = false;
bool no_line_macro = false;
// Parse options // Parse options
for (int arg = 2; arg < argc; arg++) for (int arg = 2; arg < argc; arg++)
@ -79,6 +80,8 @@ main(int argc, char** argv)
save_macro_file = string(argv[arg] + 10); save_macro_file = string(argv[arg] + 10);
} }
} }
else if (!strcmp(argv[arg], "nolinemacro"))
no_line_macro = true;
else if (!strcmp(argv[arg], "notmpterms")) else if (!strcmp(argv[arg], "notmpterms"))
no_tmp_terms = true; no_tmp_terms = true;
else else
@ -101,7 +104,7 @@ main(int argc, char** argv)
MacroDriver m; MacroDriver m;
stringstream macro_output; 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)
{ {
if (save_macro_file.empty()) if (save_macro_file.empty())

View File

@ -40,8 +40,6 @@ class MacroDriver;
{ {
// Initialize the location filenames // Initialize the location filenames
@$.begin.filename = @$.end.filename = &driver.file; @$.begin.filename = @$.end.filename = &driver.file;
// Output first @#line statement
out << "@#line \"" << driver.file << "\" 1" << endl;
}; };
%debug %debug

View File

@ -35,7 +35,7 @@ MacroDriver::~MacroDriver()
} }
void 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; file = f;
@ -46,11 +46,17 @@ MacroDriver::parse(const string &f, ostream &out, bool debug)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
lexer = new MacroFlex(&in, &out); lexer = new MacroFlex(&in, &out, no_line_macro);
lexer->set_debug(debug); lexer->set_debug(debug);
Macro::parser parser(*this, out); Macro::parser parser(*this, out);
parser.set_debug_level(debug); parser.set_debug_level(debug);
// Output first @#line statement
if (!no_line_macro)
out << "@#line \"" << file << "\" 1" << endl;
// Launch macro-processing
parser.parse(); parser.parse();
delete lexer; delete lexer;

View File

@ -72,6 +72,9 @@ private:
/*! Kept for deletion at end of current scanning buffer */ /*! Kept for deletion at end of current scanning buffer */
istream *input; 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. //! If current context is the body of a loop, contains the string of the loop body. Empty otherwise.
string for_body; string for_body;
//! If current context is the body of a loop, contains the location of the beginning of the 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 */ and initialise a new scanning context with the loop body */
bool iter_loop(MacroDriver &driver, Macro::parser::location_type *yylloc); bool iter_loop(MacroDriver &driver, Macro::parser::location_type *yylloc);
public: public:
MacroFlex(istream* in = 0, ostream* out = 0); MacroFlex(istream* in, ostream* out, bool no_line_macro_arg);
//! The main lexing function //! The main lexing function
Macro::parser::token_type lex(Macro::parser::semantic_type *yylval, Macro::parser::token_type lex(Macro::parser::semantic_type *yylval,
@ -166,7 +169,8 @@ public:
virtual ~MacroDriver(); virtual ~MacroDriver();
//! Starts parsing a file, returns output in out //! 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 //! Name of main file being parsed
string file; string file;

View File

@ -311,16 +311,18 @@ CONT \\\\
<*>. { driver.error(*yylloc, "Macro lexer error: '" + string(yytext) + "'"); } <*>. { driver.error(*yylloc, "Macro lexer error: '" + string(yytext) + "'"); }
%% %%
MacroFlex::MacroFlex(istream* in, ostream* out) MacroFlex::MacroFlex(istream* in, ostream* out, bool no_line_macro_arg)
: MacroFlexLexer(in, out), input(in), reading_for_statement(false), reading_if_statement(false) : MacroFlexLexer(in, out), input(in), no_line_macro(no_line_macro_arg),
reading_for_statement(false), reading_if_statement(false)
{ {
} }
void void
MacroFlex::output_line(Macro::parser::location_type *yylloc) const MacroFlex::output_line(Macro::parser::location_type *yylloc) const
{ {
*yyout << endl << "@#line \"" << *yylloc->begin.filename << "\" " if (!no_line_macro)
<< yylloc->begin.line << endl; *yyout << endl << "@#line \"" << *yylloc->begin.filename << "\" "
<< yylloc->begin.line << endl;
} }
void void