blob: 3dac125990bfccc361d500457f07d05adc942e81 [file] [log] [blame]
Ted Kremeneka758d092007-08-24 20:21:10 +00001//===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremeneka758d092007-08-24 20:21:10 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the subclesses of Expr class declared in ExprCXX.h
11//
12//===----------------------------------------------------------------------===//
13
Douglas Gregorb4609802008-11-14 16:09:21 +000014#include "clang/Basic/IdentifierTable.h"
15#include "clang/AST/DeclCXX.h"
Douglas Gregoredce4dd2009-06-30 22:34:41 +000016#include "clang/AST/DeclTemplate.h"
Ted Kremeneka758d092007-08-24 20:21:10 +000017#include "clang/AST/ExprCXX.h"
Douglas Gregor26d4ac92010-02-24 23:40:28 +000018#include "clang/AST/TypeLoc.h"
Ted Kremeneka758d092007-08-24 20:21:10 +000019using namespace clang;
20
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000021
Ted Kremeneka758d092007-08-24 20:21:10 +000022//===----------------------------------------------------------------------===//
23// Child Iterators for iterating over subexpressions/substatements
24//===----------------------------------------------------------------------===//
25
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000026QualType CXXTypeidExpr::getTypeOperand() const {
27 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
28 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
29 .getUnqualifiedType();
30}
31
Francois Pichet01b7c302010-09-08 12:20:18 +000032QualType CXXUuidofExpr::getTypeOperand() const {
33 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
34 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
35 .getUnqualifiedType();
36}
37
Douglas Gregored8abf12010-07-08 06:14:04 +000038// CXXScalarValueInitExpr
Douglas Gregorab6677e2010-09-08 00:15:04 +000039SourceRange CXXScalarValueInitExpr::getSourceRange() const {
40 SourceLocation Start = RParenLoc;
41 if (TypeInfo)
42 Start = TypeInfo->getTypeLoc().getBeginLoc();
43 return SourceRange(Start, RParenLoc);
44}
45
Sebastian Redl4c5d3202008-11-21 19:14:01 +000046// CXXNewExpr
Ted Kremenekad7fe862010-02-11 22:51:03 +000047CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Sebastian Redl4c5d3202008-11-21 19:14:01 +000048 Expr **placementArgs, unsigned numPlaceArgs,
Douglas Gregor4bd40312010-07-13 15:54:32 +000049 SourceRange TypeIdParens, Expr *arraySize,
Sebastian Redl4c5d3202008-11-21 19:14:01 +000050 CXXConstructorDecl *constructor, bool initializer,
51 Expr **constructorArgs, unsigned numConsArgs,
John McCall6ec278d2011-01-27 09:37:56 +000052 FunctionDecl *operatorDelete,
53 bool usualArrayDeleteWantsSize, QualType ty,
Douglas Gregor1bb2a932010-09-07 21:49:58 +000054 TypeSourceInfo *AllocatedTypeInfo,
Chandler Carruth428edaf2010-10-25 08:47:36 +000055 SourceLocation startLoc, SourceLocation endLoc,
56 SourceLocation constructorLParen,
57 SourceLocation constructorRParen)
John McCallf89e55a2010-11-18 06:31:45 +000058 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000059 ty->isDependentType(), ty->isDependentType(),
60 ty->containsUnexpandedParameterPack()),
John McCall6ec278d2011-01-27 09:37:56 +000061 GlobalNew(globalNew), Initializer(initializer),
62 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
63 SubExprs(0), OperatorNew(operatorNew),
Sebastian Redlcee63fb2008-12-02 14:43:59 +000064 OperatorDelete(operatorDelete), Constructor(constructor),
Douglas Gregor1bb2a932010-09-07 21:49:58 +000065 AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens),
Chandler Carruth428edaf2010-10-25 08:47:36 +000066 StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen),
67 ConstructorRParen(constructorRParen) {
Chris Lattner59218632010-05-10 01:22:27 +000068 AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs);
Sebastian Redl4c5d3202008-11-21 19:14:01 +000069 unsigned i = 0;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000070 if (Array) {
71 if (arraySize->containsUnexpandedParameterPack())
72 ExprBits.ContainsUnexpandedParameterPack = true;
73
Sebastian Redlcee63fb2008-12-02 14:43:59 +000074 SubExprs[i++] = arraySize;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000075 }
76
77 for (unsigned j = 0; j < NumPlacementArgs; ++j) {
78 if (placementArgs[j]->containsUnexpandedParameterPack())
79 ExprBits.ContainsUnexpandedParameterPack = true;
80
Sebastian Redl4c5d3202008-11-21 19:14:01 +000081 SubExprs[i++] = placementArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000082 }
83
84 for (unsigned j = 0; j < NumConstructorArgs; ++j) {
85 if (constructorArgs[j]->containsUnexpandedParameterPack())
86 ExprBits.ContainsUnexpandedParameterPack = true;
87
Sebastian Redl4c5d3202008-11-21 19:14:01 +000088 SubExprs[i++] = constructorArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000089 }
Sebastian Redl4c5d3202008-11-21 19:14:01 +000090}
91
Chris Lattner59218632010-05-10 01:22:27 +000092void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
93 unsigned numPlaceArgs, unsigned numConsArgs){
94 assert(SubExprs == 0 && "SubExprs already allocated");
95 Array = isArray;
96 NumPlacementArgs = numPlaceArgs;
97 NumConstructorArgs = numConsArgs;
98
99 unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs;
100 SubExprs = new (C) Stmt*[TotalSize];
101}
102
103
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000104// CXXDeleteExpr
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000105QualType CXXDeleteExpr::getDestroyedType() const {
106 const Expr *Arg = getArgument();
107 while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
108 if (ICE->getCastKind() != CK_UserDefinedConversion &&
109 ICE->getType()->isVoidPointerType())
110 Arg = ICE->getSubExpr();
111 else
112 break;
113 }
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000114 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silversteinc87fa062010-10-20 00:56:01 +0000115 const QualType ArgType = Arg->getType();
Craig Silversteina437ad32010-11-16 07:16:25 +0000116
117 if (ArgType->isDependentType() && !ArgType->isPointerType())
118 return QualType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000119
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000120 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000121}
122
Douglas Gregora71d8192009-09-04 17:36:40 +0000123// CXXPseudoDestructorExpr
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000124PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
125 : Type(Info)
126{
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000127 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000128}
129
John McCalle23cf432010-12-14 08:05:40 +0000130CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000131 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
132 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
133 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
134 PseudoDestructorTypeStorage DestroyedType)
John McCalle23cf432010-12-14 08:05:40 +0000135 : Expr(CXXPseudoDestructorExprClass,
136 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
137 FunctionProtoType::ExtProtoInfo())),
138 VK_RValue, OK_Ordinary,
139 /*isTypeDependent=*/(Base->isTypeDependent() ||
140 (DestroyedType.getTypeSourceInfo() &&
141 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000142 /*isValueDependent=*/Base->isValueDependent(),
143 // ContainsUnexpandedParameterPack
144 (Base->containsUnexpandedParameterPack() ||
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000145 (QualifierLoc &&
146 QualifierLoc.getNestedNameSpecifier()
147 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000148 (ScopeType &&
149 ScopeType->getType()->containsUnexpandedParameterPack()) ||
150 (DestroyedType.getTypeSourceInfo() &&
151 DestroyedType.getTypeSourceInfo()->getType()
152 ->containsUnexpandedParameterPack()))),
John McCalle23cf432010-12-14 08:05:40 +0000153 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000154 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalle23cf432010-12-14 08:05:40 +0000155 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
156 DestroyedType(DestroyedType) { }
157
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000158QualType CXXPseudoDestructorExpr::getDestroyedType() const {
159 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
160 return TInfo->getType();
161
162 return QualType();
163}
164
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000165SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000166 SourceLocation End = DestroyedType.getLocation();
167 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000168 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000169 return SourceRange(Base->getLocStart(), End);
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000170}
171
172
John McCallba135432009-11-21 08:51:07 +0000173// UnresolvedLookupExpr
John McCallf7a1a742009-11-24 19:00:30 +0000174UnresolvedLookupExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000175UnresolvedLookupExpr::Create(ASTContext &C,
John McCallc373d482010-01-27 01:50:18 +0000176 CXXRecordDecl *NamingClass,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000177 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000178 const DeclarationNameInfo &NameInfo,
179 bool ADL,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000180 const TemplateArgumentListInfo &Args,
181 UnresolvedSetIterator Begin,
182 UnresolvedSetIterator End)
John McCallf7a1a742009-11-24 19:00:30 +0000183{
184 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
185 ExplicitTemplateArgumentList::sizeFor(Args));
Douglas Gregor4c9be892011-02-28 20:01:57 +0000186 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000187 ADL, /*Overload*/ true, &Args,
188 Begin, End);
John McCallf7a1a742009-11-24 19:00:30 +0000189}
190
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000191UnresolvedLookupExpr *
Douglas Gregordef03542011-02-04 12:01:24 +0000192UnresolvedLookupExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
193 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000194 std::size_t size = sizeof(UnresolvedLookupExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000195 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000196 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
197
Chris Lattner32488542010-10-30 05:14:06 +0000198 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000199 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Douglas Gregordef03542011-02-04 12:01:24 +0000200 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000201 return E;
202}
203
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000204OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000205 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000206 const DeclarationNameInfo &NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000207 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000208 UnresolvedSetIterator Begin,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000209 UnresolvedSetIterator End,
210 bool KnownDependent,
211 bool KnownContainsUnexpandedParameterPack)
212 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
213 KnownDependent,
214 (KnownContainsUnexpandedParameterPack ||
215 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor4c9be892011-02-28 20:01:57 +0000216 (QualifierLoc &&
217 QualifierLoc.getNestedNameSpecifier()
218 ->containsUnexpandedParameterPack()))),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000219 Results(0), NumResults(End - Begin), NameInfo(NameInfo),
Douglas Gregor4c9be892011-02-28 20:01:57 +0000220 QualifierLoc(QualifierLoc), HasExplicitTemplateArgs(TemplateArgs != 0)
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000221{
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000222 NumResults = End - Begin;
223 if (NumResults) {
224 // Determine whether this expression is type-dependent.
225 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
226 if ((*I)->getDeclContext()->isDependentContext() ||
227 isa<UnresolvedUsingValueDecl>(*I)) {
228 ExprBits.TypeDependent = true;
229 ExprBits.ValueDependent = true;
230 }
231 }
232
233 Results = static_cast<DeclAccessPair *>(
234 C.Allocate(sizeof(DeclAccessPair) * NumResults,
235 llvm::alignOf<DeclAccessPair>()));
236 memcpy(Results, &*Begin.getIterator(),
237 NumResults * sizeof(DeclAccessPair));
238 }
239
240 // If we have explicit template arguments, check for dependent
241 // template arguments and whether they contain any unexpanded pack
242 // expansions.
243 if (TemplateArgs) {
244 bool Dependent = false;
245 bool ContainsUnexpandedParameterPack = false;
246 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
247 ContainsUnexpandedParameterPack);
248
249 if (Dependent) {
250 ExprBits.TypeDependent = true;
251 ExprBits.ValueDependent = true;
252 }
253 if (ContainsUnexpandedParameterPack)
254 ExprBits.ContainsUnexpandedParameterPack = true;
255 }
256
257 if (isTypeDependent())
258 setType(C.DependentTy);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000259}
260
261void OverloadExpr::initializeResults(ASTContext &C,
262 UnresolvedSetIterator Begin,
263 UnresolvedSetIterator End) {
264 assert(Results == 0 && "Results already initialized!");
265 NumResults = End - Begin;
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000266 if (NumResults) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000267 Results = static_cast<DeclAccessPair *>(
268 C.Allocate(sizeof(DeclAccessPair) * NumResults,
269
270 llvm::alignOf<DeclAccessPair>()));
271 memcpy(Results, &*Begin.getIterator(),
272 NumResults * sizeof(DeclAccessPair));
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000273 }
274}
275
John McCalle9ee23e2010-04-22 18:44:12 +0000276CXXRecordDecl *OverloadExpr::getNamingClass() const {
277 if (isa<UnresolvedLookupExpr>(this))
278 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
279 else
280 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
281}
282
John McCall865d4472009-11-19 22:55:06 +0000283// DependentScopeDeclRefExpr
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000284DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000285 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000286 const DeclarationNameInfo &NameInfo,
287 const TemplateArgumentListInfo *Args)
288 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
289 true, true,
290 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000291 (QualifierLoc &&
292 QualifierLoc.getNestedNameSpecifier()
293 ->containsUnexpandedParameterPack()))),
294 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000295 HasExplicitTemplateArgs(Args != 0)
296{
297 if (Args) {
298 bool Dependent = true;
299 bool ContainsUnexpandedParameterPack
300 = ExprBits.ContainsUnexpandedParameterPack;
301
302 reinterpret_cast<ExplicitTemplateArgumentList*>(this+1)
303 ->initializeFrom(*Args, Dependent, ContainsUnexpandedParameterPack);
304 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
305 }
306}
307
John McCallf7a1a742009-11-24 19:00:30 +0000308DependentScopeDeclRefExpr *
309DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000310 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000311 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +0000312 const TemplateArgumentListInfo *Args) {
313 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCallf7a1a742009-11-24 19:00:30 +0000314 if (Args)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000315 size += ExplicitTemplateArgumentList::sizeFor(*Args);
316 void *Mem = C.Allocate(size);
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000317 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000318 NameInfo, Args);
John McCallf7a1a742009-11-24 19:00:30 +0000319}
320
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000321DependentScopeDeclRefExpr *
322DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Douglas Gregordef03542011-02-04 12:01:24 +0000323 bool HasExplicitTemplateArgs,
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000324 unsigned NumTemplateArgs) {
325 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000326 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000327 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
328 void *Mem = C.Allocate(size);
Douglas Gregordef03542011-02-04 12:01:24 +0000329 DependentScopeDeclRefExpr *E
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000330 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Douglas Gregordef03542011-02-04 12:01:24 +0000331 DeclarationNameInfo(), 0);
332 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
333 return E;
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000334}
335
Chandler Carruth428edaf2010-10-25 08:47:36 +0000336SourceRange CXXConstructExpr::getSourceRange() const {
John McCall2882eca2011-02-21 06:23:05 +0000337 if (isa<CXXTemporaryObjectExpr>(this))
338 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
339
Douglas Gregor40749ee2010-11-03 00:35:38 +0000340 if (ParenRange.isValid())
341 return SourceRange(Loc, ParenRange.getEnd());
342
343 SourceLocation End = Loc;
344 for (unsigned I = getNumArgs(); I > 0; --I) {
345 const Expr *Arg = getArg(I-1);
346 if (!Arg->isDefaultArgument()) {
347 SourceLocation NewEnd = Arg->getLocEnd();
348 if (NewEnd.isValid()) {
349 End = NewEnd;
350 break;
351 }
352 }
353 }
354
355 return SourceRange(Loc, End);
Ted Kremeneke3837682009-12-23 04:00:48 +0000356}
357
Douglas Gregorb4609802008-11-14 16:09:21 +0000358SourceRange CXXOperatorCallExpr::getSourceRange() const {
359 OverloadedOperatorKind Kind = getOperator();
360 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
361 if (getNumArgs() == 1)
362 // Prefix operator
Mike Stump1eb44332009-09-09 15:08:12 +0000363 return SourceRange(getOperatorLoc(),
Douglas Gregorb4609802008-11-14 16:09:21 +0000364 getArg(0)->getSourceRange().getEnd());
365 else
366 // Postfix operator
367 return SourceRange(getArg(0)->getSourceRange().getEnd(),
368 getOperatorLoc());
369 } else if (Kind == OO_Call) {
370 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
371 } else if (Kind == OO_Subscript) {
372 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
373 } else if (getNumArgs() == 1) {
374 return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd());
375 } else if (getNumArgs() == 2) {
376 return SourceRange(getArg(0)->getSourceRange().getBegin(),
377 getArg(1)->getSourceRange().getEnd());
378 } else {
379 return SourceRange();
380 }
381}
382
Douglas Gregor88a35142008-12-22 05:46:06 +0000383Expr *CXXMemberCallExpr::getImplicitObjectArgument() {
384 if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
385 return MemExpr->getBase();
386
387 // FIXME: Will eventually need to cope with member pointers.
388 return 0;
389}
390
Chandler Carruth007a9b12010-10-27 06:55:41 +0000391CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
392 Expr* ThisArg = getImplicitObjectArgument();
393 if (!ThisArg)
394 return 0;
395
396 if (ThisArg->getType()->isAnyPointerType())
397 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
398
399 return ThisArg->getType()->getAsCXXRecordDecl();
400}
401
Douglas Gregor00b98c22009-11-12 15:31:47 +0000402
Douglas Gregor49badde2008-10-27 19:41:14 +0000403//===----------------------------------------------------------------------===//
404// Named casts
405//===----------------------------------------------------------------------===//
406
407/// getCastName - Get the name of the C++ cast being used, e.g.,
408/// "static_cast", "dynamic_cast", "reinterpret_cast", or
409/// "const_cast". The returned pointer must not be freed.
410const char *CXXNamedCastExpr::getCastName() const {
411 switch (getStmtClass()) {
412 case CXXStaticCastExprClass: return "static_cast";
413 case CXXDynamicCastExprClass: return "dynamic_cast";
414 case CXXReinterpretCastExprClass: return "reinterpret_cast";
415 case CXXConstCastExprClass: return "const_cast";
416 default: return "<invalid cast>";
417 }
418}
Douglas Gregor506ae412009-01-16 18:33:17 +0000419
John McCallf871d0c2010-08-07 06:22:56 +0000420CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000421 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000422 CastKind K, Expr *Op,
423 const CXXCastPath *BasePath,
424 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000425 SourceLocation L,
426 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000427 unsigned PathSize = (BasePath ? BasePath->size() : 0);
428 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
429 + PathSize * sizeof(CXXBaseSpecifier*));
430 CXXStaticCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000431 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
432 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000433 if (PathSize) E->setCastPath(*BasePath);
434 return E;
435}
436
437CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
438 unsigned PathSize) {
439 void *Buffer =
440 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
441 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
442}
443
444CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000445 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000446 CastKind K, Expr *Op,
447 const CXXCastPath *BasePath,
448 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000449 SourceLocation L,
450 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000451 unsigned PathSize = (BasePath ? BasePath->size() : 0);
452 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
453 + PathSize * sizeof(CXXBaseSpecifier*));
454 CXXDynamicCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000455 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
456 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000457 if (PathSize) E->setCastPath(*BasePath);
458 return E;
459}
460
461CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
462 unsigned PathSize) {
463 void *Buffer =
464 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
465 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
466}
467
468CXXReinterpretCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000469CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
470 CastKind K, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000471 const CXXCastPath *BasePath,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000472 TypeSourceInfo *WrittenTy, SourceLocation L,
473 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000474 unsigned PathSize = (BasePath ? BasePath->size() : 0);
475 void *Buffer =
476 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
477 CXXReinterpretCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000478 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
479 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000480 if (PathSize) E->setCastPath(*BasePath);
481 return E;
482}
483
484CXXReinterpretCastExpr *
485CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
486 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
487 + PathSize * sizeof(CXXBaseSpecifier*));
488 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
489}
490
John McCallf89e55a2010-11-18 06:31:45 +0000491CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
492 ExprValueKind VK, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000493 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000494 SourceLocation L,
495 SourceLocation RParenLoc) {
496 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000497}
498
499CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
500 return new (C) CXXConstCastExpr(EmptyShell());
501}
502
503CXXFunctionalCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000504CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000505 TypeSourceInfo *Written, SourceLocation L,
506 CastKind K, Expr *Op, const CXXCastPath *BasePath,
507 SourceLocation R) {
508 unsigned PathSize = (BasePath ? BasePath->size() : 0);
509 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
510 + PathSize * sizeof(CXXBaseSpecifier*));
511 CXXFunctionalCastExpr *E =
John McCallf89e55a2010-11-18 06:31:45 +0000512 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallf871d0c2010-08-07 06:22:56 +0000513 if (PathSize) E->setCastPath(*BasePath);
514 return E;
515}
516
517CXXFunctionalCastExpr *
518CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
519 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
520 + PathSize * sizeof(CXXBaseSpecifier*));
521 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
522}
523
524
Douglas Gregor65222e82009-12-23 18:19:08 +0000525CXXDefaultArgExpr *
Douglas Gregor036aed12009-12-23 23:03:06 +0000526CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
527 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor65222e82009-12-23 18:19:08 +0000528 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor036aed12009-12-23 23:03:06 +0000529 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
530 SubExpr);
Douglas Gregor65222e82009-12-23 18:19:08 +0000531}
532
Mike Stump1eb44332009-09-09 15:08:12 +0000533CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonb859f352009-05-30 20:34:37 +0000534 const CXXDestructorDecl *Destructor) {
Anders Carlsson88eaf072009-05-30 22:38:53 +0000535 return new (C) CXXTemporary(Destructor);
536}
537
Mike Stump1eb44332009-09-09 15:08:12 +0000538CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000539 CXXTemporary *Temp,
540 Expr* SubExpr) {
Mike Stump1eb44332009-09-09 15:08:12 +0000541 assert(SubExpr->getType()->isRecordType() &&
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000542 "Expression bound to a temporary must have record type!");
543
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000544 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000545}
546
Anders Carlsson8e587a12009-05-30 20:56:46 +0000547CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000548 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000549 TypeSourceInfo *Type,
Douglas Gregor506ae412009-01-16 18:33:17 +0000550 Expr **Args,
Mike Stump1eb44332009-09-09 15:08:12 +0000551 unsigned NumArgs,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000552 SourceRange parenRange,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000553 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000554 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
555 Type->getType().getNonReferenceType(),
556 Type->getTypeLoc().getBeginLoc(),
Chandler Carruth428edaf2010-10-25 08:47:36 +0000557 Cons, false, Args, NumArgs, ZeroInitialization,
558 CXXConstructExpr::CK_Complete, parenRange),
559 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000560}
561
562SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth428edaf2010-10-25 08:47:36 +0000563 return SourceRange(Type->getTypeLoc().getBeginLoc(),
564 getParenRange().getEnd());
Douglas Gregor506ae412009-01-16 18:33:17 +0000565}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000566
Mike Stump1eb44332009-09-09 15:08:12 +0000567CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000568 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000569 CXXConstructorDecl *D, bool Elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000570 Expr **Args, unsigned NumArgs,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000571 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000572 ConstructionKind ConstructKind,
573 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000574 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000575 Elidable, Args, NumArgs, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000576 ConstructKind, ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000577}
578
Mike Stump1eb44332009-09-09 15:08:12 +0000579CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000580 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000581 CXXConstructorDecl *D, bool elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000582 Expr **args, unsigned numargs,
Anders Carlsson72e96fd2010-05-02 22:54:08 +0000583 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000584 ConstructionKind ConstructKind,
585 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000586 : Expr(SC, T, VK_RValue, OK_Ordinary,
587 T->isDependentType(), T->isDependentType(),
588 T->containsUnexpandedParameterPack()),
589 Constructor(D), Loc(Loc), ParenRange(ParenRange), Elidable(elidable),
590 ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind),
591 Args(0), NumArgs(numargs)
Douglas Gregor16006c92009-12-16 18:50:27 +0000592{
593 if (NumArgs) {
594 Args = new (C) Stmt*[NumArgs];
595
596 for (unsigned i = 0; i != NumArgs; ++i) {
597 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000598
599 if (args[i]->isValueDependent())
600 ExprBits.ValueDependent = true;
601 if (args[i]->containsUnexpandedParameterPack())
602 ExprBits.ContainsUnexpandedParameterPack = true;
603
Douglas Gregor16006c92009-12-16 18:50:27 +0000604 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000605 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000606 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000607}
608
John McCall4765fa02010-12-06 08:20:24 +0000609ExprWithCleanups::ExprWithCleanups(ASTContext &C,
610 Expr *subexpr,
611 CXXTemporary **temps,
612 unsigned numtemps)
613 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +0000614 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000615 subexpr->isTypeDependent(), subexpr->isValueDependent(),
616 subexpr->containsUnexpandedParameterPack()),
Chris Lattnerd2598362010-05-10 00:25:06 +0000617 SubExpr(subexpr), Temps(0), NumTemps(0) {
Chris Lattneraff32cb2010-05-10 00:45:12 +0000618 if (numtemps) {
Ted Kremenekd04ed412010-05-10 20:06:30 +0000619 setNumTemporaries(C, numtemps);
Chris Lattnerd2598362010-05-10 00:25:06 +0000620 for (unsigned i = 0; i != numtemps; ++i)
Anders Carlssonff6b3d62009-05-30 21:05:25 +0000621 Temps[i] = temps[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000622 }
623}
624
John McCall4765fa02010-12-06 08:20:24 +0000625void ExprWithCleanups::setNumTemporaries(ASTContext &C, unsigned N) {
Chris Lattnerd2598362010-05-10 00:25:06 +0000626 assert(Temps == 0 && "Cannot resize with this");
Daniel Dunbar90556d42010-05-10 15:59:37 +0000627 NumTemps = N;
Ted Kremenekd04ed412010-05-10 20:06:30 +0000628 Temps = new (C) CXXTemporary*[NumTemps];
Chris Lattnerd2598362010-05-10 00:25:06 +0000629}
630
631
John McCall4765fa02010-12-06 08:20:24 +0000632ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C,
633 Expr *SubExpr,
634 CXXTemporary **Temps,
635 unsigned NumTemps) {
636 return new (C) ExprWithCleanups(C, SubExpr, Temps, NumTemps);
Anders Carlsson88eaf072009-05-30 22:38:53 +0000637}
638
Douglas Gregorab6677e2010-09-08 00:15:04 +0000639CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000640 SourceLocation LParenLoc,
641 Expr **Args,
642 unsigned NumArgs,
643 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000644 : Expr(CXXUnresolvedConstructExprClass,
645 Type->getType().getNonReferenceType(),
John McCall09431682010-11-18 19:01:18 +0000646 VK_LValue, OK_Ordinary,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000647 Type->getType()->isDependentType(), true,
648 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +0000649 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000650 LParenLoc(LParenLoc),
651 RParenLoc(RParenLoc),
652 NumArgs(NumArgs) {
653 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000654 for (unsigned I = 0; I != NumArgs; ++I) {
655 if (Args[I]->containsUnexpandedParameterPack())
656 ExprBits.ContainsUnexpandedParameterPack = true;
657
658 StoredArgs[I] = Args[I];
659 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000660}
661
662CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +0000663CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000664 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000665 SourceLocation LParenLoc,
666 Expr **Args,
667 unsigned NumArgs,
668 SourceLocation RParenLoc) {
669 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
670 sizeof(Expr *) * NumArgs);
Douglas Gregorab6677e2010-09-08 00:15:04 +0000671 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000672 Args, NumArgs, RParenLoc);
673}
674
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000675CXXUnresolvedConstructExpr *
676CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
677 Stmt::EmptyShell Empty;
678 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
679 sizeof(Expr *) * NumArgs);
680 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
681}
682
Douglas Gregorab6677e2010-09-08 00:15:04 +0000683SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
684 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
685}
686
John McCall865d4472009-11-19 22:55:06 +0000687CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000688 Expr *Base, QualType BaseType,
689 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000690 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000691 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000692 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000693 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000694 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +0000695 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000696 VK_LValue, OK_Ordinary, true, true,
697 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000698 (QualifierLoc &&
699 QualifierLoc.getNestedNameSpecifier()
700 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000701 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +0000702 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
703 HasExplicitTemplateArgs(TemplateArgs != 0),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000704 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000705 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +0000706 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000707 if (TemplateArgs) {
708 bool Dependent = true;
709 bool ContainsUnexpandedParameterPack = false;
710 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
711 ContainsUnexpandedParameterPack);
712 if (ContainsUnexpandedParameterPack)
713 ExprBits.ContainsUnexpandedParameterPack = true;
714 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000715}
716
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000717CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
718 Expr *Base, QualType BaseType,
719 bool IsArrow,
720 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000721 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000722 NamedDecl *FirstQualifierFoundInScope,
723 DeclarationNameInfo MemberNameInfo)
724 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
725 VK_LValue, OK_Ordinary, true, true,
726 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000727 (QualifierLoc &&
728 QualifierLoc.getNestedNameSpecifier()->
729 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000730 MemberNameInfo.containsUnexpandedParameterPack())),
731 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
732 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000733 QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000734 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
735 MemberNameInfo(MemberNameInfo) { }
736
John McCall865d4472009-11-19 22:55:06 +0000737CXXDependentScopeMemberExpr *
738CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000739 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000740 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000741 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000742 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000743 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000744 const TemplateArgumentListInfo *TemplateArgs) {
745 if (!TemplateArgs)
John McCallaa81e162009-12-01 22:10:20 +0000746 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
747 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000748 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000749 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000750 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000751
John McCalld5532b62009-11-23 01:53:49 +0000752 std::size_t size = sizeof(CXXDependentScopeMemberExpr);
753 if (TemplateArgs)
754 size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
755
Chris Lattner32488542010-10-30 05:14:06 +0000756 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +0000757 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
758 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000759 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000760 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000761 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000762}
763
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000764CXXDependentScopeMemberExpr *
765CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Douglas Gregordef03542011-02-04 12:01:24 +0000766 bool HasExplicitTemplateArgs,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000767 unsigned NumTemplateArgs) {
Douglas Gregordef03542011-02-04 12:01:24 +0000768 if (!HasExplicitTemplateArgs)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000769 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000770 0, SourceLocation(),
771 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000772 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000773
774 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
775 ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +0000776 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000777 CXXDependentScopeMemberExpr *E
778 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000779 0, SourceLocation(),
780 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000781 DeclarationNameInfo(), 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000782 E->HasExplicitTemplateArgs = true;
783 return E;
784}
785
Douglas Gregor4c9be892011-02-28 20:01:57 +0000786bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
787 if (Base == 0)
788 return true;
789
Douglas Gregor75e85042011-03-02 21:06:53 +0000790 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +0000791}
792
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000793UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000794 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000795 Expr *Base, QualType BaseType,
796 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000797 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000798 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000799 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000800 const TemplateArgumentListInfo *TemplateArgs,
801 UnresolvedSetIterator Begin,
802 UnresolvedSetIterator End)
Douglas Gregor4c9be892011-02-28 20:01:57 +0000803 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, MemberNameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000804 TemplateArgs, Begin, End,
805 // Dependent
806 ((Base && Base->isTypeDependent()) ||
807 BaseType->isDependentType()),
808 // Contains unexpanded parameter pack
809 ((Base && Base->containsUnexpandedParameterPack()) ||
810 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +0000811 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
812 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall129e2df2009-11-30 22:42:35 +0000813}
814
Douglas Gregor4c9be892011-02-28 20:01:57 +0000815bool UnresolvedMemberExpr::isImplicitAccess() const {
816 if (Base == 0)
817 return true;
818
Douglas Gregor75e85042011-03-02 21:06:53 +0000819 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +0000820}
821
John McCall129e2df2009-11-30 22:42:35 +0000822UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000823UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000824 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000825 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000826 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000827 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000828 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000829 const TemplateArgumentListInfo *TemplateArgs,
830 UnresolvedSetIterator Begin,
831 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +0000832 std::size_t size = sizeof(UnresolvedMemberExpr);
833 if (TemplateArgs)
834 size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
835
Chris Lattner32488542010-10-30 05:14:06 +0000836 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000837 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000838 HasUnresolvedUsing, Base, BaseType,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000839 IsArrow, OperatorLoc, QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000840 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +0000841}
842
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000843UnresolvedMemberExpr *
Douglas Gregordef03542011-02-04 12:01:24 +0000844UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
845 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000846 std::size_t size = sizeof(UnresolvedMemberExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000847 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000848 size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
849
Chris Lattner32488542010-10-30 05:14:06 +0000850 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000851 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Douglas Gregordef03542011-02-04 12:01:24 +0000852 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000853 return E;
854}
855
John McCallc373d482010-01-27 01:50:18 +0000856CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
857 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
858
859 // If there was a nested name specifier, it names the naming class.
860 // It can't be dependent: after all, we were actually able to do the
861 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000862 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +0000863 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +0000864 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +0000865 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000866 Record = T->getAsCXXRecordDecl();
867 assert(Record && "qualifier in member expression does not name record");
868 }
John McCallc373d482010-01-27 01:50:18 +0000869 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000870 else {
John McCallc373d482010-01-27 01:50:18 +0000871 QualType BaseType = getBaseType().getNonReferenceType();
872 if (isArrow()) {
873 const PointerType *PT = BaseType->getAs<PointerType>();
874 assert(PT && "base of arrow member access is not pointer");
875 BaseType = PT->getPointeeType();
876 }
877
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000878 Record = BaseType->getAsCXXRecordDecl();
879 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +0000880 }
881
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000882 return Record;
John McCallc373d482010-01-27 01:50:18 +0000883}
884
Douglas Gregorc7793c72011-01-15 01:15:58 +0000885SubstNonTypeTemplateParmPackExpr::
886SubstNonTypeTemplateParmPackExpr(QualType T,
887 NonTypeTemplateParmDecl *Param,
888 SourceLocation NameLoc,
889 const TemplateArgument &ArgPack)
890 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
891 true, false, true),
892 Param(Param), Arguments(ArgPack.pack_begin()),
893 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
894
895TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
896 return TemplateArgument(Arguments, NumArguments);
897}
898
Douglas Gregorc7793c72011-01-15 01:15:58 +0000899