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