blob: c9e7c397e13ce6b636475de708fd69c7684bdba1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/********************* */
/*! \file theory_bv.cpp
** \verbatim
** Original author: dejan
** Major contributors: none
** Minor contributors (to current version): none
** This file is part of the CVC4 prototype.
** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
** Courant Institute of Mathematical Sciences
** New York University
** See the file COPYING in the top-level source directory for licensing
** information.\endverbatim
**
** \brief [[ Add one-line brief description here ]]
**
** [[ Add lengthier description here ]]
** \todo document this file
**/
#include "theory/bv/theory_bv.h"
#include "theory/bv/theory_bv_utils.h"
#include "theory/theory_engine.h"
using namespace CVC4;
using namespace CVC4::theory;
using namespace CVC4::theory::bv;
using namespace CVC4::theory::bv::utils;
void TheoryBV::preRegisterTerm(TNode node) {
Debug("bitvector") << "TheoryBV::preRegister(" << node << ")" << std::endl;
if (node.getKind() == kind::EQUAL) {
d_eqEngine.addTerm(node[0]);
d_eqEngine.addTerm(node[1]);
size_t triggerId = d_eqEngine.addTrigger(node[0], node[1]);
Assert(triggerId == d_triggers.size());
d_triggers.push_back(node);
}
}
void TheoryBV::check(Effort e) {
Debug("bitvector") << "TheoryBV::check(" << e << ")" << std::endl;
while(!done()) {
// Get the assertion
TNode assertion = get();
d_assertions.insert(assertion);
Debug("bitvector") << "TheoryBV::check(" << e << "): asserting: " << assertion << std::endl;
// Do the right stuff
switch (assertion.getKind()) {
case kind::EQUAL: {
bool ok = d_eqEngine.addEquality(assertion[0], assertion[1]);
if (!ok) return;
break;
}
case kind::NOT: {
// We need to check this as the equality trigger might have been true when we made it
TNode equality = assertion[0];
if (d_eqEngine.areEqual(equality[0], equality[1])) {
vector<TNode> assertions;
d_eqEngine.getExplanation(equality[0], equality[1], assertions);
assertions.push_back(assertion);
d_out->conflict(mkAnd(assertions));
return;
}
break;
}
default:
Unhandled();
}
}
}
bool TheoryBV::triggerEquality(size_t triggerId) {
Debug("bitvector") << "TheoryBV::triggerEquality(" << triggerId << ")" << std::endl;
Assert(triggerId < d_triggers.size());
Debug("bitvector") << "TheoryBV::triggerEquality(" << triggerId << "): " << d_triggers[triggerId] << std::endl;
TNode equality = d_triggers[triggerId];
// If we have just asserted this equality ignore it
if (d_assertions.contains(equality)) return true;
// If we have a negation asserted, we have a confict
if (d_assertions.contains(equality.notNode())) {
vector<TNode> assertions;
d_eqEngine.getExplanation(equality[0], equality[1], assertions);
assertions.push_back(equality.notNode());
d_out->conflict(mkAnd(assertions));
return false;
}
// Otherwise we propagate this equality
d_out->propagate(equality);
return true;
}
Node TheoryBV::getValue(TNode n, TheoryEngine* engine) {
NodeManager* nodeManager = NodeManager::currentNM();
switch(n.getKind()) {
case kind::VARIABLE:
Unhandled(kind::VARIABLE);
case kind::EQUAL: // 2 args
return nodeManager->
mkConst( engine->getValue(n[0]) == engine->getValue(n[1]) );
default:
Unhandled(n.getKind());
}
}
|