Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Term context stack. 11 : : */ 12 : : 13 : : #include "expr/term_context_stack.h" 14 : : 15 : : #include "expr/term_context.h" 16 : : 17 : : namespace cvc5::internal { 18 : : 19 : 1924221 : TCtxStack::TCtxStack(const TermContext* tctx) : d_tctx(tctx) {} 20 : : 21 : 1924221 : void TCtxStack::pushInitial(Node t) 22 : : { 23 [ - + ][ - + ]: 1924221 : Assert(d_stack.empty()); [ - - ] 24 : 1924221 : d_stack.push_back(std::pair<Node, uint32_t>(t, d_tctx->initialValue())); 25 : 1924221 : } 26 : : 27 : 997645 : void TCtxStack::pushChildren(Node t, uint32_t tval) 28 : : { 29 [ + + ]: 2684468 : for (size_t i = 0, nchild = t.getNumChildren(); i < nchild; i++) 30 : : { 31 : 1686823 : pushChild(t, tval, i); 32 : : } 33 : 997645 : } 34 : : 35 : 14060538 : void TCtxStack::pushChild(Node t, uint32_t tval, size_t index) 36 : : { 37 [ - + ][ - + ]: 14060538 : Assert(index < t.getNumChildren()); [ - - ] 38 [ + - ]: 28121076 : Trace("tctx-debug") << "TCtxStack::pushChild: computing " << t << "[" << index 39 : 14060538 : << "] / " << tval << std::endl; 40 : 14060538 : uint32_t tcval = d_tctx->computeValue(t, tval, index); 41 [ + - ]: 28121076 : Trace("tctx-debug") << "TCtxStack::pushChild: returned " << t << "[" << index 42 : 14060538 : << "] / " << tval << " ---> " << tcval << std::endl; 43 : 14060538 : d_stack.push_back(std::pair<Node, uint32_t>(t[index], tcval)); 44 : 14060538 : } 45 : : 46 : 527 : void TCtxStack::pushOp(Node t, uint32_t tval) 47 : : { 48 [ - + ][ - + ]: 527 : Assert(t.hasOperator()); [ - - ] 49 : 527 : uint32_t toval = d_tctx->computeValueOp(t, tval); 50 : 527 : d_stack.push_back(std::pair<Node, uint32_t>(t.getOperator(), toval)); 51 : 527 : } 52 : : 53 : 1271462 : void TCtxStack::push(Node t, uint32_t tval) 54 : : { 55 : 1271462 : d_stack.push_back(std::pair<Node, uint32_t>(t, tval)); 56 : 1271462 : } 57 : : 58 : 17256707 : void TCtxStack::pop() { d_stack.pop_back(); } 59 : : 60 : 0 : void TCtxStack::clear() { d_stack.clear(); } 61 : 0 : size_t TCtxStack::size() const { return d_stack.size(); } 62 : : 63 : 23929883 : bool TCtxStack::empty() const { return d_stack.empty(); } 64 : : 65 : 23926836 : std::pair<Node, uint32_t> TCtxStack::getCurrent() const 66 : : { 67 : 23926836 : return d_stack.back(); 68 : : } 69 : : 70 : 0 : TCtxNode TCtxStack::getCurrentNode() const 71 : : { 72 : 0 : std::pair<Node, uint32_t> curr = TCtxStack::getCurrent(); 73 : 0 : return TCtxNode(curr.first, curr.second, d_tctx); 74 : 0 : } 75 : : 76 : : } // namespace cvc5::internal