Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 1 | //===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the subclesses of Expr class declared in ExprCXX.h |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 14 | #include "clang/Basic/IdentifierTable.h" |
| 15 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 17 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 18 | #include "clang/AST/TypeLoc.h" |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 19 | using namespace clang; |
| 20 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 21 | |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
| 23 | // Child Iterators for iterating over subexpressions/substatements |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 26 | QualType CXXTypeidExpr::getTypeOperand() const { |
| 27 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); |
| 28 | return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType() |
| 29 | .getUnqualifiedType(); |
| 30 | } |
| 31 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 32 | QualType CXXUuidofExpr::getTypeOperand() const { |
| 33 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); |
| 34 | return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType() |
| 35 | .getUnqualifiedType(); |
| 36 | } |
| 37 | |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 38 | // CXXScalarValueInitExpr |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 39 | SourceRange CXXScalarValueInitExpr::getSourceRange() const { |
| 40 | SourceLocation Start = RParenLoc; |
| 41 | if (TypeInfo) |
| 42 | Start = TypeInfo->getTypeLoc().getBeginLoc(); |
| 43 | return SourceRange(Start, RParenLoc); |
| 44 | } |
| 45 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 46 | // CXXNewExpr |
Ted Kremenek | ad7fe86 | 2010-02-11 22:51:03 +0000 | [diff] [blame] | 47 | CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, |
John McCall | 6ec278d | 2011-01-27 09:37:56 +0000 | [diff] [blame] | 48 | FunctionDecl *operatorDelete, |
Sebastian Redl | 5f688f4 | 2012-02-16 10:58:10 +0000 | [diff] [blame^] | 49 | bool usualArrayDeleteWantsSize, |
| 50 | Expr **placementArgs, unsigned numPlaceArgs, |
| 51 | SourceRange typeIdParens, Expr *arraySize, |
| 52 | InitializationStyle initializationStyle, |
| 53 | Expr *initializer, QualType ty, |
| 54 | TypeSourceInfo *allocatedTypeInfo, |
| 55 | SourceLocation startLoc, SourceRange directInitRange) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 56 | : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 57 | ty->isDependentType(), ty->isDependentType(), |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 58 | ty->isInstantiationDependentType(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 59 | ty->containsUnexpandedParameterPack()), |
Sebastian Redl | 5f688f4 | 2012-02-16 10:58:10 +0000 | [diff] [blame^] | 60 | GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize), |
| 61 | SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete), |
| 62 | AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens), |
| 63 | StartLoc(startLoc), DirectInitRange(directInitRange) { |
| 64 | assert((initializer != 0 || initializationStyle == NoInit) && |
| 65 | "Only NoInit can have no initializer."); |
| 66 | StoredInitializationStyle = initializer ? initializationStyle + 1 : 0; |
| 67 | AllocateArgsArray(C, arraySize != 0, numPlaceArgs, initializer != 0); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 68 | unsigned i = 0; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 69 | if (Array) { |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 70 | if (arraySize->isInstantiationDependent()) |
| 71 | ExprBits.InstantiationDependent = true; |
| 72 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 73 | if (arraySize->containsUnexpandedParameterPack()) |
| 74 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 75 | |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 76 | SubExprs[i++] = arraySize; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Sebastian Redl | 5f688f4 | 2012-02-16 10:58:10 +0000 | [diff] [blame^] | 79 | if (initializer) { |
| 80 | if (initializer->isInstantiationDependent()) |
| 81 | ExprBits.InstantiationDependent = true; |
| 82 | |
| 83 | if (initializer->containsUnexpandedParameterPack()) |
| 84 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 85 | |
| 86 | SubExprs[i++] = initializer; |
| 87 | } |
| 88 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 89 | for (unsigned j = 0; j < NumPlacementArgs; ++j) { |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 90 | if (placementArgs[j]->isInstantiationDependent()) |
| 91 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 92 | if (placementArgs[j]->containsUnexpandedParameterPack()) |
| 93 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 94 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 95 | SubExprs[i++] = placementArgs[j]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 96 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 99 | void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray, |
Sebastian Redl | 5f688f4 | 2012-02-16 10:58:10 +0000 | [diff] [blame^] | 100 | unsigned numPlaceArgs, bool hasInitializer){ |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 101 | assert(SubExprs == 0 && "SubExprs already allocated"); |
| 102 | Array = isArray; |
| 103 | NumPlacementArgs = numPlaceArgs; |
Sebastian Redl | 5f688f4 | 2012-02-16 10:58:10 +0000 | [diff] [blame^] | 104 | |
| 105 | unsigned TotalSize = Array + hasInitializer + NumPlacementArgs; |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 106 | SubExprs = new (C) Stmt*[TotalSize]; |
| 107 | } |
| 108 | |
Sebastian Redl | 8026f6d | 2011-03-13 17:09:40 +0000 | [diff] [blame] | 109 | bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const { |
John McCall | c2f3e7f | 2011-03-07 03:12:35 +0000 | [diff] [blame] | 110 | return getOperatorNew()->getType()-> |
Sebastian Redl | 8026f6d | 2011-03-13 17:09:40 +0000 | [diff] [blame] | 111 | castAs<FunctionProtoType>()->isNothrow(Ctx); |
John McCall | c2f3e7f | 2011-03-07 03:12:35 +0000 | [diff] [blame] | 112 | } |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 113 | |
Sebastian Redl | 5f688f4 | 2012-02-16 10:58:10 +0000 | [diff] [blame^] | 114 | SourceLocation CXXNewExpr::getEndLoc() const { |
| 115 | switch (getInitializationStyle()) { |
| 116 | case NoInit: |
| 117 | return AllocatedTypeInfo->getTypeLoc().getEndLoc(); |
| 118 | case CallInit: |
| 119 | return DirectInitRange.getEnd(); |
| 120 | case ListInit: |
| 121 | return getInitializer()->getSourceRange().getEnd(); |
| 122 | } |
| 123 | } |
| 124 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 125 | // CXXDeleteExpr |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 126 | QualType CXXDeleteExpr::getDestroyedType() const { |
| 127 | const Expr *Arg = getArgument(); |
| 128 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) { |
| 129 | if (ICE->getCastKind() != CK_UserDefinedConversion && |
| 130 | ICE->getType()->isVoidPointerType()) |
| 131 | Arg = ICE->getSubExpr(); |
| 132 | else |
| 133 | break; |
| 134 | } |
Craig Silverstein | 0fa0b78 | 2010-10-20 00:38:15 +0000 | [diff] [blame] | 135 | // The type-to-delete may not be a pointer if it's a dependent type. |
Craig Silverstein | c87fa06 | 2010-10-20 00:56:01 +0000 | [diff] [blame] | 136 | const QualType ArgType = Arg->getType(); |
Craig Silverstein | a437ad3 | 2010-11-16 07:16:25 +0000 | [diff] [blame] | 137 | |
| 138 | if (ArgType->isDependentType() && !ArgType->isPointerType()) |
| 139 | return QualType(); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 140 | |
Craig Silverstein | 0fa0b78 | 2010-10-20 00:38:15 +0000 | [diff] [blame] | 141 | return ArgType->getAs<PointerType>()->getPointeeType(); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 144 | // CXXPseudoDestructorExpr |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 145 | PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) |
| 146 | : Type(Info) |
| 147 | { |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 148 | Location = Info->getTypeLoc().getLocalSourceRange().getBegin(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 149 | } |
| 150 | |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 151 | CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 152 | Expr *Base, bool isArrow, SourceLocation OperatorLoc, |
| 153 | NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, |
| 154 | SourceLocation ColonColonLoc, SourceLocation TildeLoc, |
| 155 | PseudoDestructorTypeStorage DestroyedType) |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 156 | : Expr(CXXPseudoDestructorExprClass, |
| 157 | Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, |
| 158 | FunctionProtoType::ExtProtoInfo())), |
| 159 | VK_RValue, OK_Ordinary, |
| 160 | /*isTypeDependent=*/(Base->isTypeDependent() || |
| 161 | (DestroyedType.getTypeSourceInfo() && |
| 162 | DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 163 | /*isValueDependent=*/Base->isValueDependent(), |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 164 | (Base->isInstantiationDependent() || |
| 165 | (QualifierLoc && |
| 166 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) || |
| 167 | (ScopeType && |
| 168 | ScopeType->getType()->isInstantiationDependentType()) || |
| 169 | (DestroyedType.getTypeSourceInfo() && |
| 170 | DestroyedType.getTypeSourceInfo()->getType() |
| 171 | ->isInstantiationDependentType())), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 172 | // ContainsUnexpandedParameterPack |
| 173 | (Base->containsUnexpandedParameterPack() || |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 174 | (QualifierLoc && |
| 175 | QualifierLoc.getNestedNameSpecifier() |
| 176 | ->containsUnexpandedParameterPack()) || |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 177 | (ScopeType && |
| 178 | ScopeType->getType()->containsUnexpandedParameterPack()) || |
| 179 | (DestroyedType.getTypeSourceInfo() && |
| 180 | DestroyedType.getTypeSourceInfo()->getType() |
| 181 | ->containsUnexpandedParameterPack()))), |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 182 | Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 183 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 184 | ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), |
| 185 | DestroyedType(DestroyedType) { } |
| 186 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 187 | QualType CXXPseudoDestructorExpr::getDestroyedType() const { |
| 188 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
| 189 | return TInfo->getType(); |
| 190 | |
| 191 | return QualType(); |
| 192 | } |
| 193 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 194 | SourceRange CXXPseudoDestructorExpr::getSourceRange() const { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 195 | SourceLocation End = DestroyedType.getLocation(); |
| 196 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 197 | End = TInfo->getTypeLoc().getLocalSourceRange().getEnd(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 198 | return SourceRange(Base->getLocStart(), End); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 202 | // UnresolvedLookupExpr |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 203 | UnresolvedLookupExpr * |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 204 | UnresolvedLookupExpr::Create(ASTContext &C, |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 205 | CXXRecordDecl *NamingClass, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 206 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 207 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 208 | const DeclarationNameInfo &NameInfo, |
| 209 | bool ADL, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 210 | const TemplateArgumentListInfo *Args, |
| 211 | UnresolvedSetIterator Begin, |
| 212 | UnresolvedSetIterator End) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 213 | { |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 214 | assert(Args || TemplateKWLoc.isValid()); |
| 215 | unsigned num_args = Args ? Args->size() : 0; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 216 | void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) + |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 217 | ASTTemplateKWAndArgsInfo::sizeFor(num_args)); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 218 | return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, |
| 219 | TemplateKWLoc, NameInfo, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 220 | ADL, /*Overload*/ true, Args, |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 221 | Begin, End, /*StdIsAssociated=*/false); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 224 | UnresolvedLookupExpr * |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 225 | UnresolvedLookupExpr::CreateEmpty(ASTContext &C, |
| 226 | bool HasTemplateKWAndArgsInfo, |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 227 | unsigned NumTemplateArgs) { |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 228 | std::size_t size = sizeof(UnresolvedLookupExpr); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 229 | if (HasTemplateKWAndArgsInfo) |
| 230 | size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 231 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 232 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>()); |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 233 | UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 234 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 235 | return E; |
| 236 | } |
| 237 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 238 | OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 239 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 240 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 241 | const DeclarationNameInfo &NameInfo, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 242 | const TemplateArgumentListInfo *TemplateArgs, |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 243 | UnresolvedSetIterator Begin, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 244 | UnresolvedSetIterator End, |
| 245 | bool KnownDependent, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 246 | bool KnownInstantiationDependent, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 247 | bool KnownContainsUnexpandedParameterPack) |
| 248 | : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent, |
| 249 | KnownDependent, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 250 | (KnownInstantiationDependent || |
| 251 | NameInfo.isInstantiationDependent() || |
| 252 | (QualifierLoc && |
| 253 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 254 | (KnownContainsUnexpandedParameterPack || |
| 255 | NameInfo.containsUnexpandedParameterPack() || |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 256 | (QualifierLoc && |
| 257 | QualifierLoc.getNestedNameSpecifier() |
| 258 | ->containsUnexpandedParameterPack()))), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 259 | Results(0), NumResults(End - Begin), NameInfo(NameInfo), |
| 260 | QualifierLoc(QualifierLoc), |
| 261 | HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()) |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 262 | { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 263 | NumResults = End - Begin; |
| 264 | if (NumResults) { |
| 265 | // Determine whether this expression is type-dependent. |
| 266 | for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) { |
| 267 | if ((*I)->getDeclContext()->isDependentContext() || |
| 268 | isa<UnresolvedUsingValueDecl>(*I)) { |
| 269 | ExprBits.TypeDependent = true; |
| 270 | ExprBits.ValueDependent = true; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | Results = static_cast<DeclAccessPair *>( |
| 275 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 276 | llvm::alignOf<DeclAccessPair>())); |
| 277 | memcpy(Results, &*Begin.getIterator(), |
| 278 | NumResults * sizeof(DeclAccessPair)); |
| 279 | } |
| 280 | |
| 281 | // If we have explicit template arguments, check for dependent |
| 282 | // template arguments and whether they contain any unexpanded pack |
| 283 | // expansions. |
| 284 | if (TemplateArgs) { |
| 285 | bool Dependent = false; |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 286 | bool InstantiationDependent = false; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 287 | bool ContainsUnexpandedParameterPack = false; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 288 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, |
| 289 | Dependent, |
| 290 | InstantiationDependent, |
| 291 | ContainsUnexpandedParameterPack); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 292 | |
| 293 | if (Dependent) { |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 294 | ExprBits.TypeDependent = true; |
| 295 | ExprBits.ValueDependent = true; |
| 296 | } |
| 297 | if (InstantiationDependent) |
| 298 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 299 | if (ContainsUnexpandedParameterPack) |
| 300 | ExprBits.ContainsUnexpandedParameterPack = true; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 301 | } else if (TemplateKWLoc.isValid()) { |
| 302 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | if (isTypeDependent()) |
| 306 | setType(C.DependentTy); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void OverloadExpr::initializeResults(ASTContext &C, |
| 310 | UnresolvedSetIterator Begin, |
| 311 | UnresolvedSetIterator End) { |
| 312 | assert(Results == 0 && "Results already initialized!"); |
| 313 | NumResults = End - Begin; |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 314 | if (NumResults) { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 315 | Results = static_cast<DeclAccessPair *>( |
| 316 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 317 | |
| 318 | llvm::alignOf<DeclAccessPair>())); |
| 319 | memcpy(Results, &*Begin.getIterator(), |
| 320 | NumResults * sizeof(DeclAccessPair)); |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
John McCall | e9ee23e | 2010-04-22 18:44:12 +0000 | [diff] [blame] | 324 | CXXRecordDecl *OverloadExpr::getNamingClass() const { |
| 325 | if (isa<UnresolvedLookupExpr>(this)) |
| 326 | return cast<UnresolvedLookupExpr>(this)->getNamingClass(); |
| 327 | else |
| 328 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); |
| 329 | } |
| 330 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 331 | // DependentScopeDeclRefExpr |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 332 | DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T, |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 333 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 334 | SourceLocation TemplateKWLoc, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 335 | const DeclarationNameInfo &NameInfo, |
| 336 | const TemplateArgumentListInfo *Args) |
| 337 | : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary, |
| 338 | true, true, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 339 | (NameInfo.isInstantiationDependent() || |
| 340 | (QualifierLoc && |
| 341 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 342 | (NameInfo.containsUnexpandedParameterPack() || |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 343 | (QualifierLoc && |
| 344 | QualifierLoc.getNestedNameSpecifier() |
| 345 | ->containsUnexpandedParameterPack()))), |
| 346 | QualifierLoc(QualifierLoc), NameInfo(NameInfo), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 347 | HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid()) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 348 | { |
| 349 | if (Args) { |
| 350 | bool Dependent = true; |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 351 | bool InstantiationDependent = true; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 352 | bool ContainsUnexpandedParameterPack |
| 353 | = ExprBits.ContainsUnexpandedParameterPack; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 354 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args, |
| 355 | Dependent, |
| 356 | InstantiationDependent, |
| 357 | ContainsUnexpandedParameterPack); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 358 | ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 359 | } else if (TemplateKWLoc.isValid()) { |
| 360 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 364 | DependentScopeDeclRefExpr * |
| 365 | DependentScopeDeclRefExpr::Create(ASTContext &C, |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 366 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 367 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 368 | const DeclarationNameInfo &NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 369 | const TemplateArgumentListInfo *Args) { |
| 370 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 371 | if (Args) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 372 | size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size()); |
| 373 | else if (TemplateKWLoc.isValid()) |
| 374 | size += ASTTemplateKWAndArgsInfo::sizeFor(0); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 375 | void *Mem = C.Allocate(size); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 376 | return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc, |
| 377 | TemplateKWLoc, NameInfo, Args); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 380 | DependentScopeDeclRefExpr * |
| 381 | DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 382 | bool HasTemplateKWAndArgsInfo, |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 383 | unsigned NumTemplateArgs) { |
| 384 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 385 | if (HasTemplateKWAndArgsInfo) |
| 386 | size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 387 | void *Mem = C.Allocate(size); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 388 | DependentScopeDeclRefExpr *E |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 389 | = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 390 | SourceLocation(), |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 391 | DeclarationNameInfo(), 0); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 392 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 393 | return E; |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 396 | SourceRange CXXConstructExpr::getSourceRange() const { |
John McCall | 2882eca | 2011-02-21 06:23:05 +0000 | [diff] [blame] | 397 | if (isa<CXXTemporaryObjectExpr>(this)) |
| 398 | return cast<CXXTemporaryObjectExpr>(this)->getSourceRange(); |
| 399 | |
Douglas Gregor | 40749ee | 2010-11-03 00:35:38 +0000 | [diff] [blame] | 400 | if (ParenRange.isValid()) |
| 401 | return SourceRange(Loc, ParenRange.getEnd()); |
| 402 | |
| 403 | SourceLocation End = Loc; |
| 404 | for (unsigned I = getNumArgs(); I > 0; --I) { |
| 405 | const Expr *Arg = getArg(I-1); |
| 406 | if (!Arg->isDefaultArgument()) { |
| 407 | SourceLocation NewEnd = Arg->getLocEnd(); |
| 408 | if (NewEnd.isValid()) { |
| 409 | End = NewEnd; |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | return SourceRange(Loc, End); |
Ted Kremenek | e383768 | 2009-12-23 04:00:48 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 418 | SourceRange CXXOperatorCallExpr::getSourceRange() const { |
| 419 | OverloadedOperatorKind Kind = getOperator(); |
| 420 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 421 | if (getNumArgs() == 1) |
| 422 | // Prefix operator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | return SourceRange(getOperatorLoc(), |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 424 | getArg(0)->getSourceRange().getEnd()); |
| 425 | else |
| 426 | // Postfix operator |
Chandler Carruth | d765061 | 2011-04-02 09:47:38 +0000 | [diff] [blame] | 427 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 428 | getOperatorLoc()); |
Chandler Carruth | d765061 | 2011-04-02 09:47:38 +0000 | [diff] [blame] | 429 | } else if (Kind == OO_Arrow) { |
| 430 | return getArg(0)->getSourceRange(); |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 431 | } else if (Kind == OO_Call) { |
| 432 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 433 | } else if (Kind == OO_Subscript) { |
| 434 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 435 | } else if (getNumArgs() == 1) { |
| 436 | return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd()); |
| 437 | } else if (getNumArgs() == 2) { |
| 438 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
| 439 | getArg(1)->getSourceRange().getEnd()); |
| 440 | } else { |
| 441 | return SourceRange(); |
| 442 | } |
| 443 | } |
| 444 | |
Ted Kremenek | b277159 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 445 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { |
| 446 | if (const MemberExpr *MemExpr = |
| 447 | dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 448 | return MemExpr->getBase(); |
| 449 | |
| 450 | // FIXME: Will eventually need to cope with member pointers. |
| 451 | return 0; |
| 452 | } |
| 453 | |
Ted Kremenek | b277159 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 454 | CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { |
| 455 | if (const MemberExpr *MemExpr = |
| 456 | dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 457 | return cast<CXXMethodDecl>(MemExpr->getMemberDecl()); |
| 458 | |
| 459 | // FIXME: Will eventually need to cope with member pointers. |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | |
Chandler Carruth | 007a9b1 | 2010-10-27 06:55:41 +0000 | [diff] [blame] | 464 | CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() { |
| 465 | Expr* ThisArg = getImplicitObjectArgument(); |
| 466 | if (!ThisArg) |
| 467 | return 0; |
| 468 | |
| 469 | if (ThisArg->getType()->isAnyPointerType()) |
| 470 | return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl(); |
| 471 | |
| 472 | return ThisArg->getType()->getAsCXXRecordDecl(); |
| 473 | } |
| 474 | |
Douglas Gregor | 00b98c2 | 2009-11-12 15:31:47 +0000 | [diff] [blame] | 475 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 476 | //===----------------------------------------------------------------------===// |
| 477 | // Named casts |
| 478 | //===----------------------------------------------------------------------===// |
| 479 | |
| 480 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 481 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 482 | /// "const_cast". The returned pointer must not be freed. |
| 483 | const char *CXXNamedCastExpr::getCastName() const { |
| 484 | switch (getStmtClass()) { |
| 485 | case CXXStaticCastExprClass: return "static_cast"; |
| 486 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 487 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 488 | case CXXConstCastExprClass: return "const_cast"; |
| 489 | default: return "<invalid cast>"; |
| 490 | } |
| 491 | } |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 492 | |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 493 | CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 494 | ExprValueKind VK, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 495 | CastKind K, Expr *Op, |
| 496 | const CXXCastPath *BasePath, |
| 497 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 498 | SourceLocation L, |
| 499 | SourceLocation RParenLoc) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 500 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 501 | void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr) |
| 502 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 503 | CXXStaticCastExpr *E = |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 504 | new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 505 | RParenLoc); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 506 | if (PathSize) E->setCastPath(*BasePath); |
| 507 | return E; |
| 508 | } |
| 509 | |
| 510 | CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C, |
| 511 | unsigned PathSize) { |
| 512 | void *Buffer = |
| 513 | C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 514 | return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize); |
| 515 | } |
| 516 | |
| 517 | CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 518 | ExprValueKind VK, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 519 | CastKind K, Expr *Op, |
| 520 | const CXXCastPath *BasePath, |
| 521 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 522 | SourceLocation L, |
| 523 | SourceLocation RParenLoc) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 524 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 525 | void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr) |
| 526 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 527 | CXXDynamicCastExpr *E = |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 528 | new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 529 | RParenLoc); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 530 | if (PathSize) E->setCastPath(*BasePath); |
| 531 | return E; |
| 532 | } |
| 533 | |
| 534 | CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C, |
| 535 | unsigned PathSize) { |
| 536 | void *Buffer = |
| 537 | C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 538 | return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); |
| 539 | } |
| 540 | |
Anders Carlsson | 0fee330 | 2011-04-11 01:43:55 +0000 | [diff] [blame] | 541 | /// isAlwaysNull - Return whether the result of the dynamic_cast is proven |
| 542 | /// to always be null. For example: |
| 543 | /// |
| 544 | /// struct A { }; |
| 545 | /// struct B final : A { }; |
| 546 | /// struct C { }; |
| 547 | /// |
| 548 | /// C *f(B* b) { return dynamic_cast<C*>(b); } |
| 549 | bool CXXDynamicCastExpr::isAlwaysNull() const |
| 550 | { |
| 551 | QualType SrcType = getSubExpr()->getType(); |
| 552 | QualType DestType = getType(); |
| 553 | |
| 554 | if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) { |
| 555 | SrcType = SrcPTy->getPointeeType(); |
| 556 | DestType = DestType->castAs<PointerType>()->getPointeeType(); |
| 557 | } |
| 558 | |
| 559 | const CXXRecordDecl *SrcRD = |
| 560 | cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl()); |
| 561 | |
| 562 | if (!SrcRD->hasAttr<FinalAttr>()) |
| 563 | return false; |
| 564 | |
| 565 | const CXXRecordDecl *DestRD = |
| 566 | cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl()); |
| 567 | |
| 568 | return !DestRD->isDerivedFrom(SrcRD); |
| 569 | } |
| 570 | |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 571 | CXXReinterpretCastExpr * |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 572 | CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK, |
| 573 | CastKind K, Expr *Op, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 574 | const CXXCastPath *BasePath, |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 575 | TypeSourceInfo *WrittenTy, SourceLocation L, |
| 576 | SourceLocation RParenLoc) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 577 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 578 | void *Buffer = |
| 579 | C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 580 | CXXReinterpretCastExpr *E = |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 581 | new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 582 | RParenLoc); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 583 | if (PathSize) E->setCastPath(*BasePath); |
| 584 | return E; |
| 585 | } |
| 586 | |
| 587 | CXXReinterpretCastExpr * |
| 588 | CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 589 | void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr) |
| 590 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 591 | return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); |
| 592 | } |
| 593 | |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 594 | CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T, |
| 595 | ExprValueKind VK, Expr *Op, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 596 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 597 | SourceLocation L, |
| 598 | SourceLocation RParenLoc) { |
| 599 | return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) { |
| 603 | return new (C) CXXConstCastExpr(EmptyShell()); |
| 604 | } |
| 605 | |
| 606 | CXXFunctionalCastExpr * |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 607 | CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 608 | TypeSourceInfo *Written, SourceLocation L, |
| 609 | CastKind K, Expr *Op, const CXXCastPath *BasePath, |
| 610 | SourceLocation R) { |
| 611 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 612 | void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) |
| 613 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 614 | CXXFunctionalCastExpr *E = |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 615 | new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 616 | if (PathSize) E->setCastPath(*BasePath); |
| 617 | return E; |
| 618 | } |
| 619 | |
| 620 | CXXFunctionalCastExpr * |
| 621 | CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 622 | void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) |
| 623 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 624 | return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize); |
| 625 | } |
| 626 | |
| 627 | |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 628 | CXXDefaultArgExpr * |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 629 | CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc, |
| 630 | ParmVarDecl *Param, Expr *SubExpr) { |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 631 | void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *)); |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 632 | return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, |
| 633 | SubExpr); |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | CXXTemporary *CXXTemporary::Create(ASTContext &C, |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 637 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 638 | return new (C) CXXTemporary(Destructor); |
| 639 | } |
| 640 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 642 | CXXTemporary *Temp, |
| 643 | Expr* SubExpr) { |
Peter Collingbourne | bceb755 | 2011-11-27 22:09:28 +0000 | [diff] [blame] | 644 | assert((SubExpr->getType()->isRecordType() || |
| 645 | SubExpr->getType()->isArrayType()) && |
| 646 | "Expression bound to a temporary must have record or array type!"); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 647 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 648 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 651 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 26de549 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 652 | CXXConstructorDecl *Cons, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 653 | TypeSourceInfo *Type, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 654 | Expr **Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | unsigned NumArgs, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 656 | SourceRange parenRange, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 657 | bool HadMultipleCandidates, |
Douglas Gregor | 1c63b9c | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 658 | bool ZeroInitialization) |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 659 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, |
| 660 | Type->getType().getNonReferenceType(), |
| 661 | Type->getTypeLoc().getBeginLoc(), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 662 | Cons, false, Args, NumArgs, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 663 | HadMultipleCandidates, /*FIXME*/false, ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 664 | CXXConstructExpr::CK_Complete, parenRange), |
| 665 | Type(Type) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | SourceRange CXXTemporaryObjectExpr::getSourceRange() const { |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 669 | return SourceRange(Type->getTypeLoc().getBeginLoc(), |
| 670 | getParenRange().getEnd()); |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 671 | } |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 672 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 673 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 674 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 675 | CXXConstructorDecl *D, bool Elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 676 | Expr **Args, unsigned NumArgs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 677 | bool HadMultipleCandidates, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 678 | bool ListInitialization, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 679 | bool ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 680 | ConstructionKind ConstructKind, |
| 681 | SourceRange ParenRange) { |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 682 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 683 | Elidable, Args, NumArgs, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 684 | HadMultipleCandidates, ListInitialization, |
| 685 | ZeroInitialization, ConstructKind, |
| 686 | ParenRange); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 690 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 691 | CXXConstructorDecl *D, bool elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 692 | Expr **args, unsigned numargs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 693 | bool HadMultipleCandidates, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 694 | bool ListInitialization, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 695 | bool ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 696 | ConstructionKind ConstructKind, |
| 697 | SourceRange ParenRange) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 698 | : Expr(SC, T, VK_RValue, OK_Ordinary, |
| 699 | T->isDependentType(), T->isDependentType(), |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 700 | T->isInstantiationDependentType(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 701 | T->containsUnexpandedParameterPack()), |
Douglas Gregor | a48e676 | 2011-09-26 14:47:03 +0000 | [diff] [blame] | 702 | Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(numargs), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 703 | Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates), |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 704 | ListInitialization(ListInitialization), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 705 | ZeroInitialization(ZeroInitialization), |
Douglas Gregor | a48e676 | 2011-09-26 14:47:03 +0000 | [diff] [blame] | 706 | ConstructKind(ConstructKind), Args(0) |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 707 | { |
| 708 | if (NumArgs) { |
| 709 | Args = new (C) Stmt*[NumArgs]; |
| 710 | |
| 711 | for (unsigned i = 0; i != NumArgs; ++i) { |
| 712 | assert(args[i] && "NULL argument in CXXConstructExpr"); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 713 | |
| 714 | if (args[i]->isValueDependent()) |
| 715 | ExprBits.ValueDependent = true; |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 716 | if (args[i]->isInstantiationDependent()) |
| 717 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 718 | if (args[i]->containsUnexpandedParameterPack()) |
| 719 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 720 | |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 721 | Args[i] = args[i]; |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 722 | } |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 723 | } |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 726 | LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit, |
| 727 | LambdaCaptureKind Kind, VarDecl *Var, |
| 728 | SourceLocation EllipsisLoc) |
| 729 | : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) |
| 730 | { |
| 731 | unsigned Bits = 0; |
| 732 | if (Implicit) |
| 733 | Bits |= Capture_Implicit; |
| 734 | |
| 735 | switch (Kind) { |
| 736 | case LCK_This: |
| 737 | assert(Var == 0 && "'this' capture cannot have a variable!"); |
| 738 | break; |
| 739 | |
| 740 | case LCK_ByCopy: |
| 741 | Bits |= Capture_ByCopy; |
| 742 | // Fall through |
| 743 | case LCK_ByRef: |
| 744 | assert(Var && "capture must have a variable!"); |
| 745 | break; |
| 746 | } |
| 747 | VarAndBits.setInt(Bits); |
| 748 | } |
| 749 | |
| 750 | LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const { |
| 751 | if (capturesThis()) |
| 752 | return LCK_This; |
| 753 | |
| 754 | return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef; |
| 755 | } |
| 756 | |
| 757 | LambdaExpr::LambdaExpr(QualType T, |
| 758 | SourceRange IntroducerRange, |
| 759 | LambdaCaptureDefault CaptureDefault, |
| 760 | ArrayRef<Capture> Captures, |
| 761 | bool ExplicitParams, |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 762 | bool ExplicitResultType, |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 763 | ArrayRef<Expr *> CaptureInits, |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 764 | ArrayRef<VarDecl *> ArrayIndexVars, |
| 765 | ArrayRef<unsigned> ArrayIndexStarts, |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 766 | SourceLocation ClosingBrace) |
| 767 | : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, |
| 768 | T->isDependentType(), T->isDependentType(), T->isDependentType(), |
| 769 | /*ContainsUnexpandedParameterPack=*/false), |
| 770 | IntroducerRange(IntroducerRange), |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 771 | NumCaptures(Captures.size()), |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 772 | CaptureDefault(CaptureDefault), |
| 773 | ExplicitParams(ExplicitParams), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 774 | ExplicitResultType(ExplicitResultType), |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 775 | ClosingBrace(ClosingBrace) |
| 776 | { |
| 777 | assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments"); |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 778 | CXXRecordDecl *Class = getLambdaClass(); |
| 779 | CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData(); |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 780 | |
| 781 | // FIXME: Propagate "has unexpanded parameter pack" bit. |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 782 | |
| 783 | // Copy captures. |
| 784 | ASTContext &Context = Class->getASTContext(); |
| 785 | Data.NumCaptures = NumCaptures; |
| 786 | Data.NumExplicitCaptures = 0; |
| 787 | Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures); |
| 788 | Capture *ToCapture = Data.Captures; |
| 789 | for (unsigned I = 0, N = Captures.size(); I != N; ++I) { |
| 790 | if (Captures[I].isExplicit()) |
| 791 | ++Data.NumExplicitCaptures; |
| 792 | |
| 793 | *ToCapture++ = Captures[I]; |
| 794 | } |
| 795 | |
| 796 | // Copy initialization expressions for the non-static data members. |
| 797 | Stmt **Stored = getStoredStmts(); |
| 798 | for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I) |
| 799 | *Stored++ = CaptureInits[I]; |
| 800 | |
| 801 | // Copy the body of the lambda. |
| 802 | *Stored++ = getCallOperator()->getBody(); |
| 803 | |
| 804 | // Copy the array index variables, if any. |
| 805 | HasArrayIndexVars = !ArrayIndexVars.empty(); |
| 806 | if (HasArrayIndexVars) { |
| 807 | assert(ArrayIndexStarts.size() == NumCaptures); |
| 808 | memcpy(getArrayIndexVars(), ArrayIndexVars.data(), |
| 809 | sizeof(VarDecl *) * ArrayIndexVars.size()); |
| 810 | memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(), |
| 811 | sizeof(unsigned) * Captures.size()); |
| 812 | getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size(); |
| 813 | } |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | LambdaExpr *LambdaExpr::Create(ASTContext &Context, |
| 817 | CXXRecordDecl *Class, |
| 818 | SourceRange IntroducerRange, |
| 819 | LambdaCaptureDefault CaptureDefault, |
| 820 | ArrayRef<Capture> Captures, |
| 821 | bool ExplicitParams, |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 822 | bool ExplicitResultType, |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 823 | ArrayRef<Expr *> CaptureInits, |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 824 | ArrayRef<VarDecl *> ArrayIndexVars, |
| 825 | ArrayRef<unsigned> ArrayIndexStarts, |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 826 | SourceLocation ClosingBrace) { |
| 827 | // Determine the type of the expression (i.e., the type of the |
| 828 | // function object we're creating). |
| 829 | QualType T = Context.getTypeDeclType(Class); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 830 | |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 831 | unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1); |
| 832 | if (!ArrayIndexVars.empty()) |
| 833 | Size += sizeof(VarDecl *) * ArrayIndexVars.size() |
| 834 | + sizeof(unsigned) * (Captures.size() + 1); |
| 835 | void *Mem = Context.Allocate(Size); |
| 836 | return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault, |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 837 | Captures, ExplicitParams, ExplicitResultType, |
| 838 | CaptureInits, ArrayIndexVars, ArrayIndexStarts, |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 839 | ClosingBrace); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 842 | LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures, |
| 843 | unsigned NumArrayIndexVars) { |
| 844 | unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1); |
| 845 | if (NumArrayIndexVars) |
| 846 | Size += sizeof(VarDecl) * NumArrayIndexVars |
| 847 | + sizeof(unsigned) * (NumCaptures + 1); |
| 848 | void *Mem = C.Allocate(Size); |
| 849 | return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0); |
| 850 | } |
| 851 | |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 852 | LambdaExpr::capture_iterator LambdaExpr::capture_begin() const { |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 853 | return getLambdaClass()->getLambdaData().Captures; |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | LambdaExpr::capture_iterator LambdaExpr::capture_end() const { |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 857 | return capture_begin() + NumCaptures; |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const { |
| 861 | return capture_begin(); |
| 862 | } |
| 863 | |
| 864 | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const { |
| 865 | struct CXXRecordDecl::LambdaDefinitionData &Data |
| 866 | = getLambdaClass()->getLambdaData(); |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 867 | return Data.Captures + Data.NumExplicitCaptures; |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const { |
| 871 | return explicit_capture_end(); |
| 872 | } |
| 873 | |
| 874 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const { |
| 875 | return capture_end(); |
| 876 | } |
| 877 | |
Douglas Gregor | 9daa7bf | 2012-02-13 16:35:30 +0000 | [diff] [blame] | 878 | ArrayRef<VarDecl *> |
| 879 | LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const { |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 880 | assert(HasArrayIndexVars && "No array index-var data?"); |
Douglas Gregor | 9daa7bf | 2012-02-13 16:35:30 +0000 | [diff] [blame] | 881 | |
| 882 | unsigned Index = Iter - capture_init_begin(); |
Matt Beaumont-Gay | 43a1b00 | 2012-02-13 19:29:45 +0000 | [diff] [blame] | 883 | assert(Index < getLambdaClass()->getLambdaData().NumCaptures && |
| 884 | "Capture index out-of-range"); |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 885 | VarDecl **IndexVars = getArrayIndexVars(); |
| 886 | unsigned *IndexStarts = getArrayIndexStarts(); |
Douglas Gregor | 9daa7bf | 2012-02-13 16:35:30 +0000 | [diff] [blame] | 887 | return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index], |
| 888 | IndexVars + IndexStarts[Index + 1]); |
| 889 | } |
| 890 | |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 891 | CXXRecordDecl *LambdaExpr::getLambdaClass() const { |
| 892 | return getType()->getAsCXXRecordDecl(); |
| 893 | } |
| 894 | |
| 895 | CXXMethodDecl *LambdaExpr::getCallOperator() const { |
| 896 | CXXRecordDecl *Record = getLambdaClass(); |
| 897 | DeclarationName Name |
| 898 | = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call); |
| 899 | DeclContext::lookup_result Calls = Record->lookup(Name); |
| 900 | assert(Calls.first != Calls.second && "Missing lambda call operator!"); |
| 901 | CXXMethodDecl *Result = cast<CXXMethodDecl>(*Calls.first++); |
| 902 | assert(Calls.first == Calls.second && "More than lambda one call operator?"); |
| 903 | return Result; |
| 904 | } |
| 905 | |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 906 | CompoundStmt *LambdaExpr::getBody() const { |
| 907 | if (!getStoredStmts()[NumCaptures]) |
| 908 | getStoredStmts()[NumCaptures] = getCallOperator()->getBody(); |
| 909 | |
| 910 | return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]); |
| 911 | } |
| 912 | |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 913 | bool LambdaExpr::isMutable() const { |
| 914 | return (getCallOperator()->getTypeQualifiers() & Qualifiers::Const) == 0; |
| 915 | } |
| 916 | |
John McCall | 80ee6e8 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 917 | ExprWithCleanups::ExprWithCleanups(Expr *subexpr, |
| 918 | ArrayRef<CleanupObject> objects) |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 919 | : Expr(ExprWithCleanupsClass, subexpr->getType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 920 | subexpr->getValueKind(), subexpr->getObjectKind(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 921 | subexpr->isTypeDependent(), subexpr->isValueDependent(), |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 922 | subexpr->isInstantiationDependent(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 923 | subexpr->containsUnexpandedParameterPack()), |
John McCall | 80ee6e8 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 924 | SubExpr(subexpr) { |
| 925 | ExprWithCleanupsBits.NumObjects = objects.size(); |
| 926 | for (unsigned i = 0, e = objects.size(); i != e; ++i) |
| 927 | getObjectsBuffer()[i] = objects[i]; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 928 | } |
| 929 | |
John McCall | 80ee6e8 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 930 | ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr, |
| 931 | ArrayRef<CleanupObject> objects) { |
| 932 | size_t size = sizeof(ExprWithCleanups) |
| 933 | + objects.size() * sizeof(CleanupObject); |
| 934 | void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>()); |
| 935 | return new (buffer) ExprWithCleanups(subexpr, objects); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 936 | } |
| 937 | |
John McCall | 80ee6e8 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 938 | ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects) |
| 939 | : Expr(ExprWithCleanupsClass, empty) { |
| 940 | ExprWithCleanupsBits.NumObjects = numObjects; |
| 941 | } |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 942 | |
John McCall | 80ee6e8 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 943 | ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty, |
| 944 | unsigned numObjects) { |
| 945 | size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject); |
| 946 | void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>()); |
| 947 | return new (buffer) ExprWithCleanups(empty, numObjects); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 950 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 951 | SourceLocation LParenLoc, |
| 952 | Expr **Args, |
| 953 | unsigned NumArgs, |
| 954 | SourceLocation RParenLoc) |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 955 | : Expr(CXXUnresolvedConstructExprClass, |
| 956 | Type->getType().getNonReferenceType(), |
Douglas Gregor | 032c869 | 2011-07-08 15:50:43 +0000 | [diff] [blame] | 957 | (Type->getType()->isLValueReferenceType() ? VK_LValue |
| 958 | :Type->getType()->isRValueReferenceType()? VK_XValue |
| 959 | :VK_RValue), |
| 960 | OK_Ordinary, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 961 | Type->getType()->isDependentType(), true, true, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 962 | Type->getType()->containsUnexpandedParameterPack()), |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 963 | Type(Type), |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 964 | LParenLoc(LParenLoc), |
| 965 | RParenLoc(RParenLoc), |
| 966 | NumArgs(NumArgs) { |
| 967 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 968 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 969 | if (Args[I]->containsUnexpandedParameterPack()) |
| 970 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 971 | |
| 972 | StoredArgs[I] = Args[I]; |
| 973 | } |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | CXXUnresolvedConstructExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 978 | TypeSourceInfo *Type, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 979 | SourceLocation LParenLoc, |
| 980 | Expr **Args, |
| 981 | unsigned NumArgs, |
| 982 | SourceLocation RParenLoc) { |
| 983 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 984 | sizeof(Expr *) * NumArgs); |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 985 | return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 986 | Args, NumArgs, RParenLoc); |
| 987 | } |
| 988 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 989 | CXXUnresolvedConstructExpr * |
| 990 | CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) { |
| 991 | Stmt::EmptyShell Empty; |
| 992 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 993 | sizeof(Expr *) * NumArgs); |
| 994 | return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); |
| 995 | } |
| 996 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 997 | SourceRange CXXUnresolvedConstructExpr::getSourceRange() const { |
| 998 | return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc); |
| 999 | } |
| 1000 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1001 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1002 | Expr *Base, QualType BaseType, |
| 1003 | bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1004 | SourceLocation OperatorLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1005 | NestedNameSpecifierLoc QualifierLoc, |
| 1006 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1007 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1008 | DeclarationNameInfo MemberNameInfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1009 | const TemplateArgumentListInfo *TemplateArgs) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1010 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1011 | VK_LValue, OK_Ordinary, true, true, true, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1012 | ((Base && Base->containsUnexpandedParameterPack()) || |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1013 | (QualifierLoc && |
| 1014 | QualifierLoc.getNestedNameSpecifier() |
| 1015 | ->containsUnexpandedParameterPack()) || |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1016 | MemberNameInfo.containsUnexpandedParameterPack())), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1017 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1018 | HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1019 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1020 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1021 | MemberNameInfo(MemberNameInfo) { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1022 | if (TemplateArgs) { |
| 1023 | bool Dependent = true; |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1024 | bool InstantiationDependent = true; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1025 | bool ContainsUnexpandedParameterPack = false; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1026 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, |
| 1027 | Dependent, |
| 1028 | InstantiationDependent, |
| 1029 | ContainsUnexpandedParameterPack); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1030 | if (ContainsUnexpandedParameterPack) |
| 1031 | ExprBits.ContainsUnexpandedParameterPack = true; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1032 | } else if (TemplateKWLoc.isValid()) { |
| 1033 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1034 | } |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1037 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
| 1038 | Expr *Base, QualType BaseType, |
| 1039 | bool IsArrow, |
| 1040 | SourceLocation OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1041 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1042 | NamedDecl *FirstQualifierFoundInScope, |
| 1043 | DeclarationNameInfo MemberNameInfo) |
| 1044 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1045 | VK_LValue, OK_Ordinary, true, true, true, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1046 | ((Base && Base->containsUnexpandedParameterPack()) || |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1047 | (QualifierLoc && |
| 1048 | QualifierLoc.getNestedNameSpecifier()-> |
| 1049 | containsUnexpandedParameterPack()) || |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1050 | MemberNameInfo.containsUnexpandedParameterPack())), |
| 1051 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1052 | HasTemplateKWAndArgsInfo(false), |
| 1053 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1054 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
| 1055 | MemberNameInfo(MemberNameInfo) { } |
| 1056 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1057 | CXXDependentScopeMemberExpr * |
| 1058 | CXXDependentScopeMemberExpr::Create(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1059 | Expr *Base, QualType BaseType, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1060 | SourceLocation OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1061 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1062 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1063 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1064 | DeclarationNameInfo MemberNameInfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1065 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1066 | if (!TemplateArgs && !TemplateKWLoc.isValid()) |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1067 | return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 1068 | IsArrow, OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1069 | QualifierLoc, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1070 | FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1071 | MemberNameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1073 | unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0; |
| 1074 | std::size_t size = sizeof(CXXDependentScopeMemberExpr) |
| 1075 | + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1076 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 1077 | void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1078 | return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 1079 | IsArrow, OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1080 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1081 | TemplateKWLoc, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1082 | FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1083 | MemberNameInfo, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1086 | CXXDependentScopeMemberExpr * |
| 1087 | CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1088 | bool HasTemplateKWAndArgsInfo, |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1089 | unsigned NumTemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1090 | if (!HasTemplateKWAndArgsInfo) |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1091 | return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1092 | 0, SourceLocation(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1093 | NestedNameSpecifierLoc(), 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1094 | DeclarationNameInfo()); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1095 | |
| 1096 | std::size_t size = sizeof(CXXDependentScopeMemberExpr) + |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1097 | ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 1098 | void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1099 | CXXDependentScopeMemberExpr *E |
| 1100 | = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1101 | 0, SourceLocation(), |
| 1102 | NestedNameSpecifierLoc(), |
| 1103 | SourceLocation(), 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1104 | DeclarationNameInfo(), 0); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1105 | E->HasTemplateKWAndArgsInfo = true; |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1106 | return E; |
| 1107 | } |
| 1108 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1109 | bool CXXDependentScopeMemberExpr::isImplicitAccess() const { |
| 1110 | if (Base == 0) |
| 1111 | return true; |
| 1112 | |
Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 1113 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1116 | static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, |
| 1117 | UnresolvedSetIterator end) { |
| 1118 | do { |
| 1119 | NamedDecl *decl = *begin; |
| 1120 | if (isa<UnresolvedUsingValueDecl>(decl)) |
| 1121 | return false; |
| 1122 | if (isa<UsingShadowDecl>(decl)) |
| 1123 | decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl(); |
| 1124 | |
| 1125 | // Unresolved member expressions should only contain methods and |
| 1126 | // method templates. |
| 1127 | assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl)); |
| 1128 | |
| 1129 | if (isa<FunctionTemplateDecl>(decl)) |
| 1130 | decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl(); |
| 1131 | if (cast<CXXMethodDecl>(decl)->isStatic()) |
| 1132 | return false; |
| 1133 | } while (++begin != end); |
| 1134 | |
| 1135 | return true; |
| 1136 | } |
| 1137 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1138 | UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1139 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1140 | Expr *Base, QualType BaseType, |
| 1141 | bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1142 | SourceLocation OperatorLoc, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1143 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1144 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1145 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 1146 | const TemplateArgumentListInfo *TemplateArgs, |
| 1147 | UnresolvedSetIterator Begin, |
| 1148 | UnresolvedSetIterator End) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1149 | : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc, |
| 1150 | MemberNameInfo, TemplateArgs, Begin, End, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1151 | // Dependent |
| 1152 | ((Base && Base->isTypeDependent()) || |
| 1153 | BaseType->isDependentType()), |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1154 | ((Base && Base->isInstantiationDependent()) || |
| 1155 | BaseType->isInstantiationDependentType()), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1156 | // Contains unexpanded parameter pack |
| 1157 | ((Base && Base->containsUnexpandedParameterPack()) || |
| 1158 | BaseType->containsUnexpandedParameterPack())), |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 1159 | IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
| 1160 | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1161 | |
| 1162 | // Check whether all of the members are non-static member functions, |
| 1163 | // and if so, mark give this bound-member type instead of overload type. |
| 1164 | if (hasOnlyNonStaticMemberFunctions(Begin, End)) |
| 1165 | setType(C.BoundMemberTy); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1168 | bool UnresolvedMemberExpr::isImplicitAccess() const { |
| 1169 | if (Base == 0) |
| 1170 | return true; |
| 1171 | |
Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 1172 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1175 | UnresolvedMemberExpr * |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1176 | UnresolvedMemberExpr::Create(ASTContext &C, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1177 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1178 | Expr *Base, QualType BaseType, bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1179 | SourceLocation OperatorLoc, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1180 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1181 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1182 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 1183 | const TemplateArgumentListInfo *TemplateArgs, |
| 1184 | UnresolvedSetIterator Begin, |
| 1185 | UnresolvedSetIterator End) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1186 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 1187 | if (TemplateArgs) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1188 | size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size()); |
| 1189 | else if (TemplateKWLoc.isValid()) |
| 1190 | size += ASTTemplateKWAndArgsInfo::sizeFor(0); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1191 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 1192 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 1193 | return new (Mem) UnresolvedMemberExpr(C, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1194 | HasUnresolvedUsing, Base, BaseType, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1195 | IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1196 | MemberNameInfo, TemplateArgs, Begin, End); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1199 | UnresolvedMemberExpr * |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1200 | UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 1201 | unsigned NumTemplateArgs) { |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1202 | std::size_t size = sizeof(UnresolvedMemberExpr); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1203 | if (HasTemplateKWAndArgsInfo) |
| 1204 | size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1205 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 1206 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1207 | UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1208 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1209 | return E; |
| 1210 | } |
| 1211 | |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1212 | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { |
| 1213 | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
| 1214 | |
| 1215 | // If there was a nested name specifier, it names the naming class. |
| 1216 | // It can't be dependent: after all, we were actually able to do the |
| 1217 | // lookup. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1218 | CXXRecordDecl *Record = 0; |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 1219 | if (getQualifier()) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1220 | const Type *T = getQualifier()->getAsType(); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1221 | assert(T && "qualifier in member expression does not name type"); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1222 | Record = T->getAsCXXRecordDecl(); |
| 1223 | assert(Record && "qualifier in member expression does not name record"); |
| 1224 | } |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1225 | // Otherwise the naming class must have been the base class. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1226 | else { |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1227 | QualType BaseType = getBaseType().getNonReferenceType(); |
| 1228 | if (isArrow()) { |
| 1229 | const PointerType *PT = BaseType->getAs<PointerType>(); |
| 1230 | assert(PT && "base of arrow member access is not pointer"); |
| 1231 | BaseType = PT->getPointeeType(); |
| 1232 | } |
| 1233 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1234 | Record = BaseType->getAsCXXRecordDecl(); |
| 1235 | assert(Record && "base of member expression does not name record"); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1238 | return Record; |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1241 | SubstNonTypeTemplateParmPackExpr:: |
| 1242 | SubstNonTypeTemplateParmPackExpr(QualType T, |
| 1243 | NonTypeTemplateParmDecl *Param, |
| 1244 | SourceLocation NameLoc, |
| 1245 | const TemplateArgument &ArgPack) |
| 1246 | : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1247 | true, true, true, true), |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1248 | Param(Param), Arguments(ArgPack.pack_begin()), |
| 1249 | NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { } |
| 1250 | |
| 1251 | TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { |
| 1252 | return TemplateArgument(Arguments, NumArguments); |
| 1253 | } |
| 1254 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1255 | void ArrayTypeTraitExpr::anchor() { } |