Coverage Report

Created: 2020-02-18 08:44

/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
106M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
44
  StmtIteratorBase(const VariableArrayType *t);
45
  StmtIteratorBase(Decl **dgi, Decl **dge);
46
75.6M
  StmtIteratorBase() : stmt(nullptr) {}
47
48
1.30M
  bool inDeclGroup() const {
49
1.30M
    return (RawVAPtr & Flags) == DeclGroupMode;
50
1.30M
  }
51
52
28
  bool inSizeOfTypeVA() const {
53
28
    return (RawVAPtr & Flags) == SizeOfTypeVAMode;
54
28
  }
55
56
201M
  bool inStmt() const {
57
201M
    return (RawVAPtr & Flags) == StmtMode;
58
201M
  }
59
60
1.61M
  const VariableArrayType *getVAPtr() const {
61
1.61M
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
62
1.61M
  }
63
64
9.59k
  void setVAPtr(const VariableArrayType *P) {
65
9.59k
    assert(inDeclGroup() || inSizeOfTypeVA());
66
9.59k
    RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
67
9.59k
  }
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
98.7M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
82
98.0M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
82
636k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
83
84
public:
85
75.6M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
85
237k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
85
75.4M
  StmtIteratorImpl() = default;
86
106M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
86
106M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
86
398k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
87
704k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
88
14
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
89
90
123M
  DERIVED& operator++() {
91
123M
    if (inStmt())
92
123M
      ++stmt;
93
298k
    else if (getVAPtr())
94
5.79k
      NextVA();
95
293k
    else
96
293k
      NextDecl();
97
123M
98
123M
    return static_cast<DERIVED&>(*this);
99
123M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
90
47.7M
  DERIVED& operator++() {
91
47.7M
    if (inStmt())
92
47.6M
      ++stmt;
93
74.2k
    else if (getVAPtr())
94
1.60k
      NextVA();
95
72.6k
    else
96
72.6k
      NextDecl();
97
47.7M
98
47.7M
    return static_cast<DERIVED&>(*this);
99
47.7M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
90
75.7M
  DERIVED& operator++() {
91
75.7M
    if (inStmt())
92
75.5M
      ++stmt;
93
224k
    else if (getVAPtr())
94
4.19k
      NextVA();
95
220k
    else
96
220k
      NextDecl();
97
75.7M
98
75.7M
    return static_cast<DERIVED&>(*this);
99
75.7M
  }
100
101
2.21k
  DERIVED operator++(int) {
102
2.21k
    DERIVED tmp = static_cast<DERIVED&>(*this);
103
2.21k
    operator++();
104
2.21k
    return tmp;
105
2.21k
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++(int)
Line
Count
Source
101
2.21k
  DERIVED operator++(int) {
102
2.21k
    DERIVED tmp = static_cast<DERIVED&>(*this);
103
2.21k
    operator++();
104
2.21k
    return tmp;
105
2.21k
  }
Unexecuted instantiation: clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++(int)
106
107
5.88k
  bool operator==(const DERIVED& RHS) const {
108
5.88k
    return stmt == RHS.stmt && 
DGI == RHS.DGI448
&&
RawVAPtr == RHS.RawVAPtr448
;
109
5.88k
  }
Unexecuted instantiation: clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator==(clang::ConstStmtIterator const&) const
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator==(clang::StmtIterator const&) const
Line
Count
Source
107
5.88k
  bool operator==(const DERIVED& RHS) const {
108
5.88k
    return stmt == RHS.stmt && 
DGI == RHS.DGI448
&&
RawVAPtr == RHS.RawVAPtr448
;
109
5.88k
  }
110
111
159M
  bool operator!=(const DERIVED& RHS) const {
112
159M
    return stmt != RHS.stmt || 
DGI != RHS.DGI86.2M
||
RawVAPtr != RHS.RawVAPtr86.2M
;
113
159M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator!=(clang::ConstStmtIterator const&) const
Line
Count
Source
111
93.4M
  bool operator!=(const DERIVED& RHS) const {
112
93.4M
    return stmt != RHS.stmt || 
DGI != RHS.DGI48.2M
||
RawVAPtr != RHS.RawVAPtr48.2M
;
113
93.4M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator!=(clang::StmtIterator const&) const
Line
Count
Source
111
65.7M
  bool operator!=(const DERIVED& RHS) const {
112
65.7M
    return stmt != RHS.stmt || 
DGI != RHS.DGI37.9M
||
RawVAPtr != RHS.RawVAPtr37.9M
;
113
65.7M
  }
114
115
78.1M
  REFERENCE operator*() const {
116
78.1M
    return inStmt() ? 
*stmt77.8M
:
GetDeclExpr()299k
;
117
78.1M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
115
32.1M
  REFERENCE operator*() const {
116
32.1M
    return inStmt() ? 
*stmt31.9M
:
GetDeclExpr()224k
;
117
32.1M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
115
45.9M
  REFERENCE operator*() const {
116
45.9M
    return inStmt() ? 
*stmt45.8M
:
GetDeclExpr()74.2k
;
117
45.9M
  }
118
119
  REFERENCE operator->() const { return operator*(); }
120
};
121
122
struct ConstStmtIterator;
123
124
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
125
75.4M
  explicit StmtIterator() = default;
126
106M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
127
  StmtIterator(Decl** dgi, Decl** dge)
128
704k
      : StmtIteratorImpl<StmtIterator, Stmt*&>(dgi, dge) {}
129
  StmtIterator(const VariableArrayType *t)
130
14
      : StmtIteratorImpl<StmtIterator, Stmt*&>(t) {}
131
132
private:
133
  StmtIterator(const StmtIteratorBase &RHS)
134
636k
      : 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
237k
  explicit ConstStmtIterator() = default;
143
  ConstStmtIterator(const StmtIterator& RHS)
144
98.0M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
145
146
  ConstStmtIterator(Stmt * const *S)
147
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
148
398k
            const_cast<Stmt **>(S)) {}
149
};
150
151
636k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
152
636k
  return RHS;
153
636k
}
154
155
} // namespace clang
156
157
#endif // LLVM_CLANG_AST_STMTITERATOR_H