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 : : * Implementation of a cache of skolems for theory of sets. 11 : : */ 12 : : 13 : : #include "theory/sets/skolem_cache.h" 14 : : 15 : : #include "expr/skolem_manager.h" 16 : : #include "theory/rewriter.h" 17 : : 18 : : using namespace cvc5::internal::kind; 19 : : 20 : : namespace cvc5::internal { 21 : : namespace theory { 22 : : namespace sets { 23 : : 24 : 50253 : SkolemCache::SkolemCache(NodeManager* nm, Rewriter* rr) 25 : 50253 : : d_nm(nm), d_rewriter(rr) 26 : : { 27 : 50253 : } 28 : : 29 : 9969 : Node SkolemCache::mkTypedSkolemCached( 30 : : TypeNode tn, Node a, Node b, SkolemId id, const char* c) 31 : : { 32 [ + - ]: 9969 : if (d_rewriter != nullptr) 33 : : { 34 [ - + ][ + - ]: 9969 : a = a.isNull() ? a : d_rewriter->rewrite(a); [ - - ] 35 [ + + ][ + + ]: 9969 : b = b.isNull() ? b : d_rewriter->rewrite(b); [ - - ] 36 : : } 37 : 9969 : std::map<SkolemId, Node>::iterator it = d_skolemCache[a][b].find(id); 38 [ + + ]: 9969 : if (it == d_skolemCache[a][b].end()) 39 : : { 40 : 8351 : SkolemManager* sm = d_nm->getSkolemManager(); 41 : 8351 : Node sk; 42 [ + + ]: 8351 : if (id == SkolemId::SK_PURIFY) 43 : : { 44 [ - + ][ - + ]: 7164 : Assert(a.getType() == tn); [ - - ] 45 : 7164 : sk = sm->mkPurifySkolem(a); 46 : : } 47 : : else 48 : : { 49 : 1187 : sk = NodeManager::mkDummySkolem(c, tn); 50 : : } 51 : 8351 : d_skolemCache[a][b][id] = sk; 52 : 8351 : d_allSkolems.insert(sk); 53 : 8351 : return sk; 54 : 8351 : } 55 : 1618 : return it->second; 56 : : } 57 : 7168 : Node SkolemCache::mkTypedSkolemCached(TypeNode tn, 58 : : Node a, 59 : : SkolemId id, 60 : : const char* c) 61 : : { 62 : 7168 : return mkTypedSkolemCached(tn, a, Node::null(), id, c); 63 : : } 64 : : 65 : 0 : Node SkolemCache::mkTypedSkolem(TypeNode tn, const char* c) 66 : : { 67 : 0 : Node n = NodeManager::mkDummySkolem(c, tn); 68 : 0 : d_allSkolems.insert(n); 69 : 0 : return n; 70 : 0 : } 71 : : 72 : 371759 : bool SkolemCache::isSkolem(Node n) const 73 : : { 74 : 371759 : return d_allSkolems.find(n) != d_allSkolems.end(); 75 : : } 76 : : 77 : : } // namespace sets 78 : : } // namespace theory 79 : : } // namespace cvc5::internal