Instead of having skeletons declare all valid %define variables and

%code qualifiers, provide macros that retrieve the associated values
and build these lists automatically.  Thus Bison will now warn when a
variable or qualifier is not used by the skeleton in the current
invocation regardless of whether it might sometimes be used by that
skeleton in other invocations.  Also, move all %define value macros to
the b4_percent_define_ namespace, and remove the %define "NAME" {CODE}
form, which is replaced by %code.
* data/bison.m4 (b4_check_for_unrecognized_names): Rename to...
(b4_check_user_names): ... this, and change the series of valid name
arguments to a single list argument for names used in the skeleton
similar to the existing list argument for names used in the grammar.
Warn instead of complaining.
(b4_get_percent_define, b4_get_percent_code): New to retrieve %define
values and %code code, to format %code code properly, and to build
lists of all %define variables and %code qualifiers used in the
skeleton: b4_skeleton_percent_define_variables and
b4_skeleton_percent_code_qualifiers.
(b4_check_percent_define_variables, b4_check_percent_code_qualifiers):
Remove, and...
(m4_wrap): ... m4_wrap b4_check_user_names invocations instead so that
the skeleton names lists can finish building first.  In place of
b4_used_percent_define_variables and b4_used_percent_code_qualifiers,
expect the lists b4_user_percent_define_variables and
b4_user_percent_code_qualifiers.
* data/c++.m4: Where setting default values for b4_parser_class_name,
b4_location_type, b4_filename_type, b4_namespace, and
b4_define_location_comparison, update their names to the
b4_percent_define_ namespace.
* data/glr.c: Don't use b4_check_percent_define_variables and
b4_check_percent_code_qualifiers.  Use b4_get_percent_code.
* data/glr.cc, data/lalr1.cc: Likewise, and use b4_get_percent_define.
(b4_parser_class_name, b4_namespace): Define these using
b4_get_percent_define for parser_class_name and namespace.  Normally
this would be a bad idea since there might be cases when the variables
aren't used, but these variables are too pervasive in these skeletons
for that to be a problem.
* data/location.cc: Use b4_get_percent_define.
* data/push.c: Don't use b4_check_percent_define_variables and
b4_check_percent_code_qualifiers.  Use b4_get_percent_code.
* data/yacc.c: Likewise, and don't call m4_exit in
b4_use_push_for_pull_if or m4_wrap code will never execute.
* src/muscle_tab.c, src/muscle_tab.h (muscle_grow_used_name_list):
Rename to...
(muscle_grow_user_name_list): ... this for consistency with the
terminology used in bison.m4.
* src/parse-gram.y (prologue_declaration): Prepend "percent_define_" to
%define variable names, and rename muscle used_percent_define_variables
to user_percent_define_variables.
(grammar_declaration): Rename muscle used_percent_code_qualifiers to
user_percent_code_qualifiers.
(content): Remove.
(content.opt): Replace content RHS with STRING RHS so %define "NAME"
{CODE} form is no longer accepted.
* tests/input.at (Reject bad %code qualifiers): Rename to...
(Reject unused %code qualifiers): ... this, and update test output.
(%define error): Update test output.
This commit is contained in:
Joel E. Denny
2007-01-08 21:38:30 +00:00
parent 7eb8a0bcca
commit 6afc30cc87
15 changed files with 610 additions and 604 deletions

View File

@@ -1,3 +1,63 @@
2007-01-08 Joel E. Denny <jdenny@ces.clemson.edu>
Instead of having skeletons declare all valid %define variables and
%code qualifiers, provide macros that retrieve the associated values
and build these lists automatically. Thus Bison will now warn when a
variable or qualifier is not used by the skeleton in the current
invocation regardless of whether it might sometimes be used by that
skeleton in other invocations. Also, move all %define value macros to
the b4_percent_define_ namespace, and remove the %define "NAME" {CODE}
form, which is replaced by %code.
* data/bison.m4 (b4_check_for_unrecognized_names): Rename to...
(b4_check_user_names): ... this, and change the series of valid name
arguments to a single list argument for names used in the skeleton
similar to the existing list argument for names used in the grammar.
Warn instead of complaining.
(b4_get_percent_define, b4_get_percent_code): New to retrieve %define
values and %code code, to format %code code properly, and to build
lists of all %define variables and %code qualifiers used in the
skeleton: b4_skeleton_percent_define_variables and
b4_skeleton_percent_code_qualifiers.
(b4_check_percent_define_variables, b4_check_percent_code_qualifiers):
Remove, and...
(m4_wrap): ... m4_wrap b4_check_user_names invocations instead so that
the skeleton names lists can finish building first. In place of
b4_used_percent_define_variables and b4_used_percent_code_qualifiers,
expect the lists b4_user_percent_define_variables and
b4_user_percent_code_qualifiers.
* data/c++.m4: Where setting default values for b4_parser_class_name,
b4_location_type, b4_filename_type, b4_namespace, and
b4_define_location_comparison, update their names to the
b4_percent_define_ namespace.
* data/glr.c: Don't use b4_check_percent_define_variables and
b4_check_percent_code_qualifiers. Use b4_get_percent_code.
* data/glr.cc, data/lalr1.cc: Likewise, and use b4_get_percent_define.
(b4_parser_class_name, b4_namespace): Define these using
b4_get_percent_define for parser_class_name and namespace. Normally
this would be a bad idea since there might be cases when the variables
aren't used, but these variables are too pervasive in these skeletons
for that to be a problem.
* data/location.cc: Use b4_get_percent_define.
* data/push.c: Don't use b4_check_percent_define_variables and
b4_check_percent_code_qualifiers. Use b4_get_percent_code.
* data/yacc.c: Likewise, and don't call m4_exit in
b4_use_push_for_pull_if or m4_wrap code will never execute.
* src/muscle_tab.c, src/muscle_tab.h (muscle_grow_used_name_list):
Rename to...
(muscle_grow_user_name_list): ... this for consistency with the
terminology used in bison.m4.
* src/parse-gram.y (prologue_declaration): Prepend "percent_define_" to
%define variable names, and rename muscle used_percent_define_variables
to user_percent_define_variables.
(grammar_declaration): Rename muscle used_percent_code_qualifiers to
user_percent_code_qualifiers.
(content): Remove.
(content.opt): Replace content RHS with STRING RHS so %define "NAME"
{CODE} form is no longer accepted.
* tests/input.at (Reject bad %code qualifiers): Rename to...
(Reject unused %code qualifiers): ... this, and update test output.
(%define error): Update test output.
2007-01-07 Joel E. Denny <jdenny@ces.clemson.edu>
Check for unrecognized %define variables similar to checking for

