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 : : * [[ Add one-line brief description here ]] 11 : : * 12 : : * [[ Add lengthier description here ]] 13 : : * \todo document this file 14 : : */ 15 : : 16 : : #include "cvc5_private.h" 17 : : 18 : : #pragma once 19 : : 20 : : #include "context/cdhashmap.h" 21 : : #include "context/cdhashset.h" 22 : : #include "context/cdlist.h" 23 : : #include "expr/node.h" 24 : : #include "theory/theory_id.h" 25 : : 26 : : namespace cvc5::internal { 27 : : 28 : : class AtomRequests 29 : : { 30 : : public: 31 : : /** Which atom and where to send it */ 32 : : struct Request 33 : : { 34 : : /** Atom */ 35 : : Node d_atom; 36 : : /** Where to send it */ 37 : : theory::TheoryId d_toTheory; 38 : : 39 : 12923 : Request(TNode a, theory::TheoryId tt) : d_atom(a), d_toTheory(tt) {} 40 : : Request() : d_toTheory(theory::THEORY_LAST) {} 41 : : 42 : 15374 : bool operator==(const Request& other) const 43 : : { 44 [ + - ][ + + ]: 15374 : return d_atom == other.d_atom && d_toTheory == other.d_toTheory; 45 : : } 46 : : 47 : 64601 : size_t hash() const { return d_atom.getId(); } 48 : : }; 49 : : 50 : : AtomRequests(context::Context* context); 51 : : 52 : : /** Mark the atom to be sent to a theory, when the trigger atom gets assigned 53 : : */ 54 : : void add(TNode triggerAtom, TNode atomToSend, theory::TheoryId toTheory); 55 : : 56 : : /** Returns true if the node is a trigger and has a list of atoms to send */ 57 : : bool isTrigger(TNode atom) const; 58 : : 59 : : /** Indices in lists */ 60 : : typedef size_t element_index; 61 : : 62 : : class atom_iterator 63 : : { 64 : : const AtomRequests& d_requests; 65 : : element_index d_index; 66 : : friend class AtomRequests; 67 : 9184853 : atom_iterator(const AtomRequests& requests, element_index start) 68 : 9184853 : : d_requests(requests), d_index(start) 69 : : { 70 : 9184853 : } 71 : : 72 : : public: 73 : : /** Is this iterator done */ 74 : : bool done() const; 75 : : /** Go to the next element */ 76 : : void next(); 77 : : /** Get the actual request */ 78 : : const Request& get() const; 79 : : }; 80 : : 81 : : atom_iterator getAtomIterator(TNode trigger) const; 82 : : 83 : : private: 84 : : struct RequestHashFunction 85 : : { 86 : 64601 : size_t operator()(const Request& r) const { return r.hash(); } 87 : : }; 88 : : 89 : : /** Set of all requests so we don't add twice */ 90 : : context::CDHashSet<Request, RequestHashFunction> d_allRequests; 91 : : 92 : : static const element_index null_index = -1; 93 : : 94 : : struct Element 95 : : { 96 : : /** Current request */ 97 : : Request d_request; 98 : : /** Previous request */ 99 : : element_index d_previous; 100 : : 101 : 12923 : Element(const Request& r, element_index p) : d_request(r), d_previous(p) {} 102 : : }; 103 : : 104 : : /** We index the requests in this vector, it's a list */ 105 : : context::CDList<Element> d_requests; 106 : : 107 : : typedef context::CDHashMap<Node, element_index> trigger_to_list_map; 108 : : 109 : : /** Map from triggers, to the list of elements they trigger */ 110 : : trigger_to_list_map d_triggerToRequestMap; 111 : : 112 : : /** Get the list index of the trigger */ 113 : : element_index getList(TNode trigger) const; 114 : : }; 115 : : 116 : : } // namespace cvc5::internal