blob: 55722a2a99af732300c9f50db9a3d3824036cffc [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,
David Blaikie7b97aef2012-11-07 00:12:38 +000091 SourceRange Range, 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),
David Blaikie7b97aef2012-11-07 00:12:38 +000098 Range(Range), DirectInitRange(directInitRange),
Benjamin Kramerb73f76b2012-02-26 20:37:14 +000099 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 }
David Blaikie3a0de212012-11-08 22:53:48 +0000133
134 switch (getInitializationStyle()) {
135 case CallInit:
136 this->Range.setEnd(DirectInitRange.getEnd()); break;
137 case ListInit:
138 this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break;
139 default: break;
140 }
Sebastian Redlbd150f42008-11-21 19:14:01 +0000141}
142
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000143void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
Sebastian Redl6047f072012-02-16 12:22:20 +0000144 unsigned numPlaceArgs, bool hasInitializer){
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000145 assert(SubExprs == 0 && "SubExprs already allocated");
146 Array = isArray;
147 NumPlacementArgs = numPlaceArgs;
Sebastian Redl6047f072012-02-16 12:22:20 +0000148
149 unsigned TotalSize = Array + hasInitializer + NumPlacementArgs;
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000150 SubExprs = new (C) Stmt*[TotalSize];
151}
152
Sebastian Redl31ad7542011-03-13 17:09:40 +0000153bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCall75f94982011-03-07 03:12:35 +0000154 return getOperatorNew()->getType()->
Sebastian Redl31ad7542011-03-13 17:09:40 +0000155 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCall75f94982011-03-07 03:12:35 +0000156}
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000157
Sebastian Redlbd150f42008-11-21 19:14:01 +0000158// CXXDeleteExpr
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000159QualType CXXDeleteExpr::getDestroyedType() const {
160 const Expr *Arg = getArgument();
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000161 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silverstein3b9936f2010-10-20 00:56:01 +0000162 const QualType ArgType = Arg->getType();
Craig Silverstein9e448da2010-11-16 07:16:25 +0000163
164 if (ArgType->isDependentType() && !ArgType->isPointerType())
165 return QualType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000166
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000167 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000168}
169
Douglas Gregorad8a3362009-09-04 17:36:40 +0000170// CXXPseudoDestructorExpr
Douglas Gregor678f90d2010-02-25 01:56:36 +0000171PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
172 : Type(Info)
173{
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000174 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000175}
176
John McCalldb40c7f2010-12-14 08:05:40 +0000177CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregora6ce6082011-02-25 18:19:59 +0000178 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
179 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
180 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
181 PseudoDestructorTypeStorage DestroyedType)
John McCalldb40c7f2010-12-14 08:05:40 +0000182 : Expr(CXXPseudoDestructorExprClass,
183 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
184 FunctionProtoType::ExtProtoInfo())),
185 VK_RValue, OK_Ordinary,
186 /*isTypeDependent=*/(Base->isTypeDependent() ||
187 (DestroyedType.getTypeSourceInfo() &&
188 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000189 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000190 (Base->isInstantiationDependent() ||
191 (QualifierLoc &&
192 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
193 (ScopeType &&
194 ScopeType->getType()->isInstantiationDependentType()) ||
195 (DestroyedType.getTypeSourceInfo() &&
196 DestroyedType.getTypeSourceInfo()->getType()
197 ->isInstantiationDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000198 // ContainsUnexpandedParameterPack
199 (Base->containsUnexpandedParameterPack() ||
Douglas Gregora6ce6082011-02-25 18:19:59 +0000200 (QualifierLoc &&
201 QualifierLoc.getNestedNameSpecifier()
202 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +0000203 (ScopeType &&
204 ScopeType->getType()->containsUnexpandedParameterPack()) ||
205 (DestroyedType.getTypeSourceInfo() &&
206 DestroyedType.getTypeSourceInfo()->getType()
207 ->containsUnexpandedParameterPack()))),
John McCalldb40c7f2010-12-14 08:05:40 +0000208 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregora6ce6082011-02-25 18:19:59 +0000209 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalldb40c7f2010-12-14 08:05:40 +0000210 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
211 DestroyedType(DestroyedType) { }
212
Douglas Gregor678f90d2010-02-25 01:56:36 +0000213QualType CXXPseudoDestructorExpr::getDestroyedType() const {
214 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
215 return TInfo->getType();
216
217 return QualType();
218}
219
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000220SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregor678f90d2010-02-25 01:56:36 +0000221 SourceLocation End = DestroyedType.getLocation();
222 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000223 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000224 return SourceRange(Base->getLocStart(), End);
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000225}
226
John McCalld14a8642009-11-21 08:51:07 +0000227// UnresolvedLookupExpr
John McCalle66edc12009-11-24 19:00:30 +0000228UnresolvedLookupExpr *
Douglas Gregora6e053e2010-12-15 01:34:56 +0000229UnresolvedLookupExpr::Create(ASTContext &C,
John McCall58cc69d2010-01-27 01:50:18 +0000230 CXXRecordDecl *NamingClass,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000231 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000232 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000233 const DeclarationNameInfo &NameInfo,
234 bool ADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000235 const TemplateArgumentListInfo *Args,
236 UnresolvedSetIterator Begin,
237 UnresolvedSetIterator End)
John McCalle66edc12009-11-24 19:00:30 +0000238{
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000239 assert(Args || TemplateKWLoc.isValid());
240 unsigned num_args = Args ? Args->size() : 0;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000241 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000242 ASTTemplateKWAndArgsInfo::sizeFor(num_args));
Abramo Bagnara7945c982012-01-27 09:46:47 +0000243 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
244 TemplateKWLoc, NameInfo,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000245 ADL, /*Overload*/ true, Args,
Richard Smithb6626742012-10-18 17:56:02 +0000246 Begin, End);
John McCalle66edc12009-11-24 19:00:30 +0000247}
248
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000249UnresolvedLookupExpr *
Abramo Bagnara7945c982012-01-27 09:46:47 +0000250UnresolvedLookupExpr::CreateEmpty(ASTContext &C,
251 bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +0000252 unsigned NumTemplateArgs) {
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000253 std::size_t size = sizeof(UnresolvedLookupExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000254 if (HasTemplateKWAndArgsInfo)
255 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000256
Chris Lattner5c0b4052010-10-30 05:14:06 +0000257 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000258 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000259 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000260 return E;
261}
262
Douglas Gregora6e053e2010-12-15 01:34:56 +0000263OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000264 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000265 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000266 const DeclarationNameInfo &NameInfo,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000267 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregorc69978f2010-05-23 19:36:40 +0000268 UnresolvedSetIterator Begin,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000269 UnresolvedSetIterator End,
270 bool KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000271 bool KnownInstantiationDependent,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000272 bool KnownContainsUnexpandedParameterPack)
273 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
274 KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000275 (KnownInstantiationDependent ||
276 NameInfo.isInstantiationDependent() ||
277 (QualifierLoc &&
278 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000279 (KnownContainsUnexpandedParameterPack ||
280 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor0da1d432011-02-28 20:01:57 +0000281 (QualifierLoc &&
282 QualifierLoc.getNestedNameSpecifier()
283 ->containsUnexpandedParameterPack()))),
Benjamin Kramerb73f76b2012-02-26 20:37:14 +0000284 NameInfo(NameInfo), QualifierLoc(QualifierLoc),
285 Results(0), NumResults(End - Begin),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000286 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid())
Douglas Gregorc69978f2010-05-23 19:36:40 +0000287{
Douglas Gregora6e053e2010-12-15 01:34:56 +0000288 NumResults = End - Begin;
289 if (NumResults) {
290 // Determine whether this expression is type-dependent.
291 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
292 if ((*I)->getDeclContext()->isDependentContext() ||
293 isa<UnresolvedUsingValueDecl>(*I)) {
294 ExprBits.TypeDependent = true;
295 ExprBits.ValueDependent = true;
Richard Smith47726b22012-08-13 21:29:18 +0000296 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000297 }
298 }
299
300 Results = static_cast<DeclAccessPair *>(
301 C.Allocate(sizeof(DeclAccessPair) * NumResults,
302 llvm::alignOf<DeclAccessPair>()));
303 memcpy(Results, &*Begin.getIterator(),
304 NumResults * sizeof(DeclAccessPair));
305 }
306
307 // If we have explicit template arguments, check for dependent
308 // template arguments and whether they contain any unexpanded pack
309 // expansions.
310 if (TemplateArgs) {
311 bool Dependent = false;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000312 bool InstantiationDependent = false;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000313 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000314 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
315 Dependent,
316 InstantiationDependent,
317 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000318
319 if (Dependent) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000320 ExprBits.TypeDependent = true;
321 ExprBits.ValueDependent = true;
322 }
323 if (InstantiationDependent)
324 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000325 if (ContainsUnexpandedParameterPack)
326 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000327 } else if (TemplateKWLoc.isValid()) {
328 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000329 }
330
331 if (isTypeDependent())
332 setType(C.DependentTy);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000333}
334
335void OverloadExpr::initializeResults(ASTContext &C,
336 UnresolvedSetIterator Begin,
337 UnresolvedSetIterator End) {
338 assert(Results == 0 && "Results already initialized!");
339 NumResults = End - Begin;
Douglas Gregorc69978f2010-05-23 19:36:40 +0000340 if (NumResults) {
Douglas Gregora6e053e2010-12-15 01:34:56 +0000341 Results = static_cast<DeclAccessPair *>(
342 C.Allocate(sizeof(DeclAccessPair) * NumResults,
343
344 llvm::alignOf<DeclAccessPair>()));
345 memcpy(Results, &*Begin.getIterator(),
346 NumResults * sizeof(DeclAccessPair));
Douglas Gregorc69978f2010-05-23 19:36:40 +0000347 }
348}
349
John McCall8c12dc42010-04-22 18:44:12 +0000350CXXRecordDecl *OverloadExpr::getNamingClass() const {
351 if (isa<UnresolvedLookupExpr>(this))
352 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
353 else
354 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
355}
356
John McCall8cd78132009-11-19 22:55:06 +0000357// DependentScopeDeclRefExpr
Douglas Gregora6e053e2010-12-15 01:34:56 +0000358DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000359 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000360 SourceLocation TemplateKWLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000361 const DeclarationNameInfo &NameInfo,
362 const TemplateArgumentListInfo *Args)
363 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
364 true, true,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000365 (NameInfo.isInstantiationDependent() ||
366 (QualifierLoc &&
367 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000368 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000369 (QualifierLoc &&
370 QualifierLoc.getNestedNameSpecifier()
371 ->containsUnexpandedParameterPack()))),
372 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000373 HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid())
Douglas Gregora6e053e2010-12-15 01:34:56 +0000374{
375 if (Args) {
376 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000377 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000378 bool ContainsUnexpandedParameterPack
379 = ExprBits.ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000380 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args,
381 Dependent,
382 InstantiationDependent,
383 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000384 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000385 } else if (TemplateKWLoc.isValid()) {
386 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000387 }
388}
389
John McCalle66edc12009-11-24 19:00:30 +0000390DependentScopeDeclRefExpr *
391DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000392 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000393 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000394 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +0000395 const TemplateArgumentListInfo *Args) {
396 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCalle66edc12009-11-24 19:00:30 +0000397 if (Args)
Abramo Bagnara7945c982012-01-27 09:46:47 +0000398 size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size());
399 else if (TemplateKWLoc.isValid())
400 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000401 void *Mem = C.Allocate(size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000402 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
403 TemplateKWLoc, NameInfo, Args);
John McCalle66edc12009-11-24 19:00:30 +0000404}
405
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000406DependentScopeDeclRefExpr *
407DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000408 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000409 unsigned NumTemplateArgs) {
410 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000411 if (HasTemplateKWAndArgsInfo)
412 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000413 void *Mem = C.Allocate(size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000414 DependentScopeDeclRefExpr *E
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000415 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000416 SourceLocation(),
Douglas Gregor87866ce2011-02-04 12:01:24 +0000417 DeclarationNameInfo(), 0);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000418 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregor87866ce2011-02-04 12:01:24 +0000419 return E;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000420}
421
Chandler Carruth01718152010-10-25 08:47:36 +0000422SourceRange CXXConstructExpr::getSourceRange() const {
John McCall701417a2011-02-21 06:23:05 +0000423 if (isa<CXXTemporaryObjectExpr>(this))
424 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
425
Douglas Gregor15417cf2010-11-03 00:35:38 +0000426 if (ParenRange.isValid())
427 return SourceRange(Loc, ParenRange.getEnd());
428
429 SourceLocation End = Loc;
430 for (unsigned I = getNumArgs(); I > 0; --I) {
431 const Expr *Arg = getArg(I-1);
432 if (!Arg->isDefaultArgument()) {
433 SourceLocation NewEnd = Arg->getLocEnd();
434 if (NewEnd.isValid()) {
435 End = NewEnd;
436 break;
437 }
438 }
439 }
440
441 return SourceRange(Loc, End);
Ted Kremenek49ace5c2009-12-23 04:00:48 +0000442}
443
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000444SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
Douglas Gregor993603d2008-11-14 16:09:21 +0000445 OverloadedOperatorKind Kind = getOperator();
446 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
447 if (getNumArgs() == 1)
448 // Prefix operator
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000449 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000450 else
451 // Postfix operator
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000452 return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
Chandler Carruthf20ec9232011-04-02 09:47:38 +0000453 } else if (Kind == OO_Arrow) {
454 return getArg(0)->getSourceRange();
Douglas Gregor993603d2008-11-14 16:09:21 +0000455 } else if (Kind == OO_Call) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000456 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000457 } else if (Kind == OO_Subscript) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000458 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000459 } else if (getNumArgs() == 1) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000460 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000461 } else if (getNumArgs() == 2) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000462 return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000463 } else {
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000464 return getOperatorLoc();
Douglas Gregor993603d2008-11-14 16:09:21 +0000465 }
466}
467
Ted Kremenek98a24e32011-03-30 17:41:19 +0000468Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
Jordan Rose16fe35e2012-08-03 23:08:39 +0000469 const Expr *Callee = getCallee()->IgnoreParens();
470 if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee))
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000471 return MemExpr->getBase();
Jordan Rose16fe35e2012-08-03 23:08:39 +0000472 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee))
473 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
474 return BO->getLHS();
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000475
476 // FIXME: Will eventually need to cope with member pointers.
477 return 0;
478}
479
Ted Kremenek98a24e32011-03-30 17:41:19 +0000480CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
481 if (const MemberExpr *MemExpr =
482 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
483 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
484
485 // FIXME: Will eventually need to cope with member pointers.
486 return 0;
487}
488
489
David Blaikiec0f58662012-05-03 16:25:49 +0000490CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Chandler Carruth00426b42010-10-27 06:55:41 +0000491 Expr* ThisArg = getImplicitObjectArgument();
492 if (!ThisArg)
493 return 0;
494
495 if (ThisArg->getType()->isAnyPointerType())
496 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
497
498 return ThisArg->getType()->getAsCXXRecordDecl();
499}
500
Douglas Gregoref986e82009-11-12 15:31:47 +0000501
Douglas Gregore200adc2008-10-27 19:41:14 +0000502//===----------------------------------------------------------------------===//
503// Named casts
504//===----------------------------------------------------------------------===//
505
506/// getCastName - Get the name of the C++ cast being used, e.g.,
507/// "static_cast", "dynamic_cast", "reinterpret_cast", or
508/// "const_cast". The returned pointer must not be freed.
509const char *CXXNamedCastExpr::getCastName() const {
510 switch (getStmtClass()) {
511 case CXXStaticCastExprClass: return "static_cast";
512 case CXXDynamicCastExprClass: return "dynamic_cast";
513 case CXXReinterpretCastExprClass: return "reinterpret_cast";
514 case CXXConstCastExprClass: return "const_cast";
515 default: return "<invalid cast>";
516 }
517}
Douglas Gregordd04d332009-01-16 18:33:17 +0000518
John McCallcf142162010-08-07 06:22:56 +0000519CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000520 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000521 CastKind K, Expr *Op,
522 const CXXCastPath *BasePath,
523 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000524 SourceLocation L,
525 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000526 unsigned PathSize = (BasePath ? BasePath->size() : 0);
527 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
528 + PathSize * sizeof(CXXBaseSpecifier*));
529 CXXStaticCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000530 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
531 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000532 if (PathSize) E->setCastPath(*BasePath);
533 return E;
534}
535
536CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
537 unsigned PathSize) {
538 void *Buffer =
539 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
540 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
541}
542
543CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000544 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000545 CastKind K, Expr *Op,
546 const CXXCastPath *BasePath,
547 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000548 SourceLocation L,
549 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000550 unsigned PathSize = (BasePath ? BasePath->size() : 0);
551 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
552 + PathSize * sizeof(CXXBaseSpecifier*));
553 CXXDynamicCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000554 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
555 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000556 if (PathSize) E->setCastPath(*BasePath);
557 return E;
558}
559
560CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
561 unsigned PathSize) {
562 void *Buffer =
563 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
564 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
565}
566
Anders Carlsson267c0c92011-04-11 01:43:55 +0000567/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
568/// to always be null. For example:
569///
570/// struct A { };
571/// struct B final : A { };
572/// struct C { };
573///
574/// C *f(B* b) { return dynamic_cast<C*>(b); }
575bool CXXDynamicCastExpr::isAlwaysNull() const
576{
577 QualType SrcType = getSubExpr()->getType();
578 QualType DestType = getType();
579
580 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
581 SrcType = SrcPTy->getPointeeType();
582 DestType = DestType->castAs<PointerType>()->getPointeeType();
583 }
584
Alexis Hunt78e2b912012-06-19 23:44:55 +0000585 if (DestType->isVoidType())
586 return false;
587
Anders Carlsson267c0c92011-04-11 01:43:55 +0000588 const CXXRecordDecl *SrcRD =
589 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
590
Jakob Stoklund Olesene1c0ae62012-06-19 21:48:43 +0000591 if (!SrcRD->hasAttr<FinalAttr>())
592 return false;
593
Anders Carlsson267c0c92011-04-11 01:43:55 +0000594 const CXXRecordDecl *DestRD =
595 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
596
597 return !DestRD->isDerivedFrom(SrcRD);
598}
599
John McCallcf142162010-08-07 06:22:56 +0000600CXXReinterpretCastExpr *
John McCall7decc9e2010-11-18 06:31:45 +0000601CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
602 CastKind K, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000603 const CXXCastPath *BasePath,
Douglas Gregor4478f852011-01-12 22:41:29 +0000604 TypeSourceInfo *WrittenTy, SourceLocation L,
605 SourceLocation RParenLoc) {
John McCallcf142162010-08-07 06:22:56 +0000606 unsigned PathSize = (BasePath ? BasePath->size() : 0);
607 void *Buffer =
608 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
609 CXXReinterpretCastExpr *E =
Douglas Gregor4478f852011-01-12 22:41:29 +0000610 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
611 RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000612 if (PathSize) E->setCastPath(*BasePath);
613 return E;
614}
615
616CXXReinterpretCastExpr *
617CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
618 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
619 + PathSize * sizeof(CXXBaseSpecifier*));
620 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
621}
622
John McCall7decc9e2010-11-18 06:31:45 +0000623CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
624 ExprValueKind VK, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000625 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000626 SourceLocation L,
627 SourceLocation RParenLoc) {
628 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallcf142162010-08-07 06:22:56 +0000629}
630
631CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
632 return new (C) CXXConstCastExpr(EmptyShell());
633}
634
635CXXFunctionalCastExpr *
John McCall7decc9e2010-11-18 06:31:45 +0000636CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000637 TypeSourceInfo *Written, SourceLocation L,
638 CastKind K, Expr *Op, const CXXCastPath *BasePath,
639 SourceLocation R) {
640 unsigned PathSize = (BasePath ? BasePath->size() : 0);
641 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
642 + PathSize * sizeof(CXXBaseSpecifier*));
643 CXXFunctionalCastExpr *E =
John McCall7decc9e2010-11-18 06:31:45 +0000644 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallcf142162010-08-07 06:22:56 +0000645 if (PathSize) E->setCastPath(*BasePath);
646 return E;
647}
648
649CXXFunctionalCastExpr *
650CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
651 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
652 + PathSize * sizeof(CXXBaseSpecifier*));
653 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
654}
655
Richard Smithc67fdd42012-03-07 08:35:16 +0000656UserDefinedLiteral::LiteralOperatorKind
657UserDefinedLiteral::getLiteralOperatorKind() const {
658 if (getNumArgs() == 0)
659 return LOK_Template;
660 if (getNumArgs() == 2)
661 return LOK_String;
662
663 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
664 QualType ParamTy =
665 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
666 if (ParamTy->isPointerType())
667 return LOK_Raw;
668 if (ParamTy->isAnyCharacterType())
669 return LOK_Character;
670 if (ParamTy->isIntegerType())
671 return LOK_Integer;
672 if (ParamTy->isFloatingType())
673 return LOK_Floating;
674
675 llvm_unreachable("unknown kind of literal operator");
676}
677
678Expr *UserDefinedLiteral::getCookedLiteral() {
679#ifndef NDEBUG
680 LiteralOperatorKind LOK = getLiteralOperatorKind();
681 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
682#endif
683 return getArg(0);
684}
685
686const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
687 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
688}
John McCallcf142162010-08-07 06:22:56 +0000689
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000690CXXDefaultArgExpr *
Douglas Gregor033f6752009-12-23 23:03:06 +0000691CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
692 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000693 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor033f6752009-12-23 23:03:06 +0000694 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
695 SubExpr);
Douglas Gregor25ab25f2009-12-23 18:19:08 +0000696}
697
Mike Stump11289f42009-09-09 15:08:12 +0000698CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonffda6062009-05-30 20:34:37 +0000699 const CXXDestructorDecl *Destructor) {
Anders Carlsson73b836b2009-05-30 22:38:53 +0000700 return new (C) CXXTemporary(Destructor);
701}
702
Mike Stump11289f42009-09-09 15:08:12 +0000703CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlsson993a4b32009-05-30 20:03:25 +0000704 CXXTemporary *Temp,
705 Expr* SubExpr) {
Peter Collingbournefbef4c82011-11-27 22:09:28 +0000706 assert((SubExpr->getType()->isRecordType() ||
707 SubExpr->getType()->isArrayType()) &&
708 "Expression bound to a temporary must have record or array type!");
Anders Carlsson993a4b32009-05-30 20:03:25 +0000709
Douglas Gregora6e053e2010-12-15 01:34:56 +0000710 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlsson993a4b32009-05-30 20:03:25 +0000711}
712
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000713CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson56c5bd82009-04-24 05:23:13 +0000714 CXXConstructorDecl *Cons,
Douglas Gregor2b88c112010-09-08 00:15:04 +0000715 TypeSourceInfo *Type,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000716 ArrayRef<Expr*> Args,
Chandler Carruth01718152010-10-25 08:47:36 +0000717 SourceRange parenRange,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000718 bool HadMultipleCandidates,
Douglas Gregor199db362010-04-27 20:36:09 +0000719 bool ZeroInitialization)
Douglas Gregor2b88c112010-09-08 00:15:04 +0000720 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
721 Type->getType().getNonReferenceType(),
722 Type->getTypeLoc().getBeginLoc(),
Benjamin Kramerc215e762012-08-24 11:54:20 +0000723 Cons, false, Args,
Sebastian Redla9351792012-02-11 23:51:47 +0000724 HadMultipleCandidates, /*FIXME*/false, ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000725 CXXConstructExpr::CK_Complete, parenRange),
726 Type(Type) {
Douglas Gregor2b88c112010-09-08 00:15:04 +0000727}
728
729SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth01718152010-10-25 08:47:36 +0000730 return SourceRange(Type->getTypeLoc().getBeginLoc(),
731 getParenRange().getEnd());
Douglas Gregordd04d332009-01-16 18:33:17 +0000732}
Anders Carlsson6f287832009-04-21 02:22:11 +0000733
Mike Stump11289f42009-09-09 15:08:12 +0000734CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000735 SourceLocation Loc,
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000736 CXXConstructorDecl *D, bool Elidable,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000737 ArrayRef<Expr*> Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000738 bool HadMultipleCandidates,
Sebastian Redla9351792012-02-11 23:51:47 +0000739 bool ListInitialization,
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000740 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000741 ConstructionKind ConstructKind,
742 SourceRange ParenRange) {
Douglas Gregor85dabae2009-12-16 01:38:02 +0000743 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000744 Elidable, Args,
Sebastian Redla9351792012-02-11 23:51:47 +0000745 HadMultipleCandidates, ListInitialization,
746 ZeroInitialization, ConstructKind,
747 ParenRange);
Anders Carlsson0781ce72009-04-23 02:32:43 +0000748}
749
Mike Stump11289f42009-09-09 15:08:12 +0000750CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000751 SourceLocation Loc,
Anders Carlsson4b2434d2009-05-30 20:56:46 +0000752 CXXConstructorDecl *D, bool elidable,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000753 ArrayRef<Expr*> args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000754 bool HadMultipleCandidates,
Sebastian Redla9351792012-02-11 23:51:47 +0000755 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000756 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000757 ConstructionKind ConstructKind,
758 SourceRange ParenRange)
Douglas Gregora6e053e2010-12-15 01:34:56 +0000759 : Expr(SC, T, VK_RValue, OK_Ordinary,
760 T->isDependentType(), T->isDependentType(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000761 T->isInstantiationDependentType(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000762 T->containsUnexpandedParameterPack()),
Benjamin Kramerc215e762012-08-24 11:54:20 +0000763 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(args.size()),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000764 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
Sebastian Redla9351792012-02-11 23:51:47 +0000765 ListInitialization(ListInitialization),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000766 ZeroInitialization(ZeroInitialization),
Douglas Gregor488c2312011-09-26 14:47:03 +0000767 ConstructKind(ConstructKind), Args(0)
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000768{
769 if (NumArgs) {
Benjamin Kramerc215e762012-08-24 11:54:20 +0000770 Args = new (C) Stmt*[args.size()];
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000771
Benjamin Kramerc215e762012-08-24 11:54:20 +0000772 for (unsigned i = 0; i != args.size(); ++i) {
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000773 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregora6e053e2010-12-15 01:34:56 +0000774
775 if (args[i]->isValueDependent())
776 ExprBits.ValueDependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000777 if (args[i]->isInstantiationDependent())
778 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000779 if (args[i]->containsUnexpandedParameterPack())
780 ExprBits.ContainsUnexpandedParameterPack = true;
781
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000782 Args[i] = args[i];
Anders Carlsson0781ce72009-04-23 02:32:43 +0000783 }
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000784 }
Anders Carlsson0781ce72009-04-23 02:32:43 +0000785}
786
Douglas Gregore31e6062012-02-07 10:09:13 +0000787LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
788 LambdaCaptureKind Kind, VarDecl *Var,
789 SourceLocation EllipsisLoc)
790 : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
791{
792 unsigned Bits = 0;
793 if (Implicit)
794 Bits |= Capture_Implicit;
795
796 switch (Kind) {
797 case LCK_This:
798 assert(Var == 0 && "'this' capture cannot have a variable!");
799 break;
800
801 case LCK_ByCopy:
802 Bits |= Capture_ByCopy;
803 // Fall through
804 case LCK_ByRef:
805 assert(Var && "capture must have a variable!");
806 break;
807 }
808 VarAndBits.setInt(Bits);
809}
810
811LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const {
812 if (capturesThis())
813 return LCK_This;
814
815 return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef;
816}
817
818LambdaExpr::LambdaExpr(QualType T,
819 SourceRange IntroducerRange,
820 LambdaCaptureDefault CaptureDefault,
821 ArrayRef<Capture> Captures,
822 bool ExplicitParams,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000823 bool ExplicitResultType,
Douglas Gregore31e6062012-02-07 10:09:13 +0000824 ArrayRef<Expr *> CaptureInits,
Douglas Gregore5561632012-02-13 17:20:40 +0000825 ArrayRef<VarDecl *> ArrayIndexVars,
826 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000827 SourceLocation ClosingBrace,
828 bool ContainsUnexpandedParameterPack)
Douglas Gregore31e6062012-02-07 10:09:13 +0000829 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
830 T->isDependentType(), T->isDependentType(), T->isDependentType(),
Richard Smith2589b9802012-07-25 03:56:55 +0000831 ContainsUnexpandedParameterPack),
Douglas Gregore31e6062012-02-07 10:09:13 +0000832 IntroducerRange(IntroducerRange),
Douglas Gregore5561632012-02-13 17:20:40 +0000833 NumCaptures(Captures.size()),
Douglas Gregore31e6062012-02-07 10:09:13 +0000834 CaptureDefault(CaptureDefault),
835 ExplicitParams(ExplicitParams),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000836 ExplicitResultType(ExplicitResultType),
Douglas Gregore31e6062012-02-07 10:09:13 +0000837 ClosingBrace(ClosingBrace)
838{
839 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorc8a73492012-02-13 15:44:47 +0000840 CXXRecordDecl *Class = getLambdaClass();
841 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Douglas Gregorc8a73492012-02-13 15:44:47 +0000842
843 // FIXME: Propagate "has unexpanded parameter pack" bit.
Douglas Gregore5561632012-02-13 17:20:40 +0000844
845 // Copy captures.
846 ASTContext &Context = Class->getASTContext();
847 Data.NumCaptures = NumCaptures;
848 Data.NumExplicitCaptures = 0;
849 Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures);
850 Capture *ToCapture = Data.Captures;
851 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
852 if (Captures[I].isExplicit())
853 ++Data.NumExplicitCaptures;
854
855 *ToCapture++ = Captures[I];
856 }
857
858 // Copy initialization expressions for the non-static data members.
859 Stmt **Stored = getStoredStmts();
860 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
861 *Stored++ = CaptureInits[I];
862
863 // Copy the body of the lambda.
864 *Stored++ = getCallOperator()->getBody();
865
866 // Copy the array index variables, if any.
867 HasArrayIndexVars = !ArrayIndexVars.empty();
868 if (HasArrayIndexVars) {
869 assert(ArrayIndexStarts.size() == NumCaptures);
870 memcpy(getArrayIndexVars(), ArrayIndexVars.data(),
871 sizeof(VarDecl *) * ArrayIndexVars.size());
872 memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(),
873 sizeof(unsigned) * Captures.size());
874 getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size();
Douglas Gregor6f88e5e2012-02-21 04:17:39 +0000875 }
Douglas Gregore31e6062012-02-07 10:09:13 +0000876}
877
878LambdaExpr *LambdaExpr::Create(ASTContext &Context,
879 CXXRecordDecl *Class,
880 SourceRange IntroducerRange,
881 LambdaCaptureDefault CaptureDefault,
882 ArrayRef<Capture> Captures,
883 bool ExplicitParams,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000884 bool ExplicitResultType,
Douglas Gregore31e6062012-02-07 10:09:13 +0000885 ArrayRef<Expr *> CaptureInits,
Douglas Gregore5561632012-02-13 17:20:40 +0000886 ArrayRef<VarDecl *> ArrayIndexVars,
887 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000888 SourceLocation ClosingBrace,
889 bool ContainsUnexpandedParameterPack) {
Douglas Gregore31e6062012-02-07 10:09:13 +0000890 // Determine the type of the expression (i.e., the type of the
891 // function object we're creating).
892 QualType T = Context.getTypeDeclType(Class);
Douglas Gregore31e6062012-02-07 10:09:13 +0000893
Douglas Gregore5561632012-02-13 17:20:40 +0000894 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1);
Richard Smithc7520bf2012-08-21 05:42:49 +0000895 if (!ArrayIndexVars.empty()) {
896 Size += sizeof(unsigned) * (Captures.size() + 1);
897 // Realign for following VarDecl array.
Richard Smitha75e1cf2012-08-21 18:18:06 +0000898 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>());
Richard Smithc7520bf2012-08-21 05:42:49 +0000899 Size += sizeof(VarDecl *) * ArrayIndexVars.size();
900 }
Douglas Gregore5561632012-02-13 17:20:40 +0000901 void *Mem = Context.Allocate(Size);
902 return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000903 Captures, ExplicitParams, ExplicitResultType,
904 CaptureInits, ArrayIndexVars, ArrayIndexStarts,
Richard Smith2589b9802012-07-25 03:56:55 +0000905 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregore31e6062012-02-07 10:09:13 +0000906}
907
Douglas Gregor99ae8062012-02-14 17:54:36 +0000908LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures,
909 unsigned NumArrayIndexVars) {
910 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1);
911 if (NumArrayIndexVars)
912 Size += sizeof(VarDecl) * NumArrayIndexVars
913 + sizeof(unsigned) * (NumCaptures + 1);
914 void *Mem = C.Allocate(Size);
915 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0);
916}
917
Douglas Gregorc8a73492012-02-13 15:44:47 +0000918LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregore5561632012-02-13 17:20:40 +0000919 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000920}
921
922LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregore5561632012-02-13 17:20:40 +0000923 return capture_begin() + NumCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000924}
925
926LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
927 return capture_begin();
928}
929
930LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
931 struct CXXRecordDecl::LambdaDefinitionData &Data
932 = getLambdaClass()->getLambdaData();
Douglas Gregore5561632012-02-13 17:20:40 +0000933 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000934}
935
936LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
937 return explicit_capture_end();
938}
939
940LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
941 return capture_end();
942}
943
Douglas Gregor54fcea62012-02-13 16:35:30 +0000944ArrayRef<VarDecl *>
945LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const {
Douglas Gregore5561632012-02-13 17:20:40 +0000946 assert(HasArrayIndexVars && "No array index-var data?");
Douglas Gregor54fcea62012-02-13 16:35:30 +0000947
948 unsigned Index = Iter - capture_init_begin();
Matt Beaumont-Gayf2ee0672012-02-13 19:29:45 +0000949 assert(Index < getLambdaClass()->getLambdaData().NumCaptures &&
950 "Capture index out-of-range");
Douglas Gregore5561632012-02-13 17:20:40 +0000951 VarDecl **IndexVars = getArrayIndexVars();
952 unsigned *IndexStarts = getArrayIndexStarts();
Douglas Gregor54fcea62012-02-13 16:35:30 +0000953 return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index],
954 IndexVars + IndexStarts[Index + 1]);
955}
956
Douglas Gregore31e6062012-02-07 10:09:13 +0000957CXXRecordDecl *LambdaExpr::getLambdaClass() const {
958 return getType()->getAsCXXRecordDecl();
959}
960
961CXXMethodDecl *LambdaExpr::getCallOperator() const {
962 CXXRecordDecl *Record = getLambdaClass();
963 DeclarationName Name
964 = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
965 DeclContext::lookup_result Calls = Record->lookup(Name);
966 assert(Calls.first != Calls.second && "Missing lambda call operator!");
967 CXXMethodDecl *Result = cast<CXXMethodDecl>(*Calls.first++);
968 assert(Calls.first == Calls.second && "More than lambda one call operator?");
969 return Result;
970}
971
Douglas Gregor99ae8062012-02-14 17:54:36 +0000972CompoundStmt *LambdaExpr::getBody() const {
973 if (!getStoredStmts()[NumCaptures])
974 getStoredStmts()[NumCaptures] = getCallOperator()->getBody();
975
976 return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
977}
978
Douglas Gregore31e6062012-02-07 10:09:13 +0000979bool LambdaExpr::isMutable() const {
David Blaikief5697e52012-08-10 00:55:35 +0000980 return !getCallOperator()->isConst();
Douglas Gregore31e6062012-02-07 10:09:13 +0000981}
982
John McCall28fc7092011-11-10 05:35:25 +0000983ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
984 ArrayRef<CleanupObject> objects)
John McCall5d413782010-12-06 08:20:24 +0000985 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCall7decc9e2010-11-18 06:31:45 +0000986 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000987 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000988 subexpr->isInstantiationDependent(),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000989 subexpr->containsUnexpandedParameterPack()),
John McCall28fc7092011-11-10 05:35:25 +0000990 SubExpr(subexpr) {
991 ExprWithCleanupsBits.NumObjects = objects.size();
992 for (unsigned i = 0, e = objects.size(); i != e; ++i)
993 getObjectsBuffer()[i] = objects[i];
Anders Carlssondefc6442009-04-24 22:47:04 +0000994}
995
John McCall28fc7092011-11-10 05:35:25 +0000996ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
997 ArrayRef<CleanupObject> objects) {
998 size_t size = sizeof(ExprWithCleanups)
999 + objects.size() * sizeof(CleanupObject);
1000 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1001 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnercba86142010-05-10 00:25:06 +00001002}
1003
John McCall28fc7092011-11-10 05:35:25 +00001004ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1005 : Expr(ExprWithCleanupsClass, empty) {
1006 ExprWithCleanupsBits.NumObjects = numObjects;
1007}
Chris Lattnercba86142010-05-10 00:25:06 +00001008
John McCall28fc7092011-11-10 05:35:25 +00001009ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
1010 unsigned numObjects) {
1011 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
1012 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1013 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson73b836b2009-05-30 22:38:53 +00001014}
1015
Douglas Gregor2b88c112010-09-08 00:15:04 +00001016CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +00001017 SourceLocation LParenLoc,
Benjamin Kramerc215e762012-08-24 11:54:20 +00001018 ArrayRef<Expr*> Args,
Douglas Gregorce934142009-05-20 18:46:25 +00001019 SourceLocation RParenLoc)
Douglas Gregor2b88c112010-09-08 00:15:04 +00001020 : Expr(CXXUnresolvedConstructExprClass,
1021 Type->getType().getNonReferenceType(),
Douglas Gregor6336f292011-07-08 15:50:43 +00001022 (Type->getType()->isLValueReferenceType() ? VK_LValue
1023 :Type->getType()->isRValueReferenceType()? VK_XValue
1024 :VK_RValue),
1025 OK_Ordinary,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001026 Type->getType()->isDependentType(), true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001027 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001028 Type(Type),
Douglas Gregorce934142009-05-20 18:46:25 +00001029 LParenLoc(LParenLoc),
1030 RParenLoc(RParenLoc),
Benjamin Kramerc215e762012-08-24 11:54:20 +00001031 NumArgs(Args.size()) {
Douglas Gregorce934142009-05-20 18:46:25 +00001032 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Benjamin Kramerc215e762012-08-24 11:54:20 +00001033 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001034 if (Args[I]->containsUnexpandedParameterPack())
1035 ExprBits.ContainsUnexpandedParameterPack = true;
1036
1037 StoredArgs[I] = Args[I];
1038 }
Douglas Gregorce934142009-05-20 18:46:25 +00001039}
1040
1041CXXUnresolvedConstructExpr *
Mike Stump11289f42009-09-09 15:08:12 +00001042CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregor2b88c112010-09-08 00:15:04 +00001043 TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +00001044 SourceLocation LParenLoc,
Benjamin Kramerc215e762012-08-24 11:54:20 +00001045 ArrayRef<Expr*> Args,
Douglas Gregorce934142009-05-20 18:46:25 +00001046 SourceLocation RParenLoc) {
1047 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
Benjamin Kramerc215e762012-08-24 11:54:20 +00001048 sizeof(Expr *) * Args.size());
1049 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
Douglas Gregorce934142009-05-20 18:46:25 +00001050}
1051
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001052CXXUnresolvedConstructExpr *
1053CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
1054 Stmt::EmptyShell Empty;
1055 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
1056 sizeof(Expr *) * NumArgs);
1057 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1058}
1059
Douglas Gregor2b88c112010-09-08 00:15:04 +00001060SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
1061 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
1062}
1063
John McCall8cd78132009-11-19 22:55:06 +00001064CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +00001065 Expr *Base, QualType BaseType,
1066 bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +00001067 SourceLocation OperatorLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001068 NestedNameSpecifierLoc QualifierLoc,
1069 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00001070 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001071 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +00001072 const TemplateArgumentListInfo *TemplateArgs)
John McCall7decc9e2010-11-18 06:31:45 +00001073 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001074 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001075 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregore16af532011-02-28 18:50:33 +00001076 (QualifierLoc &&
1077 QualifierLoc.getNestedNameSpecifier()
1078 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +00001079 MemberNameInfo.containsUnexpandedParameterPack())),
John McCall2d74de92009-12-01 22:10:20 +00001080 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001081 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregore16af532011-02-28 18:50:33 +00001082 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor308047d2009-09-09 00:23:06 +00001083 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001084 MemberNameInfo(MemberNameInfo) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001085 if (TemplateArgs) {
1086 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +00001087 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +00001088 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnara7945c982012-01-27 09:46:47 +00001089 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
1090 Dependent,
1091 InstantiationDependent,
1092 ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001093 if (ContainsUnexpandedParameterPack)
1094 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +00001095 } else if (TemplateKWLoc.isValid()) {
1096 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001097 }
Douglas Gregor308047d2009-09-09 00:23:06 +00001098}
1099
Douglas Gregora6e053e2010-12-15 01:34:56 +00001100CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
1101 Expr *Base, QualType BaseType,
1102 bool IsArrow,
1103 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001104 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001105 NamedDecl *FirstQualifierFoundInScope,
1106 DeclarationNameInfo MemberNameInfo)
1107 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001108 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001109 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregore16af532011-02-28 18:50:33 +00001110 (QualifierLoc &&
1111 QualifierLoc.getNestedNameSpecifier()->
1112 containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +00001113 MemberNameInfo.containsUnexpandedParameterPack())),
1114 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001115 HasTemplateKWAndArgsInfo(false),
1116 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregora6e053e2010-12-15 01:34:56 +00001117 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1118 MemberNameInfo(MemberNameInfo) { }
1119
John McCall8cd78132009-11-19 22:55:06 +00001120CXXDependentScopeMemberExpr *
1121CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +00001122 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +00001123 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001124 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001125 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00001126 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001127 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +00001128 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00001129 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCall2d74de92009-12-01 22:10:20 +00001130 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
1131 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001132 QualifierLoc,
John McCall2d74de92009-12-01 22:10:20 +00001133 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001134 MemberNameInfo);
Mike Stump11289f42009-09-09 15:08:12 +00001135
Abramo Bagnara7945c982012-01-27 09:46:47 +00001136 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1137 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
1138 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCall6b51f282009-11-23 01:53:49 +00001139
Chris Lattner5c0b4052010-10-30 05:14:06 +00001140 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCall2d74de92009-12-01 22:10:20 +00001141 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1142 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001143 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001144 TemplateKWLoc,
John McCall2d74de92009-12-01 22:10:20 +00001145 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001146 MemberNameInfo, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001147}
1148
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001149CXXDependentScopeMemberExpr *
1150CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001151 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001152 unsigned NumTemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00001153 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001154 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001155 0, SourceLocation(),
Douglas Gregore16af532011-02-28 18:50:33 +00001156 NestedNameSpecifierLoc(), 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001157 DeclarationNameInfo());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001158
1159 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnara7945c982012-01-27 09:46:47 +00001160 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner5c0b4052010-10-30 05:14:06 +00001161 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001162 CXXDependentScopeMemberExpr *E
1163 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00001164 0, SourceLocation(),
1165 NestedNameSpecifierLoc(),
1166 SourceLocation(), 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001167 DeclarationNameInfo(), 0);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001168 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001169 return E;
1170}
1171
Douglas Gregor0da1d432011-02-28 20:01:57 +00001172bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
1173 if (Base == 0)
1174 return true;
1175
Douglas Gregor25b7e052011-03-02 21:06:53 +00001176 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001177}
1178
John McCall0009fcc2011-04-26 20:42:42 +00001179static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1180 UnresolvedSetIterator end) {
1181 do {
1182 NamedDecl *decl = *begin;
1183 if (isa<UnresolvedUsingValueDecl>(decl))
1184 return false;
1185 if (isa<UsingShadowDecl>(decl))
1186 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
1187
1188 // Unresolved member expressions should only contain methods and
1189 // method templates.
1190 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
1191
1192 if (isa<FunctionTemplateDecl>(decl))
1193 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
1194 if (cast<CXXMethodDecl>(decl)->isStatic())
1195 return false;
1196 } while (++begin != end);
1197
1198 return true;
1199}
1200
Douglas Gregora6e053e2010-12-15 01:34:56 +00001201UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +00001202 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +00001203 Expr *Base, QualType BaseType,
1204 bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001205 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001206 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001207 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001208 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +00001209 const TemplateArgumentListInfo *TemplateArgs,
1210 UnresolvedSetIterator Begin,
1211 UnresolvedSetIterator End)
Abramo Bagnara7945c982012-01-27 09:46:47 +00001212 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1213 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001214 // Dependent
1215 ((Base && Base->isTypeDependent()) ||
1216 BaseType->isDependentType()),
Douglas Gregor678d76c2011-07-01 01:22:09 +00001217 ((Base && Base->isInstantiationDependent()) ||
1218 BaseType->isInstantiationDependentType()),
Douglas Gregora6e053e2010-12-15 01:34:56 +00001219 // Contains unexpanded parameter pack
1220 ((Base && Base->containsUnexpandedParameterPack()) ||
1221 BaseType->containsUnexpandedParameterPack())),
John McCall1acbbb52010-02-02 06:20:04 +00001222 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1223 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall0009fcc2011-04-26 20:42:42 +00001224
1225 // Check whether all of the members are non-static member functions,
1226 // and if so, mark give this bound-member type instead of overload type.
1227 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1228 setType(C.BoundMemberTy);
John McCall10eae182009-11-30 22:42:35 +00001229}
1230
Douglas Gregor0da1d432011-02-28 20:01:57 +00001231bool UnresolvedMemberExpr::isImplicitAccess() const {
1232 if (Base == 0)
1233 return true;
1234
Douglas Gregor25b7e052011-03-02 21:06:53 +00001235 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001236}
1237
John McCall10eae182009-11-30 22:42:35 +00001238UnresolvedMemberExpr *
Douglas Gregora6e053e2010-12-15 01:34:56 +00001239UnresolvedMemberExpr::Create(ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +00001240 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +00001241 Expr *Base, QualType BaseType, bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001242 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001243 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001244 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001245 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +00001246 const TemplateArgumentListInfo *TemplateArgs,
1247 UnresolvedSetIterator Begin,
1248 UnresolvedSetIterator End) {
John McCall10eae182009-11-30 22:42:35 +00001249 std::size_t size = sizeof(UnresolvedMemberExpr);
1250 if (TemplateArgs)
Abramo Bagnara7945c982012-01-27 09:46:47 +00001251 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
1252 else if (TemplateKWLoc.isValid())
1253 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall10eae182009-11-30 22:42:35 +00001254
Chris Lattner5c0b4052010-10-30 05:14:06 +00001255 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregorc69978f2010-05-23 19:36:40 +00001256 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregora6e053e2010-12-15 01:34:56 +00001257 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001258 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001259 MemberNameInfo, TemplateArgs, Begin, End);
John McCall10eae182009-11-30 22:42:35 +00001260}
1261
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001262UnresolvedMemberExpr *
Abramo Bagnara7945c982012-01-27 09:46:47 +00001263UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +00001264 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001265 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnara7945c982012-01-27 09:46:47 +00001266 if (HasTemplateKWAndArgsInfo)
1267 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001268
Chris Lattner5c0b4052010-10-30 05:14:06 +00001269 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001270 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +00001271 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001272 return E;
1273}
1274
John McCall58cc69d2010-01-27 01:50:18 +00001275CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1276 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1277
1278 // If there was a nested name specifier, it names the naming class.
1279 // It can't be dependent: after all, we were actually able to do the
1280 // lookup.
Douglas Gregor9262f472010-04-27 18:19:34 +00001281 CXXRecordDecl *Record = 0;
John McCall1acbbb52010-02-02 06:20:04 +00001282 if (getQualifier()) {
John McCall424cec92011-01-19 06:33:43 +00001283 const Type *T = getQualifier()->getAsType();
John McCall58cc69d2010-01-27 01:50:18 +00001284 assert(T && "qualifier in member expression does not name type");
Douglas Gregor9262f472010-04-27 18:19:34 +00001285 Record = T->getAsCXXRecordDecl();
1286 assert(Record && "qualifier in member expression does not name record");
1287 }
John McCall58cc69d2010-01-27 01:50:18 +00001288 // Otherwise the naming class must have been the base class.
Douglas Gregor9262f472010-04-27 18:19:34 +00001289 else {
John McCall58cc69d2010-01-27 01:50:18 +00001290 QualType BaseType = getBaseType().getNonReferenceType();
1291 if (isArrow()) {
1292 const PointerType *PT = BaseType->getAs<PointerType>();
1293 assert(PT && "base of arrow member access is not pointer");
1294 BaseType = PT->getPointeeType();
1295 }
1296
Douglas Gregor9262f472010-04-27 18:19:34 +00001297 Record = BaseType->getAsCXXRecordDecl();
1298 assert(Record && "base of member expression does not name record");
John McCall58cc69d2010-01-27 01:50:18 +00001299 }
1300
Douglas Gregor9262f472010-04-27 18:19:34 +00001301 return Record;
John McCall58cc69d2010-01-27 01:50:18 +00001302}
1303
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001304SubstNonTypeTemplateParmPackExpr::
1305SubstNonTypeTemplateParmPackExpr(QualType T,
1306 NonTypeTemplateParmDecl *Param,
1307 SourceLocation NameLoc,
1308 const TemplateArgument &ArgPack)
1309 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor678d76c2011-07-01 01:22:09 +00001310 true, true, true, true),
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001311 Param(Param), Arguments(ArgPack.pack_begin()),
1312 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1313
1314TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1315 return TemplateArgument(Arguments, NumArguments);
1316}
1317
Richard Smithb15fe3a2012-09-12 00:56:43 +00001318FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1319 SourceLocation NameLoc,
1320 unsigned NumParams,
1321 Decl * const *Params)
1322 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary,
1323 true, true, true, true),
1324 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1325 if (Params)
1326 std::uninitialized_copy(Params, Params + NumParams,
1327 reinterpret_cast<Decl**>(this+1));
1328}
1329
1330FunctionParmPackExpr *
1331FunctionParmPackExpr::Create(ASTContext &Context, QualType T,
1332 ParmVarDecl *ParamPack, SourceLocation NameLoc,
1333 llvm::ArrayRef<Decl*> Params) {
1334 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1335 sizeof(ParmVarDecl*) * Params.size()))
1336 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1337}
1338
1339FunctionParmPackExpr *
1340FunctionParmPackExpr::CreateEmpty(ASTContext &Context, unsigned NumParams) {
1341 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1342 sizeof(ParmVarDecl*) * NumParams))
1343 FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0);
1344}
1345
Douglas Gregor29c42f22012-02-24 07:38:34 +00001346TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1347 ArrayRef<TypeSourceInfo *> Args,
1348 SourceLocation RParenLoc,
1349 bool Value)
1350 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1351 /*TypeDependent=*/false,
1352 /*ValueDependent=*/false,
1353 /*InstantiationDependent=*/false,
1354 /*ContainsUnexpandedParameterPack=*/false),
1355 Loc(Loc), RParenLoc(RParenLoc)
1356{
1357 TypeTraitExprBits.Kind = Kind;
1358 TypeTraitExprBits.Value = Value;
1359 TypeTraitExprBits.NumArgs = Args.size();
1360
1361 TypeSourceInfo **ToArgs = getTypeSourceInfos();
1362
1363 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1364 if (Args[I]->getType()->isDependentType())
1365 setValueDependent(true);
1366 if (Args[I]->getType()->isInstantiationDependentType())
1367 setInstantiationDependent(true);
1368 if (Args[I]->getType()->containsUnexpandedParameterPack())
1369 setContainsUnexpandedParameterPack(true);
1370
1371 ToArgs[I] = Args[I];
1372 }
1373}
1374
1375TypeTraitExpr *TypeTraitExpr::Create(ASTContext &C, QualType T,
1376 SourceLocation Loc,
1377 TypeTrait Kind,
1378 ArrayRef<TypeSourceInfo *> Args,
1379 SourceLocation RParenLoc,
1380 bool Value) {
1381 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size();
1382 void *Mem = C.Allocate(Size);
1383 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1384}
1385
1386TypeTraitExpr *TypeTraitExpr::CreateDeserialized(ASTContext &C,
1387 unsigned NumArgs) {
1388 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs;
1389 void *Mem = C.Allocate(Size);
1390 return new (Mem) TypeTraitExpr(EmptyShell());
1391}
1392
David Blaikie68e081d2011-12-20 02:48:34 +00001393void ArrayTypeTraitExpr::anchor() { }