GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/theory_state.cpp Lines: 66 68 97.1 %
Date: 2021-11-06 Branches: 79 190 41.6 %

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
183306
TheoryState::TheoryState(Env& env, Valuation val)
24
183306
    : EnvObj(env), d_valuation(val), d_ee(nullptr), d_conflict(context(), false)
25
{
26
183306
}
27
28
183264
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
29
30
39568651
bool TheoryState::hasTerm(TNode a) const
31
{
32
39568651
  Assert(d_ee != nullptr);
33
39568651
  return d_ee->hasTerm(a);
34
}
35
36
16843638
TNode TheoryState::getRepresentative(TNode t) const
37
{
38
16843638
  Assert(d_ee != nullptr);
39
16843638
  if (d_ee->hasTerm(t))
40
  {
41
16681662
    return d_ee->getRepresentative(t);
42
  }
43
161976
  return t;
44
}
45
46
11704716
bool TheoryState::areEqual(TNode a, TNode b) const
47
{
48
11704716
  Assert(d_ee != nullptr);
49
11704716
  if (a == b)
50
  {
51
2865976
    return true;
52
  }
53
8838740
  else if (hasTerm(a) && hasTerm(b))
54
  {
55
8782671
    return d_ee->areEqual(a, b);
56
  }
57
56069
  return false;
58
}
59
60
3293690
bool TheoryState::areDisequal(TNode a, TNode b) const
61
{
62
3293690
  Assert(d_ee != nullptr);
63
3293690
  if (a == b)
64
  {
65
416541
    return false;
66
  }
67
68
2877149
  bool isConst = true;
69
2877149
  bool hasTerms = true;
70
2877149
  if (hasTerm(a))
71
  {
72
2876452
    a = d_ee->getRepresentative(a);
73
2876452
    isConst = a.isConst();
74
  }
75
697
  else if (!a.isConst())
76
  {
77
    // if not constant and not a term in the ee, it cannot be disequal
78
445
    return false;
79
  }
80
  else
81
  {
82
252
    hasTerms = false;
83
  }
84
85
2876704
  if (hasTerm(b))
86
  {
87
2876248
    b = d_ee->getRepresentative(b);
88
2876248
    isConst = isConst && b.isConst();
89
  }
90
456
  else if (!b.isConst())
91
  {
92
    // same as above, it cannot be disequal
93
102
    return false;
94
  }
95
  else
96
  {
97
354
    hasTerms = false;
98
  }
99
100
2876602
  if (isConst)
101
  {
102
    // distinct constants are disequal
103
1346062
    return a != b;
104
  }
105
1530540
  else if (!hasTerms)
106
  {
107
366
    return false;
108
  }
109
  // otherwise there may be an explicit disequality in the equality engine
110
1530174
  return d_ee->areDisequal(a, b, false);
111
}
112
113
8430
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const
114
{
115
8430
  if (d_ee->hasTerm(a))
116
  {
117
15124
    Node rep = d_ee->getRepresentative(a);
118
7562
    eq::EqClassIterator eqc_iter(rep, d_ee);
119
120548
    while (!eqc_iter.isFinished())
120
    {
121
56493
      eqc.push_back(*eqc_iter);
122
56493
      eqc_iter++;
123
    }
124
  }
125
  else
126
  {
127
868
    eqc.push_back(a);
128
  }
129
  // a should be in its equivalence class
130
8430
  Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end());
131
8430
}
132
133
7658397
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
134
135
2687345
void TheoryState::notifyInConflict() { d_conflict = true; }
136
137
62883429
bool TheoryState::isInConflict() const { return d_conflict; }
138
139
bool TheoryState::isSatLiteral(TNode lit) const
140
{
141
  return d_valuation.isSatLiteral(lit);
142
}
143
144
17648231
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }
145
146
5317
SortInference* TheoryState::getSortInference()
147
{
148
5317
  return d_valuation.getSortInference();
149
}
150
151
41175
bool TheoryState::hasSatValue(TNode n, bool& value) const
152
{
153
41175
  return d_valuation.hasSatValue(n, value);
154
}
155
156
8017
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
157
{
158
8017
  return d_valuation.factsBegin(tid);
159
}
160
8017
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
161
{
162
8017
  return d_valuation.factsEnd(tid);
163
}
164
165
1512757
Valuation& TheoryState::getValuation() { return d_valuation; }
166
167
}  // namespace theory
168
31137
}  // namespace cvc5