@@ -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,64 @@ 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
- symbolt symbol;
1917
-
1918
- symbol.mode =" SMV" ;
1919
- symbol.module =modulep->name ;
1910
+ const irep_idt mode = " SMV" ;
1920
1911
1921
- for (const auto &var_it : vars )
1912
+ for (const auto &item : items )
1922
1913
{
1923
- const smv_parse_treet::mc_vart &var = var_it.second ;
1914
+ if (item.is_var ())
1915
+ {
1916
+ irep_idt base_name = to_symbol_expr (item.expr ).get_identifier ();
1917
+ irep_idt identifier = module + " ::var::" + id2string (base_name);
1924
1918
1925
- typet type = var. type ;
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
+ symbolt symbol{identifier, std::move (type), mode} ;
1932
1925
1933
- if (var.identifier ==" " )
1934
- {
1935
- symbol.name =module +" ::var::" +id2string (symbol.base_name );
1926
+ symbol.module = modulep->name ;
1927
+ symbol.base_name = base_name;
1936
1928
1937
1929
if (module == " smv::main" )
1938
1930
symbol.pretty_name = symbol.base_name ;
1939
1931
else
1940
1932
symbol.pretty_name = strip_smv_prefix (symbol.name );
1933
+
1934
+ symbol.value = nil_exprt{};
1935
+ symbol.is_input = true ;
1936
+ symbol.is_state_var = false ;
1937
+
1938
+ symbol_table.insert (std::move (symbol));
1941
1939
}
1942
- else
1943
- symbol.name =var.identifier ;
1940
+ else if (item.is_define ())
1941
+ {
1942
+ irep_idt base_name =
1943
+ to_symbol_expr (to_equal_expr (item.expr ).lhs ()).get_identifier ();
1944
+ irep_idt identifier = module + " ::var::" + id2string (base_name);
1945
+ typet type;
1946
+ type.make_nil ();
1944
1947
1945
- symbol.value .make_nil ();
1946
- symbol.is_input =true ;
1947
- symbol.is_state_var =false ;
1948
- symbol.type = std::move (type);
1948
+ symbolt symbol{identifier, std::move (type), mode};
1949
1949
1950
- symbol_table.add (symbol);
1950
+ symbol.mode = mode;
1951
+ symbol.module = modulep->name ;
1952
+ symbol.base_name = base_name;
1953
+
1954
+ if (module == " smv::main" )
1955
+ symbol.pretty_name = symbol.base_name ;
1956
+ else
1957
+ symbol.pretty_name = strip_smv_prefix (symbol.name );
1958
+
1959
+ symbol.value = nil_exprt{};
1960
+ symbol.is_input = true ;
1961
+ symbol.is_state_var = false ;
1962
+
1963
+ symbol_table.insert (std::move (symbol));
1964
+ }
1951
1965
}
1952
1966
}
1953
1967
@@ -2091,8 +2105,8 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)
2091
2105
2092
2106
define_map.clear ();
2093
2107
2094
- // variables first, need to be visible before declaration
2095
- convert (smv_module.vars );
2108
+ // variables/defines first, can be used before their declaration
2109
+ create_var_symbols (smv_module.items );
2096
2110
2097
2111
// transition relation
2098
2112
0 commit comments