summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2019-04-01 18:23:20 +0200
committerAkim Demaille <akim.demaille@gmail.com>2019-04-03 19:20:39 +0200
commit0f193d2d210e9b8581b487aada3d6c1a1c074931 (patch)
tree9910cadff396c797272852fb1ff72bdc0ea0a2d3
parent9832fdd6efe566441690306f184daaf3e856d8ff (diff)
downloadbison-0f193d2d210e9b8581b487aada3d6c1a1c074931.tar.gz
no-lines: avoid leaving an empty line instead of the syncline
Currently, with --no-lines, instead of "#line file line\n", we emit "\n". Let's emit nothing. * data/skeletons/bison.m4 (b4_syncline): Emit at end-of-line when enabled. * data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.cc, * data/skeletons/lalr1.cc, src/output.c: Use dnl after b4_syncline to avoid spurious empty lines. * tests/synclines.at (Sync Lines): Make sure that --no-lines is like grep -v #line. * tests/calc.at: Make sure that a rich grammar file behaves properly with %no-lines.
-rw-r--r--data/skeletons/bison.m421
-rw-r--r--data/skeletons/c++.m46
-rw-r--r--data/skeletons/c.m412
-rw-r--r--data/skeletons/glr.c4
-rw-r--r--data/skeletons/glr.cc10
-rw-r--r--data/skeletons/lalr1.cc10
-rw-r--r--data/skeletons/yacc.c2
-rw-r--r--src/muscle-tab.c4
-rw-r--r--src/output.c2
-rw-r--r--tests/calc.at6
-rw-r--r--tests/synclines.at31
11 files changed, 71 insertions, 37 deletions
diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4
index fd4c2836..4db36aff 100644
--- a/data/skeletons/bison.m4
+++ b/data/skeletons/bison.m4
@@ -448,9 +448,9 @@ m4_define([b4_symbol_action],
[],
[(*yylocationp)])dnl
_b4_symbol_case([$1])[]dnl
-b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])
+b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
b4_symbol([$1], [$2])
-b4_syncline([@oline@], [@ofile@])
+b4_syncline([@oline@], [@ofile@])dnl
break;
b4_dollar_popdef[]dnl
@@ -579,13 +579,15 @@ m4_define([b4_basename],
[m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])])
-# b4_syncline(LINE, FILE)
-# -----------------------
+# b4_syncline(LINE, FILE)dnl
+# --------------------------
+# Should always be following by a dnl.
+#
# Emit "#line LINE FILE /* __LINE__ __FILE__ */".
m4_define([b4_syncline],
[b4_flag_if([synclines],
[b4_sync_start([$1], [$2])[]dnl
-b4_sync_end([__line__], [b4_basename(m4_quote(__file__))])[]dnl
+b4_sync_end([__line__], [b4_basename(m4_quote(__file__))])
])])
# b4_sync_start(LINE, FILE)
@@ -757,8 +759,10 @@ m4_define([b4_percent_define_get_kind],
[m4_indir([b4_percent_define_kind(]$1[)])],
[b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
-# b4_percent_define_get_syncline(VARIABLE)
-# ----------------------------------------
+# b4_percent_define_get_syncline(VARIABLE)dnl
+# -------------------------------------------
+# Should always be following by a dnl.
+#
# Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly.
# That is, if the %define variable VARIABLE is undefined, complain fatally
# since that's a Bison or skeleton error. Otherwise, return its definition
@@ -974,8 +978,7 @@ m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl
m4_ifdef(b4_macro_name,
[b4_comment([m4_if([$#], [0], [[Unqualified %code]],
[["%code ]$1["]])[ blocks.]])
-b4_user_code([m4_indir(b4_macro_name)])
-])dnl
+b4_user_code([m4_indir(b4_macro_name)])])dnl
m4_popdef([b4_macro_name])])
# b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE])
diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4
index 35008f37..2d05699b 100644
--- a/data/skeletons/c++.m4
+++ b/data/skeletons/c++.m4
@@ -147,13 +147,13 @@ m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [],
[[namespace reference has a trailing "::"]])])
m4_define([b4_namespace_open],
-[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])
+[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl
[namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
[^\(.\)[ ]*::], [\1])),
[::], [ { namespace ])[ {]])])
m4_define([b4_namespace_close],
-[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])
+[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl
m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
[^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*],
[\1])),
@@ -194,7 +194,7 @@ m4_define([b4_value_type_declare],
[union\|union-directive],
[[ union semantic_type
{
- ]b4_user_union_members[
+]b4_user_union_members[
};]])])dnl
])
diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index 60c36687..d485cb69 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -474,7 +474,7 @@ m4_define([b4_sync_start], [[#]line $1 $2])
m4_define([b4_case],
[ case $1:
$2
-b4_syncline([@oline@], [@ofile@])
+b4_syncline([@oline@], [@ofile@])dnl
break;])
@@ -484,7 +484,7 @@ m4_define([b4_predicate_case],
[ case $1:
if (! (
$2)) YYERROR;
-b4_syncline([@oline@], [@ofile@])
+b4_syncline([@oline@], [@ofile@])dnl
break;])
@@ -713,13 +713,13 @@ typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE;
[m4_bmatch(b4_percent_define_get([[api.value.type]]),
[union\|union-directive],
[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
-]b4_percent_define_get_syncline([[api.value.union.name]])[
-union ]b4_percent_define_get([[api.value.union.name]])[
+]b4_percent_define_get_syncline([[api.value.union.name]])dnl
+[union ]b4_percent_define_get([[api.value.union.name]])[
{
]b4_user_union_members[
};
-]b4_percent_define_get_syncline([[api.value.union.name]])[
-typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[STYPE;
+]b4_percent_define_get_syncline([[api.value.union.name]])dnl
+[typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[STYPE;
# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
#endif
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index d88b9e79..5d4121b8 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -202,8 +202,8 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C],
]b4_cpp_guard_open([b4_spec_header_file])[
]b4_shared_declarations[
]b4_cpp_guard_close([b4_spec_header_file])[
-]b4_output_end
-])])
+]b4_output_end[
+]])])
# ------------------------- #
diff --git a/data/skeletons/glr.cc b/data/skeletons/glr.cc
index d67b9602..56d9d7a1 100644
--- a/data/skeletons/glr.cc
+++ b/data/skeletons/glr.cc
@@ -100,8 +100,8 @@ m4_defn([b4_initial_action])]))])[
# Hijack the post prologue to declare yyerror.
]m4_append([b4_post_prologue],
-[b4_syncline([@oline@], [@ofile@])[
-]b4_function_declare([yyerror],
+[b4_syncline([@oline@], [@ofile@])dnl
+b4_function_declare([yyerror],
[static void],b4_locations_if([
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
[yylocationp]],])
@@ -128,8 +128,8 @@ m4_if(b4_prefix, [yy], [],
# Hijack the epilogue to define implementations (yyerror, parser member
# functions etc.).
m4_append([b4_epilogue],
-[b4_syncline([@oline@], [@ofile@])[
-
+[b4_syncline([@oline@], [@ofile@])dnl
+[
/*------------------.
| Report an error. |
`------------------*/
@@ -234,7 +234,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
#endif
]m4_popdef([b4_parse_param])dnl
-b4_namespace_close
+b4_namespace_close[]dnl
])
diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 3f24ef77..ef5d76f5 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -111,9 +111,9 @@ b4_dollar_pushdef([yysym.value],
[],
[yysym.location])dnl
_b4_symbol_case([$1])[]dnl
-b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])
+b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
b4_symbol([$1], [$2])
-b4_syncline([@oline@], [@ofile@])
+b4_syncline([@oline@], [@ofile@])dnl
break;
m4_popdef([b4_symbol_value])[]dnl
@@ -412,9 +412,9 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
]b4_disclaimer[
]b4_cpp_guard_open([b4_spec_header_file])[
]b4_shared_declarations(hh)[
-]b4_cpp_guard_close([b4_spec_header_file])
-b4_output_end
-])
+]b4_cpp_guard_close([b4_spec_header_file])[
+]b4_output_end[
+]])
b4_output_begin([b4_parser_file_name])[
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 7e5187bc..2e7ed41e 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -1699,7 +1699,7 @@ yyreduce:
}]], [[
switch (yyn)
{
- ]b4_user_actions[
+]b4_user_actions[
default: break;
}]])[
/* User semantic actions sometimes alter yychar, and that requires
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index 118dbf23..a8cec20e 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -211,7 +211,7 @@ muscle_syncline_grow (char const *key, location loc)
obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
obstack_quote (&muscle_obstack,
quotearg_style (c_quoting_style, loc.start.file));
- obstack_sgrow (&muscle_obstack, ")[");
+ obstack_sgrow (&muscle_obstack, ")dnl\n[");
char const *extension = obstack_finish0 (&muscle_obstack);
muscle_grow (key, extension, "", "");
obstack_free (&muscle_obstack, extension);
@@ -227,7 +227,7 @@ void
muscle_code_grow (const char *key, const char *val, location loc)
{
muscle_syncline_grow (key, loc);
- muscle_grow (key, val, "\n", "\n");
+ muscle_grow (key, val, "", "\n");
}
diff --git a/src/output.c b/src/output.c
index 5f965846..05e712f1 100644
--- a/src/output.c
+++ b/src/output.c
@@ -374,7 +374,7 @@ user_actions_output (FILE *out)
rules[r].is_predicate ? "b4_predicate_case" : "b4_case",
r + 1, rules[r].action_location.start.line);
string_output (out, rules[r].action_location.start.file);
- fprintf (out, ")\n[ %s]])\n\n", rules[r].action);
+ fprintf (out, ")dnl\n[ %s]])\n\n", rules[r].action);
}
fputs ("])\n\n", out);
}
diff --git a/tests/calc.at b/tests/calc.at
index b2584576..99f1160c 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -714,6 +714,7 @@ AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %define par
AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
+AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
# ----------------------- #
# Simple GLR Calculator. #
@@ -753,6 +754,8 @@ AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %location
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
+AT_CHECK_CALC_GLR([%no-lines %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
+
# ----------------------------- #
# Simple LALR1 C++ Calculator. #
@@ -790,6 +793,8 @@ AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %debug %
AT_CHECK_CALC_LALR1_CC([%defines %locations %define api.location.file none])
AT_CHECK_CALC_LALR1_CC([%defines %locations %define api.location.file "my-location.hh"])
+AT_CHECK_CALC_LALR1_CC([%no-lines %defines %locations %define api.location.file "my-location.hh"])
+
# --------------------------- #
# Simple GLR C++ Calculator. #
@@ -821,6 +826,7 @@ AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %de
AT_CHECK_CALC_GLR_CC([%locations %defines %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
AT_CHECK_CALC_GLR_CC([%locations %defines %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
+AT_CHECK_CALC_GLR_CC([%no-lines %locations %defines %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
# --------------------------- #
diff --git a/tests/synclines.at b/tests/synclines.at
index 857a6ca5..2a8a5fd8 100644
--- a/tests/synclines.at
+++ b/tests/synclines.at
@@ -28,7 +28,7 @@ AT_BANNER([[Sync Lines.]])
m4_define([_AT_SYNCLINES_COMPILE],
[AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr])
-# Transform stderr into something like this:
+# Transform the file 'stderr' into something like this:
#
# input.y:4: #error "4"
#
@@ -121,7 +121,7 @@ EOF
# AT_SYNCLINES_COMPILE(FILE)
# --------------------------
-# Compile FILE expecting an error, and save in the file stdout the
+# Compile FILE expecting an error, and save in the file 'stdout' the
# normalized output. If we can't get a trustable location
# from the compiler, just skip the test.
#
@@ -449,11 +449,36 @@ AT_DATA_GRAMMAR([input.y],
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
+%union {
+ int ival;
+}
%%
exp: '0'
]])
+
+# Generate without.* without the #line. Don't use -o without.c which
+# would change the content (e.g., CPP guard depend on the output file
+# name).
AT_BISON_CHECK([--no-lines -o input.AT_LANG_EXT -d input.y])
-AT_CHECK([[grep '#line'] *.AT_LANG_EXT *.AT_LANG_HDR], 1)
+AT_CHECK([mv input.]AT_LANG_EXT[ without.]AT_LANG_EXT[])
+AT_CHECK([mv input.]AT_LANG_HDR[ without.]AT_LANG_HDR[])
+# There is no #line at all.
+AT_CHECK([grep '#line' *.]AT_LANG_EXT[ *.]AT_LANG_HDR[], 1)
+
+# Generate with.* without the #line.
+AT_BISON_CHECK([-o input.AT_LANG_EXT -d input.y])
+AT_CHECK([mv input.]AT_LANG_EXT[ with.]AT_LANG_EXT[])
+AT_CHECK([mv input.]AT_LANG_HDR[ with.]AT_LANG_HDR[])
+
+# The implementation file with --no-line is exactly the
+# original one with #lines removed.
+AT_CHECK([grep -v '#line' with.]AT_LANG_EXT[ >expout])
+AT_CHECK([cat without.AT_LANG_EXT], 0, [expout])
+
+# Likewise for the header.
+AT_CHECK([grep -v '#line' with.]AT_LANG_HDR[ >expout])
+AT_CHECK([cat without.AT_LANG_HDR], 0, [expout])
+
AT_BISON_OPTION_POPDEFS
AT_CLEANUP