@@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com
1414#include < util/expr_util.h>
1515#include < util/mathematical_expr.h>
1616#include < util/namespace.h>
17+ #include < util/prefix.h>
1718#include < util/std_expr.h>
1819#include < util/typecheck.h>
1920
@@ -32,13 +33,13 @@ class smv_typecheckt:public typecheckt
3233 smv_typecheckt (
3334 smv_parse_treet &_smv_parse_tree,
3435 symbol_table_baset &_symbol_table,
35- const std::string &_module ,
36+ const std::string &_module_identifier ,
3637 bool _do_spec,
3738 message_handlert &_message_handler)
3839 : typecheckt(_message_handler),
3940 smv_parse_tree (_smv_parse_tree),
4041 symbol_table(_symbol_table),
41- module(_module ),
42+ module_identifier(_module_identifier ),
4243 do_spec(_do_spec)
4344 {
4445 nondet_count=0 ;
@@ -80,7 +81,7 @@ class smv_typecheckt:public typecheckt
8081protected:
8182 smv_parse_treet &smv_parse_tree;
8283 symbol_table_baset &symbol_table;
83- const std::string &module ;
84+ const std::string &module_identifier ;
8485 bool do_spec;
8586
8687 void check_type (typet &);
@@ -104,7 +105,7 @@ class smv_typecheckt:public typecheckt
104105
105106 void instantiate (
106107 smv_parse_treet::modulet &,
107- const irep_idt &identifier ,
108+ const irep_idt &module_base_name ,
108109 const irep_idt &instance,
109110 const exprt::operandst &arguments,
110111 const source_locationt &);
@@ -216,7 +217,7 @@ void smv_typecheckt::convert_ports(
216217 ports.push_back (exprt (ID_symbol));
217218 ports.back ().set (
218219 ID_identifier,
219- id2string (smv_module.name ) + " ::var::" + id2string (port_name));
220+ id2string (smv_module.identifier ) + " ::var::" + id2string (port_name));
220221 }
221222}
222223
@@ -249,12 +250,13 @@ void smv_typecheckt::flatten_hierarchy(smv_parse_treet::modulet &smv_module)
249250 for (auto &argument : instance.arguments ())
250251 convert (argument);
251252
253+ // the base name of the instance, not the module
252254 auto instance_base_name =
253255 to_smv_identifier_expr (element.expr ).identifier ();
254256
255257 instantiate (
256258 smv_module,
257- instance.identifier (),
259+ instance.base_name (),
258260 instance_base_name,
259261 instance.arguments (),
260262 instance.source_location ());
@@ -276,18 +278,18 @@ Function: smv_typecheckt::instantiate
276278
277279void smv_typecheckt::instantiate (
278280 smv_parse_treet::modulet &smv_module,
279- const irep_idt &identifier ,
281+ const irep_idt &module_base_name ,
280282 const irep_idt &instance,
281283 const exprt::operandst &arguments,
282284 const source_locationt &location)
283285{
284286 // Find the module
285- auto module_it = smv_parse_tree.module_map .find (identifier );
287+ auto module_it = smv_parse_tree.module_map .find (module_base_name );
286288
287289 if (module_it == smv_parse_tree.module_map .end ())
288290 {
289291 throw errort ().with_location (location)
290- << " submodule `" << identifier << " ' not found" ;
292+ << " submodule `" << module_base_name << " ' not found" ;
291293 }
292294
293295 const auto &instantiated_module = *module_it->second ;
@@ -297,7 +299,7 @@ void smv_typecheckt::instantiate(
297299 if (parameters.size () != arguments.size ())
298300 {
299301 throw errort ().with_location (location)
300- << " submodule `" << identifier << " ' has wrong number of arguments" ;
302+ << " submodule `" << module_base_name << " ' has wrong number of arguments" ;
301303 }
302304
303305 rename_mapt parameter_map;
@@ -727,7 +729,7 @@ void smv_typecheckt::typecheck_expr_rec(exprt &expr, modet mode, bool next)
727729
728730 if (mode == INIT || next)
729731 {
730- if (symbol.module == module )
732+ if (symbol.module == module_identifier )
731733 {
732734 symbol.is_input =false ;
733735 symbol.is_state_var =true ;
@@ -1716,7 +1718,7 @@ void smv_typecheckt::convert_expr_to(exprt &expr, const typet &dest_type)
17161718 // sets can be assigned to scalars, which yields a nondeterministic
17171719 // choice
17181720 std::string identifier =
1719- module + " ::var::" + std::to_string (nondet_count++);
1721+ module_identifier + " ::var::" + std::to_string (nondet_count++);
17201722
17211723 expr.set (ID_identifier, identifier);
17221724 expr.set (" #smv_nondet_choice" , true );
@@ -1877,7 +1879,7 @@ void smv_typecheckt::convert(exprt &expr)
18771879 if (
18781880 smv_parse_tree.enum_set .find (identifier) == smv_parse_tree.enum_set .end ())
18791881 {
1880- std::string id = module + " ::var::" + identifier;
1882+ std::string id = module_identifier + " ::var::" + identifier;
18811883
18821884 expr.set (ID_identifier, id);
18831885 expr.id (ID_symbol);
@@ -1927,8 +1929,8 @@ void smv_typecheckt::convert(exprt &expr)
19271929 << " expected operand here" ;
19281930 }
19291931
1930- std::string identifier=
1931- module + " ::var::" + std::to_string (nondet_count++);
1932+ std::string identifier =
1933+ module_identifier + " ::var::" + std::to_string (nondet_count++);
19321934
19331935 expr.set (ID_identifier, identifier);
19341936 expr.set (" #smv_nondet_choice" , true );
@@ -2249,7 +2251,8 @@ void smv_typecheckt::create_var_symbols(
22492251 {
22502252 irep_idt base_name = merge_complex_identifier (element.expr );
22512253 auto location = element.expr .source_location ();
2252- irep_idt identifier = module + " ::var::" + id2string (base_name);
2254+ irep_idt identifier =
2255+ module_identifier + " ::var::" + id2string (base_name);
22532256
22542257 auto symbol_ptr = symbol_table.lookup (identifier);
22552258 if (symbol_ptr != nullptr )
@@ -2266,10 +2269,10 @@ void smv_typecheckt::create_var_symbols(
22662269
22672270 symbolt symbol{identifier, std::move (type), mode};
22682271
2269- symbol.module = modulep->name ;
2272+ symbol.module = modulep->identifier ;
22702273 symbol.base_name = base_name;
22712274
2272- if (module == " smv::main" )
2275+ if (module_identifier == " smv::main" )
22732276 symbol.pretty_name = symbol.base_name ;
22742277 else
22752278 symbol.pretty_name = strip_smv_prefix (symbol.name );
@@ -2289,7 +2292,8 @@ void smv_typecheckt::create_var_symbols(
22892292 {
22902293 irep_idt base_name = merge_complex_identifier (element.lhs ());
22912294 auto location = to_equal_expr (element.expr ).lhs ().source_location ();
2292- irep_idt identifier = module + " ::var::" + id2string (base_name);
2295+ irep_idt identifier =
2296+ module_identifier + " ::var::" + id2string (base_name);
22932297
22942298 auto symbol_ptr = symbol_table.lookup (identifier);
22952299 if (symbol_ptr != nullptr )
@@ -2305,10 +2309,10 @@ void smv_typecheckt::create_var_symbols(
23052309 symbolt symbol{identifier, std::move (type), mode};
23062310
23072311 symbol.mode = mode;
2308- symbol.module = modulep->name ;
2312+ symbol.module = modulep->identifier ;
23092313 symbol.base_name = base_name;
23102314
2311- if (module == " smv::main" )
2315+ if (module_identifier == " smv::main" )
23122316 symbol.pretty_name = symbol.base_name ;
23132317 else
23142318 symbol.pretty_name = strip_smv_prefix (symbol.name );
@@ -2323,7 +2327,8 @@ void smv_typecheckt::create_var_symbols(
23232327 else if (element.is_enum ())
23242328 {
23252329 irep_idt base_name = to_smv_identifier_expr (element.expr ).identifier ();
2326- irep_idt identifier = module + " ::var::" + id2string (base_name);
2330+ irep_idt identifier =
2331+ module_identifier + " ::var::" + id2string (base_name);
23272332
23282333 auto symbol_ptr = symbol_table.lookup (identifier);
23292334 if (symbol_ptr != nullptr )
@@ -2537,7 +2542,7 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)
25372542
25382543 module_symbol.base_name =smv_module.base_name ;
25392544 module_symbol.pretty_name =smv_module.base_name ;
2540- module_symbol.name = smv_module.name ;
2545+ module_symbol.name = smv_module.identifier ;
25412546 module_symbol.module =module_symbol.name ;
25422547 module_symbol.type =typet (ID_module);
25432548 module_symbol.mode =" SMV" ;
@@ -2609,17 +2614,17 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)
26092614 else
26102615 spec_symbol.base_name = " spec" + std::to_string (nr++);
26112616
2612- spec_symbol.name =
2613- id2string (smv_module. name ) + " ::" + id2string (spec_symbol.base_name );
2614- spec_symbol.module = smv_module.name ;
2617+ spec_symbol.name = id2string (smv_module. identifier ) +
2618+ " ::" + id2string (spec_symbol.base_name );
2619+ spec_symbol.module = smv_module.identifier ;
26152620 spec_symbol.type = bool_typet ();
26162621 spec_symbol.is_property = true ;
26172622 spec_symbol.mode = " SMV" ;
26182623 spec_symbol.value = element.expr ;
26192624 spec_symbol.location = element.location ;
26202625 spec_symbol.location .set_comment (to_string (element.expr ));
26212626
2622- if (smv_module.name == " smv::main" )
2627+ if (smv_module.identifier == " smv::main" )
26232628 spec_symbol.pretty_name = spec_symbol.base_name ;
26242629 else
26252630 spec_symbol.pretty_name = strip_smv_prefix (spec_symbol.name );
@@ -2632,8 +2637,9 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)
26322637 }
26332638
26342639 // lowering
2635- for (auto v_it = symbol_table.symbol_module_map .lower_bound (smv_module.name );
2636- v_it != symbol_table.symbol_module_map .upper_bound (smv_module.name );
2640+ for (auto v_it =
2641+ symbol_table.symbol_module_map .lower_bound (smv_module.identifier );
2642+ v_it != symbol_table.symbol_module_map .upper_bound (smv_module.identifier );
26372643 v_it++)
26382644 {
26392645 auto &symbol = symbol_table.get_writeable_ref (v_it->second );
@@ -2656,18 +2662,19 @@ Function: smv_typecheckt::typecheck
26562662
26572663void smv_typecheckt::typecheck ()
26582664{
2659- if (module != " smv::main" )
2665+ if (module_identifier != " smv::main" )
26602666 return ;
26612667
26622668 // check all modules for duplicate identifiers
26632669 for (auto &module : smv_parse_tree.module_list )
26642670 variable_checks (module );
26652671
2666- auto it = smv_parse_tree.module_map .find (module );
2672+ auto module_base_name = smv_module_base_name (module_identifier);
2673+ auto it = smv_parse_tree.module_map .find (module_base_name);
26672674
26682675 if (it == smv_parse_tree.module_map .end ())
26692676 {
2670- throw errort () << " failed to find module " << module ;
2677+ throw errort () << " failed to find module " << module_base_name ;
26712678 }
26722679
26732680 convert (*it->second );
@@ -2688,12 +2695,12 @@ Function: smv_typecheck
26882695bool smv_typecheck (
26892696 smv_parse_treet &smv_parse_tree,
26902697 symbol_table_baset &symbol_table,
2691- const std::string &module ,
2698+ const std::string &module_identifier ,
26922699 message_handlert &message_handler,
26932700 bool do_spec)
26942701{
26952702 smv_typecheckt smv_typecheck (
2696- smv_parse_tree, symbol_table, module , do_spec, message_handler);
2703+ smv_parse_tree, symbol_table, module_identifier , do_spec, message_handler);
26972704 return smv_typecheck.typecheck_main ();
26982705}
26992706
@@ -2709,7 +2716,25 @@ Function: smv_module_symbol
27092716
27102717\*******************************************************************/
27112718
2712- std::string smv_module_symbol (const std::string & module )
2719+ irep_idt smv_module_symbol (const irep_idt &base_name )
27132720{
2714- return " smv::" +module ;
2721+ return " smv::" + id2string (base_name);
2722+ }
2723+
2724+ /* ******************************************************************\
2725+
2726+ Function: smv_module_base_name
2727+
2728+ Inputs:
2729+
2730+ Outputs:
2731+
2732+ Purpose:
2733+
2734+ \*******************************************************************/
2735+
2736+ irep_idt smv_module_base_name (const irep_idt &identifier)
2737+ {
2738+ PRECONDITION (has_prefix (id2string (identifier), " smv::" ));
2739+ return id2string (identifier).substr (5 , std::string::npos);
27152740}
0 commit comments