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/Basic/IdentifierTable.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/DeclTemplate.h"
17 #include "clang/AST/ExprCXX.h"
18 #include "clang/AST/TypeLoc.h"
19 using namespace clang;
20
21
22 //===----------------------------------------------------------------------===//
23 // Child Iterators for iterating over subexpressions/substatements
24 //===----------------------------------------------------------------------===//
25
getTypeOperand() const26 QualType CXXTypeidExpr::getTypeOperand() const {
27 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
28 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
29 .getUnqualifiedType();
30 }
31
getTypeOperand() const32 QualType CXXUuidofExpr::getTypeOperand() const {
33 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
34 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
35 .getUnqualifiedType();
36 }
37
38 // CXXScalarValueInitExpr
getSourceRange() const39 SourceRange CXXScalarValueInitExpr::getSourceRange() const {
40 SourceLocation Start = RParenLoc;
41 if (TypeInfo)
42 Start = TypeInfo->getTypeLoc().getBeginLoc();
43 return SourceRange(Start, RParenLoc);
44 }
45
46 // CXXNewExpr
CXXNewExpr(ASTContext & C,bool globalNew,FunctionDecl * operatorNew,Expr ** placementArgs,unsigned numPlaceArgs,SourceRange TypeIdParens,Expr * arraySize,CXXConstructorDecl * constructor,bool initializer,Expr ** constructorArgs,unsigned numConsArgs,FunctionDecl * operatorDelete,bool usualArrayDeleteWantsSize,QualType ty,TypeSourceInfo * AllocatedTypeInfo,SourceLocation startLoc,SourceLocation endLoc,SourceLocation constructorLParen,SourceLocation constructorRParen)47 CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
48 Expr **placementArgs, unsigned numPlaceArgs,
49 SourceRange TypeIdParens, Expr *arraySize,
50 CXXConstructorDecl *constructor, bool initializer,
51 Expr **constructorArgs, unsigned numConsArgs,
52 FunctionDecl *operatorDelete,
53 bool usualArrayDeleteWantsSize, QualType ty,
54 TypeSourceInfo *AllocatedTypeInfo,
55 SourceLocation startLoc, SourceLocation endLoc,
56 SourceLocation constructorLParen,
57 SourceLocation constructorRParen)
58 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
59 ty->isDependentType(), ty->isDependentType(),
60 ty->isInstantiationDependentType(),
61 ty->containsUnexpandedParameterPack()),
62 GlobalNew(globalNew), Initializer(initializer),
63 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
64 SubExprs(0), OperatorNew(operatorNew),
65 OperatorDelete(operatorDelete), Constructor(constructor),
66 AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens),
67 StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen),
68 ConstructorRParen(constructorRParen) {
69 AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs);
70 unsigned i = 0;
71 if (Array) {
72 if (arraySize->isInstantiationDependent())
73 ExprBits.InstantiationDependent = true;
74
75 if (arraySize->containsUnexpandedParameterPack())
76 ExprBits.ContainsUnexpandedParameterPack = true;
77
78 SubExprs[i++] = arraySize;
79 }
80
81 for (unsigned j = 0; j < NumPlacementArgs; ++j) {
82 if (placementArgs[j]->isInstantiationDependent())
83 ExprBits.InstantiationDependent = true;
84 if (placementArgs[j]->containsUnexpandedParameterPack())
85 ExprBits.ContainsUnexpandedParameterPack = true;
86
87 SubExprs[i++] = placementArgs[j];
88 }
89
90 for (unsigned j = 0; j < NumConstructorArgs; ++j) {
91 if (constructorArgs[j]->isInstantiationDependent())
92 ExprBits.InstantiationDependent = true;
93 if (constructorArgs[j]->containsUnexpandedParameterPack())
94 ExprBits.ContainsUnexpandedParameterPack = true;
95
96 SubExprs[i++] = constructorArgs[j];
97 }
98 }
99
AllocateArgsArray(ASTContext & C,bool isArray,unsigned numPlaceArgs,unsigned numConsArgs)100 void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
101 unsigned numPlaceArgs, unsigned numConsArgs){
102 assert(SubExprs == 0 && "SubExprs already allocated");
103 Array = isArray;
104 NumPlacementArgs = numPlaceArgs;
105 NumConstructorArgs = numConsArgs;
106
107 unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs;
108 SubExprs = new (C) Stmt*[TotalSize];
109 }
110
shouldNullCheckAllocation(ASTContext & Ctx) const111 bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
112 return getOperatorNew()->getType()->
113 castAs<FunctionProtoType>()->isNothrow(Ctx);
114 }
115
116 // CXXDeleteExpr
getDestroyedType() const117 QualType CXXDeleteExpr::getDestroyedType() const {
118 const Expr *Arg = getArgument();
119 while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
120 if (ICE->getCastKind() != CK_UserDefinedConversion &&
121 ICE->getType()->isVoidPointerType())
122 Arg = ICE->getSubExpr();
123 else
124 break;
125 }
126 // The type-to-delete may not be a pointer if it's a dependent type.
127 const QualType ArgType = Arg->getType();
128
129 if (ArgType->isDependentType() && !ArgType->isPointerType())
130 return QualType();
131
132 return ArgType->getAs<PointerType>()->getPointeeType();
133 }
134
135 // CXXPseudoDestructorExpr
PseudoDestructorTypeStorage(TypeSourceInfo * Info)136 PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
137 : Type(Info)
138 {
139 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
140 }
141
CXXPseudoDestructorExpr(ASTContext & Context,Expr * Base,bool isArrow,SourceLocation OperatorLoc,NestedNameSpecifierLoc QualifierLoc,TypeSourceInfo * ScopeType,SourceLocation ColonColonLoc,SourceLocation TildeLoc,PseudoDestructorTypeStorage DestroyedType)142 CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
143 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
144 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
145 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
146 PseudoDestructorTypeStorage DestroyedType)
147 : Expr(CXXPseudoDestructorExprClass,
148 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
149 FunctionProtoType::ExtProtoInfo())),
150 VK_RValue, OK_Ordinary,
151 /*isTypeDependent=*/(Base->isTypeDependent() ||
152 (DestroyedType.getTypeSourceInfo() &&
153 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
154 /*isValueDependent=*/Base->isValueDependent(),
155 (Base->isInstantiationDependent() ||
156 (QualifierLoc &&
157 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
158 (ScopeType &&
159 ScopeType->getType()->isInstantiationDependentType()) ||
160 (DestroyedType.getTypeSourceInfo() &&
161 DestroyedType.getTypeSourceInfo()->getType()
162 ->isInstantiationDependentType())),
163 // ContainsUnexpandedParameterPack
164 (Base->containsUnexpandedParameterPack() ||
165 (QualifierLoc &&
166 QualifierLoc.getNestedNameSpecifier()
167 ->containsUnexpandedParameterPack()) ||
168 (ScopeType &&
169 ScopeType->getType()->containsUnexpandedParameterPack()) ||
170 (DestroyedType.getTypeSourceInfo() &&
171 DestroyedType.getTypeSourceInfo()->getType()
172 ->containsUnexpandedParameterPack()))),
173 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
174 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
175 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
176 DestroyedType(DestroyedType) { }
177
getDestroyedType() const178 QualType CXXPseudoDestructorExpr::getDestroyedType() const {
179 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
180 return TInfo->getType();
181
182 return QualType();
183 }
184
getSourceRange() const185 SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
186 SourceLocation End = DestroyedType.getLocation();
187 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
188 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
189 return SourceRange(Base->getLocStart(), End);
190 }
191
192
193 // UnresolvedLookupExpr
194 UnresolvedLookupExpr *
Create(ASTContext & C,CXXRecordDecl * NamingClass,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo,bool ADL,const TemplateArgumentListInfo & Args,UnresolvedSetIterator Begin,UnresolvedSetIterator End)195 UnresolvedLookupExpr::Create(ASTContext &C,
196 CXXRecordDecl *NamingClass,
197 NestedNameSpecifierLoc QualifierLoc,
198 const DeclarationNameInfo &NameInfo,
199 bool ADL,
200 const TemplateArgumentListInfo &Args,
201 UnresolvedSetIterator Begin,
202 UnresolvedSetIterator End)
203 {
204 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
205 ExplicitTemplateArgumentList::sizeFor(Args));
206 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
207 ADL, /*Overload*/ true, &Args,
208 Begin, End, /*StdIsAssociated=*/false);
209 }
210
211 UnresolvedLookupExpr *
CreateEmpty(ASTContext & C,bool HasExplicitTemplateArgs,unsigned NumTemplateArgs)212 UnresolvedLookupExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
213 unsigned NumTemplateArgs) {
214 std::size_t size = sizeof(UnresolvedLookupExpr);
215 if (HasExplicitTemplateArgs)
216 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
217
218 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
219 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
220 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
221 return E;
222 }
223
OverloadExpr(StmtClass K,ASTContext & C,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo,const TemplateArgumentListInfo * TemplateArgs,UnresolvedSetIterator Begin,UnresolvedSetIterator End,bool KnownDependent,bool KnownInstantiationDependent,bool KnownContainsUnexpandedParameterPack)224 OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
225 NestedNameSpecifierLoc QualifierLoc,
226 const DeclarationNameInfo &NameInfo,
227 const TemplateArgumentListInfo *TemplateArgs,
228 UnresolvedSetIterator Begin,
229 UnresolvedSetIterator End,
230 bool KnownDependent,
231 bool KnownInstantiationDependent,
232 bool KnownContainsUnexpandedParameterPack)
233 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
234 KnownDependent,
235 (KnownInstantiationDependent ||
236 NameInfo.isInstantiationDependent() ||
237 (QualifierLoc &&
238 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
239 (KnownContainsUnexpandedParameterPack ||
240 NameInfo.containsUnexpandedParameterPack() ||
241 (QualifierLoc &&
242 QualifierLoc.getNestedNameSpecifier()
243 ->containsUnexpandedParameterPack()))),
244 Results(0), NumResults(End - Begin), NameInfo(NameInfo),
245 QualifierLoc(QualifierLoc), HasExplicitTemplateArgs(TemplateArgs != 0)
246 {
247 NumResults = End - Begin;
248 if (NumResults) {
249 // Determine whether this expression is type-dependent.
250 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
251 if ((*I)->getDeclContext()->isDependentContext() ||
252 isa<UnresolvedUsingValueDecl>(*I)) {
253 ExprBits.TypeDependent = true;
254 ExprBits.ValueDependent = true;
255 }
256 }
257
258 Results = static_cast<DeclAccessPair *>(
259 C.Allocate(sizeof(DeclAccessPair) * NumResults,
260 llvm::alignOf<DeclAccessPair>()));
261 memcpy(Results, &*Begin.getIterator(),
262 NumResults * sizeof(DeclAccessPair));
263 }
264
265 // If we have explicit template arguments, check for dependent
266 // template arguments and whether they contain any unexpanded pack
267 // expansions.
268 if (TemplateArgs) {
269 bool Dependent = false;
270 bool InstantiationDependent = false;
271 bool ContainsUnexpandedParameterPack = false;
272 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
273 InstantiationDependent,
274 ContainsUnexpandedParameterPack);
275
276 if (Dependent) {
277 ExprBits.TypeDependent = true;
278 ExprBits.ValueDependent = true;
279 }
280 if (InstantiationDependent)
281 ExprBits.InstantiationDependent = true;
282 if (ContainsUnexpandedParameterPack)
283 ExprBits.ContainsUnexpandedParameterPack = true;
284 }
285
286 if (isTypeDependent())
287 setType(C.DependentTy);
288 }
289
initializeResults(ASTContext & C,UnresolvedSetIterator Begin,UnresolvedSetIterator End)290 void OverloadExpr::initializeResults(ASTContext &C,
291 UnresolvedSetIterator Begin,
292 UnresolvedSetIterator End) {
293 assert(Results == 0 && "Results already initialized!");
294 NumResults = End - Begin;
295 if (NumResults) {
296 Results = static_cast<DeclAccessPair *>(
297 C.Allocate(sizeof(DeclAccessPair) * NumResults,
298
299 llvm::alignOf<DeclAccessPair>()));
300 memcpy(Results, &*Begin.getIterator(),
301 NumResults * sizeof(DeclAccessPair));
302 }
303 }
304
getNamingClass() const305 CXXRecordDecl *OverloadExpr::getNamingClass() const {
306 if (isa<UnresolvedLookupExpr>(this))
307 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
308 else
309 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
310 }
311
312 // DependentScopeDeclRefExpr
DependentScopeDeclRefExpr(QualType T,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo,const TemplateArgumentListInfo * Args)313 DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
314 NestedNameSpecifierLoc QualifierLoc,
315 const DeclarationNameInfo &NameInfo,
316 const TemplateArgumentListInfo *Args)
317 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
318 true, true,
319 (NameInfo.isInstantiationDependent() ||
320 (QualifierLoc &&
321 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
322 (NameInfo.containsUnexpandedParameterPack() ||
323 (QualifierLoc &&
324 QualifierLoc.getNestedNameSpecifier()
325 ->containsUnexpandedParameterPack()))),
326 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
327 HasExplicitTemplateArgs(Args != 0)
328 {
329 if (Args) {
330 bool Dependent = true;
331 bool InstantiationDependent = true;
332 bool ContainsUnexpandedParameterPack
333 = ExprBits.ContainsUnexpandedParameterPack;
334
335 reinterpret_cast<ExplicitTemplateArgumentList*>(this+1)
336 ->initializeFrom(*Args, Dependent, InstantiationDependent,
337 ContainsUnexpandedParameterPack);
338
339 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
340 }
341 }
342
343 DependentScopeDeclRefExpr *
Create(ASTContext & C,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo,const TemplateArgumentListInfo * Args)344 DependentScopeDeclRefExpr::Create(ASTContext &C,
345 NestedNameSpecifierLoc QualifierLoc,
346 const DeclarationNameInfo &NameInfo,
347 const TemplateArgumentListInfo *Args) {
348 std::size_t size = sizeof(DependentScopeDeclRefExpr);
349 if (Args)
350 size += ExplicitTemplateArgumentList::sizeFor(*Args);
351 void *Mem = C.Allocate(size);
352 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
353 NameInfo, Args);
354 }
355
356 DependentScopeDeclRefExpr *
CreateEmpty(ASTContext & C,bool HasExplicitTemplateArgs,unsigned NumTemplateArgs)357 DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
358 bool HasExplicitTemplateArgs,
359 unsigned NumTemplateArgs) {
360 std::size_t size = sizeof(DependentScopeDeclRefExpr);
361 if (HasExplicitTemplateArgs)
362 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
363 void *Mem = C.Allocate(size);
364 DependentScopeDeclRefExpr *E
365 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
366 DeclarationNameInfo(), 0);
367 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
368 return E;
369 }
370
getSourceRange() const371 SourceRange CXXConstructExpr::getSourceRange() const {
372 if (isa<CXXTemporaryObjectExpr>(this))
373 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
374
375 if (ParenRange.isValid())
376 return SourceRange(Loc, ParenRange.getEnd());
377
378 SourceLocation End = Loc;
379 for (unsigned I = getNumArgs(); I > 0; --I) {
380 const Expr *Arg = getArg(I-1);
381 if (!Arg->isDefaultArgument()) {
382 SourceLocation NewEnd = Arg->getLocEnd();
383 if (NewEnd.isValid()) {
384 End = NewEnd;
385 break;
386 }
387 }
388 }
389
390 return SourceRange(Loc, End);
391 }
392
getSourceRange() const393 SourceRange CXXOperatorCallExpr::getSourceRange() const {
394 OverloadedOperatorKind Kind = getOperator();
395 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
396 if (getNumArgs() == 1)
397 // Prefix operator
398 return SourceRange(getOperatorLoc(),
399 getArg(0)->getSourceRange().getEnd());
400 else
401 // Postfix operator
402 return SourceRange(getArg(0)->getSourceRange().getBegin(),
403 getOperatorLoc());
404 } else if (Kind == OO_Arrow) {
405 return getArg(0)->getSourceRange();
406 } else if (Kind == OO_Call) {
407 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
408 } else if (Kind == OO_Subscript) {
409 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
410 } else if (getNumArgs() == 1) {
411 return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd());
412 } else if (getNumArgs() == 2) {
413 return SourceRange(getArg(0)->getSourceRange().getBegin(),
414 getArg(1)->getSourceRange().getEnd());
415 } else {
416 return SourceRange();
417 }
418 }
419
getImplicitObjectArgument() const420 Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
421 if (const MemberExpr *MemExpr =
422 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
423 return MemExpr->getBase();
424
425 // FIXME: Will eventually need to cope with member pointers.
426 return 0;
427 }
428
getMethodDecl() const429 CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
430 if (const MemberExpr *MemExpr =
431 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
432 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
433
434 // FIXME: Will eventually need to cope with member pointers.
435 return 0;
436 }
437
438
getRecordDecl()439 CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
440 Expr* ThisArg = getImplicitObjectArgument();
441 if (!ThisArg)
442 return 0;
443
444 if (ThisArg->getType()->isAnyPointerType())
445 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
446
447 return ThisArg->getType()->getAsCXXRecordDecl();
448 }
449
450
451 //===----------------------------------------------------------------------===//
452 // Named casts
453 //===----------------------------------------------------------------------===//
454
455 /// getCastName - Get the name of the C++ cast being used, e.g.,
456 /// "static_cast", "dynamic_cast", "reinterpret_cast", or
457 /// "const_cast". The returned pointer must not be freed.
getCastName() const458 const char *CXXNamedCastExpr::getCastName() const {
459 switch (getStmtClass()) {
460 case CXXStaticCastExprClass: return "static_cast";
461 case CXXDynamicCastExprClass: return "dynamic_cast";
462 case CXXReinterpretCastExprClass: return "reinterpret_cast";
463 case CXXConstCastExprClass: return "const_cast";
464 default: return "<invalid cast>";
465 }
466 }
467
Create(ASTContext & C,QualType T,ExprValueKind VK,CastKind K,Expr * Op,const CXXCastPath * BasePath,TypeSourceInfo * WrittenTy,SourceLocation L,SourceLocation RParenLoc)468 CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
469 ExprValueKind VK,
470 CastKind K, Expr *Op,
471 const CXXCastPath *BasePath,
472 TypeSourceInfo *WrittenTy,
473 SourceLocation L,
474 SourceLocation RParenLoc) {
475 unsigned PathSize = (BasePath ? BasePath->size() : 0);
476 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
477 + PathSize * sizeof(CXXBaseSpecifier*));
478 CXXStaticCastExpr *E =
479 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
480 RParenLoc);
481 if (PathSize) E->setCastPath(*BasePath);
482 return E;
483 }
484
CreateEmpty(ASTContext & C,unsigned PathSize)485 CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
486 unsigned PathSize) {
487 void *Buffer =
488 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
489 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
490 }
491
Create(ASTContext & C,QualType T,ExprValueKind VK,CastKind K,Expr * Op,const CXXCastPath * BasePath,TypeSourceInfo * WrittenTy,SourceLocation L,SourceLocation RParenLoc)492 CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
493 ExprValueKind VK,
494 CastKind K, Expr *Op,
495 const CXXCastPath *BasePath,
496 TypeSourceInfo *WrittenTy,
497 SourceLocation L,
498 SourceLocation RParenLoc) {
499 unsigned PathSize = (BasePath ? BasePath->size() : 0);
500 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
501 + PathSize * sizeof(CXXBaseSpecifier*));
502 CXXDynamicCastExpr *E =
503 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
504 RParenLoc);
505 if (PathSize) E->setCastPath(*BasePath);
506 return E;
507 }
508
CreateEmpty(ASTContext & C,unsigned PathSize)509 CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
510 unsigned PathSize) {
511 void *Buffer =
512 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
513 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
514 }
515
516 /// isAlwaysNull - Return whether the result of the dynamic_cast is proven
517 /// to always be null. For example:
518 ///
519 /// struct A { };
520 /// struct B final : A { };
521 /// struct C { };
522 ///
523 /// C *f(B* b) { return dynamic_cast<C*>(b); }
isAlwaysNull() const524 bool CXXDynamicCastExpr::isAlwaysNull() const
525 {
526 QualType SrcType = getSubExpr()->getType();
527 QualType DestType = getType();
528
529 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
530 SrcType = SrcPTy->getPointeeType();
531 DestType = DestType->castAs<PointerType>()->getPointeeType();
532 }
533
534 const CXXRecordDecl *SrcRD =
535 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
536
537 if (!SrcRD->hasAttr<FinalAttr>())
538 return false;
539
540 const CXXRecordDecl *DestRD =
541 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
542
543 return !DestRD->isDerivedFrom(SrcRD);
544 }
545
546 CXXReinterpretCastExpr *
Create(ASTContext & C,QualType T,ExprValueKind VK,CastKind K,Expr * Op,const CXXCastPath * BasePath,TypeSourceInfo * WrittenTy,SourceLocation L,SourceLocation RParenLoc)547 CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
548 CastKind K, Expr *Op,
549 const CXXCastPath *BasePath,
550 TypeSourceInfo *WrittenTy, SourceLocation L,
551 SourceLocation RParenLoc) {
552 unsigned PathSize = (BasePath ? BasePath->size() : 0);
553 void *Buffer =
554 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
555 CXXReinterpretCastExpr *E =
556 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
557 RParenLoc);
558 if (PathSize) E->setCastPath(*BasePath);
559 return E;
560 }
561
562 CXXReinterpretCastExpr *
CreateEmpty(ASTContext & C,unsigned PathSize)563 CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
564 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
565 + PathSize * sizeof(CXXBaseSpecifier*));
566 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
567 }
568
Create(ASTContext & C,QualType T,ExprValueKind VK,Expr * Op,TypeSourceInfo * WrittenTy,SourceLocation L,SourceLocation RParenLoc)569 CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
570 ExprValueKind VK, Expr *Op,
571 TypeSourceInfo *WrittenTy,
572 SourceLocation L,
573 SourceLocation RParenLoc) {
574 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
575 }
576
CreateEmpty(ASTContext & C)577 CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
578 return new (C) CXXConstCastExpr(EmptyShell());
579 }
580
581 CXXFunctionalCastExpr *
Create(ASTContext & C,QualType T,ExprValueKind VK,TypeSourceInfo * Written,SourceLocation L,CastKind K,Expr * Op,const CXXCastPath * BasePath,SourceLocation R)582 CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
583 TypeSourceInfo *Written, SourceLocation L,
584 CastKind K, Expr *Op, const CXXCastPath *BasePath,
585 SourceLocation R) {
586 unsigned PathSize = (BasePath ? BasePath->size() : 0);
587 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
588 + PathSize * sizeof(CXXBaseSpecifier*));
589 CXXFunctionalCastExpr *E =
590 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
591 if (PathSize) E->setCastPath(*BasePath);
592 return E;
593 }
594
595 CXXFunctionalCastExpr *
CreateEmpty(ASTContext & C,unsigned PathSize)596 CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
597 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
598 + PathSize * sizeof(CXXBaseSpecifier*));
599 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
600 }
601
602
603 CXXDefaultArgExpr *
Create(ASTContext & C,SourceLocation Loc,ParmVarDecl * Param,Expr * SubExpr)604 CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
605 ParmVarDecl *Param, Expr *SubExpr) {
606 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
607 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
608 SubExpr);
609 }
610
Create(ASTContext & C,const CXXDestructorDecl * Destructor)611 CXXTemporary *CXXTemporary::Create(ASTContext &C,
612 const CXXDestructorDecl *Destructor) {
613 return new (C) CXXTemporary(Destructor);
614 }
615
Create(ASTContext & C,CXXTemporary * Temp,Expr * SubExpr)616 CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
617 CXXTemporary *Temp,
618 Expr* SubExpr) {
619 assert(SubExpr->getType()->isRecordType() &&
620 "Expression bound to a temporary must have record type!");
621
622 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
623 }
624
CXXTemporaryObjectExpr(ASTContext & C,CXXConstructorDecl * Cons,TypeSourceInfo * Type,Expr ** Args,unsigned NumArgs,SourceRange parenRange,bool ZeroInitialization)625 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
626 CXXConstructorDecl *Cons,
627 TypeSourceInfo *Type,
628 Expr **Args,
629 unsigned NumArgs,
630 SourceRange parenRange,
631 bool ZeroInitialization)
632 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
633 Type->getType().getNonReferenceType(),
634 Type->getTypeLoc().getBeginLoc(),
635 Cons, false, Args, NumArgs, ZeroInitialization,
636 CXXConstructExpr::CK_Complete, parenRange),
637 Type(Type) {
638 }
639
getSourceRange() const640 SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
641 return SourceRange(Type->getTypeLoc().getBeginLoc(),
642 getParenRange().getEnd());
643 }
644
Create(ASTContext & C,QualType T,SourceLocation Loc,CXXConstructorDecl * D,bool Elidable,Expr ** Args,unsigned NumArgs,bool ZeroInitialization,ConstructionKind ConstructKind,SourceRange ParenRange)645 CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
646 SourceLocation Loc,
647 CXXConstructorDecl *D, bool Elidable,
648 Expr **Args, unsigned NumArgs,
649 bool ZeroInitialization,
650 ConstructionKind ConstructKind,
651 SourceRange ParenRange) {
652 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
653 Elidable, Args, NumArgs, ZeroInitialization,
654 ConstructKind, ParenRange);
655 }
656
CXXConstructExpr(ASTContext & C,StmtClass SC,QualType T,SourceLocation Loc,CXXConstructorDecl * D,bool elidable,Expr ** args,unsigned numargs,bool ZeroInitialization,ConstructionKind ConstructKind,SourceRange ParenRange)657 CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
658 SourceLocation Loc,
659 CXXConstructorDecl *D, bool elidable,
660 Expr **args, unsigned numargs,
661 bool ZeroInitialization,
662 ConstructionKind ConstructKind,
663 SourceRange ParenRange)
664 : Expr(SC, T, VK_RValue, OK_Ordinary,
665 T->isDependentType(), T->isDependentType(),
666 T->isInstantiationDependentType(),
667 T->containsUnexpandedParameterPack()),
668 Constructor(D), Loc(Loc), ParenRange(ParenRange), Elidable(elidable),
669 ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind),
670 Args(0), NumArgs(numargs)
671 {
672 if (NumArgs) {
673 Args = new (C) Stmt*[NumArgs];
674
675 for (unsigned i = 0; i != NumArgs; ++i) {
676 assert(args[i] && "NULL argument in CXXConstructExpr");
677
678 if (args[i]->isValueDependent())
679 ExprBits.ValueDependent = true;
680 if (args[i]->isInstantiationDependent())
681 ExprBits.InstantiationDependent = true;
682 if (args[i]->containsUnexpandedParameterPack())
683 ExprBits.ContainsUnexpandedParameterPack = true;
684
685 Args[i] = args[i];
686 }
687 }
688 }
689
ExprWithCleanups(ASTContext & C,Expr * subexpr,CXXTemporary ** temps,unsigned numtemps)690 ExprWithCleanups::ExprWithCleanups(ASTContext &C,
691 Expr *subexpr,
692 CXXTemporary **temps,
693 unsigned numtemps)
694 : Expr(ExprWithCleanupsClass, subexpr->getType(),
695 subexpr->getValueKind(), subexpr->getObjectKind(),
696 subexpr->isTypeDependent(), subexpr->isValueDependent(),
697 subexpr->isInstantiationDependent(),
698 subexpr->containsUnexpandedParameterPack()),
699 SubExpr(subexpr), Temps(0), NumTemps(0) {
700 if (numtemps) {
701 setNumTemporaries(C, numtemps);
702 for (unsigned i = 0; i != numtemps; ++i)
703 Temps[i] = temps[i];
704 }
705 }
706
setNumTemporaries(ASTContext & C,unsigned N)707 void ExprWithCleanups::setNumTemporaries(ASTContext &C, unsigned N) {
708 assert(Temps == 0 && "Cannot resize with this");
709 NumTemps = N;
710 Temps = new (C) CXXTemporary*[NumTemps];
711 }
712
713
Create(ASTContext & C,Expr * SubExpr,CXXTemporary ** Temps,unsigned NumTemps)714 ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C,
715 Expr *SubExpr,
716 CXXTemporary **Temps,
717 unsigned NumTemps) {
718 return new (C) ExprWithCleanups(C, SubExpr, Temps, NumTemps);
719 }
720
CXXUnresolvedConstructExpr(TypeSourceInfo * Type,SourceLocation LParenLoc,Expr ** Args,unsigned NumArgs,SourceLocation RParenLoc)721 CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
722 SourceLocation LParenLoc,
723 Expr **Args,
724 unsigned NumArgs,
725 SourceLocation RParenLoc)
726 : Expr(CXXUnresolvedConstructExprClass,
727 Type->getType().getNonReferenceType(),
728 (Type->getType()->isLValueReferenceType() ? VK_LValue
729 :Type->getType()->isRValueReferenceType()? VK_XValue
730 :VK_RValue),
731 OK_Ordinary,
732 Type->getType()->isDependentType(), true, true,
733 Type->getType()->containsUnexpandedParameterPack()),
734 Type(Type),
735 LParenLoc(LParenLoc),
736 RParenLoc(RParenLoc),
737 NumArgs(NumArgs) {
738 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
739 for (unsigned I = 0; I != NumArgs; ++I) {
740 if (Args[I]->containsUnexpandedParameterPack())
741 ExprBits.ContainsUnexpandedParameterPack = true;
742
743 StoredArgs[I] = Args[I];
744 }
745 }
746
747 CXXUnresolvedConstructExpr *
Create(ASTContext & C,TypeSourceInfo * Type,SourceLocation LParenLoc,Expr ** Args,unsigned NumArgs,SourceLocation RParenLoc)748 CXXUnresolvedConstructExpr::Create(ASTContext &C,
749 TypeSourceInfo *Type,
750 SourceLocation LParenLoc,
751 Expr **Args,
752 unsigned NumArgs,
753 SourceLocation RParenLoc) {
754 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
755 sizeof(Expr *) * NumArgs);
756 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc,
757 Args, NumArgs, RParenLoc);
758 }
759
760 CXXUnresolvedConstructExpr *
CreateEmpty(ASTContext & C,unsigned NumArgs)761 CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
762 Stmt::EmptyShell Empty;
763 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
764 sizeof(Expr *) * NumArgs);
765 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
766 }
767
getSourceRange() const768 SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
769 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
770 }
771
CXXDependentScopeMemberExpr(ASTContext & C,Expr * Base,QualType BaseType,bool IsArrow,SourceLocation OperatorLoc,NestedNameSpecifierLoc QualifierLoc,NamedDecl * FirstQualifierFoundInScope,DeclarationNameInfo MemberNameInfo,const TemplateArgumentListInfo * TemplateArgs)772 CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
773 Expr *Base, QualType BaseType,
774 bool IsArrow,
775 SourceLocation OperatorLoc,
776 NestedNameSpecifierLoc QualifierLoc,
777 NamedDecl *FirstQualifierFoundInScope,
778 DeclarationNameInfo MemberNameInfo,
779 const TemplateArgumentListInfo *TemplateArgs)
780 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
781 VK_LValue, OK_Ordinary, true, true, true,
782 ((Base && Base->containsUnexpandedParameterPack()) ||
783 (QualifierLoc &&
784 QualifierLoc.getNestedNameSpecifier()
785 ->containsUnexpandedParameterPack()) ||
786 MemberNameInfo.containsUnexpandedParameterPack())),
787 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
788 HasExplicitTemplateArgs(TemplateArgs != 0),
789 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
790 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
791 MemberNameInfo(MemberNameInfo) {
792 if (TemplateArgs) {
793 bool Dependent = true;
794 bool InstantiationDependent = true;
795 bool ContainsUnexpandedParameterPack = false;
796 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
797 InstantiationDependent,
798 ContainsUnexpandedParameterPack);
799 if (ContainsUnexpandedParameterPack)
800 ExprBits.ContainsUnexpandedParameterPack = true;
801 }
802 }
803
CXXDependentScopeMemberExpr(ASTContext & C,Expr * Base,QualType BaseType,bool IsArrow,SourceLocation OperatorLoc,NestedNameSpecifierLoc QualifierLoc,NamedDecl * FirstQualifierFoundInScope,DeclarationNameInfo MemberNameInfo)804 CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
805 Expr *Base, QualType BaseType,
806 bool IsArrow,
807 SourceLocation OperatorLoc,
808 NestedNameSpecifierLoc QualifierLoc,
809 NamedDecl *FirstQualifierFoundInScope,
810 DeclarationNameInfo MemberNameInfo)
811 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
812 VK_LValue, OK_Ordinary, true, true, true,
813 ((Base && Base->containsUnexpandedParameterPack()) ||
814 (QualifierLoc &&
815 QualifierLoc.getNestedNameSpecifier()->
816 containsUnexpandedParameterPack()) ||
817 MemberNameInfo.containsUnexpandedParameterPack())),
818 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
819 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
820 QualifierLoc(QualifierLoc),
821 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
822 MemberNameInfo(MemberNameInfo) { }
823
824 CXXDependentScopeMemberExpr *
Create(ASTContext & C,Expr * Base,QualType BaseType,bool IsArrow,SourceLocation OperatorLoc,NestedNameSpecifierLoc QualifierLoc,NamedDecl * FirstQualifierFoundInScope,DeclarationNameInfo MemberNameInfo,const TemplateArgumentListInfo * TemplateArgs)825 CXXDependentScopeMemberExpr::Create(ASTContext &C,
826 Expr *Base, QualType BaseType, bool IsArrow,
827 SourceLocation OperatorLoc,
828 NestedNameSpecifierLoc QualifierLoc,
829 NamedDecl *FirstQualifierFoundInScope,
830 DeclarationNameInfo MemberNameInfo,
831 const TemplateArgumentListInfo *TemplateArgs) {
832 if (!TemplateArgs)
833 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
834 IsArrow, OperatorLoc,
835 QualifierLoc,
836 FirstQualifierFoundInScope,
837 MemberNameInfo);
838
839 std::size_t size = sizeof(CXXDependentScopeMemberExpr);
840 if (TemplateArgs)
841 size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
842
843 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
844 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
845 IsArrow, OperatorLoc,
846 QualifierLoc,
847 FirstQualifierFoundInScope,
848 MemberNameInfo, TemplateArgs);
849 }
850
851 CXXDependentScopeMemberExpr *
CreateEmpty(ASTContext & C,bool HasExplicitTemplateArgs,unsigned NumTemplateArgs)852 CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
853 bool HasExplicitTemplateArgs,
854 unsigned NumTemplateArgs) {
855 if (!HasExplicitTemplateArgs)
856 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
857 0, SourceLocation(),
858 NestedNameSpecifierLoc(), 0,
859 DeclarationNameInfo());
860
861 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
862 ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
863 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
864 CXXDependentScopeMemberExpr *E
865 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
866 0, SourceLocation(),
867 NestedNameSpecifierLoc(), 0,
868 DeclarationNameInfo(), 0);
869 E->HasExplicitTemplateArgs = true;
870 return E;
871 }
872
isImplicitAccess() const873 bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
874 if (Base == 0)
875 return true;
876
877 return cast<Expr>(Base)->isImplicitCXXThis();
878 }
879
hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,UnresolvedSetIterator end)880 static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
881 UnresolvedSetIterator end) {
882 do {
883 NamedDecl *decl = *begin;
884 if (isa<UnresolvedUsingValueDecl>(decl))
885 return false;
886 if (isa<UsingShadowDecl>(decl))
887 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
888
889 // Unresolved member expressions should only contain methods and
890 // method templates.
891 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
892
893 if (isa<FunctionTemplateDecl>(decl))
894 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
895 if (cast<CXXMethodDecl>(decl)->isStatic())
896 return false;
897 } while (++begin != end);
898
899 return true;
900 }
901
UnresolvedMemberExpr(ASTContext & C,bool HasUnresolvedUsing,Expr * Base,QualType BaseType,bool IsArrow,SourceLocation OperatorLoc,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & MemberNameInfo,const TemplateArgumentListInfo * TemplateArgs,UnresolvedSetIterator Begin,UnresolvedSetIterator End)902 UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
903 bool HasUnresolvedUsing,
904 Expr *Base, QualType BaseType,
905 bool IsArrow,
906 SourceLocation OperatorLoc,
907 NestedNameSpecifierLoc QualifierLoc,
908 const DeclarationNameInfo &MemberNameInfo,
909 const TemplateArgumentListInfo *TemplateArgs,
910 UnresolvedSetIterator Begin,
911 UnresolvedSetIterator End)
912 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, MemberNameInfo,
913 TemplateArgs, Begin, End,
914 // Dependent
915 ((Base && Base->isTypeDependent()) ||
916 BaseType->isDependentType()),
917 ((Base && Base->isInstantiationDependent()) ||
918 BaseType->isInstantiationDependentType()),
919 // Contains unexpanded parameter pack
920 ((Base && Base->containsUnexpandedParameterPack()) ||
921 BaseType->containsUnexpandedParameterPack())),
922 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
923 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
924
925 // Check whether all of the members are non-static member functions,
926 // and if so, mark give this bound-member type instead of overload type.
927 if (hasOnlyNonStaticMemberFunctions(Begin, End))
928 setType(C.BoundMemberTy);
929 }
930
isImplicitAccess() const931 bool UnresolvedMemberExpr::isImplicitAccess() const {
932 if (Base == 0)
933 return true;
934
935 return cast<Expr>(Base)->isImplicitCXXThis();
936 }
937
938 UnresolvedMemberExpr *
Create(ASTContext & C,bool HasUnresolvedUsing,Expr * Base,QualType BaseType,bool IsArrow,SourceLocation OperatorLoc,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & MemberNameInfo,const TemplateArgumentListInfo * TemplateArgs,UnresolvedSetIterator Begin,UnresolvedSetIterator End)939 UnresolvedMemberExpr::Create(ASTContext &C,
940 bool HasUnresolvedUsing,
941 Expr *Base, QualType BaseType, bool IsArrow,
942 SourceLocation OperatorLoc,
943 NestedNameSpecifierLoc QualifierLoc,
944 const DeclarationNameInfo &MemberNameInfo,
945 const TemplateArgumentListInfo *TemplateArgs,
946 UnresolvedSetIterator Begin,
947 UnresolvedSetIterator End) {
948 std::size_t size = sizeof(UnresolvedMemberExpr);
949 if (TemplateArgs)
950 size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
951
952 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
953 return new (Mem) UnresolvedMemberExpr(C,
954 HasUnresolvedUsing, Base, BaseType,
955 IsArrow, OperatorLoc, QualifierLoc,
956 MemberNameInfo, TemplateArgs, Begin, End);
957 }
958
959 UnresolvedMemberExpr *
CreateEmpty(ASTContext & C,bool HasExplicitTemplateArgs,unsigned NumTemplateArgs)960 UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
961 unsigned NumTemplateArgs) {
962 std::size_t size = sizeof(UnresolvedMemberExpr);
963 if (HasExplicitTemplateArgs)
964 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
965
966 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
967 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
968 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
969 return E;
970 }
971
getNamingClass() const972 CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
973 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
974
975 // If there was a nested name specifier, it names the naming class.
976 // It can't be dependent: after all, we were actually able to do the
977 // lookup.
978 CXXRecordDecl *Record = 0;
979 if (getQualifier()) {
980 const Type *T = getQualifier()->getAsType();
981 assert(T && "qualifier in member expression does not name type");
982 Record = T->getAsCXXRecordDecl();
983 assert(Record && "qualifier in member expression does not name record");
984 }
985 // Otherwise the naming class must have been the base class.
986 else {
987 QualType BaseType = getBaseType().getNonReferenceType();
988 if (isArrow()) {
989 const PointerType *PT = BaseType->getAs<PointerType>();
990 assert(PT && "base of arrow member access is not pointer");
991 BaseType = PT->getPointeeType();
992 }
993
994 Record = BaseType->getAsCXXRecordDecl();
995 assert(Record && "base of member expression does not name record");
996 }
997
998 return Record;
999 }
1000
1001 SubstNonTypeTemplateParmPackExpr::
SubstNonTypeTemplateParmPackExpr(QualType T,NonTypeTemplateParmDecl * Param,SourceLocation NameLoc,const TemplateArgument & ArgPack)1002 SubstNonTypeTemplateParmPackExpr(QualType T,
1003 NonTypeTemplateParmDecl *Param,
1004 SourceLocation NameLoc,
1005 const TemplateArgument &ArgPack)
1006 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
1007 true, true, true, true),
1008 Param(Param), Arguments(ArgPack.pack_begin()),
1009 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1010
getArgumentPack() const1011 TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1012 return TemplateArgument(Arguments, NumArguments);
1013 }
1014
1015
1016