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