Coverage Report

Created: 2018-12-11 17:59

/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
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file defines the StmtIterator and ConstStmtIterator classes.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_STMTITERATOR_H
15
#define LLVM_CLANG_AST_STMTITERATOR_H
16
17
#include <cassert>
18
#include <cstddef>
19
#include <cstdint>
20
#include <iterator>
21
22
namespace clang {
23
24
class Decl;
25
class Stmt;
26
class VariableArrayType;
27
28
class StmtIteratorBase {
29
protected:
30
  enum {
31
    StmtMode = 0x0,
32
    SizeOfTypeVAMode = 0x1,
33
    DeclGroupMode = 0x2,
34
    Flags = 0x3
35
  };
36
37
  union {
38
    Stmt **stmt;
39
    Decl **DGI;
40
  };
41
  uintptr_t RawVAPtr = 0;
42
  Decl **DGE;
43
44
163M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
45
  StmtIteratorBase(const VariableArrayType *t);
46
  StmtIteratorBase(Decl **dgi, Decl **dge);
47
118M
  StmtIteratorBase() : stmt(nullptr) {}
48
49
1.00k
  bool inDeclGroup() const {
50
1.00k
    return (RawVAPtr & Flags) == DeclGroupMode;
51
1.00k
  }
52
53
0
  bool inSizeOfTypeVA() const {
54
0
    return (RawVAPtr & Flags) == SizeOfTypeVAMode;
55
0
  }
56
57
268M
  bool inStmt() const {
58
268M
    return (RawVAPtr & Flags) == StmtMode;
59
268M
  }
60
61
199k
  const VariableArrayType *getVAPtr() const {
62
199k
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
63
199k
  }
64
65
2.44k
  void setVAPtr(const VariableArrayType *P) {
66
2.44k
    assert(inDeclGroup() || inSizeOfTypeVA());
67
2.44k
    RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
68
2.44k
  }
69
70
  void NextDecl(bool ImmediateAdvance = true);
71
  bool HandleDecl(Decl* D);
72
  void NextVA();
73
74
  Stmt*& GetDeclExpr() const;
75
};
76
77
template <typename DERIVED, typename REFERENCE>
78
class StmtIteratorImpl : public StmtIteratorBase,
79
                         public std::iterator<std::forward_iterator_tag,
80
                                              REFERENCE, ptrdiff_t,
81
                                              REFERENCE, REFERENCE> {
82
protected:
83
72.5M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
83
71.2M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
83
1.24M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
84
85
public:
86
118M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
86
363k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
86
117M
  StmtIteratorImpl() = default;
87
163M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
87
884k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
87
162M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
88
227k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
89
14
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
90
91
147M
  DERIVED& operator++() {
92
147M
    if (inStmt())
93
147M
      ++stmt;
94
98.8k
    else if (getVAPtr())
95
1.45k
      NextVA();
96
97.4k
    else
97
97.4k
      NextDecl();
98
147M
99
147M
    return static_cast<DERIVED&>(*this);
100
147M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
91
33.3M
  DERIVED& operator++() {
92
33.3M
    if (inStmt())
93
33.3M
      ++stmt;
94
14.8k
    else if (getVAPtr())
95
1.26k
      NextVA();
96
13.5k
    else
97
13.5k
      NextDecl();
98
33.3M
99
33.3M
    return static_cast<DERIVED&>(*this);
100
33.3M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
91
114M
  DERIVED& operator++() {
92
114M
    if (inStmt())
93
114M
      ++stmt;
94
84.0k
    else if (getVAPtr())
95
188
      NextVA();
96
83.8k
    else
97
83.8k
      NextDecl();
98
114M
99
114M
    return static_cast<DERIVED&>(*this);
100
114M
  }
101
102
4.90k
  DERIVED operator++(int) {
103
4.90k
    DERIVED tmp = static_cast<DERIVED&>(*this);
104
4.90k
    operator++();
105
4.90k
    return tmp;
106
4.90k
  }
107
108
3.65k
  bool operator==(const DERIVED& RHS) const {
109
3.65k
    return stmt == RHS.stmt && 
DGI == RHS.DGI158
&&
RawVAPtr == RHS.RawVAPtr158
;
110
3.65k
  }
111
112
256M
  bool operator!=(const DERIVED& RHS) const {
113
256M
    return stmt != RHS.stmt || 
DGI != RHS.DGI138M
||
RawVAPtr != RHS.RawVAPtr138M
;
114
256M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator!=(clang::ConstStmtIterator const&) const
Line
Count
Source
112
66.4M
  bool operator!=(const DERIVED& RHS) const {
113
66.4M
    return stmt != RHS.stmt || 
DGI != RHS.DGI35.3M
||
RawVAPtr != RHS.RawVAPtr35.3M
;
114
66.4M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator!=(clang::StmtIterator const&) const
Line
Count
Source
112
190M
  bool operator!=(const DERIVED& RHS) const {
113
190M
    return stmt != RHS.stmt || 
DGI != RHS.DGI102M
||
RawVAPtr != RHS.RawVAPtr102M
;
114
190M
  }
115
116
121M
  REFERENCE operator*() const {
117
121M
    return inStmt() ? 
*stmt120M
:
GetDeclExpr()98.8k
;
118
121M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
116
31.4M
  REFERENCE operator*() const {
117
31.4M
    return inStmt() ? 
*stmt31.3M
:
GetDeclExpr()14.8k
;
118
31.4M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
116
89.6M
  REFERENCE operator*() const {
117
89.6M
    return inStmt() ? 
*stmt89.5M
:
GetDeclExpr()84.0k
;
118
89.6M
  }
119
120
  REFERENCE operator->() const { return operator*(); }
121
};
122
123
struct ConstStmtIterator;
124
125
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
126
117M
  explicit StmtIterator() = default;
127
162M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
128
  StmtIterator(Decl** dgi, Decl** dge)
129
227k
      : StmtIteratorImpl<StmtIterator, Stmt*&>(dgi, dge) {}
130
  StmtIterator(const VariableArrayType *t)
131
14
      : StmtIteratorImpl<StmtIterator, Stmt*&>(t) {}
132
133
private:
134
  StmtIterator(const StmtIteratorBase &RHS)
135
1.24M
      : StmtIteratorImpl<StmtIterator, Stmt *&>(RHS) {}
136
137
  inline friend StmtIterator
138
  cast_away_const(const ConstStmtIterator &RHS);
139
};
140
141
struct ConstStmtIterator : public StmtIteratorImpl<ConstStmtIterator,
142
                                                   const Stmt*> {
143
363k
  explicit ConstStmtIterator() = default;
144
  ConstStmtIterator(const StmtIterator& RHS)
145
71.2M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
146
147
  ConstStmtIterator(Stmt * const *S)
148
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
149
884k
            const_cast<Stmt **>(S)) {}
150
};
151
152
1.24M
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
153
1.24M
  return RHS;
154
1.24M
}
155
156
} // namespace clang
157
158
#endif // LLVM_CLANG_AST_STMTITERATOR_H