@@ -1260,7 +1260,7 @@ exprt verilog_typecheck_exprt::convert_nullary_expr(nullary_exprt expr)
12601260
12611261/* ******************************************************************\
12621262
1263- Function: verilog_typecheck_exprt::convert_symbol
1263+ Function: verilog_typecheck_exprt::resolve
12641264
12651265 Inputs:
12661266
@@ -1270,58 +1270,66 @@ Function: verilog_typecheck_exprt::convert_symbol
12701270
12711271\*******************************************************************/
12721272
1273- exprt verilog_typecheck_exprt::convert_symbol (
1274- symbol_exprt expr,
1275- const std::optional<typet> &implicit_net_type)
1273+ const symbolt *verilog_typecheck_exprt::resolve (const symbol_exprt &expr)
12761274{
1277- const irep_idt &identifier = expr.get_identifier ();
1278-
1279- std::string full_identifier;
1275+ const irep_idt &base_name = expr.get_identifier ();
12801276
12811277 // in a task or function? Try local ones first
12821278 if (function_or_task_name!=" " )
12831279 {
1284- full_identifier=
1285- id2string (function_or_task_name)+
1286- " ." +id2string (identifier);
1287-
1280+ auto full_identifier =
1281+ id2string (function_or_task_name) + " ." + id2string (base_name);
1282+
12881283 const symbolt *symbol;
12891284 if (!ns.lookup (full_identifier, symbol))
1290- { // found!
1291- expr.type ()=symbol->type ;
1292- expr.set_identifier (full_identifier);
1293- return std::move (expr);
1294- }
1285+ return symbol; // found!
12951286 }
1296-
1297- std::string named_block;
1298-
1287+
12991288 // try named blocks, beginning with inner one
13001289 for (named_blockst::const_reverse_iterator
13011290 it=named_blocks.rbegin ();
13021291 it!=named_blocks.rend ();
13031292 it++)
13041293 {
1305- full_identifier=
1306- id2string (module_identifier)+" ." +
1307- id2string (*it)+
1308- id2string (identifier);
1309-
1294+ auto full_identifier = id2string (module_identifier) + " ." + id2string (*it) +
1295+ id2string (base_name);
1296+
13101297 const symbolt *symbol;
13111298 if (!ns.lookup (full_identifier, symbol))
1312- { // found!
1313- named_block=*it;
1314- break ;
1315- }
1299+ return symbol; // found!
13161300 }
1317-
1318- full_identifier=
1319- id2string (module_identifier)+" ." +
1320- named_block+
1321- id2string (identifier);
1301+
1302+ auto full_identifier =
1303+ id2string (module_identifier) + " ." + id2string (base_name);
13221304
13231305 const symbolt *symbol;
13241306 if (!ns.lookup (full_identifier, symbol))
1307+ return symbol; // found!
1308+
1309+ // give up
1310+ return nullptr ;
1311+ }
1312+
1313+ /* ******************************************************************\
1314+
1315+ Function: verilog_typecheck_exprt::convert_symbol
1316+
1317+ Inputs:
1318+
1319+ Outputs:
1320+
1321+ Purpose:
1322+
1323+ \*******************************************************************/
1324+
1325+ exprt verilog_typecheck_exprt::convert_symbol (
1326+ symbol_exprt expr,
1327+ const std::optional<typet> &implicit_net_type)
1328+ {
1329+ auto symbol = resolve (expr);
1330+ auto base_name = expr.get_identifier ();
1331+
1332+ if (symbol != nullptr )
13251333 {
13261334 // found!
13271335 if (
@@ -1331,13 +1339,13 @@ exprt verilog_typecheck_exprt::convert_symbol(
13311339 // A parameter, or enum. The type is elaborated recursively.
13321340 elaborate_symbol_rec (symbol->name );
13331341 expr.type () = symbol->type ;
1334- expr.set_identifier (full_identifier );
1342+ expr.set_identifier (symbol-> name );
13351343 return std::move (expr);
13361344 }
13371345 else if (symbol->type .id () == ID_verilog_genvar)
13381346 {
13391347 // This must be a constant.
1340- mp_integer int_value = genvar_value (identifier );
1348+ mp_integer int_value = genvar_value (base_name );
13411349
13421350 if (int_value<0 )
13431351 {
@@ -1355,15 +1363,15 @@ exprt verilog_typecheck_exprt::convert_symbol(
13551363 else
13561364 {
13571365 expr.type ()=symbol->type ;
1358- expr.set_identifier (full_identifier );
1366+ expr.set_identifier (symbol-> name );
13591367 return std::move (expr);
13601368 }
13611369 }
13621370 else
13631371 {
13641372 if (implicit_net_type.has_value ())
13651373 {
1366- implicit_wire (identifier , symbol, implicit_net_type.value ());
1374+ implicit_wire (base_name , symbol, implicit_net_type.value ());
13671375 if (warn_implicit_nets)
13681376 {
13691377 warning ().source_location = expr.source_location ();
@@ -1376,7 +1384,7 @@ exprt verilog_typecheck_exprt::convert_symbol(
13761384 else
13771385 {
13781386 throw errort ().with_location (expr.source_location ())
1379- << " unknown identifier " << identifier ;
1387+ << " unknown identifier " << base_name ;
13801388 }
13811389 }
13821390}
0 commit comments