/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file implements the subclesses of Expr class declared in ExprCXX.h |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "clang/AST/ASTContext.h" |
15 | | #include "clang/AST/Attr.h" |
16 | | #include "clang/AST/DeclCXX.h" |
17 | | #include "clang/AST/DeclTemplate.h" |
18 | | #include "clang/AST/ExprCXX.h" |
19 | | #include "clang/AST/TypeLoc.h" |
20 | | #include "clang/Basic/IdentifierTable.h" |
21 | | using namespace clang; |
22 | | |
23 | | |
24 | | //===----------------------------------------------------------------------===// |
25 | | // Child Iterators for iterating over subexpressions/substatements |
26 | | //===----------------------------------------------------------------------===// |
27 | | |
28 | 7 | bool CXXOperatorCallExpr::isInfixBinaryOp() const { |
29 | 7 | // An infix binary operator is any operator with two arguments other than |
30 | 7 | // operator() and operator[]. Note that none of these operators can have |
31 | 7 | // default arguments, so it suffices to check the number of argument |
32 | 7 | // expressions. |
33 | 7 | if (getNumArgs() != 2) |
34 | 0 | return false; |
35 | 7 | |
36 | 7 | switch (getOperator()) { |
37 | 2 | case OO_Call: 2 case OO_Subscript: |
38 | 2 | return false; |
39 | 5 | default: |
40 | 5 | return true; |
41 | 0 | } |
42 | 0 | } |
43 | | |
44 | 651 | bool CXXTypeidExpr::isPotentiallyEvaluated() const { |
45 | 651 | if (isTypeOperand()) |
46 | 337 | return false; |
47 | 314 | |
48 | 314 | // C++11 [expr.typeid]p3: |
49 | 314 | // When typeid is applied to an expression other than a glvalue of |
50 | 314 | // polymorphic class type, [...] the expression is an unevaluated operand. |
51 | 314 | const Expr *E = getExprOperand(); |
52 | 314 | if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl()) |
53 | 146 | if (146 RD->isPolymorphic() && 146 E->isGLValue()131 ) |
54 | 124 | return true; |
55 | 190 | |
56 | 190 | return false; |
57 | 190 | } |
58 | | |
59 | 212 | QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const { |
60 | 212 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); |
61 | 212 | Qualifiers Quals; |
62 | 212 | return Context.getUnqualifiedArrayType( |
63 | 212 | Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); |
64 | 212 | } |
65 | | |
66 | 6 | QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const { |
67 | 6 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); |
68 | 6 | Qualifiers Quals; |
69 | 6 | return Context.getUnqualifiedArrayType( |
70 | 6 | Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); |
71 | 6 | } |
72 | | |
73 | | // CXXScalarValueInitExpr |
74 | 6.54k | SourceLocation CXXScalarValueInitExpr::getLocStart() const { |
75 | 6.54k | return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc()6.35k : RParenLoc189 ; |
76 | 6.54k | } |
77 | | |
78 | | // CXXNewExpr |
79 | | CXXNewExpr::CXXNewExpr(const ASTContext &C, bool globalNew, |
80 | | FunctionDecl *operatorNew, FunctionDecl *operatorDelete, |
81 | | bool PassAlignment, bool usualArrayDeleteWantsSize, |
82 | | ArrayRef<Expr*> placementArgs, |
83 | | SourceRange typeIdParens, Expr *arraySize, |
84 | | InitializationStyle initializationStyle, |
85 | | Expr *initializer, QualType ty, |
86 | | TypeSourceInfo *allocatedTypeInfo, |
87 | | SourceRange Range, SourceRange directInitRange) |
88 | | : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, |
89 | | ty->isDependentType(), ty->isDependentType(), |
90 | | ty->isInstantiationDependentType(), |
91 | | ty->containsUnexpandedParameterPack()), |
92 | | SubExprs(nullptr), OperatorNew(operatorNew), OperatorDelete(operatorDelete), |
93 | | AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens), |
94 | | Range(Range), DirectInitRange(directInitRange), |
95 | | GlobalNew(globalNew), PassAlignment(PassAlignment), |
96 | 7.34k | UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { |
97 | 7.34k | assert((initializer != nullptr || initializationStyle == NoInit) && |
98 | 7.34k | "Only NoInit can have no initializer."); |
99 | 7.34k | StoredInitializationStyle = initializer ? initializationStyle + 16.00k : 01.34k ; |
100 | 7.34k | AllocateArgsArray(C, arraySize != nullptr, placementArgs.size(), |
101 | 7.34k | initializer != nullptr); |
102 | 7.34k | unsigned i = 0; |
103 | 7.34k | if (Array7.34k ) { |
104 | 1.41k | if (arraySize->isInstantiationDependent()) |
105 | 23 | ExprBits.InstantiationDependent = true; |
106 | 1.41k | |
107 | 1.41k | if (arraySize->containsUnexpandedParameterPack()) |
108 | 1 | ExprBits.ContainsUnexpandedParameterPack = true; |
109 | 1.41k | |
110 | 1.41k | SubExprs[i++] = arraySize; |
111 | 1.41k | } |
112 | 7.34k | |
113 | 7.34k | if (initializer7.34k ) { |
114 | 6.00k | if (initializer->isInstantiationDependent()) |
115 | 1.72k | ExprBits.InstantiationDependent = true; |
116 | 6.00k | |
117 | 6.00k | if (initializer->containsUnexpandedParameterPack()) |
118 | 2 | ExprBits.ContainsUnexpandedParameterPack = true; |
119 | 6.00k | |
120 | 6.00k | SubExprs[i++] = initializer; |
121 | 6.00k | } |
122 | 7.34k | |
123 | 8.97k | for (unsigned j = 0; j != placementArgs.size()8.97k ; ++j1.63k ) { |
124 | 1.63k | if (placementArgs[j]->isInstantiationDependent()) |
125 | 901 | ExprBits.InstantiationDependent = true; |
126 | 1.63k | if (placementArgs[j]->containsUnexpandedParameterPack()) |
127 | 1 | ExprBits.ContainsUnexpandedParameterPack = true; |
128 | 1.63k | |
129 | 1.63k | SubExprs[i++] = placementArgs[j]; |
130 | 1.63k | } |
131 | 7.34k | |
132 | 7.34k | switch (getInitializationStyle()) { |
133 | 4.80k | case CallInit: |
134 | 4.80k | this->Range.setEnd(DirectInitRange.getEnd()); break; |
135 | 66 | case ListInit: |
136 | 66 | this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break; |
137 | 2.47k | default: |
138 | 2.47k | if (TypeIdParens.isValid()) |
139 | 13 | this->Range.setEnd(TypeIdParens.getEnd()); |
140 | 2.47k | break; |
141 | 7.34k | } |
142 | 7.34k | } |
143 | | |
144 | | void CXXNewExpr::AllocateArgsArray(const ASTContext &C, bool isArray, |
145 | 7.35k | unsigned numPlaceArgs, bool hasInitializer){ |
146 | 7.35k | assert(SubExprs == nullptr && "SubExprs already allocated"); |
147 | 7.35k | Array = isArray; |
148 | 7.35k | NumPlacementArgs = numPlaceArgs; |
149 | 7.35k | |
150 | 7.35k | unsigned TotalSize = Array + hasInitializer + NumPlacementArgs; |
151 | 7.35k | SubExprs = new (C) Stmt*[TotalSize]; |
152 | 7.35k | } |
153 | | |
154 | 2.09k | bool CXXNewExpr::shouldNullCheckAllocation(const ASTContext &Ctx) const { |
155 | 2.09k | return getOperatorNew()->getType()->castAs<FunctionProtoType>()->isNothrow( |
156 | 2.09k | Ctx) && |
157 | 23 | !getOperatorNew()->isReservedGlobalPlacementOperator(); |
158 | 2.09k | } |
159 | | |
160 | | // CXXDeleteExpr |
161 | 603 | QualType CXXDeleteExpr::getDestroyedType() const { |
162 | 603 | const Expr *Arg = getArgument(); |
163 | 603 | // The type-to-delete may not be a pointer if it's a dependent type. |
164 | 603 | const QualType ArgType = Arg->getType(); |
165 | 603 | |
166 | 603 | if (ArgType->isDependentType() && 603 !ArgType->isPointerType()3 ) |
167 | 2 | return QualType(); |
168 | 601 | |
169 | 601 | return ArgType->getAs<PointerType>()->getPointeeType(); |
170 | 601 | } |
171 | | |
172 | | // CXXPseudoDestructorExpr |
173 | | PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) |
174 | | : Type(Info) |
175 | 1.16k | { |
176 | 1.16k | Location = Info->getTypeLoc().getLocalSourceRange().getBegin(); |
177 | 1.16k | } |
178 | | |
179 | | CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(const ASTContext &Context, |
180 | | Expr *Base, bool isArrow, SourceLocation OperatorLoc, |
181 | | NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, |
182 | | SourceLocation ColonColonLoc, SourceLocation TildeLoc, |
183 | | PseudoDestructorTypeStorage DestroyedType) |
184 | | : Expr(CXXPseudoDestructorExprClass, |
185 | | Context.BoundMemberTy, |
186 | | VK_RValue, OK_Ordinary, |
187 | | /*isTypeDependent=*/(Base->isTypeDependent() || |
188 | | (DestroyedType.getTypeSourceInfo() && |
189 | | DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), |
190 | | /*isValueDependent=*/Base->isValueDependent(), |
191 | | (Base->isInstantiationDependent() || |
192 | | (QualifierLoc && |
193 | | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) || |
194 | | (ScopeType && |
195 | | ScopeType->getType()->isInstantiationDependentType()) || |
196 | | (DestroyedType.getTypeSourceInfo() && |
197 | | DestroyedType.getTypeSourceInfo()->getType() |
198 | | ->isInstantiationDependentType())), |
199 | | // ContainsUnexpandedParameterPack |
200 | | (Base->containsUnexpandedParameterPack() || |
201 | | (QualifierLoc && |
202 | | QualifierLoc.getNestedNameSpecifier() |
203 | | ->containsUnexpandedParameterPack()) || |
204 | | (ScopeType && |
205 | | ScopeType->getType()->containsUnexpandedParameterPack()) || |
206 | | (DestroyedType.getTypeSourceInfo() && |
207 | | DestroyedType.getTypeSourceInfo()->getType() |
208 | | ->containsUnexpandedParameterPack()))), |
209 | | Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), |
210 | | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
211 | | ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), |
212 | 1.05k | DestroyedType(DestroyedType) { } |
213 | | |
214 | 27 | QualType CXXPseudoDestructorExpr::getDestroyedType() const { |
215 | 27 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
216 | 27 | return TInfo->getType(); |
217 | 0 | |
218 | 0 | return QualType(); |
219 | 0 | } |
220 | | |
221 | 113 | SourceLocation CXXPseudoDestructorExpr::getLocEnd() const { |
222 | 113 | SourceLocation End = DestroyedType.getLocation(); |
223 | 113 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
224 | 113 | End = TInfo->getTypeLoc().getLocalSourceRange().getEnd(); |
225 | 113 | return End; |
226 | 113 | } |
227 | | |
228 | | // UnresolvedLookupExpr |
229 | | UnresolvedLookupExpr * |
230 | | UnresolvedLookupExpr::Create(const ASTContext &C, |
231 | | CXXRecordDecl *NamingClass, |
232 | | NestedNameSpecifierLoc QualifierLoc, |
233 | | SourceLocation TemplateKWLoc, |
234 | | const DeclarationNameInfo &NameInfo, |
235 | | bool ADL, |
236 | | const TemplateArgumentListInfo *Args, |
237 | | UnresolvedSetIterator Begin, |
238 | | UnresolvedSetIterator End) |
239 | 12.5k | { |
240 | 12.5k | assert(Args || TemplateKWLoc.isValid()); |
241 | 12.5k | unsigned num_args = Args ? Args->size()12.5k : 00 ; |
242 | 12.5k | |
243 | 12.5k | std::size_t Size = |
244 | 12.5k | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(1, |
245 | 12.5k | num_args); |
246 | 12.5k | void *Mem = C.Allocate(Size, alignof(UnresolvedLookupExpr)); |
247 | 12.5k | return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, |
248 | 12.5k | TemplateKWLoc, NameInfo, |
249 | 12.5k | ADL, /*Overload*/ true, Args, |
250 | 12.5k | Begin, End); |
251 | 12.5k | } |
252 | | |
253 | | UnresolvedLookupExpr * |
254 | | UnresolvedLookupExpr::CreateEmpty(const ASTContext &C, |
255 | | bool HasTemplateKWAndArgsInfo, |
256 | 235 | unsigned NumTemplateArgs) { |
257 | 235 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
258 | 235 | std::size_t Size = |
259 | 235 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
260 | 235 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
261 | 235 | void *Mem = C.Allocate(Size, alignof(UnresolvedLookupExpr)); |
262 | 235 | UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); |
263 | 235 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
264 | 235 | return E; |
265 | 235 | } |
266 | | |
267 | | OverloadExpr::OverloadExpr(StmtClass K, const ASTContext &C, |
268 | | NestedNameSpecifierLoc QualifierLoc, |
269 | | SourceLocation TemplateKWLoc, |
270 | | const DeclarationNameInfo &NameInfo, |
271 | | const TemplateArgumentListInfo *TemplateArgs, |
272 | | UnresolvedSetIterator Begin, |
273 | | UnresolvedSetIterator End, |
274 | | bool KnownDependent, |
275 | | bool KnownInstantiationDependent, |
276 | | bool KnownContainsUnexpandedParameterPack) |
277 | | : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent, |
278 | | KnownDependent, |
279 | | (KnownInstantiationDependent || |
280 | | NameInfo.isInstantiationDependent() || |
281 | | (QualifierLoc && |
282 | | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
283 | | (KnownContainsUnexpandedParameterPack || |
284 | | NameInfo.containsUnexpandedParameterPack() || |
285 | | (QualifierLoc && |
286 | | QualifierLoc.getNestedNameSpecifier() |
287 | | ->containsUnexpandedParameterPack()))), |
288 | | NameInfo(NameInfo), QualifierLoc(QualifierLoc), |
289 | | Results(nullptr), NumResults(End - Begin), |
290 | | HasTemplateKWAndArgsInfo(TemplateArgs != nullptr || |
291 | 332k | TemplateKWLoc.isValid()) { |
292 | 332k | NumResults = End - Begin; |
293 | 332k | if (NumResults332k ) { |
294 | 320k | // Determine whether this expression is type-dependent. |
295 | 1.57M | for (UnresolvedSetImpl::const_iterator I = Begin; I != End1.57M ; ++I1.25M ) { |
296 | 1.25M | if ((*I)->getDeclContext()->isDependentContext() || |
297 | 1.25M | isa<UnresolvedUsingValueDecl>(*I)1.22M ) { |
298 | 26.0k | ExprBits.TypeDependent = true; |
299 | 26.0k | ExprBits.ValueDependent = true; |
300 | 26.0k | ExprBits.InstantiationDependent = true; |
301 | 26.0k | } |
302 | 1.25M | } |
303 | 320k | |
304 | 320k | Results = static_cast<DeclAccessPair *>(C.Allocate( |
305 | 320k | sizeof(DeclAccessPair) * NumResults, alignof(DeclAccessPair))); |
306 | 320k | memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair)); |
307 | 320k | } |
308 | 332k | |
309 | 332k | // If we have explicit template arguments, check for dependent |
310 | 332k | // template arguments and whether they contain any unexpanded pack |
311 | 332k | // expansions. |
312 | 332k | if (TemplateArgs332k ) { |
313 | 14.0k | bool Dependent = false; |
314 | 14.0k | bool InstantiationDependent = false; |
315 | 14.0k | bool ContainsUnexpandedParameterPack = false; |
316 | 14.0k | getTrailingASTTemplateKWAndArgsInfo()->initializeFrom( |
317 | 14.0k | TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(), |
318 | 14.0k | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
319 | 14.0k | |
320 | 14.0k | if (Dependent14.0k ) { |
321 | 905 | ExprBits.TypeDependent = true; |
322 | 905 | ExprBits.ValueDependent = true; |
323 | 905 | } |
324 | 14.0k | if (InstantiationDependent) |
325 | 905 | ExprBits.InstantiationDependent = true; |
326 | 14.0k | if (ContainsUnexpandedParameterPack) |
327 | 16 | ExprBits.ContainsUnexpandedParameterPack = true; |
328 | 332k | } else if (318k TemplateKWLoc.isValid()318k ) { |
329 | 0 | getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
330 | 0 | } |
331 | 332k | |
332 | 332k | if (isTypeDependent()) |
333 | 13.9k | setType(C.DependentTy); |
334 | 332k | } |
335 | | |
336 | | void OverloadExpr::initializeResults(const ASTContext &C, |
337 | | UnresolvedSetIterator Begin, |
338 | 241 | UnresolvedSetIterator End) { |
339 | 241 | assert(!Results && "Results already initialized!"); |
340 | 241 | NumResults = End - Begin; |
341 | 241 | if (NumResults241 ) { |
342 | 84 | Results = static_cast<DeclAccessPair *>( |
343 | 84 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
344 | 84 | |
345 | 84 | alignof(DeclAccessPair))); |
346 | 84 | memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair)); |
347 | 84 | } |
348 | 241 | } |
349 | | |
350 | 47 | CXXRecordDecl *OverloadExpr::getNamingClass() const { |
351 | 47 | if (isa<UnresolvedLookupExpr>(this)) |
352 | 47 | return cast<UnresolvedLookupExpr>(this)->getNamingClass(); |
353 | 47 | else |
354 | 0 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); |
355 | 0 | } |
356 | | |
357 | | // DependentScopeDeclRefExpr |
358 | | DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T, |
359 | | NestedNameSpecifierLoc QualifierLoc, |
360 | | SourceLocation TemplateKWLoc, |
361 | | const DeclarationNameInfo &NameInfo, |
362 | | const TemplateArgumentListInfo *Args) |
363 | | : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary, |
364 | | true, true, |
365 | | (NameInfo.isInstantiationDependent() || |
366 | | (QualifierLoc && |
367 | | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
368 | | (NameInfo.containsUnexpandedParameterPack() || |
369 | | (QualifierLoc && |
370 | | QualifierLoc.getNestedNameSpecifier() |
371 | | ->containsUnexpandedParameterPack()))), |
372 | | QualifierLoc(QualifierLoc), NameInfo(NameInfo), |
373 | | HasTemplateKWAndArgsInfo(Args != nullptr || TemplateKWLoc.isValid()) |
374 | 13.1k | { |
375 | 13.1k | if (Args13.1k ) { |
376 | 36 | bool Dependent = true; |
377 | 36 | bool InstantiationDependent = true; |
378 | 36 | bool ContainsUnexpandedParameterPack |
379 | 36 | = ExprBits.ContainsUnexpandedParameterPack; |
380 | 36 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
381 | 36 | TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(), |
382 | 36 | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
383 | 36 | ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; |
384 | 13.1k | } else if (13.0k TemplateKWLoc.isValid()13.0k ) { |
385 | 0 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
386 | 0 | TemplateKWLoc); |
387 | 0 | } |
388 | 13.1k | } |
389 | | |
390 | | DependentScopeDeclRefExpr * |
391 | | DependentScopeDeclRefExpr::Create(const ASTContext &C, |
392 | | NestedNameSpecifierLoc QualifierLoc, |
393 | | SourceLocation TemplateKWLoc, |
394 | | const DeclarationNameInfo &NameInfo, |
395 | 13.0k | const TemplateArgumentListInfo *Args) { |
396 | 13.0k | assert(QualifierLoc && "should be created for dependent qualifiers"); |
397 | 13.0k | bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid(); |
398 | 13.0k | std::size_t Size = |
399 | 13.0k | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
400 | 13.0k | HasTemplateKWAndArgsInfo, Args ? Args->size()36 : 013.0k ); |
401 | 13.0k | void *Mem = C.Allocate(Size); |
402 | 13.0k | return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc, |
403 | 13.0k | TemplateKWLoc, NameInfo, Args); |
404 | 13.0k | } |
405 | | |
406 | | DependentScopeDeclRefExpr * |
407 | | DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &C, |
408 | | bool HasTemplateKWAndArgsInfo, |
409 | 47 | unsigned NumTemplateArgs) { |
410 | 47 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
411 | 47 | std::size_t Size = |
412 | 47 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
413 | 47 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
414 | 47 | void *Mem = C.Allocate(Size); |
415 | 47 | DependentScopeDeclRefExpr *E |
416 | 47 | = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(), |
417 | 47 | SourceLocation(), |
418 | 47 | DeclarationNameInfo(), nullptr); |
419 | 47 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
420 | 47 | return E; |
421 | 47 | } |
422 | | |
423 | 228k | SourceLocation CXXConstructExpr::getLocStart() const { |
424 | 228k | if (isa<CXXTemporaryObjectExpr>(this)) |
425 | 502 | return cast<CXXTemporaryObjectExpr>(this)->getLocStart(); |
426 | 227k | return Loc; |
427 | 227k | } |
428 | | |
429 | 20.4k | SourceLocation CXXConstructExpr::getLocEnd() const { |
430 | 20.4k | if (isa<CXXTemporaryObjectExpr>(this)) |
431 | 0 | return cast<CXXTemporaryObjectExpr>(this)->getLocEnd(); |
432 | 20.4k | |
433 | 20.4k | if (20.4k ParenOrBraceRange.isValid()20.4k ) |
434 | 441 | return ParenOrBraceRange.getEnd(); |
435 | 20.0k | |
436 | 20.0k | SourceLocation End = Loc; |
437 | 20.3k | for (unsigned I = getNumArgs(); I > 020.3k ; --I340 ) { |
438 | 18.9k | const Expr *Arg = getArg(I-1); |
439 | 18.9k | if (!Arg->isDefaultArgument()18.9k ) { |
440 | 18.5k | SourceLocation NewEnd = Arg->getLocEnd(); |
441 | 18.5k | if (NewEnd.isValid()18.5k ) { |
442 | 18.5k | End = NewEnd; |
443 | 18.5k | break; |
444 | 18.5k | } |
445 | 18.5k | } |
446 | 18.9k | } |
447 | 20.4k | |
448 | 20.4k | return End; |
449 | 20.4k | } |
450 | | |
451 | 118k | SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { |
452 | 118k | OverloadedOperatorKind Kind = getOperator(); |
453 | 118k | if (Kind == OO_PlusPlus || 118k Kind == OO_MinusMinus117k ) { |
454 | 1.51k | if (getNumArgs() == 1) |
455 | 1.51k | // Prefix operator |
456 | 1.42k | return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd()); |
457 | 1.51k | else |
458 | 1.51k | // Postfix operator |
459 | 93 | return SourceRange(getArg(0)->getLocStart(), getOperatorLoc()); |
460 | 117k | } else if (117k Kind == OO_Arrow117k ) { |
461 | 1.07k | return getArg(0)->getSourceRange(); |
462 | 116k | } else if (116k Kind == OO_Call116k ) { |
463 | 15.3k | return SourceRange(getArg(0)->getLocStart(), getRParenLoc()); |
464 | 100k | } else if (100k Kind == OO_Subscript100k ) { |
465 | 24.4k | return SourceRange(getArg(0)->getLocStart(), getRParenLoc()); |
466 | 76.2k | } else if (76.2k getNumArgs() == 176.2k ) { |
467 | 4.84k | return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd()); |
468 | 71.4k | } else if (71.4k getNumArgs() == 271.4k ) { |
469 | 71.4k | return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd()); |
470 | 0 | } else { |
471 | 0 | return getOperatorLoc(); |
472 | 0 | } |
473 | 0 | } |
474 | | |
475 | 323k | Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { |
476 | 323k | const Expr *Callee = getCallee()->IgnoreParens(); |
477 | 323k | if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee)) |
478 | 323k | return MemExpr->getBase(); |
479 | 34 | if (const BinaryOperator *34 BO34 = dyn_cast<BinaryOperator>(Callee)) |
480 | 34 | if (34 BO->getOpcode() == BO_PtrMemD || 34 BO->getOpcode() == BO_PtrMemI20 ) |
481 | 34 | return BO->getLHS(); |
482 | 0 |
|
483 | 0 | // FIXME: Will eventually need to cope with member pointers. |
484 | 0 | return nullptr; |
485 | 0 | } |
486 | | |
487 | 255k | CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { |
488 | 255k | if (const MemberExpr *MemExpr = |
489 | 255k | dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
490 | 255k | return cast<CXXMethodDecl>(MemExpr->getMemberDecl()); |
491 | 4 | |
492 | 4 | // FIXME: Will eventually need to cope with member pointers. |
493 | 4 | return nullptr; |
494 | 4 | } |
495 | | |
496 | | |
497 | 0 | CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const { |
498 | 0 | Expr* ThisArg = getImplicitObjectArgument(); |
499 | 0 | if (!ThisArg) |
500 | 0 | return nullptr; |
501 | 0 |
|
502 | 0 | if (0 ThisArg->getType()->isAnyPointerType()0 ) |
503 | 0 | return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl(); |
504 | 0 |
|
505 | 0 | return ThisArg->getType()->getAsCXXRecordDecl(); |
506 | 0 | } |
507 | | |
508 | | |
509 | | //===----------------------------------------------------------------------===// |
510 | | // Named casts |
511 | | //===----------------------------------------------------------------------===// |
512 | | |
513 | | /// getCastName - Get the name of the C++ cast being used, e.g., |
514 | | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
515 | | /// "const_cast". The returned pointer must not be freed. |
516 | 14 | const char *CXXNamedCastExpr::getCastName() const { |
517 | 14 | switch (getStmtClass()) { |
518 | 4 | case CXXStaticCastExprClass: return "static_cast"; |
519 | 3 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
520 | 4 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
521 | 3 | case CXXConstCastExprClass: return "const_cast"; |
522 | 0 | default: return "<invalid cast>"; |
523 | 0 | } |
524 | 0 | } |
525 | | |
526 | | CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T, |
527 | | ExprValueKind VK, |
528 | | CastKind K, Expr *Op, |
529 | | const CXXCastPath *BasePath, |
530 | | TypeSourceInfo *WrittenTy, |
531 | | SourceLocation L, |
532 | | SourceLocation RParenLoc, |
533 | 8.00k | SourceRange AngleBrackets) { |
534 | 8.00k | unsigned PathSize = (BasePath ? BasePath->size()8.00k : 00 ); |
535 | 8.00k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
536 | 8.00k | CXXStaticCastExpr *E = |
537 | 8.00k | new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
538 | 8.00k | RParenLoc, AngleBrackets); |
539 | 8.00k | if (PathSize) |
540 | 2.26k | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
541 | 2.26k | E->getTrailingObjects<CXXBaseSpecifier *>()); |
542 | 8.00k | return E; |
543 | 8.00k | } |
544 | | |
545 | | CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C, |
546 | 25 | unsigned PathSize) { |
547 | 25 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
548 | 25 | return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize); |
549 | 25 | } |
550 | | |
551 | | CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T, |
552 | | ExprValueKind VK, |
553 | | CastKind K, Expr *Op, |
554 | | const CXXCastPath *BasePath, |
555 | | TypeSourceInfo *WrittenTy, |
556 | | SourceLocation L, |
557 | | SourceLocation RParenLoc, |
558 | 2.22k | SourceRange AngleBrackets) { |
559 | 2.22k | unsigned PathSize = (BasePath ? BasePath->size()2.22k : 00 ); |
560 | 2.22k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
561 | 2.22k | CXXDynamicCastExpr *E = |
562 | 2.22k | new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
563 | 2.22k | RParenLoc, AngleBrackets); |
564 | 2.22k | if (PathSize) |
565 | 39 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
566 | 39 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
567 | 2.22k | return E; |
568 | 2.22k | } |
569 | | |
570 | | CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C, |
571 | 2 | unsigned PathSize) { |
572 | 2 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
573 | 2 | return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); |
574 | 2 | } |
575 | | |
576 | | /// isAlwaysNull - Return whether the result of the dynamic_cast is proven |
577 | | /// to always be null. For example: |
578 | | /// |
579 | | /// struct A { }; |
580 | | /// struct B final : A { }; |
581 | | /// struct C { }; |
582 | | /// |
583 | | /// C *f(B* b) { return dynamic_cast<C*>(b); } |
584 | | bool CXXDynamicCastExpr::isAlwaysNull() const |
585 | 63 | { |
586 | 63 | QualType SrcType = getSubExpr()->getType(); |
587 | 63 | QualType DestType = getType(); |
588 | 63 | |
589 | 63 | if (const PointerType *SrcPTy63 = SrcType->getAs<PointerType>()) { |
590 | 53 | SrcType = SrcPTy->getPointeeType(); |
591 | 53 | DestType = DestType->castAs<PointerType>()->getPointeeType(); |
592 | 53 | } |
593 | 63 | |
594 | 63 | if (DestType->isVoidType()) |
595 | 5 | return false; |
596 | 58 | |
597 | 58 | const CXXRecordDecl *SrcRD = |
598 | 58 | cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl()); |
599 | 58 | |
600 | 58 | if (!SrcRD->hasAttr<FinalAttr>()) |
601 | 56 | return false; |
602 | 2 | |
603 | 2 | const CXXRecordDecl *DestRD = |
604 | 2 | cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl()); |
605 | 2 | |
606 | 2 | return !DestRD->isDerivedFrom(SrcRD); |
607 | 2 | } |
608 | | |
609 | | CXXReinterpretCastExpr * |
610 | | CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T, |
611 | | ExprValueKind VK, CastKind K, Expr *Op, |
612 | | const CXXCastPath *BasePath, |
613 | | TypeSourceInfo *WrittenTy, SourceLocation L, |
614 | | SourceLocation RParenLoc, |
615 | 11.9k | SourceRange AngleBrackets) { |
616 | 11.9k | unsigned PathSize = (BasePath ? BasePath->size()1 : 011.9k ); |
617 | 11.9k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
618 | 11.9k | CXXReinterpretCastExpr *E = |
619 | 11.9k | new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
620 | 11.9k | RParenLoc, AngleBrackets); |
621 | 11.9k | if (PathSize) |
622 | 0 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
623 | 0 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
624 | 11.9k | return E; |
625 | 11.9k | } |
626 | | |
627 | | CXXReinterpretCastExpr * |
628 | 12 | CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { |
629 | 12 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
630 | 12 | return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); |
631 | 12 | } |
632 | | |
633 | | CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T, |
634 | | ExprValueKind VK, Expr *Op, |
635 | | TypeSourceInfo *WrittenTy, |
636 | | SourceLocation L, |
637 | | SourceLocation RParenLoc, |
638 | 1.31k | SourceRange AngleBrackets) { |
639 | 1.31k | return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets); |
640 | 1.31k | } |
641 | | |
642 | 2 | CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) { |
643 | 2 | return new (C) CXXConstCastExpr(EmptyShell()); |
644 | 2 | } |
645 | | |
646 | | CXXFunctionalCastExpr * |
647 | | CXXFunctionalCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, |
648 | | TypeSourceInfo *Written, CastKind K, Expr *Op, |
649 | | const CXXCastPath *BasePath, |
650 | 47.6k | SourceLocation L, SourceLocation R) { |
651 | 47.6k | unsigned PathSize = (BasePath ? BasePath->size()46.6k : 01.09k ); |
652 | 47.6k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
653 | 47.6k | CXXFunctionalCastExpr *E = |
654 | 47.6k | new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R); |
655 | 47.6k | if (PathSize) |
656 | 9 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
657 | 9 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
658 | 47.6k | return E; |
659 | 47.6k | } |
660 | | |
661 | | CXXFunctionalCastExpr * |
662 | 24 | CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { |
663 | 24 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
664 | 24 | return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize); |
665 | 24 | } |
666 | | |
667 | 165k | SourceLocation CXXFunctionalCastExpr::getLocStart() const { |
668 | 165k | return getTypeInfoAsWritten()->getTypeLoc().getLocStart(); |
669 | 165k | } |
670 | | |
671 | 3.34k | SourceLocation CXXFunctionalCastExpr::getLocEnd() const { |
672 | 3.34k | return RParenLoc.isValid() ? RParenLoc2.95k : getSubExpr()->getLocEnd()385 ; |
673 | 3.34k | } |
674 | | |
675 | | UserDefinedLiteral::LiteralOperatorKind |
676 | 8.94k | UserDefinedLiteral::getLiteralOperatorKind() const { |
677 | 8.94k | if (getNumArgs() == 0) |
678 | 526 | return LOK_Template; |
679 | 8.41k | if (8.41k getNumArgs() == 28.41k ) |
680 | 2.39k | return LOK_String; |
681 | 6.02k | |
682 | 8.41k | assert(getNumArgs() == 1 && "unexpected #args in literal operator call"); |
683 | 6.02k | QualType ParamTy = |
684 | 6.02k | cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType(); |
685 | 6.02k | if (ParamTy->isPointerType()) |
686 | 537 | return LOK_Raw; |
687 | 5.48k | if (5.48k ParamTy->isAnyCharacterType()5.48k ) |
688 | 1.86k | return LOK_Character; |
689 | 3.62k | if (3.62k ParamTy->isIntegerType()3.62k ) |
690 | 1.71k | return LOK_Integer; |
691 | 1.91k | if (1.91k ParamTy->isFloatingType()1.91k ) |
692 | 1.91k | return LOK_Floating; |
693 | 0 |
|
694 | 0 | llvm_unreachable0 ("unknown kind of literal operator"); |
695 | 0 | } |
696 | | |
697 | 9 | Expr *UserDefinedLiteral::getCookedLiteral() { |
698 | | #ifndef NDEBUG |
699 | | LiteralOperatorKind LOK = getLiteralOperatorKind(); |
700 | | assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal"); |
701 | | #endif |
702 | | return getArg(0); |
703 | 9 | } |
704 | | |
705 | 14 | const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const { |
706 | 14 | return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier(); |
707 | 14 | } |
708 | | |
709 | | CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, |
710 | | FieldDecl *Field, QualType T) |
711 | | : Expr(CXXDefaultInitExprClass, T.getNonLValueExprType(C), |
712 | | T->isLValueReferenceType() ? VK_LValue : T->isRValueReferenceType() |
713 | | ? VK_XValue |
714 | | : VK_RValue, |
715 | | /*FIXME*/ OK_Ordinary, false, false, false, false), |
716 | 610 | Field(Field), Loc(Loc) { |
717 | 610 | assert(Field->hasInClassInitializer()); |
718 | 610 | } |
719 | | |
720 | | CXXTemporary *CXXTemporary::Create(const ASTContext &C, |
721 | 5.62k | const CXXDestructorDecl *Destructor) { |
722 | 5.62k | return new (C) CXXTemporary(Destructor); |
723 | 5.62k | } |
724 | | |
725 | | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C, |
726 | | CXXTemporary *Temp, |
727 | 5.46k | Expr* SubExpr) { |
728 | 5.46k | assert((SubExpr->getType()->isRecordType() || |
729 | 5.46k | SubExpr->getType()->isArrayType()) && |
730 | 5.46k | "Expression bound to a temporary must have record or array type!"); |
731 | 5.46k | |
732 | 5.46k | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
733 | 5.46k | } |
734 | | |
735 | | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(const ASTContext &C, |
736 | | CXXConstructorDecl *Cons, |
737 | | QualType Type, |
738 | | TypeSourceInfo *TSI, |
739 | | ArrayRef<Expr*> Args, |
740 | | SourceRange ParenOrBraceRange, |
741 | | bool HadMultipleCandidates, |
742 | | bool ListInitialization, |
743 | | bool StdInitListInitialization, |
744 | | bool ZeroInitialization) |
745 | | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, Type, |
746 | | TSI->getTypeLoc().getBeginLoc(), |
747 | | Cons, false, Args, |
748 | | HadMultipleCandidates, |
749 | | ListInitialization, |
750 | | StdInitListInitialization, |
751 | | ZeroInitialization, |
752 | | CXXConstructExpr::CK_Complete, ParenOrBraceRange), |
753 | 23.8k | Type(TSI) { |
754 | 23.8k | } |
755 | | |
756 | 501k | SourceLocation CXXTemporaryObjectExpr::getLocStart() const { |
757 | 501k | return Type->getTypeLoc().getBeginLoc(); |
758 | 501k | } |
759 | | |
760 | 9.65k | SourceLocation CXXTemporaryObjectExpr::getLocEnd() const { |
761 | 9.65k | SourceLocation Loc = getParenOrBraceRange().getEnd(); |
762 | 9.65k | if (Loc.isInvalid() && 9.65k getNumArgs()21 ) |
763 | 21 | Loc = getArg(getNumArgs()-1)->getLocEnd(); |
764 | 9.65k | return Loc; |
765 | 9.65k | } |
766 | | |
767 | | CXXConstructExpr *CXXConstructExpr::Create(const ASTContext &C, QualType T, |
768 | | SourceLocation Loc, |
769 | | CXXConstructorDecl *Ctor, |
770 | | bool Elidable, |
771 | | ArrayRef<Expr*> Args, |
772 | | bool HadMultipleCandidates, |
773 | | bool ListInitialization, |
774 | | bool StdInitListInitialization, |
775 | | bool ZeroInitialization, |
776 | | ConstructionKind ConstructKind, |
777 | 125k | SourceRange ParenOrBraceRange) { |
778 | 125k | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, |
779 | 125k | Ctor, Elidable, Args, |
780 | 125k | HadMultipleCandidates, ListInitialization, |
781 | 125k | StdInitListInitialization, |
782 | 125k | ZeroInitialization, ConstructKind, |
783 | 125k | ParenOrBraceRange); |
784 | 125k | } |
785 | | |
786 | | CXXConstructExpr::CXXConstructExpr(const ASTContext &C, StmtClass SC, |
787 | | QualType T, SourceLocation Loc, |
788 | | CXXConstructorDecl *Ctor, |
789 | | bool Elidable, |
790 | | ArrayRef<Expr*> Args, |
791 | | bool HadMultipleCandidates, |
792 | | bool ListInitialization, |
793 | | bool StdInitListInitialization, |
794 | | bool ZeroInitialization, |
795 | | ConstructionKind ConstructKind, |
796 | | SourceRange ParenOrBraceRange) |
797 | | : Expr(SC, T, VK_RValue, OK_Ordinary, |
798 | | T->isDependentType(), T->isDependentType(), |
799 | | T->isInstantiationDependentType(), |
800 | | T->containsUnexpandedParameterPack()), |
801 | | Constructor(Ctor), Loc(Loc), ParenOrBraceRange(ParenOrBraceRange), |
802 | | NumArgs(Args.size()), |
803 | | Elidable(Elidable), HadMultipleCandidates(HadMultipleCandidates), |
804 | | ListInitialization(ListInitialization), |
805 | | StdInitListInitialization(StdInitListInitialization), |
806 | | ZeroInitialization(ZeroInitialization), |
807 | | ConstructKind(ConstructKind), Args(nullptr) |
808 | 149k | { |
809 | 149k | if (NumArgs149k ) { |
810 | 88.8k | this->Args = new (C) Stmt*[Args.size()]; |
811 | 88.8k | |
812 | 236k | for (unsigned i = 0; i != Args.size()236k ; ++i147k ) { |
813 | 147k | assert(Args[i] && "NULL argument in CXXConstructExpr"); |
814 | 147k | |
815 | 147k | if (Args[i]->isValueDependent()) |
816 | 498 | ExprBits.ValueDependent = true; |
817 | 147k | if (Args[i]->isInstantiationDependent()) |
818 | 498 | ExprBits.InstantiationDependent = true; |
819 | 147k | if (Args[i]->containsUnexpandedParameterPack()) |
820 | 8 | ExprBits.ContainsUnexpandedParameterPack = true; |
821 | 147k | |
822 | 147k | this->Args[i] = Args[i]; |
823 | 147k | } |
824 | 88.8k | } |
825 | 149k | } |
826 | | |
827 | | LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit, |
828 | | LambdaCaptureKind Kind, VarDecl *Var, |
829 | | SourceLocation EllipsisLoc) |
830 | | : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) |
831 | 2.22k | { |
832 | 2.22k | unsigned Bits = 0; |
833 | 2.22k | if (Implicit) |
834 | 1.19k | Bits |= Capture_Implicit; |
835 | 2.22k | |
836 | 2.22k | switch (Kind) { |
837 | 114 | case LCK_StarThis: |
838 | 114 | Bits |= Capture_ByCopy; |
839 | 114 | // Fall through |
840 | 490 | case LCK_This: |
841 | 490 | assert(!Var && "'this' capture cannot have a variable!"); |
842 | 490 | Bits |= Capture_This; |
843 | 490 | break; |
844 | 114 | |
845 | 709 | case LCK_ByCopy: |
846 | 709 | Bits |= Capture_ByCopy; |
847 | 709 | // Fall through |
848 | 1.69k | case LCK_ByRef: |
849 | 1.69k | assert(Var && "capture must have a variable!"); |
850 | 1.69k | break; |
851 | 34 | case LCK_VLAType: |
852 | 34 | assert(!Var && "VLA type capture cannot have a variable!"); |
853 | 34 | break; |
854 | 2.22k | } |
855 | 2.22k | DeclAndBits.setInt(Bits); |
856 | 2.22k | } |
857 | | |
858 | 1.04k | LambdaCaptureKind LambdaCapture::getCaptureKind() const { |
859 | 1.04k | if (capturesVLAType()) |
860 | 2 | return LCK_VLAType; |
861 | 1.03k | bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy; |
862 | 1.03k | if (capturesThis()) |
863 | 341 | return CapByCopy ? 341 LCK_StarThis50 : LCK_This291 ; |
864 | 697 | return CapByCopy ? 697 LCK_ByCopy241 : LCK_ByRef456 ; |
865 | 1.04k | } |
866 | | |
867 | | LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange, |
868 | | LambdaCaptureDefault CaptureDefault, |
869 | | SourceLocation CaptureDefaultLoc, |
870 | | ArrayRef<LambdaCapture> Captures, bool ExplicitParams, |
871 | | bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
872 | | SourceLocation ClosingBrace, |
873 | | bool ContainsUnexpandedParameterPack) |
874 | | : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, T->isDependentType(), |
875 | | T->isDependentType(), T->isDependentType(), |
876 | | ContainsUnexpandedParameterPack), |
877 | | IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc), |
878 | | NumCaptures(Captures.size()), CaptureDefault(CaptureDefault), |
879 | | ExplicitParams(ExplicitParams), ExplicitResultType(ExplicitResultType), |
880 | 3.93k | ClosingBrace(ClosingBrace) { |
881 | 3.93k | assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments"); |
882 | 3.93k | CXXRecordDecl *Class = getLambdaClass(); |
883 | 3.93k | CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData(); |
884 | 3.93k | |
885 | 3.93k | // FIXME: Propagate "has unexpanded parameter pack" bit. |
886 | 3.93k | |
887 | 3.93k | // Copy captures. |
888 | 3.93k | const ASTContext &Context = Class->getASTContext(); |
889 | 3.93k | Data.NumCaptures = NumCaptures; |
890 | 3.93k | Data.NumExplicitCaptures = 0; |
891 | 3.93k | Data.Captures = |
892 | 3.93k | (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * NumCaptures); |
893 | 3.93k | LambdaCapture *ToCapture = Data.Captures; |
894 | 5.94k | for (unsigned I = 0, N = Captures.size(); I != N5.94k ; ++I2.01k ) { |
895 | 2.01k | if (Captures[I].isExplicit()) |
896 | 1.01k | ++Data.NumExplicitCaptures; |
897 | 2.01k | |
898 | 2.01k | *ToCapture++ = Captures[I]; |
899 | 2.01k | } |
900 | 3.93k | |
901 | 3.93k | // Copy initialization expressions for the non-static data members. |
902 | 3.93k | Stmt **Stored = getStoredStmts(); |
903 | 5.94k | for (unsigned I = 0, N = CaptureInits.size(); I != N5.94k ; ++I2.01k ) |
904 | 2.01k | *Stored++ = CaptureInits[I]; |
905 | 3.93k | |
906 | 3.93k | // Copy the body of the lambda. |
907 | 3.93k | *Stored++ = getCallOperator()->getBody(); |
908 | 3.93k | } |
909 | | |
910 | | LambdaExpr *LambdaExpr::Create( |
911 | | const ASTContext &Context, CXXRecordDecl *Class, |
912 | | SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, |
913 | | SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures, |
914 | | bool ExplicitParams, bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
915 | 3.93k | SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack) { |
916 | 3.93k | // Determine the type of the expression (i.e., the type of the |
917 | 3.93k | // function object we're creating). |
918 | 3.93k | QualType T = Context.getTypeDeclType(Class); |
919 | 3.93k | |
920 | 3.93k | unsigned Size = totalSizeToAlloc<Stmt *>(Captures.size() + 1); |
921 | 3.93k | void *Mem = Context.Allocate(Size); |
922 | 3.93k | return new (Mem) |
923 | 3.93k | LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc, |
924 | 3.93k | Captures, ExplicitParams, ExplicitResultType, CaptureInits, |
925 | 3.93k | ClosingBrace, ContainsUnexpandedParameterPack); |
926 | 3.93k | } |
927 | | |
928 | | LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C, |
929 | 98 | unsigned NumCaptures) { |
930 | 98 | unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1); |
931 | 98 | void *Mem = C.Allocate(Size); |
932 | 98 | return new (Mem) LambdaExpr(EmptyShell(), NumCaptures); |
933 | 98 | } |
934 | | |
935 | 619 | bool LambdaExpr::isInitCapture(const LambdaCapture *C) const { |
936 | 519 | return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() && |
937 | 207 | (getCallOperator() == C->getCapturedVar()->getDeclContext())); |
938 | 619 | } |
939 | | |
940 | 7.29k | LambdaExpr::capture_iterator LambdaExpr::capture_begin() const { |
941 | 7.29k | return getLambdaClass()->getLambdaData().Captures; |
942 | 7.29k | } |
943 | | |
944 | 2.86k | LambdaExpr::capture_iterator LambdaExpr::capture_end() const { |
945 | 2.86k | return capture_begin() + NumCaptures; |
946 | 2.86k | } |
947 | | |
948 | 53 | LambdaExpr::capture_range LambdaExpr::captures() const { |
949 | 53 | return capture_range(capture_begin(), capture_end()); |
950 | 53 | } |
951 | | |
952 | 1.25k | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const { |
953 | 1.25k | return capture_begin(); |
954 | 1.25k | } |
955 | | |
956 | 1.25k | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const { |
957 | 1.25k | struct CXXRecordDecl::LambdaDefinitionData &Data |
958 | 1.25k | = getLambdaClass()->getLambdaData(); |
959 | 1.25k | return Data.Captures + Data.NumExplicitCaptures; |
960 | 1.25k | } |
961 | | |
962 | 0 | LambdaExpr::capture_range LambdaExpr::explicit_captures() const { |
963 | 0 | return capture_range(explicit_capture_begin(), explicit_capture_end()); |
964 | 0 | } |
965 | | |
966 | 0 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const { |
967 | 0 | return explicit_capture_end(); |
968 | 0 | } |
969 | | |
970 | 0 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const { |
971 | 0 | return capture_end(); |
972 | 0 | } |
973 | | |
974 | 0 | LambdaExpr::capture_range LambdaExpr::implicit_captures() const { |
975 | 0 | return capture_range(implicit_capture_begin(), implicit_capture_end()); |
976 | 0 | } |
977 | | |
978 | 27.1k | CXXRecordDecl *LambdaExpr::getLambdaClass() const { |
979 | 27.1k | return getType()->getAsCXXRecordDecl(); |
980 | 27.1k | } |
981 | | |
982 | 11.5k | CXXMethodDecl *LambdaExpr::getCallOperator() const { |
983 | 11.5k | CXXRecordDecl *Record = getLambdaClass(); |
984 | 11.5k | return Record->getLambdaCallOperator(); |
985 | 11.5k | } |
986 | | |
987 | 1.25k | TemplateParameterList *LambdaExpr::getTemplateParameterList() const { |
988 | 1.25k | CXXRecordDecl *Record = getLambdaClass(); |
989 | 1.25k | return Record->getGenericLambdaTemplateParameterList(); |
990 | 1.25k | |
991 | 1.25k | } |
992 | | |
993 | 1.44k | CompoundStmt *LambdaExpr::getBody() const { |
994 | 1.44k | // FIXME: this mutation in getBody is bogus. It should be |
995 | 1.44k | // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I |
996 | 1.44k | // don't understand, that doesn't work. |
997 | 1.44k | if (!getStoredStmts()[NumCaptures]) |
998 | 33 | *const_cast<clang::Stmt **>(&getStoredStmts()[NumCaptures]) = |
999 | 33 | getCallOperator()->getBody(); |
1000 | 1.44k | |
1001 | 1.44k | return static_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]); |
1002 | 1.44k | } |
1003 | | |
1004 | 1.22k | bool LambdaExpr::isMutable() const { |
1005 | 1.22k | return !getCallOperator()->isConst(); |
1006 | 1.22k | } |
1007 | | |
1008 | | ExprWithCleanups::ExprWithCleanups(Expr *subexpr, |
1009 | | bool CleanupsHaveSideEffects, |
1010 | | ArrayRef<CleanupObject> objects) |
1011 | | : Expr(ExprWithCleanupsClass, subexpr->getType(), |
1012 | | subexpr->getValueKind(), subexpr->getObjectKind(), |
1013 | | subexpr->isTypeDependent(), subexpr->isValueDependent(), |
1014 | | subexpr->isInstantiationDependent(), |
1015 | | subexpr->containsUnexpandedParameterPack()), |
1016 | 59.0k | SubExpr(subexpr) { |
1017 | 59.0k | ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects; |
1018 | 59.0k | ExprWithCleanupsBits.NumObjects = objects.size(); |
1019 | 59.8k | for (unsigned i = 0, e = objects.size(); i != e59.8k ; ++i852 ) |
1020 | 852 | getTrailingObjects<CleanupObject>()[i] = objects[i]; |
1021 | 59.0k | } |
1022 | | |
1023 | | ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr, |
1024 | | bool CleanupsHaveSideEffects, |
1025 | 59.0k | ArrayRef<CleanupObject> objects) { |
1026 | 59.0k | void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()), |
1027 | 59.0k | alignof(ExprWithCleanups)); |
1028 | 59.0k | return new (buffer) |
1029 | 59.0k | ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects); |
1030 | 59.0k | } |
1031 | | |
1032 | | ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects) |
1033 | 151 | : Expr(ExprWithCleanupsClass, empty) { |
1034 | 151 | ExprWithCleanupsBits.NumObjects = numObjects; |
1035 | 151 | } |
1036 | | |
1037 | | ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, |
1038 | | EmptyShell empty, |
1039 | 151 | unsigned numObjects) { |
1040 | 151 | void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects), |
1041 | 151 | alignof(ExprWithCleanups)); |
1042 | 151 | return new (buffer) ExprWithCleanups(empty, numObjects); |
1043 | 151 | } |
1044 | | |
1045 | | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type, |
1046 | | SourceLocation LParenLoc, |
1047 | | ArrayRef<Expr*> Args, |
1048 | | SourceLocation RParenLoc) |
1049 | | : Expr(CXXUnresolvedConstructExprClass, |
1050 | | Type->getType().getNonReferenceType(), |
1051 | | (Type->getType()->isLValueReferenceType() ? VK_LValue |
1052 | | :Type->getType()->isRValueReferenceType()? VK_XValue |
1053 | | :VK_RValue), |
1054 | | OK_Ordinary, |
1055 | | Type->getType()->isDependentType() || |
1056 | | Type->getType()->getContainedDeducedType(), |
1057 | | true, true, |
1058 | | Type->getType()->containsUnexpandedParameterPack()), |
1059 | | Type(Type), |
1060 | | LParenLoc(LParenLoc), |
1061 | | RParenLoc(RParenLoc), |
1062 | 13.3k | NumArgs(Args.size()) { |
1063 | 13.3k | Expr **StoredArgs = getTrailingObjects<Expr *>(); |
1064 | 24.2k | for (unsigned I = 0; I != Args.size()24.2k ; ++I10.9k ) { |
1065 | 10.9k | if (Args[I]->containsUnexpandedParameterPack()) |
1066 | 7 | ExprBits.ContainsUnexpandedParameterPack = true; |
1067 | 10.9k | |
1068 | 10.9k | StoredArgs[I] = Args[I]; |
1069 | 10.9k | } |
1070 | 13.3k | } |
1071 | | |
1072 | | CXXUnresolvedConstructExpr * |
1073 | | CXXUnresolvedConstructExpr::Create(const ASTContext &C, |
1074 | | TypeSourceInfo *Type, |
1075 | | SourceLocation LParenLoc, |
1076 | | ArrayRef<Expr*> Args, |
1077 | 13.3k | SourceLocation RParenLoc) { |
1078 | 13.3k | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Args.size())); |
1079 | 13.3k | return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc); |
1080 | 13.3k | } |
1081 | | |
1082 | | CXXUnresolvedConstructExpr * |
1083 | 268 | CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &C, unsigned NumArgs) { |
1084 | 268 | Stmt::EmptyShell Empty; |
1085 | 268 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumArgs)); |
1086 | 268 | return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); |
1087 | 268 | } |
1088 | | |
1089 | 7.29k | SourceLocation CXXUnresolvedConstructExpr::getLocStart() const { |
1090 | 7.29k | return Type->getTypeLoc().getBeginLoc(); |
1091 | 7.29k | } |
1092 | | |
1093 | | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr( |
1094 | | const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow, |
1095 | | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
1096 | | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, |
1097 | | DeclarationNameInfo MemberNameInfo, |
1098 | | const TemplateArgumentListInfo *TemplateArgs) |
1099 | | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, VK_LValue, |
1100 | | OK_Ordinary, true, true, true, |
1101 | | ((Base && Base->containsUnexpandedParameterPack()) || |
1102 | | (QualifierLoc && |
1103 | | QualifierLoc.getNestedNameSpecifier() |
1104 | | ->containsUnexpandedParameterPack()) || |
1105 | | MemberNameInfo.containsUnexpandedParameterPack())), |
1106 | | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
1107 | | HasTemplateKWAndArgsInfo(TemplateArgs != nullptr || |
1108 | | TemplateKWLoc.isValid()), |
1109 | | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
1110 | | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
1111 | 123k | MemberNameInfo(MemberNameInfo) { |
1112 | 123k | if (TemplateArgs123k ) { |
1113 | 103 | bool Dependent = true; |
1114 | 103 | bool InstantiationDependent = true; |
1115 | 103 | bool ContainsUnexpandedParameterPack = false; |
1116 | 103 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
1117 | 103 | TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(), |
1118 | 103 | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
1119 | 103 | if (ContainsUnexpandedParameterPack) |
1120 | 1 | ExprBits.ContainsUnexpandedParameterPack = true; |
1121 | 123k | } else if (123k TemplateKWLoc.isValid()123k ) { |
1122 | 4 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
1123 | 4 | TemplateKWLoc); |
1124 | 4 | } |
1125 | 123k | } |
1126 | | |
1127 | | CXXDependentScopeMemberExpr * |
1128 | | CXXDependentScopeMemberExpr::Create(const ASTContext &C, |
1129 | | Expr *Base, QualType BaseType, bool IsArrow, |
1130 | | SourceLocation OperatorLoc, |
1131 | | NestedNameSpecifierLoc QualifierLoc, |
1132 | | SourceLocation TemplateKWLoc, |
1133 | | NamedDecl *FirstQualifierFoundInScope, |
1134 | | DeclarationNameInfo MemberNameInfo, |
1135 | 123k | const TemplateArgumentListInfo *TemplateArgs) { |
1136 | 122k | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid(); |
1137 | 123k | unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size()103 : 0122k ; |
1138 | 123k | std::size_t Size = |
1139 | 123k | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
1140 | 123k | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
1141 | 123k | |
1142 | 123k | void *Mem = C.Allocate(Size, alignof(CXXDependentScopeMemberExpr)); |
1143 | 123k | return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, |
1144 | 123k | IsArrow, OperatorLoc, |
1145 | 123k | QualifierLoc, |
1146 | 123k | TemplateKWLoc, |
1147 | 123k | FirstQualifierFoundInScope, |
1148 | 123k | MemberNameInfo, TemplateArgs); |
1149 | 123k | } |
1150 | | |
1151 | | CXXDependentScopeMemberExpr * |
1152 | | CXXDependentScopeMemberExpr::CreateEmpty(const ASTContext &C, |
1153 | | bool HasTemplateKWAndArgsInfo, |
1154 | 403 | unsigned NumTemplateArgs) { |
1155 | 403 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
1156 | 403 | std::size_t Size = |
1157 | 403 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
1158 | 403 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
1159 | 403 | void *Mem = C.Allocate(Size, alignof(CXXDependentScopeMemberExpr)); |
1160 | 403 | CXXDependentScopeMemberExpr *E |
1161 | 403 | = new (Mem) CXXDependentScopeMemberExpr(C, nullptr, QualType(), |
1162 | 403 | 0, SourceLocation(), |
1163 | 403 | NestedNameSpecifierLoc(), |
1164 | 403 | SourceLocation(), nullptr, |
1165 | 403 | DeclarationNameInfo(), nullptr); |
1166 | 403 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
1167 | 403 | return E; |
1168 | 403 | } |
1169 | | |
1170 | 157k | bool CXXDependentScopeMemberExpr::isImplicitAccess() const { |
1171 | 157k | if (!Base) |
1172 | 15.0k | return true; |
1173 | 142k | |
1174 | 142k | return cast<Expr>(Base)->isImplicitCXXThis(); |
1175 | 142k | } |
1176 | | |
1177 | | static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, |
1178 | 34.4k | UnresolvedSetIterator end) { |
1179 | 67.2k | do { |
1180 | 67.2k | NamedDecl *decl = *begin; |
1181 | 67.2k | if (isa<UnresolvedUsingValueDecl>(decl)) |
1182 | 409 | return false; |
1183 | 66.8k | |
1184 | 66.8k | // Unresolved member expressions should only contain methods and |
1185 | 66.8k | // method templates. |
1186 | 66.8k | if (66.8k cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction()) |
1187 | 66.8k | ->isStatic()) |
1188 | 361 | return false; |
1189 | 66.4k | } while (++begin != end); |
1190 | 34.4k | |
1191 | 33.6k | return true; |
1192 | 34.4k | } |
1193 | | |
1194 | | UnresolvedMemberExpr::UnresolvedMemberExpr(const ASTContext &C, |
1195 | | bool HasUnresolvedUsing, |
1196 | | Expr *Base, QualType BaseType, |
1197 | | bool IsArrow, |
1198 | | SourceLocation OperatorLoc, |
1199 | | NestedNameSpecifierLoc QualifierLoc, |
1200 | | SourceLocation TemplateKWLoc, |
1201 | | const DeclarationNameInfo &MemberNameInfo, |
1202 | | const TemplateArgumentListInfo *TemplateArgs, |
1203 | | UnresolvedSetIterator Begin, |
1204 | | UnresolvedSetIterator End) |
1205 | | : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc, |
1206 | | MemberNameInfo, TemplateArgs, Begin, End, |
1207 | | // Dependent |
1208 | | ((Base && Base->isTypeDependent()) || |
1209 | | BaseType->isDependentType()), |
1210 | | ((Base && Base->isInstantiationDependent()) || |
1211 | | BaseType->isInstantiationDependentType()), |
1212 | | // Contains unexpanded parameter pack |
1213 | | ((Base && Base->containsUnexpandedParameterPack()) || |
1214 | | BaseType->containsUnexpandedParameterPack())), |
1215 | | IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
1216 | 34.4k | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
1217 | 34.4k | |
1218 | 34.4k | // Check whether all of the members are non-static member functions, |
1219 | 34.4k | // and if so, mark give this bound-member type instead of overload type. |
1220 | 34.4k | if (hasOnlyNonStaticMemberFunctions(Begin, End)) |
1221 | 33.6k | setType(C.BoundMemberTy); |
1222 | 34.4k | } |
1223 | | |
1224 | 71.1k | bool UnresolvedMemberExpr::isImplicitAccess() const { |
1225 | 71.1k | if (!Base) |
1226 | 9.72k | return true; |
1227 | 61.3k | |
1228 | 61.3k | return cast<Expr>(Base)->isImplicitCXXThis(); |
1229 | 61.3k | } |
1230 | | |
1231 | | UnresolvedMemberExpr *UnresolvedMemberExpr::Create( |
1232 | | const ASTContext &C, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, |
1233 | | bool IsArrow, SourceLocation OperatorLoc, |
1234 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
1235 | | const DeclarationNameInfo &MemberNameInfo, |
1236 | | const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, |
1237 | 34.4k | UnresolvedSetIterator End) { |
1238 | 33.0k | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid(); |
1239 | 34.4k | std::size_t Size = |
1240 | 34.4k | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
1241 | 34.4k | HasTemplateKWAndArgsInfo, TemplateArgs ? TemplateArgs->size()1.42k : 033.0k ); |
1242 | 34.4k | |
1243 | 34.4k | void *Mem = C.Allocate(Size, alignof(UnresolvedMemberExpr)); |
1244 | 34.4k | return new (Mem) UnresolvedMemberExpr( |
1245 | 34.4k | C, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, |
1246 | 34.4k | TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End); |
1247 | 34.4k | } |
1248 | | |
1249 | | UnresolvedMemberExpr * |
1250 | | UnresolvedMemberExpr::CreateEmpty(const ASTContext &C, |
1251 | | bool HasTemplateKWAndArgsInfo, |
1252 | 6 | unsigned NumTemplateArgs) { |
1253 | 6 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
1254 | 6 | std::size_t Size = |
1255 | 6 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
1256 | 6 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
1257 | 6 | |
1258 | 6 | void *Mem = C.Allocate(Size, alignof(UnresolvedMemberExpr)); |
1259 | 6 | UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); |
1260 | 6 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
1261 | 6 | return E; |
1262 | 6 | } |
1263 | | |
1264 | 6.52k | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { |
1265 | 6.52k | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
1266 | 6.52k | |
1267 | 6.52k | // If there was a nested name specifier, it names the naming class. |
1268 | 6.52k | // It can't be dependent: after all, we were actually able to do the |
1269 | 6.52k | // lookup. |
1270 | 6.52k | CXXRecordDecl *Record = nullptr; |
1271 | 6.52k | auto *NNS = getQualifier(); |
1272 | 6.52k | if (NNS && 6.52k NNS->getKind() != NestedNameSpecifier::Super924 ) { |
1273 | 924 | const Type *T = getQualifier()->getAsType(); |
1274 | 924 | assert(T && "qualifier in member expression does not name type"); |
1275 | 924 | Record = T->getAsCXXRecordDecl(); |
1276 | 924 | assert(Record && "qualifier in member expression does not name record"); |
1277 | 924 | } |
1278 | 6.52k | // Otherwise the naming class must have been the base class. |
1279 | 5.59k | else { |
1280 | 5.59k | QualType BaseType = getBaseType().getNonReferenceType(); |
1281 | 5.59k | if (isArrow()5.59k ) { |
1282 | 5.46k | const PointerType *PT = BaseType->getAs<PointerType>(); |
1283 | 5.46k | assert(PT && "base of arrow member access is not pointer"); |
1284 | 5.46k | BaseType = PT->getPointeeType(); |
1285 | 5.46k | } |
1286 | 5.59k | |
1287 | 5.59k | Record = BaseType->getAsCXXRecordDecl(); |
1288 | 5.59k | assert(Record && "base of member expression does not name record"); |
1289 | 5.59k | } |
1290 | 6.52k | |
1291 | 6.52k | return Record; |
1292 | 6.52k | } |
1293 | | |
1294 | | SizeOfPackExpr * |
1295 | | SizeOfPackExpr::Create(ASTContext &Context, SourceLocation OperatorLoc, |
1296 | | NamedDecl *Pack, SourceLocation PackLoc, |
1297 | | SourceLocation RParenLoc, |
1298 | | Optional<unsigned> Length, |
1299 | 365 | ArrayRef<TemplateArgument> PartialArgs) { |
1300 | 365 | void *Storage = |
1301 | 365 | Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size())); |
1302 | 365 | return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack, |
1303 | 365 | PackLoc, RParenLoc, Length, PartialArgs); |
1304 | 365 | } |
1305 | | |
1306 | | SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context, |
1307 | 0 | unsigned NumPartialArgs) { |
1308 | 0 | void *Storage = |
1309 | 0 | Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs)); |
1310 | 0 | return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs); |
1311 | 0 | } |
1312 | | |
1313 | | SubstNonTypeTemplateParmPackExpr:: |
1314 | | SubstNonTypeTemplateParmPackExpr(QualType T, |
1315 | | NonTypeTemplateParmDecl *Param, |
1316 | | SourceLocation NameLoc, |
1317 | | const TemplateArgument &ArgPack) |
1318 | | : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary, |
1319 | | true, true, true, true), |
1320 | | Param(Param), Arguments(ArgPack.pack_begin()), |
1321 | 21 | NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { } |
1322 | | |
1323 | 24 | TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { |
1324 | 24 | return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments)); |
1325 | 24 | } |
1326 | | |
1327 | | FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, |
1328 | | SourceLocation NameLoc, |
1329 | | unsigned NumParams, |
1330 | | ParmVarDecl *const *Params) |
1331 | | : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true, |
1332 | | true, true), |
1333 | 124 | ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) { |
1334 | 124 | if (Params) |
1335 | 118 | std::uninitialized_copy(Params, Params + NumParams, |
1336 | 118 | getTrailingObjects<ParmVarDecl *>()); |
1337 | 124 | } |
1338 | | |
1339 | | FunctionParmPackExpr * |
1340 | | FunctionParmPackExpr::Create(const ASTContext &Context, QualType T, |
1341 | | ParmVarDecl *ParamPack, SourceLocation NameLoc, |
1342 | 118 | ArrayRef<ParmVarDecl *> Params) { |
1343 | 118 | return new (Context.Allocate(totalSizeToAlloc<ParmVarDecl *>(Params.size()))) |
1344 | 118 | FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data()); |
1345 | 118 | } |
1346 | | |
1347 | | FunctionParmPackExpr * |
1348 | | FunctionParmPackExpr::CreateEmpty(const ASTContext &Context, |
1349 | 6 | unsigned NumParams) { |
1350 | 6 | return new (Context.Allocate(totalSizeToAlloc<ParmVarDecl *>(NumParams))) |
1351 | 6 | FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr); |
1352 | 6 | } |
1353 | | |
1354 | | void MaterializeTemporaryExpr::setExtendingDecl(const ValueDecl *ExtendedBy, |
1355 | 1.23k | unsigned ManglingNumber) { |
1356 | 1.23k | // We only need extra state if we have to remember more than just the Stmt. |
1357 | 1.23k | if (!ExtendedBy) |
1358 | 188 | return; |
1359 | 1.04k | |
1360 | 1.04k | // We may need to allocate extra storage for the mangling number and the |
1361 | 1.04k | // extended-by ValueDecl. |
1362 | 1.04k | if (1.04k !State.is<ExtraState *>()1.04k ) { |
1363 | 1.02k | auto ES = new (ExtendedBy->getASTContext()) ExtraState; |
1364 | 1.02k | ES->Temporary = State.get<Stmt *>(); |
1365 | 1.02k | State = ES; |
1366 | 1.02k | } |
1367 | 1.23k | |
1368 | 1.23k | auto ES = State.get<ExtraState *>(); |
1369 | 1.23k | ES->ExtendingDecl = ExtendedBy; |
1370 | 1.23k | ES->ManglingNumber = ManglingNumber; |
1371 | 1.23k | } |
1372 | | |
1373 | | TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, |
1374 | | ArrayRef<TypeSourceInfo *> Args, |
1375 | | SourceLocation RParenLoc, |
1376 | | bool Value) |
1377 | | : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary, |
1378 | | /*TypeDependent=*/false, |
1379 | | /*ValueDependent=*/false, |
1380 | | /*InstantiationDependent=*/false, |
1381 | | /*ContainsUnexpandedParameterPack=*/false), |
1382 | | Loc(Loc), RParenLoc(RParenLoc) |
1383 | 5.51k | { |
1384 | 5.51k | TypeTraitExprBits.Kind = Kind; |
1385 | 5.51k | TypeTraitExprBits.Value = Value; |
1386 | 5.51k | TypeTraitExprBits.NumArgs = Args.size(); |
1387 | 5.51k | |
1388 | 5.51k | TypeSourceInfo **ToArgs = getTrailingObjects<TypeSourceInfo *>(); |
1389 | 5.51k | |
1390 | 12.3k | for (unsigned I = 0, N = Args.size(); I != N12.3k ; ++I6.80k ) { |
1391 | 6.80k | if (Args[I]->getType()->isDependentType()) |
1392 | 119 | setValueDependent(true); |
1393 | 6.80k | if (Args[I]->getType()->isInstantiationDependentType()) |
1394 | 119 | setInstantiationDependent(true); |
1395 | 6.80k | if (Args[I]->getType()->containsUnexpandedParameterPack()) |
1396 | 3 | setContainsUnexpandedParameterPack(true); |
1397 | 6.80k | |
1398 | 6.80k | ToArgs[I] = Args[I]; |
1399 | 6.80k | } |
1400 | 5.51k | } |
1401 | | |
1402 | | TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T, |
1403 | | SourceLocation Loc, |
1404 | | TypeTrait Kind, |
1405 | | ArrayRef<TypeSourceInfo *> Args, |
1406 | | SourceLocation RParenLoc, |
1407 | 5.51k | bool Value) { |
1408 | 5.51k | void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size())); |
1409 | 5.51k | return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value); |
1410 | 5.51k | } |
1411 | | |
1412 | | TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C, |
1413 | 4 | unsigned NumArgs) { |
1414 | 4 | void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs)); |
1415 | 4 | return new (Mem) TypeTraitExpr(EmptyShell()); |
1416 | 4 | } |
1417 | | |
1418 | 0 | void ArrayTypeTraitExpr::anchor() { } |