Coverage Report

Created: 2022-05-21 09:15

/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
106M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
44
  StmtIteratorBase(const VariableArrayType *t);
45
  StmtIteratorBase(Decl **dgi, Decl **dge);
46
90.2M
  StmtIteratorBase() : stmt(nullptr) {}
47
48
1.02M
  bool inDeclGroup() const {
49
1.02M
    return (RawVAPtr & Flags) == DeclGroupMode;
50
1.02M
  }
51
52
65
  bool inSizeOfTypeVA() const {
53
65
    return (RawVAPtr & Flags) == SizeOfTypeVAMode;
54
65
  }
55
56
151M
  bool inStmt() const {
57
151M
    return (RawVAPtr & Flags) == StmtMode;
58
151M
  }
59
60
1.26M
  const VariableArrayType *getVAPtr() const {
61
1.26M
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
62
1.26M
  }
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
111M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
662k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
110M
  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
90.2M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
88
243k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
88
89.9M
  StmtIteratorImpl() = default;
89
106M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
105M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
421k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
90
550k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
91
28
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
92
93
75.7M
  DERIVED& operator++() {
94
75.7M
    if (inStmt())
95
75.5M
      ++stmt;
96
236k
    else if (getVAPtr())
97
5.32k
      NextVA();
98
231k
    else
99
231k
      NextDecl();
100
101
75.7M
    return static_cast<DERIVED&>(*this);
102
75.7M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
93
45.1M
  DERIVED& operator++() {
94
45.1M
    if (inStmt())
95
45.1M
      ++stmt;
96
54.8k
    else if (getVAPtr())
97
1.85k
      NextVA();
98
52.9k
    else
99
52.9k
      NextDecl();
100
101
45.1M
    return static_cast<DERIVED&>(*this);
102
45.1M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
93
30.6M
  DERIVED& operator++() {
94
30.6M
    if (inStmt())
95
30.4M
      ++stmt;
96
181k
    else if (getVAPtr())
97
3.46k
      NextVA();
98
178k
    else
99
178k
      NextDecl();
100
101
30.6M
    return static_cast<DERIVED&>(*this);
102
30.6M
  }
103
104
2.59k
  DERIVED operator++(int) {
105
2.59k
    DERIVED tmp = static_cast<DERIVED&>(*this);
106
2.59k
    operator++();
107
2.59k
    return tmp;
108
2.59k
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++(int)
Line
Count
Source
104
2.59k
  DERIVED operator++(int) {
105
2.59k
    DERIVED tmp = static_cast<DERIVED&>(*this);
106
2.59k
    operator++();
107
2.59k
    return tmp;
108
2.59k
  }
Unexecuted instantiation: clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++(int)
109
110
177M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
177M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI100M
&&
112
177M
           
LHS.RawVAPtr == RHS.RawVAPtr100M
;
113
177M
  }
clang::operator==(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
110
75.5M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
75.5M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI44.9M
&&
112
75.5M
           
LHS.RawVAPtr == RHS.RawVAPtr44.9M
;
113
75.5M
  }
clang::operator==(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
110
101M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
101M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI55.1M
&&
112
101M
           
LHS.RawVAPtr == RHS.RawVAPtr55.1M
;
113
101M
  }
114
115
175M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
175M
    return !(LHS == RHS);
117
175M
  }
clang::operator!=(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
115
75.5M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
75.5M
    return !(LHS == RHS);
117
75.5M
  }
clang::operator!=(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
115
100M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
100M
    return !(LHS == RHS);
117
100M
  }
118
119
75.4M
  REFERENCE operator*() const {
120
75.4M
    return inStmt() ? 
*stmt75.1M
:
GetDeclExpr()236k
;
121
75.4M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
119
30.2M
  REFERENCE operator*() const {
120
30.2M
    return inStmt() ? 
*stmt30.0M
:
GetDeclExpr()181k
;
121
30.2M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
119
45.2M
  REFERENCE operator*() const {
120
45.2M
    return inStmt() ? 
*stmt45.1M
:
GetDeclExpr()54.8k
;
121
45.2M
  }
122
123
  REFERENCE operator->() const { return operator*(); }
124
};
125
126
struct ConstStmtIterator;
127
128
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
129
89.9M
  explicit StmtIterator() = default;
130
105M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
131
  StmtIterator(Decl** dgi, Decl** dge)
132
550k
      : 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
662k
      : 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
243k
  explicit ConstStmtIterator() = default;
147
  ConstStmtIterator(const StmtIterator& RHS)
148
110M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
149
150
  ConstStmtIterator(Stmt * const *S)
151
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
152
421k
            const_cast<Stmt **>(S)) {}
153
};
154
155
662k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
156
662k
  return RHS;
157
662k
}
158
159
} // namespace clang
160
161
#endif // LLVM_CLANG_AST_STMTITERATOR_H