blob: 0426e59a74d837373fb5c2a459f353fa75c5b24c [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
Sebastian Redlc42e1182008-11-11 11:37:55 +000032// CXXTypeidExpr - has child iterators if the operand is an expression
33Stmt::child_iterator CXXTypeidExpr::child_begin() {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000034 return isTypeOperand() ? child_iterator()
35 : reinterpret_cast<Stmt **>(&Operand);
Sebastian Redlc42e1182008-11-11 11:37:55 +000036}
37Stmt::child_iterator CXXTypeidExpr::child_end() {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000038 return isTypeOperand() ? child_iterator()
39 : reinterpret_cast<Stmt **>(&Operand) + 1;
Sebastian Redlc42e1182008-11-11 11:37:55 +000040}
Ted Kremeneka758d092007-08-24 20:21:10 +000041
Francois Pichet01b7c302010-09-08 12:20:18 +000042QualType CXXUuidofExpr::getTypeOperand() const {
43 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
44 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
45 .getUnqualifiedType();
46}
47
48// CXXUuidofExpr - has child iterators if the operand is an expression
49Stmt::child_iterator CXXUuidofExpr::child_begin() {
50 return isTypeOperand() ? child_iterator()
51 : reinterpret_cast<Stmt **>(&Operand);
52}
53Stmt::child_iterator CXXUuidofExpr::child_end() {
54 return isTypeOperand() ? child_iterator()
55 : reinterpret_cast<Stmt **>(&Operand) + 1;
56}
57
Ted Kremeneka758d092007-08-24 20:21:10 +000058// CXXBoolLiteralExpr
Mike Stump1eb44332009-09-09 15:08:12 +000059Stmt::child_iterator CXXBoolLiteralExpr::child_begin() {
Ted Kremenek9ac59282007-10-18 23:28:49 +000060 return child_iterator();
61}
62Stmt::child_iterator CXXBoolLiteralExpr::child_end() {
63 return child_iterator();
64}
Chris Lattner50dd2892008-02-26 00:51:44 +000065
Sebastian Redl6e8ed162009-05-10 18:38:11 +000066// CXXNullPtrLiteralExpr
Mike Stump1eb44332009-09-09 15:08:12 +000067Stmt::child_iterator CXXNullPtrLiteralExpr::child_begin() {
Sebastian Redl6e8ed162009-05-10 18:38:11 +000068 return child_iterator();
69}
70Stmt::child_iterator CXXNullPtrLiteralExpr::child_end() {
71 return child_iterator();
72}
73
Douglas Gregor796da182008-11-04 14:32:21 +000074// CXXThisExpr
75Stmt::child_iterator CXXThisExpr::child_begin() { return child_iterator(); }
76Stmt::child_iterator CXXThisExpr::child_end() { return child_iterator(); }
77
Chris Lattner50dd2892008-02-26 00:51:44 +000078// CXXThrowExpr
Ted Kremenek1060aff2008-06-17 03:11:08 +000079Stmt::child_iterator CXXThrowExpr::child_begin() { return &Op; }
Chris Lattner50dd2892008-02-26 00:51:44 +000080Stmt::child_iterator CXXThrowExpr::child_end() {
81 // If Op is 0, we are processing throw; which has no children.
Ted Kremenek1060aff2008-06-17 03:11:08 +000082 return Op ? &Op+1 : &Op;
Chris Lattner50dd2892008-02-26 00:51:44 +000083}
Chris Lattner04421082008-04-08 04:40:51 +000084
85// CXXDefaultArgExpr
86Stmt::child_iterator CXXDefaultArgExpr::child_begin() {
Chris Lattner8123a952008-04-10 02:22:51 +000087 return child_iterator();
Chris Lattner04421082008-04-08 04:40:51 +000088}
89Stmt::child_iterator CXXDefaultArgExpr::child_end() {
Chris Lattner8123a952008-04-10 02:22:51 +000090 return child_iterator();
Chris Lattner04421082008-04-08 04:40:51 +000091}
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +000092
Douglas Gregored8abf12010-07-08 06:14:04 +000093// CXXScalarValueInitExpr
Douglas Gregorab6677e2010-09-08 00:15:04 +000094SourceRange CXXScalarValueInitExpr::getSourceRange() const {
95 SourceLocation Start = RParenLoc;
96 if (TypeInfo)
97 Start = TypeInfo->getTypeLoc().getBeginLoc();
98 return SourceRange(Start, RParenLoc);
99}
100
Douglas Gregored8abf12010-07-08 06:14:04 +0000101Stmt::child_iterator CXXScalarValueInitExpr::child_begin() {
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +0000102 return child_iterator();
103}
Douglas Gregored8abf12010-07-08 06:14:04 +0000104Stmt::child_iterator CXXScalarValueInitExpr::child_end() {
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +0000105 return child_iterator();
106}
Argyrios Kyrtzidis9e922b12008-09-09 23:47:53 +0000107
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000108// CXXNewExpr
Ted Kremenekad7fe862010-02-11 22:51:03 +0000109CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000110 Expr **placementArgs, unsigned numPlaceArgs,
Douglas Gregor4bd40312010-07-13 15:54:32 +0000111 SourceRange TypeIdParens, Expr *arraySize,
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000112 CXXConstructorDecl *constructor, bool initializer,
113 Expr **constructorArgs, unsigned numConsArgs,
114 FunctionDecl *operatorDelete, QualType ty,
Douglas Gregor1bb2a932010-09-07 21:49:58 +0000115 TypeSourceInfo *AllocatedTypeInfo,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000116 SourceLocation startLoc, SourceLocation endLoc,
117 SourceLocation constructorLParen,
118 SourceLocation constructorRParen)
John McCallf89e55a2010-11-18 06:31:45 +0000119 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000120 ty->isDependentType(), ty->isDependentType(),
121 ty->containsUnexpandedParameterPack()),
Douglas Gregor4bd40312010-07-13 15:54:32 +0000122 GlobalNew(globalNew),
Chris Lattner59218632010-05-10 01:22:27 +0000123 Initializer(initializer), SubExprs(0), OperatorNew(operatorNew),
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000124 OperatorDelete(operatorDelete), Constructor(constructor),
Douglas Gregor1bb2a932010-09-07 21:49:58 +0000125 AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens),
Chandler Carruth428edaf2010-10-25 08:47:36 +0000126 StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen),
127 ConstructorRParen(constructorRParen) {
Chris Lattner59218632010-05-10 01:22:27 +0000128 AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs);
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000129 unsigned i = 0;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000130 if (Array) {
131 if (arraySize->containsUnexpandedParameterPack())
132 ExprBits.ContainsUnexpandedParameterPack = true;
133
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000134 SubExprs[i++] = arraySize;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000135 }
136
137 for (unsigned j = 0; j < NumPlacementArgs; ++j) {
138 if (placementArgs[j]->containsUnexpandedParameterPack())
139 ExprBits.ContainsUnexpandedParameterPack = true;
140
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000141 SubExprs[i++] = placementArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000142 }
143
144 for (unsigned j = 0; j < NumConstructorArgs; ++j) {
145 if (constructorArgs[j]->containsUnexpandedParameterPack())
146 ExprBits.ContainsUnexpandedParameterPack = true;
147
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000148 SubExprs[i++] = constructorArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000149 }
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000150}
151
Chris Lattner59218632010-05-10 01:22:27 +0000152void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
153 unsigned numPlaceArgs, unsigned numConsArgs){
154 assert(SubExprs == 0 && "SubExprs already allocated");
155 Array = isArray;
156 NumPlacementArgs = numPlaceArgs;
157 NumConstructorArgs = numConsArgs;
158
159 unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs;
160 SubExprs = new (C) Stmt*[TotalSize];
161}
162
163
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000164Stmt::child_iterator CXXNewExpr::child_begin() { return &SubExprs[0]; }
165Stmt::child_iterator CXXNewExpr::child_end() {
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000166 return &SubExprs[0] + Array + getNumPlacementArgs() + getNumConstructorArgs();
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000167}
168
169// CXXDeleteExpr
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000170QualType CXXDeleteExpr::getDestroyedType() const {
171 const Expr *Arg = getArgument();
172 while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
173 if (ICE->getCastKind() != CK_UserDefinedConversion &&
174 ICE->getType()->isVoidPointerType())
175 Arg = ICE->getSubExpr();
176 else
177 break;
178 }
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000179 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silversteinc87fa062010-10-20 00:56:01 +0000180 const QualType ArgType = Arg->getType();
Craig Silversteina437ad32010-11-16 07:16:25 +0000181
182 if (ArgType->isDependentType() && !ArgType->isPointerType())
183 return QualType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000184
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000185 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000186}
187
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000188Stmt::child_iterator CXXDeleteExpr::child_begin() { return &Argument; }
189Stmt::child_iterator CXXDeleteExpr::child_end() { return &Argument+1; }
190
Douglas Gregora71d8192009-09-04 17:36:40 +0000191// CXXPseudoDestructorExpr
192Stmt::child_iterator CXXPseudoDestructorExpr::child_begin() { return &Base; }
193Stmt::child_iterator CXXPseudoDestructorExpr::child_end() {
194 return &Base + 1;
195}
196
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000197PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
198 : Type(Info)
199{
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000200 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000201}
202
John McCalle23cf432010-12-14 08:05:40 +0000203CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
204 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
205 NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
206 TypeSourceInfo *ScopeType, SourceLocation ColonColonLoc,
207 SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
208 : Expr(CXXPseudoDestructorExprClass,
209 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
210 FunctionProtoType::ExtProtoInfo())),
211 VK_RValue, OK_Ordinary,
212 /*isTypeDependent=*/(Base->isTypeDependent() ||
213 (DestroyedType.getTypeSourceInfo() &&
214 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000215 /*isValueDependent=*/Base->isValueDependent(),
216 // ContainsUnexpandedParameterPack
217 (Base->containsUnexpandedParameterPack() ||
218 (Qualifier && Qualifier->containsUnexpandedParameterPack()) ||
219 (ScopeType &&
220 ScopeType->getType()->containsUnexpandedParameterPack()) ||
221 (DestroyedType.getTypeSourceInfo() &&
222 DestroyedType.getTypeSourceInfo()->getType()
223 ->containsUnexpandedParameterPack()))),
John McCalle23cf432010-12-14 08:05:40 +0000224 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
225 OperatorLoc(OperatorLoc), Qualifier(Qualifier),
226 QualifierRange(QualifierRange),
227 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
228 DestroyedType(DestroyedType) { }
229
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000230QualType CXXPseudoDestructorExpr::getDestroyedType() const {
231 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
232 return TInfo->getType();
233
234 return QualType();
235}
236
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000237SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000238 SourceLocation End = DestroyedType.getLocation();
239 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000240 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000241 return SourceRange(Base->getLocStart(), End);
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000242}
243
244
John McCallba135432009-11-21 08:51:07 +0000245// UnresolvedLookupExpr
John McCallf7a1a742009-11-24 19:00:30 +0000246UnresolvedLookupExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000247UnresolvedLookupExpr::Create(ASTContext &C,
John McCallc373d482010-01-27 01:50:18 +0000248 CXXRecordDecl *NamingClass,
John McCallf7a1a742009-11-24 19:00:30 +0000249 NestedNameSpecifier *Qualifier,
Abramo Bagnara25777432010-08-11 22:01:17 +0000250 SourceRange QualifierRange,
251 const DeclarationNameInfo &NameInfo,
252 bool ADL,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000253 const TemplateArgumentListInfo &Args,
254 UnresolvedSetIterator Begin,
255 UnresolvedSetIterator End)
John McCallf7a1a742009-11-24 19:00:30 +0000256{
257 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
258 ExplicitTemplateArgumentList::sizeFor(Args));
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000259 return new (Mem) UnresolvedLookupExpr(C, NamingClass,
260 Qualifier, QualifierRange, NameInfo,
261 ADL, /*Overload*/ true, &Args,
262 Begin, End);
John McCallf7a1a742009-11-24 19:00:30 +0000263}
264
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000265UnresolvedLookupExpr *
266UnresolvedLookupExpr::CreateEmpty(ASTContext &C, unsigned NumTemplateArgs) {
267 std::size_t size = sizeof(UnresolvedLookupExpr);
268 if (NumTemplateArgs != 0)
269 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
270
Chris Lattner32488542010-10-30 05:14:06 +0000271 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000272 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
273 E->HasExplicitTemplateArgs = NumTemplateArgs != 0;
274 return E;
275}
276
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000277OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
278 NestedNameSpecifier *Qualifier, SourceRange QRange,
Abramo Bagnara25777432010-08-11 22:01:17 +0000279 const DeclarationNameInfo &NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000280 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000281 UnresolvedSetIterator Begin,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000282 UnresolvedSetIterator End,
283 bool KnownDependent,
284 bool KnownContainsUnexpandedParameterPack)
285 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
286 KnownDependent,
287 (KnownContainsUnexpandedParameterPack ||
288 NameInfo.containsUnexpandedParameterPack() ||
289 (Qualifier && Qualifier->containsUnexpandedParameterPack()))),
290 Results(0), NumResults(End - Begin), NameInfo(NameInfo),
291 Qualifier(Qualifier), QualifierRange(QRange),
292 HasExplicitTemplateArgs(TemplateArgs != 0)
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000293{
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000294 NumResults = End - Begin;
295 if (NumResults) {
296 // Determine whether this expression is type-dependent.
297 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
298 if ((*I)->getDeclContext()->isDependentContext() ||
299 isa<UnresolvedUsingValueDecl>(*I)) {
300 ExprBits.TypeDependent = true;
301 ExprBits.ValueDependent = true;
302 }
303 }
304
305 Results = static_cast<DeclAccessPair *>(
306 C.Allocate(sizeof(DeclAccessPair) * NumResults,
307 llvm::alignOf<DeclAccessPair>()));
308 memcpy(Results, &*Begin.getIterator(),
309 NumResults * sizeof(DeclAccessPair));
310 }
311
312 // If we have explicit template arguments, check for dependent
313 // template arguments and whether they contain any unexpanded pack
314 // expansions.
315 if (TemplateArgs) {
316 bool Dependent = false;
317 bool ContainsUnexpandedParameterPack = false;
318 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
319 ContainsUnexpandedParameterPack);
320
321 if (Dependent) {
322 ExprBits.TypeDependent = true;
323 ExprBits.ValueDependent = true;
324 }
325 if (ContainsUnexpandedParameterPack)
326 ExprBits.ContainsUnexpandedParameterPack = true;
327 }
328
329 if (isTypeDependent())
330 setType(C.DependentTy);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000331}
332
333void OverloadExpr::initializeResults(ASTContext &C,
334 UnresolvedSetIterator Begin,
335 UnresolvedSetIterator End) {
336 assert(Results == 0 && "Results already initialized!");
337 NumResults = End - Begin;
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000338 if (NumResults) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000339 Results = static_cast<DeclAccessPair *>(
340 C.Allocate(sizeof(DeclAccessPair) * NumResults,
341
342 llvm::alignOf<DeclAccessPair>()));
343 memcpy(Results, &*Begin.getIterator(),
344 NumResults * sizeof(DeclAccessPair));
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000345 }
346}
347
John McCalle9ee23e2010-04-22 18:44:12 +0000348CXXRecordDecl *OverloadExpr::getNamingClass() const {
349 if (isa<UnresolvedLookupExpr>(this))
350 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
351 else
352 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
353}
354
John McCallba135432009-11-21 08:51:07 +0000355Stmt::child_iterator UnresolvedLookupExpr::child_begin() {
Mike Stump1eb44332009-09-09 15:08:12 +0000356 return child_iterator();
Douglas Gregor5c37de72008-12-06 00:22:45 +0000357}
John McCallba135432009-11-21 08:51:07 +0000358Stmt::child_iterator UnresolvedLookupExpr::child_end() {
Douglas Gregor5c37de72008-12-06 00:22:45 +0000359 return child_iterator();
360}
Sebastian Redl64b45f72009-01-05 20:52:13 +0000361// UnaryTypeTraitExpr
362Stmt::child_iterator UnaryTypeTraitExpr::child_begin() {
363 return child_iterator();
364}
365Stmt::child_iterator UnaryTypeTraitExpr::child_end() {
366 return child_iterator();
367}
368
Francois Pichet6ad6f282010-12-07 00:08:36 +0000369//BinaryTypeTraitExpr
370Stmt::child_iterator BinaryTypeTraitExpr::child_begin() {
371 return child_iterator();
372}
373Stmt::child_iterator BinaryTypeTraitExpr::child_end() {
374 return child_iterator();
375}
376
John McCall865d4472009-11-19 22:55:06 +0000377// DependentScopeDeclRefExpr
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000378DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
379 NestedNameSpecifier *Qualifier,
380 SourceRange QualifierRange,
381 const DeclarationNameInfo &NameInfo,
382 const TemplateArgumentListInfo *Args)
383 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
384 true, true,
385 (NameInfo.containsUnexpandedParameterPack() ||
386 (Qualifier && Qualifier->containsUnexpandedParameterPack()))),
387 NameInfo(NameInfo), QualifierRange(QualifierRange), Qualifier(Qualifier),
388 HasExplicitTemplateArgs(Args != 0)
389{
390 if (Args) {
391 bool Dependent = true;
392 bool ContainsUnexpandedParameterPack
393 = ExprBits.ContainsUnexpandedParameterPack;
394
395 reinterpret_cast<ExplicitTemplateArgumentList*>(this+1)
396 ->initializeFrom(*Args, Dependent, ContainsUnexpandedParameterPack);
397 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
398 }
399}
400
John McCallf7a1a742009-11-24 19:00:30 +0000401DependentScopeDeclRefExpr *
402DependentScopeDeclRefExpr::Create(ASTContext &C,
403 NestedNameSpecifier *Qualifier,
404 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +0000405 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +0000406 const TemplateArgumentListInfo *Args) {
407 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCallf7a1a742009-11-24 19:00:30 +0000408 if (Args)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000409 size += ExplicitTemplateArgumentList::sizeFor(*Args);
410 void *Mem = C.Allocate(size);
411 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy,
412 Qualifier, QualifierRange,
413 NameInfo, Args);
John McCallf7a1a742009-11-24 19:00:30 +0000414}
415
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000416DependentScopeDeclRefExpr *
417DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
418 unsigned NumTemplateArgs) {
419 std::size_t size = sizeof(DependentScopeDeclRefExpr);
420 if (NumTemplateArgs)
421 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
422 void *Mem = C.Allocate(size);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000423 return new (Mem) DependentScopeDeclRefExpr(QualType(), 0, SourceRange(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000424 DeclarationNameInfo(), 0);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000425}
426
John McCall865d4472009-11-19 22:55:06 +0000427StmtIterator DependentScopeDeclRefExpr::child_begin() {
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000428 return child_iterator();
429}
430
John McCall865d4472009-11-19 22:55:06 +0000431StmtIterator DependentScopeDeclRefExpr::child_end() {
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000432 return child_iterator();
433}
434
Chandler Carruth428edaf2010-10-25 08:47:36 +0000435SourceRange CXXConstructExpr::getSourceRange() const {
Douglas Gregor40749ee2010-11-03 00:35:38 +0000436 if (ParenRange.isValid())
437 return SourceRange(Loc, ParenRange.getEnd());
438
439 SourceLocation End = Loc;
440 for (unsigned I = getNumArgs(); I > 0; --I) {
441 const Expr *Arg = getArg(I-1);
442 if (!Arg->isDefaultArgument()) {
443 SourceLocation NewEnd = Arg->getLocEnd();
444 if (NewEnd.isValid()) {
445 End = NewEnd;
446 break;
447 }
448 }
449 }
450
451 return SourceRange(Loc, End);
Ted Kremeneke3837682009-12-23 04:00:48 +0000452}
453
Douglas Gregorb4609802008-11-14 16:09:21 +0000454SourceRange CXXOperatorCallExpr::getSourceRange() const {
455 OverloadedOperatorKind Kind = getOperator();
456 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
457 if (getNumArgs() == 1)
458 // Prefix operator
Mike Stump1eb44332009-09-09 15:08:12 +0000459 return SourceRange(getOperatorLoc(),
Douglas Gregorb4609802008-11-14 16:09:21 +0000460 getArg(0)->getSourceRange().getEnd());
461 else
462 // Postfix operator
463 return SourceRange(getArg(0)->getSourceRange().getEnd(),
464 getOperatorLoc());
465 } else if (Kind == OO_Call) {
466 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
467 } else if (Kind == OO_Subscript) {
468 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
469 } else if (getNumArgs() == 1) {
470 return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd());
471 } else if (getNumArgs() == 2) {
472 return SourceRange(getArg(0)->getSourceRange().getBegin(),
473 getArg(1)->getSourceRange().getEnd());
474 } else {
475 return SourceRange();
476 }
477}
478
Douglas Gregor88a35142008-12-22 05:46:06 +0000479Expr *CXXMemberCallExpr::getImplicitObjectArgument() {
480 if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
481 return MemExpr->getBase();
482
483 // FIXME: Will eventually need to cope with member pointers.
484 return 0;
485}
486
Chandler Carruth007a9b12010-10-27 06:55:41 +0000487CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
488 Expr* ThisArg = getImplicitObjectArgument();
489 if (!ThisArg)
490 return 0;
491
492 if (ThisArg->getType()->isAnyPointerType())
493 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
494
495 return ThisArg->getType()->getAsCXXRecordDecl();
496}
497
Douglas Gregor00b98c22009-11-12 15:31:47 +0000498SourceRange CXXMemberCallExpr::getSourceRange() const {
499 SourceLocation LocStart = getCallee()->getLocStart();
500 if (LocStart.isInvalid() && getNumArgs() > 0)
501 LocStart = getArg(0)->getLocStart();
502 return SourceRange(LocStart, getRParenLoc());
503}
504
505
Douglas Gregor49badde2008-10-27 19:41:14 +0000506//===----------------------------------------------------------------------===//
507// Named casts
508//===----------------------------------------------------------------------===//
509
510/// getCastName - Get the name of the C++ cast being used, e.g.,
511/// "static_cast", "dynamic_cast", "reinterpret_cast", or
512/// "const_cast". The returned pointer must not be freed.
513const char *CXXNamedCastExpr::getCastName() const {
514 switch (getStmtClass()) {
515 case CXXStaticCastExprClass: return "static_cast";
516 case CXXDynamicCastExprClass: return "dynamic_cast";
517 case CXXReinterpretCastExprClass: return "reinterpret_cast";
518 case CXXConstCastExprClass: return "const_cast";
519 default: return "<invalid cast>";
520 }
521}
Douglas Gregor506ae412009-01-16 18:33:17 +0000522
John McCallf871d0c2010-08-07 06:22:56 +0000523CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000524 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000525 CastKind K, Expr *Op,
526 const CXXCastPath *BasePath,
527 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000528 SourceLocation L,
529 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000530 unsigned PathSize = (BasePath ? BasePath->size() : 0);
531 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
532 + PathSize * sizeof(CXXBaseSpecifier*));
533 CXXStaticCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000534 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
535 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000536 if (PathSize) E->setCastPath(*BasePath);
537 return E;
538}
539
540CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
541 unsigned PathSize) {
542 void *Buffer =
543 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
544 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
545}
546
547CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000548 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000549 CastKind K, Expr *Op,
550 const CXXCastPath *BasePath,
551 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000552 SourceLocation L,
553 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000554 unsigned PathSize = (BasePath ? BasePath->size() : 0);
555 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
556 + PathSize * sizeof(CXXBaseSpecifier*));
557 CXXDynamicCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000558 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
559 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000560 if (PathSize) E->setCastPath(*BasePath);
561 return E;
562}
563
564CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
565 unsigned PathSize) {
566 void *Buffer =
567 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
568 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
569}
570
571CXXReinterpretCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000572CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
573 CastKind K, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000574 const CXXCastPath *BasePath,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000575 TypeSourceInfo *WrittenTy, SourceLocation L,
576 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000577 unsigned PathSize = (BasePath ? BasePath->size() : 0);
578 void *Buffer =
579 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
580 CXXReinterpretCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000581 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
582 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000583 if (PathSize) E->setCastPath(*BasePath);
584 return E;
585}
586
587CXXReinterpretCastExpr *
588CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
589 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
590 + PathSize * sizeof(CXXBaseSpecifier*));
591 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
592}
593
John McCallf89e55a2010-11-18 06:31:45 +0000594CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
595 ExprValueKind VK, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000596 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000597 SourceLocation L,
598 SourceLocation RParenLoc) {
599 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000600}
601
602CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
603 return new (C) CXXConstCastExpr(EmptyShell());
604}
605
606CXXFunctionalCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000607CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000608 TypeSourceInfo *Written, SourceLocation L,
609 CastKind K, Expr *Op, const CXXCastPath *BasePath,
610 SourceLocation R) {
611 unsigned PathSize = (BasePath ? BasePath->size() : 0);
612 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
613 + PathSize * sizeof(CXXBaseSpecifier*));
614 CXXFunctionalCastExpr *E =
John McCallf89e55a2010-11-18 06:31:45 +0000615 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallf871d0c2010-08-07 06:22:56 +0000616 if (PathSize) E->setCastPath(*BasePath);
617 return E;
618}
619
620CXXFunctionalCastExpr *
621CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
622 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
623 + PathSize * sizeof(CXXBaseSpecifier*));
624 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
625}
626
627
Douglas Gregor65222e82009-12-23 18:19:08 +0000628CXXDefaultArgExpr *
Douglas Gregor036aed12009-12-23 23:03:06 +0000629CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
630 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor65222e82009-12-23 18:19:08 +0000631 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor036aed12009-12-23 23:03:06 +0000632 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
633 SubExpr);
Douglas Gregor65222e82009-12-23 18:19:08 +0000634}
635
Mike Stump1eb44332009-09-09 15:08:12 +0000636CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonb859f352009-05-30 20:34:37 +0000637 const CXXDestructorDecl *Destructor) {
Anders Carlsson88eaf072009-05-30 22:38:53 +0000638 return new (C) CXXTemporary(Destructor);
639}
640
Mike Stump1eb44332009-09-09 15:08:12 +0000641CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000642 CXXTemporary *Temp,
643 Expr* SubExpr) {
Mike Stump1eb44332009-09-09 15:08:12 +0000644 assert(SubExpr->getType()->isRecordType() &&
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000645 "Expression bound to a temporary must have record type!");
646
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000647 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000648}
649
Anders Carlsson8e587a12009-05-30 20:56:46 +0000650CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000651 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000652 TypeSourceInfo *Type,
Douglas Gregor506ae412009-01-16 18:33:17 +0000653 Expr **Args,
Mike Stump1eb44332009-09-09 15:08:12 +0000654 unsigned NumArgs,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000655 SourceRange parenRange,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000656 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000657 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
658 Type->getType().getNonReferenceType(),
659 Type->getTypeLoc().getBeginLoc(),
Chandler Carruth428edaf2010-10-25 08:47:36 +0000660 Cons, false, Args, NumArgs, ZeroInitialization,
661 CXXConstructExpr::CK_Complete, parenRange),
662 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000663}
664
665SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth428edaf2010-10-25 08:47:36 +0000666 return SourceRange(Type->getTypeLoc().getBeginLoc(),
667 getParenRange().getEnd());
Douglas Gregor506ae412009-01-16 18:33:17 +0000668}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000669
Mike Stump1eb44332009-09-09 15:08:12 +0000670CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000671 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000672 CXXConstructorDecl *D, bool Elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000673 Expr **Args, unsigned NumArgs,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000674 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000675 ConstructionKind ConstructKind,
676 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000677 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000678 Elidable, Args, NumArgs, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000679 ConstructKind, ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000680}
681
Mike Stump1eb44332009-09-09 15:08:12 +0000682CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000683 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000684 CXXConstructorDecl *D, bool elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000685 Expr **args, unsigned numargs,
Anders Carlsson72e96fd2010-05-02 22:54:08 +0000686 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000687 ConstructionKind ConstructKind,
688 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000689 : Expr(SC, T, VK_RValue, OK_Ordinary,
690 T->isDependentType(), T->isDependentType(),
691 T->containsUnexpandedParameterPack()),
692 Constructor(D), Loc(Loc), ParenRange(ParenRange), Elidable(elidable),
693 ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind),
694 Args(0), NumArgs(numargs)
Douglas Gregor16006c92009-12-16 18:50:27 +0000695{
696 if (NumArgs) {
697 Args = new (C) Stmt*[NumArgs];
698
699 for (unsigned i = 0; i != NumArgs; ++i) {
700 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000701
702 if (args[i]->isValueDependent())
703 ExprBits.ValueDependent = true;
704 if (args[i]->containsUnexpandedParameterPack())
705 ExprBits.ContainsUnexpandedParameterPack = true;
706
Douglas Gregor16006c92009-12-16 18:50:27 +0000707 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000708 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000709 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000710}
711
John McCall4765fa02010-12-06 08:20:24 +0000712ExprWithCleanups::ExprWithCleanups(ASTContext &C,
713 Expr *subexpr,
714 CXXTemporary **temps,
715 unsigned numtemps)
716 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +0000717 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000718 subexpr->isTypeDependent(), subexpr->isValueDependent(),
719 subexpr->containsUnexpandedParameterPack()),
Chris Lattnerd2598362010-05-10 00:25:06 +0000720 SubExpr(subexpr), Temps(0), NumTemps(0) {
Chris Lattneraff32cb2010-05-10 00:45:12 +0000721 if (numtemps) {
Ted Kremenekd04ed412010-05-10 20:06:30 +0000722 setNumTemporaries(C, numtemps);
Chris Lattnerd2598362010-05-10 00:25:06 +0000723 for (unsigned i = 0; i != numtemps; ++i)
Anders Carlssonff6b3d62009-05-30 21:05:25 +0000724 Temps[i] = temps[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000725 }
726}
727
John McCall4765fa02010-12-06 08:20:24 +0000728void ExprWithCleanups::setNumTemporaries(ASTContext &C, unsigned N) {
Chris Lattnerd2598362010-05-10 00:25:06 +0000729 assert(Temps == 0 && "Cannot resize with this");
Daniel Dunbar90556d42010-05-10 15:59:37 +0000730 NumTemps = N;
Ted Kremenekd04ed412010-05-10 20:06:30 +0000731 Temps = new (C) CXXTemporary*[NumTemps];
Chris Lattnerd2598362010-05-10 00:25:06 +0000732}
733
734
John McCall4765fa02010-12-06 08:20:24 +0000735ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C,
736 Expr *SubExpr,
737 CXXTemporary **Temps,
738 unsigned NumTemps) {
739 return new (C) ExprWithCleanups(C, SubExpr, Temps, NumTemps);
Anders Carlsson88eaf072009-05-30 22:38:53 +0000740}
741
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000742// CXXBindTemporaryExpr
743Stmt::child_iterator CXXBindTemporaryExpr::child_begin() {
744 return &SubExpr;
745}
746
Mike Stump1eb44332009-09-09 15:08:12 +0000747Stmt::child_iterator CXXBindTemporaryExpr::child_end() {
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000748 return &SubExpr + 1;
749}
750
Anders Carlssone349bea2009-04-23 02:32:43 +0000751// CXXConstructExpr
752Stmt::child_iterator CXXConstructExpr::child_begin() {
753 return &Args[0];
754}
755Stmt::child_iterator CXXConstructExpr::child_end() {
756 return &Args[0]+NumArgs;
757}
758
John McCall4765fa02010-12-06 08:20:24 +0000759// ExprWithCleanups
760Stmt::child_iterator ExprWithCleanups::child_begin() {
Anders Carlsson55674ac2009-05-01 22:21:22 +0000761 return &SubExpr;
Anders Carlsson19d28a62009-04-21 02:22:11 +0000762}
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000763
John McCall4765fa02010-12-06 08:20:24 +0000764Stmt::child_iterator ExprWithCleanups::child_end() {
Anders Carlsson55674ac2009-05-01 22:21:22 +0000765 return &SubExpr + 1;
766}
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000767
Douglas Gregorab6677e2010-09-08 00:15:04 +0000768CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000769 SourceLocation LParenLoc,
770 Expr **Args,
771 unsigned NumArgs,
772 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000773 : Expr(CXXUnresolvedConstructExprClass,
774 Type->getType().getNonReferenceType(),
John McCall09431682010-11-18 19:01:18 +0000775 VK_LValue, OK_Ordinary,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000776 Type->getType()->isDependentType(), true,
777 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +0000778 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000779 LParenLoc(LParenLoc),
780 RParenLoc(RParenLoc),
781 NumArgs(NumArgs) {
782 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000783 for (unsigned I = 0; I != NumArgs; ++I) {
784 if (Args[I]->containsUnexpandedParameterPack())
785 ExprBits.ContainsUnexpandedParameterPack = true;
786
787 StoredArgs[I] = Args[I];
788 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000789}
790
791CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +0000792CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000793 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000794 SourceLocation LParenLoc,
795 Expr **Args,
796 unsigned NumArgs,
797 SourceLocation RParenLoc) {
798 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
799 sizeof(Expr *) * NumArgs);
Douglas Gregorab6677e2010-09-08 00:15:04 +0000800 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000801 Args, NumArgs, RParenLoc);
802}
803
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000804CXXUnresolvedConstructExpr *
805CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
806 Stmt::EmptyShell Empty;
807 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
808 sizeof(Expr *) * NumArgs);
809 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
810}
811
Douglas Gregorab6677e2010-09-08 00:15:04 +0000812SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
813 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
814}
815
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000816Stmt::child_iterator CXXUnresolvedConstructExpr::child_begin() {
817 return child_iterator(reinterpret_cast<Stmt **>(this + 1));
818}
819
820Stmt::child_iterator CXXUnresolvedConstructExpr::child_end() {
821 return child_iterator(reinterpret_cast<Stmt **>(this + 1) + NumArgs);
822}
Sebastian Redl8b0b4752009-05-16 18:50:46 +0000823
John McCall865d4472009-11-19 22:55:06 +0000824CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000825 Expr *Base, QualType BaseType,
826 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000827 SourceLocation OperatorLoc,
828 NestedNameSpecifier *Qualifier,
829 SourceRange QualifierRange,
830 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000831 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000832 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +0000833 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000834 VK_LValue, OK_Ordinary, true, true,
835 ((Base && Base->containsUnexpandedParameterPack()) ||
836 (Qualifier && Qualifier->containsUnexpandedParameterPack()) ||
837 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +0000838 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
839 HasExplicitTemplateArgs(TemplateArgs != 0),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000840 OperatorLoc(OperatorLoc),
841 Qualifier(Qualifier), QualifierRange(QualifierRange),
842 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +0000843 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000844 if (TemplateArgs) {
845 bool Dependent = true;
846 bool ContainsUnexpandedParameterPack = false;
847 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
848 ContainsUnexpandedParameterPack);
849 if (ContainsUnexpandedParameterPack)
850 ExprBits.ContainsUnexpandedParameterPack = true;
851 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000852}
853
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000854CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
855 Expr *Base, QualType BaseType,
856 bool IsArrow,
857 SourceLocation OperatorLoc,
858 NestedNameSpecifier *Qualifier,
859 SourceRange QualifierRange,
860 NamedDecl *FirstQualifierFoundInScope,
861 DeclarationNameInfo MemberNameInfo)
862 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
863 VK_LValue, OK_Ordinary, true, true,
864 ((Base && Base->containsUnexpandedParameterPack()) ||
865 (Qualifier && Qualifier->containsUnexpandedParameterPack()) ||
866 MemberNameInfo.containsUnexpandedParameterPack())),
867 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
868 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
869 Qualifier(Qualifier), QualifierRange(QualifierRange),
870 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
871 MemberNameInfo(MemberNameInfo) { }
872
John McCall865d4472009-11-19 22:55:06 +0000873CXXDependentScopeMemberExpr *
874CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000875 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000876 SourceLocation OperatorLoc,
877 NestedNameSpecifier *Qualifier,
878 SourceRange QualifierRange,
879 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000880 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000881 const TemplateArgumentListInfo *TemplateArgs) {
882 if (!TemplateArgs)
John McCallaa81e162009-12-01 22:10:20 +0000883 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
884 IsArrow, OperatorLoc,
885 Qualifier, QualifierRange,
886 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000887 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000888
John McCalld5532b62009-11-23 01:53:49 +0000889 std::size_t size = sizeof(CXXDependentScopeMemberExpr);
890 if (TemplateArgs)
891 size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
892
Chris Lattner32488542010-10-30 05:14:06 +0000893 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +0000894 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
895 IsArrow, OperatorLoc,
896 Qualifier, QualifierRange,
897 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000898 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000899}
900
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000901CXXDependentScopeMemberExpr *
902CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
903 unsigned NumTemplateArgs) {
904 if (NumTemplateArgs == 0)
905 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
906 0, SourceLocation(), 0,
907 SourceRange(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000908 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000909
910 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
911 ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +0000912 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000913 CXXDependentScopeMemberExpr *E
914 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
915 0, SourceLocation(), 0,
916 SourceRange(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000917 DeclarationNameInfo(), 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000918 E->HasExplicitTemplateArgs = true;
919 return E;
920}
921
John McCall865d4472009-11-19 22:55:06 +0000922Stmt::child_iterator CXXDependentScopeMemberExpr::child_begin() {
Douglas Gregor1c0ca592009-05-22 21:13:27 +0000923 return child_iterator(&Base);
924}
925
John McCall865d4472009-11-19 22:55:06 +0000926Stmt::child_iterator CXXDependentScopeMemberExpr::child_end() {
John McCallaa81e162009-12-01 22:10:20 +0000927 if (isImplicitAccess())
928 return child_iterator(&Base);
Douglas Gregor1c0ca592009-05-22 21:13:27 +0000929 return child_iterator(&Base + 1);
930}
John McCall129e2df2009-11-30 22:42:35 +0000931
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000932UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000933 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000934 Expr *Base, QualType BaseType,
935 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000936 SourceLocation OperatorLoc,
937 NestedNameSpecifier *Qualifier,
938 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +0000939 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000940 const TemplateArgumentListInfo *TemplateArgs,
941 UnresolvedSetIterator Begin,
942 UnresolvedSetIterator End)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000943 : OverloadExpr(UnresolvedMemberExprClass, C,
Abramo Bagnara25777432010-08-11 22:01:17 +0000944 Qualifier, QualifierRange, MemberNameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000945 TemplateArgs, Begin, End,
946 // Dependent
947 ((Base && Base->isTypeDependent()) ||
948 BaseType->isDependentType()),
949 // Contains unexpanded parameter pack
950 ((Base && Base->containsUnexpandedParameterPack()) ||
951 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +0000952 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
953 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall129e2df2009-11-30 22:42:35 +0000954}
955
956UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000957UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000958 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000959 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000960 SourceLocation OperatorLoc,
961 NestedNameSpecifier *Qualifier,
962 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +0000963 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000964 const TemplateArgumentListInfo *TemplateArgs,
965 UnresolvedSetIterator Begin,
966 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +0000967 std::size_t size = sizeof(UnresolvedMemberExpr);
968 if (TemplateArgs)
969 size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
970
Chris Lattner32488542010-10-30 05:14:06 +0000971 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000972 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000973 HasUnresolvedUsing, Base, BaseType,
John McCallaa81e162009-12-01 22:10:20 +0000974 IsArrow, OperatorLoc, Qualifier, QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +0000975 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +0000976}
977
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000978UnresolvedMemberExpr *
979UnresolvedMemberExpr::CreateEmpty(ASTContext &C, unsigned NumTemplateArgs) {
980 std::size_t size = sizeof(UnresolvedMemberExpr);
981 if (NumTemplateArgs != 0)
982 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
983
Chris Lattner32488542010-10-30 05:14:06 +0000984 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000985 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
986 E->HasExplicitTemplateArgs = NumTemplateArgs != 0;
987 return E;
988}
989
John McCallc373d482010-01-27 01:50:18 +0000990CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
991 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
992
993 // If there was a nested name specifier, it names the naming class.
994 // It can't be dependent: after all, we were actually able to do the
995 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000996 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +0000997 if (getQualifier()) {
998 Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +0000999 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001000 Record = T->getAsCXXRecordDecl();
1001 assert(Record && "qualifier in member expression does not name record");
1002 }
John McCallc373d482010-01-27 01:50:18 +00001003 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001004 else {
John McCallc373d482010-01-27 01:50:18 +00001005 QualType BaseType = getBaseType().getNonReferenceType();
1006 if (isArrow()) {
1007 const PointerType *PT = BaseType->getAs<PointerType>();
1008 assert(PT && "base of arrow member access is not pointer");
1009 BaseType = PT->getPointeeType();
1010 }
1011
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001012 Record = BaseType->getAsCXXRecordDecl();
1013 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +00001014 }
1015
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001016 return Record;
John McCallc373d482010-01-27 01:50:18 +00001017}
1018
John McCall129e2df2009-11-30 22:42:35 +00001019Stmt::child_iterator UnresolvedMemberExpr::child_begin() {
1020 return child_iterator(&Base);
1021}
1022
1023Stmt::child_iterator UnresolvedMemberExpr::child_end() {
John McCallaa81e162009-12-01 22:10:20 +00001024 if (isImplicitAccess())
1025 return child_iterator(&Base);
John McCall129e2df2009-11-30 22:42:35 +00001026 return child_iterator(&Base + 1);
1027}
Sebastian Redl2e156222010-09-10 20:55:43 +00001028
1029Stmt::child_iterator CXXNoexceptExpr::child_begin() {
1030 return child_iterator(&Operand);
1031}
1032Stmt::child_iterator CXXNoexceptExpr::child_end() {
1033 return child_iterator(&Operand + 1);
1034}
Douglas Gregorbe230c32011-01-03 17:17:50 +00001035
1036SourceRange PackExpansionExpr::getSourceRange() const {
1037 return SourceRange(Pattern->getLocStart(), EllipsisLoc);
1038}
1039
1040Stmt::child_iterator PackExpansionExpr::child_begin() {
1041 return child_iterator(&Pattern);
1042}
1043
1044Stmt::child_iterator PackExpansionExpr::child_end() {
1045 return child_iterator(&Pattern + 1);
1046}
Douglas Gregoree8aff02011-01-04 17:33:58 +00001047
1048SourceRange SizeOfPackExpr::getSourceRange() const {
1049 return SourceRange(OperatorLoc, RParenLoc);
1050}
1051
1052Stmt::child_iterator SizeOfPackExpr::child_begin() {
1053 return child_iterator();
1054}
1055
1056Stmt::child_iterator SizeOfPackExpr::child_end() {
1057 return child_iterator();
1058}