Apply modernize-raw-string-literal from clang-tidy

Use ReplaceShorterLiterals option to enforce replacement of all strings.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-raw-string-literal.html
issue#70
Sébastien Villemot 2019-04-03 16:32:52 +02:00
parent 6ba31087ab
commit 8a41a75c85
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
15 changed files with 794 additions and 794 deletions

File diff suppressed because it is too large Load Diff

View File

@ -845,7 +845,7 @@ DataTree::writePowerDeriv(ostream &output) const
string string
DataTree::packageDir(const string &package) DataTree::packageDir(const string &package)
{ {
regex pat{"\\."}; regex pat{R"(\.)"};
string dirname = "+" + regex_replace(package, pat, "/+"); string dirname = "+" + regex_replace(package, pat, "/+");
boost::filesystem::create_directories(dirname); boost::filesystem::create_directories(dirname);
return dirname; return dirname;

View File

@ -974,7 +974,7 @@ DynamicModel::writeModelEquationsCode(const string &basename, const map_idx_t &m
code_file.open(main_name, ios::out | ios::binary | ios::ate); code_file.open(main_name, ios::out | ios::binary | ios::ate);
if (!code_file.is_open()) if (!code_file.is_open())
{ {
cerr << "Error : Can't open file \"" << main_name << "\" for writing" << endl; cerr << R"(Error : Can't open file ")" << main_name << R"(" for writing)" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -1244,7 +1244,7 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id
code_file.open(main_name, ios::out | ios::binary | ios::ate); code_file.open(main_name, ios::out | ios::binary | ios::ate);
if (!code_file.is_open()) if (!code_file.is_open())
{ {
cerr << "Error : Can't open file \"" << main_name << "\" for writing" << endl; cerr << R"(Error : Can't open file ")" << main_name << R"(" for writing)" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
//Temporary variables declaration //Temporary variables declaration
@ -1721,7 +1721,7 @@ DynamicModel::writeDynamicCFile(const string &basename, const int order) const
if (external_functions_table.get_total_number_of_unique_model_block_external_functions()) if (external_functions_table.get_total_number_of_unique_model_block_external_functions())
// External Matlab function, implies Dynamic function will call mex // External Matlab function, implies Dynamic function will call mex
mDynamicModelFile << "#include <uchar.h>" << endl // For MATLAB ≤ R2011a mDynamicModelFile << "#include <uchar.h>" << endl // For MATLAB ≤ R2011a
<< "#include \"mex.h\"" << endl; << R"(#include "mex.h")" << endl;
mDynamicModelFile << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl mDynamicModelFile << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl
<< "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl; << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl;
@ -1758,7 +1758,7 @@ DynamicModel::writeDynamicCFile(const string &basename, const int order) const
<< endl << endl
<< "#include <stdlib.h>" << endl << "#include <stdlib.h>" << endl
<< "#include <uchar.h>" << endl // For MATLAB ≤ R2011a << "#include <uchar.h>" << endl // For MATLAB ≤ R2011a
<< "#include \"mex.h\"" << endl << R"(#include "mex.h")" << endl
<< endl << endl
<< "const int ntt = " << ntt << ";" << endl << "const int ntt = " << ntt << ";" << endl
<< "void dynamic_resid_tt(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, double *T);" << endl << "void dynamic_resid_tt(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, double *T);" << endl
@ -1773,7 +1773,7 @@ DynamicModel::writeDynamicCFile(const string &basename, const int order) const
<< "{" << endl << "{" << endl
<< " /* Check that no derivatives of higher order than computed are being requested */" << endl << " /* Check that no derivatives of higher order than computed are being requested */" << endl
<< " if (nlhs > " << order + 1 << ")" << endl << " if (nlhs > " << order + 1 << ")" << endl
<< " mexErrMsgTxt(\"Derivatives of higher order than computed have been requested\");" << endl << R"( mexErrMsgTxt("Derivatives of higher order than computed have been requested");)" << endl
<< " /* Create a pointer to the input matrix y. */" << endl << " /* Create a pointer to the input matrix y. */" << endl
<< " double *y = mxGetPr(prhs[0]);" << endl << " double *y = mxGetPr(prhs[0]);" << endl
<< endl << endl
@ -1840,16 +1840,16 @@ string
DynamicModel::reform(const string name1) const DynamicModel::reform(const string name1) const
{ {
string name = name1; string name = name1;
int pos = name.find("\\", 0); int pos = name.find(R"(\)", 0);
while (pos >= 0) while (pos >= 0)
{ {
if (name.substr(pos + 1, 1) != "\\") if (name.substr(pos + 1, 1) != R"(\)")
{ {
name = name.insert(pos, "\\"); name = name.insert(pos, R"(\)");
pos++; pos++;
} }
pos++; pos++;
pos = name.find("\\", pos); pos = name.find(R"(\)", pos);
} }
return (name); return (name);
} }
@ -1910,7 +1910,7 @@ DynamicModel::Write_Inf_To_Bin_File_Block(const string &basename, const int &num
SaveCode.open(filename, ios::out | ios::binary); SaveCode.open(filename, ios::out | ios::binary);
if (!SaveCode.is_open()) if (!SaveCode.is_open())
{ {
cerr << "Error : Can't open file \"" << filename << "\" for writing" << endl; cerr << R"(Error : Can't open file ")" << filename << R"(" for writing)" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
u_count_int = 0; u_count_int = 0;
@ -3108,9 +3108,9 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
output << modstruct << "equation_tags = [" << endl; output << modstruct << "equation_tags = [" << endl;
for (const auto & equation_tag : equation_tags) for (const auto & equation_tag : equation_tags)
output << " EquationTag(" output << " EquationTag("
<< equation_tag.first + 1 << " , \"" << equation_tag.first + 1 << R"( , ")"
<< equation_tag.second.first << "\" , \"" << equation_tag.second.first << R"(" , ")"
<< equation_tag.second.second << "\")" << endl; << equation_tag.second.second << R"("))" << endl;
output << " ]" << endl; output << " ]" << endl;
} }
else else
@ -6716,14 +6716,14 @@ void
DynamicModel::writeJsonAST(ostream &output) const DynamicModel::writeJsonAST(ostream &output) const
{ {
vector<pair<string, string>> eqtags; vector<pair<string, string>> eqtags;
output << "\"abstract_syntax_tree\":[" << endl; output << R"("abstract_syntax_tree":[)" << endl;
for (int eq = 0; eq < (int) equations.size(); eq++) for (int eq = 0; eq < (int) equations.size(); eq++)
{ {
if (eq != 0) if (eq != 0)
output << ", "; output << ", ";
output << "{ \"number\":" << eq output << R"({ "number":)" << eq
<< ", \"line\":" << equations_lineno[eq]; << R"(, "line":)" << equations_lineno[eq];
for (const auto & equation_tag : equation_tags) for (const auto & equation_tag : equation_tags)
if (equation_tag.first == eq) if (equation_tag.first == eq)
@ -6731,19 +6731,19 @@ DynamicModel::writeJsonAST(ostream &output) const
if (!eqtags.empty()) if (!eqtags.empty())
{ {
output << ", \"tags\": {"; output << R"(, "tags": {)";
int i = 0; int i = 0;
for (vector<pair<string, string>>::const_iterator it = eqtags.begin(); it != eqtags.end(); it++, i++) for (vector<pair<string, string>>::const_iterator it = eqtags.begin(); it != eqtags.end(); it++, i++)
{ {
if (i != 0) if (i != 0)
output << ", "; output << ", ";
output << "\"" << it->first << "\": \"" << it->second << "\""; output << R"(")" << it->first << R"(": ")" << it->second << R"(")";
} }
output << "}"; output << "}";
eqtags.clear(); eqtags.clear();
} }
output << ", \"AST\": "; output << R"(, "AST": )";
equations[eq]->writeJsonAST(output); equations[eq]->writeJsonAST(output);
output << "}"; output << "}";
} }
@ -6758,9 +6758,9 @@ DynamicModel::writeJsonXrefsHelper(ostream &output, const map<pair<int, int>, se
{ {
if (it != xrefs.begin()) if (it != xrefs.begin())
output << ", "; output << ", ";
output << "{\"name\": \"" << symbol_table.getName(it->first.first) << "\"" output << R"({"name": ")" << symbol_table.getName(it->first.first) << R"(")"
<< ", \"shift\": " << it->first.second << R"(, "shift": )" << it->first.second
<< ", \"equations\": ["; << R"(, "equations": [)";
for (auto it1 = it->second.begin(); for (auto it1 = it->second.begin();
it1 != it->second.end(); it1++) it1 != it->second.end(); it1++)
{ {
@ -6775,17 +6775,17 @@ DynamicModel::writeJsonXrefsHelper(ostream &output, const map<pair<int, int>, se
void void
DynamicModel::writeJsonXrefs(ostream &output) const DynamicModel::writeJsonXrefs(ostream &output) const
{ {
output << "\"xrefs\": {" output << R"("xrefs": {)"
<< "\"parameters\": ["; << R"("parameters": [)";
writeJsonXrefsHelper(output, xref_param); writeJsonXrefsHelper(output, xref_param);
output << "]" output << "]"
<< ", \"endogenous\": ["; << R"(, "endogenous": [)";
writeJsonXrefsHelper(output, xref_endo); writeJsonXrefsHelper(output, xref_endo);
output << "]" output << "]"
<< ", \"exogenous\": ["; << R"(, "exogenous": [)";
writeJsonXrefsHelper(output, xref_exo); writeJsonXrefsHelper(output, xref_exo);
output << "]" output << "]"
<< ", \"exogenous_deterministic\": ["; << R"(, "exogenous_deterministic": [)";
writeJsonXrefsHelper(output, xref_exo_det); writeJsonXrefsHelper(output, xref_exo_det);
output << "]}" << endl; output << "]}" << endl;
} }
@ -6801,8 +6801,8 @@ DynamicModel::writeJsonOriginalModelOutput(ostream &output) const
void void
DynamicModel::writeJsonDynamicModelInfo(ostream &output) const DynamicModel::writeJsonDynamicModelInfo(ostream &output) const
{ {
output << "\"model_info\": {" output << R"("model_info": {)"
<< "\"lead_lag_incidence\": ["; << R"("lead_lag_incidence": [)";
// Loop on endogenous variables // Loop on endogenous variables
int nstatic = 0, int nstatic = 0,
nfwrd = 0, nfwrd = 0,
@ -6858,13 +6858,13 @@ DynamicModel::writeJsonDynamicModelInfo(ostream &output) const
output << "]"; output << "]";
} }
output << "], " output << "], "
<< "\"nstatic\": " << nstatic << ", " << R"("nstatic": )" << nstatic << ", "
<< "\"nfwrd\": " << nfwrd << ", " << R"("nfwrd": )" << nfwrd << ", "
<< "\"npred\": " << npred << ", " << R"("npred": )" << npred << ", "
<< "\"nboth\": " << nboth << ", " << R"("nboth": )" << nboth << ", "
<< "\"nsfwrd\": " << nfwrd+nboth << ", " << R"("nsfwrd": )" << nfwrd+nboth << ", "
<< "\"nspred\": " << npred+nboth << ", " << R"("nspred": )" << npred+nboth << ", "
<< "\"ndynamic\": " << npred+nboth+nfwrd << endl; << R"("ndynamic": )" << npred+nboth+nfwrd << endl;
output << "}"; output << "}";
} }
@ -6896,10 +6896,10 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
temp_term_union.insert(temporary_terms_derivatives[1].begin(), temporary_terms_derivatives[1].end()); temp_term_union.insert(temporary_terms_derivatives[1].begin(), temporary_terms_derivatives[1].end());
concat = "jacobian"; concat = "jacobian";
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, jacobian_output, tef_terms, concat); writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, jacobian_output, tef_terms, concat);
jacobian_output << ", \"jacobian\": {" jacobian_output << R"(, "jacobian": {)"
<< " \"nrows\": " << equations.size() << R"( "nrows": )" << equations.size()
<< ", \"ncols\": " << dynJacobianColsNbr << R"(, "ncols": )" << dynJacobianColsNbr
<< ", \"entries\": ["; << R"(, "entries": [)";
for (auto it = derivatives[1].begin(); for (auto it = derivatives[1].begin();
it != derivatives[1].end(); it++) it != derivatives[1].end(); it++)
{ {
@ -6912,19 +6912,19 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
expr_t d1 = it->second; expr_t d1 = it->second;
if (writeDetails) if (writeDetails)
jacobian_output << "{\"eq\": " << eq + 1; jacobian_output << R"({"eq": )" << eq + 1;
else else
jacobian_output << "{\"row\": " << eq + 1; jacobian_output << R"({"row": )" << eq + 1;
jacobian_output << ", \"col\": " << col + 1; jacobian_output << R"(, "col": )" << col + 1;
if (writeDetails) if (writeDetails)
jacobian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" jacobian_output << R"(, "var": ")" << symbol_table.getName(getSymbIDByDerivID(var)) << R"(")"
<< ", \"shift\": " << getLagByDerivID(var); << R"(, "shift": )" << getLagByDerivID(var);
jacobian_output << ", \"val\": \""; jacobian_output << R"(, "val": ")";
d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms); d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms);
jacobian_output << "\"}" << endl; jacobian_output << R"("})" << endl;
} }
jacobian_output << "]}"; jacobian_output << "]}";
@ -6933,10 +6933,10 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
temp_term_union.insert(temporary_terms_derivatives[2].begin(), temporary_terms_derivatives[2].end()); temp_term_union.insert(temporary_terms_derivatives[2].begin(), temporary_terms_derivatives[2].end());
concat = "hessian"; concat = "hessian";
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, hessian_output, tef_terms, concat); writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, hessian_output, tef_terms, concat);
hessian_output << ", \"hessian\": {" hessian_output << R"(, "hessian": {)"
<< " \"nrows\": " << equations.size() << R"( "nrows": )" << equations.size()
<< ", \"ncols\": " << hessianColsNbr << R"(, "ncols": )" << hessianColsNbr
<< ", \"entries\": ["; << R"(, "entries": [)";
for (auto it = derivatives[2].begin(); for (auto it = derivatives[2].begin();
it != derivatives[2].end(); it++) it != derivatives[2].end(); it++)
{ {
@ -6952,24 +6952,24 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
int col_nb_sym = id2 * dynJacobianColsNbr + id1; int col_nb_sym = id2 * dynJacobianColsNbr + id1;
if (writeDetails) if (writeDetails)
hessian_output << "{\"eq\": " << eq + 1; hessian_output << R"({"eq": )" << eq + 1;
else else
hessian_output << "{\"row\": " << eq + 1; hessian_output << R"({"row": )" << eq + 1;
hessian_output << ", \"col\": [" << col_nb + 1; hessian_output << R"(, "col": [)" << col_nb + 1;
if (id1 != id2) if (id1 != id2)
hessian_output << ", " << col_nb_sym + 1; hessian_output << ", " << col_nb_sym + 1;
hessian_output << "]"; hessian_output << "]";
if (writeDetails) if (writeDetails)
hessian_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" hessian_output << R"(, "var1": ")" << symbol_table.getName(getSymbIDByDerivID(var1)) << R"(")"
<< ", \"shift1\": " << getLagByDerivID(var1) << R"(, "shift1": )" << getLagByDerivID(var1)
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" << R"(, "var2": ")" << symbol_table.getName(getSymbIDByDerivID(var2)) << R"(")"
<< ", \"shift2\": " << getLagByDerivID(var2); << R"(, "shift2": )" << getLagByDerivID(var2);
hessian_output << ", \"val\": \""; hessian_output << R"(, "val": ")";
d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms); d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms);
hessian_output << "\"}" << endl; hessian_output << R"("})" << endl;
} }
hessian_output << "]}"; hessian_output << "]}";
@ -6978,10 +6978,10 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
temp_term_union.insert(temporary_terms_derivatives[3].begin(), temporary_terms_derivatives[3].end()); temp_term_union.insert(temporary_terms_derivatives[3].begin(), temporary_terms_derivatives[3].end());
concat = "third_derivatives"; concat = "third_derivatives";
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, third_derivatives_output, tef_terms, concat); writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, third_derivatives_output, tef_terms, concat);
third_derivatives_output << ", \"third_derivative\": {" third_derivatives_output << R"(, "third_derivative": {)"
<< " \"nrows\": " << equations.size() << R"( "nrows": )" << equations.size()
<< ", \"ncols\": " << hessianColsNbr * dynJacobianColsNbr << R"(, "ncols": )" << hessianColsNbr * dynJacobianColsNbr
<< ", \"entries\": ["; << R"(, "entries": [)";
for (auto it = derivatives[3].begin(); for (auto it = derivatives[3].begin();
it != derivatives[3].end(); it++) it != derivatives[3].end(); it++)
{ {
@ -6993,9 +6993,9 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
expr_t d3 = it->second; expr_t d3 = it->second;
if (writeDetails) if (writeDetails)
third_derivatives_output << "{\"eq\": " << eq + 1; third_derivatives_output << R"({"eq": )" << eq + 1;
else else
third_derivatives_output << "{\"row\": " << eq + 1; third_derivatives_output << R"({"row": )" << eq + 1;
int id1 = getDynJacobianCol(var1); int id1 = getDynJacobianCol(var1);
int id2 = getDynJacobianCol(var2); int id2 = getDynJacobianCol(var2);
@ -7008,7 +7008,7 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
cols.insert(id3 * hessianColsNbr + id1 * dynJacobianColsNbr + id2); cols.insert(id3 * hessianColsNbr + id1 * dynJacobianColsNbr + id2);
cols.insert(id3 * hessianColsNbr + id2 * dynJacobianColsNbr + id1); cols.insert(id3 * hessianColsNbr + id2 * dynJacobianColsNbr + id1);
third_derivatives_output << ", \"col\": ["; third_derivatives_output << R"(, "col": [)";
for (auto it2 = cols.begin(); it2 != cols.end(); it2++) for (auto it2 = cols.begin(); it2 != cols.end(); it2++)
{ {
if (it2 != cols.begin()) if (it2 != cols.begin())
@ -7018,23 +7018,23 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
third_derivatives_output << "]"; third_derivatives_output << "]";
if (writeDetails) if (writeDetails)
third_derivatives_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" third_derivatives_output << R"(, "var1": ")" << symbol_table.getName(getSymbIDByDerivID(var1)) << R"(")"
<< ", \"shift1\": " << getLagByDerivID(var1) << R"(, "shift1": )" << getLagByDerivID(var1)
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" << R"(, "var2": ")" << symbol_table.getName(getSymbIDByDerivID(var2)) << R"(")"
<< ", \"shift2\": " << getLagByDerivID(var2) << R"(, "shift2": )" << getLagByDerivID(var2)
<< ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\"" << R"(, "var3": ")" << symbol_table.getName(getSymbIDByDerivID(var3)) << R"(")"
<< ", \"shift3\": " << getLagByDerivID(var3); << R"(, "shift3": )" << getLagByDerivID(var3);
third_derivatives_output << ", \"val\": \""; third_derivatives_output << R"(, "val": ")";
d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms); d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms);
third_derivatives_output << "\"}" << endl; third_derivatives_output << R"("})" << endl;
} }
third_derivatives_output << "]}"; third_derivatives_output << "]}";
if (writeDetails) if (writeDetails)
output << "\"dynamic_model\": {"; output << R"("dynamic_model": {)";
else else
output << "\"dynamic_model_simple\": {"; output << R"("dynamic_model_simple": {)";
output << model_local_vars_output.str() output << model_local_vars_output.str()
<< ", " << model_output.str() << ", " << model_output.str()
<< ", " << jacobian_output.str() << ", " << jacobian_output.str()
@ -7065,10 +7065,10 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
for (const auto &it : params_derivs_temporary_terms) for (const auto &it : params_derivs_temporary_terms)
writeJsonTemporaryTerms(it.second, temp_term_union, model_output, tef_terms, concat); writeJsonTemporaryTerms(it.second, temp_term_union, model_output, tef_terms, concat);
jacobian_output << "\"deriv_wrt_params\": {" jacobian_output << R"("deriv_wrt_params": {)"
<< " \"neqs\": " << equations.size() << R"( "neqs": )" << equations.size()
<< ", \"nparamcols\": " << symbol_table.param_nbr() << R"(, "nparamcols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &rp = params_derivatives.find({ 0, 1 })->second; auto &rp = params_derivatives.find({ 0, 1 })->second;
for (auto it = rp.begin(); it != rp.end(); it++) for (auto it = rp.begin(); it != rp.end(); it++)
{ {
@ -7082,26 +7082,26 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
if (writeDetails) if (writeDetails)
jacobian_output << "{\"eq\": " << eq + 1; jacobian_output << R"({"eq": )" << eq + 1;
else else
jacobian_output << "{\"row\": " << eq + 1; jacobian_output << R"({"row": )" << eq + 1;
jacobian_output << ", \"param_col\": " << param_col + 1; jacobian_output << R"(, "param_col": )" << param_col + 1;
if (writeDetails) if (writeDetails)
jacobian_output << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; jacobian_output << R"(, "param": ")" << symbol_table.getName(getSymbIDByDerivID(param)) << R"(")";
jacobian_output << ", \"val\": \""; jacobian_output << R"(, "val": ")";
d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms); d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms);
jacobian_output << "\"}" << endl; jacobian_output << R"("})" << endl;
} }
jacobian_output << "]}"; jacobian_output << "]}";
hessian_output << "\"deriv_jacobian_wrt_params\": {" hessian_output << R"("deriv_jacobian_wrt_params": {)"
<< " \"neqs\": " << equations.size() << R"( "neqs": )" << equations.size()
<< ", \"nvarcols\": " << dynJacobianColsNbr << R"(, "nvarcols": )" << dynJacobianColsNbr
<< ", \"nparamcols\": " << symbol_table.param_nbr() << R"(, "nparamcols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &gp = params_derivatives.find({ 1, 1 })->second; auto &gp = params_derivatives.find({ 1, 1 })->second;
for (auto it = gp.begin(); it != gp.end(); it++) for (auto it = gp.begin(); it != gp.end(); it++)
{ {
@ -7116,29 +7116,29 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
if (writeDetails) if (writeDetails)
hessian_output << "{\"eq\": " << eq + 1; hessian_output << R"({"eq": )" << eq + 1;
else else
hessian_output << "{\"row\": " << eq + 1; hessian_output << R"({"row": )" << eq + 1;
hessian_output << ", \"var_col\": " << var_col + 1 hessian_output << R"(, "var_col": )" << var_col + 1
<< ", \"param_col\": " << param_col + 1; << R"(, "param_col": )" << param_col + 1;
if (writeDetails) if (writeDetails)
hessian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" hessian_output << R"(, "var": ")" << symbol_table.getName(getSymbIDByDerivID(var)) << R"(")"
<< ", \"lag\": " << getLagByDerivID(var) << R"(, "lag": )" << getLagByDerivID(var)
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; << R"(, "param": ")" << symbol_table.getName(getSymbIDByDerivID(param)) << R"(")";
hessian_output << ", \"val\": \""; hessian_output << R"(, "val": ")";
d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms); d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms);
hessian_output << "\"}" << endl; hessian_output << R"("})" << endl;
} }
hessian_output << "]}"; hessian_output << "]}";
hessian1_output << "\"second_deriv_residuals_wrt_params\": {" hessian1_output << R"("second_deriv_residuals_wrt_params": {)"
<< " \"nrows\": " << equations.size() << R"( "nrows": )" << equations.size()
<< ", \"nparam1cols\": " << symbol_table.param_nbr() << R"(, "nparam1cols": )" << symbol_table.param_nbr()
<< ", \"nparam2cols\": " << symbol_table.param_nbr() << R"(, "nparam2cols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &rpp = params_derivatives.find({ 0, 2 })->second; auto &rpp = params_derivatives.find({ 0, 2 })->second;
for (auto it = rpp.begin(); it != rpp.end(); ++it) for (auto it = rpp.begin(); it != rpp.end(); ++it)
{ {
@ -7153,28 +7153,28 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
if (writeDetails) if (writeDetails)
hessian1_output << "{\"eq\": " << eq + 1; hessian1_output << R"({"eq": )" << eq + 1;
else else
hessian1_output << "{\"row\": " << eq + 1; hessian1_output << R"({"row": )" << eq + 1;
hessian1_output << ", \"param1_col\": " << param1_col + 1 hessian1_output << R"(, "param1_col": )" << param1_col + 1
<< ", \"param2_col\": " << param2_col + 1; << R"(, "param2_col": )" << param2_col + 1;
if (writeDetails) if (writeDetails)
hessian1_output << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" hessian1_output << R"(, "param1": ")" << symbol_table.getName(getSymbIDByDerivID(param1)) << R"(")"
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; << R"(, "param2": ")" << symbol_table.getName(getSymbIDByDerivID(param2)) << R"(")";
hessian1_output << ", \"val\": \""; hessian1_output << R"(, "val": ")";
d2->writeJsonOutput(hessian1_output, temp_term_union, tef_terms); d2->writeJsonOutput(hessian1_output, temp_term_union, tef_terms);
hessian1_output << "\"}" << endl; hessian1_output << R"("})" << endl;
} }
hessian1_output << "]}"; hessian1_output << "]}";
third_derivs_output << "\"second_deriv_jacobian_wrt_params\": {" third_derivs_output << R"("second_deriv_jacobian_wrt_params": {)"
<< " \"neqs\": " << equations.size() << R"( "neqs": )" << equations.size()
<< ", \"nvarcols\": " << dynJacobianColsNbr << R"(, "nvarcols": )" << dynJacobianColsNbr
<< ", \"nparam1cols\": " << symbol_table.param_nbr() << R"(, "nparam1cols": )" << symbol_table.param_nbr()
<< ", \"nparam2cols\": " << symbol_table.param_nbr() << R"(, "nparam2cols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &gpp = params_derivatives.find({ 1, 2 })->second; auto &gpp = params_derivatives.find({ 1, 2 })->second;
for (auto it = gpp.begin(); it != gpp.end(); ++it) for (auto it = gpp.begin(); it != gpp.end(); ++it)
{ {
@ -7190,32 +7190,32 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
if (writeDetails) if (writeDetails)
third_derivs_output << "{\"eq\": " << eq + 1; third_derivs_output << R"({"eq": )" << eq + 1;
else else
third_derivs_output << "{\"row\": " << eq + 1; third_derivs_output << R"({"row": )" << eq + 1;
third_derivs_output << ", \"var_col\": " << var_col + 1 third_derivs_output << R"(, "var_col": )" << var_col + 1
<< ", \"param1_col\": " << param1_col + 1 << R"(, "param1_col": )" << param1_col + 1
<< ", \"param2_col\": " << param2_col + 1; << R"(, "param2_col": )" << param2_col + 1;
if (writeDetails) if (writeDetails)
third_derivs_output << ", \"var\": \"" << symbol_table.getName(var) << "\"" third_derivs_output << R"(, "var": ")" << symbol_table.getName(var) << R"(")"
<< ", \"lag\": " << getLagByDerivID(var) << R"(, "lag": )" << getLagByDerivID(var)
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" << R"(, "param1": ")" << symbol_table.getName(getSymbIDByDerivID(param1)) << R"(")"
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; << R"(, "param2": ")" << symbol_table.getName(getSymbIDByDerivID(param2)) << R"(")";
third_derivs_output << ", \"val\": \""; third_derivs_output << R"(, "val": ")";
d2->writeJsonOutput(third_derivs_output, temp_term_union, tef_terms); d2->writeJsonOutput(third_derivs_output, temp_term_union, tef_terms);
third_derivs_output << "\"}" << endl; third_derivs_output << R"("})" << endl;
} }
third_derivs_output << "]}" << endl; third_derivs_output << "]}" << endl;
third_derivs1_output << "\"derivative_hessian_wrt_params\": {" third_derivs1_output << R"("derivative_hessian_wrt_params": {)"
<< " \"neqs\": " << equations.size() << R"( "neqs": )" << equations.size()
<< ", \"nvar1cols\": " << dynJacobianColsNbr << R"(, "nvar1cols": )" << dynJacobianColsNbr
<< ", \"nvar2cols\": " << dynJacobianColsNbr << R"(, "nvar2cols": )" << dynJacobianColsNbr
<< ", \"nparamcols\": " << symbol_table.param_nbr() << R"(, "nparamcols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &hp = params_derivatives.find({ 2, 1 })->second; auto &hp = params_derivatives.find({ 2, 1 })->second;
for (auto it = hp.begin(); it != hp.end(); ++it) for (auto it = hp.begin(); it != hp.end(); ++it)
{ {
@ -7231,31 +7231,31 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
if (writeDetails) if (writeDetails)
third_derivs1_output << "{\"eq\": " << eq + 1; third_derivs1_output << R"({"eq": )" << eq + 1;
else else
third_derivs1_output << "{\"row\": " << eq + 1; third_derivs1_output << R"({"row": )" << eq + 1;
third_derivs1_output << ", \"var1_col\": " << var1_col + 1 third_derivs1_output << R"(, "var1_col": )" << var1_col + 1
<< ", \"var2_col\": " << var2_col + 1 << R"(, "var2_col": )" << var2_col + 1
<< ", \"param_col\": " << param_col + 1; << R"(, "param_col": )" << param_col + 1;
if (writeDetails) if (writeDetails)
third_derivs1_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" third_derivs1_output << R"(, "var1": ")" << symbol_table.getName(getSymbIDByDerivID(var1)) << R"(")"
<< ", \"lag1\": " << getLagByDerivID(var1) << R"(, "lag1": )" << getLagByDerivID(var1)
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" << R"(, "var2": ")" << symbol_table.getName(getSymbIDByDerivID(var2)) << R"(")"
<< ", \"lag2\": " << getLagByDerivID(var2) << R"(, "lag2": )" << getLagByDerivID(var2)
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; << R"(, "param": ")" << symbol_table.getName(getSymbIDByDerivID(param)) << R"(")";
third_derivs1_output << ", \"val\": \""; third_derivs1_output << R"(, "val": ")";
d2->writeJsonOutput(third_derivs1_output, temp_term_union, tef_terms); d2->writeJsonOutput(third_derivs1_output, temp_term_union, tef_terms);
third_derivs1_output << "\"}" << endl; third_derivs1_output << R"("})" << endl;
} }
third_derivs1_output << "]}" << endl; third_derivs1_output << "]}" << endl;
if (writeDetails) if (writeDetails)
output << "\"dynamic_model_params_derivative\": {"; output << R"("dynamic_model_params_derivative": {)";
else else
output << "\"dynamic_model_params_derivatives_simple\": {"; output << R"("dynamic_model_params_derivatives_simple": {)";
output << model_local_vars_output.str() output << model_local_vars_output.str()
<< ", " << model_output.str() << ", " << model_output.str()
<< ", " << jacobian_output.str() << ", " << jacobian_output.str()

