| 1 | //===- ExprCXX.cpp - (C++) Expression AST Node Implementation -------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the subclesses of Expr class declared in ExprCXX.h |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "clang/AST/ExprCXX.h" |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/Attr.h" |
| 16 | #include "clang/AST/ComparisonCategories.h" |
| 17 | #include "clang/AST/ComputeDependence.h" |
| 18 | #include "clang/AST/Decl.h" |
| 19 | #include "clang/AST/DeclAccessPair.h" |
| 20 | #include "clang/AST/DeclBase.h" |
| 21 | #include "clang/AST/DeclCXX.h" |
| 22 | #include "clang/AST/DeclTemplate.h" |
| 23 | #include "clang/AST/DeclarationName.h" |
| 24 | #include "clang/AST/DependenceFlags.h" |
| 25 | #include "clang/AST/Expr.h" |
| 26 | #include "clang/AST/LambdaCapture.h" |
| 27 | #include "clang/AST/NestedNameSpecifier.h" |
| 28 | #include "clang/AST/TemplateBase.h" |
| 29 | #include "clang/AST/Type.h" |
| 30 | #include "clang/AST/TypeLoc.h" |
| 31 | #include "clang/Basic/LLVM.h" |
| 32 | #include "clang/Basic/OperatorKinds.h" |
| 33 | #include "clang/Basic/SourceLocation.h" |
| 34 | #include "clang/Basic/Specifiers.h" |
| 35 | #include "llvm/ADT/ArrayRef.h" |
| 36 | #include "llvm/Support/ErrorHandling.h" |
| 37 | #include <cassert> |
| 38 | #include <cstddef> |
| 39 | #include <cstring> |
| 40 | #include <memory> |
| 41 | #include <optional> |
| 42 | |
| 43 | using namespace clang; |
| 44 | |
| 45 | //===----------------------------------------------------------------------===// |
| 46 | // Child Iterators for iterating over subexpressions/substatements |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | |
| 49 | bool CXXOperatorCallExpr::isInfixBinaryOp() const { |
| 50 | // An infix binary operator is any operator with two arguments other than |
| 51 | // operator() and operator[]. Note that none of these operators can have |
| 52 | // default arguments, so it suffices to check the number of argument |
| 53 | // expressions. |
| 54 | if (getNumArgs() != 2) |
| 55 | return false; |
| 56 | |
| 57 | switch (getOperator()) { |
| 58 | case OO_Call: case OO_Subscript: |
| 59 | return false; |
| 60 | default: |
| 61 | return true; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | CXXRewrittenBinaryOperator::DecomposedForm |
| 66 | CXXRewrittenBinaryOperator::getDecomposedForm() const { |
| 67 | DecomposedForm Result = {}; |
| 68 | const Expr *E = getSemanticForm()->IgnoreImplicit(); |
| 69 | |
| 70 | // Remove an outer '!' if it exists (only happens for a '!=' rewrite). |
| 71 | bool SkippedNot = false; |
| 72 | if (auto *NotEq = dyn_cast<UnaryOperator>(Val: E)) { |
| 73 | assert(NotEq->getOpcode() == UO_LNot); |
| 74 | E = NotEq->getSubExpr()->IgnoreImplicit(); |
| 75 | SkippedNot = true; |
| 76 | } |
| 77 | |
| 78 | // Decompose the outer binary operator. |
| 79 | if (auto *BO = dyn_cast<BinaryOperator>(Val: E)) { |
| 80 | assert(!SkippedNot || BO->getOpcode() == BO_EQ); |
| 81 | Result.Opcode = SkippedNot ? BO_NE : BO->getOpcode(); |
| 82 | Result.LHS = BO->getLHS(); |
| 83 | Result.RHS = BO->getRHS(); |
| 84 | Result.InnerBinOp = BO; |
| 85 | } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(Val: E)) { |
| 86 | assert(!SkippedNot || BO->getOperator() == OO_EqualEqual); |
| 87 | assert(BO->isInfixBinaryOp()); |
| 88 | switch (BO->getOperator()) { |
| 89 | case OO_Less: Result.Opcode = BO_LT; break; |
| 90 | case OO_LessEqual: Result.Opcode = BO_LE; break; |
| 91 | case OO_Greater: Result.Opcode = BO_GT; break; |
| 92 | case OO_GreaterEqual: Result.Opcode = BO_GE; break; |
| 93 | case OO_Spaceship: Result.Opcode = BO_Cmp; break; |
| 94 | case OO_EqualEqual: Result.Opcode = SkippedNot ? BO_NE : BO_EQ; break; |
| 95 | default: llvm_unreachable("unexpected binop in rewritten operator expr" ); |
| 96 | } |
| 97 | Result.LHS = BO->getArg(Arg: 0); |
| 98 | Result.RHS = BO->getArg(Arg: 1); |
| 99 | Result.InnerBinOp = BO; |
| 100 | } else { |
| 101 | llvm_unreachable("unexpected rewritten operator form" ); |
| 102 | } |
| 103 | |
| 104 | // Put the operands in the right order for == and !=, and canonicalize the |
| 105 | // <=> subexpression onto the LHS for all other forms. |
| 106 | if (isReversed()) |
| 107 | std::swap(a&: Result.LHS, b&: Result.RHS); |
| 108 | |
| 109 | // If this isn't a spaceship rewrite, we're done. |
| 110 | if (Result.Opcode == BO_EQ || Result.Opcode == BO_NE) |
| 111 | return Result; |
| 112 | |
| 113 | // Otherwise, we expect a <=> to now be on the LHS. |
| 114 | E = Result.LHS->IgnoreUnlessSpelledInSource(); |
| 115 | if (auto *BO = dyn_cast<BinaryOperator>(Val: E)) { |
| 116 | assert(BO->getOpcode() == BO_Cmp); |
| 117 | Result.LHS = BO->getLHS(); |
| 118 | Result.RHS = BO->getRHS(); |
| 119 | Result.InnerBinOp = BO; |
| 120 | } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(Val: E)) { |
| 121 | assert(BO->getOperator() == OO_Spaceship); |
| 122 | Result.LHS = BO->getArg(Arg: 0); |
| 123 | Result.RHS = BO->getArg(Arg: 1); |
| 124 | Result.InnerBinOp = BO; |
| 125 | } else { |
| 126 | llvm_unreachable("unexpected rewritten operator form" ); |
| 127 | } |
| 128 | |
| 129 | // Put the comparison operands in the right order. |
| 130 | if (isReversed()) |
| 131 | std::swap(a&: Result.LHS, b&: Result.RHS); |
| 132 | return Result; |
| 133 | } |
| 134 | |
| 135 | bool CXXTypeidExpr::isPotentiallyEvaluated() const { |
| 136 | if (isTypeOperand()) |
| 137 | return false; |
| 138 | |
| 139 | // C++11 [expr.typeid]p3: |
| 140 | // When typeid is applied to an expression other than a glvalue of |
| 141 | // polymorphic class type, [...] the expression is an unevaluated operand. |
| 142 | const Expr *E = getExprOperand(); |
| 143 | if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl()) |
| 144 | if (RD->isPolymorphic() && E->isGLValue()) |
| 145 | return true; |
| 146 | |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | bool CXXTypeidExpr::isMostDerived(const ASTContext &Context) const { |
| 151 | assert(!isTypeOperand() && "Cannot call isMostDerived for typeid(type)" ); |
| 152 | const Expr *E = getExprOperand()->IgnoreParenNoopCasts(Ctx: Context); |
| 153 | |
| 154 | if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl()) |
| 155 | if (RD->isEffectivelyFinal()) |
| 156 | return true; |
| 157 | |
| 158 | if (const auto *DRE = dyn_cast<DeclRefExpr>(Val: E)) { |
| 159 | QualType Ty = DRE->getDecl()->getType(); |
| 160 | if (!Ty->isPointerOrReferenceType()) |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | QualType CXXTypeidExpr::getTypeOperand(const ASTContext &Context) const { |
| 168 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)" ); |
| 169 | Qualifiers Quals; |
| 170 | return Context.getUnqualifiedArrayType( |
| 171 | T: cast<TypeSourceInfo *>(Val: Operand)->getType().getNonReferenceType(), Quals); |
| 172 | } |
| 173 | |
| 174 | static bool isGLValueFromPointerDeref(const Expr *E) { |
| 175 | E = E->IgnoreParens(); |
| 176 | |
| 177 | if (const auto *CE = dyn_cast<CastExpr>(Val: E)) { |
| 178 | if (!CE->getSubExpr()->isGLValue()) |
| 179 | return false; |
| 180 | return isGLValueFromPointerDeref(E: CE->getSubExpr()); |
| 181 | } |
| 182 | |
| 183 | if (const auto *OVE = dyn_cast<OpaqueValueExpr>(Val: E)) |
| 184 | return isGLValueFromPointerDeref(E: OVE->getSourceExpr()); |
| 185 | |
| 186 | if (const auto *BO = dyn_cast<BinaryOperator>(Val: E)) |
| 187 | if (BO->getOpcode() == BO_Comma) |
| 188 | return isGLValueFromPointerDeref(E: BO->getRHS()); |
| 189 | |
| 190 | if (const auto *ACO = dyn_cast<AbstractConditionalOperator>(Val: E)) |
| 191 | return isGLValueFromPointerDeref(E: ACO->getTrueExpr()) || |
| 192 | isGLValueFromPointerDeref(E: ACO->getFalseExpr()); |
| 193 | |
| 194 | // C++11 [expr.sub]p1: |
| 195 | // The expression E1[E2] is identical (by definition) to *((E1)+(E2)) |
| 196 | if (isa<ArraySubscriptExpr>(Val: E)) |
| 197 | return true; |
| 198 | |
| 199 | if (const auto *UO = dyn_cast<UnaryOperator>(Val: E)) |
| 200 | if (UO->getOpcode() == UO_Deref) |
| 201 | return true; |
| 202 | |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | bool CXXTypeidExpr::hasNullCheck() const { |
| 207 | if (!isPotentiallyEvaluated()) |
| 208 | return false; |
| 209 | |
| 210 | // C++ [expr.typeid]p2: |
| 211 | // If the glvalue expression is obtained by applying the unary * operator to |
| 212 | // a pointer and the pointer is a null pointer value, the typeid expression |
| 213 | // throws the std::bad_typeid exception. |
| 214 | // |
| 215 | // However, this paragraph's intent is not clear. We choose a very generous |
| 216 | // interpretation which implores us to consider comma operators, conditional |
| 217 | // operators, parentheses and other such constructs. |
| 218 | return isGLValueFromPointerDeref(E: getExprOperand()); |
| 219 | } |
| 220 | |
| 221 | QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const { |
| 222 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)" ); |
| 223 | Qualifiers Quals; |
| 224 | return Context.getUnqualifiedArrayType( |
| 225 | T: cast<TypeSourceInfo *>(Val: Operand)->getType().getNonReferenceType(), Quals); |
| 226 | } |
| 227 | |
| 228 | // CXXScalarValueInitExpr |
| 229 | SourceLocation CXXScalarValueInitExpr::getBeginLoc() const { |
| 230 | return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : getRParenLoc(); |
| 231 | } |
| 232 | |
| 233 | // CXXNewExpr |
| 234 | CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, |
| 235 | FunctionDecl *OperatorDelete, |
| 236 | const ImplicitAllocationParameters &IAP, |
| 237 | bool UsualArrayDeleteWantsSize, |
| 238 | ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens, |
| 239 | std::optional<Expr *> ArraySize, |
| 240 | CXXNewInitializationStyle InitializationStyle, |
| 241 | Expr *Initializer, QualType Ty, |
| 242 | TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, |
| 243 | SourceRange DirectInitRange) |
| 244 | : Expr(CXXNewExprClass, Ty, VK_PRValue, OK_Ordinary), |
| 245 | OperatorNew(OperatorNew), OperatorDelete(OperatorDelete), |
| 246 | AllocatedTypeInfo(AllocatedTypeInfo), Range(Range), |
| 247 | DirectInitRange(DirectInitRange) { |
| 248 | |
| 249 | assert((Initializer != nullptr || |
| 250 | InitializationStyle == CXXNewInitializationStyle::None) && |
| 251 | "Only CXXNewInitializationStyle::None can have no initializer!" ); |
| 252 | |
| 253 | CXXNewExprBits.IsGlobalNew = IsGlobalNew; |
| 254 | CXXNewExprBits.IsArray = ArraySize.has_value(); |
| 255 | CXXNewExprBits.ShouldPassAlignment = isAlignedAllocation(Mode: IAP.PassAlignment); |
| 256 | CXXNewExprBits.ShouldPassTypeIdentity = |
| 257 | isTypeAwareAllocation(Mode: IAP.PassTypeIdentity); |
| 258 | CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize; |
| 259 | CXXNewExprBits.HasInitializer = Initializer != nullptr; |
| 260 | CXXNewExprBits.StoredInitializationStyle = |
| 261 | llvm::to_underlying(E: InitializationStyle); |
| 262 | bool IsParenTypeId = TypeIdParens.isValid(); |
| 263 | CXXNewExprBits.IsParenTypeId = IsParenTypeId; |
| 264 | CXXNewExprBits.NumPlacementArgs = PlacementArgs.size(); |
| 265 | |
| 266 | if (ArraySize) |
| 267 | getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize; |
| 268 | if (Initializer) |
| 269 | getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer; |
| 270 | llvm::copy(Range&: PlacementArgs, |
| 271 | Out: getTrailingObjects<Stmt *>() + placementNewArgsOffset()); |
| 272 | if (IsParenTypeId) |
| 273 | getTrailingObjects<SourceRange>()[0] = TypeIdParens; |
| 274 | |
| 275 | switch (getInitializationStyle()) { |
| 276 | case CXXNewInitializationStyle::Parens: |
| 277 | this->Range.setEnd(DirectInitRange.getEnd()); |
| 278 | break; |
| 279 | case CXXNewInitializationStyle::Braces: |
| 280 | this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); |
| 281 | break; |
| 282 | default: |
| 283 | if (IsParenTypeId) |
| 284 | this->Range.setEnd(TypeIdParens.getEnd()); |
| 285 | break; |
| 286 | } |
| 287 | |
| 288 | setDependence(computeDependence(E: this)); |
| 289 | } |
| 290 | |
| 291 | CXXNewExpr::CXXNewExpr(EmptyShell Empty, bool IsArray, |
| 292 | unsigned NumPlacementArgs, bool IsParenTypeId) |
| 293 | : Expr(CXXNewExprClass, Empty) { |
| 294 | CXXNewExprBits.IsArray = IsArray; |
| 295 | CXXNewExprBits.NumPlacementArgs = NumPlacementArgs; |
| 296 | CXXNewExprBits.IsParenTypeId = IsParenTypeId; |
| 297 | } |
| 298 | |
| 299 | CXXNewExpr *CXXNewExpr::Create( |
| 300 | const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, |
| 301 | FunctionDecl *OperatorDelete, const ImplicitAllocationParameters &IAP, |
| 302 | bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, |
| 303 | SourceRange TypeIdParens, std::optional<Expr *> ArraySize, |
| 304 | CXXNewInitializationStyle InitializationStyle, Expr *Initializer, |
| 305 | QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, |
| 306 | SourceRange DirectInitRange) { |
| 307 | bool IsArray = ArraySize.has_value(); |
| 308 | bool HasInit = Initializer != nullptr; |
| 309 | unsigned NumPlacementArgs = PlacementArgs.size(); |
| 310 | bool IsParenTypeId = TypeIdParens.isValid(); |
| 311 | void *Mem = |
| 312 | Ctx.Allocate(Size: totalSizeToAlloc<Stmt *, SourceRange>( |
| 313 | Counts: IsArray + HasInit + NumPlacementArgs, Counts: IsParenTypeId), |
| 314 | Align: alignof(CXXNewExpr)); |
| 315 | return new (Mem) CXXNewExpr( |
| 316 | IsGlobalNew, OperatorNew, OperatorDelete, IAP, UsualArrayDeleteWantsSize, |
| 317 | PlacementArgs, TypeIdParens, ArraySize, InitializationStyle, Initializer, |
| 318 | Ty, AllocatedTypeInfo, Range, DirectInitRange); |
| 319 | } |
| 320 | |
| 321 | CXXNewExpr *CXXNewExpr::CreateEmpty(const ASTContext &Ctx, bool IsArray, |
| 322 | bool HasInit, unsigned NumPlacementArgs, |
| 323 | bool IsParenTypeId) { |
| 324 | void *Mem = |
| 325 | Ctx.Allocate(Size: totalSizeToAlloc<Stmt *, SourceRange>( |
| 326 | Counts: IsArray + HasInit + NumPlacementArgs, Counts: IsParenTypeId), |
| 327 | Align: alignof(CXXNewExpr)); |
| 328 | return new (Mem) |
| 329 | CXXNewExpr(EmptyShell(), IsArray, NumPlacementArgs, IsParenTypeId); |
| 330 | } |
| 331 | |
| 332 | bool CXXNewExpr::shouldNullCheckAllocation() const { |
| 333 | if (getOperatorNew()->getLangOpts().CheckNew) |
| 334 | return true; |
| 335 | return !getOperatorNew()->hasAttr<ReturnsNonNullAttr>() && |
| 336 | getOperatorNew() |
| 337 | ->getType() |
| 338 | ->castAs<FunctionProtoType>() |
| 339 | ->isNothrow() && |
| 340 | !getOperatorNew()->isReservedGlobalPlacementOperator(); |
| 341 | } |
| 342 | |
| 343 | // CXXDeleteExpr |
| 344 | QualType CXXDeleteExpr::getDestroyedType() const { |
| 345 | const Expr *Arg = getArgument(); |
| 346 | |
| 347 | // For a destroying operator delete, we may have implicitly converted the |
| 348 | // pointer type to the type of the parameter of the 'operator delete' |
| 349 | // function. |
| 350 | while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Val: Arg)) { |
| 351 | if (ICE->getCastKind() == CK_DerivedToBase || |
| 352 | ICE->getCastKind() == CK_UncheckedDerivedToBase || |
| 353 | ICE->getCastKind() == CK_NoOp) { |
| 354 | assert((ICE->getCastKind() == CK_NoOp || |
| 355 | getOperatorDelete()->isDestroyingOperatorDelete()) && |
| 356 | "only a destroying operator delete can have a converted arg" ); |
| 357 | Arg = ICE->getSubExpr(); |
| 358 | } else |
| 359 | break; |
| 360 | } |
| 361 | |
| 362 | // The type-to-delete may not be a pointer if it's a dependent type. |
| 363 | const QualType ArgType = Arg->getType(); |
| 364 | |
| 365 | if (ArgType->isDependentType() && !ArgType->isPointerType()) |
| 366 | return QualType(); |
| 367 | |
| 368 | return ArgType->castAs<PointerType>()->getPointeeType(); |
| 369 | } |
| 370 | |
| 371 | // CXXPseudoDestructorExpr |
| 372 | PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) |
| 373 | : Type(Info) { |
| 374 | Location = Info->getTypeLoc().getBeginLoc(); |
| 375 | } |
| 376 | |
| 377 | CXXPseudoDestructorExpr::CXXPseudoDestructorExpr( |
| 378 | const ASTContext &Context, Expr *Base, bool isArrow, |
| 379 | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
| 380 | TypeSourceInfo *ScopeType, SourceLocation ColonColonLoc, |
| 381 | SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType) |
| 382 | : Expr(CXXPseudoDestructorExprClass, Context.BoundMemberTy, VK_PRValue, |
| 383 | OK_Ordinary), |
| 384 | Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), |
| 385 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
| 386 | ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), |
| 387 | DestroyedType(DestroyedType) { |
| 388 | setDependence(computeDependence(E: this)); |
| 389 | } |
| 390 | |
| 391 | QualType CXXPseudoDestructorExpr::getDestroyedType() const { |
| 392 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
| 393 | return TInfo->getType(); |
| 394 | |
| 395 | return QualType(); |
| 396 | } |
| 397 | |
| 398 | SourceLocation CXXPseudoDestructorExpr::getEndLoc() const { |
| 399 | SourceLocation End = DestroyedType.getLocation(); |
| 400 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
| 401 | End = TInfo->getTypeLoc().getSourceRange().getEnd(); |
| 402 | return End; |
| 403 | } |
| 404 | |
| 405 | DependentTemplateIdExpr::DependentTemplateIdExpr( |
| 406 | const ASTContext &Context, const DeclarationNameInfo &NameInfo, |
| 407 | TemplateName Name, const TemplateArgumentListInfo &TemplateArgs) |
| 408 | : Expr(DependentTemplateIdExprClass, Context.DependentTy, VK_LValue, |
| 409 | OK_Ordinary), |
| 410 | NameInfo(NameInfo), Name(Name) { |
| 411 | KWAndArgs.initializeFrom(/*TemplateKWLoc=*/{}, List: TemplateArgs, |
| 412 | OutArgArray: getTrailingObjects()); |
| 413 | setDependence(computeDependence(E: this)); |
| 414 | } |
| 415 | |
| 416 | DependentTemplateIdExpr::DependentTemplateIdExpr(EmptyShell Empty, |
| 417 | unsigned NumTemplateArgs) |
| 418 | : Expr(DependentTemplateIdExprClass, Empty) { |
| 419 | KWAndArgs.NumTemplateArgs = NumTemplateArgs; |
| 420 | } |
| 421 | |
| 422 | DependentTemplateIdExpr *DependentTemplateIdExpr::Create( |
| 423 | const ASTContext &Context, const DeclarationNameInfo &NameInfo, |
| 424 | TemplateName Name, const TemplateArgumentListInfo &TemplateArgs) { |
| 425 | void *Mem = Context.Allocate( |
| 426 | Size: totalSizeToAlloc<TemplateArgumentLoc>(Counts: TemplateArgs.size()), |
| 427 | Align: alignof(DependentTemplateIdExpr)); |
| 428 | return new (Mem) |
| 429 | DependentTemplateIdExpr(Context, NameInfo, Name, TemplateArgs); |
| 430 | } |
| 431 | |
| 432 | DependentTemplateIdExpr * |
| 433 | DependentTemplateIdExpr::CreateEmpty(const ASTContext &Context, |
| 434 | unsigned NumTemplateArgs) { |
| 435 | void *Mem = |
| 436 | Context.Allocate(Size: totalSizeToAlloc<TemplateArgumentLoc>(Counts: NumTemplateArgs), |
| 437 | Align: alignof(DependentTemplateIdExpr)); |
| 438 | return new (Mem) DependentTemplateIdExpr(EmptyShell(), NumTemplateArgs); |
| 439 | } |
| 440 | |
| 441 | // UnresolvedLookupExpr |
| 442 | UnresolvedLookupExpr::UnresolvedLookupExpr( |
| 443 | const ASTContext &Context, CXXRecordDecl *NamingClass, |
| 444 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
| 445 | const DeclarationNameInfo &NameInfo, bool RequiresADL, |
| 446 | const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, |
| 447 | UnresolvedSetIterator End, bool KnownDependent, |
| 448 | bool KnownInstantiationDependent) |
| 449 | : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc, |
| 450 | TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, |
| 451 | KnownDependent, KnownInstantiationDependent, |
| 452 | /*KnownContainsUnexpandedParameterPack=*/false), |
| 453 | NamingClass(NamingClass) { |
| 454 | UnresolvedLookupExprBits.RequiresADL = RequiresADL; |
| 455 | } |
| 456 | |
| 457 | UnresolvedLookupExpr::UnresolvedLookupExpr(EmptyShell Empty, |
| 458 | unsigned NumResults, |
| 459 | bool HasTemplateKWAndArgsInfo) |
| 460 | : OverloadExpr(UnresolvedLookupExprClass, Empty, NumResults, |
| 461 | HasTemplateKWAndArgsInfo) {} |
| 462 | |
| 463 | UnresolvedLookupExpr *UnresolvedLookupExpr::Create( |
| 464 | const ASTContext &Context, CXXRecordDecl *NamingClass, |
| 465 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
| 466 | bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, |
| 467 | bool KnownDependent, bool KnownInstantiationDependent) { |
| 468 | unsigned NumResults = End - Begin; |
| 469 | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
| 470 | TemplateArgumentLoc>(Counts: NumResults, Counts: 0, Counts: 0); |
| 471 | void *Mem = Context.Allocate(Size, Align: alignof(UnresolvedLookupExpr)); |
| 472 | return new (Mem) UnresolvedLookupExpr( |
| 473 | Context, NamingClass, QualifierLoc, |
| 474 | /*TemplateKWLoc=*/SourceLocation(), NameInfo, RequiresADL, |
| 475 | /*TemplateArgs=*/nullptr, Begin, End, KnownDependent, |
| 476 | KnownInstantiationDependent); |
| 477 | } |
| 478 | |
| 479 | UnresolvedLookupExpr *UnresolvedLookupExpr::Create( |
| 480 | const ASTContext &Context, CXXRecordDecl *NamingClass, |
| 481 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
| 482 | const DeclarationNameInfo &NameInfo, bool RequiresADL, |
| 483 | const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin, |
| 484 | UnresolvedSetIterator End, bool KnownDependent, |
| 485 | bool KnownInstantiationDependent) { |
| 486 | unsigned NumResults = End - Begin; |
| 487 | bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid(); |
| 488 | unsigned NumTemplateArgs = Args ? Args->size() : 0; |
| 489 | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
| 490 | TemplateArgumentLoc>( |
| 491 | Counts: NumResults, Counts: HasTemplateKWAndArgsInfo, Counts: NumTemplateArgs); |
| 492 | void *Mem = Context.Allocate(Size, Align: alignof(UnresolvedLookupExpr)); |
| 493 | return new (Mem) UnresolvedLookupExpr( |
| 494 | Context, NamingClass, QualifierLoc, TemplateKWLoc, NameInfo, RequiresADL, |
| 495 | Args, Begin, End, KnownDependent, KnownInstantiationDependent); |
| 496 | } |
| 497 | |
| 498 | UnresolvedLookupExpr *UnresolvedLookupExpr::CreateEmpty( |
| 499 | const ASTContext &Context, unsigned NumResults, |
| 500 | bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) { |
| 501 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
| 502 | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
| 503 | TemplateArgumentLoc>( |
| 504 | Counts: NumResults, Counts: HasTemplateKWAndArgsInfo, Counts: NumTemplateArgs); |
| 505 | void *Mem = Context.Allocate(Size, Align: alignof(UnresolvedLookupExpr)); |
| 506 | return new (Mem) |
| 507 | UnresolvedLookupExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo); |
| 508 | } |
| 509 | |
| 510 | OverloadExpr::OverloadExpr(StmtClass SC, const ASTContext &Context, |
| 511 | NestedNameSpecifierLoc QualifierLoc, |
| 512 | SourceLocation TemplateKWLoc, |
| 513 | const DeclarationNameInfo &NameInfo, |
| 514 | const TemplateArgumentListInfo *TemplateArgs, |
| 515 | UnresolvedSetIterator Begin, |
| 516 | UnresolvedSetIterator End, bool KnownDependent, |
| 517 | bool KnownInstantiationDependent, |
| 518 | bool KnownContainsUnexpandedParameterPack) |
| 519 | : Expr(SC, Context.OverloadTy, VK_LValue, OK_Ordinary), NameInfo(NameInfo), |
| 520 | QualifierLoc(QualifierLoc) { |
| 521 | unsigned NumResults = End - Begin; |
| 522 | OverloadExprBits.NumResults = NumResults; |
| 523 | OverloadExprBits.HasTemplateKWAndArgsInfo = |
| 524 | (TemplateArgs != nullptr ) || TemplateKWLoc.isValid(); |
| 525 | |
| 526 | if (NumResults) { |
| 527 | // Copy the results to the trailing array past UnresolvedLookupExpr |
| 528 | // or UnresolvedMemberExpr. |
| 529 | DeclAccessPair *Results = getTrailingResults(); |
| 530 | memcpy(dest: Results, src: Begin.I, n: NumResults * sizeof(DeclAccessPair)); |
| 531 | } |
| 532 | |
| 533 | if (TemplateArgs) { |
| 534 | auto Deps = TemplateArgumentDependence::None; |
| 535 | getTrailingASTTemplateKWAndArgsInfo()->initializeFrom( |
| 536 | TemplateKWLoc, List: *TemplateArgs, OutArgArray: getTrailingTemplateArgumentLoc(), Deps); |
| 537 | } else if (TemplateKWLoc.isValid()) { |
| 538 | getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
| 539 | } |
| 540 | |
| 541 | setDependence(computeDependence(E: this, KnownDependent, |
| 542 | KnownInstantiationDependent, |
| 543 | KnownContainsUnexpandedParameterPack)); |
| 544 | if (isTypeDependent()) |
| 545 | setType(Context.DependentTy); |
| 546 | } |
| 547 | |
| 548 | OverloadExpr::OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults, |
| 549 | bool HasTemplateKWAndArgsInfo) |
| 550 | : Expr(SC, Empty) { |
| 551 | OverloadExprBits.NumResults = NumResults; |
| 552 | OverloadExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
| 553 | } |
| 554 | |
| 555 | // DependentScopeDeclRefExpr |
| 556 | DependentScopeDeclRefExpr::DependentScopeDeclRefExpr( |
| 557 | QualType Ty, NestedNameSpecifierLoc QualifierLoc, |
| 558 | SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, |
| 559 | const TemplateArgumentListInfo *Args) |
| 560 | : Expr(DependentScopeDeclRefExprClass, Ty, VK_LValue, OK_Ordinary), |
| 561 | QualifierLoc(QualifierLoc), NameInfo(NameInfo) { |
| 562 | DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo = |
| 563 | (Args != nullptr) || TemplateKWLoc.isValid(); |
| 564 | if (Args) { |
| 565 | auto Deps = TemplateArgumentDependence::None; |
| 566 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
| 567 | TemplateKWLoc, List: *Args, OutArgArray: getTrailingObjects<TemplateArgumentLoc>(), Deps); |
| 568 | } else if (TemplateKWLoc.isValid()) { |
| 569 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
| 570 | TemplateKWLoc); |
| 571 | } |
| 572 | setDependence(computeDependence(E: this)); |
| 573 | } |
| 574 | |
| 575 | DependentScopeDeclRefExpr *DependentScopeDeclRefExpr::Create( |
| 576 | const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, |
| 577 | SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, |
| 578 | const TemplateArgumentListInfo *Args) { |
| 579 | assert(QualifierLoc && "should be created for dependent qualifiers" ); |
| 580 | bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid(); |
| 581 | std::size_t Size = |
| 582 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 583 | Counts: HasTemplateKWAndArgsInfo, Counts: Args ? Args->size() : 0); |
| 584 | void *Mem = Context.Allocate(Size); |
| 585 | return new (Mem) DependentScopeDeclRefExpr(Context.DependentTy, QualifierLoc, |
| 586 | TemplateKWLoc, NameInfo, Args); |
| 587 | } |
| 588 | |
| 589 | DependentScopeDeclRefExpr * |
| 590 | DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &Context, |
| 591 | bool HasTemplateKWAndArgsInfo, |
| 592 | unsigned NumTemplateArgs) { |
| 593 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
| 594 | std::size_t Size = |
| 595 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 596 | Counts: HasTemplateKWAndArgsInfo, Counts: NumTemplateArgs); |
| 597 | void *Mem = Context.Allocate(Size); |
| 598 | auto *E = new (Mem) DependentScopeDeclRefExpr( |
| 599 | QualType(), NestedNameSpecifierLoc(), SourceLocation(), |
| 600 | DeclarationNameInfo(), nullptr); |
| 601 | E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo = |
| 602 | HasTemplateKWAndArgsInfo; |
| 603 | return E; |
| 604 | } |
| 605 | |
| 606 | SourceLocation CXXConstructExpr::getBeginLoc() const { |
| 607 | if (const auto *TOE = dyn_cast<CXXTemporaryObjectExpr>(Val: this)) |
| 608 | return TOE->getBeginLoc(); |
| 609 | return getLocation(); |
| 610 | } |
| 611 | |
| 612 | SourceLocation CXXConstructExpr::getEndLoc() const { |
| 613 | if (const auto *TOE = dyn_cast<CXXTemporaryObjectExpr>(Val: this)) |
| 614 | return TOE->getEndLoc(); |
| 615 | |
| 616 | if (ParenOrBraceRange.isValid()) |
| 617 | return ParenOrBraceRange.getEnd(); |
| 618 | |
| 619 | SourceLocation End = getLocation(); |
| 620 | for (unsigned I = getNumArgs(); I > 0; --I) { |
| 621 | const Expr *Arg = getArg(Arg: I-1); |
| 622 | if (!Arg->isDefaultArgument()) { |
| 623 | SourceLocation NewEnd = Arg->getEndLoc(); |
| 624 | if (NewEnd.isValid()) { |
| 625 | End = NewEnd; |
| 626 | break; |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | return End; |
| 632 | } |
| 633 | |
| 634 | CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind, |
| 635 | Expr *Fn, ArrayRef<Expr *> Args, |
| 636 | QualType Ty, ExprValueKind VK, |
| 637 | SourceLocation OperatorLoc, |
| 638 | FPOptionsOverride FPFeatures, |
| 639 | ADLCallKind UsesADL, bool IsReversed) |
| 640 | : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, |
| 641 | OperatorLoc, FPFeatures, /*MinNumArgs=*/0, UsesADL) { |
| 642 | CXXOperatorCallExprBits.OperatorKind = OpKind; |
| 643 | CXXOperatorCallExprBits.IsReversed = IsReversed; |
| 644 | assert( |
| 645 | (CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) && |
| 646 | "OperatorKind overflow!" ); |
| 647 | BeginLoc = getSourceRangeImpl().getBegin(); |
| 648 | } |
| 649 | |
| 650 | CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, bool HasFPFeatures, |
| 651 | EmptyShell Empty) |
| 652 | : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs, |
| 653 | HasFPFeatures, Empty) {} |
| 654 | |
| 655 | CXXOperatorCallExpr *CXXOperatorCallExpr::Create( |
| 656 | const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, |
| 657 | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
| 658 | SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, |
| 659 | ADLCallKind UsesADL, bool IsReversed) { |
| 660 | // Allocate storage for the trailing objects of CallExpr. |
| 661 | unsigned NumArgs = Args.size(); |
| 662 | unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects( |
| 663 | /*NumPreArgs=*/0, NumArgs, HasFPFeatures: FPFeatures.requiresTrailingStorage()); |
| 664 | void *Mem = |
| 665 | Ctx.Allocate(Size: sizeToAllocateForCallExprSubclass<CXXOperatorCallExpr>( |
| 666 | SizeOfTrailingObjects), |
| 667 | Align: alignof(CXXOperatorCallExpr)); |
| 668 | return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc, |
| 669 | FPFeatures, UsesADL, IsReversed); |
| 670 | } |
| 671 | |
| 672 | CXXOperatorCallExpr *CXXOperatorCallExpr::CreateEmpty(const ASTContext &Ctx, |
| 673 | unsigned NumArgs, |
| 674 | bool HasFPFeatures, |
| 675 | EmptyShell Empty) { |
| 676 | // Allocate storage for the trailing objects of CallExpr. |
| 677 | unsigned SizeOfTrailingObjects = |
| 678 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures); |
| 679 | void *Mem = |
| 680 | Ctx.Allocate(Size: sizeToAllocateForCallExprSubclass<CXXOperatorCallExpr>( |
| 681 | SizeOfTrailingObjects), |
| 682 | Align: alignof(CXXOperatorCallExpr)); |
| 683 | return new (Mem) CXXOperatorCallExpr(NumArgs, HasFPFeatures, Empty); |
| 684 | } |
| 685 | |
| 686 | SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { |
| 687 | OverloadedOperatorKind Kind = getOperator(); |
| 688 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 689 | if (getNumArgs() == 1) |
| 690 | // Prefix operator |
| 691 | return SourceRange(getOperatorLoc(), getArg(Arg: 0)->getEndLoc()); |
| 692 | else |
| 693 | // Postfix operator |
| 694 | return SourceRange(getArg(Arg: 0)->getBeginLoc(), getOperatorLoc()); |
| 695 | } else if (Kind == OO_Arrow) { |
| 696 | return SourceRange(getArg(Arg: 0)->getBeginLoc(), getOperatorLoc()); |
| 697 | } else if (Kind == OO_Call) { |
| 698 | return SourceRange(getArg(Arg: 0)->getBeginLoc(), getRParenLoc()); |
| 699 | } else if (Kind == OO_Subscript) { |
| 700 | return SourceRange(getArg(Arg: 0)->getBeginLoc(), getRParenLoc()); |
| 701 | } else if (getNumArgs() == 1) { |
| 702 | return SourceRange(getOperatorLoc(), getArg(Arg: 0)->getEndLoc()); |
| 703 | } else if (getNumArgs() == 2) { |
| 704 | if (CXXOperatorCallExprBits.IsReversed) |
| 705 | return SourceRange(getArg(Arg: 1)->getBeginLoc(), getArg(Arg: 0)->getEndLoc()); |
| 706 | return SourceRange(getArg(Arg: 0)->getBeginLoc(), getArg(Arg: 1)->getEndLoc()); |
| 707 | } else { |
| 708 | return getOperatorLoc(); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args, |
| 713 | QualType Ty, ExprValueKind VK, |
| 714 | SourceLocation RP, |
| 715 | FPOptionsOverride FPOptions, |
| 716 | unsigned MinNumArgs) |
| 717 | : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP, |
| 718 | FPOptions, MinNumArgs, NotADL) {} |
| 719 | |
| 720 | CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, bool HasFPFeatures, |
| 721 | EmptyShell Empty) |
| 722 | : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures, |
| 723 | Empty) {} |
| 724 | |
| 725 | CXXMemberCallExpr *CXXMemberCallExpr::Create(const ASTContext &Ctx, Expr *Fn, |
| 726 | ArrayRef<Expr *> Args, QualType Ty, |
| 727 | ExprValueKind VK, |
| 728 | SourceLocation RP, |
| 729 | FPOptionsOverride FPFeatures, |
| 730 | unsigned MinNumArgs) { |
| 731 | // Allocate storage for the trailing objects of CallExpr. |
| 732 | unsigned NumArgs = std::max<unsigned>(a: Args.size(), b: MinNumArgs); |
| 733 | unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects( |
| 734 | /*NumPreArgs=*/0, NumArgs, HasFPFeatures: FPFeatures.requiresTrailingStorage()); |
| 735 | void *Mem = Ctx.Allocate(Size: sizeToAllocateForCallExprSubclass<CXXMemberCallExpr>( |
| 736 | SizeOfTrailingObjects), |
| 737 | Align: alignof(CXXMemberCallExpr)); |
| 738 | return new (Mem) |
| 739 | CXXMemberCallExpr(Fn, Args, Ty, VK, RP, FPFeatures, MinNumArgs); |
| 740 | } |
| 741 | |
| 742 | CXXMemberCallExpr *CXXMemberCallExpr::CreateEmpty(const ASTContext &Ctx, |
| 743 | unsigned NumArgs, |
| 744 | bool HasFPFeatures, |
| 745 | EmptyShell Empty) { |
| 746 | // Allocate storage for the trailing objects of CallExpr. |
| 747 | unsigned SizeOfTrailingObjects = |
| 748 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures); |
| 749 | void *Mem = Ctx.Allocate(Size: sizeToAllocateForCallExprSubclass<CXXMemberCallExpr>( |
| 750 | SizeOfTrailingObjects), |
| 751 | Align: alignof(CXXMemberCallExpr)); |
| 752 | return new (Mem) CXXMemberCallExpr(NumArgs, HasFPFeatures, Empty); |
| 753 | } |
| 754 | |
| 755 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { |
| 756 | const Expr *Callee = getCallee()->IgnoreParens(); |
| 757 | if (const auto *MemExpr = dyn_cast<MemberExpr>(Val: Callee)) |
| 758 | return MemExpr->getBase(); |
| 759 | if (const auto *BO = dyn_cast<BinaryOperator>(Val: Callee)) |
| 760 | if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI) |
| 761 | return BO->getLHS(); |
| 762 | |
| 763 | // FIXME: Will eventually need to cope with member pointers. |
| 764 | return nullptr; |
| 765 | } |
| 766 | |
| 767 | QualType CXXMemberCallExpr::getObjectType() const { |
| 768 | QualType Ty = getImplicitObjectArgument()->getType(); |
| 769 | if (Ty->isPointerType()) |
| 770 | Ty = Ty->getPointeeType(); |
| 771 | return Ty; |
| 772 | } |
| 773 | |
| 774 | CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { |
| 775 | if (const auto *MemExpr = dyn_cast<MemberExpr>(Val: getCallee()->IgnoreParens())) |
| 776 | return cast<CXXMethodDecl>(Val: MemExpr->getMemberDecl()); |
| 777 | |
| 778 | // FIXME: Will eventually need to cope with member pointers. |
| 779 | // NOTE: Update makeTailCallIfSwiftAsync on fixing this. |
| 780 | return nullptr; |
| 781 | } |
| 782 | |
| 783 | CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const { |
| 784 | Expr* ThisArg = getImplicitObjectArgument(); |
| 785 | if (!ThisArg) |
| 786 | return nullptr; |
| 787 | |
| 788 | if (ThisArg->getType()->isAnyPointerType()) |
| 789 | return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl(); |
| 790 | |
| 791 | return ThisArg->getType()->getAsCXXRecordDecl(); |
| 792 | } |
| 793 | |
| 794 | //===----------------------------------------------------------------------===// |
| 795 | // Named casts |
| 796 | //===----------------------------------------------------------------------===// |
| 797 | |
| 798 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 799 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 800 | /// "const_cast". The returned pointer must not be freed. |
| 801 | const char *CXXNamedCastExpr::getCastName() const { |
| 802 | switch (getStmtClass()) { |
| 803 | case CXXStaticCastExprClass: return "static_cast" ; |
| 804 | case CXXDynamicCastExprClass: return "dynamic_cast" ; |
| 805 | case CXXReinterpretCastExprClass: return "reinterpret_cast" ; |
| 806 | case CXXConstCastExprClass: return "const_cast" ; |
| 807 | case CXXAddrspaceCastExprClass: return "addrspace_cast" ; |
| 808 | default: return "<invalid cast>" ; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | CXXStaticCastExpr * |
| 813 | CXXStaticCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, |
| 814 | CastKind K, Expr *Op, const CXXCastPath *BasePath, |
| 815 | TypeSourceInfo *WrittenTy, FPOptionsOverride FPO, |
| 816 | SourceLocation L, SourceLocation RParenLoc, |
| 817 | SourceRange AngleBrackets) { |
| 818 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 819 | void *Buffer = |
| 820 | C.Allocate(Size: totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>( |
| 821 | Counts: PathSize, Counts: FPO.requiresTrailingStorage())); |
| 822 | auto *E = new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, |
| 823 | FPO, L, RParenLoc, AngleBrackets); |
| 824 | if (PathSize) |
| 825 | llvm::uninitialized_copy(Src: *BasePath, |
| 826 | Dst: E->getTrailingObjects<CXXBaseSpecifier *>()); |
| 827 | return E; |
| 828 | } |
| 829 | |
| 830 | CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C, |
| 831 | unsigned PathSize, |
| 832 | bool HasFPFeatures) { |
| 833 | void *Buffer = |
| 834 | C.Allocate(Size: totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>( |
| 835 | Counts: PathSize, Counts: HasFPFeatures)); |
| 836 | return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize, HasFPFeatures); |
| 837 | } |
| 838 | |
| 839 | CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T, |
| 840 | ExprValueKind VK, |
| 841 | CastKind K, Expr *Op, |
| 842 | const CXXCastPath *BasePath, |
| 843 | TypeSourceInfo *WrittenTy, |
| 844 | SourceLocation L, |
| 845 | SourceLocation RParenLoc, |
| 846 | SourceRange AngleBrackets) { |
| 847 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 848 | void *Buffer = C.Allocate(Size: totalSizeToAlloc<CXXBaseSpecifier *>(Counts: PathSize)); |
| 849 | auto *E = |
| 850 | new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 851 | RParenLoc, AngleBrackets); |
| 852 | if (PathSize) |
| 853 | llvm::uninitialized_copy(Src: *BasePath, Dst: E->getTrailingObjects()); |
| 854 | return E; |
| 855 | } |
| 856 | |
| 857 | CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C, |
| 858 | unsigned PathSize) { |
| 859 | void *Buffer = C.Allocate(Size: totalSizeToAlloc<CXXBaseSpecifier *>(Counts: PathSize)); |
| 860 | return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); |
| 861 | } |
| 862 | |
| 863 | /// isAlwaysNull - Return whether the result of the dynamic_cast is proven |
| 864 | /// to always be null. For example: |
| 865 | /// |
| 866 | /// struct A { }; |
| 867 | /// struct B final : A { }; |
| 868 | /// struct C { }; |
| 869 | /// |
| 870 | /// C *f(B* b) { return dynamic_cast<C*>(b); } |
| 871 | bool CXXDynamicCastExpr::isAlwaysNull() const { |
| 872 | if (isValueDependent() || getCastKind() != CK_Dynamic) |
| 873 | return false; |
| 874 | |
| 875 | QualType SrcType = getSubExpr()->getType(); |
| 876 | QualType DestType = getType(); |
| 877 | |
| 878 | if (DestType->isVoidPointerType()) |
| 879 | return false; |
| 880 | |
| 881 | if (DestType->isPointerType()) { |
| 882 | SrcType = SrcType->getPointeeType(); |
| 883 | DestType = DestType->getPointeeType(); |
| 884 | } |
| 885 | |
| 886 | const auto *SrcRD = SrcType->getAsCXXRecordDecl(); |
| 887 | const auto *DestRD = DestType->getAsCXXRecordDecl(); |
| 888 | assert(SrcRD && DestRD); |
| 889 | |
| 890 | if (SrcRD->isEffectivelyFinal()) { |
| 891 | assert(!SrcRD->isDerivedFrom(DestRD) && |
| 892 | "upcasts should not use CK_Dynamic" ); |
| 893 | return true; |
| 894 | } |
| 895 | |
| 896 | if (DestRD->isEffectivelyFinal() && !DestRD->isDerivedFrom(Base: SrcRD)) |
| 897 | return true; |
| 898 | |
| 899 | return false; |
| 900 | } |
| 901 | |
| 902 | CXXReinterpretCastExpr * |
| 903 | CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T, |
| 904 | ExprValueKind VK, CastKind K, Expr *Op, |
| 905 | const CXXCastPath *BasePath, |
| 906 | TypeSourceInfo *WrittenTy, SourceLocation L, |
| 907 | SourceLocation RParenLoc, |
| 908 | SourceRange AngleBrackets) { |
| 909 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 910 | void *Buffer = C.Allocate(Size: totalSizeToAlloc<CXXBaseSpecifier *>(Counts: PathSize)); |
| 911 | auto *E = |
| 912 | new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 913 | RParenLoc, AngleBrackets); |
| 914 | if (PathSize) |
| 915 | llvm::uninitialized_copy(Src: *BasePath, Dst: E->getTrailingObjects()); |
| 916 | return E; |
| 917 | } |
| 918 | |
| 919 | CXXReinterpretCastExpr * |
| 920 | CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { |
| 921 | void *Buffer = C.Allocate(Size: totalSizeToAlloc<CXXBaseSpecifier *>(Counts: PathSize)); |
| 922 | return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); |
| 923 | } |
| 924 | |
| 925 | CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T, |
| 926 | ExprValueKind VK, Expr *Op, |
| 927 | TypeSourceInfo *WrittenTy, |
| 928 | SourceLocation L, |
| 929 | SourceLocation RParenLoc, |
| 930 | SourceRange AngleBrackets) { |
| 931 | return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets); |
| 932 | } |
| 933 | |
| 934 | CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) { |
| 935 | return new (C) CXXConstCastExpr(EmptyShell()); |
| 936 | } |
| 937 | |
| 938 | CXXAddrspaceCastExpr * |
| 939 | CXXAddrspaceCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, |
| 940 | CastKind K, Expr *Op, TypeSourceInfo *WrittenTy, |
| 941 | SourceLocation L, SourceLocation RParenLoc, |
| 942 | SourceRange AngleBrackets) { |
| 943 | return new (C) CXXAddrspaceCastExpr(T, VK, K, Op, WrittenTy, L, RParenLoc, |
| 944 | AngleBrackets); |
| 945 | } |
| 946 | |
| 947 | CXXAddrspaceCastExpr *CXXAddrspaceCastExpr::CreateEmpty(const ASTContext &C) { |
| 948 | return new (C) CXXAddrspaceCastExpr(EmptyShell()); |
| 949 | } |
| 950 | |
| 951 | CXXFunctionalCastExpr *CXXFunctionalCastExpr::Create( |
| 952 | const ASTContext &C, QualType T, ExprValueKind VK, TypeSourceInfo *Written, |
| 953 | CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, |
| 954 | SourceLocation L, SourceLocation R) { |
| 955 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 956 | void *Buffer = |
| 957 | C.Allocate(Size: totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>( |
| 958 | Counts: PathSize, Counts: FPO.requiresTrailingStorage())); |
| 959 | auto *E = new (Buffer) |
| 960 | CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, FPO, L, R); |
| 961 | if (PathSize) |
| 962 | llvm::uninitialized_copy(Src: *BasePath, |
| 963 | Dst: E->getTrailingObjects<CXXBaseSpecifier *>()); |
| 964 | return E; |
| 965 | } |
| 966 | |
| 967 | CXXFunctionalCastExpr *CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, |
| 968 | unsigned PathSize, |
| 969 | bool HasFPFeatures) { |
| 970 | void *Buffer = |
| 971 | C.Allocate(Size: totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>( |
| 972 | Counts: PathSize, Counts: HasFPFeatures)); |
| 973 | return new (Buffer) |
| 974 | CXXFunctionalCastExpr(EmptyShell(), PathSize, HasFPFeatures); |
| 975 | } |
| 976 | |
| 977 | SourceLocation CXXFunctionalCastExpr::getBeginLoc() const { |
| 978 | return getTypeInfoAsWritten()->getTypeLoc().getBeginLoc(); |
| 979 | } |
| 980 | |
| 981 | SourceLocation CXXFunctionalCastExpr::getEndLoc() const { |
| 982 | return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getEndLoc(); |
| 983 | } |
| 984 | |
| 985 | UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args, |
| 986 | QualType Ty, ExprValueKind VK, |
| 987 | SourceLocation LitEndLoc, |
| 988 | SourceLocation SuffixLoc, |
| 989 | FPOptionsOverride FPFeatures) |
| 990 | : CallExpr(UserDefinedLiteralClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, |
| 991 | LitEndLoc, FPFeatures, /*MinNumArgs=*/0, NotADL), |
| 992 | UDSuffixLoc(SuffixLoc) {} |
| 993 | |
| 994 | UserDefinedLiteral::UserDefinedLiteral(unsigned NumArgs, bool HasFPFeatures, |
| 995 | EmptyShell Empty) |
| 996 | : CallExpr(UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs, |
| 997 | HasFPFeatures, Empty) {} |
| 998 | |
| 999 | UserDefinedLiteral *UserDefinedLiteral::Create(const ASTContext &Ctx, Expr *Fn, |
| 1000 | ArrayRef<Expr *> Args, |
| 1001 | QualType Ty, ExprValueKind VK, |
| 1002 | SourceLocation LitEndLoc, |
| 1003 | SourceLocation SuffixLoc, |
| 1004 | FPOptionsOverride FPFeatures) { |
| 1005 | // Allocate storage for the trailing objects of CallExpr. |
| 1006 | unsigned NumArgs = Args.size(); |
| 1007 | unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects( |
| 1008 | /*NumPreArgs=*/0, NumArgs, HasFPFeatures: FPFeatures.requiresTrailingStorage()); |
| 1009 | void *Mem = |
| 1010 | Ctx.Allocate(Size: sizeToAllocateForCallExprSubclass<UserDefinedLiteral>( |
| 1011 | SizeOfTrailingObjects), |
| 1012 | Align: alignof(UserDefinedLiteral)); |
| 1013 | return new (Mem) |
| 1014 | UserDefinedLiteral(Fn, Args, Ty, VK, LitEndLoc, SuffixLoc, FPFeatures); |
| 1015 | } |
| 1016 | |
| 1017 | UserDefinedLiteral *UserDefinedLiteral::CreateEmpty(const ASTContext &Ctx, |
| 1018 | unsigned NumArgs, |
| 1019 | bool HasFPOptions, |
| 1020 | EmptyShell Empty) { |
| 1021 | // Allocate storage for the trailing objects of CallExpr. |
| 1022 | unsigned SizeOfTrailingObjects = |
| 1023 | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures: HasFPOptions); |
| 1024 | void *Mem = |
| 1025 | Ctx.Allocate(Size: sizeToAllocateForCallExprSubclass<UserDefinedLiteral>( |
| 1026 | SizeOfTrailingObjects), |
| 1027 | Align: alignof(UserDefinedLiteral)); |
| 1028 | return new (Mem) UserDefinedLiteral(NumArgs, HasFPOptions, Empty); |
| 1029 | } |
| 1030 | |
| 1031 | UserDefinedLiteral::LiteralOperatorKind |
| 1032 | UserDefinedLiteral::getLiteralOperatorKind() const { |
| 1033 | if (getNumArgs() == 0) |
| 1034 | return LOK_Template; |
| 1035 | if (getNumArgs() == 2) |
| 1036 | return LOK_String; |
| 1037 | |
| 1038 | assert(getNumArgs() == 1 && "unexpected #args in literal operator call" ); |
| 1039 | QualType ParamTy = |
| 1040 | cast<FunctionDecl>(Val: getCalleeDecl())->getParamDecl(i: 0)->getType(); |
| 1041 | if (ParamTy->isPointerType()) |
| 1042 | return LOK_Raw; |
| 1043 | if (ParamTy->isAnyCharacterType()) |
| 1044 | return LOK_Character; |
| 1045 | if (ParamTy->isIntegerType()) |
| 1046 | return LOK_Integer; |
| 1047 | if (ParamTy->isFloatingType()) |
| 1048 | return LOK_Floating; |
| 1049 | |
| 1050 | llvm_unreachable("unknown kind of literal operator" ); |
| 1051 | } |
| 1052 | |
| 1053 | Expr *UserDefinedLiteral::getCookedLiteral() { |
| 1054 | #ifndef NDEBUG |
| 1055 | LiteralOperatorKind LOK = getLiteralOperatorKind(); |
| 1056 | assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal" ); |
| 1057 | #endif |
| 1058 | return getArg(Arg: 0); |
| 1059 | } |
| 1060 | |
| 1061 | const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const { |
| 1062 | return cast<FunctionDecl>(Val: getCalleeDecl())->getLiteralIdentifier(); |
| 1063 | } |
| 1064 | |
| 1065 | CXXDefaultArgExpr *CXXDefaultArgExpr::CreateEmpty(const ASTContext &C, |
| 1066 | bool HasRewrittenInit) { |
| 1067 | size_t Size = totalSizeToAlloc<Expr *>(Counts: HasRewrittenInit); |
| 1068 | auto *Mem = C.Allocate(Size, Align: alignof(CXXDefaultArgExpr)); |
| 1069 | return new (Mem) CXXDefaultArgExpr(EmptyShell(), HasRewrittenInit); |
| 1070 | } |
| 1071 | |
| 1072 | CXXDefaultArgExpr *CXXDefaultArgExpr::Create(const ASTContext &C, |
| 1073 | SourceLocation Loc, |
| 1074 | ParmVarDecl *Param, |
| 1075 | Expr *RewrittenExpr, |
| 1076 | DeclContext *UsedContext) { |
| 1077 | size_t Size = totalSizeToAlloc<Expr *>(Counts: RewrittenExpr != nullptr); |
| 1078 | auto *Mem = C.Allocate(Size, Align: alignof(CXXDefaultArgExpr)); |
| 1079 | return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, |
| 1080 | RewrittenExpr, UsedContext); |
| 1081 | } |
| 1082 | |
| 1083 | Expr *CXXDefaultArgExpr::getExpr() { |
| 1084 | return CXXDefaultArgExprBits.HasRewrittenInit ? getAdjustedRewrittenExpr() |
| 1085 | : getParam()->getDefaultArg(); |
| 1086 | } |
| 1087 | |
| 1088 | Expr *CXXDefaultArgExpr::getAdjustedRewrittenExpr() { |
| 1089 | assert(hasRewrittenInit() && |
| 1090 | "expected this CXXDefaultArgExpr to have a rewritten init." ); |
| 1091 | Expr *Init = getRewrittenExpr(); |
| 1092 | if (auto *E = dyn_cast_if_present<FullExpr>(Val: Init)) |
| 1093 | if (!isa<ConstantExpr>(Val: E)) |
| 1094 | return E->getSubExpr(); |
| 1095 | return Init; |
| 1096 | } |
| 1097 | |
| 1098 | CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx, |
| 1099 | SourceLocation Loc, FieldDecl *Field, |
| 1100 | QualType Ty, DeclContext *UsedContext, |
| 1101 | Expr *RewrittenInitExpr) |
| 1102 | : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Context: Ctx), |
| 1103 | Ty->isLValueReferenceType() ? VK_LValue |
| 1104 | : Ty->isRValueReferenceType() ? VK_XValue |
| 1105 | : VK_PRValue, |
| 1106 | /*FIXME*/ OK_Ordinary), |
| 1107 | Field(Field), UsedContext(UsedContext) { |
| 1108 | CXXDefaultInitExprBits.Loc = Loc; |
| 1109 | CXXDefaultInitExprBits.HasRewrittenInit = RewrittenInitExpr != nullptr; |
| 1110 | |
| 1111 | if (CXXDefaultInitExprBits.HasRewrittenInit) |
| 1112 | *getTrailingObjects() = RewrittenInitExpr; |
| 1113 | |
| 1114 | assert(Field->hasInClassInitializer()); |
| 1115 | |
| 1116 | setDependence(computeDependence(E: this)); |
| 1117 | } |
| 1118 | |
| 1119 | CXXDefaultInitExpr *CXXDefaultInitExpr::CreateEmpty(const ASTContext &C, |
| 1120 | bool HasRewrittenInit) { |
| 1121 | size_t Size = totalSizeToAlloc<Expr *>(Counts: HasRewrittenInit); |
| 1122 | auto *Mem = C.Allocate(Size, Align: alignof(CXXDefaultInitExpr)); |
| 1123 | return new (Mem) CXXDefaultInitExpr(EmptyShell(), HasRewrittenInit); |
| 1124 | } |
| 1125 | |
| 1126 | CXXDefaultInitExpr *CXXDefaultInitExpr::Create(const ASTContext &Ctx, |
| 1127 | SourceLocation Loc, |
| 1128 | FieldDecl *Field, |
| 1129 | DeclContext *UsedContext, |
| 1130 | Expr *RewrittenInitExpr) { |
| 1131 | |
| 1132 | size_t Size = totalSizeToAlloc<Expr *>(Counts: RewrittenInitExpr != nullptr); |
| 1133 | auto *Mem = Ctx.Allocate(Size, Align: alignof(CXXDefaultInitExpr)); |
| 1134 | return new (Mem) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(), |
| 1135 | UsedContext, RewrittenInitExpr); |
| 1136 | } |
| 1137 | |
| 1138 | Expr *CXXDefaultInitExpr::getExpr() { |
| 1139 | assert(Field->getInClassInitializer() && "initializer hasn't been parsed" ); |
| 1140 | if (hasRewrittenInit()) |
| 1141 | return getRewrittenExpr(); |
| 1142 | |
| 1143 | return Field->getInClassInitializer(); |
| 1144 | } |
| 1145 | |
| 1146 | CXXTemporary *CXXTemporary::Create(const ASTContext &C, |
| 1147 | const CXXDestructorDecl *Destructor) { |
| 1148 | return new (C) CXXTemporary(Destructor); |
| 1149 | } |
| 1150 | |
| 1151 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C, |
| 1152 | CXXTemporary *Temp, |
| 1153 | Expr* SubExpr) { |
| 1154 | assert((SubExpr->getType()->isRecordType() || |
| 1155 | SubExpr->getType()->isArrayType()) && |
| 1156 | "Expression bound to a temporary must have record or array type!" ); |
| 1157 | |
| 1158 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
| 1159 | } |
| 1160 | |
| 1161 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr( |
| 1162 | CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, |
| 1163 | ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange, |
| 1164 | bool HadMultipleCandidates, bool ListInitialization, |
| 1165 | bool StdInitListInitialization, bool ZeroInitialization) |
| 1166 | : CXXConstructExpr( |
| 1167 | CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(), |
| 1168 | Cons, /* Elidable=*/false, Args, HadMultipleCandidates, |
| 1169 | ListInitialization, StdInitListInitialization, ZeroInitialization, |
| 1170 | CXXConstructionKind::Complete, ParenOrBraceRange), |
| 1171 | TSI(TSI) { |
| 1172 | setDependence(computeDependence(E: this)); |
| 1173 | } |
| 1174 | |
| 1175 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(EmptyShell Empty, |
| 1176 | unsigned NumArgs) |
| 1177 | : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty, NumArgs) {} |
| 1178 | |
| 1179 | CXXTemporaryObjectExpr *CXXTemporaryObjectExpr::Create( |
| 1180 | const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, |
| 1181 | TypeSourceInfo *TSI, ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange, |
| 1182 | bool HadMultipleCandidates, bool ListInitialization, |
| 1183 | bool StdInitListInitialization, bool ZeroInitialization) { |
| 1184 | unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs: Args.size()); |
| 1185 | void *Mem = |
| 1186 | Ctx.Allocate(Size: sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects, |
| 1187 | Align: alignof(CXXTemporaryObjectExpr)); |
| 1188 | return new (Mem) CXXTemporaryObjectExpr( |
| 1189 | Cons, Ty, TSI, Args, ParenOrBraceRange, HadMultipleCandidates, |
| 1190 | ListInitialization, StdInitListInitialization, ZeroInitialization); |
| 1191 | } |
| 1192 | |
| 1193 | CXXTemporaryObjectExpr * |
| 1194 | CXXTemporaryObjectExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs) { |
| 1195 | unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs); |
| 1196 | void *Mem = |
| 1197 | Ctx.Allocate(Size: sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects, |
| 1198 | Align: alignof(CXXTemporaryObjectExpr)); |
| 1199 | return new (Mem) CXXTemporaryObjectExpr(EmptyShell(), NumArgs); |
| 1200 | } |
| 1201 | |
| 1202 | SourceLocation CXXTemporaryObjectExpr::getBeginLoc() const { |
| 1203 | return getTypeSourceInfo()->getTypeLoc().getBeginLoc(); |
| 1204 | } |
| 1205 | |
| 1206 | SourceLocation CXXTemporaryObjectExpr::getEndLoc() const { |
| 1207 | SourceLocation Loc = getParenOrBraceRange().getEnd(); |
| 1208 | if (Loc.isInvalid() && getNumArgs()) |
| 1209 | Loc = getArg(Arg: getNumArgs() - 1)->getEndLoc(); |
| 1210 | return Loc; |
| 1211 | } |
| 1212 | |
| 1213 | CXXConstructExpr *CXXConstructExpr::Create( |
| 1214 | const ASTContext &Ctx, QualType Ty, SourceLocation Loc, |
| 1215 | CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, |
| 1216 | bool HadMultipleCandidates, bool ListInitialization, |
| 1217 | bool StdInitListInitialization, bool ZeroInitialization, |
| 1218 | CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange) { |
| 1219 | unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs: Args.size()); |
| 1220 | void *Mem = Ctx.Allocate(Size: sizeof(CXXConstructExpr) + SizeOfTrailingObjects, |
| 1221 | Align: alignof(CXXConstructExpr)); |
| 1222 | return new (Mem) CXXConstructExpr( |
| 1223 | CXXConstructExprClass, Ty, Loc, Ctor, Elidable, Args, |
| 1224 | HadMultipleCandidates, ListInitialization, StdInitListInitialization, |
| 1225 | ZeroInitialization, ConstructKind, ParenOrBraceRange); |
| 1226 | } |
| 1227 | |
| 1228 | CXXConstructExpr *CXXConstructExpr::CreateEmpty(const ASTContext &Ctx, |
| 1229 | unsigned NumArgs) { |
| 1230 | unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs); |
| 1231 | void *Mem = Ctx.Allocate(Size: sizeof(CXXConstructExpr) + SizeOfTrailingObjects, |
| 1232 | Align: alignof(CXXConstructExpr)); |
| 1233 | return new (Mem) |
| 1234 | CXXConstructExpr(CXXConstructExprClass, EmptyShell(), NumArgs); |
| 1235 | } |
| 1236 | |
| 1237 | CXXConstructExpr::CXXConstructExpr( |
| 1238 | StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, |
| 1239 | bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates, |
| 1240 | bool ListInitialization, bool StdInitListInitialization, |
| 1241 | bool ZeroInitialization, CXXConstructionKind ConstructKind, |
| 1242 | SourceRange ParenOrBraceRange) |
| 1243 | : Expr(SC, Ty, VK_PRValue, OK_Ordinary), Constructor(Ctor), |
| 1244 | ParenOrBraceRange(ParenOrBraceRange), NumArgs(Args.size()) { |
| 1245 | CXXConstructExprBits.Elidable = Elidable; |
| 1246 | CXXConstructExprBits.HadMultipleCandidates = HadMultipleCandidates; |
| 1247 | CXXConstructExprBits.ListInitialization = ListInitialization; |
| 1248 | CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization; |
| 1249 | CXXConstructExprBits.ZeroInitialization = ZeroInitialization; |
| 1250 | CXXConstructExprBits.ConstructionKind = llvm::to_underlying(E: ConstructKind); |
| 1251 | CXXConstructExprBits.IsImmediateEscalating = false; |
| 1252 | CXXConstructExprBits.Loc = Loc; |
| 1253 | |
| 1254 | Stmt **TrailingArgs = getTrailingArgs(); |
| 1255 | llvm::copy(Range&: Args, Out: TrailingArgs); |
| 1256 | assert(!llvm::is_contained(Args, nullptr)); |
| 1257 | |
| 1258 | // CXXTemporaryObjectExpr does this itself after setting its TypeSourceInfo. |
| 1259 | if (SC == CXXConstructExprClass) |
| 1260 | setDependence(computeDependence(E: this)); |
| 1261 | } |
| 1262 | |
| 1263 | CXXConstructExpr::CXXConstructExpr(StmtClass SC, EmptyShell Empty, |
| 1264 | unsigned NumArgs) |
| 1265 | : Expr(SC, Empty), NumArgs(NumArgs) {} |
| 1266 | |
| 1267 | LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit, |
| 1268 | LambdaCaptureKind Kind, ValueDecl *Var, |
| 1269 | SourceLocation EllipsisLoc) |
| 1270 | : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) { |
| 1271 | unsigned Bits = 0; |
| 1272 | if (Implicit) |
| 1273 | Bits |= Capture_Implicit; |
| 1274 | |
| 1275 | switch (Kind) { |
| 1276 | case LCK_StarThis: |
| 1277 | Bits |= Capture_ByCopy; |
| 1278 | [[fallthrough]]; |
| 1279 | case LCK_This: |
| 1280 | assert(!Var && "'this' capture cannot have a variable!" ); |
| 1281 | Bits |= Capture_This; |
| 1282 | break; |
| 1283 | |
| 1284 | case LCK_ByCopy: |
| 1285 | Bits |= Capture_ByCopy; |
| 1286 | [[fallthrough]]; |
| 1287 | case LCK_ByRef: |
| 1288 | assert(Var && "capture must have a variable!" ); |
| 1289 | break; |
| 1290 | case LCK_VLAType: |
| 1291 | assert(!Var && "VLA type capture cannot have a variable!" ); |
| 1292 | break; |
| 1293 | } |
| 1294 | DeclAndBits.setInt(Bits); |
| 1295 | } |
| 1296 | |
| 1297 | LambdaCaptureKind LambdaCapture::getCaptureKind() const { |
| 1298 | if (capturesVLAType()) |
| 1299 | return LCK_VLAType; |
| 1300 | bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy; |
| 1301 | if (capturesThis()) |
| 1302 | return CapByCopy ? LCK_StarThis : LCK_This; |
| 1303 | return CapByCopy ? LCK_ByCopy : LCK_ByRef; |
| 1304 | } |
| 1305 | |
| 1306 | LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange, |
| 1307 | LambdaCaptureDefault CaptureDefault, |
| 1308 | SourceLocation CaptureDefaultLoc, bool ExplicitParams, |
| 1309 | bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
| 1310 | SourceLocation ClosingBrace, |
| 1311 | bool ContainsUnexpandedParameterPack) |
| 1312 | : Expr(LambdaExprClass, T, VK_PRValue, OK_Ordinary), |
| 1313 | IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc), |
| 1314 | ClosingBrace(ClosingBrace) { |
| 1315 | LambdaExprBits.NumCaptures = CaptureInits.size(); |
| 1316 | LambdaExprBits.CaptureDefault = CaptureDefault; |
| 1317 | LambdaExprBits.ExplicitParams = ExplicitParams; |
| 1318 | LambdaExprBits.ExplicitResultType = ExplicitResultType; |
| 1319 | |
| 1320 | CXXRecordDecl *Class = getLambdaClass(); |
| 1321 | (void)Class; |
| 1322 | assert(capture_size() == Class->capture_size() && "Wrong number of captures" ); |
| 1323 | assert(getCaptureDefault() == Class->getLambdaCaptureDefault()); |
| 1324 | |
| 1325 | // Copy initialization expressions for the non-static data members. |
| 1326 | Stmt **Stored = getStoredStmts(); |
| 1327 | for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I) |
| 1328 | *Stored++ = CaptureInits[I]; |
| 1329 | |
| 1330 | // Copy the body of the lambda. |
| 1331 | *Stored++ = getCallOperator()->getBody(); |
| 1332 | |
| 1333 | setDependence(computeDependence(E: this, ContainsUnexpandedParameterPack)); |
| 1334 | } |
| 1335 | |
| 1336 | LambdaExpr::LambdaExpr(EmptyShell Empty, unsigned NumCaptures) |
| 1337 | : Expr(LambdaExprClass, Empty) { |
| 1338 | LambdaExprBits.NumCaptures = NumCaptures; |
| 1339 | |
| 1340 | // Initially don't initialize the body of the LambdaExpr. The body will |
| 1341 | // be lazily deserialized when needed. |
| 1342 | getStoredStmts()[NumCaptures] = nullptr; // Not one past the end. |
| 1343 | } |
| 1344 | |
| 1345 | LambdaExpr *LambdaExpr::Create(const ASTContext &Context, CXXRecordDecl *Class, |
| 1346 | SourceRange IntroducerRange, |
| 1347 | LambdaCaptureDefault CaptureDefault, |
| 1348 | SourceLocation CaptureDefaultLoc, |
| 1349 | bool ExplicitParams, bool ExplicitResultType, |
| 1350 | ArrayRef<Expr *> CaptureInits, |
| 1351 | SourceLocation ClosingBrace, |
| 1352 | bool ContainsUnexpandedParameterPack) { |
| 1353 | // Determine the type of the expression (i.e., the type of the |
| 1354 | // function object we're creating). |
| 1355 | CanQualType T = Context.getCanonicalTagType(TD: Class); |
| 1356 | |
| 1357 | unsigned Size = totalSizeToAlloc<Stmt *>(Counts: CaptureInits.size() + 1); |
| 1358 | void *Mem = Context.Allocate(Size); |
| 1359 | return new (Mem) |
| 1360 | LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc, |
| 1361 | ExplicitParams, ExplicitResultType, CaptureInits, ClosingBrace, |
| 1362 | ContainsUnexpandedParameterPack); |
| 1363 | } |
| 1364 | |
| 1365 | LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C, |
| 1366 | unsigned NumCaptures) { |
| 1367 | unsigned Size = totalSizeToAlloc<Stmt *>(Counts: NumCaptures + 1); |
| 1368 | void *Mem = C.Allocate(Size); |
| 1369 | return new (Mem) LambdaExpr(EmptyShell(), NumCaptures); |
| 1370 | } |
| 1371 | |
| 1372 | void LambdaExpr::initBodyIfNeeded() const { |
| 1373 | if (!getStoredStmts()[capture_size()]) { |
| 1374 | auto *This = const_cast<LambdaExpr *>(this); |
| 1375 | This->getStoredStmts()[capture_size()] = getCallOperator()->getBody(); |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | Stmt *LambdaExpr::getBody() const { |
| 1380 | initBodyIfNeeded(); |
| 1381 | return getStoredStmts()[capture_size()]; |
| 1382 | } |
| 1383 | |
| 1384 | const CompoundStmt *LambdaExpr::getCompoundStmtBody() const { |
| 1385 | Stmt *Body = getBody(); |
| 1386 | if (const auto *CoroBody = dyn_cast<CoroutineBodyStmt>(Val: Body)) |
| 1387 | return cast<CompoundStmt>(Val: CoroBody->getBody()); |
| 1388 | return cast<CompoundStmt>(Val: Body); |
| 1389 | } |
| 1390 | |
| 1391 | bool LambdaExpr::isInitCapture(const LambdaCapture *C) const { |
| 1392 | return C->capturesVariable() && C->getCapturedVar()->isInitCapture() && |
| 1393 | getCallOperator() == C->getCapturedVar()->getDeclContext(); |
| 1394 | } |
| 1395 | |
| 1396 | LambdaExpr::capture_iterator LambdaExpr::capture_begin() const { |
| 1397 | return getLambdaClass()->captures_begin(); |
| 1398 | } |
| 1399 | |
| 1400 | LambdaExpr::capture_iterator LambdaExpr::capture_end() const { |
| 1401 | return getLambdaClass()->captures_end(); |
| 1402 | } |
| 1403 | |
| 1404 | LambdaExpr::capture_range LambdaExpr::captures() const { |
| 1405 | return capture_range(capture_begin(), capture_end()); |
| 1406 | } |
| 1407 | |
| 1408 | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const { |
| 1409 | return capture_begin(); |
| 1410 | } |
| 1411 | |
| 1412 | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const { |
| 1413 | return capture_begin() + |
| 1414 | getLambdaClass()->getLambdaData().NumExplicitCaptures; |
| 1415 | } |
| 1416 | |
| 1417 | LambdaExpr::capture_range LambdaExpr::explicit_captures() const { |
| 1418 | return capture_range(explicit_capture_begin(), explicit_capture_end()); |
| 1419 | } |
| 1420 | |
| 1421 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const { |
| 1422 | return explicit_capture_end(); |
| 1423 | } |
| 1424 | |
| 1425 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const { |
| 1426 | return capture_end(); |
| 1427 | } |
| 1428 | |
| 1429 | LambdaExpr::capture_range LambdaExpr::implicit_captures() const { |
| 1430 | return capture_range(implicit_capture_begin(), implicit_capture_end()); |
| 1431 | } |
| 1432 | |
| 1433 | CXXRecordDecl *LambdaExpr::getLambdaClass() const { |
| 1434 | return getType()->getAsCXXRecordDecl(); |
| 1435 | } |
| 1436 | |
| 1437 | CXXMethodDecl *LambdaExpr::getCallOperator() const { |
| 1438 | CXXRecordDecl *Record = getLambdaClass(); |
| 1439 | return Record->getLambdaCallOperator(); |
| 1440 | } |
| 1441 | |
| 1442 | FunctionTemplateDecl *LambdaExpr::getDependentCallOperator() const { |
| 1443 | CXXRecordDecl *Record = getLambdaClass(); |
| 1444 | return Record->getDependentLambdaCallOperator(); |
| 1445 | } |
| 1446 | |
| 1447 | TemplateParameterList *LambdaExpr::getTemplateParameterList() const { |
| 1448 | CXXRecordDecl *Record = getLambdaClass(); |
| 1449 | return Record->getGenericLambdaTemplateParameterList(); |
| 1450 | } |
| 1451 | |
| 1452 | ArrayRef<NamedDecl *> LambdaExpr::getExplicitTemplateParameters() const { |
| 1453 | const CXXRecordDecl *Record = getLambdaClass(); |
| 1454 | return Record->getLambdaExplicitTemplateParameters(); |
| 1455 | } |
| 1456 | |
| 1457 | const AssociatedConstraint &LambdaExpr::getTrailingRequiresClause() const { |
| 1458 | return getCallOperator()->getTrailingRequiresClause(); |
| 1459 | } |
| 1460 | |
| 1461 | bool LambdaExpr::isMutable() const { return !getCallOperator()->isConst(); } |
| 1462 | |
| 1463 | LambdaExpr::child_range LambdaExpr::children() { |
| 1464 | initBodyIfNeeded(); |
| 1465 | return child_range(getStoredStmts(), getStoredStmts() + capture_size() + 1); |
| 1466 | } |
| 1467 | |
| 1468 | LambdaExpr::const_child_range LambdaExpr::children() const { |
| 1469 | initBodyIfNeeded(); |
| 1470 | return const_child_range(getStoredStmts(), |
| 1471 | getStoredStmts() + capture_size() + 1); |
| 1472 | } |
| 1473 | |
| 1474 | ExprWithCleanups::ExprWithCleanups(Expr *subexpr, |
| 1475 | bool CleanupsHaveSideEffects, |
| 1476 | ArrayRef<CleanupObject> objects) |
| 1477 | : FullExpr(ExprWithCleanupsClass, subexpr) { |
| 1478 | ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects; |
| 1479 | ExprWithCleanupsBits.NumObjects = objects.size(); |
| 1480 | llvm::copy(Range&: objects, Out: getTrailingObjects()); |
| 1481 | } |
| 1482 | |
| 1483 | ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr, |
| 1484 | bool CleanupsHaveSideEffects, |
| 1485 | ArrayRef<CleanupObject> objects) { |
| 1486 | void *buffer = C.Allocate(Size: totalSizeToAlloc<CleanupObject>(Counts: objects.size()), |
| 1487 | Align: alignof(ExprWithCleanups)); |
| 1488 | return new (buffer) |
| 1489 | ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects); |
| 1490 | } |
| 1491 | |
| 1492 | ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects) |
| 1493 | : FullExpr(ExprWithCleanupsClass, empty) { |
| 1494 | ExprWithCleanupsBits.NumObjects = numObjects; |
| 1495 | } |
| 1496 | |
| 1497 | ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, |
| 1498 | EmptyShell empty, |
| 1499 | unsigned numObjects) { |
| 1500 | void *buffer = C.Allocate(Size: totalSizeToAlloc<CleanupObject>(Counts: numObjects), |
| 1501 | Align: alignof(ExprWithCleanups)); |
| 1502 | return new (buffer) ExprWithCleanups(empty, numObjects); |
| 1503 | } |
| 1504 | |
| 1505 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr( |
| 1506 | QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, |
| 1507 | ArrayRef<Expr *> Args, SourceLocation RParenLoc, bool IsListInit) |
| 1508 | : Expr(CXXUnresolvedConstructExprClass, T, |
| 1509 | (TSI->getType()->isLValueReferenceType() ? VK_LValue |
| 1510 | : TSI->getType()->isRValueReferenceType() ? VK_XValue |
| 1511 | : VK_PRValue), |
| 1512 | OK_Ordinary), |
| 1513 | TypeAndInitForm(TSI, IsListInit), LParenLoc(LParenLoc), |
| 1514 | RParenLoc(RParenLoc) { |
| 1515 | CXXUnresolvedConstructExprBits.NumArgs = Args.size(); |
| 1516 | auto **StoredArgs = getTrailingObjects(); |
| 1517 | llvm::copy(Range&: Args, Out: StoredArgs); |
| 1518 | setDependence(computeDependence(E: this)); |
| 1519 | } |
| 1520 | |
| 1521 | CXXUnresolvedConstructExpr *CXXUnresolvedConstructExpr::Create( |
| 1522 | const ASTContext &Context, QualType T, TypeSourceInfo *TSI, |
| 1523 | SourceLocation LParenLoc, ArrayRef<Expr *> Args, SourceLocation RParenLoc, |
| 1524 | bool IsListInit) { |
| 1525 | void *Mem = Context.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: Args.size())); |
| 1526 | return new (Mem) CXXUnresolvedConstructExpr(T, TSI, LParenLoc, Args, |
| 1527 | RParenLoc, IsListInit); |
| 1528 | } |
| 1529 | |
| 1530 | CXXUnresolvedConstructExpr * |
| 1531 | CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &Context, |
| 1532 | unsigned NumArgs) { |
| 1533 | void *Mem = Context.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: NumArgs)); |
| 1534 | return new (Mem) CXXUnresolvedConstructExpr(EmptyShell(), NumArgs); |
| 1535 | } |
| 1536 | |
| 1537 | SourceLocation CXXUnresolvedConstructExpr::getBeginLoc() const { |
| 1538 | return TypeAndInitForm.getPointer()->getTypeLoc().getBeginLoc(); |
| 1539 | } |
| 1540 | |
| 1541 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr( |
| 1542 | const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, |
| 1543 | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
| 1544 | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, |
| 1545 | DeclarationNameInfo MemberNameInfo, |
| 1546 | const TemplateArgumentListInfo *TemplateArgs) |
| 1547 | : Expr(CXXDependentScopeMemberExprClass, Ctx.DependentTy, VK_LValue, |
| 1548 | OK_Ordinary), |
| 1549 | Base(Base), BaseType(BaseType), QualifierLoc(QualifierLoc), |
| 1550 | MemberNameInfo(MemberNameInfo) { |
| 1551 | CXXDependentScopeMemberExprBits.IsArrow = IsArrow; |
| 1552 | CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo = |
| 1553 | (TemplateArgs != nullptr) || TemplateKWLoc.isValid(); |
| 1554 | CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope = |
| 1555 | FirstQualifierFoundInScope != nullptr; |
| 1556 | CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc; |
| 1557 | |
| 1558 | if (TemplateArgs) { |
| 1559 | auto Deps = TemplateArgumentDependence::None; |
| 1560 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
| 1561 | TemplateKWLoc, List: *TemplateArgs, OutArgArray: getTrailingObjects<TemplateArgumentLoc>(), |
| 1562 | Deps); |
| 1563 | } else if (TemplateKWLoc.isValid()) { |
| 1564 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
| 1565 | TemplateKWLoc); |
| 1566 | } |
| 1567 | |
| 1568 | if (hasFirstQualifierFoundInScope()) |
| 1569 | *getTrailingObjects<NamedDecl *>() = FirstQualifierFoundInScope; |
| 1570 | setDependence(computeDependence(E: this)); |
| 1571 | } |
| 1572 | |
| 1573 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr( |
| 1574 | EmptyShell Empty, bool HasTemplateKWAndArgsInfo, |
| 1575 | bool HasFirstQualifierFoundInScope) |
| 1576 | : Expr(CXXDependentScopeMemberExprClass, Empty) { |
| 1577 | CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo = |
| 1578 | HasTemplateKWAndArgsInfo; |
| 1579 | CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope = |
| 1580 | HasFirstQualifierFoundInScope; |
| 1581 | } |
| 1582 | |
| 1583 | CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::Create( |
| 1584 | const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, |
| 1585 | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
| 1586 | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, |
| 1587 | DeclarationNameInfo MemberNameInfo, |
| 1588 | const TemplateArgumentListInfo *TemplateArgs) { |
| 1589 | bool HasTemplateKWAndArgsInfo = |
| 1590 | (TemplateArgs != nullptr) || TemplateKWLoc.isValid(); |
| 1591 | unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0; |
| 1592 | bool HasFirstQualifierFoundInScope = FirstQualifierFoundInScope != nullptr; |
| 1593 | |
| 1594 | unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo, |
| 1595 | TemplateArgumentLoc, NamedDecl *>( |
| 1596 | Counts: HasTemplateKWAndArgsInfo, Counts: NumTemplateArgs, Counts: HasFirstQualifierFoundInScope); |
| 1597 | |
| 1598 | void *Mem = Ctx.Allocate(Size, Align: alignof(CXXDependentScopeMemberExpr)); |
| 1599 | return new (Mem) CXXDependentScopeMemberExpr( |
| 1600 | Ctx, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc, |
| 1601 | FirstQualifierFoundInScope, MemberNameInfo, TemplateArgs); |
| 1602 | } |
| 1603 | |
| 1604 | CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::CreateEmpty( |
| 1605 | const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo, |
| 1606 | unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope) { |
| 1607 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
| 1608 | |
| 1609 | unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo, |
| 1610 | TemplateArgumentLoc, NamedDecl *>( |
| 1611 | Counts: HasTemplateKWAndArgsInfo, Counts: NumTemplateArgs, Counts: HasFirstQualifierFoundInScope); |
| 1612 | |
| 1613 | void *Mem = Ctx.Allocate(Size, Align: alignof(CXXDependentScopeMemberExpr)); |
| 1614 | return new (Mem) CXXDependentScopeMemberExpr( |
| 1615 | EmptyShell(), HasTemplateKWAndArgsInfo, HasFirstQualifierFoundInScope); |
| 1616 | } |
| 1617 | |
| 1618 | CXXThisExpr *CXXThisExpr::Create(const ASTContext &Ctx, SourceLocation L, |
| 1619 | QualType Ty, bool IsImplicit) { |
| 1620 | return new (Ctx) CXXThisExpr(L, Ty, IsImplicit, |
| 1621 | Ctx.getLangOpts().HLSL ? VK_LValue : VK_PRValue); |
| 1622 | } |
| 1623 | |
| 1624 | CXXThisExpr *CXXThisExpr::CreateEmpty(const ASTContext &Ctx) { |
| 1625 | return new (Ctx) CXXThisExpr(EmptyShell()); |
| 1626 | } |
| 1627 | |
| 1628 | static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, |
| 1629 | UnresolvedSetIterator end) { |
| 1630 | do { |
| 1631 | NamedDecl *decl = (*begin)->getUnderlyingDecl(); |
| 1632 | if (isa<UnresolvedUsingValueDecl>(Val: decl)) |
| 1633 | return false; |
| 1634 | |
| 1635 | // Unresolved member expressions should only contain methods and |
| 1636 | // method templates. |
| 1637 | if (cast<CXXMethodDecl>(Val: decl->getAsFunction())->isStatic()) |
| 1638 | return false; |
| 1639 | } while (++begin != end); |
| 1640 | |
| 1641 | return true; |
| 1642 | } |
| 1643 | |
| 1644 | UnresolvedMemberExpr::UnresolvedMemberExpr( |
| 1645 | const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, |
| 1646 | QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, |
| 1647 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
| 1648 | const DeclarationNameInfo &MemberNameInfo, |
| 1649 | const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, |
| 1650 | UnresolvedSetIterator End) |
| 1651 | : OverloadExpr( |
| 1652 | UnresolvedMemberExprClass, Context, QualifierLoc, TemplateKWLoc, |
| 1653 | MemberNameInfo, TemplateArgs, Begin, End, |
| 1654 | // Dependent |
| 1655 | ((Base && Base->isTypeDependent()) || BaseType->isDependentType()), |
| 1656 | ((Base && Base->isInstantiationDependent()) || |
| 1657 | BaseType->isInstantiationDependentType()), |
| 1658 | // Contains unexpanded parameter pack |
| 1659 | ((Base && Base->containsUnexpandedParameterPack()) || |
| 1660 | BaseType->containsUnexpandedParameterPack())), |
| 1661 | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
| 1662 | UnresolvedMemberExprBits.IsArrow = IsArrow; |
| 1663 | UnresolvedMemberExprBits.HasUnresolvedUsing = HasUnresolvedUsing; |
| 1664 | |
| 1665 | // Check whether all of the members are non-static member functions, |
| 1666 | // and if so, mark give this bound-member type instead of overload type. |
| 1667 | if (hasOnlyNonStaticMemberFunctions(begin: Begin, end: End)) |
| 1668 | setType(Context.BoundMemberTy); |
| 1669 | } |
| 1670 | |
| 1671 | UnresolvedMemberExpr::UnresolvedMemberExpr(EmptyShell Empty, |
| 1672 | unsigned NumResults, |
| 1673 | bool HasTemplateKWAndArgsInfo) |
| 1674 | : OverloadExpr(UnresolvedMemberExprClass, Empty, NumResults, |
| 1675 | HasTemplateKWAndArgsInfo) {} |
| 1676 | |
| 1677 | bool UnresolvedMemberExpr::isImplicitAccess() const { |
| 1678 | if (!Base) |
| 1679 | return true; |
| 1680 | |
| 1681 | return cast<Expr>(Val: Base)->isImplicitCXXThis(); |
| 1682 | } |
| 1683 | |
| 1684 | UnresolvedMemberExpr *UnresolvedMemberExpr::Create( |
| 1685 | const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, |
| 1686 | QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, |
| 1687 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
| 1688 | const DeclarationNameInfo &MemberNameInfo, |
| 1689 | const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, |
| 1690 | UnresolvedSetIterator End) { |
| 1691 | unsigned NumResults = End - Begin; |
| 1692 | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid(); |
| 1693 | unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0; |
| 1694 | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
| 1695 | TemplateArgumentLoc>( |
| 1696 | Counts: NumResults, Counts: HasTemplateKWAndArgsInfo, Counts: NumTemplateArgs); |
| 1697 | void *Mem = Context.Allocate(Size, Align: alignof(UnresolvedMemberExpr)); |
| 1698 | return new (Mem) UnresolvedMemberExpr( |
| 1699 | Context, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc, |
| 1700 | QualifierLoc, TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End); |
| 1701 | } |
| 1702 | |
| 1703 | UnresolvedMemberExpr *UnresolvedMemberExpr::CreateEmpty( |
| 1704 | const ASTContext &Context, unsigned NumResults, |
| 1705 | bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) { |
| 1706 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
| 1707 | unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo, |
| 1708 | TemplateArgumentLoc>( |
| 1709 | Counts: NumResults, Counts: HasTemplateKWAndArgsInfo, Counts: NumTemplateArgs); |
| 1710 | void *Mem = Context.Allocate(Size, Align: alignof(UnresolvedMemberExpr)); |
| 1711 | return new (Mem) |
| 1712 | UnresolvedMemberExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo); |
| 1713 | } |
| 1714 | |
| 1715 | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() { |
| 1716 | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
| 1717 | |
| 1718 | // If there was a nested name specifier, it names the naming class. |
| 1719 | // It can't be dependent: after all, we were actually able to do the |
| 1720 | // lookup. |
| 1721 | CXXRecordDecl *Record = nullptr; |
| 1722 | if (NestedNameSpecifier Qualifier = getQualifier(); |
| 1723 | Qualifier.getKind() == NestedNameSpecifier::Kind::Type) { |
| 1724 | const Type *T = getQualifier().getAsType(); |
| 1725 | Record = T->getAsCXXRecordDecl(); |
| 1726 | assert(Record && "qualifier in member expression does not name record" ); |
| 1727 | } |
| 1728 | // Otherwise the naming class must have been the base class. |
| 1729 | else { |
| 1730 | QualType BaseType = getBaseType().getNonReferenceType(); |
| 1731 | if (isArrow()) |
| 1732 | BaseType = BaseType->castAs<PointerType>()->getPointeeType(); |
| 1733 | |
| 1734 | Record = BaseType->getAsCXXRecordDecl(); |
| 1735 | assert(Record && "base of member expression does not name record" ); |
| 1736 | } |
| 1737 | |
| 1738 | return Record; |
| 1739 | } |
| 1740 | |
| 1741 | SizeOfPackExpr *SizeOfPackExpr::Create(ASTContext &Context, |
| 1742 | SourceLocation OperatorLoc, |
| 1743 | NamedDecl *Pack, SourceLocation PackLoc, |
| 1744 | SourceLocation RParenLoc, |
| 1745 | UnsignedOrNone Length, |
| 1746 | ArrayRef<TemplateArgument> PartialArgs) { |
| 1747 | void *Storage = |
| 1748 | Context.Allocate(Size: totalSizeToAlloc<TemplateArgument>(Counts: PartialArgs.size())); |
| 1749 | return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack, |
| 1750 | PackLoc, RParenLoc, Length, PartialArgs); |
| 1751 | } |
| 1752 | |
| 1753 | SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context, |
| 1754 | unsigned NumPartialArgs) { |
| 1755 | void *Storage = |
| 1756 | Context.Allocate(Size: totalSizeToAlloc<TemplateArgument>(Counts: NumPartialArgs)); |
| 1757 | return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs); |
| 1758 | } |
| 1759 | |
| 1760 | NonTypeTemplateParmDecl *SubstNonTypeTemplateParmExpr::getParameter() const { |
| 1761 | return cast<NonTypeTemplateParmDecl>( |
| 1762 | Val: std::get<0>(t: getReplacedTemplateParameter(D: getAssociatedDecl(), Index))); |
| 1763 | } |
| 1764 | |
| 1765 | PackIndexingExpr *PackIndexingExpr::Create( |
| 1766 | ASTContext &Context, SourceLocation EllipsisLoc, SourceLocation RSquareLoc, |
| 1767 | Expr *PackIdExpr, Expr *IndexExpr, std::optional<int64_t> Index, |
| 1768 | ArrayRef<Expr *> SubstitutedExprs, bool FullySubstituted) { |
| 1769 | QualType Type; |
| 1770 | if (Index && FullySubstituted && !SubstitutedExprs.empty()) |
| 1771 | Type = SubstitutedExprs[*Index]->getType(); |
| 1772 | else |
| 1773 | Type = PackIdExpr->getType(); |
| 1774 | |
| 1775 | void *Storage = |
| 1776 | Context.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: SubstitutedExprs.size())); |
| 1777 | return new (Storage) |
| 1778 | PackIndexingExpr(Type, EllipsisLoc, RSquareLoc, PackIdExpr, IndexExpr, |
| 1779 | SubstitutedExprs, FullySubstituted); |
| 1780 | } |
| 1781 | |
| 1782 | NamedDecl *PackIndexingExpr::getPackDecl() const { |
| 1783 | if (auto *D = dyn_cast<DeclRefExpr>(Val: getPackIdExpression()); D) { |
| 1784 | return D->getDecl(); |
| 1785 | } |
| 1786 | assert(false && "invalid declaration kind in pack indexing expression" ); |
| 1787 | return nullptr; |
| 1788 | } |
| 1789 | |
| 1790 | PackIndexingExpr * |
| 1791 | PackIndexingExpr::CreateDeserialized(ASTContext &Context, |
| 1792 | unsigned NumTransformedExprs) { |
| 1793 | void *Storage = |
| 1794 | Context.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: NumTransformedExprs)); |
| 1795 | return new (Storage) PackIndexingExpr(EmptyShell{}); |
| 1796 | } |
| 1797 | |
| 1798 | SubstNonTypeTemplateParmPackExpr::SubstNonTypeTemplateParmPackExpr( |
| 1799 | QualType T, ExprValueKind ValueKind, SourceLocation NameLoc, |
| 1800 | const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, |
| 1801 | bool Final) |
| 1802 | : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary), |
| 1803 | AssociatedDecl(AssociatedDecl), Arguments(ArgPack.pack_begin()), |
| 1804 | NumArguments(ArgPack.pack_size()), Final(Final), Index(Index), |
| 1805 | NameLoc(NameLoc) { |
| 1806 | assert(AssociatedDecl != nullptr); |
| 1807 | setDependence(ExprDependence::TypeValueInstantiation | |
| 1808 | ExprDependence::UnexpandedPack); |
| 1809 | } |
| 1810 | |
| 1811 | NonTypeTemplateParmDecl * |
| 1812 | SubstNonTypeTemplateParmPackExpr::getParameterPack() const { |
| 1813 | return cast<NonTypeTemplateParmDecl>( |
| 1814 | Val: std::get<0>(t: getReplacedTemplateParameter(D: getAssociatedDecl(), Index))); |
| 1815 | } |
| 1816 | |
| 1817 | TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { |
| 1818 | return TemplateArgument(ArrayRef(Arguments, NumArguments)); |
| 1819 | } |
| 1820 | |
| 1821 | FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ValueDecl *ParamPack, |
| 1822 | SourceLocation NameLoc, |
| 1823 | unsigned NumParams, |
| 1824 | ValueDecl *const *Params) |
| 1825 | : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary), |
| 1826 | ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) { |
| 1827 | if (Params) |
| 1828 | std::uninitialized_copy(first: Params, last: Params + NumParams, result: getTrailingObjects()); |
| 1829 | setDependence(ExprDependence::TypeValueInstantiation | |
| 1830 | ExprDependence::UnexpandedPack); |
| 1831 | } |
| 1832 | |
| 1833 | FunctionParmPackExpr * |
| 1834 | FunctionParmPackExpr::Create(const ASTContext &Context, QualType T, |
| 1835 | ValueDecl *ParamPack, SourceLocation NameLoc, |
| 1836 | ArrayRef<ValueDecl *> Params) { |
| 1837 | return new (Context.Allocate(Size: totalSizeToAlloc<ValueDecl *>(Counts: Params.size()))) |
| 1838 | FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data()); |
| 1839 | } |
| 1840 | |
| 1841 | FunctionParmPackExpr * |
| 1842 | FunctionParmPackExpr::CreateEmpty(const ASTContext &Context, |
| 1843 | unsigned NumParams) { |
| 1844 | return new (Context.Allocate(Size: totalSizeToAlloc<ValueDecl *>(Counts: NumParams))) |
| 1845 | FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr); |
| 1846 | } |
| 1847 | |
| 1848 | MaterializeTemporaryExpr::MaterializeTemporaryExpr( |
| 1849 | QualType T, Expr *Temporary, bool BoundToLvalueReference, |
| 1850 | LifetimeExtendedTemporaryDecl *MTD) |
| 1851 | : Expr(MaterializeTemporaryExprClass, T, |
| 1852 | BoundToLvalueReference ? VK_LValue : VK_XValue, OK_Ordinary) { |
| 1853 | if (MTD) { |
| 1854 | State = MTD; |
| 1855 | MTD->ExprWithTemporary = Temporary; |
| 1856 | return; |
| 1857 | } |
| 1858 | State = Temporary; |
| 1859 | setDependence(computeDependence(E: this)); |
| 1860 | } |
| 1861 | |
| 1862 | void MaterializeTemporaryExpr::setExtendingDecl(ValueDecl *ExtendedBy, |
| 1863 | unsigned ManglingNumber) { |
| 1864 | // We only need extra state if we have to remember more than just the Stmt. |
| 1865 | if (!ExtendedBy) |
| 1866 | return; |
| 1867 | |
| 1868 | // We may need to allocate extra storage for the mangling number and the |
| 1869 | // extended-by ValueDecl. |
| 1870 | if (!isa<LifetimeExtendedTemporaryDecl *>(Val: State)) |
| 1871 | State = LifetimeExtendedTemporaryDecl::Create( |
| 1872 | Temp: cast<Expr>(Val: cast<Stmt *>(Val&: State)), EDec: ExtendedBy, Mangling: ManglingNumber); |
| 1873 | |
| 1874 | auto ES = cast<LifetimeExtendedTemporaryDecl *>(Val&: State); |
| 1875 | ES->ExtendingDecl = ExtendedBy; |
| 1876 | ES->ManglingNumber = ManglingNumber; |
| 1877 | } |
| 1878 | |
| 1879 | bool MaterializeTemporaryExpr::isUsableInConstantExpressions( |
| 1880 | const ASTContext &Context) const { |
| 1881 | // C++20 [expr.const]p4: |
| 1882 | // An object or reference is usable in constant expressions if it is [...] |
| 1883 | // a temporary object of non-volatile const-qualified literal type |
| 1884 | // whose lifetime is extended to that of a variable that is usable |
| 1885 | // in constant expressions |
| 1886 | auto *VD = dyn_cast_or_null<VarDecl>(Val: getExtendingDecl()); |
| 1887 | return VD && getType().isConstant(Ctx: Context) && |
| 1888 | !getType().isVolatileQualified() && |
| 1889 | getType()->isLiteralType(Ctx: Context) && |
| 1890 | VD->isUsableInConstantExpressions(C: Context); |
| 1891 | } |
| 1892 | |
| 1893 | TypeTraitExpr::TypeTraitExpr( |
| 1894 | QualType T, SourceLocation Loc, TypeTrait Kind, |
| 1895 | ArrayRef<TypeSourceInfo *> Args, SourceLocation RParenLoc, |
| 1896 | std::variant<bool, APValue, ComparisonCategoryResult> Value) |
| 1897 | : Expr(TypeTraitExprClass, T, VK_PRValue, OK_Ordinary), Loc(Loc), |
| 1898 | RParenLoc(RParenLoc) { |
| 1899 | assert(Kind <= TT_Last && "invalid enum value!" ); |
| 1900 | |
| 1901 | TypeTraitExprBits.Kind = Kind; |
| 1902 | assert(static_cast<unsigned>(Kind) == TypeTraitExprBits.Kind && |
| 1903 | "TypeTraitExprBits.Kind overflow!" ); |
| 1904 | |
| 1905 | TypeTraitExprBits.IsBooleanTypeTrait = std::holds_alternative<bool>(v: Value); |
| 1906 | TypeTraitExprBits.IsComparisonResult = |
| 1907 | std::holds_alternative<ComparisonCategoryResult>(v: Value); |
| 1908 | if (TypeTraitExprBits.IsBooleanTypeTrait) |
| 1909 | TypeTraitExprBits.Value = std::get<bool>(v&: Value); |
| 1910 | else { |
| 1911 | if (auto *CCR = std::get_if<ComparisonCategoryResult>(ptr: &Value)) { |
| 1912 | llvm::APSInt EncodedValue = llvm::APSInt::get(X: llvm::to_underlying(E: *CCR)); |
| 1913 | ::new (getTrailingObjects<APValue>()) APValue(std::move(EncodedValue)); |
| 1914 | } else |
| 1915 | ::new (getTrailingObjects<APValue>()) |
| 1916 | APValue(std::get<APValue>(v: std::move(Value))); |
| 1917 | } |
| 1918 | |
| 1919 | TypeTraitExprBits.NumArgs = Args.size(); |
| 1920 | assert(Args.size() == TypeTraitExprBits.NumArgs && |
| 1921 | "TypeTraitExprBits.NumArgs overflow!" ); |
| 1922 | auto **ToArgs = getTrailingObjects<TypeSourceInfo *>(); |
| 1923 | llvm::copy(Range&: Args, Out: ToArgs); |
| 1924 | |
| 1925 | setDependence(computeDependence(E: this)); |
| 1926 | |
| 1927 | assert((TypeTraitExprBits.IsBooleanTypeTrait || isValueDependent() || |
| 1928 | getAPValue().isInt() || getAPValue().isAbsent()) && |
| 1929 | "Only int values are supported by clang" ); |
| 1930 | } |
| 1931 | |
| 1932 | TypeTraitExpr::TypeTraitExpr(EmptyShell Empty, bool IsStoredAsBool) |
| 1933 | : Expr(TypeTraitExprClass, Empty) { |
| 1934 | TypeTraitExprBits.IsBooleanTypeTrait = IsStoredAsBool; |
| 1935 | if (!IsStoredAsBool) |
| 1936 | ::new (getTrailingObjects<APValue>()) APValue(); |
| 1937 | } |
| 1938 | |
| 1939 | TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T, |
| 1940 | SourceLocation Loc, |
| 1941 | TypeTrait Kind, |
| 1942 | ArrayRef<TypeSourceInfo *> Args, |
| 1943 | SourceLocation RParenLoc, |
| 1944 | bool Value) { |
| 1945 | void *Mem = |
| 1946 | C.Allocate(Size: totalSizeToAlloc<APValue, TypeSourceInfo *>(Counts: 0, Counts: Args.size())); |
| 1947 | return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value); |
| 1948 | } |
| 1949 | |
| 1950 | TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T, |
| 1951 | SourceLocation Loc, TypeTrait Kind, |
| 1952 | ArrayRef<TypeSourceInfo *> Args, |
| 1953 | SourceLocation RParenLoc, APValue Value) { |
| 1954 | void *Mem = |
| 1955 | C.Allocate(Size: totalSizeToAlloc<APValue, TypeSourceInfo *>(Counts: 1, Counts: Args.size())); |
| 1956 | return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value); |
| 1957 | } |
| 1958 | |
| 1959 | TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T, |
| 1960 | SourceLocation Loc, TypeTrait Kind, |
| 1961 | ArrayRef<TypeSourceInfo *> Args, |
| 1962 | SourceLocation RParenLoc, |
| 1963 | ComparisonCategoryResult Value) { |
| 1964 | void *Mem = |
| 1965 | C.Allocate(Size: totalSizeToAlloc<APValue, TypeSourceInfo *>(Counts: 1, Counts: Args.size())); |
| 1966 | return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value); |
| 1967 | } |
| 1968 | |
| 1969 | TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C, |
| 1970 | bool IsStoredAsBool, |
| 1971 | unsigned NumArgs) { |
| 1972 | void *Mem = C.Allocate(Size: totalSizeToAlloc<APValue, TypeSourceInfo *>( |
| 1973 | Counts: IsStoredAsBool ? 0 : 1, Counts: NumArgs)); |
| 1974 | return new (Mem) TypeTraitExpr(EmptyShell(), IsStoredAsBool); |
| 1975 | } |
| 1976 | |
| 1977 | CXXReflectExpr::CXXReflectExpr(EmptyShell Empty) |
| 1978 | : Expr(CXXReflectExprClass, Empty) {} |
| 1979 | |
| 1980 | CXXReflectExpr::CXXReflectExpr(SourceLocation CaretCaretLoc, |
| 1981 | const TypeSourceInfo *TSI) |
| 1982 | : Expr(CXXReflectExprClass, TSI->getType(), VK_PRValue, OK_Ordinary), |
| 1983 | CaretCaretLoc(CaretCaretLoc), Operand(TSI) {} |
| 1984 | |
| 1985 | CXXReflectExpr *CXXReflectExpr::Create(ASTContext &C, |
| 1986 | SourceLocation CaretCaretLoc, |
| 1987 | TypeSourceInfo *TSI) { |
| 1988 | return new (C) CXXReflectExpr(CaretCaretLoc, TSI); |
| 1989 | } |
| 1990 | |
| 1991 | CXXReflectExpr *CXXReflectExpr::CreateEmpty(ASTContext &C) { |
| 1992 | return new (C) CXXReflectExpr(EmptyShell()); |
| 1993 | } |
| 1994 | |
| 1995 | CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, |
| 1996 | ArrayRef<Expr *> Args, QualType Ty, |
| 1997 | ExprValueKind VK, SourceLocation RP, |
| 1998 | FPOptionsOverride FPFeatures, |
| 1999 | unsigned MinNumArgs) |
| 2000 | : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK, |
| 2001 | RP, FPFeatures, MinNumArgs, NotADL) {} |
| 2002 | |
| 2003 | CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures, |
| 2004 | EmptyShell Empty) |
| 2005 | : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs, |
| 2006 | HasFPFeatures, Empty) {} |
| 2007 | |
| 2008 | CUDAKernelCallExpr * |
| 2009 | CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, |
| 2010 | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
| 2011 | SourceLocation RP, FPOptionsOverride FPFeatures, |
| 2012 | unsigned MinNumArgs) { |
| 2013 | // Allocate storage for the trailing objects of CallExpr. |
| 2014 | unsigned NumArgs = std::max<unsigned>(a: Args.size(), b: MinNumArgs); |
| 2015 | unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects( |
| 2016 | /*NumPreArgs=*/END_PREARG, NumArgs, HasFPFeatures: FPFeatures.requiresTrailingStorage()); |
| 2017 | void *Mem = |
| 2018 | Ctx.Allocate(Size: sizeToAllocateForCallExprSubclass<CUDAKernelCallExpr>( |
| 2019 | SizeOfTrailingObjects), |
| 2020 | Align: alignof(CUDAKernelCallExpr)); |
| 2021 | return new (Mem) |
| 2022 | CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, FPFeatures, MinNumArgs); |
| 2023 | } |
| 2024 | |
| 2025 | CUDAKernelCallExpr *CUDAKernelCallExpr::CreateEmpty(const ASTContext &Ctx, |
| 2026 | unsigned NumArgs, |
| 2027 | bool HasFPFeatures, |
| 2028 | EmptyShell Empty) { |
| 2029 | // Allocate storage for the trailing objects of CallExpr. |
| 2030 | unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects( |
| 2031 | /*NumPreArgs=*/END_PREARG, NumArgs, HasFPFeatures); |
| 2032 | void *Mem = |
| 2033 | Ctx.Allocate(Size: sizeToAllocateForCallExprSubclass<CUDAKernelCallExpr>( |
| 2034 | SizeOfTrailingObjects), |
| 2035 | Align: alignof(CUDAKernelCallExpr)); |
| 2036 | return new (Mem) CUDAKernelCallExpr(NumArgs, HasFPFeatures, Empty); |
| 2037 | } |
| 2038 | |
| 2039 | CXXParenListInitExpr * |
| 2040 | CXXParenListInitExpr::Create(ASTContext &C, ArrayRef<Expr *> Args, QualType T, |
| 2041 | unsigned NumUserSpecifiedExprs, |
| 2042 | SourceLocation InitLoc, SourceLocation LParenLoc, |
| 2043 | SourceLocation RParenLoc) { |
| 2044 | void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: Args.size())); |
| 2045 | return new (Mem) CXXParenListInitExpr(Args, T, NumUserSpecifiedExprs, InitLoc, |
| 2046 | LParenLoc, RParenLoc); |
| 2047 | } |
| 2048 | |
| 2049 | CXXParenListInitExpr *CXXParenListInitExpr::CreateEmpty(ASTContext &C, |
| 2050 | unsigned NumExprs, |
| 2051 | EmptyShell Empty) { |
| 2052 | void *Mem = C.Allocate(Size: totalSizeToAlloc<Expr *>(Counts: NumExprs), |
| 2053 | Align: alignof(CXXParenListInitExpr)); |
| 2054 | return new (Mem) CXXParenListInitExpr(Empty, NumExprs); |
| 2055 | } |
| 2056 | |
| 2057 | CXXFoldExpr::CXXFoldExpr(QualType T, UnresolvedLookupExpr *Callee, |
| 2058 | SourceLocation LParenLoc, Expr *LHS, |
| 2059 | BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, |
| 2060 | Expr *RHS, SourceLocation RParenLoc, |
| 2061 | UnsignedOrNone NumExpansions) |
| 2062 | : Expr(CXXFoldExprClass, T, VK_PRValue, OK_Ordinary), LParenLoc(LParenLoc), |
| 2063 | EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc), |
| 2064 | NumExpansions(NumExpansions) { |
| 2065 | CXXFoldExprBits.Opcode = Opcode; |
| 2066 | // We rely on asserted invariant to distinguish left and right folds. |
| 2067 | if (LHS && RHS) |
| 2068 | assert(LHS->containsUnexpandedParameterPack() != |
| 2069 | RHS->containsUnexpandedParameterPack() && |
| 2070 | "Exactly one of LHS or RHS should contain an unexpanded pack" ); |
| 2071 | SubExprs[SubExpr::Callee] = Callee; |
| 2072 | SubExprs[SubExpr::LHS] = LHS; |
| 2073 | SubExprs[SubExpr::RHS] = RHS; |
| 2074 | setDependence(computeDependence(E: this)); |
| 2075 | } |
| 2076 | |
| 2077 | CXXExpansionSelectExpr::CXXExpansionSelectExpr(EmptyShell Empty) |
| 2078 | : Expr(CXXExpansionSelectExprClass, Empty) {} |
| 2079 | |
| 2080 | CXXExpansionSelectExpr::CXXExpansionSelectExpr(const ASTContext &C, |
| 2081 | InitListExpr *Range, Expr *Idx) |
| 2082 | : Expr(CXXExpansionSelectExprClass, C.DependentTy, VK_PRValue, |
| 2083 | OK_Ordinary) { |
| 2084 | setDependence(ExprDependence::TypeValueInstantiation); |
| 2085 | SubExprs[RANGE] = Range; |
| 2086 | SubExprs[INDEX] = Idx; |
| 2087 | } |
| 2088 | |