Support enum items shadowing type identifiers
SystemVerilog allows a declaration in an inner scope to use the same name as a
type identifier from an outer scope. This also applies to enum item names. The
lexer reports such names as `TYPE_IDENTIFIER` before the enum item has been
installed, which made constructs such as:
typedef int T;
module test;
enum { T = 1 } e;
endmodule
fail in the enum item grammar.
Enum item declarations do not have the local type/name ambiguity that exists for
variable, net, or parameter declarations. The name in each `enum_name`
production is always the enum item name, including the sequence forms like
`T[2]` and `T[1:2]`. Use `identifier_name` for these names so they can shadow a
visible type identifier.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
60a81493cd
commit
0c7341be37
9
parse.y
9
parse.y
|
|
@ -3242,20 +3242,23 @@ pos_neg_number
|
|||
}
|
||||
;
|
||||
|
||||
/* Enum items are declaration names. Use identifier_name so an enum item can
|
||||
shadow a visible type identifier without introducing a type/name
|
||||
ambiguity. */
|
||||
enum_name
|
||||
: IDENTIFIER initializer_opt
|
||||
: identifier_name initializer_opt
|
||||
{ perm_string name = lex_strings.make($1);
|
||||
delete[]$1;
|
||||
$$ = make_named_number(@$, name, $2);
|
||||
}
|
||||
| IDENTIFIER '[' pos_neg_number ']' initializer_opt
|
||||
| identifier_name '[' pos_neg_number ']' initializer_opt
|
||||
{ perm_string name = lex_strings.make($1);
|
||||
long count = check_enum_seq_value(@1, $3, false);
|
||||
$$ = make_named_numbers(@$, name, 0, count-1, $5);
|
||||
delete[]$1;
|
||||
delete $3;
|
||||
}
|
||||
| IDENTIFIER '[' pos_neg_number ':' pos_neg_number ']' initializer_opt
|
||||
| identifier_name '[' pos_neg_number ':' pos_neg_number ']' initializer_opt
|
||||
{ perm_string name = lex_strings.make($1);
|
||||
$$ = make_named_numbers(@$, name, check_enum_seq_value(@1, $3, true),
|
||||
check_enum_seq_value(@1, $5, true), $7);
|
||||
|
|
|
|||
Loading…
Reference in New Issue