Improve C++ namespace support. Discussed starting at

<http://lists.gnu.org/archive/html/help-bison/2007-09/msg00016.html>.
* data/c++.m4: (b4_namespace_ref, b4_namespace_open,
b4_namespace_close): New macros that interpret the %define variable
"namespace" so its value can contain "::" to indicate nested
namespaces.
* data/glr.cc (b4_namespace): Don't define, and replace all uses with
the above macros.
* data/lalr1.cc (b4_namespace): Likewise.
* data/location.cc (b4_namespace): Likewise.
* doc/bison.texinfo (Decl Summary): Move `%define push_pull' entry
inside a new table in the general %define entry.  Document `%define
namespace' there as well.  Point the %name-prefix entry to it since it
explains it more completely in the case of C++.
(C++ Bison Interface): Mention `%define namespace' instead of
%name-prefix.
(Table of Symbols): Remove the `%define push_pull' entry.  The %define
entry suffices.
* tests/c++.at (Relative namespace references): New test case.
(Absolute namespace references): New test case.
(Syntactically invalid namespace references): New test case.
* tests/input.at (C++ namespace reference errors): New test case.
This commit is contained in:
Joel E. Denny
2007-10-08 10:09:07 +00:00
parent 35b8730d01
commit 793fbca50a
8 changed files with 309 additions and 63 deletions

View File

@@ -858,3 +858,52 @@ AT_CHECK([[bison input.y]], [1], [],
]])
AT_CLEANUP
## -------------------------------- ##
## C++ namespace reference errors. ##
## -------------------------------- ##
AT_SETUP([[C++ namespace reference errors]])
# AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
# -------------------------------------------------------------
# Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
m4_define([AT_CHECK_NAMESPACE_ERROR],
[
AT_DATA([[input.y]],
[[%language "C++"
%defines
%define namespace "]$1["
%%
start: ;
]])
AT_CHECK([[bison input.y]], [1], [],
[m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
[[input.y:3.9-17: ]b4_arg[
]])])
])
AT_CHECK_NAMESPACE_ERROR([[]],
[[namespace reference is empty]])
AT_CHECK_NAMESPACE_ERROR([[ ]],
[[namespace reference is empty]])
AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
[[namespace reference has consecutive "::"]])
AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]],
[[namespace reference has consecutive "::"]])
AT_CHECK_NAMESPACE_ERROR([[::::bar]],
[[namespace reference has consecutive "::"]])
AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
[[namespace reference has consecutive "::"]])
AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]],
[[namespace reference has consecutive "::"]],
[[namespace reference has a trailing "::"]])
AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
[[namespace reference has a trailing "::"]])
AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]],
[[namespace reference has a trailing "::"]])
AT_CHECK_NAMESPACE_ERROR([[::]],
[[namespace reference has a trailing "::"]])
AT_CLEANUP