Skip to content

Commit 45c1cbf

Browse files
authored
Merge pull request #992 from diffblue/smv-check-type
SMV: split type checking and type conversion
2 parents f6b1acd + 3ab032d commit 45c1cbf

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

src/smvlang/smv_typecheck.cpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class smv_typecheckt:public typecheckt
7979
const std::string &module;
8080
bool do_spec;
8181

82+
void check_type(const typet &);
8283
smv_ranget convert_type(const typet &);
8384
static bool is_contained_in(irep_idt, const enumeration_typet &);
8485

@@ -475,6 +476,29 @@ void smv_typecheckt::typecheck_op(
475476

476477
/*******************************************************************\
477478
479+
Function: smv_typecheckt::check_type
480+
481+
Inputs:
482+
483+
Outputs:
484+
485+
Purpose:
486+
487+
\*******************************************************************/
488+
489+
void smv_typecheckt::check_type(const typet &type)
490+
{
491+
if(type.id() == ID_range)
492+
{
493+
auto range = smv_ranget::from_type(to_range_type(type));
494+
495+
if(range.from > range.to)
496+
throw errort().with_location(type.source_location()) << "range is empty";
497+
}
498+
}
499+
500+
/*******************************************************************\
501+
478502
Function: smv_typecheckt::convert_type
479503
480504
Inputs:
@@ -487,22 +511,18 @@ Function: smv_typecheckt::convert_type
487511

488512
smv_ranget smv_typecheckt::convert_type(const typet &src)
489513
{
490-
smv_ranget dest;
491-
492514
if(src.id()==ID_bool)
493515
{
494-
dest.from=0;
495-
dest.to=1;
516+
return {0, 1};
496517
}
497518
else if(src.id()==ID_range)
498519
{
499-
dest = smv_ranget::from_type(to_range_type(src));
500-
501-
if(dest.from > dest.to)
502-
throw errort().with_location(src.source_location()) << "range is empty";
520+
return smv_ranget::from_type(to_range_type(src));
503521
}
504522
else if(src.id()==ID_enumeration)
505523
{
524+
smv_ranget dest;
525+
506526
dest.from=0;
507527

508528
std::size_t number_of_elements=
@@ -512,14 +532,14 @@ smv_ranget smv_typecheckt::convert_type(const typet &src)
512532
dest.to=0;
513533
else
514534
dest.to=(long long)number_of_elements-1;
535+
536+
return dest;
515537
}
516538
else
517539
{
518540
throw errort().with_location(src.source_location())
519541
<< "Unexpected type: `" << to_string(src) << "'";
520542
}
521-
522-
return dest;
523543
}
524544

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

1324-
// check the type, if given
1325-
if(var.type.is_not_nil() && var.type.id() != "submodule")
1326-
convert_type(var.type);
1344+
// check the type, if any
1345+
if(var.type.is_not_nil())
1346+
check_type(var.type);
13271347

13281348
symbol.base_name = var_it.first;
13291349

0 commit comments

Comments
 (0)