/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/StmtIterator.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- StmtIterator.cpp - Iterators for Statements ------------------------===// |
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 internal methods for StmtIterator. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/AST/StmtIterator.h" |
14 | | #include "clang/AST/Decl.h" |
15 | | #include "clang/AST/Type.h" |
16 | | #include "clang/Basic/LLVM.h" |
17 | | #include "llvm/Support/Casting.h" |
18 | | #include <cassert> |
19 | | #include <cstdint> |
20 | | |
21 | | using namespace clang; |
22 | | |
23 | | // FIXME: Add support for dependent-sized array types in C++? |
24 | | // Does it even make sense to build a CFG for an uninstantiated template? |
25 | 296k | static inline const VariableArrayType *FindVA(const Type* t) { |
26 | 312k | while (const ArrayType *vt = dyn_cast<ArrayType>(t)) { |
27 | 21.1k | if (const VariableArrayType *vat = dyn_cast<VariableArrayType>(vt)) |
28 | 5.30k | if (vat->getSizeExpr()) |
29 | 5.30k | return vat; |
30 | | |
31 | 15.8k | t = vt->getElementType().getTypePtr(); |
32 | 15.8k | } |
33 | | |
34 | 291k | return nullptr; |
35 | 296k | } |
36 | | |
37 | 5.33k | void StmtIteratorBase::NextVA() { |
38 | 5.33k | assert(getVAPtr()); |
39 | | |
40 | 0 | const VariableArrayType *p = getVAPtr(); |
41 | 5.33k | p = FindVA(p->getElementType().getTypePtr()); |
42 | 5.33k | setVAPtr(p); |
43 | | |
44 | 5.33k | if (p) |
45 | 1.86k | return; |
46 | | |
47 | 3.46k | if (inDeclGroup()) { |
48 | 3.43k | if (VarDecl* VD = dyn_cast<VarDecl>(*DGI)) |
49 | 3.40k | if (VD->hasInit()) |
50 | 12 | return; |
51 | | |
52 | 3.42k | NextDecl(); |
53 | 3.42k | } |
54 | 28 | else { |
55 | 28 | assert(inSizeOfTypeVA()); |
56 | 0 | RawVAPtr = 0; |
57 | 28 | } |
58 | 3.46k | } |
59 | | |
60 | 825k | void StmtIteratorBase::NextDecl(bool ImmediateAdvance) { |
61 | 825k | assert(getVAPtr() == nullptr); |
62 | 0 | assert(inDeclGroup()); |
63 | | |
64 | 825k | if (ImmediateAdvance) |
65 | 247k | ++DGI; |
66 | | |
67 | 873k | for ( ; DGI != DGE; ++DGI47.9k ) |
68 | 295k | if (HandleDecl(*DGI)) |
69 | 247k | return; |
70 | | |
71 | 577k | RawVAPtr = 0; |
72 | 577k | } |
73 | | |
74 | 295k | bool StmtIteratorBase::HandleDecl(Decl* D) { |
75 | 295k | if (VarDecl* VD = dyn_cast<VarDecl>(D)) { |
76 | 282k | if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) { |
77 | 3.40k | setVAPtr(VAPtr); |
78 | 3.40k | return true; |
79 | 3.40k | } |
80 | | |
81 | 279k | if (VD->getInit()) |
82 | 244k | return true; |
83 | 279k | } |
84 | 13.2k | else if (TypedefNameDecl* TD = dyn_cast<TypedefNameDecl>(D)) { |
85 | 8.46k | if (const VariableArrayType* VAPtr = |
86 | 8.46k | FindVA(TD->getUnderlyingType().getTypePtr())) { |
87 | 35 | setVAPtr(VAPtr); |
88 | 35 | return true; |
89 | 35 | } |
90 | 8.46k | } |
91 | 4.75k | else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) { |
92 | 0 | if (ECD->getInitExpr()) |
93 | 0 | return true; |
94 | 0 | } |
95 | | |
96 | 47.9k | return false; |
97 | 295k | } |
98 | | |
99 | | StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge) |
100 | 577k | : DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) { |
101 | 577k | NextDecl(false); |
102 | 577k | } |
103 | | |
104 | | StmtIteratorBase::StmtIteratorBase(const VariableArrayType* t) |
105 | 28 | : DGI(nullptr), RawVAPtr(SizeOfTypeVAMode) { |
106 | 28 | RawVAPtr |= reinterpret_cast<uintptr_t>(t); |
107 | 28 | } |
108 | | |
109 | 249k | Stmt*& StmtIteratorBase::GetDeclExpr() const { |
110 | 249k | if (const VariableArrayType* VAPtr = getVAPtr()) { |
111 | 5.33k | assert(VAPtr->SizeExpr); |
112 | 0 | return const_cast<Stmt*&>(VAPtr->SizeExpr); |
113 | 5.33k | } |
114 | | |
115 | 244k | assert(inDeclGroup()); |
116 | 0 | VarDecl* VD = cast<VarDecl>(*DGI); |
117 | 244k | return *VD->getInitAddress(); |
118 | 249k | } |