Coverage Report

Created: 2022-07-16 07:03

/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
114M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
44
  StmtIteratorBase(const VariableArrayType *t);
45
  StmtIteratorBase(Decl **dgi, Decl **dge);
46
99.4M
  StmtIteratorBase() : stmt(nullptr) {}
47
48
1.08M
  bool inDeclGroup() const {
49
1.08M
    return (RawVAPtr & Flags) == DeclGroupMode;
50
1.08M
  }
51
52
65
  bool inSizeOfTypeVA() const {
53
65
    return (RawVAPtr & Flags) == SizeOfTypeVAMode;
54
65
  }
55
56
163M
  bool inStmt() const {
57
163M
    return (RawVAPtr & Flags) == StmtMode;
58
163M
  }
59
60
1.33M
  const VariableArrayType *getVAPtr() const {
61
1.33M
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
62
1.33M
  }
63
64
8.76k
  void setVAPtr(const VariableArrayType *P) {
65
8.76k
    assert(inDeclGroup() || inSizeOfTypeVA());
66
0
    RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
67
8.76k
  }
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
121M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
805k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
121M
  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
99.4M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
88
373k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
88
99.0M
  StmtIteratorImpl() = default;
89
114M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
114M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
434k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
90
577k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
91
28
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
92
93
82.1M
  DERIVED& operator++() {
94
82.1M
    if (inStmt())
95
81.9M
      ++stmt;
96
249k
    else if (getVAPtr())
97
5.33k
      NextVA();
98
244k
    else
99
244k
      NextDecl();
100
101
82.1M
    return static_cast<DERIVED&>(*this);
102
82.1M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
93
48.8M
  DERIVED& operator++() {
94
48.8M
    if (inStmt())
95
48.8M
      ++stmt;
96
55.8k
    else if (getVAPtr())
97
1.86k
      NextVA();
98
53.9k
    else
99
53.9k
      NextDecl();
100
101
48.8M
    return static_cast<DERIVED&>(*this);
102
48.8M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
93
33.2M
  DERIVED& operator++() {
94
33.2M
    if (inStmt())
95
33.0M
      ++stmt;
96
193k
    else if (getVAPtr())
97
3.46k
      NextVA();
98
190k
    else
99
190k
      NextDecl();
100
101
33.2M
    return static_cast<DERIVED&>(*this);
102
33.2M
  }
103
104
2.67k
  DERIVED operator++(int) {
105
2.67k
    DERIVED tmp = static_cast<DERIVED&>(*this);
106
2.67k
    operator++();
107
2.67k
    return tmp;
108
2.67k
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++(int)
Line
Count
Source
104
2.67k
  DERIVED operator++(int) {
105
2.67k
    DERIVED tmp = static_cast<DERIVED&>(*this);
106
2.67k
    operator++();
107
2.67k
    return tmp;
108
2.67k
  }
Unexecuted instantiation: clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++(int)
109
110
193M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
193M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI109M
&&
112
193M
           
LHS.RawVAPtr == RHS.RawVAPtr109M
;
113
193M
  }
clang::operator==(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
110
82.0M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
82.0M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI48.7M
&&
112
82.0M
           
LHS.RawVAPtr == RHS.RawVAPtr48.7M
;
113
82.0M
  }
clang::operator==(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
110
111M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
111M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI60.5M
&&
112
111M
           
LHS.RawVAPtr == RHS.RawVAPtr60.5M
;
113
111M
  }
114
115
191M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
191M
    return !(LHS == RHS);
117
191M
  }
clang::operator!=(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
115
81.9M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
81.9M
    return !(LHS == RHS);
117
81.9M
  }
clang::operator!=(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
115
109M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
109M
    return !(LHS == RHS);
117
109M
  }
118
119
81.8M
  REFERENCE operator*() const {
120
81.8M
    return inStmt() ? 
*stmt81.5M
:
GetDeclExpr()249k
;
121
81.8M
  }
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()193k
;
121
32.8M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
119
48.9M
  REFERENCE operator*() const {
120
48.9M
    return inStmt() ? 
*stmt48.8M
:
GetDeclExpr()55.8k
;
121
48.9M
  }
122
123
  REFERENCE operator->() const { return operator*(); }
124
};
125
126
struct ConstStmtIterator;
127
128
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
129
99.0M
  explicit StmtIterator() = default;
130
114M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
131
  StmtIterator(Decl** dgi, Decl** dge)
132
577k
      : 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
805k
      : 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
373k
  explicit ConstStmtIterator() = default;
147
  ConstStmtIterator(const StmtIterator& RHS)
148
121M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
149
150
  ConstStmtIterator(Stmt * const *S)
151
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
152
434k
            const_cast<Stmt **>(S)) {}
153
};
154
155
805k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
156
805k
  return RHS;
157
805k
}
158
159
} // namespace clang
160
161
#endif // LLVM_CLANG_AST_STMTITERATOR_H