1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
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 |
|
* Justification stack. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "decision/justify_stack.h" |
17 |
|
|
18 |
|
namespace cvc5 { |
19 |
|
namespace decision { |
20 |
|
|
21 |
7731 |
JustifyStack::JustifyStack(context::Context* c) |
22 |
7731 |
: d_context(c), d_current(c), d_stack(c), d_stackSizeValid(c, 0) |
23 |
|
{ |
24 |
7731 |
} |
25 |
7730 |
JustifyStack::~JustifyStack() {} |
26 |
|
|
27 |
7443299 |
void JustifyStack::reset(TNode curr) |
28 |
|
{ |
29 |
7443299 |
d_current = curr; |
30 |
7443299 |
d_stackSizeValid = 0; |
31 |
7443299 |
pushToStack(curr, prop::SAT_VALUE_TRUE); |
32 |
7443299 |
} |
33 |
7476098 |
void JustifyStack::clear() |
34 |
|
{ |
35 |
7476098 |
d_current = TNode::null(); |
36 |
7476098 |
d_stackSizeValid = 0; |
37 |
7476098 |
} |
38 |
|
|
39 |
2788217 |
size_t JustifyStack::size() const { return d_stackSizeValid.get(); } |
40 |
|
|
41 |
22981397 |
TNode JustifyStack::getCurrentAssertion() const { return d_current.get(); } |
42 |
15543455 |
bool JustifyStack::hasCurrentAssertion() const |
43 |
|
{ |
44 |
15543455 |
return !d_current.get().isNull(); |
45 |
|
} |
46 |
40974529 |
JustifyInfo* JustifyStack::getCurrent() |
47 |
|
{ |
48 |
40974529 |
if (d_stackSizeValid.get() == 0) |
49 |
|
{ |
50 |
7363911 |
return nullptr; |
51 |
|
} |
52 |
33610618 |
Assert(d_stack.size() >= d_stackSizeValid.get()); |
53 |
33610618 |
return d_stack[d_stackSizeValid.get() - 1].get(); |
54 |
|
} |
55 |
|
|
56 |
10231516 |
void JustifyStack::pushToStack(TNode n, prop::SatValue desiredVal) |
57 |
|
{ |
58 |
10231516 |
if (Trace.isOn("jh-stack")) |
59 |
|
{ |
60 |
|
for (size_t i = 0, ssize = d_stackSizeValid.get(); i < ssize; i++) |
61 |
|
{ |
62 |
|
Trace("jh-stack") << " "; |
63 |
|
} |
64 |
|
Trace("jh-stack") << "- " << n << " " << desiredVal << std::endl; |
65 |
|
} |
66 |
|
// note that n is possibly negated here |
67 |
10231516 |
JustifyInfo* ji = getOrAllocJustifyInfo(d_stackSizeValid.get()); |
68 |
10231516 |
ji->set(n, desiredVal); |
69 |
10231516 |
d_stackSizeValid = d_stackSizeValid + 1; |
70 |
10231516 |
} |
71 |
|
|
72 |
9988145 |
void JustifyStack::popStack() |
73 |
|
{ |
74 |
9988145 |
Assert(d_stackSizeValid.get() > 0); |
75 |
9988145 |
d_stackSizeValid = d_stackSizeValid - 1; |
76 |
9988145 |
} |
77 |
|
|
78 |
10231516 |
JustifyInfo* JustifyStack::getOrAllocJustifyInfo(size_t i) |
79 |
|
{ |
80 |
|
// don't request stack beyond the bound |
81 |
10231516 |
Assert(i <= d_stack.size()); |
82 |
10231516 |
if (i == d_stack.size()) |
83 |
|
{ |
84 |
197909 |
d_stack.push_back(std::make_shared<JustifyInfo>(d_context)); |
85 |
|
} |
86 |
10231516 |
return d_stack[i].get(); |
87 |
|
} |
88 |
|
|
89 |
|
} |
90 |
29502 |
} // namespace cvc5 |