summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim@lrde.epita.fr>2013-04-22 13:55:00 +0200
committerAkim Demaille <akim@lrde.epita.fr>2013-04-22 13:55:00 +0200
commitf249e803f032cc5e2bdce431589067595fdfd4ef (patch)
tree11346c76713a7f13badbeac485de713ea0655fe7
parentdfb12d684501e72538f50f9f5355ca4f15931533 (diff)
downloadbison-f249e803f032cc5e2bdce431589067595fdfd4ef.tar.gz
diagnostics: always point to the first directive
Some directives cannot be used several times (e.g., a given symbol may only have a single printer). In case of repeated definitions, an error is issued for the second definition, yet it is not discarded, and becomes the definition used for the rest of the file. This is not consistent with the idea that multiple definitions are not allowed: discard any repeated directive. * src/symtab.c (symbol_type_set, symbol_code_props_set) (semantic_type_code_props_set, symbol_class_set, symbol_translation): Discard repeated directives. * tests/input.at (Default %printer and %destructor redeclared) (Per-type %printer and %destructor redeclared): Update expectations.
-rw-r--r--src/symtab.c22
-rw-r--r--tests/input.at16
2 files changed, 22 insertions, 16 deletions
diff --git a/src/symtab.c b/src/symtab.c
index 11a0d756..7141f7db 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -243,9 +243,12 @@ symbol_type_set (symbol *sym, uniqstr type_name, location loc)
{
if (sym->type_name)
symbol_redeclaration (sym, "%type", sym->type_location, loc);
- uniqstr_assert (type_name);
- sym->type_name = type_name;
- sym->type_location = loc;
+ else
+ {
+ uniqstr_assert (type_name);
+ sym->type_name = type_name;
+ sym->type_location = loc;
+ }
}
}
@@ -261,7 +264,8 @@ symbol_code_props_set (symbol *sym, code_props_type kind,
symbol_redeclaration (sym, code_props_type_string (kind),
sym->props[kind].location,
code->location);
- sym->props[kind] = *code;
+ else
+ sym->props[kind] = *code;
}
/*-----------------------------------------------------.
@@ -277,7 +281,8 @@ semantic_type_code_props_set (semantic_type *type,
semantic_type_redeclaration (type, code_props_type_string (kind),
type->props[kind].location,
code->location);
- type->props[kind] = *code;
+ else
+ type->props[kind] = *code;
}
/*---------------------------------------------------.
@@ -363,7 +368,8 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
{
if (sym->status == declared && !warned)
complain (&loc, Wother, _("symbol %s redeclared"), sym->tag);
- sym->status = declared;
+ else
+ sym->status = declared;
}
}
@@ -618,8 +624,8 @@ symbol_translation (symbol *this)
(this->user_token_number,
symbols[token_translations[this->user_token_number]],
this);
-
- token_translations[this->user_token_number] = this->number;
+ else
+ token_translations[this->user_token_number] = this->number;
}
return true;
diff --git a/tests/input.at b/tests/input.at
index 82396588..eb73bf96 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -382,14 +382,14 @@ input.y:2.10-24: previous declaration
input.y:11.13-29: error: %destructor redeclaration for <>
%destructor { destroy ($$); } <>;
^^^^^^^^^^^^^^^^^
-input.y:4.13-29: previous declaration
- %destructor { destroy ($$); } <>
+input.y:1.13-29: previous declaration
+ %destructor { destroy ($$); } <> <>
^^^^^^^^^^^^^^^^^
input.y:12.10-24: error: %printer redeclaration for <>
%printer { print ($$); } <>;
^^^^^^^^^^^^^^^
-input.y:5.10-24: previous declaration
- %printer { print ($$); } <>
+input.y:2.10-24: previous declaration
+ %printer { print ($$); } <> <>
^^^^^^^^^^^^^^^
]])
])
@@ -426,17 +426,17 @@ AT_BISON_CHECK([input.y], [1], [],
[[input.y:4.13-29: error: %destructor redeclaration for <field1>
input.y:1.13-29: previous declaration
input.y:4.13-29: error: %destructor redeclaration for <field1>
-input.y:4.13-29: previous declaration
+input.y:1.13-29: previous declaration
input.y:5.10-24: error: %printer redeclaration for <field2>
input.y:2.10-24: previous declaration
input.y:5.10-24: error: %printer redeclaration for <field2>
-input.y:5.10-24: previous declaration
+input.y:2.10-24: previous declaration
input.y:11.13-29: error: %destructor redeclaration for <field2>
input.y:1.13-29: previous declaration
input.y:11.13-29: error: %destructor redeclaration for <field1>
-input.y:4.13-29: previous declaration
+input.y:1.13-29: previous declaration
input.y:12.10-24: error: %printer redeclaration for <field2>
-input.y:5.10-24: previous declaration
+input.y:2.10-24: previous declaration
input.y:12.10-24: error: %printer redeclaration for <field1>
input.y:2.10-24: previous declaration
]])