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

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