[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/8] YYLLOC_DEFAULT: factor, and don't export it in headers.
From: |
Akim Demaille |
Subject: |
[PATCH 6/8] YYLLOC_DEFAULT: factor, and don't export it in headers. |
Date: |
Wed, 4 Jul 2012 16:53:02 +0200 |
* data/c++.m4, data/c.m4 (b4_yylloc_default_define): New.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c: Use it.
* data/glr.cc: Do not define YYLLOC_DEFAULT in the header file,
but in the implementation one.
---
data/c++.m4 | 29 +++++++++++++++++++++++++++++
data/c.m4 | 29 +++++++++++++++++++++++++++++
data/glr.c | 25 ++-----------------------
data/glr.cc | 29 ++++++-----------------------
data/lalr1.cc | 19 +------------------
data/yacc.c | 26 ++------------------------
6 files changed, 69 insertions(+), 88 deletions(-)
diff --git a/data/c++.m4 b/data/c++.m4
index 9913a17..45c4dda 100644
--- a/data/c++.m4
+++ b/data/c++.m4
@@ -174,3 +174,32 @@ m4_define([b4_cc_var_decls],
], address@hidden)])
m4_define([b4_cc_var_decl],
[ $1;])
+
+
+## ---------##
+## Values. ##
+## ---------##
+
+# b4_yylloc_default_define
+# ------------------------
+# Define YYLLOC_DEFAULT.
+m4_define([b4_yylloc_default_define],
+[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+# ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (N) \
+ { \
+ (Current).begin = YYRHSLOC (Rhs, 1).begin; \
+ (Current).end = YYRHSLOC (Rhs, N).end; \
+ } \
+ else \
+ { \
+ (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
+ } \
+ while (/*CONSTCOND*/ false)
+# endif
+]])
diff --git a/data/c.m4 b/data/c.m4
index 3c6c6f4..08296c6 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -610,3 +610,32 @@ m4_define([b4_declare_yydebug],
extern int ]b4_prefix[debug;
#endif][]dnl
])
+
+# b4_yylloc_default_define
+# ------------------------
+# Define YYLLOC_DEFAULT.
+m4_define([b4_yylloc_default_define],
+[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (YYID (N)) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (YYID (0))
+#endif
+]])
diff --git a/data/glr.c b/data/glr.c
index dd02aec..c4b394a 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -467,34 +467,13 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
]b4_stos[
};
-
/* Error token number */
#define YYTERROR 1
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
]b4_locations_if([[
-#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (YYID (N)) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC (Rhs, 0).last_column; \
- } \
- while (YYID (0))
+]b4_yylloc_default_define[
+# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
/* YY_LOCATION_PRINT -- Print the location on the stream.
This macro was not mandated originally: define only if we know
diff --git a/data/glr.cc b/data/glr.cc
index b3280a5..2579091 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -90,11 +90,13 @@ m4_define([b4_yy_symbol_print_generate],
]])
-# Declare yyerror.
+# Hijack the post prologue to insert early definition of YYLLOC_DEFAULT
+# and declaration of yyerror.
m4_append([b4_post_prologue],
-[b4_syncline(address@hidden@], address@hidden@])
-
-b4_c_ansi_function_decl([yyerror],
+[b4_syncline(address@hidden@], address@hidden@])[
+]b4_yylloc_default_define[
+#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
+]b4_c_ansi_function_decl([yyerror],
[static void],
[[const b4_namespace_ref::b4_parser_class_name::location_type
*yylocationp],
[yylocationp]],
@@ -241,25 +243,6 @@ b4_copyright([Skeleton interface for Bison GLR parsers in
C++],
]b4_YYDEBUG_define[
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
-# ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).begin = YYRHSLOC (Rhs, 1).begin; \
- (Current).end = YYRHSLOC (Rhs, N).end; \
- } \
- else \
- { \
- (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
- } \
- while (/*CONSTCOND*/ 0)
-# endif
-
]b4_namespace_open[
/// A Bison parser.
class ]b4_parser_class_name[
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 5e83ee3..17a8f22 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -298,25 +298,8 @@ m4_if(b4_prefix, [yy], [],
# endif
#endif
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).begin = YYRHSLOC (Rhs, 1).begin; \
- (Current).end = YYRHSLOC (Rhs, N).end; \
- } \
- else \
- { \
- (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
- } \
- while (false)
-#endif
+]b4_yylloc_default_define[
/* Suppress unused-variable warnings by "using" E. */
#define YYUSE(e) ((void) (e))
diff --git a/data/yacc.c b/data/yacc.c
index 8623847..2e46a1e 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -740,31 +740,9 @@ while (YYID (0))
#define YYTERROR 1
#define YYERRCODE 256
-
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
+]b4_yylloc_default_define[
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (YYID (N)) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC (Rhs, 0).last_column; \
- } \
- while (YYID (0))
-#endif]b4_locations_if([[
+]b4_locations_if([[
/* YY_LOCATION_PRINT -- Print the location on the stream.
--
1.7.11.1
- [PATCH 0/8] Various improvements prompted by api.prefix, Akim Demaille, 2012/07/04
- [PATCH 3/8] c++: fewer #includes in the headers., Akim Demaille, 2012/07/04
- [PATCH 5/8] api.prefix: do not use #define to handle YYSTYPE_IS_TRIVIAL etc., Akim Demaille, 2012/07/04
- [PATCH 7/8] glr.cc: do not override C++ definitions by C macros., Akim Demaille, 2012/07/04
- [PATCH 1/8] tests: more logs., Akim Demaille, 2012/07/04
- [PATCH 6/8] YYLLOC_DEFAULT: factor, and don't export it in headers.,
Akim Demaille <=
- [PATCH 2/8] glr.cc: formatting changes., Akim Demaille, 2012/07/04
- [PATCH 4/8] tests: portability fixes., Akim Demaille, 2012/07/04
- [PATCH 8/8] tests: headers.at: strengthen., Akim Demaille, 2012/07/04