Skip to content

Commit d40c630

Browse files
committed
SMV typechecker cleanup
1. smv_ranget is moved into a header file 2. Use override instead of virtual for the methods in smv_typecheckt. 3. Remove unnecessary declarators on method parameters. 4. Use ranged for instead of Forall_operands and forall_operands.
1 parent 7ae93d8 commit d40c630

File tree

2 files changed

+167
-153
lines changed

2 files changed

+167
-153
lines changed

src/smvlang/smv_range.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*******************************************************************\
2+
3+
Module: SMV Typechecking
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_SMV_RANGE_H
10+
#define CPROVER_SMV_RANGE_H
11+
12+
#include <util/arith_tools.h>
13+
14+
class smv_ranget
15+
{
16+
public:
17+
smv_ranget() : from(0), to(0)
18+
{
19+
}
20+
21+
smv_ranget(mp_integer _from, mp_integer _to)
22+
: from(std::move(_from)), to(std::move(_to))
23+
{
24+
PRECONDITION(_from <= _to);
25+
}
26+
27+
mp_integer from, to;
28+
29+
bool is_contained_in(const smv_ranget &other) const
30+
{
31+
if(other.from > from)
32+
return false;
33+
if(other.to < to)
34+
return false;
35+
return true;
36+
}
37+
38+
void make_union(const smv_ranget &other)
39+
{
40+
mp_min(from, other.from);
41+
mp_max(to, other.to);
42+
}
43+
44+
void to_type(typet &dest) const
45+
{
46+
dest = typet(ID_range);
47+
dest.set(ID_from, integer2string(from));
48+
dest.set(ID_to, integer2string(to));
49+
}
50+
51+
bool is_bool() const
52+
{
53+
return from == 0 && to == 1;
54+
}
55+
56+
bool is_singleton() const
57+
{
58+
return from == to;
59+
}
60+
61+
smv_ranget &operator+(const smv_ranget &other)
62+
{
63+
from += other.from;
64+
to += other.to;
65+
return *this;
66+
}
67+
68+
smv_ranget &operator-(const smv_ranget &other)
69+
{
70+
from -= other.from;
71+
to -= other.to;
72+
return *this;
73+
}
74+
75+
smv_ranget &operator*(const smv_ranget &other)
76+
{
77+
mp_integer p1 = from * other.from;
78+
mp_integer p2 = from * other.to;
79+
mp_integer p3 = to * other.from;
80+
mp_integer p4 = to * other.to;
81+
82+
from = std::min(p1, std::min(p2, std::min(p3, p4)));
83+
to = std::max(p1, std::max(p2, std::max(p3, p4)));
84+
85+
return *this;
86+
}
87+
};
88+
89+
#endif // CPROVER_SMV_RANGE_H

0 commit comments

Comments
 (0)