Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Dejan Jovanovic, Mathias Preiner, Gereon Kremer 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 : : * [[ Add one-line brief description here ]] 14 : : * 15 : : * [[ Add lengthier description here ]] 16 : : * \todo document this file 17 : : */ 18 : : 19 : : #include "theory/atom_requests.h" 20 : : 21 : : using namespace cvc5::internal; 22 : : 23 : 49172 : AtomRequests::AtomRequests(context::Context* context) 24 : : : d_allRequests(context), 25 : : d_requests(context), 26 : 49172 : d_triggerToRequestMap(context) 27 : 49172 : {} 28 : : 29 : 7953710 : AtomRequests::element_index AtomRequests::getList(TNode trigger) const { 30 : 7953710 : trigger_to_list_map::const_iterator find = d_triggerToRequestMap.find(trigger); 31 [ + + ]: 7953710 : if (find == d_triggerToRequestMap.end()) { 32 : 7911930 : return null_index; 33 : : } else { 34 : 41774 : return (*find).second; 35 : : } 36 : : } 37 : : 38 : 0 : bool AtomRequests::isTrigger(TNode atom) const { 39 : 0 : return getList(atom) != null_index; 40 : : } 41 : : 42 : 7941010 : AtomRequests::atom_iterator AtomRequests::getAtomIterator(TNode trigger) const { 43 : 7941010 : return atom_iterator(*this, getList(trigger)); 44 : : } 45 : : 46 : 12701 : void AtomRequests::add(TNode triggerAtom, TNode atomToSend, theory::TheoryId toTheory) { 47 : : 48 [ + - ]: 12701 : Trace("theory::atoms") << "AtomRequests::add(" << triggerAtom << ", " << atomToSend << ", " << toTheory << ")" << std::endl; 49 : : 50 : 12701 : Request request(atomToSend, toTheory); 51 : : 52 [ - + ]: 12701 : if (d_allRequests.find(request) != d_allRequests.end()) { 53 : : // Have it already 54 [ - - ]: 0 : Trace("theory::atoms") << "AtomRequests::add(" << triggerAtom << ", " << atomToSend << ", " << toTheory << "): already there" << std::endl; 55 : 0 : return; 56 : : } 57 [ + - ]: 12701 : Trace("theory::atoms") << "AtomRequests::add(" << triggerAtom << ", " << atomToSend << ", " << toTheory << "): adding" << std::endl; 58 : : 59 : : /// Mark the new request 60 : 12701 : d_allRequests.insert(request); 61 : : 62 : : // Index of the new request in the list of trigger 63 : 12701 : element_index index = d_requests.size(); 64 : 12701 : element_index previous = getList(triggerAtom); 65 : 12701 : d_requests.push_back(Element(request, previous)); 66 : 12701 : d_triggerToRequestMap[triggerAtom] = index; 67 : : } 68 : : 69 : 7988810 : bool AtomRequests::atom_iterator::done() const { return d_index == null_index; } 70 : : 71 : 47801 : void AtomRequests::atom_iterator::next() { 72 : 47801 : d_index = d_requests.d_requests[d_index].d_previous; 73 : 47801 : } 74 : : 75 : 47801 : const AtomRequests::Request& AtomRequests::atom_iterator::get() const { 76 : 47801 : return d_requests.d_requests[d_index].d_request; 77 : : } 78 : :