Verified Commit 4866bb59 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

macro processor: use C++17 structured bindings in for loops

parent 217dadab
......@@ -244,10 +244,10 @@ For::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &pa
void
If::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
{
for (auto & it : expr_and_body)
for (const auto & [expr, body] : expr_and_body)
try
{
auto tmp = it.first->eval();
auto tmp = expr->eval();
RealPtr dp = dynamic_pointer_cast<Real>(tmp);
BoolPtr bp = dynamic_pointer_cast<Bool>(tmp);
if (!bp && !dp)
......@@ -255,7 +255,7 @@ If::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &pat
"The condition must evaluate to a boolean or a double", location));
if ((bp && *bp) || (dp && *dp))
{
interpretBody(it.second, output, no_line_macro, paths);
interpretBody(body, output, no_line_macro, paths);
break;
}
}
......@@ -289,12 +289,12 @@ If::interpretBody(const vector<DirectivePtr> &body, ostream &output, bool no_lin
void
Ifdef::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
{
for (auto & it : expr_and_body)
if (VariablePtr vp = dynamic_pointer_cast<Variable>(it.first);
dynamic_pointer_cast<BaseType>(it.first)
for (const auto & [expr, body] : expr_and_body)
if (VariablePtr vp = dynamic_pointer_cast<Variable>(expr);
dynamic_pointer_cast<BaseType>(expr)
|| (vp && env.isVariableDefined(vp->getName())))
{
interpretBody(it.second, output, no_line_macro, paths);
interpretBody(body, output, no_line_macro, paths);
break;
}
printEndLineInfo(output, no_line_macro);
......@@ -303,12 +303,12 @@ Ifdef::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &
void
Ifndef::interpret(ostream &output, bool no_line_macro, vector<filesystem::path> &paths)
{
for (auto & it : expr_and_body)
if (VariablePtr vp = dynamic_pointer_cast<Variable>(it.first);
!(dynamic_pointer_cast<BaseType>(it.first)
for (const auto & [expr, body] : expr_and_body)
if (VariablePtr vp = dynamic_pointer_cast<Variable>(expr);
!(dynamic_pointer_cast<BaseType>(expr)
|| (vp && env.isVariableDefined(vp->getName()))))
{
interpretBody(it.second, output, no_line_macro, paths);
interpretBody(body, output, no_line_macro, paths);
break;
}
printEndLineInfo(output, no_line_macro);
......
......@@ -32,19 +32,19 @@ Driver::parse(const string &file_arg, const string &basename_arg, istream &modfi
if (!defines.empty())
{
stringstream command_line_defines_with_endl;
for (auto & define : defines)
for (const auto & [var, val] : defines)
try
{
stoi(define.second);
command_line_defines_with_endl << "@#define " << define.first << " = " << define.second << endl;
stoi(val);
command_line_defines_with_endl << "@#define " << var << " = " << val << endl;
}
catch (const invalid_argument &)
{
if (!define.second.empty() && define.second.at(0) == '[' && define.second.at(define.second.length()-1) == ']')
if (!val.empty() && val.at(0) == '[' && val.at(val.length()-1) == ']')
// If the input is an array. Issue #1578
command_line_defines_with_endl << "@#define " << define.first << " = " << define.second << endl;
command_line_defines_with_endl << "@#define " << var << " = " << val << endl;
else
command_line_defines_with_endl << "@#define " << define.first << " = \"" << define.second << "\"" << endl;
command_line_defines_with_endl << "@#define " << var << " = \"" << val << "\"" << endl;
}
Driver m(env, true);
istream is(command_line_defines_with_endl.rdbuf());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment