LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory - theory_state.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 5 100.0 %
Date: 2026-02-13 11:44:11 Functions: 4 5 80.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Andrew Reynolds, Dejan Jovanovic, Morgan Deters
       4                 :            :  *
       5                 :            :  * This file is part of the cvc5 project.
       6                 :            :  *
       7                 :            :  * Copyright (c) 2009-2025 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                 :            :  * A theory state for Theory.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "cvc5_private.h"
      17                 :            : 
      18                 :            : #ifndef CVC5__THEORY__THEORY_STATE_H
      19                 :            : #define CVC5__THEORY__THEORY_STATE_H
      20                 :            : 
      21                 :            : #include "context/cdo.h"
      22                 :            : #include "expr/node.h"
      23                 :            : #include "smt/env.h"
      24                 :            : #include "smt/env_obj.h"
      25                 :            : #include "theory/valuation.h"
      26                 :            : 
      27                 :            : namespace cvc5::internal {
      28                 :            : namespace theory {
      29                 :            : 
      30                 :            : namespace eq {
      31                 :            : class EqualityEngine;
      32                 :            : }
      33                 :            : 
      34                 :            : class TheoryState : protected EnvObj
      35                 :            : {
      36                 :            :  public:
      37                 :            :   TheoryState(Env& env,
      38                 :            :               Valuation val);
      39                 :     644275 :   virtual ~TheoryState() {}
      40                 :            :   /**
      41                 :            :    * Set equality engine, where ee is a pointer to the official equality engine
      42                 :            :    * of theory.
      43                 :            :    */
      44                 :            :   void setEqualityEngine(eq::EqualityEngine* ee);
      45                 :            :   //-------------------------------------- equality information
      46                 :            :   /** Is t registered as a term in the equality engine of this class? */
      47                 :            :   virtual bool hasTerm(TNode t) const;
      48                 :            :   /** Add term t to the equality engine if it is not registered */
      49                 :            :   virtual void addTerm(TNode t);
      50                 :            :   /**
      51                 :            :    * Get the representative of t in the equality engine of this class, or t
      52                 :            :    * itself if it is not registered as a term.
      53                 :            :    */
      54                 :            :   virtual TNode getRepresentative(TNode t) const;
      55                 :            :   /**
      56                 :            :    * Are a and b equal according to the equality engine of this class? Also
      57                 :            :    * returns true if a and b are identical.
      58                 :            :    */
      59                 :            :   virtual bool areEqual(TNode a, TNode b) const;
      60                 :            :   /**
      61                 :            :    * Are a and b disequal according to the equality engine of this class? Also
      62                 :            :    * returns true if the representative of a and b are distinct constants.
      63                 :            :    */
      64                 :            :   virtual bool areDisequal(TNode a, TNode b) const;
      65                 :            :   /**
      66                 :            :    * Get the explanation for why a and b are disequal, store it in exp. This
      67                 :            :    * assumes that areDisequal(a,b) returns true in the current context and
      68                 :            :    * ensures the equality engine has a proof of what it is in exp.
      69                 :            :    */
      70                 :            :   void explainDisequal(TNode a, TNode b, std::vector<Node>& exp);
      71                 :            :   /** get list of members in the equivalence class of a */
      72                 :            :   virtual void getEquivalenceClass(Node a, std::vector<Node>& eqc) const;
      73                 :            :   /**
      74                 :            :    * Add pred as a trigger predicate to the equality engine of the theory
      75                 :            :    * that owns this state. If the option prereg-check-sat-assert is true,
      76                 :            :    * this first checks whether pred has already been asserted. If so, then
      77                 :            :    * the trigger is not added. In this care, pred is added as a non-trigger
      78                 :            :    * term to the equality engine instead.
      79                 :            :    */
      80                 :            :   void addEqualityEngineTriggerPredicate(TNode pred);
      81                 :            :   /** get equality engine */
      82                 :            :   eq::EqualityEngine* getEqualityEngine() const;
      83                 :            :   //-------------------------------------- end equality information
      84                 :            :   /**
      85                 :            :    * Set that the current state of the solver is in conflict. This should be
      86                 :            :    * called immediately after a call to conflict(...) on the output channel of
      87                 :            :    * the theory.
      88                 :            :    */
      89                 :            :   virtual void notifyInConflict();
      90                 :            :   /** Are we currently in conflict? */
      91                 :            :   virtual bool isInConflict() const;
      92                 :            : 
      93                 :            :   /** Returns true if lit is a SAT literal. */
      94                 :            :   virtual bool isSatLiteral(TNode lit) const;
      95                 :            :   /**
      96                 :            :    * Returns pointer to model. This model is only valid during last call effort
      97                 :            :    * check.
      98                 :            :    */
      99                 :            :   TheoryModel* getModel();
     100                 :            :   /**
     101                 :            :    * Returns a pointer to the sort inference module, which lives in TheoryEngine
     102                 :            :    * and is non-null when options::sortInference is true.
     103                 :            :    */
     104                 :            :   SortInference* getSortInference();
     105                 :            : 
     106                 :            :   /** Returns true if n has a current SAT assignment and stores it in value. */
     107                 :            :   virtual bool hasSatValue(TNode n, bool& value) const;
     108                 :            : 
     109                 :            :   //------------------------------------------- access methods for assertions
     110                 :            :   /**
     111                 :            :    * The following methods are intended only to be used in limited use cases,
     112                 :            :    * for cases where a theory (e.g. quantifiers) requires knowing about the
     113                 :            :    * assertions from other theories.
     114                 :            :    */
     115                 :            :   /** The beginning iterator of facts for theory tid.*/
     116                 :            :   context::CDList<Assertion>::const_iterator factsBegin(TheoryId tid);
     117                 :            :   /** The beginning iterator of facts for theory tid.*/
     118                 :            :   context::CDList<Assertion>::const_iterator factsEnd(TheoryId tid);
     119                 :            : 
     120                 :            :   /** Get the underlying valuation class */
     121                 :            :   Valuation& getValuation();
     122                 :            : 
     123                 :            :   //------------------------------------------- access methods for shared terms
     124                 :            :   /** Add shared term, called by Theory. */
     125                 :            :   void addSharedTerm(TNode node);
     126                 :            : 
     127                 :            :   using shared_terms_iterator = context::CDList<TNode>::const_iterator;
     128                 :            :   /**
     129                 :            :    * Provides access to the shared terms, primarily intended for theory
     130                 :            :    * debugging purposes.
     131                 :            :    *
     132                 :            :    * @return the iterator to the beginning of the shared terms list
     133                 :            :    */
     134                 :     743999 :   shared_terms_iterator shared_terms_begin() const
     135                 :            :   {
     136                 :     743999 :     return d_sharedTerms.begin();
     137                 :            :   }
     138                 :            : 
     139                 :            :   /**
     140                 :            :    * Provides access to the facts queue, primarily intended for theory
     141                 :            :    * debugging purposes.
     142                 :            :    *
     143                 :            :    * @return the iterator to the end of the shared terms list
     144                 :            :    */
     145                 :     743999 :   shared_terms_iterator shared_terms_end() const { return d_sharedTerms.end(); }
     146                 :            :   /** Get shared terms */
     147                 :     131763 :   const context::CDList<TNode>& getSharedTerms() const { return d_sharedTerms; }
     148                 :            : 
     149                 :            :  protected:
     150                 :            :   /**
     151                 :            :    * The valuation proxy for the Theory to communicate back with the
     152                 :            :    * theory engine (and other theories).
     153                 :            :    */
     154                 :            :   Valuation d_valuation;
     155                 :            :   /** Pointer to equality engine of the theory. */
     156                 :            :   eq::EqualityEngine* d_ee;
     157                 :            :   /** Are we in conflict? */
     158                 :            :   context::CDO<bool> d_conflict;
     159                 :            :   /**
     160                 :            :    * A list of shared terms that the theory has.
     161                 :            :    */
     162                 :            :   context::CDList<TNode> d_sharedTerms;
     163                 :            : };
     164                 :            : 
     165                 :            : }  // namespace theory
     166                 :            : }  // namespace cvc5::internal
     167                 :            : 
     168                 :            : #endif /* CVC5__THEORY__SOLVER_STATE_H */

Generated by: LCOV version 1.14