View File

@@ -283,81 +283,107 @@ b4_define_user_code([pre_prologue])
b4_define_user_code([stype])
# b4_check_for_unrecognized_names(WHAT, LIST, [VALID_NAME], [VALID_NAME])
# -----------------------------------------------------------------------
# Complain if any name of type WHAT is used in the grammar (as recorded in
# LIST) but is not a VALID_NAME.
# b4_check_user_names(WHAT, USER-LIST, SKELETON-LIST)
# ---------------------------------------------------
# Warn if any name of type WHAT is used by the user (as recorded in USER-LIST)
# but is not used by the skeleton (as recorded in SKELETON-LIST).
#
# LIST must expand to a list specifying all grammar occurrences of all names of
# type WHAT. Each item in the list is a triplet specifying one occurrence:
# name, start boundary, and end boundary. Empty string names are fine. An
# empty list is fine.
# USER-LIST must expand to a list specifying all grammar occurrences of all
# names of type WHAT. Each item in the list is a triplet specifying one
# occurrence: name, start boundary, and end boundary. Empty string names are
# fine. An empty list is fine.
#
# For example, to define b4_foo_list to be used for LIST with three name
# occurrences and with correct quoting:
# For example, to define b4_user_foo_names to be used for USER-LIST with three
# name occurrences and with correct quoting:
#
# m4_define([b4_foo_list],
# m4_define([b4_user_foo_names],
# [[[[[[bar]], [[parser.y:1.7]], [[parser.y:1.16]]]],
# [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]],
# [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]])
#
# Each VALID_NAME must expand to a valid name of type WHAT. Multiple
# occurrences of the same valid name are fine. A VALID_NAME that expands to
# the empty string will correctly define the empty string as a valid name, but
# it would be ugly for a Bison skeleton to actually use that.
# SKELETON-LIST must expand to a list specifying all names of type WHAT that
# are used by the skeleton. Multiple occurrences of the same name are fine.
# Empty string names are fine, but it would be ugly for a Bison skeleton to
# actually use one. An empty list is fine.
#
# For example, to invoke b4_check_for_unrecognized_names with TYPE foo, with
# LIST b4_foo_list, with two valid names, and with correct quoting:
# For example, to define b4_skeleton_foo_names to be used for SKELETON-LIST
# with two names and with correct quoting:
#
# b4_check_for_unrecognized_names([[foo]], [b4_foo_list],
# [[bar]], [[baz]])
# m4_define([b4_skeleton_foo_names],
# [[[[bar]], [[baz]]]])
#
# Names and valid names must not contain the character `,'.
m4_define([b4_check_for_unrecognized_names],
[m4_foreach([b4_occurrence],
$2,
[m4_pushdef([b4_occurrence], b4_occurrence)
m4_pushdef([b4_name], m4_car(b4_occurrence))
m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))
m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))
m4_if(m4_index(m4_if($#, 2, [],
[[,]m4_quote(m4_shift(m4_shift($*)))[,]]),
[,]b4_name[,]),
[-1],
[b4_complain_at([b4_start], [b4_end],
[[`%s' is not a recognized %s]],
[b4_name], [$1])
])
m4_popdef([b4_occurrence])
m4_popdef([b4_name])
m4_popdef([b4_start])
m4_popdef([b4_end])
])
# To invoke b4_check_user_names with TYPE foo, with USER-LIST
# b4_user_foo_names, with SKELETON-LIST b4_skeleton_foo_names, and with correct
# quoting:
#
# b4_check_user_names([[foo]], [b4_user_foo_names], [b4_skeleton_foo_names])
m4_define([b4_check_user_names],
[m4_foreach([b4_occurrence], $2,
[m4_pushdef([b4_occurrence], b4_occurrence)dnl
m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl
m4_pushdef([b4_found], [[0]])dnl
m4_foreach([b4_skeleton_name], $3,
[m4_if(m4_quote(b4_user_name),
m4_quote(b4_skeleton_name),
[m4_define([b4_found], [[1]])])])dnl
m4_if(b4_found, [0], [b4_warn_at([b4_start], [b4_end],
[[%s `%s' is not used]],
[$1], [b4_user_name])])[]dnl
m4_popdef([b4_found])dnl
m4_popdef([b4_occurrence])dnl
m4_popdef([b4_user_name])dnl
m4_popdef([b4_start])dnl
m4_popdef([b4_end])dnl
])])
# b4_get_percent_define(VARIABLE)
# --------------------------------
# If the %define variable VARIABLE is defined, emit it. Also, record VARIABLE
# in b4_skeleton_percent_define_variables.
m4_define([b4_get_percent_define],
[m4_append([b4_skeleton_percent_define_variables], [[$1]], [[, ]])dnl
m4_ifdef([b4_percent_define_]$1, [b4_percent_define_]$1)])
# b4_get_percent_code([QUALIFIER])
# --------------------------------
# If any %code blocks for QUALIFIER are defined, emit them beginning with a
# comment and ending with synclines and a newline. If QUALIFIER is not
# specified (thus, b4_get_percent_code is invoked without parens), do this for
# the unqualified %code blocks. Also, record QUALIFIER (if specified) in
# b4_skeleton_percent_code_qualifiers.
m4_define([b4_get_percent_code],
[m4_pushdef([b4_macro_name], [[b4_percent_code]]m4_if([$#], [1], [[[_]$1]]))dnl
m4_if([$#], [1],
[m4_append([b4_skeleton_percent_code_qualifiers], [[$1]], [[, ]])])dnl
m4_ifdef(b4_macro_name,
[b4_comment([m4_if([$#], [0], [[Unqualified %code]],
[[%code "]$1["]])[ blocks.]])
b4_user_code(b4_macro_name)])dnl
m4_popdef([b4_macro_name])])
## --------------------------------------------------------- ##
## After processing the skeletons, check that all the user's ##
## %define variables and %code qualifiers were used. ##
## --------------------------------------------------------- ##
m4_wrap([
m4_pushdef([b4_check_user_names_wrap],
[m4_ifdef([b4_skeleton_percent_$1],
[m4_define([b4_skeleton_percent_$1],
m4_dquote(m4_dquote(b4_skeleton_percent_$1)))],
[m4_define([b4_skeleton_percent_$1], [[]])])
m4_ifdef([b4_user_percent_$1],
[b4_check_user_names([$2],
[b4_user_percent_$1],
[b4_skeleton_percent_$1])])
])
# b4_check_percent_define_variables([VAILD_VARIABLE], [VALID_VARIABLE], ...)
# --------------------------------------------------------------------------
# Wrapper around b4_check_for_unrecognized_names for %define variables.
#
# b4_used_percent_define_variables must contain a list of all %define variables
# used in the grammar similar to b4_foo_list from the
# b4_check_for_unrecognized_names documentation's example. If
# b4_used_percent_define_variables is undefined, it's treated the same as an
# empty list.
#
# Invoking b4_check_percent_define_variables with empty parens specifies one
# valid variable that is an empty string. Invoke it without parens to specify
# that there are no valid variables.
m4_define([b4_check_percent_define_variables],
[m4_ifdef([b4_used_percent_define_variables],
[b4_check_for_unrecognized_names([[%define variable]],
[b4_used_percent_define_variables]m4_if([$#], [0], [], [, $@]))])])
b4_check_user_names_wrap([define_variables], [[%define variable]])
b4_check_user_names_wrap([code_qualifiers], [[%code qualifier]])
# b4_check_percent_code_qualifiers([VAILD_QUALIFIER], [VALID_QUALIFIER], ...)
# ---------------------------------------------------------------------------
# Same as b4_check_percent_define_variables but for %code qualifiers using
# b4_used_percent_code_qualifiers.
m4_define([b4_check_percent_code_qualifiers],
[m4_ifdef([b4_used_percent_code_qualifiers],
[b4_check_for_unrecognized_names([[%code qualifier]],
[b4_used_percent_code_qualifiers]m4_if([$#], [0], [], [, $@]))])])
m4_popdef([b4_check_user_names_wrap])
])

View File

@@ -26,12 +26,13 @@ m4_include(b4_pkgdatadir/[c.m4])
## ---------------- ##
# Default parser class name.
m4_define_default([b4_parser_class_name], [parser])
m4_define_default([b4_location_type], [location])
m4_define_default([b4_filename_type], [std::string])
m4_define_default([b4_namespace], m4_defn([b4_prefix]))
m4_define_default([b4_define_location_comparison],
m4_if(b4_filename_type, [std::string], [1], [0]))
m4_define_default([b4_percent_define_parser_class_name], [parser])
m4_define_default([b4_percent_define_location_type], [location])
m4_define_default([b4_percent_define_filename_type], [std::string])
m4_define_default([b4_percent_define_namespace], m4_defn([b4_prefix]))
m4_define_default([b4_percent_define_define_location_comparison],
m4_if(b4_percent_define_filename_type, [std::string],
[1], [0]))
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)

View File

@@ -21,13 +21,6 @@
m4_include(b4_pkgdatadir/[c.m4])
# glr.cc checks %define variables also.
m4_if(b4_skeleton, [["glr.c"]], [b4_check_percent_define_variables])
b4_check_percent_code_qualifiers([[requires]],
[[provides]],
[[top]])
b4_push_if([
b4_complain([[non-deterministic push parsers are not yet supported]])])
@@ -160,9 +153,7 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
]b4_identification
m4_ifdef([b4_percent_code_top],
[[/* Copy the %code "top" blocks. */
]b4_user_code([b4_percent_code_top])])[]dnl
b4_get_percent_code([[top]])[]dnl
m4_if(b4_prefix, [yy], [],
[/* Substitute the variable and function names. */
#define yyparse b4_prefix[]parse
@@ -182,9 +173,7 @@ dnl # ----------------------
dnl # Declaration that might either go into the header (if --defines)
dnl # or open coded in the parser body.
m4_define([b4_shared_declarations],
[m4_ifdef([b4_percent_code_requires],
[[/* Copy the %code "requires" blocks. */
]b4_user_code([b4_percent_code_requires])])[]dnl
[b4_get_percent_code([[requires]])[]dnl
b4_token_enums(b4_tokens)
@@ -215,9 +204,7 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1
#endif
]m4_ifdef([b4_percent_code_provides],
[[/* Copy the %code "provides" blocks. */
]b4_user_code([b4_percent_code_provides])])[]dnl
]b4_get_percent_code([[provides]])[]dnl
])
b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
@@ -250,10 +237,7 @@ static YYSTYPE yyval_default;
/* Copy the second part of user declarations. */
]b4_user_post_prologue
m4_ifdef([b4_percent_code],
[[/* Copy the unqualified %code blocks. */
]b4_user_code([b4_percent_code])
])[]dnl
b4_get_percent_code[]dnl
[#include <stdio.h>
#include <stdlib.h>

View File

@@ -57,12 +57,10 @@ b4_defines_if([],
m4_include(b4_pkgdatadir/[c++.m4])
m4_include(b4_pkgdatadir/[location.cc])
b4_check_percent_define_variables([[global_tokens_and_yystype]],
[[parser_class_name]],
[[location_type]],
[[filename_type]],
[[b4_namespace]],
[[b4_define_location_comparison]])
m4_define([b4_parser_class_name],
[b4_get_percent_define([[parser_class_name]])])
m4_define([b4_namespace],
[b4_get_percent_define([[namespace]])])
# Save the parse parameters.
m4_define([b4_parse_param_orig], m4_defn([b4_parse_param]))
@@ -232,9 +230,7 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
#ifndef PARSER_HEADER_H
# define PARSER_HEADER_H
]m4_ifdef([b4_percent_code_requires],
[[/* Copy the %code "requires" blocks. */
]b4_user_code([b4_percent_code_requires])])[
]b4_get_percent_code([[requires]])[
#include <string>
#include <iostream>
@@ -293,7 +289,7 @@ b4_user_stype
typedef YYSTYPE semantic_type;
#endif
/// Symbol locations.
typedef ]b4_location_type[ location_type;
typedef ]b4_get_percent_define([[location_type]])[ location_type;
/// Tokens.
struct token
{
@@ -368,7 +364,7 @@ b4_user_stype
};
]dnl Redirections for glr.c.
m4_ifset([b4_global_tokens_and_yystype],
m4_ifval(b4_get_percent_define([[global_tokens_and_yystype]]),
[b4_token_defines(b4_tokens)])
[
#ifndef YYSTYPE
@@ -380,9 +376,7 @@ m4_ifset([b4_global_tokens_and_yystype],
}
]m4_ifdef([b4_percent_code_provides],
[[/* Copy the %code "provides" blocks. */
]b4_user_code([b4_percent_code_provides])])[]dnl
]b4_get_percent_code([[provides]])[]dnl
[#endif /* ! defined PARSER_HEADER_H */]
m4_divert_pop(0)

View File

@@ -19,16 +19,10 @@
m4_include(b4_pkgdatadir/[c++.m4])
b4_check_percent_define_variables([[global_tokens_and_yystype]],
[[parser_class_name]],
[[location_type]],
[[filename_type]],
[[b4_namespace]],
[[b4_define_location_comparison]])
b4_check_percent_code_qualifiers([[requires]],
[[provides]],
[[top]])
m4_define([b4_parser_class_name],
[b4_get_percent_define([[parser_class_name]])])
m4_define([b4_namespace],
[b4_get_percent_define([[namespace]])])
# The header is mandatory.
b4_defines_if([],
@@ -52,9 +46,7 @@ dnl FIXME: This is wrong, we want computed header guards.
#ifndef PARSER_HEADER_H
# define PARSER_HEADER_H
]m4_ifdef([b4_percent_code_requires],
[[/* Copy the %code "requires" blocks. */
]b4_user_code([b4_percent_code_requires])])[
]b4_get_percent_code([[requires]])[
#include <string>
#include <iostream>
@@ -125,7 +117,7 @@ b4_user_stype
typedef YYSTYPE semantic_type;
#endif
/// Symbol locations.
typedef ]b4_location_type[ location_type;
typedef ]b4_get_percent_define([[location_type]])[ location_type;
/// Tokens.
struct token
{
@@ -296,7 +288,7 @@ b4_error_verbose_if([, int tok])[);
};
}
]m4_ifset([b4_global_tokens_and_yystype],
]m4_ifval(b4_get_percent_define([[global_tokens_and_yystype]]),
[b4_token_defines(b4_tokens)
#ifndef YYSTYPE
@@ -304,18 +296,14 @@ b4_error_verbose_if([, int tok])[);
# define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
#endif
])
m4_ifdef([b4_percent_code_provides],
[[/* Copy the %code "provides" blocks. */
]b4_user_code([b4_percent_code_provides])])[]dnl
b4_get_percent_code([[provides]])[]dnl
[#endif /* ! defined PARSER_HEADER_H */]
])dnl
@output(b4_parser_file_name@)
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
[2002, 2003, 2004, 2005, 2006])
m4_ifdef([b4_percent_code_top],
[[/* Copy the %code "top" blocks. */
]b4_user_code([b4_percent_code_top])])[]dnl
b4_get_percent_code([[top]])[]dnl
m4_if(b4_prefix, [yy], [],
[
// Take the name prefix into account.
@@ -329,10 +317,7 @@ b4_defines_if([[
/* User implementation prologue. */
]b4_user_post_prologue
m4_ifdef([b4_percent_code],
[[/* Copy the unqualified %code blocks. */
]b4_user_code([b4_percent_code])
])[]dnl
b4_get_percent_code[]dnl
[#ifndef YY_
# if YYENABLE_NLS

View File

@@ -26,7 +26,7 @@ b4_copyright([Positions for Bison parsers in C++],
/**
** \file position.hh
** Define the ]b4_namespace[::position class.
** Define the ]b4_get_percent_define([[namespace]])[::position class.
*/
#ifndef BISON_POSITION_HH
@@ -36,7 +36,7 @@ b4_copyright([Positions for Bison parsers in C++],
# include <string>
# include <algorithm>
namespace ]b4_namespace[
namespace ]b4_get_percent_define([[namespace]])[
{
/// Abstract a position.
class position
@@ -51,7 +51,7 @@ namespace ]b4_namespace[
])[
/// Initialization.
inline void initialize (]b4_filename_type[* fn)
inline void initialize (]b4_get_percent_define([[filename_type]])[* fn)
{
filename = fn;
line = ]b4_location_initial_line[;
@@ -77,7 +77,7 @@ namespace ]b4_namespace[
public:
/// File name to which this position refers.
]b4_filename_type[* filename;
]b4_get_percent_define([[filename_type]])[* filename;
/// Current line number.
unsigned int line;
/// Current column number.
@@ -113,7 +113,7 @@ namespace ]b4_namespace[
{
return begin + -width;
}
]m4_if(b4_define_location_comparison, [1], [[
]m4_if(b4_get_percent_define([[define_location_comparison]]), [1], [[
/// Compare two position objects.
inline bool
operator== (const position& pos1, const position& pos2)
@@ -151,7 +151,7 @@ b4_copyright([Locations for Bison parsers in C++],
/**
** \file location.hh
** Define the ]b4_namespace[::location class.
** Define the ]b4_get_percent_define([[namespace]])[::location class.
*/
#ifndef BISON_LOCATION_HH
@@ -161,7 +161,7 @@ b4_copyright([Locations for Bison parsers in C++],
# include <string>
# include "position.hh"
namespace ]b4_namespace[
namespace ]b4_get_percent_define([[namespace]])[
{
/// Abstract a location.
@@ -177,7 +177,7 @@ namespace ]b4_namespace[
])[
/// Initialization.
inline void initialize (]b4_filename_type[* fn)
inline void initialize (]b4_get_percent_define([[filename_type]])[* fn)
{
begin.initialize (fn);
end = begin;
@@ -235,7 +235,7 @@ namespace ]b4_namespace[
res.columns (width);
return res;
}
]m4_if(b4_define_location_comparison, [1], [[
]m4_if(b4_get_percent_define([[define_location_comparison]]), [1], [[
/// Compare two location objects.
inline bool
operator== (const location& loc1, const location& loc2)

View File

@@ -34,12 +34,6 @@ b4_use_push_for_pull_if([
m4_include(b4_pkgdatadir/[c.m4])
b4_check_percent_define_variables
b4_check_percent_code_qualifiers([[requires]],
[[provides]],
[[top]])
## ---------------- ##
## Default values. ##
## ---------------- ##
@@ -166,9 +160,7 @@ b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
USER NAME SPACE" below. */
]b4_identification
m4_ifdef([b4_percent_code_top],
[[/* Copy the %code "top" blocks. */
]b4_user_code([b4_percent_code_top])])[]dnl
b4_get_percent_code([[top]])[]dnl
m4_if(b4_prefix, [yy], [],
[[/* Substitute the variable and function names. */
]b4_pull_if([[#define yyparse ]b4_prefix[parse
@@ -206,9 +198,7 @@ m4_if(b4_prefix, [yy], [],
# define YYTOKEN_TABLE ]b4_token_table[
#endif
]m4_ifdef([b4_percent_code_requires],
[[/* Copy the %code "requires" blocks. */
]b4_user_code([b4_percent_code_requires])])[]dnl
]b4_get_percent_code([[requires]])[]dnl
b4_token_enums_defines(b4_tokens)[
@@ -259,16 +249,11 @@ b4_c_function_decl([[yypstate_delete]], [[void]],
[[[yypstate *yyps]], [[yyps]]])[
#endif
]])
m4_ifdef([b4_percent_code_provides],
[[/* Copy the %code "provides" blocks. */
]b4_user_code([b4_percent_code_provides])])[]dnl
b4_get_percent_code([[provides]])[]dnl
[/* Copy the second part of user declarations. */
]b4_user_post_prologue
m4_ifdef([b4_percent_code],
[[/* Copy the unqualified %code blocks. */
]b4_user_code([b4_percent_code])
])[]dnl
b4_get_percent_code[]dnl
[#ifdef short
# undef short
@@ -1668,9 +1653,7 @@ b4_defines_if(
b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
[1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
m4_ifdef([b4_percent_code_requires],
[[/* Copy the %code "requires" blocks. */
]b4_user_code([b4_percent_code_requires])])[]dnl
b4_get_percent_code([[requires]])[]dnl
b4_token_enums_defines(b4_tokens)
@@ -1727,8 +1710,6 @@ b4_c_function_decl([b4_prefix[pstate_delete]], [[void]],
[[b4_prefix[pstate *yyps]], [[yyps]]])[
#endif
]])
m4_ifdef([b4_percent_code_provides],
[[/* Copy the %code "provides" blocks. */
]b4_user_code([b4_percent_code_provides])])[]
b4_get_percent_code([[provides]])[]dnl
])dnl b4_defines_if
m4_divert_pop(0)

View File

@@ -21,16 +21,10 @@
# 02110-1301 USA
# Handle BISON_USE_PUSH_FOR_PULL for the test suite.
b4_use_push_for_pull_if([m4_include(b4_pkgdatadir/[push.c])m4_exit])
b4_use_push_for_pull_if([m4_include(b4_pkgdatadir/[push.c])], [
m4_include(b4_pkgdatadir/[c.m4])
b4_check_percent_define_variables
b4_check_percent_code_qualifiers([[requires]],
[[provides]],
[[top]])
## ---------------- ##
## Default values. ##
## ---------------- ##
@@ -158,9 +152,7 @@ b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
USER NAME SPACE" below. */
]b4_identification
m4_ifdef([b4_percent_code_top],
[[/* Copy the %code "top" blocks. */
]b4_user_code([b4_percent_code_top])])[]dnl
b4_get_percent_code([[top]])[]dnl
m4_if(b4_prefix, [yy], [],
[/* Substitute the variable and function names. */
#define yyparse b4_prefix[]parse
@@ -193,9 +185,7 @@ b4_locations_if([#define yylloc b4_prefix[]lloc])])[
# define YYTOKEN_TABLE ]b4_token_table[
#endif
]m4_ifdef([b4_percent_code_requires],
[[/* Copy the %code "requires" blocks. */
]b4_user_code([b4_percent_code_requires])])[]dnl
]b4_get_percent_code([[requires]])[]dnl
b4_token_enums_defines(b4_tokens)[
@@ -225,16 +215,11 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1
#endif])
m4_ifdef([b4_percent_code_provides],
[[/* Copy the %code "provides" blocks. */
]b4_user_code([b4_percent_code_provides])])[]dnl
b4_get_percent_code([[provides]])[]dnl
[/* Copy the second part of user declarations. */
]b4_user_post_prologue
m4_ifdef([b4_percent_code],
[[/* Copy the unqualified %code blocks. */
]b4_user_code([b4_percent_code])
])[]dnl
b4_get_percent_code[]dnl
[#ifdef short
# undef short
@@ -1505,9 +1490,7 @@ b4_defines_if(
b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
[1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
m4_ifdef([b4_percent_code_requires],
[[/* Copy the %code "requires" blocks. */
]b4_user_code([b4_percent_code_requires])])[]dnl
b4_get_percent_code([[requires]])[]dnl
b4_token_enums_defines(b4_tokens)
@@ -1545,8 +1528,8 @@ typedef struct YYLTYPE
[extern YYLTYPE b4_prefix[]lloc;])
)dnl b4_locations_if
m4_ifdef([b4_percent_code_provides],
[[/* Copy the %code "provides" blocks. */
]b4_user_code([b4_percent_code_provides])])[]
b4_get_percent_code([[provides]])
])dnl b4_defines_if
m4_divert_pop(0)
])dnl b4_use_push_for_pull_if

View File

@@ -298,11 +298,11 @@ muscle_boundary_grow (char const *key, boundary bound)
}
void
muscle_grow_used_name_list (char const *key, char const *used_name,
muscle_grow_user_name_list (char const *key, char const *user_name,
location loc)
{
muscle_grow (key, "[[[[", ",");
muscle_grow (key, used_name, "");
muscle_grow (key, user_name, "");
muscle_grow (key, "]], [[", "");
muscle_boundary_grow (key, loc.start);
muscle_grow (key, "]], [[", "");

View File

@@ -117,12 +117,10 @@ void muscles_m4_output (FILE *out);
for special characters in the file name. */
void muscle_boundary_grow (char const *key, boundary bound);
/* Grow KEY for the occurrence of the name USED_NAME at LOC appropriately for
use with b4_check_for_unrecognized_names in ../data/bison.m4. USED_NAME
is not escaped with digraphs, so it must not contain `[' or `]'. As a
precondition on b4_check_for_unrecognized_names, it can't contain `,'
either. */
void muscle_grow_used_name_list (char const *key, char const *used_name,
/* Grow KEY for the occurrence of the name USER_NAME at LOC appropriately for
use with b4_check_user_names in ../data/bison.m4. USER_NAME is not escaped
with digraphs, so it must not contain `[' or `]'. */
void muscle_grow_user_name_list (char const *key, char const *user_name,
location loc);
#endif /* not MUSCLE_TAB_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -165,7 +165,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 1551 of yacc.c */
/* Line 1535 of yacc.c */
#line 97 "parse-gram.y"
symbol *symbol;
@@ -178,7 +178,7 @@ typedef union YYSTYPE
unsigned char character;
}
/* Line 1551 of yacc.c */
/* Line 1535 of yacc.c */
#line 183 "parse-gram.h"
YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1

View File

@@ -183,12 +183,12 @@ static int current_prec = 0;
/* braceless is not to be used for rule or symbol actions, as it
calls code_props_plain_init. */
%type <chars> STRING "%{...%}" EPILOGUE braceless content content.opt
%type <chars> STRING "%{...%}" EPILOGUE braceless content.opt
%type <code> "{...}"
%printer { fputs (quotearg_style (c_quoting_style, $$), stderr); }
STRING
%printer { fprintf (stderr, "{\n%s\n}", $$); }
braceless content content.opt "{...}" "%{...%}" EPILOGUE
braceless content.opt "{...}" "%{...%}" EPILOGUE
%type <uniqstr> TYPE ID ID_COLON
%printer { fprintf (stderr, "<%s>", $$); } TYPE
@@ -236,10 +236,15 @@ prologue_declaration:
{
/* FIXME: Special characters in $2 may break %define.
For example: `['. */
if (muscle_find_const ($2))
warn_at (@2, _("%s: `%s' redefined"), "%define", $2);
muscle_insert ($2, $3);
muscle_grow_used_name_list ("used_percent_define_variables", $2, @2);
char const name_prefix[] = "percent_define_";
char *name = xmalloc (sizeof name_prefix + strlen ($2));
strcpy (name, name_prefix);
strcpy (name + sizeof name_prefix - 1, $2);
if (muscle_find_const (name))
warn_at (@2, _("%s `%s' redefined"), "%define variable", $2);
muscle_insert (uniqstr_new (name), $3);
free (name);
muscle_grow_user_name_list ("user_percent_define_variables", $2, @2);
}
| "%defines" { defines_flag = true; }
| "%defines" STRING
@@ -332,7 +337,7 @@ grammar_declaration:
muscle_code_grow (uniqstr_new (name), $3, @3);
free (name);
code_scanner_last_string_free ();
muscle_grow_used_name_list ("used_percent_code_qualifiers", $2, @2);
muscle_grow_user_name_list ("user_percent_code_qualifiers", $2, @2);
}
;
@@ -530,14 +535,9 @@ rhs:
;
/*-----------*
| content. |
*-----------*/
content:
STRING
| braceless
;
/*---------------*
| content.opt. |
*--------------*/
/* Some content or "1" by default. */
content.opt:
@@ -546,10 +546,14 @@ content.opt:
static char one[] = "1";
$$ = one;
}
| content
| STRING
;
/*-------------*
| braceless. |
*-------------*/
braceless:
"{...}"
{

View File

@@ -703,11 +703,11 @@ AT_CHECK([bison input.y], [1], [],
AT_CLEANUP
## ----------------------------- ##
## Reject bad %code qualifiers. ##
## ----------------------------- ##
## -------------------------------- ##
## Reject unused %code qualifiers. ##
## -------------------------------- ##
AT_SETUP([Reject bad %code qualifiers])
AT_SETUP([Reject unused %code qualifiers])
AT_DATA([input-c.y],
[[%code "" {}
@@ -716,10 +716,10 @@ AT_DATA([input-c.y],
%%
start: ;
]])
AT_CHECK([[bison input-c.y]], [1], [],
[[input-c.y:1.7-8: `' is not a recognized %code qualifier
input-c.y:2.7-11: `bad' is not a recognized %code qualifier
input-c.y:3.7-11: `bad' is not a recognized %code qualifier
AT_CHECK([[bison input-c.y]], [0], [],
[[input-c.y:1.7-8: warning: %code qualifier `' is not used
input-c.y:2.7-11: warning: %code qualifier `bad' is not used
input-c.y:3.7-11: warning: %code qualifier `bad' is not used
]])
AT_DATA([input-c-glr.y],
@@ -729,10 +729,10 @@ AT_DATA([input-c-glr.y],
%%
start: ;
]])
AT_CHECK([[bison input-c-glr.y]], [1], [],
[[input-c-glr.y:1.7-8: `' is not a recognized %code qualifier
input-c-glr.y:2.7-11: `bad' is not a recognized %code qualifier
input-c-glr.y:3.8-12: `bad' is not a recognized %code qualifier
AT_CHECK([[bison input-c-glr.y]], [0], [],
[[input-c-glr.y:1.7-8: warning: %code qualifier `' is not used
input-c-glr.y:2.7-11: warning: %code qualifier `bad' is not used
input-c-glr.y:3.8-12: warning: %code qualifier `bad' is not used
]])
AT_DATA([input-c++.y],
@@ -742,10 +742,10 @@ AT_DATA([input-c++.y],
%%
start: ;
]])
AT_CHECK([[bison input-c++.y]], [1], [],
[[input-c++.y:1.7-8: `' is not a recognized %code qualifier
input-c++.y:2.7-11: `bad' is not a recognized %code qualifier
input-c++.y:3.8-9: `' is not a recognized %code qualifier
AT_CHECK([[bison input-c++.y]], [0], [],
[[input-c++.y:1.7-8: warning: %code qualifier `' is not used
input-c++.y:2.7-11: warning: %code qualifier `bad' is not used
input-c++.y:3.8-9: warning: %code qualifier `' is not used
]])
AT_DATA([input-c++-glr.y],
@@ -755,10 +755,10 @@ AT_DATA([input-c++-glr.y],
%%
start: ;
]])
AT_CHECK([[bison input-c++-glr.y]], [1], [],
[[input-c++-glr.y:1.7-11: `bad' is not a recognized %code qualifier
input-c++-glr.y:2.7-8: `' is not a recognized %code qualifier
input-c++-glr.y:3.7-8: `' is not a recognized %code qualifier
AT_CHECK([[bison input-c++-glr.y]], [0], [],
[[input-c++-glr.y:1.7-11: warning: %code qualifier `bad' is not used
input-c++-glr.y:2.7-8: warning: %code qualifier `' is not used
input-c++-glr.y:3.7-8: warning: %code qualifier `' is not used
]])
AT_DATA([special-char-@@.y],
@@ -768,10 +768,10 @@ AT_DATA([special-char-@@.y],
%%
start: ;
]])
AT_CHECK([[bison special-char-@@.y]], [1], [],
[[special-char-@@.y:1.7-11: `bad' is not a recognized %code qualifier
special-char-@@.y:2.7-8: `' is not a recognized %code qualifier
special-char-@@.y:3.7-8: `' is not a recognized %code qualifier
AT_CHECK([[bison special-char-@@.y]], [0], [],
[[special-char-@@.y:1.7-11: warning: %code qualifier `bad' is not used
special-char-@@.y:2.7-8: warning: %code qualifier `' is not used
special-char-@@.y:3.7-8: warning: %code qualifier `' is not used
]])
AT_DATA([special-char-@:>@.y],
@@ -781,10 +781,10 @@ AT_DATA([special-char-@:>@.y],
%%
start: ;
]])
AT_CHECK([[bison special-char-@:>@.y]], [1], [],
[[special-char-@:>@.y:1.7-11: `bad' is not a recognized %code qualifier
special-char-@:>@.y:2.7-8: `' is not a recognized %code qualifier
special-char-@:>@.y:3.7-8: `' is not a recognized %code qualifier
AT_CHECK([[bison special-char-@:>@.y]], [0], [],
[[special-char-@:>@.y:1.7-11: warning: %code qualifier `bad' is not used
special-char-@:>@.y:2.7-8: warning: %code qualifier `' is not used
special-char-@:>@.y:3.7-8: warning: %code qualifier `' is not used
]])
AT_CLEANUP
@@ -804,12 +804,12 @@ AT_DATA([input.y],
start: ;
]])
AT_CHECK([[bison input.y]], [1], [],
[[input.y:2.9-13: warning: %define: `var' redefined
input.y:3.10-14: warning: %define: `var' redefined
input.y:1.9-13: `var' is not a recognized %define variable
input.y:2.9-13: `var' is not a recognized %define variable
input.y:3.10-14: `var' is not a recognized %define variable
AT_CHECK([[bison input.y]], [0], [],
[[input.y:2.9-13: warning: %define variable `var' redefined
input.y:3.10-14: warning: %define variable `var' redefined
input.y:1.9-13: warning: %define variable `var' is not used
input.y:2.9-13: warning: %define variable `var' is not used
input.y:3.10-14: warning: %define variable `var' is not used
]])
AT_CLEANUP