blob: 1bbf8494fa22c1ce968962be3be662862f1685a1 [file] [log] [blame]
Ted Kremeneka758d092007-08-24 20:21:10 +00001//===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremeneka758d092007-08-24 20:21:10 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the subclesses of Expr class declared in ExprCXX.h
11//
12//===----------------------------------------------------------------------===//
13
Douglas Gregorb4609802008-11-14 16:09:21 +000014#include "clang/Basic/IdentifierTable.h"
15#include "clang/AST/DeclCXX.h"
Douglas Gregoredce4dd2009-06-30 22:34:41 +000016#include "clang/AST/DeclTemplate.h"
Ted Kremeneka758d092007-08-24 20:21:10 +000017#include "clang/AST/ExprCXX.h"
Douglas Gregor26d4ac92010-02-24 23:40:28 +000018#include "clang/AST/TypeLoc.h"
Ted Kremeneka758d092007-08-24 20:21:10 +000019using namespace clang;
20
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000021
Ted Kremeneka758d092007-08-24 20:21:10 +000022//===----------------------------------------------------------------------===//
23// Child Iterators for iterating over subexpressions/substatements
24//===----------------------------------------------------------------------===//
25
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000026QualType CXXTypeidExpr::getTypeOperand() const {
27 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
28 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
29 .getUnqualifiedType();
30}
31
Francois Pichet01b7c302010-09-08 12:20:18 +000032QualType CXXUuidofExpr::getTypeOperand() const {
33 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
34 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
35 .getUnqualifiedType();
36}
37
Douglas Gregored8abf12010-07-08 06:14:04 +000038// CXXScalarValueInitExpr
Douglas Gregorab6677e2010-09-08 00:15:04 +000039SourceRange CXXScalarValueInitExpr::getSourceRange() const {
40 SourceLocation Start = RParenLoc;
41 if (TypeInfo)
42 Start = TypeInfo->getTypeLoc().getBeginLoc();
43 return SourceRange(Start, RParenLoc);
44}
45
Sebastian Redl4c5d3202008-11-21 19:14:01 +000046// CXXNewExpr
Ted Kremenekad7fe862010-02-11 22:51:03 +000047CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Sebastian Redl4c5d3202008-11-21 19:14:01 +000048 Expr **placementArgs, unsigned numPlaceArgs,
Douglas Gregor4bd40312010-07-13 15:54:32 +000049 SourceRange TypeIdParens, Expr *arraySize,
Sebastian Redl4c5d3202008-11-21 19:14:01 +000050 CXXConstructorDecl *constructor, bool initializer,
51 Expr **constructorArgs, unsigned numConsArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +000052 bool HadMultipleCandidates,
John McCall6ec278d2011-01-27 09:37:56 +000053 FunctionDecl *operatorDelete,
54 bool usualArrayDeleteWantsSize, QualType ty,
Douglas Gregor1bb2a932010-09-07 21:49:58 +000055 TypeSourceInfo *AllocatedTypeInfo,
Chandler Carruth428edaf2010-10-25 08:47:36 +000056 SourceLocation startLoc, SourceLocation endLoc,
57 SourceLocation constructorLParen,
58 SourceLocation constructorRParen)
John McCallf89e55a2010-11-18 06:31:45 +000059 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000060 ty->isDependentType(), ty->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +000061 ty->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000062 ty->containsUnexpandedParameterPack()),
John McCall6ec278d2011-01-27 09:37:56 +000063 GlobalNew(globalNew), Initializer(initializer),
64 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +000065 HadMultipleCandidates(HadMultipleCandidates),
John McCall6ec278d2011-01-27 09:37:56 +000066 SubExprs(0), OperatorNew(operatorNew),
Sebastian Redlcee63fb2008-12-02 14:43:59 +000067 OperatorDelete(operatorDelete), Constructor(constructor),
Douglas Gregor1bb2a932010-09-07 21:49:58 +000068 AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens),
Chandler Carruth428edaf2010-10-25 08:47:36 +000069 StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen),
70 ConstructorRParen(constructorRParen) {
Chris Lattner59218632010-05-10 01:22:27 +000071 AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs);
Sebastian Redl4c5d3202008-11-21 19:14:01 +000072 unsigned i = 0;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000073 if (Array) {
Douglas Gregor561f8122011-07-01 01:22:09 +000074 if (arraySize->isInstantiationDependent())
75 ExprBits.InstantiationDependent = true;
76
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000077 if (arraySize->containsUnexpandedParameterPack())
78 ExprBits.ContainsUnexpandedParameterPack = true;
79
Sebastian Redlcee63fb2008-12-02 14:43:59 +000080 SubExprs[i++] = arraySize;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000081 }
82
83 for (unsigned j = 0; j < NumPlacementArgs; ++j) {
Douglas Gregor561f8122011-07-01 01:22:09 +000084 if (placementArgs[j]->isInstantiationDependent())
85 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000086 if (placementArgs[j]->containsUnexpandedParameterPack())
87 ExprBits.ContainsUnexpandedParameterPack = true;
88
Sebastian Redl4c5d3202008-11-21 19:14:01 +000089 SubExprs[i++] = placementArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000090 }
91
92 for (unsigned j = 0; j < NumConstructorArgs; ++j) {
Douglas Gregor561f8122011-07-01 01:22:09 +000093 if (constructorArgs[j]->isInstantiationDependent())
94 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000095 if (constructorArgs[j]->containsUnexpandedParameterPack())
96 ExprBits.ContainsUnexpandedParameterPack = true;
97
Sebastian Redl4c5d3202008-11-21 19:14:01 +000098 SubExprs[i++] = constructorArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000099 }
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000100}
101
Chris Lattner59218632010-05-10 01:22:27 +0000102void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
103 unsigned numPlaceArgs, unsigned numConsArgs){
104 assert(SubExprs == 0 && "SubExprs already allocated");
105 Array = isArray;
106 NumPlacementArgs = numPlaceArgs;
107 NumConstructorArgs = numConsArgs;
108
109 unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs;
110 SubExprs = new (C) Stmt*[TotalSize];
111}
112
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000113bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCallc2f3e7f2011-03-07 03:12:35 +0000114 return getOperatorNew()->getType()->
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000115 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCallc2f3e7f2011-03-07 03:12:35 +0000116}
Chris Lattner59218632010-05-10 01:22:27 +0000117
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000118// CXXDeleteExpr
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000119QualType CXXDeleteExpr::getDestroyedType() const {
120 const Expr *Arg = getArgument();
121 while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
122 if (ICE->getCastKind() != CK_UserDefinedConversion &&
123 ICE->getType()->isVoidPointerType())
124 Arg = ICE->getSubExpr();
125 else
126 break;
127 }
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000128 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silversteinc87fa062010-10-20 00:56:01 +0000129 const QualType ArgType = Arg->getType();
Craig Silversteina437ad32010-11-16 07:16:25 +0000130
131 if (ArgType->isDependentType() && !ArgType->isPointerType())
132 return QualType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000133
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000134 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000135}
136
Douglas Gregora71d8192009-09-04 17:36:40 +0000137// CXXPseudoDestructorExpr
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000138PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
139 : Type(Info)
140{
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000141 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000142}
143
John McCalle23cf432010-12-14 08:05:40 +0000144CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000145 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
146 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
147 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
148 PseudoDestructorTypeStorage DestroyedType)
John McCalle23cf432010-12-14 08:05:40 +0000149 : Expr(CXXPseudoDestructorExprClass,
150 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
151 FunctionProtoType::ExtProtoInfo())),
152 VK_RValue, OK_Ordinary,
153 /*isTypeDependent=*/(Base->isTypeDependent() ||
154 (DestroyedType.getTypeSourceInfo() &&
155 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000156 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000157 (Base->isInstantiationDependent() ||
158 (QualifierLoc &&
159 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
160 (ScopeType &&
161 ScopeType->getType()->isInstantiationDependentType()) ||
162 (DestroyedType.getTypeSourceInfo() &&
163 DestroyedType.getTypeSourceInfo()->getType()
164 ->isInstantiationDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000165 // ContainsUnexpandedParameterPack
166 (Base->containsUnexpandedParameterPack() ||
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000167 (QualifierLoc &&
168 QualifierLoc.getNestedNameSpecifier()
169 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000170 (ScopeType &&
171 ScopeType->getType()->containsUnexpandedParameterPack()) ||
172 (DestroyedType.getTypeSourceInfo() &&
173 DestroyedType.getTypeSourceInfo()->getType()
174 ->containsUnexpandedParameterPack()))),
John McCalle23cf432010-12-14 08:05:40 +0000175 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000176 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalle23cf432010-12-14 08:05:40 +0000177 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
178 DestroyedType(DestroyedType) { }
179
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000180QualType CXXPseudoDestructorExpr::getDestroyedType() const {
181 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
182 return TInfo->getType();
183
184 return QualType();
185}
186
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000187SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000188 SourceLocation End = DestroyedType.getLocation();
189 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000190 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000191 return SourceRange(Base->getLocStart(), End);
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000192}
193
194
John McCallba135432009-11-21 08:51:07 +0000195// UnresolvedLookupExpr
John McCallf7a1a742009-11-24 19:00:30 +0000196UnresolvedLookupExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000197UnresolvedLookupExpr::Create(ASTContext &C,
John McCallc373d482010-01-27 01:50:18 +0000198 CXXRecordDecl *NamingClass,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000199 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000200 const DeclarationNameInfo &NameInfo,
201 bool ADL,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000202 const TemplateArgumentListInfo &Args,
203 UnresolvedSetIterator Begin,
204 UnresolvedSetIterator End)
John McCallf7a1a742009-11-24 19:00:30 +0000205{
206 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000207 ASTTemplateArgumentListInfo::sizeFor(Args));
Douglas Gregor4c9be892011-02-28 20:01:57 +0000208 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000209 ADL, /*Overload*/ true, &Args,
Richard Smithad762fc2011-04-14 22:09:26 +0000210 Begin, End, /*StdIsAssociated=*/false);
John McCallf7a1a742009-11-24 19:00:30 +0000211}
212
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000213UnresolvedLookupExpr *
Douglas Gregordef03542011-02-04 12:01:24 +0000214UnresolvedLookupExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
215 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000216 std::size_t size = sizeof(UnresolvedLookupExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000217 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000218 size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000219
Chris Lattner32488542010-10-30 05:14:06 +0000220 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000221 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Douglas Gregordef03542011-02-04 12:01:24 +0000222 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000223 return E;
224}
225
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000226OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000227 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000228 const DeclarationNameInfo &NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000229 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000230 UnresolvedSetIterator Begin,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000231 UnresolvedSetIterator End,
232 bool KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000233 bool KnownInstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000234 bool KnownContainsUnexpandedParameterPack)
235 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
236 KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000237 (KnownInstantiationDependent ||
238 NameInfo.isInstantiationDependent() ||
239 (QualifierLoc &&
240 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000241 (KnownContainsUnexpandedParameterPack ||
242 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor4c9be892011-02-28 20:01:57 +0000243 (QualifierLoc &&
244 QualifierLoc.getNestedNameSpecifier()
245 ->containsUnexpandedParameterPack()))),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000246 Results(0), NumResults(End - Begin), NameInfo(NameInfo),
Douglas Gregor4c9be892011-02-28 20:01:57 +0000247 QualifierLoc(QualifierLoc), HasExplicitTemplateArgs(TemplateArgs != 0)
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000248{
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000249 NumResults = End - Begin;
250 if (NumResults) {
251 // Determine whether this expression is type-dependent.
252 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
253 if ((*I)->getDeclContext()->isDependentContext() ||
254 isa<UnresolvedUsingValueDecl>(*I)) {
255 ExprBits.TypeDependent = true;
256 ExprBits.ValueDependent = true;
257 }
258 }
259
260 Results = static_cast<DeclAccessPair *>(
261 C.Allocate(sizeof(DeclAccessPair) * NumResults,
262 llvm::alignOf<DeclAccessPair>()));
263 memcpy(Results, &*Begin.getIterator(),
264 NumResults * sizeof(DeclAccessPair));
265 }
266
267 // If we have explicit template arguments, check for dependent
268 // template arguments and whether they contain any unexpanded pack
269 // expansions.
270 if (TemplateArgs) {
271 bool Dependent = false;
Douglas Gregor561f8122011-07-01 01:22:09 +0000272 bool InstantiationDependent = false;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000273 bool ContainsUnexpandedParameterPack = false;
274 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000275 InstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000276 ContainsUnexpandedParameterPack);
277
278 if (Dependent) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000279 ExprBits.TypeDependent = true;
280 ExprBits.ValueDependent = true;
281 }
282 if (InstantiationDependent)
283 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000284 if (ContainsUnexpandedParameterPack)
285 ExprBits.ContainsUnexpandedParameterPack = true;
286 }
287
288 if (isTypeDependent())
289 setType(C.DependentTy);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000290}
291
292void OverloadExpr::initializeResults(ASTContext &C,
293 UnresolvedSetIterator Begin,
294 UnresolvedSetIterator End) {
295 assert(Results == 0 && "Results already initialized!");
296 NumResults = End - Begin;
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000297 if (NumResults) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000298 Results = static_cast<DeclAccessPair *>(
299 C.Allocate(sizeof(DeclAccessPair) * NumResults,
300
301 llvm::alignOf<DeclAccessPair>()));
302 memcpy(Results, &*Begin.getIterator(),
303 NumResults * sizeof(DeclAccessPair));
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000304 }
305}
306
John McCalle9ee23e2010-04-22 18:44:12 +0000307CXXRecordDecl *OverloadExpr::getNamingClass() const {
308 if (isa<UnresolvedLookupExpr>(this))
309 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
310 else
311 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
312}
313
John McCall865d4472009-11-19 22:55:06 +0000314// DependentScopeDeclRefExpr
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000315DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000316 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000317 const DeclarationNameInfo &NameInfo,
318 const TemplateArgumentListInfo *Args)
319 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
320 true, true,
Douglas Gregor561f8122011-07-01 01:22:09 +0000321 (NameInfo.isInstantiationDependent() ||
322 (QualifierLoc &&
323 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000324 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000325 (QualifierLoc &&
326 QualifierLoc.getNestedNameSpecifier()
327 ->containsUnexpandedParameterPack()))),
328 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000329 HasExplicitTemplateArgs(Args != 0)
330{
331 if (Args) {
332 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000333 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000334 bool ContainsUnexpandedParameterPack
335 = ExprBits.ContainsUnexpandedParameterPack;
336
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000337 reinterpret_cast<ASTTemplateArgumentListInfo*>(this+1)
Douglas Gregor561f8122011-07-01 01:22:09 +0000338 ->initializeFrom(*Args, Dependent, InstantiationDependent,
339 ContainsUnexpandedParameterPack);
340
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000341 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
342 }
343}
344
John McCallf7a1a742009-11-24 19:00:30 +0000345DependentScopeDeclRefExpr *
346DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000347 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000348 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +0000349 const TemplateArgumentListInfo *Args) {
350 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCallf7a1a742009-11-24 19:00:30 +0000351 if (Args)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000352 size += ASTTemplateArgumentListInfo::sizeFor(*Args);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000353 void *Mem = C.Allocate(size);
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000354 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000355 NameInfo, Args);
John McCallf7a1a742009-11-24 19:00:30 +0000356}
357
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000358DependentScopeDeclRefExpr *
359DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Douglas Gregordef03542011-02-04 12:01:24 +0000360 bool HasExplicitTemplateArgs,
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000361 unsigned NumTemplateArgs) {
362 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000363 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000364 size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000365 void *Mem = C.Allocate(size);
Douglas Gregordef03542011-02-04 12:01:24 +0000366 DependentScopeDeclRefExpr *E
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000367 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Douglas Gregordef03542011-02-04 12:01:24 +0000368 DeclarationNameInfo(), 0);
369 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
370 return E;
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000371}
372
Chandler Carruth428edaf2010-10-25 08:47:36 +0000373SourceRange CXXConstructExpr::getSourceRange() const {
John McCall2882eca2011-02-21 06:23:05 +0000374 if (isa<CXXTemporaryObjectExpr>(this))
375 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
376
Douglas Gregor40749ee2010-11-03 00:35:38 +0000377 if (ParenRange.isValid())
378 return SourceRange(Loc, ParenRange.getEnd());
379
380 SourceLocation End = Loc;
381 for (unsigned I = getNumArgs(); I > 0; --I) {
382 const Expr *Arg = getArg(I-1);
383 if (!Arg->isDefaultArgument()) {
384 SourceLocation NewEnd = Arg->getLocEnd();
385 if (NewEnd.isValid()) {
386 End = NewEnd;
387 break;
388 }
389 }
390 }
391
392 return SourceRange(Loc, End);
Ted Kremeneke3837682009-12-23 04:00:48 +0000393}
394
Douglas Gregorb4609802008-11-14 16:09:21 +0000395SourceRange CXXOperatorCallExpr::getSourceRange() const {
396 OverloadedOperatorKind Kind = getOperator();
397 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
398 if (getNumArgs() == 1)
399 // Prefix operator
Mike Stump1eb44332009-09-09 15:08:12 +0000400 return SourceRange(getOperatorLoc(),
Douglas Gregorb4609802008-11-14 16:09:21 +0000401 getArg(0)->getSourceRange().getEnd());
402 else
403 // Postfix operator
Chandler Carruthd7650612011-04-02 09:47:38 +0000404 return SourceRange(getArg(0)->getSourceRange().getBegin(),
Douglas Gregorb4609802008-11-14 16:09:21 +0000405 getOperatorLoc());
Chandler Carruthd7650612011-04-02 09:47:38 +0000406 } else if (Kind == OO_Arrow) {
407 return getArg(0)->getSourceRange();
Douglas Gregorb4609802008-11-14 16:09:21 +0000408 } else if (Kind == OO_Call) {
409 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
410 } else if (Kind == OO_Subscript) {
411 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
412 } else if (getNumArgs() == 1) {
413 return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd());
414 } else if (getNumArgs() == 2) {
415 return SourceRange(getArg(0)->getSourceRange().getBegin(),
416 getArg(1)->getSourceRange().getEnd());
417 } else {
418 return SourceRange();
419 }
420}
421
Ted Kremenekb2771592011-03-30 17:41:19 +0000422Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
423 if (const MemberExpr *MemExpr =
424 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
Douglas Gregor88a35142008-12-22 05:46:06 +0000425 return MemExpr->getBase();
426
427 // FIXME: Will eventually need to cope with member pointers.
428 return 0;
429}
430
Ted Kremenekb2771592011-03-30 17:41:19 +0000431CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
432 if (const MemberExpr *MemExpr =
433 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
434 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
435
436 // FIXME: Will eventually need to cope with member pointers.
437 return 0;
438}
439
440
Chandler Carruth007a9b12010-10-27 06:55:41 +0000441CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
442 Expr* ThisArg = getImplicitObjectArgument();
443 if (!ThisArg)
444 return 0;
445
446 if (ThisArg->getType()->isAnyPointerType())
447 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
448
449 return ThisArg->getType()->getAsCXXRecordDecl();
450}
451
Douglas Gregor00b98c22009-11-12 15:31:47 +0000452
Douglas Gregor49badde2008-10-27 19:41:14 +0000453//===----------------------------------------------------------------------===//
454// Named casts
455//===----------------------------------------------------------------------===//
456
457/// getCastName - Get the name of the C++ cast being used, e.g.,
458/// "static_cast", "dynamic_cast", "reinterpret_cast", or
459/// "const_cast". The returned pointer must not be freed.
460const char *CXXNamedCastExpr::getCastName() const {
461 switch (getStmtClass()) {
462 case CXXStaticCastExprClass: return "static_cast";
463 case CXXDynamicCastExprClass: return "dynamic_cast";
464 case CXXReinterpretCastExprClass: return "reinterpret_cast";
465 case CXXConstCastExprClass: return "const_cast";
466 default: return "<invalid cast>";
467 }
468}
Douglas Gregor506ae412009-01-16 18:33:17 +0000469
John McCallf871d0c2010-08-07 06:22:56 +0000470CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000471 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000472 CastKind K, Expr *Op,
473 const CXXCastPath *BasePath,
474 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000475 SourceLocation L,
476 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000477 unsigned PathSize = (BasePath ? BasePath->size() : 0);
478 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
479 + PathSize * sizeof(CXXBaseSpecifier*));
480 CXXStaticCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000481 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
482 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000483 if (PathSize) E->setCastPath(*BasePath);
484 return E;
485}
486
487CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
488 unsigned PathSize) {
489 void *Buffer =
490 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
491 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
492}
493
494CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000495 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000496 CastKind K, Expr *Op,
497 const CXXCastPath *BasePath,
498 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000499 SourceLocation L,
500 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000501 unsigned PathSize = (BasePath ? BasePath->size() : 0);
502 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
503 + PathSize * sizeof(CXXBaseSpecifier*));
504 CXXDynamicCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000505 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
506 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000507 if (PathSize) E->setCastPath(*BasePath);
508 return E;
509}
510
511CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
512 unsigned PathSize) {
513 void *Buffer =
514 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
515 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
516}
517
Anders Carlsson0fee3302011-04-11 01:43:55 +0000518/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
519/// to always be null. For example:
520///
521/// struct A { };
522/// struct B final : A { };
523/// struct C { };
524///
525/// C *f(B* b) { return dynamic_cast<C*>(b); }
526bool CXXDynamicCastExpr::isAlwaysNull() const
527{
528 QualType SrcType = getSubExpr()->getType();
529 QualType DestType = getType();
530
531 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
532 SrcType = SrcPTy->getPointeeType();
533 DestType = DestType->castAs<PointerType>()->getPointeeType();
534 }
535
536 const CXXRecordDecl *SrcRD =
537 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
538
539 if (!SrcRD->hasAttr<FinalAttr>())
540 return false;
541
542 const CXXRecordDecl *DestRD =
543 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
544
545 return !DestRD->isDerivedFrom(SrcRD);
546}
547
John McCallf871d0c2010-08-07 06:22:56 +0000548CXXReinterpretCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000549CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
550 CastKind K, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000551 const CXXCastPath *BasePath,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000552 TypeSourceInfo *WrittenTy, SourceLocation L,
553 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000554 unsigned PathSize = (BasePath ? BasePath->size() : 0);
555 void *Buffer =
556 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
557 CXXReinterpretCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000558 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
559 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000560 if (PathSize) E->setCastPath(*BasePath);
561 return E;
562}
563
564CXXReinterpretCastExpr *
565CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
566 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
567 + PathSize * sizeof(CXXBaseSpecifier*));
568 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
569}
570
John McCallf89e55a2010-11-18 06:31:45 +0000571CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
572 ExprValueKind VK, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000573 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000574 SourceLocation L,
575 SourceLocation RParenLoc) {
576 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000577}
578
579CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
580 return new (C) CXXConstCastExpr(EmptyShell());
581}
582
583CXXFunctionalCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000584CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000585 TypeSourceInfo *Written, SourceLocation L,
586 CastKind K, Expr *Op, const CXXCastPath *BasePath,
587 SourceLocation R) {
588 unsigned PathSize = (BasePath ? BasePath->size() : 0);
589 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
590 + PathSize * sizeof(CXXBaseSpecifier*));
591 CXXFunctionalCastExpr *E =
John McCallf89e55a2010-11-18 06:31:45 +0000592 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallf871d0c2010-08-07 06:22:56 +0000593 if (PathSize) E->setCastPath(*BasePath);
594 return E;
595}
596
597CXXFunctionalCastExpr *
598CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
599 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
600 + PathSize * sizeof(CXXBaseSpecifier*));
601 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
602}
603
604
Douglas Gregor65222e82009-12-23 18:19:08 +0000605CXXDefaultArgExpr *
Douglas Gregor036aed12009-12-23 23:03:06 +0000606CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
607 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor65222e82009-12-23 18:19:08 +0000608 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor036aed12009-12-23 23:03:06 +0000609 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
610 SubExpr);
Douglas Gregor65222e82009-12-23 18:19:08 +0000611}
612
Mike Stump1eb44332009-09-09 15:08:12 +0000613CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonb859f352009-05-30 20:34:37 +0000614 const CXXDestructorDecl *Destructor) {
Anders Carlsson88eaf072009-05-30 22:38:53 +0000615 return new (C) CXXTemporary(Destructor);
616}
617
Mike Stump1eb44332009-09-09 15:08:12 +0000618CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000619 CXXTemporary *Temp,
620 Expr* SubExpr) {
Peter Collingbournebceb7552011-11-27 22:09:28 +0000621 assert((SubExpr->getType()->isRecordType() ||
622 SubExpr->getType()->isArrayType()) &&
623 "Expression bound to a temporary must have record or array type!");
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000624
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000625 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000626}
627
Anders Carlsson8e587a12009-05-30 20:56:46 +0000628CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000629 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000630 TypeSourceInfo *Type,
Douglas Gregor506ae412009-01-16 18:33:17 +0000631 Expr **Args,
Mike Stump1eb44332009-09-09 15:08:12 +0000632 unsigned NumArgs,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000633 SourceRange parenRange,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000634 bool HadMultipleCandidates,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000635 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000636 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
637 Type->getType().getNonReferenceType(),
638 Type->getTypeLoc().getBeginLoc(),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000639 Cons, false, Args, NumArgs,
640 HadMultipleCandidates, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000641 CXXConstructExpr::CK_Complete, parenRange),
642 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000643}
644
645SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth428edaf2010-10-25 08:47:36 +0000646 return SourceRange(Type->getTypeLoc().getBeginLoc(),
647 getParenRange().getEnd());
Douglas Gregor506ae412009-01-16 18:33:17 +0000648}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000649
Mike Stump1eb44332009-09-09 15:08:12 +0000650CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000651 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000652 CXXConstructorDecl *D, bool Elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000653 Expr **Args, unsigned NumArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000654 bool HadMultipleCandidates,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000655 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000656 ConstructionKind ConstructKind,
657 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000658 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000659 Elidable, Args, NumArgs,
660 HadMultipleCandidates, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000661 ConstructKind, ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000662}
663
Mike Stump1eb44332009-09-09 15:08:12 +0000664CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000665 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000666 CXXConstructorDecl *D, bool elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000667 Expr **args, unsigned numargs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000668 bool HadMultipleCandidates,
669 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000670 ConstructionKind ConstructKind,
671 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000672 : Expr(SC, T, VK_RValue, OK_Ordinary,
673 T->isDependentType(), T->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000674 T->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000675 T->containsUnexpandedParameterPack()),
Douglas Gregora48e6762011-09-26 14:47:03 +0000676 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(numargs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000677 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
678 ZeroInitialization(ZeroInitialization),
Douglas Gregora48e6762011-09-26 14:47:03 +0000679 ConstructKind(ConstructKind), Args(0)
Douglas Gregor16006c92009-12-16 18:50:27 +0000680{
681 if (NumArgs) {
682 Args = new (C) Stmt*[NumArgs];
683
684 for (unsigned i = 0; i != NumArgs; ++i) {
685 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000686
687 if (args[i]->isValueDependent())
688 ExprBits.ValueDependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000689 if (args[i]->isInstantiationDependent())
690 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000691 if (args[i]->containsUnexpandedParameterPack())
692 ExprBits.ContainsUnexpandedParameterPack = true;
693
Douglas Gregor16006c92009-12-16 18:50:27 +0000694 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000695 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000696 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000697}
698
John McCall80ee6e82011-11-10 05:35:25 +0000699ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
700 ArrayRef<CleanupObject> objects)
John McCall4765fa02010-12-06 08:20:24 +0000701 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +0000702 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000703 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000704 subexpr->isInstantiationDependent(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000705 subexpr->containsUnexpandedParameterPack()),
John McCall80ee6e82011-11-10 05:35:25 +0000706 SubExpr(subexpr) {
707 ExprWithCleanupsBits.NumObjects = objects.size();
708 for (unsigned i = 0, e = objects.size(); i != e; ++i)
709 getObjectsBuffer()[i] = objects[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000710}
711
John McCall80ee6e82011-11-10 05:35:25 +0000712ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
713 ArrayRef<CleanupObject> objects) {
714 size_t size = sizeof(ExprWithCleanups)
715 + objects.size() * sizeof(CleanupObject);
716 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
717 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnerd2598362010-05-10 00:25:06 +0000718}
719
John McCall80ee6e82011-11-10 05:35:25 +0000720ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
721 : Expr(ExprWithCleanupsClass, empty) {
722 ExprWithCleanupsBits.NumObjects = numObjects;
723}
Chris Lattnerd2598362010-05-10 00:25:06 +0000724
John McCall80ee6e82011-11-10 05:35:25 +0000725ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
726 unsigned numObjects) {
727 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
728 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
729 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson88eaf072009-05-30 22:38:53 +0000730}
731
Douglas Gregorab6677e2010-09-08 00:15:04 +0000732CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000733 SourceLocation LParenLoc,
734 Expr **Args,
735 unsigned NumArgs,
736 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000737 : Expr(CXXUnresolvedConstructExprClass,
738 Type->getType().getNonReferenceType(),
Douglas Gregor032c8692011-07-08 15:50:43 +0000739 (Type->getType()->isLValueReferenceType() ? VK_LValue
740 :Type->getType()->isRValueReferenceType()? VK_XValue
741 :VK_RValue),
742 OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +0000743 Type->getType()->isDependentType(), true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000744 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +0000745 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000746 LParenLoc(LParenLoc),
747 RParenLoc(RParenLoc),
748 NumArgs(NumArgs) {
749 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000750 for (unsigned I = 0; I != NumArgs; ++I) {
751 if (Args[I]->containsUnexpandedParameterPack())
752 ExprBits.ContainsUnexpandedParameterPack = true;
753
754 StoredArgs[I] = Args[I];
755 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000756}
757
758CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +0000759CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000760 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000761 SourceLocation LParenLoc,
762 Expr **Args,
763 unsigned NumArgs,
764 SourceLocation RParenLoc) {
765 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
766 sizeof(Expr *) * NumArgs);
Douglas Gregorab6677e2010-09-08 00:15:04 +0000767 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000768 Args, NumArgs, RParenLoc);
769}
770
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000771CXXUnresolvedConstructExpr *
772CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
773 Stmt::EmptyShell Empty;
774 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
775 sizeof(Expr *) * NumArgs);
776 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
777}
778
Douglas Gregorab6677e2010-09-08 00:15:04 +0000779SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
780 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
781}
782
John McCall865d4472009-11-19 22:55:06 +0000783CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000784 Expr *Base, QualType BaseType,
785 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000786 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000787 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000788 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000789 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000790 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +0000791 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +0000792 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000793 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000794 (QualifierLoc &&
795 QualifierLoc.getNestedNameSpecifier()
796 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000797 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +0000798 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
799 HasExplicitTemplateArgs(TemplateArgs != 0),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000800 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000801 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +0000802 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000803 if (TemplateArgs) {
804 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000805 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000806 bool ContainsUnexpandedParameterPack = false;
807 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000808 InstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000809 ContainsUnexpandedParameterPack);
810 if (ContainsUnexpandedParameterPack)
811 ExprBits.ContainsUnexpandedParameterPack = true;
812 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000813}
814
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000815CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
816 Expr *Base, QualType BaseType,
817 bool IsArrow,
818 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000819 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000820 NamedDecl *FirstQualifierFoundInScope,
821 DeclarationNameInfo MemberNameInfo)
822 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +0000823 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000824 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000825 (QualifierLoc &&
826 QualifierLoc.getNestedNameSpecifier()->
827 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000828 MemberNameInfo.containsUnexpandedParameterPack())),
829 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
830 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000831 QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000832 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
833 MemberNameInfo(MemberNameInfo) { }
834
John McCall865d4472009-11-19 22:55:06 +0000835CXXDependentScopeMemberExpr *
836CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000837 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000838 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000839 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000840 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000841 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000842 const TemplateArgumentListInfo *TemplateArgs) {
843 if (!TemplateArgs)
John McCallaa81e162009-12-01 22:10:20 +0000844 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
845 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000846 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000847 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000848 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000849
John McCalld5532b62009-11-23 01:53:49 +0000850 std::size_t size = sizeof(CXXDependentScopeMemberExpr);
851 if (TemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000852 size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs);
John McCalld5532b62009-11-23 01:53:49 +0000853
Chris Lattner32488542010-10-30 05:14:06 +0000854 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +0000855 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
856 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000857 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000858 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000859 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000860}
861
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000862CXXDependentScopeMemberExpr *
863CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Douglas Gregordef03542011-02-04 12:01:24 +0000864 bool HasExplicitTemplateArgs,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000865 unsigned NumTemplateArgs) {
Douglas Gregordef03542011-02-04 12:01:24 +0000866 if (!HasExplicitTemplateArgs)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000867 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000868 0, SourceLocation(),
869 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000870 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000871
872 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000873 ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +0000874 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000875 CXXDependentScopeMemberExpr *E
876 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000877 0, SourceLocation(),
878 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000879 DeclarationNameInfo(), 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000880 E->HasExplicitTemplateArgs = true;
881 return E;
882}
883
Douglas Gregor4c9be892011-02-28 20:01:57 +0000884bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
885 if (Base == 0)
886 return true;
887
Douglas Gregor75e85042011-03-02 21:06:53 +0000888 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +0000889}
890
John McCall864c0412011-04-26 20:42:42 +0000891static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
892 UnresolvedSetIterator end) {
893 do {
894 NamedDecl *decl = *begin;
895 if (isa<UnresolvedUsingValueDecl>(decl))
896 return false;
897 if (isa<UsingShadowDecl>(decl))
898 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
899
900 // Unresolved member expressions should only contain methods and
901 // method templates.
902 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
903
904 if (isa<FunctionTemplateDecl>(decl))
905 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
906 if (cast<CXXMethodDecl>(decl)->isStatic())
907 return false;
908 } while (++begin != end);
909
910 return true;
911}
912
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000913UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000914 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000915 Expr *Base, QualType BaseType,
916 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000917 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000918 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000919 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000920 const TemplateArgumentListInfo *TemplateArgs,
921 UnresolvedSetIterator Begin,
922 UnresolvedSetIterator End)
Douglas Gregor4c9be892011-02-28 20:01:57 +0000923 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, MemberNameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000924 TemplateArgs, Begin, End,
925 // Dependent
926 ((Base && Base->isTypeDependent()) ||
927 BaseType->isDependentType()),
Douglas Gregor561f8122011-07-01 01:22:09 +0000928 ((Base && Base->isInstantiationDependent()) ||
929 BaseType->isInstantiationDependentType()),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000930 // Contains unexpanded parameter pack
931 ((Base && Base->containsUnexpandedParameterPack()) ||
932 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +0000933 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
934 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall864c0412011-04-26 20:42:42 +0000935
936 // Check whether all of the members are non-static member functions,
937 // and if so, mark give this bound-member type instead of overload type.
938 if (hasOnlyNonStaticMemberFunctions(Begin, End))
939 setType(C.BoundMemberTy);
John McCall129e2df2009-11-30 22:42:35 +0000940}
941
Douglas Gregor4c9be892011-02-28 20:01:57 +0000942bool UnresolvedMemberExpr::isImplicitAccess() const {
943 if (Base == 0)
944 return true;
945
Douglas Gregor75e85042011-03-02 21:06:53 +0000946 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +0000947}
948
John McCall129e2df2009-11-30 22:42:35 +0000949UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000950UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000951 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000952 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000953 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000954 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000955 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000956 const TemplateArgumentListInfo *TemplateArgs,
957 UnresolvedSetIterator Begin,
958 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +0000959 std::size_t size = sizeof(UnresolvedMemberExpr);
960 if (TemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000961 size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs);
John McCall129e2df2009-11-30 22:42:35 +0000962
Chris Lattner32488542010-10-30 05:14:06 +0000963 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000964 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000965 HasUnresolvedUsing, Base, BaseType,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000966 IsArrow, OperatorLoc, QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000967 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +0000968}
969
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000970UnresolvedMemberExpr *
Douglas Gregordef03542011-02-04 12:01:24 +0000971UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
972 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000973 std::size_t size = sizeof(UnresolvedMemberExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000974 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000975 size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000976
Chris Lattner32488542010-10-30 05:14:06 +0000977 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000978 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Douglas Gregordef03542011-02-04 12:01:24 +0000979 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000980 return E;
981}
982
John McCallc373d482010-01-27 01:50:18 +0000983CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
984 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
985
986 // If there was a nested name specifier, it names the naming class.
987 // It can't be dependent: after all, we were actually able to do the
988 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000989 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +0000990 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +0000991 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +0000992 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000993 Record = T->getAsCXXRecordDecl();
994 assert(Record && "qualifier in member expression does not name record");
995 }
John McCallc373d482010-01-27 01:50:18 +0000996 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000997 else {
John McCallc373d482010-01-27 01:50:18 +0000998 QualType BaseType = getBaseType().getNonReferenceType();
999 if (isArrow()) {
1000 const PointerType *PT = BaseType->getAs<PointerType>();
1001 assert(PT && "base of arrow member access is not pointer");
1002 BaseType = PT->getPointeeType();
1003 }
1004
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001005 Record = BaseType->getAsCXXRecordDecl();
1006 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +00001007 }
1008
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001009 return Record;
John McCallc373d482010-01-27 01:50:18 +00001010}
1011
Douglas Gregorc7793c72011-01-15 01:15:58 +00001012SubstNonTypeTemplateParmPackExpr::
1013SubstNonTypeTemplateParmPackExpr(QualType T,
1014 NonTypeTemplateParmDecl *Param,
1015 SourceLocation NameLoc,
1016 const TemplateArgument &ArgPack)
1017 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001018 true, true, true, true),
Douglas Gregorc7793c72011-01-15 01:15:58 +00001019 Param(Param), Arguments(ArgPack.pack_begin()),
1020 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1021
1022TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1023 return TemplateArgument(Arguments, NumArguments);
1024}
1025
Douglas Gregorc7793c72011-01-15 01:15:58 +00001026