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