Skip to content

SystemVerilog: fix identifier on enum type #919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/verilog/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1467,8 +1467,8 @@ data_type:

// We attach a dummy id to distinguish two syntactically
// identical enum types.
auto id = PARSER.current_scope->prefix + "enum-" + PARSER.get_next_id();
stack_expr($$).set(ID_identifier, id);
auto base_name = "enum-" + PARSER.get_next_id();
stack_expr($$).set(ID_base_name, base_name);
}
| TOK_STRING
{ init($$, ID_string); }
Expand Down
8 changes: 6 additions & 2 deletions src/verilog/verilog_elaborate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ void verilog_typecheckt::collect_symbols(const typet &type)
// Add a symbol for the enum to the symbol table.
// This allows looking up the enum name identifiers.
{
auto identifier = enum_type.identifier();
type_symbolt enum_type_symbol(identifier, enum_type, mode);
const auto base_name = enum_type.base_name();
const auto identifier = hierarchical_identifier(base_name);
auto enum_type_with_identifier = enum_type;
enum_type_with_identifier.identifier(identifier);
type_symbolt enum_type_symbol(
identifier, enum_type_with_identifier, mode);
enum_type_symbol.module = module_identifier;
enum_type_symbol.is_file_local = true;
enum_type_symbol.location = enum_type.source_location();
Expand Down
13 changes: 12 additions & 1 deletion src/verilog/verilog_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,23 @@ class verilog_enum_typet : public type_with_subtypet
return (enum_namest &)(add(ID_enum_names).get_sub());
}

// The identifier is generated by the parser, using a counter.
// The base name is generated by the parser, using a counter.
irep_idt base_name() const
{
return get(ID_base_name);
}

// Generated by the type checker.
irep_idt identifier() const
{
return get(ID_identifier);
}

void identifier(irep_idt __identifier)
{
return set(ID_identifier, __identifier);
}

protected:
// use base_type instead
using type_with_subtypet::subtype;
Expand Down
Loading