GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/theory_state.cpp Lines: 72 74 97.3 %
Date: 2021-08-17 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
118242
TheoryState::TheoryState(Env& env, Valuation val)
24
    : d_env(env),
25
      d_valuation(val),
26
      d_ee(nullptr),
27
118242
      d_conflict(d_env.getContext(), false)
28
{
29
118242
}
30
31
118200
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
32
33
220756
context::Context* TheoryState::getSatContext() const
34
{
35
220756
  return d_env.getContext();
36
}
37
38
293503
context::UserContext* TheoryState::getUserContext() const
39
{
40
293503
  return d_env.getUserContext();
41
}
42
43
25059550
bool TheoryState::hasTerm(TNode a) const
44
{
45
25059550
  Assert(d_ee != nullptr);
46
25059550
  return d_ee->hasTerm(a);
47
}
48
49
13307164
TNode TheoryState::getRepresentative(TNode t) const
50
{
51
13307164
  Assert(d_ee != nullptr);
52
13307164
  if (d_ee->hasTerm(t))
53
  {
54
13148455
    return d_ee->getRepresentative(t);
55
  }
56
158709
  return t;
57
}
58
59
7742317
bool TheoryState::areEqual(TNode a, TNode b) const
60
{
61
7742317
  Assert(d_ee != nullptr);
62
7742317
  if (a == b)
63
  {
64
1913083
    return true;
65
  }
66
5829234
  else if (hasTerm(a) && hasTerm(b))
67
  {
68
5794537
    return d_ee->areEqual(a, b);
69
  }
70
34697
  return false;
71
}
72
73
529303
bool TheoryState::areDisequal(TNode a, TNode b) const
74
{
75
529303
  Assert(d_ee != nullptr);
76
529303
  if (a == b)
77
  {
78
241677
    return false;
79
  }
80
81
287626
  bool isConst = true;
82
287626
  bool hasTerms = true;
83
287626
  if (hasTerm(a))
84
  {
85
287067
    a = d_ee->getRepresentative(a);
86
287067
    isConst = a.isConst();
87
  }
88
559
  else if (!a.isConst())
89
  {
90
    // if not constant and not a term in the ee, it cannot be disequal
91
317
    return false;
92
  }
93
  else
94
  {
95
242
    hasTerms = false;
96
  }
97
98
287309
  if (hasTerm(b))
99
  {
100
286919
    b = d_ee->getRepresentative(b);
101
286919
    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
287252
  if (isConst)
114
  {
115
    // distinct constants are disequal
116
51918
    return a != b;
117
  }
118
235334
  else if (!hasTerms)
119
  {
120
337
    return false;
121
  }
122
  // otherwise there may be an explicit disequality in the equality engine
123
234997
  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
7171698
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
147
148
2319652
void TheoryState::notifyInConflict() { d_conflict = true; }
149
150
43736845
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
1514
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }
158
159
5171
SortInference* TheoryState::getSortInference()
160
{
161
5171
  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
7607
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
170
{
171
7607
  return d_valuation.factsBegin(tid);
172
}
173
7607
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
174
{
175
7607
  return d_valuation.factsEnd(tid);
176
}
177
178
11286
bool TheoryState::isFiniteType(TypeNode tn) const
179
{
180
11286
  return d_valuation.isFiniteType(tn);
181
}
182
183
1346734
Valuation& TheoryState::getValuation() { return d_valuation; }
184
185
}  // namespace theory
186
29337
}  // namespace cvc5