blob: e6076f007fa3265df5cf093c6ab314e56efa4b66 [file] [log] [blame]
Ted Kremeneka758d092007-08-24 20:21:10 +00001//===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremeneka758d092007-08-24 20:21:10 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the subclesses of Expr class declared in ExprCXX.h
11//
12//===----------------------------------------------------------------------===//
13
Douglas Gregorb4609802008-11-14 16:09:21 +000014#include "clang/Basic/IdentifierTable.h"
Benjamin Kramer471c8b42012-07-04 20:19:54 +000015#include "clang/AST/ASTContext.h"
Douglas Gregorb4609802008-11-14 16:09:21 +000016#include "clang/AST/DeclCXX.h"
Douglas Gregoredce4dd2009-06-30 22:34:41 +000017#include "clang/AST/DeclTemplate.h"
Ted Kremeneka758d092007-08-24 20:21:10 +000018#include "clang/AST/ExprCXX.h"
Douglas Gregor26d4ac92010-02-24 23:40:28 +000019#include "clang/AST/TypeLoc.h"
Ted Kremeneka758d092007-08-24 20:21:10 +000020using namespace clang;
21
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000022
Ted Kremeneka758d092007-08-24 20:21:10 +000023//===----------------------------------------------------------------------===//
24// Child Iterators for iterating over subexpressions/substatements
25//===----------------------------------------------------------------------===//
26
Richard Smith0d729102012-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 Gregor57fdc8a2010-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 Pichet01b7c302010-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
Douglas Gregored8abf12010-07-08 06:14:04 +000054// CXXScalarValueInitExpr
Douglas Gregorab6677e2010-09-08 00:15:04 +000055SourceRange CXXScalarValueInitExpr::getSourceRange() const {
56 SourceLocation Start = RParenLoc;
57 if (TypeInfo)
58 Start = TypeInfo->getTypeLoc().getBeginLoc();
59 return SourceRange(Start, RParenLoc);
60}
61
Sebastian Redl4c5d3202008-11-21 19:14:01 +000062// CXXNewExpr
Ted Kremenekad7fe862010-02-11 22:51:03 +000063CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Sebastian Redl1548d142012-02-16 11:35:52 +000064 FunctionDecl *operatorDelete,
Sebastian Redl2aed8b82012-02-16 12:22:20 +000065 bool usualArrayDeleteWantsSize,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +000066 ArrayRef<Expr*> placementArgs,
Sebastian Redl2aed8b82012-02-16 12:22:20 +000067 SourceRange typeIdParens, Expr *arraySize,
68 InitializationStyle initializationStyle,
69 Expr *initializer, QualType ty,
70 TypeSourceInfo *allocatedTypeInfo,
71 SourceLocation startLoc, SourceRange directInitRange)
John McCallf89e55a2010-11-18 06:31:45 +000072 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000073 ty->isDependentType(), ty->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +000074 ty->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000075 ty->containsUnexpandedParameterPack()),
Sebastian Redl2aed8b82012-02-16 12:22:20 +000076 SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete),
77 AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens),
Benjamin Kramerd162cf12012-02-26 20:37:14 +000078 StartLoc(startLoc), DirectInitRange(directInitRange),
79 GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {
Sebastian Redl2aed8b82012-02-16 12:22:20 +000080 assert((initializer != 0 || initializationStyle == NoInit) &&
81 "Only NoInit can have no initializer.");
82 StoredInitializationStyle = initializer ? initializationStyle + 1 : 0;
Benjamin Kramer3b6bef92012-08-24 11:54:20 +000083 AllocateArgsArray(C, arraySize != 0, placementArgs.size(), initializer != 0);
Sebastian Redl4c5d3202008-11-21 19:14:01 +000084 unsigned i = 0;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000085 if (Array) {
Douglas Gregor561f8122011-07-01 01:22:09 +000086 if (arraySize->isInstantiationDependent())
87 ExprBits.InstantiationDependent = true;
88
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000089 if (arraySize->containsUnexpandedParameterPack())
90 ExprBits.ContainsUnexpandedParameterPack = true;
91
Sebastian Redlcee63fb2008-12-02 14:43:59 +000092 SubExprs[i++] = arraySize;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000093 }
94
Sebastian Redl2aed8b82012-02-16 12:22:20 +000095 if (initializer) {
96 if (initializer->isInstantiationDependent())
97 ExprBits.InstantiationDependent = true;
98
99 if (initializer->containsUnexpandedParameterPack())
100 ExprBits.ContainsUnexpandedParameterPack = true;
101
102 SubExprs[i++] = initializer;
103 }
104
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000105 for (unsigned j = 0; j != placementArgs.size(); ++j) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000106 if (placementArgs[j]->isInstantiationDependent())
107 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000108 if (placementArgs[j]->containsUnexpandedParameterPack())
109 ExprBits.ContainsUnexpandedParameterPack = true;
110
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000111 SubExprs[i++] = placementArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000112 }
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000113}
114
Chris Lattner59218632010-05-10 01:22:27 +0000115void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000116 unsigned numPlaceArgs, bool hasInitializer){
Chris Lattner59218632010-05-10 01:22:27 +0000117 assert(SubExprs == 0 && "SubExprs already allocated");
118 Array = isArray;
119 NumPlacementArgs = numPlaceArgs;
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000120
121 unsigned TotalSize = Array + hasInitializer + NumPlacementArgs;
Chris Lattner59218632010-05-10 01:22:27 +0000122 SubExprs = new (C) Stmt*[TotalSize];
123}
124
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000125bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCallc2f3e7f2011-03-07 03:12:35 +0000126 return getOperatorNew()->getType()->
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000127 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCallc2f3e7f2011-03-07 03:12:35 +0000128}
Chris Lattner59218632010-05-10 01:22:27 +0000129
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000130SourceLocation CXXNewExpr::getEndLoc() const {
131 switch (getInitializationStyle()) {
132 case NoInit:
133 return AllocatedTypeInfo->getTypeLoc().getEndLoc();
134 case CallInit:
135 return DirectInitRange.getEnd();
136 case ListInit:
137 return getInitializer()->getSourceRange().getEnd();
138 }
Matt Beaumont-Gayebc6af12012-02-16 22:15:50 +0000139 llvm_unreachable("bogus initialization style");
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000140}
141
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000142// CXXDeleteExpr
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000143QualType CXXDeleteExpr::getDestroyedType() const {
144 const Expr *Arg = getArgument();
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000145 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silversteinc87fa062010-10-20 00:56:01 +0000146 const QualType ArgType = Arg->getType();
Craig Silversteina437ad32010-11-16 07:16:25 +0000147
148 if (ArgType->isDependentType() && !ArgType->isPointerType())
149 return QualType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000150
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000151 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000152}
153
Douglas Gregora71d8192009-09-04 17:36:40 +0000154// CXXPseudoDestructorExpr
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000155PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
156 : Type(Info)
157{
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000158 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000159}
160
John McCalle23cf432010-12-14 08:05:40 +0000161CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000162 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
163 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
164 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
165 PseudoDestructorTypeStorage DestroyedType)
John McCalle23cf432010-12-14 08:05:40 +0000166 : Expr(CXXPseudoDestructorExprClass,
167 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
168 FunctionProtoType::ExtProtoInfo())),
169 VK_RValue, OK_Ordinary,
170 /*isTypeDependent=*/(Base->isTypeDependent() ||
171 (DestroyedType.getTypeSourceInfo() &&
172 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000173 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000174 (Base->isInstantiationDependent() ||
175 (QualifierLoc &&
176 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
177 (ScopeType &&
178 ScopeType->getType()->isInstantiationDependentType()) ||
179 (DestroyedType.getTypeSourceInfo() &&
180 DestroyedType.getTypeSourceInfo()->getType()
181 ->isInstantiationDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000182 // ContainsUnexpandedParameterPack
183 (Base->containsUnexpandedParameterPack() ||
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000184 (QualifierLoc &&
185 QualifierLoc.getNestedNameSpecifier()
186 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000187 (ScopeType &&
188 ScopeType->getType()->containsUnexpandedParameterPack()) ||
189 (DestroyedType.getTypeSourceInfo() &&
190 DestroyedType.getTypeSourceInfo()->getType()
191 ->containsUnexpandedParameterPack()))),
John McCalle23cf432010-12-14 08:05:40 +0000192 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000193 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalle23cf432010-12-14 08:05:40 +0000194 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
195 DestroyedType(DestroyedType) { }
196
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000197QualType CXXPseudoDestructorExpr::getDestroyedType() const {
198 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
199 return TInfo->getType();
200
201 return QualType();
202}
203
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000204SourceRange CXXPseudoDestructorExpr::getSourceRange() const {
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000205 SourceLocation End = DestroyedType.getLocation();
206 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000207 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000208 return SourceRange(Base->getLocStart(), End);
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000209}
210
John McCallba135432009-11-21 08:51:07 +0000211// UnresolvedLookupExpr
John McCallf7a1a742009-11-24 19:00:30 +0000212UnresolvedLookupExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000213UnresolvedLookupExpr::Create(ASTContext &C,
John McCallc373d482010-01-27 01:50:18 +0000214 CXXRecordDecl *NamingClass,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000215 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000216 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000217 const DeclarationNameInfo &NameInfo,
218 bool ADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000219 const TemplateArgumentListInfo *Args,
220 UnresolvedSetIterator Begin,
221 UnresolvedSetIterator End)
John McCallf7a1a742009-11-24 19:00:30 +0000222{
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000223 assert(Args || TemplateKWLoc.isValid());
224 unsigned num_args = Args ? Args->size() : 0;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000225 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000226 ASTTemplateKWAndArgsInfo::sizeFor(num_args));
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000227 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
228 TemplateKWLoc, NameInfo,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000229 ADL, /*Overload*/ true, Args,
Richard Smithad762fc2011-04-14 22:09:26 +0000230 Begin, End, /*StdIsAssociated=*/false);
John McCallf7a1a742009-11-24 19:00:30 +0000231}
232
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000233UnresolvedLookupExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000234UnresolvedLookupExpr::CreateEmpty(ASTContext &C,
235 bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +0000236 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000237 std::size_t size = sizeof(UnresolvedLookupExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000238 if (HasTemplateKWAndArgsInfo)
239 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000240
Chris Lattner32488542010-10-30 05:14:06 +0000241 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000242 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000243 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000244 return E;
245}
246
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000247OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000248 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000249 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000250 const DeclarationNameInfo &NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000251 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000252 UnresolvedSetIterator Begin,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000253 UnresolvedSetIterator End,
254 bool KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000255 bool KnownInstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000256 bool KnownContainsUnexpandedParameterPack)
257 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
258 KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000259 (KnownInstantiationDependent ||
260 NameInfo.isInstantiationDependent() ||
261 (QualifierLoc &&
262 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000263 (KnownContainsUnexpandedParameterPack ||
264 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor4c9be892011-02-28 20:01:57 +0000265 (QualifierLoc &&
266 QualifierLoc.getNestedNameSpecifier()
267 ->containsUnexpandedParameterPack()))),
Benjamin Kramerd162cf12012-02-26 20:37:14 +0000268 NameInfo(NameInfo), QualifierLoc(QualifierLoc),
269 Results(0), NumResults(End - Begin),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000270 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid())
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000271{
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000272 NumResults = End - Begin;
273 if (NumResults) {
274 // Determine whether this expression is type-dependent.
275 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
276 if ((*I)->getDeclContext()->isDependentContext() ||
277 isa<UnresolvedUsingValueDecl>(*I)) {
278 ExprBits.TypeDependent = true;
279 ExprBits.ValueDependent = true;
Richard Smith7657fd72012-08-13 21:29:18 +0000280 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000281 }
282 }
283
284 Results = static_cast<DeclAccessPair *>(
285 C.Allocate(sizeof(DeclAccessPair) * NumResults,
286 llvm::alignOf<DeclAccessPair>()));
287 memcpy(Results, &*Begin.getIterator(),
288 NumResults * sizeof(DeclAccessPair));
289 }
290
291 // If we have explicit template arguments, check for dependent
292 // template arguments and whether they contain any unexpanded pack
293 // expansions.
294 if (TemplateArgs) {
295 bool Dependent = false;
Douglas Gregor561f8122011-07-01 01:22:09 +0000296 bool InstantiationDependent = false;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000297 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000298 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
299 Dependent,
300 InstantiationDependent,
301 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000302
303 if (Dependent) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000304 ExprBits.TypeDependent = true;
305 ExprBits.ValueDependent = true;
306 }
307 if (InstantiationDependent)
308 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000309 if (ContainsUnexpandedParameterPack)
310 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000311 } else if (TemplateKWLoc.isValid()) {
312 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000313 }
314
315 if (isTypeDependent())
316 setType(C.DependentTy);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000317}
318
319void OverloadExpr::initializeResults(ASTContext &C,
320 UnresolvedSetIterator Begin,
321 UnresolvedSetIterator End) {
322 assert(Results == 0 && "Results already initialized!");
323 NumResults = End - Begin;
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000324 if (NumResults) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000325 Results = static_cast<DeclAccessPair *>(
326 C.Allocate(sizeof(DeclAccessPair) * NumResults,
327
328 llvm::alignOf<DeclAccessPair>()));
329 memcpy(Results, &*Begin.getIterator(),
330 NumResults * sizeof(DeclAccessPair));
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000331 }
332}
333
John McCalle9ee23e2010-04-22 18:44:12 +0000334CXXRecordDecl *OverloadExpr::getNamingClass() const {
335 if (isa<UnresolvedLookupExpr>(this))
336 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
337 else
338 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
339}
340
John McCall865d4472009-11-19 22:55:06 +0000341// DependentScopeDeclRefExpr
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000342DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000343 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000344 SourceLocation TemplateKWLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000345 const DeclarationNameInfo &NameInfo,
346 const TemplateArgumentListInfo *Args)
347 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
348 true, true,
Douglas Gregor561f8122011-07-01 01:22:09 +0000349 (NameInfo.isInstantiationDependent() ||
350 (QualifierLoc &&
351 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000352 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000353 (QualifierLoc &&
354 QualifierLoc.getNestedNameSpecifier()
355 ->containsUnexpandedParameterPack()))),
356 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000357 HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid())
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000358{
359 if (Args) {
360 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000361 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000362 bool ContainsUnexpandedParameterPack
363 = ExprBits.ContainsUnexpandedParameterPack;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000364 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args,
365 Dependent,
366 InstantiationDependent,
367 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000368 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000369 } else if (TemplateKWLoc.isValid()) {
370 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000371 }
372}
373
John McCallf7a1a742009-11-24 19:00:30 +0000374DependentScopeDeclRefExpr *
375DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000376 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000377 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000378 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +0000379 const TemplateArgumentListInfo *Args) {
380 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCallf7a1a742009-11-24 19:00:30 +0000381 if (Args)
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000382 size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size());
383 else if (TemplateKWLoc.isValid())
384 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000385 void *Mem = C.Allocate(size);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000386 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
387 TemplateKWLoc, NameInfo, Args);
John McCallf7a1a742009-11-24 19:00:30 +0000388}
389
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000390DependentScopeDeclRefExpr *
391DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000392 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000393 unsigned NumTemplateArgs) {
394 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000395 if (HasTemplateKWAndArgsInfo)
396 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000397 void *Mem = C.Allocate(size);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000398 DependentScopeDeclRefExpr *E
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000399 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000400 SourceLocation(),
Douglas Gregordef03542011-02-04 12:01:24 +0000401 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000402 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregordef03542011-02-04 12:01:24 +0000403 return E;
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000404}
405
Chandler Carruth428edaf2010-10-25 08:47:36 +0000406SourceRange CXXConstructExpr::getSourceRange() const {
John McCall2882eca2011-02-21 06:23:05 +0000407 if (isa<CXXTemporaryObjectExpr>(this))
408 return cast<CXXTemporaryObjectExpr>(this)->getSourceRange();
409
Douglas Gregor40749ee2010-11-03 00:35:38 +0000410 if (ParenRange.isValid())
411 return SourceRange(Loc, ParenRange.getEnd());
412
413 SourceLocation End = Loc;
414 for (unsigned I = getNumArgs(); I > 0; --I) {
415 const Expr *Arg = getArg(I-1);
416 if (!Arg->isDefaultArgument()) {
417 SourceLocation NewEnd = Arg->getLocEnd();
418 if (NewEnd.isValid()) {
419 End = NewEnd;
420 break;
421 }
422 }
423 }
424
425 return SourceRange(Loc, End);
Ted Kremeneke3837682009-12-23 04:00:48 +0000426}
427
Argyrios Kyrtzidis4548ca22012-04-30 22:12:22 +0000428SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
Douglas Gregorb4609802008-11-14 16:09:21 +0000429 OverloadedOperatorKind Kind = getOperator();
430 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
431 if (getNumArgs() == 1)
432 // Prefix operator
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000433 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000434 else
435 // Postfix operator
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000436 return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
Chandler Carruthd7650612011-04-02 09:47:38 +0000437 } else if (Kind == OO_Arrow) {
438 return getArg(0)->getSourceRange();
Douglas Gregorb4609802008-11-14 16:09:21 +0000439 } else if (Kind == OO_Call) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000440 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregorb4609802008-11-14 16:09:21 +0000441 } else if (Kind == OO_Subscript) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000442 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregorb4609802008-11-14 16:09:21 +0000443 } else if (getNumArgs() == 1) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000444 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000445 } else if (getNumArgs() == 2) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000446 return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000447 } else {
Argyrios Kyrtzidis4548ca22012-04-30 22:12:22 +0000448 return getOperatorLoc();
Douglas Gregorb4609802008-11-14 16:09:21 +0000449 }
450}
451
Ted Kremenekb2771592011-03-30 17:41:19 +0000452Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
Jordan Rose51e87c52012-08-03 23:08:39 +0000453 const Expr *Callee = getCallee()->IgnoreParens();
454 if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee))
Douglas Gregor88a35142008-12-22 05:46:06 +0000455 return MemExpr->getBase();
Jordan Rose51e87c52012-08-03 23:08:39 +0000456 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee))
457 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
458 return BO->getLHS();
Douglas Gregor88a35142008-12-22 05:46:06 +0000459
460 // FIXME: Will eventually need to cope with member pointers.
461 return 0;
462}
463
Ted Kremenekb2771592011-03-30 17:41:19 +0000464CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
465 if (const MemberExpr *MemExpr =
466 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
467 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
468
469 // FIXME: Will eventually need to cope with member pointers.
470 return 0;
471}
472
473
David Blaikie0cf3c0e2012-05-03 16:25:49 +0000474CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Chandler Carruth007a9b12010-10-27 06:55:41 +0000475 Expr* ThisArg = getImplicitObjectArgument();
476 if (!ThisArg)
477 return 0;
478
479 if (ThisArg->getType()->isAnyPointerType())
480 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
481
482 return ThisArg->getType()->getAsCXXRecordDecl();
483}
484
Douglas Gregor00b98c22009-11-12 15:31:47 +0000485
Douglas Gregor49badde2008-10-27 19:41:14 +0000486//===----------------------------------------------------------------------===//
487// Named casts
488//===----------------------------------------------------------------------===//
489
490/// getCastName - Get the name of the C++ cast being used, e.g.,
491/// "static_cast", "dynamic_cast", "reinterpret_cast", or
492/// "const_cast". The returned pointer must not be freed.
493const char *CXXNamedCastExpr::getCastName() const {
494 switch (getStmtClass()) {
495 case CXXStaticCastExprClass: return "static_cast";
496 case CXXDynamicCastExprClass: return "dynamic_cast";
497 case CXXReinterpretCastExprClass: return "reinterpret_cast";
498 case CXXConstCastExprClass: return "const_cast";
499 default: return "<invalid cast>";
500 }
501}
Douglas Gregor506ae412009-01-16 18:33:17 +0000502
John McCallf871d0c2010-08-07 06:22:56 +0000503CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000504 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000505 CastKind K, Expr *Op,
506 const CXXCastPath *BasePath,
507 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000508 SourceLocation L,
509 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000510 unsigned PathSize = (BasePath ? BasePath->size() : 0);
511 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
512 + PathSize * sizeof(CXXBaseSpecifier*));
513 CXXStaticCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000514 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
515 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000516 if (PathSize) E->setCastPath(*BasePath);
517 return E;
518}
519
520CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
521 unsigned PathSize) {
522 void *Buffer =
523 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
524 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
525}
526
527CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000528 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000529 CastKind K, Expr *Op,
530 const CXXCastPath *BasePath,
531 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000532 SourceLocation L,
533 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000534 unsigned PathSize = (BasePath ? BasePath->size() : 0);
535 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
536 + PathSize * sizeof(CXXBaseSpecifier*));
537 CXXDynamicCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000538 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
539 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000540 if (PathSize) E->setCastPath(*BasePath);
541 return E;
542}
543
544CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
545 unsigned PathSize) {
546 void *Buffer =
547 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
548 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
549}
550
Anders Carlsson0fee3302011-04-11 01:43:55 +0000551/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
552/// to always be null. For example:
553///
554/// struct A { };
555/// struct B final : A { };
556/// struct C { };
557///
558/// C *f(B* b) { return dynamic_cast<C*>(b); }
559bool CXXDynamicCastExpr::isAlwaysNull() const
560{
561 QualType SrcType = getSubExpr()->getType();
562 QualType DestType = getType();
563
564 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
565 SrcType = SrcPTy->getPointeeType();
566 DestType = DestType->castAs<PointerType>()->getPointeeType();
567 }
568
Sean Hunt5ca86392012-06-19 23:44:55 +0000569 if (DestType->isVoidType())
570 return false;
571
Anders Carlsson0fee3302011-04-11 01:43:55 +0000572 const CXXRecordDecl *SrcRD =
573 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
574
Jakob Stoklund Olesen35329362012-06-19 21:48:43 +0000575 if (!SrcRD->hasAttr<FinalAttr>())
576 return false;
577
Anders Carlsson0fee3302011-04-11 01:43:55 +0000578 const CXXRecordDecl *DestRD =
579 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
580
581 return !DestRD->isDerivedFrom(SrcRD);
582}
583
John McCallf871d0c2010-08-07 06:22:56 +0000584CXXReinterpretCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000585CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
586 CastKind K, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000587 const CXXCastPath *BasePath,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000588 TypeSourceInfo *WrittenTy, SourceLocation L,
589 SourceLocation RParenLoc) {
John McCallf871d0c2010-08-07 06:22:56 +0000590 unsigned PathSize = (BasePath ? BasePath->size() : 0);
591 void *Buffer =
592 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
593 CXXReinterpretCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000594 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
595 RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000596 if (PathSize) E->setCastPath(*BasePath);
597 return E;
598}
599
600CXXReinterpretCastExpr *
601CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
602 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
603 + PathSize * sizeof(CXXBaseSpecifier*));
604 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
605}
606
John McCallf89e55a2010-11-18 06:31:45 +0000607CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
608 ExprValueKind VK, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000609 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000610 SourceLocation L,
611 SourceLocation RParenLoc) {
612 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc);
John McCallf871d0c2010-08-07 06:22:56 +0000613}
614
615CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
616 return new (C) CXXConstCastExpr(EmptyShell());
617}
618
619CXXFunctionalCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000620CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000621 TypeSourceInfo *Written, SourceLocation L,
622 CastKind K, Expr *Op, const CXXCastPath *BasePath,
623 SourceLocation R) {
624 unsigned PathSize = (BasePath ? BasePath->size() : 0);
625 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
626 + PathSize * sizeof(CXXBaseSpecifier*));
627 CXXFunctionalCastExpr *E =
John McCallf89e55a2010-11-18 06:31:45 +0000628 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallf871d0c2010-08-07 06:22:56 +0000629 if (PathSize) E->setCastPath(*BasePath);
630 return E;
631}
632
633CXXFunctionalCastExpr *
634CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
635 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
636 + PathSize * sizeof(CXXBaseSpecifier*));
637 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
638}
639
Richard Smith9fcce652012-03-07 08:35:16 +0000640UserDefinedLiteral::LiteralOperatorKind
641UserDefinedLiteral::getLiteralOperatorKind() const {
642 if (getNumArgs() == 0)
643 return LOK_Template;
644 if (getNumArgs() == 2)
645 return LOK_String;
646
647 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
648 QualType ParamTy =
649 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
650 if (ParamTy->isPointerType())
651 return LOK_Raw;
652 if (ParamTy->isAnyCharacterType())
653 return LOK_Character;
654 if (ParamTy->isIntegerType())
655 return LOK_Integer;
656 if (ParamTy->isFloatingType())
657 return LOK_Floating;
658
659 llvm_unreachable("unknown kind of literal operator");
660}
661
662Expr *UserDefinedLiteral::getCookedLiteral() {
663#ifndef NDEBUG
664 LiteralOperatorKind LOK = getLiteralOperatorKind();
665 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
666#endif
667 return getArg(0);
668}
669
670const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
671 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
672}
John McCallf871d0c2010-08-07 06:22:56 +0000673
Douglas Gregor65222e82009-12-23 18:19:08 +0000674CXXDefaultArgExpr *
Douglas Gregor036aed12009-12-23 23:03:06 +0000675CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
676 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor65222e82009-12-23 18:19:08 +0000677 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor036aed12009-12-23 23:03:06 +0000678 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
679 SubExpr);
Douglas Gregor65222e82009-12-23 18:19:08 +0000680}
681
Mike Stump1eb44332009-09-09 15:08:12 +0000682CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonb859f352009-05-30 20:34:37 +0000683 const CXXDestructorDecl *Destructor) {
Anders Carlsson88eaf072009-05-30 22:38:53 +0000684 return new (C) CXXTemporary(Destructor);
685}
686
Mike Stump1eb44332009-09-09 15:08:12 +0000687CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000688 CXXTemporary *Temp,
689 Expr* SubExpr) {
Peter Collingbournebceb7552011-11-27 22:09:28 +0000690 assert((SubExpr->getType()->isRecordType() ||
691 SubExpr->getType()->isArrayType()) &&
692 "Expression bound to a temporary must have record or array type!");
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000693
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000694 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000695}
696
Anders Carlsson8e587a12009-05-30 20:56:46 +0000697CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000698 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000699 TypeSourceInfo *Type,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000700 ArrayRef<Expr*> Args,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000701 SourceRange parenRange,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000702 bool HadMultipleCandidates,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000703 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000704 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
705 Type->getType().getNonReferenceType(),
706 Type->getTypeLoc().getBeginLoc(),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000707 Cons, false, Args,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000708 HadMultipleCandidates, /*FIXME*/false, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000709 CXXConstructExpr::CK_Complete, parenRange),
710 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000711}
712
713SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
Chandler Carruth428edaf2010-10-25 08:47:36 +0000714 return SourceRange(Type->getTypeLoc().getBeginLoc(),
715 getParenRange().getEnd());
Douglas Gregor506ae412009-01-16 18:33:17 +0000716}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000717
Mike Stump1eb44332009-09-09 15:08:12 +0000718CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000719 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000720 CXXConstructorDecl *D, bool Elidable,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000721 ArrayRef<Expr*> Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000722 bool HadMultipleCandidates,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000723 bool ListInitialization,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000724 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000725 ConstructionKind ConstructKind,
726 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000727 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000728 Elidable, Args,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000729 HadMultipleCandidates, ListInitialization,
730 ZeroInitialization, ConstructKind,
731 ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000732}
733
Mike Stump1eb44332009-09-09 15:08:12 +0000734CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000735 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000736 CXXConstructorDecl *D, bool elidable,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000737 ArrayRef<Expr*> args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000738 bool HadMultipleCandidates,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000739 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000740 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000741 ConstructionKind ConstructKind,
742 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000743 : Expr(SC, T, VK_RValue, OK_Ordinary,
744 T->isDependentType(), T->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000745 T->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000746 T->containsUnexpandedParameterPack()),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000747 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(args.size()),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000748 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000749 ListInitialization(ListInitialization),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000750 ZeroInitialization(ZeroInitialization),
Douglas Gregora48e6762011-09-26 14:47:03 +0000751 ConstructKind(ConstructKind), Args(0)
Douglas Gregor16006c92009-12-16 18:50:27 +0000752{
753 if (NumArgs) {
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000754 Args = new (C) Stmt*[args.size()];
Douglas Gregor16006c92009-12-16 18:50:27 +0000755
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000756 for (unsigned i = 0; i != args.size(); ++i) {
Douglas Gregor16006c92009-12-16 18:50:27 +0000757 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000758
759 if (args[i]->isValueDependent())
760 ExprBits.ValueDependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000761 if (args[i]->isInstantiationDependent())
762 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000763 if (args[i]->containsUnexpandedParameterPack())
764 ExprBits.ContainsUnexpandedParameterPack = true;
765
Douglas Gregor16006c92009-12-16 18:50:27 +0000766 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000767 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000768 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000769}
770
Douglas Gregor01d08012012-02-07 10:09:13 +0000771LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
772 LambdaCaptureKind Kind, VarDecl *Var,
773 SourceLocation EllipsisLoc)
774 : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
775{
776 unsigned Bits = 0;
777 if (Implicit)
778 Bits |= Capture_Implicit;
779
780 switch (Kind) {
781 case LCK_This:
782 assert(Var == 0 && "'this' capture cannot have a variable!");
783 break;
784
785 case LCK_ByCopy:
786 Bits |= Capture_ByCopy;
787 // Fall through
788 case LCK_ByRef:
789 assert(Var && "capture must have a variable!");
790 break;
791 }
792 VarAndBits.setInt(Bits);
793}
794
795LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const {
796 if (capturesThis())
797 return LCK_This;
798
799 return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef;
800}
801
802LambdaExpr::LambdaExpr(QualType T,
803 SourceRange IntroducerRange,
804 LambdaCaptureDefault CaptureDefault,
805 ArrayRef<Capture> Captures,
806 bool ExplicitParams,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000807 bool ExplicitResultType,
Douglas Gregor01d08012012-02-07 10:09:13 +0000808 ArrayRef<Expr *> CaptureInits,
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000809 ArrayRef<VarDecl *> ArrayIndexVars,
810 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000811 SourceLocation ClosingBrace,
812 bool ContainsUnexpandedParameterPack)
Douglas Gregor01d08012012-02-07 10:09:13 +0000813 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
814 T->isDependentType(), T->isDependentType(), T->isDependentType(),
Richard Smith612409e2012-07-25 03:56:55 +0000815 ContainsUnexpandedParameterPack),
Douglas Gregor01d08012012-02-07 10:09:13 +0000816 IntroducerRange(IntroducerRange),
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000817 NumCaptures(Captures.size()),
Douglas Gregor01d08012012-02-07 10:09:13 +0000818 CaptureDefault(CaptureDefault),
819 ExplicitParams(ExplicitParams),
Douglas Gregordfca6f52012-02-13 22:00:16 +0000820 ExplicitResultType(ExplicitResultType),
Douglas Gregor01d08012012-02-07 10:09:13 +0000821 ClosingBrace(ClosingBrace)
822{
823 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorda8962a2012-02-13 15:44:47 +0000824 CXXRecordDecl *Class = getLambdaClass();
825 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Douglas Gregorda8962a2012-02-13 15:44:47 +0000826
827 // FIXME: Propagate "has unexpanded parameter pack" bit.
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000828
829 // Copy captures.
830 ASTContext &Context = Class->getASTContext();
831 Data.NumCaptures = NumCaptures;
832 Data.NumExplicitCaptures = 0;
833 Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures);
834 Capture *ToCapture = Data.Captures;
835 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
836 if (Captures[I].isExplicit())
837 ++Data.NumExplicitCaptures;
838
839 *ToCapture++ = Captures[I];
840 }
841
842 // Copy initialization expressions for the non-static data members.
843 Stmt **Stored = getStoredStmts();
844 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
845 *Stored++ = CaptureInits[I];
846
847 // Copy the body of the lambda.
848 *Stored++ = getCallOperator()->getBody();
849
850 // Copy the array index variables, if any.
851 HasArrayIndexVars = !ArrayIndexVars.empty();
852 if (HasArrayIndexVars) {
853 assert(ArrayIndexStarts.size() == NumCaptures);
854 memcpy(getArrayIndexVars(), ArrayIndexVars.data(),
855 sizeof(VarDecl *) * ArrayIndexVars.size());
856 memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(),
857 sizeof(unsigned) * Captures.size());
858 getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size();
Douglas Gregor5878cbc2012-02-21 04:17:39 +0000859 }
Douglas Gregor01d08012012-02-07 10:09:13 +0000860}
861
862LambdaExpr *LambdaExpr::Create(ASTContext &Context,
863 CXXRecordDecl *Class,
864 SourceRange IntroducerRange,
865 LambdaCaptureDefault CaptureDefault,
866 ArrayRef<Capture> Captures,
867 bool ExplicitParams,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000868 bool ExplicitResultType,
Douglas Gregor01d08012012-02-07 10:09:13 +0000869 ArrayRef<Expr *> CaptureInits,
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000870 ArrayRef<VarDecl *> ArrayIndexVars,
871 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000872 SourceLocation ClosingBrace,
873 bool ContainsUnexpandedParameterPack) {
Douglas Gregor01d08012012-02-07 10:09:13 +0000874 // Determine the type of the expression (i.e., the type of the
875 // function object we're creating).
876 QualType T = Context.getTypeDeclType(Class);
Douglas Gregor01d08012012-02-07 10:09:13 +0000877
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000878 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1);
Richard Smith88d2f672012-08-21 05:42:49 +0000879 if (!ArrayIndexVars.empty()) {
880 Size += sizeof(unsigned) * (Captures.size() + 1);
881 // Realign for following VarDecl array.
Richard Smitha796b6c2012-08-21 18:18:06 +0000882 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>());
Richard Smith88d2f672012-08-21 05:42:49 +0000883 Size += sizeof(VarDecl *) * ArrayIndexVars.size();
884 }
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000885 void *Mem = Context.Allocate(Size);
886 return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000887 Captures, ExplicitParams, ExplicitResultType,
888 CaptureInits, ArrayIndexVars, ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000889 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregor01d08012012-02-07 10:09:13 +0000890}
891
Douglas Gregor9d36f5d2012-02-14 17:54:36 +0000892LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures,
893 unsigned NumArrayIndexVars) {
894 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1);
895 if (NumArrayIndexVars)
896 Size += sizeof(VarDecl) * NumArrayIndexVars
897 + sizeof(unsigned) * (NumCaptures + 1);
898 void *Mem = C.Allocate(Size);
899 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0);
900}
901
Douglas Gregorda8962a2012-02-13 15:44:47 +0000902LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000903 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000904}
905
906LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000907 return capture_begin() + NumCaptures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000908}
909
910LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
911 return capture_begin();
912}
913
914LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
915 struct CXXRecordDecl::LambdaDefinitionData &Data
916 = getLambdaClass()->getLambdaData();
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000917 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000918}
919
920LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
921 return explicit_capture_end();
922}
923
924LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
925 return capture_end();
926}
927
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000928ArrayRef<VarDecl *>
929LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000930 assert(HasArrayIndexVars && "No array index-var data?");
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000931
932 unsigned Index = Iter - capture_init_begin();
Matt Beaumont-Gay43a1b002012-02-13 19:29:45 +0000933 assert(Index < getLambdaClass()->getLambdaData().NumCaptures &&
934 "Capture index out-of-range");
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000935 VarDecl **IndexVars = getArrayIndexVars();
936 unsigned *IndexStarts = getArrayIndexStarts();
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000937 return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index],
938 IndexVars + IndexStarts[Index + 1]);
939}
940
Douglas Gregor01d08012012-02-07 10:09:13 +0000941CXXRecordDecl *LambdaExpr::getLambdaClass() const {
942 return getType()->getAsCXXRecordDecl();
943}
944
945CXXMethodDecl *LambdaExpr::getCallOperator() const {
946 CXXRecordDecl *Record = getLambdaClass();
947 DeclarationName Name
948 = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
949 DeclContext::lookup_result Calls = Record->lookup(Name);
950 assert(Calls.first != Calls.second && "Missing lambda call operator!");
951 CXXMethodDecl *Result = cast<CXXMethodDecl>(*Calls.first++);
952 assert(Calls.first == Calls.second && "More than lambda one call operator?");
953 return Result;
954}
955
Douglas Gregor9d36f5d2012-02-14 17:54:36 +0000956CompoundStmt *LambdaExpr::getBody() const {
957 if (!getStoredStmts()[NumCaptures])
958 getStoredStmts()[NumCaptures] = getCallOperator()->getBody();
959
960 return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
961}
962
Douglas Gregor01d08012012-02-07 10:09:13 +0000963bool LambdaExpr::isMutable() const {
David Blaikie4ef832f2012-08-10 00:55:35 +0000964 return !getCallOperator()->isConst();
Douglas Gregor01d08012012-02-07 10:09:13 +0000965}
966
John McCall80ee6e82011-11-10 05:35:25 +0000967ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
968 ArrayRef<CleanupObject> objects)
John McCall4765fa02010-12-06 08:20:24 +0000969 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +0000970 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000971 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000972 subexpr->isInstantiationDependent(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000973 subexpr->containsUnexpandedParameterPack()),
John McCall80ee6e82011-11-10 05:35:25 +0000974 SubExpr(subexpr) {
975 ExprWithCleanupsBits.NumObjects = objects.size();
976 for (unsigned i = 0, e = objects.size(); i != e; ++i)
977 getObjectsBuffer()[i] = objects[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +0000978}
979
John McCall80ee6e82011-11-10 05:35:25 +0000980ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
981 ArrayRef<CleanupObject> objects) {
982 size_t size = sizeof(ExprWithCleanups)
983 + objects.size() * sizeof(CleanupObject);
984 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
985 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnerd2598362010-05-10 00:25:06 +0000986}
987
John McCall80ee6e82011-11-10 05:35:25 +0000988ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
989 : Expr(ExprWithCleanupsClass, empty) {
990 ExprWithCleanupsBits.NumObjects = numObjects;
991}
Chris Lattnerd2598362010-05-10 00:25:06 +0000992
John McCall80ee6e82011-11-10 05:35:25 +0000993ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
994 unsigned numObjects) {
995 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
996 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
997 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson88eaf072009-05-30 22:38:53 +0000998}
999
Douglas Gregorab6677e2010-09-08 00:15:04 +00001000CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001001 SourceLocation LParenLoc,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001002 ArrayRef<Expr*> Args,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001003 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +00001004 : Expr(CXXUnresolvedConstructExprClass,
1005 Type->getType().getNonReferenceType(),
Douglas Gregor032c8692011-07-08 15:50:43 +00001006 (Type->getType()->isLValueReferenceType() ? VK_LValue
1007 :Type->getType()->isRValueReferenceType()? VK_XValue
1008 :VK_RValue),
1009 OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001010 Type->getType()->isDependentType(), true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001011 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001012 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001013 LParenLoc(LParenLoc),
1014 RParenLoc(RParenLoc),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001015 NumArgs(Args.size()) {
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001016 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001017 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001018 if (Args[I]->containsUnexpandedParameterPack())
1019 ExprBits.ContainsUnexpandedParameterPack = true;
1020
1021 StoredArgs[I] = Args[I];
1022 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001023}
1024
1025CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +00001026CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +00001027 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001028 SourceLocation LParenLoc,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001029 ArrayRef<Expr*> Args,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001030 SourceLocation RParenLoc) {
1031 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001032 sizeof(Expr *) * Args.size());
1033 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001034}
1035
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001036CXXUnresolvedConstructExpr *
1037CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
1038 Stmt::EmptyShell Empty;
1039 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
1040 sizeof(Expr *) * NumArgs);
1041 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1042}
1043
Douglas Gregorab6677e2010-09-08 00:15:04 +00001044SourceRange CXXUnresolvedConstructExpr::getSourceRange() const {
1045 return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc);
1046}
1047
John McCall865d4472009-11-19 22:55:06 +00001048CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +00001049 Expr *Base, QualType BaseType,
1050 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001051 SourceLocation OperatorLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001052 NestedNameSpecifierLoc QualifierLoc,
1053 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001054 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001055 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +00001056 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +00001057 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +00001058 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001059 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001060 (QualifierLoc &&
1061 QualifierLoc.getNestedNameSpecifier()
1062 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001063 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +00001064 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001065 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001066 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001067 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +00001068 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001069 if (TemplateArgs) {
1070 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +00001071 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001072 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001073 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
1074 Dependent,
1075 InstantiationDependent,
1076 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001077 if (ContainsUnexpandedParameterPack)
1078 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001079 } else if (TemplateKWLoc.isValid()) {
1080 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001081 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001082}
1083
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001084CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
1085 Expr *Base, QualType BaseType,
1086 bool IsArrow,
1087 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001088 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001089 NamedDecl *FirstQualifierFoundInScope,
1090 DeclarationNameInfo MemberNameInfo)
1091 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +00001092 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001093 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001094 (QualifierLoc &&
1095 QualifierLoc.getNestedNameSpecifier()->
1096 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001097 MemberNameInfo.containsUnexpandedParameterPack())),
1098 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001099 HasTemplateKWAndArgsInfo(false),
1100 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001101 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1102 MemberNameInfo(MemberNameInfo) { }
1103
John McCall865d4472009-11-19 22:55:06 +00001104CXXDependentScopeMemberExpr *
1105CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +00001106 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001107 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001108 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001109 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001110 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001111 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +00001112 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001113 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCallaa81e162009-12-01 22:10:20 +00001114 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
1115 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001116 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +00001117 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001118 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +00001119
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001120 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1121 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
1122 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCalld5532b62009-11-23 01:53:49 +00001123
Chris Lattner32488542010-10-30 05:14:06 +00001124 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +00001125 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1126 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001127 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001128 TemplateKWLoc,
John McCallaa81e162009-12-01 22:10:20 +00001129 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001130 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001131}
1132
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001133CXXDependentScopeMemberExpr *
1134CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001135 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001136 unsigned NumTemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001137 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001138 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001139 0, SourceLocation(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001140 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001141 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001142
1143 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001144 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +00001145 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001146 CXXDependentScopeMemberExpr *E
1147 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001148 0, SourceLocation(),
1149 NestedNameSpecifierLoc(),
1150 SourceLocation(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001151 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001152 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001153 return E;
1154}
1155
Douglas Gregor4c9be892011-02-28 20:01:57 +00001156bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
1157 if (Base == 0)
1158 return true;
1159
Douglas Gregor75e85042011-03-02 21:06:53 +00001160 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001161}
1162
John McCall864c0412011-04-26 20:42:42 +00001163static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1164 UnresolvedSetIterator end) {
1165 do {
1166 NamedDecl *decl = *begin;
1167 if (isa<UnresolvedUsingValueDecl>(decl))
1168 return false;
1169 if (isa<UsingShadowDecl>(decl))
1170 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
1171
1172 // Unresolved member expressions should only contain methods and
1173 // method templates.
1174 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
1175
1176 if (isa<FunctionTemplateDecl>(decl))
1177 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
1178 if (cast<CXXMethodDecl>(decl)->isStatic())
1179 return false;
1180 } while (++begin != end);
1181
1182 return true;
1183}
1184
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001185UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001186 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001187 Expr *Base, QualType BaseType,
1188 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001189 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001190 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001191 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001192 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001193 const TemplateArgumentListInfo *TemplateArgs,
1194 UnresolvedSetIterator Begin,
1195 UnresolvedSetIterator End)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001196 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1197 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001198 // Dependent
1199 ((Base && Base->isTypeDependent()) ||
1200 BaseType->isDependentType()),
Douglas Gregor561f8122011-07-01 01:22:09 +00001201 ((Base && Base->isInstantiationDependent()) ||
1202 BaseType->isInstantiationDependentType()),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001203 // Contains unexpanded parameter pack
1204 ((Base && Base->containsUnexpandedParameterPack()) ||
1205 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +00001206 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1207 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall864c0412011-04-26 20:42:42 +00001208
1209 // Check whether all of the members are non-static member functions,
1210 // and if so, mark give this bound-member type instead of overload type.
1211 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1212 setType(C.BoundMemberTy);
John McCall129e2df2009-11-30 22:42:35 +00001213}
1214
Douglas Gregor4c9be892011-02-28 20:01:57 +00001215bool UnresolvedMemberExpr::isImplicitAccess() const {
1216 if (Base == 0)
1217 return true;
1218
Douglas Gregor75e85042011-03-02 21:06:53 +00001219 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001220}
1221
John McCall129e2df2009-11-30 22:42:35 +00001222UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001223UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001224 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001225 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001226 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001227 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001228 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001229 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001230 const TemplateArgumentListInfo *TemplateArgs,
1231 UnresolvedSetIterator Begin,
1232 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +00001233 std::size_t size = sizeof(UnresolvedMemberExpr);
1234 if (TemplateArgs)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001235 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
1236 else if (TemplateKWLoc.isValid())
1237 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall129e2df2009-11-30 22:42:35 +00001238
Chris Lattner32488542010-10-30 05:14:06 +00001239 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +00001240 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001241 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001242 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001243 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +00001244}
1245
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001246UnresolvedMemberExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001247UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001248 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001249 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001250 if (HasTemplateKWAndArgsInfo)
1251 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001252
Chris Lattner32488542010-10-30 05:14:06 +00001253 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001254 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001255 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001256 return E;
1257}
1258
John McCallc373d482010-01-27 01:50:18 +00001259CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1260 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1261
1262 // If there was a nested name specifier, it names the naming class.
1263 // It can't be dependent: after all, we were actually able to do the
1264 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001265 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +00001266 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +00001267 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +00001268 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001269 Record = T->getAsCXXRecordDecl();
1270 assert(Record && "qualifier in member expression does not name record");
1271 }
John McCallc373d482010-01-27 01:50:18 +00001272 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001273 else {
John McCallc373d482010-01-27 01:50:18 +00001274 QualType BaseType = getBaseType().getNonReferenceType();
1275 if (isArrow()) {
1276 const PointerType *PT = BaseType->getAs<PointerType>();
1277 assert(PT && "base of arrow member access is not pointer");
1278 BaseType = PT->getPointeeType();
1279 }
1280
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001281 Record = BaseType->getAsCXXRecordDecl();
1282 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +00001283 }
1284
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001285 return Record;
John McCallc373d482010-01-27 01:50:18 +00001286}
1287
Douglas Gregorc7793c72011-01-15 01:15:58 +00001288SubstNonTypeTemplateParmPackExpr::
1289SubstNonTypeTemplateParmPackExpr(QualType T,
1290 NonTypeTemplateParmDecl *Param,
1291 SourceLocation NameLoc,
1292 const TemplateArgument &ArgPack)
1293 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001294 true, true, true, true),
Douglas Gregorc7793c72011-01-15 01:15:58 +00001295 Param(Param), Arguments(ArgPack.pack_begin()),
1296 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1297
1298TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1299 return TemplateArgument(Arguments, NumArguments);
1300}
1301
Richard Smith9a4db032012-09-12 00:56:43 +00001302FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1303 SourceLocation NameLoc,
1304 unsigned NumParams,
1305 Decl * const *Params)
1306 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary,
1307 true, true, true, true),
1308 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1309 if (Params)
1310 std::uninitialized_copy(Params, Params + NumParams,
1311 reinterpret_cast<Decl**>(this+1));
1312}
1313
1314FunctionParmPackExpr *
1315FunctionParmPackExpr::Create(ASTContext &Context, QualType T,
1316 ParmVarDecl *ParamPack, SourceLocation NameLoc,
1317 llvm::ArrayRef<Decl*> Params) {
1318 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1319 sizeof(ParmVarDecl*) * Params.size()))
1320 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1321}
1322
1323FunctionParmPackExpr *
1324FunctionParmPackExpr::CreateEmpty(ASTContext &Context, unsigned NumParams) {
1325 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1326 sizeof(ParmVarDecl*) * NumParams))
1327 FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0);
1328}
1329
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00001330TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1331 ArrayRef<TypeSourceInfo *> Args,
1332 SourceLocation RParenLoc,
1333 bool Value)
1334 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1335 /*TypeDependent=*/false,
1336 /*ValueDependent=*/false,
1337 /*InstantiationDependent=*/false,
1338 /*ContainsUnexpandedParameterPack=*/false),
1339 Loc(Loc), RParenLoc(RParenLoc)
1340{
1341 TypeTraitExprBits.Kind = Kind;
1342 TypeTraitExprBits.Value = Value;
1343 TypeTraitExprBits.NumArgs = Args.size();
1344
1345 TypeSourceInfo **ToArgs = getTypeSourceInfos();
1346
1347 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1348 if (Args[I]->getType()->isDependentType())
1349 setValueDependent(true);
1350 if (Args[I]->getType()->isInstantiationDependentType())
1351 setInstantiationDependent(true);
1352 if (Args[I]->getType()->containsUnexpandedParameterPack())
1353 setContainsUnexpandedParameterPack(true);
1354
1355 ToArgs[I] = Args[I];
1356 }
1357}
1358
1359TypeTraitExpr *TypeTraitExpr::Create(ASTContext &C, QualType T,
1360 SourceLocation Loc,
1361 TypeTrait Kind,
1362 ArrayRef<TypeSourceInfo *> Args,
1363 SourceLocation RParenLoc,
1364 bool Value) {
1365 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size();
1366 void *Mem = C.Allocate(Size);
1367 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1368}
1369
1370TypeTraitExpr *TypeTraitExpr::CreateDeserialized(ASTContext &C,
1371 unsigned NumArgs) {
1372 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs;
1373 void *Mem = C.Allocate(Size);
1374 return new (Mem) TypeTraitExpr(EmptyShell());
1375}
1376
David Blaikie99ba9e32011-12-20 02:48:34 +00001377void ArrayTypeTraitExpr::anchor() { }