Ted Kremenek | e3a0c14 | 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 | 5b12ab8 | 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 | e3a0c14 | 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 | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 14 | #include "clang/Basic/IdentifierTable.h" |
Benjamin Kramer | 4ab984e | 2012-07-04 20:19:54 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | a727cb9 | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | e3a0c14 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 18 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 19 | #include "clang/AST/TypeLoc.h" |
Ted Kremenek | e3a0c14 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 22 | |
Ted Kremenek | e3a0c14 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 23 | //===----------------------------------------------------------------------===// |
| 24 | // Child Iterators for iterating over subexpressions/substatements |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
Richard Smith | ef8bf43 | 2012-08-13 20:08:14 +0000 | [diff] [blame] | 27 | bool CXXTypeidExpr::isPotentiallyEvaluated() const { |
| 28 | if (isTypeOperand()) |
| 29 | return false; |
| 30 | |
| 31 | // C++11 [expr.typeid]p3: |
| 32 | // When typeid is applied to an expression other than a glvalue of |
| 33 | // polymorphic class type, [...] the expression is an unevaluated operand. |
| 34 | const Expr *E = getExprOperand(); |
| 35 | if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl()) |
| 36 | if (RD->isPolymorphic() && E->isGLValue()) |
| 37 | return true; |
| 38 | |
| 39 | return false; |
| 40 | } |
| 41 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 42 | QualType CXXTypeidExpr::getTypeOperand() const { |
| 43 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); |
| 44 | return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType() |
| 45 | .getUnqualifiedType(); |
| 46 | } |
| 47 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 48 | QualType CXXUuidofExpr::getTypeOperand() const { |
| 49 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); |
| 50 | return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType() |
| 51 | .getUnqualifiedType(); |
| 52 | } |
| 53 | |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 54 | // static |
| 55 | UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT) { |
| 56 | // Optionally remove one level of pointer, reference or array indirection. |
| 57 | const Type *Ty = QT.getTypePtr(); |
| 58 | if (QT->isPointerType() || QT->isReferenceType()) |
| 59 | Ty = QT->getPointeeType().getTypePtr(); |
| 60 | else if (QT->isArrayType()) |
| 61 | Ty = cast<ArrayType>(QT)->getElementType().getTypePtr(); |
| 62 | |
| 63 | // Loop all record redeclaration looking for an uuid attribute. |
| 64 | CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); |
| 65 | for (CXXRecordDecl::redecl_iterator I = RD->redecls_begin(), |
| 66 | E = RD->redecls_end(); I != E; ++I) { |
| 67 | if (UuidAttr *Uuid = I->getAttr<UuidAttr>()) |
| 68 | return Uuid; |
| 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 74 | // CXXScalarValueInitExpr |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 75 | SourceRange CXXScalarValueInitExpr::getSourceRange() const { |
| 76 | SourceLocation Start = RParenLoc; |
| 77 | if (TypeInfo) |
| 78 | Start = TypeInfo->getTypeLoc().getBeginLoc(); |
| 79 | return SourceRange(Start, RParenLoc); |
| 80 | } |
| 81 | |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 82 | // CXXNewExpr |
Ted Kremenek | 9d6eb40 | 2010-02-11 22:51:03 +0000 | [diff] [blame] | 83 | CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, |
Sebastian Redl | c3a3c60 | 2012-02-16 11:35:52 +0000 | [diff] [blame] | 84 | FunctionDecl *operatorDelete, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 85 | bool usualArrayDeleteWantsSize, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 86 | ArrayRef<Expr*> placementArgs, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 87 | SourceRange typeIdParens, Expr *arraySize, |
| 88 | InitializationStyle initializationStyle, |
| 89 | Expr *initializer, QualType ty, |
| 90 | TypeSourceInfo *allocatedTypeInfo, |
| 91 | SourceLocation startLoc, SourceRange directInitRange) |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 92 | : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 93 | ty->isDependentType(), ty->isDependentType(), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 94 | ty->isInstantiationDependentType(), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 95 | ty->containsUnexpandedParameterPack()), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 96 | SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete), |
| 97 | AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens), |
Benjamin Kramer | b73f76b | 2012-02-26 20:37:14 +0000 | [diff] [blame] | 98 | StartLoc(startLoc), DirectInitRange(directInitRange), |
| 99 | GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 100 | assert((initializer != 0 || initializationStyle == NoInit) && |
| 101 | "Only NoInit can have no initializer."); |
| 102 | StoredInitializationStyle = initializer ? initializationStyle + 1 : 0; |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 103 | AllocateArgsArray(C, arraySize != 0, placementArgs.size(), initializer != 0); |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 104 | unsigned i = 0; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 105 | if (Array) { |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 106 | if (arraySize->isInstantiationDependent()) |
| 107 | ExprBits.InstantiationDependent = true; |
| 108 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 109 | if (arraySize->containsUnexpandedParameterPack()) |
| 110 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 111 | |
Sebastian Redl | 351bb78 | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 112 | SubExprs[i++] = arraySize; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 115 | if (initializer) { |
| 116 | if (initializer->isInstantiationDependent()) |
| 117 | ExprBits.InstantiationDependent = true; |
| 118 | |
| 119 | if (initializer->containsUnexpandedParameterPack()) |
| 120 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 121 | |
| 122 | SubExprs[i++] = initializer; |
| 123 | } |
| 124 | |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 125 | for (unsigned j = 0; j != placementArgs.size(); ++j) { |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 126 | if (placementArgs[j]->isInstantiationDependent()) |
| 127 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 128 | if (placementArgs[j]->containsUnexpandedParameterPack()) |
| 129 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 130 | |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 131 | SubExprs[i++] = placementArgs[j]; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 132 | } |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Chris Lattner | abfb58d | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 135 | void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 136 | unsigned numPlaceArgs, bool hasInitializer){ |
Chris Lattner | abfb58d | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 137 | assert(SubExprs == 0 && "SubExprs already allocated"); |
| 138 | Array = isArray; |
| 139 | NumPlacementArgs = numPlaceArgs; |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 140 | |
| 141 | unsigned TotalSize = Array + hasInitializer + NumPlacementArgs; |
Chris Lattner | abfb58d | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 142 | SubExprs = new (C) Stmt*[TotalSize]; |
| 143 | } |
| 144 | |
Sebastian Redl | 31ad754 | 2011-03-13 17:09:40 +0000 | [diff] [blame] | 145 | bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const { |
John McCall | 75f9498 | 2011-03-07 03:12:35 +0000 | [diff] [blame] | 146 | return getOperatorNew()->getType()-> |
Sebastian Redl | 31ad754 | 2011-03-13 17:09:40 +0000 | [diff] [blame] | 147 | castAs<FunctionProtoType>()->isNothrow(Ctx); |
John McCall | 75f9498 | 2011-03-07 03:12:35 +0000 | [diff] [blame] | 148 | } |
Chris Lattner | abfb58d | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 149 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 150 | SourceLocation CXXNewExpr::getEndLoc() const { |
| 151 | switch (getInitializationStyle()) { |
| 152 | case NoInit: |
| 153 | return AllocatedTypeInfo->getTypeLoc().getEndLoc(); |
| 154 | case CallInit: |
| 155 | return DirectInitRange.getEnd(); |
| 156 | case ListInit: |
| 157 | return getInitializer()->getSourceRange().getEnd(); |
| 158 | } |
Matt Beaumont-Gay | 2150d38 | 2012-02-16 22:15:50 +0000 | [diff] [blame] | 159 | llvm_unreachable("bogus initialization style"); |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 162 | // CXXDeleteExpr |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 163 | QualType CXXDeleteExpr::getDestroyedType() const { |
| 164 | const Expr *Arg = getArgument(); |
Craig Silverstein | 20f7ab7 | 2010-10-20 00:38:15 +0000 | [diff] [blame] | 165 | // The type-to-delete may not be a pointer if it's a dependent type. |
Craig Silverstein | 3b9936f | 2010-10-20 00:56:01 +0000 | [diff] [blame] | 166 | const QualType ArgType = Arg->getType(); |
Craig Silverstein | 9e448da | 2010-11-16 07:16:25 +0000 | [diff] [blame] | 167 | |
| 168 | if (ArgType->isDependentType() && !ArgType->isPointerType()) |
| 169 | return QualType(); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 170 | |
Craig Silverstein | 20f7ab7 | 2010-10-20 00:38:15 +0000 | [diff] [blame] | 171 | return ArgType->getAs<PointerType>()->getPointeeType(); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 174 | // CXXPseudoDestructorExpr |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 175 | PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) |
| 176 | : Type(Info) |
| 177 | { |
Abramo Bagnara | 1108e7b | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 178 | Location = Info->getTypeLoc().getLocalSourceRange().getBegin(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 179 | } |
| 180 | |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 181 | CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 182 | Expr *Base, bool isArrow, SourceLocation OperatorLoc, |
| 183 | NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, |
| 184 | SourceLocation ColonColonLoc, SourceLocation TildeLoc, |
| 185 | PseudoDestructorTypeStorage DestroyedType) |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 186 | : Expr(CXXPseudoDestructorExprClass, |
| 187 | Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, |
| 188 | FunctionProtoType::ExtProtoInfo())), |
| 189 | VK_RValue, OK_Ordinary, |
| 190 | /*isTypeDependent=*/(Base->isTypeDependent() || |
| 191 | (DestroyedType.getTypeSourceInfo() && |
| 192 | DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 193 | /*isValueDependent=*/Base->isValueDependent(), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 194 | (Base->isInstantiationDependent() || |
| 195 | (QualifierLoc && |
| 196 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) || |
| 197 | (ScopeType && |
| 198 | ScopeType->getType()->isInstantiationDependentType()) || |
| 199 | (DestroyedType.getTypeSourceInfo() && |
| 200 | DestroyedType.getTypeSourceInfo()->getType() |
| 201 | ->isInstantiationDependentType())), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 202 | // ContainsUnexpandedParameterPack |
| 203 | (Base->containsUnexpandedParameterPack() || |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 204 | (QualifierLoc && |
| 205 | QualifierLoc.getNestedNameSpecifier() |
| 206 | ->containsUnexpandedParameterPack()) || |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 207 | (ScopeType && |
| 208 | ScopeType->getType()->containsUnexpandedParameterPack()) || |
| 209 | (DestroyedType.getTypeSourceInfo() && |
| 210 | DestroyedType.getTypeSourceInfo()->getType() |
| 211 | ->containsUnexpandedParameterPack()))), |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 212 | Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 213 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 214 | ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), |
| 215 | DestroyedType(DestroyedType) { } |
| 216 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 217 | QualType CXXPseudoDestructorExpr::getDestroyedType() const { |
| 218 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
| 219 | return TInfo->getType(); |
| 220 | |
| 221 | return QualType(); |
| 222 | } |
| 223 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 224 | SourceRange CXXPseudoDestructorExpr::getSourceRange() const { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 225 | SourceLocation End = DestroyedType.getLocation(); |
| 226 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
Abramo Bagnara | 1108e7b | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 227 | End = TInfo->getTypeLoc().getLocalSourceRange().getEnd(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 228 | return SourceRange(Base->getLocStart(), End); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 229 | } |
| 230 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 231 | // UnresolvedLookupExpr |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 232 | UnresolvedLookupExpr * |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 233 | UnresolvedLookupExpr::Create(ASTContext &C, |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 234 | CXXRecordDecl *NamingClass, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 235 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 236 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 237 | const DeclarationNameInfo &NameInfo, |
| 238 | bool ADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 239 | const TemplateArgumentListInfo *Args, |
| 240 | UnresolvedSetIterator Begin, |
| 241 | UnresolvedSetIterator End) |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 242 | { |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 243 | assert(Args || TemplateKWLoc.isValid()); |
| 244 | unsigned num_args = Args ? Args->size() : 0; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 245 | void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) + |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 246 | ASTTemplateKWAndArgsInfo::sizeFor(num_args)); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 247 | return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, |
| 248 | TemplateKWLoc, NameInfo, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 249 | ADL, /*Overload*/ true, Args, |
Richard Smith | b662674 | 2012-10-18 17:56:02 +0000 | [diff] [blame^] | 250 | Begin, End); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Argyrios Kyrtzidis | 58e01ad | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 253 | UnresolvedLookupExpr * |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 254 | UnresolvedLookupExpr::CreateEmpty(ASTContext &C, |
| 255 | bool HasTemplateKWAndArgsInfo, |
Douglas Gregor | 87866ce | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 256 | unsigned NumTemplateArgs) { |
Argyrios Kyrtzidis | 58e01ad | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 257 | std::size_t size = sizeof(UnresolvedLookupExpr); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 258 | if (HasTemplateKWAndArgsInfo) |
| 259 | size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
Argyrios Kyrtzidis | 58e01ad | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 260 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 261 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>()); |
Argyrios Kyrtzidis | 58e01ad | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 262 | UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 263 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Argyrios Kyrtzidis | 58e01ad | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 264 | return E; |
| 265 | } |
| 266 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 267 | OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 268 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 269 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 270 | const DeclarationNameInfo &NameInfo, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 271 | const TemplateArgumentListInfo *TemplateArgs, |
Douglas Gregor | c69978f | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 272 | UnresolvedSetIterator Begin, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 273 | UnresolvedSetIterator End, |
| 274 | bool KnownDependent, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 275 | bool KnownInstantiationDependent, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 276 | bool KnownContainsUnexpandedParameterPack) |
| 277 | : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent, |
| 278 | KnownDependent, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 279 | (KnownInstantiationDependent || |
| 280 | NameInfo.isInstantiationDependent() || |
| 281 | (QualifierLoc && |
| 282 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 283 | (KnownContainsUnexpandedParameterPack || |
| 284 | NameInfo.containsUnexpandedParameterPack() || |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 285 | (QualifierLoc && |
| 286 | QualifierLoc.getNestedNameSpecifier() |
| 287 | ->containsUnexpandedParameterPack()))), |
Benjamin Kramer | b73f76b | 2012-02-26 20:37:14 +0000 | [diff] [blame] | 288 | NameInfo(NameInfo), QualifierLoc(QualifierLoc), |
| 289 | Results(0), NumResults(End - Begin), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 290 | HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()) |
Douglas Gregor | c69978f | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 291 | { |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 292 | NumResults = End - Begin; |
| 293 | if (NumResults) { |
| 294 | // Determine whether this expression is type-dependent. |
| 295 | for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) { |
| 296 | if ((*I)->getDeclContext()->isDependentContext() || |
| 297 | isa<UnresolvedUsingValueDecl>(*I)) { |
| 298 | ExprBits.TypeDependent = true; |
| 299 | ExprBits.ValueDependent = true; |
Richard Smith | 47726b2 | 2012-08-13 21:29:18 +0000 | [diff] [blame] | 300 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | Results = static_cast<DeclAccessPair *>( |
| 305 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 306 | llvm::alignOf<DeclAccessPair>())); |
| 307 | memcpy(Results, &*Begin.getIterator(), |
| 308 | NumResults * sizeof(DeclAccessPair)); |
| 309 | } |
| 310 | |
| 311 | // If we have explicit template arguments, check for dependent |
| 312 | // template arguments and whether they contain any unexpanded pack |
| 313 | // expansions. |
| 314 | if (TemplateArgs) { |
| 315 | bool Dependent = false; |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 316 | bool InstantiationDependent = false; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 317 | bool ContainsUnexpandedParameterPack = false; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 318 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, |
| 319 | Dependent, |
| 320 | InstantiationDependent, |
| 321 | ContainsUnexpandedParameterPack); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 322 | |
| 323 | if (Dependent) { |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 324 | ExprBits.TypeDependent = true; |
| 325 | ExprBits.ValueDependent = true; |
| 326 | } |
| 327 | if (InstantiationDependent) |
| 328 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 329 | if (ContainsUnexpandedParameterPack) |
| 330 | ExprBits.ContainsUnexpandedParameterPack = true; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 331 | } else if (TemplateKWLoc.isValid()) { |
| 332 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | if (isTypeDependent()) |
| 336 | setType(C.DependentTy); |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void OverloadExpr::initializeResults(ASTContext &C, |
| 340 | UnresolvedSetIterator Begin, |
| 341 | UnresolvedSetIterator End) { |
| 342 | assert(Results == 0 && "Results already initialized!"); |
| 343 | NumResults = End - Begin; |
Douglas Gregor | c69978f | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 344 | if (NumResults) { |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 345 | Results = static_cast<DeclAccessPair *>( |
| 346 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 347 | |
| 348 | llvm::alignOf<DeclAccessPair>())); |
| 349 | memcpy(Results, &*Begin.getIterator(), |
| 350 | NumResults * sizeof(DeclAccessPair)); |
Douglas Gregor | c69978f | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
John McCall | 8c12dc4 | 2010-04-22 18:44:12 +0000 | [diff] [blame] | 354 | CXXRecordDecl *OverloadExpr::getNamingClass() const { |
| 355 | if (isa<UnresolvedLookupExpr>(this)) |
| 356 | return cast<UnresolvedLookupExpr>(this)->getNamingClass(); |
| 357 | else |
| 358 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); |
| 359 | } |
| 360 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 361 | // DependentScopeDeclRefExpr |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 362 | DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T, |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 363 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 364 | SourceLocation TemplateKWLoc, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 365 | const DeclarationNameInfo &NameInfo, |
| 366 | const TemplateArgumentListInfo *Args) |
| 367 | : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary, |
| 368 | true, true, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 369 | (NameInfo.isInstantiationDependent() || |
| 370 | (QualifierLoc && |
| 371 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 372 | (NameInfo.containsUnexpandedParameterPack() || |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 373 | (QualifierLoc && |
| 374 | QualifierLoc.getNestedNameSpecifier() |
| 375 | ->containsUnexpandedParameterPack()))), |
| 376 | QualifierLoc(QualifierLoc), NameInfo(NameInfo), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 377 | HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid()) |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 378 | { |
| 379 | if (Args) { |
| 380 | bool Dependent = true; |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 381 | bool InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 382 | bool ContainsUnexpandedParameterPack |
| 383 | = ExprBits.ContainsUnexpandedParameterPack; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 384 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args, |
| 385 | Dependent, |
| 386 | InstantiationDependent, |
| 387 | ContainsUnexpandedParameterPack); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 388 | ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 389 | } else if (TemplateKWLoc.isValid()) { |
| 390 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 394 | DependentScopeDeclRefExpr * |
| 395 | DependentScopeDeclRefExpr::Create(ASTContext &C, |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 396 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 397 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 398 | const DeclarationNameInfo &NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 399 | const TemplateArgumentListInfo *Args) { |
| 400 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 401 | if (Args) |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 402 | size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size()); |
| 403 | else if (TemplateKWLoc.isValid()) |
| 404 | size += ASTTemplateKWAndArgsInfo::sizeFor(0); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 405 | void *Mem = C.Allocate(size); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 406 | return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc, |
| 407 | TemplateKWLoc, NameInfo, Args); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Argyrios Kyrtzidis | cd444d1a | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 410 | DependentScopeDeclRefExpr * |
| 411 | DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 412 | bool HasTemplateKWAndArgsInfo, |
Argyrios Kyrtzidis | cd444d1a | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 413 | unsigned NumTemplateArgs) { |
| 414 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 415 | if (HasTemplateKWAndArgsInfo) |
| 416 | size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
Argyrios Kyrtzidis | cd444d1a | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 417 | void *Mem = C.Allocate(size); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 418 | DependentScopeDeclRefExpr *E |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 419 | = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 420 | SourceLocation(), |
Douglas Gregor | 87866ce | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 421 | DeclarationNameInfo(), 0); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 422 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Douglas Gregor | 87866ce | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 423 | return E; |
Argyrios Kyrtzidis | cd444d1a | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 426 | SourceRange CXXConstructExpr::getSourceRange() const { |
John McCall | 701417a | 2011-02-21 06:23:05 +0000 | [diff] [blame] | 427 | if (isa<CXXTemporaryObjectExpr>(this)) |
| 428 | return cast<CXXTemporaryObjectExpr>(this)->getSourceRange(); |
| 429 | |
Douglas Gregor | 15417cf | 2010-11-03 00:35:38 +0000 | [diff] [blame] | 430 | if (ParenRange.isValid()) |
| 431 | return SourceRange(Loc, ParenRange.getEnd()); |
| 432 | |
| 433 | SourceLocation End = Loc; |
| 434 | for (unsigned I = getNumArgs(); I > 0; --I) { |
| 435 | const Expr *Arg = getArg(I-1); |
| 436 | if (!Arg->isDefaultArgument()) { |
| 437 | SourceLocation NewEnd = Arg->getLocEnd(); |
| 438 | if (NewEnd.isValid()) { |
| 439 | End = NewEnd; |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | return SourceRange(Loc, End); |
Ted Kremenek | 49ace5c | 2009-12-23 04:00:48 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Argyrios Kyrtzidis | d8e0769 | 2012-04-30 22:12:22 +0000 | [diff] [blame] | 448 | SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 449 | OverloadedOperatorKind Kind = getOperator(); |
| 450 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 451 | if (getNumArgs() == 1) |
| 452 | // Prefix operator |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 453 | return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 454 | else |
| 455 | // Postfix operator |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 456 | return SourceRange(getArg(0)->getLocStart(), getOperatorLoc()); |
Chandler Carruth | f20ec923 | 2011-04-02 09:47:38 +0000 | [diff] [blame] | 457 | } else if (Kind == OO_Arrow) { |
| 458 | return getArg(0)->getSourceRange(); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 459 | } else if (Kind == OO_Call) { |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 460 | return SourceRange(getArg(0)->getLocStart(), getRParenLoc()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 461 | } else if (Kind == OO_Subscript) { |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 462 | return SourceRange(getArg(0)->getLocStart(), getRParenLoc()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 463 | } else if (getNumArgs() == 1) { |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 464 | return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 465 | } else if (getNumArgs() == 2) { |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 466 | return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 467 | } else { |
Argyrios Kyrtzidis | d8e0769 | 2012-04-30 22:12:22 +0000 | [diff] [blame] | 468 | return getOperatorLoc(); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
Ted Kremenek | 98a24e3 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 472 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { |
Jordan Rose | 16fe35e | 2012-08-03 23:08:39 +0000 | [diff] [blame] | 473 | const Expr *Callee = getCallee()->IgnoreParens(); |
| 474 | if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee)) |
Douglas Gregor | 97fd6e2 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 475 | return MemExpr->getBase(); |
Jordan Rose | 16fe35e | 2012-08-03 23:08:39 +0000 | [diff] [blame] | 476 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee)) |
| 477 | if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI) |
| 478 | return BO->getLHS(); |
Douglas Gregor | 97fd6e2 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 479 | |
| 480 | // FIXME: Will eventually need to cope with member pointers. |
| 481 | return 0; |
| 482 | } |
| 483 | |
Ted Kremenek | 98a24e3 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 484 | CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { |
| 485 | if (const MemberExpr *MemExpr = |
| 486 | dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 487 | return cast<CXXMethodDecl>(MemExpr->getMemberDecl()); |
| 488 | |
| 489 | // FIXME: Will eventually need to cope with member pointers. |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | |
David Blaikie | c0f5866 | 2012-05-03 16:25:49 +0000 | [diff] [blame] | 494 | CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const { |
Chandler Carruth | 00426b4 | 2010-10-27 06:55:41 +0000 | [diff] [blame] | 495 | Expr* ThisArg = getImplicitObjectArgument(); |
| 496 | if (!ThisArg) |
| 497 | return 0; |
| 498 | |
| 499 | if (ThisArg->getType()->isAnyPointerType()) |
| 500 | return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl(); |
| 501 | |
| 502 | return ThisArg->getType()->getAsCXXRecordDecl(); |
| 503 | } |
| 504 | |
Douglas Gregor | ef986e8 | 2009-11-12 15:31:47 +0000 | [diff] [blame] | 505 | |
Douglas Gregor | e200adc | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 506 | //===----------------------------------------------------------------------===// |
| 507 | // Named casts |
| 508 | //===----------------------------------------------------------------------===// |
| 509 | |
| 510 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 511 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 512 | /// "const_cast". The returned pointer must not be freed. |
| 513 | const char *CXXNamedCastExpr::getCastName() const { |
| 514 | switch (getStmtClass()) { |
| 515 | case CXXStaticCastExprClass: return "static_cast"; |
| 516 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 517 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 518 | case CXXConstCastExprClass: return "const_cast"; |
| 519 | default: return "<invalid cast>"; |
| 520 | } |
| 521 | } |
Douglas Gregor | dd04d33 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 522 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 523 | CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 524 | ExprValueKind VK, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 525 | CastKind K, Expr *Op, |
| 526 | const CXXCastPath *BasePath, |
| 527 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 528 | SourceLocation L, |
| 529 | SourceLocation RParenLoc) { |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 530 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 531 | void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr) |
| 532 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 533 | CXXStaticCastExpr *E = |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 534 | new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 535 | RParenLoc); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 536 | if (PathSize) E->setCastPath(*BasePath); |
| 537 | return E; |
| 538 | } |
| 539 | |
| 540 | CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C, |
| 541 | unsigned PathSize) { |
| 542 | void *Buffer = |
| 543 | C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 544 | return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize); |
| 545 | } |
| 546 | |
| 547 | CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 548 | ExprValueKind VK, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 549 | CastKind K, Expr *Op, |
| 550 | const CXXCastPath *BasePath, |
| 551 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 552 | SourceLocation L, |
| 553 | SourceLocation RParenLoc) { |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 554 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 555 | void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr) |
| 556 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 557 | CXXDynamicCastExpr *E = |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 558 | new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 559 | RParenLoc); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 560 | if (PathSize) E->setCastPath(*BasePath); |
| 561 | return E; |
| 562 | } |
| 563 | |
| 564 | CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C, |
| 565 | unsigned PathSize) { |
| 566 | void *Buffer = |
| 567 | C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 568 | return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); |
| 569 | } |
| 570 | |
Anders Carlsson | 267c0c9 | 2011-04-11 01:43:55 +0000 | [diff] [blame] | 571 | /// isAlwaysNull - Return whether the result of the dynamic_cast is proven |
| 572 | /// to always be null. For example: |
| 573 | /// |
| 574 | /// struct A { }; |
| 575 | /// struct B final : A { }; |
| 576 | /// struct C { }; |
| 577 | /// |
| 578 | /// C *f(B* b) { return dynamic_cast<C*>(b); } |
| 579 | bool CXXDynamicCastExpr::isAlwaysNull() const |
| 580 | { |
| 581 | QualType SrcType = getSubExpr()->getType(); |
| 582 | QualType DestType = getType(); |
| 583 | |
| 584 | if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) { |
| 585 | SrcType = SrcPTy->getPointeeType(); |
| 586 | DestType = DestType->castAs<PointerType>()->getPointeeType(); |
| 587 | } |
| 588 | |
Alexis Hunt | 78e2b91 | 2012-06-19 23:44:55 +0000 | [diff] [blame] | 589 | if (DestType->isVoidType()) |
| 590 | return false; |
| 591 | |
Anders Carlsson | 267c0c9 | 2011-04-11 01:43:55 +0000 | [diff] [blame] | 592 | const CXXRecordDecl *SrcRD = |
| 593 | cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl()); |
| 594 | |
Jakob Stoklund Olesen | e1c0ae6 | 2012-06-19 21:48:43 +0000 | [diff] [blame] | 595 | if (!SrcRD->hasAttr<FinalAttr>()) |
| 596 | return false; |
| 597 | |
Anders Carlsson | 267c0c9 | 2011-04-11 01:43:55 +0000 | [diff] [blame] | 598 | const CXXRecordDecl *DestRD = |
| 599 | cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl()); |
| 600 | |
| 601 | return !DestRD->isDerivedFrom(SrcRD); |
| 602 | } |
| 603 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 604 | CXXReinterpretCastExpr * |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 605 | CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK, |
| 606 | CastKind K, Expr *Op, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 607 | const CXXCastPath *BasePath, |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 608 | TypeSourceInfo *WrittenTy, SourceLocation L, |
| 609 | SourceLocation RParenLoc) { |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 610 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 611 | void *Buffer = |
| 612 | C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 613 | CXXReinterpretCastExpr *E = |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 614 | new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 615 | RParenLoc); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 616 | if (PathSize) E->setCastPath(*BasePath); |
| 617 | return E; |
| 618 | } |
| 619 | |
| 620 | CXXReinterpretCastExpr * |
| 621 | CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 622 | void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr) |
| 623 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 624 | return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); |
| 625 | } |
| 626 | |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 627 | CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T, |
| 628 | ExprValueKind VK, Expr *Op, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 629 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 630 | SourceLocation L, |
| 631 | SourceLocation RParenLoc) { |
| 632 | return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) { |
| 636 | return new (C) CXXConstCastExpr(EmptyShell()); |
| 637 | } |
| 638 | |
| 639 | CXXFunctionalCastExpr * |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 640 | CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 641 | TypeSourceInfo *Written, SourceLocation L, |
| 642 | CastKind K, Expr *Op, const CXXCastPath *BasePath, |
| 643 | SourceLocation R) { |
| 644 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 645 | void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) |
| 646 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 647 | CXXFunctionalCastExpr *E = |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 648 | new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 649 | if (PathSize) E->setCastPath(*BasePath); |
| 650 | return E; |
| 651 | } |
| 652 | |
| 653 | CXXFunctionalCastExpr * |
| 654 | CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 655 | void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) |
| 656 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 657 | return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize); |
| 658 | } |
| 659 | |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 660 | UserDefinedLiteral::LiteralOperatorKind |
| 661 | UserDefinedLiteral::getLiteralOperatorKind() const { |
| 662 | if (getNumArgs() == 0) |
| 663 | return LOK_Template; |
| 664 | if (getNumArgs() == 2) |
| 665 | return LOK_String; |
| 666 | |
| 667 | assert(getNumArgs() == 1 && "unexpected #args in literal operator call"); |
| 668 | QualType ParamTy = |
| 669 | cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType(); |
| 670 | if (ParamTy->isPointerType()) |
| 671 | return LOK_Raw; |
| 672 | if (ParamTy->isAnyCharacterType()) |
| 673 | return LOK_Character; |
| 674 | if (ParamTy->isIntegerType()) |
| 675 | return LOK_Integer; |
| 676 | if (ParamTy->isFloatingType()) |
| 677 | return LOK_Floating; |
| 678 | |
| 679 | llvm_unreachable("unknown kind of literal operator"); |
| 680 | } |
| 681 | |
| 682 | Expr *UserDefinedLiteral::getCookedLiteral() { |
| 683 | #ifndef NDEBUG |
| 684 | LiteralOperatorKind LOK = getLiteralOperatorKind(); |
| 685 | assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal"); |
| 686 | #endif |
| 687 | return getArg(0); |
| 688 | } |
| 689 | |
| 690 | const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const { |
| 691 | return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier(); |
| 692 | } |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 693 | |
Douglas Gregor | 25ab25f | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 694 | CXXDefaultArgExpr * |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 695 | CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc, |
| 696 | ParmVarDecl *Param, Expr *SubExpr) { |
Douglas Gregor | 25ab25f | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 697 | void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *)); |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 698 | return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, |
| 699 | SubExpr); |
Douglas Gregor | 25ab25f | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 702 | CXXTemporary *CXXTemporary::Create(ASTContext &C, |
Anders Carlsson | ffda606 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 703 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 73b836b | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 704 | return new (C) CXXTemporary(Destructor); |
| 705 | } |
| 706 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, |
Anders Carlsson | 993a4b3 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 708 | CXXTemporary *Temp, |
| 709 | Expr* SubExpr) { |
Peter Collingbourne | fbef4c8 | 2011-11-27 22:09:28 +0000 | [diff] [blame] | 710 | assert((SubExpr->getType()->isRecordType() || |
| 711 | SubExpr->getType()->isArrayType()) && |
| 712 | "Expression bound to a temporary must have record or array type!"); |
Anders Carlsson | 993a4b3 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 713 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 714 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | 993a4b3 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Anders Carlsson | 4b2434d | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 717 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 56c5bd8 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 718 | CXXConstructorDecl *Cons, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 719 | TypeSourceInfo *Type, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 720 | ArrayRef<Expr*> Args, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 721 | SourceRange parenRange, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 722 | bool HadMultipleCandidates, |
Douglas Gregor | 199db36 | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 723 | bool ZeroInitialization) |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 724 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, |
| 725 | Type->getType().getNonReferenceType(), |
| 726 | Type->getTypeLoc().getBeginLoc(), |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 727 | Cons, false, Args, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 728 | HadMultipleCandidates, /*FIXME*/false, ZeroInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 729 | CXXConstructExpr::CK_Complete, parenRange), |
| 730 | Type(Type) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | SourceRange CXXTemporaryObjectExpr::getSourceRange() const { |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 734 | return SourceRange(Type->getTypeLoc().getBeginLoc(), |
| 735 | getParenRange().getEnd()); |
Douglas Gregor | dd04d33 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 736 | } |
Anders Carlsson | 6f28783 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 737 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
Douglas Gregor | 85dabae | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 739 | SourceLocation Loc, |
Anders Carlsson | 4b2434d | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 740 | CXXConstructorDecl *D, bool Elidable, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 741 | ArrayRef<Expr*> Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 742 | bool HadMultipleCandidates, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 743 | bool ListInitialization, |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 744 | bool ZeroInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 745 | ConstructionKind ConstructKind, |
| 746 | SourceRange ParenRange) { |
Douglas Gregor | 85dabae | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 747 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 748 | Elidable, Args, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 749 | HadMultipleCandidates, ListInitialization, |
| 750 | ZeroInitialization, ConstructKind, |
| 751 | ParenRange); |
Anders Carlsson | 0781ce7 | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 754 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
Douglas Gregor | 85dabae | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 755 | SourceLocation Loc, |
Anders Carlsson | 4b2434d | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 756 | CXXConstructorDecl *D, bool elidable, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 757 | ArrayRef<Expr*> args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 758 | bool HadMultipleCandidates, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 759 | bool ListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 760 | bool ZeroInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 761 | ConstructionKind ConstructKind, |
| 762 | SourceRange ParenRange) |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 763 | : Expr(SC, T, VK_RValue, OK_Ordinary, |
| 764 | T->isDependentType(), T->isDependentType(), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 765 | T->isInstantiationDependentType(), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 766 | T->containsUnexpandedParameterPack()), |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 767 | Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(args.size()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 768 | Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates), |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 769 | ListInitialization(ListInitialization), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 770 | ZeroInitialization(ZeroInitialization), |
Douglas Gregor | 488c231 | 2011-09-26 14:47:03 +0000 | [diff] [blame] | 771 | ConstructKind(ConstructKind), Args(0) |
Douglas Gregor | 4f4b186 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 772 | { |
| 773 | if (NumArgs) { |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 774 | Args = new (C) Stmt*[args.size()]; |
Douglas Gregor | 4f4b186 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 775 | |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 776 | for (unsigned i = 0; i != args.size(); ++i) { |
Douglas Gregor | 4f4b186 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 777 | assert(args[i] && "NULL argument in CXXConstructExpr"); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 778 | |
| 779 | if (args[i]->isValueDependent()) |
| 780 | ExprBits.ValueDependent = true; |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 781 | if (args[i]->isInstantiationDependent()) |
| 782 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 783 | if (args[i]->containsUnexpandedParameterPack()) |
| 784 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 785 | |
Douglas Gregor | 4f4b186 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 786 | Args[i] = args[i]; |
Anders Carlsson | 0781ce7 | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 787 | } |
Douglas Gregor | 4f4b186 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 788 | } |
Anders Carlsson | 0781ce7 | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 791 | LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit, |
| 792 | LambdaCaptureKind Kind, VarDecl *Var, |
| 793 | SourceLocation EllipsisLoc) |
| 794 | : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) |
| 795 | { |
| 796 | unsigned Bits = 0; |
| 797 | if (Implicit) |
| 798 | Bits |= Capture_Implicit; |
| 799 | |
| 800 | switch (Kind) { |
| 801 | case LCK_This: |
| 802 | assert(Var == 0 && "'this' capture cannot have a variable!"); |
| 803 | break; |
| 804 | |
| 805 | case LCK_ByCopy: |
| 806 | Bits |= Capture_ByCopy; |
| 807 | // Fall through |
| 808 | case LCK_ByRef: |
| 809 | assert(Var && "capture must have a variable!"); |
| 810 | break; |
| 811 | } |
| 812 | VarAndBits.setInt(Bits); |
| 813 | } |
| 814 | |
| 815 | LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const { |
| 816 | if (capturesThis()) |
| 817 | return LCK_This; |
| 818 | |
| 819 | return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef; |
| 820 | } |
| 821 | |
| 822 | LambdaExpr::LambdaExpr(QualType T, |
| 823 | SourceRange IntroducerRange, |
| 824 | LambdaCaptureDefault CaptureDefault, |
| 825 | ArrayRef<Capture> Captures, |
| 826 | bool ExplicitParams, |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 827 | bool ExplicitResultType, |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 828 | ArrayRef<Expr *> CaptureInits, |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 829 | ArrayRef<VarDecl *> ArrayIndexVars, |
| 830 | ArrayRef<unsigned> ArrayIndexStarts, |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 831 | SourceLocation ClosingBrace, |
| 832 | bool ContainsUnexpandedParameterPack) |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 833 | : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, |
| 834 | T->isDependentType(), T->isDependentType(), T->isDependentType(), |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 835 | ContainsUnexpandedParameterPack), |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 836 | IntroducerRange(IntroducerRange), |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 837 | NumCaptures(Captures.size()), |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 838 | CaptureDefault(CaptureDefault), |
| 839 | ExplicitParams(ExplicitParams), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 840 | ExplicitResultType(ExplicitResultType), |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 841 | ClosingBrace(ClosingBrace) |
| 842 | { |
| 843 | assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments"); |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 844 | CXXRecordDecl *Class = getLambdaClass(); |
| 845 | CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData(); |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 846 | |
| 847 | // FIXME: Propagate "has unexpanded parameter pack" bit. |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 848 | |
| 849 | // Copy captures. |
| 850 | ASTContext &Context = Class->getASTContext(); |
| 851 | Data.NumCaptures = NumCaptures; |
| 852 | Data.NumExplicitCaptures = 0; |
| 853 | Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures); |
| 854 | Capture *ToCapture = Data.Captures; |
| 855 | for (unsigned I = 0, N = Captures.size(); I != N; ++I) { |
| 856 | if (Captures[I].isExplicit()) |
| 857 | ++Data.NumExplicitCaptures; |
| 858 | |
| 859 | *ToCapture++ = Captures[I]; |
| 860 | } |
| 861 | |
| 862 | // Copy initialization expressions for the non-static data members. |
| 863 | Stmt **Stored = getStoredStmts(); |
| 864 | for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I) |
| 865 | *Stored++ = CaptureInits[I]; |
| 866 | |
| 867 | // Copy the body of the lambda. |
| 868 | *Stored++ = getCallOperator()->getBody(); |
| 869 | |
| 870 | // Copy the array index variables, if any. |
| 871 | HasArrayIndexVars = !ArrayIndexVars.empty(); |
| 872 | if (HasArrayIndexVars) { |
| 873 | assert(ArrayIndexStarts.size() == NumCaptures); |
| 874 | memcpy(getArrayIndexVars(), ArrayIndexVars.data(), |
| 875 | sizeof(VarDecl *) * ArrayIndexVars.size()); |
| 876 | memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(), |
| 877 | sizeof(unsigned) * Captures.size()); |
| 878 | getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size(); |
Douglas Gregor | 6f88e5e | 2012-02-21 04:17:39 +0000 | [diff] [blame] | 879 | } |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | LambdaExpr *LambdaExpr::Create(ASTContext &Context, |
| 883 | CXXRecordDecl *Class, |
| 884 | SourceRange IntroducerRange, |
| 885 | LambdaCaptureDefault CaptureDefault, |
| 886 | ArrayRef<Capture> Captures, |
| 887 | bool ExplicitParams, |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 888 | bool ExplicitResultType, |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 889 | ArrayRef<Expr *> CaptureInits, |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 890 | ArrayRef<VarDecl *> ArrayIndexVars, |
| 891 | ArrayRef<unsigned> ArrayIndexStarts, |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 892 | SourceLocation ClosingBrace, |
| 893 | bool ContainsUnexpandedParameterPack) { |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 894 | // Determine the type of the expression (i.e., the type of the |
| 895 | // function object we're creating). |
| 896 | QualType T = Context.getTypeDeclType(Class); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 897 | |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 898 | unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1); |
Richard Smith | c7520bf | 2012-08-21 05:42:49 +0000 | [diff] [blame] | 899 | if (!ArrayIndexVars.empty()) { |
| 900 | Size += sizeof(unsigned) * (Captures.size() + 1); |
| 901 | // Realign for following VarDecl array. |
Richard Smith | a75e1cf | 2012-08-21 18:18:06 +0000 | [diff] [blame] | 902 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>()); |
Richard Smith | c7520bf | 2012-08-21 05:42:49 +0000 | [diff] [blame] | 903 | Size += sizeof(VarDecl *) * ArrayIndexVars.size(); |
| 904 | } |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 905 | void *Mem = Context.Allocate(Size); |
| 906 | return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault, |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 907 | Captures, ExplicitParams, ExplicitResultType, |
| 908 | CaptureInits, ArrayIndexVars, ArrayIndexStarts, |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 909 | ClosingBrace, ContainsUnexpandedParameterPack); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 912 | LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures, |
| 913 | unsigned NumArrayIndexVars) { |
| 914 | unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1); |
| 915 | if (NumArrayIndexVars) |
| 916 | Size += sizeof(VarDecl) * NumArrayIndexVars |
| 917 | + sizeof(unsigned) * (NumCaptures + 1); |
| 918 | void *Mem = C.Allocate(Size); |
| 919 | return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0); |
| 920 | } |
| 921 | |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 922 | LambdaExpr::capture_iterator LambdaExpr::capture_begin() const { |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 923 | return getLambdaClass()->getLambdaData().Captures; |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | LambdaExpr::capture_iterator LambdaExpr::capture_end() const { |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 927 | return capture_begin() + NumCaptures; |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const { |
| 931 | return capture_begin(); |
| 932 | } |
| 933 | |
| 934 | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const { |
| 935 | struct CXXRecordDecl::LambdaDefinitionData &Data |
| 936 | = getLambdaClass()->getLambdaData(); |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 937 | return Data.Captures + Data.NumExplicitCaptures; |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const { |
| 941 | return explicit_capture_end(); |
| 942 | } |
| 943 | |
| 944 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const { |
| 945 | return capture_end(); |
| 946 | } |
| 947 | |
Douglas Gregor | 54fcea6 | 2012-02-13 16:35:30 +0000 | [diff] [blame] | 948 | ArrayRef<VarDecl *> |
| 949 | LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const { |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 950 | assert(HasArrayIndexVars && "No array index-var data?"); |
Douglas Gregor | 54fcea6 | 2012-02-13 16:35:30 +0000 | [diff] [blame] | 951 | |
| 952 | unsigned Index = Iter - capture_init_begin(); |
Matt Beaumont-Gay | f2ee067 | 2012-02-13 19:29:45 +0000 | [diff] [blame] | 953 | assert(Index < getLambdaClass()->getLambdaData().NumCaptures && |
| 954 | "Capture index out-of-range"); |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 955 | VarDecl **IndexVars = getArrayIndexVars(); |
| 956 | unsigned *IndexStarts = getArrayIndexStarts(); |
Douglas Gregor | 54fcea6 | 2012-02-13 16:35:30 +0000 | [diff] [blame] | 957 | return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index], |
| 958 | IndexVars + IndexStarts[Index + 1]); |
| 959 | } |
| 960 | |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 961 | CXXRecordDecl *LambdaExpr::getLambdaClass() const { |
| 962 | return getType()->getAsCXXRecordDecl(); |
| 963 | } |
| 964 | |
| 965 | CXXMethodDecl *LambdaExpr::getCallOperator() const { |
| 966 | CXXRecordDecl *Record = getLambdaClass(); |
| 967 | DeclarationName Name |
| 968 | = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call); |
| 969 | DeclContext::lookup_result Calls = Record->lookup(Name); |
| 970 | assert(Calls.first != Calls.second && "Missing lambda call operator!"); |
| 971 | CXXMethodDecl *Result = cast<CXXMethodDecl>(*Calls.first++); |
| 972 | assert(Calls.first == Calls.second && "More than lambda one call operator?"); |
| 973 | return Result; |
| 974 | } |
| 975 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 976 | CompoundStmt *LambdaExpr::getBody() const { |
| 977 | if (!getStoredStmts()[NumCaptures]) |
| 978 | getStoredStmts()[NumCaptures] = getCallOperator()->getBody(); |
| 979 | |
| 980 | return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]); |
| 981 | } |
| 982 | |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 983 | bool LambdaExpr::isMutable() const { |
David Blaikie | f5697e5 | 2012-08-10 00:55:35 +0000 | [diff] [blame] | 984 | return !getCallOperator()->isConst(); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 985 | } |
| 986 | |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 987 | ExprWithCleanups::ExprWithCleanups(Expr *subexpr, |
| 988 | ArrayRef<CleanupObject> objects) |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 989 | : Expr(ExprWithCleanupsClass, subexpr->getType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 990 | subexpr->getValueKind(), subexpr->getObjectKind(), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 991 | subexpr->isTypeDependent(), subexpr->isValueDependent(), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 992 | subexpr->isInstantiationDependent(), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 993 | subexpr->containsUnexpandedParameterPack()), |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 994 | SubExpr(subexpr) { |
| 995 | ExprWithCleanupsBits.NumObjects = objects.size(); |
| 996 | for (unsigned i = 0, e = objects.size(); i != e; ++i) |
| 997 | getObjectsBuffer()[i] = objects[i]; |
Anders Carlsson | defc644 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 998 | } |
| 999 | |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1000 | ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr, |
| 1001 | ArrayRef<CleanupObject> objects) { |
| 1002 | size_t size = sizeof(ExprWithCleanups) |
| 1003 | + objects.size() * sizeof(CleanupObject); |
| 1004 | void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>()); |
| 1005 | return new (buffer) ExprWithCleanups(subexpr, objects); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1008 | ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects) |
| 1009 | : Expr(ExprWithCleanupsClass, empty) { |
| 1010 | ExprWithCleanupsBits.NumObjects = numObjects; |
| 1011 | } |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1012 | |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1013 | ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty, |
| 1014 | unsigned numObjects) { |
| 1015 | size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject); |
| 1016 | void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>()); |
| 1017 | return new (buffer) ExprWithCleanups(empty, numObjects); |
Anders Carlsson | 73b836b | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1020 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type, |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1021 | SourceLocation LParenLoc, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1022 | ArrayRef<Expr*> Args, |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1023 | SourceLocation RParenLoc) |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1024 | : Expr(CXXUnresolvedConstructExprClass, |
| 1025 | Type->getType().getNonReferenceType(), |
Douglas Gregor | 6336f29 | 2011-07-08 15:50:43 +0000 | [diff] [blame] | 1026 | (Type->getType()->isLValueReferenceType() ? VK_LValue |
| 1027 | :Type->getType()->isRValueReferenceType()? VK_XValue |
| 1028 | :VK_RValue), |
| 1029 | OK_Ordinary, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1030 | Type->getType()->isDependentType(), true, true, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1031 | Type->getType()->containsUnexpandedParameterPack()), |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1032 | Type(Type), |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1033 | LParenLoc(LParenLoc), |
| 1034 | RParenLoc(RParenLoc), |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1035 | NumArgs(Args.size()) { |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1036 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1037 | for (unsigned I = 0; I != Args.size(); ++I) { |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1038 | if (Args[I]->containsUnexpandedParameterPack()) |
| 1039 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 1040 | |
| 1041 | StoredArgs[I] = Args[I]; |
| 1042 | } |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | CXXUnresolvedConstructExpr * |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1047 | TypeSourceInfo *Type, |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1048 | SourceLocation LParenLoc, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1049 | ArrayRef<Expr*> Args, |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1050 | SourceLocation RParenLoc) { |
| 1051 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1052 | sizeof(Expr *) * Args.size()); |
| 1053 | return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc); |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1056 | CXXUnresolvedConstructExpr * |
| 1057 | CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) { |
| 1058 | Stmt::EmptyShell Empty; |
| 1059 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 1060 | sizeof(Expr *) * NumArgs); |
| 1061 | return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); |
| 1062 | } |
| 1063 | |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1064 | SourceRange CXXUnresolvedConstructExpr::getSourceRange() const { |
| 1065 | return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc); |
| 1066 | } |
| 1067 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1068 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1069 | Expr *Base, QualType BaseType, |
| 1070 | bool IsArrow, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1071 | SourceLocation OperatorLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1072 | NestedNameSpecifierLoc QualifierLoc, |
| 1073 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1074 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1075 | DeclarationNameInfo MemberNameInfo, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1076 | const TemplateArgumentListInfo *TemplateArgs) |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1077 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1078 | VK_LValue, OK_Ordinary, true, true, true, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1079 | ((Base && Base->containsUnexpandedParameterPack()) || |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1080 | (QualifierLoc && |
| 1081 | QualifierLoc.getNestedNameSpecifier() |
| 1082 | ->containsUnexpandedParameterPack()) || |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1083 | MemberNameInfo.containsUnexpandedParameterPack())), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1084 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1085 | HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1086 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1087 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1088 | MemberNameInfo(MemberNameInfo) { |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1089 | if (TemplateArgs) { |
| 1090 | bool Dependent = true; |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1091 | bool InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1092 | bool ContainsUnexpandedParameterPack = false; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1093 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, |
| 1094 | Dependent, |
| 1095 | InstantiationDependent, |
| 1096 | ContainsUnexpandedParameterPack); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1097 | if (ContainsUnexpandedParameterPack) |
| 1098 | ExprBits.ContainsUnexpandedParameterPack = true; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1099 | } else if (TemplateKWLoc.isValid()) { |
| 1100 | getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1101 | } |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1104 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
| 1105 | Expr *Base, QualType BaseType, |
| 1106 | bool IsArrow, |
| 1107 | SourceLocation OperatorLoc, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1108 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1109 | NamedDecl *FirstQualifierFoundInScope, |
| 1110 | DeclarationNameInfo MemberNameInfo) |
| 1111 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1112 | VK_LValue, OK_Ordinary, true, true, true, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1113 | ((Base && Base->containsUnexpandedParameterPack()) || |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1114 | (QualifierLoc && |
| 1115 | QualifierLoc.getNestedNameSpecifier()-> |
| 1116 | containsUnexpandedParameterPack()) || |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1117 | MemberNameInfo.containsUnexpandedParameterPack())), |
| 1118 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1119 | HasTemplateKWAndArgsInfo(false), |
| 1120 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1121 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
| 1122 | MemberNameInfo(MemberNameInfo) { } |
| 1123 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1124 | CXXDependentScopeMemberExpr * |
| 1125 | CXXDependentScopeMemberExpr::Create(ASTContext &C, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1126 | Expr *Base, QualType BaseType, bool IsArrow, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1127 | SourceLocation OperatorLoc, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1128 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1129 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1130 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1131 | DeclarationNameInfo MemberNameInfo, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1132 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1133 | if (!TemplateArgs && !TemplateKWLoc.isValid()) |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1134 | return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 1135 | IsArrow, OperatorLoc, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1136 | QualifierLoc, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1137 | FirstQualifierFoundInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1138 | MemberNameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1140 | unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0; |
| 1141 | std::size_t size = sizeof(CXXDependentScopeMemberExpr) |
| 1142 | + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1143 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 1144 | void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1145 | return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 1146 | IsArrow, OperatorLoc, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1147 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1148 | TemplateKWLoc, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1149 | FirstQualifierFoundInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1150 | MemberNameInfo, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1153 | CXXDependentScopeMemberExpr * |
| 1154 | CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1155 | bool HasTemplateKWAndArgsInfo, |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1156 | unsigned NumTemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1157 | if (!HasTemplateKWAndArgsInfo) |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1158 | return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1159 | 0, SourceLocation(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1160 | NestedNameSpecifierLoc(), 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1161 | DeclarationNameInfo()); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1162 | |
| 1163 | std::size_t size = sizeof(CXXDependentScopeMemberExpr) + |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1164 | ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 1165 | void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1166 | CXXDependentScopeMemberExpr *E |
| 1167 | = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1168 | 0, SourceLocation(), |
| 1169 | NestedNameSpecifierLoc(), |
| 1170 | SourceLocation(), 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1171 | DeclarationNameInfo(), 0); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1172 | E->HasTemplateKWAndArgsInfo = true; |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1173 | return E; |
| 1174 | } |
| 1175 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1176 | bool CXXDependentScopeMemberExpr::isImplicitAccess() const { |
| 1177 | if (Base == 0) |
| 1178 | return true; |
| 1179 | |
Douglas Gregor | 25b7e05 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 1180 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1183 | static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, |
| 1184 | UnresolvedSetIterator end) { |
| 1185 | do { |
| 1186 | NamedDecl *decl = *begin; |
| 1187 | if (isa<UnresolvedUsingValueDecl>(decl)) |
| 1188 | return false; |
| 1189 | if (isa<UsingShadowDecl>(decl)) |
| 1190 | decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl(); |
| 1191 | |
| 1192 | // Unresolved member expressions should only contain methods and |
| 1193 | // method templates. |
| 1194 | assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl)); |
| 1195 | |
| 1196 | if (isa<FunctionTemplateDecl>(decl)) |
| 1197 | decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl(); |
| 1198 | if (cast<CXXMethodDecl>(decl)->isStatic()) |
| 1199 | return false; |
| 1200 | } while (++begin != end); |
| 1201 | |
| 1202 | return true; |
| 1203 | } |
| 1204 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1205 | UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1206 | bool HasUnresolvedUsing, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1207 | Expr *Base, QualType BaseType, |
| 1208 | bool IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1209 | SourceLocation OperatorLoc, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1210 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1211 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1212 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 30a4f4c | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 1213 | const TemplateArgumentListInfo *TemplateArgs, |
| 1214 | UnresolvedSetIterator Begin, |
| 1215 | UnresolvedSetIterator End) |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1216 | : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc, |
| 1217 | MemberNameInfo, TemplateArgs, Begin, End, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1218 | // Dependent |
| 1219 | ((Base && Base->isTypeDependent()) || |
| 1220 | BaseType->isDependentType()), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1221 | ((Base && Base->isInstantiationDependent()) || |
| 1222 | BaseType->isInstantiationDependentType()), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1223 | // Contains unexpanded parameter pack |
| 1224 | ((Base && Base->containsUnexpandedParameterPack()) || |
| 1225 | BaseType->containsUnexpandedParameterPack())), |
John McCall | 1acbbb5 | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 1226 | IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
| 1227 | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1228 | |
| 1229 | // Check whether all of the members are non-static member functions, |
| 1230 | // and if so, mark give this bound-member type instead of overload type. |
| 1231 | if (hasOnlyNonStaticMemberFunctions(Begin, End)) |
| 1232 | setType(C.BoundMemberTy); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1235 | bool UnresolvedMemberExpr::isImplicitAccess() const { |
| 1236 | if (Base == 0) |
| 1237 | return true; |
| 1238 | |
Douglas Gregor | 25b7e05 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 1239 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1242 | UnresolvedMemberExpr * |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1243 | UnresolvedMemberExpr::Create(ASTContext &C, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1244 | bool HasUnresolvedUsing, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1245 | Expr *Base, QualType BaseType, bool IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1246 | SourceLocation OperatorLoc, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1247 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1248 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1249 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 30a4f4c | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 1250 | const TemplateArgumentListInfo *TemplateArgs, |
| 1251 | UnresolvedSetIterator Begin, |
| 1252 | UnresolvedSetIterator End) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1253 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 1254 | if (TemplateArgs) |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1255 | size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size()); |
| 1256 | else if (TemplateKWLoc.isValid()) |
| 1257 | size += ASTTemplateKWAndArgsInfo::sizeFor(0); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1258 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 1259 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); |
Douglas Gregor | c69978f | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 1260 | return new (Mem) UnresolvedMemberExpr(C, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1261 | HasUnresolvedUsing, Base, BaseType, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1262 | IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1263 | MemberNameInfo, TemplateArgs, Begin, End); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1266 | UnresolvedMemberExpr * |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1267 | UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, |
Douglas Gregor | 87866ce | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 1268 | unsigned NumTemplateArgs) { |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1269 | std::size_t size = sizeof(UnresolvedMemberExpr); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1270 | if (HasTemplateKWAndArgsInfo) |
| 1271 | size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1272 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 1273 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1274 | UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1275 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1276 | return E; |
| 1277 | } |
| 1278 | |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1279 | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { |
| 1280 | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
| 1281 | |
| 1282 | // If there was a nested name specifier, it names the naming class. |
| 1283 | // It can't be dependent: after all, we were actually able to do the |
| 1284 | // lookup. |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1285 | CXXRecordDecl *Record = 0; |
John McCall | 1acbbb5 | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 1286 | if (getQualifier()) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1287 | const Type *T = getQualifier()->getAsType(); |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1288 | assert(T && "qualifier in member expression does not name type"); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1289 | Record = T->getAsCXXRecordDecl(); |
| 1290 | assert(Record && "qualifier in member expression does not name record"); |
| 1291 | } |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1292 | // Otherwise the naming class must have been the base class. |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1293 | else { |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1294 | QualType BaseType = getBaseType().getNonReferenceType(); |
| 1295 | if (isArrow()) { |
| 1296 | const PointerType *PT = BaseType->getAs<PointerType>(); |
| 1297 | assert(PT && "base of arrow member access is not pointer"); |
| 1298 | BaseType = PT->getPointeeType(); |
| 1299 | } |
| 1300 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1301 | Record = BaseType->getAsCXXRecordDecl(); |
| 1302 | assert(Record && "base of member expression does not name record"); |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1305 | return Record; |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1308 | SubstNonTypeTemplateParmPackExpr:: |
| 1309 | SubstNonTypeTemplateParmPackExpr(QualType T, |
| 1310 | NonTypeTemplateParmDecl *Param, |
| 1311 | SourceLocation NameLoc, |
| 1312 | const TemplateArgument &ArgPack) |
| 1313 | : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1314 | true, true, true, true), |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1315 | Param(Param), Arguments(ArgPack.pack_begin()), |
| 1316 | NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { } |
| 1317 | |
| 1318 | TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { |
| 1319 | return TemplateArgument(Arguments, NumArguments); |
| 1320 | } |
| 1321 | |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1322 | FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, |
| 1323 | SourceLocation NameLoc, |
| 1324 | unsigned NumParams, |
| 1325 | Decl * const *Params) |
| 1326 | : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, |
| 1327 | true, true, true, true), |
| 1328 | ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) { |
| 1329 | if (Params) |
| 1330 | std::uninitialized_copy(Params, Params + NumParams, |
| 1331 | reinterpret_cast<Decl**>(this+1)); |
| 1332 | } |
| 1333 | |
| 1334 | FunctionParmPackExpr * |
| 1335 | FunctionParmPackExpr::Create(ASTContext &Context, QualType T, |
| 1336 | ParmVarDecl *ParamPack, SourceLocation NameLoc, |
| 1337 | llvm::ArrayRef<Decl*> Params) { |
| 1338 | return new (Context.Allocate(sizeof(FunctionParmPackExpr) + |
| 1339 | sizeof(ParmVarDecl*) * Params.size())) |
| 1340 | FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data()); |
| 1341 | } |
| 1342 | |
| 1343 | FunctionParmPackExpr * |
| 1344 | FunctionParmPackExpr::CreateEmpty(ASTContext &Context, unsigned NumParams) { |
| 1345 | return new (Context.Allocate(sizeof(FunctionParmPackExpr) + |
| 1346 | sizeof(ParmVarDecl*) * NumParams)) |
| 1347 | FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0); |
| 1348 | } |
| 1349 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 1350 | TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, |
| 1351 | ArrayRef<TypeSourceInfo *> Args, |
| 1352 | SourceLocation RParenLoc, |
| 1353 | bool Value) |
| 1354 | : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary, |
| 1355 | /*TypeDependent=*/false, |
| 1356 | /*ValueDependent=*/false, |
| 1357 | /*InstantiationDependent=*/false, |
| 1358 | /*ContainsUnexpandedParameterPack=*/false), |
| 1359 | Loc(Loc), RParenLoc(RParenLoc) |
| 1360 | { |
| 1361 | TypeTraitExprBits.Kind = Kind; |
| 1362 | TypeTraitExprBits.Value = Value; |
| 1363 | TypeTraitExprBits.NumArgs = Args.size(); |
| 1364 | |
| 1365 | TypeSourceInfo **ToArgs = getTypeSourceInfos(); |
| 1366 | |
| 1367 | for (unsigned I = 0, N = Args.size(); I != N; ++I) { |
| 1368 | if (Args[I]->getType()->isDependentType()) |
| 1369 | setValueDependent(true); |
| 1370 | if (Args[I]->getType()->isInstantiationDependentType()) |
| 1371 | setInstantiationDependent(true); |
| 1372 | if (Args[I]->getType()->containsUnexpandedParameterPack()) |
| 1373 | setContainsUnexpandedParameterPack(true); |
| 1374 | |
| 1375 | ToArgs[I] = Args[I]; |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | TypeTraitExpr *TypeTraitExpr::Create(ASTContext &C, QualType T, |
| 1380 | SourceLocation Loc, |
| 1381 | TypeTrait Kind, |
| 1382 | ArrayRef<TypeSourceInfo *> Args, |
| 1383 | SourceLocation RParenLoc, |
| 1384 | bool Value) { |
| 1385 | unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size(); |
| 1386 | void *Mem = C.Allocate(Size); |
| 1387 | return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value); |
| 1388 | } |
| 1389 | |
| 1390 | TypeTraitExpr *TypeTraitExpr::CreateDeserialized(ASTContext &C, |
| 1391 | unsigned NumArgs) { |
| 1392 | unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs; |
| 1393 | void *Mem = C.Allocate(Size); |
| 1394 | return new (Mem) TypeTraitExpr(EmptyShell()); |
| 1395 | } |
| 1396 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1397 | void ArrayTypeTraitExpr::anchor() { } |