GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/theory_state.cpp Lines: 72 74 97.3 %
Date: 2021-08-19 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
118290
TheoryState::TheoryState(Env& env, Valuation val)
24
    : d_env(env),
25
      d_valuation(val),
26
      d_ee(nullptr),
27
118290
      d_conflict(d_env.getContext(), false)
28
{
29
118290
}
30
31
118248
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
32
33
220825
context::Context* TheoryState::getSatContext() const
34
{
35
220825
  return d_env.getContext();
36
}
37
38
293799
context::UserContext* TheoryState::getUserContext() const
39
{
40
293799
  return d_env.getUserContext();
41
}
42
43
25850933
bool TheoryState::hasTerm(TNode a) const
44
{
45
25850933
  Assert(d_ee != nullptr);
46
25850933
  return d_ee->hasTerm(a);
47
}
48
49
13384146
TNode TheoryState::getRepresentative(TNode t) const
50
{
51
13384146
  Assert(d_ee != nullptr);
52
13384146
  if (d_ee->hasTerm(t))
53
  {
54
13226445
    return d_ee->getRepresentative(t);
55
  }
56
157701
  return t;
57
}
58
59
7786345
bool TheoryState::areEqual(TNode a, TNode b) const
60
{
61
7786345
  Assert(d_ee != nullptr);
62
7786345
  if (a == b)
63
  {
64
1916123
    return true;
65
  }
66
5870222
  else if (hasTerm(a) && hasTerm(b))
67
  {
68
5833031
    return d_ee->areEqual(a, b);
69
  }
70
37191
  return false;
71
}
72
73
529434
bool TheoryState::areDisequal(TNode a, TNode b) const
74
{
75
529434
  Assert(d_ee != nullptr);
76
529434
  if (a == b)
77
  {
78
237998
    return false;
79
  }
80
81
291436
  bool isConst = true;
82
291436
  bool hasTerms = true;
83
291436
  if (hasTerm(a))
84
  {
85
290873
    a = d_ee->getRepresentative(a);
86
290873
    isConst = a.isConst();
87
  }
88
563
  else if (!a.isConst())
89
  {
90
    // if not constant and not a term in the ee, it cannot be disequal
91
321
    return false;
92
  }
93
  else
94
  {
95
242
    hasTerms = false;
96
  }
97
98
291115
  if (hasTerm(b))
99
  {
100
290725
    b = d_ee->getRepresentative(b);
101
290725
    isConst = isConst && b.isConst();
102
  }
103
390
  else if (!b.isConst())
104
  {
105
    // same as above, it cannot be disequal
106
57
    return false;
107
  }
108
  else
109
  {
110
333
    hasTerms = false;
111
  }
112
113
291058
  if (isConst)
114
  {
115
    // distinct constants are disequal
116
51813
    return a != b;
117
  }
118
239245
  else if (!hasTerms)
119
  {
120
337
    return false;
121
  }
122
  // otherwise there may be an explicit disequality in the equality engine
123
238908
  return d_ee->areDisequal(a, b, false);
124
}
125
126
7691
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const
127
{
128
7691
  if (d_ee->hasTerm(a))
129
  {
130
13916
    Node rep = d_ee->getRepresentative(a);
131
6958
    eq::EqClassIterator eqc_iter(rep, d_ee);
132
108164
    while (!eqc_iter.isFinished())
133
    {
134
50603
      eqc.push_back(*eqc_iter);
135
50603
      eqc_iter++;
136
    }
137
  }
138
  else
139
  {
140
733
    eqc.push_back(a);
141
  }
142
  // a should be in its equivalence class
143
7691
  Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end());
144
7691
}
145
146
7042906
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
147
148
2315848
void TheoryState::notifyInConflict() { d_conflict = true; }
149
150
43849203
bool TheoryState::isInConflict() const { return d_conflict; }
151
152
bool TheoryState::isSatLiteral(TNode lit) const
153
{
154
  return d_valuation.isSatLiteral(lit);
155
}
156
157
2830920
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }
158
159
5158
SortInference* TheoryState::getSortInference()
160
{
161
5158
  return d_valuation.getSortInference();
162
}
163
164
42519
bool TheoryState::hasSatValue(TNode n, bool& value) const
165
{
166
42519
  return d_valuation.hasSatValue(n, value);
167
}
168
169
7611
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
170
{
171
7611
  return d_valuation.factsBegin(tid);
172
}
173
7611
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
174
{
175
7611
  return d_valuation.factsEnd(tid);
176
}
177
178
11357
bool TheoryState::isFiniteType(TypeNode tn) const
179
{
180
11357
  return d_valuation.isFiniteType(tn);
181
}
182
183
1346859
Valuation& TheoryState::getValuation() { return d_valuation; }
184
185
}  // namespace theory
186
29349
}  // namespace cvc5