Coverage Report

Created: 2018-07-20 23:04

/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
118M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
45
  StmtIteratorBase(const VariableArrayType *t);
46
  StmtIteratorBase(Decl **dgi, Decl **dge);
47
83.9M
  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
204M
  bool inStmt() const {
58
204M
    return (RawVAPtr & Flags) == StmtMode;
59
204M
  }
60
61
191k
  const VariableArrayType *getVAPtr() const {
62
191k
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
63
191k
  }
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
50.6M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
83
49.7M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
83
931k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
84
85
public:
86
83.9M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
86
229k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
86
83.7M
  StmtIteratorImpl() = default;
87
118M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
87
702k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
87
117M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
88
218k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
89
10
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
90
91
114M
  DERIVED& operator++() {
92
114M
    if (inStmt())
93
114M
      ++stmt;
94
95.0k
    else if (getVAPtr())
95
1.45k
      NextVA();
96
93.6k
    else
97
93.6k
      NextDecl();
98
114M
99
114M
    return static_cast<DERIVED&>(*this);
100
114M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
91
25.0M
  DERIVED& operator++() {
92
25.0M
    if (inStmt())
93
25.0M
      ++stmt;
94
15.1k
    else if (getVAPtr())
95
1.26k
      NextVA();
96
13.9k
    else
97
13.9k
      NextDecl();
98
25.0M
99
25.0M
    return static_cast<DERIVED&>(*this);
100
25.0M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
91
89.6M
  DERIVED& operator++() {
92
89.6M
    if (inStmt())
93
89.5M
      ++stmt;
94
79.9k
    else if (getVAPtr())
95
184
      NextVA();
96
79.7k
    else
97
79.7k
      NextDecl();
98
89.6M
99
89.6M
    return static_cast<DERIVED&>(*this);
100
89.6M
  }
101
102
3.01k
  DERIVED operator++(int) {
103
3.01k
    DERIVED tmp = static_cast<DERIVED&>(*this);
104
3.01k
    operator++();
105
3.01k
    return tmp;
106
3.01k
  }
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
186M
  bool operator!=(const DERIVED& RHS) const {
113
186M
    return stmt != RHS.stmt || 
DGI != RHS.DGI98.8M
||
RawVAPtr != RHS.RawVAPtr98.8M
;
114
186M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator!=(clang::ConstStmtIterator const&) const
Line
Count
Source
112
47.7M
  bool operator!=(const DERIVED& RHS) const {
113
47.7M
    return stmt != RHS.stmt || 
DGI != RHS.DGI24.5M
||
RawVAPtr != RHS.RawVAPtr24.5M
;
114
47.7M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator!=(clang::StmtIterator const&) const
Line
Count
Source
112
138M
  bool operator!=(const DERIVED& RHS) const {
113
138M
    return stmt != RHS.stmt || 
DGI != RHS.DGI74.2M
||
RawVAPtr != RHS.RawVAPtr74.2M
;
114
138M
  }
115
116
90.2M
  REFERENCE operator*() const {
117
90.2M
    return inStmt() ? 
*stmt90.1M
:
GetDeclExpr()95.0k
;
118
90.2M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
116
23.4M
  REFERENCE operator*() const {
117
23.4M
    return inStmt() ? 
*stmt23.3M
:
GetDeclExpr()15.1k
;
118
23.4M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
116
66.8M
  REFERENCE operator*() const {
117
66.8M
    return inStmt() ? 
*stmt66.7M
:
GetDeclExpr()79.9k
;
118
66.8M
  }
119
120
  REFERENCE operator->() const { return operator*(); }
121
};
122
123
struct ConstStmtIterator;
124
125
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
126
83.7M
  explicit StmtIterator() = default;
127
117M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
128
  StmtIterator(Decl** dgi, Decl** dge)
129
218k
      : StmtIteratorImpl<StmtIterator, Stmt*&>(dgi, dge) {}
130
  StmtIterator(const VariableArrayType *t)
131
10
      : StmtIteratorImpl<StmtIterator, Stmt*&>(t) {}
132
133
private:
134
  StmtIterator(const StmtIteratorBase &RHS)
135
931k
      : 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
229k
  explicit ConstStmtIterator() = default;
144
  ConstStmtIterator(const StmtIterator& RHS)
145
49.7M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
146
147
  ConstStmtIterator(Stmt * const *S)
148
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
149
702k
            const_cast<Stmt **>(S)) {}
150
};
151
152
931k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
153
931k
  return RHS;
154
931k
}
155
156
} // namespace clang
157
158
#endif // LLVM_CLANG_AST_STMTITERATOR_H