GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/theory_state.cpp Lines: 71 73 97.3 %
Date: 2021-08-01 Branches: 79 192 41.1 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * A theory state for Theory.
14
 */
15
16
#include "theory/theory_state.h"
17
18
#include "theory/uf/equality_engine.h"
19
20
namespace cvc5 {
21
namespace theory {
22
23
108260
TheoryState::TheoryState(context::Context* c,
24
                         context::UserContext* u,
25
108260
                         Valuation val)
26
    : d_context(c),
27
      d_ucontext(u),
28
      d_valuation(val),
29
      d_ee(nullptr),
30
108260
      d_conflict(c, false)
31
{
32
108260
}
33
34
108218
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
35
36
220504
context::Context* TheoryState::getSatContext() const { return d_context; }
37
38
293104
context::UserContext* TheoryState::getUserContext() const { return d_ucontext; }
39
40
24840438
bool TheoryState::hasTerm(TNode a) const
41
{
42
24840438
  Assert(d_ee != nullptr);
43
24840438
  return d_ee->hasTerm(a);
44
}
45
46
12944298
TNode TheoryState::getRepresentative(TNode t) const
47
{
48
12944298
  Assert(d_ee != nullptr);
49
12944298
  if (d_ee->hasTerm(t))
50
  {
51
12785652
    return d_ee->getRepresentative(t);
52
  }
53
158646
  return t;
54
}
55
56
7621459
bool TheoryState::areEqual(TNode a, TNode b) const
57
{
58
7621459
  Assert(d_ee != nullptr);
59
7621459
  if (a == b)
60
  {
61
1890065
    return true;
62
  }
63
5731394
  else if (hasTerm(a) && hasTerm(b))
64
  {
65
5696734
    return d_ee->areEqual(a, b);
66
  }
67
34660
  return false;
68
}
69
70
526869
bool TheoryState::areDisequal(TNode a, TNode b) const
71
{
72
526869
  Assert(d_ee != nullptr);
73
526869
  if (a == b)
74
  {
75
241677
    return false;
76
  }
77
78
285192
  bool isConst = true;
79
285192
  bool hasTerms = true;
80
285192
  if (hasTerm(a))
81
  {
82
284625
    a = d_ee->getRepresentative(a);
83
284625
    isConst = a.isConst();
84
  }
85
567
  else if (!a.isConst())
86
  {
87
    // if not constant and not a term in the ee, it cannot be disequal
88
313
    return false;
89
  }
90
  else
91
  {
92
254
    hasTerms = false;
93
  }
94
95
284879
  if (hasTerm(b))
96
  {
97
284489
    b = d_ee->getRepresentative(b);
98
284489
    isConst = isConst && b.isConst();
99
  }
100
390
  else if (!b.isConst())
101
  {
102
    // same as above, it cannot be disequal
103
57
    return false;
104
  }
105
  else
106
  {
107
333
    hasTerms = false;
108
  }
109
110
284822
  if (isConst)
111
  {
112
    // distinct constants are disequal
113
51469
    return a != b;
114
  }
115
233353
  else if (!hasTerms)
116
  {
117
347
    return false;
118
  }
119
  // otherwise there may be an explicit disequality in the equality engine
120
233006
  return d_ee->areDisequal(a, b, false);
121
}
122
123
7691
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const
124
{
125
7691
  if (d_ee->hasTerm(a))
126
  {
127
13914
    Node rep = d_ee->getRepresentative(a);
128
6957
    eq::EqClassIterator eqc_iter(rep, d_ee);
129
108187
    while (!eqc_iter.isFinished())
130
    {
131
50615
      eqc.push_back(*eqc_iter);
132
50615
      eqc_iter++;
133
    }
134
  }
135
  else
136
  {
137
734
    eqc.push_back(a);
138
  }
139
  // a should be in its equivalence class
140
7691
  Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end());
141
7691
}
142
143
7098157
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
144
145
2109964
void TheoryState::notifyInConflict() { d_conflict = true; }
146
147
43012720
bool TheoryState::isInConflict() const { return d_conflict; }
148
149
bool TheoryState::isSatLiteral(TNode lit) const
150
{
151
  return d_valuation.isSatLiteral(lit);
152
}
153
154
1514
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }
155
156
5171
SortInference* TheoryState::getSortInference()
157
{
158
5171
  return d_valuation.getSortInference();
159
}
160
161
42519
bool TheoryState::hasSatValue(TNode n, bool& value) const
162
{
163
42519
  return d_valuation.hasSatValue(n, value);
164
}
165
166
7607
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
167
{
168
7607
  return d_valuation.factsBegin(tid);
169
}
170
7607
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
171
{
172
7607
  return d_valuation.factsEnd(tid);
173
}
174
175
11294
bool TheoryState::isFiniteType(TypeNode tn) const
176
{
177
11294
  return d_valuation.isFiniteType(tn);
178
}
179
180
1335055
Valuation& TheoryState::getValuation() { return d_valuation; }
181
182
}  // namespace theory
183
29280
}  // namespace cvc5