From ed3e74994f14e2e826b860e53c7e0fab986232aa Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 28 Feb 2017 14:34:22 +0100 Subject: [PATCH] preprocessor: add onlyjson option to allow exit upon writing of JSON output. #1387 --- matlab/dynare.m | 4 ++-- preprocessor/DynareMain.cc | 9 ++++++--- preprocessor/DynareMain2.cc | 10 +++++----- preprocessor/ModFile.cc | 5 ++++- preprocessor/ModFile.hh | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index 4eb83c291..34ee71148 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -195,8 +195,8 @@ if ismember('onlymacro', varargin) return; end -if ismember('language=json', varargin) - disp('Preprocesser stopped after preprocessing step because of ''language=json'' option.'); +if ismember('onlyjson', varargin) + disp('Preprocesser stopped after preprocessing step because of ''onlyjson'' option.'); return; end diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc index cd62325c9..3aa0aa3f7 100644 --- a/preprocessor/DynareMain.cc +++ b/preprocessor/DynareMain.cc @@ -45,7 +45,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) , bool cygwin, bool msvc, bool mingw #endif - , JsonOutputPointType json, JsonFileOutputType json_output_mode + , JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson ); void main1(char *modfile, string &basename, bool debug, bool save_macro, string &save_macro_file, @@ -62,7 +62,7 @@ usage() #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) << " [cygwin] [msvc] [mingw]" #endif - << "[json=parse|check|transform|compute] [jsonstdout]" + << "[json=parse|check|transform|compute] [jsonstdout] [onlyjson]" << endl; exit(EXIT_FAILURE); } @@ -117,6 +117,7 @@ main(int argc, char **argv) FileOutputType output_mode = none; JsonOutputPointType json = nojson; JsonFileOutputType json_output_mode = file; + bool onlyjson = false; LanguageOutputType language = matlab; // Parse options @@ -297,6 +298,8 @@ main(int argc, char **argv) } else if (!strcmp(argv[arg], "jsonstdout")) json_output_mode = standardout; + else if (!strcmp(argv[arg], "onlyjson")) + onlyjson = true; else if (strlen(argv[arg]) >= 4 && !strncmp(argv[arg], "json", 4)) { if (strlen(argv[arg]) <= 5 || argv[arg][4] != '=') @@ -364,7 +367,7 @@ main(int argc, char **argv) #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) , cygwin, msvc, mingw #endif - , json, json_output_mode + , json, json_output_mode, onlyjson ); return EXIT_SUCCESS; diff --git a/preprocessor/DynareMain2.cc b/preprocessor/DynareMain2.cc index bc2d34ffc..5139cd3d1 100644 --- a/preprocessor/DynareMain2.cc +++ b/preprocessor/DynareMain2.cc @@ -34,7 +34,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) , bool cygwin, bool msvc, bool mingw #endif - , JsonOutputPointType json, JsonFileOutputType json_output_mode + , JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson ) { ParsingDriver p(warnings, nostrict); @@ -42,17 +42,17 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear // Do parsing and construct internal representation of mod file ModFile *mod_file = p.parse(in, debug); if (json == parsing) - mod_file->writeJsonOutput(basename, json, json_output_mode); + mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); // Run checking pass mod_file->checkPass(nostrict); if (json == checkpass) - mod_file->writeJsonOutput(basename, json, json_output_mode); + mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); // Perform transformations on the model (creation of auxiliary vars and equations) mod_file->transformPass(nostrict); if (json == transformpass) - mod_file->writeJsonOutput(basename, json, json_output_mode); + mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); // Evaluate parameters initialization, initval, endval and pounds mod_file->evalAllExpressions(warn_uninit); @@ -60,7 +60,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear // Do computations mod_file->computingPass(no_tmp_terms, output_mode, compute_xrefs, params_derivs_order); if (json == computingpass) - mod_file->writeJsonOutput(basename, json, json_output_mode); + mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); // Write outputs if (output_mode != none) diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 4228a393c..32cb70bff 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -1248,7 +1248,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output) } void -ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode) +ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson) { if (json == nojson) return; @@ -1282,6 +1282,9 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF cerr << "ModFile::writeJsonOutput: should not arrive here." << endl; exit(EXIT_FAILURE); } + + if (onlyjson) + exit(EXIT_SUCCESS); } void diff --git a/preprocessor/ModFile.hh b/preprocessor/ModFile.hh index 684d592ee..385e97b69 100644 --- a/preprocessor/ModFile.hh +++ b/preprocessor/ModFile.hh @@ -174,7 +174,7 @@ public: //! Initially created to enable Julia to work with .mod files //! Potentially outputs ModFile after the various parts of processing (parsing, checkPass, transformPass, computingPass) //! Allows user of other host language platforms (python, fortran, etc) to provide support for dynare .mod files - void writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode); + void writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson); }; #endif // ! MOD_FILE_HH