style: clarify the use of symbol_lists' locations

symbol_list features a 'location' and a 'sym_loc' member.  The former
is expected to be set only for symbol_lists that denote a symbol (not
a type name), and the latter should only denote the location of the
symbol/type name.  Yet both are set, and the name "location" is too
unprecise.

* src/symlist.h, src/symlist.c (symbol_list::location): Rename as
rhs_loc for clarity.  Move it to the "section" of data valid only
for rules.
* src/reader.c, src/scan-code.l: Adjust.
This commit is contained in:
Akim Demaille
2019-05-03 08:30:02 +02:00
parent 5bb44cca81
commit 365b4d95a4
4 changed files with 22 additions and 19 deletions

View File

@@ -295,7 +295,7 @@ grammar_rule_check_and_complete (symbol_list *r)
char const *rhs_type = char const *rhs_type =
first_rhs->content->type_name ? first_rhs->content->type_name : ""; first_rhs->content->type_name ? first_rhs->content->type_name : "";
if (!UNIQSTR_EQ (lhs_type, rhs_type)) if (!UNIQSTR_EQ (lhs_type, rhs_type))
complain (&r->location, Wother, complain (&r->rhs_loc, Wother,
_("type clash on default action: <%s> != <%s>"), _("type clash on default action: <%s> != <%s>"),
lhs_type, rhs_type); lhs_type, rhs_type);
else else
@@ -308,7 +308,7 @@ grammar_rule_check_and_complete (symbol_list *r)
if (is_cxx) if (is_cxx)
{ {
code_props_rule_action_init (&r->action_props, "{ $$ = $1; }", code_props_rule_action_init (&r->action_props, "{ $$ = $1; }",
r->location, r, r->rhs_loc, r,
/* name */ NULL, /* name */ NULL,
/* type */ NULL, /* type */ NULL,
/* is_predicate */ false); /* is_predicate */ false);
@@ -318,7 +318,7 @@ grammar_rule_check_and_complete (symbol_list *r)
} }
/* Warn if there is no default for $$ but we need one. */ /* Warn if there is no default for $$ but we need one. */
else else
complain (&r->location, Wother, complain (&r->rhs_loc, Wother,
_("empty rule for typed nonterminal, and no action")); _("empty rule for typed nonterminal, and no action"));
} }
@@ -335,9 +335,9 @@ grammar_rule_check_and_complete (symbol_list *r)
{ {
warnings warn_flag = midrule_warning ? Wmidrule_values : Wother; warnings warn_flag = midrule_warning ? Wmidrule_values : Wother;
if (n) if (n)
complain (&l->location, warn_flag, _("unused value: $%d"), n); complain (&l->sym_loc, warn_flag, _("unused value: $%d"), n);
else else
complain (&l->location, warn_flag, _("unset value: $$")); complain (&l->rhs_loc, warn_flag, _("unset value: $$"));
} }
} }
} }
@@ -357,9 +357,9 @@ grammar_rule_check_and_complete (symbol_list *r)
&& !r->percent_empty_loc.start.file && !r->percent_empty_loc.start.file
&& warning_is_enabled (Wempty_rule)) && warning_is_enabled (Wempty_rule))
{ {
complain (&r->location, Wempty_rule, complain (&r->rhs_loc, Wempty_rule,
_("empty rule without %%empty")); _("empty rule without %%empty"));
fixits_register (&r->location, " %empty "); fixits_register (&r->rhs_loc, " %empty ");
} }
/* See comments in grammar_current_rule_prec_set for how POSIX /* See comments in grammar_current_rule_prec_set for how POSIX
@@ -369,12 +369,12 @@ grammar_rule_check_and_complete (symbol_list *r)
&& r->ruleprec->tag[0] != '\'' && r->ruleprec->tag[0] != '"' && r->ruleprec->tag[0] != '\'' && r->ruleprec->tag[0] != '"'
&& r->ruleprec->content->status != declared && r->ruleprec->content->status != declared
&& !r->ruleprec->content->prec) && !r->ruleprec->content->prec)
complain (&r->location, Wother, complain (&r->rhs_loc, Wother,
_("token for %%prec is not defined: %s"), r->ruleprec->tag); _("token for %%prec is not defined: %s"), r->ruleprec->tag);
/* Check that the (main) action was not typed. */ /* Check that the (main) action was not typed. */
if (r->action_props.type) if (r->action_props.type)
complain (&r->location, Wother, complain (&r->rhs_loc, Wother,
_("only midrule actions can be typed: %s"), r->action_props.type); _("only midrule actions can be typed: %s"), r->action_props.type);
} }
@@ -387,8 +387,8 @@ void
grammar_current_rule_end (location loc) grammar_current_rule_end (location loc)
{ {
/* Put an empty link in the list to mark the end of this rule */ /* Put an empty link in the list to mark the end of this rule */
grammar_symbol_append (NULL, grammar_end->location); grammar_symbol_append (NULL, grammar_end->rhs_loc);
current_rule->location = loc; current_rule->rhs_loc = loc;
} }
@@ -422,7 +422,7 @@ grammar_midrule_action (void)
++nrules; ++nrules;
++nritems; ++nritems;
/* Attach its location and actions to that of the DUMMY. */ /* Attach its location and actions to that of the DUMMY. */
midrule->location = dummy_location; midrule->rhs_loc = dummy_location;
code_props_rule_action_init (&midrule->action_props, code_props_rule_action_init (&midrule->action_props,
current_rule->action_props.code, current_rule->action_props.code,
current_rule->action_props.location, current_rule->action_props.location,
@@ -647,7 +647,7 @@ packgram (void)
rules[ruleno].dprec = lhs->dprec; rules[ruleno].dprec = lhs->dprec;
rules[ruleno].merger = lhs->merger; rules[ruleno].merger = lhs->merger;
rules[ruleno].precsym = NULL; rules[ruleno].precsym = NULL;
rules[ruleno].location = lhs->location; rules[ruleno].location = lhs->rhs_loc;
rules[ruleno].useful = true; rules[ruleno].useful = true;
rules[ruleno].action = lhs->action_props.code; rules[ruleno].action = lhs->action_props.code;
rules[ruleno].action_location = lhs->action_props.location; rules[ruleno].action_location = lhs->action_props.location;
@@ -824,7 +824,7 @@ check_and_convert_grammar (void)
$accept: %start $end. */ $accept: %start $end. */
{ {
symbol_list *p = symbol_list_sym_new (accept, empty_location); symbol_list *p = symbol_list_sym_new (accept, empty_location);
p->location = grammar->location; p->rhs_loc = grammar->rhs_loc;
p->next = symbol_list_sym_new (startsymbol, empty_location); p->next = symbol_list_sym_new (startsymbol, empty_location);
p->next->next = symbol_list_sym_new (endtoken, empty_location); p->next->next = symbol_list_sym_new (endtoken, empty_location);
p->next->next->next = symbol_list_sym_new (NULL, empty_location); p->next->next->next = symbol_list_sym_new (NULL, empty_location);

View File

@@ -507,12 +507,12 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
dollar_or_at); dollar_or_at);
} }
else if (midrule_rhs_index) else if (midrule_rhs_index)
complain_indent (&rule->location, complaint, &indent, complain_indent (&rule->rhs_loc, complaint, &indent,
_("symbol not found in production before $%d: " _("symbol not found in production before $%d: "
"%.*s"), "%.*s"),
midrule_rhs_index, len, cp); midrule_rhs_index, len, cp);
else else
complain_indent (&rule->location, complaint, &indent, complain_indent (&rule->rhs_loc, complaint, &indent,
_("symbol not found in production: %.*s"), _("symbol not found in production: %.*s"),
len, cp); len, cp);

