Coverage Report

Created: 2021-06-15 06:44

/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
107M
  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.28M
  bool inDeclGroup() const {
49
1.28M
    return (RawVAPtr & Flags) == DeclGroupMode;
50
1.28M
  }
51
52
65
  bool inSizeOfTypeVA() const {
53
65
    return (RawVAPtr & Flags) == SizeOfTypeVAMode;
54
65
  }
55
56
154M
  bool inStmt() const {
57
154M
    return (RawVAPtr & Flags) == StmtMode;
58
154M
  }
59
60
1.58M
  const VariableArrayType *getVAPtr() const {
61
1.58M
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
62
1.58M
  }
63
64
9.07k
  void setVAPtr(const VariableArrayType *P) {
65
9.07k
    assert(inDeclGroup() || inSizeOfTypeVA());
66
0
    RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
67
9.07k
  }
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
110M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
723k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
79
109M
  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
252k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
88
89.9M
  StmtIteratorImpl() = default;
89
107M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
106M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
89
472k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
90
689k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
91
28
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
92
93
77.0M
  DERIVED& operator++() {
94
77.0M
    if (inStmt())
95
76.7M
      ++stmt;
96
294k
    else if (getVAPtr())
97
5.51k
      NextVA();
98
289k
    else
99
289k
      NextDecl();
100
101
77.0M
    return static_cast<DERIVED&>(*this);
102
77.0M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
93
45.0M
  DERIVED& operator++() {
94
45.0M
    if (inStmt())
95
45.0M
      ++stmt;
96
54.4k
    else if (getVAPtr())
97
1.85k
      NextVA();
98
52.6k
    else
99
52.6k
      NextDecl();
100
101
45.0M
    return static_cast<DERIVED&>(*this);
102
45.0M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
93
31.9M
  DERIVED& operator++() {
94
31.9M
    if (inStmt())
95
31.7M
      ++stmt;
96
240k
    else if (getVAPtr())
97
3.65k
      NextVA();
98
236k
    else
99
236k
      NextDecl();
100
101
31.9M
    return static_cast<DERIVED&>(*this);
102
31.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
177M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
177M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI99.0M
&&
112
177M
           
LHS.RawVAPtr == RHS.RawVAPtr99.0M
;
113
177M
  }
clang::operator==(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
110
76.3M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
76.3M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI44.3M
&&
112
76.3M
           
LHS.RawVAPtr == RHS.RawVAPtr44.3M
;
113
76.3M
  }
clang::operator==(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
110
100M
  friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
111
100M
    return LHS.stmt == RHS.stmt && 
LHS.DGI == RHS.DGI54.6M
&&
112
100M
           
LHS.RawVAPtr == RHS.RawVAPtr54.6M
;
113
100M
  }
114
115
176M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
176M
    return !(LHS == RHS);
117
176M
  }
clang::operator!=(clang::StmtIterator const&, clang::StmtIterator const&)
Line
Count
Source
115
76.3M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
76.3M
    return !(LHS == RHS);
117
76.3M
  }
clang::operator!=(clang::ConstStmtIterator const&, clang::ConstStmtIterator const&)
Line
Count
Source
115
99.7M
  friend bool operator!=(const DERIVED &LHS, const DERIVED &RHS) {
116
99.7M
    return !(LHS == RHS);
117
99.7M
  }
118
119
77.0M
  REFERENCE operator*() const {
120
77.0M
    return inStmt() ? 
*stmt76.7M
:
GetDeclExpr()294k
;
121
77.0M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
119
31.9M
  REFERENCE operator*() const {
120
31.9M
    return inStmt() ? 
*stmt31.7M
:
GetDeclExpr()240k
;
121
31.9M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
119
45.0M
  REFERENCE operator*() const {
120
45.0M
    return inStmt() ? 
*stmt45.0M
:
GetDeclExpr()54.4k
;
121
45.0M
  }
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
106M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
131
  StmtIterator(Decl** dgi, Decl** dge)
132
689k
      : 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
723k
      : 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
252k
  explicit ConstStmtIterator() = default;
147
  ConstStmtIterator(const StmtIterator& RHS)
148
109M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
149
150
  ConstStmtIterator(Stmt * const *S)
151
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
152
472k
            const_cast<Stmt **>(S)) {}
153
};
154
155
723k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
156
723k
  return RHS;
157
723k
}
158
159
} // namespace clang
160
161
#endif // LLVM_CLANG_AST_STMTITERATOR_H