blob: 9758b607279c5295f418ab1c2b1f40ce9916633c [file] [log] [blame]
Ted Kremeneke3a0c142007-08-24 20:21:10 +00001//===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremeneke3a0c142007-08-24 20:21:10 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the subclesses of Expr class declared in ExprCXX.h
11//
12//===----------------------------------------------------------------------===//
13
Douglas Gregor993603d2008-11-14 16:09:21 +000014#include "clang/Basic/IdentifierTable.h"
Benjamin Kramer4ab984e2012-07-04 20:19:54 +000015#include "clang/AST/ASTContext.h"
Douglas Gregor993603d2008-11-14 16:09:21 +000016#include "clang/AST/DeclCXX.h"
Douglas Gregora727cb92009-06-30 22:34:41 +000017#include "clang/AST/DeclTemplate.h"
Ted Kremeneke3a0c142007-08-24 20:21:10 +000018#include "clang/AST/ExprCXX.h"
Douglas Gregor651fe5e2010-02-24 23:40:28 +000019#include "clang/AST/TypeLoc.h"
Ted Kremeneke3a0c142007-08-24 20:21:10 +000020using namespace clang;
21
Douglas Gregor9da64192010-04-26 22:37:10 +000022
Ted Kremeneke3a0c142007-08-24 20:21:10 +000023//===----------------------------------------------------------------------===//
24// Child Iterators for iterating over subexpressions/substatements
25//===----------------------------------------------------------------------===//
26
Richard Smithef8bf432012-08-13 20:08:14 +000027bool CXXTypeidExpr::isPotentiallyEvaluated() const {
28 if (isTypeOperand())
29 return false;
30
31 // C++11 [expr.typeid]p3:
32 // When typeid is applied to an expression other than a glvalue of
33 // polymorphic class type, [...] the expression is an unevaluated operand.
34 const Expr *E = getExprOperand();
35 if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
36 if (RD->isPolymorphic() && E->isGLValue())
37 return true;
38
39 return false;
40}
41
Douglas Gregor9da64192010-04-26 22:37:10 +000042QualType CXXTypeidExpr::getTypeOperand() const {
43 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
44 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
45 .getUnqualifiedType();
46}
47
Francois Pichet9f4f2072010-09-08 12:20:18 +000048QualType CXXUuidofExpr::getTypeOperand() const {
49 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
50 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
51 .getUnqualifiedType();
52}
53
Nico Webercf4ff5862012-10-11 10:13:44 +000054// static
55UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT) {
56 // Optionally remove one level of pointer, reference or array indirection.
57 const Type *Ty = QT.getTypePtr();
58 if (QT->isPointerType() || QT->isReferenceType())
59 Ty = QT->getPointeeType().getTypePtr();
60 else if (QT->isArrayType())
61 Ty = cast<ArrayType>(QT)->getElementType().getTypePtr();
62
63 // Loop all record redeclaration looking for an uuid attribute.
64 CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
65 for (CXXRecordDecl::redecl_iterator I = RD->redecls_begin(),
66 E = RD->redecls_end(); I != E; ++I) {
67 if (UuidAttr *Uuid = I->getAttr<UuidAttr>())
68 return Uuid;
69 }
70
71 return 0;
72}
73
Douglas Gregor747eb782010-07-08 06:14:04 +000074// CXXScalarValueInitExpr
Douglas Gregor2b88c112010-09-08 00:15:04 +000075SourceRange CXXScalarValueInitExpr::getSourceRange() const {
76 SourceLocation Start = RParenLoc;
77 if (TypeInfo)
78 Start = TypeInfo->getTypeLoc().getBeginLoc();
79 return SourceRange(Start, RParenLoc);
80}
81
Sebastian Redlbd150f42008-11-21 19:14:01 +000082// CXXNewExpr
Ted Kremenek9d6eb402010-02-11 22:51:03 +000083CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Sebastian Redlc3a3c602012-02-16 11:35:52 +000084 FunctionDecl *operatorDelete,
Sebastian Redl6047f072012-02-16 12:22:20 +000085 bool usualArrayDeleteWantsSize,
Benjamin Kramerc215e762012-08-24 11:54:20 +000086 ArrayRef<Expr*> placementArgs,
Sebastian Redl6047f072012-02-16 12:22:20 +000087 SourceRange typeIdParens, Expr *arraySize,
88 InitializationStyle initializationStyle,
89 Expr *initializer, QualType ty,
90 TypeSourceInfo *allocatedTypeInfo,
91 SourceLocation startLoc, SourceRange directInitRange)
John McCall7decc9e2010-11-18 06:31:45 +000092 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
Douglas Gregora6e053e2010-12-15 01:34:56 +000093 ty->isDependentType(), ty->isDependentType(),
Douglas Gregor678d76c2011-07-01 01:22:09 +000094 ty->isInstantiationDependentType(),
Douglas Gregora6e053e2010-12-15 01:34:56 +000095 ty->containsUnexpandedParameterPack()),
Sebastian Redl6047f072012-02-16 12:22:20 +000096 SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete),
97 AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens),
Benjamin Kramerb73f76b2012-02-26 20:37:14 +000098 StartLoc(startLoc), DirectInitRange(directInitRange),
99 GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {
Sebastian Redl6047f072012-02-16 12:22:20 +0000100 assert((initializer != 0 || initializationStyle == NoInit) &&
101 "Only NoInit can have no initializer.");
102 StoredInitializationStyle = initializer ? initializationStyle + 1 : 0;
Benjamin Kramerc215e762012-08-24 11:54:20 +0000103 AllocateArgsArray(C, arraySize != 0, placementArgs.size(), initializer != 0);
Sebastian Redlbd150f42008-11-21 19:14:01 +0000104 unsigned i = 0;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000105 if (Array) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000106 if (arraySize->isInstantiationDependent())
107 ExprBits.InstantiationDependent = true;
108
Douglas Gregora6e053e2010-12-15 01:34:56 +0000109 if (arraySize->containsUnexpandedParameterPack())
110 ExprBits.ContainsUnexpandedParameterPack = true;
111
Sebastian Redl351bb782008-12-02 14:43:59 +0000112 SubExprs[i++] = arraySize;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000113 }
114
Sebastian Redl6047f072012-02-16 12:22:20 +0000115 if (initializer) {
116 if (initializer->isInstantiationDependent())
117 ExprBits.InstantiationDependent = true;
118
119 if (initializer->containsUnexpandedParameterPack())
120 ExprBits.ContainsUnexpandedParameterPack = true;
121
122 SubExprs[i++] = initializer;
123 }
124
Benjamin Kramerc215e762012-08-24 11:54:20 +0000125 for (unsigned j = 0; j != placementArgs.size(); ++j) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000126 if (placementArgs[j]->isInstantiationDependent())
127 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000128 if (placementArgs[j]->containsUnexpandedParameterPack())
129 ExprBits.ContainsUnexpandedParameterPack = true;
130
Sebastian Redlbd150f42008-11-21 19:14:01 +0000131 SubExprs[i++] = placementArgs[j];
Douglas Gregora6e053e2010-12-15 01:34:56 +0000132 }
Sebastian Redlbd150f42008-11-21 19:14:01 +0000133}
134
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000135void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
Sebastian Redl6047f072012-02-16 12:22:20 +0000136 unsigned numPlaceArgs, bool hasInitializer){
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000137 assert(SubExprs == 0 && "SubExprs already allocated");
138 Array = isArray;
139 NumPlacementArgs = numPlaceArgs;
Sebastian Redl6047f072012-02-16 12:22:20 +0000140
141 unsigned TotalSize = Array + hasInitializer + NumPlacementArgs;
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000142 SubExprs = new (C) Stmt*[TotalSize];
143}
144
Sebastian Redl31ad7542011-03-13 17:09:40 +0000145bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCall75f94982011-03-07 03:12:35 +0000146 return getOperatorNew()->getType()->
Sebastian Redl31ad7542011-03-13 17:09:40 +0000147 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCall75f94982011-03-07 03:12:35 +0000148}
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000149
Sebastian Redl6047f072012-02-16 12:22:20 +0000150SourceLocation CXXNewExpr::getEndLoc() const {
151 switch (getInitializationStyle()) {
152 case NoInit:
153 return AllocatedTypeInfo->getTypeLoc().getEndLoc();
154 case CallInit:
155 return DirectInitRange.getEnd();
156 case ListInit:
157 return getInitializer()->getSourceRange().getEnd();
158 }
Matt Beaumont-Gay2150d382012-02-16 22:15:50 +0000159 llvm_unreachable("bogus initialization style");
Sebastian Redl6047f072012-02-16 12:22:20 +0000160}
161
Sebastian Redlbd150f42008-11-21 19:14:01 +0000162// CXXDeleteExpr
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000163QualType CXXDeleteExpr::getDestroyedType() const {
164 const Expr *Arg = getArgument();
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000165 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silverstein3b9936f2010-10-20 00:56:01 +0000166 const QualType ArgType = Arg->getType();
Craig Silverstein9e448da2010-11-16 07:16:25 +0000167
168 if (ArgType->isDependentType() && !ArgType->isPointerType())
169 return QualType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000170
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000171 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000172}
173
Douglas Gregorad8a3362009-09-04 17:36:40 +0000174// CXXPseudoDestructorExpr
Douglas Gregor678f90d2010-02-25 01:56:36 +0000175PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
176 : Type(Info)
177{
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000178 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000179}
180
John McCalldb40c7f2010-12-14 08:05:40 +0000181CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregora6ce6082011-02-25 18:19:59 +0000182 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
183 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
184 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
185 PseudoDestructorTypeStorage DestroyedType)
John McCalldb40c7f2010-12-14 08:05:40 +0000186 : Expr(CXXPseudoDestructorExprClass,
187 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
188 FunctionProtoType::ExtProtoInfo())),
189 VK_RValue, OK_Ordinary,
190 /*isTypeDependent=*/(Base->isTypeDependent() ||
191 (DestroyedType.getTypeSourceInfo() &&
192 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000193 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000194 (Base->isInstantiationDependent() ||
195 (QualifierLoc &&
196 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
197 (ScopeType &&
198 ScopeType->getType()->isInstantiationDependentType()) ||
199 (DestroyedType.getTypeSourceInfo() &&
200 DestroyedType.getTypeSourceInfo()->getType()
201 ->isInstantiationDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000202 // ContainsUnexpandedParameterPack
203 (Base->containsUnexpandedParameterPack() ||
Douglas Gregora6ce6082011-02-25 18:19:59 +0000204 (QualifierLoc &&
205 QualifierLoc.getNestedNameSpecifier()
206 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +0000207 (ScopeType &&
208 ScopeType->getType()->containsUnexpandedParameterPack()) ||
209 (DestroyedType.getTypeSourceInfo() &&
210 DestroyedType.getTypeSourceInfo()->getType()
211 ->containsUnexpandedParameterPack()))),
John McCalldb40c7f2010-12-14 08:05:40 +0000212 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregora6ce6082011-02-25 18:19:59 +0000213 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalldb40c7f2010-12-14 08:05:40 +0000214 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
215 DestroyedType(DestroyedType) { }
216
Douglas Gregor678f90d2010-02-25 01:56:36 +0000217QualType CXXPseudoDestructorExpr::getDestroyedType() const {
218 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
219 return TInfo->getType();
220
221 return QualType();
222}
223
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000224SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregor678f90d2010-02-25 01:56:36 +0000225 SourceLocation End = DestroyedType.getLocation();
226 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000227 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000228 return SourceRange(Base->getLocStart(), End);
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000229}
230
John McCalld14a8642009-11-21 08:51:07 +0000231// UnresolvedLookupExpr
John McCalle66edc12009-11-24 19:00:30 +0000232UnresolvedLookupExpr *
Douglas Gregora6e053e2010-12-15 01:34:56 +0000233UnresolvedLookupExpr::Create(ASTContext &C,
John McCall58cc69d2010-01-27 01:50:18 +0000234 CXXRecordDecl *NamingClass,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000235 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000236 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000237 const DeclarationNameInfo &NameInfo,
238 bool ADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000239 const TemplateArgumentListInfo *Args,
240 UnresolvedSetIterator Begin,
241 UnresolvedSetIterator End)
John McCalle66edc12009-11-24 19:00:30 +0000242{
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000243 assert(Args || TemplateKWLoc.isValid());
244 unsigned num_args = Args ? Args->size() : 0;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000245 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000246 ASTTemplateKWAndArgsInfo::sizeFor(num_args));
Abramo Bagnara7945c982012-01-27 09:46:47 +0000247 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
248 TemplateKWLoc, NameInfo,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000249 ADL, /*Overload*/ true, Args,
Richard Smithb6626742012-10-18 17:56:02 +0000250 Begin, End);
John McCalle66edc12009-11-24 19:00:30 +0000251}
252
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000253UnresolvedLookupExpr *
Abramo Bagnara7945c982012-01-27 09:46:47 +0000254UnresolvedLookupExpr::CreateEmpty(ASTContext &C,
255 bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +0000256 unsigned NumTemplateArgs) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000257 std::size_t size = sizeof(UnresolvedLookupExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000258 if (HasTemplateKWAndArgsInfo)
259 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000260
Chris Lattner5c0b4052010-10-30 05:14:06 +0000261 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000262 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000263 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000264 return E;
265}
266
Douglas Gregora6e053e2010-12-15 01:34:56 +0000267OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000268 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000269 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000270 const DeclarationNameInfo &NameInfo,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000271 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregorc69978f2010-05-23 19:36:40 +0000272 UnresolvedSetIterator Begin,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000273 UnresolvedSetIterator End,
274 bool KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000275 bool KnownInstantiationDependent,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000276 bool KnownContainsUnexpandedParameterPack)
277 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
278 KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000279 (KnownInstantiationDependent ||
280 NameInfo.isInstantiationDependent() ||
281 (QualifierLoc &&
282 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000283 (KnownContainsUnexpandedParameterPack ||
284 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor0da1d432011-02-28 20:01:57 +0000285 (QualifierLoc &&
286 QualifierLoc.getNestedNameSpecifier()
287 ->containsUnexpandedParameterPack()))),
Benjamin Kramerb73f76b2012-02-26 20:37:14 +0000288 NameInfo(NameInfo), QualifierLoc(QualifierLoc),
289 Results(0), NumResults(End - Begin),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000290 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid())
Douglas Gregorc69978f2010-05-23 19:36:40 +0000291{
Douglas Gregora6e053e2010-12-15 01:34:56 +0000292 NumResults = End - Begin;
293 if (NumResults) {
294 // Determine whether this expression is type-dependent.
295 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
296 if ((*I)->getDeclContext()->isDependentContext() ||
297 isa<UnresolvedUsingValueDecl>(*I)) {
298 ExprBits.TypeDependent = true;
299 ExprBits.ValueDependent = true;
Richard Smith47726b22012-08-13 21:29:18 +0000300 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000301 }
302 }
303
304 Results = static_cast<DeclAccessPair *>(
305 C.Allocate(sizeof(DeclAccessPair) * NumResults,
306 llvm::alignOf<DeclAccessPair>()));
307 memcpy(Results, &*Begin.getIterator(),
308 NumResults * sizeof(DeclAccessPair));
309 }
310
311 // If we have explicit template arguments, check for dependent
312 // template arguments and whether they contain any unexpanded pack
313 // expansions.
314 if (TemplateArgs) {
315 bool Dependent = false;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000316 bool InstantiationDependent = false;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000317 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000318 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
319 Dependent,
320 InstantiationDependent,
321 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000322
323 if (Dependent) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000324 ExprBits.TypeDependent = true;
325 ExprBits.ValueDependent = true;
326 }
327 if (InstantiationDependent)
328 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000329 if (ContainsUnexpandedParameterPack)
330 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000331 } else if (TemplateKWLoc.isValid()) {
332 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000333 }
334
335 if (isTypeDependent())
336 setType(C.DependentTy);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000337}
338
339void OverloadExpr::initializeResults(ASTContext &C,
340 UnresolvedSetIterator Begin,
341 UnresolvedSetIterator End) {
342 assert(Results == 0 && "Results already initialized!");
343 NumResults = End - Begin;
Douglas Gregorc69978f2010-05-23 19:36:40 +0000344 if (NumResults) {
Douglas Gregora6e053e2010-12-15 01:34:56 +0000345 Results = static_cast<DeclAccessPair *>(
346 C.Allocate(sizeof(DeclAccessPair) * NumResults,
347
348 llvm::alignOf<DeclAccessPair>()));
349 memcpy(Results, &*Begin.getIterator(),
350 NumResults * sizeof(DeclAccessPair));
Douglas Gregorc69978f2010-05-23 19:36:40 +0000351 }
352}
353
John McCall8c12dc42010-04-22 18:44:12 +0000354CXXRecordDecl *OverloadExpr::getNamingClass() const {
355 if (isa<UnresolvedLookupExpr>(this))
356 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
357 else
358 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
359}
360
John McCall8cd78132009-11-19 22:55:06 +0000361// DependentScopeDeclRefExpr
Douglas Gregora6e053e2010-12-15 01:34:56 +0000362DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000363 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000364 SourceLocation TemplateKWLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000365 const DeclarationNameInfo &NameInfo,
366 const TemplateArgumentListInfo *Args)
367 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
368 true, true,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000369 (NameInfo.isInstantiationDependent() ||
370 (QualifierLoc &&
371 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000372 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000373 (QualifierLoc &&
374 QualifierLoc.getNestedNameSpecifier()
375 ->containsUnexpandedParameterPack()))),
376 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000377 HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid())
Douglas Gregora6e053e2010-12-15 01:34:56 +0000378{
379 if (Args) {
380 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000381 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000382 bool ContainsUnexpandedParameterPack
383 = ExprBits.ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000384 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args,
385 Dependent,
386 InstantiationDependent,
387 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000388 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000389 } else if (TemplateKWLoc.isValid()) {
390 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000391 }
392}
393
John McCalle66edc12009-11-24 19:00:30 +0000394DependentScopeDeclRefExpr *
395DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000396 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000397 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000398 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +0000399 const TemplateArgumentListInfo *Args) {
400 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCalle66edc12009-11-24 19:00:30 +0000401 if (Args)
Abramo Bagnara7945c982012-01-27 09:46:47 +0000402 size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size());
403 else if (TemplateKWLoc.isValid())
404 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000405 void *Mem = C.Allocate(size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000406 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
407 TemplateKWLoc, NameInfo, Args);
John McCalle66edc12009-11-24 19:00:30 +0000408}
409
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000410DependentScopeDeclRefExpr *
411DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000412 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000413 unsigned NumTemplateArgs) {
414 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000415 if (HasTemplateKWAndArgsInfo)
416 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000417 void *Mem = C.Allocate(size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000418 DependentScopeDeclRefExpr *E
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000419 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000420 SourceLocation(),
Douglas Gregor87866ce2011-02-04 12:01:24 +0000421 DeclarationNameInfo(), 0);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000422 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregor87866ce2011-02-04 12:01:24 +0000423 return E;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000424}
425
Chandler Carruth01718152010-10-25 08:47:36 +0000426SourceRange CXXConstructExpr::getSourceRange() const {
John McCall701417a2011-02-21 06:23:05 +0000427 if (isa<CXXTemporaryObjectExpr>(this))
428 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
429
Douglas Gregor15417cf2010-11-03 00:35:38 +0000430 if (ParenRange.isValid())
431 return SourceRange(Loc, ParenRange.getEnd());
432
433 SourceLocation End = Loc;
434 for (unsigned I = getNumArgs(); I > 0; --I) {
435 const Expr *Arg = getArg(I-1);
436 if (!Arg->isDefaultArgument()) {
437 SourceLocation NewEnd = Arg->getLocEnd();
438 if (NewEnd.isValid()) {
439 End = NewEnd;
440 break;
441 }
442 }
443 }
444
445 return SourceRange(Loc, End);
Ted Kremenek49ace5c2009-12-23 04:00:48 +0000446}
447
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000448SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
Douglas Gregor993603d2008-11-14 16:09:21 +0000449 OverloadedOperatorKind Kind = getOperator();
450 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
451 if (getNumArgs() == 1)
452 // Prefix operator
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000453 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000454 else
455 // Postfix operator
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000456 return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
Chandler Carruthf20ec9232011-04-02 09:47:38 +0000457 } else if (Kind == OO_Arrow) {
458 return getArg(0)->getSourceRange();
Douglas Gregor993603d2008-11-14 16:09:21 +0000459 } else if (Kind == OO_Call) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000460 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000461 } else if (Kind == OO_Subscript) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000462 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000463 } else if (getNumArgs() == 1) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000464 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000465 } else if (getNumArgs() == 2) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000466 return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000467 } else {
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000468 return getOperatorLoc();
Douglas Gregor993603d2008-11-14 16:09:21 +0000469 }
470}
471
Ted Kremenek98a24e32011-03-30 17:41:19 +0000472Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
Jordan Rose16fe35e2012-08-03 23:08:39 +0000473 const Expr *Callee = getCallee()->IgnoreParens();
474 if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee))
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000475 return MemExpr->getBase();
Jordan Rose16fe35e2012-08-03 23:08:39 +0000476 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee))
477 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
478 return BO->getLHS();
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000479
480 // FIXME: Will eventually need to cope with member pointers.
481 return 0;
482}
483
Ted Kremenek98a24e32011-03-30 17:41:19 +0000484CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
485 if (const MemberExpr *MemExpr =
486 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
487 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
488
489 // FIXME: Will eventually need to cope with member pointers.
490 return 0;
491}
492
493
David Blaikiec0f58662012-05-03 16:25:49 +0000494CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Chandler Carruth00426b42010-10-27 06:55:41 +0000495 Expr* ThisArg = getImplicitObjectArgument();
496 if (!ThisArg)
497 return 0;
498
499 if (ThisArg->getType()->isAnyPointerType())
500 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
501
502 return ThisArg->getType()->getAsCXXRecordDecl();
503}
504
Douglas Gregoref986e82009-11-12 15:31:47 +0000505
Douglas Gregore200adc2008-10-27 19:41:14 +0000506//===----------------------------------------------------------------------===//
507// Named casts
508//===----------------------------------------------------------------------===//
509
510/// getCastName - Get the name of the C++ cast being used, e.g.,
511/// "static_cast", "dynamic_cast", "reinterpret_cast", or
512/// "const_cast". The returned pointer must not be freed.
513const char *CXXNamedCastExpr::getCastName() const {
514 switch (getStmtClass()) {
515 case CXXStaticCastExprClass: return "static_cast";
516 case CXXDynamicCastExprClass: return "dynamic_cast";
517 case CXXReinterpretCastExprClass: return "reinterpret_cast";
518 case CXXConstCastExprClass: return "const_cast";
519 default: return "<invalid cast>";
520 }
521}
Douglas Gregordd04d332009-01-16 18:33:17 +0000522
John McCallcf142162010-08-07 06:22:56 +0000523CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000524 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000525 CastKind K, Expr *Op,
526 const CXXCastPath *BasePath,
527 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000528 SourceLocation L,
529 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000530 unsigned PathSize = (BasePath ? BasePath->size() : 0);
531 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
532 + PathSize * sizeof(CXXBaseSpecifier*));
533 CXXStaticCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000534 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
535 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000536 if (PathSize) E->setCastPath(*BasePath);
537 return E;
538}
539
540CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
541 unsigned PathSize) {
542 void *Buffer =
543 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
544 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
545}
546
547CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000548 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000549 CastKind K, Expr *Op,
550 const CXXCastPath *BasePath,
551 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000552 SourceLocation L,
553 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000554 unsigned PathSize = (BasePath ? BasePath->size() : 0);
555 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
556 + PathSize * sizeof(CXXBaseSpecifier*));
557 CXXDynamicCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000558 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
559 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000560 if (PathSize) E->setCastPath(*BasePath);
561 return E;
562}
563
564CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
565 unsigned PathSize) {
566 void *Buffer =
567 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
568 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
569}
570
Anders Carlsson267c0c92011-04-11 01:43:55 +0000571/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
572/// to always be null. For example:
573///
574/// struct A { };
575/// struct B final : A { };
576/// struct C { };
577///
578/// C *f(B* b) { return dynamic_cast<C*>(b); }
579bool CXXDynamicCastExpr::isAlwaysNull() const
580{
581 QualType SrcType = getSubExpr()->getType();
582 QualType DestType = getType();
583
584 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
585 SrcType = SrcPTy->getPointeeType();
586 DestType = DestType->castAs<PointerType>()->getPointeeType();
587 }
588
Alexis Hunt78e2b912012-06-19 23:44:55 +0000589 if (DestType->isVoidType())
590 return false;
591
Anders Carlsson267c0c92011-04-11 01:43:55 +0000592 const CXXRecordDecl *SrcRD =
593 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
594
Jakob Stoklund Olesene1c0ae62012-06-19 21:48:43 +0000595 if (!SrcRD->hasAttr<FinalAttr>())
596 return false;
597
Anders Carlsson267c0c92011-04-11 01:43:55 +0000598 const CXXRecordDecl *DestRD =
599 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
600
601 return !DestRD->isDerivedFrom(SrcRD);
602}
603
John McCallcf142162010-08-07 06:22:56 +0000604CXXReinterpretCastExpr *
John McCall7decc9e2010-11-18 06:31:45 +0000605CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
606 CastKind K, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000607 const CXXCastPath *BasePath,
Douglas Gregor4478f852011-01-12 22:41:29 +0000608 TypeSourceInfo *WrittenTy, SourceLocation L,
609 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000610 unsigned PathSize = (BasePath ? BasePath->size() : 0);
611 void *Buffer =
612 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
613 CXXReinterpretCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000614 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
615 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000616 if (PathSize) E->setCastPath(*BasePath);
617 return E;
618}
619
620CXXReinterpretCastExpr *
621CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
622 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
623 + PathSize * sizeof(CXXBaseSpecifier*));
624 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
625}
626
John McCall7decc9e2010-11-18 06:31:45 +0000627CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
628 ExprValueKind VK, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000629 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000630 SourceLocation L,
631 SourceLocation RParenLoc) {
632 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000633}
634
635CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
636 return new (C) CXXConstCastExpr(EmptyShell());
637}
638
639CXXFunctionalCastExpr *
John McCall7decc9e2010-11-18 06:31:45 +0000640CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000641 TypeSourceInfo *Written, SourceLocation L,
642 CastKind K, Expr *Op, const CXXCastPath *BasePath,
643 SourceLocation R) {
644 unsigned PathSize = (BasePath ? BasePath->size() : 0);
645 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
646 + PathSize * sizeof(CXXBaseSpecifier*));
647 CXXFunctionalCastExpr *E =
John McCall7decc9e2010-11-18 06:31:45 +0000648 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallcf142162010-08-07 06:22:56 +0000649 if (PathSize) E->setCastPath(*BasePath);
650 return E;
651}
652
653CXXFunctionalCastExpr *
654CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
655 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
656 + PathSize * sizeof(CXXBaseSpecifier*));
657 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
658}
659
Richard Smithc67fdd42012-03-07 08:35:16 +0000660UserDefinedLiteral::LiteralOperatorKind
661UserDefinedLiteral::getLiteralOperatorKind() const {
662 if (getNumArgs() == 0)
663 return LOK_Template;
664 if (getNumArgs() == 2)
665 return LOK_String;
666
667 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
668 QualType ParamTy =
669 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
670 if (ParamTy->isPointerType())
671 return LOK_Raw;
672 if (ParamTy->isAnyCharacterType())
673 return LOK_Character;
674 if (ParamTy->isIntegerType())
675 return LOK_Integer;
676 if (ParamTy->isFloatingType())
677 return LOK_Floating;
678
679 llvm_unreachable("unknown kind of literal operator");
680}
681
682Expr *UserDefinedLiteral::getCookedLiteral() {
683#ifndef NDEBUG
684 LiteralOperatorKind LOK = getLiteralOperatorKind();
685 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
686#endif
687 return getArg(0);
688}
689
690const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
691 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
692}
John McCallcf142162010-08-07 06:22:56 +0000693
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000694CXXDefaultArgExpr *
Douglas Gregor033f6752009-12-23 23:03:06 +0000695CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
696 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000697 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor033f6752009-12-23 23:03:06 +0000698 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
699 SubExpr);
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000700}
701
Mike Stump11289f42009-09-09 15:08:12 +0000702CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonffda6062009-05-30 20:34:37 +0000703 const CXXDestructorDecl *Destructor) {
Anders Carlsson73b836b2009-05-30 22:38:53 +0000704 return new (C) CXXTemporary(Destructor);
705}
706
Mike Stump11289f42009-09-09 15:08:12 +0000707CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlsson993a4b32009-05-30 20:03:25 +0000708 CXXTemporary *Temp,
709 Expr* SubExpr) {
Peter Collingbournefbef4c82011-11-27 22:09:28 +0000710 assert((SubExpr->getType()->isRecordType() ||
711 SubExpr->getType()->isArrayType()) &&
712 "Expression bound to a temporary must have record or array type!");
Anders Carlsson993a4b32009-05-30 20:03:25 +0000713
Douglas Gregora6e053e2010-12-15 01:34:56 +0000714 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlsson993a4b32009-05-30 20:03:25 +0000715}
716
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000717CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson56c5bd82009-04-24 05:23:13 +0000718 CXXConstructorDecl *Cons,
Douglas Gregor2b88c112010-09-08 00:15:04 +0000719 TypeSourceInfo *Type,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000720 ArrayRef<Expr*> Args,
Chandler Carruth01718152010-10-25 08:47:36 +0000721 SourceRange parenRange,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000722 bool HadMultipleCandidates,
Douglas Gregor199db362010-04-27 20:36:09 +0000723 bool ZeroInitialization)
Douglas Gregor2b88c112010-09-08 00:15:04 +0000724 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
725 Type->getType().getNonReferenceType(),
726 Type->getTypeLoc().getBeginLoc(),
Benjamin Kramerc215e762012-08-24 11:54:20 +0000727 Cons, false, Args,
Sebastian Redla9351792012-02-11 23:51:47 +0000728 HadMultipleCandidates, /*FIXME*/false, ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000729 CXXConstructExpr::CK_Complete, parenRange),
730 Type(Type) {
Douglas Gregor2b88c112010-09-08 00:15:04 +0000731}
732
733SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth01718152010-10-25 08:47:36 +0000734 return SourceRange(Type->getTypeLoc().getBeginLoc(),
735 getParenRange().getEnd());
Douglas Gregordd04d332009-01-16 18:33:17 +0000736}
Anders Carlsson6f287832009-04-21 02:22:11 +0000737
Mike Stump11289f42009-09-09 15:08:12 +0000738CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000739 SourceLocation Loc,
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000740 CXXConstructorDecl *D, bool Elidable,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000741 ArrayRef<Expr*> Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000742 bool HadMultipleCandidates,
Sebastian Redla9351792012-02-11 23:51:47 +0000743 bool ListInitialization,
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000744 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000745 ConstructionKind ConstructKind,
746 SourceRange ParenRange) {
Douglas Gregor85dabae2009-12-16 01:38:02 +0000747 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000748 Elidable, Args,
Sebastian Redla9351792012-02-11 23:51:47 +0000749 HadMultipleCandidates, ListInitialization,
750 ZeroInitialization, ConstructKind,
751 ParenRange);
Anders Carlsson0781ce72009-04-23 02:32:43 +0000752}
753
Mike Stump11289f42009-09-09 15:08:12 +0000754CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000755 SourceLocation Loc,
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000756 CXXConstructorDecl *D, bool elidable,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000757 ArrayRef<Expr*> args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000758 bool HadMultipleCandidates,
Sebastian Redla9351792012-02-11 23:51:47 +0000759 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000760 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000761 ConstructionKind ConstructKind,
762 SourceRange ParenRange)
Douglas Gregora6e053e2010-12-15 01:34:56 +0000763 : Expr(SC, T, VK_RValue, OK_Ordinary,
764 T->isDependentType(), T->isDependentType(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000765 T->isInstantiationDependentType(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000766 T->containsUnexpandedParameterPack()),
Benjamin Kramerc215e762012-08-24 11:54:20 +0000767 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(args.size()),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000768 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
Sebastian Redla9351792012-02-11 23:51:47 +0000769 ListInitialization(ListInitialization),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000770 ZeroInitialization(ZeroInitialization),
Douglas Gregor488c2312011-09-26 14:47:03 +0000771 ConstructKind(ConstructKind), Args(0)
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000772{
773 if (NumArgs) {
Benjamin Kramerc215e762012-08-24 11:54:20 +0000774 Args = new (C) Stmt*[args.size()];
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000775
Benjamin Kramerc215e762012-08-24 11:54:20 +0000776 for (unsigned i = 0; i != args.size(); ++i) {
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000777 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregora6e053e2010-12-15 01:34:56 +0000778
779 if (args[i]->isValueDependent())
780 ExprBits.ValueDependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000781 if (args[i]->isInstantiationDependent())
782 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000783 if (args[i]->containsUnexpandedParameterPack())
784 ExprBits.ContainsUnexpandedParameterPack = true;
785
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000786 Args[i] = args[i];
Anders Carlsson0781ce72009-04-23 02:32:43 +0000787 }
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000788 }
Anders Carlsson0781ce72009-04-23 02:32:43 +0000789}
790
Douglas Gregore31e6062012-02-07 10:09:13 +0000791LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
792 LambdaCaptureKind Kind, VarDecl *Var,
793 SourceLocation EllipsisLoc)
794 : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
795{
796 unsigned Bits = 0;
797 if (Implicit)
798 Bits |= Capture_Implicit;
799
800 switch (Kind) {
801 case LCK_This:
802 assert(Var == 0 && "'this' capture cannot have a variable!");
803 break;
804
805 case LCK_ByCopy:
806 Bits |= Capture_ByCopy;
807 // Fall through
808 case LCK_ByRef:
809 assert(Var && "capture must have a variable!");
810 break;
811 }
812 VarAndBits.setInt(Bits);
813}
814
815LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const {
816 if (capturesThis())
817 return LCK_This;
818
819 return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef;
820}
821
822LambdaExpr::LambdaExpr(QualType T,
823 SourceRange IntroducerRange,
824 LambdaCaptureDefault CaptureDefault,
825 ArrayRef<Capture> Captures,
826 bool ExplicitParams,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000827 bool ExplicitResultType,
Douglas Gregore31e6062012-02-07 10:09:13 +0000828 ArrayRef<Expr *> CaptureInits,
Douglas Gregore5561632012-02-13 17:20:40 +0000829 ArrayRef<VarDecl *> ArrayIndexVars,
830 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000831 SourceLocation ClosingBrace,
832 bool ContainsUnexpandedParameterPack)
Douglas Gregore31e6062012-02-07 10:09:13 +0000833 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
834 T->isDependentType(), T->isDependentType(), T->isDependentType(),
Richard Smith2589b9802012-07-25 03:56:55 +0000835 ContainsUnexpandedParameterPack),
Douglas Gregore31e6062012-02-07 10:09:13 +0000836 IntroducerRange(IntroducerRange),
Douglas Gregore5561632012-02-13 17:20:40 +0000837 NumCaptures(Captures.size()),
Douglas Gregore31e6062012-02-07 10:09:13 +0000838 CaptureDefault(CaptureDefault),
839 ExplicitParams(ExplicitParams),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000840 ExplicitResultType(ExplicitResultType),
Douglas Gregore31e6062012-02-07 10:09:13 +0000841 ClosingBrace(ClosingBrace)
842{
843 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorc8a73492012-02-13 15:44:47 +0000844 CXXRecordDecl *Class = getLambdaClass();
845 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Douglas Gregorc8a73492012-02-13 15:44:47 +0000846
847 // FIXME: Propagate "has unexpanded parameter pack" bit.
Douglas Gregore5561632012-02-13 17:20:40 +0000848
849 // Copy captures.
850 ASTContext &Context = Class->getASTContext();
851 Data.NumCaptures = NumCaptures;
852 Data.NumExplicitCaptures = 0;
853 Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures);
854 Capture *ToCapture = Data.Captures;
855 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
856 if (Captures[I].isExplicit())
857 ++Data.NumExplicitCaptures;
858
859 *ToCapture++ = Captures[I];
860 }
861
862 // Copy initialization expressions for the non-static data members.
863 Stmt **Stored = getStoredStmts();
864 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
865 *Stored++ = CaptureInits[I];
866
867 // Copy the body of the lambda.
868 *Stored++ = getCallOperator()->getBody();
869
870 // Copy the array index variables, if any.
871 HasArrayIndexVars = !ArrayIndexVars.empty();
872 if (HasArrayIndexVars) {
873 assert(ArrayIndexStarts.size() == NumCaptures);
874 memcpy(getArrayIndexVars(), ArrayIndexVars.data(),
875 sizeof(VarDecl *) * ArrayIndexVars.size());
876 memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(),
877 sizeof(unsigned) * Captures.size());
878 getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size();
Douglas Gregor6f88e5e2012-02-21 04:17:39 +0000879 }
Douglas Gregore31e6062012-02-07 10:09:13 +0000880}
881
882LambdaExpr *LambdaExpr::Create(ASTContext &Context,
883 CXXRecordDecl *Class,
884 SourceRange IntroducerRange,
885 LambdaCaptureDefault CaptureDefault,
886 ArrayRef<Capture> Captures,
887 bool ExplicitParams,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000888 bool ExplicitResultType,
Douglas Gregore31e6062012-02-07 10:09:13 +0000889 ArrayRef<Expr *> CaptureInits,
Douglas Gregore5561632012-02-13 17:20:40 +0000890 ArrayRef<VarDecl *> ArrayIndexVars,
891 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000892 SourceLocation ClosingBrace,
893 bool ContainsUnexpandedParameterPack) {
Douglas Gregore31e6062012-02-07 10:09:13 +0000894 // Determine the type of the expression (i.e., the type of the
895 // function object we're creating).
896 QualType T = Context.getTypeDeclType(Class);
Douglas Gregore31e6062012-02-07 10:09:13 +0000897
Douglas Gregore5561632012-02-13 17:20:40 +0000898 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1);
Richard Smithc7520bf2012-08-21 05:42:49 +0000899 if (!ArrayIndexVars.empty()) {
900 Size += sizeof(unsigned) * (Captures.size() + 1);
901 // Realign for following VarDecl array.
Richard Smitha75e1cf2012-08-21 18:18:06 +0000902 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>());
Richard Smithc7520bf2012-08-21 05:42:49 +0000903 Size += sizeof(VarDecl *) * ArrayIndexVars.size();
904 }
Douglas Gregore5561632012-02-13 17:20:40 +0000905 void *Mem = Context.Allocate(Size);
906 return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000907 Captures, ExplicitParams, ExplicitResultType,
908 CaptureInits, ArrayIndexVars, ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000909 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregore31e6062012-02-07 10:09:13 +0000910}
911
Douglas Gregor99ae8062012-02-14 17:54:36 +0000912LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures,
913 unsigned NumArrayIndexVars) {
914 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1);
915 if (NumArrayIndexVars)
916 Size += sizeof(VarDecl) * NumArrayIndexVars
917 + sizeof(unsigned) * (NumCaptures + 1);
918 void *Mem = C.Allocate(Size);
919 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0);
920}
921
Douglas Gregorc8a73492012-02-13 15:44:47 +0000922LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregore5561632012-02-13 17:20:40 +0000923 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000924}
925
926LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregore5561632012-02-13 17:20:40 +0000927 return capture_begin() + NumCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000928}
929
930LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
931 return capture_begin();
932}
933
934LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
935 struct CXXRecordDecl::LambdaDefinitionData &Data
936 = getLambdaClass()->getLambdaData();
Douglas Gregore5561632012-02-13 17:20:40 +0000937 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000938}
939
940LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
941 return explicit_capture_end();
942}
943
944LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
945 return capture_end();
946}
947
Douglas Gregor54fcea62012-02-13 16:35:30 +0000948ArrayRef<VarDecl *>
949LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const {
Douglas Gregore5561632012-02-13 17:20:40 +0000950 assert(HasArrayIndexVars && "No array index-var data?");
Douglas Gregor54fcea62012-02-13 16:35:30 +0000951
952 unsigned Index = Iter - capture_init_begin();
Matt Beaumont-Gayf2ee0672012-02-13 19:29:45 +0000953 assert(Index < getLambdaClass()->getLambdaData().NumCaptures &&
954 "Capture index out-of-range");
Douglas Gregore5561632012-02-13 17:20:40 +0000955 VarDecl **IndexVars = getArrayIndexVars();
956 unsigned *IndexStarts = getArrayIndexStarts();
Douglas Gregor54fcea62012-02-13 16:35:30 +0000957 return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index],
958 IndexVars + IndexStarts[Index + 1]);
959}
960
Douglas Gregore31e6062012-02-07 10:09:13 +0000961CXXRecordDecl *LambdaExpr::getLambdaClass() const {
962 return getType()->getAsCXXRecordDecl();
963}
964
965CXXMethodDecl *LambdaExpr::getCallOperator() const {
966 CXXRecordDecl *Record = getLambdaClass();
967 DeclarationName Name
968 = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
969 DeclContext::lookup_result Calls = Record->lookup(Name);
970 assert(Calls.first != Calls.second && "Missing lambda call operator!");
971 CXXMethodDecl *Result = cast<CXXMethodDecl>(*Calls.first++);
972 assert(Calls.first == Calls.second && "More than lambda one call operator?");
973 return Result;
974}
975
Douglas Gregor99ae8062012-02-14 17:54:36 +0000976CompoundStmt *LambdaExpr::getBody() const {
977 if (!getStoredStmts()[NumCaptures])
978 getStoredStmts()[NumCaptures] = getCallOperator()->getBody();
979
980 return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
981}
982
Douglas Gregore31e6062012-02-07 10:09:13 +0000983bool LambdaExpr::isMutable() const {
David Blaikief5697e52012-08-10 00:55:35 +0000984 return !getCallOperator()->isConst();
Douglas Gregore31e6062012-02-07 10:09:13 +0000985}
986
John McCall28fc7092011-11-10 05:35:25 +0000987ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
988 ArrayRef<CleanupObject> objects)
John McCall5d413782010-12-06 08:20:24 +0000989 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCall7decc9e2010-11-18 06:31:45 +0000990 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000991 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000992 subexpr->isInstantiationDependent(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000993 subexpr->containsUnexpandedParameterPack()),
John McCall28fc7092011-11-10 05:35:25 +0000994 SubExpr(subexpr) {
995 ExprWithCleanupsBits.NumObjects = objects.size();
996 for (unsigned i = 0, e = objects.size(); i != e; ++i)
997 getObjectsBuffer()[i] = objects[i];
Anders Carlssondefc6442009-04-24 22:47:04 +0000998}
999
John McCall28fc7092011-11-10 05:35:25 +00001000ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
1001 ArrayRef<CleanupObject> objects) {
1002 size_t size = sizeof(ExprWithCleanups)
1003 + objects.size() * sizeof(CleanupObject);
1004 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1005 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnercba86142010-05-10 00:25:06 +00001006}
1007
John McCall28fc7092011-11-10 05:35:25 +00001008ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1009 : Expr(ExprWithCleanupsClass, empty) {
1010 ExprWithCleanupsBits.NumObjects = numObjects;
1011}
Chris Lattnercba86142010-05-10 00:25:06 +00001012
John McCall28fc7092011-11-10 05:35:25 +00001013ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
1014 unsigned numObjects) {
1015 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
1016 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1017 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson73b836b2009-05-30 22:38:53 +00001018}
1019
Douglas Gregor2b88c112010-09-08 00:15:04 +00001020CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +00001021 SourceLocation LParenLoc,
Benjamin Kramerc215e762012-08-24 11:54:20 +00001022 ArrayRef<Expr*> Args,
Douglas Gregorce934142009-05-20 18:46:25 +00001023 SourceLocation RParenLoc)
Douglas Gregor2b88c112010-09-08 00:15:04 +00001024 : Expr(CXXUnresolvedConstructExprClass,
1025 Type->getType().getNonReferenceType(),
Douglas Gregor6336f292011-07-08 15:50:43 +00001026 (Type->getType()->isLValueReferenceType() ? VK_LValue
1027 :Type->getType()->isRValueReferenceType()? VK_XValue
1028 :VK_RValue),
1029 OK_Ordinary,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001030 Type->getType()->isDependentType(), true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001031 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001032 Type(Type),
Douglas Gregorce934142009-05-20 18:46:25 +00001033 LParenLoc(LParenLoc),
1034 RParenLoc(RParenLoc),
Benjamin Kramerc215e762012-08-24 11:54:20 +00001035 NumArgs(Args.size()) {
Douglas Gregorce934142009-05-20 18:46:25 +00001036 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Benjamin Kramerc215e762012-08-24 11:54:20 +00001037 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001038 if (Args[I]->containsUnexpandedParameterPack())
1039 ExprBits.ContainsUnexpandedParameterPack = true;
1040
1041 StoredArgs[I] = Args[I];
1042 }
Douglas Gregorce934142009-05-20 18:46:25 +00001043}
1044
1045CXXUnresolvedConstructExpr *
Mike Stump11289f42009-09-09 15:08:12 +00001046CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregor2b88c112010-09-08 00:15:04 +00001047 TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +00001048 SourceLocation LParenLoc,
Benjamin Kramerc215e762012-08-24 11:54:20 +00001049 ArrayRef<Expr*> Args,
Douglas Gregorce934142009-05-20 18:46:25 +00001050 SourceLocation RParenLoc) {
1051 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
Benjamin Kramerc215e762012-08-24 11:54:20 +00001052 sizeof(Expr *) * Args.size());
1053 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
Douglas Gregorce934142009-05-20 18:46:25 +00001054}
1055
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001056CXXUnresolvedConstructExpr *
1057CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
1058 Stmt::EmptyShell Empty;
1059 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
1060 sizeof(Expr *) * NumArgs);
1061 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1062}
1063
Douglas Gregor2b88c112010-09-08 00:15:04 +00001064SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
1065 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
1066}
1067
John McCall8cd78132009-11-19 22:55:06 +00001068CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +00001069 Expr *Base, QualType BaseType,
1070 bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +00001071 SourceLocation OperatorLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001072 NestedNameSpecifierLoc QualifierLoc,
1073 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00001074 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001075 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +00001076 const TemplateArgumentListInfo *TemplateArgs)
John McCall7decc9e2010-11-18 06:31:45 +00001077 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001078 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001079 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregore16af532011-02-28 18:50:33 +00001080 (QualifierLoc &&
1081 QualifierLoc.getNestedNameSpecifier()
1082 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +00001083 MemberNameInfo.containsUnexpandedParameterPack())),
John McCall2d74de92009-12-01 22:10:20 +00001084 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001085 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregore16af532011-02-28 18:50:33 +00001086 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor308047d2009-09-09 00:23:06 +00001087 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001088 MemberNameInfo(MemberNameInfo) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001089 if (TemplateArgs) {
1090 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +00001091 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +00001092 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnara7945c982012-01-27 09:46:47 +00001093 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
1094 Dependent,
1095 InstantiationDependent,
1096 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001097 if (ContainsUnexpandedParameterPack)
1098 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +00001099 } else if (TemplateKWLoc.isValid()) {
1100 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001101 }
Douglas Gregor308047d2009-09-09 00:23:06 +00001102}
1103
Douglas Gregora6e053e2010-12-15 01:34:56 +00001104CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
1105 Expr *Base, QualType BaseType,
1106 bool IsArrow,
1107 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001108 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001109 NamedDecl *FirstQualifierFoundInScope,
1110 DeclarationNameInfo MemberNameInfo)
1111 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001112 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001113 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregore16af532011-02-28 18:50:33 +00001114 (QualifierLoc &&
1115 QualifierLoc.getNestedNameSpecifier()->
1116 containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +00001117 MemberNameInfo.containsUnexpandedParameterPack())),
1118 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001119 HasTemplateKWAndArgsInfo(false),
1120 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregora6e053e2010-12-15 01:34:56 +00001121 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1122 MemberNameInfo(MemberNameInfo) { }
1123
John McCall8cd78132009-11-19 22:55:06 +00001124CXXDependentScopeMemberExpr *
1125CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +00001126 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +00001127 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001128 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001129 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00001130 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001131 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +00001132 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00001133 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCall2d74de92009-12-01 22:10:20 +00001134 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
1135 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001136 QualifierLoc,
John McCall2d74de92009-12-01 22:10:20 +00001137 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001138 MemberNameInfo);
Mike Stump11289f42009-09-09 15:08:12 +00001139
Abramo Bagnara7945c982012-01-27 09:46:47 +00001140 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1141 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
1142 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCall6b51f282009-11-23 01:53:49 +00001143
Chris Lattner5c0b4052010-10-30 05:14:06 +00001144 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCall2d74de92009-12-01 22:10:20 +00001145 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1146 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001147 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001148 TemplateKWLoc,
John McCall2d74de92009-12-01 22:10:20 +00001149 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001150 MemberNameInfo, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001151}
1152
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001153CXXDependentScopeMemberExpr *
1154CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001155 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001156 unsigned NumTemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00001157 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001158 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001159 0, SourceLocation(),
Douglas Gregore16af532011-02-28 18:50:33 +00001160 NestedNameSpecifierLoc(), 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001161 DeclarationNameInfo());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001162
1163 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnara7945c982012-01-27 09:46:47 +00001164 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner5c0b4052010-10-30 05:14:06 +00001165 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001166 CXXDependentScopeMemberExpr *E
1167 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001168 0, SourceLocation(),
1169 NestedNameSpecifierLoc(),
1170 SourceLocation(), 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001171 DeclarationNameInfo(), 0);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001172 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001173 return E;
1174}
1175
Douglas Gregor0da1d432011-02-28 20:01:57 +00001176bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
1177 if (Base == 0)
1178 return true;
1179
Douglas Gregor25b7e052011-03-02 21:06:53 +00001180 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001181}
1182
John McCall0009fcc2011-04-26 20:42:42 +00001183static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1184 UnresolvedSetIterator end) {
1185 do {
1186 NamedDecl *decl = *begin;
1187 if (isa<UnresolvedUsingValueDecl>(decl))
1188 return false;
1189 if (isa<UsingShadowDecl>(decl))
1190 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
1191
1192 // Unresolved member expressions should only contain methods and
1193 // method templates.
1194 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
1195
1196 if (isa<FunctionTemplateDecl>(decl))
1197 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
1198 if (cast<CXXMethodDecl>(decl)->isStatic())
1199 return false;
1200 } while (++begin != end);
1201
1202 return true;
1203}
1204
Douglas Gregora6e053e2010-12-15 01:34:56 +00001205UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +00001206 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +00001207 Expr *Base, QualType BaseType,
1208 bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001209 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001210 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001211 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001212 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +00001213 const TemplateArgumentListInfo *TemplateArgs,
1214 UnresolvedSetIterator Begin,
1215 UnresolvedSetIterator End)
Abramo Bagnara7945c982012-01-27 09:46:47 +00001216 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1217 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001218 // Dependent
1219 ((Base && Base->isTypeDependent()) ||
1220 BaseType->isDependentType()),
Douglas Gregor678d76c2011-07-01 01:22:09 +00001221 ((Base && Base->isInstantiationDependent()) ||
1222 BaseType->isInstantiationDependentType()),
Douglas Gregora6e053e2010-12-15 01:34:56 +00001223 // Contains unexpanded parameter pack
1224 ((Base && Base->containsUnexpandedParameterPack()) ||
1225 BaseType->containsUnexpandedParameterPack())),
John McCall1acbbb52010-02-02 06:20:04 +00001226 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1227 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall0009fcc2011-04-26 20:42:42 +00001228
1229 // Check whether all of the members are non-static member functions,
1230 // and if so, mark give this bound-member type instead of overload type.
1231 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1232 setType(C.BoundMemberTy);
John McCall10eae182009-11-30 22:42:35 +00001233}
1234
Douglas Gregor0da1d432011-02-28 20:01:57 +00001235bool UnresolvedMemberExpr::isImplicitAccess() const {
1236 if (Base == 0)
1237 return true;
1238
Douglas Gregor25b7e052011-03-02 21:06:53 +00001239 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001240}
1241
John McCall10eae182009-11-30 22:42:35 +00001242UnresolvedMemberExpr *
Douglas Gregora6e053e2010-12-15 01:34:56 +00001243UnresolvedMemberExpr::Create(ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +00001244 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +00001245 Expr *Base, QualType BaseType, bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001246 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001247 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001248 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001249 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +00001250 const TemplateArgumentListInfo *TemplateArgs,
1251 UnresolvedSetIterator Begin,
1252 UnresolvedSetIterator End) {
John McCall10eae182009-11-30 22:42:35 +00001253 std::size_t size = sizeof(UnresolvedMemberExpr);
1254 if (TemplateArgs)
Abramo Bagnara7945c982012-01-27 09:46:47 +00001255 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
1256 else if (TemplateKWLoc.isValid())
1257 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall10eae182009-11-30 22:42:35 +00001258
Chris Lattner5c0b4052010-10-30 05:14:06 +00001259 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregorc69978f2010-05-23 19:36:40 +00001260 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001261 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001262 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001263 MemberNameInfo, TemplateArgs, Begin, End);
John McCall10eae182009-11-30 22:42:35 +00001264}
1265
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001266UnresolvedMemberExpr *
Abramo Bagnara7945c982012-01-27 09:46:47 +00001267UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +00001268 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001269 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001270 if (HasTemplateKWAndArgsInfo)
1271 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001272
Chris Lattner5c0b4052010-10-30 05:14:06 +00001273 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001274 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +00001275 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001276 return E;
1277}
1278
John McCall58cc69d2010-01-27 01:50:18 +00001279CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1280 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1281
1282 // If there was a nested name specifier, it names the naming class.
1283 // It can't be dependent: after all, we were actually able to do the
1284 // lookup.
Douglas Gregor9262f472010-04-27 18:19:34 +00001285 CXXRecordDecl *Record = 0;
John McCall1acbbb52010-02-02 06:20:04 +00001286 if (getQualifier()) {
John McCall424cec92011-01-19 06:33:43 +00001287 const Type *T = getQualifier()->getAsType();
John McCall58cc69d2010-01-27 01:50:18 +00001288 assert(T && "qualifier in member expression does not name type");
Douglas Gregor9262f472010-04-27 18:19:34 +00001289 Record = T->getAsCXXRecordDecl();
1290 assert(Record && "qualifier in member expression does not name record");
1291 }
John McCall58cc69d2010-01-27 01:50:18 +00001292 // Otherwise the naming class must have been the base class.
Douglas Gregor9262f472010-04-27 18:19:34 +00001293 else {
John McCall58cc69d2010-01-27 01:50:18 +00001294 QualType BaseType = getBaseType().getNonReferenceType();
1295 if (isArrow()) {
1296 const PointerType *PT = BaseType->getAs<PointerType>();
1297 assert(PT && "base of arrow member access is not pointer");
1298 BaseType = PT->getPointeeType();
1299 }
1300
Douglas Gregor9262f472010-04-27 18:19:34 +00001301 Record = BaseType->getAsCXXRecordDecl();
1302 assert(Record && "base of member expression does not name record");
John McCall58cc69d2010-01-27 01:50:18 +00001303 }
1304
Douglas Gregor9262f472010-04-27 18:19:34 +00001305 return Record;
John McCall58cc69d2010-01-27 01:50:18 +00001306}
1307
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001308SubstNonTypeTemplateParmPackExpr::
1309SubstNonTypeTemplateParmPackExpr(QualType T,
1310 NonTypeTemplateParmDecl *Param,
1311 SourceLocation NameLoc,
1312 const TemplateArgument &ArgPack)
1313 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001314 true, true, true, true),
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001315 Param(Param), Arguments(ArgPack.pack_begin()),
1316 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1317
1318TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1319 return TemplateArgument(Arguments, NumArguments);
1320}
1321
Richard Smithb15fe3a2012-09-12 00:56:43 +00001322FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1323 SourceLocation NameLoc,
1324 unsigned NumParams,
1325 Decl * const *Params)
1326 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary,
1327 true, true, true, true),
1328 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1329 if (Params)
1330 std::uninitialized_copy(Params, Params + NumParams,
1331 reinterpret_cast<Decl**>(this+1));
1332}
1333
1334FunctionParmPackExpr *
1335FunctionParmPackExpr::Create(ASTContext &Context, QualType T,
1336 ParmVarDecl *ParamPack, SourceLocation NameLoc,
1337 llvm::ArrayRef<Decl*> Params) {
1338 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1339 sizeof(ParmVarDecl*) * Params.size()))
1340 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1341}
1342
1343FunctionParmPackExpr *
1344FunctionParmPackExpr::CreateEmpty(ASTContext &Context, unsigned NumParams) {
1345 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1346 sizeof(ParmVarDecl*) * NumParams))
1347 FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0);
1348}
1349
Douglas Gregor29c42f22012-02-24 07:38:34 +00001350TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1351 ArrayRef<TypeSourceInfo *> Args,
1352 SourceLocation RParenLoc,
1353 bool Value)
1354 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1355 /*TypeDependent=*/false,
1356 /*ValueDependent=*/false,
1357 /*InstantiationDependent=*/false,
1358 /*ContainsUnexpandedParameterPack=*/false),
1359 Loc(Loc), RParenLoc(RParenLoc)
1360{
1361 TypeTraitExprBits.Kind = Kind;
1362 TypeTraitExprBits.Value = Value;
1363 TypeTraitExprBits.NumArgs = Args.size();
1364
1365 TypeSourceInfo **ToArgs = getTypeSourceInfos();
1366
1367 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1368 if (Args[I]->getType()->isDependentType())
1369 setValueDependent(true);
1370 if (Args[I]->getType()->isInstantiationDependentType())
1371 setInstantiationDependent(true);
1372 if (Args[I]->getType()->containsUnexpandedParameterPack())
1373 setContainsUnexpandedParameterPack(true);
1374
1375 ToArgs[I] = Args[I];
1376 }
1377}
1378
1379TypeTraitExpr *TypeTraitExpr::Create(ASTContext &C, QualType T,
1380 SourceLocation Loc,
1381 TypeTrait Kind,
1382 ArrayRef<TypeSourceInfo *> Args,
1383 SourceLocation RParenLoc,
1384 bool Value) {
1385 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size();
1386 void *Mem = C.Allocate(Size);
1387 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1388}
1389
1390TypeTraitExpr *TypeTraitExpr::CreateDeserialized(ASTContext &C,
1391 unsigned NumArgs) {
1392 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs;
1393 void *Mem = C.Allocate(Size);
1394 return new (Mem) TypeTraitExpr(EmptyShell());
1395}
1396
David Blaikie68e081d2011-12-20 02:48:34 +00001397void ArrayTypeTraitExpr::anchor() { }