Coverage Report

Created: 2018-09-25 23:22

/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
124M
  StmtIteratorBase(Stmt **s) : stmt(s) {}
45
  StmtIteratorBase(const VariableArrayType *t);
46
  StmtIteratorBase(Decl **dgi, Decl **dge);
47
88.2M
  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
214M
  bool inStmt() const {
58
214M
    return (RawVAPtr & Flags) == StmtMode;
59
214M
  }
60
61
193k
  const VariableArrayType *getVAPtr() const {
62
193k
    return reinterpret_cast<const VariableArrayType*>(RawVAPtr & ~Flags);
63
193k
  }
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
53.2M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
83
52.2M
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::StmtIteratorBase const&)
Line
Count
Source
83
987k
  StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
84
85
public:
86
88.2M
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl()
Line
Count
Source
86
252k
  StmtIteratorImpl() = default;
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl()
Line
Count
Source
86
87.9M
  StmtIteratorImpl() = default;
87
124M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
87
735k
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::StmtIteratorImpl(clang::Stmt**)
Line
Count
Source
87
123M
  StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
88
221k
  StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
89
14
  StmtIteratorImpl(const VariableArrayType *t) : StmtIteratorBase(t) {}
90
91
119M
  DERIVED& operator++() {
92
119M
    if (inStmt())
93
119M
      ++stmt;
94
96.2k
    else if (getVAPtr())
95
1.45k
      NextVA();
96
94.7k
    else
97
94.7k
      NextDecl();
98
119M
99
119M
    return static_cast<DERIVED&>(*this);
100
119M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator++()
Line
Count
Source
91
26.0M
  DERIVED& operator++() {
92
26.0M
    if (inStmt())
93
26.0M
      ++stmt;
94
14.3k
    else if (getVAPtr())
95
1.26k
      NextVA();
96
13.0k
    else
97
13.0k
      NextDecl();
98
26.0M
99
26.0M
    return static_cast<DERIVED&>(*this);
100
26.0M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator++()
Line
Count
Source
91
93.5M
  DERIVED& operator++() {
92
93.5M
    if (inStmt())
93
93.4M
      ++stmt;
94
81.9k
    else if (getVAPtr())
95
188
      NextVA();
96
81.7k
    else
97
81.7k
      NextDecl();
98
93.5M
99
93.5M
    return static_cast<DERIVED&>(*this);
100
93.5M
  }
101
102
3.14k
  DERIVED operator++(int) {
103
3.14k
    DERIVED tmp = static_cast<DERIVED&>(*this);
104
3.14k
    operator++();
105
3.14k
    return tmp;
106
3.14k
  }
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
195M
  bool operator!=(const DERIVED& RHS) const {
113
195M
    return stmt != RHS.stmt || 
DGI != RHS.DGI103M
||
RawVAPtr != RHS.RawVAPtr103M
;
114
195M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator!=(clang::ConstStmtIterator const&) const
Line
Count
Source
112
49.7M
  bool operator!=(const DERIVED& RHS) const {
113
49.7M
    return stmt != RHS.stmt || 
DGI != RHS.DGI25.8M
||
RawVAPtr != RHS.RawVAPtr25.8M
;
114
49.7M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator!=(clang::StmtIterator const&) const
Line
Count
Source
112
146M
  bool operator!=(const DERIVED& RHS) const {
113
146M
    return stmt != RHS.stmt || 
DGI != RHS.DGI77.9M
||
RawVAPtr != RHS.RawVAPtr77.9M
;
114
146M
  }
115
116
94.5M
  REFERENCE operator*() const {
117
94.5M
    return inStmt() ? 
*stmt94.4M
:
GetDeclExpr()96.2k
;
118
94.5M
  }
clang::StmtIteratorImpl<clang::ConstStmtIterator, clang::Stmt const*>::operator*() const
Line
Count
Source
116
24.1M
  REFERENCE operator*() const {
117
24.1M
    return inStmt() ? 
*stmt24.1M
:
GetDeclExpr()14.3k
;
118
24.1M
  }
clang::StmtIteratorImpl<clang::StmtIterator, clang::Stmt*&>::operator*() const
Line
Count
Source
116
70.3M
  REFERENCE operator*() const {
117
70.3M
    return inStmt() ? 
*stmt70.2M
:
GetDeclExpr()81.9k
;
118
70.3M
  }
119
120
  REFERENCE operator->() const { return operator*(); }
121
};
122
123
struct ConstStmtIterator;
124
125
struct StmtIterator : public StmtIteratorImpl<StmtIterator, Stmt*&> {
126
87.9M
  explicit StmtIterator() = default;
127
123M
  StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator, Stmt*&>(S) {}
128
  StmtIterator(Decl** dgi, Decl** dge)
129
221k
      : 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
987k
      : 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
252k
  explicit ConstStmtIterator() = default;
144
  ConstStmtIterator(const StmtIterator& RHS)
145
52.2M
      : StmtIteratorImpl<ConstStmtIterator, const Stmt*>(RHS) {}
146
147
  ConstStmtIterator(Stmt * const *S)
148
      : StmtIteratorImpl<ConstStmtIterator, const Stmt *>(
149
735k
            const_cast<Stmt **>(S)) {}
150
};
151
152
987k
inline StmtIterator cast_away_const(const ConstStmtIterator &RHS) {
153
987k
  return RHS;
154
987k
}
155
156
} // namespace clang
157
158
#endif // LLVM_CLANG_AST_STMTITERATOR_H