[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 0/8] provide more control over C++ file names
From: |
Akim Demaille |
Subject: |
[PATCH 0/8] provide more control over C++ file names |
Date: |
Sat, 6 Oct 2018 18:03:09 +0200 |
I think I have finally reached a point where I have implemented
everything I had on my mind about the names of the auxiliary files in
C++. If I had known earlier what a burden it is, I guess I would have
hesitated more... But I really wanted two C++ parsers to be able to
export and use a single location.hh file.
These patches are quite different from my first proposal, so let's
start a new thread. But see
https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00144.html.
I have explained all the details in NEWS, so rather than paraphrasing,
here is the NEWS snippet that says it all. The tests are included and
work well. The documentation is yet to write, but NEWS should be a
good starting point.
Comments are most welcome. I will push this soon to gnu (it's on my
github), but I'm open to later changes.
** Bison 3.2
*** C++: Renaming location.hh
When both %defines and %locations are enabled, Bison generates a
location.hh file. If you don't use locations outside of the parser, you
may avoid its creation with:
%define api.location.file none
However this file is useful if, for instance, your parser builds an AST
decorated with locations: you may use Bison's location independently of
Bison's parser. You can now give it another name, for instance:
%define api.location.file "my-location.hh"
This name can have directory components, and even be absolute. The name
under which the location file is included is controlled by
api.location.include.
This way it is possible to have several parsers share the same location
file.
For instance, in src/foo/parser.hh, generate the include/ast/loc.hh file:
%locations
%define api.namespace {foo}
%define api.location.file "include/ast/loc.hh"
%define api.location.include {<ast/loc.hh>}
and use it in src/bar/parser.hh:
%locations
%define api.namespace {bar}
%code requires {#include <ast/loc.hh>}
%define api.location.type {bar::location}
Absolute file names are supported, so in your Makefile, passing the flag
-Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"' to bison is
safe.
*** C++: stack.hh and position.hh are deprecated
When asked to generate a header file (%defines), the lalr1.cc skeleton
generates a stack.hh file. This file had no interest for users; it is now
made useless: its content is included in the parser definition. It is
still generated for backward compatibility.
To stop generating it, use the following directive:
%define api.stack.file none
When in addition to %defines, location support is requested (%locations),
the file position.hh is also generated. It is now also useless: its
content is now included in location.hh.
To stop generating it, use the following directive:
%define api.position.file none
Any definition of api.location.file eliminates both position.hh and
stack.hh (i.e., implies '%define api.position.file none' and '%define
api.stack.file none').
Akim Demaille (8):
c++: provide control over the stack.hh file name
c++: add support for api.position.file and api.location.file
c++: make stack.hh completely useless
c++: make position.hh completely useless
c++: when api.location.file is defined, don't generate stack.hh
c++: support absolute api.location.file names
c++: provide a means to control how location.hh is included
NEWS: document api.*.file changes
NEWS | 75 ++++++++++++++++++++++++++++++++++++
data/bison.m4 | 41 ++++++++++++++++++--
data/glr.cc | 14 ++++---
data/lalr1.cc | 13 +++----
data/location.cc | 94 ++++++++++++++++++++++++++++------------------
data/stack.hh | 47 +++++++++++------------
src/scan-skel.l | 7 ++--
tests/c++.at | 79 ++++++++++++++++++++++++++++++++++++++
tests/calc.at | 2 +
tests/input.at | 33 ++++++++++++++++
tests/output.at | 45 +++++++++++++++++++++-
tests/skeletons.at | 2 +-
12 files changed, 370 insertions(+), 82 deletions(-)
--
2.19.0
- [PATCH 0/8] provide more control over C++ file names,
Akim Demaille <=
- [PATCH 7/8] c++: provide a means to control how location.hh is included, Akim Demaille, 2018/10/06
- [PATCH 8/8] NEWS: document api.*.file changes, Akim Demaille, 2018/10/06
- [PATCH 6/8] c++: support absolute api.location.file names, Akim Demaille, 2018/10/06
- [PATCH 3/8] c++: make stack.hh completely useless, Akim Demaille, 2018/10/06
- [PATCH 5/8] c++: when api.location.file is defined, don't generate stack.hh, Akim Demaille, 2018/10/06
- [PATCH 4/8] c++: make position.hh completely useless, Akim Demaille, 2018/10/06
- [PATCH 2/8] c++: add support for api.position.file and api.location.file, Akim Demaille, 2018/10/06
- [PATCH 1/8] c++: provide control over the stack.hh file name, Akim Demaille, 2018/10/06
- Re: [PATCH 0/8] provide more control over C++ file names, Hans Ã…berg, 2018/10/07