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