From 35831c5c46ec177a1ac67dc9ff95aa6a4f7d34c7 Mon Sep 17 00:00:00 2001
From: Michel Juillard <michel.juillard@mjui.fr>
Date: Sun, 20 Apr 2014 11:12:12 +0200
Subject: [PATCH] changed line options for extended preprocessor, adding
 language option renamed FileOutputType.hh as ExtendedPreprocessorTypes.hh
 updated Makefile.am

---
 preprocessor/DynareMain.cc                    | 39 ++++++++++++++-----
 preprocessor/DynareMain2.cc                   |  4 +-
 ...utType.hh => ExtendedPreprocessorTypes.hh} | 22 ++++++++---
 preprocessor/Makefile.am                      |  2 +-
 preprocessor/ModFile.hh                       |  2 +-
 5 files changed, 50 insertions(+), 19 deletions(-)
 rename preprocessor/{FileOutputType.hh => ExtendedPreprocessorTypes.hh} (57%)

diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc
index 1f99d8746d..016488682a 100644
--- a/preprocessor/DynareMain.cc
+++ b/preprocessor/DynareMain.cc
@@ -29,7 +29,7 @@
 #include "macro/MacroDriver.hh"
 
 #include <unistd.h>
-#include "FileOutputType.hh"
+#include "ExtendedPreprocessorTypes.hh"
 
 /* Prototype for second part of main function
    Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be
@@ -37,7 +37,7 @@
 */
 void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, 
            bool parallel, const string &parallel_config_file, const string &cluster_name, bool parallel_slave_open_mode,
-           bool parallel_test, bool nostrict, FileOutputType output_mode, bool cuda
+           bool parallel_test, bool nostrict, FileOutputType output_mode, LanguageOutputType lang
 #if defined(_WIN32) || defined(__CYGWIN32__)
            , bool cygwin, bool msvc
 #endif
@@ -48,7 +48,7 @@ usage()
 {
   cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]"
        << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test] "
-       << " [-D<variable>[=<value>]] [nostrict] [-double=dynamic|first|second|third] [cuda]"
+       << " [-D<variable>[=<value>]] [nostrict] [output=dynamic|first|second|third] [language=C|C++]"
 #if defined(_WIN32) || defined(__CYGWIN32__)
        << " [cygwin] [msvc]"
 #endif
@@ -97,7 +97,7 @@ main(int argc, char **argv)
   bool nostrict = false;
   map<string, string> defines;
   FileOutputType output_mode = none;
-  bool cuda = false;
+  LanguageOutputType language = matlab;
 
   // Parse options
   for (int arg = 2; arg < argc; arg++)
@@ -199,8 +199,6 @@ main(int argc, char **argv)
 	      cerr << "Incorrect syntax for ouput option" << endl;
 	      usage();
 	    }
-	  // we don't want temp terms in CC functions
-	  no_tmp_terms = true;
 	  if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 7, "dynamic", 7))
 	    output_mode = dynamic;
 	  else if (strlen(argv[arg]) ==  12 && !strncmp(argv[arg] + 7, "first", 5))
@@ -215,8 +213,31 @@ main(int argc, char **argv)
 	      usage();
             }
         }
-      else if (!strcmp(argv[arg], "cuda"))
-        cuda = true;
+      else if (strlen(argv[arg]) >= 8 && !strncmp(argv[arg], "language", 8))
+        {
+	  if (strlen(argv[arg]) <= 9 || argv[arg][6] != '=')
+	    {
+	      cerr << "Incorrect syntax for language option" << endl;
+	      usage();
+	    }
+	  // we don't want temp terms in external functions
+	  no_tmp_terms = true;
+	  if (strlen(argv[arg]) == 10 && !strncmp(argv[arg] + 9, "C", 1))
+	    language = c;
+	  else if (strlen(argv[arg]) ==  12 && !strncmp(argv[arg] + 9, "C++", 3))
+	    language = cpp;
+	  else if (strlen(argv[arg]) == 13 && !strncmp(argv[arg] + 9, "cuda", 4))
+	    language = cuda;
+	  else if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 9, "julia", 5))
+	    language = julia;
+	  else if (strlen(argv[arg]) == 15 && !strncmp(argv[arg] + 9, "python", 6))
+	    language = python;
+	  else
+	    {
+	      cerr << "Incorrect syntax for ouput option" << endl;
+	      usage();
+            }
+        }
       else
         {
           cerr << "Unknown option: " << argv[arg] << endl;
@@ -257,7 +278,7 @@ main(int argc, char **argv)
 
   // Do the rest
   main2(macro_output, basename, debug, clear_all, no_tmp_terms, no_log, no_warn, warn_uninit, console, nograph, nointeractive, 
-        parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test, nostrict, output_mode, cuda
+        parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test, nostrict, output_mode, language
 #if defined(_WIN32) || defined(__CYGWIN32__)
         , cygwin, msvc
 #endif
diff --git a/preprocessor/DynareMain2.cc b/preprocessor/DynareMain2.cc
index 2f0f30a3c3..60a06064ae 100644
--- a/preprocessor/DynareMain2.cc
+++ b/preprocessor/DynareMain2.cc
@@ -22,12 +22,12 @@
 #include "ParsingDriver.hh"
 #include "ModFile.hh"
 #include "ConfigFile.hh"
-#include "FileOutputType.hh"
+#include "ExtendedPreprocessorTypes.hh"
 
 void
 main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive,
       bool parallel, const string &parallel_config_file, const string &cluster_name, bool parallel_slave_open_mode,
-      bool parallel_test, bool nostrict, FileOutputType output_mode, bool cuda
+      bool parallel_test, bool nostrict, FileOutputType output_mode, LanguageOutputType lang
 #if defined(_WIN32) || defined(__CYGWIN32__)
       , bool cygwin, bool msvc
 #endif
diff --git a/preprocessor/FileOutputType.hh b/preprocessor/ExtendedPreprocessorTypes.hh
similarity index 57%
rename from preprocessor/FileOutputType.hh
rename to preprocessor/ExtendedPreprocessorTypes.hh
index 8f4e681f39..d9a210e770 100644
--- a/preprocessor/FileOutputType.hh
+++ b/preprocessor/ExtendedPreprocessorTypes.hh
@@ -17,15 +17,25 @@
  * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _FILE_OUTPUT_TYPE_HH
-#define _FILE_OUTPUT_TYPE_HH
+#ifndef _EXTENDED_PREPROCESSOR_TYPES_HH
+#define _EXTENDED_PREPROCESSOR_TYPES_HH
 
 enum FileOutputType
   {
     none,                             // outputs files for Matlab/Octave processing
-    dynamic,                          // outputs <fname>_dynamic.cc and related files
-    first,                            // outputs <fname>_first_derivatives and related files 
-    second,                           // outputs <fname>_first_derivatives, <fname>_second_derivatives.cc and related files 
-    third,                            // outputs <fname>_first_derivatives, <fname>_second_derivatives.cc, <fname>_third_derivatives.cc  and related files 
+    dynamic,                          // outputs <fname>_dynamic.* and related files
+    first,                            // outputs <fname>_first_derivatives.* and related files 
+    second,                           // outputs <fname>_first_derivatives.*, <fname>_second_derivatives.* and related files 
+    third,                            // outputs <fname>_first_derivatives.*, <fname>_second_derivatives.*, <fname>_third_derivatives.*  and related files 
+  };
+
+enum LanguageOutputType
+  {
+    matlab,                           // outputs files for Matlab/Octave processing
+    c,                                // outputs files for C
+    cpp,                              // outputs files for C++
+    cuda,                             // outputs files for CUDA (not yet implemented)
+    julia,                            // outputs files for Julia (not yet implemented)
+    python,                           // outputs files for Python (not yet implemented) (not yet implemented)
   };
 #endif
diff --git a/preprocessor/Makefile.am b/preprocessor/Makefile.am
index 91112aefe0..fc33ec33ff 100644
--- a/preprocessor/Makefile.am
+++ b/preprocessor/Makefile.am
@@ -53,7 +53,7 @@ dynare_m_SOURCES = \
 	SteadyStateModel.cc \
 	WarningConsolidation.hh \
 	WarningConsolidation.cc \
-	FileOutputType.hh
+	ExtendedPreprocessorTypes.hh
 
 # The -I. is for <FlexLexer.h>
 dynare_m_CPPFLAGS = $(BOOST_CPPFLAGS) -I.
diff --git a/preprocessor/ModFile.hh b/preprocessor/ModFile.hh
index f680936197..8b22f2db6c 100644
--- a/preprocessor/ModFile.hh
+++ b/preprocessor/ModFile.hh
@@ -35,7 +35,7 @@ using namespace std;
 #include "ExternalFunctionsTable.hh"
 #include "ConfigFile.hh"
 #include "WarningConsolidation.hh"
-#include "FileOutputType.hh"
+#include "ExtendedPreprocessorTypes.hh"
 
 //! The abstract representation of a "mod" file
 class ModFile
-- 
GitLab