Skip to content

Commit 0ad571d

Browse files
committed
SMV: use module items for VAR and DEFINE for creating symbols
The SMV typechecker now uses the module items for creating the symbols for VAR and DEFINE.
1 parent 6dcb40c commit 0ad571d

File tree

1 file changed

+52
-38
lines changed

1 file changed

+52
-38
lines changed

src/smvlang/smv_typecheck.cpp

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class smv_typecheckt:public typecheckt
5858
} modet;
5959

6060
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 &);
6262

6363
void collect_define(const equal_exprt &);
6464
void convert_defines(exprt::operandst &invar);
@@ -1702,22 +1702,15 @@ void smv_typecheckt::convert(exprt &expr, expr_modet expr_mode)
17021702
{
17031703
const std::string &identifier=expr.get_string(ID_identifier);
17041704

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");
17081707

1709-
smv_parse_treet::mc_varst::const_iterator it=
1710-
modulep->vars.find(identifier);
1708+
std::string id = module + "::var::" + identifier;
17111709

1712-
if(it!=modulep->vars.end())
1713-
if(it->second.identifier!="")
1714-
id=id2string(it->second.identifier);
1710+
expr.set(ID_identifier, id);
17151711

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);
17211714
}
17221715
else if(expr.id()=="smv_nondet_choice" ||
17231716
expr.id()=="smv_union")
@@ -1901,7 +1894,7 @@ void smv_typecheckt::convert(
19011894

19021895
/*******************************************************************\
19031896
1904-
Function: smv_typecheckt::convert_vars
1897+
Function: smv_typecheckt::create_var_symbols
19051898
19061899
Inputs:
19071900
@@ -1911,43 +1904,64 @@ Function: smv_typecheckt::convert_vars
19111904
19121905
\*******************************************************************/
19131906

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)
19151909
{
1916-
symbolt symbol;
1917-
1918-
symbol.mode="SMV";
1919-
symbol.module=modulep->name;
1910+
const irep_idt mode = "SMV";
19201911

1921-
for(const auto &var_it : vars)
1912+
for(const auto &item : items)
19221913
{
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);
19241918

1925-
typet type = var.type;
1919+
typet type = item.expr.type();
19261920

1927-
// check the type, if any
1928-
if(type.is_not_nil())
1921+
// check the type
19291922
check_type(type);
19301923

1931-
symbol.base_name = var_it.first;
1924+
symbolt symbol{identifier, std::move(type), mode};
19321925

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;
19361928

19371929
if(module == "smv::main")
19381930
symbol.pretty_name = symbol.base_name;
19391931
else
19401932
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));
19411939
}
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();
19441947

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};
19491949

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+
}
19511965
}
19521966
}
19531967

@@ -2091,8 +2105,8 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)
20912105

20922106
define_map.clear();
20932107

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);
20962110

20972111
// transition relation
20982112

0 commit comments

Comments
 (0)