View File

@ -77,12 +77,12 @@ parse_options_line(istream &modfile)
string first_line; string first_line;
getline(modfile, first_line); getline(modfile, first_line);
regex pat{"^\\s*//\\s*--\\+\\s*options:([^\\+]*)\\+--"}; regex pat{R"(^\s*//\s*--\+\s*options:([^\+]*)\+--)"};
smatch matches; smatch matches;
if (regex_search(first_line, matches, pat)) if (regex_search(first_line, matches, pat))
if (matches.size() > 1 && matches[1].matched) if (matches.size() > 1 && matches[1].matched)
{ {
regex pat2{"([^,\\s]+)"}; regex pat2{R"(([^,\s]+))"};
string s{matches[1]}; string s{matches[1]};
for (sregex_iterator p(s.begin(), s.end(), pat2); for (sregex_iterator p(s.begin(), s.end(), pat2);
p != sregex_iterator{}; ++p) p != sregex_iterator{}; ++p)

View File

@ -458,7 +458,7 @@ NumConstNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
void void
NumConstNode::writeJsonAST(ostream &output) const NumConstNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"NumConstNode\", \"value\" : "; output << R"({"node_type" : "NumConstNode", "value" : )";
double testval = datatree.num_constants.getDouble(id); double testval = datatree.num_constants.getDouble(id);
if (testval < 1.0 && testval > -1.0 && testval != 0.0) if (testval < 1.0 && testval > -1.0 && testval != 0.0)
output << "0"; output << "0";
@ -899,8 +899,8 @@ VariableNode::containsExternalFunction() const
void void
VariableNode::writeJsonAST(ostream &output) const VariableNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"VariableNode\", " output << R"({"node_type" : "VariableNode", )"
<< "\"name\" : \"" << datatree.symbol_table.getName(symb_id) << "\", \"type\" : \""; << R"("name" : ")" << datatree.symbol_table.getName(symb_id) << R"(", "type" : ")";
switch (get_type()) switch (get_type())
{ {
case SymbolType::endogenous: case SymbolType::endogenous:
@ -943,7 +943,7 @@ VariableNode::writeJsonAST(ostream &output) const
output << "epilogue"; output << "epilogue";
break; break;
} }
output << "\", \"lag\" : " << lag << "}"; output << R"(", "lag" : )" << lag << "}";
} }
void void
@ -977,7 +977,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
if (isLatexOutput(output_type)) if (isLatexOutput(output_type))
{ {
if (output_type == ExprNodeOutputType::latexDynamicSteadyStateOperator) if (output_type == ExprNodeOutputType::latexDynamicSteadyStateOperator)
output << "\\bar"; output << R"(\bar)";
output << "{" << datatree.symbol_table.getTeXName(symb_id); output << "{" << datatree.symbol_table.getTeXName(symb_id);
if (output_type == ExprNodeOutputType::latexDynamicModel if (output_type == ExprNodeOutputType::latexDynamicModel
&& (type == SymbolType::endogenous || type == SymbolType::exogenous || type == SymbolType::exogenousDet || type == SymbolType::modelLocalVariable || type == SymbolType::trend || type == SymbolType::logTrend)) && (type == SymbolType::endogenous || type == SymbolType::exogenous || type == SymbolType::exogenousDet || type == SymbolType::modelLocalVariable || type == SymbolType::trend || type == SymbolType::logTrend))
@ -2449,7 +2449,7 @@ UnaryOpNode::containsExternalFunction() const
void void
UnaryOpNode::writeJsonAST(ostream &output) const UnaryOpNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"UnaryOpNode\", \"op\" : \""; output << R"({"node_type" : "UnaryOpNode", "op" : ")";
switch (op_code) switch (op_code)
{ {
case UnaryOpcode::uminus: case UnaryOpcode::uminus:
@ -2530,13 +2530,13 @@ UnaryOpNode::writeJsonAST(ostream &output) const
output << "erf"; output << "erf";
break; break;
} }
output << "\", \"arg\" : "; output << R"(", "arg" : )";
arg->writeJsonAST(output); arg->writeJsonAST(output);
switch (op_code) switch (op_code)
{ {
case UnaryOpcode::adl: case UnaryOpcode::adl:
output << ", \"adl_param_name\" : \"" << adl_param_name << "\"" output << R"(, "adl_param_name" : ")" << adl_param_name << R"(")"
<< ", \"lags\" : ["; << R"(, "lags" : [)";
for (auto it = adl_lags.begin(); it != adl_lags.end(); it++) for (auto it = adl_lags.begin(); it != adl_lags.end(); it++)
{ {
if (it != adl_lags.begin()) if (it != adl_lags.begin())
@ -2728,13 +2728,13 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
break; break;
case UnaryOpcode::log: case UnaryOpcode::log:
if (isLatexOutput(output_type)) if (isLatexOutput(output_type))
output << "\\log"; output << R"(\log)";
else else
output << "log"; output << "log";
break; break;
case UnaryOpcode::log10: case UnaryOpcode::log10:
if (isLatexOutput(output_type)) if (isLatexOutput(output_type))
output << "\\log_{10}"; output << R"(\log_{10})";
else else
output << "log10"; output << "log10";
break; break;
@ -2846,7 +2846,7 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
cerr << "UnaryOpNode::writeOutput: not implemented on UnaryOpcode::expectation" << endl; cerr << "UnaryOpNode::writeOutput: not implemented on UnaryOpcode::expectation" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
output << "\\mathbb{E}_{t"; output << R"(\mathbb{E}_{t)";
if (expectation_information_set != 0) if (expectation_information_set != 0)
{ {
if (expectation_information_set > 0) if (expectation_information_set > 0)
@ -4400,8 +4400,8 @@ BinaryOpNode::containsExternalFunction() const
void void
BinaryOpNode::writeJsonAST(ostream &output) const BinaryOpNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"BinaryOpNode\"," output << R"({"node_type" : "BinaryOpNode",)"
<< " \"op\" : \""; << R"( "op" : ")";
switch (op_code) switch (op_code)
{ {
case BinaryOpcode::plus: case BinaryOpcode::plus:
@ -4450,9 +4450,9 @@ BinaryOpNode::writeJsonAST(ostream &output) const
output << "power_deriv"; output << "power_deriv";
break; break;
} }
output << "\", \"arg1\" : "; output << R"(", "arg1" : )";
arg1->writeJsonAST(output); arg1->writeJsonAST(output);
output << ", \"arg2\" : "; output << R"(, "arg2" : )";
arg2->writeJsonAST(output); arg2->writeJsonAST(output);
output << "}"; output << "}";
} }
@ -4646,7 +4646,7 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
bool close_parenthesis = false; bool close_parenthesis = false;
if (isLatexOutput(output_type) && op_code == BinaryOpcode::divide) if (isLatexOutput(output_type) && op_code == BinaryOpcode::divide)
output << "\\frac{"; output << R"(\frac{)";
else else
{ {
// If left argument has a lower precedence, or if current and left argument are both power operators, add parenthesis around left argument // If left argument has a lower precedence, or if current and left argument are both power operators, add parenthesis around left argument
@ -4679,7 +4679,7 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
break; break;
case BinaryOpcode::times: case BinaryOpcode::times:
if (isLatexOutput(output_type)) if (isLatexOutput(output_type))
output << "\\, "; output << R"(\, )";
else else
output << "*"; output << "*";
break; break;
@ -4698,13 +4698,13 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
break; break;
case BinaryOpcode::lessEqual: case BinaryOpcode::lessEqual:
if (isLatexOutput(output_type)) if (isLatexOutput(output_type))
output << "\\leq "; output << R"(\leq )";
else else
output << "<="; output << "<=";
break; break;
case BinaryOpcode::greaterEqual: case BinaryOpcode::greaterEqual:
if (isLatexOutput(output_type)) if (isLatexOutput(output_type))
output << "\\geq "; output << R"(\geq )";
else else
output << ">="; output << ">=";
break; break;
@ -4719,7 +4719,7 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
if (isCOutput(output_type) || isJuliaOutput(output_type)) if (isCOutput(output_type) || isJuliaOutput(output_type))
output << "!="; output << "!=";
else else
output << "\\neq "; output << R"(\neq )";
} }
break; break;
case BinaryOpcode::equal: case BinaryOpcode::equal:
@ -6293,8 +6293,8 @@ TrinaryOpNode::containsExternalFunction() const
void void
TrinaryOpNode::writeJsonAST(ostream &output) const TrinaryOpNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"TrinaryOpNode\", " output << R"({"node_type" : "TrinaryOpNode", )"
<< "\"op\" : \""; << R"("op" : ")";
switch (op_code) switch (op_code)
{ {
case TrinaryOpcode::normcdf: case TrinaryOpcode::normcdf:
@ -6304,11 +6304,11 @@ TrinaryOpNode::writeJsonAST(ostream &output) const
output << "normpdf"; output << "normpdf";
break; break;
} }
output << "\", \"arg1\" : "; output << R"(", "arg1" : )";
arg1->writeJsonAST(output); arg1->writeJsonAST(output);
output << ", \"arg2\" : "; output << R"(, "arg2" : )";
arg2->writeJsonAST(output); arg2->writeJsonAST(output);
output << ", \"arg2\" : "; output << R"(, "arg2" : )";
arg3->writeJsonAST(output); arg3->writeJsonAST(output);
output << "}"; output << "}";
} }
@ -7440,7 +7440,7 @@ AbstractExternalFunctionNode::writeJsonASTExternalFunctionArguments(ostream &out
if (it != arguments.begin()) if (it != arguments.begin())
output << ","; output << ",";
output << "\"arg" << i << "\" : "; output << R"("arg)" << i << R"(" : )";
(*it)->writeJsonAST(output); (*it)->writeJsonAST(output);
} }
output << "}"; output << "}";
@ -7634,8 +7634,8 @@ ExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsign
void void
ExternalFunctionNode::writeJsonAST(ostream &output) const ExternalFunctionNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"ExternalFunctionNode\", " output << R"({"node_type" : "ExternalFunctionNode", )"
<< "\"name\" : \"" << datatree.symbol_table.getName(symb_id) << "\", \"args\" : ["; << R"("name" : ")" << datatree.symbol_table.getName(symb_id) << R"(", "args" : [)";
writeJsonASTExternalFunctionArguments(output); writeJsonASTExternalFunctionArguments(output);
output << "]}"; output << "]}";
} }
@ -7729,8 +7729,8 @@ ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutpu
<< "nlhs" << ending.str() << ", " << "nlhs" << ending.str() << ", "
<< "plhs" << ending.str() << ", " << "plhs" << ending.str() << ", "
<< "nrhs" << ending.str() << ", " << "nrhs" << ending.str() << ", "
<< "prhs" << ending.str() << ", \"" << "prhs" << ending.str() << R"(, ")"
<< datatree.symbol_table.getName(symb_id) << "\");" << endl; << datatree.symbol_table.getName(symb_id) << R"(");)" << endl;
if (symb_id == first_deriv_symb_id if (symb_id == first_deriv_symb_id
&& symb_id == second_deriv_symb_id) && symb_id == second_deriv_symb_id)
@ -7781,18 +7781,18 @@ ExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
assert(second_deriv_symb_id != ExternalFunctionsTable::IDSetButNoNameProvided); assert(second_deriv_symb_id != ExternalFunctionsTable::IDSetButNoNameProvided);
stringstream ef; stringstream ef;
ef << "{\"external_function\": {" ef << R"({"external_function": {)"
<< "\"external_function_term\": \"TEF_" << indx << "\""; << R"("external_function_term": "TEF_)" << indx << R"(")";
if (symb_id == first_deriv_symb_id) if (symb_id == first_deriv_symb_id)
ef << ", \"external_function_term_d\": \"TEFD_" << indx << "\""; ef << R"(, "external_function_term_d": "TEFD_)" << indx << R"(")";
if (symb_id == second_deriv_symb_id) if (symb_id == second_deriv_symb_id)
ef << ", \"external_function_term_dd\": \"TEFDD_" << indx << "\""; ef << R"(, "external_function_term_dd": "TEFDD_)" << indx << R"(")";
ef << ", \"value\": \"" << datatree.symbol_table.getName(symb_id) << "("; ef << R"(, "value": ")" << datatree.symbol_table.getName(symb_id) << "(";
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic); writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic);
ef << ")\"}}"; ef << R"lit()"}})lit";
efout.push_back(ef.str()); efout.push_back(ef.str());
} }
} }
@ -7878,8 +7878,8 @@ FirstDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
void void
FirstDerivExternalFunctionNode::writeJsonAST(ostream &output) const FirstDerivExternalFunctionNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"FirstDerivExternalFunctionNode\", " output << R"({"node_type" : "FirstDerivExternalFunctionNode", )"
<< "\"name\" : \"" << datatree.symbol_table.getName(symb_id) << "\", \"args\" : ["; << R"("name" : ")" << datatree.symbol_table.getName(symb_id) << R"(", "args" : [)";
writeJsonASTExternalFunctionArguments(output); writeJsonASTExternalFunctionArguments(output);
output << "]}"; output << "]}";
} }
@ -7923,8 +7923,8 @@ FirstDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType
if (isLatexOutput(output_type)) if (isLatexOutput(output_type))
{ {
output << "\\frac{\\partial " << datatree.symbol_table.getTeXName(symb_id) output << R"(\frac{\partial )" << datatree.symbol_table.getTeXName(symb_id)
<< "}{\\partial " << inputIndex << "}("; << R"(}{\partial )" << inputIndex << "}(";
writeExternalFunctionArguments(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms); writeExternalFunctionArguments(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
output << ")"; output << ")";
return; return;
@ -8028,7 +8028,7 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
output << "dims" << ending.str() << "[0] = 1;" << endl output << "dims" << ending.str() << "[0] = 1;" << endl
<< "dims" << ending.str() << "[1] = " << arguments.size() << ";" << endl; << "dims" << ending.str() << "[1] = " << arguments.size() << ";" << endl;
output << "prhs" << ending.str() << "[0] = mxCreateString(\"" << datatree.symbol_table.getName(symb_id) << "\");" << endl output << "prhs" << ending.str() << R"([0] = mxCreateString(")" << datatree.symbol_table.getName(symb_id) << R"(");)" << endl
<< "prhs" << ending.str() << "[1] = mxCreateDoubleScalar(" << inputIndex << ");"<< endl << "prhs" << ending.str() << "[1] = mxCreateDoubleScalar(" << inputIndex << ");"<< endl
<< "prhs" << ending.str() << "[2] = mxCreateCellArray(2, dims" << ending.str() << ");"<< endl; << "prhs" << ending.str() << "[2] = mxCreateCellArray(2, dims" << ending.str() << ");"<< endl;
@ -8046,8 +8046,8 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
<< "nlhs" << ending.str() << ", " << "nlhs" << ending.str() << ", "
<< "plhs" << ending.str() << ", " << "plhs" << ending.str() << ", "
<< "nrhs" << ending.str() << ", " << "nrhs" << ending.str() << ", "
<< "prhs" << ending.str() << ", \"" << "prhs" << ending.str() << R"(, ")"
<< "jacob_element\");" << endl; << R"(jacob_element");)" << endl;
output << "TEFD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex output << "TEFD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex
<< " = mxGetPr(plhs" << ending.str() << "[0]);" << endl; << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl;
@ -8068,8 +8068,8 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
<< "nlhs" << ending.str() << ", " << "nlhs" << ending.str() << ", "
<< "plhs" << ending.str() << ", " << "plhs" << ending.str() << ", "
<< "nrhs" << ending.str() << ", " << "nrhs" << ending.str() << ", "
<< "prhs" << ending.str() << ", \"" << "prhs" << ending.str() << R"(, ")"
<< datatree.symbol_table.getName(first_deriv_symb_id) << "\");" << endl; << datatree.symbol_table.getName(first_deriv_symb_id) << R"(");)" << endl;
output << "TEFD_def_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl; output << "TEFD_def_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl;
} }
@ -8116,22 +8116,22 @@ FirstDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &
stringstream ef; stringstream ef;
if (first_deriv_symb_id == ExternalFunctionsTable::IDNotSet) if (first_deriv_symb_id == ExternalFunctionsTable::IDNotSet)
ef << "{\"first_deriv_external_function\": {" ef << R"({"first_deriv_external_function": {)"
<< "\"external_function_term\": \"TEFD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex << "\"" << R"("external_function_term": "TEFD_fdd_)" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex << R"(")"
<< ", \"analytic_derivative\": false" << R"(, "analytic_derivative": false)"
<< ", \"wrt\": " << inputIndex << R"(, "wrt": )" << inputIndex
<< ", \"value\": \"" << datatree.symbol_table.getName(symb_id) << "("; << R"(, "value": ")" << datatree.symbol_table.getName(symb_id) << "(";
else else
{ {
tef_terms[{ first_deriv_symb_id, arguments }] = (int) tef_terms.size(); tef_terms[{ first_deriv_symb_id, arguments }] = (int) tef_terms.size();
ef << "{\"first_deriv_external_function\": {" ef << R"({"first_deriv_external_function": {)"
<< "\"external_function_term\": \"TEFD_def_" << getIndxInTefTerms(first_deriv_symb_id, tef_terms) << "\"" << R"("external_function_term": "TEFD_def_)" << getIndxInTefTerms(first_deriv_symb_id, tef_terms) << R"(")"
<< ", \"analytic_derivative\": true" << R"(, "analytic_derivative": true)"
<< ", \"value\": \"" << datatree.symbol_table.getName(first_deriv_symb_id) << "("; << R"(, "value": ")" << datatree.symbol_table.getName(first_deriv_symb_id) << "(";
} }
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic); writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic);
ef << ")\"}}"; ef << R"lit()"}})lit";
efout.push_back(ef.str()); efout.push_back(ef.str());
} }
@ -8267,8 +8267,8 @@ SecondDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
void void
SecondDerivExternalFunctionNode::writeJsonAST(ostream &output) const SecondDerivExternalFunctionNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"SecondDerivExternalFunctionNode\", " output << R"({"node_type" : "SecondDerivExternalFunctionNode", )"
<< "\"name\" : \"" << datatree.symbol_table.getName(symb_id) << "\", \"args\" : ["; << R"("name" : ")" << datatree.symbol_table.getName(symb_id) << R"(", "args" : [)";
writeJsonASTExternalFunctionArguments(output); writeJsonASTExternalFunctionArguments(output);
output << "]}"; output << "]}";
} }
@ -8313,8 +8313,8 @@ SecondDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType
if (isLatexOutput(output_type)) if (isLatexOutput(output_type))
{ {
output << "\\frac{\\partial^2 " << datatree.symbol_table.getTeXName(symb_id) output << R"(\frac{\partial^2 )" << datatree.symbol_table.getTeXName(symb_id)
<< "}{\\partial " << inputIndex1 << "\\partial " << inputIndex2 << "}("; << R"(}{\partial )" << inputIndex1 << R"(\partial )" << inputIndex2 << "}(";
writeExternalFunctionArguments(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms); writeExternalFunctionArguments(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
output << ")"; output << ")";
return; return;
@ -8392,7 +8392,7 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
output << "dims" << ending.str() << "[0] = 1;" << endl output << "dims" << ending.str() << "[0] = 1;" << endl
<< "dims" << ending.str() << "[1] = " << arguments.size() << ";" << endl; << "dims" << ending.str() << "[1] = " << arguments.size() << ";" << endl;
output << "prhs" << ending.str() << "[0] = mxCreateString(\"" << datatree.symbol_table.getName(symb_id) << "\");" << endl output << "prhs" << ending.str() << R"([0] = mxCreateString(")" << datatree.symbol_table.getName(symb_id) << R"(");)" << endl
<< "prhs" << ending.str() << "[1] = mxCreateDoubleScalar(" << inputIndex1 << ");"<< endl << "prhs" << ending.str() << "[1] = mxCreateDoubleScalar(" << inputIndex1 << ");"<< endl
<< "prhs" << ending.str() << "[2] = mxCreateDoubleScalar(" << inputIndex2 << ");"<< endl << "prhs" << ending.str() << "[2] = mxCreateDoubleScalar(" << inputIndex2 << ");"<< endl
<< "prhs" << ending.str() << "[3] = mxCreateCellArray(2, dims" << ending.str() << ");"<< endl; << "prhs" << ending.str() << "[3] = mxCreateCellArray(2, dims" << ending.str() << ");"<< endl;
@ -8411,8 +8411,8 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
<< "nlhs" << ending.str() << ", " << "nlhs" << ending.str() << ", "
<< "plhs" << ending.str() << ", " << "plhs" << ending.str() << ", "
<< "nrhs" << ending.str() << ", " << "nrhs" << ending.str() << ", "
<< "prhs" << ending.str() << ", \"" << "prhs" << ending.str() << R"(, ")"
<< "hess_element\");" << endl; << R"(hess_element");)" << endl;
output << "TEFDD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex1 << "_" << inputIndex2 output << "TEFDD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex1 << "_" << inputIndex2
<< " = mxGetPr(plhs" << ending.str() << "[0]);" << endl; << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl;
@ -8434,8 +8434,8 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
<< "nlhs" << ending.str() << ", " << "nlhs" << ending.str() << ", "
<< "plhs" << ending.str() << ", " << "plhs" << ending.str() << ", "
<< "nrhs" << ending.str() << ", " << "nrhs" << ending.str() << ", "
<< "prhs" << ending.str() << ", \"" << "prhs" << ending.str() << R"(, ")"
<< datatree.symbol_table.getName(second_deriv_symb_id) << "\");" << endl; << datatree.symbol_table.getName(second_deriv_symb_id) << R"(");)" << endl;
output << "TEFDD_def_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl; output << "TEFDD_def_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl;
} }
@ -8483,23 +8483,23 @@ SecondDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string>
stringstream ef; stringstream ef;
if (second_deriv_symb_id == ExternalFunctionsTable::IDNotSet) if (second_deriv_symb_id == ExternalFunctionsTable::IDNotSet)
ef << "{\"second_deriv_external_function\": {" ef << R"({"second_deriv_external_function": {)"
<< "\"external_function_term\": \"TEFDD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex1 << "_" << inputIndex2 << "\"" << R"("external_function_term": "TEFDD_fdd_)" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex1 << "_" << inputIndex2 << R"(")"
<< ", \"analytic_derivative\": false" << R"(, "analytic_derivative": false)"
<< ", \"wrt1\": " << inputIndex1 << R"(, "wrt1": )" << inputIndex1
<< ", \"wrt2\": " << inputIndex2 << R"(, "wrt2": )" << inputIndex2
<< ", \"value\": \"" << datatree.symbol_table.getName(symb_id) << "("; << R"(, "value": ")" << datatree.symbol_table.getName(symb_id) << "(";
else else
{ {
tef_terms[{ second_deriv_symb_id, arguments }] = (int) tef_terms.size(); tef_terms[{ second_deriv_symb_id, arguments }] = (int) tef_terms.size();
ef << "{\"second_deriv_external_function\": {" ef << R"({"second_deriv_external_function": {)"
<< "\"external_function_term\": \"TEFDD_def_" << getIndxInTefTerms(second_deriv_symb_id, tef_terms) << "\"" << R"("external_function_term": "TEFDD_def_)" << getIndxInTefTerms(second_deriv_symb_id, tef_terms) << R"(")"
<< ", \"analytic_derivative\": true" << R"(, "analytic_derivative": true)"
<< ", \"value\": \"" << datatree.symbol_table.getName(second_deriv_symb_id) << "("; << R"(, "value": ")" << datatree.symbol_table.getName(second_deriv_symb_id) << "(";
} }
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic); writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic);
ef << ")\"}}" << endl; ef << R"lit()"}})lit" << endl;
efout.push_back(ef.str()); efout.push_back(ef.str());
} }
@ -9012,8 +9012,8 @@ VarExpectationNode::replaceVarsInEquation(map<VariableNode *, NumConstNode *> &t
void void
VarExpectationNode::writeJsonAST(ostream &output) const VarExpectationNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"VarExpectationNode\", " output << R"({"node_type" : "VarExpectationNode", )"
<< "\"name\" : \"" << model_name << "\"}"; << R"("name" : ")" << model_name << R"("})";
} }
void void
@ -9416,8 +9416,8 @@ PacExpectationNode::replaceVarsInEquation(map<VariableNode *, NumConstNode *> &t
void void
PacExpectationNode::writeJsonAST(ostream &output) const PacExpectationNode::writeJsonAST(ostream &output) const
{ {
output << "{\"node_type\" : \"PacExpectationNode\", " output << R"({"node_type" : "PacExpectationNode", )"
<< "\"name\" : \"" << model_name << "\"}"; << R"("name" : ")" << model_name << R"("})";
} }
void void

View File

@ -301,7 +301,7 @@ ModFile::checkPass(bool nostrict, bool stochastic)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::lessEqual) || dynamic_model.isBinaryOpUsed(BinaryOpcode::lessEqual)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::equalEqual) || dynamic_model.isBinaryOpUsed(BinaryOpcode::equalEqual)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::different))) || dynamic_model.isBinaryOpUsed(BinaryOpcode::different)))
warnings << "WARNING: you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which is unsuitable for a stochastic context; see the reference manual, section about \"Expressions\", for more details." << endl; warnings << R"(WARNING: you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which is unsuitable for a stochastic context; see the reference manual, section about "Expressions", for more details.)" << endl;
if (linear if (linear
&& (dynamic_model.isUnaryOpUsed(UnaryOpcode::sign) && (dynamic_model.isUnaryOpUsed(UnaryOpcode::sign)
@ -944,7 +944,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
mOutputFile << "options_.parallel_info.local_files = {" << endl; mOutputFile << "options_.parallel_info.local_files = {" << endl;
for (const auto & parallel_local_file : parallel_local_files) for (const auto & parallel_local_file : parallel_local_files)
{ {
size_t j = parallel_local_file.find_last_of("/\\"); size_t j = parallel_local_file.find_last_of(R"(/\)");
if (j == string::npos) if (j == string::npos)
mOutputFile << "'', '" << parallel_local_file << "';" << endl; mOutputFile << "'', '" << parallel_local_file << "';" << endl;
else else
@ -1158,10 +1158,10 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
<< "using SteadyState" << endl << endl << "using SteadyState" << endl << endl
<< "using " << basename << "Static" << endl << "using " << basename << "Static" << endl
<< "using " << basename << "Dynamic" << endl << "using " << basename << "Dynamic" << endl
<< "if isfile(\"" << basename << "SteadyState.jl" "\")" << endl << R"(if isfile(")" << basename << R"(SteadyState.jl"))" << endl
<< " using " << basename << "SteadyState" << endl << " using " << basename << "SteadyState" << endl
<< "end" << endl << "end" << endl
<< "if isfile(\"" << basename << "SteadyState2.jl" "\")" << endl << R"(if isfile(")" << basename << R"(SteadyState2.jl"))" << endl
<< " using " << basename << "SteadyState2" << endl << " using " << basename << "SteadyState2" << endl
<< "end" << endl << endl << "end" << endl << endl
<< "export model_, options_, oo_" << endl; << "export model_, options_, oo_" << endl;
@ -1169,20 +1169,20 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
// Write Output // Write Output
jlOutputFile << endl jlOutputFile << endl
<< "oo_ = dynare_output()" << endl << "oo_ = dynare_output()" << endl
<< "oo_.dynare_version = \"" << PACKAGE_VERSION << "\"" << endl; << R"(oo_.dynare_version = ")" << PACKAGE_VERSION << R"(")" << endl;
// Write Options // Write Options
jlOutputFile << endl jlOutputFile << endl
<< "options_ = dynare_options()" << endl << "options_ = dynare_options()" << endl
<< "options_.dynare_version = \"" << PACKAGE_VERSION << "\"" << endl; << R"(options_.dynare_version = ")" << PACKAGE_VERSION << R"(")" << endl;
if (linear == 1) if (linear == 1)
jlOutputFile << "options_.linear = true" << endl; jlOutputFile << "options_.linear = true" << endl;
// Write Model // Write Model
jlOutputFile << endl jlOutputFile << endl
<< "model_ = dynare_model()" << endl << "model_ = dynare_model()" << endl
<< "model_.fname = \"" << basename << "\"" << endl << R"(model_.fname = ")" << basename << R"(")" << endl
<< "model_.dynare_version = \"" << PACKAGE_VERSION << "\"" << endl << R"(model_.dynare_version = ")" << PACKAGE_VERSION << R"(")" << endl
<< "model_.sigma_e = zeros(Float64, " << symbol_table.exo_nbr() << ", " << "model_.sigma_e = zeros(Float64, " << symbol_table.exo_nbr() << ", "
<< symbol_table.exo_nbr() << ")" << endl << symbol_table.exo_nbr() << ")" << endl
<< "model_.correlation_matrix = ones(Float64, " << symbol_table.exo_nbr() << ", " << "model_.correlation_matrix = ones(Float64, " << symbol_table.exo_nbr() << ", "
@ -1229,19 +1229,19 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
<< "model_.dynamic = " << basename << "Dynamic.dynamic!" << endl << "model_.dynamic = " << basename << "Dynamic.dynamic!" << endl
<< "model_.temporaries.static = " << basename << "Static.tmp_nbr" << endl << "model_.temporaries.static = " << basename << "Static.tmp_nbr" << endl
<< "model_.temporaries.dynamic = " << basename << "Dynamic.tmp_nbr" << endl << "model_.temporaries.dynamic = " << basename << "Dynamic.tmp_nbr" << endl
<< "if isfile(\"" << basename << "SteadyState.jl" "\")" << endl << R"(if isfile(")" << basename << R"(SteadyState.jl"))" << endl
<< " model_.user_written_analytical_steady_state = true" << endl << " model_.user_written_analytical_steady_state = true" << endl
<< " model_.steady_state = " << basename << "SteadyState.steady_state!" << endl << " model_.steady_state = " << basename << "SteadyState.steady_state!" << endl
<< "end" << endl << "end" << endl
<< "if isfile(\"" << basename << "SteadyState2.jl" "\")" << endl << R"(if isfile(")" << basename << R"(SteadyState2.jl"))" << endl
<< " model_.analytical_steady_state = true" << endl << " model_.analytical_steady_state = true" << endl
<< " model_.steady_state = " << basename << "SteadyState2.steady_state!" << endl << " model_.steady_state = " << basename << "SteadyState2.steady_state!" << endl
<< "end" << endl << "end" << endl
<< "if isfile(\"" << basename << "StaticParamsDerivs.jl" "\")" << endl << R"(if isfile(")" << basename << R"(StaticParamsDerivs.jl"))" << endl
<< " using " << basename << "StaticParamsDerivs" << endl << " using " << basename << "StaticParamsDerivs" << endl
<< " model_.static_params_derivs = " << basename << "StaticParamsDerivs.params_derivs" << endl << " model_.static_params_derivs = " << basename << "StaticParamsDerivs.params_derivs" << endl
<< "end" << endl << "end" << endl
<< "if isfile(\"" << basename << "DynamicParamsDerivs.jl" "\")" << endl << R"(if isfile(")" << basename << R"(DynamicParamsDerivs.jl"))" << endl
<< " using " << basename << "DynamicParamsDerivs" << endl << " using " << basename << "DynamicParamsDerivs" << endl
<< " model_.dynamic_params_derivs = " << basename << "DynamicParamsDerivs.params_derivs" << endl << " model_.dynamic_params_derivs = " << basename << "DynamicParamsDerivs.params_derivs" << endl
<< "end" << endl << "end" << endl
@ -1312,7 +1312,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
|| !var_model_table.empty() || !var_model_table.empty()
|| !trend_component_model_table.empty()) || !trend_component_model_table.empty())
{ {
output << ", \"statements\": ["; output << R"(, "statements": [)";
if (!var_model_table.empty()) if (!var_model_table.empty())
{ {
var_model_table.writeJsonOutput(output); var_model_table.writeJsonOutput(output);
@ -1350,7 +1350,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
original_model.writeJsonOriginalModelOutput(original_model_output); original_model.writeJsonOriginalModelOutput(original_model_output);
if (!statements.empty() || !var_model_table.empty() || !trend_component_model_table.empty()) if (!statements.empty() || !var_model_table.empty() || !trend_component_model_table.empty())
{ {
original_model_output << endl << ", \"statements\": ["; original_model_output << endl << R"(, "statements": [)";
if (!var_model_table.empty()) if (!var_model_table.empty())
{ {
var_model_table.writeJsonOutput(original_model_output); var_model_table.writeJsonOutput(original_model_output);
@ -1381,14 +1381,14 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
if (json_output_mode == JsonFileOutputType::standardout) if (json_output_mode == JsonFileOutputType::standardout)
{ {
if (transformpass || computingpass) if (transformpass || computingpass)
cout << "\"transformed_modfile\": "; cout << R"("transformed_modfile": )";
else else
cout << "\"modfile\": "; cout << R"("modfile": )";
cout << output.str(); cout << output.str();
if (!original_model_output.str().empty()) if (!original_model_output.str().empty())
cout << ", \"original_model\": " << original_model_output.str(); cout << R"(, "original_model": )" << original_model_output.str();
if (!steady_state_model_output.str().empty()) if (!steady_state_model_output.str().empty())
cout << ", \"steady_state_model\": " << steady_state_model_output.str(); cout << R"(, "steady_state_model": )" << steady_state_model_output.str();
} }
else else
{ {
@ -1492,14 +1492,14 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType
if (json_output_mode == JsonFileOutputType::standardout) if (json_output_mode == JsonFileOutputType::standardout)
{ {
cout << ", \"static_model\": " << static_output.str() << endl cout << R"(, "static_model": )" << static_output.str() << endl
<< ", \"dynamic_model\": " << dynamic_output.str() << endl; << R"(, "dynamic_model": )" << dynamic_output.str() << endl;
if (!static_paramsd_output.str().empty()) if (!static_paramsd_output.str().empty())
cout << ", \"static_params_deriv\": " << static_paramsd_output.str() << endl; cout << R"(, "static_params_deriv": )" << static_paramsd_output.str() << endl;
if (!dynamic_paramsd_output.str().empty()) if (!dynamic_paramsd_output.str().empty())
cout << ", \"dynamic_params_deriv\": " << dynamic_paramsd_output.str() << endl; cout << R"(, "dynamic_params_deriv": )" << dynamic_paramsd_output.str() << endl;
} }
else else
{ {

View File

@ -1434,7 +1434,7 @@ ModelTree::writeJsonTemporaryTerms(const temporary_terms_t &tt, const temporary_
bool wrote_term = false; bool wrote_term = false;
temporary_terms_t tt2 = ttm1; temporary_terms_t tt2 = ttm1;
output << "\"external_functions_temporary_terms_" << concat << "\": ["; output << R"("external_functions_temporary_terms_)" << concat << R"(": [)";
for (auto it : tt) for (auto it : tt)
if (ttm1.find(it) == ttm1.end()) if (ttm1.find(it) == ttm1.end())
{ {
@ -1458,19 +1458,19 @@ ModelTree::writeJsonTemporaryTerms(const temporary_terms_t &tt, const temporary_
tt2 = ttm1; tt2 = ttm1;
wrote_term = false; wrote_term = false;
output << "]" output << "]"
<< ", \"temporary_terms_" << concat << "\": ["; << R"(, "temporary_terms_)" << concat << R"(": [)";
for (auto it = tt.begin(); for (auto it = tt.begin();
it != tt.end(); it++) it != tt.end(); it++)
if (ttm1.find(*it) == ttm1.end()) if (ttm1.find(*it) == ttm1.end())
{ {
if (wrote_term) if (wrote_term)
output << ", "; output << ", ";
output << "{\"temporary_term\": \""; output << R"({"temporary_term": ")";
(*it)->writeJsonOutput(output, tt, tef_terms); (*it)->writeJsonOutput(output, tt, tef_terms);
output << "\"" output << R"(")"
<< ", \"value\": \""; << R"(, "value": ")";
(*it)->writeJsonOutput(output, tt2, tef_terms); (*it)->writeJsonOutput(output, tt2, tef_terms);
output << "\"}" << endl; output << R"("})" << endl;
wrote_term = true; wrote_term = true;
// Insert current node into tt2 // Insert current node into tt2
@ -1647,7 +1647,7 @@ ModelTree::writeJsonModelLocalVariables(ostream &output, deriv_node_temp_terms_t
for (auto equation : equations) for (auto equation : equations)
equation->collectVariables(SymbolType::modelLocalVariable, used_local_vars); equation->collectVariables(SymbolType::modelLocalVariable, used_local_vars);
output << "\"model_local_variables\": ["; output << R"("model_local_variables": [)";
bool printed = false; bool printed = false;
for (int it : local_variables_vector) for (int it : local_variables_vector)
if (used_local_vars.find(it) != used_local_vars.end()) if (used_local_vars.find(it) != used_local_vars.end())
@ -1673,10 +1673,10 @@ ModelTree::writeJsonModelLocalVariables(ostream &output, deriv_node_temp_terms_t
/* We append underscores to avoid name clashes with "g1" or "oo_" (see /* We append underscores to avoid name clashes with "g1" or "oo_" (see
also VariableNode::writeOutput) */ also VariableNode::writeOutput) */
output << "{\"variable\": \"" << symbol_table.getName(id) << "__\"" output << R"({"variable": ")" << symbol_table.getName(id) << R"(__")"
<< ", \"value\": \""; << R"(, "value": ")";
value->writeJsonOutput(output, tt, tef_terms); value->writeJsonOutput(output, tt, tef_terms);
output << "\"}" << endl; output << R"("})" << endl;
} }
output << "]"; output << "]";
} }
@ -1800,7 +1800,7 @@ ModelTree::Write_Inf_To_Bin_File(const string &filename,
SaveCode.open(filename, ios::out | ios::binary); SaveCode.open(filename, ios::out | ios::binary);
if (!SaveCode.is_open()) if (!SaveCode.is_open())
{ {
cerr << "Error : Can't open file \"" << filename << "\" for writing" << endl; cerr << R"(Error : Can't open file ")" << filename << R"(" for writing)" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
u_count_int = 0; u_count_int = 0;
@ -1852,24 +1852,24 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
output << "\\documentclass[10pt,a4paper]{article}" << endl output << R"(\documentclass[10pt,a4paper]{article})" << endl
<< "\\usepackage[landscape]{geometry}" << endl << R"(\usepackage[landscape]{geometry})" << endl
<< "\\usepackage{fullpage}" << endl << R"(\usepackage{fullpage})" << endl
<< "\\usepackage{amsfonts}" << endl << R"(\usepackage{amsfonts})" << endl
<< "\\usepackage{breqn}" << endl << R"(\usepackage{breqn})" << endl
<< "\\begin{document}" << endl << R"(\begin{document})" << endl
<< "\\footnotesize" << endl; << R"(\footnotesize)" << endl;
// Write model local variables // Write model local variables
for (int id : local_variables_vector) for (int id : local_variables_vector)
{ {
expr_t value = local_variables_table.find(id)->second; expr_t value = local_variables_table.find(id)->second;
content_output << "\\begin{dmath*}" << endl content_output << R"(\begin{dmath*})" << endl
<< symbol_table.getTeXName(id) << " = "; << symbol_table.getTeXName(id) << " = ";
// Use an empty set for the temporary terms // Use an empty set for the temporary terms
value->writeOutput(content_output, output_type); value->writeOutput(content_output, output_type);
content_output << endl << "\\end{dmath*}" << endl; content_output << endl << R"(\end{dmath*})" << endl;
} }
for (int eq = 0; eq < (int) equations.size(); eq++) for (int eq = 0; eq < (int) equations.size(); eq++)
@ -1882,7 +1882,7 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
if (equation_tag.first == eq) if (equation_tag.first == eq)
{ {
if (!wrote_eq_tag) if (!wrote_eq_tag)
content_output << "\\noindent["; content_output << R"(\noindent[)";
else else
content_output << ", "; content_output << ", ";
@ -1898,14 +1898,14 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
content_output << "]"; content_output << "]";
} }
content_output << "\\begin{dmath}" << endl; content_output << R"(\begin{dmath})" << endl;
// Here it is necessary to cast to superclass ExprNode, otherwise the overloaded writeOutput() method is not found // Here it is necessary to cast to superclass ExprNode, otherwise the overloaded writeOutput() method is not found
dynamic_cast<ExprNode *>(equations[eq])->writeOutput(content_output, output_type); dynamic_cast<ExprNode *>(equations[eq])->writeOutput(content_output, output_type);
content_output << endl << "\\end{dmath}" << endl; content_output << endl << R"(\end{dmath})" << endl;
} }
output << "\\include{" << content_basename << "}" << endl output << R"(\include{)" << content_basename << "}" << endl
<< "\\end{document}" << endl; << R"(\end{document})" << endl;
output.close(); output.close();
content_output.close(); content_output.close();
@ -2114,9 +2114,9 @@ ModelTree::writeJsonModelEquations(ostream &output, bool residuals) const
vector<pair<string, string>> eqtags; vector<pair<string, string>> eqtags;
temporary_terms_t tt_empty; temporary_terms_t tt_empty;
if (residuals) if (residuals)
output << endl << "\"residuals\":[" << endl; output << endl << R"("residuals":[)" << endl;
else else
output << endl << "\"model\":[" << endl; output << endl << R"("model":[)" << endl;
for (int eq = 0; eq < (int) equations.size(); eq++) for (int eq = 0; eq < (int) equations.size(); eq++)
{ {
if (eq > 0) if (eq > 0)
@ -2128,22 +2128,22 @@ ModelTree::writeJsonModelEquations(ostream &output, bool residuals) const
if (residuals) if (residuals)
{ {
output << "{\"residual\": {" output << R"({"residual": {)"
<< "\"lhs\": \""; << R"("lhs": ")";
lhs->writeJsonOutput(output, temporary_terms, {}); lhs->writeJsonOutput(output, temporary_terms, {});
output << "\""; output << R"(")";
output << ", \"rhs\": \""; output << R"(, "rhs": ")";
rhs->writeJsonOutput(output, temporary_terms, {}); rhs->writeJsonOutput(output, temporary_terms, {});
output << "\""; output << R"(")";
try try
{ {
// Test if the right hand side of the equation is empty. // Test if the right hand side of the equation is empty.
if (rhs->eval(eval_context_t()) != 0) if (rhs->eval(eval_context_t()) != 0)
{ {
output << ", \"rhs\": \""; output << R"(, "rhs": ")";
rhs->writeJsonOutput(output, temporary_terms, {}); rhs->writeJsonOutput(output, temporary_terms, {});
output << "\""; output << R"(")";
} }
} }
catch (ExprNode::EvalException &e) catch (ExprNode::EvalException &e)
@ -2153,12 +2153,12 @@ ModelTree::writeJsonModelEquations(ostream &output, bool residuals) const
} }
else else
{ {
output << "{\"lhs\": \""; output << R"({"lhs": ")";
lhs->writeJsonOutput(output, tt_empty, {}); lhs->writeJsonOutput(output, tt_empty, {});
output << "\", \"rhs\": \""; output << R"(", "rhs": ")";
rhs->writeJsonOutput(output, tt_empty, {}); rhs->writeJsonOutput(output, tt_empty, {});
output << "\"" output << R"(")"
<< ", \"line\": " << equations_lineno[eq]; << R"(, "line": )" << equations_lineno[eq];
for (const auto & equation_tag : equation_tags) for (const auto & equation_tag : equation_tags)
if (equation_tag.first == eq) if (equation_tag.first == eq)
@ -2166,13 +2166,13 @@ ModelTree::writeJsonModelEquations(ostream &output, bool residuals) const
if (!eqtags.empty()) if (!eqtags.empty())
{ {
output << ", \"tags\": {"; output << R"(, "tags": {)";
int i = 0; int i = 0;
for (vector<pair<string, string>>::const_iterator it = eqtags.begin(); it != eqtags.end(); it++, i++) for (vector<pair<string, string>>::const_iterator it = eqtags.begin(); it != eqtags.end(); it++, i++)
{ {
if (i != 0) if (i != 0)
output << ", "; output << ", ";
output << "\"" << it->first << "\": \"" << it->second << "\""; output << R"(")" << it->first << R"(": ")" << it->second << R"(")";
} }
output << "}"; output << "}";
eqtags.clear(); eqtags.clear();

View File

@ -67,9 +67,9 @@ InitParamStatement::writeJuliaOutput(ostream &output, const string &basename)
void void
InitParamStatement::writeJsonOutput(ostream &output) const InitParamStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"param_init\", \"name\": \"" << symbol_table.getName(symb_id) << "\", " << "\"value\": \""; output << R"({"statementName": "param_init", "name": ")" << symbol_table.getName(symb_id) << R"(", )" << R"("value": ")";
param_value->writeJsonOutput(output, {}, {}); param_value->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
void void
@ -179,9 +179,9 @@ InitOrEndValStatement::writeJsonInitValues(ostream &output) const
{ {
if (it != init_values.begin()) if (it != init_values.begin())
output << ", "; output << ", ";
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\", " << "\"value\": \""; output << R"({"name": ")" << symbol_table.getName(it->first) << R"(", )" << R"("value": ")";
it->second->writeJsonOutput(output, {}, {}); it->second->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
} }
@ -233,7 +233,7 @@ InitValStatement::writeOutput(ostream &output, const string &basename, bool mini
void void
InitValStatement::writeJsonOutput(ostream &output) const InitValStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"initval\", \"vals\": ["; output << R"({"statementName": "initval", "vals": [)";
writeJsonInitValues(output); writeJsonInitValues(output);
output << "]}"; output << "]}";
} }
@ -298,7 +298,7 @@ EndValStatement::writeOutput(ostream &output, const string &basename, bool minim
void void
EndValStatement::writeJsonOutput(ostream &output) const EndValStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"endval\", \"vals\": ["; output << R"({"statementName": "endval", "vals": [)";
writeJsonInitValues(output); writeJsonInitValues(output);
output << "]}"; output << "]}";
} }
@ -394,17 +394,17 @@ HistValStatement::writeOutput(ostream &output, const string &basename, bool mini
void void
HistValStatement::writeJsonOutput(ostream &output) const HistValStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"histval\", \"vals\": ["; output << R"({"statementName": "histval", "vals": [)";
for (auto it = hist_values.begin(); for (auto it = hist_values.begin();
it != hist_values.end(); it++) it != hist_values.end(); it++)
{ {
if (it != hist_values.begin()) if (it != hist_values.begin())
output << ", "; output << ", ";
output << "{ \"name\": \"" << symbol_table.getName(it->first.first) << "\"" output << R"({ "name": ")" << symbol_table.getName(it->first.first) << R"(")"
<< ", \"lag\": " << it->first.second << R"(, "lag": )" << it->first.second
<< ", \"value\": \""; << R"(, "value": ")";
it->second->writeJsonOutput(output, {}, {}); it->second->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
output << "]}"; output << "]}";
} }
@ -427,8 +427,8 @@ InitvalFileStatement::writeOutput(ostream &output, const string &basename, bool
void void
InitvalFileStatement::writeJsonOutput(ostream &output) const InitvalFileStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"init_val_file\"" output << R"({"statementName": "init_val_file")"
<< ", \"filename\": \"" << filename << "\"" << R"(, "filename": ")" << filename << R"(")"
<< "}"; << "}";
} }
@ -446,8 +446,8 @@ HistvalFileStatement::writeOutput(ostream &output, const string &basename, bool
void void
HistvalFileStatement::writeJsonOutput(ostream &output) const HistvalFileStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"hist_val_file\"" output << R"({"statementName": "hist_val_file")"
<< ", \"filename\": \"" << filename << "\"" << R"(, "filename": ")" << filename << R"(")"
<< "}"; << "}";
} }
@ -489,8 +489,8 @@ HomotopyStatement::writeOutput(ostream &output, const string &basename, bool min
void void
HomotopyStatement::writeJsonOutput(ostream &output) const HomotopyStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"homotopy\", " output << R"({"statementName": "homotopy", )"
<< "\"values\": ["; << R"("values": [)";
for (auto it = homotopy_values.begin(); for (auto it = homotopy_values.begin();
it != homotopy_values.end(); ++it) it != homotopy_values.end(); ++it)
{ {
@ -501,15 +501,15 @@ HomotopyStatement::writeJsonOutput(ostream &output) const
expr_t expression1, expression2; expr_t expression1, expression2;
tie(symb_id, expression1, expression2) = *it; tie(symb_id, expression1, expression2) = *it;
output << "{\"name\": \"" << symbol_table.getName(symb_id) << "\"" output << R"({"name": ")" << symbol_table.getName(symb_id) << R"(")"
<< ", \"initial_value\": \""; << R"(, "initial_value": ")";
if (expression1) if (expression1)
expression1->writeJsonOutput(output, {}, {}); expression1->writeJsonOutput(output, {}, {});
else else
output << "NaN"; output << "NaN";
output << "\", \"final_value\": \""; output << R"(", "final_value": ")";
expression2->writeJsonOutput(output, {}, {}); expression2->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
output << "]" output << "]"
<< "}"; << "}";
@ -529,8 +529,8 @@ SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba
void void
SaveParamsAndSteadyStateStatement::writeJsonOutput(ostream &output) const SaveParamsAndSteadyStateStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"save_params_and_steady_state\"" output << R"({"statementName": "save_params_and_steady_state")"
<< ", \"filename\": \"" << filename << "\"" << R"(, "filename": ")" << filename << R"(")"
<< "}"; << "}";
} }
@ -601,15 +601,15 @@ LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba
void void
LoadParamsAndSteadyStateStatement::writeJsonOutput(ostream &output) const LoadParamsAndSteadyStateStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"load_params_and_steady_state\"" output << R"({"statementName": "load_params_and_steady_state")"
<< "\"values\": ["; << R"("values": [)";
for (auto it = content.begin(); for (auto it = content.begin();
it != content.end(); it++) it != content.end(); it++)
{ {
if (it != content.begin()) if (it != content.begin())
output << ", "; output << ", ";
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\"" output << R"({"name": ")" << symbol_table.getName(it->first) << R"(")"
<< ", \"value\": \"" << it->second << "\"}"; << R"(, "value": ")" << it->second << R"("})";
} }
output << "]" output << "]"
<< "}"; << "}";

View File

@ -70,24 +70,24 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
void void
AbstractShocksStatement::writeJsonDetShocks(ostream &output) const AbstractShocksStatement::writeJsonDetShocks(ostream &output) const
{ {
output << "\"deterministic_shocks\": ["; output << R"("deterministic_shocks": [)";
for (auto it = det_shocks.begin(); for (auto it = det_shocks.begin();
it != det_shocks.end(); it++) it != det_shocks.end(); it++)
{ {
if (it != det_shocks.begin()) if (it != det_shocks.begin())
output << ", "; output << ", ";
output << "{\"var\": \"" << symbol_table.getName(it->first) << "\", " output << R"({"var": ")" << symbol_table.getName(it->first) << R"(", )"
<< "\"values\": ["; << R"("values": [)";
for (auto it1 = it->second.begin(); for (auto it1 = it->second.begin();
it1 != it->second.end(); it1++) it1 != it->second.end(); it1++)
{ {
if (it1 != it->second.begin()) if (it1 != it->second.begin())
output << ", "; output << ", ";
output << "{\"period1\": " << it1->period1 << ", " output << R"({"period1": )" << it1->period1 << ", "
<< "\"period2\": " << it1->period2 << ", " << R"("period2": )" << it1->period2 << ", "
<< "\"value\": \""; << R"("value": ")";
it1->value->writeJsonOutput(output, {}, {}); it1->value->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
output << "]}"; output << "]}";
} }
@ -153,8 +153,8 @@ ShocksStatement::writeOutput(ostream &output, const string &basename, bool minim
void void
ShocksStatement::writeJsonOutput(ostream &output) const ShocksStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"shocks\"" output << R"({"statementName": "shocks")"
<< ", \"overwrite\": "; << R"(, "overwrite": )";
if (overwrite) if (overwrite)
output << "true"; output << "true";
else else
@ -164,52 +164,52 @@ ShocksStatement::writeJsonOutput(ostream &output) const
output << ", "; output << ", ";
writeJsonDetShocks(output); writeJsonDetShocks(output);
} }
output<< ", \"variance\": ["; output<< R"(, "variance": [)";
for (auto it = var_shocks.begin(); it != var_shocks.end(); it++) for (auto it = var_shocks.begin(); it != var_shocks.end(); it++)
{ {
if (it != var_shocks.begin()) if (it != var_shocks.begin())
output << ", "; output << ", ";
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\", " output << R"({"name": ")" << symbol_table.getName(it->first) << R"(", )"
<< "\"variance\": \""; << R"("variance": ")";
it->second->writeJsonOutput(output, {}, {}); it->second->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
output << "]" output << "]"
<< ", \"stderr\": ["; << R"(, "stderr": [)";
for (auto it = std_shocks.begin(); it != std_shocks.end(); it++) for (auto it = std_shocks.begin(); it != std_shocks.end(); it++)
{ {
if (it != std_shocks.begin()) if (it != std_shocks.begin())
output << ", "; output << ", ";
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\", " output << R"({"name": ")" << symbol_table.getName(it->first) << R"(", )"
<< "\"stderr\": \""; << R"("stderr": ")";
it->second->writeJsonOutput(output, {}, {}); it->second->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
output << "]" output << "]"
<< ", \"covariance\": ["; << R"(, "covariance": [)";
for (auto it = covar_shocks.begin(); it != covar_shocks.end(); it++) for (auto it = covar_shocks.begin(); it != covar_shocks.end(); it++)
{ {
if (it != covar_shocks.begin()) if (it != covar_shocks.begin())
output << ", "; output << ", ";
output << "{" output << "{"
<< "\"name\": \"" << symbol_table.getName(it->first.first) << "\", " << R"("name": ")" << symbol_table.getName(it->first.first) << R"(", )"
<< "\"name2\": \"" << symbol_table.getName(it->first.second) << "\", " << R"("name2": ")" << symbol_table.getName(it->first.second) << R"(", )"
<< "\"covariance\": \""; << R"("covariance": ")";
it->second->writeJsonOutput(output, {}, {}); it->second->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
output << "]" output << "]"
<< ", \"correlation\": ["; << R"(, "correlation": [)";
for (auto it = corr_shocks.begin(); it != corr_shocks.end(); it++) for (auto it = corr_shocks.begin(); it != corr_shocks.end(); it++)
{ {
if (it != corr_shocks.begin()) if (it != corr_shocks.begin())
output << ", "; output << ", ";
output << "{" output << "{"
<< "\"name\": \"" << symbol_table.getName(it->first.first) << "\", " << R"("name": ")" << symbol_table.getName(it->first.first) << R"(", )"
<< "\"name2\": \"" << symbol_table.getName(it->first.second) << "\", " << R"("name2": ")" << symbol_table.getName(it->first.second) << R"(", )"
<< "\"correlation\": \""; << R"("correlation": ")";
it->second->writeJsonOutput(output, {}, {}); it->second->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
output << "]" output << "]"
<< "}"; << "}";
@ -487,23 +487,23 @@ ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &ba
void void
ConditionalForecastPathsStatement::writeJsonOutput(ostream &output) const ConditionalForecastPathsStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"conditional_forecast_paths\"" output << R"({"statementName": "conditional_forecast_paths")"
<< ", \"paths\": ["; << R"(, "paths": [)";
for (auto it = paths.begin(); it != paths.end(); it++) for (auto it = paths.begin(); it != paths.end(); it++)
{ {
if (it != paths.begin()) if (it != paths.begin())
output << ", "; output << ", ";
output << "{\"var\": \"" << symbol_table.getName(it->first) << "\", " output << R"({"var": ")" << symbol_table.getName(it->first) << R"(", )"
<< "\"values\": ["; << R"("values": [)";
for (auto it1 = it->second.begin(); it1 != it->second.end(); it1++) for (auto it1 = it->second.begin(); it1 != it->second.end(); it1++)
{ {
if (it1 != it->second.begin()) if (it1 != it->second.begin())
output << ", "; output << ", ";
output << "{\"period1\": " << it1->period1 << ", " output << R"({"period1": )" << it1->period1 << ", "
<< "\"period2\": " << it1->period2 << ", " << R"("period2": )" << it1->period2 << ", "
<< "\"value\": \""; << R"("value": ")";
it1->value->writeJsonOutput(output, {}, {}); it1->value->writeJsonOutput(output, {}, {});
output << "\"}"; output << R"("})";
} }
output << "]}"; output << "]}";
} }
@ -534,17 +534,17 @@ MomentCalibration::writeOutput(ostream &output, const string &basename, bool min
void void
MomentCalibration::writeJsonOutput(ostream &output) const MomentCalibration::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"moment_calibration\"" output << R"({"statementName": "moment_calibration")"
<< ", \"moment_calibration_criteria\": ["; << R"(, "moment_calibration_criteria": [)";
for (auto it = constraints.begin(); it != constraints.end(); it++) for (auto it = constraints.begin(); it != constraints.end(); it++)
{ {
if (it != constraints.begin()) if (it != constraints.begin())
output << ", "; output << ", ";
output << "{\"endogenous1\": \"" << symbol_table.getName(it->endo1) << "\"" output << R"({"endogenous1": ")" << symbol_table.getName(it->endo1) << R"(")"
<< ", \"endogenous2\": \"" << symbol_table.getName(it->endo2) << "\"" << R"(, "endogenous2": ")" << symbol_table.getName(it->endo2) << R"(")"
<< ", \"lags\": \"" << it->lags << "\"" << R"(, "lags": ")" << it->lags << R"(")"
<< ", \"lower_bound\": \"" << it->lower_bound << "\"" << R"(, "lower_bound": ")" << it->lower_bound << R"(")"
<< ", \"upper_bound\": \"" << it->upper_bound << "\"" << R"(, "upper_bound": ")" << it->upper_bound << R"(")"
<< "}"; << "}";
} }
output << "]" output << "]"
@ -578,23 +578,23 @@ IrfCalibration::writeOutput(ostream &output, const string &basename, bool minima
void void
IrfCalibration::writeJsonOutput(ostream &output) const IrfCalibration::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"irf_calibration\""; output << R"({"statementName": "irf_calibration")";
if (options_list.getNumberOfOptions()) if (options_list.getNumberOfOptions())
{ {
output << ", "; output << ", ";
options_list.writeJsonOutput(output); options_list.writeJsonOutput(output);
} }
output << ", \"irf_restrictions\": ["; output << R"(, "irf_restrictions": [)";
for (auto it = constraints.begin(); it != constraints.end(); it++) for (auto it = constraints.begin(); it != constraints.end(); it++)
{ {
if (it != constraints.begin()) if (it != constraints.begin())
output << ", "; output << ", ";
output << "{\"endogenous\": \"" << symbol_table.getName(it->endo) << "\"" output << R"({"endogenous": ")" << symbol_table.getName(it->endo) << R"(")"
<< ", \"exogenous\": \"" << symbol_table.getName(it->exo) << "\"" << R"(, "exogenous": ")" << symbol_table.getName(it->exo) << R"(")"
<< ", \"periods\": \"" << it->periods << "\"" << R"(, "periods": ")" << it->periods << R"(")"
<< ", \"lower_bound\": \"" << it->lower_bound << "\"" << R"(, "lower_bound": ")" << it->lower_bound << R"(")"
<< ", \"upper_bound\": \"" << it->upper_bound << "\"" << R"(, "upper_bound": ")" << it->upper_bound << R"(")"
<< "}"; << "}";
} }
output << "]" output << "]"

View File

@ -55,9 +55,9 @@ void
NativeStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const NativeStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{ {
using namespace boost::xpressive; using namespace boost::xpressive;
string date_regex = "(-?\\d+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4]\\d|5[0-2])))"; string date_regex = R"((-?\d+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4]\d|5[0-2]))))";
sregex regex_lookbehind = sregex::compile("(?<!\\$|\\d|[a-zA-Z_]|\\')" + date_regex); sregex regex_lookbehind = sregex::compile(R"((?<!\$|\d|[a-zA-Z_]|\'))" + date_regex);
sregex regex_dollar = sregex::compile("(\\$)"+date_regex); sregex regex_dollar = sregex::compile(R"((\$))"+date_regex);
string ns = regex_replace(native_statement, regex_lookbehind, "dates('$&')"); string ns = regex_replace(native_statement, regex_lookbehind, "dates('$&')");
ns = regex_replace(ns, regex_dollar, "$2"); //replace $DATE with DATE ns = regex_replace(ns, regex_dollar, "$2"); //replace $DATE with DATE
@ -67,8 +67,8 @@ NativeStatement::writeOutput(ostream &output, const string &basename, bool minim
void void
NativeStatement::writeJsonOutput(ostream &output) const NativeStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"native\"" output << R"({"statementName": "native")"
<< ", \"string\": \"" << native_statement << "\"" << R"(, "string": ")" << native_statement << R"(")"
<< "}"; << "}";
} }
@ -86,8 +86,8 @@ VerbatimStatement::writeOutput(ostream &output, const string &basename, bool min
void void
VerbatimStatement::writeJsonOutput(ostream &output) const VerbatimStatement::writeJsonOutput(ostream &output) const
{ {
output << "{\"statementName\": \"verbatim\"" output << R"({"statementName": "verbatim")"
<< ", \"string\": \"" << verbatim_statement << "\"" << R"(, "string": ")" << verbatim_statement << R"(")"
<< "}"; << "}";
} }
@ -204,11 +204,11 @@ OptionsList::writeJsonOutput(ostream &output) const
if (getNumberOfOptions() == 0) if (getNumberOfOptions() == 0)
return; return;
output << "\"options\": {"; output << R"("options": {)";
for (auto it = num_options.begin(); for (auto it = num_options.begin();
it != num_options.end();) it != num_options.end();)
{ {
output << "\""<< it->first << "\": " << it->second; output << R"(")"<< it->first << R"(": )" << it->second;
it++; it++;
if (it != num_options.end() if (it != num_options.end()
|| !(paired_num_options.empty() || !(paired_num_options.empty()
@ -222,7 +222,7 @@ OptionsList::writeJsonOutput(ostream &output) const
for (auto it = paired_num_options.begin(); for (auto it = paired_num_options.begin();
it != paired_num_options.end();) it != paired_num_options.end();)
{ {
output << "\""<< it->first << "\": [" << it->second.first << " " << it->second.second << "]"; output << R"(")"<< it->first << R"(": [)" << it->second.first << " " << it->second.second << "]";
it++; it++;
if (it != paired_num_options.end() if (it != paired_num_options.end()
|| !(string_options.empty() || !(string_options.empty()
@ -235,7 +235,7 @@ OptionsList::writeJsonOutput(ostream &output) const
for (auto it = string_options.begin(); for (auto it = string_options.begin();
it != string_options.end();) it != string_options.end();)
{ {
output << "\""<< it->first << "\": \"" << it->second << "\""; output << R"(")"<< it->first << R"(": ")" << it->second << R"(")";
it++; it++;
if (it != string_options.end() if (it != string_options.end()
|| !(date_options.empty() || !(date_options.empty()
@ -247,7 +247,7 @@ OptionsList::writeJsonOutput(ostream &output) const
for (auto it = date_options.begin(); for (auto it = date_options.begin();
it != date_options.end();) it != date_options.end();)
{ {
output << "\""<< it->first << "\": \"" << it->second << "\""; output << R"(")"<< it->first << R"(": ")" << it->second << R"(")";
it++; it++;
if (it != date_options.end() if (it != date_options.end()
|| !(symbol_list_options.empty() || !(symbol_list_options.empty()
@ -258,7 +258,7 @@ OptionsList::writeJsonOutput(ostream &output) const
for (auto it = symbol_list_options.begin(); for (auto it = symbol_list_options.begin();
it != symbol_list_options.end();) it != symbol_list_options.end();)
{ {
output << "\""<< it->first << "\": {"; output << R"(")"<< it->first << R"(": {)";
it->second.writeJsonOutput(output); it->second.writeJsonOutput(output);
output << "}"; output << "}";
it++; it++;
@ -270,7 +270,7 @@ OptionsList::writeJsonOutput(ostream &output) const
for (auto it = vector_int_options.begin(); for (auto it = vector_int_options.begin();
it != vector_int_options.end();) it != vector_int_options.end();)
{ {
output << "\""<< it->first << "\": ["; output << R"(")"<< it->first << R"(": [)";
if (it->second.size() > 1) if (it->second.size() > 1)
{ {
for (auto viit = it->second.begin(); for (auto viit = it->second.begin();
@ -293,13 +293,13 @@ OptionsList::writeJsonOutput(ostream &output) const
for (auto it = vector_str_options.begin(); for (auto it = vector_str_options.begin();
it != vector_str_options.end();) it != vector_str_options.end();)
{ {
output << "\""<< it->first << "\": ["; output << R"(")"<< it->first << R"(": [)";
if (it->second.size() > 1) if (it->second.size() > 1)
{ {
for (auto viit = it->second.begin(); for (auto viit = it->second.begin();
viit != it->second.end();) viit != it->second.end();)
{ {
output << "\"" << *viit << "\""; output << R"(")" << *viit << R"(")";
viit++; viit++;
if (viit != it->second.end()) if (viit != it->second.end())
output << ", "; output << ", ";

View File

@ -564,7 +564,7 @@ StaticModel::writeModelEquationsCode(const string &basename, map_idx_t map_idx)
code_file.open(main_name, ios::out | ios::binary | ios::ate); code_file.open(main_name, ios::out | ios::binary | ios::ate);
if (!code_file.is_open()) if (!code_file.is_open())
{ {
cerr << "Error : Can't open file \"" << main_name << "\" for writing" << endl; cerr << R"(Error : Can't open file ")" << main_name << R"(" for writing)" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int count_u; int count_u;
@ -741,7 +741,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map
code_file.open(main_name, ios::out | ios::binary | ios::ate); code_file.open(main_name, ios::out | ios::binary | ios::ate);
if (!code_file.is_open()) if (!code_file.is_open())
{ {
cerr << "Error : Can't open file \"" << main_name << "\" for writing" << endl; cerr << R"(Error : Can't open file ")" << main_name << R"(" for writing)" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
//Temporary variables declaration //Temporary variables declaration
@ -2031,7 +2031,7 @@ StaticModel::writeStaticCFile(const string &basename) const
if (external_functions_table.get_total_number_of_unique_model_block_external_functions()) if (external_functions_table.get_total_number_of_unique_model_block_external_functions())
// External Matlab function, implies Static function will call mex // External Matlab function, implies Static function will call mex
output << "#include <uchar.h>" << endl // For MATLAB ≤ R2011a output << "#include <uchar.h>" << endl // For MATLAB ≤ R2011a
<< "#include \"mex.h\"" << endl; << R"(#include "mex.h")" << endl;
output << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl output << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl
<< "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl; << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl;
@ -2067,7 +2067,7 @@ StaticModel::writeStaticCFile(const string &basename) const
<< endl << endl
<< "#include <stdlib.h>" << endl << "#include <stdlib.h>" << endl
<< "#include <uchar.h>" << endl // For MATLAB ≤ R2011a << "#include <uchar.h>" << endl // For MATLAB ≤ R2011a
<< "#include \"mex.h\"" << endl << R"(#include "mex.h")" << endl
<< endl << endl
<< "const int ntt = " << ntt << ";" << endl << "const int ntt = " << ntt << ";" << endl
<< "void static_resid_tt(const double *y, const double *x, int nb_row_x, const double *params, double *T);" << endl << "void static_resid_tt(const double *y, const double *x, int nb_row_x, const double *params, double *T);" << endl
@ -2557,9 +2557,9 @@ StaticModel::writeLatexAuxVarRecursiveDefinitions(ostream &output) const
temporary_terms, temporary_terms_idxs, tef_terms); temporary_terms, temporary_terms_idxs, tef_terms);
for (auto aux_equation : aux_equations) for (auto aux_equation : aux_equations)
{ {
output << "\\begin{dmath}" << endl; output << R"(\begin{dmath})" << endl;
dynamic_cast<ExprNode *>(aux_equation->substituteStaticAuxiliaryDefinition())->writeOutput(output, ExprNodeOutputType::latexStaticModel); dynamic_cast<ExprNode *>(aux_equation->substituteStaticAuxiliaryDefinition())->writeOutput(output, ExprNodeOutputType::latexStaticModel);
output << endl << "\\end{dmath}" << endl; output << endl << R"(\end{dmath})" << endl;
} }
} }
@ -2587,11 +2587,11 @@ StaticModel::writeJsonAuxVarRecursiveDefinitions(ostream &output) const
for (auto aux_equation : aux_equations) for (auto aux_equation : aux_equations)
{ {
output << ", {\"lhs\": \""; output << R"(, {"lhs": ")";
aux_equation->arg1->writeJsonOutput(output, temporary_terms, tef_terms, false); aux_equation->arg1->writeJsonOutput(output, temporary_terms, tef_terms, false);
output << "\", \"rhs\": \""; output << R"(", "rhs": ")";
dynamic_cast<BinaryOpNode *>(aux_equation->substituteStaticAuxiliaryDefinition())->arg2->writeJsonOutput(output, temporary_terms, tef_terms, false); dynamic_cast<BinaryOpNode *>(aux_equation->substituteStaticAuxiliaryDefinition())->arg2->writeJsonOutput(output, temporary_terms, tef_terms, false);
output << "\"}"; output << R"("})";
} }
} }
@ -2915,10 +2915,10 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
temp_term_union.insert(temporary_terms_derivatives[1].begin(), temporary_terms_derivatives[1].end()); temp_term_union.insert(temporary_terms_derivatives[1].begin(), temporary_terms_derivatives[1].end());
concat = "jacobian"; concat = "jacobian";
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, jacobian_output, tef_terms, concat); writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, jacobian_output, tef_terms, concat);
jacobian_output << ", \"jacobian\": {" jacobian_output << R"(, "jacobian": {)"
<< " \"nrows\": " << nrows << R"( "nrows": )" << nrows
<< ", \"ncols\": " << JacobianColsNbr << R"(, "ncols": )" << JacobianColsNbr
<< ", \"entries\": ["; << R"(, "entries": [)";
for (auto it = derivatives[1].begin(); for (auto it = derivatives[1].begin();
it != derivatives[1].end(); it++) it != derivatives[1].end(); it++)
{ {
@ -2932,18 +2932,18 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
expr_t d1 = it->second; expr_t d1 = it->second;
if (writeDetails) if (writeDetails)
jacobian_output << "{\"eq\": " << eq + 1; jacobian_output << R"({"eq": )" << eq + 1;
else else
jacobian_output << "{\"row\": " << eq + 1; jacobian_output << R"({"row": )" << eq + 1;
jacobian_output << ", \"col\": " << col + 1; jacobian_output << R"(, "col": )" << col + 1;
if (writeDetails) if (writeDetails)
jacobian_output << ", \"var\": \"" << symbol_table.getName(symb_id) << "\""; jacobian_output << R"(, "var": ")" << symbol_table.getName(symb_id) << R"(")";
jacobian_output << ", \"val\": \""; jacobian_output << R"(, "val": ")";
d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms); d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms);
jacobian_output << "\"}" << endl; jacobian_output << R"("})" << endl;
} }
jacobian_output << "]}"; jacobian_output << "]}";
@ -2953,10 +2953,10 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
temp_term_union.insert(temporary_terms_derivatives[2].begin(), temporary_terms_derivatives[2].end()); temp_term_union.insert(temporary_terms_derivatives[2].begin(), temporary_terms_derivatives[2].end());
concat = "hessian"; concat = "hessian";
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, hessian_output, tef_terms, concat); writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, hessian_output, tef_terms, concat);
hessian_output << ", \"hessian\": {" hessian_output << R"(, "hessian": {)"
<< " \"nrows\": " << equations.size() << R"( "nrows": )" << equations.size()
<< ", \"ncols\": " << g2ncols << R"(, "ncols": )" << g2ncols
<< ", \"entries\": ["; << R"(, "entries": [)";
for (auto it = derivatives[2].begin(); for (auto it = derivatives[2].begin();
it != derivatives[2].end(); it++) it != derivatives[2].end(); it++)
{ {
@ -2976,22 +2976,22 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
int col_sym = tsid2*symbol_table.endo_nbr()+tsid1; int col_sym = tsid2*symbol_table.endo_nbr()+tsid1;
if (writeDetails) if (writeDetails)
hessian_output << "{\"eq\": " << eq + 1; hessian_output << R"({"eq": )" << eq + 1;
else else
hessian_output << "{\"row\": " << eq + 1; hessian_output << R"({"row": )" << eq + 1;
hessian_output << ", \"col\": [" << col + 1; hessian_output << R"(, "col": [)" << col + 1;
if (writeDetails) if (writeDetails)
hessian_output << ", \"var1\": \"" << symbol_table.getName(symb_id1) << "\"" hessian_output << R"(, "var1": ")" << symbol_table.getName(symb_id1) << R"(")"
<< ", \"var2\": \"" << symbol_table.getName(symb_id2) << "\""; << R"(, "var2": ")" << symbol_table.getName(symb_id2) << R"(")";
if (symb_id1 != symb_id2) if (symb_id1 != symb_id2)
hessian_output << ", " << col_sym + 1; hessian_output << ", " << col_sym + 1;
hessian_output << "]" hessian_output << "]"
<< ", \"val\": \""; << R"(, "val": ")";
d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms); d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms);
hessian_output << "\"}" << endl; hessian_output << R"("})" << endl;
} }
hessian_output << "]}"; hessian_output << "]}";
@ -3000,10 +3000,10 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
temp_term_union.insert(temporary_terms_derivatives[3].begin(), temporary_terms_derivatives[3].end()); temp_term_union.insert(temporary_terms_derivatives[3].begin(), temporary_terms_derivatives[3].end());
concat = "third_derivatives"; concat = "third_derivatives";
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, third_derivatives_output, tef_terms, concat); writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, third_derivatives_output, tef_terms, concat);
third_derivatives_output << ", \"third_derivative\": {" third_derivatives_output << R"(, "third_derivative": {)"
<< " \"nrows\": " << equations.size() << R"( "nrows": )" << equations.size()
<< ", \"ncols\": " << hessianColsNbr * JacobianColsNbr << R"(, "ncols": )" << hessianColsNbr * JacobianColsNbr
<< ", \"entries\": ["; << R"(, "entries": [)";
for (auto it = derivatives[3].begin(); for (auto it = derivatives[3].begin();
it != derivatives[3].end(); it++) it != derivatives[3].end(); it++)
{ {
@ -3015,9 +3015,9 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
expr_t d3 = it->second; expr_t d3 = it->second;
if (writeDetails) if (writeDetails)
third_derivatives_output << "{\"eq\": " << eq + 1; third_derivatives_output << R"({"eq": )" << eq + 1;
else else
third_derivatives_output << "{\"row\": " << eq + 1; third_derivatives_output << R"({"row": )" << eq + 1;
int id1 = getSymbIDByDerivID(var1); int id1 = getSymbIDByDerivID(var1);
int id2 = getSymbIDByDerivID(var2); int id2 = getSymbIDByDerivID(var2);
@ -3030,7 +3030,7 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
cols.insert(id3 * hessianColsNbr + id1 * JacobianColsNbr + id2); cols.insert(id3 * hessianColsNbr + id1 * JacobianColsNbr + id2);
cols.insert(id3 * hessianColsNbr + id2 * JacobianColsNbr + id1); cols.insert(id3 * hessianColsNbr + id2 * JacobianColsNbr + id1);
third_derivatives_output << ", \"col\": ["; third_derivatives_output << R"(, "col": [)";
for (auto it2 = cols.begin(); it2 != cols.end(); it2++) for (auto it2 = cols.begin(); it2 != cols.end(); it2++)
{ {
if (it2 != cols.begin()) if (it2 != cols.begin())
@ -3040,20 +3040,20 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
third_derivatives_output << "]"; third_derivatives_output << "]";
if (writeDetails) if (writeDetails)
third_derivatives_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" third_derivatives_output << R"(, "var1": ")" << symbol_table.getName(getSymbIDByDerivID(var1)) << R"(")"
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" << R"(, "var2": ")" << symbol_table.getName(getSymbIDByDerivID(var2)) << R"(")"
<< ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\""; << R"(, "var3": ")" << symbol_table.getName(getSymbIDByDerivID(var3)) << R"(")";
third_derivatives_output << ", \"val\": \""; third_derivatives_output << R"(, "val": ")";
d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms); d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms);
third_derivatives_output << "\"}" << endl; third_derivatives_output << R"("})" << endl;
} }
third_derivatives_output << "]}"; third_derivatives_output << "]}";
if (writeDetails) if (writeDetails)
output << "\"static_model\": {"; output << R"("static_model": {)";
else else
output << "\"static_model_simple\": {"; output << R"("static_model_simple": {)";
output << model_local_vars_output.str() output << model_local_vars_output.str()
<< ", " << model_output.str() << ", " << model_output.str()
<< ", " << jacobian_output.str() << ", " << jacobian_output.str()
@ -3084,10 +3084,10 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
for (const auto &it : params_derivs_temporary_terms) for (const auto &it : params_derivs_temporary_terms)
writeJsonTemporaryTerms(it.second, temp_term_union, model_output, tef_terms, concat); writeJsonTemporaryTerms(it.second, temp_term_union, model_output, tef_terms, concat);
jacobian_output << "\"deriv_wrt_params\": {" jacobian_output << R"("deriv_wrt_params": {)"
<< " \"neqs\": " << equations.size() << R"( "neqs": )" << equations.size()
<< ", \"nparamcols\": " << symbol_table.param_nbr() << R"(, "nparamcols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &rp = params_derivatives.find({ 0, 1 })->second; auto &rp = params_derivatives.find({ 0, 1 })->second;
for (auto it = rp.begin(); it != rp.end(); it++) for (auto it = rp.begin(); it != rp.end(); it++)
{ {
@ -3101,26 +3101,26 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
if (writeDetails) if (writeDetails)
jacobian_output << "{\"eq\": " << eq + 1; jacobian_output << R"({"eq": )" << eq + 1;
else else
jacobian_output << "{\"row\": " << eq + 1; jacobian_output << R"({"row": )" << eq + 1;
if (writeDetails) if (writeDetails)
jacobian_output << ", \"param_col\": " << param_col; jacobian_output << R"(, "param_col": )" << param_col;
jacobian_output << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; jacobian_output << R"(, "param": ")" << symbol_table.getName(getSymbIDByDerivID(param)) << R"(")";
jacobian_output << ", \"val\": \""; jacobian_output << R"(, "val": ")";
d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms); d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms);
jacobian_output << "\"}" << endl; jacobian_output << R"("})" << endl;
} }
jacobian_output << "]}"; jacobian_output << "]}";
hessian_output << "\"deriv_jacobian_wrt_params\": {" hessian_output << R"("deriv_jacobian_wrt_params": {)"
<< " \"neqs\": " << equations.size() << R"( "neqs": )" << equations.size()
<< ", \"nvarcols\": " << symbol_table.endo_nbr() << R"(, "nvarcols": )" << symbol_table.endo_nbr()
<< ", \"nparamcols\": " << symbol_table.param_nbr() << R"(, "nparamcols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &gp = params_derivatives.find({ 1, 1 })->second; auto &gp = params_derivatives.find({ 1, 1 })->second;
for (auto it = gp.begin(); it != gp.end(); it++) for (auto it = gp.begin(); it != gp.end(); it++)
{ {
@ -3135,27 +3135,27 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
if (writeDetails) if (writeDetails)
hessian_output << "{\"eq\": " << eq + 1; hessian_output << R"({"eq": )" << eq + 1;
else else
hessian_output << "{\"row\": " << eq + 1; hessian_output << R"({"row": )" << eq + 1;
if (writeDetails) if (writeDetails)
hessian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" hessian_output << R"(, "var": ")" << symbol_table.getName(getSymbIDByDerivID(var)) << R"(")"
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; << R"(, "param": ")" << symbol_table.getName(getSymbIDByDerivID(param)) << R"(")";
hessian_output << ", \"var_col\": " << var_col hessian_output << R"(, "var_col": )" << var_col
<< ", \"param_col\": " << param_col << R"(, "param_col": )" << param_col
<< ", \"val\": \""; << R"(, "val": ")";
d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms); d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms);
hessian_output << "\"}" << endl; hessian_output << R"("})" << endl;
} }
hessian_output << "]}"; hessian_output << "]}";
hessian1_output << "\"second_deriv_residuals_wrt_params\": {" hessian1_output << R"("second_deriv_residuals_wrt_params": {)"
<< " \"nrows\": " << equations.size() << R"( "nrows": )" << equations.size()
<< ", \"nparam1cols\": " << symbol_table.param_nbr() << R"(, "nparam1cols": )" << symbol_table.param_nbr()
<< ", \"nparam2cols\": " << symbol_table.param_nbr() << R"(, "nparam2cols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &rpp = params_derivatives.find({ 0, 2 })->second; auto &rpp = params_derivatives.find({ 0, 2 })->second;
for (auto it = rpp.begin(); it != rpp.end(); ++it) for (auto it = rpp.begin(); it != rpp.end(); ++it)
{ {
@ -3170,29 +3170,29 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
if (writeDetails) if (writeDetails)
hessian1_output << "{\"eq\": " << eq + 1; hessian1_output << R"({"eq": )" << eq + 1;
else else
hessian1_output << "{\"row\": " << eq + 1; hessian1_output << R"({"row": )" << eq + 1;
hessian1_output << ", \"param1_col\": " << param1_col hessian1_output << R"(, "param1_col": )" << param1_col
<< ", \"param2_col\": " << param2_col; << R"(, "param2_col": )" << param2_col;
if (writeDetails) if (writeDetails)
hessian1_output << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" hessian1_output << R"(, "param1": ")" << symbol_table.getName(getSymbIDByDerivID(param1)) << R"(")"
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; << R"(, "param2": ")" << symbol_table.getName(getSymbIDByDerivID(param2)) << R"(")";
hessian1_output << ", \"val\": \""; hessian1_output << R"(, "val": ")";
d2->writeJsonOutput(hessian1_output, temp_term_union, tef_terms); d2->writeJsonOutput(hessian1_output, temp_term_union, tef_terms);
hessian1_output << "\"}" << endl; hessian1_output << R"("})" << endl;
} }
hessian1_output << "]}"; hessian1_output << "]}";
third_derivs_output << "\"second_deriv_jacobian_wrt_params\": {" third_derivs_output << R"("second_deriv_jacobian_wrt_params": {)"
<< " \"neqs\": " << equations.size() << R"( "neqs": )" << equations.size()
<< ", \"nvarcols\": " << symbol_table.endo_nbr() << R"(, "nvarcols": )" << symbol_table.endo_nbr()
<< ", \"nparam1cols\": " << symbol_table.param_nbr() << R"(, "nparam1cols": )" << symbol_table.param_nbr()
<< ", \"nparam2cols\": " << symbol_table.param_nbr() << R"(, "nparam2cols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &gpp = params_derivatives.find({ 1, 2 })->second; auto &gpp = params_derivatives.find({ 1, 2 })->second;
for (auto it = gpp.begin(); it != gpp.end(); ++it) for (auto it = gpp.begin(); it != gpp.end(); ++it)
{ {
@ -3208,30 +3208,30 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
if (writeDetails) if (writeDetails)
third_derivs_output << "{\"eq\": " << eq + 1; third_derivs_output << R"({"eq": )" << eq + 1;
else else
third_derivs_output << "{\"row\": " << eq + 1; third_derivs_output << R"({"row": )" << eq + 1;
third_derivs_output << ", \"var_col\": " << var_col third_derivs_output << R"(, "var_col": )" << var_col
<< ", \"param1_col\": " << param1_col << R"(, "param1_col": )" << param1_col
<< ", \"param2_col\": " << param2_col; << R"(, "param2_col": )" << param2_col;
if (writeDetails) if (writeDetails)
third_derivs_output << ", \"var\": \"" << symbol_table.getName(var) << "\"" third_derivs_output << R"(, "var": ")" << symbol_table.getName(var) << R"(")"
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" << R"(, "param1": ")" << symbol_table.getName(getSymbIDByDerivID(param1)) << R"(")"
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; << R"(, "param2": ")" << symbol_table.getName(getSymbIDByDerivID(param2)) << R"(")";
third_derivs_output << ", \"val\": \""; third_derivs_output << R"(, "val": ")";
d2->writeJsonOutput(third_derivs_output, temp_term_union, tef_terms); d2->writeJsonOutput(third_derivs_output, temp_term_union, tef_terms);
third_derivs_output << "\"}" << endl; third_derivs_output << R"("})" << endl;
} }
third_derivs_output << "]}" << endl; third_derivs_output << "]}" << endl;
third_derivs1_output << "\"derivative_hessian_wrt_params\": {" third_derivs1_output << R"("derivative_hessian_wrt_params": {)"
<< " \"neqs\": " << equations.size() << R"( "neqs": )" << equations.size()
<< ", \"nvar1cols\": " << symbol_table.endo_nbr() << R"(, "nvar1cols": )" << symbol_table.endo_nbr()
<< ", \"nvar2cols\": " << symbol_table.endo_nbr() << R"(, "nvar2cols": )" << symbol_table.endo_nbr()
<< ", \"nparamcols\": " << symbol_table.param_nbr() << R"(, "nparamcols": )" << symbol_table.param_nbr()
<< ", \"entries\": ["; << R"(, "entries": [)";
auto &hp = params_derivatives.find({ 2, 1 })->second; auto &hp = params_derivatives.find({ 2, 1 })->second;
for (auto it = hp.begin(); it != hp.end(); ++it) for (auto it = hp.begin(); it != hp.end(); ++it)
{ {
@ -3247,29 +3247,29 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
if (writeDetails) if (writeDetails)
third_derivs1_output << "{\"eq\": " << eq + 1; third_derivs1_output << R"({"eq": )" << eq + 1;
else else
third_derivs1_output << "{\"row\": " << eq + 1; third_derivs1_output << R"({"row": )" << eq + 1;
third_derivs1_output << ", \"var1_col\": " << var1_col third_derivs1_output << R"(, "var1_col": )" << var1_col
<< ", \"var2_col\": " << var2_col << R"(, "var2_col": )" << var2_col
<< ", \"param_col\": " << param_col; << R"(, "param_col": )" << param_col;
if (writeDetails) if (writeDetails)
third_derivs1_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" third_derivs1_output << R"(, "var1": ")" << symbol_table.getName(getSymbIDByDerivID(var1)) << R"(")"
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" << R"(, "var2": ")" << symbol_table.getName(getSymbIDByDerivID(var2)) << R"(")"
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; << R"(, "param1": ")" << symbol_table.getName(getSymbIDByDerivID(param)) << R"(")";
third_derivs1_output << ", \"val\": \""; third_derivs1_output << R"(, "val": ")";
d2->writeJsonOutput(third_derivs1_output, temp_term_union, tef_terms); d2->writeJsonOutput(third_derivs1_output, temp_term_union, tef_terms);
third_derivs1_output << "\"}" << endl; third_derivs1_output << R"("})" << endl;
} }
third_derivs1_output << "]}" << endl; third_derivs1_output << "]}" << endl;
if (writeDetails) if (writeDetails)
output << "\"static_model_params_derivative\": {"; output << R"("static_model_params_derivative": {)";
else else
output << "\"static_model_params_derivatives_simple\": {"; output << R"("static_model_params_derivatives_simple": {)";
output << model_local_vars_output.str() output << model_local_vars_output.str()
<< ", " << model_output.str() << ", " << model_output.str()
<< ", " << jacobian_output.str() << ", " << jacobian_output.str()

View File

@ -407,19 +407,19 @@ TrendComponentModelTable::writeJsonOutput(ostream &output) const
{ {
if (name != *(names.begin())) if (name != *(names.begin()))
output << ", "; output << ", ";
output << "{\"statementName\": \"trend_component_model\"," output << R"({"statementName": "trend_component_model",)"
<< "\"model_name\": \"" << name << "\"," << R"("model_name": ")" << name << R"(",)"
<< "\"eqtags\": ["; << R"("eqtags": [)";
for (const auto &it : eqtags.at(name)) for (const auto &it : eqtags.at(name))
{ {
output << "\"" << it << "\""; output << R"(")" << it << R"(")";
if (&it != &eqtags.at(name).back()) if (&it != &eqtags.at(name).back())
output << ", "; output << ", ";
} }
output << "], \"target_eqtags\": ["; output << R"(], "target_eqtags": [)";
for (const auto &it : target_eqtags.at(name)) for (const auto &it : target_eqtags.at(name))
{ {
output << "\"" << it << "\""; output << R"(")" << it << R"(")";
if (&it != &target_eqtags.at(name).back()) if (&it != &target_eqtags.at(name).back())
output << ", "; output << ", ";
} }
@ -547,21 +547,21 @@ VarModelTable::writeJsonOutput(ostream &output) const
{ {
if (name != *(names.begin())) if (name != *(names.begin()))
output << ", "; output << ", ";
output << "{\"statementName\": \"var_model\"," output << R"({"statementName": "var_model",)"
<< "\"model_name\": \"" << name << "\","; << R"("model_name": ")" << name << R"(",)";
if (symbol_list_and_order.empty()) if (symbol_list_and_order.empty())
{ {
output << "\"eqtags\": ["; output << R"("eqtags": [)";
for (const auto &it : eqtags.at(name)) for (const auto &it : eqtags.at(name))
{ {
output << "\"" << it << "\""; output << R"(")" << it << R"(")";
if (&it != &eqtags.at(name).back()) if (&it != &eqtags.at(name).back())
output << ", "; output << ", ";
} }
output << "]"; output << "]";
} }
else else
output << "\"order\": \"" << symbol_list_and_order.at(name).second << "\""; output << R"("order": ")" << symbol_list_and_order.at(name).second << R"(")";
output << "}"; output << "}";
} }
} }

View File

@ -42,13 +42,13 @@ SymbolList::writeOutput(const string &varname, ostream &output) const
void void
SymbolList::writeJsonOutput(ostream &output) const SymbolList::writeJsonOutput(ostream &output) const
{ {
output << "\"symbol_list\": ["; output << R"("symbol_list": [)";
for (auto it = symbols.begin(); for (auto it = symbols.begin();
it != symbols.end(); ++it) it != symbols.end(); ++it)
{ {
if (it != symbols.begin()) if (it != symbols.begin())
output << ","; output << ",";
output << "\"" << *it << "\""; output << R"(")" << *it << R"(")";
} }
output << "]"; output << "]";
} }

View File

@ -64,7 +64,7 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
size_t pos = 0; size_t pos = 0;
while ((pos = final_tex_name.find('_', pos)) != string::npos) while ((pos = final_tex_name.find('_', pos)) != string::npos)
{ {
final_tex_name.insert(pos, "\\"); final_tex_name.insert(pos, R"(\)");
pos += 2; pos += 2;
} }
} }
@ -375,7 +375,7 @@ SymbolTable::writeOutput(ostream &output) const noexcept(false)
output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl; output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl;
break; break;
case AuxVarType::expectation: case AuxVarType::expectation:
output << "M_.aux_vars(" << i+1 << ").orig_expr = '\\mathbb{E}_{t" output << "M_.aux_vars(" << i+1 << R"().orig_expr = '\mathbb{E}_{t)"
<< (aux_vars[i].get_information_set() < 0 ? "" : "+") << (aux_vars[i].get_information_set() < 0 ? "" : "+")
<< aux_vars[i].get_information_set() << "}("; << aux_vars[i].get_information_set() << "}(";
aux_vars[i].get_expr_node()->writeOutput(output, ExprNodeOutputType::latexDynamicModel); aux_vars[i].get_expr_node()->writeOutput(output, ExprNodeOutputType::latexDynamicModel);
@ -440,7 +440,7 @@ SymbolTable::writeCOutput(ostream &output) const noexcept(false)
{ {
output << "char *exo_names[" << exo_nbr() << "];" << endl; output << "char *exo_names[" << exo_nbr() << "];" << endl;
for (int id = 0; id < exo_nbr(); id++) for (int id = 0; id < exo_nbr(); id++)
output << "exo_names[" << id << "] = \"" << getName(exo_ids[id]) << "\";" << endl; output << "exo_names[" << id << R"(] = ")" << getName(exo_ids[id]) << R"(";)" << endl;
} }
output << endl output << endl
@ -449,7 +449,7 @@ SymbolTable::writeCOutput(ostream &output) const noexcept(false)
{ {
output << "char *exo_det_names[" << exo_det_nbr() << "];" << endl; output << "char *exo_det_names[" << exo_det_nbr() << "];" << endl;
for (int id = 0; id < exo_det_nbr(); id++) for (int id = 0; id < exo_det_nbr(); id++)
output << "exo_det_names[" << id << "] = \"" << getName(exo_det_ids[id]) << "\";" << endl; output << "exo_det_names[" << id << R"(] = ")" << getName(exo_det_ids[id]) << R"(";)" << endl;
} }
output << endl output << endl
@ -458,7 +458,7 @@ SymbolTable::writeCOutput(ostream &output) const noexcept(false)
{ {
output << "char *endo_names[" << endo_nbr() << "];" << endl; output << "char *endo_names[" << endo_nbr() << "];" << endl;
for (int id = 0; id < endo_nbr(); id++) for (int id = 0; id < endo_nbr(); id++)
output << "endo_names[" << id << "] = \"" << getName(endo_ids[id]) << "\";" << endl; output << "endo_names[" << id << R"(] = ")" << getName(endo_ids[id]) << R"(";)" << endl;
} }
output << endl output << endl
@ -467,7 +467,7 @@ SymbolTable::writeCOutput(ostream &output) const noexcept(false)
{ {
output << "char *param_names[" << param_nbr() << "];" << endl; output << "char *param_names[" << param_nbr() << "];" << endl;
for (int id = 0; id < param_nbr(); id++) for (int id = 0; id < param_nbr(); id++)
output << "param_names[" << id << "] = \"" << getName(param_ids[id]) << "\";" << endl; output << "param_names[" << id << R"(] = ")" << getName(param_ids[id]) << R"(";)" << endl;
} }
// Write the auxiliary variable table // Write the auxiliary variable table
@ -497,7 +497,7 @@ SymbolTable::writeCOutput(ostream &output) const noexcept(false)
if (aux_vars[i].get_orig_symb_id() >= 0) if (aux_vars[i].get_orig_symb_id() >= 0)
output << "av[" << i << "].orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl output << "av[" << i << "].orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
<< "av[" << i << "].orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl; << "av[" << i << "].orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
output << "av[" << i << "].unary_op = \"" << aux_vars[i].get_unary_op() << "\";" << endl; output << "av[" << i << R"(].unary_op = ")" << aux_vars[i].get_unary_op() << R"(";)" << endl;
break; break;
case AuxVarType::diff: case AuxVarType::diff:
case AuxVarType::diffLag: case AuxVarType::diffLag:
@ -562,22 +562,22 @@ SymbolTable::writeCCOutput(ostream &output) const noexcept(false)
output << endl output << endl
<< "exo_nbr = " << exo_nbr() << ";" << endl; << "exo_nbr = " << exo_nbr() << ";" << endl;
for (int id = 0; id < exo_nbr(); id++) for (int id = 0; id < exo_nbr(); id++)
output << "exo_names[\"" << getName(exo_ids[id]) << "\"] = " << id << ";" << endl; output << R"(exo_names[")" << getName(exo_ids[id]) << R"("] = )" << id << ";" << endl;
output << endl output << endl
<< "exo_det_nbr = " << exo_det_nbr() << ";" << endl; << "exo_det_nbr = " << exo_det_nbr() << ";" << endl;
for (int id = 0; id < exo_det_nbr(); id++) for (int id = 0; id < exo_det_nbr(); id++)
output << "exo_det_names[\"" << getName(exo_det_ids[id]) << "\"] = " << id << " ;" << endl; output << R"(exo_det_names[")" << getName(exo_det_ids[id]) << R"("] = )" << id << " ;" << endl;
output << endl output << endl
<< "endo_nbr = " << endo_nbr() << ";" << endl; << "endo_nbr = " << endo_nbr() << ";" << endl;
for (int id = 0; id < endo_nbr(); id++) for (int id = 0; id < endo_nbr(); id++)
output << "endo_names[\"" << getName(endo_ids[id]) << "\"] = " << id << ";" << endl; output << R"(endo_names[")" << getName(endo_ids[id]) << R"("] = )" << id << ";" << endl;
output << endl output << endl
<< "param_nbr = " << param_nbr() << ";" << endl; << "param_nbr = " << param_nbr() << ";" << endl;
for (int id = 0; id < param_nbr(); id++) for (int id = 0; id < param_nbr(); id++)
output << "param_names[\"" << getName(param_ids[id]) << "\"] = " << id << ";" << endl; output << R"(param_names[")" << getName(param_ids[id]) << R"("] = )" << id << ";" << endl;
// Write the auxiliary variable table // Write the auxiliary variable table
for (int i = 0; i < (int) aux_vars.size(); i++) for (int i = 0; i < (int) aux_vars.size(); i++)
@ -603,7 +603,7 @@ SymbolTable::writeCCOutput(ostream &output) const noexcept(false)
if (aux_vars[i].get_orig_symb_id() >= 0) if (aux_vars[i].get_orig_symb_id() >= 0)
output << "av" << i << ".orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl output << "av" << i << ".orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
<< "av" << i << ".orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl; << "av" << i << ".orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
output << "av" << i << ".unary_op = \"" << aux_vars[i].get_unary_op() << "\";" << endl; output << "av" << i << R"(.unary_op = ")" << aux_vars[i].get_unary_op() << R"(";)" << endl;
break; break;
case AuxVarType::diff: case AuxVarType::diff:
case AuxVarType::diffLag: case AuxVarType::diffLag:
@ -1123,10 +1123,10 @@ SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false)
<< "model_.endo = [" << endl; << "model_.endo = [" << endl;
if (endo_nbr() > 0) if (endo_nbr() > 0)
for (int id = 0; id < endo_nbr(); id++) for (int id = 0; id < endo_nbr(); id++)
output << " DynareModel.Endo(\"" output << R"( DynareModel.Endo(")"
<< getName(endo_ids[id]) << "\", raw\"" << getName(endo_ids[id]) << R"(", raw")"
<< getTeXName(endo_ids[id]) << "\", \"" << getTeXName(endo_ids[id]) << R"(", ")"
<< getLongName(endo_ids[id]) << "\")" << endl; << getLongName(endo_ids[id]) << R"("))" << endl;
output << " ]" << endl; output << " ]" << endl;
output << "model_.endo_nbr = " << endo_nbr() << ";" << endl; output << "model_.endo_nbr = " << endo_nbr() << ";" << endl;
@ -1134,10 +1134,10 @@ SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false)
<< "model_.exo = [" << endl; << "model_.exo = [" << endl;
if (exo_nbr() > 0) if (exo_nbr() > 0)
for (int id = 0; id < exo_nbr(); id++) for (int id = 0; id < exo_nbr(); id++)
output << " DynareModel.Exo(\"" output << R"( DynareModel.Exo(")"
<< getName(exo_ids[id]) << "\", raw\"" << getName(exo_ids[id]) << R"(", raw")"
<< getTeXName(exo_ids[id]) << "\", \"" << getTeXName(exo_ids[id]) << R"(", ")"
<< getLongName(exo_ids[id]) << "\")" << endl; << getLongName(exo_ids[id]) << R"("))" << endl;
output << " ]" << endl; output << " ]" << endl;
output << "model_.exo_nbr = " << exo_nbr() << ";" << endl; output << "model_.exo_nbr = " << exo_nbr() << ";" << endl;
@ -1147,10 +1147,10 @@ SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false)
<< "model_.exo_det = [" << endl; << "model_.exo_det = [" << endl;
if (exo_det_nbr() > 0) if (exo_det_nbr() > 0)
for (int id = 0; id < exo_det_nbr(); id++) for (int id = 0; id < exo_det_nbr(); id++)
output << " DynareModel.ExoDet(\"" output << R"( DynareModel.ExoDet(")"
<< getName(exo_det_ids[id]) << "\", raw\"" << getName(exo_det_ids[id]) << R"(", raw")"
<< getTeXName(exo_det_ids[id]) << "\", \"" << getTeXName(exo_det_ids[id]) << R"(", ")"
<< getLongName(exo_det_ids[id]) << "\")" << endl; << getLongName(exo_det_ids[id]) << R"("))" << endl;
output << " ]" << endl; output << " ]" << endl;
output << "model_.exo_det_nbr = " << exo_det_nbr() << ";" << endl; output << "model_.exo_det_nbr = " << exo_det_nbr() << ";" << endl;
} }
@ -1159,10 +1159,10 @@ SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false)
<< "model_.param = [" << endl; << "model_.param = [" << endl;
if (param_nbr() > 0) if (param_nbr() > 0)
for (int id = 0; id < param_nbr(); id++) for (int id = 0; id < param_nbr(); id++)
output << " DynareModel.Param(\"" output << R"( DynareModel.Param(")"
<< getName(param_ids[id]) << "\", raw\"" << getName(param_ids[id]) << R"(", raw")"
<< getTeXName(param_ids[id]) << "\", \"" << getTeXName(param_ids[id]) << R"(", ")"
<< getLongName(param_ids[id]) << "\")" << endl; << getLongName(param_ids[id]) << R"("))" << endl;
output << " ]" << endl; output << " ]" << endl;
output << "model_.param_nbr = " << param_nbr() << ";" << endl; output << "model_.param_nbr = " << param_nbr() << ";" << endl;
@ -1193,7 +1193,7 @@ SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false)
else else
output << "typemin(Int), typemin(Int)"; output << "typemin(Int), typemin(Int)";
output << ", typemin(Int), string(), " output << ", typemin(Int), string(), "
<< "\"" << aux_var.get_unary_op() << "\"" << endl; << R"(")" << aux_var.get_unary_op() << R"(")" << endl;
break; break;
case AuxVarType::diff: case AuxVarType::diff:
case AuxVarType::diffLag: case AuxVarType::diffLag:
@ -1210,11 +1210,11 @@ SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false)
output << getTypeSpecificID(aux_var.get_orig_symb_id())+1 << ", typemin(Int), typemin(Int), string(), string()"; output << getTypeSpecificID(aux_var.get_orig_symb_id())+1 << ", typemin(Int), typemin(Int), string(), string()";
break; break;
case AuxVarType::expectation: case AuxVarType::expectation:
output << "typemin(Int), typemin(Int), typemin(Int), \"\\mathbb{E}_{t" output << R"(typemin(Int), typemin(Int), typemin(Int), "\mathbb{E}_{t)"
<< (aux_var.get_information_set() < 0 ? "" : "+") << (aux_var.get_information_set() < 0 ? "" : "+")
<< aux_var.get_information_set() << "}("; << aux_var.get_information_set() << "}(";
aux_var.get_expr_node()->writeOutput(output, ExprNodeOutputType::latexDynamicModel); aux_var.get_expr_node()->writeOutput(output, ExprNodeOutputType::latexDynamicModel);
output << ")\""; output << R"lit()")lit";
break; break;
default: default:
output << " typemin(Int), typemin(Int), typemin(Int), string(), string()"; output << " typemin(Int), typemin(Int), typemin(Int), string(), string()";
@ -1248,16 +1248,16 @@ SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false)
void void
SymbolTable::writeJsonOutput(ostream &output) const SymbolTable::writeJsonOutput(ostream &output) const
{ {
output << "\"endogenous\": "; output << R"("endogenous": )";
writeJsonVarVector(output, endo_ids); writeJsonVarVector(output, endo_ids);
output << ", \"exogenous\":"; output << R"(, "exogenous":)";
writeJsonVarVector(output, exo_ids); writeJsonVarVector(output, exo_ids);
output << ", \"exogenous_deterministic\": "; output << R"(, "exogenous_deterministic": )";
writeJsonVarVector(output, exo_det_ids); writeJsonVarVector(output, exo_det_ids);
output << ", \"parameters\": "; output << R"(, "parameters": )";
writeJsonVarVector(output, param_ids); writeJsonVarVector(output, param_ids);
} }
@ -1270,9 +1270,9 @@ SymbolTable::writeJsonVarVector(ostream &output, const vector<int> &varvec) cons
if (i != 0) if (i != 0)
output << ", "; output << ", ";
output << "{" output << "{"
<< "\"name\":\"" << getName(varvec[i]) << "\", " << R"("name":")" << getName(varvec[i]) << R"(", )"
<< "\"texName\":\"" << boost::replace_all_copy(getTeXName(varvec[i]), "\\", "\\\\") << "\", " << R"("texName":")" << boost::replace_all_copy(getTeXName(varvec[i]), R"(\)", R"(\\)") << R"(", )"
<< "\"longName\":\"" << boost::replace_all_copy(getLongName(varvec[i]), "\\", "\\\\") << "\"}" << R"("longName":")" << boost::replace_all_copy(getLongName(varvec[i]), R"(\)", R"(\\)") << R"("})"
<< endl; << endl;
} }
output << "]" << endl; output << "]" << endl;

