Skip to content

Commit f8aa6bd

Browse files
authored
Merge pull request #902 from diffblue/smt-typecheck-cleanup
SMV typechecker cleanup
2 parents 7ae93d8 + 836a55e commit f8aa6bd

File tree

4 files changed

+315
-289
lines changed

4 files changed

+315
-289
lines changed

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ IREP_ID_ONE(F)
1717
IREP_ID_ONE(E)
1818
IREP_ID_ONE(G)
1919
IREP_ID_ONE(X)
20+
IREP_ID_ONE(smv_next)
2021
IREP_ID_ONE(smv_iff)
2122
IREP_ID_TWO(C_smv_iff, "#smv_iff")
2223
IREP_ID_ONE(smv_setin)

src/smvlang/parser.y

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,10 @@ assignment : assignment_head '(' assignment_var ')' BECOMES_Token formula ';'
377377
{
378378
binary($$, $3, ID_equal, $6, bool_typet{});
379379

380-
if(stack_expr($1).id()=="next")
380+
if(stack_expr($1).id()==ID_smv_next)
381381
{
382382
exprt &op=to_binary_expr(stack_expr($$)).op0();
383-
unary_exprt tmp("smv_next", std::move(op));
383+
unary_exprt tmp(ID_smv_next, std::move(op));
384384
tmp.swap(op);
385385
PARSER.module->add_trans(stack_expr($$));
386386
}
@@ -393,7 +393,7 @@ assignment_var: variable_name
393393
;
394394

395395
assignment_head: init_Token { init($$, ID_init); }
396-
| NEXT_Token { init($$, "next"); }
396+
| NEXT_Token { init($$, ID_smv_next); }
397397
;
398398

399399
defines: define
@@ -439,7 +439,7 @@ formula : term
439439
;
440440

441441
term : variable_name
442-
| NEXT_Token '(' term ')' { init($$, "smv_next"); mto($$, $3); }
442+
| NEXT_Token '(' term ')' { init($$, ID_smv_next); mto($$, $3); }
443443
| '(' formula ')' { $$=$2; }
444444
| '{' formula_list '}' { $$=$2; stack_expr($$).id("smv_nondet_choice"); }
445445
| INC_Token '(' term ')' { init($$, "inc"); mto($$, $3); }

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)