/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/IgnoreExpr.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- IgnoreExpr.h - Ignore intermediate Expressions -----------------===// |
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 common functions to ignore intermediate expression nodes |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_CLANG_AST_IGNOREEXPR_H |
14 | | #define LLVM_CLANG_AST_IGNOREEXPR_H |
15 | | |
16 | | #include "clang/AST/Expr.h" |
17 | | #include "clang/AST/ExprCXX.h" |
18 | | |
19 | | namespace clang { |
20 | | namespace detail { |
21 | | /// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *, |
22 | | /// Return Fn_n(...(Fn_1(E))) |
23 | 414M | inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; } |
24 | | template <typename FnTy, typename... FnTys> |
25 | 695M | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { |
26 | 695M | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); |
27 | 695M | } clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*)) Line | Count | Source | 25 | 414M | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 414M | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 414M | } |
clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)) Line | Count | Source | 25 | 280M | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 280M | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 280M | } |
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&) Line | Count | Source | 25 | 207k | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 207k | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 207k | } |
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&>(clang::Expr*, clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&) Line | Count | Source | 25 | 207k | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 207k | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 207k | } |
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&) Line | Count | Source | 25 | 38.8k | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 38.8k | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 38.8k | } |
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&) Line | Count | Source | 25 | 38.8k | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 38.8k | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 38.8k | } |
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&) Line | Count | Source | 25 | 38.8k | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 38.8k | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 38.8k | } |
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&) Line | Count | Source | 25 | 38.8k | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 38.8k | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 38.8k | } |
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&) Line | Count | Source | 25 | 38.8k | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 38.8k | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 38.8k | } |
clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)) Line | Count | Source | 25 | 11.4k | Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) { | 26 | 11.4k | return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...); | 27 | 11.4k | } |
|
28 | | } // namespace detail |
29 | | |
30 | | /// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *, |
31 | | /// Recursively apply each of the functions to E until reaching a fixed point. |
32 | | /// Note that a null E is valid; in this case nothing is done. |
33 | 328M | template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) { |
34 | 328M | Expr *LastE = nullptr; |
35 | 742M | while (E != LastE) { |
36 | 414M | LastE = E; |
37 | 414M | E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...); |
38 | 414M | } |
39 | 328M | return E; |
40 | 328M | } clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*)) Line | Count | Source | 33 | 123M | template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) { | 34 | 123M | Expr *LastE = nullptr; | 35 | 257M | while (E != LastE) { | 36 | 133M | LastE = E; | 37 | 133M | E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...); | 38 | 133M | } | 39 | 123M | return E; | 40 | 123M | } |
clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)) Line | Count | Source | 33 | 204M | template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) { | 34 | 204M | Expr *LastE = nullptr; | 35 | 484M | while (E != LastE) { | 36 | 280M | LastE = E; | 37 | 280M | E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...); | 38 | 280M | } | 39 | 204M | return E; | 40 | 204M | } |
Expr.cpp:clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&) Line | Count | Source | 33 | 202k | template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) { | 34 | 202k | Expr *LastE = nullptr; | 35 | 410k | while (E != LastE) { | 36 | 207k | LastE = E; | 37 | 207k | E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...); | 38 | 207k | } | 39 | 202k | return E; | 40 | 202k | } |
Expr.cpp:clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&) Line | Count | Source | 33 | 35.8k | template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) { | 34 | 35.8k | Expr *LastE = nullptr; | 35 | 74.6k | while (E != LastE) { | 36 | 38.8k | LastE = E; | 37 | 38.8k | E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...); | 38 | 38.8k | } | 39 | 35.8k | return E; | 40 | 35.8k | } |
clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)) Line | Count | Source | 33 | 9.42k | template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) { | 34 | 9.42k | Expr *LastE = nullptr; | 35 | 20.9k | while (E != LastE) { | 36 | 11.4k | LastE = E; | 37 | 11.4k | E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...); | 38 | 11.4k | } | 39 | 9.42k | return E; | 40 | 9.42k | } |
|
41 | | |
42 | | template <typename... FnTys> |
43 | 2.17M | const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) { |
44 | 2.17M | return IgnoreExprNodes(const_cast<Expr *>(E), std::forward<FnTys>(Fns)...); |
45 | 2.17M | } |
46 | | |
47 | 200M | inline Expr *IgnoreImplicitCastsSingleStep(Expr *E) { |
48 | 200M | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
49 | 54.5M | return ICE->getSubExpr(); |
50 | | |
51 | 145M | if (auto *FE = dyn_cast<FullExpr>(E)) |
52 | 353k | return FE->getSubExpr(); |
53 | | |
54 | 145M | return E; |
55 | 145M | } |
56 | | |
57 | 178M | inline Expr *IgnoreImplicitCastsExtraSingleStep(Expr *E) { |
58 | | // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in |
59 | | // addition to what IgnoreImpCasts() skips to account for the current |
60 | | // behaviour of IgnoreParenImpCasts(). |
61 | 178M | Expr *SubE = IgnoreImplicitCastsSingleStep(E); |
62 | 178M | if (SubE != E) |
63 | 49.2M | return SubE; |
64 | | |
65 | 129M | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
66 | 321k | return MTE->getSubExpr(); |
67 | | |
68 | 129M | if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) |
69 | 1.68M | return NTTP->getReplacement(); |
70 | | |
71 | 127M | return E; |
72 | 129M | } |
73 | | |
74 | 101M | inline Expr *IgnoreCastsSingleStep(Expr *E) { |
75 | 101M | if (auto *CE = dyn_cast<CastExpr>(E)) |
76 | 16.0M | return CE->getSubExpr(); |
77 | | |
78 | 85.4M | if (auto *FE = dyn_cast<FullExpr>(E)) |
79 | 124k | return FE->getSubExpr(); |
80 | | |
81 | 85.2M | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
82 | 34.0k | return MTE->getSubExpr(); |
83 | | |
84 | 85.2M | if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) |
85 | 315k | return NTTP->getReplacement(); |
86 | | |
87 | 84.9M | return E; |
88 | 85.2M | } |
89 | | |
90 | 69.4k | inline Expr *IgnoreLValueCastsSingleStep(Expr *E) { |
91 | | // Skip what IgnoreCastsSingleStep skips, except that only |
92 | | // lvalue-to-rvalue casts are skipped. |
93 | 69.4k | if (auto *CE = dyn_cast<CastExpr>(E)) |
94 | 3.30k | if (CE->getCastKind() != CK_LValueToRValue) |
95 | 287 | return E; |
96 | | |
97 | 69.1k | return IgnoreCastsSingleStep(E); |
98 | 69.4k | } |
99 | | |
100 | 42.3k | inline Expr *IgnoreBaseCastsSingleStep(Expr *E) { |
101 | 42.3k | if (auto *CE = dyn_cast<CastExpr>(E)) |
102 | 8.53k | if (CE->getCastKind() == CK_DerivedToBase || |
103 | 8.53k | CE->getCastKind() == CK_UncheckedDerivedToBase8.44k || |
104 | 8.53k | CE->getCastKind() == CK_NoOp8.11k ) |
105 | 4.43k | return CE->getSubExpr(); |
106 | | |
107 | 37.8k | return E; |
108 | 42.3k | } |
109 | | |
110 | 8.11M | inline Expr *IgnoreImplicitSingleStep(Expr *E) { |
111 | 8.11M | Expr *SubE = IgnoreImplicitCastsSingleStep(E); |
112 | 8.11M | if (SubE != E) |
113 | 2.29M | return SubE; |
114 | | |
115 | 5.81M | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
116 | 829 | return MTE->getSubExpr(); |
117 | | |
118 | 5.81M | if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E)) |
119 | 191 | return BTE->getSubExpr(); |
120 | | |
121 | 5.81M | return E; |
122 | 5.81M | } |
123 | | |
124 | 217 | inline Expr *IgnoreElidableImplicitConstructorSingleStep(Expr *E) { |
125 | 217 | auto *CCE = dyn_cast<CXXConstructExpr>(E); |
126 | 217 | if (CCE && CCE->isElidable()17 && !isa<CXXTemporaryObjectExpr>(CCE)15 ) { |
127 | 15 | unsigned NumArgs = CCE->getNumArgs(); |
128 | 15 | if ((NumArgs == 1 || |
129 | 15 | (0 NumArgs > 10 && CCE->getArg(1)->isDefaultArgument()0 )) && |
130 | 15 | !CCE->getArg(0)->isDefaultArgument() && !CCE->isListInitialization()) |
131 | 15 | return CCE->getArg(0); |
132 | 15 | } |
133 | 202 | return E; |
134 | 217 | } |
135 | | |
136 | 5.60k | inline Expr *IgnoreImplicitAsWrittenSingleStep(Expr *E) { |
137 | 5.60k | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
138 | 2.27k | return ICE->getSubExprAsWritten(); |
139 | | |
140 | 3.32k | return IgnoreImplicitSingleStep(E); |
141 | 5.60k | } |
142 | | |
143 | 38.8k | inline Expr *IgnoreParensOnlySingleStep(Expr *E) { |
144 | 38.8k | if (auto *PE = dyn_cast<ParenExpr>(E)) |
145 | 5 | return PE->getSubExpr(); |
146 | 38.8k | return E; |
147 | 38.8k | } |
148 | | |
149 | 391M | inline Expr *IgnoreParensSingleStep(Expr *E) { |
150 | 391M | if (auto *PE = dyn_cast<ParenExpr>(E)) |
151 | 12.3M | return PE->getSubExpr(); |
152 | | |
153 | 378M | if (auto *UO = dyn_cast<UnaryOperator>(E)) { |
154 | 6.04M | if (UO->getOpcode() == UO_Extension) |
155 | 236k | return UO->getSubExpr(); |
156 | 6.04M | } |
157 | | |
158 | 372M | else if (auto *GSE = dyn_cast<GenericSelectionExpr>(E)) { |
159 | 1.44k | if (!GSE->isResultDependent()) |
160 | 1.43k | return GSE->getResultExpr(); |
161 | 1.44k | } |
162 | | |
163 | 372M | else if (auto *CE = dyn_cast<ChooseExpr>(E)) { |
164 | 275 | if (!CE->isConditionDependent()) |
165 | 272 | return CE->getChosenSubExpr(); |
166 | 275 | } |
167 | | |
168 | 378M | return E; |
169 | 378M | } |
170 | | |
171 | | } // namespace clang |
172 | | |
173 | | #endif // LLVM_CLANG_AST_IGNOREEXPR_H |