View File

@ -53,7 +53,7 @@ MacroDriver::parse(const string &file_arg, const string &basename_arg, istream &
// If the input is an array. Issue #1578 // If the input is an array. Issue #1578
file_with_endl << "@#define " << define.first << " = " << define.second << endl; file_with_endl << "@#define " << define.first << " = " << define.second << endl;
else else
file_with_endl << "@#define " << define.first << " = \"" << define.second << "\"" << endl; file_with_endl << "@#define " << define.first << R"( = ")" << define.second << R"(")" << endl;
} }
file_with_endl << modfile.rdbuf() << endl; file_with_endl << modfile.rdbuf() << endl;
@ -65,7 +65,7 @@ MacroDriver::parse(const string &file_arg, const string &basename_arg, istream &
// Output first @#line statement // Output first @#line statement
if (!no_line_macro) if (!no_line_macro)
out << "@#line \"" << file << "\" 1" << endl; out << R"(@#line ")" << file << R"(" 1)" << endl;
// Launch macro-processing // Launch macro-processing
parser.parse(); parser.parse();
@ -88,7 +88,7 @@ MacroDriver::replace_vars_in_str(const string &s) const
smatch name; smatch name;
string name_str ("[A-Za-z_][A-Za-z0-9_]*"); string name_str ("[A-Za-z_][A-Za-z0-9_]*");
regex name_regex (name_str); // Matches NAME regex name_regex (name_str); // Matches NAME
regex macro_regex ("@\\s*\\{\\s*" + name_str + "\\s*\\}"); // Matches @{NAME} with potential whitespace regex macro_regex (R"(@\s*\{\s*)" + name_str + R"(\s*\})"); // Matches @{NAME} with potential whitespace
for(sregex_iterator it = sregex_iterator(s.begin(), s.end(), macro_regex); for(sregex_iterator it = sregex_iterator(s.begin(), s.end(), macro_regex);
it != std::sregex_iterator(); ++it) it != std::sregex_iterator(); ++it)
{ {
@ -412,7 +412,7 @@ MacroDriver::printvars(const Macro::parser::location_type &l, const bool tostdou
stringstream intomfile; stringstream intomfile;
if (!no_line_macro) if (!no_line_macro)
intomfile << "@#line \"" << file << "\" " << l.begin.line << endl; intomfile << R"(@#line ")" << file << R"(" )" << l.begin.line << endl;
for (const auto & it : env) for (const auto & it : env)
intomfile<< "options_.macrovars_line_" << l.begin.line << "." << it.first << " = " << it.second->print() << ";" << endl; intomfile<< "options_.macrovars_line_" << l.begin.line << "." << it.first << " = " << it.second->print() << ";" << endl;