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