blob: ad5ec8b8331a68ea0ad31d6582aa49c579815d78 [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) {
Mike Stump1eb44332009-09-09 15:08:12 +0000621 assert(SubExpr->getType()->isRecordType() &&
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000622 "Expression bound to a temporary must have record type!");
623
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000624 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000625}
626
Anders Carlsson8e587a12009-05-30 20:56:46 +0000627CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000628 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000629 TypeSourceInfo *Type,
Douglas Gregor506ae412009-01-16 18:33:17 +0000630 Expr **Args,
Mike Stump1eb44332009-09-09 15:08:12 +0000631 unsigned NumArgs,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000632 SourceRange parenRange,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000633 bool HadMultipleCandidates,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000634 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000635 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
636 Type->getType().getNonReferenceType(),
637 Type->getTypeLoc().getBeginLoc(),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000638 Cons, false, Args, NumArgs,
639 HadMultipleCandidates, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000640 CXXConstructExpr::CK_Complete, parenRange),
641 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000642}
643
644SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth428edaf2010-10-25 08:47:36 +0000645 return SourceRange(Type->getTypeLoc().getBeginLoc(),
646 getParenRange().getEnd());
Douglas Gregor506ae412009-01-16 18:33:17 +0000647}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000648
Mike Stump1eb44332009-09-09 15:08:12 +0000649CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000650 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000651 CXXConstructorDecl *D, bool Elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000652 Expr **Args, unsigned NumArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000653 bool HadMultipleCandidates,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000654 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000655 ConstructionKind ConstructKind,
656 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000657 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000658 Elidable, Args, NumArgs,
659 HadMultipleCandidates, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000660 ConstructKind, ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000661}
662
Mike Stump1eb44332009-09-09 15:08:12 +0000663CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000664 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000665 CXXConstructorDecl *D, bool elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000666 Expr **args, unsigned numargs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000667 bool HadMultipleCandidates,
668 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000669 ConstructionKind ConstructKind,
670 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000671 : Expr(SC, T, VK_RValue, OK_Ordinary,
672 T->isDependentType(), T->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000673 T->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000674 T->containsUnexpandedParameterPack()),
Douglas Gregora48e6762011-09-26 14:47:03 +0000675 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(numargs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000676 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
677 ZeroInitialization(ZeroInitialization),
Douglas Gregora48e6762011-09-26 14:47:03 +0000678 ConstructKind(ConstructKind), Args(0)
Douglas Gregor16006c92009-12-16 18:50:27 +0000679{
680 if (NumArgs) {
681 Args = new (C) Stmt*[NumArgs];
682
683 for (unsigned i = 0; i != NumArgs; ++i) {
684 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000685
686 if (args[i]->isValueDependent())
687 ExprBits.ValueDependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000688 if (args[i]->isInstantiationDependent())
689 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000690 if (args[i]->containsUnexpandedParameterPack())
691 ExprBits.ContainsUnexpandedParameterPack = true;
692
Douglas Gregor16006c92009-12-16 18:50:27 +0000693 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000694 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000695 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000696}
697
John McCall4765fa02010-12-06 08:20:24 +0000698ExprWithCleanups::ExprWithCleanups(ASTContext &C,
699 Expr *subexpr,
700 CXXTemporary **temps,
701 unsigned numtemps)
702 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +0000703 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000704 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000705 subexpr->isInstantiationDependent(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000706 subexpr->containsUnexpandedParameterPack()),
Chris Lattnerd2598362010-05-10 00:25:06 +0000707 SubExpr(subexpr), Temps(0), NumTemps(0) {
Chris Lattneraff32cb2010-05-10 00:45:12 +0000708 if (numtemps) {
Ted Kremenekd04ed412010-05-10 20:06:30 +0000709 setNumTemporaries(C, numtemps);
Chris Lattnerd2598362010-05-10 00:25:06 +0000710 for (unsigned i = 0; i != numtemps; ++i)
Anders Carlssonff6b3d62009-05-30 21:05:25 +0000711 Temps[i] = temps[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000712 }
713}
714
John McCall4765fa02010-12-06 08:20:24 +0000715void ExprWithCleanups::setNumTemporaries(ASTContext &C, unsigned N) {
Chris Lattnerd2598362010-05-10 00:25:06 +0000716 assert(Temps == 0 && "Cannot resize with this");
Daniel Dunbar90556d42010-05-10 15:59:37 +0000717 NumTemps = N;
Ted Kremenekd04ed412010-05-10 20:06:30 +0000718 Temps = new (C) CXXTemporary*[NumTemps];
Chris Lattnerd2598362010-05-10 00:25:06 +0000719}
720
721
John McCall4765fa02010-12-06 08:20:24 +0000722ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C,
723 Expr *SubExpr,
724 CXXTemporary **Temps,
725 unsigned NumTemps) {
726 return new (C) ExprWithCleanups(C, SubExpr, Temps, NumTemps);
Anders Carlsson88eaf072009-05-30 22:38:53 +0000727}
728
Douglas Gregorab6677e2010-09-08 00:15:04 +0000729CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000730 SourceLocation LParenLoc,
731 Expr **Args,
732 unsigned NumArgs,
733 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000734 : Expr(CXXUnresolvedConstructExprClass,
735 Type->getType().getNonReferenceType(),
Douglas Gregor032c8692011-07-08 15:50:43 +0000736 (Type->getType()->isLValueReferenceType() ? VK_LValue
737 :Type->getType()->isRValueReferenceType()? VK_XValue
738 :VK_RValue),
739 OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +0000740 Type->getType()->isDependentType(), true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000741 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +0000742 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000743 LParenLoc(LParenLoc),
744 RParenLoc(RParenLoc),
745 NumArgs(NumArgs) {
746 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000747 for (unsigned I = 0; I != NumArgs; ++I) {
748 if (Args[I]->containsUnexpandedParameterPack())
749 ExprBits.ContainsUnexpandedParameterPack = true;
750
751 StoredArgs[I] = Args[I];
752 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000753}
754
755CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +0000756CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000757 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000758 SourceLocation LParenLoc,
759 Expr **Args,
760 unsigned NumArgs,
761 SourceLocation RParenLoc) {
762 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
763 sizeof(Expr *) * NumArgs);
Douglas Gregorab6677e2010-09-08 00:15:04 +0000764 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000765 Args, NumArgs, RParenLoc);
766}
767
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000768CXXUnresolvedConstructExpr *
769CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
770 Stmt::EmptyShell Empty;
771 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
772 sizeof(Expr *) * NumArgs);
773 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
774}
775
Douglas Gregorab6677e2010-09-08 00:15:04 +0000776SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
777 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
778}
779
John McCall865d4472009-11-19 22:55:06 +0000780CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000781 Expr *Base, QualType BaseType,
782 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000783 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000784 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000785 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000786 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000787 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +0000788 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +0000789 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000790 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000791 (QualifierLoc &&
792 QualifierLoc.getNestedNameSpecifier()
793 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000794 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +0000795 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
796 HasExplicitTemplateArgs(TemplateArgs != 0),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000797 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000798 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +0000799 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000800 if (TemplateArgs) {
801 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000802 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000803 bool ContainsUnexpandedParameterPack = false;
804 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000805 InstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000806 ContainsUnexpandedParameterPack);
807 if (ContainsUnexpandedParameterPack)
808 ExprBits.ContainsUnexpandedParameterPack = true;
809 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000810}
811
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000812CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
813 Expr *Base, QualType BaseType,
814 bool IsArrow,
815 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000816 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000817 NamedDecl *FirstQualifierFoundInScope,
818 DeclarationNameInfo MemberNameInfo)
819 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +0000820 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000821 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000822 (QualifierLoc &&
823 QualifierLoc.getNestedNameSpecifier()->
824 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000825 MemberNameInfo.containsUnexpandedParameterPack())),
826 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
827 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000828 QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000829 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
830 MemberNameInfo(MemberNameInfo) { }
831
John McCall865d4472009-11-19 22:55:06 +0000832CXXDependentScopeMemberExpr *
833CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000834 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000835 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000836 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000837 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000838 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000839 const TemplateArgumentListInfo *TemplateArgs) {
840 if (!TemplateArgs)
John McCallaa81e162009-12-01 22:10:20 +0000841 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
842 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000843 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000844 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000845 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000846
John McCalld5532b62009-11-23 01:53:49 +0000847 std::size_t size = sizeof(CXXDependentScopeMemberExpr);
848 if (TemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000849 size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs);
John McCalld5532b62009-11-23 01:53:49 +0000850
Chris Lattner32488542010-10-30 05:14:06 +0000851 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +0000852 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
853 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000854 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000855 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000856 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000857}
858
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000859CXXDependentScopeMemberExpr *
860CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Douglas Gregordef03542011-02-04 12:01:24 +0000861 bool HasExplicitTemplateArgs,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000862 unsigned NumTemplateArgs) {
Douglas Gregordef03542011-02-04 12:01:24 +0000863 if (!HasExplicitTemplateArgs)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000864 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000865 0, SourceLocation(),
866 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000867 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000868
869 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000870 ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +0000871 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000872 CXXDependentScopeMemberExpr *E
873 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000874 0, SourceLocation(),
875 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000876 DeclarationNameInfo(), 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000877 E->HasExplicitTemplateArgs = true;
878 return E;
879}
880
Douglas Gregor4c9be892011-02-28 20:01:57 +0000881bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
882 if (Base == 0)
883 return true;
884
Douglas Gregor75e85042011-03-02 21:06:53 +0000885 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +0000886}
887
John McCall864c0412011-04-26 20:42:42 +0000888static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
889 UnresolvedSetIterator end) {
890 do {
891 NamedDecl *decl = *begin;
892 if (isa<UnresolvedUsingValueDecl>(decl))
893 return false;
894 if (isa<UsingShadowDecl>(decl))
895 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
896
897 // Unresolved member expressions should only contain methods and
898 // method templates.
899 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
900
901 if (isa<FunctionTemplateDecl>(decl))
902 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
903 if (cast<CXXMethodDecl>(decl)->isStatic())
904 return false;
905 } while (++begin != end);
906
907 return true;
908}
909
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000910UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000911 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000912 Expr *Base, QualType BaseType,
913 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000914 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000915 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000916 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000917 const TemplateArgumentListInfo *TemplateArgs,
918 UnresolvedSetIterator Begin,
919 UnresolvedSetIterator End)
Douglas Gregor4c9be892011-02-28 20:01:57 +0000920 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, MemberNameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000921 TemplateArgs, Begin, End,
922 // Dependent
923 ((Base && Base->isTypeDependent()) ||
924 BaseType->isDependentType()),
Douglas Gregor561f8122011-07-01 01:22:09 +0000925 ((Base && Base->isInstantiationDependent()) ||
926 BaseType->isInstantiationDependentType()),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000927 // Contains unexpanded parameter pack
928 ((Base && Base->containsUnexpandedParameterPack()) ||
929 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +0000930 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
931 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall864c0412011-04-26 20:42:42 +0000932
933 // Check whether all of the members are non-static member functions,
934 // and if so, mark give this bound-member type instead of overload type.
935 if (hasOnlyNonStaticMemberFunctions(Begin, End))
936 setType(C.BoundMemberTy);
John McCall129e2df2009-11-30 22:42:35 +0000937}
938
Douglas Gregor4c9be892011-02-28 20:01:57 +0000939bool UnresolvedMemberExpr::isImplicitAccess() const {
940 if (Base == 0)
941 return true;
942
Douglas Gregor75e85042011-03-02 21:06:53 +0000943 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +0000944}
945
John McCall129e2df2009-11-30 22:42:35 +0000946UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000947UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000948 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000949 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000950 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000951 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000952 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000953 const TemplateArgumentListInfo *TemplateArgs,
954 UnresolvedSetIterator Begin,
955 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +0000956 std::size_t size = sizeof(UnresolvedMemberExpr);
957 if (TemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000958 size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs);
John McCall129e2df2009-11-30 22:42:35 +0000959
Chris Lattner32488542010-10-30 05:14:06 +0000960 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000961 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000962 HasUnresolvedUsing, Base, BaseType,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000963 IsArrow, OperatorLoc, QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000964 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +0000965}
966
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000967UnresolvedMemberExpr *
Douglas Gregordef03542011-02-04 12:01:24 +0000968UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
969 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000970 std::size_t size = sizeof(UnresolvedMemberExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000971 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000972 size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000973
Chris Lattner32488542010-10-30 05:14:06 +0000974 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000975 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Douglas Gregordef03542011-02-04 12:01:24 +0000976 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000977 return E;
978}
979
John McCallc373d482010-01-27 01:50:18 +0000980CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
981 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
982
983 // If there was a nested name specifier, it names the naming class.
984 // It can't be dependent: after all, we were actually able to do the
985 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000986 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +0000987 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +0000988 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +0000989 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000990 Record = T->getAsCXXRecordDecl();
991 assert(Record && "qualifier in member expression does not name record");
992 }
John McCallc373d482010-01-27 01:50:18 +0000993 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000994 else {
John McCallc373d482010-01-27 01:50:18 +0000995 QualType BaseType = getBaseType().getNonReferenceType();
996 if (isArrow()) {
997 const PointerType *PT = BaseType->getAs<PointerType>();
998 assert(PT && "base of arrow member access is not pointer");
999 BaseType = PT->getPointeeType();
1000 }
1001
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001002 Record = BaseType->getAsCXXRecordDecl();
1003 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +00001004 }
1005
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001006 return Record;
John McCallc373d482010-01-27 01:50:18 +00001007}
1008
Douglas Gregorc7793c72011-01-15 01:15:58 +00001009SubstNonTypeTemplateParmPackExpr::
1010SubstNonTypeTemplateParmPackExpr(QualType T,
1011 NonTypeTemplateParmDecl *Param,
1012 SourceLocation NameLoc,
1013 const TemplateArgument &ArgPack)
1014 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001015 true, true, true, true),
Douglas Gregorc7793c72011-01-15 01:15:58 +00001016 Param(Param), Arguments(ArgPack.pack_begin()),
1017 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1018
1019TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1020 return TemplateArgument(Arguments, NumArguments);
1021}
1022
Douglas Gregorc7793c72011-01-15 01:15:58 +00001023