[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/8] c++: support absolute api.location.file names
From: |
Akim Demaille |
Subject: |
[PATCH 6/8] c++: support absolute api.location.file names |
Date: |
Sat, 6 Oct 2018 18:03:15 +0200 |
In the case a user wants to create location.hh elsewhere, it can be
helpful to define api.location.file to some possibly absolute path
such as -Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"'.
Currently this does not work with `-o foo/parser.cc`, as we join foo/
and $(top_srcdir) together, the latter starting with slash.
We should not try to do that in m4, manipulating file names is quite
complex when you through Windows file name in. Let m4 delegate this
to gnulib.
* src/scan-skel.l (at_output): Accept up to two arguments.
* data/bison.m4 (b4_output): Adjust.
* tests/skeletons.at (Fatal errors but M4 continues producing output):
Adjust to keep the error.
* data/location.cc, data/stack.hh: Leave the concatenation to @output.
* tests/output.at: Exercise api.location.file with an absolute path.
---
data/bison.m4 | 8 +++++---
data/location.cc | 4 ++--
data/stack.hh | 2 +-
src/scan-skel.l | 7 ++++---
tests/output.at | 12 +++++++++---
tests/skeletons.at | 2 +-
6 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/data/bison.m4 b/data/bison.m4
index 87ad0ca1..6dde067d 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -65,14 +65,16 @@ version 2.2 of Bison.])])
## Output. ##
## -------- ##
-# b4_output_begin(FILE)
-# ---------------------
+# b4_output_begin(FILE1, FILE2)
+# -----------------------------
# Enable output, i.e., send to diversion 0, expand after "#", and
# generate the tag to output into FILE. Must be followed by EOL.
+# FILE is FILE1 concatenated to FILE2. FILE2 can be empty, or be
+# absolute: do the right thing.
m4_define([b4_output_begin],
[m4_changecom()
m4_divert_push(0)dnl
address@hidden(m4_unquote([$1])@)@dnl
address@hidden(m4_unquote([$1])@,m4_unquote([$2])@)@dnl
])
diff --git a/data/location.cc b/data/location.cc
index 7ebf2f40..9c21cecd 100644
--- a/data/location.cc
+++ b/data/location.cc
@@ -305,7 +305,7 @@ m4_define([b4_location_define],
m4_ifdef([b4_position_file], [[
-]b4_output_begin([b4_dir_prefix[]b4_position_file])[
+]b4_output_begin([b4_dir_prefix], [b4_position_file])[
// Starting with Bison 3.2, this file is useless: the structure it
// used to define is now defined in "]b4_location_file[".
//
@@ -323,7 +323,7 @@ m4_ifdef([b4_position_file], [[
m4_ifdef([b4_location_file], [[
-]b4_output_begin([b4_dir_prefix[]b4_location_file])[
+]b4_output_begin([b4_dir_prefix], [b4_location_file])[
]b4_copyright([Locations for Bison parsers in C++])[
/**
diff --git a/data/stack.hh b/data/stack.hh
index 1946cc48..a8b13b04 100644
--- a/data/stack.hh
+++ b/data/stack.hh
@@ -140,7 +140,7 @@ m4_define([b4_stack_define],
m4_ifdef([b4_stack_file],
-[b4_output_begin([b4_dir_prefix[]b4_stack_file])[
+[b4_output_begin([b4_dir_prefix], [b4_stack_file])[
// Starting with Bison 3.2, this file is useless: the structure it
// used to define is now defined with the parser itself.
//
diff --git a/src/scan-skel.l b/src/scan-skel.l
index 096a07ae..63a6dc32 100644
--- a/src/scan-skel.l
+++ b/src/scan-skel.l
@@ -29,8 +29,9 @@
#define FLEX_PREFIX(Id) skel_ ## Id
#include <src/flex-scanner.h>
-#include <dirname.h>
#include <error.h>
+#include <dirname.h>
+#include <path-join.h>
#include <quotearg.h>
#include <src/complain.h>
@@ -236,14 +237,14 @@ at_complain (int argc, char *argv[], char **out_namep,
int *out_linenop)
static void
at_output (int argc, char *argv[], char **out_namep, int *out_linenop)
{
- if (2 < argc)
+ if (3 < argc)
fail_for_at_directive_too_many_args (argv[0]);
if (*out_namep)
{
free (*out_namep);
xfclose (yyout);
}
- *out_namep = xstrdup (argv[1]);
+ *out_namep = xpath_join (argv[1], 2 < argc ? argv[2] : NULL);
output_file_name_check (out_namep, true);
/* If there were errors, do not generate the output. */
yyout = xfopen (complaint_status ? "/dev/null" : *out_namep, "w");
diff --git a/tests/output.at b/tests/output.at
index 3ee79df7..2c2cd9b8 100644
--- a/tests/output.at
+++ b/tests/output.at
@@ -45,9 +45,13 @@ done
[$2[
%%
foo: %empty {};
-]])[
+]])
+
+# There is not AT_DATA_UNQUOTED.
+AT_CHECK([$PERL -pi -e 's{\$at_dir}'"{$at_group_dir}g" $1])
-]AT_BISON_CHECK([$3 $1], [$5], [], [ignore])[
+
+AT_BISON_CHECK([$3 $1], [$5], [], [ignore])[
# Ignore the files non-generated files
]AT_CHECK_FILES([$4], [$1])[
]$6[
@@ -206,8 +210,10 @@ AT_CHECK_OUTPUT([foo.yy],
[%skeleton "lalr1.cc" %defines %locations %define
api.location.file "foo.loc.hh"],
[],
[foo.loc.hh foo.tab.cc foo.tab.hh])
+
+# Absolute paths.
AT_CHECK_OUTPUT([foo.yy],
- [%skeleton "lalr1.cc" %defines %define api.stack.file none
%locations %define api.location.file "foo.loc.hh"],
+ [%skeleton "lalr1.cc" %defines %locations %define
api.location.file "$at_dir/foo.loc.hh"],
[],
[foo.loc.hh foo.tab.cc foo.tab.hh])
diff --git a/tests/skeletons.at b/tests/skeletons.at
index 5e99b340..8c180564 100644
--- a/tests/skeletons.at
+++ b/tests/skeletons.at
@@ -306,7 +306,7 @@ use strict;
my $M4 = "m4";
my $DNL = "d"."nl";
print "${M4}_divert_push(0)$DNL\n";
-print '@output(@,@)', "\n";
+print '@output(@,@,@)', "\n";
(print "garbage"x10, "\n") for (1..1000);
print "${M4}_divert_pop(0)\n";
]])
--
2.19.0
- [PATCH 0/8] provide more control over C++ file names, Akim Demaille, 2018/10/06
- [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 <=
- [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