blob: 51dd57cfe3cbba8d56257cab9b88113566911d9d [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 Bagnarae4b92762012-01-27 09:46:47 +0000200 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000201 const DeclarationNameInfo &NameInfo,
202 bool ADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000203 const TemplateArgumentListInfo *Args,
204 UnresolvedSetIterator Begin,
205 UnresolvedSetIterator End)
John McCallf7a1a742009-11-24 19:00:30 +0000206{
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000207 assert(Args || TemplateKWLoc.isValid());
208 unsigned num_args = Args ? Args->size() : 0;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000209 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000210 ASTTemplateKWAndArgsInfo::sizeFor(num_args));
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000211 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
212 TemplateKWLoc, NameInfo,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000213 ADL, /*Overload*/ true, Args,
Richard Smithad762fc2011-04-14 22:09:26 +0000214 Begin, End, /*StdIsAssociated=*/false);
John McCallf7a1a742009-11-24 19:00:30 +0000215}
216
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000217UnresolvedLookupExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000218UnresolvedLookupExpr::CreateEmpty(ASTContext &C,
219 bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +0000220 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000221 std::size_t size = sizeof(UnresolvedLookupExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000222 if (HasTemplateKWAndArgsInfo)
223 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000224
Chris Lattner32488542010-10-30 05:14:06 +0000225 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000226 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000227 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000228 return E;
229}
230
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000231OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000232 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000233 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000234 const DeclarationNameInfo &NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000235 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000236 UnresolvedSetIterator Begin,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000237 UnresolvedSetIterator End,
238 bool KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000239 bool KnownInstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000240 bool KnownContainsUnexpandedParameterPack)
241 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
242 KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000243 (KnownInstantiationDependent ||
244 NameInfo.isInstantiationDependent() ||
245 (QualifierLoc &&
246 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000247 (KnownContainsUnexpandedParameterPack ||
248 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor4c9be892011-02-28 20:01:57 +0000249 (QualifierLoc &&
250 QualifierLoc.getNestedNameSpecifier()
251 ->containsUnexpandedParameterPack()))),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000252 Results(0), NumResults(End - Begin), NameInfo(NameInfo),
253 QualifierLoc(QualifierLoc),
254 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid())
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000255{
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000256 NumResults = End - Begin;
257 if (NumResults) {
258 // Determine whether this expression is type-dependent.
259 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
260 if ((*I)->getDeclContext()->isDependentContext() ||
261 isa<UnresolvedUsingValueDecl>(*I)) {
262 ExprBits.TypeDependent = true;
263 ExprBits.ValueDependent = true;
264 }
265 }
266
267 Results = static_cast<DeclAccessPair *>(
268 C.Allocate(sizeof(DeclAccessPair) * NumResults,
269 llvm::alignOf<DeclAccessPair>()));
270 memcpy(Results, &*Begin.getIterator(),
271 NumResults * sizeof(DeclAccessPair));
272 }
273
274 // If we have explicit template arguments, check for dependent
275 // template arguments and whether they contain any unexpanded pack
276 // expansions.
277 if (TemplateArgs) {
278 bool Dependent = false;
Douglas Gregor561f8122011-07-01 01:22:09 +0000279 bool InstantiationDependent = false;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000280 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000281 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
282 Dependent,
283 InstantiationDependent,
284 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000285
286 if (Dependent) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000287 ExprBits.TypeDependent = true;
288 ExprBits.ValueDependent = true;
289 }
290 if (InstantiationDependent)
291 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000292 if (ContainsUnexpandedParameterPack)
293 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000294 } else if (TemplateKWLoc.isValid()) {
295 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000296 }
297
298 if (isTypeDependent())
299 setType(C.DependentTy);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000300}
301
302void OverloadExpr::initializeResults(ASTContext &C,
303 UnresolvedSetIterator Begin,
304 UnresolvedSetIterator End) {
305 assert(Results == 0 && "Results already initialized!");
306 NumResults = End - Begin;
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000307 if (NumResults) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000308 Results = static_cast<DeclAccessPair *>(
309 C.Allocate(sizeof(DeclAccessPair) * NumResults,
310
311 llvm::alignOf<DeclAccessPair>()));
312 memcpy(Results, &*Begin.getIterator(),
313 NumResults * sizeof(DeclAccessPair));
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000314 }
315}
316
John McCalle9ee23e2010-04-22 18:44:12 +0000317CXXRecordDecl *OverloadExpr::getNamingClass() const {
318 if (isa<UnresolvedLookupExpr>(this))
319 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
320 else
321 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
322}
323
John McCall865d4472009-11-19 22:55:06 +0000324// DependentScopeDeclRefExpr
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000325DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000326 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000327 SourceLocation TemplateKWLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000328 const DeclarationNameInfo &NameInfo,
329 const TemplateArgumentListInfo *Args)
330 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
331 true, true,
Douglas Gregor561f8122011-07-01 01:22:09 +0000332 (NameInfo.isInstantiationDependent() ||
333 (QualifierLoc &&
334 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000335 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000336 (QualifierLoc &&
337 QualifierLoc.getNestedNameSpecifier()
338 ->containsUnexpandedParameterPack()))),
339 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000340 HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid())
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000341{
342 if (Args) {
343 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000344 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000345 bool ContainsUnexpandedParameterPack
346 = ExprBits.ContainsUnexpandedParameterPack;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000347 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args,
348 Dependent,
349 InstantiationDependent,
350 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000351 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000352 } else if (TemplateKWLoc.isValid()) {
353 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000354 }
355}
356
John McCallf7a1a742009-11-24 19:00:30 +0000357DependentScopeDeclRefExpr *
358DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000359 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000360 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000361 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +0000362 const TemplateArgumentListInfo *Args) {
363 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCallf7a1a742009-11-24 19:00:30 +0000364 if (Args)
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000365 size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size());
366 else if (TemplateKWLoc.isValid())
367 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000368 void *Mem = C.Allocate(size);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000369 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
370 TemplateKWLoc, NameInfo, Args);
John McCallf7a1a742009-11-24 19:00:30 +0000371}
372
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000373DependentScopeDeclRefExpr *
374DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000375 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000376 unsigned NumTemplateArgs) {
377 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000378 if (HasTemplateKWAndArgsInfo)
379 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000380 void *Mem = C.Allocate(size);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000381 DependentScopeDeclRefExpr *E
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000382 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000383 SourceLocation(),
Douglas Gregordef03542011-02-04 12:01:24 +0000384 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000385 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregordef03542011-02-04 12:01:24 +0000386 return E;
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000387}
388
Chandler Carruth428edaf2010-10-25 08:47:36 +0000389SourceRange CXXConstructExpr::getSourceRange() const {
John McCall2882eca2011-02-21 06:23:05 +0000390 if (isa<CXXTemporaryObjectExpr>(this))
391 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
392
Douglas Gregor40749ee2010-11-03 00:35:38 +0000393 if (ParenRange.isValid())
394 return SourceRange(Loc, ParenRange.getEnd());
395
396 SourceLocation End = Loc;
397 for (unsigned I = getNumArgs(); I > 0; --I) {
398 const Expr *Arg = getArg(I-1);
399 if (!Arg->isDefaultArgument()) {
400 SourceLocation NewEnd = Arg->getLocEnd();
401 if (NewEnd.isValid()) {
402 End = NewEnd;
403 break;
404 }
405 }
406 }
407
408 return SourceRange(Loc, End);
Ted Kremeneke3837682009-12-23 04:00:48 +0000409}
410
Douglas Gregorb4609802008-11-14 16:09:21 +0000411SourceRange CXXOperatorCallExpr::getSourceRange() const {
412 OverloadedOperatorKind Kind = getOperator();
413 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
414 if (getNumArgs() == 1)
415 // Prefix operator
Mike Stump1eb44332009-09-09 15:08:12 +0000416 return SourceRange(getOperatorLoc(),
Douglas Gregorb4609802008-11-14 16:09:21 +0000417 getArg(0)->getSourceRange().getEnd());
418 else
419 // Postfix operator
Chandler Carruthd7650612011-04-02 09:47:38 +0000420 return SourceRange(getArg(0)->getSourceRange().getBegin(),
Douglas Gregorb4609802008-11-14 16:09:21 +0000421 getOperatorLoc());
Chandler Carruthd7650612011-04-02 09:47:38 +0000422 } else if (Kind == OO_Arrow) {
423 return getArg(0)->getSourceRange();
Douglas Gregorb4609802008-11-14 16:09:21 +0000424 } else if (Kind == OO_Call) {
425 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
426 } else if (Kind == OO_Subscript) {
427 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
428 } else if (getNumArgs() == 1) {
429 return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd());
430 } else if (getNumArgs() == 2) {
431 return SourceRange(getArg(0)->getSourceRange().getBegin(),
432 getArg(1)->getSourceRange().getEnd());
433 } else {
434 return SourceRange();
435 }
436}
437
Ted Kremenekb2771592011-03-30 17:41:19 +0000438Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
439 if (const MemberExpr *MemExpr =
440 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
Douglas Gregor88a35142008-12-22 05:46:06 +0000441 return MemExpr->getBase();
442
443 // FIXME: Will eventually need to cope with member pointers.
444 return 0;
445}
446
Ted Kremenekb2771592011-03-30 17:41:19 +0000447CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
448 if (const MemberExpr *MemExpr =
449 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
450 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
451
452 // FIXME: Will eventually need to cope with member pointers.
453 return 0;
454}
455
456
Chandler Carruth007a9b12010-10-27 06:55:41 +0000457CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
458 Expr* ThisArg = getImplicitObjectArgument();
459 if (!ThisArg)
460 return 0;
461
462 if (ThisArg->getType()->isAnyPointerType())
463 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
464
465 return ThisArg->getType()->getAsCXXRecordDecl();
466}
467
Douglas Gregor00b98c22009-11-12 15:31:47 +0000468
Douglas Gregor49badde2008-10-27 19:41:14 +0000469//===----------------------------------------------------------------------===//
470// Named casts
471//===----------------------------------------------------------------------===//
472
473/// getCastName - Get the name of the C++ cast being used, e.g.,
474/// "static_cast", "dynamic_cast", "reinterpret_cast", or
475/// "const_cast". The returned pointer must not be freed.
476const char *CXXNamedCastExpr::getCastName() const {
477 switch (getStmtClass()) {
478 case CXXStaticCastExprClass: return "static_cast";
479 case CXXDynamicCastExprClass: return "dynamic_cast";
480 case CXXReinterpretCastExprClass: return "reinterpret_cast";
481 case CXXConstCastExprClass: return "const_cast";
482 default: return "<invalid cast>";
483 }
484}
Douglas Gregor506ae412009-01-16 18:33:17 +0000485
John McCallf871d0c2010-08-07 06:22:56 +0000486CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000487 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000488 CastKind K, Expr *Op,
489 const CXXCastPath *BasePath,
490 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000491 SourceLocation L,
492 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000493 unsigned PathSize = (BasePath ? BasePath->size() : 0);
494 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
495 + PathSize * sizeof(CXXBaseSpecifier*));
496 CXXStaticCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000497 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
498 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000499 if (PathSize) E->setCastPath(*BasePath);
500 return E;
501}
502
503CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
504 unsigned PathSize) {
505 void *Buffer =
506 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
507 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
508}
509
510CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000511 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000512 CastKind K, Expr *Op,
513 const CXXCastPath *BasePath,
514 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000515 SourceLocation L,
516 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000517 unsigned PathSize = (BasePath ? BasePath->size() : 0);
518 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
519 + PathSize * sizeof(CXXBaseSpecifier*));
520 CXXDynamicCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000521 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
522 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000523 if (PathSize) E->setCastPath(*BasePath);
524 return E;
525}
526
527CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
528 unsigned PathSize) {
529 void *Buffer =
530 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
531 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
532}
533
Anders Carlsson0fee3302011-04-11 01:43:55 +0000534/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
535/// to always be null. For example:
536///
537/// struct A { };
538/// struct B final : A { };
539/// struct C { };
540///
541/// C *f(B* b) { return dynamic_cast<C*>(b); }
542bool CXXDynamicCastExpr::isAlwaysNull() const
543{
544 QualType SrcType = getSubExpr()->getType();
545 QualType DestType = getType();
546
547 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
548 SrcType = SrcPTy->getPointeeType();
549 DestType = DestType->castAs<PointerType>()->getPointeeType();
550 }
551
552 const CXXRecordDecl *SrcRD =
553 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
554
555 if (!SrcRD->hasAttr<FinalAttr>())
556 return false;
557
558 const CXXRecordDecl *DestRD =
559 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
560
561 return !DestRD->isDerivedFrom(SrcRD);
562}
563
John McCallf871d0c2010-08-07 06:22:56 +0000564CXXReinterpretCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000565CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
566 CastKind K, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000567 const CXXCastPath *BasePath,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000568 TypeSourceInfo *WrittenTy, SourceLocation L,
569 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000570 unsigned PathSize = (BasePath ? BasePath->size() : 0);
571 void *Buffer =
572 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
573 CXXReinterpretCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000574 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
575 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000576 if (PathSize) E->setCastPath(*BasePath);
577 return E;
578}
579
580CXXReinterpretCastExpr *
581CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
582 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
583 + PathSize * sizeof(CXXBaseSpecifier*));
584 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
585}
586
John McCallf89e55a2010-11-18 06:31:45 +0000587CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
588 ExprValueKind VK, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000589 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000590 SourceLocation L,
591 SourceLocation RParenLoc) {
592 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000593}
594
595CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
596 return new (C) CXXConstCastExpr(EmptyShell());
597}
598
599CXXFunctionalCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000600CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000601 TypeSourceInfo *Written, SourceLocation L,
602 CastKind K, Expr *Op, const CXXCastPath *BasePath,
603 SourceLocation R) {
604 unsigned PathSize = (BasePath ? BasePath->size() : 0);
605 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
606 + PathSize * sizeof(CXXBaseSpecifier*));
607 CXXFunctionalCastExpr *E =
John McCallf89e55a2010-11-18 06:31:45 +0000608 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallf871d0c2010-08-07 06:22:56 +0000609 if (PathSize) E->setCastPath(*BasePath);
610 return E;
611}
612
613CXXFunctionalCastExpr *
614CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
615 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
616 + PathSize * sizeof(CXXBaseSpecifier*));
617 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
618}
619
620
Douglas Gregor65222e82009-12-23 18:19:08 +0000621CXXDefaultArgExpr *
Douglas Gregor036aed12009-12-23 23:03:06 +0000622CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
623 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor65222e82009-12-23 18:19:08 +0000624 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor036aed12009-12-23 23:03:06 +0000625 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
626 SubExpr);
Douglas Gregor65222e82009-12-23 18:19:08 +0000627}
628
Mike Stump1eb44332009-09-09 15:08:12 +0000629CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonb859f352009-05-30 20:34:37 +0000630 const CXXDestructorDecl *Destructor) {
Anders Carlsson88eaf072009-05-30 22:38:53 +0000631 return new (C) CXXTemporary(Destructor);
632}
633
Mike Stump1eb44332009-09-09 15:08:12 +0000634CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000635 CXXTemporary *Temp,
636 Expr* SubExpr) {
Peter Collingbournebceb7552011-11-27 22:09:28 +0000637 assert((SubExpr->getType()->isRecordType() ||
638 SubExpr->getType()->isArrayType()) &&
639 "Expression bound to a temporary must have record or array type!");
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000640
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000641 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000642}
643
Anders Carlsson8e587a12009-05-30 20:56:46 +0000644CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000645 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000646 TypeSourceInfo *Type,
Douglas Gregor506ae412009-01-16 18:33:17 +0000647 Expr **Args,
Mike Stump1eb44332009-09-09 15:08:12 +0000648 unsigned NumArgs,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000649 SourceRange parenRange,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000650 bool HadMultipleCandidates,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000651 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000652 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
653 Type->getType().getNonReferenceType(),
654 Type->getTypeLoc().getBeginLoc(),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000655 Cons, false, Args, NumArgs,
656 HadMultipleCandidates, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000657 CXXConstructExpr::CK_Complete, parenRange),
658 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000659}
660
661SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth428edaf2010-10-25 08:47:36 +0000662 return SourceRange(Type->getTypeLoc().getBeginLoc(),
663 getParenRange().getEnd());
Douglas Gregor506ae412009-01-16 18:33:17 +0000664}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000665
Mike Stump1eb44332009-09-09 15:08:12 +0000666CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000667 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000668 CXXConstructorDecl *D, bool Elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000669 Expr **Args, unsigned NumArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000670 bool HadMultipleCandidates,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000671 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000672 ConstructionKind ConstructKind,
673 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000674 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000675 Elidable, Args, NumArgs,
676 HadMultipleCandidates, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000677 ConstructKind, ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000678}
679
Mike Stump1eb44332009-09-09 15:08:12 +0000680CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000681 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000682 CXXConstructorDecl *D, bool elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000683 Expr **args, unsigned numargs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000684 bool HadMultipleCandidates,
685 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000686 ConstructionKind ConstructKind,
687 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000688 : Expr(SC, T, VK_RValue, OK_Ordinary,
689 T->isDependentType(), T->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000690 T->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000691 T->containsUnexpandedParameterPack()),
Douglas Gregora48e6762011-09-26 14:47:03 +0000692 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(numargs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000693 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
694 ZeroInitialization(ZeroInitialization),
Douglas Gregora48e6762011-09-26 14:47:03 +0000695 ConstructKind(ConstructKind), Args(0)
Douglas Gregor16006c92009-12-16 18:50:27 +0000696{
697 if (NumArgs) {
698 Args = new (C) Stmt*[NumArgs];
699
700 for (unsigned i = 0; i != NumArgs; ++i) {
701 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000702
703 if (args[i]->isValueDependent())
704 ExprBits.ValueDependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000705 if (args[i]->isInstantiationDependent())
706 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000707 if (args[i]->containsUnexpandedParameterPack())
708 ExprBits.ContainsUnexpandedParameterPack = true;
709
Douglas Gregor16006c92009-12-16 18:50:27 +0000710 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000711 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000712 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000713}
714
Douglas Gregor01d08012012-02-07 10:09:13 +0000715LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
716 LambdaCaptureKind Kind, VarDecl *Var,
717 SourceLocation EllipsisLoc)
718 : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
719{
720 unsigned Bits = 0;
721 if (Implicit)
722 Bits |= Capture_Implicit;
723
724 switch (Kind) {
725 case LCK_This:
726 assert(Var == 0 && "'this' capture cannot have a variable!");
727 break;
728
729 case LCK_ByCopy:
730 Bits |= Capture_ByCopy;
731 // Fall through
732 case LCK_ByRef:
733 assert(Var && "capture must have a variable!");
734 break;
735 }
736 VarAndBits.setInt(Bits);
737}
738
739LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const {
740 if (capturesThis())
741 return LCK_This;
742
743 return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef;
744}
745
746LambdaExpr::LambdaExpr(QualType T,
747 SourceRange IntroducerRange,
748 LambdaCaptureDefault CaptureDefault,
749 ArrayRef<Capture> Captures,
750 bool ExplicitParams,
751 ArrayRef<Expr *> CaptureInits,
752 SourceLocation ClosingBrace)
753 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
754 T->isDependentType(), T->isDependentType(), T->isDependentType(),
755 /*ContainsUnexpandedParameterPack=*/false),
756 IntroducerRange(IntroducerRange),
757 NumCaptures(Captures.size()),
758 NumExplicitCaptures(0),
759 CaptureDefault(CaptureDefault),
760 ExplicitParams(ExplicitParams),
761 ClosingBrace(ClosingBrace)
762{
763 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
764
765 // Copy captures.
766 // FIXME: Do we need to update "contains unexpanded parameter pack" here?
767 Capture *ToCapture = reinterpret_cast<Capture *>(this + 1);
768 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
769 if (Captures[I].isExplicit())
770 ++NumExplicitCaptures;
771 *ToCapture++ = Captures[I];
772 }
773
774 // Copy initialization expressions for the non-static data members.
775 Stmt **Stored = getStoredStmts();
776 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
777 *Stored++ = CaptureInits[I];
778
779 // Copy the body of the lambda.
780 *Stored++ = getCallOperator()->getBody();
781}
782
783LambdaExpr *LambdaExpr::Create(ASTContext &Context,
784 CXXRecordDecl *Class,
785 SourceRange IntroducerRange,
786 LambdaCaptureDefault CaptureDefault,
787 ArrayRef<Capture> Captures,
788 bool ExplicitParams,
789 ArrayRef<Expr *> CaptureInits,
790 SourceLocation ClosingBrace) {
791 // Determine the type of the expression (i.e., the type of the
792 // function object we're creating).
793 QualType T = Context.getTypeDeclType(Class);
794 size_t Size = sizeof(LambdaExpr) + sizeof(Capture) * Captures.size()
795 + sizeof(Stmt *) * (Captures.size() + 1);
796
797 void *Mem = Context.Allocate(Size, llvm::alignOf<LambdaExpr>());
798 return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault,
799 Captures, ExplicitParams, CaptureInits,
800 ClosingBrace);
801}
802
803CXXRecordDecl *LambdaExpr::getLambdaClass() const {
804 return getType()->getAsCXXRecordDecl();
805}
806
807CXXMethodDecl *LambdaExpr::getCallOperator() const {
808 CXXRecordDecl *Record = getLambdaClass();
809 DeclarationName Name
810 = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
811 DeclContext::lookup_result Calls = Record->lookup(Name);
812 assert(Calls.first != Calls.second && "Missing lambda call operator!");
813 CXXMethodDecl *Result = cast<CXXMethodDecl>(*Calls.first++);
814 assert(Calls.first == Calls.second && "More than lambda one call operator?");
815 return Result;
816}
817
818bool LambdaExpr::isMutable() const {
819 return (getCallOperator()->getTypeQualifiers() & Qualifiers::Const) == 0;
820}
821
John McCall80ee6e82011-11-10 05:35:25 +0000822ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
823 ArrayRef<CleanupObject> objects)
John McCall4765fa02010-12-06 08:20:24 +0000824 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +0000825 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000826 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000827 subexpr->isInstantiationDependent(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000828 subexpr->containsUnexpandedParameterPack()),
John McCall80ee6e82011-11-10 05:35:25 +0000829 SubExpr(subexpr) {
830 ExprWithCleanupsBits.NumObjects = objects.size();
831 for (unsigned i = 0, e = objects.size(); i != e; ++i)
832 getObjectsBuffer()[i] = objects[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000833}
834
John McCall80ee6e82011-11-10 05:35:25 +0000835ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
836 ArrayRef<CleanupObject> objects) {
837 size_t size = sizeof(ExprWithCleanups)
838 + objects.size() * sizeof(CleanupObject);
839 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
840 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnerd2598362010-05-10 00:25:06 +0000841}
842
John McCall80ee6e82011-11-10 05:35:25 +0000843ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
844 : Expr(ExprWithCleanupsClass, empty) {
845 ExprWithCleanupsBits.NumObjects = numObjects;
846}
Chris Lattnerd2598362010-05-10 00:25:06 +0000847
John McCall80ee6e82011-11-10 05:35:25 +0000848ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
849 unsigned numObjects) {
850 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
851 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
852 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson88eaf072009-05-30 22:38:53 +0000853}
854
Douglas Gregorab6677e2010-09-08 00:15:04 +0000855CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000856 SourceLocation LParenLoc,
857 Expr **Args,
858 unsigned NumArgs,
859 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000860 : Expr(CXXUnresolvedConstructExprClass,
861 Type->getType().getNonReferenceType(),
Douglas Gregor032c8692011-07-08 15:50:43 +0000862 (Type->getType()->isLValueReferenceType() ? VK_LValue
863 :Type->getType()->isRValueReferenceType()? VK_XValue
864 :VK_RValue),
865 OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +0000866 Type->getType()->isDependentType(), true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000867 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +0000868 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000869 LParenLoc(LParenLoc),
870 RParenLoc(RParenLoc),
871 NumArgs(NumArgs) {
872 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000873 for (unsigned I = 0; I != NumArgs; ++I) {
874 if (Args[I]->containsUnexpandedParameterPack())
875 ExprBits.ContainsUnexpandedParameterPack = true;
876
877 StoredArgs[I] = Args[I];
878 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000879}
880
881CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +0000882CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000883 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000884 SourceLocation LParenLoc,
885 Expr **Args,
886 unsigned NumArgs,
887 SourceLocation RParenLoc) {
888 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
889 sizeof(Expr *) * NumArgs);
Douglas Gregorab6677e2010-09-08 00:15:04 +0000890 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000891 Args, NumArgs, RParenLoc);
892}
893
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000894CXXUnresolvedConstructExpr *
895CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
896 Stmt::EmptyShell Empty;
897 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
898 sizeof(Expr *) * NumArgs);
899 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
900}
901
Douglas Gregorab6677e2010-09-08 00:15:04 +0000902SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
903 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
904}
905
John McCall865d4472009-11-19 22:55:06 +0000906CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000907 Expr *Base, QualType BaseType,
908 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000909 SourceLocation OperatorLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000910 NestedNameSpecifierLoc QualifierLoc,
911 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000912 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000913 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000914 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +0000915 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +0000916 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000917 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000918 (QualifierLoc &&
919 QualifierLoc.getNestedNameSpecifier()
920 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000921 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +0000922 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000923 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000924 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000925 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +0000926 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000927 if (TemplateArgs) {
928 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000929 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000930 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000931 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
932 Dependent,
933 InstantiationDependent,
934 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000935 if (ContainsUnexpandedParameterPack)
936 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000937 } else if (TemplateKWLoc.isValid()) {
938 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000939 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000940}
941
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000942CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
943 Expr *Base, QualType BaseType,
944 bool IsArrow,
945 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000946 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000947 NamedDecl *FirstQualifierFoundInScope,
948 DeclarationNameInfo MemberNameInfo)
949 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +0000950 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000951 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000952 (QualifierLoc &&
953 QualifierLoc.getNestedNameSpecifier()->
954 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000955 MemberNameInfo.containsUnexpandedParameterPack())),
956 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000957 HasTemplateKWAndArgsInfo(false),
958 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000959 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
960 MemberNameInfo(MemberNameInfo) { }
961
John McCall865d4472009-11-19 22:55:06 +0000962CXXDependentScopeMemberExpr *
963CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000964 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000965 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000966 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000967 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000968 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000969 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000970 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000971 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCallaa81e162009-12-01 22:10:20 +0000972 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
973 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000974 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000975 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000976 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000977
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000978 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
979 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
980 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCalld5532b62009-11-23 01:53:49 +0000981
Chris Lattner32488542010-10-30 05:14:06 +0000982 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +0000983 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
984 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000985 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000986 TemplateKWLoc,
John McCallaa81e162009-12-01 22:10:20 +0000987 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000988 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000989}
990
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000991CXXDependentScopeMemberExpr *
992CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000993 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000994 unsigned NumTemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000995 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000996 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000997 0, SourceLocation(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000998 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000999 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001000
1001 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001002 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +00001003 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001004 CXXDependentScopeMemberExpr *E
1005 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001006 0, SourceLocation(),
1007 NestedNameSpecifierLoc(),
1008 SourceLocation(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001009 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001010 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001011 return E;
1012}
1013
Douglas Gregor4c9be892011-02-28 20:01:57 +00001014bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
1015 if (Base == 0)
1016 return true;
1017
Douglas Gregor75e85042011-03-02 21:06:53 +00001018 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001019}
1020
John McCall864c0412011-04-26 20:42:42 +00001021static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1022 UnresolvedSetIterator end) {
1023 do {
1024 NamedDecl *decl = *begin;
1025 if (isa<UnresolvedUsingValueDecl>(decl))
1026 return false;
1027 if (isa<UsingShadowDecl>(decl))
1028 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
1029
1030 // Unresolved member expressions should only contain methods and
1031 // method templates.
1032 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
1033
1034 if (isa<FunctionTemplateDecl>(decl))
1035 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
1036 if (cast<CXXMethodDecl>(decl)->isStatic())
1037 return false;
1038 } while (++begin != end);
1039
1040 return true;
1041}
1042
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001043UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001044 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001045 Expr *Base, QualType BaseType,
1046 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001047 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001048 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001049 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001050 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001051 const TemplateArgumentListInfo *TemplateArgs,
1052 UnresolvedSetIterator Begin,
1053 UnresolvedSetIterator End)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001054 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1055 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001056 // Dependent
1057 ((Base && Base->isTypeDependent()) ||
1058 BaseType->isDependentType()),
Douglas Gregor561f8122011-07-01 01:22:09 +00001059 ((Base && Base->isInstantiationDependent()) ||
1060 BaseType->isInstantiationDependentType()),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001061 // Contains unexpanded parameter pack
1062 ((Base && Base->containsUnexpandedParameterPack()) ||
1063 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +00001064 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1065 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall864c0412011-04-26 20:42:42 +00001066
1067 // Check whether all of the members are non-static member functions,
1068 // and if so, mark give this bound-member type instead of overload type.
1069 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1070 setType(C.BoundMemberTy);
John McCall129e2df2009-11-30 22:42:35 +00001071}
1072
Douglas Gregor4c9be892011-02-28 20:01:57 +00001073bool UnresolvedMemberExpr::isImplicitAccess() const {
1074 if (Base == 0)
1075 return true;
1076
Douglas Gregor75e85042011-03-02 21:06:53 +00001077 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001078}
1079
John McCall129e2df2009-11-30 22:42:35 +00001080UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001081UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001082 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001083 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001084 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001085 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001086 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001087 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001088 const TemplateArgumentListInfo *TemplateArgs,
1089 UnresolvedSetIterator Begin,
1090 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +00001091 std::size_t size = sizeof(UnresolvedMemberExpr);
1092 if (TemplateArgs)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001093 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
1094 else if (TemplateKWLoc.isValid())
1095 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall129e2df2009-11-30 22:42:35 +00001096
Chris Lattner32488542010-10-30 05:14:06 +00001097 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +00001098 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001099 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001100 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001101 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +00001102}
1103
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001104UnresolvedMemberExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001105UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001106 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001107 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001108 if (HasTemplateKWAndArgsInfo)
1109 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001110
Chris Lattner32488542010-10-30 05:14:06 +00001111 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001112 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001113 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001114 return E;
1115}
1116
John McCallc373d482010-01-27 01:50:18 +00001117CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1118 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1119
1120 // If there was a nested name specifier, it names the naming class.
1121 // It can't be dependent: after all, we were actually able to do the
1122 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001123 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +00001124 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +00001125 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +00001126 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001127 Record = T->getAsCXXRecordDecl();
1128 assert(Record && "qualifier in member expression does not name record");
1129 }
John McCallc373d482010-01-27 01:50:18 +00001130 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001131 else {
John McCallc373d482010-01-27 01:50:18 +00001132 QualType BaseType = getBaseType().getNonReferenceType();
1133 if (isArrow()) {
1134 const PointerType *PT = BaseType->getAs<PointerType>();
1135 assert(PT && "base of arrow member access is not pointer");
1136 BaseType = PT->getPointeeType();
1137 }
1138
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001139 Record = BaseType->getAsCXXRecordDecl();
1140 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +00001141 }
1142
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001143 return Record;
John McCallc373d482010-01-27 01:50:18 +00001144}
1145
Douglas Gregorc7793c72011-01-15 01:15:58 +00001146SubstNonTypeTemplateParmPackExpr::
1147SubstNonTypeTemplateParmPackExpr(QualType T,
1148 NonTypeTemplateParmDecl *Param,
1149 SourceLocation NameLoc,
1150 const TemplateArgument &ArgPack)
1151 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001152 true, true, true, true),
Douglas Gregorc7793c72011-01-15 01:15:58 +00001153 Param(Param), Arguments(ArgPack.pack_begin()),
1154 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1155
1156TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1157 return TemplateArgument(Arguments, NumArguments);
1158}
1159
David Blaikie99ba9e32011-12-20 02:48:34 +00001160void ArrayTypeTraitExpr::anchor() { }