1 /********************* */
2 /*! \file term_registration_visitor.h
4 ** Top contributors (to current version):
5 ** Dejan Jovanovic, Andrew Reynolds, Morgan Deters
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 ** [[ Add lengthier description here ]]
13 ** \todo document this file
16 #include "cvc4_private.h"
20 #include "context/context.h"
21 #include "theory/shared_terms_database.h"
23 #include <unordered_map>
30 * Visitor that calls the appropriate theory to pre-register the term. The visitor also keeps track
31 * of the sets of theories that are involved in the terms, so that it can say if there are multiple
34 * A sub-term has been visited if the theories of both the parent and the term itself have already
37 * Computation of the set of theories in the original term are computed in the alreadyVisited method
38 * so as no to skip any theories.
40 class PreRegisterVisitor
{
43 TheoryEngine
* d_engine
;
45 typedef context::CDHashMap
<TNode
, theory::TheoryIdSet
, TNodeHashFunction
>
49 * Map from terms to the theories that have already had this term pre-registered.
51 TNodeToTheorySetMap d_visited
;
54 * A set of all theories in the term
56 theory::TheoryIdSet d_theories
;
59 * String representation of the visited map, for debugging purposes.
61 std::string
toString() const;
64 /** Returned set tells us which theories there are */
65 typedef theory::TheoryIdSet return_type
;
67 PreRegisterVisitor(TheoryEngine
* engine
, context::Context
* context
)
68 : d_engine(engine
), d_visited(context
), d_theories(0)
73 * Returns true is current has already been pre-registered with both current
74 * and parent theories.
76 bool alreadyVisited(TNode current
, TNode parent
);
79 * Pre-registeres current with any of the current and parent theories that
80 * haven't seen the term yet.
82 void visit(TNode current
, TNode parent
);
85 * Marks the node as the starting literal.
87 void start(TNode node
) {}
90 * Notifies the engine of all the theories used.
92 theory::TheoryIdSet
done(TNode node
) { return d_theories
; }
97 * The reason why we need to make this outside of the pre-registration loop is because we need a shared term x to
98 * be associated with every atom that contains it. For example, if given f(x) >= 0 and f(x) + 1 >= 0, although f(x) has
99 * been visited already, we need to visit it again, since we need to associate it with both atoms.
101 class SharedTermsVisitor
{
103 /** The shared terms database */
104 SharedTermsDatabase
& d_sharedTerms
;
107 * Cache from preprocessing of atoms.
109 typedef std::unordered_map
<TNode
, theory::TheoryIdSet
, TNodeHashFunction
>
111 TNodeVisitedMap d_visited
;
114 * String representation of the visited map, for debugging purposes.
116 std::string
toString() const;
125 typedef void return_type
;
127 SharedTermsVisitor(SharedTermsDatabase
& sharedTerms
)
128 : d_sharedTerms(sharedTerms
) {}
131 * Returns true is current has already been pre-registered with both current and parent theories.
133 bool alreadyVisited(TNode current
, TNode parent
) const;
136 * Pre-registeres current with any of the current and parent theories that haven't seen the term yet.
138 void visit(TNode current
, TNode parent
);
141 * Marks the node as the starting literal.
143 void start(TNode node
);
146 * Just clears the state.
148 void done(TNode node
);
151 * Clears the internal state.