maintain order of macro variables defined on command line when writing them to the .mod file

Before this commit, a dynare call such as
```
dynare <<mod file>> -Db=“A” -Da=@{b}
```
would not expand the value of `b` in `a` whereas
```
dynare <<mod file>> -Da=“A” -Db=@{a}
```
would expand the value of `a` into `b` because the arguments were stored in a map which printed the `@#define` statements in the .mod file in alphabetic order.
issue#70
Houtan Bastani 2019-04-10 12:51:13 +02:00
parent 4d287a94f2
commit 2a9c4b234a
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
4 changed files with 9 additions and 9 deletions

View File

@ -53,7 +53,7 @@ void main2(stringstream &in, const string &basename, bool debug, bool clear_all,
const boost::filesystem::path &dynareroot, bool onlymodel); const boost::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 map<string, string> &defines, const vector<string> &path, stringstream &macro_output); bool no_line_macro, bool no_empty_line_macro, const vector<pair<string, string>> &defines, const vector<string> &path, stringstream &macro_output);
void void
usage() usage()
@ -151,7 +151,7 @@ main(int argc, char **argv)
bool minimal_workspace = false; bool minimal_workspace = false;
bool compute_xrefs = false; bool compute_xrefs = false;
bool transform_unary_ops = false; bool transform_unary_ops = false;
map<string, string> defines; vector<pair<string, string>> defines;
vector<string> path; vector<string> path;
FileOutputType output_mode{FileOutputType::none}; FileOutputType output_mode{FileOutputType::none};
JsonOutputPointType json{JsonOutputPointType::nojson}; JsonOutputPointType json{JsonOutputPointType::nojson};
@ -269,9 +269,9 @@ main(int argc, char **argv)
auto equal_index = s.find('='); auto equal_index = s.find('=');
if (equal_index != string::npos) if (equal_index != string::npos)
defines[s.substr(2, equal_index-2)] = s.substr(equal_index+1); defines.emplace_back(s.substr(2, equal_index-2), s.substr(equal_index+1));
else else
defines[s.substr(2)] = "1"; defines.emplace_back(s.substr(2), "1");
} }
else if (s.substr(0, 2) == "-I") else if (s.substr(0, 2) == "-I")
{ {

View File

@ -28,7 +28,7 @@ bool compareNewline (int i, int j) {
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, bool no_empty_line_macro, const map<string, string> &defines, const vector<string> &path, stringstream &macro_output) bool no_line_macro, bool no_empty_line_macro, const vector<pair<string, string>> &defines, const vector<string> &path, stringstream &macro_output)
{ {
// Do macro processing // Do macro processing
MacroDriver m; MacroDriver m;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008-2018 Dynare Team * Copyright (C) 2008-2019 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -28,7 +28,7 @@
void void
MacroDriver::parse(const string &file_arg, const string &basename_arg, istream &modfile, MacroDriver::parse(const string &file_arg, const string &basename_arg, istream &modfile,
ostream &out, bool debug, bool no_line_macro_arg, map<string, string> defines, ostream &out, bool debug, bool no_line_macro_arg, const vector<pair<string, string>> &defines,
vector<string> path) vector<string> path)
{ {
file = file_arg; file = file_arg;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008-2018 Dynare Team * Copyright (C) 2008-2019 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -227,7 +227,7 @@ public:
//! Starts parsing a file, returns output in out //! Starts parsing a file, returns output in out
/*! \param no_line_macro should we omit the @#line statements ? */ /*! \param no_line_macro should we omit the @#line statements ? */
void parse(const string &file_arg, const string &basename_arg, istream &modfile, ostream &out, bool debug, bool no_line_macro_arg, void parse(const string &file_arg, const string &basename_arg, istream &modfile, ostream &out, bool debug, bool no_line_macro_arg,
map<string, string> defines, vector<string> path); const vector<pair<string, string>> &defines, vector<string> path);
//! Name of main file being parsed //! Name of main file being parsed
string file; string file;