1 /********************* */
2 /*! \file atom_requests.h
4 ** Top contributors (to current version):
5 ** Dejan Jovanovic, Andrew Reynolds
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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.\endverbatim
12 ** \brief [[ Add one-line brief description here ]]
14 ** [[ Add lengthier description here ]]
15 ** \todo document this file
18 #include "cvc4_private.h"
22 #include "expr/node.h"
23 #include "theory/theory.h"
24 #include "context/cdlist.h"
25 #include "context/cdhashset.h"
26 #include "context/cdhashmap.h"
34 /** Which atom and where to send it */
38 /** Where to send it */
39 theory::TheoryId d_toTheory
;
41 Request(TNode a
, theory::TheoryId tt
) : d_atom(a
), d_toTheory(tt
) {}
42 Request() : d_toTheory(theory::THEORY_LAST
) {}
44 bool operator == (const Request
& other
) const {
45 return d_atom
== other
.d_atom
&& d_toTheory
== other
.d_toTheory
;
48 size_t hash() const { return d_atom
.getId(); }
51 AtomRequests(context::Context
* context
);
53 /** Mark the atom to be sent to a theory, when the trigger atom gets assigned */
54 void add(TNode triggerAtom
, TNode atomToSend
, theory::TheoryId toTheory
);
56 /** Returns true if the node is a trigger and has a list of atoms to send */
57 bool isTrigger(TNode atom
) const;
59 /** Indices in lists */
60 typedef size_t element_index
;
63 const AtomRequests
& d_requests
;
64 element_index d_index
;
65 friend class AtomRequests
;
66 atom_iterator(const AtomRequests
& requests
, element_index start
)
67 : d_requests(requests
), d_index(start
)
72 /** Is this iterator done */
74 /** Go to the next element */
76 /** Get the actual request */
77 const Request
& get() const;
80 atom_iterator
getAtomIterator(TNode trigger
) const;
84 struct RequestHashFunction
{
85 size_t operator () (const Request
& r
) const {
90 /** Set of all requests so we don't add twice */
91 context::CDHashSet
<Request
, RequestHashFunction
> d_allRequests
;
93 static const element_index null_index
= -1;
96 /** Current request */
98 /** Previous request */
99 element_index d_previous
;
101 Element(const Request
& r
, element_index p
) : d_request(r
), d_previous(p
) {}
104 /** We index the requests in this vector, it's a list */
105 context::CDList
<Element
> d_requests
;
107 typedef context::CDHashMap
<Node
, element_index
, NodeHashFunction
> trigger_to_list_map
;
109 /** Map from triggers, to the list of elements they trigger */
110 trigger_to_list_map d_triggerToRequestMap
;
112 /** Get the list index of the trigger */
113 element_index
getList(TNode trigger
) const;