View File

@@ -34,7 +34,7 @@ symbol_list_sym_new (symbol *sym, location loc)
res->content_type = SYMLIST_SYMBOL; res->content_type = SYMLIST_SYMBOL;
res->content.sym = sym; res->content.sym = sym;
res->location = res->sym_loc = loc; res->sym_loc = loc;
res->named_ref = NULL; res->named_ref = NULL;
res->midrule = NULL; res->midrule = NULL;
@@ -42,6 +42,7 @@ symbol_list_sym_new (symbol *sym, location loc)
res->midrule_parent_rhs_index = 0; res->midrule_parent_rhs_index = 0;
/* Members used for LHS only. */ /* Members used for LHS only. */
res->rhs_loc = empty_location;
res->ruleprec = NULL; res->ruleprec = NULL;
res->percent_empty_loc = empty_location; res->percent_empty_loc = empty_location;
code_props_none_init (&res->action_props); code_props_none_init (&res->action_props);
@@ -73,7 +74,7 @@ symbol_list_type_new (uniqstr type_name, location loc)
res->content.sem_type->location = loc; res->content.sem_type->location = loc;
res->content.sem_type->status = undeclared; res->content.sem_type->status = undeclared;
res->location = res->sym_loc = loc; res->sym_loc = loc;
res->named_ref = NULL; res->named_ref = NULL;
res->next = NULL; res->next = NULL;

View File

@@ -50,7 +50,6 @@ typedef struct symbol_list
*/ */
semantic_type *sem_type; semantic_type *sem_type;
} content; } content;
location location;
/* Named reference. */ /* Named reference. */
named_ref *named_ref; named_ref *named_ref;
@@ -74,6 +73,9 @@ typedef struct symbol_list
| when several RHSs are bound to a single lhs via "|"). | | when several RHSs are bound to a single lhs via "|"). |
`--------------------------------------------------------------*/ `--------------------------------------------------------------*/
/* Location of the RHS. */
location rhs_loc;
/* Precedence/associativity. */ /* Precedence/associativity. */
symbol *ruleprec; symbol *ruleprec;