GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/node_self_iterator.h Lines: 40 43 93.0 %
Date: 2021-03-22 Branches: 23 94 24.5 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file node_self_iterator.h
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Morgan Deters, Mathias Preiner, Andres Noetzli
6
 ** This file is part of the CVC4 project.
7
 ** Copyright (c) 2009-2021 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
11
 **
12
 ** \brief Iterator supporting Node "self-iteration"
13
 **
14
 ** Iterator supporting Node "self-iteration."
15
 **/
16
17
#include "cvc4_private.h"
18
19
#ifndef CVC4__EXPR__NODE_SELF_ITERATOR_H
20
#define CVC4__EXPR__NODE_SELF_ITERATOR_H
21
22
#include <iterator>
23
24
#include "base/check.h"
25
#include "expr/node.h"
26
27
namespace CVC4 {
28
namespace expr {
29
30
4133664033
class NodeSelfIterator : public std::iterator<std::input_iterator_tag, Node> {
31
  Node d_node;
32
  Node::const_iterator d_child;
33
34
public:
35
  static NodeSelfIterator self(TNode n);
36
  static NodeSelfIterator selfEnd(TNode n);
37
38
  NodeSelfIterator();
39
  NodeSelfIterator(Node n);
40
  NodeSelfIterator(TNode n);
41
  NodeSelfIterator(const NodeSelfIterator& i);
42
43
  NodeSelfIterator(Node::const_iterator i);
44
  NodeSelfIterator(TNode::const_iterator i);
45
46
  Node operator*() const;
47
  NodeSelfIterator& operator++();
48
  NodeSelfIterator operator++(int);
49
50
  bool operator==(NodeSelfIterator i) const;
51
  bool operator!=(NodeSelfIterator i) const;
52
53
};/* class NodeSelfIterator */
54
55
254717437
inline NodeSelfIterator NodeSelfIterator::self(TNode n) {
56
254717437
  Assert(!n.isNull()) << "Self-iteration over null nodes not permitted.";
57
254717437
  return NodeSelfIterator(n);
58
}
59
60
227157514
inline NodeSelfIterator NodeSelfIterator::selfEnd(TNode n) {
61
227157514
  Assert(!n.isNull()) << "Self-iteration over null nodes not permitted.";
62
227157514
  return NodeSelfIterator(n.end());
63
}
64
65
inline NodeSelfIterator::NodeSelfIterator() :
66
  d_node(),
67
  d_child() {
68
}
69
70
2
inline NodeSelfIterator::NodeSelfIterator(Node node) :
71
  d_node(node),
72
2
  d_child() {
73
2
  Assert(!node.isNull()) << "Self-iteration over null nodes not permitted.";
74
2
}
75
76
254717437
inline NodeSelfIterator::NodeSelfIterator(TNode node) :
77
  d_node(node),
78
254717437
  d_child() {
79
254717437
  Assert(!node.isNull()) << "Self-iteration over null nodes not permitted.";
80
254717437
}
81
82
3529573672
inline NodeSelfIterator::NodeSelfIterator(const NodeSelfIterator& i) :
83
  d_node(i.d_node),
84
3529573672
  d_child(i.d_child) {
85
3529573672
}
86
87
109946396
inline NodeSelfIterator::NodeSelfIterator(Node::const_iterator i) :
88
  d_node(),
89
109946396
  d_child(i) {
90
109946396
}
91
92
227157514
inline NodeSelfIterator::NodeSelfIterator(TNode::const_iterator i) :
93
  d_node(),
94
227157514
  d_child(i) {
95
227157514
}
96
97
220761804
inline Node NodeSelfIterator::operator*() const {
98
220761804
  return d_node.isNull() ? *d_child : d_node;
99
}
100
101
291768999
inline NodeSelfIterator& NodeSelfIterator::operator++() {
102
291768999
  if(d_node.isNull()) {
103
76410218
    ++d_child;
104
  } else {
105
215358781
    d_child = d_node.end();
106
215358781
    d_node = Node::null();
107
  }
108
291768999
  return *this;
109
}
110
111
4
inline NodeSelfIterator NodeSelfIterator::operator++(int) {
112
4
  NodeSelfIterator i = *this;
113
4
  ++*this;
114
4
  return i;
115
}
116
117
733331231
inline bool NodeSelfIterator::operator==(NodeSelfIterator i) const {
118
733331231
  return d_node == i.d_node && d_child == i.d_child;
119
}
120
121
411527982
inline bool NodeSelfIterator::operator!=(NodeSelfIterator i) const {
122
411527982
  return !(*this == i);
123
}
124
125
}/* CVC4::expr namespace */
126
}/* CVC4 namespace */
127
128
#endif /* CVC4__EXPR__NODE_SELF_ITERATOR_H */