blob: 1dc7de1b4dbb6c153cf6c0adbbd064b9fe49cc29 [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
Benjamin Kramer4ab984e2012-07-04 20:19:54 +000014#include "clang/AST/ASTContext.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000015#include "clang/AST/Attr.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"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000020#include "clang/Basic/IdentifierTable.h"
Ted Kremeneke3a0c142007-08-24 20:21:10 +000021using namespace clang;
22
Douglas Gregor9da64192010-04-26 22:37:10 +000023
Ted Kremeneke3a0c142007-08-24 20:21:10 +000024//===----------------------------------------------------------------------===//
25// Child Iterators for iterating over subexpressions/substatements
26//===----------------------------------------------------------------------===//
27
Richard Smithef8bf432012-08-13 20:08:14 +000028bool CXXTypeidExpr::isPotentiallyEvaluated() const {
29 if (isTypeOperand())
30 return false;
31
32 // C++11 [expr.typeid]p3:
33 // When typeid is applied to an expression other than a glvalue of
34 // polymorphic class type, [...] the expression is an unevaluated operand.
35 const Expr *E = getExprOperand();
36 if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
37 if (RD->isPolymorphic() && E->isGLValue())
38 return true;
39
40 return false;
41}
42
Douglas Gregor9da64192010-04-26 22:37:10 +000043QualType CXXTypeidExpr::getTypeOperand() const {
44 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
45 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
46 .getUnqualifiedType();
47}
48
Francois Pichet9f4f2072010-09-08 12:20:18 +000049QualType CXXUuidofExpr::getTypeOperand() const {
50 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
51 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
52 .getUnqualifiedType();
53}
54
Nico Webercf4ff5862012-10-11 10:13:44 +000055// static
56UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT) {
57 // Optionally remove one level of pointer, reference or array indirection.
58 const Type *Ty = QT.getTypePtr();
59 if (QT->isPointerType() || QT->isReferenceType())
60 Ty = QT->getPointeeType().getTypePtr();
61 else if (QT->isArrayType())
62 Ty = cast<ArrayType>(QT)->getElementType().getTypePtr();
63
64 // Loop all record redeclaration looking for an uuid attribute.
65 CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
66 for (CXXRecordDecl::redecl_iterator I = RD->redecls_begin(),
67 E = RD->redecls_end(); I != E; ++I) {
68 if (UuidAttr *Uuid = I->getAttr<UuidAttr>())
69 return Uuid;
70 }
71
72 return 0;
73}
74
Douglas Gregor747eb782010-07-08 06:14:04 +000075// CXXScalarValueInitExpr
Douglas Gregor2b88c112010-09-08 00:15:04 +000076SourceRange CXXScalarValueInitExpr::getSourceRange() const {
77 SourceLocation Start = RParenLoc;
78 if (TypeInfo)
79 Start = TypeInfo->getTypeLoc().getBeginLoc();
80 return SourceRange(Start, RParenLoc);
81}
82
Sebastian Redlbd150f42008-11-21 19:14:01 +000083// CXXNewExpr
Ted Kremenek9d6eb402010-02-11 22:51:03 +000084CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Sebastian Redlc3a3c602012-02-16 11:35:52 +000085 FunctionDecl *operatorDelete,
Sebastian Redl6047f072012-02-16 12:22:20 +000086 bool usualArrayDeleteWantsSize,
Benjamin Kramerc215e762012-08-24 11:54:20 +000087 ArrayRef<Expr*> placementArgs,
Sebastian Redl6047f072012-02-16 12:22:20 +000088 SourceRange typeIdParens, Expr *arraySize,
89 InitializationStyle initializationStyle,
90 Expr *initializer, QualType ty,
91 TypeSourceInfo *allocatedTypeInfo,
David Blaikie7b97aef2012-11-07 00:12:38 +000092 SourceRange Range, SourceRange directInitRange)
John McCall7decc9e2010-11-18 06:31:45 +000093 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
Douglas Gregora6e053e2010-12-15 01:34:56 +000094 ty->isDependentType(), ty->isDependentType(),
Douglas Gregor678d76c2011-07-01 01:22:09 +000095 ty->isInstantiationDependentType(),
Douglas Gregora6e053e2010-12-15 01:34:56 +000096 ty->containsUnexpandedParameterPack()),
Sebastian Redl6047f072012-02-16 12:22:20 +000097 SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete),
98 AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens),
David Blaikie7b97aef2012-11-07 00:12:38 +000099 Range(Range), DirectInitRange(directInitRange),
Benjamin Kramerb73f76b2012-02-26 20:37:14 +0000100 GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {
Sebastian Redl6047f072012-02-16 12:22:20 +0000101 assert((initializer != 0 || initializationStyle == NoInit) &&
102 "Only NoInit can have no initializer.");
103 StoredInitializationStyle = initializer ? initializationStyle + 1 : 0;
Benjamin Kramerc215e762012-08-24 11:54:20 +0000104 AllocateArgsArray(C, arraySize != 0, placementArgs.size(), initializer != 0);
Sebastian Redlbd150f42008-11-21 19:14:01 +0000105 unsigned i = 0;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000106 if (Array) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000107 if (arraySize->isInstantiationDependent())
108 ExprBits.InstantiationDependent = true;
109
Douglas Gregora6e053e2010-12-15 01:34:56 +0000110 if (arraySize->containsUnexpandedParameterPack())
111 ExprBits.ContainsUnexpandedParameterPack = true;
112
Sebastian Redl351bb782008-12-02 14:43:59 +0000113 SubExprs[i++] = arraySize;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000114 }
115
Sebastian Redl6047f072012-02-16 12:22:20 +0000116 if (initializer) {
117 if (initializer->isInstantiationDependent())
118 ExprBits.InstantiationDependent = true;
119
120 if (initializer->containsUnexpandedParameterPack())
121 ExprBits.ContainsUnexpandedParameterPack = true;
122
123 SubExprs[i++] = initializer;
124 }
125
Benjamin Kramerc215e762012-08-24 11:54:20 +0000126 for (unsigned j = 0; j != placementArgs.size(); ++j) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000127 if (placementArgs[j]->isInstantiationDependent())
128 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000129 if (placementArgs[j]->containsUnexpandedParameterPack())
130 ExprBits.ContainsUnexpandedParameterPack = true;
131
Sebastian Redlbd150f42008-11-21 19:14:01 +0000132 SubExprs[i++] = placementArgs[j];
Douglas Gregora6e053e2010-12-15 01:34:56 +0000133 }
David Blaikie3a0de212012-11-08 22:53:48 +0000134
135 switch (getInitializationStyle()) {
136 case CallInit:
137 this->Range.setEnd(DirectInitRange.getEnd()); break;
138 case ListInit:
139 this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break;
140 default: break;
141 }
Sebastian Redlbd150f42008-11-21 19:14:01 +0000142}
143
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000144void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
Sebastian Redl6047f072012-02-16 12:22:20 +0000145 unsigned numPlaceArgs, bool hasInitializer){
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000146 assert(SubExprs == 0 && "SubExprs already allocated");
147 Array = isArray;
148 NumPlacementArgs = numPlaceArgs;
Sebastian Redl6047f072012-02-16 12:22:20 +0000149
150 unsigned TotalSize = Array + hasInitializer + NumPlacementArgs;
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000151 SubExprs = new (C) Stmt*[TotalSize];
152}
153
Sebastian Redl31ad7542011-03-13 17:09:40 +0000154bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCall75f94982011-03-07 03:12:35 +0000155 return getOperatorNew()->getType()->
Sebastian Redl31ad7542011-03-13 17:09:40 +0000156 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCall75f94982011-03-07 03:12:35 +0000157}
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000158
Sebastian Redlbd150f42008-11-21 19:14:01 +0000159// CXXDeleteExpr
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000160QualType CXXDeleteExpr::getDestroyedType() const {
161 const Expr *Arg = getArgument();
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000162 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silverstein3b9936f2010-10-20 00:56:01 +0000163 const QualType ArgType = Arg->getType();
Craig Silverstein9e448da2010-11-16 07:16:25 +0000164
165 if (ArgType->isDependentType() && !ArgType->isPointerType())
166 return QualType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000167
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000168 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000169}
170
Douglas Gregorad8a3362009-09-04 17:36:40 +0000171// CXXPseudoDestructorExpr
Douglas Gregor678f90d2010-02-25 01:56:36 +0000172PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
173 : Type(Info)
174{
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000175 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000176}
177
John McCalldb40c7f2010-12-14 08:05:40 +0000178CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregora6ce6082011-02-25 18:19:59 +0000179 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
180 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
181 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
182 PseudoDestructorTypeStorage DestroyedType)
John McCalldb40c7f2010-12-14 08:05:40 +0000183 : Expr(CXXPseudoDestructorExprClass,
184 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
185 FunctionProtoType::ExtProtoInfo())),
186 VK_RValue, OK_Ordinary,
187 /*isTypeDependent=*/(Base->isTypeDependent() ||
188 (DestroyedType.getTypeSourceInfo() &&
189 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000190 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000191 (Base->isInstantiationDependent() ||
192 (QualifierLoc &&
193 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
194 (ScopeType &&
195 ScopeType->getType()->isInstantiationDependentType()) ||
196 (DestroyedType.getTypeSourceInfo() &&
197 DestroyedType.getTypeSourceInfo()->getType()
198 ->isInstantiationDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000199 // ContainsUnexpandedParameterPack
200 (Base->containsUnexpandedParameterPack() ||
Douglas Gregora6ce6082011-02-25 18:19:59 +0000201 (QualifierLoc &&
202 QualifierLoc.getNestedNameSpecifier()
203 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +0000204 (ScopeType &&
205 ScopeType->getType()->containsUnexpandedParameterPack()) ||
206 (DestroyedType.getTypeSourceInfo() &&
207 DestroyedType.getTypeSourceInfo()->getType()
208 ->containsUnexpandedParameterPack()))),
John McCalldb40c7f2010-12-14 08:05:40 +0000209 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregora6ce6082011-02-25 18:19:59 +0000210 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalldb40c7f2010-12-14 08:05:40 +0000211 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
212 DestroyedType(DestroyedType) { }
213
Douglas Gregor678f90d2010-02-25 01:56:36 +0000214QualType CXXPseudoDestructorExpr::getDestroyedType() const {
215 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
216 return TInfo->getType();
217
218 return QualType();
219}
220
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000221SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregor678f90d2010-02-25 01:56:36 +0000222 SourceLocation End = DestroyedType.getLocation();
223 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000224 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000225 return SourceRange(Base->getLocStart(), End);
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000226}
227
John McCalld14a8642009-11-21 08:51:07 +0000228// UnresolvedLookupExpr
John McCalle66edc12009-11-24 19:00:30 +0000229UnresolvedLookupExpr *
Douglas Gregora6e053e2010-12-15 01:34:56 +0000230UnresolvedLookupExpr::Create(ASTContext &C,
John McCall58cc69d2010-01-27 01:50:18 +0000231 CXXRecordDecl *NamingClass,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000232 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000233 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000234 const DeclarationNameInfo &NameInfo,
235 bool ADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000236 const TemplateArgumentListInfo *Args,
237 UnresolvedSetIterator Begin,
238 UnresolvedSetIterator End)
John McCalle66edc12009-11-24 19:00:30 +0000239{
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000240 assert(Args || TemplateKWLoc.isValid());
241 unsigned num_args = Args ? Args->size() : 0;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000242 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000243 ASTTemplateKWAndArgsInfo::sizeFor(num_args));
Abramo Bagnara7945c982012-01-27 09:46:47 +0000244 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
245 TemplateKWLoc, NameInfo,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000246 ADL, /*Overload*/ true, Args,
Richard Smithb6626742012-10-18 17:56:02 +0000247 Begin, End);
John McCalle66edc12009-11-24 19:00:30 +0000248}
249
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000250UnresolvedLookupExpr *
Abramo Bagnara7945c982012-01-27 09:46:47 +0000251UnresolvedLookupExpr::CreateEmpty(ASTContext &C,
252 bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +0000253 unsigned NumTemplateArgs) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000254 std::size_t size = sizeof(UnresolvedLookupExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000255 if (HasTemplateKWAndArgsInfo)
256 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000257
Chris Lattner5c0b4052010-10-30 05:14:06 +0000258 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000259 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000260 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000261 return E;
262}
263
Douglas Gregora6e053e2010-12-15 01:34:56 +0000264OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000265 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000266 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000267 const DeclarationNameInfo &NameInfo,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000268 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregorc69978f2010-05-23 19:36:40 +0000269 UnresolvedSetIterator Begin,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000270 UnresolvedSetIterator End,
271 bool KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000272 bool KnownInstantiationDependent,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000273 bool KnownContainsUnexpandedParameterPack)
274 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
275 KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000276 (KnownInstantiationDependent ||
277 NameInfo.isInstantiationDependent() ||
278 (QualifierLoc &&
279 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000280 (KnownContainsUnexpandedParameterPack ||
281 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor0da1d432011-02-28 20:01:57 +0000282 (QualifierLoc &&
283 QualifierLoc.getNestedNameSpecifier()
284 ->containsUnexpandedParameterPack()))),
Benjamin Kramerb73f76b2012-02-26 20:37:14 +0000285 NameInfo(NameInfo), QualifierLoc(QualifierLoc),
286 Results(0), NumResults(End - Begin),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000287 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid())
Douglas Gregorc69978f2010-05-23 19:36:40 +0000288{
Douglas Gregora6e053e2010-12-15 01:34:56 +0000289 NumResults = End - Begin;
290 if (NumResults) {
291 // Determine whether this expression is type-dependent.
292 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
293 if ((*I)->getDeclContext()->isDependentContext() ||
294 isa<UnresolvedUsingValueDecl>(*I)) {
295 ExprBits.TypeDependent = true;
296 ExprBits.ValueDependent = true;
Richard Smith47726b22012-08-13 21:29:18 +0000297 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000298 }
299 }
300
301 Results = static_cast<DeclAccessPair *>(
302 C.Allocate(sizeof(DeclAccessPair) * NumResults,
303 llvm::alignOf<DeclAccessPair>()));
304 memcpy(Results, &*Begin.getIterator(),
305 NumResults * sizeof(DeclAccessPair));
306 }
307
308 // If we have explicit template arguments, check for dependent
309 // template arguments and whether they contain any unexpanded pack
310 // expansions.
311 if (TemplateArgs) {
312 bool Dependent = false;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000313 bool InstantiationDependent = false;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000314 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000315 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
316 Dependent,
317 InstantiationDependent,
318 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000319
320 if (Dependent) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000321 ExprBits.TypeDependent = true;
322 ExprBits.ValueDependent = true;
323 }
324 if (InstantiationDependent)
325 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000326 if (ContainsUnexpandedParameterPack)
327 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000328 } else if (TemplateKWLoc.isValid()) {
329 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000330 }
331
332 if (isTypeDependent())
333 setType(C.DependentTy);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000334}
335
336void OverloadExpr::initializeResults(ASTContext &C,
337 UnresolvedSetIterator Begin,
338 UnresolvedSetIterator End) {
339 assert(Results == 0 && "Results already initialized!");
340 NumResults = End - Begin;
Douglas Gregorc69978f2010-05-23 19:36:40 +0000341 if (NumResults) {
Douglas Gregora6e053e2010-12-15 01:34:56 +0000342 Results = static_cast<DeclAccessPair *>(
343 C.Allocate(sizeof(DeclAccessPair) * NumResults,
344
345 llvm::alignOf<DeclAccessPair>()));
346 memcpy(Results, &*Begin.getIterator(),
347 NumResults * sizeof(DeclAccessPair));
Douglas Gregorc69978f2010-05-23 19:36:40 +0000348 }
349}
350
John McCall8c12dc42010-04-22 18:44:12 +0000351CXXRecordDecl *OverloadExpr::getNamingClass() const {
352 if (isa<UnresolvedLookupExpr>(this))
353 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
354 else
355 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
356}
357
John McCall8cd78132009-11-19 22:55:06 +0000358// DependentScopeDeclRefExpr
Douglas Gregora6e053e2010-12-15 01:34:56 +0000359DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000360 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000361 SourceLocation TemplateKWLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000362 const DeclarationNameInfo &NameInfo,
363 const TemplateArgumentListInfo *Args)
364 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
365 true, true,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000366 (NameInfo.isInstantiationDependent() ||
367 (QualifierLoc &&
368 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000369 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000370 (QualifierLoc &&
371 QualifierLoc.getNestedNameSpecifier()
372 ->containsUnexpandedParameterPack()))),
373 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000374 HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid())
Douglas Gregora6e053e2010-12-15 01:34:56 +0000375{
376 if (Args) {
377 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000378 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000379 bool ContainsUnexpandedParameterPack
380 = ExprBits.ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000381 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args,
382 Dependent,
383 InstantiationDependent,
384 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000385 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000386 } else if (TemplateKWLoc.isValid()) {
387 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000388 }
389}
390
John McCalle66edc12009-11-24 19:00:30 +0000391DependentScopeDeclRefExpr *
392DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000393 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000394 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000395 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +0000396 const TemplateArgumentListInfo *Args) {
397 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCalle66edc12009-11-24 19:00:30 +0000398 if (Args)
Abramo Bagnara7945c982012-01-27 09:46:47 +0000399 size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size());
400 else if (TemplateKWLoc.isValid())
401 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000402 void *Mem = C.Allocate(size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000403 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
404 TemplateKWLoc, NameInfo, Args);
John McCalle66edc12009-11-24 19:00:30 +0000405}
406
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000407DependentScopeDeclRefExpr *
408DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000409 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000410 unsigned NumTemplateArgs) {
411 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000412 if (HasTemplateKWAndArgsInfo)
413 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000414 void *Mem = C.Allocate(size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000415 DependentScopeDeclRefExpr *E
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000416 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000417 SourceLocation(),
Douglas Gregor87866ce2011-02-04 12:01:24 +0000418 DeclarationNameInfo(), 0);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000419 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregor87866ce2011-02-04 12:01:24 +0000420 return E;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000421}
422
Chandler Carruth01718152010-10-25 08:47:36 +0000423SourceRange CXXConstructExpr::getSourceRange() const {
John McCall701417a2011-02-21 06:23:05 +0000424 if (isa<CXXTemporaryObjectExpr>(this))
425 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
426
Douglas Gregor15417cf2010-11-03 00:35:38 +0000427 if (ParenRange.isValid())
428 return SourceRange(Loc, ParenRange.getEnd());
429
430 SourceLocation End = Loc;
431 for (unsigned I = getNumArgs(); I > 0; --I) {
432 const Expr *Arg = getArg(I-1);
433 if (!Arg->isDefaultArgument()) {
434 SourceLocation NewEnd = Arg->getLocEnd();
435 if (NewEnd.isValid()) {
436 End = NewEnd;
437 break;
438 }
439 }
440 }
441
442 return SourceRange(Loc, End);
Ted Kremenek49ace5c2009-12-23 04:00:48 +0000443}
444
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000445SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
Douglas Gregor993603d2008-11-14 16:09:21 +0000446 OverloadedOperatorKind Kind = getOperator();
447 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
448 if (getNumArgs() == 1)
449 // Prefix operator
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000450 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000451 else
452 // Postfix operator
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000453 return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
Chandler Carruthf20ec9232011-04-02 09:47:38 +0000454 } else if (Kind == OO_Arrow) {
455 return getArg(0)->getSourceRange();
Douglas Gregor993603d2008-11-14 16:09:21 +0000456 } else if (Kind == OO_Call) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000457 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000458 } else if (Kind == OO_Subscript) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000459 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000460 } else if (getNumArgs() == 1) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000461 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000462 } else if (getNumArgs() == 2) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000463 return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000464 } else {
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000465 return getOperatorLoc();
Douglas Gregor993603d2008-11-14 16:09:21 +0000466 }
467}
468
Ted Kremenek98a24e32011-03-30 17:41:19 +0000469Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
Jordan Rose16fe35e2012-08-03 23:08:39 +0000470 const Expr *Callee = getCallee()->IgnoreParens();
471 if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee))
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000472 return MemExpr->getBase();
Jordan Rose16fe35e2012-08-03 23:08:39 +0000473 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee))
474 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
475 return BO->getLHS();
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000476
477 // FIXME: Will eventually need to cope with member pointers.
478 return 0;
479}
480
Ted Kremenek98a24e32011-03-30 17:41:19 +0000481CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
482 if (const MemberExpr *MemExpr =
483 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
484 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
485
486 // FIXME: Will eventually need to cope with member pointers.
487 return 0;
488}
489
490
David Blaikiec0f58662012-05-03 16:25:49 +0000491CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Chandler Carruth00426b42010-10-27 06:55:41 +0000492 Expr* ThisArg = getImplicitObjectArgument();
493 if (!ThisArg)
494 return 0;
495
496 if (ThisArg->getType()->isAnyPointerType())
497 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
498
499 return ThisArg->getType()->getAsCXXRecordDecl();
500}
501
Douglas Gregoref986e82009-11-12 15:31:47 +0000502
Douglas Gregore200adc2008-10-27 19:41:14 +0000503//===----------------------------------------------------------------------===//
504// Named casts
505//===----------------------------------------------------------------------===//
506
507/// getCastName - Get the name of the C++ cast being used, e.g.,
508/// "static_cast", "dynamic_cast", "reinterpret_cast", or
509/// "const_cast". The returned pointer must not be freed.
510const char *CXXNamedCastExpr::getCastName() const {
511 switch (getStmtClass()) {
512 case CXXStaticCastExprClass: return "static_cast";
513 case CXXDynamicCastExprClass: return "dynamic_cast";
514 case CXXReinterpretCastExprClass: return "reinterpret_cast";
515 case CXXConstCastExprClass: return "const_cast";
516 default: return "<invalid cast>";
517 }
518}
Douglas Gregordd04d332009-01-16 18:33:17 +0000519
John McCallcf142162010-08-07 06:22:56 +0000520CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000521 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000522 CastKind K, Expr *Op,
523 const CXXCastPath *BasePath,
524 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000525 SourceLocation L,
526 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000527 unsigned PathSize = (BasePath ? BasePath->size() : 0);
528 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
529 + PathSize * sizeof(CXXBaseSpecifier*));
530 CXXStaticCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000531 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
532 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000533 if (PathSize) E->setCastPath(*BasePath);
534 return E;
535}
536
537CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
538 unsigned PathSize) {
539 void *Buffer =
540 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
541 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
542}
543
544CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000545 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000546 CastKind K, Expr *Op,
547 const CXXCastPath *BasePath,
548 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000549 SourceLocation L,
550 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000551 unsigned PathSize = (BasePath ? BasePath->size() : 0);
552 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
553 + PathSize * sizeof(CXXBaseSpecifier*));
554 CXXDynamicCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000555 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
556 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000557 if (PathSize) E->setCastPath(*BasePath);
558 return E;
559}
560
561CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
562 unsigned PathSize) {
563 void *Buffer =
564 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
565 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
566}
567
Anders Carlsson267c0c92011-04-11 01:43:55 +0000568/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
569/// to always be null. For example:
570///
571/// struct A { };
572/// struct B final : A { };
573/// struct C { };
574///
575/// C *f(B* b) { return dynamic_cast<C*>(b); }
576bool CXXDynamicCastExpr::isAlwaysNull() const
577{
578 QualType SrcType = getSubExpr()->getType();
579 QualType DestType = getType();
580
581 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
582 SrcType = SrcPTy->getPointeeType();
583 DestType = DestType->castAs<PointerType>()->getPointeeType();
584 }
585
Alexis Hunt78e2b912012-06-19 23:44:55 +0000586 if (DestType->isVoidType())
587 return false;
588
Anders Carlsson267c0c92011-04-11 01:43:55 +0000589 const CXXRecordDecl *SrcRD =
590 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
591
Jakob Stoklund Olesene1c0ae62012-06-19 21:48:43 +0000592 if (!SrcRD->hasAttr<FinalAttr>())
593 return false;
594
Anders Carlsson267c0c92011-04-11 01:43:55 +0000595 const CXXRecordDecl *DestRD =
596 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
597
598 return !DestRD->isDerivedFrom(SrcRD);
599}
600
John McCallcf142162010-08-07 06:22:56 +0000601CXXReinterpretCastExpr *
John McCall7decc9e2010-11-18 06:31:45 +0000602CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
603 CastKind K, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000604 const CXXCastPath *BasePath,
Douglas Gregor4478f852011-01-12 22:41:29 +0000605 TypeSourceInfo *WrittenTy, SourceLocation L,
606 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000607 unsigned PathSize = (BasePath ? BasePath->size() : 0);
608 void *Buffer =
609 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
610 CXXReinterpretCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000611 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
612 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000613 if (PathSize) E->setCastPath(*BasePath);
614 return E;
615}
616
617CXXReinterpretCastExpr *
618CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
619 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
620 + PathSize * sizeof(CXXBaseSpecifier*));
621 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
622}
623
John McCall7decc9e2010-11-18 06:31:45 +0000624CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
625 ExprValueKind VK, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000626 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000627 SourceLocation L,
628 SourceLocation RParenLoc) {
629 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000630}
631
632CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
633 return new (C) CXXConstCastExpr(EmptyShell());
634}
635
636CXXFunctionalCastExpr *
John McCall7decc9e2010-11-18 06:31:45 +0000637CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000638 TypeSourceInfo *Written, SourceLocation L,
639 CastKind K, Expr *Op, const CXXCastPath *BasePath,
640 SourceLocation R) {
641 unsigned PathSize = (BasePath ? BasePath->size() : 0);
642 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
643 + PathSize * sizeof(CXXBaseSpecifier*));
644 CXXFunctionalCastExpr *E =
John McCall7decc9e2010-11-18 06:31:45 +0000645 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallcf142162010-08-07 06:22:56 +0000646 if (PathSize) E->setCastPath(*BasePath);
647 return E;
648}
649
650CXXFunctionalCastExpr *
651CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
652 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
653 + PathSize * sizeof(CXXBaseSpecifier*));
654 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
655}
656
Richard Smithc67fdd42012-03-07 08:35:16 +0000657UserDefinedLiteral::LiteralOperatorKind
658UserDefinedLiteral::getLiteralOperatorKind() const {
659 if (getNumArgs() == 0)
660 return LOK_Template;
661 if (getNumArgs() == 2)
662 return LOK_String;
663
664 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
665 QualType ParamTy =
666 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
667 if (ParamTy->isPointerType())
668 return LOK_Raw;
669 if (ParamTy->isAnyCharacterType())
670 return LOK_Character;
671 if (ParamTy->isIntegerType())
672 return LOK_Integer;
673 if (ParamTy->isFloatingType())
674 return LOK_Floating;
675
676 llvm_unreachable("unknown kind of literal operator");
677}
678
679Expr *UserDefinedLiteral::getCookedLiteral() {
680#ifndef NDEBUG
681 LiteralOperatorKind LOK = getLiteralOperatorKind();
682 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
683#endif
684 return getArg(0);
685}
686
687const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
688 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
689}
John McCallcf142162010-08-07 06:22:56 +0000690
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000691CXXDefaultArgExpr *
Douglas Gregor033f6752009-12-23 23:03:06 +0000692CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
693 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000694 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor033f6752009-12-23 23:03:06 +0000695 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
696 SubExpr);
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000697}
698
Mike Stump11289f42009-09-09 15:08:12 +0000699CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonffda6062009-05-30 20:34:37 +0000700 const CXXDestructorDecl *Destructor) {
Anders Carlsson73b836b2009-05-30 22:38:53 +0000701 return new (C) CXXTemporary(Destructor);
702}
703
Mike Stump11289f42009-09-09 15:08:12 +0000704CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlsson993a4b32009-05-30 20:03:25 +0000705 CXXTemporary *Temp,
706 Expr* SubExpr) {
Peter Collingbournefbef4c82011-11-27 22:09:28 +0000707 assert((SubExpr->getType()->isRecordType() ||
708 SubExpr->getType()->isArrayType()) &&
709 "Expression bound to a temporary must have record or array type!");
Anders Carlsson993a4b32009-05-30 20:03:25 +0000710
Douglas Gregora6e053e2010-12-15 01:34:56 +0000711 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlsson993a4b32009-05-30 20:03:25 +0000712}
713
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000714CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson56c5bd82009-04-24 05:23:13 +0000715 CXXConstructorDecl *Cons,
Douglas Gregor2b88c112010-09-08 00:15:04 +0000716 TypeSourceInfo *Type,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000717 ArrayRef<Expr*> Args,
Chandler Carruth01718152010-10-25 08:47:36 +0000718 SourceRange parenRange,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000719 bool HadMultipleCandidates,
Douglas Gregor199db362010-04-27 20:36:09 +0000720 bool ZeroInitialization)
Douglas Gregor2b88c112010-09-08 00:15:04 +0000721 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
722 Type->getType().getNonReferenceType(),
723 Type->getTypeLoc().getBeginLoc(),
Benjamin Kramerc215e762012-08-24 11:54:20 +0000724 Cons, false, Args,
Sebastian Redla9351792012-02-11 23:51:47 +0000725 HadMultipleCandidates, /*FIXME*/false, ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000726 CXXConstructExpr::CK_Complete, parenRange),
727 Type(Type) {
Douglas Gregor2b88c112010-09-08 00:15:04 +0000728}
729
730SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth01718152010-10-25 08:47:36 +0000731 return SourceRange(Type->getTypeLoc().getBeginLoc(),
732 getParenRange().getEnd());
Douglas Gregordd04d332009-01-16 18:33:17 +0000733}
Anders Carlsson6f287832009-04-21 02:22:11 +0000734
Mike Stump11289f42009-09-09 15:08:12 +0000735CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000736 SourceLocation Loc,
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000737 CXXConstructorDecl *D, bool Elidable,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000738 ArrayRef<Expr*> Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000739 bool HadMultipleCandidates,
Sebastian Redla9351792012-02-11 23:51:47 +0000740 bool ListInitialization,
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000741 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000742 ConstructionKind ConstructKind,
743 SourceRange ParenRange) {
Douglas Gregor85dabae2009-12-16 01:38:02 +0000744 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000745 Elidable, Args,
Sebastian Redla9351792012-02-11 23:51:47 +0000746 HadMultipleCandidates, ListInitialization,
747 ZeroInitialization, ConstructKind,
748 ParenRange);
Anders Carlsson0781ce72009-04-23 02:32:43 +0000749}
750
Mike Stump11289f42009-09-09 15:08:12 +0000751CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000752 SourceLocation Loc,
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000753 CXXConstructorDecl *D, bool elidable,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000754 ArrayRef<Expr*> args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000755 bool HadMultipleCandidates,
Sebastian Redla9351792012-02-11 23:51:47 +0000756 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000757 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000758 ConstructionKind ConstructKind,
759 SourceRange ParenRange)
Douglas Gregora6e053e2010-12-15 01:34:56 +0000760 : Expr(SC, T, VK_RValue, OK_Ordinary,
761 T->isDependentType(), T->isDependentType(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000762 T->isInstantiationDependentType(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000763 T->containsUnexpandedParameterPack()),
Benjamin Kramerc215e762012-08-24 11:54:20 +0000764 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(args.size()),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000765 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
Sebastian Redla9351792012-02-11 23:51:47 +0000766 ListInitialization(ListInitialization),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000767 ZeroInitialization(ZeroInitialization),
Douglas Gregor488c2312011-09-26 14:47:03 +0000768 ConstructKind(ConstructKind), Args(0)
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000769{
770 if (NumArgs) {
Benjamin Kramerc215e762012-08-24 11:54:20 +0000771 Args = new (C) Stmt*[args.size()];
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000772
Benjamin Kramerc215e762012-08-24 11:54:20 +0000773 for (unsigned i = 0; i != args.size(); ++i) {
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000774 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregora6e053e2010-12-15 01:34:56 +0000775
776 if (args[i]->isValueDependent())
777 ExprBits.ValueDependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000778 if (args[i]->isInstantiationDependent())
779 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000780 if (args[i]->containsUnexpandedParameterPack())
781 ExprBits.ContainsUnexpandedParameterPack = true;
782
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000783 Args[i] = args[i];
Anders Carlsson0781ce72009-04-23 02:32:43 +0000784 }
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000785 }
Anders Carlsson0781ce72009-04-23 02:32:43 +0000786}
787
Douglas Gregore31e6062012-02-07 10:09:13 +0000788LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
789 LambdaCaptureKind Kind, VarDecl *Var,
790 SourceLocation EllipsisLoc)
791 : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
792{
793 unsigned Bits = 0;
794 if (Implicit)
795 Bits |= Capture_Implicit;
796
797 switch (Kind) {
798 case LCK_This:
799 assert(Var == 0 && "'this' capture cannot have a variable!");
800 break;
801
802 case LCK_ByCopy:
803 Bits |= Capture_ByCopy;
804 // Fall through
805 case LCK_ByRef:
806 assert(Var && "capture must have a variable!");
807 break;
808 }
809 VarAndBits.setInt(Bits);
810}
811
812LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const {
813 if (capturesThis())
814 return LCK_This;
815
816 return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef;
817}
818
819LambdaExpr::LambdaExpr(QualType T,
820 SourceRange IntroducerRange,
821 LambdaCaptureDefault CaptureDefault,
822 ArrayRef<Capture> Captures,
823 bool ExplicitParams,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000824 bool ExplicitResultType,
Douglas Gregore31e6062012-02-07 10:09:13 +0000825 ArrayRef<Expr *> CaptureInits,
Douglas Gregore5561632012-02-13 17:20:40 +0000826 ArrayRef<VarDecl *> ArrayIndexVars,
827 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000828 SourceLocation ClosingBrace,
829 bool ContainsUnexpandedParameterPack)
Douglas Gregore31e6062012-02-07 10:09:13 +0000830 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
831 T->isDependentType(), T->isDependentType(), T->isDependentType(),
Richard Smith2589b9802012-07-25 03:56:55 +0000832 ContainsUnexpandedParameterPack),
Douglas Gregore31e6062012-02-07 10:09:13 +0000833 IntroducerRange(IntroducerRange),
Douglas Gregore5561632012-02-13 17:20:40 +0000834 NumCaptures(Captures.size()),
Douglas Gregore31e6062012-02-07 10:09:13 +0000835 CaptureDefault(CaptureDefault),
836 ExplicitParams(ExplicitParams),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000837 ExplicitResultType(ExplicitResultType),
Douglas Gregore31e6062012-02-07 10:09:13 +0000838 ClosingBrace(ClosingBrace)
839{
840 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorc8a73492012-02-13 15:44:47 +0000841 CXXRecordDecl *Class = getLambdaClass();
842 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Douglas Gregorc8a73492012-02-13 15:44:47 +0000843
844 // FIXME: Propagate "has unexpanded parameter pack" bit.
Douglas Gregore5561632012-02-13 17:20:40 +0000845
846 // Copy captures.
847 ASTContext &Context = Class->getASTContext();
848 Data.NumCaptures = NumCaptures;
849 Data.NumExplicitCaptures = 0;
850 Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures);
851 Capture *ToCapture = Data.Captures;
852 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
853 if (Captures[I].isExplicit())
854 ++Data.NumExplicitCaptures;
855
856 *ToCapture++ = Captures[I];
857 }
858
859 // Copy initialization expressions for the non-static data members.
860 Stmt **Stored = getStoredStmts();
861 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
862 *Stored++ = CaptureInits[I];
863
864 // Copy the body of the lambda.
865 *Stored++ = getCallOperator()->getBody();
866
867 // Copy the array index variables, if any.
868 HasArrayIndexVars = !ArrayIndexVars.empty();
869 if (HasArrayIndexVars) {
870 assert(ArrayIndexStarts.size() == NumCaptures);
871 memcpy(getArrayIndexVars(), ArrayIndexVars.data(),
872 sizeof(VarDecl *) * ArrayIndexVars.size());
873 memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(),
874 sizeof(unsigned) * Captures.size());
875 getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size();
Douglas Gregor6f88e5e2012-02-21 04:17:39 +0000876 }
Douglas Gregore31e6062012-02-07 10:09:13 +0000877}
878
879LambdaExpr *LambdaExpr::Create(ASTContext &Context,
880 CXXRecordDecl *Class,
881 SourceRange IntroducerRange,
882 LambdaCaptureDefault CaptureDefault,
883 ArrayRef<Capture> Captures,
884 bool ExplicitParams,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000885 bool ExplicitResultType,
Douglas Gregore31e6062012-02-07 10:09:13 +0000886 ArrayRef<Expr *> CaptureInits,
Douglas Gregore5561632012-02-13 17:20:40 +0000887 ArrayRef<VarDecl *> ArrayIndexVars,
888 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000889 SourceLocation ClosingBrace,
890 bool ContainsUnexpandedParameterPack) {
Douglas Gregore31e6062012-02-07 10:09:13 +0000891 // Determine the type of the expression (i.e., the type of the
892 // function object we're creating).
893 QualType T = Context.getTypeDeclType(Class);
Douglas Gregore31e6062012-02-07 10:09:13 +0000894
Douglas Gregore5561632012-02-13 17:20:40 +0000895 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1);
Richard Smithc7520bf2012-08-21 05:42:49 +0000896 if (!ArrayIndexVars.empty()) {
897 Size += sizeof(unsigned) * (Captures.size() + 1);
898 // Realign for following VarDecl array.
Richard Smitha75e1cf2012-08-21 18:18:06 +0000899 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>());
Richard Smithc7520bf2012-08-21 05:42:49 +0000900 Size += sizeof(VarDecl *) * ArrayIndexVars.size();
901 }
Douglas Gregore5561632012-02-13 17:20:40 +0000902 void *Mem = Context.Allocate(Size);
903 return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000904 Captures, ExplicitParams, ExplicitResultType,
905 CaptureInits, ArrayIndexVars, ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000906 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregore31e6062012-02-07 10:09:13 +0000907}
908
Douglas Gregor99ae8062012-02-14 17:54:36 +0000909LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures,
910 unsigned NumArrayIndexVars) {
911 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1);
912 if (NumArrayIndexVars)
913 Size += sizeof(VarDecl) * NumArrayIndexVars
914 + sizeof(unsigned) * (NumCaptures + 1);
915 void *Mem = C.Allocate(Size);
916 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0);
917}
918
Douglas Gregorc8a73492012-02-13 15:44:47 +0000919LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregore5561632012-02-13 17:20:40 +0000920 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000921}
922
923LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregore5561632012-02-13 17:20:40 +0000924 return capture_begin() + NumCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000925}
926
927LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
928 return capture_begin();
929}
930
931LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
932 struct CXXRecordDecl::LambdaDefinitionData &Data
933 = getLambdaClass()->getLambdaData();
Douglas Gregore5561632012-02-13 17:20:40 +0000934 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000935}
936
937LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
938 return explicit_capture_end();
939}
940
941LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
942 return capture_end();
943}
944
Douglas Gregor54fcea62012-02-13 16:35:30 +0000945ArrayRef<VarDecl *>
946LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const {
Douglas Gregore5561632012-02-13 17:20:40 +0000947 assert(HasArrayIndexVars && "No array index-var data?");
Douglas Gregor54fcea62012-02-13 16:35:30 +0000948
949 unsigned Index = Iter - capture_init_begin();
Matt Beaumont-Gayf2ee0672012-02-13 19:29:45 +0000950 assert(Index < getLambdaClass()->getLambdaData().NumCaptures &&
951 "Capture index out-of-range");
Douglas Gregore5561632012-02-13 17:20:40 +0000952 VarDecl **IndexVars = getArrayIndexVars();
953 unsigned *IndexStarts = getArrayIndexStarts();
Douglas Gregor54fcea62012-02-13 16:35:30 +0000954 return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index],
955 IndexVars + IndexStarts[Index + 1]);
956}
957
Douglas Gregore31e6062012-02-07 10:09:13 +0000958CXXRecordDecl *LambdaExpr::getLambdaClass() const {
959 return getType()->getAsCXXRecordDecl();
960}
961
962CXXMethodDecl *LambdaExpr::getCallOperator() const {
963 CXXRecordDecl *Record = getLambdaClass();
964 DeclarationName Name
965 = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
966 DeclContext::lookup_result Calls = Record->lookup(Name);
967 assert(Calls.first != Calls.second && "Missing lambda call operator!");
968 CXXMethodDecl *Result = cast<CXXMethodDecl>(*Calls.first++);
969 assert(Calls.first == Calls.second && "More than lambda one call operator?");
970 return Result;
971}
972
Douglas Gregor99ae8062012-02-14 17:54:36 +0000973CompoundStmt *LambdaExpr::getBody() const {
974 if (!getStoredStmts()[NumCaptures])
975 getStoredStmts()[NumCaptures] = getCallOperator()->getBody();
976
977 return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
978}
979
Douglas Gregore31e6062012-02-07 10:09:13 +0000980bool LambdaExpr::isMutable() const {
David Blaikief5697e52012-08-10 00:55:35 +0000981 return !getCallOperator()->isConst();
Douglas Gregore31e6062012-02-07 10:09:13 +0000982}
983
John McCall28fc7092011-11-10 05:35:25 +0000984ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
985 ArrayRef<CleanupObject> objects)
John McCall5d413782010-12-06 08:20:24 +0000986 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCall7decc9e2010-11-18 06:31:45 +0000987 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000988 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000989 subexpr->isInstantiationDependent(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000990 subexpr->containsUnexpandedParameterPack()),
John McCall28fc7092011-11-10 05:35:25 +0000991 SubExpr(subexpr) {
992 ExprWithCleanupsBits.NumObjects = objects.size();
993 for (unsigned i = 0, e = objects.size(); i != e; ++i)
994 getObjectsBuffer()[i] = objects[i];
Anders Carlssondefc6442009-04-24 22:47:04 +0000995}
996
John McCall28fc7092011-11-10 05:35:25 +0000997ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
998 ArrayRef<CleanupObject> objects) {
999 size_t size = sizeof(ExprWithCleanups)
1000 + objects.size() * sizeof(CleanupObject);
1001 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1002 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnercba86142010-05-10 00:25:06 +00001003}
1004
John McCall28fc7092011-11-10 05:35:25 +00001005ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1006 : Expr(ExprWithCleanupsClass, empty) {
1007 ExprWithCleanupsBits.NumObjects = numObjects;
1008}
Chris Lattnercba86142010-05-10 00:25:06 +00001009
John McCall28fc7092011-11-10 05:35:25 +00001010ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
1011 unsigned numObjects) {
1012 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
1013 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1014 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson73b836b2009-05-30 22:38:53 +00001015}
1016
Douglas Gregor2b88c112010-09-08 00:15:04 +00001017CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +00001018 SourceLocation LParenLoc,
Benjamin Kramerc215e762012-08-24 11:54:20 +00001019 ArrayRef<Expr*> Args,
Douglas Gregorce934142009-05-20 18:46:25 +00001020 SourceLocation RParenLoc)
Douglas Gregor2b88c112010-09-08 00:15:04 +00001021 : Expr(CXXUnresolvedConstructExprClass,
1022 Type->getType().getNonReferenceType(),
Douglas Gregor6336f292011-07-08 15:50:43 +00001023 (Type->getType()->isLValueReferenceType() ? VK_LValue
1024 :Type->getType()->isRValueReferenceType()? VK_XValue
1025 :VK_RValue),
1026 OK_Ordinary,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001027 Type->getType()->isDependentType(), true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001028 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001029 Type(Type),
Douglas Gregorce934142009-05-20 18:46:25 +00001030 LParenLoc(LParenLoc),
1031 RParenLoc(RParenLoc),
Benjamin Kramerc215e762012-08-24 11:54:20 +00001032 NumArgs(Args.size()) {
Douglas Gregorce934142009-05-20 18:46:25 +00001033 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Benjamin Kramerc215e762012-08-24 11:54:20 +00001034 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001035 if (Args[I]->containsUnexpandedParameterPack())
1036 ExprBits.ContainsUnexpandedParameterPack = true;
1037
1038 StoredArgs[I] = Args[I];
1039 }
Douglas Gregorce934142009-05-20 18:46:25 +00001040}
1041
1042CXXUnresolvedConstructExpr *
Mike Stump11289f42009-09-09 15:08:12 +00001043CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregor2b88c112010-09-08 00:15:04 +00001044 TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +00001045 SourceLocation LParenLoc,
Benjamin Kramerc215e762012-08-24 11:54:20 +00001046 ArrayRef<Expr*> Args,
Douglas Gregorce934142009-05-20 18:46:25 +00001047 SourceLocation RParenLoc) {
1048 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
Benjamin Kramerc215e762012-08-24 11:54:20 +00001049 sizeof(Expr *) * Args.size());
1050 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
Douglas Gregorce934142009-05-20 18:46:25 +00001051}
1052
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001053CXXUnresolvedConstructExpr *
1054CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
1055 Stmt::EmptyShell Empty;
1056 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
1057 sizeof(Expr *) * NumArgs);
1058 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1059}
1060
Douglas Gregor2b88c112010-09-08 00:15:04 +00001061SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
1062 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
1063}
1064
John McCall8cd78132009-11-19 22:55:06 +00001065CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +00001066 Expr *Base, QualType BaseType,
1067 bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +00001068 SourceLocation OperatorLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001069 NestedNameSpecifierLoc QualifierLoc,
1070 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00001071 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001072 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +00001073 const TemplateArgumentListInfo *TemplateArgs)
John McCall7decc9e2010-11-18 06:31:45 +00001074 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001075 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001076 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregore16af532011-02-28 18:50:33 +00001077 (QualifierLoc &&
1078 QualifierLoc.getNestedNameSpecifier()
1079 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +00001080 MemberNameInfo.containsUnexpandedParameterPack())),
John McCall2d74de92009-12-01 22:10:20 +00001081 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001082 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregore16af532011-02-28 18:50:33 +00001083 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor308047d2009-09-09 00:23:06 +00001084 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001085 MemberNameInfo(MemberNameInfo) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001086 if (TemplateArgs) {
1087 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +00001088 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +00001089 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnara7945c982012-01-27 09:46:47 +00001090 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
1091 Dependent,
1092 InstantiationDependent,
1093 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001094 if (ContainsUnexpandedParameterPack)
1095 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +00001096 } else if (TemplateKWLoc.isValid()) {
1097 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001098 }
Douglas Gregor308047d2009-09-09 00:23:06 +00001099}
1100
Douglas Gregora6e053e2010-12-15 01:34:56 +00001101CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
1102 Expr *Base, QualType BaseType,
1103 bool IsArrow,
1104 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001105 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001106 NamedDecl *FirstQualifierFoundInScope,
1107 DeclarationNameInfo MemberNameInfo)
1108 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001109 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001110 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregore16af532011-02-28 18:50:33 +00001111 (QualifierLoc &&
1112 QualifierLoc.getNestedNameSpecifier()->
1113 containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +00001114 MemberNameInfo.containsUnexpandedParameterPack())),
1115 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001116 HasTemplateKWAndArgsInfo(false),
1117 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregora6e053e2010-12-15 01:34:56 +00001118 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1119 MemberNameInfo(MemberNameInfo) { }
1120
John McCall8cd78132009-11-19 22:55:06 +00001121CXXDependentScopeMemberExpr *
1122CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +00001123 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +00001124 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001125 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001126 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00001127 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001128 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +00001129 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00001130 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCall2d74de92009-12-01 22:10:20 +00001131 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
1132 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001133 QualifierLoc,
John McCall2d74de92009-12-01 22:10:20 +00001134 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001135 MemberNameInfo);
Mike Stump11289f42009-09-09 15:08:12 +00001136
Abramo Bagnara7945c982012-01-27 09:46:47 +00001137 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1138 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
1139 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCall6b51f282009-11-23 01:53:49 +00001140
Chris Lattner5c0b4052010-10-30 05:14:06 +00001141 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCall2d74de92009-12-01 22:10:20 +00001142 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1143 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001144 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001145 TemplateKWLoc,
John McCall2d74de92009-12-01 22:10:20 +00001146 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001147 MemberNameInfo, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001148}
1149
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001150CXXDependentScopeMemberExpr *
1151CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001152 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001153 unsigned NumTemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00001154 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001155 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001156 0, SourceLocation(),
Douglas Gregore16af532011-02-28 18:50:33 +00001157 NestedNameSpecifierLoc(), 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001158 DeclarationNameInfo());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001159
1160 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnara7945c982012-01-27 09:46:47 +00001161 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner5c0b4052010-10-30 05:14:06 +00001162 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001163 CXXDependentScopeMemberExpr *E
1164 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001165 0, SourceLocation(),
1166 NestedNameSpecifierLoc(),
1167 SourceLocation(), 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001168 DeclarationNameInfo(), 0);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001169 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001170 return E;
1171}
1172
Douglas Gregor0da1d432011-02-28 20:01:57 +00001173bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
1174 if (Base == 0)
1175 return true;
1176
Douglas Gregor25b7e052011-03-02 21:06:53 +00001177 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001178}
1179
John McCall0009fcc2011-04-26 20:42:42 +00001180static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1181 UnresolvedSetIterator end) {
1182 do {
1183 NamedDecl *decl = *begin;
1184 if (isa<UnresolvedUsingValueDecl>(decl))
1185 return false;
1186 if (isa<UsingShadowDecl>(decl))
1187 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
1188
1189 // Unresolved member expressions should only contain methods and
1190 // method templates.
1191 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
1192
1193 if (isa<FunctionTemplateDecl>(decl))
1194 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
1195 if (cast<CXXMethodDecl>(decl)->isStatic())
1196 return false;
1197 } while (++begin != end);
1198
1199 return true;
1200}
1201
Douglas Gregora6e053e2010-12-15 01:34:56 +00001202UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +00001203 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +00001204 Expr *Base, QualType BaseType,
1205 bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001206 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001207 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001208 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001209 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +00001210 const TemplateArgumentListInfo *TemplateArgs,
1211 UnresolvedSetIterator Begin,
1212 UnresolvedSetIterator End)
Abramo Bagnara7945c982012-01-27 09:46:47 +00001213 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1214 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001215 // Dependent
1216 ((Base && Base->isTypeDependent()) ||
1217 BaseType->isDependentType()),
Douglas Gregor678d76c2011-07-01 01:22:09 +00001218 ((Base && Base->isInstantiationDependent()) ||
1219 BaseType->isInstantiationDependentType()),
Douglas Gregora6e053e2010-12-15 01:34:56 +00001220 // Contains unexpanded parameter pack
1221 ((Base && Base->containsUnexpandedParameterPack()) ||
1222 BaseType->containsUnexpandedParameterPack())),
John McCall1acbbb52010-02-02 06:20:04 +00001223 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1224 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall0009fcc2011-04-26 20:42:42 +00001225
1226 // Check whether all of the members are non-static member functions,
1227 // and if so, mark give this bound-member type instead of overload type.
1228 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1229 setType(C.BoundMemberTy);
John McCall10eae182009-11-30 22:42:35 +00001230}
1231
Douglas Gregor0da1d432011-02-28 20:01:57 +00001232bool UnresolvedMemberExpr::isImplicitAccess() const {
1233 if (Base == 0)
1234 return true;
1235
Douglas Gregor25b7e052011-03-02 21:06:53 +00001236 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001237}
1238
John McCall10eae182009-11-30 22:42:35 +00001239UnresolvedMemberExpr *
Douglas Gregora6e053e2010-12-15 01:34:56 +00001240UnresolvedMemberExpr::Create(ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +00001241 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +00001242 Expr *Base, QualType BaseType, bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001243 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001244 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001245 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001246 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +00001247 const TemplateArgumentListInfo *TemplateArgs,
1248 UnresolvedSetIterator Begin,
1249 UnresolvedSetIterator End) {
John McCall10eae182009-11-30 22:42:35 +00001250 std::size_t size = sizeof(UnresolvedMemberExpr);
1251 if (TemplateArgs)
Abramo Bagnara7945c982012-01-27 09:46:47 +00001252 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
1253 else if (TemplateKWLoc.isValid())
1254 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall10eae182009-11-30 22:42:35 +00001255
Chris Lattner5c0b4052010-10-30 05:14:06 +00001256 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregorc69978f2010-05-23 19:36:40 +00001257 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001258 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001259 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001260 MemberNameInfo, TemplateArgs, Begin, End);
John McCall10eae182009-11-30 22:42:35 +00001261}
1262
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001263UnresolvedMemberExpr *
Abramo Bagnara7945c982012-01-27 09:46:47 +00001264UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +00001265 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001266 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001267 if (HasTemplateKWAndArgsInfo)
1268 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001269
Chris Lattner5c0b4052010-10-30 05:14:06 +00001270 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001271 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +00001272 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001273 return E;
1274}
1275
John McCall58cc69d2010-01-27 01:50:18 +00001276CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1277 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1278
1279 // If there was a nested name specifier, it names the naming class.
1280 // It can't be dependent: after all, we were actually able to do the
1281 // lookup.
Douglas Gregor9262f472010-04-27 18:19:34 +00001282 CXXRecordDecl *Record = 0;
John McCall1acbbb52010-02-02 06:20:04 +00001283 if (getQualifier()) {
John McCall424cec92011-01-19 06:33:43 +00001284 const Type *T = getQualifier()->getAsType();
John McCall58cc69d2010-01-27 01:50:18 +00001285 assert(T && "qualifier in member expression does not name type");
Douglas Gregor9262f472010-04-27 18:19:34 +00001286 Record = T->getAsCXXRecordDecl();
1287 assert(Record && "qualifier in member expression does not name record");
1288 }
John McCall58cc69d2010-01-27 01:50:18 +00001289 // Otherwise the naming class must have been the base class.
Douglas Gregor9262f472010-04-27 18:19:34 +00001290 else {
John McCall58cc69d2010-01-27 01:50:18 +00001291 QualType BaseType = getBaseType().getNonReferenceType();
1292 if (isArrow()) {
1293 const PointerType *PT = BaseType->getAs<PointerType>();
1294 assert(PT && "base of arrow member access is not pointer");
1295 BaseType = PT->getPointeeType();
1296 }
1297
Douglas Gregor9262f472010-04-27 18:19:34 +00001298 Record = BaseType->getAsCXXRecordDecl();
1299 assert(Record && "base of member expression does not name record");
John McCall58cc69d2010-01-27 01:50:18 +00001300 }
1301
Douglas Gregor9262f472010-04-27 18:19:34 +00001302 return Record;
John McCall58cc69d2010-01-27 01:50:18 +00001303}
1304
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001305SubstNonTypeTemplateParmPackExpr::
1306SubstNonTypeTemplateParmPackExpr(QualType T,
1307 NonTypeTemplateParmDecl *Param,
1308 SourceLocation NameLoc,
1309 const TemplateArgument &ArgPack)
1310 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001311 true, true, true, true),
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001312 Param(Param), Arguments(ArgPack.pack_begin()),
1313 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1314
1315TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1316 return TemplateArgument(Arguments, NumArguments);
1317}
1318
Richard Smithb15fe3a2012-09-12 00:56:43 +00001319FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1320 SourceLocation NameLoc,
1321 unsigned NumParams,
1322 Decl * const *Params)
1323 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary,
1324 true, true, true, true),
1325 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1326 if (Params)
1327 std::uninitialized_copy(Params, Params + NumParams,
1328 reinterpret_cast<Decl**>(this+1));
1329}
1330
1331FunctionParmPackExpr *
1332FunctionParmPackExpr::Create(ASTContext &Context, QualType T,
1333 ParmVarDecl *ParamPack, SourceLocation NameLoc,
1334 llvm::ArrayRef<Decl*> Params) {
1335 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1336 sizeof(ParmVarDecl*) * Params.size()))
1337 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1338}
1339
1340FunctionParmPackExpr *
1341FunctionParmPackExpr::CreateEmpty(ASTContext &Context, unsigned NumParams) {
1342 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1343 sizeof(ParmVarDecl*) * NumParams))
1344 FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0);
1345}
1346
Douglas Gregor29c42f22012-02-24 07:38:34 +00001347TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1348 ArrayRef<TypeSourceInfo *> Args,
1349 SourceLocation RParenLoc,
1350 bool Value)
1351 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1352 /*TypeDependent=*/false,
1353 /*ValueDependent=*/false,
1354 /*InstantiationDependent=*/false,
1355 /*ContainsUnexpandedParameterPack=*/false),
1356 Loc(Loc), RParenLoc(RParenLoc)
1357{
1358 TypeTraitExprBits.Kind = Kind;
1359 TypeTraitExprBits.Value = Value;
1360 TypeTraitExprBits.NumArgs = Args.size();
1361
1362 TypeSourceInfo **ToArgs = getTypeSourceInfos();
1363
1364 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1365 if (Args[I]->getType()->isDependentType())
1366 setValueDependent(true);
1367 if (Args[I]->getType()->isInstantiationDependentType())
1368 setInstantiationDependent(true);
1369 if (Args[I]->getType()->containsUnexpandedParameterPack())
1370 setContainsUnexpandedParameterPack(true);
1371
1372 ToArgs[I] = Args[I];
1373 }
1374}
1375
1376TypeTraitExpr *TypeTraitExpr::Create(ASTContext &C, QualType T,
1377 SourceLocation Loc,
1378 TypeTrait Kind,
1379 ArrayRef<TypeSourceInfo *> Args,
1380 SourceLocation RParenLoc,
1381 bool Value) {
1382 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size();
1383 void *Mem = C.Allocate(Size);
1384 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1385}
1386
1387TypeTraitExpr *TypeTraitExpr::CreateDeserialized(ASTContext &C,
1388 unsigned NumArgs) {
1389 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs;
1390 void *Mem = C.Allocate(Size);
1391 return new (Mem) TypeTraitExpr(EmptyShell());
1392}
1393
David Blaikie68e081d2011-12-20 02:48:34 +00001394void ArrayTypeTraitExpr::anchor() { }