Coverage Report

Created: 2021-09-21 08:58

/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
110M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
44
  StmtIteratorBase(const VariableArrayType *t);
45
  StmtIteratorBase(Decl **dgi, Decl **dge);
46
91.8M
  StmtIteratorBase() : stmt(nullptr) {}
47
48
1.30M
  bool inDeclGroup() const {
49
1.30M
    return (RawVAPtr & Flags) == DeclGroupMode;
50
1.30M
  }
51
52
65
  bool inSizeOfTypeVA() const {
53
65
    return (RawVAPtr & Flags) == SizeOfTypeVAMode;
54
65
  }
55
56
158M
  bool inStmt() const {
57
158M
    return (RawVAPtr & Flags) == StmtMode;
58
158M
  }
59
60
1.60M
  const VariableArrayType *getVAPtr() const {
61
1.60M
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
62
1.60M
  }
63
64
9.13k
  void setVAPtr(const VariableArrayType *P) {
65
9.13k
    assert(inDeclGroup() || inSizeOfTypeVA());
66
0
    RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
67
9.13k
  }
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
113M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
751k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
112M
  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
91.8M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
88
253k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
88
91.6M
  StmtIteratorImpl() = default;
89
110M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
110M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
500k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
90
700k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
91
28
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
92
93
79.3M
  DERIVED& operator++() {
94
79.3M
    if (inStmt())
95
79.0M
      ++stmt;
96
299k
    else if (getVAPtr())
97
5.55k
      NextVA();
98
293k
    else
99
293k
      NextDecl();
100
101
79.3M
    return static_cast<DERIVED&>(*this);
102
79.3M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
93
46.4M
  DERIVED& operator++() {
94
46.4M
    if (inStmt())
95
46.3M
      ++stmt;
96
55.1k
    else if (getVAPtr())
97
1.85k
      NextVA();
98
53.2k
    else
99
53.2k
      NextDecl();
100
101
46.4M
    return static_cast<DERIVED&>(*this);
102
46.4M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
93
32.9M
  DERIVED& operator++() {
94
32.9M
    if (inStmt())
95
32.6M
      ++stmt;
96
244k
    else if (getVAPtr())
97
3.70k
      NextVA();
98
240k
    else
99
240k
      NextDecl();
100
101
32.9M
    return static_cast<DERIVED&>(*this);
102
32.9M
  }
103
104
2.56k
  DERIVED operator++(int) {
105
2.56k
    DERIVED tmp = static_cast<DERIVED&>(*this);
106
2.56k
    operator++();
107
2.56k
    return tmp;
108
2.56k
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++(int)
Line
Count
Source
104
2.56k
  DERIVED operator++(int) {
105
2.56k
    DERIVED tmp = static_cast<DERIVED&>(*this);
106
2.56k
    operator++();
107
2.56k
    return tmp;
108
2.56k
  }
Unexecuted instantiation: clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++(int)
109
110
182M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
182M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI101M
&&
112
182M
           
LHS.RawVAPtr == RHS.RawVAPtr101M
;
113
182M
  }
clang::operator==(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
110
78.4M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
78.4M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI45.5M
&&
112
78.4M
           
LHS.RawVAPtr == RHS.RawVAPtr45.5M
;
113
78.4M
  }
clang::operator==(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
110
103M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
103M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI56.1M
&&
112
103M
           
LHS.RawVAPtr == RHS.RawVAPtr56.1M
;
113
103M
  }
114
115
180M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
180M
    return !(LHS == RHS);
117
180M
  }
clang::operator!=(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
115
78.3M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
78.3M
    return !(LHS == RHS);
117
78.3M
  }
clang::operator!=(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
115
102M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
102M
    return !(LHS == RHS);
117
102M
  }
118
119
79.3M
  REFERENCE operator*() const {
120
79.3M
    return inStmt() ? 
*stmt79.0M
:
GetDeclExpr()299k
;
121
79.3M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
119
32.8M
  REFERENCE operator*() const {
120
32.8M
    return inStmt() ? 
*stmt32.6M
:
GetDeclExpr()244k
;
121
32.8M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
119
46.4M
  REFERENCE operator*() const {
120
46.4M
    return inStmt() ? 
*stmt46.3M
:
GetDeclExpr()55.1k
;
121
46.4M
  }
122
123
  REFERENCE operator->() const { return operator*(); }
124
};
125
126
struct ConstStmtIterator;
127
128
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
129
91.6M
  explicit StmtIterator() = default;
130
110M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
131
  StmtIterator(Decl** dgi, Decl** dge)
132
700k
      : 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
751k
      : 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
253k
  explicit ConstStmtIterator() = default;
147
  ConstStmtIterator(const StmtIterator& RHS)
148
112M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
149
150
  ConstStmtIterator(Stmt * const *S)
151
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
152
500k
            const_cast<Stmt **>(S)) {}
153
};
154
155
751k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
156
751k
  return RHS;
157
751k
}
158
159
} // namespace clang
160
161
#endif // LLVM_CLANG_AST_STMTITERATOR_H