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-bf33cf982152issue#70
parent
b5f2d0d763
commit
0fabc27aed
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue