From b155cb56bafe45298f2c98b5a9b363d97d51d2bc Mon Sep 17 00:00:00 2001
From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Fri, 28 Mar 2008 17:21:45 +0000
Subject: [PATCH] v4 preprocessor: minor improvement related to debugging of
 scanning & parsing

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1751 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 preprocessor/DynareMain.cc            | 18 ++++++------------
 preprocessor/DynareMain2.cc           |  6 ++----
 preprocessor/ParsingDriver.cc         |  5 +++--
 preprocessor/include/ParsingDriver.hh | 14 ++++----------
 preprocessor/macro/MacroDriver.cc     |  5 +++--
 preprocessor/macro/MacroDriver.hh     | 14 ++++----------
 6 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc
index 1381e789a2..36f1749315 100644
--- a/preprocessor/DynareMain.cc
+++ b/preprocessor/DynareMain.cc
@@ -32,8 +32,7 @@ using namespace std;
    Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be
    included simultaneously (because of Bison limitations).
 */
-void main2(stringstream &in, string &basename, bool trace_scanning, bool trace_parsing,
-           bool clear_all);
+void main2(stringstream &in, string &basename, bool debug, bool clear_all);
 
 int
 main(int argc, char** argv)
@@ -47,17 +46,13 @@ main(int argc, char** argv)
 
   bool clear_all = true;
   bool save_macro = false;
-  bool trace_scanning = false;
-  bool trace_parsing = false;
+  bool debug = false;
 
   // Parse options
   for (int arg = 2; arg < argc; arg++)
     {
       if (string(argv[arg]) == string("debug"))
-        {
-          trace_scanning = true;
-          trace_parsing = true;
-        }
+        debug = true;
       else if (string(argv[arg]) == string("noclearall"))
         clear_all = false;
       else if (string(argv[arg]) == string("savemacro"))
@@ -79,9 +74,8 @@ main(int argc, char** argv)
   basename.erase(basename.size() - 4, 4);
 
   // Do macro processing
-  MacroDriver m;
-  m.trace_scanning = trace_scanning;
-  m.trace_parsing = trace_parsing;
+  MacroDriver m(debug);
+
   stringstream macro_output;
   m.parse(argv[1], macro_output);
   if (save_macro)
@@ -92,7 +86,7 @@ main(int argc, char** argv)
     }
 
   // Do the rest
-  main2(macro_output, basename, trace_scanning, trace_parsing, clear_all);
+  main2(macro_output, basename, debug, clear_all);
 
   return 0;
 }
diff --git a/preprocessor/DynareMain2.cc b/preprocessor/DynareMain2.cc
index 39480cbc5d..3d2b53a7b2 100644
--- a/preprocessor/DynareMain2.cc
+++ b/preprocessor/DynareMain2.cc
@@ -25,11 +25,9 @@ using namespace std;
 #include "ModFile.hh"
 
 void
-main2(stringstream &in, string &basename, bool trace_scanning, bool trace_parsing, bool clear_all)
+main2(stringstream &in, string &basename, bool debug, bool clear_all)
 {
-  ParsingDriver p;
-  p.trace_scanning = trace_scanning;
-  p.trace_parsing = trace_parsing;
+  ParsingDriver p(debug);
 
   // Do parsing and construct internal representation of mod file
   ModFile *mod_file = p.parse(in);
diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc
index ba145fd36c..34a419d4fe 100644
--- a/preprocessor/ParsingDriver.cc
+++ b/preprocessor/ParsingDriver.cc
@@ -23,7 +23,7 @@
 #include "ParsingDriver.hh"
 #include "Statement.hh"
 
-ParsingDriver::ParsingDriver() : trace_scanning(false), trace_parsing(false)
+ParsingDriver::ParsingDriver(bool debug_arg) : debug(debug_arg)
 {
 }
 
@@ -70,9 +70,10 @@ ParsingDriver::parse(istream &in)
   reset_data_tree();
 
   lexer = new DynareFlex(&in);
-  lexer->set_debug(trace_scanning);
+  lexer->set_debug(debug);
 
   Dynare::parser parser(*this);
+  parser.set_debug_level(debug);
   parser.parse();
 
   delete lexer;
diff --git a/preprocessor/include/ParsingDriver.hh b/preprocessor/include/ParsingDriver.hh
index 2b189ed628..c8166dbb6f 100644
--- a/preprocessor/include/ParsingDriver.hh
+++ b/preprocessor/include/ParsingDriver.hh
@@ -137,9 +137,12 @@ private:
   //! The mod file representation constructed by this ParsingDriver
   ModFile *mod_file;
 
+  //! Output debugging info during scanning and parsing ?
+  const bool debug;
+
 public:
   //! Constructor
-  ParsingDriver();
+  ParsingDriver(bool debug_arg);
   //! Destructor
   virtual ~ParsingDriver();
 
@@ -153,15 +156,6 @@ public:
   //! Copy of parsing location, maintained by YYLLOC_DEFAULT macro in DynareBison.yy
   Dynare::parser::location_type location;
 
-  //! Trace scanning ?
-  /*! If set to true before calling parse(), the flex scanner will dump a lot of debugging information. Defaults to false.
-  */
-  bool trace_scanning;
-
-  //! Trace parsing ?
-  /*! If set to true before calling parse(), the bison parser will dump debugging information. Defaults to false. */
-  bool trace_parsing;
-
   //! Estimation parameters
   EstimationParams estim_params;
 
diff --git a/preprocessor/macro/MacroDriver.cc b/preprocessor/macro/MacroDriver.cc
index 00f46ba0c2..e551dd80e8 100644
--- a/preprocessor/macro/MacroDriver.cc
+++ b/preprocessor/macro/MacroDriver.cc
@@ -22,7 +22,7 @@
 
 #include "MacroDriver.hh"
 
-MacroDriver::MacroDriver() : trace_scanning(false), trace_parsing(false)
+MacroDriver::MacroDriver(bool debug_arg) : debug(debug_arg)
 {
 }
 
@@ -47,9 +47,10 @@ MacroDriver::parse(const string &f, ostream &out)
     }
 
   lexer = new MacroFlex(&in, &out);
-  lexer->set_debug(trace_scanning);
+  lexer->set_debug(debug);
 
   Macro::parser parser(*this, out);
+  parser.set_debug_level(debug);
   parser.parse();
 
   delete lexer;
diff --git a/preprocessor/macro/MacroDriver.hh b/preprocessor/macro/MacroDriver.hh
index 3f00abf277..5a67d1891e 100644
--- a/preprocessor/macro/MacroDriver.hh
+++ b/preprocessor/macro/MacroDriver.hh
@@ -138,6 +138,9 @@ class MacroDriver
 {
   friend class MacroValue;
 private:
+  //! Output debugging info during scanning and parsing ?
+  const bool debug;
+
   //! Stores all created macro values
   set<const MacroValue *> values;
 
@@ -157,7 +160,7 @@ public:
   };
 
   //! Constructor
-  MacroDriver();
+  MacroDriver(bool debug_arg);
   //! Destructor
   virtual ~MacroDriver();
 
@@ -176,15 +179,6 @@ public:
   //! Used to store the value of the last @if condition
   bool last_if;
 
-  //! Trace scanning ?
-  /*! If set to true before calling parse(), the flex scanner will dump a lot of debugging information. Defaults to false.
-  */
-  bool trace_scanning;
-
-  //! Trace parsing ?
-  /*! If set to true before calling parse(), the bison parser will dump debugging information. Defaults to false. */
-  bool trace_parsing;
-
   //! Error handler
   void error(const Macro::parser::location_type &l, const string &m) const;
 
-- 
GitLab