/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/AST/ExprCXX.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- ExprCXX.cpp - (C++) Expression AST Node Implementation -------------===// |
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 implements the subclesses of Expr class declared in ExprCXX.h |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/AST/ExprCXX.h" |
14 | | #include "clang/AST/ASTContext.h" |
15 | | #include "clang/AST/Attr.h" |
16 | | #include "clang/AST/Decl.h" |
17 | | #include "clang/AST/DeclAccessPair.h" |
18 | | #include "clang/AST/DeclBase.h" |
19 | | #include "clang/AST/DeclCXX.h" |
20 | | #include "clang/AST/DeclarationName.h" |
21 | | #include "clang/AST/Expr.h" |
22 | | #include "clang/AST/LambdaCapture.h" |
23 | | #include "clang/AST/NestedNameSpecifier.h" |
24 | | #include "clang/AST/TemplateBase.h" |
25 | | #include "clang/AST/Type.h" |
26 | | #include "clang/AST/TypeLoc.h" |
27 | | #include "clang/Basic/LLVM.h" |
28 | | #include "clang/Basic/OperatorKinds.h" |
29 | | #include "clang/Basic/SourceLocation.h" |
30 | | #include "clang/Basic/Specifiers.h" |
31 | | #include "llvm/ADT/ArrayRef.h" |
32 | | #include "llvm/Support/Casting.h" |
33 | | #include "llvm/Support/ErrorHandling.h" |
34 | | #include <cassert> |
35 | | #include <cstddef> |
36 | | #include <cstring> |
37 | | #include <memory> |
38 | | |
39 | | using namespace clang; |
40 | | |
41 | | //===----------------------------------------------------------------------===// |
42 | | // Child Iterators for iterating over subexpressions/substatements |
43 | | //===----------------------------------------------------------------------===// |
44 | | |
45 | 7 | bool CXXOperatorCallExpr::isInfixBinaryOp() const { |
46 | 7 | // An infix binary operator is any operator with two arguments other than |
47 | 7 | // operator() and operator[]. Note that none of these operators can have |
48 | 7 | // default arguments, so it suffices to check the number of argument |
49 | 7 | // expressions. |
50 | 7 | if (getNumArgs() != 2) |
51 | 0 | return false; |
52 | 7 | |
53 | 7 | switch (getOperator()) { |
54 | 7 | case OO_Call: 2 case OO_Subscript: |
55 | 2 | return false; |
56 | 5 | default: |
57 | 5 | return true; |
58 | 7 | } |
59 | 7 | } |
60 | | |
61 | 2.51k | bool CXXTypeidExpr::isPotentiallyEvaluated() const { |
62 | 2.51k | if (isTypeOperand()) |
63 | 2.13k | return false; |
64 | 382 | |
65 | 382 | // C++11 [expr.typeid]p3: |
66 | 382 | // When typeid is applied to an expression other than a glvalue of |
67 | 382 | // polymorphic class type, [...] the expression is an unevaluated operand. |
68 | 382 | const Expr *E = getExprOperand(); |
69 | 382 | if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl()) |
70 | 190 | if (RD->isPolymorphic() && E->isGLValue()157 ) |
71 | 148 | return true; |
72 | 234 | |
73 | 234 | return false; |
74 | 234 | } |
75 | | |
76 | 576 | QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const { |
77 | 576 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); |
78 | 576 | Qualifiers Quals; |
79 | 576 | return Context.getUnqualifiedArrayType( |
80 | 576 | Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); |
81 | 576 | } |
82 | | |
83 | 6 | QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const { |
84 | 6 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); |
85 | 6 | Qualifiers Quals; |
86 | 6 | return Context.getUnqualifiedArrayType( |
87 | 6 | Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); |
88 | 6 | } |
89 | | |
90 | | // CXXScalarValueInitExpr |
91 | 36.9k | SourceLocation CXXScalarValueInitExpr::getBeginLoc() const { |
92 | 36.9k | return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc()36.7k : getRParenLoc()189 ; |
93 | 36.9k | } |
94 | | |
95 | | // CXXNewExpr |
96 | | CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, |
97 | | FunctionDecl *OperatorDelete, bool ShouldPassAlignment, |
98 | | bool UsualArrayDeleteWantsSize, |
99 | | ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens, |
100 | | Optional<Expr *> ArraySize, |
101 | | InitializationStyle InitializationStyle, |
102 | | Expr *Initializer, QualType Ty, |
103 | | TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, |
104 | | SourceRange DirectInitRange) |
105 | | : Expr(CXXNewExprClass, Ty, VK_RValue, OK_Ordinary, Ty->isDependentType(), |
106 | | Ty->isDependentType(), Ty->isInstantiationDependentType(), |
107 | | Ty->containsUnexpandedParameterPack()), |
108 | | OperatorNew(OperatorNew), OperatorDelete(OperatorDelete), |
109 | | AllocatedTypeInfo(AllocatedTypeInfo), Range(Range), |
110 | 26.2k | DirectInitRange(DirectInitRange) { |
111 | 26.2k | |
112 | 26.2k | assert((Initializer != nullptr || InitializationStyle == NoInit) && |
113 | 26.2k | "Only NoInit can have no initializer!"); |
114 | 26.2k | |
115 | 26.2k | CXXNewExprBits.IsGlobalNew = IsGlobalNew; |
116 | 26.2k | CXXNewExprBits.IsArray = ArraySize.hasValue(); |
117 | 26.2k | CXXNewExprBits.ShouldPassAlignment = ShouldPassAlignment; |
118 | 26.2k | CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize; |
119 | 26.2k | CXXNewExprBits.StoredInitializationStyle = |
120 | 26.2k | Initializer ? InitializationStyle + 123.1k : 03.04k ; |
121 | 26.2k | bool IsParenTypeId = TypeIdParens.isValid(); |
122 | 26.2k | CXXNewExprBits.IsParenTypeId = IsParenTypeId; |
123 | 26.2k | CXXNewExprBits.NumPlacementArgs = PlacementArgs.size(); |
124 | 26.2k | |
125 | 26.2k | if (ArraySize) { |
126 | 2.21k | if (Expr *SizeExpr = *ArraySize) { |
127 | 2.21k | if (SizeExpr->isInstantiationDependent()) |
128 | 696 | ExprBits.InstantiationDependent = true; |
129 | 2.21k | if (SizeExpr->containsUnexpandedParameterPack()) |
130 | 1 | ExprBits.ContainsUnexpandedParameterPack = true; |
131 | 2.21k | } |
132 | 2.21k | |
133 | 2.21k | getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize; |
134 | 2.21k | } |
135 | 26.2k | |
136 | 26.2k | if (Initializer) { |
137 | 23.1k | if (Initializer->isInstantiationDependent()) |
138 | 15.8k | ExprBits.InstantiationDependent = true; |
139 | 23.1k | if (Initializer->containsUnexpandedParameterPack()) |
140 | 2 | ExprBits.ContainsUnexpandedParameterPack = true; |
141 | 23.1k | |
142 | 23.1k | getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer; |
143 | 23.1k | } |
144 | 26.2k | |
145 | 43.4k | for (unsigned I = 0; I != PlacementArgs.size(); ++I17.2k ) { |
146 | 17.2k | if (PlacementArgs[I]->isInstantiationDependent()) |
147 | 12.7k | ExprBits.InstantiationDependent = true; |
148 | 17.2k | if (PlacementArgs[I]->containsUnexpandedParameterPack()) |
149 | 1 | ExprBits.ContainsUnexpandedParameterPack = true; |
150 | 17.2k | |
151 | 17.2k | getTrailingObjects<Stmt *>()[placementNewArgsOffset() + I] = |
152 | 17.2k | PlacementArgs[I]; |
153 | 17.2k | } |
154 | 26.2k | |
155 | 26.2k | if (IsParenTypeId) |
156 | 32 | getTrailingObjects<SourceRange>()[0] = TypeIdParens; |
157 | 26.2k | |
158 | 26.2k | switch (getInitializationStyle()) { |
159 | 26.2k | case CallInit: |
160 | 21.6k | this->Range.setEnd(DirectInitRange.getEnd()); |
161 | 21.6k | break; |
162 | 26.2k | case ListInit: |
163 | 203 | this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); |
164 | 203 | break; |
165 | 26.2k | default: |
166 | 4.30k | if (IsParenTypeId) |
167 | 15 | this->Range.setEnd(TypeIdParens.getEnd()); |
168 | 4.30k | break; |
169 | 26.2k | } |
170 | 26.2k | } |
171 | | |
172 | | CXXNewExpr::CXXNewExpr(EmptyShell Empty, bool IsArray, |
173 | | unsigned NumPlacementArgs, bool IsParenTypeId) |
174 | 18 | : Expr(CXXNewExprClass, Empty) { |
175 | 18 | CXXNewExprBits.IsArray = IsArray; |
176 | 18 | CXXNewExprBits.NumPlacementArgs = NumPlacementArgs; |
177 | 18 | CXXNewExprBits.IsParenTypeId = IsParenTypeId; |
178 | 18 | } |
179 | | |
180 | | CXXNewExpr * |
181 | | CXXNewExpr::Create(const ASTContext &Ctx, bool IsGlobalNew, |
182 | | FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, |
183 | | bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, |
184 | | ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens, |
185 | | Optional<Expr *> ArraySize, |
186 | | InitializationStyle InitializationStyle, Expr *Initializer, |
187 | | QualType Ty, TypeSourceInfo *AllocatedTypeInfo, |
188 | 26.2k | SourceRange Range, SourceRange DirectInitRange) { |
189 | 26.2k | bool IsArray = ArraySize.hasValue(); |
190 | 26.2k | bool HasInit = Initializer != nullptr; |
191 | 26.2k | unsigned NumPlacementArgs = PlacementArgs.size(); |
192 | 26.2k | bool IsParenTypeId = TypeIdParens.isValid(); |
193 | 26.2k | void *Mem = |
194 | 26.2k | Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>( |
195 | 26.2k | IsArray + HasInit + NumPlacementArgs, IsParenTypeId), |
196 | 26.2k | alignof(CXXNewExpr)); |
197 | 26.2k | return new (Mem) |
198 | 26.2k | CXXNewExpr(IsGlobalNew, OperatorNew, OperatorDelete, ShouldPassAlignment, |
199 | 26.2k | UsualArrayDeleteWantsSize, PlacementArgs, TypeIdParens, |
200 | 26.2k | ArraySize, InitializationStyle, Initializer, Ty, |
201 | 26.2k | AllocatedTypeInfo, Range, DirectInitRange); |
202 | 26.2k | } |
203 | | |
204 | | CXXNewExpr *CXXNewExpr::CreateEmpty(const ASTContext &Ctx, bool IsArray, |
205 | | bool HasInit, unsigned NumPlacementArgs, |
206 | 18 | bool IsParenTypeId) { |
207 | 18 | void *Mem = |
208 | 18 | Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>( |
209 | 18 | IsArray + HasInit + NumPlacementArgs, IsParenTypeId), |
210 | 18 | alignof(CXXNewExpr)); |
211 | 18 | return new (Mem) |
212 | 18 | CXXNewExpr(EmptyShell(), IsArray, NumPlacementArgs, IsParenTypeId); |
213 | 18 | } |
214 | | |
215 | 5.05k | bool CXXNewExpr::shouldNullCheckAllocation() const { |
216 | 5.05k | return getOperatorNew() |
217 | 5.05k | ->getType() |
218 | 5.05k | ->castAs<FunctionProtoType>() |
219 | 5.05k | ->isNothrow() && |
220 | 5.05k | !getOperatorNew()->isReservedGlobalPlacementOperator()1.42k ; |
221 | 5.05k | } |
222 | | |
223 | | // CXXDeleteExpr |
224 | 3.09k | QualType CXXDeleteExpr::getDestroyedType() const { |
225 | 3.09k | const Expr *Arg = getArgument(); |
226 | 3.09k | |
227 | 3.09k | // For a destroying operator delete, we may have implicitly converted the |
228 | 3.09k | // pointer type to the type of the parameter of the 'operator delete' |
229 | 3.09k | // function. |
230 | 3.09k | while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) { |
231 | 2.50k | if (ICE->getCastKind() == CK_DerivedToBase || |
232 | 2.50k | ICE->getCastKind() == CK_UncheckedDerivedToBase2.49k || |
233 | 2.50k | ICE->getCastKind() == CK_NoOp2.49k ) { |
234 | 4 | assert((ICE->getCastKind() == CK_NoOp || |
235 | 4 | getOperatorDelete()->isDestroyingOperatorDelete()) && |
236 | 4 | "only a destroying operator delete can have a converted arg"); |
237 | 4 | Arg = ICE->getSubExpr(); |
238 | 4 | } else |
239 | 2.49k | break; |
240 | 2.50k | } |
241 | 3.09k | |
242 | 3.09k | // The type-to-delete may not be a pointer if it's a dependent type. |
243 | 3.09k | const QualType ArgType = Arg->getType(); |
244 | 3.09k | |
245 | 3.09k | if (ArgType->isDependentType() && !ArgType->isPointerType()3 ) |
246 | 2 | return QualType(); |
247 | 3.08k | |
248 | 3.08k | return ArgType->getAs<PointerType>()->getPointeeType(); |
249 | 3.08k | } |
250 | | |
251 | | // CXXPseudoDestructorExpr |
252 | | PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) |
253 | 7.99k | : Type(Info) { |
254 | 7.99k | Location = Info->getTypeLoc().getLocalSourceRange().getBegin(); |
255 | 7.99k | } |
256 | | |
257 | | CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(const ASTContext &Context, |
258 | | Expr *Base, bool isArrow, SourceLocation OperatorLoc, |
259 | | NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, |
260 | | SourceLocation ColonColonLoc, SourceLocation TildeLoc, |
261 | | PseudoDestructorTypeStorage DestroyedType) |
262 | | : Expr(CXXPseudoDestructorExprClass, |
263 | | Context.BoundMemberTy, |
264 | | VK_RValue, OK_Ordinary, |
265 | | /*isTypeDependent=*/(Base->isTypeDependent() || |
266 | | (DestroyedType.getTypeSourceInfo() && |
267 | | DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), |
268 | | /*isValueDependent=*/Base->isValueDependent(), |
269 | | (Base->isInstantiationDependent() || |
270 | | (QualifierLoc && |
271 | | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) || |
272 | | (ScopeType && |
273 | | ScopeType->getType()->isInstantiationDependentType()) || |
274 | | (DestroyedType.getTypeSourceInfo() && |
275 | | DestroyedType.getTypeSourceInfo()->getType() |
276 | | ->isInstantiationDependentType())), |
277 | | // ContainsUnexpandedParameterPack |
278 | | (Base->containsUnexpandedParameterPack() || |
279 | | (QualifierLoc && |
280 | | QualifierLoc.getNestedNameSpecifier() |
281 | | ->containsUnexpandedParameterPack()) || |
282 | | (ScopeType && |
283 | | ScopeType->getType()->containsUnexpandedParameterPack()) || |
284 | | (DestroyedType.getTypeSourceInfo() && |
285 | | DestroyedType.getTypeSourceInfo()->getType() |
286 | | ->containsUnexpandedParameterPack()))), |
287 | | Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), |
288 | | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
289 | | ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), |
290 | 6.82k | DestroyedType(DestroyedType) {} |
291 | | |
292 | 5.34k | QualType CXXPseudoDestructorExpr::getDestroyedType() const { |
293 | 5.34k | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
294 | 5.34k | return TInfo->getType(); |
295 | 0 | |
296 | 0 | return QualType(); |
297 | 0 | } |
298 | | |
299 | 842 | SourceLocation CXXPseudoDestructorExpr::getEndLoc() const { |
300 | 842 | SourceLocation End = DestroyedType.getLocation(); |
301 | 842 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
302 | 842 | End = TInfo->getTypeLoc().getLocalSourceRange().getEnd(); |
303 | 842 | return End; |
304 | 842 | } |
305 | | |
306 | | // UnresolvedLookupExpr |
307 | | UnresolvedLookupExpr::UnresolvedLookupExpr( |
308 | | const ASTContext &Context, CXXRecordDecl *NamingClass, |
309 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
310 | | const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, |
311 | | const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, |
312 | | UnresolvedSetIterator End) |
313 | | : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc, |
314 | | TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false, |
315 | | false, false), |
316 | 2.39M | NamingClass(NamingClass) { |
317 | 2.39M | UnresolvedLookupExprBits.RequiresADL = RequiresADL; |
318 | 2.39M | UnresolvedLookupExprBits.Overloaded = Overloaded; |
319 | 2.39M | } |
320 | | |
321 | | UnresolvedLookupExpr::UnresolvedLookupExpr(EmptyShell Empty, |
322 | | unsigned NumResults, |
323 | | bool HasTemplateKWAndArgsInfo) |
324 | | : OverloadExpr(UnresolvedLookupExprClass, Empty, NumResults, |
325 | 839 | HasTemplateKWAndArgsInfo) {} |
326 | | |
327 | | UnresolvedLookupExpr *UnresolvedLookupExpr::Create( |
328 | | const ASTContext &Context, CXXRecordDecl *NamingClass, |
329 | | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
330 | | bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin, |
331 | 1.95M | UnresolvedSetIterator End) { |
332 | 1.95M | unsigned NumResults = End - Begin; |
333 | 1.95M | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
334 | 1.95M | TemplateArgumentLoc>(NumResults, 0, 0); |
335 | 1.95M | void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr)); |
336 | 1.95M | return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc, |
337 | 1.95M | SourceLocation(), NameInfo, RequiresADL, |
338 | 1.95M | Overloaded, nullptr, Begin, End); |
339 | 1.95M | } |
340 | | |
341 | | UnresolvedLookupExpr *UnresolvedLookupExpr::Create( |
342 | | const ASTContext &Context, CXXRecordDecl *NamingClass, |
343 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
344 | | const DeclarationNameInfo &NameInfo, bool RequiresADL, |
345 | | const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin, |
346 | 438k | UnresolvedSetIterator End) { |
347 | 438k | assert(Args || TemplateKWLoc.isValid()); |
348 | 438k | unsigned NumResults = End - Begin; |
349 | 438k | unsigned NumTemplateArgs = Args ? Args->size()438k : 014 ; |
350 | 438k | unsigned Size = |
351 | 438k | totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
352 | 438k | TemplateArgumentLoc>(NumResults, 1, NumTemplateArgs); |
353 | 438k | void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr)); |
354 | 438k | return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc, |
355 | 438k | TemplateKWLoc, NameInfo, RequiresADL, |
356 | 438k | /*Overloaded*/ true, Args, Begin, End); |
357 | 438k | } |
358 | | |
359 | | UnresolvedLookupExpr *UnresolvedLookupExpr::CreateEmpty( |
360 | | const ASTContext &Context, unsigned NumResults, |
361 | 839 | bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) { |
362 | 839 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
363 | 839 | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
364 | 839 | TemplateArgumentLoc>( |
365 | 839 | NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs); |
366 | 839 | void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr)); |
367 | 839 | return new (Mem) |
368 | 839 | UnresolvedLookupExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo); |
369 | 839 | } |
370 | | |
371 | | OverloadExpr::OverloadExpr(StmtClass SC, const ASTContext &Context, |
372 | | NestedNameSpecifierLoc QualifierLoc, |
373 | | SourceLocation TemplateKWLoc, |
374 | | const DeclarationNameInfo &NameInfo, |
375 | | const TemplateArgumentListInfo *TemplateArgs, |
376 | | UnresolvedSetIterator Begin, |
377 | | UnresolvedSetIterator End, bool KnownDependent, |
378 | | bool KnownInstantiationDependent, |
379 | | bool KnownContainsUnexpandedParameterPack) |
380 | | : Expr( |
381 | | SC, Context.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent, |
382 | | KnownDependent, |
383 | | (KnownInstantiationDependent || NameInfo.isInstantiationDependent() || |
384 | | (QualifierLoc && |
385 | | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
386 | | (KnownContainsUnexpandedParameterPack || |
387 | | NameInfo.containsUnexpandedParameterPack() || |
388 | | (QualifierLoc && QualifierLoc.getNestedNameSpecifier() |
389 | | ->containsUnexpandedParameterPack()))), |
390 | 2.77M | NameInfo(NameInfo), QualifierLoc(QualifierLoc) { |
391 | 2.77M | unsigned NumResults = End - Begin; |
392 | 2.77M | OverloadExprBits.NumResults = NumResults; |
393 | 2.77M | OverloadExprBits.HasTemplateKWAndArgsInfo = |
394 | 2.77M | (TemplateArgs != nullptr ) || TemplateKWLoc.isValid()2.33M ; |
395 | 2.77M | |
396 | 2.77M | if (NumResults) { |
397 | 2.75M | // Determine whether this expression is type-dependent. |
398 | 18.6M | for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I15.9M ) { |
399 | 15.9M | if ((*I)->getDeclContext()->isDependentContext() || |
400 | 15.9M | isa<UnresolvedUsingValueDecl>(*I)15.1M ) { |
401 | 724k | ExprBits.TypeDependent = true; |
402 | 724k | ExprBits.ValueDependent = true; |
403 | 724k | ExprBits.InstantiationDependent = true; |
404 | 724k | } |
405 | 15.9M | } |
406 | 2.75M | |
407 | 2.75M | // Copy the results to the trailing array past UnresolvedLookupExpr |
408 | 2.75M | // or UnresolvedMemberExpr. |
409 | 2.75M | DeclAccessPair *Results = getTrailingResults(); |
410 | 2.75M | memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair)); |
411 | 2.75M | } |
412 | 2.77M | |
413 | 2.77M | // If we have explicit template arguments, check for dependent |
414 | 2.77M | // template arguments and whether they contain any unexpanded pack |
415 | 2.77M | // expansions. |
416 | 2.77M | if (TemplateArgs) { |
417 | 441k | bool Dependent = false; |
418 | 441k | bool InstantiationDependent = false; |
419 | 441k | bool ContainsUnexpandedParameterPack = false; |
420 | 441k | getTrailingASTTemplateKWAndArgsInfo()->initializeFrom( |
421 | 441k | TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(), |
422 | 441k | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
423 | 441k | |
424 | 441k | if (Dependent) { |
425 | 224k | ExprBits.TypeDependent = true; |
426 | 224k | ExprBits.ValueDependent = true; |
427 | 224k | } |
428 | 441k | if (InstantiationDependent) |
429 | 224k | ExprBits.InstantiationDependent = true; |
430 | 441k | if (ContainsUnexpandedParameterPack) |
431 | 44.9k | ExprBits.ContainsUnexpandedParameterPack = true; |
432 | 2.33M | } else if (TemplateKWLoc.isValid()) { |
433 | 56 | getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
434 | 56 | } |
435 | 2.77M | |
436 | 2.77M | if (isTypeDependent()) |
437 | 447k | setType(Context.DependentTy); |
438 | 2.77M | } |
439 | | |
440 | | OverloadExpr::OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults, |
441 | | bool HasTemplateKWAndArgsInfo) |
442 | 845 | : Expr(SC, Empty) { |
443 | 845 | OverloadExprBits.NumResults = NumResults; |
444 | 845 | OverloadExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
445 | 845 | } |
446 | | |
447 | | // DependentScopeDeclRefExpr |
448 | | DependentScopeDeclRefExpr::DependentScopeDeclRefExpr( |
449 | | QualType Ty, NestedNameSpecifierLoc QualifierLoc, |
450 | | SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, |
451 | | const TemplateArgumentListInfo *Args) |
452 | | : Expr( |
453 | | DependentScopeDeclRefExprClass, Ty, VK_LValue, OK_Ordinary, true, |
454 | | true, |
455 | | (NameInfo.isInstantiationDependent() || |
456 | | (QualifierLoc && |
457 | | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
458 | | (NameInfo.containsUnexpandedParameterPack() || |
459 | | (QualifierLoc && QualifierLoc.getNestedNameSpecifier() |
460 | | ->containsUnexpandedParameterPack()))), |
461 | 1.08M | QualifierLoc(QualifierLoc), NameInfo(NameInfo) { |
462 | 1.08M | DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo = |
463 | 1.08M | (Args != nullptr) || TemplateKWLoc.isValid()1.05M ; |
464 | 1.08M | if (Args) { |
465 | 29.0k | bool Dependent = true; |
466 | 29.0k | bool InstantiationDependent = true; |
467 | 29.0k | bool ContainsUnexpandedParameterPack |
468 | 29.0k | = ExprBits.ContainsUnexpandedParameterPack; |
469 | 29.0k | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
470 | 29.0k | TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(), |
471 | 29.0k | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
472 | 29.0k | ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; |
473 | 1.05M | } else if (TemplateKWLoc.isValid()) { |
474 | 9 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
475 | 9 | TemplateKWLoc); |
476 | 9 | } |
477 | 1.08M | } |
478 | | |
479 | | DependentScopeDeclRefExpr *DependentScopeDeclRefExpr::Create( |
480 | | const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, |
481 | | SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, |
482 | 1.08M | const TemplateArgumentListInfo *Args) { |
483 | 1.08M | assert(QualifierLoc && "should be created for dependent qualifiers"); |
484 | 1.08M | bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid()1.05M ; |
485 | 1.08M | std::size_t Size = |
486 | 1.08M | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
487 | 1.08M | HasTemplateKWAndArgsInfo, Args ? Args->size()29.0k : 01.05M ); |
488 | 1.08M | void *Mem = Context.Allocate(Size); |
489 | 1.08M | return new (Mem) DependentScopeDeclRefExpr(Context.DependentTy, QualifierLoc, |
490 | 1.08M | TemplateKWLoc, NameInfo, Args); |
491 | 1.08M | } |
492 | | |
493 | | DependentScopeDeclRefExpr * |
494 | | DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &Context, |
495 | | bool HasTemplateKWAndArgsInfo, |
496 | 74 | unsigned NumTemplateArgs) { |
497 | 74 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
498 | 74 | std::size_t Size = |
499 | 74 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
500 | 74 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
501 | 74 | void *Mem = Context.Allocate(Size); |
502 | 74 | auto *E = new (Mem) DependentScopeDeclRefExpr( |
503 | 74 | QualType(), NestedNameSpecifierLoc(), SourceLocation(), |
504 | 74 | DeclarationNameInfo(), nullptr); |
505 | 74 | E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo = |
506 | 74 | HasTemplateKWAndArgsInfo; |
507 | 74 | return E; |
508 | 74 | } |
509 | | |
510 | 973k | SourceLocation CXXConstructExpr::getBeginLoc() const { |
511 | 973k | if (isa<CXXTemporaryObjectExpr>(this)) |
512 | 2.24k | return cast<CXXTemporaryObjectExpr>(this)->getBeginLoc(); |
513 | 971k | return getLocation(); |
514 | 971k | } |
515 | | |
516 | 76.7k | SourceLocation CXXConstructExpr::getEndLoc() const { |
517 | 76.7k | if (isa<CXXTemporaryObjectExpr>(this)) |
518 | 0 | return cast<CXXTemporaryObjectExpr>(this)->getEndLoc(); |
519 | 76.7k | |
520 | 76.7k | if (ParenOrBraceRange.isValid()) |
521 | 17.6k | return ParenOrBraceRange.getEnd(); |
522 | 59.0k | |
523 | 59.0k | SourceLocation End = getLocation(); |
524 | 66.4k | for (unsigned I = getNumArgs(); I > 0; --I7.39k ) { |
525 | 46.9k | const Expr *Arg = getArg(I-1); |
526 | 46.9k | if (!Arg->isDefaultArgument()) { |
527 | 39.5k | SourceLocation NewEnd = Arg->getEndLoc(); |
528 | 39.5k | if (NewEnd.isValid()) { |
529 | 39.5k | End = NewEnd; |
530 | 39.5k | break; |
531 | 39.5k | } |
532 | 39.5k | } |
533 | 46.9k | } |
534 | 59.0k | |
535 | 59.0k | return End; |
536 | 59.0k | } |
537 | | |
538 | | CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind, |
539 | | Expr *Fn, ArrayRef<Expr *> Args, |
540 | | QualType Ty, ExprValueKind VK, |
541 | | SourceLocation OperatorLoc, |
542 | | FPOptions FPFeatures, |
543 | | ADLCallKind UsesADL) |
544 | | : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, |
545 | 903k | OperatorLoc, /*MinNumArgs=*/0, UsesADL) { |
546 | 903k | CXXOperatorCallExprBits.OperatorKind = OpKind; |
547 | 903k | CXXOperatorCallExprBits.FPFeatures = FPFeatures.getInt(); |
548 | 903k | assert( |
549 | 903k | (CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) && |
550 | 903k | "OperatorKind overflow!"); |
551 | 903k | assert((CXXOperatorCallExprBits.FPFeatures == FPFeatures.getInt()) && |
552 | 903k | "FPFeatures overflow!"); |
553 | 903k | Range = getSourceRangeImpl(); |
554 | 903k | } |
555 | | |
556 | | CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty) |
557 | 1.15k | : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {} |
558 | | |
559 | | CXXOperatorCallExpr *CXXOperatorCallExpr::Create( |
560 | | const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, |
561 | | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
562 | 903k | SourceLocation OperatorLoc, FPOptions FPFeatures, ADLCallKind UsesADL) { |
563 | 903k | // Allocate storage for the trailing objects of CallExpr. |
564 | 903k | unsigned NumArgs = Args.size(); |
565 | 903k | unsigned SizeOfTrailingObjects = |
566 | 903k | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); |
567 | 903k | void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects, |
568 | 903k | alignof(CXXOperatorCallExpr)); |
569 | 903k | return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc, |
570 | 903k | FPFeatures, UsesADL); |
571 | 903k | } |
572 | | |
573 | | CXXOperatorCallExpr *CXXOperatorCallExpr::CreateEmpty(const ASTContext &Ctx, |
574 | | unsigned NumArgs, |
575 | 1.15k | EmptyShell Empty) { |
576 | 1.15k | // Allocate storage for the trailing objects of CallExpr. |
577 | 1.15k | unsigned SizeOfTrailingObjects = |
578 | 1.15k | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); |
579 | 1.15k | void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects, |
580 | 1.15k | alignof(CXXOperatorCallExpr)); |
581 | 1.15k | return new (Mem) CXXOperatorCallExpr(NumArgs, Empty); |
582 | 1.15k | } |
583 | | |
584 | 903k | SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { |
585 | 903k | OverloadedOperatorKind Kind = getOperator(); |
586 | 903k | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus897k ) { |
587 | 6.90k | if (getNumArgs() == 1) |
588 | 6.59k | // Prefix operator |
589 | 6.59k | return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc()); |
590 | 314 | else |
591 | 314 | // Postfix operator |
592 | 314 | return SourceRange(getArg(0)->getBeginLoc(), getOperatorLoc()); |
593 | 896k | } else if (Kind == OO_Arrow) { |
594 | 2.47k | return getArg(0)->getSourceRange(); |
595 | 894k | } else if (Kind == OO_Call) { |
596 | 22.2k | return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc()); |
597 | 872k | } else if (Kind == OO_Subscript) { |
598 | 30.9k | return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc()); |
599 | 841k | } else if (getNumArgs() == 1) { |
600 | 28.2k | return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc()); |
601 | 812k | } else if (getNumArgs() == 2) { |
602 | 812k | return SourceRange(getArg(0)->getBeginLoc(), getArg(1)->getEndLoc()); |
603 | 812k | } else { |
604 | 0 | return getOperatorLoc(); |
605 | 0 | } |
606 | 903k | } |
607 | | |
608 | | CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args, |
609 | | QualType Ty, ExprValueKind VK, |
610 | | SourceLocation RP, unsigned MinNumArgs) |
611 | | : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP, |
612 | 564k | MinNumArgs, NotADL) {} |
613 | | |
614 | | CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty) |
615 | 1.11k | : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {} |
616 | | |
617 | | CXXMemberCallExpr *CXXMemberCallExpr::Create(const ASTContext &Ctx, Expr *Fn, |
618 | | ArrayRef<Expr *> Args, QualType Ty, |
619 | | ExprValueKind VK, |
620 | | SourceLocation RP, |
621 | 564k | unsigned MinNumArgs) { |
622 | 564k | // Allocate storage for the trailing objects of CallExpr. |
623 | 564k | unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs); |
624 | 564k | unsigned SizeOfTrailingObjects = |
625 | 564k | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); |
626 | 564k | void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects, |
627 | 564k | alignof(CXXMemberCallExpr)); |
628 | 564k | return new (Mem) CXXMemberCallExpr(Fn, Args, Ty, VK, RP, MinNumArgs); |
629 | 564k | } |
630 | | |
631 | | CXXMemberCallExpr *CXXMemberCallExpr::CreateEmpty(const ASTContext &Ctx, |
632 | | unsigned NumArgs, |
633 | 1.11k | EmptyShell Empty) { |
634 | 1.11k | // Allocate storage for the trailing objects of CallExpr. |
635 | 1.11k | unsigned SizeOfTrailingObjects = |
636 | 1.11k | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); |
637 | 1.11k | void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects, |
638 | 1.11k | alignof(CXXMemberCallExpr)); |
639 | 1.11k | return new (Mem) CXXMemberCallExpr(NumArgs, Empty); |
640 | 1.11k | } |
641 | | |
642 | 894k | Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { |
643 | 894k | const Expr *Callee = getCallee()->IgnoreParens(); |
644 | 894k | if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee)) |
645 | 894k | return MemExpr->getBase(); |
646 | 39 | if (const auto *BO = dyn_cast<BinaryOperator>(Callee)) |
647 | 39 | if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI24 ) |
648 | 39 | return BO->getLHS(); |
649 | 0 | |
650 | 0 | // FIXME: Will eventually need to cope with member pointers. |
651 | 0 | return nullptr; |
652 | 0 | } |
653 | | |
654 | 54 | QualType CXXMemberCallExpr::getObjectType() const { |
655 | 54 | QualType Ty = getImplicitObjectArgument()->getType(); |
656 | 54 | if (Ty->isPointerType()) |
657 | 52 | Ty = Ty->getPointeeType(); |
658 | 54 | return Ty; |
659 | 54 | } |
660 | | |
661 | 598k | CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { |
662 | 598k | if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
663 | 598k | return cast<CXXMethodDecl>(MemExpr->getMemberDecl()); |
664 | 4 | |
665 | 4 | // FIXME: Will eventually need to cope with member pointers. |
666 | 4 | return nullptr; |
667 | 4 | } |
668 | | |
669 | 0 | CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const { |
670 | 0 | Expr* ThisArg = getImplicitObjectArgument(); |
671 | 0 | if (!ThisArg) |
672 | 0 | return nullptr; |
673 | 0 | |
674 | 0 | if (ThisArg->getType()->isAnyPointerType()) |
675 | 0 | return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl(); |
676 | 0 | |
677 | 0 | return ThisArg->getType()->getAsCXXRecordDecl(); |
678 | 0 | } |
679 | | |
680 | | //===----------------------------------------------------------------------===// |
681 | | // Named casts |
682 | | //===----------------------------------------------------------------------===// |
683 | | |
684 | | /// getCastName - Get the name of the C++ cast being used, e.g., |
685 | | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
686 | | /// "const_cast". The returned pointer must not be freed. |
687 | 51 | const char *CXXNamedCastExpr::getCastName() const { |
688 | 51 | switch (getStmtClass()) { |
689 | 51 | case CXXStaticCastExprClass: return "static_cast"26 ; |
690 | 51 | case CXXDynamicCastExprClass: return "dynamic_cast"8 ; |
691 | 51 | case CXXReinterpretCastExprClass: return "reinterpret_cast"9 ; |
692 | 51 | case CXXConstCastExprClass: return "const_cast"8 ; |
693 | 51 | default: return "<invalid cast>"0 ; |
694 | 51 | } |
695 | 51 | } |
696 | | |
697 | | CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T, |
698 | | ExprValueKind VK, |
699 | | CastKind K, Expr *Op, |
700 | | const CXXCastPath *BasePath, |
701 | | TypeSourceInfo *WrittenTy, |
702 | | SourceLocation L, |
703 | | SourceLocation RParenLoc, |
704 | 206k | SourceRange AngleBrackets) { |
705 | 206k | unsigned PathSize = (BasePath ? BasePath->size() : 00 ); |
706 | 206k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
707 | 206k | auto *E = |
708 | 206k | new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
709 | 206k | RParenLoc, AngleBrackets); |
710 | 206k | if (PathSize) |
711 | 3.88k | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
712 | 3.88k | E->getTrailingObjects<CXXBaseSpecifier *>()); |
713 | 206k | return E; |
714 | 206k | } |
715 | | |
716 | | CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C, |
717 | 43 | unsigned PathSize) { |
718 | 43 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
719 | 43 | return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize); |
720 | 43 | } |
721 | | |
722 | | CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T, |
723 | | ExprValueKind VK, |
724 | | CastKind K, Expr *Op, |
725 | | const CXXCastPath *BasePath, |
726 | | TypeSourceInfo *WrittenTy, |
727 | | SourceLocation L, |
728 | | SourceLocation RParenLoc, |
729 | 2.03k | SourceRange AngleBrackets) { |
730 | 2.03k | unsigned PathSize = (BasePath ? BasePath->size() : 00 ); |
731 | 2.03k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
732 | 2.03k | auto *E = |
733 | 2.03k | new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
734 | 2.03k | RParenLoc, AngleBrackets); |
735 | 2.03k | if (PathSize) |
736 | 57 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
737 | 57 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
738 | 2.03k | return E; |
739 | 2.03k | } |
740 | | |
741 | | CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C, |
742 | 2 | unsigned PathSize) { |
743 | 2 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
744 | 2 | return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); |
745 | 2 | } |
746 | | |
747 | | /// isAlwaysNull - Return whether the result of the dynamic_cast is proven |
748 | | /// to always be null. For example: |
749 | | /// |
750 | | /// struct A { }; |
751 | | /// struct B final : A { }; |
752 | | /// struct C { }; |
753 | | /// |
754 | | /// C *f(B* b) { return dynamic_cast<C*>(b); } |
755 | | bool CXXDynamicCastExpr::isAlwaysNull() const |
756 | 1.12k | { |
757 | 1.12k | QualType SrcType = getSubExpr()->getType(); |
758 | 1.12k | QualType DestType = getType(); |
759 | 1.12k | |
760 | 1.12k | if (const auto *SrcPTy = SrcType->getAs<PointerType>()) { |
761 | 1.10k | SrcType = SrcPTy->getPointeeType(); |
762 | 1.10k | DestType = DestType->castAs<PointerType>()->getPointeeType(); |
763 | 1.10k | } |
764 | 1.12k | |
765 | 1.12k | if (DestType->isVoidType()) |
766 | 5 | return false; |
767 | 1.11k | |
768 | 1.11k | const auto *SrcRD = |
769 | 1.11k | cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl()); |
770 | 1.11k | |
771 | 1.11k | if (!SrcRD->hasAttr<FinalAttr>()) |
772 | 1.11k | return false; |
773 | 2 | |
774 | 2 | const auto *DestRD = |
775 | 2 | cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl()); |
776 | 2 | |
777 | 2 | return !DestRD->isDerivedFrom(SrcRD); |
778 | 2 | } |
779 | | |
780 | | CXXReinterpretCastExpr * |
781 | | CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T, |
782 | | ExprValueKind VK, CastKind K, Expr *Op, |
783 | | const CXXCastPath *BasePath, |
784 | | TypeSourceInfo *WrittenTy, SourceLocation L, |
785 | | SourceLocation RParenLoc, |
786 | 67.0k | SourceRange AngleBrackets) { |
787 | 67.0k | unsigned PathSize = (BasePath ? BasePath->size()3 : 067.0k ); |
788 | 67.0k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
789 | 67.0k | auto *E = |
790 | 67.0k | new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
791 | 67.0k | RParenLoc, AngleBrackets); |
792 | 67.0k | if (PathSize) |
793 | 0 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
794 | 0 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
795 | 67.0k | return E; |
796 | 67.0k | } |
797 | | |
798 | | CXXReinterpretCastExpr * |
799 | 14 | CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { |
800 | 14 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
801 | 14 | return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); |
802 | 14 | } |
803 | | |
804 | | CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T, |
805 | | ExprValueKind VK, Expr *Op, |
806 | | TypeSourceInfo *WrittenTy, |
807 | | SourceLocation L, |
808 | | SourceLocation RParenLoc, |
809 | 10.5k | SourceRange AngleBrackets) { |
810 | 10.5k | return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets); |
811 | 10.5k | } |
812 | | |
813 | 2 | CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) { |
814 | 2 | return new (C) CXXConstCastExpr(EmptyShell()); |
815 | 2 | } |
816 | | |
817 | | CXXFunctionalCastExpr * |
818 | | CXXFunctionalCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, |
819 | | TypeSourceInfo *Written, CastKind K, Expr *Op, |
820 | | const CXXCastPath *BasePath, |
821 | 86.9k | SourceLocation L, SourceLocation R) { |
822 | 86.9k | unsigned PathSize = (BasePath ? BasePath->size()81.1k : 05.71k ); |
823 | 86.9k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
824 | 86.9k | auto *E = |
825 | 86.9k | new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R); |
826 | 86.9k | if (PathSize) |
827 | 9 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
828 | 9 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
829 | 86.9k | return E; |
830 | 86.9k | } |
831 | | |
832 | | CXXFunctionalCastExpr * |
833 | 34 | CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { |
834 | 34 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
835 | 34 | return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize); |
836 | 34 | } |
837 | | |
838 | 446k | SourceLocation CXXFunctionalCastExpr::getBeginLoc() const { |
839 | 446k | return getTypeInfoAsWritten()->getTypeLoc().getBeginLoc(); |
840 | 446k | } |
841 | | |
842 | 17.6k | SourceLocation CXXFunctionalCastExpr::getEndLoc() const { |
843 | 17.6k | return RParenLoc.isValid() ? RParenLoc16.6k : getSubExpr()->getEndLoc()931 ; |
844 | 17.6k | } |
845 | | |
846 | | UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args, |
847 | | QualType Ty, ExprValueKind VK, |
848 | | SourceLocation LitEndLoc, |
849 | | SourceLocation SuffixLoc) |
850 | | : CallExpr(UserDefinedLiteralClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, |
851 | | LitEndLoc, /*MinNumArgs=*/0, NotADL), |
852 | 175 | UDSuffixLoc(SuffixLoc) {} |
853 | | |
854 | | UserDefinedLiteral::UserDefinedLiteral(unsigned NumArgs, EmptyShell Empty) |
855 | 1 | : CallExpr(UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs, Empty) {} |
856 | | |
857 | | UserDefinedLiteral *UserDefinedLiteral::Create(const ASTContext &Ctx, Expr *Fn, |
858 | | ArrayRef<Expr *> Args, |
859 | | QualType Ty, ExprValueKind VK, |
860 | | SourceLocation LitEndLoc, |
861 | 175 | SourceLocation SuffixLoc) { |
862 | 175 | // Allocate storage for the trailing objects of CallExpr. |
863 | 175 | unsigned NumArgs = Args.size(); |
864 | 175 | unsigned SizeOfTrailingObjects = |
865 | 175 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); |
866 | 175 | void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects, |
867 | 175 | alignof(UserDefinedLiteral)); |
868 | 175 | return new (Mem) UserDefinedLiteral(Fn, Args, Ty, VK, LitEndLoc, SuffixLoc); |
869 | 175 | } |
870 | | |
871 | | UserDefinedLiteral *UserDefinedLiteral::CreateEmpty(const ASTContext &Ctx, |
872 | | unsigned NumArgs, |
873 | 1 | EmptyShell Empty) { |
874 | 1 | // Allocate storage for the trailing objects of CallExpr. |
875 | 1 | unsigned SizeOfTrailingObjects = |
876 | 1 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs); |
877 | 1 | void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects, |
878 | 1 | alignof(UserDefinedLiteral)); |
879 | 1 | return new (Mem) UserDefinedLiteral(NumArgs, Empty); |
880 | 1 | } |
881 | | |
882 | | UserDefinedLiteral::LiteralOperatorKind |
883 | 7.76k | UserDefinedLiteral::getLiteralOperatorKind() const { |
884 | 7.76k | if (getNumArgs() == 0) |
885 | 455 | return LOK_Template; |
886 | 7.31k | if (getNumArgs() == 2) |
887 | 2.09k | return LOK_String; |
888 | 5.21k | |
889 | 5.21k | assert(getNumArgs() == 1 && "unexpected #args in literal operator call"); |
890 | 5.21k | QualType ParamTy = |
891 | 5.21k | cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType(); |
892 | 5.21k | if (ParamTy->isPointerType()) |
893 | 467 | return LOK_Raw; |
894 | 4.75k | if (ParamTy->isAnyCharacterType()) |
895 | 1.59k | return LOK_Character; |
896 | 3.16k | if (ParamTy->isIntegerType()) |
897 | 1.53k | return LOK_Integer; |
898 | 1.62k | if (ParamTy->isFloatingType()) |
899 | 1.62k | return LOK_Floating; |
900 | 0 | |
901 | 0 | llvm_unreachable("unknown kind of literal operator"); |
902 | 0 | } |
903 | | |
904 | 9 | Expr *UserDefinedLiteral::getCookedLiteral() { |
905 | | #ifndef NDEBUG |
906 | | LiteralOperatorKind LOK = getLiteralOperatorKind(); |
907 | | assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal"); |
908 | | #endif |
909 | | return getArg(0); |
910 | 9 | } |
911 | | |
912 | 14 | const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const { |
913 | 14 | return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier(); |
914 | 14 | } |
915 | | |
916 | | CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc, |
917 | | FieldDecl *Field, QualType Ty, |
918 | | DeclContext *UsedContext) |
919 | | : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Ctx), |
920 | | Ty->isLValueReferenceType() ? VK_LValue : Ty->isRValueReferenceType() |
921 | | ? VK_XValue |
922 | | : VK_RValue, |
923 | | /*FIXME*/ OK_Ordinary, false, false, false, false), |
924 | 2.45k | Field(Field), UsedContext(UsedContext) { |
925 | 2.45k | CXXDefaultInitExprBits.Loc = Loc; |
926 | 2.45k | assert(Field->hasInClassInitializer()); |
927 | 2.45k | } |
928 | | |
929 | | CXXTemporary *CXXTemporary::Create(const ASTContext &C, |
930 | 58.8k | const CXXDestructorDecl *Destructor) { |
931 | 58.8k | return new (C) CXXTemporary(Destructor); |
932 | 58.8k | } |
933 | | |
934 | | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C, |
935 | | CXXTemporary *Temp, |
936 | 57.7k | Expr* SubExpr) { |
937 | 57.7k | assert((SubExpr->getType()->isRecordType() || |
938 | 57.7k | SubExpr->getType()->isArrayType()) && |
939 | 57.7k | "Expression bound to a temporary must have record or array type!"); |
940 | 57.7k | |
941 | 57.7k | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
942 | 57.7k | } |
943 | | |
944 | | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr( |
945 | | CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, |
946 | | ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange, |
947 | | bool HadMultipleCandidates, bool ListInitialization, |
948 | | bool StdInitListInitialization, bool ZeroInitialization) |
949 | | : CXXConstructExpr( |
950 | | CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(), |
951 | | Cons, /* Elidable=*/false, Args, HadMultipleCandidates, |
952 | | ListInitialization, StdInitListInitialization, ZeroInitialization, |
953 | | CXXConstructExpr::CK_Complete, ParenOrBraceRange), |
954 | 59.9k | TSI(TSI) {} |
955 | | |
956 | | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(EmptyShell Empty, |
957 | | unsigned NumArgs) |
958 | 309 | : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty, NumArgs) {} |
959 | | |
960 | | CXXTemporaryObjectExpr *CXXTemporaryObjectExpr::Create( |
961 | | const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, |
962 | | TypeSourceInfo *TSI, ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange, |
963 | | bool HadMultipleCandidates, bool ListInitialization, |
964 | 59.9k | bool StdInitListInitialization, bool ZeroInitialization) { |
965 | 59.9k | unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size()); |
966 | 59.9k | void *Mem = |
967 | 59.9k | Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects, |
968 | 59.9k | alignof(CXXTemporaryObjectExpr)); |
969 | 59.9k | return new (Mem) CXXTemporaryObjectExpr( |
970 | 59.9k | Cons, Ty, TSI, Args, ParenOrBraceRange, HadMultipleCandidates, |
971 | 59.9k | ListInitialization, StdInitListInitialization, ZeroInitialization); |
972 | 59.9k | } |
973 | | |
974 | | CXXTemporaryObjectExpr * |
975 | 309 | CXXTemporaryObjectExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs) { |
976 | 309 | unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs); |
977 | 309 | void *Mem = |
978 | 309 | Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects, |
979 | 309 | alignof(CXXTemporaryObjectExpr)); |
980 | 309 | return new (Mem) CXXTemporaryObjectExpr(EmptyShell(), NumArgs); |
981 | 309 | } |
982 | | |
983 | 991k | SourceLocation CXXTemporaryObjectExpr::getBeginLoc() const { |
984 | 991k | return getTypeSourceInfo()->getTypeLoc().getBeginLoc(); |
985 | 991k | } |
986 | | |
987 | 28.9k | SourceLocation CXXTemporaryObjectExpr::getEndLoc() const { |
988 | 28.9k | SourceLocation Loc = getParenOrBraceRange().getEnd(); |
989 | 28.9k | if (Loc.isInvalid() && getNumArgs()0 ) |
990 | 0 | Loc = getArg(getNumArgs() - 1)->getEndLoc(); |
991 | 28.9k | return Loc; |
992 | 28.9k | } |
993 | | |
994 | | CXXConstructExpr *CXXConstructExpr::Create( |
995 | | const ASTContext &Ctx, QualType Ty, SourceLocation Loc, |
996 | | CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, |
997 | | bool HadMultipleCandidates, bool ListInitialization, |
998 | | bool StdInitListInitialization, bool ZeroInitialization, |
999 | 360k | ConstructionKind ConstructKind, SourceRange ParenOrBraceRange) { |
1000 | 360k | unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size()); |
1001 | 360k | void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects, |
1002 | 360k | alignof(CXXConstructExpr)); |
1003 | 360k | return new (Mem) CXXConstructExpr( |
1004 | 360k | CXXConstructExprClass, Ty, Loc, Ctor, Elidable, Args, |
1005 | 360k | HadMultipleCandidates, ListInitialization, StdInitListInitialization, |
1006 | 360k | ZeroInitialization, ConstructKind, ParenOrBraceRange); |
1007 | 360k | } |
1008 | | |
1009 | | CXXConstructExpr *CXXConstructExpr::CreateEmpty(const ASTContext &Ctx, |
1010 | 4.73k | unsigned NumArgs) { |
1011 | 4.73k | unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs); |
1012 | 4.73k | void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects, |
1013 | 4.73k | alignof(CXXConstructExpr)); |
1014 | 4.73k | return new (Mem) |
1015 | 4.73k | CXXConstructExpr(CXXConstructExprClass, EmptyShell(), NumArgs); |
1016 | 4.73k | } |
1017 | | |
1018 | | CXXConstructExpr::CXXConstructExpr( |
1019 | | StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, |
1020 | | bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates, |
1021 | | bool ListInitialization, bool StdInitListInitialization, |
1022 | | bool ZeroInitialization, ConstructionKind ConstructKind, |
1023 | | SourceRange ParenOrBraceRange) |
1024 | | : Expr(SC, Ty, VK_RValue, OK_Ordinary, Ty->isDependentType(), |
1025 | | Ty->isDependentType(), Ty->isInstantiationDependentType(), |
1026 | | Ty->containsUnexpandedParameterPack()), |
1027 | | Constructor(Ctor), ParenOrBraceRange(ParenOrBraceRange), |
1028 | 420k | NumArgs(Args.size()) { |
1029 | 420k | CXXConstructExprBits.Elidable = Elidable; |
1030 | 420k | CXXConstructExprBits.HadMultipleCandidates = HadMultipleCandidates; |
1031 | 420k | CXXConstructExprBits.ListInitialization = ListInitialization; |
1032 | 420k | CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization; |
1033 | 420k | CXXConstructExprBits.ZeroInitialization = ZeroInitialization; |
1034 | 420k | CXXConstructExprBits.ConstructionKind = ConstructKind; |
1035 | 420k | CXXConstructExprBits.Loc = Loc; |
1036 | 420k | |
1037 | 420k | Stmt **TrailingArgs = getTrailingArgs(); |
1038 | 770k | for (unsigned I = 0, N = Args.size(); I != N; ++I350k ) { |
1039 | 350k | assert(Args[I] && "NULL argument in CXXConstructExpr!"); |
1040 | 350k | |
1041 | 350k | if (Args[I]->isValueDependent()) |
1042 | 836 | ExprBits.ValueDependent = true; |
1043 | 350k | if (Args[I]->isInstantiationDependent()) |
1044 | 836 | ExprBits.InstantiationDependent = true; |
1045 | 350k | if (Args[I]->containsUnexpandedParameterPack()) |
1046 | 8 | ExprBits.ContainsUnexpandedParameterPack = true; |
1047 | 350k | |
1048 | 350k | TrailingArgs[I] = Args[I]; |
1049 | 350k | } |
1050 | 420k | } |
1051 | | |
1052 | | CXXConstructExpr::CXXConstructExpr(StmtClass SC, EmptyShell Empty, |
1053 | | unsigned NumArgs) |
1054 | 5.04k | : Expr(SC, Empty), NumArgs(NumArgs) {} |
1055 | | |
1056 | | LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit, |
1057 | | LambdaCaptureKind Kind, VarDecl *Var, |
1058 | | SourceLocation EllipsisLoc) |
1059 | 6.37k | : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) { |
1060 | 6.37k | unsigned Bits = 0; |
1061 | 6.37k | if (Implicit) |
1062 | 4.86k | Bits |= Capture_Implicit; |
1063 | 6.37k | |
1064 | 6.37k | switch (Kind) { |
1065 | 6.37k | case LCK_StarThis: |
1066 | 122 | Bits |= Capture_ByCopy; |
1067 | 122 | LLVM_FALLTHROUGH; |
1068 | 694 | case LCK_This: |
1069 | 694 | assert(!Var && "'this' capture cannot have a variable!"); |
1070 | 694 | Bits |= Capture_This; |
1071 | 694 | break; |
1072 | 122 | |
1073 | 1.13k | case LCK_ByCopy: |
1074 | 1.13k | Bits |= Capture_ByCopy; |
1075 | 1.13k | LLVM_FALLTHROUGH; |
1076 | 5.64k | case LCK_ByRef: |
1077 | 5.64k | assert(Var && "capture must have a variable!"); |
1078 | 5.64k | break; |
1079 | 1.13k | case LCK_VLAType: |
1080 | 40 | assert(!Var && "VLA type capture cannot have a variable!"); |
1081 | 40 | break; |
1082 | 6.37k | } |
1083 | 6.37k | DeclAndBits.setInt(Bits); |
1084 | 6.37k | } |
1085 | | |
1086 | 3.37k | LambdaCaptureKind LambdaCapture::getCaptureKind() const { |
1087 | 3.37k | if (capturesVLAType()) |
1088 | 2 | return LCK_VLAType; |
1089 | 3.37k | bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy; |
1090 | 3.37k | if (capturesThis()) |
1091 | 522 | return CapByCopy ? LCK_StarThis66 : LCK_This456 ; |
1092 | 2.84k | return CapByCopy ? LCK_ByCopy544 : LCK_ByRef2.30k ; |
1093 | 2.84k | } |
1094 | | |
1095 | | LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange, |
1096 | | LambdaCaptureDefault CaptureDefault, |
1097 | | SourceLocation CaptureDefaultLoc, |
1098 | | ArrayRef<LambdaCapture> Captures, bool ExplicitParams, |
1099 | | bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
1100 | | SourceLocation ClosingBrace, |
1101 | | bool ContainsUnexpandedParameterPack) |
1102 | | : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, T->isDependentType(), |
1103 | | T->isDependentType(), T->isDependentType(), |
1104 | | ContainsUnexpandedParameterPack), |
1105 | | IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc), |
1106 | | NumCaptures(Captures.size()), CaptureDefault(CaptureDefault), |
1107 | | ExplicitParams(ExplicitParams), ExplicitResultType(ExplicitResultType), |
1108 | 6.71k | ClosingBrace(ClosingBrace) { |
1109 | 6.71k | assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments"); |
1110 | 6.71k | CXXRecordDecl *Class = getLambdaClass(); |
1111 | 6.71k | CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData(); |
1112 | 6.71k | |
1113 | 6.71k | // FIXME: Propagate "has unexpanded parameter pack" bit. |
1114 | 6.71k | |
1115 | 6.71k | // Copy captures. |
1116 | 6.71k | const ASTContext &Context = Class->getASTContext(); |
1117 | 6.71k | Data.NumCaptures = NumCaptures; |
1118 | 6.71k | Data.NumExplicitCaptures = 0; |
1119 | 6.71k | Data.Captures = |
1120 | 6.71k | (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * NumCaptures); |
1121 | 6.71k | LambdaCapture *ToCapture = Data.Captures; |
1122 | 12.0k | for (unsigned I = 0, N = Captures.size(); I != N; ++I5.34k ) { |
1123 | 5.34k | if (Captures[I].isExplicit()) |
1124 | 1.50k | ++Data.NumExplicitCaptures; |
1125 | 5.34k | |
1126 | 5.34k | *ToCapture++ = Captures[I]; |
1127 | 5.34k | } |
1128 | 6.71k | |
1129 | 6.71k | // Copy initialization expressions for the non-static data members. |
1130 | 6.71k | Stmt **Stored = getStoredStmts(); |
1131 | 12.0k | for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I5.34k ) |
1132 | 5.34k | *Stored++ = CaptureInits[I]; |
1133 | 6.71k | |
1134 | 6.71k | // Copy the body of the lambda. |
1135 | 6.71k | *Stored++ = getCallOperator()->getBody(); |
1136 | 6.71k | } |
1137 | | |
1138 | | LambdaExpr *LambdaExpr::Create( |
1139 | | const ASTContext &Context, CXXRecordDecl *Class, |
1140 | | SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, |
1141 | | SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures, |
1142 | | bool ExplicitParams, bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
1143 | 6.71k | SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack) { |
1144 | 6.71k | // Determine the type of the expression (i.e., the type of the |
1145 | 6.71k | // function object we're creating). |
1146 | 6.71k | QualType T = Context.getTypeDeclType(Class); |
1147 | 6.71k | |
1148 | 6.71k | unsigned Size = totalSizeToAlloc<Stmt *>(Captures.size() + 1); |
1149 | 6.71k | void *Mem = Context.Allocate(Size); |
1150 | 6.71k | return new (Mem) |
1151 | 6.71k | LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc, |
1152 | 6.71k | Captures, ExplicitParams, ExplicitResultType, CaptureInits, |
1153 | 6.71k | ClosingBrace, ContainsUnexpandedParameterPack); |
1154 | 6.71k | } |
1155 | | |
1156 | | LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C, |
1157 | 490 | unsigned NumCaptures) { |
1158 | 490 | unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1); |
1159 | 490 | void *Mem = C.Allocate(Size); |
1160 | 490 | return new (Mem) LambdaExpr(EmptyShell(), NumCaptures); |
1161 | 490 | } |
1162 | | |
1163 | 879 | bool LambdaExpr::isInitCapture(const LambdaCapture *C) const { |
1164 | 879 | return (C->capturesVariable() && C->getCapturedVar()->isInitCapture()742 && |
1165 | 879 | (getCallOperator() == C->getCapturedVar()->getDeclContext())326 ); |
1166 | 879 | } |
1167 | | |
1168 | 8.90k | LambdaExpr::capture_iterator LambdaExpr::capture_begin() const { |
1169 | 8.90k | return getLambdaClass()->getLambdaData().Captures; |
1170 | 8.90k | } |
1171 | | |
1172 | 3.18k | LambdaExpr::capture_iterator LambdaExpr::capture_end() const { |
1173 | 3.18k | return capture_begin() + NumCaptures; |
1174 | 3.18k | } |
1175 | | |
1176 | 85 | LambdaExpr::capture_range LambdaExpr::captures() const { |
1177 | 85 | return capture_range(capture_begin(), capture_end()); |
1178 | 85 | } |
1179 | | |
1180 | 1.96k | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const { |
1181 | 1.96k | return capture_begin(); |
1182 | 1.96k | } |
1183 | | |
1184 | 1.96k | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const { |
1185 | 1.96k | struct CXXRecordDecl::LambdaDefinitionData &Data |
1186 | 1.96k | = getLambdaClass()->getLambdaData(); |
1187 | 1.96k | return Data.Captures + Data.NumExplicitCaptures; |
1188 | 1.96k | } |
1189 | | |
1190 | 0 | LambdaExpr::capture_range LambdaExpr::explicit_captures() const { |
1191 | 0 | return capture_range(explicit_capture_begin(), explicit_capture_end()); |
1192 | 0 | } |
1193 | | |
1194 | 0 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const { |
1195 | 0 | return explicit_capture_end(); |
1196 | 0 | } |
1197 | | |
1198 | 0 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const { |
1199 | 0 | return capture_end(); |
1200 | 0 | } |
1201 | | |
1202 | 0 | LambdaExpr::capture_range LambdaExpr::implicit_captures() const { |
1203 | 0 | return capture_range(implicit_capture_begin(), implicit_capture_end()); |
1204 | 0 | } |
1205 | | |
1206 | 39.9k | CXXRecordDecl *LambdaExpr::getLambdaClass() const { |
1207 | 39.9k | return getType()->getAsCXXRecordDecl(); |
1208 | 39.9k | } |
1209 | | |
1210 | 16.5k | CXXMethodDecl *LambdaExpr::getCallOperator() const { |
1211 | 16.5k | CXXRecordDecl *Record = getLambdaClass(); |
1212 | 16.5k | return Record->getLambdaCallOperator(); |
1213 | 16.5k | } |
1214 | | |
1215 | 1.58k | TemplateParameterList *LambdaExpr::getTemplateParameterList() const { |
1216 | 1.58k | CXXRecordDecl *Record = getLambdaClass(); |
1217 | 1.58k | return Record->getGenericLambdaTemplateParameterList(); |
1218 | 1.58k | } |
1219 | | |
1220 | 394 | ArrayRef<NamedDecl *> LambdaExpr::getExplicitTemplateParameters() const { |
1221 | 394 | const CXXRecordDecl *Record = getLambdaClass(); |
1222 | 394 | return Record->getLambdaExplicitTemplateParameters(); |
1223 | 394 | } |
1224 | | |
1225 | 2.29k | CompoundStmt *LambdaExpr::getBody() const { |
1226 | 2.29k | // FIXME: this mutation in getBody is bogus. It should be |
1227 | 2.29k | // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I |
1228 | 2.29k | // don't understand, that doesn't work. |
1229 | 2.29k | if (!getStoredStmts()[NumCaptures]) |
1230 | 64 | *const_cast<Stmt **>(&getStoredStmts()[NumCaptures]) = |
1231 | 64 | getCallOperator()->getBody(); |
1232 | 2.29k | |
1233 | 2.29k | return static_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]); |
1234 | 2.29k | } |
1235 | | |
1236 | 1.56k | bool LambdaExpr::isMutable() const { |
1237 | 1.56k | return !getCallOperator()->isConst(); |
1238 | 1.56k | } |
1239 | | |
1240 | | ExprWithCleanups::ExprWithCleanups(Expr *subexpr, |
1241 | | bool CleanupsHaveSideEffects, |
1242 | | ArrayRef<CleanupObject> objects) |
1243 | 133k | : FullExpr(ExprWithCleanupsClass, subexpr) { |
1244 | 133k | ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects; |
1245 | 133k | ExprWithCleanupsBits.NumObjects = objects.size(); |
1246 | 134k | for (unsigned i = 0, e = objects.size(); i != e; ++i1.56k ) |
1247 | 1.56k | getTrailingObjects<CleanupObject>()[i] = objects[i]; |
1248 | 133k | } |
1249 | | |
1250 | | ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr, |
1251 | | bool CleanupsHaveSideEffects, |
1252 | 133k | ArrayRef<CleanupObject> objects) { |
1253 | 133k | void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()), |
1254 | 133k | alignof(ExprWithCleanups)); |
1255 | 133k | return new (buffer) |
1256 | 133k | ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects); |
1257 | 133k | } |
1258 | | |
1259 | | ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects) |
1260 | 1.11k | : FullExpr(ExprWithCleanupsClass, empty) { |
1261 | 1.11k | ExprWithCleanupsBits.NumObjects = numObjects; |
1262 | 1.11k | } |
1263 | | |
1264 | | ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, |
1265 | | EmptyShell empty, |
1266 | 1.11k | unsigned numObjects) { |
1267 | 1.11k | void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects), |
1268 | 1.11k | alignof(ExprWithCleanups)); |
1269 | 1.11k | return new (buffer) ExprWithCleanups(empty, numObjects); |
1270 | 1.11k | } |
1271 | | |
1272 | | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *TSI, |
1273 | | SourceLocation LParenLoc, |
1274 | | ArrayRef<Expr *> Args, |
1275 | | SourceLocation RParenLoc) |
1276 | | : Expr(CXXUnresolvedConstructExprClass, |
1277 | | TSI->getType().getNonReferenceType(), |
1278 | | (TSI->getType()->isLValueReferenceType() |
1279 | | ? VK_LValue |
1280 | | : TSI->getType()->isRValueReferenceType() ? VK_XValue |
1281 | | : VK_RValue), |
1282 | | OK_Ordinary, |
1283 | | TSI->getType()->isDependentType() || |
1284 | | TSI->getType()->getContainedDeducedType(), |
1285 | | true, true, TSI->getType()->containsUnexpandedParameterPack()), |
1286 | 258k | TSI(TSI), LParenLoc(LParenLoc), RParenLoc(RParenLoc) { |
1287 | 258k | CXXUnresolvedConstructExprBits.NumArgs = Args.size(); |
1288 | 258k | auto **StoredArgs = getTrailingObjects<Expr *>(); |
1289 | 452k | for (unsigned I = 0; I != Args.size(); ++I194k ) { |
1290 | 194k | if (Args[I]->containsUnexpandedParameterPack()) |
1291 | 7 | ExprBits.ContainsUnexpandedParameterPack = true; |
1292 | 194k | |
1293 | 194k | StoredArgs[I] = Args[I]; |
1294 | 194k | } |
1295 | 258k | } |
1296 | | |
1297 | | CXXUnresolvedConstructExpr *CXXUnresolvedConstructExpr::Create( |
1298 | | const ASTContext &Context, TypeSourceInfo *TSI, SourceLocation LParenLoc, |
1299 | 258k | ArrayRef<Expr *> Args, SourceLocation RParenLoc) { |
1300 | 258k | void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(Args.size())); |
1301 | 258k | return new (Mem) CXXUnresolvedConstructExpr(TSI, LParenLoc, Args, RParenLoc); |
1302 | 258k | } |
1303 | | |
1304 | | CXXUnresolvedConstructExpr * |
1305 | | CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &Context, |
1306 | 823 | unsigned NumArgs) { |
1307 | 823 | void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(NumArgs)); |
1308 | 823 | return new (Mem) CXXUnresolvedConstructExpr(EmptyShell(), NumArgs); |
1309 | 823 | } |
1310 | | |
1311 | 108k | SourceLocation CXXUnresolvedConstructExpr::getBeginLoc() const { |
1312 | 108k | return TSI->getTypeLoc().getBeginLoc(); |
1313 | 108k | } |
1314 | | |
1315 | | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr( |
1316 | | const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, |
1317 | | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
1318 | | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, |
1319 | | DeclarationNameInfo MemberNameInfo, |
1320 | | const TemplateArgumentListInfo *TemplateArgs) |
1321 | | : Expr(CXXDependentScopeMemberExprClass, Ctx.DependentTy, VK_LValue, |
1322 | | OK_Ordinary, true, true, true, |
1323 | | ((Base && Base->containsUnexpandedParameterPack()) || |
1324 | | (QualifierLoc && QualifierLoc.getNestedNameSpecifier() |
1325 | | ->containsUnexpandedParameterPack()) || |
1326 | | MemberNameInfo.containsUnexpandedParameterPack())), |
1327 | | Base(Base), BaseType(BaseType), QualifierLoc(QualifierLoc), |
1328 | 1.52M | MemberNameInfo(MemberNameInfo) { |
1329 | 1.52M | CXXDependentScopeMemberExprBits.IsArrow = IsArrow; |
1330 | 1.52M | CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo = |
1331 | 1.52M | (TemplateArgs != nullptr) || TemplateKWLoc.isValid()1.52M ; |
1332 | 1.52M | CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope = |
1333 | 1.52M | FirstQualifierFoundInScope != nullptr; |
1334 | 1.52M | CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc; |
1335 | 1.52M | |
1336 | 1.52M | if (TemplateArgs) { |
1337 | 1.76k | bool Dependent = true; |
1338 | 1.76k | bool InstantiationDependent = true; |
1339 | 1.76k | bool ContainsUnexpandedParameterPack = false; |
1340 | 1.76k | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
1341 | 1.76k | TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(), |
1342 | 1.76k | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
1343 | 1.76k | if (ContainsUnexpandedParameterPack) |
1344 | 1 | ExprBits.ContainsUnexpandedParameterPack = true; |
1345 | 1.52M | } else if (TemplateKWLoc.isValid()) { |
1346 | 34 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
1347 | 34 | TemplateKWLoc); |
1348 | 34 | } |
1349 | 1.52M | |
1350 | 1.52M | if (hasFirstQualifierFoundInScope()) |
1351 | 54 | *getTrailingObjects<NamedDecl *>() = FirstQualifierFoundInScope; |
1352 | 1.52M | } |
1353 | | |
1354 | | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr( |
1355 | | EmptyShell Empty, bool HasTemplateKWAndArgsInfo, |
1356 | | bool HasFirstQualifierFoundInScope) |
1357 | 893 | : Expr(CXXDependentScopeMemberExprClass, Empty) { |
1358 | 893 | CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo = |
1359 | 893 | HasTemplateKWAndArgsInfo; |
1360 | 893 | CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope = |
1361 | 893 | HasFirstQualifierFoundInScope; |
1362 | 893 | } |
1363 | | |
1364 | | CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::Create( |
1365 | | const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, |
1366 | | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
1367 | | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, |
1368 | | DeclarationNameInfo MemberNameInfo, |
1369 | 1.52M | const TemplateArgumentListInfo *TemplateArgs) { |
1370 | 1.52M | bool HasTemplateKWAndArgsInfo = |
1371 | 1.52M | (TemplateArgs != nullptr) || TemplateKWLoc.isValid()1.52M ; |
1372 | 1.52M | unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size()1.76k : 01.52M ; |
1373 | 1.52M | bool HasFirstQualifierFoundInScope = FirstQualifierFoundInScope != nullptr; |
1374 | 1.52M | |
1375 | 1.52M | unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo, |
1376 | 1.52M | TemplateArgumentLoc, NamedDecl *>( |
1377 | 1.52M | HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope); |
1378 | 1.52M | |
1379 | 1.52M | void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr)); |
1380 | 1.52M | return new (Mem) CXXDependentScopeMemberExpr( |
1381 | 1.52M | Ctx, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc, |
1382 | 1.52M | FirstQualifierFoundInScope, MemberNameInfo, TemplateArgs); |
1383 | 1.52M | } |
1384 | | |
1385 | | CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::CreateEmpty( |
1386 | | const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo, |
1387 | 893 | unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope) { |
1388 | 893 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
1389 | 893 | |
1390 | 893 | unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo, |
1391 | 893 | TemplateArgumentLoc, NamedDecl *>( |
1392 | 893 | HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope); |
1393 | 893 | |
1394 | 893 | void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr)); |
1395 | 893 | return new (Mem) CXXDependentScopeMemberExpr( |
1396 | 893 | EmptyShell(), HasTemplateKWAndArgsInfo, HasFirstQualifierFoundInScope); |
1397 | 893 | } |
1398 | | |
1399 | | static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, |
1400 | 385k | UnresolvedSetIterator end) { |
1401 | 1.01M | do { |
1402 | 1.01M | NamedDecl *decl = *begin; |
1403 | 1.01M | if (isa<UnresolvedUsingValueDecl>(decl)) |
1404 | 224 | return false; |
1405 | 1.01M | |
1406 | 1.01M | // Unresolved member expressions should only contain methods and |
1407 | 1.01M | // method templates. |
1408 | 1.01M | if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction()) |
1409 | 1.01M | ->isStatic()) |
1410 | 12.2k | return false; |
1411 | 1.00M | } while (++begin != end); |
1412 | 385k | |
1413 | 385k | return true373k ; |
1414 | 385k | } |
1415 | | |
1416 | | UnresolvedMemberExpr::UnresolvedMemberExpr( |
1417 | | const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, |
1418 | | QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, |
1419 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
1420 | | const DeclarationNameInfo &MemberNameInfo, |
1421 | | const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, |
1422 | | UnresolvedSetIterator End) |
1423 | | : OverloadExpr( |
1424 | | UnresolvedMemberExprClass, Context, QualifierLoc, TemplateKWLoc, |
1425 | | MemberNameInfo, TemplateArgs, Begin, End, |
1426 | | // Dependent |
1427 | | ((Base && Base->isTypeDependent()) || BaseType->isDependentType()), |
1428 | | ((Base && Base->isInstantiationDependent()) || |
1429 | | BaseType->isInstantiationDependentType()), |
1430 | | // Contains unexpanded parameter pack |
1431 | | ((Base && Base->containsUnexpandedParameterPack()) || |
1432 | | BaseType->containsUnexpandedParameterPack())), |
1433 | 385k | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
1434 | 385k | UnresolvedMemberExprBits.IsArrow = IsArrow; |
1435 | 385k | UnresolvedMemberExprBits.HasUnresolvedUsing = HasUnresolvedUsing; |
1436 | 385k | |
1437 | 385k | // Check whether all of the members are non-static member functions, |
1438 | 385k | // and if so, mark give this bound-member type instead of overload type. |
1439 | 385k | if (hasOnlyNonStaticMemberFunctions(Begin, End)) |
1440 | 373k | setType(Context.BoundMemberTy); |
1441 | 385k | } |
1442 | | |
1443 | | UnresolvedMemberExpr::UnresolvedMemberExpr(EmptyShell Empty, |
1444 | | unsigned NumResults, |
1445 | | bool HasTemplateKWAndArgsInfo) |
1446 | | : OverloadExpr(UnresolvedMemberExprClass, Empty, NumResults, |
1447 | 6 | HasTemplateKWAndArgsInfo) {} |
1448 | | |
1449 | 914k | bool UnresolvedMemberExpr::isImplicitAccess() const { |
1450 | 914k | if (!Base) |
1451 | 177k | return true; |
1452 | 737k | |
1453 | 737k | return cast<Expr>(Base)->isImplicitCXXThis(); |
1454 | 737k | } |
1455 | | |
1456 | | UnresolvedMemberExpr *UnresolvedMemberExpr::Create( |
1457 | | const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, |
1458 | | QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, |
1459 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
1460 | | const DeclarationNameInfo &MemberNameInfo, |
1461 | | const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, |
1462 | 385k | UnresolvedSetIterator End) { |
1463 | 385k | unsigned NumResults = End - Begin; |
1464 | 385k | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid()382k ; |
1465 | 385k | unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size()3.06k : 0382k ; |
1466 | 385k | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
1467 | 385k | TemplateArgumentLoc>( |
1468 | 385k | NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs); |
1469 | 385k | void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr)); |
1470 | 385k | return new (Mem) UnresolvedMemberExpr( |
1471 | 385k | Context, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc, |
1472 | 385k | QualifierLoc, TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End); |
1473 | 385k | } |
1474 | | |
1475 | | UnresolvedMemberExpr *UnresolvedMemberExpr::CreateEmpty( |
1476 | | const ASTContext &Context, unsigned NumResults, |
1477 | 6 | bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) { |
1478 | 6 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
1479 | 6 | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
1480 | 6 | TemplateArgumentLoc>( |
1481 | 6 | NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs); |
1482 | 6 | void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr)); |
1483 | 6 | return new (Mem) |
1484 | 6 | UnresolvedMemberExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo); |
1485 | 6 | } |
1486 | | |
1487 | 111k | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() { |
1488 | 111k | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
1489 | 111k | |
1490 | 111k | // If there was a nested name specifier, it names the naming class. |
1491 | 111k | // It can't be dependent: after all, we were actually able to do the |
1492 | 111k | // lookup. |
1493 | 111k | CXXRecordDecl *Record = nullptr; |
1494 | 111k | auto *NNS = getQualifier(); |
1495 | 111k | if (NNS && NNS->getKind() != NestedNameSpecifier::Super1.76k ) { |
1496 | 1.76k | const Type *T = getQualifier()->getAsType(); |
1497 | 1.76k | assert(T && "qualifier in member expression does not name type"); |
1498 | 1.76k | Record = T->getAsCXXRecordDecl(); |
1499 | 1.76k | assert(Record && "qualifier in member expression does not name record"); |
1500 | 1.76k | } |
1501 | 109k | // Otherwise the naming class must have been the base class. |
1502 | 109k | else { |
1503 | 109k | QualType BaseType = getBaseType().getNonReferenceType(); |
1504 | 109k | if (isArrow()) { |
1505 | 107k | const auto *PT = BaseType->getAs<PointerType>(); |
1506 | 107k | assert(PT && "base of arrow member access is not pointer"); |
1507 | 107k | BaseType = PT->getPointeeType(); |
1508 | 107k | } |
1509 | 109k | |
1510 | 109k | Record = BaseType->getAsCXXRecordDecl(); |
1511 | 109k | assert(Record && "base of member expression does not name record"); |
1512 | 109k | } |
1513 | 111k | |
1514 | 111k | return Record; |
1515 | 111k | } |
1516 | | |
1517 | | SizeOfPackExpr * |
1518 | | SizeOfPackExpr::Create(ASTContext &Context, SourceLocation OperatorLoc, |
1519 | | NamedDecl *Pack, SourceLocation PackLoc, |
1520 | | SourceLocation RParenLoc, |
1521 | | Optional<unsigned> Length, |
1522 | 90.7k | ArrayRef<TemplateArgument> PartialArgs) { |
1523 | 90.7k | void *Storage = |
1524 | 90.7k | Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size())); |
1525 | 90.7k | return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack, |
1526 | 90.7k | PackLoc, RParenLoc, Length, PartialArgs); |
1527 | 90.7k | } |
1528 | | |
1529 | | SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context, |
1530 | 0 | unsigned NumPartialArgs) { |
1531 | 0 | void *Storage = |
1532 | 0 | Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs)); |
1533 | 0 | return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs); |
1534 | 0 | } |
1535 | | |
1536 | | SubstNonTypeTemplateParmPackExpr:: |
1537 | | SubstNonTypeTemplateParmPackExpr(QualType T, |
1538 | | ExprValueKind ValueKind, |
1539 | | NonTypeTemplateParmDecl *Param, |
1540 | | SourceLocation NameLoc, |
1541 | | const TemplateArgument &ArgPack) |
1542 | | : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary, |
1543 | | true, true, true, true), |
1544 | | Param(Param), Arguments(ArgPack.pack_begin()), |
1545 | 25 | NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) {} |
1546 | | |
1547 | 29 | TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { |
1548 | 29 | return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments)); |
1549 | 29 | } |
1550 | | |
1551 | | FunctionParmPackExpr::FunctionParmPackExpr(QualType T, VarDecl *ParamPack, |
1552 | | SourceLocation NameLoc, |
1553 | | unsigned NumParams, |
1554 | | VarDecl *const *Params) |
1555 | | : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true, |
1556 | | true, true), |
1557 | 130 | ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) { |
1558 | 130 | if (Params) |
1559 | 124 | std::uninitialized_copy(Params, Params + NumParams, |
1560 | 124 | getTrailingObjects<VarDecl *>()); |
1561 | 130 | } |
1562 | | |
1563 | | FunctionParmPackExpr * |
1564 | | FunctionParmPackExpr::Create(const ASTContext &Context, QualType T, |
1565 | | VarDecl *ParamPack, SourceLocation NameLoc, |
1566 | 124 | ArrayRef<VarDecl *> Params) { |
1567 | 124 | return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(Params.size()))) |
1568 | 124 | FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data()); |
1569 | 124 | } |
1570 | | |
1571 | | FunctionParmPackExpr * |
1572 | | FunctionParmPackExpr::CreateEmpty(const ASTContext &Context, |
1573 | 6 | unsigned NumParams) { |
1574 | 6 | return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(NumParams))) |
1575 | 6 | FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr); |
1576 | 6 | } |
1577 | | |
1578 | | void MaterializeTemporaryExpr::setExtendingDecl(const ValueDecl *ExtendedBy, |
1579 | 3.00k | unsigned ManglingNumber) { |
1580 | 3.00k | // We only need extra state if we have to remember more than just the Stmt. |
1581 | 3.00k | if (!ExtendedBy) |
1582 | 1.37k | return; |
1583 | 1.63k | |
1584 | 1.63k | // We may need to allocate extra storage for the mangling number and the |
1585 | 1.63k | // extended-by ValueDecl. |
1586 | 1.63k | if (!State.is<ExtraState *>()) { |
1587 | 1.63k | auto *ES = new (ExtendedBy->getASTContext()) ExtraState; |
1588 | 1.63k | ES->Temporary = State.get<Stmt *>(); |
1589 | 1.63k | State = ES; |
1590 | 1.63k | } |
1591 | 1.63k | |
1592 | 1.63k | auto ES = State.get<ExtraState *>(); |
1593 | 1.63k | ES->ExtendingDecl = ExtendedBy; |
1594 | 1.63k | ES->ManglingNumber = ManglingNumber; |
1595 | 1.63k | } |
1596 | | |
1597 | | TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, |
1598 | | ArrayRef<TypeSourceInfo *> Args, |
1599 | | SourceLocation RParenLoc, |
1600 | | bool Value) |
1601 | | : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary, |
1602 | | /*TypeDependent=*/false, |
1603 | | /*ValueDependent=*/false, |
1604 | | /*InstantiationDependent=*/false, |
1605 | | /*ContainsUnexpandedParameterPack=*/false), |
1606 | 247k | Loc(Loc), RParenLoc(RParenLoc) { |
1607 | 247k | TypeTraitExprBits.Kind = Kind; |
1608 | 247k | TypeTraitExprBits.Value = Value; |
1609 | 247k | TypeTraitExprBits.NumArgs = Args.size(); |
1610 | 247k | |
1611 | 247k | auto **ToArgs = getTrailingObjects<TypeSourceInfo *>(); |
1612 | 247k | |
1613 | 647k | for (unsigned I = 0, N = Args.size(); I != N; ++I399k ) { |
1614 | 399k | if (Args[I]->getType()->isDependentType()) |
1615 | 115k | setValueDependent(true); |
1616 | 399k | if (Args[I]->getType()->isInstantiationDependentType()) |
1617 | 115k | setInstantiationDependent(true); |
1618 | 399k | if (Args[I]->getType()->containsUnexpandedParameterPack()) |
1619 | 3 | setContainsUnexpandedParameterPack(true); |
1620 | 399k | |
1621 | 399k | ToArgs[I] = Args[I]; |
1622 | 399k | } |
1623 | 247k | } |
1624 | | |
1625 | | TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T, |
1626 | | SourceLocation Loc, |
1627 | | TypeTrait Kind, |
1628 | | ArrayRef<TypeSourceInfo *> Args, |
1629 | | SourceLocation RParenLoc, |
1630 | 247k | bool Value) { |
1631 | 247k | void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size())); |
1632 | 247k | return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value); |
1633 | 247k | } |
1634 | | |
1635 | | TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C, |
1636 | 4 | unsigned NumArgs) { |
1637 | 4 | void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs)); |
1638 | 4 | return new (Mem) TypeTraitExpr(EmptyShell()); |
1639 | 4 | } |
1640 | | |
1641 | | CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, |
1642 | | ArrayRef<Expr *> Args, QualType Ty, |
1643 | | ExprValueKind VK, SourceLocation RP, |
1644 | | unsigned MinNumArgs) |
1645 | | : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK, |
1646 | 42 | RP, MinNumArgs, NotADL) {} |
1647 | | |
1648 | | CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty) |
1649 | | : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs, |
1650 | 1 | Empty) {} |
1651 | | |
1652 | | CUDAKernelCallExpr * |
1653 | | CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, |
1654 | | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
1655 | 42 | SourceLocation RP, unsigned MinNumArgs) { |
1656 | 42 | // Allocate storage for the trailing objects of CallExpr. |
1657 | 42 | unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs); |
1658 | 42 | unsigned SizeOfTrailingObjects = |
1659 | 42 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs); |
1660 | 42 | void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects, |
1661 | 42 | alignof(CUDAKernelCallExpr)); |
1662 | 42 | return new (Mem) CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, MinNumArgs); |
1663 | 42 | } |
1664 | | |
1665 | | CUDAKernelCallExpr *CUDAKernelCallExpr::CreateEmpty(const ASTContext &Ctx, |
1666 | | unsigned NumArgs, |
1667 | 1 | EmptyShell Empty) { |
1668 | 1 | // Allocate storage for the trailing objects of CallExpr. |
1669 | 1 | unsigned SizeOfTrailingObjects = |
1670 | 1 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs); |
1671 | 1 | void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects, |
1672 | 1 | alignof(CUDAKernelCallExpr)); |
1673 | 1 | return new (Mem) CUDAKernelCallExpr(NumArgs, Empty); |
1674 | 1 | } |