Coverage Report

Created: 2019-03-22 08:08

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
128M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
44
  StmtIteratorBase(const VariableArrayType *t);
45
  StmtIteratorBase(Decl **dgi, Decl **dge);
46
89.9M
  StmtIteratorBase() : stmt(nullptr) {}
47
48
1.01k
  bool inDeclGroup() const {
49
1.01k
    return (RawVAPtr & Flags) == DeclGroupMode;
50
1.01k
  }
51
52
0
  bool inSizeOfTypeVA() const {
53
0
    return (RawVAPtr & Flags) == SizeOfTypeVAMode;
54
0
  }
55
56
220M
  bool inStmt() const {
57
220M
    return (RawVAPtr & Flags) == StmtMode;
58
220M
  }
59
60
204k
  const VariableArrayType *getVAPtr() const {
61
204k
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
62
204k
  }
63
64
2.45k
  void setVAPtr(const VariableArrayType *P) {
65
2.45k
    assert(inDeclGroup() || inSizeOfTypeVA());
66
2.45k
    RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
67
2.45k
  }
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
54.5M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
82
53.5M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
82
1.00M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
83
84
public:
85
89.9M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
85
253k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
85
89.7M
  StmtIteratorImpl() = default;
86
128M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
86
756k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
86
127M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
87
235k
  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
101k
    else if (getVAPtr())
94
1.45k
      NextVA();
95
100k
    else
96
100k
      NextDecl();
97
123M
98
123M
    return static_cast<DERIVED&>(*this);
99
123M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
90
25.7M
  DERIVED& operator++() {
91
25.7M
    if (inStmt())
92
25.7M
      ++stmt;
93
14.4k
    else if (getVAPtr())
94
1.26k
      NextVA();
95
13.1k
    else
96
13.1k
      NextDecl();
97
25.7M
98
25.7M
    return static_cast<DERIVED&>(*this);
99
25.7M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
90
97.7M
  DERIVED& operator++() {
91
97.7M
    if (inStmt())
92
97.7M
      ++stmt;
93
87.1k
    else if (getVAPtr())
94
191
      NextVA();
95
86.9k
    else
96
86.9k
      NextDecl();
97
97.7M
98
97.7M
    return static_cast<DERIVED&>(*this);
99
97.7M
  }
100
101
3.04k
  DERIVED operator++(int) {
102
3.04k
    DERIVED tmp = static_cast<DERIVED&>(*this);
103
3.04k
    operator++();
104
3.04k
    return tmp;
105
3.04k
  }
106
107
3.66k
  bool operator==(const DERIVED& RHS) const {
108
3.66k
    return stmt == RHS.stmt && 
DGI == RHS.DGI160
&&
RawVAPtr == RHS.RawVAPtr160
;
109
3.66k
  }
110
111
200M
  bool operator!=(const DERIVED& RHS) const {
112
200M
    return stmt != RHS.stmt || 
DGI != RHS.DGI106M
||
RawVAPtr != RHS.RawVAPtr106M
;
113
200M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator!=(clang::ConstStmtIterator const&) const
Line
Count
Source
111
49.7M
  bool operator!=(const DERIVED& RHS) const {
112
49.7M
    return stmt != RHS.stmt || 
DGI != RHS.DGI26.3M
||
RawVAPtr != RHS.RawVAPtr26.3M
;
113
49.7M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator!=(clang::StmtIterator const&) const
Line
Count
Source
111
150M
  bool operator!=(const DERIVED& RHS) const {
112
150M
    return stmt != RHS.stmt || 
DGI != RHS.DGI80.1M
||
RawVAPtr != RHS.RawVAPtr80.1M
;
113
150M
  }
114
115
96.9M
  REFERENCE operator*() const {
116
96.9M
    return inStmt() ? 
*stmt96.8M
:
GetDeclExpr()101k
;
117
96.9M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
115
23.8M
  REFERENCE operator*() const {
116
23.8M
    return inStmt() ? 
*stmt23.8M
:
GetDeclExpr()14.4k
;
117
23.8M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
115
73.1M
  REFERENCE operator*() const {
116
73.1M
    return inStmt() ? 
*stmt73.0M
:
GetDeclExpr()87.1k
;
117
73.1M
  }
118
119
  REFERENCE operator->() const { return operator*(); }
120
};
121
122
struct ConstStmtIterator;
123
124
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
125
89.7M
  explicit StmtIterator() = default;
126
127M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
127
  StmtIterator(Decl** dgi, Decl** dge)
128
235k
      : 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
1.00M
      : 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
253k
  explicit ConstStmtIterator() = default;
143
  ConstStmtIterator(const StmtIterator& RHS)
144
53.5M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
145
146
  ConstStmtIterator(Stmt * const *S)
147
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
148
756k
            const_cast<Stmt **>(S)) {}
149
};
150
151
1.00M
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
152
1.00M
  return RHS;
153
1.00M
}
154
155
} // namespace clang
156
157
#endif // LLVM_CLANG_AST_STMTITERATOR_H