Skip to content

Commit 13577a8

Browse files
committed
style: prefer passing locations by pointer
The code is inconsistent: sometimes we pass by value, sometimes by reference. Let's stick to the last, more conventional for large values in C. * src/scan-code.l: Pass locations by reference.
1 parent afc219a commit 13577a8

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/scan-code.l

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ YY_DECL;
4848
#define YY_USER_ACTION location_compute (loc, &loc->end, yytext, yyleng);
4949

5050
static char *fetch_type_name (char *cp, char const **type_name,
51-
location dollar_loc);
51+
const location *dollar_loc);
5252

5353
static void handle_action_dollar (symbol_list *rule, char *cp,
54-
location dollar_loc);
55-
static void handle_action_at (symbol_list *rule, char *cp, location at_loc);
54+
const location *dollar_loc);
55+
static void handle_action_at (symbol_list *rule, char *cp,
56+
const location *at_loc);
5657

5758
/* A string to be pushed to obstack after dollar/at has been handled. */
5859
static char *ref_tail_fields;
@@ -163,13 +164,13 @@ ref -?[0-9]+|{id}|"["{id}"]"|"$"
163164
{
164165
"$"("<"{tag}">")?{ref} {
165166
ref_tail_fields = NULL;
166-
handle_action_dollar (self->rule, yytext, *loc);
167+
handle_action_dollar (self->rule, yytext, loc);
167168
if (ref_tail_fields)
168169
obstack_sgrow (&obstack_for_string, ref_tail_fields);
169170
}
170171
"@"{ref} {
171172
ref_tail_fields = NULL;
172-
handle_action_at (self->rule, yytext, *loc);
173+
handle_action_at (self->rule, yytext, loc);
173174
if (ref_tail_fields)
174175
obstack_sgrow (&obstack_for_string, ref_tail_fields);
175176
}
@@ -179,7 +180,7 @@ ref -?[0-9]+|{id}|"["{id}"]"|"$"
179180
{
180181
"$"("<"{tag}">")?"$" {
181182
const char *type_name = NULL;
182-
fetch_type_name (yytext + 1, &type_name, *loc)[-1] = 0;
183+
fetch_type_name (yytext + 1, &type_name, loc)[-1] = 0;
183184
obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar(");
184185
obstack_quote (&obstack_for_string, type_name);
185186
obstack_sgrow (&obstack_for_string, ")[");
@@ -406,7 +407,7 @@ show_sub_messages (warnings warning,
406407
accesses. */
407408
static long
408409
parse_ref (char *cp, symbol_list *rule, int rule_length,
409-
int midrule_rhs_index, char *text, location text_loc,
410+
int midrule_rhs_index, char *text, const location *text_loc,
410411
char dollar_or_at)
411412
{
412413
if ('$' == *cp)
@@ -419,7 +420,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
419420
return num;
420421
else
421422
{
422-
complain (&text_loc, complaint, _("integer out of range: %s"),
423+
complain (text_loc, complaint, _("integer out of range: %s"),
423424
quote (text));
424425
return INVALID_REF;
425426
}
@@ -493,12 +494,12 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
493494
cp_end - cp : ref_tail_fields - cp;
494495
unsigned indent = 0;
495496

496-
complain_indent (&text_loc, complaint, &indent,
497+
complain_indent (text_loc, complaint, &indent,
497498
_("invalid reference: %s"), quote (text));
498499
indent += SUB_INDENT;
499500
if (len == 0)
500501
{
501-
location sym_loc = text_loc;
502+
location sym_loc = *text_loc;
502503
sym_loc.start.column += 1;
503504
sym_loc.end = sym_loc.start;
504505
complain_indent (&sym_loc, complaint, &indent,
@@ -527,7 +528,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
527528
unsigned indent = 0;
528529
if (variant_count > 1)
529530
{
530-
complain_indent (&text_loc, Wother, &indent,
531+
complain_indent (text_loc, Wother, &indent,
531532
_("misleading reference: %s"), quote (text));
532533
show_sub_messages (Wother,
533534
cp, explicit_bracketing, midrule_rhs_index,
@@ -543,7 +544,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
543544
default:
544545
{
545546
unsigned indent = 0;
546-
complain_indent (&text_loc, complaint, &indent,
547+
complain_indent (text_loc, complaint, &indent,
547548
_("ambiguous reference: %s"), quote (text));
548549
show_sub_messages (complaint,
549550
cp, explicit_bracketing, midrule_rhs_index,
@@ -566,7 +567,7 @@ int max_left_semantic_context = 0;
566567
static
567568
char *
568569
fetch_type_name (char *cp, char const **type_name,
569-
location dollar_loc)
570+
const location *dollar_loc)
570571
{
571572
if (*cp == '<')
572573
{
@@ -579,7 +580,7 @@ fetch_type_name (char *cp, char const **type_name,
579580
'text' is needed for error messages. */
580581
++cp;
581582
if (untyped_var_seen)
582-
complain (&dollar_loc, complaint,
583+
complain (dollar_loc, complaint,
583584
_("explicit type given in untyped grammar"));
584585
tag_seen = true;
585586
}
@@ -595,7 +596,7 @@ fetch_type_name (char *cp, char const **type_name,
595596
`------------------------------------------------------------------*/
596597

597598
static void
598-
handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
599+
handle_action_dollar (symbol_list *rule, char *text, const location *dollar_loc)
599600
{
600601
symbol_list *effective_rule;
601602
int effective_rule_length;
@@ -634,13 +635,13 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
634635
if (union_seen || tag_seen)
635636
{
636637
if (rule->midrule_parent_rule)
637-
complain (&dollar_loc, complaint,
638+
complain (dollar_loc, complaint,
638639
_("$$ for the midrule at $%d of %s"
639640
" has no declared type"),
640641
rule->midrule_parent_rhs_index,
641642
quote (effective_rule->content.sym->tag));
642643
else
643-
complain (&dollar_loc, complaint,
644+
complain (dollar_loc, complaint,
644645
_("$$ of %s has no declared type"),
645646
quote (rule->content.sym->tag));
646647
}
@@ -666,7 +667,7 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
666667
&& (!sym || !sym->content.sym->content->type_name))
667668
{
668669
if (union_seen || tag_seen)
669-
complain (&dollar_loc, complaint,
670+
complain (dollar_loc, complaint,
670671
_("$%s of %s has no declared type"), cp,
671672
quote (effective_rule->content.sym->tag));
672673
else
@@ -689,7 +690,7 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
689690
{
690691
if (muscle_percent_define_ifdef ("api.value.automove")
691692
&& sym->action_props.is_value_used)
692-
complain (&dollar_loc, Wother,
693+
complain (dollar_loc, Wother,
693694
_("multiple occurrences of $%d with api.value.automove"),
694695
n);
695696
sym->action_props.is_value_used = true;
@@ -706,7 +707,7 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
706707
`------------------------------------------------------*/
707708

708709
static void
709-
handle_action_at (symbol_list *rule, char *text, location at_loc)
710+
handle_action_at (symbol_list *rule, char *text, const location *at_loc)
710711
{
711712
symbol_list *effective_rule;
712713
int effective_rule_length;
@@ -722,7 +723,7 @@ handle_action_at (symbol_list *rule, char *text, location at_loc)
722723
effective_rule_length = symbol_list_length (rule->next);
723724
}
724725

725-
muscle_percent_define_ensure("locations", at_loc, true);
726+
muscle_percent_define_ensure ("locations", *at_loc, true);
726727

727728
int n = parse_ref (text + 1, effective_rule, effective_rule_length,
728729
rule->midrule_parent_rhs_index, text, at_loc, '@');

0 commit comments

Comments
 (0)