From 5de5b9875193d1ae08f238052243b08ecf71ed69 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 30 Jul 2012 16:51:29 +0200 Subject: [PATCH] lalr1.cc: do not create stack.hh without %defines * data/stack.hh (b4_stack_define): New. * data/lalr1.cc: Use it when %defines is not passed. * tests/output.at: Adjust expected output. --- NEWS | 3 ++- TODO | 5 +++++ data/lalr1.cc | 18 ++++++++++-------- data/stack.hh | 42 +++++++++++++++++++++++++----------------- tests/output.at | 6 +++--- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/NEWS b/NEWS index ef01a6a2..fa1b948f 100644 --- a/NEWS +++ b/NEWS @@ -87,7 +87,8 @@ GNU Bison NEWS *** parser header (%defines) is no longer mandatory (lalr1.cc) In which case, if needed, the support classes are defined in the generated - parser, instead of additional files such as position.hh and location.hh. + parser, instead of additional files (location.hh, position.hh and + stack.hh). *** locations are no longer mandatory (lalr1.cc, glr.cc) diff --git a/TODO b/TODO index 9eb10920..1c5d3585 100644 --- a/TODO +++ b/TODO @@ -10,6 +10,11 @@ b4_parser_declaration for instance. ** glr.cc: %defines it should not be mandatory. +** stack.hh +Get rid of it. The original idea is nice, but actually it makes +the code harder to follow, and uselessly different from the other +skeletons. + ** Variable names. What should we name `variant' and `lex_symbol'? diff --git a/data/lalr1.cc b/data/lalr1.cc index 6e299d5d..8cf20430 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -134,20 +134,22 @@ b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])]) m4_define([b4_shared_declarations], [b4_percent_code_get([[requires]])[ ]b4_parse_assert_if([# include ])[ -# include -# include +# include # include - -]b4_YYDEBUG_define[ - +# include +# include ]b4_defines_if([[ # include "stack.hh" ]b4_locations_if([b4_percent_define_ifdef([[location_type]], [], - [b4_defines_if([[# include "location.hh"]])])])[ + [[# include "location.hh"]])])])[ + +]b4_YYDEBUG_define[ ]b4_namespace_open[ -]b4_locations_if([b4_percent_define_ifdef([[location_type]], [], - [b4_defines_if([], [b4_position_define +]b4_defines_if([], +[b4_stack_define +b4_locations_if([b4_percent_define_ifdef([[location_type]], [], + [b4_position_define b4_location_define])])])[ ]b4_variant_if([b4_variant_define])[ diff --git a/data/stack.hh b/data/stack.hh index cea7b41a..bd94eb2d 100644 --- a/data/stack.hh +++ b/data/stack.hh @@ -18,23 +18,10 @@ m4_pushdef([b4_copyright_years], [2002-2012]) -# We do want M4 expansion after # for CPP macros. -m4_changecom() -m4_divert_push(0)dnl -@output(b4_dir_prefix[]stack.hh@)@ -b4_copyright([Stack handling for Bison parsers in C++])[ - -/** - ** \file ]b4_dir_prefix[stack.hh - ** Define the ]b4_namespace_ref[::stack class. - */ - -]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[ - -# include - -]b4_namespace_open[ - template > +# b4_stack_define +# --------------- +m4_define([b4_stack_define], +[[ template > class stack { public: @@ -129,9 +116,30 @@ b4_copyright([Stack handling for Bison parsers in C++])[ const S& stack_; unsigned int range_; }; +]]) + +b4_defines_if( +[# We do want M4 expansion after # for CPP macros. +m4_changecom() +m4_divert_push(0)dnl +@output(b4_dir_prefix[]stack.hh@)@ +b4_copyright([Stack handling for Bison parsers in C++])[ + +/** + ** \file ]b4_dir_prefix[stack.hh + ** Define the ]b4_namespace_ref[::stack class. + */ + +]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[ + +# include + +]b4_namespace_open[ +]b4_stack_define[ ]b4_namespace_close[ ]b4_cpp_guard_close([b4_dir_prefix[]stack.hh]) m4_divert_pop(0) m4_popdef([b4_copyright_years])dnl m4_changecom([#]) +]) diff --git a/tests/output.at b/tests/output.at index e8019c2a..400f5c20 100644 --- a/tests/output.at +++ b/tests/output.at @@ -114,13 +114,13 @@ AT_CHECK([grep 'include .subdir/' $1.hh], 1, []) ]) AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %verbose], [], - [foo.tab.cc foo.output stack.hh]) + [foo.tab.cc foo.output]) AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %defines %verbose], [], - [foo.tab.cc foo.tab.hh foo.output stack.hh]) + [foo.tab.cc foo.tab.hh foo.output]) AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %verbose %locations], [], - [foo.tab.cc foo.output stack.hh]) + [foo.tab.cc foo.output]) AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %defines %verbose %locations], [], [foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh]) -- 2.45.2