Coverage Report

Created: 2020-09-15 12:33

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/StmtIterator.h
Line
Count
Source
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
101M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
44
  StmtIteratorBase(const VariableArrayType *t);
45
  StmtIteratorBase(Decl **dgi, Decl **dge);
46
83.5M
  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
146M
  bool inStmt() const {
57
146M
    return (RawVAPtr & Flags) == StmtMode;
58
146M
  }
59
60
1.58M
  const VariableArrayType *getVAPtr() const {
61
1.58M
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
62
1.58M
  }
63
64
9.22k
  void setVAPtr(const VariableArrayType *P) {
65
9.22k
    assert(inDeclGroup() || inSizeOfTypeVA());
66
9.22k
    RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
67
9.22k
  }
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
                         public std::iterator<std::forward_iterator_tag,
79
                                              REFERENCE, ptrdiff_t,
80
                                              REFERENCE, REFERENCE> {
81
protected:
82
101M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
82
691k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
82
101M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
83
84
public:
85
83.5M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
85
224k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
85
83.2M
  StmtIteratorImpl() = default;
86
101M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
86
101M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
86
467k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
87
689k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
88
28
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
89
90
73.4M
  DERIVED& operator++() {
91
73.4M
    if (inStmt())
92
73.1M
      ++stmt;
93
296k
    else if (getVAPtr())
94
5.58k
      NextVA();
95
291k
    else
96
291k
      NextDecl();
97
73.4M
98
73.4M
    return static_cast<DERIVED&>(*this);
99
73.4M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
90
42.5M
  DERIVED& operator++() {
91
42.5M
    if (inStmt())
92
42.4M
      ++stmt;
93
59.5k
    else if (getVAPtr())
94
1.93k
      NextVA();
95
57.5k
    else
96
57.5k
      NextDecl();
97
42.5M
98
42.5M
    return static_cast<DERIVED&>(*this);
99
42.5M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
90
30.9M
  DERIVED& operator++() {
91
30.9M
    if (inStmt())
92
30.7M
      ++stmt;
93
237k
    else if (getVAPtr())
94
3.64k
      NextVA();
95
233k
    else
96
233k
      NextDecl();
97
30.9M
98
30.9M
    return static_cast<DERIVED&>(*this);
99
30.9M
  }
100
101
2.32k
  DERIVED operator++(int) {
102
2.32k
    DERIVED tmp = static_cast<DERIVED&>(*this);
103
2.32k
    operator++();
104
2.32k
    return tmp;
105
2.32k
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++(int)
Line
Count
Source
101
2.32k
  DERIVED operator++(int) {
102
2.32k
    DERIVED tmp = static_cast<DERIVED&>(*this);
103
2.32k
    operator++();
104
2.32k
    return tmp;
105
2.32k
  }
Unexecuted instantiation: clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++(int)
106
107
45.7k
  bool operator==(const DERIVED& RHS) const {
108
45.7k
    return stmt == RHS.stmt && 
DGI == RHS.DGI466
&&
RawVAPtr == RHS.RawVAPtr466
;
109
45.7k
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator==(clang::ConstStmtIterator const&) const
Line
Count
Source
107
38.3k
  bool operator==(const DERIVED& RHS) const {
108
38.3k
    return stmt == RHS.stmt && 
DGI == RHS.DGI0
&&
RawVAPtr == RHS.RawVAPtr0
;
109
38.3k
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator==(clang::StmtIterator const&) const
Line
Count
Source
107
7.35k
  bool operator==(const DERIVED& RHS) const {
108
7.35k
    return stmt == RHS.stmt && 
DGI == RHS.DGI466
&&
RawVAPtr == RHS.RawVAPtr466
;
109
7.35k
  }
110
111
166M
  bool operator!=(const DERIVED& RHS) const {
112
166M
    return stmt != RHS.stmt || 
DGI != RHS.DGI92.9M
||
RawVAPtr != RHS.RawVAPtr92.9M
;
113
166M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator!=(clang::StmtIterator const&) const
Line
Count
Source
111
73.3M
  bool operator!=(const DERIVED& RHS) const {
112
73.3M
    return stmt != RHS.stmt || 
DGI != RHS.DGI42.3M
||
RawVAPtr != RHS.RawVAPtr42.3M
;
113
73.3M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator!=(clang::ConstStmtIterator const&) const
Line
Count
Source
111
93.1M
  bool operator!=(const DERIVED& RHS) const {
112
93.1M
    return stmt != RHS.stmt || 
DGI != RHS.DGI50.5M
||
RawVAPtr != RHS.RawVAPtr50.5M
;
113
93.1M
  }
114
115
73.4M
  REFERENCE operator*() const {
116
73.1M
    return inStmt() ? *stmt : 
GetDeclExpr()296k
;
117
73.4M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
115
30.9M
  REFERENCE operator*() const {
116
30.6M
    return inStmt() ? *stmt : 
GetDeclExpr()237k
;
117
30.9M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
115
42.5M
  REFERENCE operator*() const {
116
42.5M
    return inStmt() ? *stmt : 
GetDeclExpr()59.5k
;
117
42.5M
  }
118
119
  REFERENCE operator->() const { return operator*(); }
120
};
121
122
struct ConstStmtIterator;
123
124
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
125
83.2M
  explicit StmtIterator() = default;
126
101M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
127
  StmtIterator(Decl** dgi, Decl** dge)
128
689k
      : StmtIteratorImpl<StmtIterator, Stmt*&>(dgi, dge) {}
129
  StmtIterator(const VariableArrayType *t)
130
28
      : StmtIteratorImpl<StmtIterator, Stmt*&>(t) {}
131
132
private:
133
  StmtIterator(const StmtIteratorBase &RHS)
134
691k
      : StmtIteratorImpl<StmtIterator, Stmt *&>(RHS) {}
135
136
  inline friend StmtIterator
137
  cast_away_const(const ConstStmtIterator &RHS);
138
};
139
140
struct ConstStmtIterator : public StmtIteratorImpl<ConstStmtIterator,
141
                                                   const Stmt*> {
142
224k
  explicit ConstStmtIterator() = default;
143
  ConstStmtIterator(const StmtIterator& RHS)
144
101M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
145
146
  ConstStmtIterator(Stmt * const *S)
147
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
148
467k
            const_cast<Stmt **>(S)) {}
149
};
150
151
691k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
152
691k
  return RHS;
153
691k
}
154
155
} // namespace clang
156
157
#endif // LLVM_CLANG_AST_STMTITERATOR_H