bison-patches
[Top][All Lists]
Advanced

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

c++: get rid of global_tokens_and_yystype


From: Akim Demaille
Subject: c++: get rid of global_tokens_and_yystype
Date: Tue, 16 Jun 2020 08:15:54 +0200

commit efb65daa36db3e918ace73c8a500373340867fbe
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Tue Jun 16 08:01:48 2020 +0200

    c++: get rid of global_tokens_and_yystype
    
    This was a hack to make it easier for people to migrate from yacc.c to
    lalr1.cc and from glr.c to glr.cc: when set, YYSTYPE and YYLTYPE were
    `#defined`.  It was never documented (just mentioned in NEWS for Bison
    2.2, 2006-05-19), but was used to simplify the test suite.  Stop that:
    adjust the test suite to the skeletons, not the converse.
    
    In C++ use yy::parser::semantic_type, yy::parser::location_type, and
    yy::parser::token::MY_TOKEN, instead of YYSTYPE, YYLTYPE and MY_TOKEN.
    
    * data/skeletons/glr.cc, data/skeletons/lalr1.cc: Remove its support.
    * tests/actions.at, tests/c++.at, tests/calc.at: Adjust.

diff --git a/TODO b/TODO
index 1f9aacf6..cc463db3 100644
--- a/TODO
+++ b/TODO
@@ -41,9 +41,6 @@ Use "•" instead of ".".
 Not all the conflicts have counterexamples generated.  See the "break"s in
 counterexample_report_state.
 
-** glr.cc
-Get rid of global_tokens_and_yystype.
-
 ** Bistromathic
 - Hitting tab on a line with a syntax error is ugly
 
diff --git a/data/skeletons/glr.cc b/data/skeletons/glr.cc
index 1c75b27e..56279f42 100644
--- a/data/skeletons/glr.cc
+++ b/data/skeletons/glr.cc
@@ -252,14 +252,9 @@ m4_define([b4_undef_symbol_kind],
 # -----------------
 # Remove redirections for glr.c.
 m4_define([b4_glr_cc_cleanup],
-[b4_percent_define_flag_if([[global_tokens_and_yystype]], [],
 [[#undef ]b4_symbol(-2, [id])[
 #undef ]b4_symbol(0, [id])[
 #undef ]b4_symbol(1, [id])[
-]])[
-
-#undef ]b4_api_PREFIX[STYPE
-#undef ]b4_api_PREFIX[LTYPE
 
 ]b4_undef_symbol_kind(-2)dnl
 b4_symbol_foreach([b4_undef_symbol_kind])dnl
@@ -377,10 +372,6 @@ b4_percent_code_get([[requires]])[
 ]b4_parse_param_vars[
   };
 
-]dnl Redirections for glr.c.
-b4_percent_define_flag_if([[global_tokens_and_yystype]],
-[b4_token_defines
-])[
 ]b4_namespace_close[
 
 ]b4_percent_code_get([[provides]])[
diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 45d0626b..b95f9aa9 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -493,14 +493,6 @@ m4_define([b4_shared_declarations],
 ]b4_public_types_define([$1])])[
 ]b4_namespace_close[
 
-]b4_percent_define_flag_if([[global_tokens_and_yystype]],
-[b4_token_defines
-
-#ifndef ]b4_api_PREFIX[STYPE
- // Redirection for backward compatibility.
-# define ]b4_api_PREFIX[STYPE b4_namespace_ref::b4_parser_class::semantic_type
-#endif
-])[
 ]b4_percent_code_get([[provides]])[
 ]])
 
diff --git a/tests/actions.at b/tests/actions.at
index 46761c25..d90851de 100644
--- a/tests/actions.at
+++ b/tests/actions.at
@@ -607,7 +607,6 @@ $5
 {
   int ival;
 }])
-AT_LALR1_CC_IF([%define global_tokens_and_yystype])
 m4_ifval([$6], [[%code provides {]], [[%code {]])
 AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[
 ]AT_YYLEX_DECLARE[
diff --git a/tests/c++.at b/tests/c++.at
index e3a13224..adc41f31 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -803,12 +803,10 @@ AT_DATA_GRAMMAR([[input.yy]],
 [[%language "C++"
 %define api.namespace {]$1[}
 %union { int i; }
-%define global_tokens_and_yystype
 %locations
 
 %code {
-  // YYSTYPE contains a namespace reference.
-  int yylex (YYSTYPE *lval, const ]$1[::parser::location_type*) {
+  int yylex (]$1[::parser::semantic_type *lval, const 
]$1[::parser::location_type*) {
     lval->i = 3;
     return 0;
   }
diff --git a/tests/calc.at b/tests/calc.at
index 34fa9bab..ee75bf27 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -213,12 +213,12 @@ read_integer (]AT_YYLEX_FORMALS[)
     {
       unget_char (]AT_YYLEX_PRE_ARGS[ c);
       ]AT_VAL[.ival = read_integer (]AT_YYLEX_ARGS[);
-      return ]AT_TOKEN_PREFIX[NUM;
+      return ]AT_CXX_IF([AT_NAMESPACE::parser::token::])[]AT_TOKEN_PREFIX[NUM;
     }
 
   /* Return end-of-file.  */
   if (c == EOF)
-    return ]AT_TOKEN_PREFIX[CALC_EOF;
+    return 
]AT_CXX_IF([AT_NAMESPACE::parser::token::])[]AT_TOKEN_PREFIX[CALC_EOF;
 
   /* An explicit error raised by the scanner. */
   if (c == '#')
@@ -226,7 +226,7 @@ read_integer (]AT_YYLEX_FORMALS[)
       fprintf (stderr, "%d.%d: ",
                AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN);])[
       fputs ("syntax error: invalid character: '#'\n", stderr);
-      return ]AT_TOKEN_PREFIX[]AT_API_PREFIX[error;
+      return 
]AT_CXX_IF([AT_NAMESPACE::parser::token::])[]AT_TOKEN_PREFIX[]AT_API_PREFIX[error;
     }
 
   /* Return single chars. */
@@ -444,7 +444,6 @@ m4_define([_AT_DATA_CALC_Y(c)],
 [AT_DATA_GRAMMAR([calc.y],
 [[/* Infix notation calculator--calc */
 ]$4[
-]AT_CXX_IF([%define global_tokens_and_yystype])[
 ]AT_LANG_MATCH(
 [d], [[
 %code imports {




reply via email to

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