GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/theory_state.cpp Lines: 71 73 97.3 %
Date: 2021-09-07 Branches: 80 192 41.7 %

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
119154
TheoryState::TheoryState(Env& env, Valuation val)
24
119154
    : EnvObj(env), d_valuation(val), d_ee(nullptr), d_conflict(context(), false)
25
{
26
119154
}
27
28
119112
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
29
30
222401
context::Context* TheoryState::getSatContext() const { return context(); }
31
32
290746
context::UserContext* TheoryState::getUserContext() const
33
{
34
290746
  return userContext();
35
}
36
37
29050346
bool TheoryState::hasTerm(TNode a) const
38
{
39
29050346
  Assert(d_ee != nullptr);
40
29050346
  return d_ee->hasTerm(a);
41
}
42
43
15025658
TNode TheoryState::getRepresentative(TNode t) const
44
{
45
15025658
  Assert(d_ee != nullptr);
46
15025658
  if (d_ee->hasTerm(t))
47
  {
48
14867876
    return d_ee->getRepresentative(t);
49
  }
50
157782
  return t;
51
}
52
53
9633038
bool TheoryState::areEqual(TNode a, TNode b) const
54
{
55
9633038
  Assert(d_ee != nullptr);
56
9633038
  if (a == b)
57
  {
58
2469150
    return true;
59
  }
60
7163888
  else if (hasTerm(a) && hasTerm(b))
61
  {
62
7123871
    return d_ee->areEqual(a, b);
63
  }
64
40017
  return false;
65
}
66
67
555158
bool TheoryState::areDisequal(TNode a, TNode b) const
68
{
69
555158
  Assert(d_ee != nullptr);
70
555158
  if (a == b)
71
  {
72
238012
    return false;
73
  }
74
75
317146
  bool isConst = true;
76
317146
  bool hasTerms = true;
77
317146
  if (hasTerm(a))
78
  {
79
316583
    a = d_ee->getRepresentative(a);
80
316583
    isConst = a.isConst();
81
  }
82
563
  else if (!a.isConst())
83
  {
84
    // if not constant and not a term in the ee, it cannot be disequal
85
321
    return false;
86
  }
87
  else
88
  {
89
242
    hasTerms = false;
90
  }
91
92
316825
  if (hasTerm(b))
93
  {
94
316433
    b = d_ee->getRepresentative(b);
95
316433
    isConst = isConst && b.isConst();
96
  }
97
392
  else if (!b.isConst())
98
  {
99
    // same as above, it cannot be disequal
100
57
    return false;
101
  }
102
  else
103
  {
104
335
    hasTerms = false;
105
  }
106
107
316768
  if (isConst)
108
  {
109
    // distinct constants are disequal
110
60333
    return a != b;
111
  }
112
256435
  else if (!hasTerms)
113
  {
114
339
    return false;
115
  }
116
  // otherwise there may be an explicit disequality in the equality engine
117
256096
  return d_ee->areDisequal(a, b, false);
118
}
119
120
8297
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const
121
{
122
8297
  if (d_ee->hasTerm(a))
123
  {
124
15072
    Node rep = d_ee->getRepresentative(a);
125
7536
    eq::EqClassIterator eqc_iter(rep, d_ee);
126
121350
    while (!eqc_iter.isFinished())
127
    {
128
56907
      eqc.push_back(*eqc_iter);
129
56907
      eqc_iter++;
130
    }
131
  }
132
  else
133
  {
134
761
    eqc.push_back(a);
135
  }
136
  // a should be in its equivalence class
137
8297
  Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end());
138
8297
}
139
140
7208379
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
141
142
2469642
void TheoryState::notifyInConflict() { d_conflict = true; }
143
144
46938173
bool TheoryState::isInConflict() const { return d_conflict; }
145
146
bool TheoryState::isSatLiteral(TNode lit) const
147
{
148
  return d_valuation.isSatLiteral(lit);
149
}
150
151
6958487
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }
152
153
5151
SortInference* TheoryState::getSortInference()
154
{
155
5151
  return d_valuation.getSortInference();
156
}
157
158
42519
bool TheoryState::hasSatValue(TNode n, bool& value) const
159
{
160
42519
  return d_valuation.hasSatValue(n, value);
161
}
162
163
7570
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
164
{
165
7570
  return d_valuation.factsBegin(tid);
166
}
167
7570
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
168
{
169
7570
  return d_valuation.factsEnd(tid);
170
}
171
172
11372
bool TheoryState::isFiniteType(TypeNode tn) const
173
{
174
11372
  return d_valuation.isFiniteType(tn);
175
}
176
177
1346604
Valuation& TheoryState::getValuation() { return d_valuation; }
178
179
}  // namespace theory
180
29502
}  // namespace cvc5