LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/expr - node_self_iterator.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 36 97.2 %
Date: 2026-04-23 10:47:37 Functions: 12 12 100.0 %
Branches: 16 32 50.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                 :            :  * Iterator supporting Node "self-iteration."
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "cvc5_private.h"
      14                 :            : 
      15                 :            : #ifndef CVC5__EXPR__NODE_SELF_ITERATOR_H
      16                 :            : #define CVC5__EXPR__NODE_SELF_ITERATOR_H
      17                 :            : 
      18                 :            : #include <iterator>
      19                 :            : 
      20                 :            : #include "base/check.h"
      21                 :            : #include "expr/node.h"
      22                 :            : 
      23                 :            : namespace cvc5::internal {
      24                 :            : namespace expr {
      25                 :            : 
      26                 :            : class NodeSelfIterator
      27                 :            : {
      28                 :            :   Node d_node;
      29                 :            :   Node::const_iterator d_child;
      30                 :            : 
      31                 :            :  public:
      32                 :            :   /* The following types are required by trait std::iterator_traits */
      33                 :            : 
      34                 :            :   /** Iterator tag */
      35                 :            :   using iterator_category = std::forward_iterator_tag;
      36                 :            : 
      37                 :            :   /** The type of the item */
      38                 :            :   using value_type = Node;
      39                 :            : 
      40                 :            :   /** The pointer type of the item */
      41                 :            :   using pointer = Node*;
      42                 :            : 
      43                 :            :   /** The reference type of the item */
      44                 :            :   using reference = Node&;
      45                 :            : 
      46                 :            :   /** The type returned when two iterators are subtracted */
      47                 :            :   using difference_type = std::ptrdiff_t;
      48                 :            : 
      49                 :            :   /* End of std::iterator_traits required types */
      50                 :            : 
      51                 :            :   static NodeSelfIterator self(TNode n);
      52                 :            :   static NodeSelfIterator selfEnd(TNode n);
      53                 :            : 
      54                 :            :   NodeSelfIterator();
      55                 :            :   NodeSelfIterator(Node n);
      56                 :            :   NodeSelfIterator(TNode n);
      57                 :            : 
      58                 :            :   NodeSelfIterator(Node::const_iterator i);
      59                 :            :   NodeSelfIterator(TNode::const_iterator i);
      60                 :            : 
      61                 :            :   Node operator*() const;
      62                 :            :   NodeSelfIterator& operator++();
      63                 :            :   NodeSelfIterator operator++(int);
      64                 :            : 
      65                 :            :   bool operator==(NodeSelfIterator i) const;
      66                 :            :   bool operator!=(NodeSelfIterator i) const;
      67                 :            : 
      68                 :            : }; /* class NodeSelfIterator */
      69                 :            : 
      70                 :  301906442 : inline NodeSelfIterator NodeSelfIterator::self(TNode n)
      71                 :            : {
      72 [ -  + ][ -  + ]:  301906442 :   Assert(!n.isNull()) << "Self-iteration over null nodes not permitted.";
                 [ -  - ]
      73                 :  301906442 :   return NodeSelfIterator(n);
      74                 :            : }
      75                 :            : 
      76                 :  273223966 : inline NodeSelfIterator NodeSelfIterator::selfEnd(TNode n)
      77                 :            : {
      78 [ -  + ][ -  + ]:  273223966 :   Assert(!n.isNull()) << "Self-iteration over null nodes not permitted.";
                 [ -  - ]
      79                 :  273223966 :   return NodeSelfIterator(n.end());
      80                 :            : }
      81                 :            : 
      82                 :         56 : inline NodeSelfIterator::NodeSelfIterator() : d_node(), d_child() {}
      83                 :            : 
      84                 :          1 : inline NodeSelfIterator::NodeSelfIterator(Node node) : d_node(node), d_child()
      85                 :            : {
      86 [ -  + ][ -  + ]:          1 :   Assert(!node.isNull()) << "Self-iteration over null nodes not permitted.";
                 [ -  - ]
      87                 :          1 : }
      88                 :            : 
      89                 :  301906442 : inline NodeSelfIterator::NodeSelfIterator(TNode node) : d_node(node), d_child()
      90                 :            : {
      91 [ -  + ][ -  + ]:  301906442 :   Assert(!node.isNull()) << "Self-iteration over null nodes not permitted.";
                 [ -  - ]
      92                 :  301906442 : }
      93                 :            : 
      94                 :   73939608 : inline NodeSelfIterator::NodeSelfIterator(Node::const_iterator i)
      95                 :   73939608 :     : d_node(), d_child(i)
      96                 :            : {
      97                 :   73939608 : }
      98                 :            : 
      99                 :  273224022 : inline NodeSelfIterator::NodeSelfIterator(TNode::const_iterator i)
     100                 :  273224022 :     : d_node(), d_child(i)
     101                 :            : {
     102                 :  273224022 : }
     103                 :            : 
     104                 :  197071294 : inline Node NodeSelfIterator::operator*() const
     105                 :            : {
     106         [ +  + ]:  197071294 :   return d_node.isNull() ? *d_child : d_node;
     107                 :            : }
     108                 :            : 
     109                 :  309427929 : inline NodeSelfIterator& NodeSelfIterator::operator++()
     110                 :            : {
     111         [ +  + ]:  309427929 :   if (d_node.isNull())
     112                 :            :   {
     113                 :   47359236 :     ++d_child;
     114                 :            :   }
     115                 :            :   else
     116                 :            :   {
     117                 :  262068693 :     d_child = d_node.end();
     118                 :  262068693 :     d_node = Node::null();
     119                 :            :   }
     120                 :  309427929 :   return *this;
     121                 :            : }
     122                 :            : 
     123                 :          2 : inline NodeSelfIterator NodeSelfIterator::operator++(int)
     124                 :            : {
     125                 :          2 :   NodeSelfIterator i = *this;
     126                 :          2 :   ++*this;
     127                 :          2 :   return i;
     128                 :          0 : }
     129                 :            : 
     130                 :  828592425 : inline bool NodeSelfIterator::operator==(NodeSelfIterator i) const
     131                 :            : {
     132 [ +  + ][ +  + ]:  828592425 :   return d_node == i.d_node && d_child == i.d_child;
     133                 :            : }
     134                 :            : 
     135                 :  436444348 : inline bool NodeSelfIterator::operator!=(NodeSelfIterator i) const
     136                 :            : {
     137                 :  436444348 :   return !(*this == i);
     138                 :            : }
     139                 :            : 
     140                 :            : }  // namespace expr
     141                 :            : }  // namespace cvc5::internal
     142                 :            : 
     143                 :            : #endif /* CVC5__EXPR__NODE_SELF_ITERATOR_H */

Generated by: LCOV version 1.14