Remove options `noemptylinemacro` and `nolinemacro`; add option `linemacro`
This only concerns the situation when `savemacro` is also passed. When `linemacro` is passed, the macro expanded .mod file is the same as before When `linemacro` is not passed, the macro expanded .mod file is equivalent to what it was before when both `noemptylinemacro` and `nolinemacro` were passed. closes #44 closes #45issue#70
parent
c4a9f93d40
commit
1dbbd87d3d
|
@ -52,13 +52,12 @@ void main2(stringstream &in, const string &basename, bool debug, bool clear_all,
|
||||||
const filesystem::path &dynareroot, bool onlymodel);
|
const filesystem::path &dynareroot, bool onlymodel);
|
||||||
|
|
||||||
void main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file,
|
void main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file,
|
||||||
bool no_line_macro, bool no_empty_line_macro, const vector<pair<string, string>> &defines,
|
bool line_macro, const vector<pair<string, string>> &defines, vector<filesystem::path> &paths, stringstream ¯o_output);
|
||||||
vector<filesystem::path> &paths, stringstream ¯o_output);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [noemptylinemacro] [notmpterms] [nolog] [warn_uninit]"
|
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [linemacro] [notmpterms] [nolog] [warn_uninit]"
|
||||||
<< " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
|
<< " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
|
||||||
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=matlab|julia]"
|
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=matlab|julia]"
|
||||||
<< " [params_derivs_order=0|1|2] [transform_unary_ops] [exclude_eqs=<equation_tag_list_or_file>] [include_eqs=<equation_tag_list_or_file>]"
|
<< " [params_derivs_order=0|1|2] [transform_unary_ops] [exclude_eqs=<equation_tag_list_or_file>] [include_eqs=<equation_tag_list_or_file>]"
|
||||||
|
@ -136,8 +135,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;
|
bool line_macro = false;
|
||||||
bool no_empty_line_macro = false;
|
|
||||||
bool no_log = false;
|
bool no_log = false;
|
||||||
bool no_warn = false;
|
bool no_warn = false;
|
||||||
int params_derivs_order = 2;
|
int params_derivs_order = 2;
|
||||||
|
@ -208,10 +206,8 @@ main(int argc, char **argv)
|
||||||
save_macro_file = s.substr(10);
|
save_macro_file = s.substr(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (s == "nolinemacro")
|
else if (s == "linemacro")
|
||||||
no_line_macro = true;
|
line_macro = true;
|
||||||
else if (s == "noemptylinemacro")
|
|
||||||
no_empty_line_macro = true;
|
|
||||||
else if (s == "notmpterms")
|
else if (s == "notmpterms")
|
||||||
no_tmp_terms = true;
|
no_tmp_terms = true;
|
||||||
else if (s == "nolog")
|
else if (s == "nolog")
|
||||||
|
@ -433,7 +429,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
// Do macro processing
|
// Do macro processing
|
||||||
stringstream macro_output;
|
stringstream macro_output;
|
||||||
main1(filename, basename, modfile, debug, save_macro, save_macro_file, no_line_macro, no_empty_line_macro,
|
main1(filename, basename, modfile, debug, save_macro, save_macro_file, line_macro,
|
||||||
defines, paths, macro_output);
|
defines, paths, macro_output);
|
||||||
|
|
||||||
if (only_macro)
|
if (only_macro)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2015-2019 Dynare Team
|
* Copyright © 2015-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -21,17 +21,17 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include "macro/Driver.hh"
|
#include "macro/Driver.hh"
|
||||||
|
|
||||||
void
|
void
|
||||||
main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file,
|
main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file,
|
||||||
bool no_line_macro_arg, bool no_empty_line_macro, const vector<pair<string, string>> &defines,
|
bool line_macro, const vector<pair<string, string>> &defines, vector<filesystem::path> &paths, stringstream ¯o_output)
|
||||||
vector<filesystem::path> &paths, stringstream ¯o_output)
|
|
||||||
{
|
{
|
||||||
// Do macro processing
|
// Do macro processing
|
||||||
macro::Environment env = macro::Environment();
|
macro::Environment env = macro::Environment();
|
||||||
macro::Driver m(env, no_line_macro_arg);
|
macro::Driver m(env);
|
||||||
m.parse(filename, basename, modfile, macro_output, debug, defines, paths);
|
m.parse(filename, basename, modfile, macro_output, debug, defines, paths);
|
||||||
if (save_macro)
|
if (save_macro)
|
||||||
{
|
{
|
||||||
|
@ -45,8 +45,9 @@ main1(const string &filename, const string &basename, istream &modfile, bool deb
|
||||||
}
|
}
|
||||||
|
|
||||||
string str(macro_output.str());
|
string str(macro_output.str());
|
||||||
if (no_empty_line_macro)
|
if (!line_macro)
|
||||||
{
|
{
|
||||||
|
str = regex_replace(str, regex(R"((^|\n)\s*@#line.*)"), "");
|
||||||
auto compareNewline = [](char i, char j) { return i == '\n' && j == '\n'; };
|
auto compareNewline = [](char i, char j) { return i == '\n' && j == '\n'; };
|
||||||
str.erase(0, str.find_first_not_of('\n'));
|
str.erase(0, str.find_first_not_of('\n'));
|
||||||
str.erase(unique(str.begin(), str.end(), compareNewline), str.end());
|
str.erase(unique(str.begin(), str.end(), compareNewline), str.end());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2019 Dynare Team
|
* Copyright © 2019-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
using namespace macro;
|
using namespace macro;
|
||||||
|
|
||||||
void
|
void
|
||||||
Eval::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
Eval::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ Eval::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &p
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Include::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
Include::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
using namespace filesystem;
|
using namespace filesystem;
|
||||||
try
|
try
|
||||||
|
@ -71,7 +71,7 @@ Include::interpret(ostream &output, bool no_line_macro, vector<filesystem::path>
|
||||||
+". The following directories were searched:\n" + errmsg.str(), location));
|
+". The following directories were searched:\n" + errmsg.str(), location));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Driver m(env, no_line_macro);
|
Driver m(env);
|
||||||
// Calling `string()` method on filename and filename.stem() because of bug in
|
// Calling `string()` method on filename and filename.stem() because of bug in
|
||||||
// MinGW 8.3.0 that ignores implicit conversion to string from filename::path.
|
// MinGW 8.3.0 that ignores implicit conversion to string from filename::path.
|
||||||
// Test if bug exists when version of MinGW is upgraded on Debian runners
|
// Test if bug exists when version of MinGW is upgraded on Debian runners
|
||||||
|
@ -86,11 +86,11 @@ Include::interpret(ostream &output, bool no_line_macro, vector<filesystem::path>
|
||||||
{
|
{
|
||||||
error(StackTrace("@#include", e.what(), location));
|
error(StackTrace("@#include", e.what(), location));
|
||||||
}
|
}
|
||||||
printLineInfo(output, no_line_macro);
|
printLineInfo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
IncludePath::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
IncludePath::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
using namespace filesystem;
|
using namespace filesystem;
|
||||||
try
|
try
|
||||||
|
@ -117,7 +117,7 @@ IncludePath::interpret(ostream &output, bool no_line_macro, vector<filesystem::p
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Define::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
Define::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -140,7 +140,7 @@ Define::interpret(ostream &output, bool no_line_macro, vector<filesystem::path>
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Echo::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
Echo::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -155,11 +155,11 @@ Echo::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &p
|
||||||
{
|
{
|
||||||
error(StackTrace("@#echo", e.what(), location));
|
error(StackTrace("@#echo", e.what(), location));
|
||||||
}
|
}
|
||||||
printEndLineInfo(output, no_line_macro);
|
printEndLineInfo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Error::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
Error::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -177,17 +177,17 @@ Error::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EchoMacroVars::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
EchoMacroVars::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
if (save)
|
if (save)
|
||||||
env.print(output, vars, location.begin.line, true);
|
env.print(output, vars, location.begin.line, true);
|
||||||
else
|
else
|
||||||
env.print(cout, vars);
|
env.print(cout, vars);
|
||||||
printEndLineInfo(output, no_line_macro);
|
printEndLineInfo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
For::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
For::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
ArrayPtr ap;
|
ArrayPtr ap;
|
||||||
try
|
try
|
||||||
|
@ -233,17 +233,17 @@ For::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &pa
|
||||||
{
|
{
|
||||||
if (printLine)
|
if (printLine)
|
||||||
{
|
{
|
||||||
statement->printLineInfo(output, no_line_macro);
|
statement->printLineInfo(output);
|
||||||
printLine = false;
|
printLine = false;
|
||||||
}
|
}
|
||||||
statement->interpret(output, no_line_macro, paths);
|
statement->interpret(output, paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printEndLineInfo(output, no_line_macro);
|
printEndLineInfo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
If::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
If::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
for (const auto & [expr, body] : expr_and_body)
|
for (const auto & [expr, body] : expr_and_body)
|
||||||
try
|
try
|
||||||
|
@ -256,7 +256,7 @@ If::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &pat
|
||||||
"The condition must evaluate to a boolean or a double", location));
|
"The condition must evaluate to a boolean or a double", location));
|
||||||
if ((bp && *bp) || (dp && *dp))
|
if ((bp && *bp) || (dp && *dp))
|
||||||
{
|
{
|
||||||
interpretBody(body, output, no_line_macro, paths);
|
interpretBody(body, output, paths);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,48 +269,48 @@ If::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &pat
|
||||||
{
|
{
|
||||||
error(StackTrace("@#if", e.what(), location));
|
error(StackTrace("@#if", e.what(), location));
|
||||||
}
|
}
|
||||||
printEndLineInfo(output, no_line_macro);
|
printEndLineInfo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
If::interpretBody(const vector<DirectivePtr> &body, ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
If::interpretBody(const vector<DirectivePtr> &body, ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
bool printLine = !no_line_macro;
|
bool printLine = true;
|
||||||
for (const auto &statement : body)
|
for (const auto &statement : body)
|
||||||
{
|
{
|
||||||
if (printLine)
|
if (printLine)
|
||||||
{
|
{
|
||||||
statement->printLineInfo(output, no_line_macro);
|
statement->printLineInfo(output);
|
||||||
printLine = false;
|
printLine = false;
|
||||||
}
|
}
|
||||||
statement->interpret(output, no_line_macro, paths);
|
statement->interpret(output, paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Ifdef::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
Ifdef::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
for (const auto & [expr, body] : expr_and_body)
|
for (const auto & [expr, body] : expr_and_body)
|
||||||
if (VariablePtr vp = dynamic_pointer_cast<Variable>(expr);
|
if (VariablePtr vp = dynamic_pointer_cast<Variable>(expr);
|
||||||
dynamic_pointer_cast<BaseType>(expr)
|
dynamic_pointer_cast<BaseType>(expr)
|
||||||
|| (vp && env.isVariableDefined(vp->getName())))
|
|| (vp && env.isVariableDefined(vp->getName())))
|
||||||
{
|
{
|
||||||
interpretBody(body, output, no_line_macro, paths);
|
interpretBody(body, output, paths);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printEndLineInfo(output, no_line_macro);
|
printEndLineInfo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Ifndef::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
|
Ifndef::interpret(ostream &output, vector<filesystem::path> &paths)
|
||||||
{
|
{
|
||||||
for (const auto & [expr, body] : expr_and_body)
|
for (const auto & [expr, body] : expr_and_body)
|
||||||
if (VariablePtr vp = dynamic_pointer_cast<Variable>(expr);
|
if (VariablePtr vp = dynamic_pointer_cast<Variable>(expr);
|
||||||
!(dynamic_pointer_cast<BaseType>(expr)
|
!(dynamic_pointer_cast<BaseType>(expr)
|
||||||
|| (vp && env.isVariableDefined(vp->getName()))))
|
|| (vp && env.isVariableDefined(vp->getName()))))
|
||||||
{
|
{
|
||||||
interpretBody(body, output, no_line_macro, paths);
|
interpretBody(body, output, paths);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printEndLineInfo(output, no_line_macro);
|
printEndLineInfo(output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2019 Dynare Team
|
* Copyright (C) 2019-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -33,7 +33,7 @@ namespace macro
|
||||||
Directive(Environment &env_arg, Tokenizer::location location_arg) :
|
Directive(Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Node(env_arg, move(location_arg)) { }
|
Node(env_arg, move(location_arg)) { }
|
||||||
// Directives can be interpreted
|
// Directives can be interpreted
|
||||||
virtual void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) = 0;
|
virtual void interpret(ostream &output, vector<filesystem::path> &paths) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
TextNode(string text_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
TextNode(string text_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), text{move(text_arg)} { }
|
Directive(env_arg, move(location_arg)), text{move(text_arg)} { }
|
||||||
inline void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override { output << text; }
|
inline void interpret(ostream &output, vector<filesystem::path> &paths) override { output << text; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
Eval(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
Eval(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
Include(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
Include(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
IncludePath(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
IncludePath(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ namespace macro
|
||||||
ExpressionPtr value_arg,
|
ExpressionPtr value_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), func{move(func_arg)}, value{move(value_arg)} { }
|
Directive(env_arg, move(location_arg)), func{move(func_arg)}, value{move(value_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ namespace macro
|
||||||
Echo(ExpressionPtr expr_arg,
|
Echo(ExpressionPtr expr_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ namespace macro
|
||||||
Error(ExpressionPtr expr_arg,
|
Error(ExpressionPtr expr_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ namespace macro
|
||||||
EchoMacroVars(bool save_arg, vector<string> vars_arg,
|
EchoMacroVars(bool save_arg, vector<string> vars_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), save{save_arg}, vars{move(vars_arg)} { }
|
Directive(env_arg, move(location_arg)), save{save_arg}, vars{move(vars_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ namespace macro
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), index_vec{move(index_vec_arg)},
|
Directive(env_arg, move(location_arg)), index_vec{move(index_vec_arg)},
|
||||||
index_vals{move(index_vals_arg)}, statements{move(statements_arg)} { }
|
index_vals{move(index_vals_arg)}, statements{move(statements_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,9 +179,10 @@ namespace macro
|
||||||
If(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
If(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
Directive(env_arg, move(location_arg)), expr_and_body{move(expr_and_body_arg)} { }
|
Directive(env_arg, move(location_arg)), expr_and_body{move(expr_and_body_arg)} { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
protected:
|
protected:
|
||||||
void interpretBody(const vector<DirectivePtr> &body, ostream &output, bool no_line_macro, vector<filesystem::path> &paths);
|
void interpretBody(const vector<DirectivePtr> &body, ostream &output,
|
||||||
|
vector<filesystem::path> &paths);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -191,7 +192,7 @@ namespace macro
|
||||||
Ifdef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
Ifdef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
If(move(expr_and_body_arg), env_arg, move(location_arg)) { }
|
If(move(expr_and_body_arg), env_arg, move(location_arg)) { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -201,7 +202,7 @@ namespace macro
|
||||||
Ifndef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
Ifndef(vector<pair<ExpressionPtr, vector<DirectivePtr>>> expr_and_body_arg,
|
||||||
Environment &env_arg, Tokenizer::location location_arg) :
|
Environment &env_arg, Tokenizer::location location_arg) :
|
||||||
If(move(expr_and_body_arg), env_arg, move(location_arg)) { }
|
If(move(expr_and_body_arg), env_arg, move(location_arg)) { }
|
||||||
void interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths) override;
|
void interpret(ostream &output, vector<filesystem::path> &paths) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,7 +35,7 @@ Driver::parse(const string &file_arg, const string &basename_arg, istream &modfi
|
||||||
stringstream command_line_defines_with_endl;
|
stringstream command_line_defines_with_endl;
|
||||||
for (const auto & [var, val] : defines)
|
for (const auto & [var, val] : defines)
|
||||||
command_line_defines_with_endl << "@#define " << var << " = " << val << endl;
|
command_line_defines_with_endl << "@#define " << var << " = " << val << endl;
|
||||||
Driver m(env, true);
|
Driver m(env);
|
||||||
istream is(command_line_defines_with_endl.rdbuf());
|
istream is(command_line_defines_with_endl.rdbuf());
|
||||||
m.parse("command_line_defines", "command_line_defines", is, output, debug, {}, paths);
|
m.parse("command_line_defines", "command_line_defines", is, output, debug, {}, paths);
|
||||||
}
|
}
|
||||||
|
@ -62,10 +62,10 @@ Driver::parse(const string &file_arg, const string &basename_arg, istream &modfi
|
||||||
{
|
{
|
||||||
if (printLine)
|
if (printLine)
|
||||||
{
|
{
|
||||||
statement->printLineInfo(output, no_line_macro);
|
statement->printLineInfo(output);
|
||||||
printLine = false;
|
printLine = false;
|
||||||
}
|
}
|
||||||
statement->interpret(output, no_line_macro, paths);
|
statement->interpret(output, paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2019 Dynare Team
|
* Copyright © 2019-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -64,12 +64,11 @@ namespace macro
|
||||||
public:
|
public:
|
||||||
Environment &env;
|
Environment &env;
|
||||||
private:
|
private:
|
||||||
bool no_line_macro;
|
|
||||||
vector<DirectivePtr> statements;
|
vector<DirectivePtr> statements;
|
||||||
stack<vector<DirectivePtr>> directive_stack;
|
stack<vector<DirectivePtr>> directive_stack;
|
||||||
public:
|
public:
|
||||||
Driver(Environment &env_arg, bool no_line_macro_arg) :
|
Driver(Environment &env_arg) :
|
||||||
env{env_arg}, no_line_macro(no_line_macro_arg) { }
|
env{env_arg} { }
|
||||||
Driver(const Driver &) = delete;
|
Driver(const Driver &) = delete;
|
||||||
Driver(Driver &&) = delete;
|
Driver(Driver &&) = delete;
|
||||||
Driver &operator=(const Driver &) = delete;
|
Driver &operator=(const Driver &) = delete;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2019 Dynare Team
|
* Copyright © 2019-2020 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -98,14 +98,12 @@ namespace macro
|
||||||
{
|
{
|
||||||
cerr << endl << "Macro-processing warning: backtrace..." << endl << e.trace();
|
cerr << endl << "Macro-processing warning: backtrace..." << endl << e.trace();
|
||||||
}
|
}
|
||||||
inline void printLineInfo(ostream &output, bool no_line_macro) const noexcept
|
inline void printLineInfo(ostream &output) const noexcept
|
||||||
{
|
{
|
||||||
if (!no_line_macro)
|
|
||||||
output << R"(@#line ")" << *(location.begin.filename) << R"(" )" << location.begin.line << endl;
|
output << R"(@#line ")" << *(location.begin.filename) << R"(" )" << location.begin.line << endl;
|
||||||
}
|
}
|
||||||
inline void printEndLineInfo(ostream &output, bool no_line_macro) const noexcept
|
inline void printEndLineInfo(ostream &output) const noexcept
|
||||||
{
|
{
|
||||||
if (!no_line_macro)
|
|
||||||
// Add one to end line because we want to print the line number of the line *following* the end statement
|
// Add one to end line because we want to print the line number of the line *following* the end statement
|
||||||
output << R"(@#line ")" << *(location.begin.filename) << R"(" )" << location.end.line + 1 << endl;
|
output << R"(@#line ")" << *(location.begin.filename) << R"(" )" << location.end.line + 1 << endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue