From cb72ae38dc884d40333c58ec7f34952885053aba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 8 Nov 2024 18:12:19 +0100
Subject: [PATCH] Bison file: better use of %code sections

Also do some coding style manual enforcement.
---
 src/DynareBison.yy   | 17 +++++++++--------
 src/ParsingDriver.hh |  1 -
 src/macro/Parser.yy  |  9 ++++-----
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/DynareBison.yy b/src/DynareBison.yy
index ab5d0bc9..ac49f71e 100644
--- a/src/DynareBison.yy
+++ b/src/DynareBison.yy
@@ -28,21 +28,19 @@
 %define parse.error verbose
 %define parse.trace
 
-%code top {
-class ParsingDriver;
-}
-
 %code requires {
+// Only headers needed for the value and location types go here
+// Headers needed by the Bison file itself go in the unqualified %code section
 #include <string>
 #include <vector>
 #include <map>
-#include <utility>
 #include <tuple>
 #include <variant>
-#include <ranges>
 
 #include "CommonEnums.hh"
 #include "ExprNode.hh"
+
+class ParsingDriver;
 }
 
 %param { ParsingDriver &driver }
@@ -55,6 +53,9 @@ class ParsingDriver;
 }
 
 %code {
+#include <ranges>
+#include <utility>
+
 /* Little hack: we redefine the macro which computes the locations, because
    we need to access the location from within the parsing driver for error
    and warning messages. */
@@ -245,8 +246,8 @@ str_tolower(string s)
 %type <tuple<string,string,string,string>> prior_eq_opt options_eq_opt
 %type <vector<pair<int, int>>> period_list
 %type <vector<expr_t>> matched_moments_list value_list ramsey_constraints_list
-%type <tuple<string, BinaryOpNode *, BinaryOpNode *, expr_t, expr_t>> occbin_constraints_regime
-%type <vector<tuple<string, BinaryOpNode *, BinaryOpNode *, expr_t, expr_t>>> occbin_constraints_regimes_list
+%type <tuple<string, BinaryOpNode*, BinaryOpNode*, expr_t, expr_t>> occbin_constraints_regime
+%type <vector<tuple<string, BinaryOpNode*, BinaryOpNode*, expr_t, expr_t>>> occbin_constraints_regimes_list
 %type <map<string, expr_t>> occbin_constraints_regime_options_list
 %type <pair<string, expr_t>> occbin_constraints_regime_option
 %type <PacTargetKind> pac_target_kind
diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh
index 628cd5a0..a3364267 100644
--- a/src/ParsingDriver.hh
+++ b/src/ParsingDriver.hh
@@ -34,7 +34,6 @@
 #include "ModFile.hh"
 #include "SymbolList.hh"
 
-class ParsingDriver;
 #include "DynareBison.hh"
 #include "ExprNode.hh"
 
diff --git a/src/macro/Parser.yy b/src/macro/Parser.yy
index 42ddd2d0..82bf6061 100644
--- a/src/macro/Parser.yy
+++ b/src/macro/Parser.yy
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /*
- * Copyright © 2019-2023 Dynare Team
+ * Copyright © 2019-2024 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -28,10 +28,6 @@
 %define parse.error verbose
 %define parse.trace
 
-%code requires {
-namespace macro { class Driver; }
-}
-
 %param { macro::Driver& driver }
 
 %locations
@@ -43,6 +39,9 @@ namespace macro { class Driver; }
 
 %code requires {
 #include "Directives.hh"
+
+namespace macro { class Driver; }
+
 using namespace macro;
 }
 
-- 
GitLab