Skip to content

Commit b0fa961

Browse files
authored
Merge pull request #320 from diffblue/verilog_module_sourcet_ports
Verilog: strengthen typing of verilog_module_sourcet::ports
2 parents 445ab39 + bfba9fe commit b0fa961

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/verilog/verilog_expr.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,9 +1422,11 @@ class verilog_module_sourcet : public irept
14221422
return (parameter_port_listt &)(add(ID_parameter_port_list).get_sub());
14231423
}
14241424

1425-
const exprt::operandst &ports() const
1425+
using port_listt = std::vector<verilog_declt>;
1426+
1427+
const port_listt &ports() const
14261428
{
1427-
return (const exprt::operandst &)(find(ID_ports).get_sub());
1429+
return (const port_listt &)(find(ID_ports).get_sub());
14281430
}
14291431

14301432
using module_itemst = std::vector<class verilog_module_itemt>;

src/verilog/verilog_interfaces.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,22 @@ void verilog_typecheckt::check_module_ports(
6161

6262
unsigned nr=0;
6363

64-
for(auto &port : module_ports)
64+
for(auto &decl : module_ports)
6565
{
66-
assert(port.id() == ID_decl);
66+
DATA_INVARIANT(decl.id() == ID_decl, "port declaration id");
67+
DATA_INVARIANT(
68+
decl.declarators().size() == 1,
69+
"port declarations must have one declarator");
6770

68-
const verilog_declt &decl = to_verilog_decl(port);
71+
const auto &declarator = decl.declarators().front();
6972

70-
assert(decl.operands().size()==1);
71-
const auto &declarator = to_unary_expr(decl).op();
72-
assert(declarator.id() == ID_symbol);
73+
const irep_idt &name = declarator.identifier();
74+
const irep_idt &port_class = decl.get_class();
7375

74-
const irep_idt &name = to_symbol_expr(declarator).get_identifier();
75-
const irep_idt &port_class=decl.get(ID_class);
76-
7776
if(name.empty())
7877
{
79-
error().source_location =
80-
static_cast<const exprt &>(port).source_location();
81-
error() << "empty port name (module "
82-
<< module_symbol.base_name << ')' << eom;
83-
throw 0;
78+
throw errort().with_location(decl.source_location())
79+
<< "empty port name (module " << module_symbol.base_name << ')';
8480
}
8581

8682
if(port_names.find(name)!=

0 commit comments

Comments
 (0)