bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/6] c: rename YY_LOCATION_PRINT as YYLOCATION_PRINT and make it


From: Akim Demaille
Subject: [PATCH 3/6] c: rename YY_LOCATION_PRINT as YYLOCATION_PRINT and make it public
Date: Tue, 9 Feb 2021 07:15:43 +0100

It is very helpful to be able to look at the locations in the debug
traces, let's provide the users with (i) a means to do that for their
location types, and (ii) a public macro to print locations when debug
traces are enabled.

* data/skeletons/c.m4 (b4_yy_location_print_define): Rename as...
(b4_yylocation_print_define): this.
Define YYLOCATION_PRINT instead of YY_LOCATION_PRINT.
Ensure backward compatibility for those who might have defined/used
YY_LOCATION_PRINT in spite the warnings.
Adjust dependencies.
* data/skeletons/glr2.cc: We don't use YYLOCATION_PRINT here.
---
 data/skeletons/c.m4    | 39 +++++++++++++++++++++++++++------------
 data/skeletons/glr.c   |  2 +-
 data/skeletons/glr2.cc |  2 --
 data/skeletons/yacc.c  |  2 +-
 4 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index 96f53ee68..a0e35ae04 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -781,7 +781,7 @@ yy_symbol_print (FILE *yyo,
   YYFPRINTF (yyo, "%s %s (",
              yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
 
-]b4_locations_if([  YY_LOCATION_PRINT (yyo, *yylocationp);
+]b4_locations_if([  YYLOCATION_PRINT (yyo, yylocationp);
   YYFPRINTF (yyo, ": ");
 ])dnl
 [  yy_symbol_value_print (yyo, yykind, yyvaluep]dnl
@@ -1038,17 +1038,24 @@ m4_define([b4_yylloc_default_define],
 #endif
 ]])
 
-# b4_yy_location_print_define
-# ---------------------------
-# Define YY_LOCATION_PRINT.
-m4_define([b4_yy_location_print_define],
+# b4_yylocation_print_define
+# --------------------------
+# Define YYLOCATION_PRINT.
+m4_define([b4_yylocation_print_define],
 [b4_locations_if([[
-/* YY_LOCATION_PRINT -- Print the location on the stream.
+/* YYLOCATION_PRINT -- Print the location on the stream.
    This macro was not mandated originally: define only if we know
    we won't break user code: when these are the locations we know.  */
 
-# ifndef YY_LOCATION_PRINT
-#  if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && 
]b4_api_PREFIX[LTYPE_IS_TRIVIAL
+# ifndef YYLOCATION_PRINT
+
+#  if defined YY_LOCATION_PRINT
+
+   /* Temporary convenience wrapper in case some people defined the
+      undocumented and private YY_LOCATION_PRINT macros.  */
+#   define YYLOCATION_PRINT(File, Loc)  YY_LOCATION_PRINT(File, *(Loc))
+
+#  elif defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && 
]b4_api_PREFIX[LTYPE_IS_TRIVIAL
 
 /* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
 
@@ -1078,13 +1085,21 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const 
yylocp)
   return res;
 }
 
-#   define YY_LOCATION_PRINT(File, Loc)          \
-  yy_location_print_ (File, &(Loc))
+#   define YYLOCATION_PRINT  yy_location_print_
+
+    /* Temporary convenience wrapper in case some people defined the
+       undocumented and private YY_LOCATION_PRINT macros.  */
+#   define YY_LOCATION_PRINT(File, Loc)  YYLOCATION_PRINT(File, &(Loc))
 
 #  else
-#   define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+
+#   define YYLOCATION_PRINT(File, Loc) ((void) 0)
+    /* Temporary convenience wrapper in case some people defined the
+       undocumented and private YY_LOCATION_PRINT macros.  */
+#   define YY_LOCATION_PRINT  YYLOCATION_PRINT
+
 #  endif
-# endif /* !defined YY_LOCATION_PRINT */]])
+# endif /* !defined YYLOCATION_PRINT */]])
 ])
 
 # b4_yyloc_default
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index a1c301dd5..1f956955f 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -683,7 +683,7 @@ yylhsNonterm (yyRuleNum yyrule)
     YY_IGNORE_USELESS_CAST_END                  \
   } while (0)
 
-]b4_yy_location_print_define[
+]b4_yylocation_print_define[
 
 ]b4_yy_symbol_print_define[
 
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index e53de88af..51383fe31 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -553,8 +553,6 @@ enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
 
 #if ]b4_api_PREFIX[DEBUG
 
-]b4_yy_location_print_define[
-
 #define YYCDEBUG if (!yydebug) {} else std::cerr
 
 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                  \
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index ee05ae1b7..a59e6aef3 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -768,7 +768,7 @@ do {                                            \
     YYFPRINTF Args;                             \
 } while (0)
 
-]b4_yy_location_print_define[
+]b4_yylocation_print_define[
 
 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                    \
 do {                                                                      \
-- 
2.30.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]