glr2.cc: example: use objects (not pointers) to represent the AST

Currently we are using pointers.  The whole point of
glr2.cc (vs. glr.cc) is precisely to allow genuine C++ objects to be
semantic values.  Let's make that work.

* data/skeletons/glr2.cc (glr_state::glr_state): Be sure to initialize
yysval.
(glr_state): Add copy-ctor, assignment and dtor.
(glr_state::copyFrom): Be sure to initialize the destination if it was
not.
(glr_state::~glr_state): Destroy the semantic value.
* examples/c++/glr/ast.hh: Rewrite so that we use genuine objects,
rather than a traditional OOP hierarchy that requires to deal with
pointers.
With help from Bruno Belanyi <bruno.belanyi@epita.fr>.
* examples/c++/glr/c++-types.yy: Remove memory management.
Use true objects.
(main): Don't reach yydebug directly.

* examples/c++/glr/local.mk: We need C++11.
This commit is contained in:
Akim Demaille
2020-12-14 20:26:41 +01:00
parent 611348e67b
commit 0a82316e54
7 changed files with 177 additions and 89 deletions

View File

@@ -34,7 +34,7 @@ CLEANDIRS += %D%/*.dSYM
# Avoid using BUILT_SOURCES which is too global.
$(%C%_c___types_OBJECTS): $(cxx_types_sources_generated)
if ENABLE_CXX
if ENABLE_CXX14
check_PROGRAMS += %D%/c++-types
dist_%C%_c___types_SOURCES = \
%D%/ast.hh
@@ -43,6 +43,7 @@ if ENABLE_CXX
%D%/c++-types.hh
# Don't use gnulib's system headers.
%C%_c___types_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_c___types_CXXFLAGS = $(CXX14_CXXFLAGS) $(WARN_CXXFLAGS_TEST)
TESTS += %D%/c++-types.test
endif ENABLE_CXX
endif ENABLE_CXX14
EXTRA_DIST += %D%/c++-types.yy %D%/c++-types.test