Skip to content

Commit

Permalink
Merge pull request #992 from diffblue/smv-check-type
Browse files Browse the repository at this point in the history
SMV: split type checking and type conversion
  • Loading branch information
tautschnig authored Feb 18, 2025
2 parents f6b1acd + 3ab032d commit 45c1cbf
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/smvlang/smv_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class smv_typecheckt:public typecheckt
const std::string &module;
bool do_spec;

void check_type(const typet &);
smv_ranget convert_type(const typet &);
static bool is_contained_in(irep_idt, const enumeration_typet &);

Expand Down Expand Up @@ -475,6 +476,29 @@ void smv_typecheckt::typecheck_op(

/*******************************************************************\
Function: smv_typecheckt::check_type
Inputs:
Outputs:
Purpose:
\*******************************************************************/

void smv_typecheckt::check_type(const typet &type)
{
if(type.id() == ID_range)
{
auto range = smv_ranget::from_type(to_range_type(type));

if(range.from > range.to)
throw errort().with_location(type.source_location()) << "range is empty";
}
}

/*******************************************************************\
Function: smv_typecheckt::convert_type
Inputs:
Expand All @@ -487,22 +511,18 @@ Function: smv_typecheckt::convert_type

smv_ranget smv_typecheckt::convert_type(const typet &src)
{
smv_ranget dest;

if(src.id()==ID_bool)
{
dest.from=0;
dest.to=1;
return {0, 1};
}
else if(src.id()==ID_range)
{
dest = smv_ranget::from_type(to_range_type(src));

if(dest.from > dest.to)
throw errort().with_location(src.source_location()) << "range is empty";
return smv_ranget::from_type(to_range_type(src));
}
else if(src.id()==ID_enumeration)
{
smv_ranget dest;

dest.from=0;

std::size_t number_of_elements=
Expand All @@ -512,14 +532,14 @@ smv_ranget smv_typecheckt::convert_type(const typet &src)
dest.to=0;
else
dest.to=(long long)number_of_elements-1;

return dest;
}
else
{
throw errort().with_location(src.source_location())
<< "Unexpected type: `" << to_string(src) << "'";
}

return dest;
}

/*******************************************************************\
Expand Down Expand Up @@ -1321,9 +1341,9 @@ void smv_typecheckt::convert(smv_parse_treet::mc_varst &vars)
{
const smv_parse_treet::mc_vart &var = var_it.second;

// check the type, if given
if(var.type.is_not_nil() && var.type.id() != "submodule")
convert_type(var.type);
// check the type, if any
if(var.type.is_not_nil())
check_type(var.type);

symbol.base_name = var_it.first;

Expand Down

0 comments on commit 45c1cbf

Please sign in to comment.