From ac4749edf99b8acf1b690872d7d28f633fa777a0 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

---
 src/DynareMain.cc | 5 ++++-
 src/ModFile.cc    | 8 ++++++--
 src/ModFile.hh    | 2 +-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/DynareMain.cc b/src/DynareMain.cc
index 9429c978..d9621dc4 100644
--- a/src/DynareMain.cc
+++ b/src/DynareMain.cc
@@ -145,6 +145,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;
@@ -390,6 +391,8 @@ main(int argc, char **argv)
         }
       else if (s == "onlymodel")
         onlymodel = true;
+      else if (s == "gui")
+        gui = true;
       else
         {
           cerr << "Unknown option: " << s << endl;
@@ -471,7 +474,7 @@ main(int argc, char **argv)
   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;
   return EXIT_SUCCESS;
diff --git a/src/ModFile.cc b/src/ModFile.cc
index 293a8980..4b225a1f 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 (const 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