mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
Check for unrecognized %define variables similar to checking for
unrecognized %code qualifiers. Check for redefined %define variables. * data/bison.m4 (b4_check_for_unrecognized_names): New macro that generalizes... (b4_check_percent_code_qualifiers): ... this, which now wraps it. (b4_check_percent_define_variables): New, also wraps it. * data/glr.c: Unless glr.cc is wrapping glr.c, declare no valid %define variables using b4_check_percent_define_variables. * data/glr.cc, data/lalr1.cc: Declare the valid %define variables as all those exercised in the test suite and all those listed in the `Default values' section of c++.m4. Are there others? * data/push.c, data/yacc.c: Declare no valid %define variables. * src/muscle_tab.c, src/muscle_tab.h (muscle_find_const): New function, similar to muscle_find, but it works even when the muscle stores a const value. (muscle_grow_used_name_list): New function for constructing the used name list muscles that b4_check_for_unrecognized_names requires. * src/parse-gram.y (prologue_declaration): Warn if a variable is %define'd more than once. Define the b4_used_percent_define_variables muscle with muscle_grow_used_name_list. (grammar_declaration): Abbreviate %code code with muscle_grow_used_name_list. * tests/input.at (%define errors): New.
This commit is contained in:
@@ -209,6 +209,26 @@ void muscle_pair_list_grow (const char *muscle,
|
||||
obstack_free (&muscle_obstack, pair);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------.
|
||||
| Find the value of muscle KEY. Unlike MUSCLE_FIND, this is always reliable |
|
||||
| to determine whether KEY has a value. |
|
||||
`----------------------------------------------------------------------------*/
|
||||
|
||||
char const *
|
||||
muscle_find_const (char const *key)
|
||||
{
|
||||
muscle_entry probe;
|
||||
muscle_entry *result = NULL;
|
||||
|
||||
probe.key = key;
|
||||
result = hash_lookup (muscle_table, &probe);
|
||||
if (result)
|
||||
return result->value;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------.
|
||||
| Find the value of muscle KEY. Abort if muscle_insert was invoked more |
|
||||
| recently than muscle_grow for KEY since muscle_find can't return a |
|
||||
@@ -216,7 +236,7 @@ void muscle_pair_list_grow (const char *muscle,
|
||||
`----------------------------------------------------------------------------*/
|
||||
|
||||
char *
|
||||
muscle_find (const char *key)
|
||||
muscle_find (char const *key)
|
||||
{
|
||||
muscle_entry probe;
|
||||
muscle_entry *result = NULL;
|
||||
@@ -276,3 +296,16 @@ muscle_boundary_grow (char const *key, boundary bound)
|
||||
muscle_grow (key, extension, "");
|
||||
obstack_free (&muscle_obstack, extension);
|
||||
}
|
||||
|
||||
void
|
||||
muscle_grow_used_name_list (char const *key, char const *used_name,
|
||||
location loc)
|
||||
{
|
||||
muscle_grow (key, "[[[[", ",");
|
||||
muscle_grow (key, used_name, "");
|
||||
muscle_grow (key, "]], [[", "");
|
||||
muscle_boundary_grow (key, loc.start);
|
||||
muscle_grow (key, "]], [[", "");
|
||||
muscle_boundary_grow (key, loc.end);
|
||||
muscle_grow (key, "]]]]", "");
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
void muscle_init (void);
|
||||
void muscle_insert (char const *key, char const *value);
|
||||
char *muscle_find (char const *key);
|
||||
char const *muscle_find_const (char const *key);
|
||||
void muscle_free (void);
|
||||
|
||||
|
||||
@@ -116,4 +117,12 @@ 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,
|
||||
location loc);
|
||||
|
||||
#endif /* not MUSCLE_TAB_H_ */
|
||||
|
||||
485
src/parse-gram.c
485
src/parse-gram.c
File diff suppressed because it is too large
Load Diff
@@ -165,8 +165,8 @@
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
{
|
||||
/* Line 1546 of yacc.c */
|
||||
#line 98 "parse-gram.y"
|
||||
/* Line 1551 of yacc.c */
|
||||
#line 97 "parse-gram.y"
|
||||
|
||||
symbol *symbol;
|
||||
symbol_list *list;
|
||||
@@ -178,7 +178,7 @@ typedef union YYSTYPE
|
||||
unsigned char character;
|
||||
}
|
||||
|
||||
/* Line 1546 of yacc.c */
|
||||
/* Line 1551 of yacc.c */
|
||||
#line 183 "parse-gram.h"
|
||||
YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
|
||||
@@ -82,7 +82,6 @@ static int current_prec = 0;
|
||||
%locations
|
||||
%pure-parser
|
||||
%error-verbose
|
||||
%defines
|
||||
%name-prefix="gram_"
|
||||
%expect 0
|
||||
|
||||
@@ -233,7 +232,15 @@ prologue_declaration:
|
||||
code_scanner_last_string_free ();
|
||||
}
|
||||
| "%debug" { debug_flag = true; }
|
||||
| "%define" STRING content.opt { muscle_insert ($2, $3); }
|
||||
| "%define" STRING content.opt
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
| "%defines" { defines_flag = true; }
|
||||
| "%defines" STRING
|
||||
{
|
||||
@@ -316,6 +323,8 @@ grammar_declaration:
|
||||
}
|
||||
| "%code" STRING braceless
|
||||
{
|
||||
/* FIXME: Special characters in $2 may break %code.
|
||||
For example: `['. */
|
||||
char const name_prefix[] = "percent_code_";
|
||||
char *name = xmalloc (sizeof name_prefix + strlen ($2));
|
||||
strcpy (name, name_prefix);
|
||||
@@ -323,13 +332,7 @@ grammar_declaration:
|
||||
muscle_code_grow (uniqstr_new (name), $3, @3);
|
||||
free (name);
|
||||
code_scanner_last_string_free ();
|
||||
muscle_grow ("used_percent_code_qualifiers", "[[[[", ",");
|
||||
muscle_grow ("used_percent_code_qualifiers", $2, "");
|
||||
muscle_grow ("used_percent_code_qualifiers", "]], [[", "");
|
||||
muscle_boundary_grow ("used_percent_code_qualifiers", @2.start);
|
||||
muscle_grow ("used_percent_code_qualifiers", "]], [[", "");
|
||||
muscle_boundary_grow ("used_percent_code_qualifiers", @2.end);
|
||||
muscle_grow ("used_percent_code_qualifiers", "]]]]", "");
|
||||
muscle_grow_used_name_list ("used_percent_code_qualifiers", $2, @2);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user