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