preprocessor: add onlyjson option to allow exit upon writing of JSON output. #1387

issue#70
Houtan Bastani 2017-02-28 14:34:22 +01:00
parent 301c9691d9
commit 32a08f8db0
4 changed files with 16 additions and 10 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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

View File

@ -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