Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/StmtIterator.h
Line
Count
Source (jump to first uncovered line)
1
//===- StmtIterator.h - Iterators for Statements ----------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file defines the StmtIterator and ConstStmtIterator classes.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_AST_STMTITERATOR_H
14
#define LLVM_CLANG_AST_STMTITERATOR_H
15
16
#include <cassert>
17
#include <cstddef>
18
#include <cstdint>
19
#include <iterator>
20
21
namespace clang {
22
23
class Decl;
24
class Stmt;
25
class VariableArrayType;
26
27
class StmtIteratorBase {
28
protected:
29
  enum {
30
    StmtMode = 0x0,
31
    SizeOfTypeVAMode = 0x1,
32
    DeclGroupMode = 0x2,
33
    Flags = 0x3
34
  };
35
36
  union {
37
    Stmt **stmt;
38
    Decl **DGI;
39
  };
40
  uintptr_t RawVAPtr = 0;
41
  Decl **DGE;
42
43
103M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
44
  StmtIteratorBase(const VariableArrayType *t);
45
  StmtIteratorBase(Decl **dgi, Decl **dge);
46
89.3M
  StmtIteratorBase() : stmt(nullptr) {}
47
48
1.00M
  bool inDeclGroup() const {
49
1.00M
    return (RawVAPtr & Flags) == DeclGroupMode;
50
1.00M
  }
51
52
65
  bool inSizeOfTypeVA() const {
53
65
    return (RawVAPtr & Flags) == SizeOfTypeVAMode;
54
65
  }
55
56
148M
  bool inStmt() const {
57
148M
    return (RawVAPtr & Flags) == StmtMode;
58
148M
  }
59
60
1.23M
  const VariableArrayType *getVAPtr() const {
61
1.23M
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
62
1.23M
  }
63
64
8.75k
  void setVAPtr(const VariableArrayType *P) {
65
8.75k
    assert(inDeclGroup() || inSizeOfTypeVA());
66
0
    RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
67
8.75k
  }
68
69
  void NextDecl(bool ImmediateAdvance = true);
70
  bool HandleDecl(Decl* D);
71
  void NextVA();
72
73
  Stmt*& GetDeclExpr() const;
74
};
75
76
template <typename DERIVED, typename REFERENCE>
77
class StmtIteratorImpl : public StmtIteratorBase {
78
protected:
79
109M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
678k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
108M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
80
81
public:
82
  using iterator_category = std::forward_iterator_tag;
83
  using value_type = REFERENCE;
84
  using difference_type = std::ptrdiff_t;
85
  using pointer = REFERENCE;
86
  using reference = REFERENCE;
87
88
89.3M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
88
270k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
88
89.0M
  StmtIteratorImpl() = default;
89
103M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
103M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
410k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
90
536k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
91
28
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
92
93
73.9M
  DERIVED& operator++() {
94
73.9M
    if (inStmt())
95
73.7M
      ++stmt;
96
230k
    else if (getVAPtr())
97
5.32k
      NextVA();
98
225k
    else
99
225k
      NextDecl();
100
101
73.9M
    return static_cast<DERIVED&>(*this);
102
73.9M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
93
44.2M
  DERIVED& operator++() {
94
44.2M
    if (inStmt())
95
44.2M
      ++stmt;
96
51.0k
    else if (getVAPtr())
97
1.85k
      NextVA();
98
49.2k
    else
99
49.2k
      NextDecl();
100
101
44.2M
    return static_cast<DERIVED&>(*this);
102
44.2M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
93
29.7M
  DERIVED& operator++() {
94
29.7M
    if (inStmt())
95
29.5M
      ++stmt;
96
179k
    else if (getVAPtr())
97
3.46k
      NextVA();
98
176k
    else
99
176k
      NextDecl();
100
101
29.7M
    return static_cast<DERIVED&>(*this);
102
29.7M
  }
103
104
2.61k
  DERIVED operator++(int) {
105
2.61k
    DERIVED tmp = static_cast<DERIVED&>(*this);
106
2.61k
    operator++();
107
2.61k
    return tmp;
108
2.61k
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++(int)
Line
Count
Source
104
2.61k
  DERIVED operator++(int) {
105
2.61k
    DERIVED tmp = static_cast<DERIVED&>(*this);
106
2.61k
    operator++();
107
2.61k
    return tmp;
108
2.61k
  }
Unexecuted instantiation: clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++(int)
109
110
171M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
171M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI96.7M
&&
112
171M
           
LHS.RawVAPtr == RHS.RawVAPtr96.7M
;
113
171M
  }
clang::operator==(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
110
72.2M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
72.2M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI42.5M
&&
112
72.2M
           
LHS.RawVAPtr == RHS.RawVAPtr42.5M
;
113
72.2M
  }
clang::operator==(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
110
99.6M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
99.6M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI54.2M
&&
112
99.6M
           
LHS.RawVAPtr == RHS.RawVAPtr54.2M
;
113
99.6M
  }
114
115
170M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
170M
    return !(LHS == RHS);
117
170M
  }
clang::operator!=(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
115
72.2M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
72.2M
    return !(LHS == RHS);
117
72.2M
  }
clang::operator!=(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
115
98.5M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
98.5M
    return !(LHS == RHS);
117
98.5M
  }
118
119
74.0M
  REFERENCE operator*() const {
120
74.0M
    return inStmt() ? 
*stmt73.7M
:
GetDeclExpr()230k
;
121
74.0M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
119
29.7M
  REFERENCE operator*() const {
120
29.7M
    return inStmt() ? 
*stmt29.5M
:
GetDeclExpr()179k
;
121
29.7M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
119
44.2M
  REFERENCE operator*() const {
120
44.2M
    return inStmt() ? 
*stmt44.2M
:
GetDeclExpr()51.0k
;
121
44.2M
  }
122
123
  REFERENCE operator->() const { return operator*(); }
124
};
125
126
struct ConstStmtIterator;
127
128
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
129
89.0M
  explicit StmtIterator() = default;
130
103M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
131
  StmtIterator(Decl** dgi, Decl** dge)
132
536k
      : StmtIteratorImpl<StmtIterator, Stmt*&>(dgi, dge) {}
133
  StmtIterator(const VariableArrayType *t)
134
28
      : StmtIteratorImpl<StmtIterator, Stmt*&>(t) {}
135
136
private:
137
  StmtIterator(const StmtIteratorBase &RHS)
138
678k
      : StmtIteratorImpl<StmtIterator, Stmt *&>(RHS) {}
139
140
  inline friend StmtIterator
141
  cast_away_const(const ConstStmtIterator &RHS);
142
};
143
144
struct ConstStmtIterator : public StmtIteratorImpl<ConstStmtIterator,
145
                                                   const Stmt*> {
146
270k
  explicit ConstStmtIterator() = default;
147
  ConstStmtIterator(const StmtIterator& RHS)
148
108M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
149
150
  ConstStmtIterator(Stmt * const *S)
151
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
152
410k
            const_cast<Stmt **>(S)) {}
153
};
154
155
678k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
156
678k
  return RHS;
157
678k
}
158
159
} // namespace clang
160
161
#endif // LLVM_CLANG_AST_STMTITERATOR_H