Skip to content

SMV: variable definitions are now parse tree items #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/smvlang/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ vardecl : variable_identifier ':' type_specifier ';'
switch(var.var_class)
{
case smv_parse_treet::mc_vart::UNKNOWN:
var.type=(typet &)stack_expr($3);
var.type=stack_type($3);
var.var_class=smv_parse_treet::mc_vart::DECLARED;
break;

Expand All @@ -616,6 +616,8 @@ vardecl : variable_identifier ':' type_specifier ';'
default:
DATA_INVARIANT(false, "unexpected variable class");
}

PARSER.module->add_var(stack_expr($1), stack_type($3));
}
;

Expand Down
7 changes: 5 additions & 2 deletions src/smvlang/smv_parse_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ std::string to_string(smv_parse_treet::modulet::itemt::item_typet i)
case smv_parse_treet::modulet::itemt::LTLSPEC:
return "LTLSPEC";
case smv_parse_treet::modulet::itemt::FAIRNESS: return "FAIRNESS";
case smv_parse_treet::modulet::itemt::DEFINE: return "DEFINE";

case smv_parse_treet::modulet::itemt::DEFINE:
return "DEFINE";
case smv_parse_treet::modulet::itemt::VAR:
return "VAR";

default:;
}

Expand Down
23 changes: 18 additions & 5 deletions src/smvlang/smv_parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class smv_parse_treet
ASSIGN_INIT,
ASSIGN_NEXT,
CTLSPEC,
LTLSPEC,
INIT,
TRANS,
DEFINE,
FAIRNESS,
INIT,
INVAR,
FAIRNESS
LTLSPEC,
TRANS,
VAR
};

itemt(item_typet __item_type, exprt __expr, source_locationt __location)
Expand Down Expand Up @@ -125,6 +126,11 @@ class smv_parse_treet
return item_type==INIT;
}

bool is_var() const
{
return item_type == VAR;
}

// for ASSIGN_CURRENT, ASSIGN_INIT, ASSIGN_NEXT, DEFINE
const equal_exprt &equal_expr() const
{
Expand Down Expand Up @@ -246,7 +252,14 @@ class smv_parse_treet
{
items.emplace_back(itemt::TRANS, std::move(expr), std::move(location));
}


void add_var(exprt expr, typet type)
{
expr.type() = std::move(type);
auto location = expr.source_location();
items.emplace_back(itemt::VAR, std::move(expr), std::move(location));
}

mc_varst vars;
enum_sett enum_set;

Expand Down
11 changes: 8 additions & 3 deletions src/smvlang/smv_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,9 @@ void smv_typecheckt::typecheck(
typecheck(item.expr, OTHER);
item.equal_expr().type() = bool_typet{};
return;

case smv_parse_treet::modulet::itemt::VAR:
return;
}
}

Expand Down Expand Up @@ -2104,6 +2107,7 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)

define_map.clear();

// variables first, need to be visible before declaration
convert(smv_module.vars);

// transition relation
Expand All @@ -2122,9 +2126,10 @@ void smv_typecheckt::convert(smv_parse_treet::modulet &smv_module)

convert_ports(smv_module, module_symbol.type);

for (auto &item : smv_module.items) {
convert(item);
}
// non-variable items
for(auto &item : smv_module.items)
if(!item.is_var())
convert(item);

flatten_hierarchy(smv_module);

Expand Down
Loading