blob: 95b03ee1832ee06759babeea8f5d25db474892b5 [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(),
Douglas Gregor561f8122011-07-01 01:22:09 +000060 ty->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000061 ty->containsUnexpandedParameterPack()),
John McCall6ec278d2011-01-27 09:37:56 +000062 GlobalNew(globalNew), Initializer(initializer),
63 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
64 SubExprs(0), OperatorNew(operatorNew),
Sebastian Redlcee63fb2008-12-02 14:43:59 +000065 OperatorDelete(operatorDelete), Constructor(constructor),
Douglas Gregor1bb2a932010-09-07 21:49:58 +000066 AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens),
Chandler Carruth428edaf2010-10-25 08:47:36 +000067 StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen),
68 ConstructorRParen(constructorRParen) {
Chris Lattner59218632010-05-10 01:22:27 +000069 AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs);
Sebastian Redl4c5d3202008-11-21 19:14:01 +000070 unsigned i = 0;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000071 if (Array) {
Douglas Gregor561f8122011-07-01 01:22:09 +000072 if (arraySize->isInstantiationDependent())
73 ExprBits.InstantiationDependent = true;
74
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000075 if (arraySize->containsUnexpandedParameterPack())
76 ExprBits.ContainsUnexpandedParameterPack = true;
77
Sebastian Redlcee63fb2008-12-02 14:43:59 +000078 SubExprs[i++] = arraySize;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000079 }
80
81 for (unsigned j = 0; j < NumPlacementArgs; ++j) {
Douglas Gregor561f8122011-07-01 01:22:09 +000082 if (placementArgs[j]->isInstantiationDependent())
83 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000084 if (placementArgs[j]->containsUnexpandedParameterPack())
85 ExprBits.ContainsUnexpandedParameterPack = true;
86
Sebastian Redl4c5d3202008-11-21 19:14:01 +000087 SubExprs[i++] = placementArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000088 }
89
90 for (unsigned j = 0; j < NumConstructorArgs; ++j) {
Douglas Gregor561f8122011-07-01 01:22:09 +000091 if (constructorArgs[j]->isInstantiationDependent())
92 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000093 if (constructorArgs[j]->containsUnexpandedParameterPack())
94 ExprBits.ContainsUnexpandedParameterPack = true;
95
Sebastian Redl4c5d3202008-11-21 19:14:01 +000096 SubExprs[i++] = constructorArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000097 }
Sebastian Redl4c5d3202008-11-21 19:14:01 +000098}
99
Chris Lattner59218632010-05-10 01:22:27 +0000100void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
101 unsigned numPlaceArgs, unsigned numConsArgs){
102 assert(SubExprs == 0 && "SubExprs already allocated");
103 Array = isArray;
104 NumPlacementArgs = numPlaceArgs;
105 NumConstructorArgs = numConsArgs;
106
107 unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs;
108 SubExprs = new (C) Stmt*[TotalSize];
109}
110
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000111bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCallc2f3e7f2011-03-07 03:12:35 +0000112 return getOperatorNew()->getType()->
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000113 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCallc2f3e7f2011-03-07 03:12:35 +0000114}
Chris Lattner59218632010-05-10 01:22:27 +0000115
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000116// CXXDeleteExpr
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000117QualType CXXDeleteExpr::getDestroyedType() const {
118 const Expr *Arg = getArgument();
119 while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
120 if (ICE->getCastKind() != CK_UserDefinedConversion &&
121 ICE->getType()->isVoidPointerType())
122 Arg = ICE->getSubExpr();
123 else
124 break;
125 }
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000126 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silversteinc87fa062010-10-20 00:56:01 +0000127 const QualType ArgType = Arg->getType();
Craig Silversteina437ad32010-11-16 07:16:25 +0000128
129 if (ArgType->isDependentType() && !ArgType->isPointerType())
130 return QualType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000131
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000132 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000133}
134
Douglas Gregora71d8192009-09-04 17:36:40 +0000135// CXXPseudoDestructorExpr
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000136PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
137 : Type(Info)
138{
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000139 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000140}
141
John McCalle23cf432010-12-14 08:05:40 +0000142CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000143 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
144 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
145 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
146 PseudoDestructorTypeStorage DestroyedType)
John McCalle23cf432010-12-14 08:05:40 +0000147 : Expr(CXXPseudoDestructorExprClass,
148 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
149 FunctionProtoType::ExtProtoInfo())),
150 VK_RValue, OK_Ordinary,
151 /*isTypeDependent=*/(Base->isTypeDependent() ||
152 (DestroyedType.getTypeSourceInfo() &&
153 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000154 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000155 (Base->isInstantiationDependent() ||
156 (QualifierLoc &&
157 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
158 (ScopeType &&
159 ScopeType->getType()->isInstantiationDependentType()) ||
160 (DestroyedType.getTypeSourceInfo() &&
161 DestroyedType.getTypeSourceInfo()->getType()
162 ->isInstantiationDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000163 // ContainsUnexpandedParameterPack
164 (Base->containsUnexpandedParameterPack() ||
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000165 (QualifierLoc &&
166 QualifierLoc.getNestedNameSpecifier()
167 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000168 (ScopeType &&
169 ScopeType->getType()->containsUnexpandedParameterPack()) ||
170 (DestroyedType.getTypeSourceInfo() &&
171 DestroyedType.getTypeSourceInfo()->getType()
172 ->containsUnexpandedParameterPack()))),
John McCalle23cf432010-12-14 08:05:40 +0000173 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000174 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalle23cf432010-12-14 08:05:40 +0000175 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
176 DestroyedType(DestroyedType) { }
177
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000178QualType CXXPseudoDestructorExpr::getDestroyedType() const {
179 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
180 return TInfo->getType();
181
182 return QualType();
183}
184
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000185SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000186 SourceLocation End = DestroyedType.getLocation();
187 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000188 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000189 return SourceRange(Base->getLocStart(), End);
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000190}
191
192
John McCallba135432009-11-21 08:51:07 +0000193// UnresolvedLookupExpr
John McCallf7a1a742009-11-24 19:00:30 +0000194UnresolvedLookupExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000195UnresolvedLookupExpr::Create(ASTContext &C,
John McCallc373d482010-01-27 01:50:18 +0000196 CXXRecordDecl *NamingClass,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000197 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000198 const DeclarationNameInfo &NameInfo,
199 bool ADL,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000200 const TemplateArgumentListInfo &Args,
201 UnresolvedSetIterator Begin,
202 UnresolvedSetIterator End)
John McCallf7a1a742009-11-24 19:00:30 +0000203{
204 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000205 ASTTemplateArgumentListInfo::sizeFor(Args));
Douglas Gregor4c9be892011-02-28 20:01:57 +0000206 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000207 ADL, /*Overload*/ true, &Args,
Richard Smithad762fc2011-04-14 22:09:26 +0000208 Begin, End, /*StdIsAssociated=*/false);
John McCallf7a1a742009-11-24 19:00:30 +0000209}
210
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000211UnresolvedLookupExpr *
Douglas Gregordef03542011-02-04 12:01:24 +0000212UnresolvedLookupExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
213 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000214 std::size_t size = sizeof(UnresolvedLookupExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000215 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000216 size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000217
Chris Lattner32488542010-10-30 05:14:06 +0000218 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000219 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Douglas Gregordef03542011-02-04 12:01:24 +0000220 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000221 return E;
222}
223
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000224OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000225 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000226 const DeclarationNameInfo &NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000227 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000228 UnresolvedSetIterator Begin,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000229 UnresolvedSetIterator End,
230 bool KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000231 bool KnownInstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000232 bool KnownContainsUnexpandedParameterPack)
233 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
234 KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000235 (KnownInstantiationDependent ||
236 NameInfo.isInstantiationDependent() ||
237 (QualifierLoc &&
238 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000239 (KnownContainsUnexpandedParameterPack ||
240 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor4c9be892011-02-28 20:01:57 +0000241 (QualifierLoc &&
242 QualifierLoc.getNestedNameSpecifier()
243 ->containsUnexpandedParameterPack()))),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000244 Results(0), NumResults(End - Begin), NameInfo(NameInfo),
Douglas Gregor4c9be892011-02-28 20:01:57 +0000245 QualifierLoc(QualifierLoc), HasExplicitTemplateArgs(TemplateArgs != 0)
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000246{
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000247 NumResults = End - Begin;
248 if (NumResults) {
249 // Determine whether this expression is type-dependent.
250 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
251 if ((*I)->getDeclContext()->isDependentContext() ||
252 isa<UnresolvedUsingValueDecl>(*I)) {
253 ExprBits.TypeDependent = true;
254 ExprBits.ValueDependent = true;
255 }
256 }
257
258 Results = static_cast<DeclAccessPair *>(
259 C.Allocate(sizeof(DeclAccessPair) * NumResults,
260 llvm::alignOf<DeclAccessPair>()));
261 memcpy(Results, &*Begin.getIterator(),
262 NumResults * sizeof(DeclAccessPair));
263 }
264
265 // If we have explicit template arguments, check for dependent
266 // template arguments and whether they contain any unexpanded pack
267 // expansions.
268 if (TemplateArgs) {
269 bool Dependent = false;
Douglas Gregor561f8122011-07-01 01:22:09 +0000270 bool InstantiationDependent = false;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000271 bool ContainsUnexpandedParameterPack = false;
272 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000273 InstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000274 ContainsUnexpandedParameterPack);
275
276 if (Dependent) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000277 ExprBits.TypeDependent = true;
278 ExprBits.ValueDependent = true;
279 }
280 if (InstantiationDependent)
281 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000282 if (ContainsUnexpandedParameterPack)
283 ExprBits.ContainsUnexpandedParameterPack = true;
284 }
285
286 if (isTypeDependent())
287 setType(C.DependentTy);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000288}
289
290void OverloadExpr::initializeResults(ASTContext &C,
291 UnresolvedSetIterator Begin,
292 UnresolvedSetIterator End) {
293 assert(Results == 0 && "Results already initialized!");
294 NumResults = End - Begin;
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000295 if (NumResults) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000296 Results = static_cast<DeclAccessPair *>(
297 C.Allocate(sizeof(DeclAccessPair) * NumResults,
298
299 llvm::alignOf<DeclAccessPair>()));
300 memcpy(Results, &*Begin.getIterator(),
301 NumResults * sizeof(DeclAccessPair));
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000302 }
303}
304
John McCalle9ee23e2010-04-22 18:44:12 +0000305CXXRecordDecl *OverloadExpr::getNamingClass() const {
306 if (isa<UnresolvedLookupExpr>(this))
307 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
308 else
309 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
310}
311
John McCall865d4472009-11-19 22:55:06 +0000312// DependentScopeDeclRefExpr
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000313DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000314 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000315 const DeclarationNameInfo &NameInfo,
316 const TemplateArgumentListInfo *Args)
317 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
318 true, true,
Douglas Gregor561f8122011-07-01 01:22:09 +0000319 (NameInfo.isInstantiationDependent() ||
320 (QualifierLoc &&
321 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000322 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000323 (QualifierLoc &&
324 QualifierLoc.getNestedNameSpecifier()
325 ->containsUnexpandedParameterPack()))),
326 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000327 HasExplicitTemplateArgs(Args != 0)
328{
329 if (Args) {
330 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000331 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000332 bool ContainsUnexpandedParameterPack
333 = ExprBits.ContainsUnexpandedParameterPack;
334
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000335 reinterpret_cast<ASTTemplateArgumentListInfo*>(this+1)
Douglas Gregor561f8122011-07-01 01:22:09 +0000336 ->initializeFrom(*Args, Dependent, InstantiationDependent,
337 ContainsUnexpandedParameterPack);
338
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000339 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
340 }
341}
342
John McCallf7a1a742009-11-24 19:00:30 +0000343DependentScopeDeclRefExpr *
344DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000345 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000346 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +0000347 const TemplateArgumentListInfo *Args) {
348 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCallf7a1a742009-11-24 19:00:30 +0000349 if (Args)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000350 size += ASTTemplateArgumentListInfo::sizeFor(*Args);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000351 void *Mem = C.Allocate(size);
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000352 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000353 NameInfo, Args);
John McCallf7a1a742009-11-24 19:00:30 +0000354}
355
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000356DependentScopeDeclRefExpr *
357DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Douglas Gregordef03542011-02-04 12:01:24 +0000358 bool HasExplicitTemplateArgs,
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000359 unsigned NumTemplateArgs) {
360 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000361 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000362 size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000363 void *Mem = C.Allocate(size);
Douglas Gregordef03542011-02-04 12:01:24 +0000364 DependentScopeDeclRefExpr *E
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000365 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Douglas Gregordef03542011-02-04 12:01:24 +0000366 DeclarationNameInfo(), 0);
367 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
368 return E;
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000369}
370
Chandler Carruth428edaf2010-10-25 08:47:36 +0000371SourceRange CXXConstructExpr::getSourceRange() const {
John McCall2882eca2011-02-21 06:23:05 +0000372 if (isa<CXXTemporaryObjectExpr>(this))
373 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
374
Douglas Gregor40749ee2010-11-03 00:35:38 +0000375 if (ParenRange.isValid())
376 return SourceRange(Loc, ParenRange.getEnd());
377
378 SourceLocation End = Loc;
379 for (unsigned I = getNumArgs(); I > 0; --I) {
380 const Expr *Arg = getArg(I-1);
381 if (!Arg->isDefaultArgument()) {
382 SourceLocation NewEnd = Arg->getLocEnd();
383 if (NewEnd.isValid()) {
384 End = NewEnd;
385 break;
386 }
387 }
388 }
389
390 return SourceRange(Loc, End);
Ted Kremeneke3837682009-12-23 04:00:48 +0000391}
392
Douglas Gregorb4609802008-11-14 16:09:21 +0000393SourceRange CXXOperatorCallExpr::getSourceRange() const {
394 OverloadedOperatorKind Kind = getOperator();
395 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
396 if (getNumArgs() == 1)
397 // Prefix operator
Mike Stump1eb44332009-09-09 15:08:12 +0000398 return SourceRange(getOperatorLoc(),
Douglas Gregorb4609802008-11-14 16:09:21 +0000399 getArg(0)->getSourceRange().getEnd());
400 else
401 // Postfix operator
Chandler Carruthd7650612011-04-02 09:47:38 +0000402 return SourceRange(getArg(0)->getSourceRange().getBegin(),
Douglas Gregorb4609802008-11-14 16:09:21 +0000403 getOperatorLoc());
Chandler Carruthd7650612011-04-02 09:47:38 +0000404 } else if (Kind == OO_Arrow) {
405 return getArg(0)->getSourceRange();
Douglas Gregorb4609802008-11-14 16:09:21 +0000406 } else if (Kind == OO_Call) {
407 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
408 } else if (Kind == OO_Subscript) {
409 return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
410 } else if (getNumArgs() == 1) {
411 return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd());
412 } else if (getNumArgs() == 2) {
413 return SourceRange(getArg(0)->getSourceRange().getBegin(),
414 getArg(1)->getSourceRange().getEnd());
415 } else {
416 return SourceRange();
417 }
418}
419
Ted Kremenekb2771592011-03-30 17:41:19 +0000420Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
421 if (const MemberExpr *MemExpr =
422 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
Douglas Gregor88a35142008-12-22 05:46:06 +0000423 return MemExpr->getBase();
424
425 // FIXME: Will eventually need to cope with member pointers.
426 return 0;
427}
428
Ted Kremenekb2771592011-03-30 17:41:19 +0000429CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
430 if (const MemberExpr *MemExpr =
431 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
432 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
433
434 // FIXME: Will eventually need to cope with member pointers.
435 return 0;
436}
437
438
Chandler Carruth007a9b12010-10-27 06:55:41 +0000439CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
440 Expr* ThisArg = getImplicitObjectArgument();
441 if (!ThisArg)
442 return 0;
443
444 if (ThisArg->getType()->isAnyPointerType())
445 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
446
447 return ThisArg->getType()->getAsCXXRecordDecl();
448}
449
Douglas Gregor00b98c22009-11-12 15:31:47 +0000450
Douglas Gregor49badde2008-10-27 19:41:14 +0000451//===----------------------------------------------------------------------===//
452// Named casts
453//===----------------------------------------------------------------------===//
454
455/// getCastName - Get the name of the C++ cast being used, e.g.,
456/// "static_cast", "dynamic_cast", "reinterpret_cast", or
457/// "const_cast". The returned pointer must not be freed.
458const char *CXXNamedCastExpr::getCastName() const {
459 switch (getStmtClass()) {
460 case CXXStaticCastExprClass: return "static_cast";
461 case CXXDynamicCastExprClass: return "dynamic_cast";
462 case CXXReinterpretCastExprClass: return "reinterpret_cast";
463 case CXXConstCastExprClass: return "const_cast";
464 default: return "<invalid cast>";
465 }
466}
Douglas Gregor506ae412009-01-16 18:33:17 +0000467
John McCallf871d0c2010-08-07 06:22:56 +0000468CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000469 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000470 CastKind K, Expr *Op,
471 const CXXCastPath *BasePath,
472 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000473 SourceLocation L,
474 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000475 unsigned PathSize = (BasePath ? BasePath->size() : 0);
476 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
477 + PathSize * sizeof(CXXBaseSpecifier*));
478 CXXStaticCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000479 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
480 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000481 if (PathSize) E->setCastPath(*BasePath);
482 return E;
483}
484
485CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
486 unsigned PathSize) {
487 void *Buffer =
488 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
489 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
490}
491
492CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000493 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000494 CastKind K, Expr *Op,
495 const CXXCastPath *BasePath,
496 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000497 SourceLocation L,
498 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000499 unsigned PathSize = (BasePath ? BasePath->size() : 0);
500 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
501 + PathSize * sizeof(CXXBaseSpecifier*));
502 CXXDynamicCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000503 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
504 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000505 if (PathSize) E->setCastPath(*BasePath);
506 return E;
507}
508
509CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
510 unsigned PathSize) {
511 void *Buffer =
512 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
513 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
514}
515
Anders Carlsson0fee3302011-04-11 01:43:55 +0000516/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
517/// to always be null. For example:
518///
519/// struct A { };
520/// struct B final : A { };
521/// struct C { };
522///
523/// C *f(B* b) { return dynamic_cast<C*>(b); }
524bool CXXDynamicCastExpr::isAlwaysNull() const
525{
526 QualType SrcType = getSubExpr()->getType();
527 QualType DestType = getType();
528
529 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
530 SrcType = SrcPTy->getPointeeType();
531 DestType = DestType->castAs<PointerType>()->getPointeeType();
532 }
533
534 const CXXRecordDecl *SrcRD =
535 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
536
537 if (!SrcRD->hasAttr<FinalAttr>())
538 return false;
539
540 const CXXRecordDecl *DestRD =
541 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
542
543 return !DestRD->isDerivedFrom(SrcRD);
544}
545
John McCallf871d0c2010-08-07 06:22:56 +0000546CXXReinterpretCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000547CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
548 CastKind K, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000549 const CXXCastPath *BasePath,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000550 TypeSourceInfo *WrittenTy, SourceLocation L,
551 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000552 unsigned PathSize = (BasePath ? BasePath->size() : 0);
553 void *Buffer =
554 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
555 CXXReinterpretCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000556 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
557 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000558 if (PathSize) E->setCastPath(*BasePath);
559 return E;
560}
561
562CXXReinterpretCastExpr *
563CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
564 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
565 + PathSize * sizeof(CXXBaseSpecifier*));
566 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
567}
568
John McCallf89e55a2010-11-18 06:31:45 +0000569CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
570 ExprValueKind VK, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000571 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000572 SourceLocation L,
573 SourceLocation RParenLoc) {
574 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000575}
576
577CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
578 return new (C) CXXConstCastExpr(EmptyShell());
579}
580
581CXXFunctionalCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000582CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000583 TypeSourceInfo *Written, SourceLocation L,
584 CastKind K, Expr *Op, const CXXCastPath *BasePath,
585 SourceLocation R) {
586 unsigned PathSize = (BasePath ? BasePath->size() : 0);
587 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
588 + PathSize * sizeof(CXXBaseSpecifier*));
589 CXXFunctionalCastExpr *E =
John McCallf89e55a2010-11-18 06:31:45 +0000590 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallf871d0c2010-08-07 06:22:56 +0000591 if (PathSize) E->setCastPath(*BasePath);
592 return E;
593}
594
595CXXFunctionalCastExpr *
596CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
597 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
598 + PathSize * sizeof(CXXBaseSpecifier*));
599 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
600}
601
602
Douglas Gregor65222e82009-12-23 18:19:08 +0000603CXXDefaultArgExpr *
Douglas Gregor036aed12009-12-23 23:03:06 +0000604CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
605 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor65222e82009-12-23 18:19:08 +0000606 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor036aed12009-12-23 23:03:06 +0000607 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
608 SubExpr);
Douglas Gregor65222e82009-12-23 18:19:08 +0000609}
610
Mike Stump1eb44332009-09-09 15:08:12 +0000611CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonb859f352009-05-30 20:34:37 +0000612 const CXXDestructorDecl *Destructor) {
Anders Carlsson88eaf072009-05-30 22:38:53 +0000613 return new (C) CXXTemporary(Destructor);
614}
615
Mike Stump1eb44332009-09-09 15:08:12 +0000616CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000617 CXXTemporary *Temp,
618 Expr* SubExpr) {
Mike Stump1eb44332009-09-09 15:08:12 +0000619 assert(SubExpr->getType()->isRecordType() &&
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000620 "Expression bound to a temporary must have record type!");
621
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000622 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000623}
624
Anders Carlsson8e587a12009-05-30 20:56:46 +0000625CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000626 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000627 TypeSourceInfo *Type,
Douglas Gregor506ae412009-01-16 18:33:17 +0000628 Expr **Args,
Mike Stump1eb44332009-09-09 15:08:12 +0000629 unsigned NumArgs,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000630 SourceRange parenRange,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000631 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000632 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
633 Type->getType().getNonReferenceType(),
634 Type->getTypeLoc().getBeginLoc(),
Chandler Carruth428edaf2010-10-25 08:47:36 +0000635 Cons, false, Args, NumArgs, ZeroInitialization,
636 CXXConstructExpr::CK_Complete, parenRange),
637 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000638}
639
640SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth428edaf2010-10-25 08:47:36 +0000641 return SourceRange(Type->getTypeLoc().getBeginLoc(),
642 getParenRange().getEnd());
Douglas Gregor506ae412009-01-16 18:33:17 +0000643}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000644
Mike Stump1eb44332009-09-09 15:08:12 +0000645CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000646 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000647 CXXConstructorDecl *D, bool Elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000648 Expr **Args, unsigned NumArgs,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000649 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000650 ConstructionKind ConstructKind,
651 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000652 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000653 Elidable, Args, NumArgs, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000654 ConstructKind, ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000655}
656
Mike Stump1eb44332009-09-09 15:08:12 +0000657CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000658 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000659 CXXConstructorDecl *D, bool elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +0000660 Expr **args, unsigned numargs,
Anders Carlsson72e96fd2010-05-02 22:54:08 +0000661 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000662 ConstructionKind ConstructKind,
663 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000664 : Expr(SC, T, VK_RValue, OK_Ordinary,
665 T->isDependentType(), T->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000666 T->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000667 T->containsUnexpandedParameterPack()),
Douglas Gregora48e6762011-09-26 14:47:03 +0000668 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(numargs),
669 Elidable(elidable), ZeroInitialization(ZeroInitialization),
670 ConstructKind(ConstructKind), Args(0)
Douglas Gregor16006c92009-12-16 18:50:27 +0000671{
672 if (NumArgs) {
673 Args = new (C) Stmt*[NumArgs];
674
675 for (unsigned i = 0; i != NumArgs; ++i) {
676 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000677
678 if (args[i]->isValueDependent())
679 ExprBits.ValueDependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000680 if (args[i]->isInstantiationDependent())
681 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000682 if (args[i]->containsUnexpandedParameterPack())
683 ExprBits.ContainsUnexpandedParameterPack = true;
684
Douglas Gregor16006c92009-12-16 18:50:27 +0000685 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000686 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000687 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000688}
689
John McCall4765fa02010-12-06 08:20:24 +0000690ExprWithCleanups::ExprWithCleanups(ASTContext &C,
691 Expr *subexpr,
692 CXXTemporary **temps,
693 unsigned numtemps)
694 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +0000695 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000696 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000697 subexpr->isInstantiationDependent(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000698 subexpr->containsUnexpandedParameterPack()),
Chris Lattnerd2598362010-05-10 00:25:06 +0000699 SubExpr(subexpr), Temps(0), NumTemps(0) {
Chris Lattneraff32cb2010-05-10 00:45:12 +0000700 if (numtemps) {
Ted Kremenekd04ed412010-05-10 20:06:30 +0000701 setNumTemporaries(C, numtemps);
Chris Lattnerd2598362010-05-10 00:25:06 +0000702 for (unsigned i = 0; i != numtemps; ++i)
Anders Carlssonff6b3d62009-05-30 21:05:25 +0000703 Temps[i] = temps[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000704 }
705}
706
John McCall4765fa02010-12-06 08:20:24 +0000707void ExprWithCleanups::setNumTemporaries(ASTContext &C, unsigned N) {
Chris Lattnerd2598362010-05-10 00:25:06 +0000708 assert(Temps == 0 && "Cannot resize with this");
Daniel Dunbar90556d42010-05-10 15:59:37 +0000709 NumTemps = N;
Ted Kremenekd04ed412010-05-10 20:06:30 +0000710 Temps = new (C) CXXTemporary*[NumTemps];
Chris Lattnerd2598362010-05-10 00:25:06 +0000711}
712
713
John McCall4765fa02010-12-06 08:20:24 +0000714ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C,
715 Expr *SubExpr,
716 CXXTemporary **Temps,
717 unsigned NumTemps) {
718 return new (C) ExprWithCleanups(C, SubExpr, Temps, NumTemps);
Anders Carlsson88eaf072009-05-30 22:38:53 +0000719}
720
Douglas Gregorab6677e2010-09-08 00:15:04 +0000721CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000722 SourceLocation LParenLoc,
723 Expr **Args,
724 unsigned NumArgs,
725 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000726 : Expr(CXXUnresolvedConstructExprClass,
727 Type->getType().getNonReferenceType(),
Douglas Gregor032c8692011-07-08 15:50:43 +0000728 (Type->getType()->isLValueReferenceType() ? VK_LValue
729 :Type->getType()->isRValueReferenceType()? VK_XValue
730 :VK_RValue),
731 OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +0000732 Type->getType()->isDependentType(), true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000733 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +0000734 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000735 LParenLoc(LParenLoc),
736 RParenLoc(RParenLoc),
737 NumArgs(NumArgs) {
738 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000739 for (unsigned I = 0; I != NumArgs; ++I) {
740 if (Args[I]->containsUnexpandedParameterPack())
741 ExprBits.ContainsUnexpandedParameterPack = true;
742
743 StoredArgs[I] = Args[I];
744 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000745}
746
747CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +0000748CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000749 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000750 SourceLocation LParenLoc,
751 Expr **Args,
752 unsigned NumArgs,
753 SourceLocation RParenLoc) {
754 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
755 sizeof(Expr *) * NumArgs);
Douglas Gregorab6677e2010-09-08 00:15:04 +0000756 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc,
Douglas Gregord81e6ca2009-05-20 18:46:25 +0000757 Args, NumArgs, RParenLoc);
758}
759
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000760CXXUnresolvedConstructExpr *
761CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
762 Stmt::EmptyShell Empty;
763 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
764 sizeof(Expr *) * NumArgs);
765 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
766}
767
Douglas Gregorab6677e2010-09-08 00:15:04 +0000768SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
769 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
770}
771
John McCall865d4472009-11-19 22:55:06 +0000772CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000773 Expr *Base, QualType BaseType,
774 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000775 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000776 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000777 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000778 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000779 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +0000780 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +0000781 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000782 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000783 (QualifierLoc &&
784 QualifierLoc.getNestedNameSpecifier()
785 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000786 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +0000787 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
788 HasExplicitTemplateArgs(TemplateArgs != 0),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000789 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000790 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +0000791 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000792 if (TemplateArgs) {
793 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000794 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000795 bool ContainsUnexpandedParameterPack = false;
796 getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000797 InstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000798 ContainsUnexpandedParameterPack);
799 if (ContainsUnexpandedParameterPack)
800 ExprBits.ContainsUnexpandedParameterPack = true;
801 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000802}
803
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000804CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
805 Expr *Base, QualType BaseType,
806 bool IsArrow,
807 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000808 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000809 NamedDecl *FirstQualifierFoundInScope,
810 DeclarationNameInfo MemberNameInfo)
811 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +0000812 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000813 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000814 (QualifierLoc &&
815 QualifierLoc.getNestedNameSpecifier()->
816 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000817 MemberNameInfo.containsUnexpandedParameterPack())),
818 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
819 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000820 QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000821 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
822 MemberNameInfo(MemberNameInfo) { }
823
John McCall865d4472009-11-19 22:55:06 +0000824CXXDependentScopeMemberExpr *
825CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +0000826 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000827 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000828 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000829 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000830 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +0000831 const TemplateArgumentListInfo *TemplateArgs) {
832 if (!TemplateArgs)
John McCallaa81e162009-12-01 22:10:20 +0000833 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
834 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000835 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000836 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000837 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000838
John McCalld5532b62009-11-23 01:53:49 +0000839 std::size_t size = sizeof(CXXDependentScopeMemberExpr);
840 if (TemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000841 size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs);
John McCalld5532b62009-11-23 01:53:49 +0000842
Chris Lattner32488542010-10-30 05:14:06 +0000843 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +0000844 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
845 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000846 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +0000847 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +0000848 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000849}
850
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000851CXXDependentScopeMemberExpr *
852CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Douglas Gregordef03542011-02-04 12:01:24 +0000853 bool HasExplicitTemplateArgs,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000854 unsigned NumTemplateArgs) {
Douglas Gregordef03542011-02-04 12:01:24 +0000855 if (!HasExplicitTemplateArgs)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000856 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000857 0, SourceLocation(),
858 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000859 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000860
861 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000862 ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +0000863 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000864 CXXDependentScopeMemberExpr *E
865 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +0000866 0, SourceLocation(),
867 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +0000868 DeclarationNameInfo(), 0);
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +0000869 E->HasExplicitTemplateArgs = true;
870 return E;
871}
872
Douglas Gregor4c9be892011-02-28 20:01:57 +0000873bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
874 if (Base == 0)
875 return true;
876
Douglas Gregor75e85042011-03-02 21:06:53 +0000877 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +0000878}
879
John McCall864c0412011-04-26 20:42:42 +0000880static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
881 UnresolvedSetIterator end) {
882 do {
883 NamedDecl *decl = *begin;
884 if (isa<UnresolvedUsingValueDecl>(decl))
885 return false;
886 if (isa<UsingShadowDecl>(decl))
887 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
888
889 // Unresolved member expressions should only contain methods and
890 // method templates.
891 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
892
893 if (isa<FunctionTemplateDecl>(decl))
894 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
895 if (cast<CXXMethodDecl>(decl)->isStatic())
896 return false;
897 } while (++begin != end);
898
899 return true;
900}
901
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000902UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000903 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000904 Expr *Base, QualType BaseType,
905 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000906 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000907 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000908 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000909 const TemplateArgumentListInfo *TemplateArgs,
910 UnresolvedSetIterator Begin,
911 UnresolvedSetIterator End)
Douglas Gregor4c9be892011-02-28 20:01:57 +0000912 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, MemberNameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000913 TemplateArgs, Begin, End,
914 // Dependent
915 ((Base && Base->isTypeDependent()) ||
916 BaseType->isDependentType()),
Douglas Gregor561f8122011-07-01 01:22:09 +0000917 ((Base && Base->isInstantiationDependent()) ||
918 BaseType->isInstantiationDependentType()),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000919 // Contains unexpanded parameter pack
920 ((Base && Base->containsUnexpandedParameterPack()) ||
921 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +0000922 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
923 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall864c0412011-04-26 20:42:42 +0000924
925 // Check whether all of the members are non-static member functions,
926 // and if so, mark give this bound-member type instead of overload type.
927 if (hasOnlyNonStaticMemberFunctions(Begin, End))
928 setType(C.BoundMemberTy);
John McCall129e2df2009-11-30 22:42:35 +0000929}
930
Douglas Gregor4c9be892011-02-28 20:01:57 +0000931bool UnresolvedMemberExpr::isImplicitAccess() const {
932 if (Base == 0)
933 return true;
934
Douglas Gregor75e85042011-03-02 21:06:53 +0000935 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +0000936}
937
John McCall129e2df2009-11-30 22:42:35 +0000938UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000939UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +0000940 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +0000941 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +0000942 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000943 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000944 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +0000945 const TemplateArgumentListInfo *TemplateArgs,
946 UnresolvedSetIterator Begin,
947 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +0000948 std::size_t size = sizeof(UnresolvedMemberExpr);
949 if (TemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000950 size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs);
John McCall129e2df2009-11-30 22:42:35 +0000951
Chris Lattner32488542010-10-30 05:14:06 +0000952 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000953 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000954 HasUnresolvedUsing, Base, BaseType,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000955 IsArrow, OperatorLoc, QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000956 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +0000957}
958
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000959UnresolvedMemberExpr *
Douglas Gregordef03542011-02-04 12:01:24 +0000960UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
961 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000962 std::size_t size = sizeof(UnresolvedMemberExpr);
Douglas Gregordef03542011-02-04 12:01:24 +0000963 if (HasExplicitTemplateArgs)
Argyrios Kyrtzidisb0c3e092011-09-22 20:07:03 +0000964 size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000965
Chris Lattner32488542010-10-30 05:14:06 +0000966 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000967 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Douglas Gregordef03542011-02-04 12:01:24 +0000968 E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000969 return E;
970}
971
John McCallc373d482010-01-27 01:50:18 +0000972CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
973 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
974
975 // If there was a nested name specifier, it names the naming class.
976 // It can't be dependent: after all, we were actually able to do the
977 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000978 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +0000979 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +0000980 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +0000981 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000982 Record = T->getAsCXXRecordDecl();
983 assert(Record && "qualifier in member expression does not name record");
984 }
John McCallc373d482010-01-27 01:50:18 +0000985 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000986 else {
John McCallc373d482010-01-27 01:50:18 +0000987 QualType BaseType = getBaseType().getNonReferenceType();
988 if (isArrow()) {
989 const PointerType *PT = BaseType->getAs<PointerType>();
990 assert(PT && "base of arrow member access is not pointer");
991 BaseType = PT->getPointeeType();
992 }
993
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000994 Record = BaseType->getAsCXXRecordDecl();
995 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +0000996 }
997
Douglas Gregorc96be1e2010-04-27 18:19:34 +0000998 return Record;
John McCallc373d482010-01-27 01:50:18 +0000999}
1000
Douglas Gregorc7793c72011-01-15 01:15:58 +00001001SubstNonTypeTemplateParmPackExpr::
1002SubstNonTypeTemplateParmPackExpr(QualType T,
1003 NonTypeTemplateParmDecl *Param,
1004 SourceLocation NameLoc,
1005 const TemplateArgument &ArgPack)
1006 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001007 true, true, true, true),
Douglas Gregorc7793c72011-01-15 01:15:58 +00001008 Param(Param), Arguments(ArgPack.pack_begin()),
1009 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1010
1011TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1012 return TemplateArgument(Arguments, NumArguments);
1013}
1014
Douglas Gregorc7793c72011-01-15 01:15:58 +00001015