From a5743ae743916287e03c8ed9fdcd4c68d23418d5 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Thu, 6 Feb 2020 15:25:14 +0100
Subject: [PATCH] add undocumented `gui` option to preprocessor

(cherry picked from commit ac4749edf99b8acf1b690872d7d28f633fa777a0)

# Conflicts:
#	src/DynareMain.cc
#	src/ModFile.cc
---
 src/DynareMain.cc  | 9 ++++++---
 src/DynareMain2.cc | 6 +++---
 src/ModFile.cc     | 8 ++++++--
 src/ModFile.hh     | 2 +-
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/DynareMain.cc b/src/DynareMain.cc
index 490b82e7..26d4f7fc 100644
--- a/src/DynareMain.cc
+++ b/src/DynareMain.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2003-2019 Dynare Team
+ * Copyright © 2003-2020 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -49,7 +49,7 @@ void main2(stringstream &in, const string &basename, bool debug, bool clear_all,
            const string &exclude_eqs, const string &include_eqs,
            JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple,
            const string &mexext, const filesystem::path &matlabroot,
-           const filesystem::path &dynareroot, bool onlymodel);
+           const filesystem::path &dynareroot, bool onlymodel, bool gui);
 
 void main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file,
            bool line_macro, const vector<pair<string, string>> &defines, vector<filesystem::path> &paths, stringstream &macro_output);
@@ -153,6 +153,7 @@ main(int argc, char **argv)
   bool minimal_workspace = false;
   bool compute_xrefs = false;
   bool transform_unary_ops = false;
+  bool gui = false;
   string exclude_eqs, include_eqs;
   vector<pair<string, string>> defines;
   vector<filesystem::path> paths;
@@ -398,6 +399,8 @@ main(int argc, char **argv)
         }
       else if (s == "onlymodel")
         onlymodel = true;
+      else if (s == "gui")
+        gui = true;
       else
         {
           cerr << "Unknown option: " << s << endl;
@@ -446,7 +449,7 @@ main(int argc, char **argv)
         parallel, config_file, warnings, nostrict, stochastic, check_model_changes, minimal_workspace,
         compute_xrefs, output_mode, language, params_derivs_order, transform_unary_ops, exclude_eqs, include_eqs,
         json, json_output_mode, onlyjson, jsonderivsimple,
-        mexext, matlabroot, dynareroot, onlymodel);
+        mexext, matlabroot, dynareroot, onlymodel, gui);
 
   return EXIT_SUCCESS;
 }
diff --git a/src/DynareMain2.cc b/src/DynareMain2.cc
index abcb9dda..b31e31f4 100644
--- a/src/DynareMain2.cc
+++ b/src/DynareMain2.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2008-2019 Dynare Team
+ * Copyright © 2008-2020  Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -35,7 +35,7 @@ main2(stringstream &in, const string &basename, bool debug, bool clear_all, bool
       const string &exclude_eqs, const string &include_eqs,
       JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple,
       const string &mexext, const filesystem::path &matlabroot,
-      const filesystem::path &dynareroot, bool onlymodel)
+      const filesystem::path &dynareroot, bool onlymodel, bool gui)
 {
   ParsingDriver p(warnings, nostrict);
 
@@ -71,7 +71,7 @@ main2(stringstream &in, const string &basename, bool debug, bool clear_all, bool
   else
     mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph,
                                nointeractive, config_file, check_model_changes, minimal_workspace, compute_xrefs,
-                               mexext, matlabroot, dynareroot, onlymodel);
+                               mexext, matlabroot, dynareroot, onlymodel, gui);
 
   cout << "Preprocessing completed." << endl;
 }
diff --git a/src/ModFile.cc b/src/ModFile.cc
index 84e2588d..d6dec070 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -839,7 +839,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
                           bool check_model_changes, bool minimal_workspace, bool compute_xrefs,
                           const string &mexext,
                           const filesystem::path &matlabroot,
-                          const filesystem::path &dynareroot, bool onlymodel) const
+                          const filesystem::path &dynareroot, bool onlymodel, bool gui) const
 {
   bool hasModelChanged = !dynamic_model.isChecksumMatching(basename, block) || !check_model_changes;
   if (hasModelChanged)
@@ -1024,7 +1024,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
         static_model.writeOutput(mOutputFile, block);
     }
 
-  if (onlymodel)
+  if (onlymodel || gui)
     for (auto &statement : statements)
       {
         /* Special treatment for initval block: insert initial values for the
@@ -1054,6 +1054,10 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
 
         if (auto sgs = dynamic_cast<ShockGroupsStatement *>(statement.get()); sgs)
           sgs->writeOutput(mOutputFile, basename, minimal_workspace);
+
+        if (gui)
+          if (auto it = dynamic_cast<NativeStatement *>(statement.get()); it)
+            it->writeOutput(mOutputFile, basename, minimal_workspace);
       }
   else
     {
diff --git a/src/ModFile.hh b/src/ModFile.hh
index 7eaa88b3..ae53b468 100644
--- a/src/ModFile.hh
+++ b/src/ModFile.hh
@@ -168,7 +168,7 @@ public:
                         bool console, bool nograph, bool nointeractive, const ConfigFile &config_file,
                         bool check_model_changes, bool minimal_workspace, bool compute_xrefs,
                         const string &mexext, const filesystem::path &matlabroot,
-                        const filesystem::path &dynareroot, bool onlymodel) const;
+                        const filesystem::path &dynareroot, bool onlymodel, bool gui) const;
   void writeExternalFiles(const string &basename, LanguageOutputType language) const;
   void writeExternalFilesJulia(const string &basename) const;
 
-- 
GitLab