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 |
|
* Term context stack. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "expr/term_context_stack.h" |
17 |
|
|
18 |
|
#include "expr/term_context.h" |
19 |
|
|
20 |
|
namespace cvc5 { |
21 |
|
|
22 |
549381 |
TCtxStack::TCtxStack(const TermContext* tctx) : d_tctx(tctx) {} |
23 |
|
|
24 |
549381 |
void TCtxStack::pushInitial(Node t) |
25 |
|
{ |
26 |
549381 |
Assert(d_stack.empty()); |
27 |
549381 |
d_stack.push_back(std::pair<Node, uint32_t>(t, d_tctx->initialValue())); |
28 |
549381 |
} |
29 |
|
|
30 |
276664 |
void TCtxStack::pushChildren(Node t, uint32_t tval) |
31 |
|
{ |
32 |
751336 |
for (size_t i = 0, nchild = t.getNumChildren(); i < nchild; i++) |
33 |
|
{ |
34 |
474672 |
pushChild(t, tval, i); |
35 |
|
} |
36 |
276664 |
} |
37 |
|
|
38 |
2551268 |
void TCtxStack::pushChild(Node t, uint32_t tval, size_t index) |
39 |
|
{ |
40 |
2551268 |
Assert(index < t.getNumChildren()); |
41 |
5102536 |
Trace("tctx-debug") << "TCtxStack::pushChild: computing " << t << "[" << index |
42 |
2551268 |
<< "] / " << tval << std::endl; |
43 |
2551268 |
uint32_t tcval = d_tctx->computeValue(t, tval, index); |
44 |
5102536 |
Trace("tctx-debug") << "TCtxStack::pushChild: returned " << t << "[" << index |
45 |
2551268 |
<< "] / " << tval << " ---> " << tcval << std::endl; |
46 |
2551268 |
d_stack.push_back(std::pair<Node, uint32_t>(t[index], tcval)); |
47 |
2551268 |
} |
48 |
|
|
49 |
|
void TCtxStack::pushOp(Node t, uint32_t tval) |
50 |
|
{ |
51 |
|
Assert(t.hasOperator()); |
52 |
|
uint32_t toval = d_tctx->computeValueOp(t, tval); |
53 |
|
d_stack.push_back(std::pair<Node, uint32_t>(t.getOperator(), toval)); |
54 |
|
} |
55 |
|
|
56 |
383334 |
void TCtxStack::push(Node t, uint32_t tval) |
57 |
|
{ |
58 |
383334 |
d_stack.push_back(std::pair<Node, uint32_t>(t, tval)); |
59 |
383334 |
} |
60 |
|
|
61 |
3483983 |
void TCtxStack::pop() { d_stack.pop_back(); } |
62 |
|
|
63 |
|
void TCtxStack::clear() { d_stack.clear(); } |
64 |
|
size_t TCtxStack::size() const { return d_stack.size(); } |
65 |
|
|
66 |
4937190 |
bool TCtxStack::empty() const { return d_stack.empty(); } |
67 |
|
|
68 |
4937190 |
std::pair<Node, uint32_t> TCtxStack::getCurrent() const |
69 |
|
{ |
70 |
4937190 |
return d_stack.back(); |
71 |
|
} |
72 |
|
|
73 |
|
TCtxNode TCtxStack::getCurrentNode() const |
74 |
|
{ |
75 |
|
std::pair<Node, uint32_t> curr = TCtxStack::getCurrent(); |
76 |
|
return TCtxNode(curr.first, curr.second, d_tctx); |
77 |
|
} |
78 |
|
|
79 |
27735 |
} // namespace cvc5 |