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