@@ -58,7 +58,7 @@ class smv_typecheckt:public typecheckt
58
58
} modet;
59
59
60
60
void convert (smv_parse_treet::modulet &);
61
- void convert ( smv_parse_treet::mc_varst &);
61
+ void create_var_symbols ( const smv_parse_treet::modulet::item_listt &);
62
62
63
63
void collect_define (const equal_exprt &);
64
64
void convert_defines (exprt::operandst &invar);
@@ -1702,22 +1702,15 @@ void smv_typecheckt::convert(exprt &expr, expr_modet expr_mode)
1702
1702
{
1703
1703
const std::string &identifier=expr.get_string (ID_identifier);
1704
1704
1705
- if (identifier.find (" ::" ) == std::string::npos)
1706
- {
1707
- std::string id=module +" ::var::" +identifier;
1705
+ DATA_INVARIANT (
1706
+ identifier.find (" ::" ) == std::string::npos, " conversion is done once" );
1708
1707
1709
- smv_parse_treet::mc_varst::const_iterator it=
1710
- modulep->vars .find (identifier);
1708
+ std::string id = module + " ::var::" + identifier;
1711
1709
1712
- if (it!=modulep->vars .end ())
1713
- if (it->second .identifier !=" " )
1714
- id=id2string (it->second .identifier );
1710
+ expr.set (ID_identifier, id);
1715
1711
1716
- expr.set (ID_identifier, id);
1717
-
1718
- if (expr_mode==NEXT)
1719
- expr.id (ID_next_symbol);
1720
- }
1712
+ if (expr_mode == NEXT)
1713
+ expr.id (ID_next_symbol);
1721
1714
}
1722
1715
else if (expr.id ()==" smv_nondet_choice" ||
1723
1716
expr.id ()==" smv_union" )
@@ -1901,7 +1894,7 @@ void smv_typecheckt::convert(
1901
1894
1902
1895
/* ******************************************************************\
1903
1896
1904
- Function: smv_typecheckt::convert_vars
1897
+ Function: smv_typecheckt::create_var_symbols
1905
1898
1906
1899
Inputs:
1907
1900
@@ -1911,43 +1904,56 @@ Function: smv_typecheckt::convert_vars
1911
1904
1912
1905
\*******************************************************************/
1913
1906
1914
- void smv_typecheckt::convert (smv_parse_treet::mc_varst &vars)
1907
+ void smv_typecheckt::create_var_symbols (
1908
+ const smv_parse_treet::modulet::item_listt &items)
1915
1909
{
1916
1910
symbolt symbol;
1917
1911
1918
1912
symbol.mode =" SMV" ;
1919
1913
symbol.module =modulep->name ;
1920
1914
1921
- for (const auto &var_it : vars )
1915
+ for (const auto &item : items )
1922
1916
{
1923
- const smv_parse_treet::mc_vart &var = var_it. second ;
1924
-
1925
- typet type = var. type ;
1917
+ if (item. is_var ())
1918
+ {
1919
+ typet type = item. expr . type () ;
1926
1920
1927
- // check the type, if any
1928
- if (type.is_not_nil ())
1921
+ // check the type
1929
1922
check_type (type);
1930
1923
1931
- symbol.base_name = var_it.first ;
1924
+ symbol.base_name = to_symbol_expr (item.expr ).get_identifier ();
1925
+ symbol.name = module + " ::var::" + id2string (symbol.base_name );
1926
+
1927
+ if (module == " smv::main" )
1928
+ symbol.pretty_name = symbol.base_name ;
1929
+ else
1930
+ symbol.pretty_name = strip_smv_prefix (symbol.name );
1931
+
1932
+ symbol.value = nil_exprt{};
1933
+ symbol.is_input = true ;
1934
+ symbol.is_state_var = false ;
1935
+ symbol.type = std::move (type);
1932
1936
1933
- if (var.identifier ==" " )
1937
+ symbol_table.add (symbol);
1938
+ }
1939
+ else if (item.is_define ())
1934
1940
{
1941
+ symbol.base_name =
1942
+ to_symbol_expr (to_equal_expr (item.expr ).lhs ()).get_identifier ();
1935
1943
symbol.name =module +" ::var::" +id2string (symbol.base_name );
1936
1944
1937
1945
if (module == " smv::main" )
1938
1946
symbol.pretty_name = symbol.base_name ;
1939
1947
else
1940
1948
symbol.pretty_name = strip_smv_prefix (symbol.name );
1941
- }
1942
- else
1943
- symbol.name =var.identifier ;
1944
1949
1945
- symbol.value . make_nil () ;
1946
- symbol.is_input = true ;
1947
- symbol.is_state_var = false ;
1948
- symbol.type = std::move (type );
1950
+ symbol.value = nil_exprt{} ;
1951
+ symbol.is_input = true ;
1952
+ symbol.is_state_var = false ;
1953
+ symbol.type . make_nil ( );
1949
1954
1950
- symbol_table.add (symbol);
1955
+ symbol_table.add (symbol);
1956
+ }
1951
1957
}
1952
1958
}
1953
1959
@@ -2091,8 +2097,8 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)
2091
2097
2092
2098
define_map.clear ();
2093
2099
2094
- // variables first, need to be visible before declaration
2095
- convert (smv_module.vars );
2100
+ // variables/defines first, can be used before their declaration
2101
+ create_var_symbols (smv_module.items );
2096
2102
2097
2103
// transition relation
2098
2104
0 commit comments