FloatingPoint: Separate out symFPU glue code. (#5492)
[cvc5.git] / src / theory / atom_requests.h
1 /********************* */
2 /*! \file atom_requests.h
3 ** \verbatim
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
11 **
12 ** \brief [[ Add one-line brief description here ]]
13 **
14 ** [[ Add lengthier description here ]]
15 ** \todo document this file
16 **/
17
18 #include "cvc4_private.h"
19
20 #pragma once
21
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"
27
28 namespace CVC4 {
29
30 class AtomRequests {
31
32 public:
33
34 /** Which atom and where to send it */
35 struct Request {
36 /** Atom */
37 Node d_atom;
38 /** Where to send it */
39 theory::TheoryId d_toTheory;
40
41 Request(TNode a, theory::TheoryId tt) : d_atom(a), d_toTheory(tt) {}
42 Request() : d_toTheory(theory::THEORY_LAST) {}
43
44 bool operator == (const Request& other) const {
45 return d_atom == other.d_atom && d_toTheory == other.d_toTheory;
46 }
47
48 size_t hash() const { return d_atom.getId(); }
49 };
50
51 AtomRequests(context::Context* context);
52
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);
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 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)
68 {
69 }
70
71 public:
72 /** Is this iterator done */
73 bool done() const;
74 /** Go to the next element */
75 void next();
76 /** Get the actual request */
77 const Request& get() const;
78 };
79
80 atom_iterator getAtomIterator(TNode trigger) const;
81
82 private:
83
84 struct RequestHashFunction {
85 size_t operator () (const Request& r) const {
86 return r.hash();
87 }
88 };
89
90 /** Set of all requests so we don't add twice */
91 context::CDHashSet<Request, RequestHashFunction> d_allRequests;
92
93 static const element_index null_index = -1;
94
95 struct Element {
96 /** Current request */
97 Request d_request;
98 /** Previous request */
99 element_index d_previous;
100
101 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, NodeHashFunction> 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
117 }
118
119
120
121