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