1 /********************* */
2 /*! \file shared_solver.h
4 ** Top contributors (to current version):
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 Base class for shared solver
15 #include "cvc4_private.h"
17 #ifndef CVC4__THEORY__SHARED_SOLVER__H
18 #define CVC4__THEORY__SHARED_SOLVER__H
20 #include "expr/node.h"
21 #include "expr/proof_node_manager.h"
22 #include "theory/ee_setup_info.h"
23 #include "theory/logic_info.h"
24 #include "theory/shared_terms_database.h"
25 #include "theory/term_registration_visitor.h"
26 #include "theory/valuation.h"
35 * A base class for shared solver. The shared solver is the component of theory
36 * engine that behaves like a theory solver, and whose purpose is to ensure the
37 * main theory combination method can be performed in CombinationEngine.
39 * (1) Notify the individual theories of shared terms via addSharedTerms,
40 * (2) Be the official interface for equality statuses,
41 * (3) Propagate equalities to TheoryEngine when necessary and explain them.
46 SharedSolver(TheoryEngine
& te
, ProofNodeManager
* pnm
);
47 virtual ~SharedSolver() {}
48 //------------------------------------- initialization
50 * Returns true if we need an equality engine, this has the same contract
51 * as Theory::needsEqualityEngine.
53 virtual bool needsEqualityEngine(theory::EeSetupInfo
& esi
);
55 * Set the equality engine. This should be called by equality engine manager
56 * during EqEngineManager::initializeTheories.
58 virtual void setEqualityEngine(eq::EqualityEngine
* ee
) = 0;
59 //------------------------------------- end initialization
61 * Called when the given atom is pre-registered in TheoryEngine.
63 * This calls Theory::preRegisterTerm on all subterms of atom for the
64 * appropriate theories.
66 * Also, if sharing is enabled, this adds atom as an equality to propagate in
67 * the shared terms database if it is an equality, and adds its shared terms
68 * to the appropariate theories.
70 * @param atom The atom to preregister
72 void preRegister(TNode atom
);
74 * Pre-notify assertion fact with the given atom. This is called when any
75 * fact is asserted in TheoryEngine, just before it is dispatched to the
78 * This calls Theory::notifySharedTerm for the shared terms of the atom.
80 void preNotifySharedFact(TNode atom
);
82 * Get the equality status of a and b.
84 * This method is used by theories via Valuation mostly for determining their
87 virtual EqualityStatus
getEqualityStatus(TNode a
, TNode b
);
89 * Explain literal, which returns a conjunction of literals that entail
92 virtual TrustNode
explain(TNode literal
, TheoryId id
) = 0;
94 * Assert equality to the shared terms database.
96 * This method is called by TheoryEngine when a fact has been marked to
97 * send to THEORY_BUILTIN, meaning that shared terms database should
98 * maintain this fact. This is the case when either an equality is
99 * asserted from the SAT solver or a theory propagates an equality between
102 virtual void assertSharedEquality(TNode equality
,
105 /** Is term t a shared term? */
106 virtual bool isShared(TNode t
) const;
109 * Method called by equalityEngine when a becomes (dis-)equal to b and a and b
110 * are shared with the theory. Returns false if there is a direct conflict
111 * (via rewrite for example).
113 bool propagateSharedEquality(theory::TheoryId theory
,
117 /** Send lemma to the theory engine, atomsTo is the theory to send atoms to */
118 void sendLemma(TrustNode trn
, TheoryId atomsTo
);
121 /** Solver-specific pre-register shared */
122 virtual void preRegisterSharedInternal(TNode t
) = 0;
123 /** Reference to the theory engine */
125 /** Logic info of theory engine (cached) */
126 const LogicInfo
& d_logicInfo
;
127 /** The database of shared terms.*/
128 SharedTermsDatabase d_sharedTerms
;
129 /** Default visitor for pre-registration */
130 PreRegisterVisitor d_preRegistrationVisitor
;
131 /** Visitor for collecting shared terms */
132 SharedTermsVisitor d_sharedTermsVisitor
;
135 } // namespace theory
138 #endif /* CVC4__THEORY__SHARED_SOLVER__H */