blob: af8498daa7bd212ec64a7cdac360ec22a3119707 [file] [log] [blame]
Ted Kremeneke3a0c142007-08-24 20:21:10 +00001//===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-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 Kremeneke3a0c142007-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 Gregor993603d2008-11-14 16:09:21 +000014#include "clang/Basic/IdentifierTable.h"
15#include "clang/AST/DeclCXX.h"
Douglas Gregora727cb92009-06-30 22:34:41 +000016#include "clang/AST/DeclTemplate.h"
Ted Kremeneke3a0c142007-08-24 20:21:10 +000017#include "clang/AST/ExprCXX.h"
Douglas Gregor651fe5e2010-02-24 23:40:28 +000018#include "clang/AST/TypeLoc.h"
Ted Kremeneke3a0c142007-08-24 20:21:10 +000019using namespace clang;
20
Douglas Gregor9da64192010-04-26 22:37:10 +000021
Ted Kremeneke3a0c142007-08-24 20:21:10 +000022//===----------------------------------------------------------------------===//
23// Child Iterators for iterating over subexpressions/substatements
24//===----------------------------------------------------------------------===//
25
Douglas Gregor9da64192010-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 Pichet9f4f2072010-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 Gregor747eb782010-07-08 06:14:04 +000038// CXXScalarValueInitExpr
Douglas Gregor2b88c112010-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 Redlbd150f42008-11-21 19:14:01 +000046// CXXNewExpr
Ted Kremenek9d6eb402010-02-11 22:51:03 +000047CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Sebastian Redlbd150f42008-11-21 19:14:01 +000048 Expr **placementArgs, unsigned numPlaceArgs,
Douglas Gregorf2753b32010-07-13 15:54:32 +000049 SourceRange TypeIdParens, Expr *arraySize,
Sebastian Redlbd150f42008-11-21 19:14:01 +000050 CXXConstructorDecl *constructor, bool initializer,
51 Expr **constructorArgs, unsigned numConsArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000052 bool HadMultipleCandidates,
John McCall284c48f2011-01-27 09:37:56 +000053 FunctionDecl *operatorDelete,
54 bool usualArrayDeleteWantsSize, QualType ty,
Douglas Gregor0744ef62010-09-07 21:49:58 +000055 TypeSourceInfo *AllocatedTypeInfo,
Chandler Carruth01718152010-10-25 08:47:36 +000056 SourceLocation startLoc, SourceLocation endLoc,
57 SourceLocation constructorLParen,
58 SourceLocation constructorRParen)
John McCall7decc9e2010-11-18 06:31:45 +000059 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
Douglas Gregora6e053e2010-12-15 01:34:56 +000060 ty->isDependentType(), ty->isDependentType(),
Douglas Gregor678d76c2011-07-01 01:22:09 +000061 ty->isInstantiationDependentType(),
Douglas Gregora6e053e2010-12-15 01:34:56 +000062 ty->containsUnexpandedParameterPack()),
John McCall284c48f2011-01-27 09:37:56 +000063 GlobalNew(globalNew), Initializer(initializer),
64 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000065 HadMultipleCandidates(HadMultipleCandidates),
John McCall284c48f2011-01-27 09:37:56 +000066 SubExprs(0), OperatorNew(operatorNew),
Sebastian Redl351bb782008-12-02 14:43:59 +000067 OperatorDelete(operatorDelete), Constructor(constructor),
Douglas Gregor0744ef62010-09-07 21:49:58 +000068 AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens),
Chandler Carruth01718152010-10-25 08:47:36 +000069 StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen),
70 ConstructorRParen(constructorRParen) {
Chris Lattnerabfb58d2010-05-10 01:22:27 +000071 AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs);
Sebastian Redlbd150f42008-11-21 19:14:01 +000072 unsigned i = 0;
Douglas Gregora6e053e2010-12-15 01:34:56 +000073 if (Array) {
Douglas Gregor678d76c2011-07-01 01:22:09 +000074 if (arraySize->isInstantiationDependent())
75 ExprBits.InstantiationDependent = true;
76
Douglas Gregora6e053e2010-12-15 01:34:56 +000077 if (arraySize->containsUnexpandedParameterPack())
78 ExprBits.ContainsUnexpandedParameterPack = true;
79
Sebastian Redl351bb782008-12-02 14:43:59 +000080 SubExprs[i++] = arraySize;
Douglas Gregora6e053e2010-12-15 01:34:56 +000081 }
82
83 for (unsigned j = 0; j < NumPlacementArgs; ++j) {
Douglas Gregor678d76c2011-07-01 01:22:09 +000084 if (placementArgs[j]->isInstantiationDependent())
85 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +000086 if (placementArgs[j]->containsUnexpandedParameterPack())
87 ExprBits.ContainsUnexpandedParameterPack = true;
88
Sebastian Redlbd150f42008-11-21 19:14:01 +000089 SubExprs[i++] = placementArgs[j];
Douglas Gregora6e053e2010-12-15 01:34:56 +000090 }
91
92 for (unsigned j = 0; j < NumConstructorArgs; ++j) {
Douglas Gregor678d76c2011-07-01 01:22:09 +000093 if (constructorArgs[j]->isInstantiationDependent())
94 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +000095 if (constructorArgs[j]->containsUnexpandedParameterPack())
96 ExprBits.ContainsUnexpandedParameterPack = true;
97
Sebastian Redlbd150f42008-11-21 19:14:01 +000098 SubExprs[i++] = constructorArgs[j];
Douglas Gregora6e053e2010-12-15 01:34:56 +000099 }
Sebastian Redlbd150f42008-11-21 19:14:01 +0000100}
101
Chris Lattnerabfb58d2010-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 Redl31ad7542011-03-13 17:09:40 +0000113bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCall75f94982011-03-07 03:12:35 +0000114 return getOperatorNew()->getType()->
Sebastian Redl31ad7542011-03-13 17:09:40 +0000115 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCall75f94982011-03-07 03:12:35 +0000116}
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000117
Sebastian Redlbd150f42008-11-21 19:14:01 +0000118// CXXDeleteExpr
Douglas Gregor6ed2fee2010-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 Silverstein20f7ab72010-10-20 00:38:15 +0000128 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silverstein3b9936f2010-10-20 00:56:01 +0000129 const QualType ArgType = Arg->getType();
Craig Silverstein9e448da2010-11-16 07:16:25 +0000130
131 if (ArgType->isDependentType() && !ArgType->isPointerType())
132 return QualType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000133
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000134 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000135}
136
Douglas Gregorad8a3362009-09-04 17:36:40 +0000137// CXXPseudoDestructorExpr
Douglas Gregor678f90d2010-02-25 01:56:36 +0000138PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
139 : Type(Info)
140{
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000141 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000142}
143
John McCalldb40c7f2010-12-14 08:05:40 +0000144CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregora6ce6082011-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 McCalldb40c7f2010-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 Gregora6e053e2010-12-15 01:34:56 +0000156 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor678d76c2011-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 Gregora6e053e2010-12-15 01:34:56 +0000165 // ContainsUnexpandedParameterPack
166 (Base->containsUnexpandedParameterPack() ||
Douglas Gregora6ce6082011-02-25 18:19:59 +0000167 (QualifierLoc &&
168 QualifierLoc.getNestedNameSpecifier()
169 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +0000170 (ScopeType &&
171 ScopeType->getType()->containsUnexpandedParameterPack()) ||
172 (DestroyedType.getTypeSourceInfo() &&
173 DestroyedType.getTypeSourceInfo()->getType()
174 ->containsUnexpandedParameterPack()))),
John McCalldb40c7f2010-12-14 08:05:40 +0000175 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregora6ce6082011-02-25 18:19:59 +0000176 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalldb40c7f2010-12-14 08:05:40 +0000177 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
178 DestroyedType(DestroyedType) { }
179
Douglas Gregor678f90d2010-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 Gregor651fe5e2010-02-24 23:40:28 +0000187SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregor678f90d2010-02-25 01:56:36 +0000188 SourceLocation End = DestroyedType.getLocation();
189 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000190 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000191 return SourceRange(Base->getLocStart(), End);
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000192}
193
194
John McCalld14a8642009-11-21 08:51:07 +0000195// UnresolvedLookupExpr
John McCalle66edc12009-11-24 19:00:30 +0000196UnresolvedLookupExpr *
Douglas Gregora6e053e2010-12-15 01:34:56 +0000197UnresolvedLookupExpr::Create(ASTContext &C,
John McCall58cc69d2010-01-27 01:50:18 +0000198 CXXRecordDecl *NamingClass,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000199 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000200 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000201 const DeclarationNameInfo &NameInfo,
202 bool ADL,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +0000203 const TemplateArgumentListInfo &Args,
204 UnresolvedSetIterator Begin,
205 UnresolvedSetIterator End)
John McCalle66edc12009-11-24 19:00:30 +0000206{
Abramo Bagnara7945c982012-01-27 09:46:47 +0000207 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
208 ASTTemplateKWAndArgsInfo::sizeFor(Args.size()));
209 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
210 TemplateKWLoc, NameInfo,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000211 ADL, /*Overload*/ true, &Args,
Richard Smith02e85f32011-04-14 22:09:26 +0000212 Begin, End, /*StdIsAssociated=*/false);
John McCalle66edc12009-11-24 19:00:30 +0000213}
214
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000215UnresolvedLookupExpr *
Abramo Bagnara7945c982012-01-27 09:46:47 +0000216UnresolvedLookupExpr::CreateEmpty(ASTContext &C,
217 bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +0000218 unsigned NumTemplateArgs) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000219 std::size_t size = sizeof(UnresolvedLookupExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000220 if (HasTemplateKWAndArgsInfo)
221 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000222
Chris Lattner5c0b4052010-10-30 05:14:06 +0000223 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000224 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000225 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000226 return E;
227}
228
Douglas Gregora6e053e2010-12-15 01:34:56 +0000229OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000230 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000231 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000232 const DeclarationNameInfo &NameInfo,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000233 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregorc69978f2010-05-23 19:36:40 +0000234 UnresolvedSetIterator Begin,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000235 UnresolvedSetIterator End,
236 bool KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000237 bool KnownInstantiationDependent,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000238 bool KnownContainsUnexpandedParameterPack)
239 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
240 KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000241 (KnownInstantiationDependent ||
242 NameInfo.isInstantiationDependent() ||
243 (QualifierLoc &&
244 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000245 (KnownContainsUnexpandedParameterPack ||
246 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor0da1d432011-02-28 20:01:57 +0000247 (QualifierLoc &&
248 QualifierLoc.getNestedNameSpecifier()
249 ->containsUnexpandedParameterPack()))),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000250 Results(0), NumResults(End - Begin), NameInfo(NameInfo),
251 QualifierLoc(QualifierLoc),
252 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid())
Douglas Gregorc69978f2010-05-23 19:36:40 +0000253{
Douglas Gregora6e053e2010-12-15 01:34:56 +0000254 NumResults = End - Begin;
255 if (NumResults) {
256 // Determine whether this expression is type-dependent.
257 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
258 if ((*I)->getDeclContext()->isDependentContext() ||
259 isa<UnresolvedUsingValueDecl>(*I)) {
260 ExprBits.TypeDependent = true;
261 ExprBits.ValueDependent = true;
262 }
263 }
264
265 Results = static_cast<DeclAccessPair *>(
266 C.Allocate(sizeof(DeclAccessPair) * NumResults,
267 llvm::alignOf<DeclAccessPair>()));
268 memcpy(Results, &*Begin.getIterator(),
269 NumResults * sizeof(DeclAccessPair));
270 }
271
272 // If we have explicit template arguments, check for dependent
273 // template arguments and whether they contain any unexpanded pack
274 // expansions.
275 if (TemplateArgs) {
276 bool Dependent = false;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000277 bool InstantiationDependent = false;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000278 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000279 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
280 Dependent,
281 InstantiationDependent,
282 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000283
284 if (Dependent) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000285 ExprBits.TypeDependent = true;
286 ExprBits.ValueDependent = true;
287 }
288 if (InstantiationDependent)
289 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000290 if (ContainsUnexpandedParameterPack)
291 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000292 } else if (TemplateKWLoc.isValid()) {
293 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000294 }
295
296 if (isTypeDependent())
297 setType(C.DependentTy);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000298}
299
300void OverloadExpr::initializeResults(ASTContext &C,
301 UnresolvedSetIterator Begin,
302 UnresolvedSetIterator End) {
303 assert(Results == 0 && "Results already initialized!");
304 NumResults = End - Begin;
Douglas Gregorc69978f2010-05-23 19:36:40 +0000305 if (NumResults) {
Douglas Gregora6e053e2010-12-15 01:34:56 +0000306 Results = static_cast<DeclAccessPair *>(
307 C.Allocate(sizeof(DeclAccessPair) * NumResults,
308
309 llvm::alignOf<DeclAccessPair>()));
310 memcpy(Results, &*Begin.getIterator(),
311 NumResults * sizeof(DeclAccessPair));
Douglas Gregorc69978f2010-05-23 19:36:40 +0000312 }
313}
314
John McCall8c12dc42010-04-22 18:44:12 +0000315CXXRecordDecl *OverloadExpr::getNamingClass() const {
316 if (isa<UnresolvedLookupExpr>(this))
317 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
318 else
319 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
320}
321
John McCall8cd78132009-11-19 22:55:06 +0000322// DependentScopeDeclRefExpr
Douglas Gregora6e053e2010-12-15 01:34:56 +0000323DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000324 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000325 SourceLocation TemplateKWLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000326 const DeclarationNameInfo &NameInfo,
327 const TemplateArgumentListInfo *Args)
328 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
329 true, true,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000330 (NameInfo.isInstantiationDependent() ||
331 (QualifierLoc &&
332 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000333 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000334 (QualifierLoc &&
335 QualifierLoc.getNestedNameSpecifier()
336 ->containsUnexpandedParameterPack()))),
337 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000338 HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid())
Douglas Gregora6e053e2010-12-15 01:34:56 +0000339{
340 if (Args) {
341 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000342 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000343 bool ContainsUnexpandedParameterPack
344 = ExprBits.ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000345 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args,
346 Dependent,
347 InstantiationDependent,
348 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000349 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000350 } else if (TemplateKWLoc.isValid()) {
351 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000352 }
353}
354
John McCalle66edc12009-11-24 19:00:30 +0000355DependentScopeDeclRefExpr *
356DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000357 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000358 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000359 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +0000360 const TemplateArgumentListInfo *Args) {
361 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCalle66edc12009-11-24 19:00:30 +0000362 if (Args)
Abramo Bagnara7945c982012-01-27 09:46:47 +0000363 size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size());
364 else if (TemplateKWLoc.isValid())
365 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000366 void *Mem = C.Allocate(size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000367 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
368 TemplateKWLoc, NameInfo, Args);
John McCalle66edc12009-11-24 19:00:30 +0000369}
370
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000371DependentScopeDeclRefExpr *
372DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000373 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000374 unsigned NumTemplateArgs) {
375 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000376 if (HasTemplateKWAndArgsInfo)
377 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000378 void *Mem = C.Allocate(size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000379 DependentScopeDeclRefExpr *E
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000380 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000381 SourceLocation(),
Douglas Gregor87866ce2011-02-04 12:01:24 +0000382 DeclarationNameInfo(), 0);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000383 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregor87866ce2011-02-04 12:01:24 +0000384 return E;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000385}
386
Chandler Carruth01718152010-10-25 08:47:36 +0000387SourceRange CXXConstructExpr::getSourceRange() const {
John McCall701417a2011-02-21 06:23:05 +0000388 if (isa<CXXTemporaryObjectExpr>(this))
389 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
390
Douglas Gregor15417cf2010-11-03 00:35:38 +0000391 if (ParenRange.isValid())
392 return SourceRange(Loc, ParenRange.getEnd());
393
394 SourceLocation End = Loc;
395 for (unsigned I = getNumArgs(); I > 0; --I) {
396 const Expr *Arg = getArg(I-1);
397 if (!Arg->isDefaultArgument()) {
398 SourceLocation NewEnd = Arg->getLocEnd();
399 if (NewEnd.isValid()) {
400 End = NewEnd;
401 break;
402 }
403 }
404 }
405
406 return SourceRange(Loc, End);
Ted Kremenek49ace5c2009-12-23 04:00:48 +0000407}
408
Douglas Gregor993603d2008-11-14 16:09:21 +0000409SourceRange CXXOperatorCallExpr::getSourceRange() const {
410 OverloadedOperatorKind Kind = getOperator();
411 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
412 if (getNumArgs() == 1)
413 // Prefix operator
Mike Stump11289f42009-09-09 15:08:12 +0000414 return SourceRange(getOperatorLoc(),
Douglas Gregor993603d2008-11-14 16:09:21 +0000415 getArg(0)->getSourceRange().getEnd());
416 else
417 // Postfix operator
Chandler Carruthf20ec9232011-04-02 09:47:38 +0000418 return SourceRange(getArg(0)->getSourceRange().getBegin(),
Douglas Gregor993603d2008-11-14 16:09:21 +0000419 getOperatorLoc());
Chandler Carruthf20ec9232011-04-02 09:47:38 +0000420 } else if (Kind == OO_Arrow) {
421 return getArg(0)->getSourceRange();
Douglas Gregor993603d2008-11-14 16:09:21 +0000422 } else if (Kind == OO_Call) {
423 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
424 } else if (Kind == OO_Subscript) {
425 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
426 } else if (getNumArgs() == 1) {
427 return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd());
428 } else if (getNumArgs() == 2) {
429 return SourceRange(getArg(0)->getSourceRange().getBegin(),
430 getArg(1)->getSourceRange().getEnd());
431 } else {
432 return SourceRange();
433 }
434}
435
Ted Kremenek98a24e32011-03-30 17:41:19 +0000436Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
437 if (const MemberExpr *MemExpr =
438 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000439 return MemExpr->getBase();
440
441 // FIXME: Will eventually need to cope with member pointers.
442 return 0;
443}
444
Ted Kremenek98a24e32011-03-30 17:41:19 +0000445CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
446 if (const MemberExpr *MemExpr =
447 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
448 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
449
450 // FIXME: Will eventually need to cope with member pointers.
451 return 0;
452}
453
454
Chandler Carruth00426b42010-10-27 06:55:41 +0000455CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
456 Expr* ThisArg = getImplicitObjectArgument();
457 if (!ThisArg)
458 return 0;
459
460 if (ThisArg->getType()->isAnyPointerType())
461 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
462
463 return ThisArg->getType()->getAsCXXRecordDecl();
464}
465
Douglas Gregoref986e82009-11-12 15:31:47 +0000466
Douglas Gregore200adc2008-10-27 19:41:14 +0000467//===----------------------------------------------------------------------===//
468// Named casts
469//===----------------------------------------------------------------------===//
470
471/// getCastName - Get the name of the C++ cast being used, e.g.,
472/// "static_cast", "dynamic_cast", "reinterpret_cast", or
473/// "const_cast". The returned pointer must not be freed.
474const char *CXXNamedCastExpr::getCastName() const {
475 switch (getStmtClass()) {
476 case CXXStaticCastExprClass: return "static_cast";
477 case CXXDynamicCastExprClass: return "dynamic_cast";
478 case CXXReinterpretCastExprClass: return "reinterpret_cast";
479 case CXXConstCastExprClass: return "const_cast";
480 default: return "<invalid cast>";
481 }
482}
Douglas Gregordd04d332009-01-16 18:33:17 +0000483
John McCallcf142162010-08-07 06:22:56 +0000484CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000485 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000486 CastKind K, Expr *Op,
487 const CXXCastPath *BasePath,
488 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000489 SourceLocation L,
490 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000491 unsigned PathSize = (BasePath ? BasePath->size() : 0);
492 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
493 + PathSize * sizeof(CXXBaseSpecifier*));
494 CXXStaticCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000495 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
496 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000497 if (PathSize) E->setCastPath(*BasePath);
498 return E;
499}
500
501CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
502 unsigned PathSize) {
503 void *Buffer =
504 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
505 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
506}
507
508CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000509 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000510 CastKind K, Expr *Op,
511 const CXXCastPath *BasePath,
512 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000513 SourceLocation L,
514 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000515 unsigned PathSize = (BasePath ? BasePath->size() : 0);
516 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
517 + PathSize * sizeof(CXXBaseSpecifier*));
518 CXXDynamicCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000519 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
520 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000521 if (PathSize) E->setCastPath(*BasePath);
522 return E;
523}
524
525CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
526 unsigned PathSize) {
527 void *Buffer =
528 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
529 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
530}
531
Anders Carlsson267c0c92011-04-11 01:43:55 +0000532/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
533/// to always be null. For example:
534///
535/// struct A { };
536/// struct B final : A { };
537/// struct C { };
538///
539/// C *f(B* b) { return dynamic_cast<C*>(b); }
540bool CXXDynamicCastExpr::isAlwaysNull() const
541{
542 QualType SrcType = getSubExpr()->getType();
543 QualType DestType = getType();
544
545 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
546 SrcType = SrcPTy->getPointeeType();
547 DestType = DestType->castAs<PointerType>()->getPointeeType();
548 }
549
550 const CXXRecordDecl *SrcRD =
551 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
552
553 if (!SrcRD->hasAttr<FinalAttr>())
554 return false;
555
556 const CXXRecordDecl *DestRD =
557 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
558
559 return !DestRD->isDerivedFrom(SrcRD);
560}
561
John McCallcf142162010-08-07 06:22:56 +0000562CXXReinterpretCastExpr *
John McCall7decc9e2010-11-18 06:31:45 +0000563CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
564 CastKind K, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000565 const CXXCastPath *BasePath,
Douglas Gregor4478f852011-01-12 22:41:29 +0000566 TypeSourceInfo *WrittenTy, SourceLocation L,
567 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000568 unsigned PathSize = (BasePath ? BasePath->size() : 0);
569 void *Buffer =
570 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
571 CXXReinterpretCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000572 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
573 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000574 if (PathSize) E->setCastPath(*BasePath);
575 return E;
576}
577
578CXXReinterpretCastExpr *
579CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
580 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
581 + PathSize * sizeof(CXXBaseSpecifier*));
582 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
583}
584
John McCall7decc9e2010-11-18 06:31:45 +0000585CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
586 ExprValueKind VK, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000587 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000588 SourceLocation L,
589 SourceLocation RParenLoc) {
590 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000591}
592
593CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
594 return new (C) CXXConstCastExpr(EmptyShell());
595}
596
597CXXFunctionalCastExpr *
John McCall7decc9e2010-11-18 06:31:45 +0000598CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000599 TypeSourceInfo *Written, SourceLocation L,
600 CastKind K, Expr *Op, const CXXCastPath *BasePath,
601 SourceLocation R) {
602 unsigned PathSize = (BasePath ? BasePath->size() : 0);
603 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
604 + PathSize * sizeof(CXXBaseSpecifier*));
605 CXXFunctionalCastExpr *E =
John McCall7decc9e2010-11-18 06:31:45 +0000606 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallcf142162010-08-07 06:22:56 +0000607 if (PathSize) E->setCastPath(*BasePath);
608 return E;
609}
610
611CXXFunctionalCastExpr *
612CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
613 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
614 + PathSize * sizeof(CXXBaseSpecifier*));
615 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
616}
617
618
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000619CXXDefaultArgExpr *
Douglas Gregor033f6752009-12-23 23:03:06 +0000620CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
621 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000622 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor033f6752009-12-23 23:03:06 +0000623 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
624 SubExpr);
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000625}
626
Mike Stump11289f42009-09-09 15:08:12 +0000627CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonffda6062009-05-30 20:34:37 +0000628 const CXXDestructorDecl *Destructor) {
Anders Carlsson73b836b2009-05-30 22:38:53 +0000629 return new (C) CXXTemporary(Destructor);
630}
631
Mike Stump11289f42009-09-09 15:08:12 +0000632CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlsson993a4b32009-05-30 20:03:25 +0000633 CXXTemporary *Temp,
634 Expr* SubExpr) {
Peter Collingbournefbef4c82011-11-27 22:09:28 +0000635 assert((SubExpr->getType()->isRecordType() ||
636 SubExpr->getType()->isArrayType()) &&
637 "Expression bound to a temporary must have record or array type!");
Anders Carlsson993a4b32009-05-30 20:03:25 +0000638
Douglas Gregora6e053e2010-12-15 01:34:56 +0000639 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlsson993a4b32009-05-30 20:03:25 +0000640}
641
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000642CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson56c5bd82009-04-24 05:23:13 +0000643 CXXConstructorDecl *Cons,
Douglas Gregor2b88c112010-09-08 00:15:04 +0000644 TypeSourceInfo *Type,
Douglas Gregordd04d332009-01-16 18:33:17 +0000645 Expr **Args,
Mike Stump11289f42009-09-09 15:08:12 +0000646 unsigned NumArgs,
Chandler Carruth01718152010-10-25 08:47:36 +0000647 SourceRange parenRange,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000648 bool HadMultipleCandidates,
Douglas Gregor199db362010-04-27 20:36:09 +0000649 bool ZeroInitialization)
Douglas Gregor2b88c112010-09-08 00:15:04 +0000650 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
651 Type->getType().getNonReferenceType(),
652 Type->getTypeLoc().getBeginLoc(),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000653 Cons, false, Args, NumArgs,
654 HadMultipleCandidates, ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000655 CXXConstructExpr::CK_Complete, parenRange),
656 Type(Type) {
Douglas Gregor2b88c112010-09-08 00:15:04 +0000657}
658
659SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth01718152010-10-25 08:47:36 +0000660 return SourceRange(Type->getTypeLoc().getBeginLoc(),
661 getParenRange().getEnd());
Douglas Gregordd04d332009-01-16 18:33:17 +0000662}
Anders Carlsson6f287832009-04-21 02:22:11 +0000663
Mike Stump11289f42009-09-09 15:08:12 +0000664CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000665 SourceLocation Loc,
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000666 CXXConstructorDecl *D, bool Elidable,
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000667 Expr **Args, unsigned NumArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000668 bool HadMultipleCandidates,
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000669 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000670 ConstructionKind ConstructKind,
671 SourceRange ParenRange) {
Douglas Gregor85dabae2009-12-16 01:38:02 +0000672 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000673 Elidable, Args, NumArgs,
674 HadMultipleCandidates, ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000675 ConstructKind, ParenRange);
Anders Carlsson0781ce72009-04-23 02:32:43 +0000676}
677
Mike Stump11289f42009-09-09 15:08:12 +0000678CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000679 SourceLocation Loc,
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000680 CXXConstructorDecl *D, bool elidable,
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000681 Expr **args, unsigned numargs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000682 bool HadMultipleCandidates,
683 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000684 ConstructionKind ConstructKind,
685 SourceRange ParenRange)
Douglas Gregora6e053e2010-12-15 01:34:56 +0000686 : Expr(SC, T, VK_RValue, OK_Ordinary,
687 T->isDependentType(), T->isDependentType(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000688 T->isInstantiationDependentType(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000689 T->containsUnexpandedParameterPack()),
Douglas Gregor488c2312011-09-26 14:47:03 +0000690 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(numargs),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000691 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
692 ZeroInitialization(ZeroInitialization),
Douglas Gregor488c2312011-09-26 14:47:03 +0000693 ConstructKind(ConstructKind), Args(0)
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000694{
695 if (NumArgs) {
696 Args = new (C) Stmt*[NumArgs];
697
698 for (unsigned i = 0; i != NumArgs; ++i) {
699 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregora6e053e2010-12-15 01:34:56 +0000700
701 if (args[i]->isValueDependent())
702 ExprBits.ValueDependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000703 if (args[i]->isInstantiationDependent())
704 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000705 if (args[i]->containsUnexpandedParameterPack())
706 ExprBits.ContainsUnexpandedParameterPack = true;
707
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000708 Args[i] = args[i];
Anders Carlsson0781ce72009-04-23 02:32:43 +0000709 }
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000710 }
Anders Carlsson0781ce72009-04-23 02:32:43 +0000711}
712
John McCall28fc7092011-11-10 05:35:25 +0000713ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
714 ArrayRef<CleanupObject> objects)
John McCall5d413782010-12-06 08:20:24 +0000715 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCall7decc9e2010-11-18 06:31:45 +0000716 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000717 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000718 subexpr->isInstantiationDependent(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000719 subexpr->containsUnexpandedParameterPack()),
John McCall28fc7092011-11-10 05:35:25 +0000720 SubExpr(subexpr) {
721 ExprWithCleanupsBits.NumObjects = objects.size();
722 for (unsigned i = 0, e = objects.size(); i != e; ++i)
723 getObjectsBuffer()[i] = objects[i];
Anders Carlssondefc6442009-04-24 22:47:04 +0000724}
725
John McCall28fc7092011-11-10 05:35:25 +0000726ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
727 ArrayRef<CleanupObject> objects) {
728 size_t size = sizeof(ExprWithCleanups)
729 + objects.size() * sizeof(CleanupObject);
730 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
731 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnercba86142010-05-10 00:25:06 +0000732}
733
John McCall28fc7092011-11-10 05:35:25 +0000734ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
735 : Expr(ExprWithCleanupsClass, empty) {
736 ExprWithCleanupsBits.NumObjects = numObjects;
737}
Chris Lattnercba86142010-05-10 00:25:06 +0000738
John McCall28fc7092011-11-10 05:35:25 +0000739ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
740 unsigned numObjects) {
741 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
742 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
743 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson73b836b2009-05-30 22:38:53 +0000744}
745
Douglas Gregor2b88c112010-09-08 00:15:04 +0000746CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +0000747 SourceLocation LParenLoc,
748 Expr **Args,
749 unsigned NumArgs,
750 SourceLocation RParenLoc)
Douglas Gregor2b88c112010-09-08 00:15:04 +0000751 : Expr(CXXUnresolvedConstructExprClass,
752 Type->getType().getNonReferenceType(),
Douglas Gregor6336f292011-07-08 15:50:43 +0000753 (Type->getType()->isLValueReferenceType() ? VK_LValue
754 :Type->getType()->isRValueReferenceType()? VK_XValue
755 :VK_RValue),
756 OK_Ordinary,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000757 Type->getType()->isDependentType(), true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000758 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregor2b88c112010-09-08 00:15:04 +0000759 Type(Type),
Douglas Gregorce934142009-05-20 18:46:25 +0000760 LParenLoc(LParenLoc),
761 RParenLoc(RParenLoc),
762 NumArgs(NumArgs) {
763 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000764 for (unsigned I = 0; I != NumArgs; ++I) {
765 if (Args[I]->containsUnexpandedParameterPack())
766 ExprBits.ContainsUnexpandedParameterPack = true;
767
768 StoredArgs[I] = Args[I];
769 }
Douglas Gregorce934142009-05-20 18:46:25 +0000770}
771
772CXXUnresolvedConstructExpr *
Mike Stump11289f42009-09-09 15:08:12 +0000773CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregor2b88c112010-09-08 00:15:04 +0000774 TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +0000775 SourceLocation LParenLoc,
776 Expr **Args,
777 unsigned NumArgs,
778 SourceLocation RParenLoc) {
779 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
780 sizeof(Expr *) * NumArgs);
Douglas Gregor2b88c112010-09-08 00:15:04 +0000781 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc,
Douglas Gregorce934142009-05-20 18:46:25 +0000782 Args, NumArgs, RParenLoc);
783}
784
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +0000785CXXUnresolvedConstructExpr *
786CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
787 Stmt::EmptyShell Empty;
788 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
789 sizeof(Expr *) * NumArgs);
790 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
791}
792
Douglas Gregor2b88c112010-09-08 00:15:04 +0000793SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
794 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
795}
796
John McCall8cd78132009-11-19 22:55:06 +0000797CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +0000798 Expr *Base, QualType BaseType,
799 bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +0000800 SourceLocation OperatorLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000801 NestedNameSpecifierLoc QualifierLoc,
802 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +0000803 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000804 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +0000805 const TemplateArgumentListInfo *TemplateArgs)
John McCall7decc9e2010-11-18 06:31:45 +0000806 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000807 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000808 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregore16af532011-02-28 18:50:33 +0000809 (QualifierLoc &&
810 QualifierLoc.getNestedNameSpecifier()
811 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +0000812 MemberNameInfo.containsUnexpandedParameterPack())),
John McCall2d74de92009-12-01 22:10:20 +0000813 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000814 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregore16af532011-02-28 18:50:33 +0000815 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor308047d2009-09-09 00:23:06 +0000816 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000817 MemberNameInfo(MemberNameInfo) {
Douglas Gregora6e053e2010-12-15 01:34:56 +0000818 if (TemplateArgs) {
819 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000820 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000821 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000822 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
823 Dependent,
824 InstantiationDependent,
825 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000826 if (ContainsUnexpandedParameterPack)
827 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000828 } else if (TemplateKWLoc.isValid()) {
829 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000830 }
Douglas Gregor308047d2009-09-09 00:23:06 +0000831}
832
Douglas Gregora6e053e2010-12-15 01:34:56 +0000833CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
834 Expr *Base, QualType BaseType,
835 bool IsArrow,
836 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +0000837 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000838 NamedDecl *FirstQualifierFoundInScope,
839 DeclarationNameInfo MemberNameInfo)
840 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000841 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000842 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregore16af532011-02-28 18:50:33 +0000843 (QualifierLoc &&
844 QualifierLoc.getNestedNameSpecifier()->
845 containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +0000846 MemberNameInfo.containsUnexpandedParameterPack())),
847 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000848 HasTemplateKWAndArgsInfo(false),
849 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000850 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
851 MemberNameInfo(MemberNameInfo) { }
852
John McCall8cd78132009-11-19 22:55:06 +0000853CXXDependentScopeMemberExpr *
854CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +0000855 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +0000856 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +0000857 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000858 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +0000859 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000860 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +0000861 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +0000862 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCall2d74de92009-12-01 22:10:20 +0000863 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
864 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +0000865 QualifierLoc,
John McCall2d74de92009-12-01 22:10:20 +0000866 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000867 MemberNameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000868
Abramo Bagnara7945c982012-01-27 09:46:47 +0000869 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
870 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
871 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCall6b51f282009-11-23 01:53:49 +0000872
Chris Lattner5c0b4052010-10-30 05:14:06 +0000873 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCall2d74de92009-12-01 22:10:20 +0000874 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
875 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +0000876 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000877 TemplateKWLoc,
John McCall2d74de92009-12-01 22:10:20 +0000878 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000879 MemberNameInfo, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +0000880}
881
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +0000882CXXDependentScopeMemberExpr *
883CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000884 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +0000885 unsigned NumTemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +0000886 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +0000887 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000888 0, SourceLocation(),
Douglas Gregore16af532011-02-28 18:50:33 +0000889 NestedNameSpecifierLoc(), 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000890 DeclarationNameInfo());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +0000891
892 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnara7945c982012-01-27 09:46:47 +0000893 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner5c0b4052010-10-30 05:14:06 +0000894 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +0000895 CXXDependentScopeMemberExpr *E
896 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000897 0, SourceLocation(),
898 NestedNameSpecifierLoc(),
899 SourceLocation(), 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000900 DeclarationNameInfo(), 0);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000901 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +0000902 return E;
903}
904
Douglas Gregor0da1d432011-02-28 20:01:57 +0000905bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
906 if (Base == 0)
907 return true;
908
Douglas Gregor25b7e052011-03-02 21:06:53 +0000909 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +0000910}
911
John McCall0009fcc2011-04-26 20:42:42 +0000912static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
913 UnresolvedSetIterator end) {
914 do {
915 NamedDecl *decl = *begin;
916 if (isa<UnresolvedUsingValueDecl>(decl))
917 return false;
918 if (isa<UsingShadowDecl>(decl))
919 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
920
921 // Unresolved member expressions should only contain methods and
922 // method templates.
923 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
924
925 if (isa<FunctionTemplateDecl>(decl))
926 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
927 if (cast<CXXMethodDecl>(decl)->isStatic())
928 return false;
929 } while (++begin != end);
930
931 return true;
932}
933
Douglas Gregora6e053e2010-12-15 01:34:56 +0000934UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +0000935 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +0000936 Expr *Base, QualType BaseType,
937 bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +0000938 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000939 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000940 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000941 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +0000942 const TemplateArgumentListInfo *TemplateArgs,
943 UnresolvedSetIterator Begin,
944 UnresolvedSetIterator End)
Abramo Bagnara7945c982012-01-27 09:46:47 +0000945 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
946 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000947 // Dependent
948 ((Base && Base->isTypeDependent()) ||
949 BaseType->isDependentType()),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000950 ((Base && Base->isInstantiationDependent()) ||
951 BaseType->isInstantiationDependentType()),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000952 // Contains unexpanded parameter pack
953 ((Base && Base->containsUnexpandedParameterPack()) ||
954 BaseType->containsUnexpandedParameterPack())),
John McCall1acbbb52010-02-02 06:20:04 +0000955 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
956 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall0009fcc2011-04-26 20:42:42 +0000957
958 // Check whether all of the members are non-static member functions,
959 // and if so, mark give this bound-member type instead of overload type.
960 if (hasOnlyNonStaticMemberFunctions(Begin, End))
961 setType(C.BoundMemberTy);
John McCall10eae182009-11-30 22:42:35 +0000962}
963
Douglas Gregor0da1d432011-02-28 20:01:57 +0000964bool UnresolvedMemberExpr::isImplicitAccess() const {
965 if (Base == 0)
966 return true;
967
Douglas Gregor25b7e052011-03-02 21:06:53 +0000968 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +0000969}
970
John McCall10eae182009-11-30 22:42:35 +0000971UnresolvedMemberExpr *
Douglas Gregora6e053e2010-12-15 01:34:56 +0000972UnresolvedMemberExpr::Create(ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +0000973 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +0000974 Expr *Base, QualType BaseType, bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +0000975 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000976 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000977 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000978 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +0000979 const TemplateArgumentListInfo *TemplateArgs,
980 UnresolvedSetIterator Begin,
981 UnresolvedSetIterator End) {
John McCall10eae182009-11-30 22:42:35 +0000982 std::size_t size = sizeof(UnresolvedMemberExpr);
983 if (TemplateArgs)
Abramo Bagnara7945c982012-01-27 09:46:47 +0000984 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
985 else if (TemplateKWLoc.isValid())
986 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall10eae182009-11-30 22:42:35 +0000987
Chris Lattner5c0b4052010-10-30 05:14:06 +0000988 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregorc69978f2010-05-23 19:36:40 +0000989 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000990 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000991 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000992 MemberNameInfo, TemplateArgs, Begin, End);
John McCall10eae182009-11-30 22:42:35 +0000993}
994
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000995UnresolvedMemberExpr *
Abramo Bagnara7945c982012-01-27 09:46:47 +0000996UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +0000997 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000998 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000999 if (HasTemplateKWAndArgsInfo)
1000 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001001
Chris Lattner5c0b4052010-10-30 05:14:06 +00001002 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001003 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +00001004 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001005 return E;
1006}
1007
John McCall58cc69d2010-01-27 01:50:18 +00001008CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1009 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1010
1011 // If there was a nested name specifier, it names the naming class.
1012 // It can't be dependent: after all, we were actually able to do the
1013 // lookup.
Douglas Gregor9262f472010-04-27 18:19:34 +00001014 CXXRecordDecl *Record = 0;
John McCall1acbbb52010-02-02 06:20:04 +00001015 if (getQualifier()) {
John McCall424cec92011-01-19 06:33:43 +00001016 const Type *T = getQualifier()->getAsType();
John McCall58cc69d2010-01-27 01:50:18 +00001017 assert(T && "qualifier in member expression does not name type");
Douglas Gregor9262f472010-04-27 18:19:34 +00001018 Record = T->getAsCXXRecordDecl();
1019 assert(Record && "qualifier in member expression does not name record");
1020 }
John McCall58cc69d2010-01-27 01:50:18 +00001021 // Otherwise the naming class must have been the base class.
Douglas Gregor9262f472010-04-27 18:19:34 +00001022 else {
John McCall58cc69d2010-01-27 01:50:18 +00001023 QualType BaseType = getBaseType().getNonReferenceType();
1024 if (isArrow()) {
1025 const PointerType *PT = BaseType->getAs<PointerType>();
1026 assert(PT && "base of arrow member access is not pointer");
1027 BaseType = PT->getPointeeType();
1028 }
1029
Douglas Gregor9262f472010-04-27 18:19:34 +00001030 Record = BaseType->getAsCXXRecordDecl();
1031 assert(Record && "base of member expression does not name record");
John McCall58cc69d2010-01-27 01:50:18 +00001032 }
1033
Douglas Gregor9262f472010-04-27 18:19:34 +00001034 return Record;
John McCall58cc69d2010-01-27 01:50:18 +00001035}
1036
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001037SubstNonTypeTemplateParmPackExpr::
1038SubstNonTypeTemplateParmPackExpr(QualType T,
1039 NonTypeTemplateParmDecl *Param,
1040 SourceLocation NameLoc,
1041 const TemplateArgument &ArgPack)
1042 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001043 true, true, true, true),
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001044 Param(Param), Arguments(ArgPack.pack_begin()),
1045 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1046
1047TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1048 return TemplateArgument(Arguments, NumArguments);
1049}
1050
David Blaikie68e081d2011-12-20 02:48:34 +00001051void ArrayTypeTraitExpr::anchor() { }