LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory - atom_requests.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 10 100.0 %
Date: 2026-03-21 10:41:10 Functions: 6 6 100.0 %
Branches: 3 4 75.0 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  * [[ Add one-line brief description here ]]
      11                 :            :  *
      12                 :            :  * [[ Add lengthier description here ]]
      13                 :            :  * \todo document this file
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "cvc5_private.h"
      17                 :            : 
      18                 :            : #pragma once
      19                 :            : 
      20                 :            : #include "expr/node.h"
      21                 :            : #include "theory/theory_id.h"
      22                 :            : #include "context/cdlist.h"
      23                 :            : #include "context/cdhashset.h"
      24                 :            : #include "context/cdhashmap.h"
      25                 :            : 
      26                 :            : namespace cvc5::internal {
      27                 :            : 
      28                 :            : class AtomRequests {
      29                 :            : 
      30                 :            : public:
      31                 :            : 
      32                 :            :   /** Which atom and where to send it */
      33                 :            :   struct Request {
      34                 :            :     /** Atom */
      35                 :            :     Node d_atom;
      36                 :            :     /** Where to send it */
      37                 :            :     theory::TheoryId d_toTheory;
      38                 :            : 
      39                 :      12636 :     Request(TNode a, theory::TheoryId tt) : d_atom(a), d_toTheory(tt) {}
      40                 :            :     Request() : d_toTheory(theory::THEORY_LAST) {}
      41                 :            : 
      42                 :      15087 :     bool operator == (const Request& other) const {
      43 [ +  - ][ +  + ]:      15087 :       return d_atom == other.d_atom && d_toTheory == other.d_toTheory;
      44                 :            :     }
      45                 :            : 
      46                 :      63166 :     size_t hash() const { return d_atom.getId(); }
      47                 :            :   };
      48                 :            : 
      49                 :            :   AtomRequests(context::Context* context);
      50                 :            : 
      51                 :            :   /** Mark the atom to be sent to a theory, when the trigger atom gets assigned */
      52                 :            :   void add(TNode triggerAtom, TNode atomToSend, theory::TheoryId toTheory);
      53                 :            : 
      54                 :            :   /** Returns true if the node is a trigger and has a list of atoms to send */
      55                 :            :   bool isTrigger(TNode atom) const;
      56                 :            : 
      57                 :            :   /** Indices in lists */
      58                 :            :   typedef size_t element_index;
      59                 :            : 
      60                 :            :   class atom_iterator {
      61                 :            :     const AtomRequests& d_requests;
      62                 :            :     element_index d_index;
      63                 :            :     friend class AtomRequests;
      64                 :    9165720 :     atom_iterator(const AtomRequests& requests, element_index start)
      65                 :    9165720 :         : d_requests(requests), d_index(start)
      66                 :            :     {
      67                 :    9165720 :     }
      68                 :            : 
      69                 :            :   public:
      70                 :            :     /** Is this iterator done  */
      71                 :            :     bool done() const;
      72                 :            :     /** Go to the next element */
      73                 :            :     void next();
      74                 :            :     /** Get the actual request */
      75                 :            :     const Request& get() const;
      76                 :            :   };
      77                 :            : 
      78                 :            :   atom_iterator getAtomIterator(TNode trigger) const;
      79                 :            : 
      80                 :            : private:
      81                 :            : 
      82                 :            :   struct RequestHashFunction {
      83                 :      63166 :     size_t operator () (const Request& r) const {
      84                 :      63166 :       return r.hash();
      85                 :            :     }
      86                 :            :   };
      87                 :            : 
      88                 :            :   /** Set of all requests so we don't add twice */
      89                 :            :   context::CDHashSet<Request, RequestHashFunction> d_allRequests;
      90                 :            : 
      91                 :            :   static const element_index null_index = -1;
      92                 :            : 
      93                 :            :   struct Element {
      94                 :            :     /** Current request */
      95                 :            :     Request d_request;
      96                 :            :     /** Previous request */
      97                 :            :     element_index d_previous;
      98                 :            : 
      99                 :      12636 :     Element(const Request& r, element_index p) : d_request(r), d_previous(p) {}
     100                 :            :   };
     101                 :            : 
     102                 :            :   /** We index the requests in this vector, it's a list */
     103                 :            :   context::CDList<Element> d_requests;
     104                 :            : 
     105                 :            :   typedef context::CDHashMap<Node, element_index> trigger_to_list_map;
     106                 :            : 
     107                 :            :   /** Map from triggers, to the list of elements they trigger */
     108                 :            :   trigger_to_list_map d_triggerToRequestMap;
     109                 :            : 
     110                 :            :   /** Get the list index of the trigger */
     111                 :            :   element_index getList(TNode trigger) const;
     112                 :            : 
     113                 :            : };
     114                 :            : 
     115                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14