GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/theory_state.cpp Lines: 73 73 100.0 %
Date: 2021-05-22 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
104102
TheoryState::TheoryState(context::Context* c,
24
                         context::UserContext* u,
25
104102
                         Valuation val)
26
    : d_context(c),
27
      d_ucontext(u),
28
      d_valuation(val),
29
      d_ee(nullptr),
30
104102
      d_conflict(c, false)
31
{
32
104102
}
33
34
104060
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
35
36
165858
context::Context* TheoryState::getSatContext() const { return d_context; }
37
38
256548
context::UserContext* TheoryState::getUserContext() const { return d_ucontext; }
39
40
27674516
bool TheoryState::hasTerm(TNode a) const
41
{
42
27674516
  Assert(d_ee != nullptr);
43
27674516
  return d_ee->hasTerm(a);
44
}
45
46
12594652
TNode TheoryState::getRepresentative(TNode t) const
47
{
48
12594652
  Assert(d_ee != nullptr);
49
12594652
  if (d_ee->hasTerm(t))
50
  {
51
12427460
    return d_ee->getRepresentative(t);
52
  }
53
167192
  return t;
54
}
55
56
7943689
bool TheoryState::areEqual(TNode a, TNode b) const
57
{
58
7943689
  Assert(d_ee != nullptr);
59
7943689
  if (a == b)
60
  {
61
2444786
    return true;
62
  }
63
5498903
  else if (hasTerm(a) && hasTerm(b))
64
  {
65
5472104
    return d_ee->areEqual(a, b);
66
  }
67
26799
  return false;
68
}
69
70
578426
bool TheoryState::areDisequal(TNode a, TNode b) const
71
{
72
578426
  Assert(d_ee != nullptr);
73
578426
  if (a == b)
74
  {
75
298687
    return false;
76
  }
77
78
279739
  bool isConst = true;
79
279739
  bool hasTerms = true;
80
279739
  if (hasTerm(a))
81
  {
82
279244
    a = d_ee->getRepresentative(a);
83
279244
    isConst = a.isConst();
84
  }
85
495
  else if (!a.isConst())
86
  {
87
    // if not constant and not a term in the ee, it cannot be disequal
88
317
    return false;
89
  }
90
  else
91
  {
92
178
    hasTerms = false;
93
  }
94
95
279422
  if (hasTerm(b))
96
  {
97
279010
    b = d_ee->getRepresentative(b);
98
279010
    isConst = isConst && b.isConst();
99
  }
100
412
  else if (!b.isConst())
101
  {
102
    // same as above, it cannot be disequal
103
77
    return false;
104
  }
105
  else
106
  {
107
335
    hasTerms = false;
108
  }
109
110
279345
  if (isConst)
111
  {
112
    // distinct constants are disequal
113
48331
    return a != b;
114
  }
115
231014
  else if (!hasTerms)
116
  {
117
267
    return false;
118
  }
119
  // otherwise there may be an explicit disequality in the equality engine
120
230747
  return d_ee->areDisequal(a, b, false);
121
}
122
123
8688
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const
124
{
125
8688
  if (d_ee->hasTerm(a))
126
  {
127
16030
    Node rep = d_ee->getRepresentative(a);
128
8015
    eq::EqClassIterator eqc_iter(rep, d_ee);
129
107331
    while (!eqc_iter.isFinished())
130
    {
131
49658
      eqc.push_back(*eqc_iter);
132
49658
      eqc_iter++;
133
    }
134
  }
135
  else
136
  {
137
673
    eqc.push_back(a);
138
  }
139
  // a should be in its equivalence class
140
8688
  Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end());
141
8688
}
142
143
6330479
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
144
145
165708
void TheoryState::notifyInConflict() { d_conflict = true; }
146
147
37174381
bool TheoryState::isInConflict() const { return d_conflict; }
148
149
568798
bool TheoryState::isSatLiteral(TNode lit) const
150
{
151
568798
  return d_valuation.isSatLiteral(lit);
152
}
153
154
1725
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }
155
156
5217
SortInference* TheoryState::getSortInference()
157
{
158
5217
  return d_valuation.getSortInference();
159
}
160
161
108
bool TheoryState::hasSatValue(TNode n, bool& value) const
162
{
163
108
  return d_valuation.hasSatValue(n, value);
164
}
165
166
6444
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
167
{
168
6444
  return d_valuation.factsBegin(tid);
169
}
170
6444
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
171
{
172
6444
  return d_valuation.factsEnd(tid);
173
}
174
175
11008
bool TheoryState::isFiniteType(TypeNode tn) const
176
{
177
11008
  return d_valuation.isFiniteType(tn);
178
}
179
180
132470
Valuation& TheoryState::getValuation() { return d_valuation; }
181
182
}  // namespace theory
183
28194
}  // namespace cvc5