1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// 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 // This file implements a semantic tree transformation that takes a given 9 // AST and rebuilds it, possibly transforming some nodes in the process. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H 14 #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H 15 16 #include "CoroutineStmtBuilder.h" 17 #include "TypeLocBuilder.h" 18 #include "clang/AST/Decl.h" 19 #include "clang/AST/DeclObjC.h" 20 #include "clang/AST/DeclTemplate.h" 21 #include "clang/AST/Expr.h" 22 #include "clang/AST/ExprConcepts.h" 23 #include "clang/AST/ExprCXX.h" 24 #include "clang/AST/ExprObjC.h" 25 #include "clang/AST/ExprOpenMP.h" 26 #include "clang/AST/OpenMPClause.h" 27 #include "clang/AST/Stmt.h" 28 #include "clang/AST/StmtCXX.h" 29 #include "clang/AST/StmtObjC.h" 30 #include "clang/AST/StmtOpenMP.h" 31 #include "clang/Sema/Designator.h" 32 #include "clang/Sema/Lookup.h" 33 #include "clang/Sema/Ownership.h" 34 #include "clang/Sema/ParsedTemplate.h" 35 #include "clang/Sema/ScopeInfo.h" 36 #include "clang/Sema/SemaDiagnostic.h" 37 #include "clang/Sema/SemaInternal.h" 38 #include "llvm/ADT/ArrayRef.h" 39 #include "llvm/Support/ErrorHandling.h" 40 #include <algorithm> 41 42 using namespace llvm::omp; 43 44 namespace clang { 45 using namespace sema; 46 47 /// A semantic tree transformation that allows one to transform one 48 /// abstract syntax tree into another. 49 /// 50 /// A new tree transformation is defined by creating a new subclass \c X of 51 /// \c TreeTransform<X> and then overriding certain operations to provide 52 /// behavior specific to that transformation. For example, template 53 /// instantiation is implemented as a tree transformation where the 54 /// transformation of TemplateTypeParmType nodes involves substituting the 55 /// template arguments for their corresponding template parameters; a similar 56 /// transformation is performed for non-type template parameters and 57 /// template template parameters. 58 /// 59 /// This tree-transformation template uses static polymorphism to allow 60 /// subclasses to customize any of its operations. Thus, a subclass can 61 /// override any of the transformation or rebuild operators by providing an 62 /// operation with the same signature as the default implementation. The 63 /// overriding function should not be virtual. 64 /// 65 /// Semantic tree transformations are split into two stages, either of which 66 /// can be replaced by a subclass. The "transform" step transforms an AST node 67 /// or the parts of an AST node using the various transformation functions, 68 /// then passes the pieces on to the "rebuild" step, which constructs a new AST 69 /// node of the appropriate kind from the pieces. The default transformation 70 /// routines recursively transform the operands to composite AST nodes (e.g., 71 /// the pointee type of a PointerType node) and, if any of those operand nodes 72 /// were changed by the transformation, invokes the rebuild operation to create 73 /// a new AST node. 74 /// 75 /// Subclasses can customize the transformation at various levels. The 76 /// most coarse-grained transformations involve replacing TransformType(), 77 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), 78 /// TransformTemplateName(), or TransformTemplateArgument() with entirely 79 /// new implementations. 80 /// 81 /// For more fine-grained transformations, subclasses can replace any of the 82 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., 83 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, 84 /// replacing TransformTemplateTypeParmType() allows template instantiation 85 /// to substitute template arguments for their corresponding template 86 /// parameters. Additionally, subclasses can override the \c RebuildXXX 87 /// functions to control how AST nodes are rebuilt when their operands change. 88 /// By default, \c TreeTransform will invoke semantic analysis to rebuild 89 /// AST nodes. However, certain other tree transformations (e.g, cloning) may 90 /// be able to use more efficient rebuild steps. 91 /// 92 /// There are a handful of other functions that can be overridden, allowing one 93 /// to avoid traversing nodes that don't need any transformation 94 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their 95 /// operands have not changed (\c AlwaysRebuild()), and customize the 96 /// default locations and entity names used for type-checking 97 /// (\c getBaseLocation(), \c getBaseEntity()). 98 template<typename Derived> 99 class TreeTransform { 100 /// Private RAII object that helps us forget and then re-remember 101 /// the template argument corresponding to a partially-substituted parameter 102 /// pack. 103 class ForgetPartiallySubstitutedPackRAII { 104 Derived &Self; 105 TemplateArgument Old; 106 107 public: 108 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { 109 Old = Self.ForgetPartiallySubstitutedPack(); 110 } 111 112 ~ForgetPartiallySubstitutedPackRAII() { 113 Self.RememberPartiallySubstitutedPack(Old); 114 } 115 }; 116 117 protected: 118 Sema &SemaRef; 119 120 /// The set of local declarations that have been transformed, for 121 /// cases where we are forced to build new declarations within the transformer 122 /// rather than in the subclass (e.g., lambda closure types). 123 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; 124 125 public: 126 /// Initializes a new tree transformer. 127 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } 128 129 /// Retrieves a reference to the derived class. 130 Derived &getDerived() { return static_cast<Derived&>(*this); } 131 132 /// Retrieves a reference to the derived class. 133 const Derived &getDerived() const { 134 return static_cast<const Derived&>(*this); 135 } 136 137 static inline ExprResult Owned(Expr *E) { return E; } 138 static inline StmtResult Owned(Stmt *S) { return S; } 139 140 /// Retrieves a reference to the semantic analysis object used for 141 /// this tree transform. 142 Sema &getSema() const { return SemaRef; } 143 144 /// Whether the transformation should always rebuild AST nodes, even 145 /// if none of the children have changed. 146 /// 147 /// Subclasses may override this function to specify when the transformation 148 /// should rebuild all AST nodes. 149 /// 150 /// We must always rebuild all AST nodes when performing variadic template 151 /// pack expansion, in order to avoid violating the AST invariant that each 152 /// statement node appears at most once in its containing declaration. 153 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } 154 155 /// Whether the transformation is forming an expression or statement that 156 /// replaces the original. In this case, we'll reuse mangling numbers from 157 /// existing lambdas. 158 bool ReplacingOriginal() { return false; } 159 160 /// Returns the location of the entity being transformed, if that 161 /// information was not available elsewhere in the AST. 162 /// 163 /// By default, returns no source-location information. Subclasses can 164 /// provide an alternative implementation that provides better location 165 /// information. 166 SourceLocation getBaseLocation() { return SourceLocation(); } 167 168 /// Returns the name of the entity being transformed, if that 169 /// information was not available elsewhere in the AST. 170 /// 171 /// By default, returns an empty name. Subclasses can provide an alternative 172 /// implementation with a more precise name. 173 DeclarationName getBaseEntity() { return DeclarationName(); } 174 175 /// Sets the "base" location and entity when that 176 /// information is known based on another transformation. 177 /// 178 /// By default, the source location and entity are ignored. Subclasses can 179 /// override this function to provide a customized implementation. 180 void setBase(SourceLocation Loc, DeclarationName Entity) { } 181 182 /// RAII object that temporarily sets the base location and entity 183 /// used for reporting diagnostics in types. 184 class TemporaryBase { 185 TreeTransform &Self; 186 SourceLocation OldLocation; 187 DeclarationName OldEntity; 188 189 public: 190 TemporaryBase(TreeTransform &Self, SourceLocation Location, 191 DeclarationName Entity) : Self(Self) { 192 OldLocation = Self.getDerived().getBaseLocation(); 193 OldEntity = Self.getDerived().getBaseEntity(); 194 195 if (Location.isValid()) 196 Self.getDerived().setBase(Location, Entity); 197 } 198 199 ~TemporaryBase() { 200 Self.getDerived().setBase(OldLocation, OldEntity); 201 } 202 }; 203 204 /// Determine whether the given type \p T has already been 205 /// transformed. 206 /// 207 /// Subclasses can provide an alternative implementation of this routine 208 /// to short-circuit evaluation when it is known that a given type will 209 /// not change. For example, template instantiation need not traverse 210 /// non-dependent types. 211 bool AlreadyTransformed(QualType T) { 212 return T.isNull(); 213 } 214 215 /// Transform a template parameter depth level. 216 /// 217 /// During a transformation that transforms template parameters, this maps 218 /// an old template parameter depth to a new depth. 219 unsigned TransformTemplateDepth(unsigned Depth) { 220 return Depth; 221 } 222 223 /// Determine whether the given call argument should be dropped, e.g., 224 /// because it is a default argument. 225 /// 226 /// Subclasses can provide an alternative implementation of this routine to 227 /// determine which kinds of call arguments get dropped. By default, 228 /// CXXDefaultArgument nodes are dropped (prior to transformation). 229 bool DropCallArgument(Expr *E) { 230 return E->isDefaultArgument(); 231 } 232 233 /// Determine whether we should expand a pack expansion with the 234 /// given set of parameter packs into separate arguments by repeatedly 235 /// transforming the pattern. 236 /// 237 /// By default, the transformer never tries to expand pack expansions. 238 /// Subclasses can override this routine to provide different behavior. 239 /// 240 /// \param EllipsisLoc The location of the ellipsis that identifies the 241 /// pack expansion. 242 /// 243 /// \param PatternRange The source range that covers the entire pattern of 244 /// the pack expansion. 245 /// 246 /// \param Unexpanded The set of unexpanded parameter packs within the 247 /// pattern. 248 /// 249 /// \param ShouldExpand Will be set to \c true if the transformer should 250 /// expand the corresponding pack expansions into separate arguments. When 251 /// set, \c NumExpansions must also be set. 252 /// 253 /// \param RetainExpansion Whether the caller should add an unexpanded 254 /// pack expansion after all of the expanded arguments. This is used 255 /// when extending explicitly-specified template argument packs per 256 /// C++0x [temp.arg.explicit]p9. 257 /// 258 /// \param NumExpansions The number of separate arguments that will be in 259 /// the expanded form of the corresponding pack expansion. This is both an 260 /// input and an output parameter, which can be set by the caller if the 261 /// number of expansions is known a priori (e.g., due to a prior substitution) 262 /// and will be set by the callee when the number of expansions is known. 263 /// The callee must set this value when \c ShouldExpand is \c true; it may 264 /// set this value in other cases. 265 /// 266 /// \returns true if an error occurred (e.g., because the parameter packs 267 /// are to be instantiated with arguments of different lengths), false 268 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 269 /// must be set. 270 bool TryExpandParameterPacks(SourceLocation EllipsisLoc, 271 SourceRange PatternRange, 272 ArrayRef<UnexpandedParameterPack> Unexpanded, 273 bool &ShouldExpand, 274 bool &RetainExpansion, 275 Optional<unsigned> &NumExpansions) { 276 ShouldExpand = false; 277 return false; 278 } 279 280 /// "Forget" about the partially-substituted pack template argument, 281 /// when performing an instantiation that must preserve the parameter pack 282 /// use. 283 /// 284 /// This routine is meant to be overridden by the template instantiator. 285 TemplateArgument ForgetPartiallySubstitutedPack() { 286 return TemplateArgument(); 287 } 288 289 /// "Remember" the partially-substituted pack template argument 290 /// after performing an instantiation that must preserve the parameter pack 291 /// use. 292 /// 293 /// This routine is meant to be overridden by the template instantiator. 294 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } 295 296 /// Note to the derived class when a function parameter pack is 297 /// being expanded. 298 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } 299 300 /// Transforms the given type into another type. 301 /// 302 /// By default, this routine transforms a type by creating a 303 /// TypeSourceInfo for it and delegating to the appropriate 304 /// function. This is expensive, but we don't mind, because 305 /// this method is deprecated anyway; all users should be 306 /// switched to storing TypeSourceInfos. 307 /// 308 /// \returns the transformed type. 309 QualType TransformType(QualType T); 310 311 /// Transforms the given type-with-location into a new 312 /// type-with-location. 313 /// 314 /// By default, this routine transforms a type by delegating to the 315 /// appropriate TransformXXXType to build a new type. Subclasses 316 /// may override this function (to take over all type 317 /// transformations) or some set of the TransformXXXType functions 318 /// to alter the transformation. 319 TypeSourceInfo *TransformType(TypeSourceInfo *DI); 320 321 /// Transform the given type-with-location into a new 322 /// type, collecting location information in the given builder 323 /// as necessary. 324 /// 325 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); 326 327 /// Transform a type that is permitted to produce a 328 /// DeducedTemplateSpecializationType. 329 /// 330 /// This is used in the (relatively rare) contexts where it is acceptable 331 /// for transformation to produce a class template type with deduced 332 /// template arguments. 333 /// @{ 334 QualType TransformTypeWithDeducedTST(QualType T); 335 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI); 336 /// @} 337 338 /// The reason why the value of a statement is not discarded, if any. 339 enum StmtDiscardKind { 340 SDK_Discarded, 341 SDK_NotDiscarded, 342 SDK_StmtExprResult, 343 }; 344 345 /// Transform the given statement. 346 /// 347 /// By default, this routine transforms a statement by delegating to the 348 /// appropriate TransformXXXStmt function to transform a specific kind of 349 /// statement or the TransformExpr() function to transform an expression. 350 /// Subclasses may override this function to transform statements using some 351 /// other mechanism. 352 /// 353 /// \returns the transformed statement. 354 StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded); 355 356 /// Transform the given statement. 357 /// 358 /// By default, this routine transforms a statement by delegating to the 359 /// appropriate TransformOMPXXXClause function to transform a specific kind 360 /// of clause. Subclasses may override this function to transform statements 361 /// using some other mechanism. 362 /// 363 /// \returns the transformed OpenMP clause. 364 OMPClause *TransformOMPClause(OMPClause *S); 365 366 /// Transform the given attribute. 367 /// 368 /// By default, this routine transforms a statement by delegating to the 369 /// appropriate TransformXXXAttr function to transform a specific kind 370 /// of attribute. Subclasses may override this function to transform 371 /// attributed statements using some other mechanism. 372 /// 373 /// \returns the transformed attribute 374 const Attr *TransformAttr(const Attr *S); 375 376 /// Transform the specified attribute. 377 /// 378 /// Subclasses should override the transformation of attributes with a pragma 379 /// spelling to transform expressions stored within the attribute. 380 /// 381 /// \returns the transformed attribute. 382 #define ATTR(X) 383 #define PRAGMA_SPELLING_ATTR(X) \ 384 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } 385 #include "clang/Basic/AttrList.inc" 386 387 /// Transform the given expression. 388 /// 389 /// By default, this routine transforms an expression by delegating to the 390 /// appropriate TransformXXXExpr function to build a new expression. 391 /// Subclasses may override this function to transform expressions using some 392 /// other mechanism. 393 /// 394 /// \returns the transformed expression. 395 ExprResult TransformExpr(Expr *E); 396 397 /// Transform the given initializer. 398 /// 399 /// By default, this routine transforms an initializer by stripping off the 400 /// semantic nodes added by initialization, then passing the result to 401 /// TransformExpr or TransformExprs. 402 /// 403 /// \returns the transformed initializer. 404 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); 405 406 /// Transform the given list of expressions. 407 /// 408 /// This routine transforms a list of expressions by invoking 409 /// \c TransformExpr() for each subexpression. However, it also provides 410 /// support for variadic templates by expanding any pack expansions (if the 411 /// derived class permits such expansion) along the way. When pack expansions 412 /// are present, the number of outputs may not equal the number of inputs. 413 /// 414 /// \param Inputs The set of expressions to be transformed. 415 /// 416 /// \param NumInputs The number of expressions in \c Inputs. 417 /// 418 /// \param IsCall If \c true, then this transform is being performed on 419 /// function-call arguments, and any arguments that should be dropped, will 420 /// be. 421 /// 422 /// \param Outputs The transformed input expressions will be added to this 423 /// vector. 424 /// 425 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed 426 /// due to transformation. 427 /// 428 /// \returns true if an error occurred, false otherwise. 429 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, 430 SmallVectorImpl<Expr *> &Outputs, 431 bool *ArgChanged = nullptr); 432 433 /// Transform the given declaration, which is referenced from a type 434 /// or expression. 435 /// 436 /// By default, acts as the identity function on declarations, unless the 437 /// transformer has had to transform the declaration itself. Subclasses 438 /// may override this function to provide alternate behavior. 439 Decl *TransformDecl(SourceLocation Loc, Decl *D) { 440 llvm::DenseMap<Decl *, Decl *>::iterator Known 441 = TransformedLocalDecls.find(D); 442 if (Known != TransformedLocalDecls.end()) 443 return Known->second; 444 445 return D; 446 } 447 448 /// Transform the specified condition. 449 /// 450 /// By default, this transforms the variable and expression and rebuilds 451 /// the condition. 452 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, 453 Expr *Expr, 454 Sema::ConditionKind Kind); 455 456 /// Transform the attributes associated with the given declaration and 457 /// place them on the new declaration. 458 /// 459 /// By default, this operation does nothing. Subclasses may override this 460 /// behavior to transform attributes. 461 void transformAttrs(Decl *Old, Decl *New) { } 462 463 /// Note that a local declaration has been transformed by this 464 /// transformer. 465 /// 466 /// Local declarations are typically transformed via a call to 467 /// TransformDefinition. However, in some cases (e.g., lambda expressions), 468 /// the transformer itself has to transform the declarations. This routine 469 /// can be overridden by a subclass that keeps track of such mappings. 470 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) { 471 assert(New.size() == 1 && 472 "must override transformedLocalDecl if performing pack expansion"); 473 TransformedLocalDecls[Old] = New.front(); 474 } 475 476 /// Transform the definition of the given declaration. 477 /// 478 /// By default, invokes TransformDecl() to transform the declaration. 479 /// Subclasses may override this function to provide alternate behavior. 480 Decl *TransformDefinition(SourceLocation Loc, Decl *D) { 481 return getDerived().TransformDecl(Loc, D); 482 } 483 484 /// Transform the given declaration, which was the first part of a 485 /// nested-name-specifier in a member access expression. 486 /// 487 /// This specific declaration transformation only applies to the first 488 /// identifier in a nested-name-specifier of a member access expression, e.g., 489 /// the \c T in \c x->T::member 490 /// 491 /// By default, invokes TransformDecl() to transform the declaration. 492 /// Subclasses may override this function to provide alternate behavior. 493 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { 494 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); 495 } 496 497 /// Transform the set of declarations in an OverloadExpr. 498 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, 499 LookupResult &R); 500 501 /// Transform the given nested-name-specifier with source-location 502 /// information. 503 /// 504 /// By default, transforms all of the types and declarations within the 505 /// nested-name-specifier. Subclasses may override this function to provide 506 /// alternate behavior. 507 NestedNameSpecifierLoc 508 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 509 QualType ObjectType = QualType(), 510 NamedDecl *FirstQualifierInScope = nullptr); 511 512 /// Transform the given declaration name. 513 /// 514 /// By default, transforms the types of conversion function, constructor, 515 /// and destructor names and then (if needed) rebuilds the declaration name. 516 /// Identifiers and selectors are returned unmodified. Sublcasses may 517 /// override this function to provide alternate behavior. 518 DeclarationNameInfo 519 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); 520 521 bool TransformRequiresExprRequirements(ArrayRef<concepts::Requirement *> Reqs, 522 llvm::SmallVectorImpl<concepts::Requirement *> &Transformed); 523 concepts::TypeRequirement * 524 TransformTypeRequirement(concepts::TypeRequirement *Req); 525 concepts::ExprRequirement * 526 TransformExprRequirement(concepts::ExprRequirement *Req); 527 concepts::NestedRequirement * 528 TransformNestedRequirement(concepts::NestedRequirement *Req); 529 530 /// Transform the given template name. 531 /// 532 /// \param SS The nested-name-specifier that qualifies the template 533 /// name. This nested-name-specifier must already have been transformed. 534 /// 535 /// \param Name The template name to transform. 536 /// 537 /// \param NameLoc The source location of the template name. 538 /// 539 /// \param ObjectType If we're translating a template name within a member 540 /// access expression, this is the type of the object whose member template 541 /// is being referenced. 542 /// 543 /// \param FirstQualifierInScope If the first part of a nested-name-specifier 544 /// also refers to a name within the current (lexical) scope, this is the 545 /// declaration it refers to. 546 /// 547 /// By default, transforms the template name by transforming the declarations 548 /// and nested-name-specifiers that occur within the template name. 549 /// Subclasses may override this function to provide alternate behavior. 550 TemplateName 551 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, 552 SourceLocation NameLoc, 553 QualType ObjectType = QualType(), 554 NamedDecl *FirstQualifierInScope = nullptr, 555 bool AllowInjectedClassName = false); 556 557 /// Transform the given template argument. 558 /// 559 /// By default, this operation transforms the type, expression, or 560 /// declaration stored within the template argument and constructs a 561 /// new template argument from the transformed result. Subclasses may 562 /// override this function to provide alternate behavior. 563 /// 564 /// Returns true if there was an error. 565 bool TransformTemplateArgument(const TemplateArgumentLoc &Input, 566 TemplateArgumentLoc &Output, 567 bool Uneval = false); 568 569 /// Transform the given set of template arguments. 570 /// 571 /// By default, this operation transforms all of the template arguments 572 /// in the input set using \c TransformTemplateArgument(), and appends 573 /// the transformed arguments to the output list. 574 /// 575 /// Note that this overload of \c TransformTemplateArguments() is merely 576 /// a convenience function. Subclasses that wish to override this behavior 577 /// should override the iterator-based member template version. 578 /// 579 /// \param Inputs The set of template arguments to be transformed. 580 /// 581 /// \param NumInputs The number of template arguments in \p Inputs. 582 /// 583 /// \param Outputs The set of transformed template arguments output by this 584 /// routine. 585 /// 586 /// Returns true if an error occurred. 587 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, 588 unsigned NumInputs, 589 TemplateArgumentListInfo &Outputs, 590 bool Uneval = false) { 591 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, 592 Uneval); 593 } 594 595 /// Transform the given set of template arguments. 596 /// 597 /// By default, this operation transforms all of the template arguments 598 /// in the input set using \c TransformTemplateArgument(), and appends 599 /// the transformed arguments to the output list. 600 /// 601 /// \param First An iterator to the first template argument. 602 /// 603 /// \param Last An iterator one step past the last template argument. 604 /// 605 /// \param Outputs The set of transformed template arguments output by this 606 /// routine. 607 /// 608 /// Returns true if an error occurred. 609 template<typename InputIterator> 610 bool TransformTemplateArguments(InputIterator First, 611 InputIterator Last, 612 TemplateArgumentListInfo &Outputs, 613 bool Uneval = false); 614 615 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument. 616 void InventTemplateArgumentLoc(const TemplateArgument &Arg, 617 TemplateArgumentLoc &ArgLoc); 618 619 /// Fakes up a TypeSourceInfo for a type. 620 TypeSourceInfo *InventTypeSourceInfo(QualType T) { 621 return SemaRef.Context.getTrivialTypeSourceInfo(T, 622 getDerived().getBaseLocation()); 623 } 624 625 #define ABSTRACT_TYPELOC(CLASS, PARENT) 626 #define TYPELOC(CLASS, PARENT) \ 627 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); 628 #include "clang/AST/TypeLocNodes.def" 629 630 template<typename Fn> 631 QualType TransformFunctionProtoType(TypeLocBuilder &TLB, 632 FunctionProtoTypeLoc TL, 633 CXXRecordDecl *ThisContext, 634 Qualifiers ThisTypeQuals, 635 Fn TransformExceptionSpec); 636 637 bool TransformExceptionSpec(SourceLocation Loc, 638 FunctionProtoType::ExceptionSpecInfo &ESI, 639 SmallVectorImpl<QualType> &Exceptions, 640 bool &Changed); 641 642 StmtResult TransformSEHHandler(Stmt *Handler); 643 644 QualType 645 TransformTemplateSpecializationType(TypeLocBuilder &TLB, 646 TemplateSpecializationTypeLoc TL, 647 TemplateName Template); 648 649 QualType 650 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 651 DependentTemplateSpecializationTypeLoc TL, 652 TemplateName Template, 653 CXXScopeSpec &SS); 654 655 QualType TransformDependentTemplateSpecializationType( 656 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, 657 NestedNameSpecifierLoc QualifierLoc); 658 659 /// Transforms the parameters of a function type into the 660 /// given vectors. 661 /// 662 /// The result vectors should be kept in sync; null entries in the 663 /// variables vector are acceptable. 664 /// 665 /// Return true on error. 666 bool TransformFunctionTypeParams( 667 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, 668 const QualType *ParamTypes, 669 const FunctionProtoType::ExtParameterInfo *ParamInfos, 670 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, 671 Sema::ExtParameterInfoBuilder &PInfos); 672 673 /// Transforms a single function-type parameter. Return null 674 /// on error. 675 /// 676 /// \param indexAdjustment - A number to add to the parameter's 677 /// scope index; can be negative 678 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, 679 int indexAdjustment, 680 Optional<unsigned> NumExpansions, 681 bool ExpectParameterPack); 682 683 /// Transform the body of a lambda-expression. 684 StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body); 685 /// Alternative implementation of TransformLambdaBody that skips transforming 686 /// the body. 687 StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body); 688 689 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); 690 691 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); 692 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); 693 694 TemplateParameterList *TransformTemplateParameterList( 695 TemplateParameterList *TPL) { 696 return TPL; 697 } 698 699 ExprResult TransformAddressOfOperand(Expr *E); 700 701 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, 702 bool IsAddressOfOperand, 703 TypeSourceInfo **RecoveryTSI); 704 705 ExprResult TransformParenDependentScopeDeclRefExpr( 706 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, 707 TypeSourceInfo **RecoveryTSI); 708 709 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); 710 711 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous 712 // amount of stack usage with clang. 713 #define STMT(Node, Parent) \ 714 LLVM_ATTRIBUTE_NOINLINE \ 715 StmtResult Transform##Node(Node *S); 716 #define VALUESTMT(Node, Parent) \ 717 LLVM_ATTRIBUTE_NOINLINE \ 718 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK); 719 #define EXPR(Node, Parent) \ 720 LLVM_ATTRIBUTE_NOINLINE \ 721 ExprResult Transform##Node(Node *E); 722 #define ABSTRACT_STMT(Stmt) 723 #include "clang/AST/StmtNodes.inc" 724 725 #define OPENMP_CLAUSE(Name, Class) \ 726 LLVM_ATTRIBUTE_NOINLINE \ 727 OMPClause *Transform ## Class(Class *S); 728 #include "clang/Basic/OpenMPKinds.def" 729 730 /// Build a new qualified type given its unqualified type and type location. 731 /// 732 /// By default, this routine adds type qualifiers only to types that can 733 /// have qualifiers, and silently suppresses those qualifiers that are not 734 /// permitted. Subclasses may override this routine to provide different 735 /// behavior. 736 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL); 737 738 /// Build a new pointer type given its pointee type. 739 /// 740 /// By default, performs semantic analysis when building the pointer type. 741 /// Subclasses may override this routine to provide different behavior. 742 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 743 744 /// Build a new block pointer type given its pointee type. 745 /// 746 /// By default, performs semantic analysis when building the block pointer 747 /// type. Subclasses may override this routine to provide different behavior. 748 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 749 750 /// Build a new reference type given the type it references. 751 /// 752 /// By default, performs semantic analysis when building the 753 /// reference type. Subclasses may override this routine to provide 754 /// different behavior. 755 /// 756 /// \param LValue whether the type was written with an lvalue sigil 757 /// or an rvalue sigil. 758 QualType RebuildReferenceType(QualType ReferentType, 759 bool LValue, 760 SourceLocation Sigil); 761 762 /// Build a new member pointer type given the pointee type and the 763 /// class type it refers into. 764 /// 765 /// By default, performs semantic analysis when building the member pointer 766 /// type. Subclasses may override this routine to provide different behavior. 767 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 768 SourceLocation Sigil); 769 770 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, 771 SourceLocation ProtocolLAngleLoc, 772 ArrayRef<ObjCProtocolDecl *> Protocols, 773 ArrayRef<SourceLocation> ProtocolLocs, 774 SourceLocation ProtocolRAngleLoc); 775 776 /// Build an Objective-C object type. 777 /// 778 /// By default, performs semantic analysis when building the object type. 779 /// Subclasses may override this routine to provide different behavior. 780 QualType RebuildObjCObjectType(QualType BaseType, 781 SourceLocation Loc, 782 SourceLocation TypeArgsLAngleLoc, 783 ArrayRef<TypeSourceInfo *> TypeArgs, 784 SourceLocation TypeArgsRAngleLoc, 785 SourceLocation ProtocolLAngleLoc, 786 ArrayRef<ObjCProtocolDecl *> Protocols, 787 ArrayRef<SourceLocation> ProtocolLocs, 788 SourceLocation ProtocolRAngleLoc); 789 790 /// Build a new Objective-C object pointer type given the pointee type. 791 /// 792 /// By default, directly builds the pointer type, with no additional semantic 793 /// analysis. 794 QualType RebuildObjCObjectPointerType(QualType PointeeType, 795 SourceLocation Star); 796 797 /// Build a new array type given the element type, size 798 /// modifier, size of the array (if known), size expression, and index type 799 /// qualifiers. 800 /// 801 /// By default, performs semantic analysis when building the array type. 802 /// Subclasses may override this routine to provide different behavior. 803 /// Also by default, all of the other Rebuild*Array 804 QualType RebuildArrayType(QualType ElementType, 805 ArrayType::ArraySizeModifier SizeMod, 806 const llvm::APInt *Size, 807 Expr *SizeExpr, 808 unsigned IndexTypeQuals, 809 SourceRange BracketsRange); 810 811 /// Build a new constant array type given the element type, size 812 /// modifier, (known) size of the array, and index type qualifiers. 813 /// 814 /// By default, performs semantic analysis when building the array type. 815 /// Subclasses may override this routine to provide different behavior. 816 QualType RebuildConstantArrayType(QualType ElementType, 817 ArrayType::ArraySizeModifier SizeMod, 818 const llvm::APInt &Size, 819 Expr *SizeExpr, 820 unsigned IndexTypeQuals, 821 SourceRange BracketsRange); 822 823 /// Build a new incomplete array type given the element type, size 824 /// modifier, and index type qualifiers. 825 /// 826 /// By default, performs semantic analysis when building the array type. 827 /// Subclasses may override this routine to provide different behavior. 828 QualType RebuildIncompleteArrayType(QualType ElementType, 829 ArrayType::ArraySizeModifier SizeMod, 830 unsigned IndexTypeQuals, 831 SourceRange BracketsRange); 832 833 /// Build a new variable-length array type given the element type, 834 /// size modifier, size expression, and index type qualifiers. 835 /// 836 /// By default, performs semantic analysis when building the array type. 837 /// Subclasses may override this routine to provide different behavior. 838 QualType RebuildVariableArrayType(QualType ElementType, 839 ArrayType::ArraySizeModifier SizeMod, 840 Expr *SizeExpr, 841 unsigned IndexTypeQuals, 842 SourceRange BracketsRange); 843 844 /// Build a new dependent-sized array type given the element type, 845 /// size modifier, size expression, and index type qualifiers. 846 /// 847 /// By default, performs semantic analysis when building the array type. 848 /// Subclasses may override this routine to provide different behavior. 849 QualType RebuildDependentSizedArrayType(QualType ElementType, 850 ArrayType::ArraySizeModifier SizeMod, 851 Expr *SizeExpr, 852 unsigned IndexTypeQuals, 853 SourceRange BracketsRange); 854 855 /// Build a new vector type given the element type and 856 /// number of elements. 857 /// 858 /// By default, performs semantic analysis when building the vector type. 859 /// Subclasses may override this routine to provide different behavior. 860 QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 861 VectorType::VectorKind VecKind); 862 863 /// Build a new potentially dependently-sized extended vector type 864 /// given the element type and number of elements. 865 /// 866 /// By default, performs semantic analysis when building the vector type. 867 /// Subclasses may override this routine to provide different behavior. 868 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, 869 SourceLocation AttributeLoc, 870 VectorType::VectorKind); 871 872 /// Build a new extended vector type given the element type and 873 /// number of elements. 874 /// 875 /// By default, performs semantic analysis when building the vector type. 876 /// Subclasses may override this routine to provide different behavior. 877 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 878 SourceLocation AttributeLoc); 879 880 /// Build a new potentially dependently-sized extended vector type 881 /// given the element type and number of elements. 882 /// 883 /// By default, performs semantic analysis when building the vector type. 884 /// Subclasses may override this routine to provide different behavior. 885 QualType RebuildDependentSizedExtVectorType(QualType ElementType, 886 Expr *SizeExpr, 887 SourceLocation AttributeLoc); 888 889 /// Build a new DependentAddressSpaceType or return the pointee 890 /// type variable with the correct address space (retrieved from 891 /// AddrSpaceExpr) applied to it. The former will be returned in cases 892 /// where the address space remains dependent. 893 /// 894 /// By default, performs semantic analysis when building the type with address 895 /// space applied. Subclasses may override this routine to provide different 896 /// behavior. 897 QualType RebuildDependentAddressSpaceType(QualType PointeeType, 898 Expr *AddrSpaceExpr, 899 SourceLocation AttributeLoc); 900 901 /// Build a new function type. 902 /// 903 /// By default, performs semantic analysis when building the function type. 904 /// Subclasses may override this routine to provide different behavior. 905 QualType RebuildFunctionProtoType(QualType T, 906 MutableArrayRef<QualType> ParamTypes, 907 const FunctionProtoType::ExtProtoInfo &EPI); 908 909 /// Build a new unprototyped function type. 910 QualType RebuildFunctionNoProtoType(QualType ResultType); 911 912 /// Rebuild an unresolved typename type, given the decl that 913 /// the UnresolvedUsingTypenameDecl was transformed to. 914 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D); 915 916 /// Build a new typedef type. 917 QualType RebuildTypedefType(TypedefNameDecl *Typedef) { 918 return SemaRef.Context.getTypeDeclType(Typedef); 919 } 920 921 /// Build a new MacroDefined type. 922 QualType RebuildMacroQualifiedType(QualType T, 923 const IdentifierInfo *MacroII) { 924 return SemaRef.Context.getMacroQualifiedType(T, MacroII); 925 } 926 927 /// Build a new class/struct/union type. 928 QualType RebuildRecordType(RecordDecl *Record) { 929 return SemaRef.Context.getTypeDeclType(Record); 930 } 931 932 /// Build a new Enum type. 933 QualType RebuildEnumType(EnumDecl *Enum) { 934 return SemaRef.Context.getTypeDeclType(Enum); 935 } 936 937 /// Build a new typeof(expr) type. 938 /// 939 /// By default, performs semantic analysis when building the typeof type. 940 /// Subclasses may override this routine to provide different behavior. 941 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); 942 943 /// Build a new typeof(type) type. 944 /// 945 /// By default, builds a new TypeOfType with the given underlying type. 946 QualType RebuildTypeOfType(QualType Underlying); 947 948 /// Build a new unary transform type. 949 QualType RebuildUnaryTransformType(QualType BaseType, 950 UnaryTransformType::UTTKind UKind, 951 SourceLocation Loc); 952 953 /// Build a new C++11 decltype type. 954 /// 955 /// By default, performs semantic analysis when building the decltype type. 956 /// Subclasses may override this routine to provide different behavior. 957 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 958 959 /// Build a new C++11 auto type. 960 /// 961 /// By default, builds a new AutoType with the given deduced type. 962 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, 963 ConceptDecl *TypeConstraintConcept, 964 ArrayRef<TemplateArgument> TypeConstraintArgs) { 965 // Note, IsDependent is always false here: we implicitly convert an 'auto' 966 // which has been deduced to a dependent type into an undeduced 'auto', so 967 // that we'll retry deduction after the transformation. 968 return SemaRef.Context.getAutoType(Deduced, Keyword, 969 /*IsDependent*/ false, /*IsPack=*/false, 970 TypeConstraintConcept, 971 TypeConstraintArgs); 972 } 973 974 /// By default, builds a new DeducedTemplateSpecializationType with the given 975 /// deduced type. 976 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, 977 QualType Deduced) { 978 return SemaRef.Context.getDeducedTemplateSpecializationType( 979 Template, Deduced, /*IsDependent*/ false); 980 } 981 982 /// Build a new template specialization type. 983 /// 984 /// By default, performs semantic analysis when building the template 985 /// specialization type. Subclasses may override this routine to provide 986 /// different behavior. 987 QualType RebuildTemplateSpecializationType(TemplateName Template, 988 SourceLocation TemplateLoc, 989 TemplateArgumentListInfo &Args); 990 991 /// Build a new parenthesized type. 992 /// 993 /// By default, builds a new ParenType type from the inner type. 994 /// Subclasses may override this routine to provide different behavior. 995 QualType RebuildParenType(QualType InnerType) { 996 return SemaRef.BuildParenType(InnerType); 997 } 998 999 /// Build a new qualified name type. 1000 /// 1001 /// By default, builds a new ElaboratedType type from the keyword, 1002 /// the nested-name-specifier and the named type. 1003 /// Subclasses may override this routine to provide different behavior. 1004 QualType RebuildElaboratedType(SourceLocation KeywordLoc, 1005 ElaboratedTypeKeyword Keyword, 1006 NestedNameSpecifierLoc QualifierLoc, 1007 QualType Named) { 1008 return SemaRef.Context.getElaboratedType(Keyword, 1009 QualifierLoc.getNestedNameSpecifier(), 1010 Named); 1011 } 1012 1013 /// Build a new typename type that refers to a template-id. 1014 /// 1015 /// By default, builds a new DependentNameType type from the 1016 /// nested-name-specifier and the given type. Subclasses may override 1017 /// this routine to provide different behavior. 1018 QualType RebuildDependentTemplateSpecializationType( 1019 ElaboratedTypeKeyword Keyword, 1020 NestedNameSpecifierLoc QualifierLoc, 1021 SourceLocation TemplateKWLoc, 1022 const IdentifierInfo *Name, 1023 SourceLocation NameLoc, 1024 TemplateArgumentListInfo &Args, 1025 bool AllowInjectedClassName) { 1026 // Rebuild the template name. 1027 // TODO: avoid TemplateName abstraction 1028 CXXScopeSpec SS; 1029 SS.Adopt(QualifierLoc); 1030 TemplateName InstName = getDerived().RebuildTemplateName( 1031 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr, 1032 AllowInjectedClassName); 1033 1034 if (InstName.isNull()) 1035 return QualType(); 1036 1037 // If it's still dependent, make a dependent specialization. 1038 if (InstName.getAsDependentTemplateName()) 1039 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, 1040 QualifierLoc.getNestedNameSpecifier(), 1041 Name, 1042 Args); 1043 1044 // Otherwise, make an elaborated type wrapping a non-dependent 1045 // specialization. 1046 QualType T = 1047 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 1048 if (T.isNull()) return QualType(); 1049 1050 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) 1051 return T; 1052 1053 return SemaRef.Context.getElaboratedType(Keyword, 1054 QualifierLoc.getNestedNameSpecifier(), 1055 T); 1056 } 1057 1058 /// Build a new typename type that refers to an identifier. 1059 /// 1060 /// By default, performs semantic analysis when building the typename type 1061 /// (or elaborated type). Subclasses may override this routine to provide 1062 /// different behavior. 1063 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 1064 SourceLocation KeywordLoc, 1065 NestedNameSpecifierLoc QualifierLoc, 1066 const IdentifierInfo *Id, 1067 SourceLocation IdLoc, 1068 bool DeducedTSTContext) { 1069 CXXScopeSpec SS; 1070 SS.Adopt(QualifierLoc); 1071 1072 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { 1073 // If the name is still dependent, just build a new dependent name type. 1074 if (!SemaRef.computeDeclContext(SS)) 1075 return SemaRef.Context.getDependentNameType(Keyword, 1076 QualifierLoc.getNestedNameSpecifier(), 1077 Id); 1078 } 1079 1080 if (Keyword == ETK_None || Keyword == ETK_Typename) { 1081 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, 1082 *Id, IdLoc, DeducedTSTContext); 1083 } 1084 1085 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 1086 1087 // We had a dependent elaborated-type-specifier that has been transformed 1088 // into a non-dependent elaborated-type-specifier. Find the tag we're 1089 // referring to. 1090 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 1091 DeclContext *DC = SemaRef.computeDeclContext(SS, false); 1092 if (!DC) 1093 return QualType(); 1094 1095 if (SemaRef.RequireCompleteDeclContext(SS, DC)) 1096 return QualType(); 1097 1098 TagDecl *Tag = nullptr; 1099 SemaRef.LookupQualifiedName(Result, DC); 1100 switch (Result.getResultKind()) { 1101 case LookupResult::NotFound: 1102 case LookupResult::NotFoundInCurrentInstantiation: 1103 break; 1104 1105 case LookupResult::Found: 1106 Tag = Result.getAsSingle<TagDecl>(); 1107 break; 1108 1109 case LookupResult::FoundOverloaded: 1110 case LookupResult::FoundUnresolvedValue: 1111 llvm_unreachable("Tag lookup cannot find non-tags"); 1112 1113 case LookupResult::Ambiguous: 1114 // Let the LookupResult structure handle ambiguities. 1115 return QualType(); 1116 } 1117 1118 if (!Tag) { 1119 // Check where the name exists but isn't a tag type and use that to emit 1120 // better diagnostics. 1121 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 1122 SemaRef.LookupQualifiedName(Result, DC); 1123 switch (Result.getResultKind()) { 1124 case LookupResult::Found: 1125 case LookupResult::FoundOverloaded: 1126 case LookupResult::FoundUnresolvedValue: { 1127 NamedDecl *SomeDecl = Result.getRepresentativeDecl(); 1128 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind); 1129 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl 1130 << NTK << Kind; 1131 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); 1132 break; 1133 } 1134 default: 1135 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 1136 << Kind << Id << DC << QualifierLoc.getSourceRange(); 1137 break; 1138 } 1139 return QualType(); 1140 } 1141 1142 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, 1143 IdLoc, Id)) { 1144 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 1145 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 1146 return QualType(); 1147 } 1148 1149 // Build the elaborated-type-specifier type. 1150 QualType T = SemaRef.Context.getTypeDeclType(Tag); 1151 return SemaRef.Context.getElaboratedType(Keyword, 1152 QualifierLoc.getNestedNameSpecifier(), 1153 T); 1154 } 1155 1156 /// Build a new pack expansion type. 1157 /// 1158 /// By default, builds a new PackExpansionType type from the given pattern. 1159 /// Subclasses may override this routine to provide different behavior. 1160 QualType RebuildPackExpansionType(QualType Pattern, 1161 SourceRange PatternRange, 1162 SourceLocation EllipsisLoc, 1163 Optional<unsigned> NumExpansions) { 1164 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, 1165 NumExpansions); 1166 } 1167 1168 /// Build a new atomic type given its value type. 1169 /// 1170 /// By default, performs semantic analysis when building the atomic type. 1171 /// Subclasses may override this routine to provide different behavior. 1172 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); 1173 1174 /// Build a new pipe type given its value type. 1175 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, 1176 bool isReadPipe); 1177 1178 /// Build a new template name given a nested name specifier, a flag 1179 /// indicating whether the "template" keyword was provided, and the template 1180 /// that the template name refers to. 1181 /// 1182 /// By default, builds the new template name directly. Subclasses may override 1183 /// this routine to provide different behavior. 1184 TemplateName RebuildTemplateName(CXXScopeSpec &SS, 1185 bool TemplateKW, 1186 TemplateDecl *Template); 1187 1188 /// Build a new template name given a nested name specifier and the 1189 /// name that is referred to as a template. 1190 /// 1191 /// By default, performs semantic analysis to determine whether the name can 1192 /// be resolved to a specific template, then builds the appropriate kind of 1193 /// template name. Subclasses may override this routine to provide different 1194 /// behavior. 1195 TemplateName RebuildTemplateName(CXXScopeSpec &SS, 1196 SourceLocation TemplateKWLoc, 1197 const IdentifierInfo &Name, 1198 SourceLocation NameLoc, QualType ObjectType, 1199 NamedDecl *FirstQualifierInScope, 1200 bool AllowInjectedClassName); 1201 1202 /// Build a new template name given a nested name specifier and the 1203 /// overloaded operator name that is referred to as a template. 1204 /// 1205 /// By default, performs semantic analysis to determine whether the name can 1206 /// be resolved to a specific template, then builds the appropriate kind of 1207 /// template name. Subclasses may override this routine to provide different 1208 /// behavior. 1209 TemplateName RebuildTemplateName(CXXScopeSpec &SS, 1210 SourceLocation TemplateKWLoc, 1211 OverloadedOperatorKind Operator, 1212 SourceLocation NameLoc, QualType ObjectType, 1213 bool AllowInjectedClassName); 1214 1215 /// Build a new template name given a template template parameter pack 1216 /// and the 1217 /// 1218 /// By default, performs semantic analysis to determine whether the name can 1219 /// be resolved to a specific template, then builds the appropriate kind of 1220 /// template name. Subclasses may override this routine to provide different 1221 /// behavior. 1222 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, 1223 const TemplateArgument &ArgPack) { 1224 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); 1225 } 1226 1227 /// Build a new compound statement. 1228 /// 1229 /// By default, performs semantic analysis to build the new statement. 1230 /// Subclasses may override this routine to provide different behavior. 1231 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 1232 MultiStmtArg Statements, 1233 SourceLocation RBraceLoc, 1234 bool IsStmtExpr) { 1235 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 1236 IsStmtExpr); 1237 } 1238 1239 /// Build a new case statement. 1240 /// 1241 /// By default, performs semantic analysis to build the new statement. 1242 /// Subclasses may override this routine to provide different behavior. 1243 StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 1244 Expr *LHS, 1245 SourceLocation EllipsisLoc, 1246 Expr *RHS, 1247 SourceLocation ColonLoc) { 1248 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 1249 ColonLoc); 1250 } 1251 1252 /// Attach the body to a new case statement. 1253 /// 1254 /// By default, performs semantic analysis to build the new statement. 1255 /// Subclasses may override this routine to provide different behavior. 1256 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 1257 getSema().ActOnCaseStmtBody(S, Body); 1258 return S; 1259 } 1260 1261 /// Build a new default statement. 1262 /// 1263 /// By default, performs semantic analysis to build the new statement. 1264 /// Subclasses may override this routine to provide different behavior. 1265 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, 1266 SourceLocation ColonLoc, 1267 Stmt *SubStmt) { 1268 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 1269 /*CurScope=*/nullptr); 1270 } 1271 1272 /// Build a new label statement. 1273 /// 1274 /// By default, performs semantic analysis to build the new statement. 1275 /// Subclasses may override this routine to provide different behavior. 1276 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, 1277 SourceLocation ColonLoc, Stmt *SubStmt) { 1278 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); 1279 } 1280 1281 /// Build a new label statement. 1282 /// 1283 /// By default, performs semantic analysis to build the new statement. 1284 /// Subclasses may override this routine to provide different behavior. 1285 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, 1286 ArrayRef<const Attr*> Attrs, 1287 Stmt *SubStmt) { 1288 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); 1289 } 1290 1291 /// Build a new "if" statement. 1292 /// 1293 /// By default, performs semantic analysis to build the new statement. 1294 /// Subclasses may override this routine to provide different behavior. 1295 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, 1296 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then, 1297 SourceLocation ElseLoc, Stmt *Else) { 1298 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then, 1299 ElseLoc, Else); 1300 } 1301 1302 /// Start building a new switch statement. 1303 /// 1304 /// By default, performs semantic analysis to build the new statement. 1305 /// Subclasses may override this routine to provide different behavior. 1306 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init, 1307 Sema::ConditionResult Cond) { 1308 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond); 1309 } 1310 1311 /// Attach the body to the switch statement. 1312 /// 1313 /// By default, performs semantic analysis to build the new statement. 1314 /// Subclasses may override this routine to provide different behavior. 1315 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 1316 Stmt *Switch, Stmt *Body) { 1317 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 1318 } 1319 1320 /// Build a new while statement. 1321 /// 1322 /// By default, performs semantic analysis to build the new statement. 1323 /// Subclasses may override this routine to provide different behavior. 1324 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, 1325 Sema::ConditionResult Cond, Stmt *Body) { 1326 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body); 1327 } 1328 1329 /// Build a new do-while statement. 1330 /// 1331 /// By default, performs semantic analysis to build the new statement. 1332 /// Subclasses may override this routine to provide different behavior. 1333 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 1334 SourceLocation WhileLoc, SourceLocation LParenLoc, 1335 Expr *Cond, SourceLocation RParenLoc) { 1336 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 1337 Cond, RParenLoc); 1338 } 1339 1340 /// Build a new for statement. 1341 /// 1342 /// By default, performs semantic analysis to build the new statement. 1343 /// Subclasses may override this routine to provide different behavior. 1344 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 1345 Stmt *Init, Sema::ConditionResult Cond, 1346 Sema::FullExprArg Inc, SourceLocation RParenLoc, 1347 Stmt *Body) { 1348 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 1349 Inc, RParenLoc, Body); 1350 } 1351 1352 /// Build a new goto statement. 1353 /// 1354 /// By default, performs semantic analysis to build the new statement. 1355 /// Subclasses may override this routine to provide different behavior. 1356 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, 1357 LabelDecl *Label) { 1358 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); 1359 } 1360 1361 /// Build a new indirect goto statement. 1362 /// 1363 /// By default, performs semantic analysis to build the new statement. 1364 /// Subclasses may override this routine to provide different behavior. 1365 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 1366 SourceLocation StarLoc, 1367 Expr *Target) { 1368 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 1369 } 1370 1371 /// Build a new return statement. 1372 /// 1373 /// By default, performs semantic analysis to build the new statement. 1374 /// Subclasses may override this routine to provide different behavior. 1375 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { 1376 return getSema().BuildReturnStmt(ReturnLoc, Result); 1377 } 1378 1379 /// Build a new declaration statement. 1380 /// 1381 /// By default, performs semantic analysis to build the new statement. 1382 /// Subclasses may override this routine to provide different behavior. 1383 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, 1384 SourceLocation StartLoc, SourceLocation EndLoc) { 1385 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); 1386 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); 1387 } 1388 1389 /// Build a new inline asm statement. 1390 /// 1391 /// By default, performs semantic analysis to build the new statement. 1392 /// Subclasses may override this routine to provide different behavior. 1393 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, 1394 bool IsVolatile, unsigned NumOutputs, 1395 unsigned NumInputs, IdentifierInfo **Names, 1396 MultiExprArg Constraints, MultiExprArg Exprs, 1397 Expr *AsmString, MultiExprArg Clobbers, 1398 unsigned NumLabels, 1399 SourceLocation RParenLoc) { 1400 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 1401 NumInputs, Names, Constraints, Exprs, 1402 AsmString, Clobbers, NumLabels, RParenLoc); 1403 } 1404 1405 /// Build a new MS style inline asm statement. 1406 /// 1407 /// By default, performs semantic analysis to build the new statement. 1408 /// Subclasses may override this routine to provide different behavior. 1409 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, 1410 ArrayRef<Token> AsmToks, 1411 StringRef AsmString, 1412 unsigned NumOutputs, unsigned NumInputs, 1413 ArrayRef<StringRef> Constraints, 1414 ArrayRef<StringRef> Clobbers, 1415 ArrayRef<Expr*> Exprs, 1416 SourceLocation EndLoc) { 1417 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, 1418 NumOutputs, NumInputs, 1419 Constraints, Clobbers, Exprs, EndLoc); 1420 } 1421 1422 /// Build a new co_return statement. 1423 /// 1424 /// By default, performs semantic analysis to build the new statement. 1425 /// Subclasses may override this routine to provide different behavior. 1426 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, 1427 bool IsImplicit) { 1428 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit); 1429 } 1430 1431 /// Build a new co_await expression. 1432 /// 1433 /// By default, performs semantic analysis to build the new expression. 1434 /// Subclasses may override this routine to provide different behavior. 1435 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, 1436 bool IsImplicit) { 1437 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit); 1438 } 1439 1440 /// Build a new co_await expression. 1441 /// 1442 /// By default, performs semantic analysis to build the new expression. 1443 /// Subclasses may override this routine to provide different behavior. 1444 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, 1445 Expr *Result, 1446 UnresolvedLookupExpr *Lookup) { 1447 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup); 1448 } 1449 1450 /// Build a new co_yield expression. 1451 /// 1452 /// By default, performs semantic analysis to build the new expression. 1453 /// Subclasses may override this routine to provide different behavior. 1454 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) { 1455 return getSema().BuildCoyieldExpr(CoyieldLoc, Result); 1456 } 1457 1458 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) { 1459 return getSema().BuildCoroutineBodyStmt(Args); 1460 } 1461 1462 /// Build a new Objective-C \@try statement. 1463 /// 1464 /// By default, performs semantic analysis to build the new statement. 1465 /// Subclasses may override this routine to provide different behavior. 1466 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 1467 Stmt *TryBody, 1468 MultiStmtArg CatchStmts, 1469 Stmt *Finally) { 1470 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, 1471 Finally); 1472 } 1473 1474 /// Rebuild an Objective-C exception declaration. 1475 /// 1476 /// By default, performs semantic analysis to build the new declaration. 1477 /// Subclasses may override this routine to provide different behavior. 1478 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1479 TypeSourceInfo *TInfo, QualType T) { 1480 return getSema().BuildObjCExceptionDecl(TInfo, T, 1481 ExceptionDecl->getInnerLocStart(), 1482 ExceptionDecl->getLocation(), 1483 ExceptionDecl->getIdentifier()); 1484 } 1485 1486 /// Build a new Objective-C \@catch statement. 1487 /// 1488 /// By default, performs semantic analysis to build the new statement. 1489 /// Subclasses may override this routine to provide different behavior. 1490 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1491 SourceLocation RParenLoc, 1492 VarDecl *Var, 1493 Stmt *Body) { 1494 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 1495 Var, Body); 1496 } 1497 1498 /// Build a new Objective-C \@finally statement. 1499 /// 1500 /// By default, performs semantic analysis to build the new statement. 1501 /// Subclasses may override this routine to provide different behavior. 1502 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 1503 Stmt *Body) { 1504 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 1505 } 1506 1507 /// Build a new Objective-C \@throw statement. 1508 /// 1509 /// By default, performs semantic analysis to build the new statement. 1510 /// Subclasses may override this routine to provide different behavior. 1511 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 1512 Expr *Operand) { 1513 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1514 } 1515 1516 /// Build a new OpenMP executable directive. 1517 /// 1518 /// By default, performs semantic analysis to build the new statement. 1519 /// Subclasses may override this routine to provide different behavior. 1520 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, 1521 DeclarationNameInfo DirName, 1522 OpenMPDirectiveKind CancelRegion, 1523 ArrayRef<OMPClause *> Clauses, 1524 Stmt *AStmt, SourceLocation StartLoc, 1525 SourceLocation EndLoc) { 1526 return getSema().ActOnOpenMPExecutableDirective( 1527 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); 1528 } 1529 1530 /// Build a new OpenMP 'if' clause. 1531 /// 1532 /// By default, performs semantic analysis to build the new OpenMP clause. 1533 /// Subclasses may override this routine to provide different behavior. 1534 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, 1535 Expr *Condition, SourceLocation StartLoc, 1536 SourceLocation LParenLoc, 1537 SourceLocation NameModifierLoc, 1538 SourceLocation ColonLoc, 1539 SourceLocation EndLoc) { 1540 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc, 1541 LParenLoc, NameModifierLoc, ColonLoc, 1542 EndLoc); 1543 } 1544 1545 /// Build a new OpenMP 'final' clause. 1546 /// 1547 /// By default, performs semantic analysis to build the new OpenMP clause. 1548 /// Subclasses may override this routine to provide different behavior. 1549 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, 1550 SourceLocation LParenLoc, 1551 SourceLocation EndLoc) { 1552 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, 1553 EndLoc); 1554 } 1555 1556 /// Build a new OpenMP 'num_threads' clause. 1557 /// 1558 /// By default, performs semantic analysis to build the new OpenMP clause. 1559 /// Subclasses may override this routine to provide different behavior. 1560 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, 1561 SourceLocation StartLoc, 1562 SourceLocation LParenLoc, 1563 SourceLocation EndLoc) { 1564 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, 1565 LParenLoc, EndLoc); 1566 } 1567 1568 /// Build a new OpenMP 'safelen' clause. 1569 /// 1570 /// By default, performs semantic analysis to build the new OpenMP clause. 1571 /// Subclasses may override this routine to provide different behavior. 1572 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, 1573 SourceLocation LParenLoc, 1574 SourceLocation EndLoc) { 1575 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); 1576 } 1577 1578 /// Build a new OpenMP 'simdlen' clause. 1579 /// 1580 /// By default, performs semantic analysis to build the new OpenMP clause. 1581 /// Subclasses may override this routine to provide different behavior. 1582 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, 1583 SourceLocation LParenLoc, 1584 SourceLocation EndLoc) { 1585 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc); 1586 } 1587 1588 /// Build a new OpenMP 'allocator' clause. 1589 /// 1590 /// By default, performs semantic analysis to build the new OpenMP clause. 1591 /// Subclasses may override this routine to provide different behavior. 1592 OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, 1593 SourceLocation LParenLoc, 1594 SourceLocation EndLoc) { 1595 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc); 1596 } 1597 1598 /// Build a new OpenMP 'collapse' clause. 1599 /// 1600 /// By default, performs semantic analysis to build the new OpenMP clause. 1601 /// Subclasses may override this routine to provide different behavior. 1602 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, 1603 SourceLocation LParenLoc, 1604 SourceLocation EndLoc) { 1605 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, 1606 EndLoc); 1607 } 1608 1609 /// Build a new OpenMP 'default' clause. 1610 /// 1611 /// By default, performs semantic analysis to build the new OpenMP clause. 1612 /// Subclasses may override this routine to provide different behavior. 1613 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, 1614 SourceLocation KindKwLoc, 1615 SourceLocation StartLoc, 1616 SourceLocation LParenLoc, 1617 SourceLocation EndLoc) { 1618 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, 1619 StartLoc, LParenLoc, EndLoc); 1620 } 1621 1622 /// Build a new OpenMP 'proc_bind' clause. 1623 /// 1624 /// By default, performs semantic analysis to build the new OpenMP clause. 1625 /// Subclasses may override this routine to provide different behavior. 1626 OMPClause *RebuildOMPProcBindClause(ProcBindKind Kind, 1627 SourceLocation KindKwLoc, 1628 SourceLocation StartLoc, 1629 SourceLocation LParenLoc, 1630 SourceLocation EndLoc) { 1631 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, 1632 StartLoc, LParenLoc, EndLoc); 1633 } 1634 1635 /// Build a new OpenMP 'schedule' clause. 1636 /// 1637 /// By default, performs semantic analysis to build the new OpenMP clause. 1638 /// Subclasses may override this routine to provide different behavior. 1639 OMPClause *RebuildOMPScheduleClause( 1640 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, 1641 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, 1642 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, 1643 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { 1644 return getSema().ActOnOpenMPScheduleClause( 1645 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc, 1646 CommaLoc, EndLoc); 1647 } 1648 1649 /// Build a new OpenMP 'ordered' clause. 1650 /// 1651 /// By default, performs semantic analysis to build the new OpenMP clause. 1652 /// Subclasses may override this routine to provide different behavior. 1653 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, 1654 SourceLocation EndLoc, 1655 SourceLocation LParenLoc, Expr *Num) { 1656 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); 1657 } 1658 1659 /// Build a new OpenMP 'private' clause. 1660 /// 1661 /// By default, performs semantic analysis to build the new OpenMP clause. 1662 /// Subclasses may override this routine to provide different behavior. 1663 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, 1664 SourceLocation StartLoc, 1665 SourceLocation LParenLoc, 1666 SourceLocation EndLoc) { 1667 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, 1668 EndLoc); 1669 } 1670 1671 /// Build a new OpenMP 'firstprivate' clause. 1672 /// 1673 /// By default, performs semantic analysis to build the new OpenMP clause. 1674 /// Subclasses may override this routine to provide different behavior. 1675 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, 1676 SourceLocation StartLoc, 1677 SourceLocation LParenLoc, 1678 SourceLocation EndLoc) { 1679 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, 1680 EndLoc); 1681 } 1682 1683 /// Build a new OpenMP 'lastprivate' clause. 1684 /// 1685 /// By default, performs semantic analysis to build the new OpenMP clause. 1686 /// Subclasses may override this routine to provide different behavior. 1687 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, 1688 OpenMPLastprivateModifier LPKind, 1689 SourceLocation LPKindLoc, 1690 SourceLocation ColonLoc, 1691 SourceLocation StartLoc, 1692 SourceLocation LParenLoc, 1693 SourceLocation EndLoc) { 1694 return getSema().ActOnOpenMPLastprivateClause( 1695 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc); 1696 } 1697 1698 /// Build a new OpenMP 'shared' clause. 1699 /// 1700 /// By default, performs semantic analysis to build the new OpenMP clause. 1701 /// Subclasses may override this routine to provide different behavior. 1702 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, 1703 SourceLocation StartLoc, 1704 SourceLocation LParenLoc, 1705 SourceLocation EndLoc) { 1706 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, 1707 EndLoc); 1708 } 1709 1710 /// Build a new OpenMP 'reduction' clause. 1711 /// 1712 /// By default, performs semantic analysis to build the new statement. 1713 /// Subclasses may override this routine to provide different behavior. 1714 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList, 1715 SourceLocation StartLoc, 1716 SourceLocation LParenLoc, 1717 SourceLocation ColonLoc, 1718 SourceLocation EndLoc, 1719 CXXScopeSpec &ReductionIdScopeSpec, 1720 const DeclarationNameInfo &ReductionId, 1721 ArrayRef<Expr *> UnresolvedReductions) { 1722 return getSema().ActOnOpenMPReductionClause( 1723 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, 1724 ReductionId, UnresolvedReductions); 1725 } 1726 1727 /// Build a new OpenMP 'task_reduction' clause. 1728 /// 1729 /// By default, performs semantic analysis to build the new statement. 1730 /// Subclasses may override this routine to provide different behavior. 1731 OMPClause *RebuildOMPTaskReductionClause( 1732 ArrayRef<Expr *> VarList, SourceLocation StartLoc, 1733 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, 1734 CXXScopeSpec &ReductionIdScopeSpec, 1735 const DeclarationNameInfo &ReductionId, 1736 ArrayRef<Expr *> UnresolvedReductions) { 1737 return getSema().ActOnOpenMPTaskReductionClause( 1738 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, 1739 ReductionId, UnresolvedReductions); 1740 } 1741 1742 /// Build a new OpenMP 'in_reduction' clause. 1743 /// 1744 /// By default, performs semantic analysis to build the new statement. 1745 /// Subclasses may override this routine to provide different behavior. 1746 OMPClause * 1747 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc, 1748 SourceLocation LParenLoc, SourceLocation ColonLoc, 1749 SourceLocation EndLoc, 1750 CXXScopeSpec &ReductionIdScopeSpec, 1751 const DeclarationNameInfo &ReductionId, 1752 ArrayRef<Expr *> UnresolvedReductions) { 1753 return getSema().ActOnOpenMPInReductionClause( 1754 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, 1755 ReductionId, UnresolvedReductions); 1756 } 1757 1758 /// Build a new OpenMP 'linear' clause. 1759 /// 1760 /// By default, performs semantic analysis to build the new OpenMP clause. 1761 /// Subclasses may override this routine to provide different behavior. 1762 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, 1763 SourceLocation StartLoc, 1764 SourceLocation LParenLoc, 1765 OpenMPLinearClauseKind Modifier, 1766 SourceLocation ModifierLoc, 1767 SourceLocation ColonLoc, 1768 SourceLocation EndLoc) { 1769 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, 1770 Modifier, ModifierLoc, ColonLoc, 1771 EndLoc); 1772 } 1773 1774 /// Build a new OpenMP 'aligned' clause. 1775 /// 1776 /// By default, performs semantic analysis to build the new OpenMP clause. 1777 /// Subclasses may override this routine to provide different behavior. 1778 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, 1779 SourceLocation StartLoc, 1780 SourceLocation LParenLoc, 1781 SourceLocation ColonLoc, 1782 SourceLocation EndLoc) { 1783 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, 1784 LParenLoc, ColonLoc, EndLoc); 1785 } 1786 1787 /// Build a new OpenMP 'copyin' clause. 1788 /// 1789 /// By default, performs semantic analysis to build the new OpenMP clause. 1790 /// Subclasses may override this routine to provide different behavior. 1791 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, 1792 SourceLocation StartLoc, 1793 SourceLocation LParenLoc, 1794 SourceLocation EndLoc) { 1795 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, 1796 EndLoc); 1797 } 1798 1799 /// Build a new OpenMP 'copyprivate' clause. 1800 /// 1801 /// By default, performs semantic analysis to build the new OpenMP clause. 1802 /// Subclasses may override this routine to provide different behavior. 1803 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, 1804 SourceLocation StartLoc, 1805 SourceLocation LParenLoc, 1806 SourceLocation EndLoc) { 1807 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, 1808 EndLoc); 1809 } 1810 1811 /// Build a new OpenMP 'flush' pseudo clause. 1812 /// 1813 /// By default, performs semantic analysis to build the new OpenMP clause. 1814 /// Subclasses may override this routine to provide different behavior. 1815 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, 1816 SourceLocation StartLoc, 1817 SourceLocation LParenLoc, 1818 SourceLocation EndLoc) { 1819 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, 1820 EndLoc); 1821 } 1822 1823 /// Build a new OpenMP 'depend' pseudo clause. 1824 /// 1825 /// By default, performs semantic analysis to build the new OpenMP clause. 1826 /// Subclasses may override this routine to provide different behavior. 1827 OMPClause * 1828 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc, 1829 SourceLocation ColonLoc, ArrayRef<Expr *> VarList, 1830 SourceLocation StartLoc, SourceLocation LParenLoc, 1831 SourceLocation EndLoc) { 1832 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList, 1833 StartLoc, LParenLoc, EndLoc); 1834 } 1835 1836 /// Build a new OpenMP 'device' clause. 1837 /// 1838 /// By default, performs semantic analysis to build the new statement. 1839 /// Subclasses may override this routine to provide different behavior. 1840 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, 1841 SourceLocation LParenLoc, 1842 SourceLocation EndLoc) { 1843 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc, 1844 EndLoc); 1845 } 1846 1847 /// Build a new OpenMP 'map' clause. 1848 /// 1849 /// By default, performs semantic analysis to build the new OpenMP clause. 1850 /// Subclasses may override this routine to provide different behavior. 1851 OMPClause *RebuildOMPMapClause( 1852 ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, 1853 ArrayRef<SourceLocation> MapTypeModifiersLoc, 1854 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, 1855 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, 1856 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, 1857 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) { 1858 return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc, 1859 MapperIdScopeSpec, MapperId, MapType, 1860 IsMapTypeImplicit, MapLoc, ColonLoc, 1861 VarList, Locs, UnresolvedMappers); 1862 } 1863 1864 /// Build a new OpenMP 'allocate' clause. 1865 /// 1866 /// By default, performs semantic analysis to build the new OpenMP clause. 1867 /// Subclasses may override this routine to provide different behavior. 1868 OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList, 1869 SourceLocation StartLoc, 1870 SourceLocation LParenLoc, 1871 SourceLocation ColonLoc, 1872 SourceLocation EndLoc) { 1873 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc, 1874 LParenLoc, ColonLoc, EndLoc); 1875 } 1876 1877 /// Build a new OpenMP 'num_teams' clause. 1878 /// 1879 /// By default, performs semantic analysis to build the new statement. 1880 /// Subclasses may override this routine to provide different behavior. 1881 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, 1882 SourceLocation LParenLoc, 1883 SourceLocation EndLoc) { 1884 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc, 1885 EndLoc); 1886 } 1887 1888 /// Build a new OpenMP 'thread_limit' clause. 1889 /// 1890 /// By default, performs semantic analysis to build the new statement. 1891 /// Subclasses may override this routine to provide different behavior. 1892 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit, 1893 SourceLocation StartLoc, 1894 SourceLocation LParenLoc, 1895 SourceLocation EndLoc) { 1896 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc, 1897 LParenLoc, EndLoc); 1898 } 1899 1900 /// Build a new OpenMP 'priority' clause. 1901 /// 1902 /// By default, performs semantic analysis to build the new statement. 1903 /// Subclasses may override this routine to provide different behavior. 1904 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, 1905 SourceLocation LParenLoc, 1906 SourceLocation EndLoc) { 1907 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc, 1908 EndLoc); 1909 } 1910 1911 /// Build a new OpenMP 'grainsize' clause. 1912 /// 1913 /// By default, performs semantic analysis to build the new statement. 1914 /// Subclasses may override this routine to provide different behavior. 1915 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc, 1916 SourceLocation LParenLoc, 1917 SourceLocation EndLoc) { 1918 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc, 1919 EndLoc); 1920 } 1921 1922 /// Build a new OpenMP 'num_tasks' clause. 1923 /// 1924 /// By default, performs semantic analysis to build the new statement. 1925 /// Subclasses may override this routine to provide different behavior. 1926 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, 1927 SourceLocation LParenLoc, 1928 SourceLocation EndLoc) { 1929 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc, 1930 EndLoc); 1931 } 1932 1933 /// Build a new OpenMP 'hint' clause. 1934 /// 1935 /// By default, performs semantic analysis to build the new statement. 1936 /// Subclasses may override this routine to provide different behavior. 1937 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, 1938 SourceLocation LParenLoc, 1939 SourceLocation EndLoc) { 1940 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc); 1941 } 1942 1943 /// Build a new OpenMP 'dist_schedule' clause. 1944 /// 1945 /// By default, performs semantic analysis to build the new OpenMP clause. 1946 /// Subclasses may override this routine to provide different behavior. 1947 OMPClause * 1948 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, 1949 Expr *ChunkSize, SourceLocation StartLoc, 1950 SourceLocation LParenLoc, SourceLocation KindLoc, 1951 SourceLocation CommaLoc, SourceLocation EndLoc) { 1952 return getSema().ActOnOpenMPDistScheduleClause( 1953 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); 1954 } 1955 1956 /// Build a new OpenMP 'to' clause. 1957 /// 1958 /// By default, performs semantic analysis to build the new statement. 1959 /// Subclasses may override this routine to provide different behavior. 1960 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList, 1961 CXXScopeSpec &MapperIdScopeSpec, 1962 DeclarationNameInfo &MapperId, 1963 const OMPVarListLocTy &Locs, 1964 ArrayRef<Expr *> UnresolvedMappers) { 1965 return getSema().ActOnOpenMPToClause(VarList, MapperIdScopeSpec, MapperId, 1966 Locs, UnresolvedMappers); 1967 } 1968 1969 /// Build a new OpenMP 'from' clause. 1970 /// 1971 /// By default, performs semantic analysis to build the new statement. 1972 /// Subclasses may override this routine to provide different behavior. 1973 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList, 1974 CXXScopeSpec &MapperIdScopeSpec, 1975 DeclarationNameInfo &MapperId, 1976 const OMPVarListLocTy &Locs, 1977 ArrayRef<Expr *> UnresolvedMappers) { 1978 return getSema().ActOnOpenMPFromClause(VarList, MapperIdScopeSpec, MapperId, 1979 Locs, UnresolvedMappers); 1980 } 1981 1982 /// Build a new OpenMP 'use_device_ptr' clause. 1983 /// 1984 /// By default, performs semantic analysis to build the new OpenMP clause. 1985 /// Subclasses may override this routine to provide different behavior. 1986 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList, 1987 const OMPVarListLocTy &Locs) { 1988 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs); 1989 } 1990 1991 /// Build a new OpenMP 'is_device_ptr' clause. 1992 /// 1993 /// By default, performs semantic analysis to build the new OpenMP clause. 1994 /// Subclasses may override this routine to provide different behavior. 1995 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList, 1996 const OMPVarListLocTy &Locs) { 1997 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs); 1998 } 1999 2000 /// Build a new OpenMP 'defaultmap' clause. 2001 /// 2002 /// By default, performs semantic analysis to build the new OpenMP clause. 2003 /// Subclasses may override this routine to provide different behavior. 2004 OMPClause *RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, 2005 OpenMPDefaultmapClauseKind Kind, 2006 SourceLocation StartLoc, 2007 SourceLocation LParenLoc, 2008 SourceLocation MLoc, 2009 SourceLocation KindLoc, 2010 SourceLocation EndLoc) { 2011 return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc, 2012 MLoc, KindLoc, EndLoc); 2013 } 2014 2015 /// Build a new OpenMP 'nontemporal' clause. 2016 /// 2017 /// By default, performs semantic analysis to build the new OpenMP clause. 2018 /// Subclasses may override this routine to provide different behavior. 2019 OMPClause *RebuildOMPNontemporalClause(ArrayRef<Expr *> VarList, 2020 SourceLocation StartLoc, 2021 SourceLocation LParenLoc, 2022 SourceLocation EndLoc) { 2023 return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc, 2024 EndLoc); 2025 } 2026 2027 /// Rebuild the operand to an Objective-C \@synchronized statement. 2028 /// 2029 /// By default, performs semantic analysis to build the new statement. 2030 /// Subclasses may override this routine to provide different behavior. 2031 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, 2032 Expr *object) { 2033 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); 2034 } 2035 2036 /// Build a new Objective-C \@synchronized statement. 2037 /// 2038 /// By default, performs semantic analysis to build the new statement. 2039 /// Subclasses may override this routine to provide different behavior. 2040 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 2041 Expr *Object, Stmt *Body) { 2042 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); 2043 } 2044 2045 /// Build a new Objective-C \@autoreleasepool statement. 2046 /// 2047 /// By default, performs semantic analysis to build the new statement. 2048 /// Subclasses may override this routine to provide different behavior. 2049 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, 2050 Stmt *Body) { 2051 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); 2052 } 2053 2054 /// Build a new Objective-C fast enumeration statement. 2055 /// 2056 /// By default, performs semantic analysis to build the new statement. 2057 /// Subclasses may override this routine to provide different behavior. 2058 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 2059 Stmt *Element, 2060 Expr *Collection, 2061 SourceLocation RParenLoc, 2062 Stmt *Body) { 2063 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, 2064 Element, 2065 Collection, 2066 RParenLoc); 2067 if (ForEachStmt.isInvalid()) 2068 return StmtError(); 2069 2070 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); 2071 } 2072 2073 /// Build a new C++ exception declaration. 2074 /// 2075 /// By default, performs semantic analysis to build the new decaration. 2076 /// Subclasses may override this routine to provide different behavior. 2077 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 2078 TypeSourceInfo *Declarator, 2079 SourceLocation StartLoc, 2080 SourceLocation IdLoc, 2081 IdentifierInfo *Id) { 2082 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, 2083 StartLoc, IdLoc, Id); 2084 if (Var) 2085 getSema().CurContext->addDecl(Var); 2086 return Var; 2087 } 2088 2089 /// Build a new C++ catch statement. 2090 /// 2091 /// By default, performs semantic analysis to build the new statement. 2092 /// Subclasses may override this routine to provide different behavior. 2093 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 2094 VarDecl *ExceptionDecl, 2095 Stmt *Handler) { 2096 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 2097 Handler)); 2098 } 2099 2100 /// Build a new C++ try statement. 2101 /// 2102 /// By default, performs semantic analysis to build the new statement. 2103 /// Subclasses may override this routine to provide different behavior. 2104 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, 2105 ArrayRef<Stmt *> Handlers) { 2106 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); 2107 } 2108 2109 /// Build a new C++0x range-based for statement. 2110 /// 2111 /// By default, performs semantic analysis to build the new statement. 2112 /// Subclasses may override this routine to provide different behavior. 2113 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, 2114 SourceLocation CoawaitLoc, Stmt *Init, 2115 SourceLocation ColonLoc, Stmt *Range, 2116 Stmt *Begin, Stmt *End, Expr *Cond, 2117 Expr *Inc, Stmt *LoopVar, 2118 SourceLocation RParenLoc) { 2119 // If we've just learned that the range is actually an Objective-C 2120 // collection, treat this as an Objective-C fast enumeration loop. 2121 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { 2122 if (RangeStmt->isSingleDecl()) { 2123 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { 2124 if (RangeVar->isInvalidDecl()) 2125 return StmtError(); 2126 2127 Expr *RangeExpr = RangeVar->getInit(); 2128 if (!RangeExpr->isTypeDependent() && 2129 RangeExpr->getType()->isObjCObjectPointerType()) { 2130 // FIXME: Support init-statements in Objective-C++20 ranged for 2131 // statement. 2132 if (Init) { 2133 return SemaRef.Diag(Init->getBeginLoc(), 2134 diag::err_objc_for_range_init_stmt) 2135 << Init->getSourceRange(); 2136 } 2137 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, 2138 RangeExpr, RParenLoc); 2139 } 2140 } 2141 } 2142 } 2143 2144 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc, 2145 Range, Begin, End, Cond, Inc, LoopVar, 2146 RParenLoc, Sema::BFRK_Rebuild); 2147 } 2148 2149 /// Build a new C++0x range-based for statement. 2150 /// 2151 /// By default, performs semantic analysis to build the new statement. 2152 /// Subclasses may override this routine to provide different behavior. 2153 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, 2154 bool IsIfExists, 2155 NestedNameSpecifierLoc QualifierLoc, 2156 DeclarationNameInfo NameInfo, 2157 Stmt *Nested) { 2158 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, 2159 QualifierLoc, NameInfo, Nested); 2160 } 2161 2162 /// Attach body to a C++0x range-based for statement. 2163 /// 2164 /// By default, performs semantic analysis to finish the new statement. 2165 /// Subclasses may override this routine to provide different behavior. 2166 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { 2167 return getSema().FinishCXXForRangeStmt(ForRange, Body); 2168 } 2169 2170 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, 2171 Stmt *TryBlock, Stmt *Handler) { 2172 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); 2173 } 2174 2175 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, 2176 Stmt *Block) { 2177 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); 2178 } 2179 2180 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { 2181 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); 2182 } 2183 2184 /// Build a new predefined expression. 2185 /// 2186 /// By default, performs semantic analysis to build the new expression. 2187 /// Subclasses may override this routine to provide different behavior. 2188 ExprResult RebuildPredefinedExpr(SourceLocation Loc, 2189 PredefinedExpr::IdentKind IK) { 2190 return getSema().BuildPredefinedExpr(Loc, IK); 2191 } 2192 2193 /// Build a new expression that references a declaration. 2194 /// 2195 /// By default, performs semantic analysis to build the new expression. 2196 /// Subclasses may override this routine to provide different behavior. 2197 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 2198 LookupResult &R, 2199 bool RequiresADL) { 2200 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 2201 } 2202 2203 2204 /// Build a new expression that references a declaration. 2205 /// 2206 /// By default, performs semantic analysis to build the new expression. 2207 /// Subclasses may override this routine to provide different behavior. 2208 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 2209 ValueDecl *VD, 2210 const DeclarationNameInfo &NameInfo, 2211 NamedDecl *Found, 2212 TemplateArgumentListInfo *TemplateArgs) { 2213 CXXScopeSpec SS; 2214 SS.Adopt(QualifierLoc); 2215 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found, 2216 TemplateArgs); 2217 } 2218 2219 /// Build a new expression in parentheses. 2220 /// 2221 /// By default, performs semantic analysis to build the new expression. 2222 /// Subclasses may override this routine to provide different behavior. 2223 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 2224 SourceLocation RParen) { 2225 return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 2226 } 2227 2228 /// Build a new pseudo-destructor expression. 2229 /// 2230 /// By default, performs semantic analysis to build the new expression. 2231 /// Subclasses may override this routine to provide different behavior. 2232 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 2233 SourceLocation OperatorLoc, 2234 bool isArrow, 2235 CXXScopeSpec &SS, 2236 TypeSourceInfo *ScopeType, 2237 SourceLocation CCLoc, 2238 SourceLocation TildeLoc, 2239 PseudoDestructorTypeStorage Destroyed); 2240 2241 /// Build a new unary operator expression. 2242 /// 2243 /// By default, performs semantic analysis to build the new expression. 2244 /// Subclasses may override this routine to provide different behavior. 2245 ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 2246 UnaryOperatorKind Opc, 2247 Expr *SubExpr) { 2248 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); 2249 } 2250 2251 /// Build a new builtin offsetof expression. 2252 /// 2253 /// By default, performs semantic analysis to build the new expression. 2254 /// Subclasses may override this routine to provide different behavior. 2255 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 2256 TypeSourceInfo *Type, 2257 ArrayRef<Sema::OffsetOfComponent> Components, 2258 SourceLocation RParenLoc) { 2259 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 2260 RParenLoc); 2261 } 2262 2263 /// Build a new sizeof, alignof or vec_step expression with a 2264 /// type argument. 2265 /// 2266 /// By default, performs semantic analysis to build the new expression. 2267 /// Subclasses may override this routine to provide different behavior. 2268 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, 2269 SourceLocation OpLoc, 2270 UnaryExprOrTypeTrait ExprKind, 2271 SourceRange R) { 2272 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); 2273 } 2274 2275 /// Build a new sizeof, alignof or vec step expression with an 2276 /// expression argument. 2277 /// 2278 /// By default, performs semantic analysis to build the new expression. 2279 /// Subclasses may override this routine to provide different behavior. 2280 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, 2281 UnaryExprOrTypeTrait ExprKind, 2282 SourceRange R) { 2283 ExprResult Result 2284 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); 2285 if (Result.isInvalid()) 2286 return ExprError(); 2287 2288 return Result; 2289 } 2290 2291 /// Build a new array subscript expression. 2292 /// 2293 /// By default, performs semantic analysis to build the new expression. 2294 /// Subclasses may override this routine to provide different behavior. 2295 ExprResult RebuildArraySubscriptExpr(Expr *LHS, 2296 SourceLocation LBracketLoc, 2297 Expr *RHS, 2298 SourceLocation RBracketLoc) { 2299 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, 2300 LBracketLoc, RHS, 2301 RBracketLoc); 2302 } 2303 2304 /// Build a new array section expression. 2305 /// 2306 /// By default, performs semantic analysis to build the new expression. 2307 /// Subclasses may override this routine to provide different behavior. 2308 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, 2309 Expr *LowerBound, 2310 SourceLocation ColonLoc, Expr *Length, 2311 SourceLocation RBracketLoc) { 2312 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound, 2313 ColonLoc, Length, RBracketLoc); 2314 } 2315 2316 /// Build a new call expression. 2317 /// 2318 /// By default, performs semantic analysis to build the new expression. 2319 /// Subclasses may override this routine to provide different behavior. 2320 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 2321 MultiExprArg Args, 2322 SourceLocation RParenLoc, 2323 Expr *ExecConfig = nullptr) { 2324 return getSema().BuildCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, Args, 2325 RParenLoc, ExecConfig); 2326 } 2327 2328 /// Build a new member access expression. 2329 /// 2330 /// By default, performs semantic analysis to build the new expression. 2331 /// Subclasses may override this routine to provide different behavior. 2332 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 2333 bool isArrow, 2334 NestedNameSpecifierLoc QualifierLoc, 2335 SourceLocation TemplateKWLoc, 2336 const DeclarationNameInfo &MemberNameInfo, 2337 ValueDecl *Member, 2338 NamedDecl *FoundDecl, 2339 const TemplateArgumentListInfo *ExplicitTemplateArgs, 2340 NamedDecl *FirstQualifierInScope) { 2341 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, 2342 isArrow); 2343 if (!Member->getDeclName()) { 2344 // We have a reference to an unnamed field. This is always the 2345 // base of an anonymous struct/union member access, i.e. the 2346 // field is always of record type. 2347 assert(Member->getType()->isRecordType() && 2348 "unnamed member not of record type?"); 2349 2350 BaseResult = 2351 getSema().PerformObjectMemberConversion(BaseResult.get(), 2352 QualifierLoc.getNestedNameSpecifier(), 2353 FoundDecl, Member); 2354 if (BaseResult.isInvalid()) 2355 return ExprError(); 2356 Base = BaseResult.get(); 2357 2358 CXXScopeSpec EmptySS; 2359 return getSema().BuildFieldReferenceExpr( 2360 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member), 2361 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo); 2362 } 2363 2364 CXXScopeSpec SS; 2365 SS.Adopt(QualifierLoc); 2366 2367 Base = BaseResult.get(); 2368 QualType BaseType = Base->getType(); 2369 2370 if (isArrow && !BaseType->isPointerType()) 2371 return ExprError(); 2372 2373 // FIXME: this involves duplicating earlier analysis in a lot of 2374 // cases; we should avoid this when possible. 2375 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 2376 R.addDecl(FoundDecl); 2377 R.resolveKind(); 2378 2379 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 2380 SS, TemplateKWLoc, 2381 FirstQualifierInScope, 2382 R, ExplicitTemplateArgs, 2383 /*S*/nullptr); 2384 } 2385 2386 /// Build a new binary operator expression. 2387 /// 2388 /// By default, performs semantic analysis to build the new expression. 2389 /// Subclasses may override this routine to provide different behavior. 2390 ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 2391 BinaryOperatorKind Opc, 2392 Expr *LHS, Expr *RHS) { 2393 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); 2394 } 2395 2396 /// Build a new rewritten operator expression. 2397 /// 2398 /// By default, performs semantic analysis to build the new expression. 2399 /// Subclasses may override this routine to provide different behavior. 2400 ExprResult RebuildCXXRewrittenBinaryOperator( 2401 SourceLocation OpLoc, BinaryOperatorKind Opcode, 2402 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) { 2403 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS, 2404 RHS, /*RequiresADL*/false); 2405 } 2406 2407 /// Build a new conditional operator expression. 2408 /// 2409 /// By default, performs semantic analysis to build the new expression. 2410 /// Subclasses may override this routine to provide different behavior. 2411 ExprResult RebuildConditionalOperator(Expr *Cond, 2412 SourceLocation QuestionLoc, 2413 Expr *LHS, 2414 SourceLocation ColonLoc, 2415 Expr *RHS) { 2416 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 2417 LHS, RHS); 2418 } 2419 2420 /// Build a new C-style cast expression. 2421 /// 2422 /// By default, performs semantic analysis to build the new expression. 2423 /// Subclasses may override this routine to provide different behavior. 2424 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 2425 TypeSourceInfo *TInfo, 2426 SourceLocation RParenLoc, 2427 Expr *SubExpr) { 2428 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 2429 SubExpr); 2430 } 2431 2432 /// Build a new compound literal expression. 2433 /// 2434 /// By default, performs semantic analysis to build the new expression. 2435 /// Subclasses may override this routine to provide different behavior. 2436 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 2437 TypeSourceInfo *TInfo, 2438 SourceLocation RParenLoc, 2439 Expr *Init) { 2440 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 2441 Init); 2442 } 2443 2444 /// Build a new extended vector element access expression. 2445 /// 2446 /// By default, performs semantic analysis to build the new expression. 2447 /// Subclasses may override this routine to provide different behavior. 2448 ExprResult RebuildExtVectorElementExpr(Expr *Base, 2449 SourceLocation OpLoc, 2450 SourceLocation AccessorLoc, 2451 IdentifierInfo &Accessor) { 2452 2453 CXXScopeSpec SS; 2454 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 2455 return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 2456 OpLoc, /*IsArrow*/ false, 2457 SS, SourceLocation(), 2458 /*FirstQualifierInScope*/ nullptr, 2459 NameInfo, 2460 /* TemplateArgs */ nullptr, 2461 /*S*/ nullptr); 2462 } 2463 2464 /// Build a new initializer list expression. 2465 /// 2466 /// By default, performs semantic analysis to build the new expression. 2467 /// Subclasses may override this routine to provide different behavior. 2468 ExprResult RebuildInitList(SourceLocation LBraceLoc, 2469 MultiExprArg Inits, 2470 SourceLocation RBraceLoc) { 2471 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc); 2472 } 2473 2474 /// Build a new designated initializer expression. 2475 /// 2476 /// By default, performs semantic analysis to build the new expression. 2477 /// Subclasses may override this routine to provide different behavior. 2478 ExprResult RebuildDesignatedInitExpr(Designation &Desig, 2479 MultiExprArg ArrayExprs, 2480 SourceLocation EqualOrColonLoc, 2481 bool GNUSyntax, 2482 Expr *Init) { 2483 ExprResult Result 2484 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 2485 Init); 2486 if (Result.isInvalid()) 2487 return ExprError(); 2488 2489 return Result; 2490 } 2491 2492 /// Build a new value-initialized expression. 2493 /// 2494 /// By default, builds the implicit value initialization without performing 2495 /// any semantic analysis. Subclasses may override this routine to provide 2496 /// different behavior. 2497 ExprResult RebuildImplicitValueInitExpr(QualType T) { 2498 return new (SemaRef.Context) ImplicitValueInitExpr(T); 2499 } 2500 2501 /// Build a new \c va_arg expression. 2502 /// 2503 /// By default, performs semantic analysis to build the new expression. 2504 /// Subclasses may override this routine to provide different behavior. 2505 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 2506 Expr *SubExpr, TypeSourceInfo *TInfo, 2507 SourceLocation RParenLoc) { 2508 return getSema().BuildVAArgExpr(BuiltinLoc, 2509 SubExpr, TInfo, 2510 RParenLoc); 2511 } 2512 2513 /// Build a new expression list in parentheses. 2514 /// 2515 /// By default, performs semantic analysis to build the new expression. 2516 /// Subclasses may override this routine to provide different behavior. 2517 ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 2518 MultiExprArg SubExprs, 2519 SourceLocation RParenLoc) { 2520 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); 2521 } 2522 2523 /// Build a new address-of-label expression. 2524 /// 2525 /// By default, performs semantic analysis, using the name of the label 2526 /// rather than attempting to map the label statement itself. 2527 /// Subclasses may override this routine to provide different behavior. 2528 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 2529 SourceLocation LabelLoc, LabelDecl *Label) { 2530 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 2531 } 2532 2533 /// Build a new GNU statement expression. 2534 /// 2535 /// By default, performs semantic analysis to build the new expression. 2536 /// Subclasses may override this routine to provide different behavior. 2537 ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, 2538 SourceLocation RParenLoc, unsigned TemplateDepth) { 2539 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc, 2540 TemplateDepth); 2541 } 2542 2543 /// Build a new __builtin_choose_expr expression. 2544 /// 2545 /// By default, performs semantic analysis to build the new expression. 2546 /// Subclasses may override this routine to provide different behavior. 2547 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 2548 Expr *Cond, Expr *LHS, Expr *RHS, 2549 SourceLocation RParenLoc) { 2550 return SemaRef.ActOnChooseExpr(BuiltinLoc, 2551 Cond, LHS, RHS, 2552 RParenLoc); 2553 } 2554 2555 /// Build a new generic selection expression. 2556 /// 2557 /// By default, performs semantic analysis to build the new expression. 2558 /// Subclasses may override this routine to provide different behavior. 2559 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 2560 SourceLocation DefaultLoc, 2561 SourceLocation RParenLoc, 2562 Expr *ControllingExpr, 2563 ArrayRef<TypeSourceInfo *> Types, 2564 ArrayRef<Expr *> Exprs) { 2565 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 2566 ControllingExpr, Types, Exprs); 2567 } 2568 2569 /// Build a new overloaded operator call expression. 2570 /// 2571 /// By default, performs semantic analysis to build the new expression. 2572 /// The semantic analysis provides the behavior of template instantiation, 2573 /// copying with transformations that turn what looks like an overloaded 2574 /// operator call into a use of a builtin operator, performing 2575 /// argument-dependent lookup, etc. Subclasses may override this routine to 2576 /// provide different behavior. 2577 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 2578 SourceLocation OpLoc, 2579 Expr *Callee, 2580 Expr *First, 2581 Expr *Second); 2582 2583 /// Build a new C++ "named" cast expression, such as static_cast or 2584 /// reinterpret_cast. 2585 /// 2586 /// By default, this routine dispatches to one of the more-specific routines 2587 /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 2588 /// Subclasses may override this routine to provide different behavior. 2589 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 2590 Stmt::StmtClass Class, 2591 SourceLocation LAngleLoc, 2592 TypeSourceInfo *TInfo, 2593 SourceLocation RAngleLoc, 2594 SourceLocation LParenLoc, 2595 Expr *SubExpr, 2596 SourceLocation RParenLoc) { 2597 switch (Class) { 2598 case Stmt::CXXStaticCastExprClass: 2599 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 2600 RAngleLoc, LParenLoc, 2601 SubExpr, RParenLoc); 2602 2603 case Stmt::CXXDynamicCastExprClass: 2604 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 2605 RAngleLoc, LParenLoc, 2606 SubExpr, RParenLoc); 2607 2608 case Stmt::CXXReinterpretCastExprClass: 2609 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 2610 RAngleLoc, LParenLoc, 2611 SubExpr, 2612 RParenLoc); 2613 2614 case Stmt::CXXConstCastExprClass: 2615 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 2616 RAngleLoc, LParenLoc, 2617 SubExpr, RParenLoc); 2618 2619 default: 2620 llvm_unreachable("Invalid C++ named cast"); 2621 } 2622 } 2623 2624 /// Build a new C++ static_cast expression. 2625 /// 2626 /// By default, performs semantic analysis to build the new expression. 2627 /// Subclasses may override this routine to provide different behavior. 2628 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 2629 SourceLocation LAngleLoc, 2630 TypeSourceInfo *TInfo, 2631 SourceLocation RAngleLoc, 2632 SourceLocation LParenLoc, 2633 Expr *SubExpr, 2634 SourceLocation RParenLoc) { 2635 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 2636 TInfo, SubExpr, 2637 SourceRange(LAngleLoc, RAngleLoc), 2638 SourceRange(LParenLoc, RParenLoc)); 2639 } 2640 2641 /// Build a new C++ dynamic_cast expression. 2642 /// 2643 /// By default, performs semantic analysis to build the new expression. 2644 /// Subclasses may override this routine to provide different behavior. 2645 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 2646 SourceLocation LAngleLoc, 2647 TypeSourceInfo *TInfo, 2648 SourceLocation RAngleLoc, 2649 SourceLocation LParenLoc, 2650 Expr *SubExpr, 2651 SourceLocation RParenLoc) { 2652 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 2653 TInfo, SubExpr, 2654 SourceRange(LAngleLoc, RAngleLoc), 2655 SourceRange(LParenLoc, RParenLoc)); 2656 } 2657 2658 /// Build a new C++ reinterpret_cast expression. 2659 /// 2660 /// By default, performs semantic analysis to build the new expression. 2661 /// Subclasses may override this routine to provide different behavior. 2662 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 2663 SourceLocation LAngleLoc, 2664 TypeSourceInfo *TInfo, 2665 SourceLocation RAngleLoc, 2666 SourceLocation LParenLoc, 2667 Expr *SubExpr, 2668 SourceLocation RParenLoc) { 2669 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 2670 TInfo, SubExpr, 2671 SourceRange(LAngleLoc, RAngleLoc), 2672 SourceRange(LParenLoc, RParenLoc)); 2673 } 2674 2675 /// Build a new C++ const_cast expression. 2676 /// 2677 /// By default, performs semantic analysis to build the new expression. 2678 /// Subclasses may override this routine to provide different behavior. 2679 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 2680 SourceLocation LAngleLoc, 2681 TypeSourceInfo *TInfo, 2682 SourceLocation RAngleLoc, 2683 SourceLocation LParenLoc, 2684 Expr *SubExpr, 2685 SourceLocation RParenLoc) { 2686 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 2687 TInfo, SubExpr, 2688 SourceRange(LAngleLoc, RAngleLoc), 2689 SourceRange(LParenLoc, RParenLoc)); 2690 } 2691 2692 /// Build a new C++ functional-style cast expression. 2693 /// 2694 /// By default, performs semantic analysis to build the new expression. 2695 /// Subclasses may override this routine to provide different behavior. 2696 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 2697 SourceLocation LParenLoc, 2698 Expr *Sub, 2699 SourceLocation RParenLoc, 2700 bool ListInitialization) { 2701 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 2702 MultiExprArg(&Sub, 1), RParenLoc, 2703 ListInitialization); 2704 } 2705 2706 /// Build a new C++ __builtin_bit_cast expression. 2707 /// 2708 /// By default, performs semantic analysis to build the new expression. 2709 /// Subclasses may override this routine to provide different behavior. 2710 ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, 2711 TypeSourceInfo *TSI, Expr *Sub, 2712 SourceLocation RParenLoc) { 2713 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc); 2714 } 2715 2716 /// Build a new C++ typeid(type) expression. 2717 /// 2718 /// By default, performs semantic analysis to build the new expression. 2719 /// Subclasses may override this routine to provide different behavior. 2720 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 2721 SourceLocation TypeidLoc, 2722 TypeSourceInfo *Operand, 2723 SourceLocation RParenLoc) { 2724 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 2725 RParenLoc); 2726 } 2727 2728 2729 /// Build a new C++ typeid(expr) expression. 2730 /// 2731 /// By default, performs semantic analysis to build the new expression. 2732 /// Subclasses may override this routine to provide different behavior. 2733 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 2734 SourceLocation TypeidLoc, 2735 Expr *Operand, 2736 SourceLocation RParenLoc) { 2737 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 2738 RParenLoc); 2739 } 2740 2741 /// Build a new C++ __uuidof(type) expression. 2742 /// 2743 /// By default, performs semantic analysis to build the new expression. 2744 /// Subclasses may override this routine to provide different behavior. 2745 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 2746 SourceLocation TypeidLoc, 2747 TypeSourceInfo *Operand, 2748 SourceLocation RParenLoc) { 2749 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 2750 RParenLoc); 2751 } 2752 2753 /// Build a new C++ __uuidof(expr) expression. 2754 /// 2755 /// By default, performs semantic analysis to build the new expression. 2756 /// Subclasses may override this routine to provide different behavior. 2757 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 2758 SourceLocation TypeidLoc, 2759 Expr *Operand, 2760 SourceLocation RParenLoc) { 2761 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 2762 RParenLoc); 2763 } 2764 2765 /// Build a new C++ "this" expression. 2766 /// 2767 /// By default, builds a new "this" expression without performing any 2768 /// semantic analysis. Subclasses may override this routine to provide 2769 /// different behavior. 2770 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 2771 QualType ThisType, 2772 bool isImplicit) { 2773 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit); 2774 } 2775 2776 /// Build a new C++ throw expression. 2777 /// 2778 /// By default, performs semantic analysis to build the new expression. 2779 /// Subclasses may override this routine to provide different behavior. 2780 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, 2781 bool IsThrownVariableInScope) { 2782 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); 2783 } 2784 2785 /// Build a new C++ default-argument expression. 2786 /// 2787 /// By default, builds a new default-argument expression, which does not 2788 /// require any semantic analysis. Subclasses may override this routine to 2789 /// provide different behavior. 2790 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) { 2791 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param, 2792 getSema().CurContext); 2793 } 2794 2795 /// Build a new C++11 default-initialization expression. 2796 /// 2797 /// By default, builds a new default field initialization expression, which 2798 /// does not require any semantic analysis. Subclasses may override this 2799 /// routine to provide different behavior. 2800 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, 2801 FieldDecl *Field) { 2802 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field, 2803 getSema().CurContext); 2804 } 2805 2806 /// Build a new C++ zero-initialization expression. 2807 /// 2808 /// By default, performs semantic analysis to build the new expression. 2809 /// Subclasses may override this routine to provide different behavior. 2810 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 2811 SourceLocation LParenLoc, 2812 SourceLocation RParenLoc) { 2813 return getSema().BuildCXXTypeConstructExpr( 2814 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false); 2815 } 2816 2817 /// Build a new C++ "new" expression. 2818 /// 2819 /// By default, performs semantic analysis to build the new expression. 2820 /// Subclasses may override this routine to provide different behavior. 2821 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, 2822 bool UseGlobal, 2823 SourceLocation PlacementLParen, 2824 MultiExprArg PlacementArgs, 2825 SourceLocation PlacementRParen, 2826 SourceRange TypeIdParens, 2827 QualType AllocatedType, 2828 TypeSourceInfo *AllocatedTypeInfo, 2829 Optional<Expr *> ArraySize, 2830 SourceRange DirectInitRange, 2831 Expr *Initializer) { 2832 return getSema().BuildCXXNew(StartLoc, UseGlobal, 2833 PlacementLParen, 2834 PlacementArgs, 2835 PlacementRParen, 2836 TypeIdParens, 2837 AllocatedType, 2838 AllocatedTypeInfo, 2839 ArraySize, 2840 DirectInitRange, 2841 Initializer); 2842 } 2843 2844 /// Build a new C++ "delete" expression. 2845 /// 2846 /// By default, performs semantic analysis to build the new expression. 2847 /// Subclasses may override this routine to provide different behavior. 2848 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 2849 bool IsGlobalDelete, 2850 bool IsArrayForm, 2851 Expr *Operand) { 2852 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 2853 Operand); 2854 } 2855 2856 /// Build a new type trait expression. 2857 /// 2858 /// By default, performs semantic analysis to build the new expression. 2859 /// Subclasses may override this routine to provide different behavior. 2860 ExprResult RebuildTypeTrait(TypeTrait Trait, 2861 SourceLocation StartLoc, 2862 ArrayRef<TypeSourceInfo *> Args, 2863 SourceLocation RParenLoc) { 2864 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); 2865 } 2866 2867 /// Build a new array type trait expression. 2868 /// 2869 /// By default, performs semantic analysis to build the new expression. 2870 /// Subclasses may override this routine to provide different behavior. 2871 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, 2872 SourceLocation StartLoc, 2873 TypeSourceInfo *TSInfo, 2874 Expr *DimExpr, 2875 SourceLocation RParenLoc) { 2876 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); 2877 } 2878 2879 /// Build a new expression trait expression. 2880 /// 2881 /// By default, performs semantic analysis to build the new expression. 2882 /// Subclasses may override this routine to provide different behavior. 2883 ExprResult RebuildExpressionTrait(ExpressionTrait Trait, 2884 SourceLocation StartLoc, 2885 Expr *Queried, 2886 SourceLocation RParenLoc) { 2887 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); 2888 } 2889 2890 /// Build a new (previously unresolved) declaration reference 2891 /// expression. 2892 /// 2893 /// By default, performs semantic analysis to build the new expression. 2894 /// Subclasses may override this routine to provide different behavior. 2895 ExprResult RebuildDependentScopeDeclRefExpr( 2896 NestedNameSpecifierLoc QualifierLoc, 2897 SourceLocation TemplateKWLoc, 2898 const DeclarationNameInfo &NameInfo, 2899 const TemplateArgumentListInfo *TemplateArgs, 2900 bool IsAddressOfOperand, 2901 TypeSourceInfo **RecoveryTSI) { 2902 CXXScopeSpec SS; 2903 SS.Adopt(QualifierLoc); 2904 2905 if (TemplateArgs || TemplateKWLoc.isValid()) 2906 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, 2907 TemplateArgs); 2908 2909 return getSema().BuildQualifiedDeclarationNameExpr( 2910 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI); 2911 } 2912 2913 /// Build a new template-id expression. 2914 /// 2915 /// By default, performs semantic analysis to build the new expression. 2916 /// Subclasses may override this routine to provide different behavior. 2917 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 2918 SourceLocation TemplateKWLoc, 2919 LookupResult &R, 2920 bool RequiresADL, 2921 const TemplateArgumentListInfo *TemplateArgs) { 2922 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, 2923 TemplateArgs); 2924 } 2925 2926 /// Build a new object-construction expression. 2927 /// 2928 /// By default, performs semantic analysis to build the new expression. 2929 /// Subclasses may override this routine to provide different behavior. 2930 ExprResult RebuildCXXConstructExpr(QualType T, 2931 SourceLocation Loc, 2932 CXXConstructorDecl *Constructor, 2933 bool IsElidable, 2934 MultiExprArg Args, 2935 bool HadMultipleCandidates, 2936 bool ListInitialization, 2937 bool StdInitListInitialization, 2938 bool RequiresZeroInit, 2939 CXXConstructExpr::ConstructionKind ConstructKind, 2940 SourceRange ParenRange) { 2941 SmallVector<Expr*, 8> ConvertedArgs; 2942 if (getSema().CompleteConstructorCall(Constructor, Args, Loc, 2943 ConvertedArgs)) 2944 return ExprError(); 2945 2946 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, 2947 IsElidable, 2948 ConvertedArgs, 2949 HadMultipleCandidates, 2950 ListInitialization, 2951 StdInitListInitialization, 2952 RequiresZeroInit, ConstructKind, 2953 ParenRange); 2954 } 2955 2956 /// Build a new implicit construction via inherited constructor 2957 /// expression. 2958 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, 2959 CXXConstructorDecl *Constructor, 2960 bool ConstructsVBase, 2961 bool InheritedFromVBase) { 2962 return new (getSema().Context) CXXInheritedCtorInitExpr( 2963 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase); 2964 } 2965 2966 /// Build a new object-construction expression. 2967 /// 2968 /// By default, performs semantic analysis to build the new expression. 2969 /// Subclasses may override this routine to provide different behavior. 2970 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 2971 SourceLocation LParenOrBraceLoc, 2972 MultiExprArg Args, 2973 SourceLocation RParenOrBraceLoc, 2974 bool ListInitialization) { 2975 return getSema().BuildCXXTypeConstructExpr( 2976 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization); 2977 } 2978 2979 /// Build a new object-construction expression. 2980 /// 2981 /// By default, performs semantic analysis to build the new expression. 2982 /// Subclasses may override this routine to provide different behavior. 2983 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 2984 SourceLocation LParenLoc, 2985 MultiExprArg Args, 2986 SourceLocation RParenLoc, 2987 bool ListInitialization) { 2988 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args, 2989 RParenLoc, ListInitialization); 2990 } 2991 2992 /// Build a new member reference expression. 2993 /// 2994 /// By default, performs semantic analysis to build the new expression. 2995 /// Subclasses may override this routine to provide different behavior. 2996 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 2997 QualType BaseType, 2998 bool IsArrow, 2999 SourceLocation OperatorLoc, 3000 NestedNameSpecifierLoc QualifierLoc, 3001 SourceLocation TemplateKWLoc, 3002 NamedDecl *FirstQualifierInScope, 3003 const DeclarationNameInfo &MemberNameInfo, 3004 const TemplateArgumentListInfo *TemplateArgs) { 3005 CXXScopeSpec SS; 3006 SS.Adopt(QualifierLoc); 3007 3008 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 3009 OperatorLoc, IsArrow, 3010 SS, TemplateKWLoc, 3011 FirstQualifierInScope, 3012 MemberNameInfo, 3013 TemplateArgs, /*S*/nullptr); 3014 } 3015 3016 /// Build a new member reference expression. 3017 /// 3018 /// By default, performs semantic analysis to build the new expression. 3019 /// Subclasses may override this routine to provide different behavior. 3020 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, 3021 SourceLocation OperatorLoc, 3022 bool IsArrow, 3023 NestedNameSpecifierLoc QualifierLoc, 3024 SourceLocation TemplateKWLoc, 3025 NamedDecl *FirstQualifierInScope, 3026 LookupResult &R, 3027 const TemplateArgumentListInfo *TemplateArgs) { 3028 CXXScopeSpec SS; 3029 SS.Adopt(QualifierLoc); 3030 3031 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 3032 OperatorLoc, IsArrow, 3033 SS, TemplateKWLoc, 3034 FirstQualifierInScope, 3035 R, TemplateArgs, /*S*/nullptr); 3036 } 3037 3038 /// Build a new noexcept expression. 3039 /// 3040 /// By default, performs semantic analysis to build the new expression. 3041 /// Subclasses may override this routine to provide different behavior. 3042 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 3043 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 3044 } 3045 3046 /// Build a new expression to compute the length of a parameter pack. 3047 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, 3048 NamedDecl *Pack, 3049 SourceLocation PackLoc, 3050 SourceLocation RParenLoc, 3051 Optional<unsigned> Length, 3052 ArrayRef<TemplateArgument> PartialArgs) { 3053 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, 3054 RParenLoc, Length, PartialArgs); 3055 } 3056 3057 /// Build a new expression representing a call to a source location 3058 /// builtin. 3059 /// 3060 /// By default, performs semantic analysis to build the new expression. 3061 /// Subclasses may override this routine to provide different behavior. 3062 ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind, 3063 SourceLocation BuiltinLoc, 3064 SourceLocation RPLoc, 3065 DeclContext *ParentContext) { 3066 return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext); 3067 } 3068 3069 /// Build a new Objective-C boxed expression. 3070 /// 3071 /// By default, performs semantic analysis to build the new expression. 3072 /// Subclasses may override this routine to provide different behavior. 3073 ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, 3074 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, 3075 NamedDecl *FoundDecl, ConceptDecl *NamedConcept, 3076 TemplateArgumentListInfo *TALI) { 3077 CXXScopeSpec SS; 3078 SS.Adopt(NNS); 3079 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc, 3080 ConceptNameInfo, 3081 FoundDecl, 3082 NamedConcept, TALI); 3083 if (Result.isInvalid()) 3084 return ExprError(); 3085 return Result; 3086 } 3087 3088 /// \brief Build a new requires expression. 3089 /// 3090 /// By default, performs semantic analysis to build the new expression. 3091 /// Subclasses may override this routine to provide different behavior. 3092 ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, 3093 RequiresExprBodyDecl *Body, 3094 ArrayRef<ParmVarDecl *> LocalParameters, 3095 ArrayRef<concepts::Requirement *> Requirements, 3096 SourceLocation ClosingBraceLoc) { 3097 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, 3098 LocalParameters, Requirements, ClosingBraceLoc); 3099 } 3100 3101 concepts::TypeRequirement * 3102 RebuildTypeRequirement( 3103 concepts::Requirement::SubstitutionDiagnostic *SubstDiag) { 3104 return SemaRef.BuildTypeRequirement(SubstDiag); 3105 } 3106 3107 concepts::TypeRequirement *RebuildTypeRequirement(TypeSourceInfo *T) { 3108 return SemaRef.BuildTypeRequirement(T); 3109 } 3110 3111 concepts::ExprRequirement * 3112 RebuildExprRequirement( 3113 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, 3114 SourceLocation NoexceptLoc, 3115 concepts::ExprRequirement::ReturnTypeRequirement Ret) { 3116 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc, 3117 std::move(Ret)); 3118 } 3119 3120 concepts::ExprRequirement * 3121 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, 3122 concepts::ExprRequirement::ReturnTypeRequirement Ret) { 3123 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc, 3124 std::move(Ret)); 3125 } 3126 3127 concepts::NestedRequirement * 3128 RebuildNestedRequirement( 3129 concepts::Requirement::SubstitutionDiagnostic *SubstDiag) { 3130 return SemaRef.BuildNestedRequirement(SubstDiag); 3131 } 3132 3133 concepts::NestedRequirement *RebuildNestedRequirement(Expr *Constraint) { 3134 return SemaRef.BuildNestedRequirement(Constraint); 3135 } 3136 3137 /// \brief Build a new Objective-C boxed expression. 3138 /// 3139 /// By default, performs semantic analysis to build the new expression. 3140 /// Subclasses may override this routine to provide different behavior. 3141 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { 3142 return getSema().BuildObjCBoxedExpr(SR, ValueExpr); 3143 } 3144 3145 /// Build a new Objective-C array literal. 3146 /// 3147 /// By default, performs semantic analysis to build the new expression. 3148 /// Subclasses may override this routine to provide different behavior. 3149 ExprResult RebuildObjCArrayLiteral(SourceRange Range, 3150 Expr **Elements, unsigned NumElements) { 3151 return getSema().BuildObjCArrayLiteral(Range, 3152 MultiExprArg(Elements, NumElements)); 3153 } 3154 3155 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, 3156 Expr *Base, Expr *Key, 3157 ObjCMethodDecl *getterMethod, 3158 ObjCMethodDecl *setterMethod) { 3159 return getSema().BuildObjCSubscriptExpression(RB, Base, Key, 3160 getterMethod, setterMethod); 3161 } 3162 3163 /// Build a new Objective-C dictionary literal. 3164 /// 3165 /// By default, performs semantic analysis to build the new expression. 3166 /// Subclasses may override this routine to provide different behavior. 3167 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, 3168 MutableArrayRef<ObjCDictionaryElement> Elements) { 3169 return getSema().BuildObjCDictionaryLiteral(Range, Elements); 3170 } 3171 3172 /// Build a new Objective-C \@encode expression. 3173 /// 3174 /// By default, performs semantic analysis to build the new expression. 3175 /// Subclasses may override this routine to provide different behavior. 3176 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 3177 TypeSourceInfo *EncodeTypeInfo, 3178 SourceLocation RParenLoc) { 3179 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); 3180 } 3181 3182 /// Build a new Objective-C class message. 3183 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 3184 Selector Sel, 3185 ArrayRef<SourceLocation> SelectorLocs, 3186 ObjCMethodDecl *Method, 3187 SourceLocation LBracLoc, 3188 MultiExprArg Args, 3189 SourceLocation RBracLoc) { 3190 return SemaRef.BuildClassMessage(ReceiverTypeInfo, 3191 ReceiverTypeInfo->getType(), 3192 /*SuperLoc=*/SourceLocation(), 3193 Sel, Method, LBracLoc, SelectorLocs, 3194 RBracLoc, Args); 3195 } 3196 3197 /// Build a new Objective-C instance message. 3198 ExprResult RebuildObjCMessageExpr(Expr *Receiver, 3199 Selector Sel, 3200 ArrayRef<SourceLocation> SelectorLocs, 3201 ObjCMethodDecl *Method, 3202 SourceLocation LBracLoc, 3203 MultiExprArg Args, 3204 SourceLocation RBracLoc) { 3205 return SemaRef.BuildInstanceMessage(Receiver, 3206 Receiver->getType(), 3207 /*SuperLoc=*/SourceLocation(), 3208 Sel, Method, LBracLoc, SelectorLocs, 3209 RBracLoc, Args); 3210 } 3211 3212 /// Build a new Objective-C instance/class message to 'super'. 3213 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, 3214 Selector Sel, 3215 ArrayRef<SourceLocation> SelectorLocs, 3216 QualType SuperType, 3217 ObjCMethodDecl *Method, 3218 SourceLocation LBracLoc, 3219 MultiExprArg Args, 3220 SourceLocation RBracLoc) { 3221 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, 3222 SuperType, 3223 SuperLoc, 3224 Sel, Method, LBracLoc, SelectorLocs, 3225 RBracLoc, Args) 3226 : SemaRef.BuildClassMessage(nullptr, 3227 SuperType, 3228 SuperLoc, 3229 Sel, Method, LBracLoc, SelectorLocs, 3230 RBracLoc, Args); 3231 3232 3233 } 3234 3235 /// Build a new Objective-C ivar reference expression. 3236 /// 3237 /// By default, performs semantic analysis to build the new expression. 3238 /// Subclasses may override this routine to provide different behavior. 3239 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 3240 SourceLocation IvarLoc, 3241 bool IsArrow, bool IsFreeIvar) { 3242 CXXScopeSpec SS; 3243 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); 3244 ExprResult Result = getSema().BuildMemberReferenceExpr( 3245 BaseArg, BaseArg->getType(), 3246 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(), 3247 /*FirstQualifierInScope=*/nullptr, NameInfo, 3248 /*TemplateArgs=*/nullptr, 3249 /*S=*/nullptr); 3250 if (IsFreeIvar && Result.isUsable()) 3251 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar); 3252 return Result; 3253 } 3254 3255 /// Build a new Objective-C property reference expression. 3256 /// 3257 /// By default, performs semantic analysis to build the new expression. 3258 /// Subclasses may override this routine to provide different behavior. 3259 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 3260 ObjCPropertyDecl *Property, 3261 SourceLocation PropertyLoc) { 3262 CXXScopeSpec SS; 3263 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); 3264 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), 3265 /*FIXME:*/PropertyLoc, 3266 /*IsArrow=*/false, 3267 SS, SourceLocation(), 3268 /*FirstQualifierInScope=*/nullptr, 3269 NameInfo, 3270 /*TemplateArgs=*/nullptr, 3271 /*S=*/nullptr); 3272 } 3273 3274 /// Build a new Objective-C property reference expression. 3275 /// 3276 /// By default, performs semantic analysis to build the new expression. 3277 /// Subclasses may override this routine to provide different behavior. 3278 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 3279 ObjCMethodDecl *Getter, 3280 ObjCMethodDecl *Setter, 3281 SourceLocation PropertyLoc) { 3282 // Since these expressions can only be value-dependent, we do not 3283 // need to perform semantic analysis again. 3284 return Owned( 3285 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 3286 VK_LValue, OK_ObjCProperty, 3287 PropertyLoc, Base)); 3288 } 3289 3290 /// Build a new Objective-C "isa" expression. 3291 /// 3292 /// By default, performs semantic analysis to build the new expression. 3293 /// Subclasses may override this routine to provide different behavior. 3294 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 3295 SourceLocation OpLoc, bool IsArrow) { 3296 CXXScopeSpec SS; 3297 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); 3298 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), 3299 OpLoc, IsArrow, 3300 SS, SourceLocation(), 3301 /*FirstQualifierInScope=*/nullptr, 3302 NameInfo, 3303 /*TemplateArgs=*/nullptr, 3304 /*S=*/nullptr); 3305 } 3306 3307 /// Build a new shuffle vector expression. 3308 /// 3309 /// By default, performs semantic analysis to build the new expression. 3310 /// Subclasses may override this routine to provide different behavior. 3311 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 3312 MultiExprArg SubExprs, 3313 SourceLocation RParenLoc) { 3314 // Find the declaration for __builtin_shufflevector 3315 const IdentifierInfo &Name 3316 = SemaRef.Context.Idents.get("__builtin_shufflevector"); 3317 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 3318 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 3319 assert(!Lookup.empty() && "No __builtin_shufflevector?"); 3320 3321 // Build a reference to the __builtin_shufflevector builtin 3322 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); 3323 Expr *Callee = new (SemaRef.Context) 3324 DeclRefExpr(SemaRef.Context, Builtin, false, 3325 SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc); 3326 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); 3327 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, 3328 CK_BuiltinFnToFnPtr).get(); 3329 3330 // Build the CallExpr 3331 ExprResult TheCall = CallExpr::Create( 3332 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), 3333 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); 3334 3335 // Type-check the __builtin_shufflevector expression. 3336 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); 3337 } 3338 3339 /// Build a new convert vector expression. 3340 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, 3341 Expr *SrcExpr, TypeSourceInfo *DstTInfo, 3342 SourceLocation RParenLoc) { 3343 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, 3344 BuiltinLoc, RParenLoc); 3345 } 3346 3347 /// Build a new template argument pack expansion. 3348 /// 3349 /// By default, performs semantic analysis to build a new pack expansion 3350 /// for a template argument. Subclasses may override this routine to provide 3351 /// different behavior. 3352 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 3353 SourceLocation EllipsisLoc, 3354 Optional<unsigned> NumExpansions) { 3355 switch (Pattern.getArgument().getKind()) { 3356 case TemplateArgument::Expression: { 3357 ExprResult Result 3358 = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 3359 EllipsisLoc, NumExpansions); 3360 if (Result.isInvalid()) 3361 return TemplateArgumentLoc(); 3362 3363 return TemplateArgumentLoc(Result.get(), Result.get()); 3364 } 3365 3366 case TemplateArgument::Template: 3367 return TemplateArgumentLoc(TemplateArgument( 3368 Pattern.getArgument().getAsTemplate(), 3369 NumExpansions), 3370 Pattern.getTemplateQualifierLoc(), 3371 Pattern.getTemplateNameLoc(), 3372 EllipsisLoc); 3373 3374 case TemplateArgument::Null: 3375 case TemplateArgument::Integral: 3376 case TemplateArgument::Declaration: 3377 case TemplateArgument::Pack: 3378 case TemplateArgument::TemplateExpansion: 3379 case TemplateArgument::NullPtr: 3380 llvm_unreachable("Pack expansion pattern has no parameter packs"); 3381 3382 case TemplateArgument::Type: 3383 if (TypeSourceInfo *Expansion 3384 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 3385 EllipsisLoc, 3386 NumExpansions)) 3387 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 3388 Expansion); 3389 break; 3390 } 3391 3392 return TemplateArgumentLoc(); 3393 } 3394 3395 /// Build a new expression pack expansion. 3396 /// 3397 /// By default, performs semantic analysis to build a new pack expansion 3398 /// for an expression. Subclasses may override this routine to provide 3399 /// different behavior. 3400 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 3401 Optional<unsigned> NumExpansions) { 3402 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 3403 } 3404 3405 /// Build a new C++1z fold-expression. 3406 /// 3407 /// By default, performs semantic analysis in order to build a new fold 3408 /// expression. 3409 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, 3410 BinaryOperatorKind Operator, 3411 SourceLocation EllipsisLoc, Expr *RHS, 3412 SourceLocation RParenLoc, 3413 Optional<unsigned> NumExpansions) { 3414 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc, 3415 RHS, RParenLoc, NumExpansions); 3416 } 3417 3418 /// Build an empty C++1z fold-expression with the given operator. 3419 /// 3420 /// By default, produces the fallback value for the fold-expression, or 3421 /// produce an error if there is no fallback value. 3422 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, 3423 BinaryOperatorKind Operator) { 3424 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); 3425 } 3426 3427 /// Build a new atomic operation expression. 3428 /// 3429 /// By default, performs semantic analysis to build the new expression. 3430 /// Subclasses may override this routine to provide different behavior. 3431 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, 3432 AtomicExpr::AtomicOp Op, 3433 SourceLocation RParenLoc) { 3434 // Use this for all of the locations, since we don't know the difference 3435 // between the call and the expr at this point. 3436 SourceRange Range{BuiltinLoc, RParenLoc}; 3437 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op, 3438 Sema::AtomicArgumentOrder::AST); 3439 } 3440 3441 private: 3442 TypeLoc TransformTypeInObjectScope(TypeLoc TL, 3443 QualType ObjectType, 3444 NamedDecl *FirstQualifierInScope, 3445 CXXScopeSpec &SS); 3446 3447 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 3448 QualType ObjectType, 3449 NamedDecl *FirstQualifierInScope, 3450 CXXScopeSpec &SS); 3451 3452 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, 3453 NamedDecl *FirstQualifierInScope, 3454 CXXScopeSpec &SS); 3455 3456 QualType TransformDependentNameType(TypeLocBuilder &TLB, 3457 DependentNameTypeLoc TL, 3458 bool DeducibleTSTContext); 3459 }; 3460 3461 template <typename Derived> 3462 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) { 3463 if (!S) 3464 return S; 3465 3466 switch (S->getStmtClass()) { 3467 case Stmt::NoStmtClass: break; 3468 3469 // Transform individual statement nodes 3470 // Pass SDK into statements that can produce a value 3471 #define STMT(Node, Parent) \ 3472 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 3473 #define VALUESTMT(Node, Parent) \ 3474 case Stmt::Node##Class: \ 3475 return getDerived().Transform##Node(cast<Node>(S), SDK); 3476 #define ABSTRACT_STMT(Node) 3477 #define EXPR(Node, Parent) 3478 #include "clang/AST/StmtNodes.inc" 3479 3480 // Transform expressions by calling TransformExpr. 3481 #define STMT(Node, Parent) 3482 #define ABSTRACT_STMT(Stmt) 3483 #define EXPR(Node, Parent) case Stmt::Node##Class: 3484 #include "clang/AST/StmtNodes.inc" 3485 { 3486 ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 3487 3488 if (SDK == SDK_StmtExprResult) 3489 E = getSema().ActOnStmtExprResult(E); 3490 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded); 3491 } 3492 } 3493 3494 return S; 3495 } 3496 3497 template<typename Derived> 3498 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { 3499 if (!S) 3500 return S; 3501 3502 switch (S->getClauseKind()) { 3503 default: break; 3504 // Transform individual clause nodes 3505 #define OPENMP_CLAUSE(Name, Class) \ 3506 case OMPC_ ## Name : \ 3507 return getDerived().Transform ## Class(cast<Class>(S)); 3508 #include "clang/Basic/OpenMPKinds.def" 3509 } 3510 3511 return S; 3512 } 3513 3514 3515 template<typename Derived> 3516 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 3517 if (!E) 3518 return E; 3519 3520 switch (E->getStmtClass()) { 3521 case Stmt::NoStmtClass: break; 3522 #define STMT(Node, Parent) case Stmt::Node##Class: break; 3523 #define ABSTRACT_STMT(Stmt) 3524 #define EXPR(Node, Parent) \ 3525 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 3526 #include "clang/AST/StmtNodes.inc" 3527 } 3528 3529 return E; 3530 } 3531 3532 template<typename Derived> 3533 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, 3534 bool NotCopyInit) { 3535 // Initializers are instantiated like expressions, except that various outer 3536 // layers are stripped. 3537 if (!Init) 3538 return Init; 3539 3540 if (auto *FE = dyn_cast<FullExpr>(Init)) 3541 Init = FE->getSubExpr(); 3542 3543 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) 3544 Init = AIL->getCommonExpr(); 3545 3546 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) 3547 Init = MTE->getSubExpr(); 3548 3549 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) 3550 Init = Binder->getSubExpr(); 3551 3552 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) 3553 Init = ICE->getSubExprAsWritten(); 3554 3555 if (CXXStdInitializerListExpr *ILE = 3556 dyn_cast<CXXStdInitializerListExpr>(Init)) 3557 return TransformInitializer(ILE->getSubExpr(), NotCopyInit); 3558 3559 // If this is copy-initialization, we only need to reconstruct 3560 // InitListExprs. Other forms of copy-initialization will be a no-op if 3561 // the initializer is already the right type. 3562 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); 3563 if (!NotCopyInit && !(Construct && Construct->isListInitialization())) 3564 return getDerived().TransformExpr(Init); 3565 3566 // Revert value-initialization back to empty parens. 3567 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { 3568 SourceRange Parens = VIE->getSourceRange(); 3569 return getDerived().RebuildParenListExpr(Parens.getBegin(), None, 3570 Parens.getEnd()); 3571 } 3572 3573 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. 3574 if (isa<ImplicitValueInitExpr>(Init)) 3575 return getDerived().RebuildParenListExpr(SourceLocation(), None, 3576 SourceLocation()); 3577 3578 // Revert initialization by constructor back to a parenthesized or braced list 3579 // of expressions. Any other form of initializer can just be reused directly. 3580 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) 3581 return getDerived().TransformExpr(Init); 3582 3583 // If the initialization implicitly converted an initializer list to a 3584 // std::initializer_list object, unwrap the std::initializer_list too. 3585 if (Construct && Construct->isStdInitListInitialization()) 3586 return TransformInitializer(Construct->getArg(0), NotCopyInit); 3587 3588 // Enter a list-init context if this was list initialization. 3589 EnterExpressionEvaluationContext Context( 3590 getSema(), EnterExpressionEvaluationContext::InitList, 3591 Construct->isListInitialization()); 3592 3593 SmallVector<Expr*, 8> NewArgs; 3594 bool ArgChanged = false; 3595 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), 3596 /*IsCall*/true, NewArgs, &ArgChanged)) 3597 return ExprError(); 3598 3599 // If this was list initialization, revert to syntactic list form. 3600 if (Construct->isListInitialization()) 3601 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs, 3602 Construct->getEndLoc()); 3603 3604 // Build a ParenListExpr to represent anything else. 3605 SourceRange Parens = Construct->getParenOrBraceRange(); 3606 if (Parens.isInvalid()) { 3607 // This was a variable declaration's initialization for which no initializer 3608 // was specified. 3609 assert(NewArgs.empty() && 3610 "no parens or braces but have direct init with arguments?"); 3611 return ExprEmpty(); 3612 } 3613 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, 3614 Parens.getEnd()); 3615 } 3616 3617 template<typename Derived> 3618 bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs, 3619 unsigned NumInputs, 3620 bool IsCall, 3621 SmallVectorImpl<Expr *> &Outputs, 3622 bool *ArgChanged) { 3623 for (unsigned I = 0; I != NumInputs; ++I) { 3624 // If requested, drop call arguments that need to be dropped. 3625 if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 3626 if (ArgChanged) 3627 *ArgChanged = true; 3628 3629 break; 3630 } 3631 3632 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 3633 Expr *Pattern = Expansion->getPattern(); 3634 3635 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3636 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 3637 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 3638 3639 // Determine whether the set of unexpanded parameter packs can and should 3640 // be expanded. 3641 bool Expand = true; 3642 bool RetainExpansion = false; 3643 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); 3644 Optional<unsigned> NumExpansions = OrigNumExpansions; 3645 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 3646 Pattern->getSourceRange(), 3647 Unexpanded, 3648 Expand, RetainExpansion, 3649 NumExpansions)) 3650 return true; 3651 3652 if (!Expand) { 3653 // The transform has determined that we should perform a simple 3654 // transformation on the pack expansion, producing another pack 3655 // expansion. 3656 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 3657 ExprResult OutPattern = getDerived().TransformExpr(Pattern); 3658 if (OutPattern.isInvalid()) 3659 return true; 3660 3661 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 3662 Expansion->getEllipsisLoc(), 3663 NumExpansions); 3664 if (Out.isInvalid()) 3665 return true; 3666 3667 if (ArgChanged) 3668 *ArgChanged = true; 3669 Outputs.push_back(Out.get()); 3670 continue; 3671 } 3672 3673 // Record right away that the argument was changed. This needs 3674 // to happen even if the array expands to nothing. 3675 if (ArgChanged) *ArgChanged = true; 3676 3677 // The transform has determined that we should perform an elementwise 3678 // expansion of the pattern. Do so. 3679 for (unsigned I = 0; I != *NumExpansions; ++I) { 3680 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 3681 ExprResult Out = getDerived().TransformExpr(Pattern); 3682 if (Out.isInvalid()) 3683 return true; 3684 3685 if (Out.get()->containsUnexpandedParameterPack()) { 3686 Out = getDerived().RebuildPackExpansion( 3687 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); 3688 if (Out.isInvalid()) 3689 return true; 3690 } 3691 3692 Outputs.push_back(Out.get()); 3693 } 3694 3695 // If we're supposed to retain a pack expansion, do so by temporarily 3696 // forgetting the partially-substituted parameter pack. 3697 if (RetainExpansion) { 3698 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 3699 3700 ExprResult Out = getDerived().TransformExpr(Pattern); 3701 if (Out.isInvalid()) 3702 return true; 3703 3704 Out = getDerived().RebuildPackExpansion( 3705 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); 3706 if (Out.isInvalid()) 3707 return true; 3708 3709 Outputs.push_back(Out.get()); 3710 } 3711 3712 continue; 3713 } 3714 3715 ExprResult Result = 3716 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) 3717 : getDerived().TransformExpr(Inputs[I]); 3718 if (Result.isInvalid()) 3719 return true; 3720 3721 if (Result.get() != Inputs[I] && ArgChanged) 3722 *ArgChanged = true; 3723 3724 Outputs.push_back(Result.get()); 3725 } 3726 3727 return false; 3728 } 3729 3730 template <typename Derived> 3731 Sema::ConditionResult TreeTransform<Derived>::TransformCondition( 3732 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) { 3733 if (Var) { 3734 VarDecl *ConditionVar = cast_or_null<VarDecl>( 3735 getDerived().TransformDefinition(Var->getLocation(), Var)); 3736 3737 if (!ConditionVar) 3738 return Sema::ConditionError(); 3739 3740 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind); 3741 } 3742 3743 if (Expr) { 3744 ExprResult CondExpr = getDerived().TransformExpr(Expr); 3745 3746 if (CondExpr.isInvalid()) 3747 return Sema::ConditionError(); 3748 3749 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind); 3750 } 3751 3752 return Sema::ConditionResult(); 3753 } 3754 3755 template<typename Derived> 3756 NestedNameSpecifierLoc 3757 TreeTransform<Derived>::TransformNestedNameSpecifierLoc( 3758 NestedNameSpecifierLoc NNS, 3759 QualType ObjectType, 3760 NamedDecl *FirstQualifierInScope) { 3761 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 3762 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 3763 Qualifier = Qualifier.getPrefix()) 3764 Qualifiers.push_back(Qualifier); 3765 3766 CXXScopeSpec SS; 3767 while (!Qualifiers.empty()) { 3768 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 3769 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 3770 3771 switch (QNNS->getKind()) { 3772 case NestedNameSpecifier::Identifier: { 3773 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(), 3774 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType); 3775 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false, 3776 SS, FirstQualifierInScope, false)) 3777 return NestedNameSpecifierLoc(); 3778 } 3779 break; 3780 3781 case NestedNameSpecifier::Namespace: { 3782 NamespaceDecl *NS 3783 = cast_or_null<NamespaceDecl>( 3784 getDerived().TransformDecl( 3785 Q.getLocalBeginLoc(), 3786 QNNS->getAsNamespace())); 3787 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 3788 break; 3789 } 3790 3791 case NestedNameSpecifier::NamespaceAlias: { 3792 NamespaceAliasDecl *Alias 3793 = cast_or_null<NamespaceAliasDecl>( 3794 getDerived().TransformDecl(Q.getLocalBeginLoc(), 3795 QNNS->getAsNamespaceAlias())); 3796 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 3797 Q.getLocalEndLoc()); 3798 break; 3799 } 3800 3801 case NestedNameSpecifier::Global: 3802 // There is no meaningful transformation that one could perform on the 3803 // global scope. 3804 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 3805 break; 3806 3807 case NestedNameSpecifier::Super: { 3808 CXXRecordDecl *RD = 3809 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 3810 SourceLocation(), QNNS->getAsRecordDecl())); 3811 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); 3812 break; 3813 } 3814 3815 case NestedNameSpecifier::TypeSpecWithTemplate: 3816 case NestedNameSpecifier::TypeSpec: { 3817 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 3818 FirstQualifierInScope, SS); 3819 3820 if (!TL) 3821 return NestedNameSpecifierLoc(); 3822 3823 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || 3824 (SemaRef.getLangOpts().CPlusPlus11 && 3825 TL.getType()->isEnumeralType())) { 3826 assert(!TL.getType().hasLocalQualifiers() && 3827 "Can't get cv-qualifiers here"); 3828 if (TL.getType()->isEnumeralType()) 3829 SemaRef.Diag(TL.getBeginLoc(), 3830 diag::warn_cxx98_compat_enum_nested_name_spec); 3831 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, 3832 Q.getLocalEndLoc()); 3833 break; 3834 } 3835 // If the nested-name-specifier is an invalid type def, don't emit an 3836 // error because a previous error should have already been emitted. 3837 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); 3838 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { 3839 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 3840 << TL.getType() << SS.getRange(); 3841 } 3842 return NestedNameSpecifierLoc(); 3843 } 3844 } 3845 3846 // The qualifier-in-scope and object type only apply to the leftmost entity. 3847 FirstQualifierInScope = nullptr; 3848 ObjectType = QualType(); 3849 } 3850 3851 // Don't rebuild the nested-name-specifier if we don't have to. 3852 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 3853 !getDerived().AlwaysRebuild()) 3854 return NNS; 3855 3856 // If we can re-use the source-location data from the original 3857 // nested-name-specifier, do so. 3858 if (SS.location_size() == NNS.getDataLength() && 3859 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 3860 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 3861 3862 // Allocate new nested-name-specifier location information. 3863 return SS.getWithLocInContext(SemaRef.Context); 3864 } 3865 3866 template<typename Derived> 3867 DeclarationNameInfo 3868 TreeTransform<Derived> 3869 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 3870 DeclarationName Name = NameInfo.getName(); 3871 if (!Name) 3872 return DeclarationNameInfo(); 3873 3874 switch (Name.getNameKind()) { 3875 case DeclarationName::Identifier: 3876 case DeclarationName::ObjCZeroArgSelector: 3877 case DeclarationName::ObjCOneArgSelector: 3878 case DeclarationName::ObjCMultiArgSelector: 3879 case DeclarationName::CXXOperatorName: 3880 case DeclarationName::CXXLiteralOperatorName: 3881 case DeclarationName::CXXUsingDirective: 3882 return NameInfo; 3883 3884 case DeclarationName::CXXDeductionGuideName: { 3885 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate(); 3886 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>( 3887 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate)); 3888 if (!NewTemplate) 3889 return DeclarationNameInfo(); 3890 3891 DeclarationNameInfo NewNameInfo(NameInfo); 3892 NewNameInfo.setName( 3893 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate)); 3894 return NewNameInfo; 3895 } 3896 3897 case DeclarationName::CXXConstructorName: 3898 case DeclarationName::CXXDestructorName: 3899 case DeclarationName::CXXConversionFunctionName: { 3900 TypeSourceInfo *NewTInfo; 3901 CanQualType NewCanTy; 3902 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 3903 NewTInfo = getDerived().TransformType(OldTInfo); 3904 if (!NewTInfo) 3905 return DeclarationNameInfo(); 3906 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 3907 } 3908 else { 3909 NewTInfo = nullptr; 3910 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 3911 QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 3912 if (NewT.isNull()) 3913 return DeclarationNameInfo(); 3914 NewCanTy = SemaRef.Context.getCanonicalType(NewT); 3915 } 3916 3917 DeclarationName NewName 3918 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 3919 NewCanTy); 3920 DeclarationNameInfo NewNameInfo(NameInfo); 3921 NewNameInfo.setName(NewName); 3922 NewNameInfo.setNamedTypeInfo(NewTInfo); 3923 return NewNameInfo; 3924 } 3925 } 3926 3927 llvm_unreachable("Unknown name kind."); 3928 } 3929 3930 template<typename Derived> 3931 TemplateName 3932 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, 3933 TemplateName Name, 3934 SourceLocation NameLoc, 3935 QualType ObjectType, 3936 NamedDecl *FirstQualifierInScope, 3937 bool AllowInjectedClassName) { 3938 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 3939 TemplateDecl *Template = QTN->getTemplateDecl(); 3940 assert(Template && "qualified template name must refer to a template"); 3941 3942 TemplateDecl *TransTemplate 3943 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 3944 Template)); 3945 if (!TransTemplate) 3946 return TemplateName(); 3947 3948 if (!getDerived().AlwaysRebuild() && 3949 SS.getScopeRep() == QTN->getQualifier() && 3950 TransTemplate == Template) 3951 return Name; 3952 3953 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), 3954 TransTemplate); 3955 } 3956 3957 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 3958 if (SS.getScopeRep()) { 3959 // These apply to the scope specifier, not the template. 3960 ObjectType = QualType(); 3961 FirstQualifierInScope = nullptr; 3962 } 3963 3964 if (!getDerived().AlwaysRebuild() && 3965 SS.getScopeRep() == DTN->getQualifier() && 3966 ObjectType.isNull()) 3967 return Name; 3968 3969 // FIXME: Preserve the location of the "template" keyword. 3970 SourceLocation TemplateKWLoc = NameLoc; 3971 3972 if (DTN->isIdentifier()) { 3973 return getDerived().RebuildTemplateName(SS, 3974 TemplateKWLoc, 3975 *DTN->getIdentifier(), 3976 NameLoc, 3977 ObjectType, 3978 FirstQualifierInScope, 3979 AllowInjectedClassName); 3980 } 3981 3982 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, 3983 DTN->getOperator(), NameLoc, 3984 ObjectType, AllowInjectedClassName); 3985 } 3986 3987 if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 3988 TemplateDecl *TransTemplate 3989 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 3990 Template)); 3991 if (!TransTemplate) 3992 return TemplateName(); 3993 3994 if (!getDerived().AlwaysRebuild() && 3995 TransTemplate == Template) 3996 return Name; 3997 3998 return TemplateName(TransTemplate); 3999 } 4000 4001 if (SubstTemplateTemplateParmPackStorage *SubstPack 4002 = Name.getAsSubstTemplateTemplateParmPack()) { 4003 TemplateTemplateParmDecl *TransParam 4004 = cast_or_null<TemplateTemplateParmDecl>( 4005 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); 4006 if (!TransParam) 4007 return TemplateName(); 4008 4009 if (!getDerived().AlwaysRebuild() && 4010 TransParam == SubstPack->getParameterPack()) 4011 return Name; 4012 4013 return getDerived().RebuildTemplateName(TransParam, 4014 SubstPack->getArgumentPack()); 4015 } 4016 4017 // These should be getting filtered out before they reach the AST. 4018 llvm_unreachable("overloaded function decl survived to here"); 4019 } 4020 4021 template<typename Derived> 4022 void TreeTransform<Derived>::InventTemplateArgumentLoc( 4023 const TemplateArgument &Arg, 4024 TemplateArgumentLoc &Output) { 4025 Output = getSema().getTrivialTemplateArgumentLoc( 4026 Arg, QualType(), getDerived().getBaseLocation()); 4027 } 4028 4029 template<typename Derived> 4030 bool TreeTransform<Derived>::TransformTemplateArgument( 4031 const TemplateArgumentLoc &Input, 4032 TemplateArgumentLoc &Output, bool Uneval) { 4033 const TemplateArgument &Arg = Input.getArgument(); 4034 switch (Arg.getKind()) { 4035 case TemplateArgument::Null: 4036 case TemplateArgument::Pack: 4037 llvm_unreachable("Unexpected TemplateArgument"); 4038 4039 case TemplateArgument::Integral: 4040 case TemplateArgument::NullPtr: 4041 case TemplateArgument::Declaration: { 4042 // Transform a resolved template argument straight to a resolved template 4043 // argument. We get here when substituting into an already-substituted 4044 // template type argument during concept satisfaction checking. 4045 QualType T = Arg.getNonTypeTemplateArgumentType(); 4046 QualType NewT = getDerived().TransformType(T); 4047 if (NewT.isNull()) 4048 return true; 4049 4050 ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration 4051 ? Arg.getAsDecl() 4052 : nullptr; 4053 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl( 4054 getDerived().getBaseLocation(), D)) 4055 : nullptr; 4056 if (D && !NewD) 4057 return true; 4058 4059 if (NewT == T && D == NewD) 4060 Output = Input; 4061 else if (Arg.getKind() == TemplateArgument::Integral) 4062 Output = TemplateArgumentLoc( 4063 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT), 4064 TemplateArgumentLocInfo()); 4065 else if (Arg.getKind() == TemplateArgument::NullPtr) 4066 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true), 4067 TemplateArgumentLocInfo()); 4068 else 4069 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT), 4070 TemplateArgumentLocInfo()); 4071 4072 return false; 4073 } 4074 4075 case TemplateArgument::Type: { 4076 TypeSourceInfo *DI = Input.getTypeSourceInfo(); 4077 if (!DI) 4078 DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 4079 4080 DI = getDerived().TransformType(DI); 4081 if (!DI) return true; 4082 4083 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 4084 return false; 4085 } 4086 4087 case TemplateArgument::Template: { 4088 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); 4089 if (QualifierLoc) { 4090 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); 4091 if (!QualifierLoc) 4092 return true; 4093 } 4094 4095 CXXScopeSpec SS; 4096 SS.Adopt(QualifierLoc); 4097 TemplateName Template 4098 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), 4099 Input.getTemplateNameLoc()); 4100 if (Template.isNull()) 4101 return true; 4102 4103 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, 4104 Input.getTemplateNameLoc()); 4105 return false; 4106 } 4107 4108 case TemplateArgument::TemplateExpansion: 4109 llvm_unreachable("Caller should expand pack expansions"); 4110 4111 case TemplateArgument::Expression: { 4112 // Template argument expressions are constant expressions. 4113 EnterExpressionEvaluationContext Unevaluated( 4114 getSema(), 4115 Uneval ? Sema::ExpressionEvaluationContext::Unevaluated 4116 : Sema::ExpressionEvaluationContext::ConstantEvaluated, 4117 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/ 4118 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); 4119 4120 Expr *InputExpr = Input.getSourceExpression(); 4121 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 4122 4123 ExprResult E = getDerived().TransformExpr(InputExpr); 4124 E = SemaRef.ActOnConstantExpression(E); 4125 if (E.isInvalid()) return true; 4126 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); 4127 return false; 4128 } 4129 } 4130 4131 // Work around bogus GCC warning 4132 return true; 4133 } 4134 4135 /// Iterator adaptor that invents template argument location information 4136 /// for each of the template arguments in its underlying iterator. 4137 template<typename Derived, typename InputIterator> 4138 class TemplateArgumentLocInventIterator { 4139 TreeTransform<Derived> &Self; 4140 InputIterator Iter; 4141 4142 public: 4143 typedef TemplateArgumentLoc value_type; 4144 typedef TemplateArgumentLoc reference; 4145 typedef typename std::iterator_traits<InputIterator>::difference_type 4146 difference_type; 4147 typedef std::input_iterator_tag iterator_category; 4148 4149 class pointer { 4150 TemplateArgumentLoc Arg; 4151 4152 public: 4153 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 4154 4155 const TemplateArgumentLoc *operator->() const { return &Arg; } 4156 }; 4157 4158 TemplateArgumentLocInventIterator() { } 4159 4160 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 4161 InputIterator Iter) 4162 : Self(Self), Iter(Iter) { } 4163 4164 TemplateArgumentLocInventIterator &operator++() { 4165 ++Iter; 4166 return *this; 4167 } 4168 4169 TemplateArgumentLocInventIterator operator++(int) { 4170 TemplateArgumentLocInventIterator Old(*this); 4171 ++(*this); 4172 return Old; 4173 } 4174 4175 reference operator*() const { 4176 TemplateArgumentLoc Result; 4177 Self.InventTemplateArgumentLoc(*Iter, Result); 4178 return Result; 4179 } 4180 4181 pointer operator->() const { return pointer(**this); } 4182 4183 friend bool operator==(const TemplateArgumentLocInventIterator &X, 4184 const TemplateArgumentLocInventIterator &Y) { 4185 return X.Iter == Y.Iter; 4186 } 4187 4188 friend bool operator!=(const TemplateArgumentLocInventIterator &X, 4189 const TemplateArgumentLocInventIterator &Y) { 4190 return X.Iter != Y.Iter; 4191 } 4192 }; 4193 4194 template<typename Derived> 4195 template<typename InputIterator> 4196 bool TreeTransform<Derived>::TransformTemplateArguments( 4197 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, 4198 bool Uneval) { 4199 for (; First != Last; ++First) { 4200 TemplateArgumentLoc Out; 4201 TemplateArgumentLoc In = *First; 4202 4203 if (In.getArgument().getKind() == TemplateArgument::Pack) { 4204 // Unpack argument packs, which we translate them into separate 4205 // arguments. 4206 // FIXME: We could do much better if we could guarantee that the 4207 // TemplateArgumentLocInfo for the pack expansion would be usable for 4208 // all of the template arguments in the argument pack. 4209 typedef TemplateArgumentLocInventIterator<Derived, 4210 TemplateArgument::pack_iterator> 4211 PackLocIterator; 4212 if (TransformTemplateArguments(PackLocIterator(*this, 4213 In.getArgument().pack_begin()), 4214 PackLocIterator(*this, 4215 In.getArgument().pack_end()), 4216 Outputs, Uneval)) 4217 return true; 4218 4219 continue; 4220 } 4221 4222 if (In.getArgument().isPackExpansion()) { 4223 // We have a pack expansion, for which we will be substituting into 4224 // the pattern. 4225 SourceLocation Ellipsis; 4226 Optional<unsigned> OrigNumExpansions; 4227 TemplateArgumentLoc Pattern 4228 = getSema().getTemplateArgumentPackExpansionPattern( 4229 In, Ellipsis, OrigNumExpansions); 4230 4231 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 4232 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 4233 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 4234 4235 // Determine whether the set of unexpanded parameter packs can and should 4236 // be expanded. 4237 bool Expand = true; 4238 bool RetainExpansion = false; 4239 Optional<unsigned> NumExpansions = OrigNumExpansions; 4240 if (getDerived().TryExpandParameterPacks(Ellipsis, 4241 Pattern.getSourceRange(), 4242 Unexpanded, 4243 Expand, 4244 RetainExpansion, 4245 NumExpansions)) 4246 return true; 4247 4248 if (!Expand) { 4249 // The transform has determined that we should perform a simple 4250 // transformation on the pack expansion, producing another pack 4251 // expansion. 4252 TemplateArgumentLoc OutPattern; 4253 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4254 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) 4255 return true; 4256 4257 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 4258 NumExpansions); 4259 if (Out.getArgument().isNull()) 4260 return true; 4261 4262 Outputs.addArgument(Out); 4263 continue; 4264 } 4265 4266 // The transform has determined that we should perform an elementwise 4267 // expansion of the pattern. Do so. 4268 for (unsigned I = 0; I != *NumExpansions; ++I) { 4269 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4270 4271 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) 4272 return true; 4273 4274 if (Out.getArgument().containsUnexpandedParameterPack()) { 4275 Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 4276 OrigNumExpansions); 4277 if (Out.getArgument().isNull()) 4278 return true; 4279 } 4280 4281 Outputs.addArgument(Out); 4282 } 4283 4284 // If we're supposed to retain a pack expansion, do so by temporarily 4285 // forgetting the partially-substituted parameter pack. 4286 if (RetainExpansion) { 4287 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 4288 4289 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) 4290 return true; 4291 4292 Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 4293 OrigNumExpansions); 4294 if (Out.getArgument().isNull()) 4295 return true; 4296 4297 Outputs.addArgument(Out); 4298 } 4299 4300 continue; 4301 } 4302 4303 // The simple case: 4304 if (getDerived().TransformTemplateArgument(In, Out, Uneval)) 4305 return true; 4306 4307 Outputs.addArgument(Out); 4308 } 4309 4310 return false; 4311 4312 } 4313 4314 //===----------------------------------------------------------------------===// 4315 // Type transformation 4316 //===----------------------------------------------------------------------===// 4317 4318 template<typename Derived> 4319 QualType TreeTransform<Derived>::TransformType(QualType T) { 4320 if (getDerived().AlreadyTransformed(T)) 4321 return T; 4322 4323 // Temporary workaround. All of these transformations should 4324 // eventually turn into transformations on TypeLocs. 4325 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 4326 getDerived().getBaseLocation()); 4327 4328 TypeSourceInfo *NewDI = getDerived().TransformType(DI); 4329 4330 if (!NewDI) 4331 return QualType(); 4332 4333 return NewDI->getType(); 4334 } 4335 4336 template<typename Derived> 4337 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 4338 // Refine the base location to the type's location. 4339 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), 4340 getDerived().getBaseEntity()); 4341 if (getDerived().AlreadyTransformed(DI->getType())) 4342 return DI; 4343 4344 TypeLocBuilder TLB; 4345 4346 TypeLoc TL = DI->getTypeLoc(); 4347 TLB.reserve(TL.getFullDataSize()); 4348 4349 QualType Result = getDerived().TransformType(TLB, TL); 4350 if (Result.isNull()) 4351 return nullptr; 4352 4353 return TLB.getTypeSourceInfo(SemaRef.Context, Result); 4354 } 4355 4356 template<typename Derived> 4357 QualType 4358 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 4359 switch (T.getTypeLocClass()) { 4360 #define ABSTRACT_TYPELOC(CLASS, PARENT) 4361 #define TYPELOC(CLASS, PARENT) \ 4362 case TypeLoc::CLASS: \ 4363 return getDerived().Transform##CLASS##Type(TLB, \ 4364 T.castAs<CLASS##TypeLoc>()); 4365 #include "clang/AST/TypeLocNodes.def" 4366 } 4367 4368 llvm_unreachable("unhandled type loc!"); 4369 } 4370 4371 template<typename Derived> 4372 QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) { 4373 if (!isa<DependentNameType>(T)) 4374 return TransformType(T); 4375 4376 if (getDerived().AlreadyTransformed(T)) 4377 return T; 4378 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 4379 getDerived().getBaseLocation()); 4380 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI); 4381 return NewDI ? NewDI->getType() : QualType(); 4382 } 4383 4384 template<typename Derived> 4385 TypeSourceInfo * 4386 TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) { 4387 if (!isa<DependentNameType>(DI->getType())) 4388 return TransformType(DI); 4389 4390 // Refine the base location to the type's location. 4391 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), 4392 getDerived().getBaseEntity()); 4393 if (getDerived().AlreadyTransformed(DI->getType())) 4394 return DI; 4395 4396 TypeLocBuilder TLB; 4397 4398 TypeLoc TL = DI->getTypeLoc(); 4399 TLB.reserve(TL.getFullDataSize()); 4400 4401 auto QTL = TL.getAs<QualifiedTypeLoc>(); 4402 if (QTL) 4403 TL = QTL.getUnqualifiedLoc(); 4404 4405 auto DNTL = TL.castAs<DependentNameTypeLoc>(); 4406 4407 QualType Result = getDerived().TransformDependentNameType( 4408 TLB, DNTL, /*DeducedTSTContext*/true); 4409 if (Result.isNull()) 4410 return nullptr; 4411 4412 if (QTL) { 4413 Result = getDerived().RebuildQualifiedType(Result, QTL); 4414 if (Result.isNull()) 4415 return nullptr; 4416 TLB.TypeWasModifiedSafely(Result); 4417 } 4418 4419 return TLB.getTypeSourceInfo(SemaRef.Context, Result); 4420 } 4421 4422 template<typename Derived> 4423 QualType 4424 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 4425 QualifiedTypeLoc T) { 4426 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 4427 if (Result.isNull()) 4428 return QualType(); 4429 4430 Result = getDerived().RebuildQualifiedType(Result, T); 4431 4432 if (Result.isNull()) 4433 return QualType(); 4434 4435 // RebuildQualifiedType might have updated the type, but not in a way 4436 // that invalidates the TypeLoc. (There's no location information for 4437 // qualifiers.) 4438 TLB.TypeWasModifiedSafely(Result); 4439 4440 return Result; 4441 } 4442 4443 template <typename Derived> 4444 QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T, 4445 QualifiedTypeLoc TL) { 4446 4447 SourceLocation Loc = TL.getBeginLoc(); 4448 Qualifiers Quals = TL.getType().getLocalQualifiers(); 4449 4450 if (((T.getAddressSpace() != LangAS::Default && 4451 Quals.getAddressSpace() != LangAS::Default)) && 4452 T.getAddressSpace() != Quals.getAddressSpace()) { 4453 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst) 4454 << TL.getType() << T; 4455 return QualType(); 4456 } 4457 4458 // C++ [dcl.fct]p7: 4459 // [When] adding cv-qualifications on top of the function type [...] the 4460 // cv-qualifiers are ignored. 4461 if (T->isFunctionType()) { 4462 T = SemaRef.getASTContext().getAddrSpaceQualType(T, 4463 Quals.getAddressSpace()); 4464 return T; 4465 } 4466 4467 // C++ [dcl.ref]p1: 4468 // when the cv-qualifiers are introduced through the use of a typedef-name 4469 // or decltype-specifier [...] the cv-qualifiers are ignored. 4470 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be 4471 // applied to a reference type. 4472 if (T->isReferenceType()) { 4473 // The only qualifier that applies to a reference type is restrict. 4474 if (!Quals.hasRestrict()) 4475 return T; 4476 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); 4477 } 4478 4479 // Suppress Objective-C lifetime qualifiers if they don't make sense for the 4480 // resulting type. 4481 if (Quals.hasObjCLifetime()) { 4482 if (!T->isObjCLifetimeType() && !T->isDependentType()) 4483 Quals.removeObjCLifetime(); 4484 else if (T.getObjCLifetime()) { 4485 // Objective-C ARC: 4486 // A lifetime qualifier applied to a substituted template parameter 4487 // overrides the lifetime qualifier from the template argument. 4488 const AutoType *AutoTy; 4489 if (const SubstTemplateTypeParmType *SubstTypeParam 4490 = dyn_cast<SubstTemplateTypeParmType>(T)) { 4491 QualType Replacement = SubstTypeParam->getReplacementType(); 4492 Qualifiers Qs = Replacement.getQualifiers(); 4493 Qs.removeObjCLifetime(); 4494 Replacement = SemaRef.Context.getQualifiedType( 4495 Replacement.getUnqualifiedType(), Qs); 4496 T = SemaRef.Context.getSubstTemplateTypeParmType( 4497 SubstTypeParam->getReplacedParameter(), Replacement); 4498 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) { 4499 // 'auto' types behave the same way as template parameters. 4500 QualType Deduced = AutoTy->getDeducedType(); 4501 Qualifiers Qs = Deduced.getQualifiers(); 4502 Qs.removeObjCLifetime(); 4503 Deduced = 4504 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs); 4505 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(), 4506 AutoTy->isDependentType(), 4507 /*isPack=*/false, 4508 AutoTy->getTypeConstraintConcept(), 4509 AutoTy->getTypeConstraintArguments()); 4510 } else { 4511 // Otherwise, complain about the addition of a qualifier to an 4512 // already-qualified type. 4513 // FIXME: Why is this check not in Sema::BuildQualifiedType? 4514 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T; 4515 Quals.removeObjCLifetime(); 4516 } 4517 } 4518 } 4519 4520 return SemaRef.BuildQualifiedType(T, Loc, Quals); 4521 } 4522 4523 template<typename Derived> 4524 TypeLoc 4525 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 4526 QualType ObjectType, 4527 NamedDecl *UnqualLookup, 4528 CXXScopeSpec &SS) { 4529 if (getDerived().AlreadyTransformed(TL.getType())) 4530 return TL; 4531 4532 TypeSourceInfo *TSI = 4533 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); 4534 if (TSI) 4535 return TSI->getTypeLoc(); 4536 return TypeLoc(); 4537 } 4538 4539 template<typename Derived> 4540 TypeSourceInfo * 4541 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 4542 QualType ObjectType, 4543 NamedDecl *UnqualLookup, 4544 CXXScopeSpec &SS) { 4545 if (getDerived().AlreadyTransformed(TSInfo->getType())) 4546 return TSInfo; 4547 4548 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, 4549 UnqualLookup, SS); 4550 } 4551 4552 template <typename Derived> 4553 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( 4554 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, 4555 CXXScopeSpec &SS) { 4556 QualType T = TL.getType(); 4557 assert(!getDerived().AlreadyTransformed(T)); 4558 4559 TypeLocBuilder TLB; 4560 QualType Result; 4561 4562 if (isa<TemplateSpecializationType>(T)) { 4563 TemplateSpecializationTypeLoc SpecTL = 4564 TL.castAs<TemplateSpecializationTypeLoc>(); 4565 4566 TemplateName Template = getDerived().TransformTemplateName( 4567 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(), 4568 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true); 4569 if (Template.isNull()) 4570 return nullptr; 4571 4572 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 4573 Template); 4574 } else if (isa<DependentTemplateSpecializationType>(T)) { 4575 DependentTemplateSpecializationTypeLoc SpecTL = 4576 TL.castAs<DependentTemplateSpecializationTypeLoc>(); 4577 4578 TemplateName Template 4579 = getDerived().RebuildTemplateName(SS, 4580 SpecTL.getTemplateKeywordLoc(), 4581 *SpecTL.getTypePtr()->getIdentifier(), 4582 SpecTL.getTemplateNameLoc(), 4583 ObjectType, UnqualLookup, 4584 /*AllowInjectedClassName*/true); 4585 if (Template.isNull()) 4586 return nullptr; 4587 4588 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 4589 SpecTL, 4590 Template, 4591 SS); 4592 } else { 4593 // Nothing special needs to be done for these. 4594 Result = getDerived().TransformType(TLB, TL); 4595 } 4596 4597 if (Result.isNull()) 4598 return nullptr; 4599 4600 return TLB.getTypeSourceInfo(SemaRef.Context, Result); 4601 } 4602 4603 template <class TyLoc> static inline 4604 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 4605 TyLoc NewT = TLB.push<TyLoc>(T.getType()); 4606 NewT.setNameLoc(T.getNameLoc()); 4607 return T.getType(); 4608 } 4609 4610 template<typename Derived> 4611 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 4612 BuiltinTypeLoc T) { 4613 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 4614 NewT.setBuiltinLoc(T.getBuiltinLoc()); 4615 if (T.needsExtraLocalData()) 4616 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 4617 return T.getType(); 4618 } 4619 4620 template<typename Derived> 4621 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 4622 ComplexTypeLoc T) { 4623 // FIXME: recurse? 4624 return TransformTypeSpecType(TLB, T); 4625 } 4626 4627 template <typename Derived> 4628 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, 4629 AdjustedTypeLoc TL) { 4630 // Adjustments applied during transformation are handled elsewhere. 4631 return getDerived().TransformType(TLB, TL.getOriginalLoc()); 4632 } 4633 4634 template<typename Derived> 4635 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, 4636 DecayedTypeLoc TL) { 4637 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); 4638 if (OriginalType.isNull()) 4639 return QualType(); 4640 4641 QualType Result = TL.getType(); 4642 if (getDerived().AlwaysRebuild() || 4643 OriginalType != TL.getOriginalLoc().getType()) 4644 Result = SemaRef.Context.getDecayedType(OriginalType); 4645 TLB.push<DecayedTypeLoc>(Result); 4646 // Nothing to set for DecayedTypeLoc. 4647 return Result; 4648 } 4649 4650 template<typename Derived> 4651 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 4652 PointerTypeLoc TL) { 4653 QualType PointeeType 4654 = getDerived().TransformType(TLB, TL.getPointeeLoc()); 4655 if (PointeeType.isNull()) 4656 return QualType(); 4657 4658 QualType Result = TL.getType(); 4659 if (PointeeType->getAs<ObjCObjectType>()) { 4660 // A dependent pointer type 'T *' has is being transformed such 4661 // that an Objective-C class type is being replaced for 'T'. The 4662 // resulting pointer type is an ObjCObjectPointerType, not a 4663 // PointerType. 4664 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 4665 4666 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 4667 NewT.setStarLoc(TL.getStarLoc()); 4668 return Result; 4669 } 4670 4671 if (getDerived().AlwaysRebuild() || 4672 PointeeType != TL.getPointeeLoc().getType()) { 4673 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 4674 if (Result.isNull()) 4675 return QualType(); 4676 } 4677 4678 // Objective-C ARC can add lifetime qualifiers to the type that we're 4679 // pointing to. 4680 TLB.TypeWasModifiedSafely(Result->getPointeeType()); 4681 4682 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 4683 NewT.setSigilLoc(TL.getSigilLoc()); 4684 return Result; 4685 } 4686 4687 template<typename Derived> 4688 QualType 4689 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 4690 BlockPointerTypeLoc TL) { 4691 QualType PointeeType 4692 = getDerived().TransformType(TLB, TL.getPointeeLoc()); 4693 if (PointeeType.isNull()) 4694 return QualType(); 4695 4696 QualType Result = TL.getType(); 4697 if (getDerived().AlwaysRebuild() || 4698 PointeeType != TL.getPointeeLoc().getType()) { 4699 Result = getDerived().RebuildBlockPointerType(PointeeType, 4700 TL.getSigilLoc()); 4701 if (Result.isNull()) 4702 return QualType(); 4703 } 4704 4705 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 4706 NewT.setSigilLoc(TL.getSigilLoc()); 4707 return Result; 4708 } 4709 4710 /// Transforms a reference type. Note that somewhat paradoxically we 4711 /// don't care whether the type itself is an l-value type or an r-value 4712 /// type; we only care if the type was *written* as an l-value type 4713 /// or an r-value type. 4714 template<typename Derived> 4715 QualType 4716 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 4717 ReferenceTypeLoc TL) { 4718 const ReferenceType *T = TL.getTypePtr(); 4719 4720 // Note that this works with the pointee-as-written. 4721 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 4722 if (PointeeType.isNull()) 4723 return QualType(); 4724 4725 QualType Result = TL.getType(); 4726 if (getDerived().AlwaysRebuild() || 4727 PointeeType != T->getPointeeTypeAsWritten()) { 4728 Result = getDerived().RebuildReferenceType(PointeeType, 4729 T->isSpelledAsLValue(), 4730 TL.getSigilLoc()); 4731 if (Result.isNull()) 4732 return QualType(); 4733 } 4734 4735 // Objective-C ARC can add lifetime qualifiers to the type that we're 4736 // referring to. 4737 TLB.TypeWasModifiedSafely( 4738 Result->castAs<ReferenceType>()->getPointeeTypeAsWritten()); 4739 4740 // r-value references can be rebuilt as l-value references. 4741 ReferenceTypeLoc NewTL; 4742 if (isa<LValueReferenceType>(Result)) 4743 NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 4744 else 4745 NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 4746 NewTL.setSigilLoc(TL.getSigilLoc()); 4747 4748 return Result; 4749 } 4750 4751 template<typename Derived> 4752 QualType 4753 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 4754 LValueReferenceTypeLoc TL) { 4755 return TransformReferenceType(TLB, TL); 4756 } 4757 4758 template<typename Derived> 4759 QualType 4760 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 4761 RValueReferenceTypeLoc TL) { 4762 return TransformReferenceType(TLB, TL); 4763 } 4764 4765 template<typename Derived> 4766 QualType 4767 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 4768 MemberPointerTypeLoc TL) { 4769 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 4770 if (PointeeType.isNull()) 4771 return QualType(); 4772 4773 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); 4774 TypeSourceInfo *NewClsTInfo = nullptr; 4775 if (OldClsTInfo) { 4776 NewClsTInfo = getDerived().TransformType(OldClsTInfo); 4777 if (!NewClsTInfo) 4778 return QualType(); 4779 } 4780 4781 const MemberPointerType *T = TL.getTypePtr(); 4782 QualType OldClsType = QualType(T->getClass(), 0); 4783 QualType NewClsType; 4784 if (NewClsTInfo) 4785 NewClsType = NewClsTInfo->getType(); 4786 else { 4787 NewClsType = getDerived().TransformType(OldClsType); 4788 if (NewClsType.isNull()) 4789 return QualType(); 4790 } 4791 4792 QualType Result = TL.getType(); 4793 if (getDerived().AlwaysRebuild() || 4794 PointeeType != T->getPointeeType() || 4795 NewClsType != OldClsType) { 4796 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, 4797 TL.getStarLoc()); 4798 if (Result.isNull()) 4799 return QualType(); 4800 } 4801 4802 // If we had to adjust the pointee type when building a member pointer, make 4803 // sure to push TypeLoc info for it. 4804 const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); 4805 if (MPT && PointeeType != MPT->getPointeeType()) { 4806 assert(isa<AdjustedType>(MPT->getPointeeType())); 4807 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); 4808 } 4809 4810 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 4811 NewTL.setSigilLoc(TL.getSigilLoc()); 4812 NewTL.setClassTInfo(NewClsTInfo); 4813 4814 return Result; 4815 } 4816 4817 template<typename Derived> 4818 QualType 4819 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 4820 ConstantArrayTypeLoc TL) { 4821 const ConstantArrayType *T = TL.getTypePtr(); 4822 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 4823 if (ElementType.isNull()) 4824 return QualType(); 4825 4826 // Prefer the expression from the TypeLoc; the other may have been uniqued. 4827 Expr *OldSize = TL.getSizeExpr(); 4828 if (!OldSize) 4829 OldSize = const_cast<Expr*>(T->getSizeExpr()); 4830 Expr *NewSize = nullptr; 4831 if (OldSize) { 4832 EnterExpressionEvaluationContext Unevaluated( 4833 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 4834 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>(); 4835 NewSize = SemaRef.ActOnConstantExpression(NewSize).get(); 4836 } 4837 4838 QualType Result = TL.getType(); 4839 if (getDerived().AlwaysRebuild() || 4840 ElementType != T->getElementType() || 4841 (T->getSizeExpr() && NewSize != OldSize)) { 4842 Result = getDerived().RebuildConstantArrayType(ElementType, 4843 T->getSizeModifier(), 4844 T->getSize(), NewSize, 4845 T->getIndexTypeCVRQualifiers(), 4846 TL.getBracketsRange()); 4847 if (Result.isNull()) 4848 return QualType(); 4849 } 4850 4851 // We might have either a ConstantArrayType or a VariableArrayType now: 4852 // a ConstantArrayType is allowed to have an element type which is a 4853 // VariableArrayType if the type is dependent. Fortunately, all array 4854 // types have the same location layout. 4855 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 4856 NewTL.setLBracketLoc(TL.getLBracketLoc()); 4857 NewTL.setRBracketLoc(TL.getRBracketLoc()); 4858 NewTL.setSizeExpr(NewSize); 4859 4860 return Result; 4861 } 4862 4863 template<typename Derived> 4864 QualType TreeTransform<Derived>::TransformIncompleteArrayType( 4865 TypeLocBuilder &TLB, 4866 IncompleteArrayTypeLoc TL) { 4867 const IncompleteArrayType *T = TL.getTypePtr(); 4868 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 4869 if (ElementType.isNull()) 4870 return QualType(); 4871 4872 QualType Result = TL.getType(); 4873 if (getDerived().AlwaysRebuild() || 4874 ElementType != T->getElementType()) { 4875 Result = getDerived().RebuildIncompleteArrayType(ElementType, 4876 T->getSizeModifier(), 4877 T->getIndexTypeCVRQualifiers(), 4878 TL.getBracketsRange()); 4879 if (Result.isNull()) 4880 return QualType(); 4881 } 4882 4883 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 4884 NewTL.setLBracketLoc(TL.getLBracketLoc()); 4885 NewTL.setRBracketLoc(TL.getRBracketLoc()); 4886 NewTL.setSizeExpr(nullptr); 4887 4888 return Result; 4889 } 4890 4891 template<typename Derived> 4892 QualType 4893 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 4894 VariableArrayTypeLoc TL) { 4895 const VariableArrayType *T = TL.getTypePtr(); 4896 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 4897 if (ElementType.isNull()) 4898 return QualType(); 4899 4900 ExprResult SizeResult; 4901 { 4902 EnterExpressionEvaluationContext Context( 4903 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); 4904 SizeResult = getDerived().TransformExpr(T->getSizeExpr()); 4905 } 4906 if (SizeResult.isInvalid()) 4907 return QualType(); 4908 SizeResult = 4909 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false); 4910 if (SizeResult.isInvalid()) 4911 return QualType(); 4912 4913 Expr *Size = SizeResult.get(); 4914 4915 QualType Result = TL.getType(); 4916 if (getDerived().AlwaysRebuild() || 4917 ElementType != T->getElementType() || 4918 Size != T->getSizeExpr()) { 4919 Result = getDerived().RebuildVariableArrayType(ElementType, 4920 T->getSizeModifier(), 4921 Size, 4922 T->getIndexTypeCVRQualifiers(), 4923 TL.getBracketsRange()); 4924 if (Result.isNull()) 4925 return QualType(); 4926 } 4927 4928 // We might have constant size array now, but fortunately it has the same 4929 // location layout. 4930 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 4931 NewTL.setLBracketLoc(TL.getLBracketLoc()); 4932 NewTL.setRBracketLoc(TL.getRBracketLoc()); 4933 NewTL.setSizeExpr(Size); 4934 4935 return Result; 4936 } 4937 4938 template<typename Derived> 4939 QualType 4940 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 4941 DependentSizedArrayTypeLoc TL) { 4942 const DependentSizedArrayType *T = TL.getTypePtr(); 4943 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 4944 if (ElementType.isNull()) 4945 return QualType(); 4946 4947 // Array bounds are constant expressions. 4948 EnterExpressionEvaluationContext Unevaluated( 4949 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 4950 4951 // Prefer the expression from the TypeLoc; the other may have been uniqued. 4952 Expr *origSize = TL.getSizeExpr(); 4953 if (!origSize) origSize = T->getSizeExpr(); 4954 4955 ExprResult sizeResult 4956 = getDerived().TransformExpr(origSize); 4957 sizeResult = SemaRef.ActOnConstantExpression(sizeResult); 4958 if (sizeResult.isInvalid()) 4959 return QualType(); 4960 4961 Expr *size = sizeResult.get(); 4962 4963 QualType Result = TL.getType(); 4964 if (getDerived().AlwaysRebuild() || 4965 ElementType != T->getElementType() || 4966 size != origSize) { 4967 Result = getDerived().RebuildDependentSizedArrayType(ElementType, 4968 T->getSizeModifier(), 4969 size, 4970 T->getIndexTypeCVRQualifiers(), 4971 TL.getBracketsRange()); 4972 if (Result.isNull()) 4973 return QualType(); 4974 } 4975 4976 // We might have any sort of array type now, but fortunately they 4977 // all have the same location layout. 4978 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 4979 NewTL.setLBracketLoc(TL.getLBracketLoc()); 4980 NewTL.setRBracketLoc(TL.getRBracketLoc()); 4981 NewTL.setSizeExpr(size); 4982 4983 return Result; 4984 } 4985 4986 template <typename Derived> 4987 QualType TreeTransform<Derived>::TransformDependentVectorType( 4988 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) { 4989 const DependentVectorType *T = TL.getTypePtr(); 4990 QualType ElementType = getDerived().TransformType(T->getElementType()); 4991 if (ElementType.isNull()) 4992 return QualType(); 4993 4994 EnterExpressionEvaluationContext Unevaluated( 4995 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 4996 4997 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 4998 Size = SemaRef.ActOnConstantExpression(Size); 4999 if (Size.isInvalid()) 5000 return QualType(); 5001 5002 QualType Result = TL.getType(); 5003 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || 5004 Size.get() != T->getSizeExpr()) { 5005 Result = getDerived().RebuildDependentVectorType( 5006 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind()); 5007 if (Result.isNull()) 5008 return QualType(); 5009 } 5010 5011 // Result might be dependent or not. 5012 if (isa<DependentVectorType>(Result)) { 5013 DependentVectorTypeLoc NewTL = 5014 TLB.push<DependentVectorTypeLoc>(Result); 5015 NewTL.setNameLoc(TL.getNameLoc()); 5016 } else { 5017 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 5018 NewTL.setNameLoc(TL.getNameLoc()); 5019 } 5020 5021 return Result; 5022 } 5023 5024 template<typename Derived> 5025 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 5026 TypeLocBuilder &TLB, 5027 DependentSizedExtVectorTypeLoc TL) { 5028 const DependentSizedExtVectorType *T = TL.getTypePtr(); 5029 5030 // FIXME: ext vector locs should be nested 5031 QualType ElementType = getDerived().TransformType(T->getElementType()); 5032 if (ElementType.isNull()) 5033 return QualType(); 5034 5035 // Vector sizes are constant expressions. 5036 EnterExpressionEvaluationContext Unevaluated( 5037 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 5038 5039 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 5040 Size = SemaRef.ActOnConstantExpression(Size); 5041 if (Size.isInvalid()) 5042 return QualType(); 5043 5044 QualType Result = TL.getType(); 5045 if (getDerived().AlwaysRebuild() || 5046 ElementType != T->getElementType() || 5047 Size.get() != T->getSizeExpr()) { 5048 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 5049 Size.get(), 5050 T->getAttributeLoc()); 5051 if (Result.isNull()) 5052 return QualType(); 5053 } 5054 5055 // Result might be dependent or not. 5056 if (isa<DependentSizedExtVectorType>(Result)) { 5057 DependentSizedExtVectorTypeLoc NewTL 5058 = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 5059 NewTL.setNameLoc(TL.getNameLoc()); 5060 } else { 5061 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 5062 NewTL.setNameLoc(TL.getNameLoc()); 5063 } 5064 5065 return Result; 5066 } 5067 5068 template <typename Derived> 5069 QualType TreeTransform<Derived>::TransformDependentAddressSpaceType( 5070 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) { 5071 const DependentAddressSpaceType *T = TL.getTypePtr(); 5072 5073 QualType pointeeType = getDerived().TransformType(T->getPointeeType()); 5074 5075 if (pointeeType.isNull()) 5076 return QualType(); 5077 5078 // Address spaces are constant expressions. 5079 EnterExpressionEvaluationContext Unevaluated( 5080 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 5081 5082 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr()); 5083 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace); 5084 if (AddrSpace.isInvalid()) 5085 return QualType(); 5086 5087 QualType Result = TL.getType(); 5088 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() || 5089 AddrSpace.get() != T->getAddrSpaceExpr()) { 5090 Result = getDerived().RebuildDependentAddressSpaceType( 5091 pointeeType, AddrSpace.get(), T->getAttributeLoc()); 5092 if (Result.isNull()) 5093 return QualType(); 5094 } 5095 5096 // Result might be dependent or not. 5097 if (isa<DependentAddressSpaceType>(Result)) { 5098 DependentAddressSpaceTypeLoc NewTL = 5099 TLB.push<DependentAddressSpaceTypeLoc>(Result); 5100 5101 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 5102 NewTL.setAttrExprOperand(TL.getAttrExprOperand()); 5103 NewTL.setAttrNameLoc(TL.getAttrNameLoc()); 5104 5105 } else { 5106 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo( 5107 Result, getDerived().getBaseLocation()); 5108 TransformType(TLB, DI->getTypeLoc()); 5109 } 5110 5111 return Result; 5112 } 5113 5114 template <typename Derived> 5115 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 5116 VectorTypeLoc TL) { 5117 const VectorType *T = TL.getTypePtr(); 5118 QualType ElementType = getDerived().TransformType(T->getElementType()); 5119 if (ElementType.isNull()) 5120 return QualType(); 5121 5122 QualType Result = TL.getType(); 5123 if (getDerived().AlwaysRebuild() || 5124 ElementType != T->getElementType()) { 5125 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 5126 T->getVectorKind()); 5127 if (Result.isNull()) 5128 return QualType(); 5129 } 5130 5131 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 5132 NewTL.setNameLoc(TL.getNameLoc()); 5133 5134 return Result; 5135 } 5136 5137 template<typename Derived> 5138 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 5139 ExtVectorTypeLoc TL) { 5140 const VectorType *T = TL.getTypePtr(); 5141 QualType ElementType = getDerived().TransformType(T->getElementType()); 5142 if (ElementType.isNull()) 5143 return QualType(); 5144 5145 QualType Result = TL.getType(); 5146 if (getDerived().AlwaysRebuild() || 5147 ElementType != T->getElementType()) { 5148 Result = getDerived().RebuildExtVectorType(ElementType, 5149 T->getNumElements(), 5150 /*FIXME*/ SourceLocation()); 5151 if (Result.isNull()) 5152 return QualType(); 5153 } 5154 5155 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 5156 NewTL.setNameLoc(TL.getNameLoc()); 5157 5158 return Result; 5159 } 5160 5161 template <typename Derived> 5162 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( 5163 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, 5164 bool ExpectParameterPack) { 5165 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 5166 TypeSourceInfo *NewDI = nullptr; 5167 5168 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 5169 // If we're substituting into a pack expansion type and we know the 5170 // length we want to expand to, just substitute for the pattern. 5171 TypeLoc OldTL = OldDI->getTypeLoc(); 5172 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); 5173 5174 TypeLocBuilder TLB; 5175 TypeLoc NewTL = OldDI->getTypeLoc(); 5176 TLB.reserve(NewTL.getFullDataSize()); 5177 5178 QualType Result = getDerived().TransformType(TLB, 5179 OldExpansionTL.getPatternLoc()); 5180 if (Result.isNull()) 5181 return nullptr; 5182 5183 Result = RebuildPackExpansionType(Result, 5184 OldExpansionTL.getPatternLoc().getSourceRange(), 5185 OldExpansionTL.getEllipsisLoc(), 5186 NumExpansions); 5187 if (Result.isNull()) 5188 return nullptr; 5189 5190 PackExpansionTypeLoc NewExpansionTL 5191 = TLB.push<PackExpansionTypeLoc>(Result); 5192 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 5193 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 5194 } else 5195 NewDI = getDerived().TransformType(OldDI); 5196 if (!NewDI) 5197 return nullptr; 5198 5199 if (NewDI == OldDI && indexAdjustment == 0) 5200 return OldParm; 5201 5202 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, 5203 OldParm->getDeclContext(), 5204 OldParm->getInnerLocStart(), 5205 OldParm->getLocation(), 5206 OldParm->getIdentifier(), 5207 NewDI->getType(), 5208 NewDI, 5209 OldParm->getStorageClass(), 5210 /* DefArg */ nullptr); 5211 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), 5212 OldParm->getFunctionScopeIndex() + indexAdjustment); 5213 return newParm; 5214 } 5215 5216 template <typename Derived> 5217 bool TreeTransform<Derived>::TransformFunctionTypeParams( 5218 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, 5219 const QualType *ParamTypes, 5220 const FunctionProtoType::ExtParameterInfo *ParamInfos, 5221 SmallVectorImpl<QualType> &OutParamTypes, 5222 SmallVectorImpl<ParmVarDecl *> *PVars, 5223 Sema::ExtParameterInfoBuilder &PInfos) { 5224 int indexAdjustment = 0; 5225 5226 unsigned NumParams = Params.size(); 5227 for (unsigned i = 0; i != NumParams; ++i) { 5228 if (ParmVarDecl *OldParm = Params[i]) { 5229 assert(OldParm->getFunctionScopeIndex() == i); 5230 5231 Optional<unsigned> NumExpansions; 5232 ParmVarDecl *NewParm = nullptr; 5233 if (OldParm->isParameterPack()) { 5234 // We have a function parameter pack that may need to be expanded. 5235 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 5236 5237 // Find the parameter packs that could be expanded. 5238 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 5239 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); 5240 TypeLoc Pattern = ExpansionTL.getPatternLoc(); 5241 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 5242 5243 // Determine whether we should expand the parameter packs. 5244 bool ShouldExpand = false; 5245 bool RetainExpansion = false; 5246 Optional<unsigned> OrigNumExpansions; 5247 if (Unexpanded.size() > 0) { 5248 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions(); 5249 NumExpansions = OrigNumExpansions; 5250 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 5251 Pattern.getSourceRange(), 5252 Unexpanded, 5253 ShouldExpand, 5254 RetainExpansion, 5255 NumExpansions)) { 5256 return true; 5257 } 5258 } else { 5259 #ifndef NDEBUG 5260 const AutoType *AT = 5261 Pattern.getType().getTypePtr()->getContainedAutoType(); 5262 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) && 5263 "Could not find parameter packs or undeduced auto type!"); 5264 #endif 5265 } 5266 5267 if (ShouldExpand) { 5268 // Expand the function parameter pack into multiple, separate 5269 // parameters. 5270 getDerived().ExpandingFunctionParameterPack(OldParm); 5271 for (unsigned I = 0; I != *NumExpansions; ++I) { 5272 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 5273 ParmVarDecl *NewParm 5274 = getDerived().TransformFunctionTypeParam(OldParm, 5275 indexAdjustment++, 5276 OrigNumExpansions, 5277 /*ExpectParameterPack=*/false); 5278 if (!NewParm) 5279 return true; 5280 5281 if (ParamInfos) 5282 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5283 OutParamTypes.push_back(NewParm->getType()); 5284 if (PVars) 5285 PVars->push_back(NewParm); 5286 } 5287 5288 // If we're supposed to retain a pack expansion, do so by temporarily 5289 // forgetting the partially-substituted parameter pack. 5290 if (RetainExpansion) { 5291 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 5292 ParmVarDecl *NewParm 5293 = getDerived().TransformFunctionTypeParam(OldParm, 5294 indexAdjustment++, 5295 OrigNumExpansions, 5296 /*ExpectParameterPack=*/false); 5297 if (!NewParm) 5298 return true; 5299 5300 if (ParamInfos) 5301 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5302 OutParamTypes.push_back(NewParm->getType()); 5303 if (PVars) 5304 PVars->push_back(NewParm); 5305 } 5306 5307 // The next parameter should have the same adjustment as the 5308 // last thing we pushed, but we post-incremented indexAdjustment 5309 // on every push. Also, if we push nothing, the adjustment should 5310 // go down by one. 5311 indexAdjustment--; 5312 5313 // We're done with the pack expansion. 5314 continue; 5315 } 5316 5317 // We'll substitute the parameter now without expanding the pack 5318 // expansion. 5319 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 5320 NewParm = getDerived().TransformFunctionTypeParam(OldParm, 5321 indexAdjustment, 5322 NumExpansions, 5323 /*ExpectParameterPack=*/true); 5324 assert(NewParm->isParameterPack() && 5325 "Parameter pack no longer a parameter pack after " 5326 "transformation."); 5327 } else { 5328 NewParm = getDerived().TransformFunctionTypeParam( 5329 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); 5330 } 5331 5332 if (!NewParm) 5333 return true; 5334 5335 if (ParamInfos) 5336 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5337 OutParamTypes.push_back(NewParm->getType()); 5338 if (PVars) 5339 PVars->push_back(NewParm); 5340 continue; 5341 } 5342 5343 // Deal with the possibility that we don't have a parameter 5344 // declaration for this parameter. 5345 QualType OldType = ParamTypes[i]; 5346 bool IsPackExpansion = false; 5347 Optional<unsigned> NumExpansions; 5348 QualType NewType; 5349 if (const PackExpansionType *Expansion 5350 = dyn_cast<PackExpansionType>(OldType)) { 5351 // We have a function parameter pack that may need to be expanded. 5352 QualType Pattern = Expansion->getPattern(); 5353 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 5354 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 5355 5356 // Determine whether we should expand the parameter packs. 5357 bool ShouldExpand = false; 5358 bool RetainExpansion = false; 5359 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 5360 Unexpanded, 5361 ShouldExpand, 5362 RetainExpansion, 5363 NumExpansions)) { 5364 return true; 5365 } 5366 5367 if (ShouldExpand) { 5368 // Expand the function parameter pack into multiple, separate 5369 // parameters. 5370 for (unsigned I = 0; I != *NumExpansions; ++I) { 5371 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 5372 QualType NewType = getDerived().TransformType(Pattern); 5373 if (NewType.isNull()) 5374 return true; 5375 5376 if (NewType->containsUnexpandedParameterPack()) { 5377 NewType = 5378 getSema().getASTContext().getPackExpansionType(NewType, None); 5379 5380 if (NewType.isNull()) 5381 return true; 5382 } 5383 5384 if (ParamInfos) 5385 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5386 OutParamTypes.push_back(NewType); 5387 if (PVars) 5388 PVars->push_back(nullptr); 5389 } 5390 5391 // We're done with the pack expansion. 5392 continue; 5393 } 5394 5395 // If we're supposed to retain a pack expansion, do so by temporarily 5396 // forgetting the partially-substituted parameter pack. 5397 if (RetainExpansion) { 5398 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 5399 QualType NewType = getDerived().TransformType(Pattern); 5400 if (NewType.isNull()) 5401 return true; 5402 5403 if (ParamInfos) 5404 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5405 OutParamTypes.push_back(NewType); 5406 if (PVars) 5407 PVars->push_back(nullptr); 5408 } 5409 5410 // We'll substitute the parameter now without expanding the pack 5411 // expansion. 5412 OldType = Expansion->getPattern(); 5413 IsPackExpansion = true; 5414 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 5415 NewType = getDerived().TransformType(OldType); 5416 } else { 5417 NewType = getDerived().TransformType(OldType); 5418 } 5419 5420 if (NewType.isNull()) 5421 return true; 5422 5423 if (IsPackExpansion) 5424 NewType = getSema().Context.getPackExpansionType(NewType, 5425 NumExpansions); 5426 5427 if (ParamInfos) 5428 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5429 OutParamTypes.push_back(NewType); 5430 if (PVars) 5431 PVars->push_back(nullptr); 5432 } 5433 5434 #ifndef NDEBUG 5435 if (PVars) { 5436 for (unsigned i = 0, e = PVars->size(); i != e; ++i) 5437 if (ParmVarDecl *parm = (*PVars)[i]) 5438 assert(parm->getFunctionScopeIndex() == i); 5439 } 5440 #endif 5441 5442 return false; 5443 } 5444 5445 template<typename Derived> 5446 QualType 5447 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 5448 FunctionProtoTypeLoc TL) { 5449 SmallVector<QualType, 4> ExceptionStorage; 5450 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. 5451 return getDerived().TransformFunctionProtoType( 5452 TLB, TL, nullptr, Qualifiers(), 5453 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { 5454 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI, 5455 ExceptionStorage, Changed); 5456 }); 5457 } 5458 5459 template<typename Derived> template<typename Fn> 5460 QualType TreeTransform<Derived>::TransformFunctionProtoType( 5461 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, 5462 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) { 5463 5464 // Transform the parameters and return type. 5465 // 5466 // We are required to instantiate the params and return type in source order. 5467 // When the function has a trailing return type, we instantiate the 5468 // parameters before the return type, since the return type can then refer 5469 // to the parameters themselves (via decltype, sizeof, etc.). 5470 // 5471 SmallVector<QualType, 4> ParamTypes; 5472 SmallVector<ParmVarDecl*, 4> ParamDecls; 5473 Sema::ExtParameterInfoBuilder ExtParamInfos; 5474 const FunctionProtoType *T = TL.getTypePtr(); 5475 5476 QualType ResultType; 5477 5478 if (T->hasTrailingReturn()) { 5479 if (getDerived().TransformFunctionTypeParams( 5480 TL.getBeginLoc(), TL.getParams(), 5481 TL.getTypePtr()->param_type_begin(), 5482 T->getExtParameterInfosOrNull(), 5483 ParamTypes, &ParamDecls, ExtParamInfos)) 5484 return QualType(); 5485 5486 { 5487 // C++11 [expr.prim.general]p3: 5488 // If a declaration declares a member function or member function 5489 // template of a class X, the expression this is a prvalue of type 5490 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq 5491 // and the end of the function-definition, member-declarator, or 5492 // declarator. 5493 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); 5494 5495 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); 5496 if (ResultType.isNull()) 5497 return QualType(); 5498 } 5499 } 5500 else { 5501 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); 5502 if (ResultType.isNull()) 5503 return QualType(); 5504 5505 if (getDerived().TransformFunctionTypeParams( 5506 TL.getBeginLoc(), TL.getParams(), 5507 TL.getTypePtr()->param_type_begin(), 5508 T->getExtParameterInfosOrNull(), 5509 ParamTypes, &ParamDecls, ExtParamInfos)) 5510 return QualType(); 5511 } 5512 5513 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); 5514 5515 bool EPIChanged = false; 5516 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) 5517 return QualType(); 5518 5519 // Handle extended parameter information. 5520 if (auto NewExtParamInfos = 5521 ExtParamInfos.getPointerOrNull(ParamTypes.size())) { 5522 if (!EPI.ExtParameterInfos || 5523 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams()) 5524 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) { 5525 EPIChanged = true; 5526 } 5527 EPI.ExtParameterInfos = NewExtParamInfos; 5528 } else if (EPI.ExtParameterInfos) { 5529 EPIChanged = true; 5530 EPI.ExtParameterInfos = nullptr; 5531 } 5532 5533 QualType Result = TL.getType(); 5534 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || 5535 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) { 5536 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); 5537 if (Result.isNull()) 5538 return QualType(); 5539 } 5540 5541 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 5542 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 5543 NewTL.setLParenLoc(TL.getLParenLoc()); 5544 NewTL.setRParenLoc(TL.getRParenLoc()); 5545 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange()); 5546 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 5547 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) 5548 NewTL.setParam(i, ParamDecls[i]); 5549 5550 return Result; 5551 } 5552 5553 template<typename Derived> 5554 bool TreeTransform<Derived>::TransformExceptionSpec( 5555 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, 5556 SmallVectorImpl<QualType> &Exceptions, bool &Changed) { 5557 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); 5558 5559 // Instantiate a dynamic noexcept expression, if any. 5560 if (isComputedNoexcept(ESI.Type)) { 5561 EnterExpressionEvaluationContext Unevaluated( 5562 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); 5563 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); 5564 if (NoexceptExpr.isInvalid()) 5565 return true; 5566 5567 ExceptionSpecificationType EST = ESI.Type; 5568 NoexceptExpr = 5569 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST); 5570 if (NoexceptExpr.isInvalid()) 5571 return true; 5572 5573 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type) 5574 Changed = true; 5575 ESI.NoexceptExpr = NoexceptExpr.get(); 5576 ESI.Type = EST; 5577 } 5578 5579 if (ESI.Type != EST_Dynamic) 5580 return false; 5581 5582 // Instantiate a dynamic exception specification's type. 5583 for (QualType T : ESI.Exceptions) { 5584 if (const PackExpansionType *PackExpansion = 5585 T->getAs<PackExpansionType>()) { 5586 Changed = true; 5587 5588 // We have a pack expansion. Instantiate it. 5589 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 5590 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), 5591 Unexpanded); 5592 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 5593 5594 // Determine whether the set of unexpanded parameter packs can and 5595 // should 5596 // be expanded. 5597 bool Expand = false; 5598 bool RetainExpansion = false; 5599 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); 5600 // FIXME: Track the location of the ellipsis (and track source location 5601 // information for the types in the exception specification in general). 5602 if (getDerived().TryExpandParameterPacks( 5603 Loc, SourceRange(), Unexpanded, Expand, 5604 RetainExpansion, NumExpansions)) 5605 return true; 5606 5607 if (!Expand) { 5608 // We can't expand this pack expansion into separate arguments yet; 5609 // just substitute into the pattern and create a new pack expansion 5610 // type. 5611 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 5612 QualType U = getDerived().TransformType(PackExpansion->getPattern()); 5613 if (U.isNull()) 5614 return true; 5615 5616 U = SemaRef.Context.getPackExpansionType(U, NumExpansions); 5617 Exceptions.push_back(U); 5618 continue; 5619 } 5620 5621 // Substitute into the pack expansion pattern for each slice of the 5622 // pack. 5623 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { 5624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); 5625 5626 QualType U = getDerived().TransformType(PackExpansion->getPattern()); 5627 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) 5628 return true; 5629 5630 Exceptions.push_back(U); 5631 } 5632 } else { 5633 QualType U = getDerived().TransformType(T); 5634 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) 5635 return true; 5636 if (T != U) 5637 Changed = true; 5638 5639 Exceptions.push_back(U); 5640 } 5641 } 5642 5643 ESI.Exceptions = Exceptions; 5644 if (ESI.Exceptions.empty()) 5645 ESI.Type = EST_DynamicNone; 5646 return false; 5647 } 5648 5649 template<typename Derived> 5650 QualType TreeTransform<Derived>::TransformFunctionNoProtoType( 5651 TypeLocBuilder &TLB, 5652 FunctionNoProtoTypeLoc TL) { 5653 const FunctionNoProtoType *T = TL.getTypePtr(); 5654 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); 5655 if (ResultType.isNull()) 5656 return QualType(); 5657 5658 QualType Result = TL.getType(); 5659 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) 5660 Result = getDerived().RebuildFunctionNoProtoType(ResultType); 5661 5662 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 5663 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 5664 NewTL.setLParenLoc(TL.getLParenLoc()); 5665 NewTL.setRParenLoc(TL.getRParenLoc()); 5666 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 5667 5668 return Result; 5669 } 5670 5671 template<typename Derived> QualType 5672 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 5673 UnresolvedUsingTypeLoc TL) { 5674 const UnresolvedUsingType *T = TL.getTypePtr(); 5675 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 5676 if (!D) 5677 return QualType(); 5678 5679 QualType Result = TL.getType(); 5680 if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 5681 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D); 5682 if (Result.isNull()) 5683 return QualType(); 5684 } 5685 5686 // We might get an arbitrary type spec type back. We should at 5687 // least always get a type spec type, though. 5688 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 5689 NewTL.setNameLoc(TL.getNameLoc()); 5690 5691 return Result; 5692 } 5693 5694 template<typename Derived> 5695 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 5696 TypedefTypeLoc TL) { 5697 const TypedefType *T = TL.getTypePtr(); 5698 TypedefNameDecl *Typedef 5699 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), 5700 T->getDecl())); 5701 if (!Typedef) 5702 return QualType(); 5703 5704 QualType Result = TL.getType(); 5705 if (getDerived().AlwaysRebuild() || 5706 Typedef != T->getDecl()) { 5707 Result = getDerived().RebuildTypedefType(Typedef); 5708 if (Result.isNull()) 5709 return QualType(); 5710 } 5711 5712 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 5713 NewTL.setNameLoc(TL.getNameLoc()); 5714 5715 return Result; 5716 } 5717 5718 template<typename Derived> 5719 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 5720 TypeOfExprTypeLoc TL) { 5721 // typeof expressions are not potentially evaluated contexts 5722 EnterExpressionEvaluationContext Unevaluated( 5723 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, 5724 Sema::ReuseLambdaContextDecl); 5725 5726 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 5727 if (E.isInvalid()) 5728 return QualType(); 5729 5730 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); 5731 if (E.isInvalid()) 5732 return QualType(); 5733 5734 QualType Result = TL.getType(); 5735 if (getDerived().AlwaysRebuild() || 5736 E.get() != TL.getUnderlyingExpr()) { 5737 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 5738 if (Result.isNull()) 5739 return QualType(); 5740 } 5741 else E.get(); 5742 5743 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 5744 NewTL.setTypeofLoc(TL.getTypeofLoc()); 5745 NewTL.setLParenLoc(TL.getLParenLoc()); 5746 NewTL.setRParenLoc(TL.getRParenLoc()); 5747 5748 return Result; 5749 } 5750 5751 template<typename Derived> 5752 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 5753 TypeOfTypeLoc TL) { 5754 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 5755 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 5756 if (!New_Under_TI) 5757 return QualType(); 5758 5759 QualType Result = TL.getType(); 5760 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 5761 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 5762 if (Result.isNull()) 5763 return QualType(); 5764 } 5765 5766 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 5767 NewTL.setTypeofLoc(TL.getTypeofLoc()); 5768 NewTL.setLParenLoc(TL.getLParenLoc()); 5769 NewTL.setRParenLoc(TL.getRParenLoc()); 5770 NewTL.setUnderlyingTInfo(New_Under_TI); 5771 5772 return Result; 5773 } 5774 5775 template<typename Derived> 5776 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 5777 DecltypeTypeLoc TL) { 5778 const DecltypeType *T = TL.getTypePtr(); 5779 5780 // decltype expressions are not potentially evaluated contexts 5781 EnterExpressionEvaluationContext Unevaluated( 5782 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, 5783 Sema::ExpressionEvaluationContextRecord::EK_Decltype); 5784 5785 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 5786 if (E.isInvalid()) 5787 return QualType(); 5788 5789 E = getSema().ActOnDecltypeExpression(E.get()); 5790 if (E.isInvalid()) 5791 return QualType(); 5792 5793 QualType Result = TL.getType(); 5794 if (getDerived().AlwaysRebuild() || 5795 E.get() != T->getUnderlyingExpr()) { 5796 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 5797 if (Result.isNull()) 5798 return QualType(); 5799 } 5800 else E.get(); 5801 5802 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 5803 NewTL.setNameLoc(TL.getNameLoc()); 5804 5805 return Result; 5806 } 5807 5808 template<typename Derived> 5809 QualType TreeTransform<Derived>::TransformUnaryTransformType( 5810 TypeLocBuilder &TLB, 5811 UnaryTransformTypeLoc TL) { 5812 QualType Result = TL.getType(); 5813 if (Result->isDependentType()) { 5814 const UnaryTransformType *T = TL.getTypePtr(); 5815 QualType NewBase = 5816 getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); 5817 Result = getDerived().RebuildUnaryTransformType(NewBase, 5818 T->getUTTKind(), 5819 TL.getKWLoc()); 5820 if (Result.isNull()) 5821 return QualType(); 5822 } 5823 5824 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); 5825 NewTL.setKWLoc(TL.getKWLoc()); 5826 NewTL.setParensRange(TL.getParensRange()); 5827 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); 5828 return Result; 5829 } 5830 5831 template<typename Derived> 5832 QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType( 5833 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) { 5834 const DeducedTemplateSpecializationType *T = TL.getTypePtr(); 5835 5836 CXXScopeSpec SS; 5837 TemplateName TemplateName = getDerived().TransformTemplateName( 5838 SS, T->getTemplateName(), TL.getTemplateNameLoc()); 5839 if (TemplateName.isNull()) 5840 return QualType(); 5841 5842 QualType OldDeduced = T->getDeducedType(); 5843 QualType NewDeduced; 5844 if (!OldDeduced.isNull()) { 5845 NewDeduced = getDerived().TransformType(OldDeduced); 5846 if (NewDeduced.isNull()) 5847 return QualType(); 5848 } 5849 5850 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType( 5851 TemplateName, NewDeduced); 5852 if (Result.isNull()) 5853 return QualType(); 5854 5855 DeducedTemplateSpecializationTypeLoc NewTL = 5856 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result); 5857 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 5858 5859 return Result; 5860 } 5861 5862 template<typename Derived> 5863 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 5864 RecordTypeLoc TL) { 5865 const RecordType *T = TL.getTypePtr(); 5866 RecordDecl *Record 5867 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 5868 T->getDecl())); 5869 if (!Record) 5870 return QualType(); 5871 5872 QualType Result = TL.getType(); 5873 if (getDerived().AlwaysRebuild() || 5874 Record != T->getDecl()) { 5875 Result = getDerived().RebuildRecordType(Record); 5876 if (Result.isNull()) 5877 return QualType(); 5878 } 5879 5880 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 5881 NewTL.setNameLoc(TL.getNameLoc()); 5882 5883 return Result; 5884 } 5885 5886 template<typename Derived> 5887 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 5888 EnumTypeLoc TL) { 5889 const EnumType *T = TL.getTypePtr(); 5890 EnumDecl *Enum 5891 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 5892 T->getDecl())); 5893 if (!Enum) 5894 return QualType(); 5895 5896 QualType Result = TL.getType(); 5897 if (getDerived().AlwaysRebuild() || 5898 Enum != T->getDecl()) { 5899 Result = getDerived().RebuildEnumType(Enum); 5900 if (Result.isNull()) 5901 return QualType(); 5902 } 5903 5904 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 5905 NewTL.setNameLoc(TL.getNameLoc()); 5906 5907 return Result; 5908 } 5909 5910 template<typename Derived> 5911 QualType TreeTransform<Derived>::TransformInjectedClassNameType( 5912 TypeLocBuilder &TLB, 5913 InjectedClassNameTypeLoc TL) { 5914 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 5915 TL.getTypePtr()->getDecl()); 5916 if (!D) return QualType(); 5917 5918 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 5919 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 5920 return T; 5921 } 5922 5923 template<typename Derived> 5924 QualType TreeTransform<Derived>::TransformTemplateTypeParmType( 5925 TypeLocBuilder &TLB, 5926 TemplateTypeParmTypeLoc TL) { 5927 return TransformTypeSpecType(TLB, TL); 5928 } 5929 5930 template<typename Derived> 5931 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 5932 TypeLocBuilder &TLB, 5933 SubstTemplateTypeParmTypeLoc TL) { 5934 const SubstTemplateTypeParmType *T = TL.getTypePtr(); 5935 5936 // Substitute into the replacement type, which itself might involve something 5937 // that needs to be transformed. This only tends to occur with default 5938 // template arguments of template template parameters. 5939 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); 5940 QualType Replacement = getDerived().TransformType(T->getReplacementType()); 5941 if (Replacement.isNull()) 5942 return QualType(); 5943 5944 // Always canonicalize the replacement type. 5945 Replacement = SemaRef.Context.getCanonicalType(Replacement); 5946 QualType Result 5947 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), 5948 Replacement); 5949 5950 // Propagate type-source information. 5951 SubstTemplateTypeParmTypeLoc NewTL 5952 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); 5953 NewTL.setNameLoc(TL.getNameLoc()); 5954 return Result; 5955 5956 } 5957 5958 template<typename Derived> 5959 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 5960 TypeLocBuilder &TLB, 5961 SubstTemplateTypeParmPackTypeLoc TL) { 5962 return TransformTypeSpecType(TLB, TL); 5963 } 5964 5965 template<typename Derived> 5966 QualType TreeTransform<Derived>::TransformTemplateSpecializationType( 5967 TypeLocBuilder &TLB, 5968 TemplateSpecializationTypeLoc TL) { 5969 const TemplateSpecializationType *T = TL.getTypePtr(); 5970 5971 // The nested-name-specifier never matters in a TemplateSpecializationType, 5972 // because we can't have a dependent nested-name-specifier anyway. 5973 CXXScopeSpec SS; 5974 TemplateName Template 5975 = getDerived().TransformTemplateName(SS, T->getTemplateName(), 5976 TL.getTemplateNameLoc()); 5977 if (Template.isNull()) 5978 return QualType(); 5979 5980 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 5981 } 5982 5983 template<typename Derived> 5984 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, 5985 AtomicTypeLoc TL) { 5986 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 5987 if (ValueType.isNull()) 5988 return QualType(); 5989 5990 QualType Result = TL.getType(); 5991 if (getDerived().AlwaysRebuild() || 5992 ValueType != TL.getValueLoc().getType()) { 5993 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); 5994 if (Result.isNull()) 5995 return QualType(); 5996 } 5997 5998 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); 5999 NewTL.setKWLoc(TL.getKWLoc()); 6000 NewTL.setLParenLoc(TL.getLParenLoc()); 6001 NewTL.setRParenLoc(TL.getRParenLoc()); 6002 6003 return Result; 6004 } 6005 6006 template <typename Derived> 6007 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB, 6008 PipeTypeLoc TL) { 6009 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 6010 if (ValueType.isNull()) 6011 return QualType(); 6012 6013 QualType Result = TL.getType(); 6014 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) { 6015 const PipeType *PT = Result->castAs<PipeType>(); 6016 bool isReadPipe = PT->isReadOnly(); 6017 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe); 6018 if (Result.isNull()) 6019 return QualType(); 6020 } 6021 6022 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result); 6023 NewTL.setKWLoc(TL.getKWLoc()); 6024 6025 return Result; 6026 } 6027 6028 /// Simple iterator that traverses the template arguments in a 6029 /// container that provides a \c getArgLoc() member function. 6030 /// 6031 /// This iterator is intended to be used with the iterator form of 6032 /// \c TreeTransform<Derived>::TransformTemplateArguments(). 6033 template<typename ArgLocContainer> 6034 class TemplateArgumentLocContainerIterator { 6035 ArgLocContainer *Container; 6036 unsigned Index; 6037 6038 public: 6039 typedef TemplateArgumentLoc value_type; 6040 typedef TemplateArgumentLoc reference; 6041 typedef int difference_type; 6042 typedef std::input_iterator_tag iterator_category; 6043 6044 class pointer { 6045 TemplateArgumentLoc Arg; 6046 6047 public: 6048 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 6049 6050 const TemplateArgumentLoc *operator->() const { 6051 return &Arg; 6052 } 6053 }; 6054 6055 6056 TemplateArgumentLocContainerIterator() {} 6057 6058 TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 6059 unsigned Index) 6060 : Container(&Container), Index(Index) { } 6061 6062 TemplateArgumentLocContainerIterator &operator++() { 6063 ++Index; 6064 return *this; 6065 } 6066 6067 TemplateArgumentLocContainerIterator operator++(int) { 6068 TemplateArgumentLocContainerIterator Old(*this); 6069 ++(*this); 6070 return Old; 6071 } 6072 6073 TemplateArgumentLoc operator*() const { 6074 return Container->getArgLoc(Index); 6075 } 6076 6077 pointer operator->() const { 6078 return pointer(Container->getArgLoc(Index)); 6079 } 6080 6081 friend bool operator==(const TemplateArgumentLocContainerIterator &X, 6082 const TemplateArgumentLocContainerIterator &Y) { 6083 return X.Container == Y.Container && X.Index == Y.Index; 6084 } 6085 6086 friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 6087 const TemplateArgumentLocContainerIterator &Y) { 6088 return !(X == Y); 6089 } 6090 }; 6091 6092 template<typename Derived> 6093 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 6094 AutoTypeLoc TL) { 6095 const AutoType *T = TL.getTypePtr(); 6096 QualType OldDeduced = T->getDeducedType(); 6097 QualType NewDeduced; 6098 if (!OldDeduced.isNull()) { 6099 NewDeduced = getDerived().TransformType(OldDeduced); 6100 if (NewDeduced.isNull()) 6101 return QualType(); 6102 } 6103 6104 ConceptDecl *NewCD = nullptr; 6105 TemplateArgumentListInfo NewTemplateArgs; 6106 NestedNameSpecifierLoc NewNestedNameSpec; 6107 if (TL.getTypePtr()->isConstrained()) { 6108 NewCD = cast_or_null<ConceptDecl>( 6109 getDerived().TransformDecl( 6110 TL.getConceptNameLoc(), 6111 TL.getTypePtr()->getTypeConstraintConcept())); 6112 6113 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 6114 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 6115 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator; 6116 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 6117 ArgIterator(TL, 6118 TL.getNumArgs()), 6119 NewTemplateArgs)) 6120 return QualType(); 6121 6122 if (TL.getNestedNameSpecifierLoc()) { 6123 NewNestedNameSpec 6124 = getDerived().TransformNestedNameSpecifierLoc( 6125 TL.getNestedNameSpecifierLoc()); 6126 if (!NewNestedNameSpec) 6127 return QualType(); 6128 } 6129 } 6130 6131 QualType Result = TL.getType(); 6132 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || 6133 T->isDependentType()) { 6134 llvm::SmallVector<TemplateArgument, 4> NewArgList; 6135 NewArgList.reserve(NewArgList.size()); 6136 for (const auto &ArgLoc : NewTemplateArgs.arguments()) 6137 NewArgList.push_back(ArgLoc.getArgument()); 6138 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD, 6139 NewArgList); 6140 if (Result.isNull()) 6141 return QualType(); 6142 } 6143 6144 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 6145 NewTL.setNameLoc(TL.getNameLoc()); 6146 NewTL.setNestedNameSpecifierLoc(NewNestedNameSpec); 6147 NewTL.setTemplateKWLoc(TL.getTemplateKWLoc()); 6148 NewTL.setConceptNameLoc(TL.getConceptNameLoc()); 6149 NewTL.setFoundDecl(TL.getFoundDecl()); 6150 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6151 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6152 for (unsigned I = 0; I < TL.getNumArgs(); ++I) 6153 NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo()); 6154 6155 return Result; 6156 } 6157 6158 template <typename Derived> 6159 QualType TreeTransform<Derived>::TransformTemplateSpecializationType( 6160 TypeLocBuilder &TLB, 6161 TemplateSpecializationTypeLoc TL, 6162 TemplateName Template) { 6163 TemplateArgumentListInfo NewTemplateArgs; 6164 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 6165 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 6166 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 6167 ArgIterator; 6168 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 6169 ArgIterator(TL, TL.getNumArgs()), 6170 NewTemplateArgs)) 6171 return QualType(); 6172 6173 // FIXME: maybe don't rebuild if all the template arguments are the same. 6174 6175 QualType Result = 6176 getDerived().RebuildTemplateSpecializationType(Template, 6177 TL.getTemplateNameLoc(), 6178 NewTemplateArgs); 6179 6180 if (!Result.isNull()) { 6181 // Specializations of template template parameters are represented as 6182 // TemplateSpecializationTypes, and substitution of type alias templates 6183 // within a dependent context can transform them into 6184 // DependentTemplateSpecializationTypes. 6185 if (isa<DependentTemplateSpecializationType>(Result)) { 6186 DependentTemplateSpecializationTypeLoc NewTL 6187 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 6188 NewTL.setElaboratedKeywordLoc(SourceLocation()); 6189 NewTL.setQualifierLoc(NestedNameSpecifierLoc()); 6190 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6191 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6192 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6193 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6194 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 6195 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 6196 return Result; 6197 } 6198 6199 TemplateSpecializationTypeLoc NewTL 6200 = TLB.push<TemplateSpecializationTypeLoc>(Result); 6201 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6202 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6203 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6204 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6205 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 6206 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 6207 } 6208 6209 return Result; 6210 } 6211 6212 template <typename Derived> 6213 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 6214 TypeLocBuilder &TLB, 6215 DependentTemplateSpecializationTypeLoc TL, 6216 TemplateName Template, 6217 CXXScopeSpec &SS) { 6218 TemplateArgumentListInfo NewTemplateArgs; 6219 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 6220 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 6221 typedef TemplateArgumentLocContainerIterator< 6222 DependentTemplateSpecializationTypeLoc> ArgIterator; 6223 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 6224 ArgIterator(TL, TL.getNumArgs()), 6225 NewTemplateArgs)) 6226 return QualType(); 6227 6228 // FIXME: maybe don't rebuild if all the template arguments are the same. 6229 6230 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 6231 QualType Result 6232 = getSema().Context.getDependentTemplateSpecializationType( 6233 TL.getTypePtr()->getKeyword(), 6234 DTN->getQualifier(), 6235 DTN->getIdentifier(), 6236 NewTemplateArgs); 6237 6238 DependentTemplateSpecializationTypeLoc NewTL 6239 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 6240 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 6241 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); 6242 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6243 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6244 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6245 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6246 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 6247 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 6248 return Result; 6249 } 6250 6251 QualType Result 6252 = getDerived().RebuildTemplateSpecializationType(Template, 6253 TL.getTemplateNameLoc(), 6254 NewTemplateArgs); 6255 6256 if (!Result.isNull()) { 6257 /// FIXME: Wrap this in an elaborated-type-specifier? 6258 TemplateSpecializationTypeLoc NewTL 6259 = TLB.push<TemplateSpecializationTypeLoc>(Result); 6260 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6261 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6262 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6263 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6264 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 6265 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 6266 } 6267 6268 return Result; 6269 } 6270 6271 template<typename Derived> 6272 QualType 6273 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 6274 ElaboratedTypeLoc TL) { 6275 const ElaboratedType *T = TL.getTypePtr(); 6276 6277 NestedNameSpecifierLoc QualifierLoc; 6278 // NOTE: the qualifier in an ElaboratedType is optional. 6279 if (TL.getQualifierLoc()) { 6280 QualifierLoc 6281 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 6282 if (!QualifierLoc) 6283 return QualType(); 6284 } 6285 6286 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 6287 if (NamedT.isNull()) 6288 return QualType(); 6289 6290 // C++0x [dcl.type.elab]p2: 6291 // If the identifier resolves to a typedef-name or the simple-template-id 6292 // resolves to an alias template specialization, the 6293 // elaborated-type-specifier is ill-formed. 6294 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { 6295 if (const TemplateSpecializationType *TST = 6296 NamedT->getAs<TemplateSpecializationType>()) { 6297 TemplateName Template = TST->getTemplateName(); 6298 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( 6299 Template.getAsTemplateDecl())) { 6300 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), 6301 diag::err_tag_reference_non_tag) 6302 << TAT << Sema::NTK_TypeAliasTemplate 6303 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword()); 6304 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); 6305 } 6306 } 6307 } 6308 6309 QualType Result = TL.getType(); 6310 if (getDerived().AlwaysRebuild() || 6311 QualifierLoc != TL.getQualifierLoc() || 6312 NamedT != T->getNamedType()) { 6313 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), 6314 T->getKeyword(), 6315 QualifierLoc, NamedT); 6316 if (Result.isNull()) 6317 return QualType(); 6318 } 6319 6320 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 6321 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 6322 NewTL.setQualifierLoc(QualifierLoc); 6323 return Result; 6324 } 6325 6326 template<typename Derived> 6327 QualType TreeTransform<Derived>::TransformAttributedType( 6328 TypeLocBuilder &TLB, 6329 AttributedTypeLoc TL) { 6330 const AttributedType *oldType = TL.getTypePtr(); 6331 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 6332 if (modifiedType.isNull()) 6333 return QualType(); 6334 6335 // oldAttr can be null if we started with a QualType rather than a TypeLoc. 6336 const Attr *oldAttr = TL.getAttr(); 6337 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr; 6338 if (oldAttr && !newAttr) 6339 return QualType(); 6340 6341 QualType result = TL.getType(); 6342 6343 // FIXME: dependent operand expressions? 6344 if (getDerived().AlwaysRebuild() || 6345 modifiedType != oldType->getModifiedType()) { 6346 // TODO: this is really lame; we should really be rebuilding the 6347 // equivalent type from first principles. 6348 QualType equivalentType 6349 = getDerived().TransformType(oldType->getEquivalentType()); 6350 if (equivalentType.isNull()) 6351 return QualType(); 6352 6353 // Check whether we can add nullability; it is only represented as 6354 // type sugar, and therefore cannot be diagnosed in any other way. 6355 if (auto nullability = oldType->getImmediateNullability()) { 6356 if (!modifiedType->canHaveNullability()) { 6357 SemaRef.Diag(TL.getAttr()->getLocation(), 6358 diag::err_nullability_nonpointer) 6359 << DiagNullabilityKind(*nullability, false) << modifiedType; 6360 return QualType(); 6361 } 6362 } 6363 6364 result = SemaRef.Context.getAttributedType(TL.getAttrKind(), 6365 modifiedType, 6366 equivalentType); 6367 } 6368 6369 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 6370 newTL.setAttr(newAttr); 6371 return result; 6372 } 6373 6374 template<typename Derived> 6375 QualType 6376 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 6377 ParenTypeLoc TL) { 6378 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 6379 if (Inner.isNull()) 6380 return QualType(); 6381 6382 QualType Result = TL.getType(); 6383 if (getDerived().AlwaysRebuild() || 6384 Inner != TL.getInnerLoc().getType()) { 6385 Result = getDerived().RebuildParenType(Inner); 6386 if (Result.isNull()) 6387 return QualType(); 6388 } 6389 6390 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 6391 NewTL.setLParenLoc(TL.getLParenLoc()); 6392 NewTL.setRParenLoc(TL.getRParenLoc()); 6393 return Result; 6394 } 6395 6396 template <typename Derived> 6397 QualType 6398 TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB, 6399 MacroQualifiedTypeLoc TL) { 6400 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 6401 if (Inner.isNull()) 6402 return QualType(); 6403 6404 QualType Result = TL.getType(); 6405 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) { 6406 Result = 6407 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier()); 6408 if (Result.isNull()) 6409 return QualType(); 6410 } 6411 6412 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result); 6413 NewTL.setExpansionLoc(TL.getExpansionLoc()); 6414 return Result; 6415 } 6416 6417 template<typename Derived> 6418 QualType TreeTransform<Derived>::TransformDependentNameType( 6419 TypeLocBuilder &TLB, DependentNameTypeLoc TL) { 6420 return TransformDependentNameType(TLB, TL, false); 6421 } 6422 6423 template<typename Derived> 6424 QualType TreeTransform<Derived>::TransformDependentNameType( 6425 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) { 6426 const DependentNameType *T = TL.getTypePtr(); 6427 6428 NestedNameSpecifierLoc QualifierLoc 6429 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 6430 if (!QualifierLoc) 6431 return QualType(); 6432 6433 QualType Result 6434 = getDerived().RebuildDependentNameType(T->getKeyword(), 6435 TL.getElaboratedKeywordLoc(), 6436 QualifierLoc, 6437 T->getIdentifier(), 6438 TL.getNameLoc(), 6439 DeducedTSTContext); 6440 if (Result.isNull()) 6441 return QualType(); 6442 6443 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 6444 QualType NamedT = ElabT->getNamedType(); 6445 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 6446 6447 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 6448 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 6449 NewTL.setQualifierLoc(QualifierLoc); 6450 } else { 6451 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 6452 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 6453 NewTL.setQualifierLoc(QualifierLoc); 6454 NewTL.setNameLoc(TL.getNameLoc()); 6455 } 6456 return Result; 6457 } 6458 6459 template<typename Derived> 6460 QualType TreeTransform<Derived>:: 6461 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 6462 DependentTemplateSpecializationTypeLoc TL) { 6463 NestedNameSpecifierLoc QualifierLoc; 6464 if (TL.getQualifierLoc()) { 6465 QualifierLoc 6466 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 6467 if (!QualifierLoc) 6468 return QualType(); 6469 } 6470 6471 return getDerived() 6472 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); 6473 } 6474 6475 template<typename Derived> 6476 QualType TreeTransform<Derived>:: 6477 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 6478 DependentTemplateSpecializationTypeLoc TL, 6479 NestedNameSpecifierLoc QualifierLoc) { 6480 const DependentTemplateSpecializationType *T = TL.getTypePtr(); 6481 6482 TemplateArgumentListInfo NewTemplateArgs; 6483 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 6484 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 6485 6486 typedef TemplateArgumentLocContainerIterator< 6487 DependentTemplateSpecializationTypeLoc> ArgIterator; 6488 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 6489 ArgIterator(TL, TL.getNumArgs()), 6490 NewTemplateArgs)) 6491 return QualType(); 6492 6493 QualType Result = getDerived().RebuildDependentTemplateSpecializationType( 6494 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(), 6495 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs, 6496 /*AllowInjectedClassName*/ false); 6497 if (Result.isNull()) 6498 return QualType(); 6499 6500 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 6501 QualType NamedT = ElabT->getNamedType(); 6502 6503 // Copy information relevant to the template specialization. 6504 TemplateSpecializationTypeLoc NamedTL 6505 = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 6506 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6507 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6508 NamedTL.setLAngleLoc(TL.getLAngleLoc()); 6509 NamedTL.setRAngleLoc(TL.getRAngleLoc()); 6510 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 6511 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 6512 6513 // Copy information relevant to the elaborated type. 6514 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 6515 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 6516 NewTL.setQualifierLoc(QualifierLoc); 6517 } else if (isa<DependentTemplateSpecializationType>(Result)) { 6518 DependentTemplateSpecializationTypeLoc SpecTL 6519 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 6520 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 6521 SpecTL.setQualifierLoc(QualifierLoc); 6522 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6523 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6524 SpecTL.setLAngleLoc(TL.getLAngleLoc()); 6525 SpecTL.setRAngleLoc(TL.getRAngleLoc()); 6526 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 6527 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 6528 } else { 6529 TemplateSpecializationTypeLoc SpecTL 6530 = TLB.push<TemplateSpecializationTypeLoc>(Result); 6531 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6532 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6533 SpecTL.setLAngleLoc(TL.getLAngleLoc()); 6534 SpecTL.setRAngleLoc(TL.getRAngleLoc()); 6535 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 6536 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 6537 } 6538 return Result; 6539 } 6540 6541 template<typename Derived> 6542 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 6543 PackExpansionTypeLoc TL) { 6544 QualType Pattern 6545 = getDerived().TransformType(TLB, TL.getPatternLoc()); 6546 if (Pattern.isNull()) 6547 return QualType(); 6548 6549 QualType Result = TL.getType(); 6550 if (getDerived().AlwaysRebuild() || 6551 Pattern != TL.getPatternLoc().getType()) { 6552 Result = getDerived().RebuildPackExpansionType(Pattern, 6553 TL.getPatternLoc().getSourceRange(), 6554 TL.getEllipsisLoc(), 6555 TL.getTypePtr()->getNumExpansions()); 6556 if (Result.isNull()) 6557 return QualType(); 6558 } 6559 6560 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 6561 NewT.setEllipsisLoc(TL.getEllipsisLoc()); 6562 return Result; 6563 } 6564 6565 template<typename Derived> 6566 QualType 6567 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 6568 ObjCInterfaceTypeLoc TL) { 6569 // ObjCInterfaceType is never dependent. 6570 TLB.pushFullCopy(TL); 6571 return TL.getType(); 6572 } 6573 6574 template<typename Derived> 6575 QualType 6576 TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB, 6577 ObjCTypeParamTypeLoc TL) { 6578 const ObjCTypeParamType *T = TL.getTypePtr(); 6579 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>( 6580 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl())); 6581 if (!OTP) 6582 return QualType(); 6583 6584 QualType Result = TL.getType(); 6585 if (getDerived().AlwaysRebuild() || 6586 OTP != T->getDecl()) { 6587 Result = getDerived().RebuildObjCTypeParamType(OTP, 6588 TL.getProtocolLAngleLoc(), 6589 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), 6590 TL.getNumProtocols()), 6591 TL.getProtocolLocs(), 6592 TL.getProtocolRAngleLoc()); 6593 if (Result.isNull()) 6594 return QualType(); 6595 } 6596 6597 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result); 6598 if (TL.getNumProtocols()) { 6599 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); 6600 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) 6601 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i)); 6602 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); 6603 } 6604 return Result; 6605 } 6606 6607 template<typename Derived> 6608 QualType 6609 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 6610 ObjCObjectTypeLoc TL) { 6611 // Transform base type. 6612 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); 6613 if (BaseType.isNull()) 6614 return QualType(); 6615 6616 bool AnyChanged = BaseType != TL.getBaseLoc().getType(); 6617 6618 // Transform type arguments. 6619 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; 6620 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { 6621 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); 6622 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); 6623 QualType TypeArg = TypeArgInfo->getType(); 6624 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { 6625 AnyChanged = true; 6626 6627 // We have a pack expansion. Instantiate it. 6628 const auto *PackExpansion = PackExpansionLoc.getType() 6629 ->castAs<PackExpansionType>(); 6630 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 6631 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), 6632 Unexpanded); 6633 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 6634 6635 // Determine whether the set of unexpanded parameter packs can 6636 // and should be expanded. 6637 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); 6638 bool Expand = false; 6639 bool RetainExpansion = false; 6640 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); 6641 if (getDerived().TryExpandParameterPacks( 6642 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), 6643 Unexpanded, Expand, RetainExpansion, NumExpansions)) 6644 return QualType(); 6645 6646 if (!Expand) { 6647 // We can't expand this pack expansion into separate arguments yet; 6648 // just substitute into the pattern and create a new pack expansion 6649 // type. 6650 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 6651 6652 TypeLocBuilder TypeArgBuilder; 6653 TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); 6654 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, 6655 PatternLoc); 6656 if (NewPatternType.isNull()) 6657 return QualType(); 6658 6659 QualType NewExpansionType = SemaRef.Context.getPackExpansionType( 6660 NewPatternType, NumExpansions); 6661 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); 6662 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); 6663 NewTypeArgInfos.push_back( 6664 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); 6665 continue; 6666 } 6667 6668 // Substitute into the pack expansion pattern for each slice of the 6669 // pack. 6670 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { 6671 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); 6672 6673 TypeLocBuilder TypeArgBuilder; 6674 TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); 6675 6676 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, 6677 PatternLoc); 6678 if (NewTypeArg.isNull()) 6679 return QualType(); 6680 6681 NewTypeArgInfos.push_back( 6682 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); 6683 } 6684 6685 continue; 6686 } 6687 6688 TypeLocBuilder TypeArgBuilder; 6689 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); 6690 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc); 6691 if (NewTypeArg.isNull()) 6692 return QualType(); 6693 6694 // If nothing changed, just keep the old TypeSourceInfo. 6695 if (NewTypeArg == TypeArg) { 6696 NewTypeArgInfos.push_back(TypeArgInfo); 6697 continue; 6698 } 6699 6700 NewTypeArgInfos.push_back( 6701 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); 6702 AnyChanged = true; 6703 } 6704 6705 QualType Result = TL.getType(); 6706 if (getDerived().AlwaysRebuild() || AnyChanged) { 6707 // Rebuild the type. 6708 Result = getDerived().RebuildObjCObjectType( 6709 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos, 6710 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(), 6711 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), 6712 TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); 6713 6714 if (Result.isNull()) 6715 return QualType(); 6716 } 6717 6718 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); 6719 NewT.setHasBaseTypeAsWritten(true); 6720 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); 6721 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) 6722 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); 6723 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); 6724 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); 6725 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) 6726 NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); 6727 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); 6728 return Result; 6729 } 6730 6731 template<typename Derived> 6732 QualType 6733 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 6734 ObjCObjectPointerTypeLoc TL) { 6735 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 6736 if (PointeeType.isNull()) 6737 return QualType(); 6738 6739 QualType Result = TL.getType(); 6740 if (getDerived().AlwaysRebuild() || 6741 PointeeType != TL.getPointeeLoc().getType()) { 6742 Result = getDerived().RebuildObjCObjectPointerType(PointeeType, 6743 TL.getStarLoc()); 6744 if (Result.isNull()) 6745 return QualType(); 6746 } 6747 6748 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 6749 NewT.setStarLoc(TL.getStarLoc()); 6750 return Result; 6751 } 6752 6753 //===----------------------------------------------------------------------===// 6754 // Statement transformation 6755 //===----------------------------------------------------------------------===// 6756 template<typename Derived> 6757 StmtResult 6758 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 6759 return S; 6760 } 6761 6762 template<typename Derived> 6763 StmtResult 6764 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 6765 return getDerived().TransformCompoundStmt(S, false); 6766 } 6767 6768 template<typename Derived> 6769 StmtResult 6770 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 6771 bool IsStmtExpr) { 6772 Sema::CompoundScopeRAII CompoundScope(getSema()); 6773 6774 const Stmt *ExprResult = S->getStmtExprResult(); 6775 bool SubStmtInvalid = false; 6776 bool SubStmtChanged = false; 6777 SmallVector<Stmt*, 8> Statements; 6778 for (auto *B : S->body()) { 6779 StmtResult Result = getDerived().TransformStmt( 6780 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded); 6781 6782 if (Result.isInvalid()) { 6783 // Immediately fail if this was a DeclStmt, since it's very 6784 // likely that this will cause problems for future statements. 6785 if (isa<DeclStmt>(B)) 6786 return StmtError(); 6787 6788 // Otherwise, just keep processing substatements and fail later. 6789 SubStmtInvalid = true; 6790 continue; 6791 } 6792 6793 SubStmtChanged = SubStmtChanged || Result.get() != B; 6794 Statements.push_back(Result.getAs<Stmt>()); 6795 } 6796 6797 if (SubStmtInvalid) 6798 return StmtError(); 6799 6800 if (!getDerived().AlwaysRebuild() && 6801 !SubStmtChanged) 6802 return S; 6803 6804 return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 6805 Statements, 6806 S->getRBracLoc(), 6807 IsStmtExpr); 6808 } 6809 6810 template<typename Derived> 6811 StmtResult 6812 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 6813 ExprResult LHS, RHS; 6814 { 6815 EnterExpressionEvaluationContext Unevaluated( 6816 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 6817 6818 // Transform the left-hand case value. 6819 LHS = getDerived().TransformExpr(S->getLHS()); 6820 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS); 6821 if (LHS.isInvalid()) 6822 return StmtError(); 6823 6824 // Transform the right-hand case value (for the GNU case-range extension). 6825 RHS = getDerived().TransformExpr(S->getRHS()); 6826 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS); 6827 if (RHS.isInvalid()) 6828 return StmtError(); 6829 } 6830 6831 // Build the case statement. 6832 // Case statements are always rebuilt so that they will attached to their 6833 // transformed switch statement. 6834 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 6835 LHS.get(), 6836 S->getEllipsisLoc(), 6837 RHS.get(), 6838 S->getColonLoc()); 6839 if (Case.isInvalid()) 6840 return StmtError(); 6841 6842 // Transform the statement following the case 6843 StmtResult SubStmt = 6844 getDerived().TransformStmt(S->getSubStmt()); 6845 if (SubStmt.isInvalid()) 6846 return StmtError(); 6847 6848 // Attach the body to the case statement 6849 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 6850 } 6851 6852 template <typename Derived> 6853 StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 6854 // Transform the statement following the default case 6855 StmtResult SubStmt = 6856 getDerived().TransformStmt(S->getSubStmt()); 6857 if (SubStmt.isInvalid()) 6858 return StmtError(); 6859 6860 // Default statements are always rebuilt 6861 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 6862 SubStmt.get()); 6863 } 6864 6865 template<typename Derived> 6866 StmtResult 6867 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) { 6868 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); 6869 if (SubStmt.isInvalid()) 6870 return StmtError(); 6871 6872 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 6873 S->getDecl()); 6874 if (!LD) 6875 return StmtError(); 6876 6877 // If we're transforming "in-place" (we're not creating new local 6878 // declarations), assume we're replacing the old label statement 6879 // and clear out the reference to it. 6880 if (LD == S->getDecl()) 6881 S->getDecl()->setStmt(nullptr); 6882 6883 // FIXME: Pass the real colon location in. 6884 return getDerived().RebuildLabelStmt(S->getIdentLoc(), 6885 cast<LabelDecl>(LD), SourceLocation(), 6886 SubStmt.get()); 6887 } 6888 6889 template <typename Derived> 6890 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { 6891 if (!R) 6892 return R; 6893 6894 switch (R->getKind()) { 6895 // Transform attributes with a pragma spelling by calling TransformXXXAttr. 6896 #define ATTR(X) 6897 #define PRAGMA_SPELLING_ATTR(X) \ 6898 case attr::X: \ 6899 return getDerived().Transform##X##Attr(cast<X##Attr>(R)); 6900 #include "clang/Basic/AttrList.inc" 6901 default: 6902 return R; 6903 } 6904 } 6905 6906 template <typename Derived> 6907 StmtResult 6908 TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S, 6909 StmtDiscardKind SDK) { 6910 bool AttrsChanged = false; 6911 SmallVector<const Attr *, 1> Attrs; 6912 6913 // Visit attributes and keep track if any are transformed. 6914 for (const auto *I : S->getAttrs()) { 6915 const Attr *R = getDerived().TransformAttr(I); 6916 AttrsChanged |= (I != R); 6917 Attrs.push_back(R); 6918 } 6919 6920 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); 6921 if (SubStmt.isInvalid()) 6922 return StmtError(); 6923 6924 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) 6925 return S; 6926 6927 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, 6928 SubStmt.get()); 6929 } 6930 6931 template<typename Derived> 6932 StmtResult 6933 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 6934 // Transform the initialization statement 6935 StmtResult Init = getDerived().TransformStmt(S->getInit()); 6936 if (Init.isInvalid()) 6937 return StmtError(); 6938 6939 // Transform the condition 6940 Sema::ConditionResult Cond = getDerived().TransformCondition( 6941 S->getIfLoc(), S->getConditionVariable(), S->getCond(), 6942 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf 6943 : Sema::ConditionKind::Boolean); 6944 if (Cond.isInvalid()) 6945 return StmtError(); 6946 6947 // If this is a constexpr if, determine which arm we should instantiate. 6948 llvm::Optional<bool> ConstexprConditionValue; 6949 if (S->isConstexpr()) 6950 ConstexprConditionValue = Cond.getKnownValue(); 6951 6952 // Transform the "then" branch. 6953 StmtResult Then; 6954 if (!ConstexprConditionValue || *ConstexprConditionValue) { 6955 Then = getDerived().TransformStmt(S->getThen()); 6956 if (Then.isInvalid()) 6957 return StmtError(); 6958 } else { 6959 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc()); 6960 } 6961 6962 // Transform the "else" branch. 6963 StmtResult Else; 6964 if (!ConstexprConditionValue || !*ConstexprConditionValue) { 6965 Else = getDerived().TransformStmt(S->getElse()); 6966 if (Else.isInvalid()) 6967 return StmtError(); 6968 } 6969 6970 if (!getDerived().AlwaysRebuild() && 6971 Init.get() == S->getInit() && 6972 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && 6973 Then.get() == S->getThen() && 6974 Else.get() == S->getElse()) 6975 return S; 6976 6977 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond, 6978 Init.get(), Then.get(), S->getElseLoc(), 6979 Else.get()); 6980 } 6981 6982 template<typename Derived> 6983 StmtResult 6984 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 6985 // Transform the initialization statement 6986 StmtResult Init = getDerived().TransformStmt(S->getInit()); 6987 if (Init.isInvalid()) 6988 return StmtError(); 6989 6990 // Transform the condition. 6991 Sema::ConditionResult Cond = getDerived().TransformCondition( 6992 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(), 6993 Sema::ConditionKind::Switch); 6994 if (Cond.isInvalid()) 6995 return StmtError(); 6996 6997 // Rebuild the switch statement. 6998 StmtResult Switch 6999 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond); 7000 if (Switch.isInvalid()) 7001 return StmtError(); 7002 7003 // Transform the body of the switch statement. 7004 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7005 if (Body.isInvalid()) 7006 return StmtError(); 7007 7008 // Complete the switch statement. 7009 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 7010 Body.get()); 7011 } 7012 7013 template<typename Derived> 7014 StmtResult 7015 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 7016 // Transform the condition 7017 Sema::ConditionResult Cond = getDerived().TransformCondition( 7018 S->getWhileLoc(), S->getConditionVariable(), S->getCond(), 7019 Sema::ConditionKind::Boolean); 7020 if (Cond.isInvalid()) 7021 return StmtError(); 7022 7023 // Transform the body 7024 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7025 if (Body.isInvalid()) 7026 return StmtError(); 7027 7028 if (!getDerived().AlwaysRebuild() && 7029 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && 7030 Body.get() == S->getBody()) 7031 return Owned(S); 7032 7033 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get()); 7034 } 7035 7036 template<typename Derived> 7037 StmtResult 7038 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 7039 // Transform the body 7040 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7041 if (Body.isInvalid()) 7042 return StmtError(); 7043 7044 // Transform the condition 7045 ExprResult Cond = getDerived().TransformExpr(S->getCond()); 7046 if (Cond.isInvalid()) 7047 return StmtError(); 7048 7049 if (!getDerived().AlwaysRebuild() && 7050 Cond.get() == S->getCond() && 7051 Body.get() == S->getBody()) 7052 return S; 7053 7054 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 7055 /*FIXME:*/S->getWhileLoc(), Cond.get(), 7056 S->getRParenLoc()); 7057 } 7058 7059 template<typename Derived> 7060 StmtResult 7061 TreeTransform<Derived>::TransformForStmt(ForStmt *S) { 7062 if (getSema().getLangOpts().OpenMP) 7063 getSema().startOpenMPLoop(); 7064 7065 // Transform the initialization statement 7066 StmtResult Init = getDerived().TransformStmt(S->getInit()); 7067 if (Init.isInvalid()) 7068 return StmtError(); 7069 7070 // In OpenMP loop region loop control variable must be captured and be 7071 // private. Perform analysis of first part (if any). 7072 if (getSema().getLangOpts().OpenMP && Init.isUsable()) 7073 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get()); 7074 7075 // Transform the condition 7076 Sema::ConditionResult Cond = getDerived().TransformCondition( 7077 S->getForLoc(), S->getConditionVariable(), S->getCond(), 7078 Sema::ConditionKind::Boolean); 7079 if (Cond.isInvalid()) 7080 return StmtError(); 7081 7082 // Transform the increment 7083 ExprResult Inc = getDerived().TransformExpr(S->getInc()); 7084 if (Inc.isInvalid()) 7085 return StmtError(); 7086 7087 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); 7088 if (S->getInc() && !FullInc.get()) 7089 return StmtError(); 7090 7091 // Transform the body 7092 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7093 if (Body.isInvalid()) 7094 return StmtError(); 7095 7096 if (!getDerived().AlwaysRebuild() && 7097 Init.get() == S->getInit() && 7098 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && 7099 Inc.get() == S->getInc() && 7100 Body.get() == S->getBody()) 7101 return S; 7102 7103 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 7104 Init.get(), Cond, FullInc, 7105 S->getRParenLoc(), Body.get()); 7106 } 7107 7108 template<typename Derived> 7109 StmtResult 7110 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 7111 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 7112 S->getLabel()); 7113 if (!LD) 7114 return StmtError(); 7115 7116 // Goto statements must always be rebuilt, to resolve the label. 7117 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 7118 cast<LabelDecl>(LD)); 7119 } 7120 7121 template<typename Derived> 7122 StmtResult 7123 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 7124 ExprResult Target = getDerived().TransformExpr(S->getTarget()); 7125 if (Target.isInvalid()) 7126 return StmtError(); 7127 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); 7128 7129 if (!getDerived().AlwaysRebuild() && 7130 Target.get() == S->getTarget()) 7131 return S; 7132 7133 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 7134 Target.get()); 7135 } 7136 7137 template<typename Derived> 7138 StmtResult 7139 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 7140 return S; 7141 } 7142 7143 template<typename Derived> 7144 StmtResult 7145 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 7146 return S; 7147 } 7148 7149 template<typename Derived> 7150 StmtResult 7151 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 7152 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), 7153 /*NotCopyInit*/false); 7154 if (Result.isInvalid()) 7155 return StmtError(); 7156 7157 // FIXME: We always rebuild the return statement because there is no way 7158 // to tell whether the return type of the function has changed. 7159 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 7160 } 7161 7162 template<typename Derived> 7163 StmtResult 7164 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 7165 bool DeclChanged = false; 7166 SmallVector<Decl *, 4> Decls; 7167 for (auto *D : S->decls()) { 7168 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); 7169 if (!Transformed) 7170 return StmtError(); 7171 7172 if (Transformed != D) 7173 DeclChanged = true; 7174 7175 Decls.push_back(Transformed); 7176 } 7177 7178 if (!getDerived().AlwaysRebuild() && !DeclChanged) 7179 return S; 7180 7181 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc()); 7182 } 7183 7184 template<typename Derived> 7185 StmtResult 7186 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { 7187 7188 SmallVector<Expr*, 8> Constraints; 7189 SmallVector<Expr*, 8> Exprs; 7190 SmallVector<IdentifierInfo *, 4> Names; 7191 7192 ExprResult AsmString; 7193 SmallVector<Expr*, 8> Clobbers; 7194 7195 bool ExprsChanged = false; 7196 7197 // Go through the outputs. 7198 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 7199 Names.push_back(S->getOutputIdentifier(I)); 7200 7201 // No need to transform the constraint literal. 7202 Constraints.push_back(S->getOutputConstraintLiteral(I)); 7203 7204 // Transform the output expr. 7205 Expr *OutputExpr = S->getOutputExpr(I); 7206 ExprResult Result = getDerived().TransformExpr(OutputExpr); 7207 if (Result.isInvalid()) 7208 return StmtError(); 7209 7210 ExprsChanged |= Result.get() != OutputExpr; 7211 7212 Exprs.push_back(Result.get()); 7213 } 7214 7215 // Go through the inputs. 7216 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 7217 Names.push_back(S->getInputIdentifier(I)); 7218 7219 // No need to transform the constraint literal. 7220 Constraints.push_back(S->getInputConstraintLiteral(I)); 7221 7222 // Transform the input expr. 7223 Expr *InputExpr = S->getInputExpr(I); 7224 ExprResult Result = getDerived().TransformExpr(InputExpr); 7225 if (Result.isInvalid()) 7226 return StmtError(); 7227 7228 ExprsChanged |= Result.get() != InputExpr; 7229 7230 Exprs.push_back(Result.get()); 7231 } 7232 7233 // Go through the Labels. 7234 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) { 7235 Names.push_back(S->getLabelIdentifier(I)); 7236 7237 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I)); 7238 if (Result.isInvalid()) 7239 return StmtError(); 7240 ExprsChanged |= Result.get() != S->getLabelExpr(I); 7241 Exprs.push_back(Result.get()); 7242 } 7243 if (!getDerived().AlwaysRebuild() && !ExprsChanged) 7244 return S; 7245 7246 // Go through the clobbers. 7247 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 7248 Clobbers.push_back(S->getClobberStringLiteral(I)); 7249 7250 // No need to transform the asm string literal. 7251 AsmString = S->getAsmString(); 7252 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), 7253 S->isVolatile(), S->getNumOutputs(), 7254 S->getNumInputs(), Names.data(), 7255 Constraints, Exprs, AsmString.get(), 7256 Clobbers, S->getNumLabels(), 7257 S->getRParenLoc()); 7258 } 7259 7260 template<typename Derived> 7261 StmtResult 7262 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { 7263 ArrayRef<Token> AsmToks = 7264 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); 7265 7266 bool HadError = false, HadChange = false; 7267 7268 ArrayRef<Expr*> SrcExprs = S->getAllExprs(); 7269 SmallVector<Expr*, 8> TransformedExprs; 7270 TransformedExprs.reserve(SrcExprs.size()); 7271 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { 7272 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); 7273 if (!Result.isUsable()) { 7274 HadError = true; 7275 } else { 7276 HadChange |= (Result.get() != SrcExprs[i]); 7277 TransformedExprs.push_back(Result.get()); 7278 } 7279 } 7280 7281 if (HadError) return StmtError(); 7282 if (!HadChange && !getDerived().AlwaysRebuild()) 7283 return Owned(S); 7284 7285 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), 7286 AsmToks, S->getAsmString(), 7287 S->getNumOutputs(), S->getNumInputs(), 7288 S->getAllConstraints(), S->getClobbers(), 7289 TransformedExprs, S->getEndLoc()); 7290 } 7291 7292 // C++ Coroutines TS 7293 7294 template<typename Derived> 7295 StmtResult 7296 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) { 7297 auto *ScopeInfo = SemaRef.getCurFunction(); 7298 auto *FD = cast<FunctionDecl>(SemaRef.CurContext); 7299 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise && 7300 ScopeInfo->NeedsCoroutineSuspends && 7301 ScopeInfo->CoroutineSuspends.first == nullptr && 7302 ScopeInfo->CoroutineSuspends.second == nullptr && 7303 "expected clean scope info"); 7304 7305 // Set that we have (possibly-invalid) suspend points before we do anything 7306 // that may fail. 7307 ScopeInfo->setNeedsCoroutineSuspends(false); 7308 7309 // We re-build the coroutine promise object (and the coroutine parameters its 7310 // type and constructor depend on) based on the types used in our current 7311 // function. We must do so, and set it on the current FunctionScopeInfo, 7312 // before attempting to transform the other parts of the coroutine body 7313 // statement, such as the implicit suspend statements (because those 7314 // statements reference the FunctionScopeInfo::CoroutinePromise). 7315 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation())) 7316 return StmtError(); 7317 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation()); 7318 if (!Promise) 7319 return StmtError(); 7320 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise}); 7321 ScopeInfo->CoroutinePromise = Promise; 7322 7323 // Transform the implicit coroutine statements constructed using dependent 7324 // types during the previous parse: initial and final suspensions, the return 7325 // object, and others. We also transform the coroutine function's body. 7326 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt()); 7327 if (InitSuspend.isInvalid()) 7328 return StmtError(); 7329 StmtResult FinalSuspend = 7330 getDerived().TransformStmt(S->getFinalSuspendStmt()); 7331 if (FinalSuspend.isInvalid()) 7332 return StmtError(); 7333 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get()); 7334 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get())); 7335 7336 StmtResult BodyRes = getDerived().TransformStmt(S->getBody()); 7337 if (BodyRes.isInvalid()) 7338 return StmtError(); 7339 7340 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get()); 7341 if (Builder.isInvalid()) 7342 return StmtError(); 7343 7344 Expr *ReturnObject = S->getReturnValueInit(); 7345 assert(ReturnObject && "the return object is expected to be valid"); 7346 ExprResult Res = getDerived().TransformInitializer(ReturnObject, 7347 /*NoCopyInit*/ false); 7348 if (Res.isInvalid()) 7349 return StmtError(); 7350 Builder.ReturnValue = Res.get(); 7351 7352 // If during the previous parse the coroutine still had a dependent promise 7353 // statement, we may need to build some implicit coroutine statements 7354 // (such as exception and fallthrough handlers) for the first time. 7355 if (S->hasDependentPromiseType()) { 7356 // We can only build these statements, however, if the current promise type 7357 // is not dependent. 7358 if (!Promise->getType()->isDependentType()) { 7359 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() && 7360 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() && 7361 "these nodes should not have been built yet"); 7362 if (!Builder.buildDependentStatements()) 7363 return StmtError(); 7364 } 7365 } else { 7366 if (auto *OnFallthrough = S->getFallthroughHandler()) { 7367 StmtResult Res = getDerived().TransformStmt(OnFallthrough); 7368 if (Res.isInvalid()) 7369 return StmtError(); 7370 Builder.OnFallthrough = Res.get(); 7371 } 7372 7373 if (auto *OnException = S->getExceptionHandler()) { 7374 StmtResult Res = getDerived().TransformStmt(OnException); 7375 if (Res.isInvalid()) 7376 return StmtError(); 7377 Builder.OnException = Res.get(); 7378 } 7379 7380 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) { 7381 StmtResult Res = getDerived().TransformStmt(OnAllocFailure); 7382 if (Res.isInvalid()) 7383 return StmtError(); 7384 Builder.ReturnStmtOnAllocFailure = Res.get(); 7385 } 7386 7387 // Transform any additional statements we may have already built 7388 assert(S->getAllocate() && S->getDeallocate() && 7389 "allocation and deallocation calls must already be built"); 7390 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate()); 7391 if (AllocRes.isInvalid()) 7392 return StmtError(); 7393 Builder.Allocate = AllocRes.get(); 7394 7395 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate()); 7396 if (DeallocRes.isInvalid()) 7397 return StmtError(); 7398 Builder.Deallocate = DeallocRes.get(); 7399 7400 assert(S->getResultDecl() && "ResultDecl must already be built"); 7401 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl()); 7402 if (ResultDecl.isInvalid()) 7403 return StmtError(); 7404 Builder.ResultDecl = ResultDecl.get(); 7405 7406 if (auto *ReturnStmt = S->getReturnStmt()) { 7407 StmtResult Res = getDerived().TransformStmt(ReturnStmt); 7408 if (Res.isInvalid()) 7409 return StmtError(); 7410 Builder.ReturnStmt = Res.get(); 7411 } 7412 } 7413 7414 return getDerived().RebuildCoroutineBodyStmt(Builder); 7415 } 7416 7417 template<typename Derived> 7418 StmtResult 7419 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) { 7420 ExprResult Result = getDerived().TransformInitializer(S->getOperand(), 7421 /*NotCopyInit*/false); 7422 if (Result.isInvalid()) 7423 return StmtError(); 7424 7425 // Always rebuild; we don't know if this needs to be injected into a new 7426 // context or if the promise type has changed. 7427 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(), 7428 S->isImplicit()); 7429 } 7430 7431 template<typename Derived> 7432 ExprResult 7433 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) { 7434 ExprResult Result = getDerived().TransformInitializer(E->getOperand(), 7435 /*NotCopyInit*/false); 7436 if (Result.isInvalid()) 7437 return ExprError(); 7438 7439 // Always rebuild; we don't know if this needs to be injected into a new 7440 // context or if the promise type has changed. 7441 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(), 7442 E->isImplicit()); 7443 } 7444 7445 template <typename Derived> 7446 ExprResult 7447 TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) { 7448 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(), 7449 /*NotCopyInit*/ false); 7450 if (OperandResult.isInvalid()) 7451 return ExprError(); 7452 7453 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr( 7454 E->getOperatorCoawaitLookup()); 7455 7456 if (LookupResult.isInvalid()) 7457 return ExprError(); 7458 7459 // Always rebuild; we don't know if this needs to be injected into a new 7460 // context or if the promise type has changed. 7461 return getDerived().RebuildDependentCoawaitExpr( 7462 E->getKeywordLoc(), OperandResult.get(), 7463 cast<UnresolvedLookupExpr>(LookupResult.get())); 7464 } 7465 7466 template<typename Derived> 7467 ExprResult 7468 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) { 7469 ExprResult Result = getDerived().TransformInitializer(E->getOperand(), 7470 /*NotCopyInit*/false); 7471 if (Result.isInvalid()) 7472 return ExprError(); 7473 7474 // Always rebuild; we don't know if this needs to be injected into a new 7475 // context or if the promise type has changed. 7476 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get()); 7477 } 7478 7479 // Objective-C Statements. 7480 7481 template<typename Derived> 7482 StmtResult 7483 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 7484 // Transform the body of the @try. 7485 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 7486 if (TryBody.isInvalid()) 7487 return StmtError(); 7488 7489 // Transform the @catch statements (if present). 7490 bool AnyCatchChanged = false; 7491 SmallVector<Stmt*, 8> CatchStmts; 7492 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 7493 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 7494 if (Catch.isInvalid()) 7495 return StmtError(); 7496 if (Catch.get() != S->getCatchStmt(I)) 7497 AnyCatchChanged = true; 7498 CatchStmts.push_back(Catch.get()); 7499 } 7500 7501 // Transform the @finally statement (if present). 7502 StmtResult Finally; 7503 if (S->getFinallyStmt()) { 7504 Finally = getDerived().TransformStmt(S->getFinallyStmt()); 7505 if (Finally.isInvalid()) 7506 return StmtError(); 7507 } 7508 7509 // If nothing changed, just retain this statement. 7510 if (!getDerived().AlwaysRebuild() && 7511 TryBody.get() == S->getTryBody() && 7512 !AnyCatchChanged && 7513 Finally.get() == S->getFinallyStmt()) 7514 return S; 7515 7516 // Build a new statement. 7517 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 7518 CatchStmts, Finally.get()); 7519 } 7520 7521 template<typename Derived> 7522 StmtResult 7523 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 7524 // Transform the @catch parameter, if there is one. 7525 VarDecl *Var = nullptr; 7526 if (VarDecl *FromVar = S->getCatchParamDecl()) { 7527 TypeSourceInfo *TSInfo = nullptr; 7528 if (FromVar->getTypeSourceInfo()) { 7529 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 7530 if (!TSInfo) 7531 return StmtError(); 7532 } 7533 7534 QualType T; 7535 if (TSInfo) 7536 T = TSInfo->getType(); 7537 else { 7538 T = getDerived().TransformType(FromVar->getType()); 7539 if (T.isNull()) 7540 return StmtError(); 7541 } 7542 7543 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 7544 if (!Var) 7545 return StmtError(); 7546 } 7547 7548 StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 7549 if (Body.isInvalid()) 7550 return StmtError(); 7551 7552 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 7553 S->getRParenLoc(), 7554 Var, Body.get()); 7555 } 7556 7557 template<typename Derived> 7558 StmtResult 7559 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 7560 // Transform the body. 7561 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 7562 if (Body.isInvalid()) 7563 return StmtError(); 7564 7565 // If nothing changed, just retain this statement. 7566 if (!getDerived().AlwaysRebuild() && 7567 Body.get() == S->getFinallyBody()) 7568 return S; 7569 7570 // Build a new statement. 7571 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 7572 Body.get()); 7573 } 7574 7575 template<typename Derived> 7576 StmtResult 7577 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 7578 ExprResult Operand; 7579 if (S->getThrowExpr()) { 7580 Operand = getDerived().TransformExpr(S->getThrowExpr()); 7581 if (Operand.isInvalid()) 7582 return StmtError(); 7583 } 7584 7585 if (!getDerived().AlwaysRebuild() && 7586 Operand.get() == S->getThrowExpr()) 7587 return S; 7588 7589 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 7590 } 7591 7592 template<typename Derived> 7593 StmtResult 7594 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 7595 ObjCAtSynchronizedStmt *S) { 7596 // Transform the object we are locking. 7597 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 7598 if (Object.isInvalid()) 7599 return StmtError(); 7600 Object = 7601 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), 7602 Object.get()); 7603 if (Object.isInvalid()) 7604 return StmtError(); 7605 7606 // Transform the body. 7607 StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 7608 if (Body.isInvalid()) 7609 return StmtError(); 7610 7611 // If nothing change, just retain the current statement. 7612 if (!getDerived().AlwaysRebuild() && 7613 Object.get() == S->getSynchExpr() && 7614 Body.get() == S->getSynchBody()) 7615 return S; 7616 7617 // Build a new statement. 7618 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 7619 Object.get(), Body.get()); 7620 } 7621 7622 template<typename Derived> 7623 StmtResult 7624 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( 7625 ObjCAutoreleasePoolStmt *S) { 7626 // Transform the body. 7627 StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); 7628 if (Body.isInvalid()) 7629 return StmtError(); 7630 7631 // If nothing changed, just retain this statement. 7632 if (!getDerived().AlwaysRebuild() && 7633 Body.get() == S->getSubStmt()) 7634 return S; 7635 7636 // Build a new statement. 7637 return getDerived().RebuildObjCAutoreleasePoolStmt( 7638 S->getAtLoc(), Body.get()); 7639 } 7640 7641 template<typename Derived> 7642 StmtResult 7643 TreeTransform<Derived>::TransformObjCForCollectionStmt( 7644 ObjCForCollectionStmt *S) { 7645 // Transform the element statement. 7646 StmtResult Element = 7647 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded); 7648 if (Element.isInvalid()) 7649 return StmtError(); 7650 7651 // Transform the collection expression. 7652 ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 7653 if (Collection.isInvalid()) 7654 return StmtError(); 7655 7656 // Transform the body. 7657 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7658 if (Body.isInvalid()) 7659 return StmtError(); 7660 7661 // If nothing changed, just retain this statement. 7662 if (!getDerived().AlwaysRebuild() && 7663 Element.get() == S->getElement() && 7664 Collection.get() == S->getCollection() && 7665 Body.get() == S->getBody()) 7666 return S; 7667 7668 // Build a new statement. 7669 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 7670 Element.get(), 7671 Collection.get(), 7672 S->getRParenLoc(), 7673 Body.get()); 7674 } 7675 7676 template <typename Derived> 7677 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 7678 // Transform the exception declaration, if any. 7679 VarDecl *Var = nullptr; 7680 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { 7681 TypeSourceInfo *T = 7682 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); 7683 if (!T) 7684 return StmtError(); 7685 7686 Var = getDerived().RebuildExceptionDecl( 7687 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), 7688 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); 7689 if (!Var || Var->isInvalidDecl()) 7690 return StmtError(); 7691 } 7692 7693 // Transform the actual exception handler. 7694 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 7695 if (Handler.isInvalid()) 7696 return StmtError(); 7697 7698 if (!getDerived().AlwaysRebuild() && !Var && 7699 Handler.get() == S->getHandlerBlock()) 7700 return S; 7701 7702 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); 7703 } 7704 7705 template <typename Derived> 7706 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 7707 // Transform the try block itself. 7708 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); 7709 if (TryBlock.isInvalid()) 7710 return StmtError(); 7711 7712 // Transform the handlers. 7713 bool HandlerChanged = false; 7714 SmallVector<Stmt *, 8> Handlers; 7715 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 7716 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 7717 if (Handler.isInvalid()) 7718 return StmtError(); 7719 7720 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 7721 Handlers.push_back(Handler.getAs<Stmt>()); 7722 } 7723 7724 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && 7725 !HandlerChanged) 7726 return S; 7727 7728 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 7729 Handlers); 7730 } 7731 7732 template<typename Derived> 7733 StmtResult 7734 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { 7735 StmtResult Init = 7736 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult(); 7737 if (Init.isInvalid()) 7738 return StmtError(); 7739 7740 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); 7741 if (Range.isInvalid()) 7742 return StmtError(); 7743 7744 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt()); 7745 if (Begin.isInvalid()) 7746 return StmtError(); 7747 StmtResult End = getDerived().TransformStmt(S->getEndStmt()); 7748 if (End.isInvalid()) 7749 return StmtError(); 7750 7751 ExprResult Cond = getDerived().TransformExpr(S->getCond()); 7752 if (Cond.isInvalid()) 7753 return StmtError(); 7754 if (Cond.get()) 7755 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get()); 7756 if (Cond.isInvalid()) 7757 return StmtError(); 7758 if (Cond.get()) 7759 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); 7760 7761 ExprResult Inc = getDerived().TransformExpr(S->getInc()); 7762 if (Inc.isInvalid()) 7763 return StmtError(); 7764 if (Inc.get()) 7765 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); 7766 7767 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); 7768 if (LoopVar.isInvalid()) 7769 return StmtError(); 7770 7771 StmtResult NewStmt = S; 7772 if (getDerived().AlwaysRebuild() || 7773 Init.get() != S->getInit() || 7774 Range.get() != S->getRangeStmt() || 7775 Begin.get() != S->getBeginStmt() || 7776 End.get() != S->getEndStmt() || 7777 Cond.get() != S->getCond() || 7778 Inc.get() != S->getInc() || 7779 LoopVar.get() != S->getLoopVarStmt()) { 7780 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 7781 S->getCoawaitLoc(), Init.get(), 7782 S->getColonLoc(), Range.get(), 7783 Begin.get(), End.get(), 7784 Cond.get(), 7785 Inc.get(), LoopVar.get(), 7786 S->getRParenLoc()); 7787 if (NewStmt.isInvalid()) 7788 return StmtError(); 7789 } 7790 7791 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7792 if (Body.isInvalid()) 7793 return StmtError(); 7794 7795 // Body has changed but we didn't rebuild the for-range statement. Rebuild 7796 // it now so we have a new statement to attach the body to. 7797 if (Body.get() != S->getBody() && NewStmt.get() == S) { 7798 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 7799 S->getCoawaitLoc(), Init.get(), 7800 S->getColonLoc(), Range.get(), 7801 Begin.get(), End.get(), 7802 Cond.get(), 7803 Inc.get(), LoopVar.get(), 7804 S->getRParenLoc()); 7805 if (NewStmt.isInvalid()) 7806 return StmtError(); 7807 } 7808 7809 if (NewStmt.get() == S) 7810 return S; 7811 7812 return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); 7813 } 7814 7815 template<typename Derived> 7816 StmtResult 7817 TreeTransform<Derived>::TransformMSDependentExistsStmt( 7818 MSDependentExistsStmt *S) { 7819 // Transform the nested-name-specifier, if any. 7820 NestedNameSpecifierLoc QualifierLoc; 7821 if (S->getQualifierLoc()) { 7822 QualifierLoc 7823 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); 7824 if (!QualifierLoc) 7825 return StmtError(); 7826 } 7827 7828 // Transform the declaration name. 7829 DeclarationNameInfo NameInfo = S->getNameInfo(); 7830 if (NameInfo.getName()) { 7831 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 7832 if (!NameInfo.getName()) 7833 return StmtError(); 7834 } 7835 7836 // Check whether anything changed. 7837 if (!getDerived().AlwaysRebuild() && 7838 QualifierLoc == S->getQualifierLoc() && 7839 NameInfo.getName() == S->getNameInfo().getName()) 7840 return S; 7841 7842 // Determine whether this name exists, if we can. 7843 CXXScopeSpec SS; 7844 SS.Adopt(QualifierLoc); 7845 bool Dependent = false; 7846 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { 7847 case Sema::IER_Exists: 7848 if (S->isIfExists()) 7849 break; 7850 7851 return new (getSema().Context) NullStmt(S->getKeywordLoc()); 7852 7853 case Sema::IER_DoesNotExist: 7854 if (S->isIfNotExists()) 7855 break; 7856 7857 return new (getSema().Context) NullStmt(S->getKeywordLoc()); 7858 7859 case Sema::IER_Dependent: 7860 Dependent = true; 7861 break; 7862 7863 case Sema::IER_Error: 7864 return StmtError(); 7865 } 7866 7867 // We need to continue with the instantiation, so do so now. 7868 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); 7869 if (SubStmt.isInvalid()) 7870 return StmtError(); 7871 7872 // If we have resolved the name, just transform to the substatement. 7873 if (!Dependent) 7874 return SubStmt; 7875 7876 // The name is still dependent, so build a dependent expression again. 7877 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), 7878 S->isIfExists(), 7879 QualifierLoc, 7880 NameInfo, 7881 SubStmt.get()); 7882 } 7883 7884 template<typename Derived> 7885 ExprResult 7886 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { 7887 NestedNameSpecifierLoc QualifierLoc; 7888 if (E->getQualifierLoc()) { 7889 QualifierLoc 7890 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 7891 if (!QualifierLoc) 7892 return ExprError(); 7893 } 7894 7895 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( 7896 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); 7897 if (!PD) 7898 return ExprError(); 7899 7900 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); 7901 if (Base.isInvalid()) 7902 return ExprError(); 7903 7904 return new (SemaRef.getASTContext()) 7905 MSPropertyRefExpr(Base.get(), PD, E->isArrow(), 7906 SemaRef.getASTContext().PseudoObjectTy, VK_LValue, 7907 QualifierLoc, E->getMemberLoc()); 7908 } 7909 7910 template <typename Derived> 7911 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr( 7912 MSPropertySubscriptExpr *E) { 7913 auto BaseRes = getDerived().TransformExpr(E->getBase()); 7914 if (BaseRes.isInvalid()) 7915 return ExprError(); 7916 auto IdxRes = getDerived().TransformExpr(E->getIdx()); 7917 if (IdxRes.isInvalid()) 7918 return ExprError(); 7919 7920 if (!getDerived().AlwaysRebuild() && 7921 BaseRes.get() == E->getBase() && 7922 IdxRes.get() == E->getIdx()) 7923 return E; 7924 7925 return getDerived().RebuildArraySubscriptExpr( 7926 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc()); 7927 } 7928 7929 template <typename Derived> 7930 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { 7931 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); 7932 if (TryBlock.isInvalid()) 7933 return StmtError(); 7934 7935 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); 7936 if (Handler.isInvalid()) 7937 return StmtError(); 7938 7939 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && 7940 Handler.get() == S->getHandler()) 7941 return S; 7942 7943 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), 7944 TryBlock.get(), Handler.get()); 7945 } 7946 7947 template <typename Derived> 7948 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { 7949 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); 7950 if (Block.isInvalid()) 7951 return StmtError(); 7952 7953 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); 7954 } 7955 7956 template <typename Derived> 7957 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { 7958 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); 7959 if (FilterExpr.isInvalid()) 7960 return StmtError(); 7961 7962 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); 7963 if (Block.isInvalid()) 7964 return StmtError(); 7965 7966 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), 7967 Block.get()); 7968 } 7969 7970 template <typename Derived> 7971 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { 7972 if (isa<SEHFinallyStmt>(Handler)) 7973 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); 7974 else 7975 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); 7976 } 7977 7978 template<typename Derived> 7979 StmtResult 7980 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { 7981 return S; 7982 } 7983 7984 //===----------------------------------------------------------------------===// 7985 // OpenMP directive transformation 7986 //===----------------------------------------------------------------------===// 7987 template <typename Derived> 7988 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( 7989 OMPExecutableDirective *D) { 7990 7991 // Transform the clauses 7992 llvm::SmallVector<OMPClause *, 16> TClauses; 7993 ArrayRef<OMPClause *> Clauses = D->clauses(); 7994 TClauses.reserve(Clauses.size()); 7995 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); 7996 I != E; ++I) { 7997 if (*I) { 7998 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); 7999 OMPClause *Clause = getDerived().TransformOMPClause(*I); 8000 getDerived().getSema().EndOpenMPClause(); 8001 if (Clause) 8002 TClauses.push_back(Clause); 8003 } else { 8004 TClauses.push_back(nullptr); 8005 } 8006 } 8007 StmtResult AssociatedStmt; 8008 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { 8009 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), 8010 /*CurScope=*/nullptr); 8011 StmtResult Body; 8012 { 8013 Sema::CompoundScopeRAII CompoundScope(getSema()); 8014 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt(); 8015 Body = getDerived().TransformStmt(CS); 8016 } 8017 AssociatedStmt = 8018 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); 8019 if (AssociatedStmt.isInvalid()) { 8020 return StmtError(); 8021 } 8022 } 8023 if (TClauses.size() != Clauses.size()) { 8024 return StmtError(); 8025 } 8026 8027 // Transform directive name for 'omp critical' directive. 8028 DeclarationNameInfo DirName; 8029 if (D->getDirectiveKind() == OMPD_critical) { 8030 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); 8031 DirName = getDerived().TransformDeclarationNameInfo(DirName); 8032 } 8033 OpenMPDirectiveKind CancelRegion = OMPD_unknown; 8034 if (D->getDirectiveKind() == OMPD_cancellation_point) { 8035 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); 8036 } else if (D->getDirectiveKind() == OMPD_cancel) { 8037 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); 8038 } 8039 8040 return getDerived().RebuildOMPExecutableDirective( 8041 D->getDirectiveKind(), DirName, CancelRegion, TClauses, 8042 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc()); 8043 } 8044 8045 template <typename Derived> 8046 StmtResult 8047 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { 8048 DeclarationNameInfo DirName; 8049 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, 8050 D->getBeginLoc()); 8051 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8052 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8053 return Res; 8054 } 8055 8056 template <typename Derived> 8057 StmtResult 8058 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { 8059 DeclarationNameInfo DirName; 8060 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, 8061 D->getBeginLoc()); 8062 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8063 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8064 return Res; 8065 } 8066 8067 template <typename Derived> 8068 StmtResult 8069 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { 8070 DeclarationNameInfo DirName; 8071 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, 8072 D->getBeginLoc()); 8073 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8074 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8075 return Res; 8076 } 8077 8078 template <typename Derived> 8079 StmtResult 8080 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { 8081 DeclarationNameInfo DirName; 8082 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, 8083 D->getBeginLoc()); 8084 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8085 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8086 return Res; 8087 } 8088 8089 template <typename Derived> 8090 StmtResult 8091 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { 8092 DeclarationNameInfo DirName; 8093 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, 8094 D->getBeginLoc()); 8095 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8096 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8097 return Res; 8098 } 8099 8100 template <typename Derived> 8101 StmtResult 8102 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { 8103 DeclarationNameInfo DirName; 8104 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, 8105 D->getBeginLoc()); 8106 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8107 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8108 return Res; 8109 } 8110 8111 template <typename Derived> 8112 StmtResult 8113 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { 8114 DeclarationNameInfo DirName; 8115 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, 8116 D->getBeginLoc()); 8117 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8118 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8119 return Res; 8120 } 8121 8122 template <typename Derived> 8123 StmtResult 8124 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { 8125 DeclarationNameInfo DirName; 8126 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, 8127 D->getBeginLoc()); 8128 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8129 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8130 return Res; 8131 } 8132 8133 template <typename Derived> 8134 StmtResult 8135 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { 8136 getDerived().getSema().StartOpenMPDSABlock( 8137 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc()); 8138 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8139 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8140 return Res; 8141 } 8142 8143 template <typename Derived> 8144 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( 8145 OMPParallelForDirective *D) { 8146 DeclarationNameInfo DirName; 8147 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, 8148 nullptr, D->getBeginLoc()); 8149 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8150 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8151 return Res; 8152 } 8153 8154 template <typename Derived> 8155 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( 8156 OMPParallelForSimdDirective *D) { 8157 DeclarationNameInfo DirName; 8158 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, 8159 nullptr, D->getBeginLoc()); 8160 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8161 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8162 return Res; 8163 } 8164 8165 template <typename Derived> 8166 StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective( 8167 OMPParallelMasterDirective *D) { 8168 DeclarationNameInfo DirName; 8169 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master, DirName, 8170 nullptr, D->getBeginLoc()); 8171 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8172 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8173 return Res; 8174 } 8175 8176 template <typename Derived> 8177 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( 8178 OMPParallelSectionsDirective *D) { 8179 DeclarationNameInfo DirName; 8180 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, 8181 nullptr, D->getBeginLoc()); 8182 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8183 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8184 return Res; 8185 } 8186 8187 template <typename Derived> 8188 StmtResult 8189 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { 8190 DeclarationNameInfo DirName; 8191 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, 8192 D->getBeginLoc()); 8193 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8194 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8195 return Res; 8196 } 8197 8198 template <typename Derived> 8199 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( 8200 OMPTaskyieldDirective *D) { 8201 DeclarationNameInfo DirName; 8202 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, 8203 D->getBeginLoc()); 8204 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8205 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8206 return Res; 8207 } 8208 8209 template <typename Derived> 8210 StmtResult 8211 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { 8212 DeclarationNameInfo DirName; 8213 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, 8214 D->getBeginLoc()); 8215 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8216 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8217 return Res; 8218 } 8219 8220 template <typename Derived> 8221 StmtResult 8222 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { 8223 DeclarationNameInfo DirName; 8224 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, 8225 D->getBeginLoc()); 8226 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8227 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8228 return Res; 8229 } 8230 8231 template <typename Derived> 8232 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( 8233 OMPTaskgroupDirective *D) { 8234 DeclarationNameInfo DirName; 8235 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, 8236 D->getBeginLoc()); 8237 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8238 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8239 return Res; 8240 } 8241 8242 template <typename Derived> 8243 StmtResult 8244 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { 8245 DeclarationNameInfo DirName; 8246 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, 8247 D->getBeginLoc()); 8248 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8249 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8250 return Res; 8251 } 8252 8253 template <typename Derived> 8254 StmtResult 8255 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { 8256 DeclarationNameInfo DirName; 8257 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, 8258 D->getBeginLoc()); 8259 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8260 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8261 return Res; 8262 } 8263 8264 template <typename Derived> 8265 StmtResult 8266 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { 8267 DeclarationNameInfo DirName; 8268 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, 8269 D->getBeginLoc()); 8270 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8271 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8272 return Res; 8273 } 8274 8275 template <typename Derived> 8276 StmtResult 8277 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { 8278 DeclarationNameInfo DirName; 8279 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, 8280 D->getBeginLoc()); 8281 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8282 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8283 return Res; 8284 } 8285 8286 template <typename Derived> 8287 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( 8288 OMPTargetDataDirective *D) { 8289 DeclarationNameInfo DirName; 8290 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, 8291 D->getBeginLoc()); 8292 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8293 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8294 return Res; 8295 } 8296 8297 template <typename Derived> 8298 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective( 8299 OMPTargetEnterDataDirective *D) { 8300 DeclarationNameInfo DirName; 8301 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName, 8302 nullptr, D->getBeginLoc()); 8303 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8304 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8305 return Res; 8306 } 8307 8308 template <typename Derived> 8309 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective( 8310 OMPTargetExitDataDirective *D) { 8311 DeclarationNameInfo DirName; 8312 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName, 8313 nullptr, D->getBeginLoc()); 8314 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8315 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8316 return Res; 8317 } 8318 8319 template <typename Derived> 8320 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective( 8321 OMPTargetParallelDirective *D) { 8322 DeclarationNameInfo DirName; 8323 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName, 8324 nullptr, D->getBeginLoc()); 8325 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8326 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8327 return Res; 8328 } 8329 8330 template <typename Derived> 8331 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective( 8332 OMPTargetParallelForDirective *D) { 8333 DeclarationNameInfo DirName; 8334 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName, 8335 nullptr, D->getBeginLoc()); 8336 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8337 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8338 return Res; 8339 } 8340 8341 template <typename Derived> 8342 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective( 8343 OMPTargetUpdateDirective *D) { 8344 DeclarationNameInfo DirName; 8345 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName, 8346 nullptr, D->getBeginLoc()); 8347 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8348 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8349 return Res; 8350 } 8351 8352 template <typename Derived> 8353 StmtResult 8354 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { 8355 DeclarationNameInfo DirName; 8356 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, 8357 D->getBeginLoc()); 8358 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8359 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8360 return Res; 8361 } 8362 8363 template <typename Derived> 8364 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( 8365 OMPCancellationPointDirective *D) { 8366 DeclarationNameInfo DirName; 8367 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, 8368 nullptr, D->getBeginLoc()); 8369 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8370 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8371 return Res; 8372 } 8373 8374 template <typename Derived> 8375 StmtResult 8376 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { 8377 DeclarationNameInfo DirName; 8378 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, 8379 D->getBeginLoc()); 8380 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8381 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8382 return Res; 8383 } 8384 8385 template <typename Derived> 8386 StmtResult 8387 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { 8388 DeclarationNameInfo DirName; 8389 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr, 8390 D->getBeginLoc()); 8391 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8392 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8393 return Res; 8394 } 8395 8396 template <typename Derived> 8397 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective( 8398 OMPTaskLoopSimdDirective *D) { 8399 DeclarationNameInfo DirName; 8400 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName, 8401 nullptr, D->getBeginLoc()); 8402 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8403 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8404 return Res; 8405 } 8406 8407 template <typename Derived> 8408 StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective( 8409 OMPMasterTaskLoopDirective *D) { 8410 DeclarationNameInfo DirName; 8411 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop, DirName, 8412 nullptr, D->getBeginLoc()); 8413 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8414 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8415 return Res; 8416 } 8417 8418 template <typename Derived> 8419 StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective( 8420 OMPMasterTaskLoopSimdDirective *D) { 8421 DeclarationNameInfo DirName; 8422 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop_simd, DirName, 8423 nullptr, D->getBeginLoc()); 8424 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8425 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8426 return Res; 8427 } 8428 8429 template <typename Derived> 8430 StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective( 8431 OMPParallelMasterTaskLoopDirective *D) { 8432 DeclarationNameInfo DirName; 8433 getDerived().getSema().StartOpenMPDSABlock( 8434 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc()); 8435 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8436 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8437 return Res; 8438 } 8439 8440 template <typename Derived> 8441 StmtResult 8442 TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective( 8443 OMPParallelMasterTaskLoopSimdDirective *D) { 8444 DeclarationNameInfo DirName; 8445 getDerived().getSema().StartOpenMPDSABlock( 8446 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc()); 8447 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8448 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8449 return Res; 8450 } 8451 8452 template <typename Derived> 8453 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective( 8454 OMPDistributeDirective *D) { 8455 DeclarationNameInfo DirName; 8456 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr, 8457 D->getBeginLoc()); 8458 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8459 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8460 return Res; 8461 } 8462 8463 template <typename Derived> 8464 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective( 8465 OMPDistributeParallelForDirective *D) { 8466 DeclarationNameInfo DirName; 8467 getDerived().getSema().StartOpenMPDSABlock( 8468 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); 8469 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8470 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8471 return Res; 8472 } 8473 8474 template <typename Derived> 8475 StmtResult 8476 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective( 8477 OMPDistributeParallelForSimdDirective *D) { 8478 DeclarationNameInfo DirName; 8479 getDerived().getSema().StartOpenMPDSABlock( 8480 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); 8481 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8482 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8483 return Res; 8484 } 8485 8486 template <typename Derived> 8487 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective( 8488 OMPDistributeSimdDirective *D) { 8489 DeclarationNameInfo DirName; 8490 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName, 8491 nullptr, D->getBeginLoc()); 8492 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8493 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8494 return Res; 8495 } 8496 8497 template <typename Derived> 8498 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective( 8499 OMPTargetParallelForSimdDirective *D) { 8500 DeclarationNameInfo DirName; 8501 getDerived().getSema().StartOpenMPDSABlock( 8502 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); 8503 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8504 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8505 return Res; 8506 } 8507 8508 template <typename Derived> 8509 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective( 8510 OMPTargetSimdDirective *D) { 8511 DeclarationNameInfo DirName; 8512 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr, 8513 D->getBeginLoc()); 8514 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8515 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8516 return Res; 8517 } 8518 8519 template <typename Derived> 8520 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective( 8521 OMPTeamsDistributeDirective *D) { 8522 DeclarationNameInfo DirName; 8523 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName, 8524 nullptr, D->getBeginLoc()); 8525 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8526 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8527 return Res; 8528 } 8529 8530 template <typename Derived> 8531 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective( 8532 OMPTeamsDistributeSimdDirective *D) { 8533 DeclarationNameInfo DirName; 8534 getDerived().getSema().StartOpenMPDSABlock( 8535 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); 8536 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8537 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8538 return Res; 8539 } 8540 8541 template <typename Derived> 8542 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective( 8543 OMPTeamsDistributeParallelForSimdDirective *D) { 8544 DeclarationNameInfo DirName; 8545 getDerived().getSema().StartOpenMPDSABlock( 8546 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, 8547 D->getBeginLoc()); 8548 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8549 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8550 return Res; 8551 } 8552 8553 template <typename Derived> 8554 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective( 8555 OMPTeamsDistributeParallelForDirective *D) { 8556 DeclarationNameInfo DirName; 8557 getDerived().getSema().StartOpenMPDSABlock( 8558 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); 8559 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8560 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8561 return Res; 8562 } 8563 8564 template <typename Derived> 8565 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective( 8566 OMPTargetTeamsDirective *D) { 8567 DeclarationNameInfo DirName; 8568 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName, 8569 nullptr, D->getBeginLoc()); 8570 auto Res = getDerived().TransformOMPExecutableDirective(D); 8571 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8572 return Res; 8573 } 8574 8575 template <typename Derived> 8576 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective( 8577 OMPTargetTeamsDistributeDirective *D) { 8578 DeclarationNameInfo DirName; 8579 getDerived().getSema().StartOpenMPDSABlock( 8580 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc()); 8581 auto Res = getDerived().TransformOMPExecutableDirective(D); 8582 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8583 return Res; 8584 } 8585 8586 template <typename Derived> 8587 StmtResult 8588 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective( 8589 OMPTargetTeamsDistributeParallelForDirective *D) { 8590 DeclarationNameInfo DirName; 8591 getDerived().getSema().StartOpenMPDSABlock( 8592 OMPD_target_teams_distribute_parallel_for, DirName, nullptr, 8593 D->getBeginLoc()); 8594 auto Res = getDerived().TransformOMPExecutableDirective(D); 8595 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8596 return Res; 8597 } 8598 8599 template <typename Derived> 8600 StmtResult TreeTransform<Derived>:: 8601 TransformOMPTargetTeamsDistributeParallelForSimdDirective( 8602 OMPTargetTeamsDistributeParallelForSimdDirective *D) { 8603 DeclarationNameInfo DirName; 8604 getDerived().getSema().StartOpenMPDSABlock( 8605 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr, 8606 D->getBeginLoc()); 8607 auto Res = getDerived().TransformOMPExecutableDirective(D); 8608 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8609 return Res; 8610 } 8611 8612 template <typename Derived> 8613 StmtResult 8614 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective( 8615 OMPTargetTeamsDistributeSimdDirective *D) { 8616 DeclarationNameInfo DirName; 8617 getDerived().getSema().StartOpenMPDSABlock( 8618 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); 8619 auto Res = getDerived().TransformOMPExecutableDirective(D); 8620 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8621 return Res; 8622 } 8623 8624 8625 //===----------------------------------------------------------------------===// 8626 // OpenMP clause transformation 8627 //===----------------------------------------------------------------------===// 8628 template <typename Derived> 8629 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { 8630 ExprResult Cond = getDerived().TransformExpr(C->getCondition()); 8631 if (Cond.isInvalid()) 8632 return nullptr; 8633 return getDerived().RebuildOMPIfClause( 8634 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(), 8635 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc()); 8636 } 8637 8638 template <typename Derived> 8639 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { 8640 ExprResult Cond = getDerived().TransformExpr(C->getCondition()); 8641 if (Cond.isInvalid()) 8642 return nullptr; 8643 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(), 8644 C->getLParenLoc(), C->getEndLoc()); 8645 } 8646 8647 template <typename Derived> 8648 OMPClause * 8649 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { 8650 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); 8651 if (NumThreads.isInvalid()) 8652 return nullptr; 8653 return getDerived().RebuildOMPNumThreadsClause( 8654 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 8655 } 8656 8657 template <typename Derived> 8658 OMPClause * 8659 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { 8660 ExprResult E = getDerived().TransformExpr(C->getSafelen()); 8661 if (E.isInvalid()) 8662 return nullptr; 8663 return getDerived().RebuildOMPSafelenClause( 8664 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 8665 } 8666 8667 template <typename Derived> 8668 OMPClause * 8669 TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) { 8670 ExprResult E = getDerived().TransformExpr(C->getAllocator()); 8671 if (E.isInvalid()) 8672 return nullptr; 8673 return getDerived().RebuildOMPAllocatorClause( 8674 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 8675 } 8676 8677 template <typename Derived> 8678 OMPClause * 8679 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { 8680 ExprResult E = getDerived().TransformExpr(C->getSimdlen()); 8681 if (E.isInvalid()) 8682 return nullptr; 8683 return getDerived().RebuildOMPSimdlenClause( 8684 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 8685 } 8686 8687 template <typename Derived> 8688 OMPClause * 8689 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { 8690 ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); 8691 if (E.isInvalid()) 8692 return nullptr; 8693 return getDerived().RebuildOMPCollapseClause( 8694 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 8695 } 8696 8697 template <typename Derived> 8698 OMPClause * 8699 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { 8700 return getDerived().RebuildOMPDefaultClause( 8701 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(), 8702 C->getLParenLoc(), C->getEndLoc()); 8703 } 8704 8705 template <typename Derived> 8706 OMPClause * 8707 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { 8708 return getDerived().RebuildOMPProcBindClause( 8709 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(), 8710 C->getLParenLoc(), C->getEndLoc()); 8711 } 8712 8713 template <typename Derived> 8714 OMPClause * 8715 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { 8716 ExprResult E = getDerived().TransformExpr(C->getChunkSize()); 8717 if (E.isInvalid()) 8718 return nullptr; 8719 return getDerived().RebuildOMPScheduleClause( 8720 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(), 8721 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), 8722 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(), 8723 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); 8724 } 8725 8726 template <typename Derived> 8727 OMPClause * 8728 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { 8729 ExprResult E; 8730 if (auto *Num = C->getNumForLoops()) { 8731 E = getDerived().TransformExpr(Num); 8732 if (E.isInvalid()) 8733 return nullptr; 8734 } 8735 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(), 8736 C->getLParenLoc(), E.get()); 8737 } 8738 8739 template <typename Derived> 8740 OMPClause * 8741 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { 8742 // No need to rebuild this clause, no template-dependent parameters. 8743 return C; 8744 } 8745 8746 template <typename Derived> 8747 OMPClause * 8748 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { 8749 // No need to rebuild this clause, no template-dependent parameters. 8750 return C; 8751 } 8752 8753 template <typename Derived> 8754 OMPClause * 8755 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { 8756 // No need to rebuild this clause, no template-dependent parameters. 8757 return C; 8758 } 8759 8760 template <typename Derived> 8761 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { 8762 // No need to rebuild this clause, no template-dependent parameters. 8763 return C; 8764 } 8765 8766 template <typename Derived> 8767 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { 8768 // No need to rebuild this clause, no template-dependent parameters. 8769 return C; 8770 } 8771 8772 template <typename Derived> 8773 OMPClause * 8774 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { 8775 // No need to rebuild this clause, no template-dependent parameters. 8776 return C; 8777 } 8778 8779 template <typename Derived> 8780 OMPClause * 8781 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { 8782 // No need to rebuild this clause, no template-dependent parameters. 8783 return C; 8784 } 8785 8786 template <typename Derived> 8787 OMPClause * 8788 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { 8789 // No need to rebuild this clause, no template-dependent parameters. 8790 return C; 8791 } 8792 8793 template <typename Derived> 8794 OMPClause * 8795 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { 8796 // No need to rebuild this clause, no template-dependent parameters. 8797 return C; 8798 } 8799 8800 template <typename Derived> 8801 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { 8802 // No need to rebuild this clause, no template-dependent parameters. 8803 return C; 8804 } 8805 8806 template <typename Derived> 8807 OMPClause * 8808 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) { 8809 // No need to rebuild this clause, no template-dependent parameters. 8810 return C; 8811 } 8812 8813 template <typename Derived> 8814 OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause( 8815 OMPUnifiedAddressClause *C) { 8816 llvm_unreachable("unified_address clause cannot appear in dependent context"); 8817 } 8818 8819 template <typename Derived> 8820 OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause( 8821 OMPUnifiedSharedMemoryClause *C) { 8822 llvm_unreachable( 8823 "unified_shared_memory clause cannot appear in dependent context"); 8824 } 8825 8826 template <typename Derived> 8827 OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause( 8828 OMPReverseOffloadClause *C) { 8829 llvm_unreachable("reverse_offload clause cannot appear in dependent context"); 8830 } 8831 8832 template <typename Derived> 8833 OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause( 8834 OMPDynamicAllocatorsClause *C) { 8835 llvm_unreachable( 8836 "dynamic_allocators clause cannot appear in dependent context"); 8837 } 8838 8839 template <typename Derived> 8840 OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause( 8841 OMPAtomicDefaultMemOrderClause *C) { 8842 llvm_unreachable( 8843 "atomic_default_mem_order clause cannot appear in dependent context"); 8844 } 8845 8846 template <typename Derived> 8847 OMPClause * 8848 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { 8849 llvm::SmallVector<Expr *, 16> Vars; 8850 Vars.reserve(C->varlist_size()); 8851 for (auto *VE : C->varlists()) { 8852 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 8853 if (EVar.isInvalid()) 8854 return nullptr; 8855 Vars.push_back(EVar.get()); 8856 } 8857 return getDerived().RebuildOMPPrivateClause( 8858 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 8859 } 8860 8861 template <typename Derived> 8862 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( 8863 OMPFirstprivateClause *C) { 8864 llvm::SmallVector<Expr *, 16> Vars; 8865 Vars.reserve(C->varlist_size()); 8866 for (auto *VE : C->varlists()) { 8867 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 8868 if (EVar.isInvalid()) 8869 return nullptr; 8870 Vars.push_back(EVar.get()); 8871 } 8872 return getDerived().RebuildOMPFirstprivateClause( 8873 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 8874 } 8875 8876 template <typename Derived> 8877 OMPClause * 8878 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { 8879 llvm::SmallVector<Expr *, 16> Vars; 8880 Vars.reserve(C->varlist_size()); 8881 for (auto *VE : C->varlists()) { 8882 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 8883 if (EVar.isInvalid()) 8884 return nullptr; 8885 Vars.push_back(EVar.get()); 8886 } 8887 return getDerived().RebuildOMPLastprivateClause( 8888 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(), 8889 C->getLParenLoc(), C->getEndLoc()); 8890 } 8891 8892 template <typename Derived> 8893 OMPClause * 8894 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { 8895 llvm::SmallVector<Expr *, 16> Vars; 8896 Vars.reserve(C->varlist_size()); 8897 for (auto *VE : C->varlists()) { 8898 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 8899 if (EVar.isInvalid()) 8900 return nullptr; 8901 Vars.push_back(EVar.get()); 8902 } 8903 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(), 8904 C->getLParenLoc(), C->getEndLoc()); 8905 } 8906 8907 template <typename Derived> 8908 OMPClause * 8909 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { 8910 llvm::SmallVector<Expr *, 16> Vars; 8911 Vars.reserve(C->varlist_size()); 8912 for (auto *VE : C->varlists()) { 8913 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 8914 if (EVar.isInvalid()) 8915 return nullptr; 8916 Vars.push_back(EVar.get()); 8917 } 8918 CXXScopeSpec ReductionIdScopeSpec; 8919 ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); 8920 8921 DeclarationNameInfo NameInfo = C->getNameInfo(); 8922 if (NameInfo.getName()) { 8923 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 8924 if (!NameInfo.getName()) 8925 return nullptr; 8926 } 8927 // Build a list of all UDR decls with the same names ranged by the Scopes. 8928 // The Scope boundary is a duplication of the previous decl. 8929 llvm::SmallVector<Expr *, 16> UnresolvedReductions; 8930 for (auto *E : C->reduction_ops()) { 8931 // Transform all the decls. 8932 if (E) { 8933 auto *ULE = cast<UnresolvedLookupExpr>(E); 8934 UnresolvedSet<8> Decls; 8935 for (auto *D : ULE->decls()) { 8936 NamedDecl *InstD = 8937 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); 8938 Decls.addDecl(InstD, InstD->getAccess()); 8939 } 8940 UnresolvedReductions.push_back( 8941 UnresolvedLookupExpr::Create( 8942 SemaRef.Context, /*NamingClass=*/nullptr, 8943 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), 8944 NameInfo, /*ADL=*/true, ULE->isOverloaded(), 8945 Decls.begin(), Decls.end())); 8946 } else 8947 UnresolvedReductions.push_back(nullptr); 8948 } 8949 return getDerived().RebuildOMPReductionClause( 8950 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), 8951 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); 8952 } 8953 8954 template <typename Derived> 8955 OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause( 8956 OMPTaskReductionClause *C) { 8957 llvm::SmallVector<Expr *, 16> Vars; 8958 Vars.reserve(C->varlist_size()); 8959 for (auto *VE : C->varlists()) { 8960 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 8961 if (EVar.isInvalid()) 8962 return nullptr; 8963 Vars.push_back(EVar.get()); 8964 } 8965 CXXScopeSpec ReductionIdScopeSpec; 8966 ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); 8967 8968 DeclarationNameInfo NameInfo = C->getNameInfo(); 8969 if (NameInfo.getName()) { 8970 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 8971 if (!NameInfo.getName()) 8972 return nullptr; 8973 } 8974 // Build a list of all UDR decls with the same names ranged by the Scopes. 8975 // The Scope boundary is a duplication of the previous decl. 8976 llvm::SmallVector<Expr *, 16> UnresolvedReductions; 8977 for (auto *E : C->reduction_ops()) { 8978 // Transform all the decls. 8979 if (E) { 8980 auto *ULE = cast<UnresolvedLookupExpr>(E); 8981 UnresolvedSet<8> Decls; 8982 for (auto *D : ULE->decls()) { 8983 NamedDecl *InstD = 8984 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); 8985 Decls.addDecl(InstD, InstD->getAccess()); 8986 } 8987 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( 8988 SemaRef.Context, /*NamingClass=*/nullptr, 8989 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, 8990 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); 8991 } else 8992 UnresolvedReductions.push_back(nullptr); 8993 } 8994 return getDerived().RebuildOMPTaskReductionClause( 8995 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), 8996 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); 8997 } 8998 8999 template <typename Derived> 9000 OMPClause * 9001 TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) { 9002 llvm::SmallVector<Expr *, 16> Vars; 9003 Vars.reserve(C->varlist_size()); 9004 for (auto *VE : C->varlists()) { 9005 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9006 if (EVar.isInvalid()) 9007 return nullptr; 9008 Vars.push_back(EVar.get()); 9009 } 9010 CXXScopeSpec ReductionIdScopeSpec; 9011 ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); 9012 9013 DeclarationNameInfo NameInfo = C->getNameInfo(); 9014 if (NameInfo.getName()) { 9015 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 9016 if (!NameInfo.getName()) 9017 return nullptr; 9018 } 9019 // Build a list of all UDR decls with the same names ranged by the Scopes. 9020 // The Scope boundary is a duplication of the previous decl. 9021 llvm::SmallVector<Expr *, 16> UnresolvedReductions; 9022 for (auto *E : C->reduction_ops()) { 9023 // Transform all the decls. 9024 if (E) { 9025 auto *ULE = cast<UnresolvedLookupExpr>(E); 9026 UnresolvedSet<8> Decls; 9027 for (auto *D : ULE->decls()) { 9028 NamedDecl *InstD = 9029 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); 9030 Decls.addDecl(InstD, InstD->getAccess()); 9031 } 9032 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( 9033 SemaRef.Context, /*NamingClass=*/nullptr, 9034 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, 9035 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); 9036 } else 9037 UnresolvedReductions.push_back(nullptr); 9038 } 9039 return getDerived().RebuildOMPInReductionClause( 9040 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), 9041 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); 9042 } 9043 9044 template <typename Derived> 9045 OMPClause * 9046 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { 9047 llvm::SmallVector<Expr *, 16> Vars; 9048 Vars.reserve(C->varlist_size()); 9049 for (auto *VE : C->varlists()) { 9050 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9051 if (EVar.isInvalid()) 9052 return nullptr; 9053 Vars.push_back(EVar.get()); 9054 } 9055 ExprResult Step = getDerived().TransformExpr(C->getStep()); 9056 if (Step.isInvalid()) 9057 return nullptr; 9058 return getDerived().RebuildOMPLinearClause( 9059 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(), 9060 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc()); 9061 } 9062 9063 template <typename Derived> 9064 OMPClause * 9065 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { 9066 llvm::SmallVector<Expr *, 16> Vars; 9067 Vars.reserve(C->varlist_size()); 9068 for (auto *VE : C->varlists()) { 9069 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9070 if (EVar.isInvalid()) 9071 return nullptr; 9072 Vars.push_back(EVar.get()); 9073 } 9074 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); 9075 if (Alignment.isInvalid()) 9076 return nullptr; 9077 return getDerived().RebuildOMPAlignedClause( 9078 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(), 9079 C->getColonLoc(), C->getEndLoc()); 9080 } 9081 9082 template <typename Derived> 9083 OMPClause * 9084 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { 9085 llvm::SmallVector<Expr *, 16> Vars; 9086 Vars.reserve(C->varlist_size()); 9087 for (auto *VE : C->varlists()) { 9088 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9089 if (EVar.isInvalid()) 9090 return nullptr; 9091 Vars.push_back(EVar.get()); 9092 } 9093 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(), 9094 C->getLParenLoc(), C->getEndLoc()); 9095 } 9096 9097 template <typename Derived> 9098 OMPClause * 9099 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { 9100 llvm::SmallVector<Expr *, 16> Vars; 9101 Vars.reserve(C->varlist_size()); 9102 for (auto *VE : C->varlists()) { 9103 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9104 if (EVar.isInvalid()) 9105 return nullptr; 9106 Vars.push_back(EVar.get()); 9107 } 9108 return getDerived().RebuildOMPCopyprivateClause( 9109 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9110 } 9111 9112 template <typename Derived> 9113 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { 9114 llvm::SmallVector<Expr *, 16> Vars; 9115 Vars.reserve(C->varlist_size()); 9116 for (auto *VE : C->varlists()) { 9117 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9118 if (EVar.isInvalid()) 9119 return nullptr; 9120 Vars.push_back(EVar.get()); 9121 } 9122 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(), 9123 C->getLParenLoc(), C->getEndLoc()); 9124 } 9125 9126 template <typename Derived> 9127 OMPClause * 9128 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { 9129 llvm::SmallVector<Expr *, 16> Vars; 9130 Vars.reserve(C->varlist_size()); 9131 for (auto *VE : C->varlists()) { 9132 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9133 if (EVar.isInvalid()) 9134 return nullptr; 9135 Vars.push_back(EVar.get()); 9136 } 9137 return getDerived().RebuildOMPDependClause( 9138 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars, 9139 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9140 } 9141 9142 template <typename Derived> 9143 OMPClause * 9144 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { 9145 ExprResult E = getDerived().TransformExpr(C->getDevice()); 9146 if (E.isInvalid()) 9147 return nullptr; 9148 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(), 9149 C->getLParenLoc(), C->getEndLoc()); 9150 } 9151 9152 template <typename Derived, class T> 9153 bool transformOMPMappableExprListClause( 9154 TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C, 9155 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec, 9156 DeclarationNameInfo &MapperIdInfo, 9157 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) { 9158 // Transform expressions in the list. 9159 Vars.reserve(C->varlist_size()); 9160 for (auto *VE : C->varlists()) { 9161 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE)); 9162 if (EVar.isInvalid()) 9163 return true; 9164 Vars.push_back(EVar.get()); 9165 } 9166 // Transform mapper scope specifier and identifier. 9167 NestedNameSpecifierLoc QualifierLoc; 9168 if (C->getMapperQualifierLoc()) { 9169 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc( 9170 C->getMapperQualifierLoc()); 9171 if (!QualifierLoc) 9172 return true; 9173 } 9174 MapperIdScopeSpec.Adopt(QualifierLoc); 9175 MapperIdInfo = C->getMapperIdInfo(); 9176 if (MapperIdInfo.getName()) { 9177 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo); 9178 if (!MapperIdInfo.getName()) 9179 return true; 9180 } 9181 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by 9182 // the previous user-defined mapper lookup in dependent environment. 9183 for (auto *E : C->mapperlists()) { 9184 // Transform all the decls. 9185 if (E) { 9186 auto *ULE = cast<UnresolvedLookupExpr>(E); 9187 UnresolvedSet<8> Decls; 9188 for (auto *D : ULE->decls()) { 9189 NamedDecl *InstD = 9190 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D)); 9191 Decls.addDecl(InstD, InstD->getAccess()); 9192 } 9193 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create( 9194 TT.getSema().Context, /*NamingClass=*/nullptr, 9195 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context), 9196 MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), 9197 Decls.end())); 9198 } else { 9199 UnresolvedMappers.push_back(nullptr); 9200 } 9201 } 9202 return false; 9203 } 9204 9205 template <typename Derived> 9206 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) { 9207 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9208 llvm::SmallVector<Expr *, 16> Vars; 9209 CXXScopeSpec MapperIdScopeSpec; 9210 DeclarationNameInfo MapperIdInfo; 9211 llvm::SmallVector<Expr *, 16> UnresolvedMappers; 9212 if (transformOMPMappableExprListClause<Derived, OMPMapClause>( 9213 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) 9214 return nullptr; 9215 return getDerived().RebuildOMPMapClause( 9216 C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec, 9217 MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(), 9218 C->getColonLoc(), Vars, Locs, UnresolvedMappers); 9219 } 9220 9221 template <typename Derived> 9222 OMPClause * 9223 TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) { 9224 Expr *Allocator = C->getAllocator(); 9225 if (Allocator) { 9226 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator); 9227 if (AllocatorRes.isInvalid()) 9228 return nullptr; 9229 Allocator = AllocatorRes.get(); 9230 } 9231 llvm::SmallVector<Expr *, 16> Vars; 9232 Vars.reserve(C->varlist_size()); 9233 for (auto *VE : C->varlists()) { 9234 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9235 if (EVar.isInvalid()) 9236 return nullptr; 9237 Vars.push_back(EVar.get()); 9238 } 9239 return getDerived().RebuildOMPAllocateClause( 9240 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), 9241 C->getEndLoc()); 9242 } 9243 9244 template <typename Derived> 9245 OMPClause * 9246 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { 9247 ExprResult E = getDerived().TransformExpr(C->getNumTeams()); 9248 if (E.isInvalid()) 9249 return nullptr; 9250 return getDerived().RebuildOMPNumTeamsClause( 9251 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9252 } 9253 9254 template <typename Derived> 9255 OMPClause * 9256 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) { 9257 ExprResult E = getDerived().TransformExpr(C->getThreadLimit()); 9258 if (E.isInvalid()) 9259 return nullptr; 9260 return getDerived().RebuildOMPThreadLimitClause( 9261 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9262 } 9263 9264 template <typename Derived> 9265 OMPClause * 9266 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) { 9267 ExprResult E = getDerived().TransformExpr(C->getPriority()); 9268 if (E.isInvalid()) 9269 return nullptr; 9270 return getDerived().RebuildOMPPriorityClause( 9271 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9272 } 9273 9274 template <typename Derived> 9275 OMPClause * 9276 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { 9277 ExprResult E = getDerived().TransformExpr(C->getGrainsize()); 9278 if (E.isInvalid()) 9279 return nullptr; 9280 return getDerived().RebuildOMPGrainsizeClause( 9281 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9282 } 9283 9284 template <typename Derived> 9285 OMPClause * 9286 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) { 9287 ExprResult E = getDerived().TransformExpr(C->getNumTasks()); 9288 if (E.isInvalid()) 9289 return nullptr; 9290 return getDerived().RebuildOMPNumTasksClause( 9291 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9292 } 9293 9294 template <typename Derived> 9295 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) { 9296 ExprResult E = getDerived().TransformExpr(C->getHint()); 9297 if (E.isInvalid()) 9298 return nullptr; 9299 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(), 9300 C->getLParenLoc(), C->getEndLoc()); 9301 } 9302 9303 template <typename Derived> 9304 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause( 9305 OMPDistScheduleClause *C) { 9306 ExprResult E = getDerived().TransformExpr(C->getChunkSize()); 9307 if (E.isInvalid()) 9308 return nullptr; 9309 return getDerived().RebuildOMPDistScheduleClause( 9310 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), 9311 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); 9312 } 9313 9314 template <typename Derived> 9315 OMPClause * 9316 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) { 9317 // Rebuild Defaultmap Clause since we need to invoke the checking of 9318 // defaultmap(none:variable-category) after template initialization. 9319 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(), 9320 C->getDefaultmapKind(), 9321 C->getBeginLoc(), 9322 C->getLParenLoc(), 9323 C->getDefaultmapModifierLoc(), 9324 C->getDefaultmapKindLoc(), 9325 C->getEndLoc()); 9326 } 9327 9328 template <typename Derived> 9329 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) { 9330 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9331 llvm::SmallVector<Expr *, 16> Vars; 9332 CXXScopeSpec MapperIdScopeSpec; 9333 DeclarationNameInfo MapperIdInfo; 9334 llvm::SmallVector<Expr *, 16> UnresolvedMappers; 9335 if (transformOMPMappableExprListClause<Derived, OMPToClause>( 9336 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) 9337 return nullptr; 9338 return getDerived().RebuildOMPToClause(Vars, MapperIdScopeSpec, MapperIdInfo, 9339 Locs, UnresolvedMappers); 9340 } 9341 9342 template <typename Derived> 9343 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) { 9344 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9345 llvm::SmallVector<Expr *, 16> Vars; 9346 CXXScopeSpec MapperIdScopeSpec; 9347 DeclarationNameInfo MapperIdInfo; 9348 llvm::SmallVector<Expr *, 16> UnresolvedMappers; 9349 if (transformOMPMappableExprListClause<Derived, OMPFromClause>( 9350 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) 9351 return nullptr; 9352 return getDerived().RebuildOMPFromClause( 9353 Vars, MapperIdScopeSpec, MapperIdInfo, Locs, UnresolvedMappers); 9354 } 9355 9356 template <typename Derived> 9357 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause( 9358 OMPUseDevicePtrClause *C) { 9359 llvm::SmallVector<Expr *, 16> Vars; 9360 Vars.reserve(C->varlist_size()); 9361 for (auto *VE : C->varlists()) { 9362 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9363 if (EVar.isInvalid()) 9364 return nullptr; 9365 Vars.push_back(EVar.get()); 9366 } 9367 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9368 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs); 9369 } 9370 9371 template <typename Derived> 9372 OMPClause * 9373 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { 9374 llvm::SmallVector<Expr *, 16> Vars; 9375 Vars.reserve(C->varlist_size()); 9376 for (auto *VE : C->varlists()) { 9377 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9378 if (EVar.isInvalid()) 9379 return nullptr; 9380 Vars.push_back(EVar.get()); 9381 } 9382 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9383 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs); 9384 } 9385 9386 template <typename Derived> 9387 OMPClause * 9388 TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) { 9389 llvm::SmallVector<Expr *, 16> Vars; 9390 Vars.reserve(C->varlist_size()); 9391 for (auto *VE : C->varlists()) { 9392 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 9393 if (EVar.isInvalid()) 9394 return nullptr; 9395 Vars.push_back(EVar.get()); 9396 } 9397 return getDerived().RebuildOMPNontemporalClause( 9398 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9399 } 9400 9401 //===----------------------------------------------------------------------===// 9402 // Expression transformation 9403 //===----------------------------------------------------------------------===// 9404 template<typename Derived> 9405 ExprResult 9406 TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) { 9407 return TransformExpr(E->getSubExpr()); 9408 } 9409 9410 template<typename Derived> 9411 ExprResult 9412 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 9413 if (!E->isTypeDependent()) 9414 return E; 9415 9416 return getDerived().RebuildPredefinedExpr(E->getLocation(), 9417 E->getIdentKind()); 9418 } 9419 9420 template<typename Derived> 9421 ExprResult 9422 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 9423 NestedNameSpecifierLoc QualifierLoc; 9424 if (E->getQualifierLoc()) { 9425 QualifierLoc 9426 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 9427 if (!QualifierLoc) 9428 return ExprError(); 9429 } 9430 9431 ValueDecl *ND 9432 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 9433 E->getDecl())); 9434 if (!ND) 9435 return ExprError(); 9436 9437 NamedDecl *Found = ND; 9438 if (E->getFoundDecl() != E->getDecl()) { 9439 Found = cast_or_null<NamedDecl>( 9440 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl())); 9441 if (!Found) 9442 return ExprError(); 9443 } 9444 9445 DeclarationNameInfo NameInfo = E->getNameInfo(); 9446 if (NameInfo.getName()) { 9447 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 9448 if (!NameInfo.getName()) 9449 return ExprError(); 9450 } 9451 9452 if (!getDerived().AlwaysRebuild() && 9453 QualifierLoc == E->getQualifierLoc() && 9454 ND == E->getDecl() && 9455 Found == E->getFoundDecl() && 9456 NameInfo.getName() == E->getDecl()->getDeclName() && 9457 !E->hasExplicitTemplateArgs()) { 9458 9459 // Mark it referenced in the new context regardless. 9460 // FIXME: this is a bit instantiation-specific. 9461 SemaRef.MarkDeclRefReferenced(E); 9462 9463 return E; 9464 } 9465 9466 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; 9467 if (E->hasExplicitTemplateArgs()) { 9468 TemplateArgs = &TransArgs; 9469 TransArgs.setLAngleLoc(E->getLAngleLoc()); 9470 TransArgs.setRAngleLoc(E->getRAngleLoc()); 9471 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 9472 E->getNumTemplateArgs(), 9473 TransArgs)) 9474 return ExprError(); 9475 } 9476 9477 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 9478 Found, TemplateArgs); 9479 } 9480 9481 template<typename Derived> 9482 ExprResult 9483 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 9484 return E; 9485 } 9486 9487 template <typename Derived> 9488 ExprResult TreeTransform<Derived>::TransformFixedPointLiteral( 9489 FixedPointLiteral *E) { 9490 return E; 9491 } 9492 9493 template<typename Derived> 9494 ExprResult 9495 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 9496 return E; 9497 } 9498 9499 template<typename Derived> 9500 ExprResult 9501 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 9502 return E; 9503 } 9504 9505 template<typename Derived> 9506 ExprResult 9507 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 9508 return E; 9509 } 9510 9511 template<typename Derived> 9512 ExprResult 9513 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 9514 return E; 9515 } 9516 9517 template<typename Derived> 9518 ExprResult 9519 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { 9520 if (FunctionDecl *FD = E->getDirectCallee()) 9521 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD); 9522 return SemaRef.MaybeBindToTemporary(E); 9523 } 9524 9525 template<typename Derived> 9526 ExprResult 9527 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { 9528 ExprResult ControllingExpr = 9529 getDerived().TransformExpr(E->getControllingExpr()); 9530 if (ControllingExpr.isInvalid()) 9531 return ExprError(); 9532 9533 SmallVector<Expr *, 4> AssocExprs; 9534 SmallVector<TypeSourceInfo *, 4> AssocTypes; 9535 for (const GenericSelectionExpr::Association Assoc : E->associations()) { 9536 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo(); 9537 if (TSI) { 9538 TypeSourceInfo *AssocType = getDerived().TransformType(TSI); 9539 if (!AssocType) 9540 return ExprError(); 9541 AssocTypes.push_back(AssocType); 9542 } else { 9543 AssocTypes.push_back(nullptr); 9544 } 9545 9546 ExprResult AssocExpr = 9547 getDerived().TransformExpr(Assoc.getAssociationExpr()); 9548 if (AssocExpr.isInvalid()) 9549 return ExprError(); 9550 AssocExprs.push_back(AssocExpr.get()); 9551 } 9552 9553 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), 9554 E->getDefaultLoc(), 9555 E->getRParenLoc(), 9556 ControllingExpr.get(), 9557 AssocTypes, 9558 AssocExprs); 9559 } 9560 9561 template<typename Derived> 9562 ExprResult 9563 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 9564 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 9565 if (SubExpr.isInvalid()) 9566 return ExprError(); 9567 9568 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 9569 return E; 9570 9571 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 9572 E->getRParen()); 9573 } 9574 9575 /// The operand of a unary address-of operator has special rules: it's 9576 /// allowed to refer to a non-static member of a class even if there's no 'this' 9577 /// object available. 9578 template<typename Derived> 9579 ExprResult 9580 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { 9581 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) 9582 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); 9583 else 9584 return getDerived().TransformExpr(E); 9585 } 9586 9587 template<typename Derived> 9588 ExprResult 9589 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 9590 ExprResult SubExpr; 9591 if (E->getOpcode() == UO_AddrOf) 9592 SubExpr = TransformAddressOfOperand(E->getSubExpr()); 9593 else 9594 SubExpr = TransformExpr(E->getSubExpr()); 9595 if (SubExpr.isInvalid()) 9596 return ExprError(); 9597 9598 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 9599 return E; 9600 9601 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 9602 E->getOpcode(), 9603 SubExpr.get()); 9604 } 9605 9606 template<typename Derived> 9607 ExprResult 9608 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 9609 // Transform the type. 9610 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 9611 if (!Type) 9612 return ExprError(); 9613 9614 // Transform all of the components into components similar to what the 9615 // parser uses. 9616 // FIXME: It would be slightly more efficient in the non-dependent case to 9617 // just map FieldDecls, rather than requiring the rebuilder to look for 9618 // the fields again. However, __builtin_offsetof is rare enough in 9619 // template code that we don't care. 9620 bool ExprChanged = false; 9621 typedef Sema::OffsetOfComponent Component; 9622 SmallVector<Component, 4> Components; 9623 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 9624 const OffsetOfNode &ON = E->getComponent(I); 9625 Component Comp; 9626 Comp.isBrackets = true; 9627 Comp.LocStart = ON.getSourceRange().getBegin(); 9628 Comp.LocEnd = ON.getSourceRange().getEnd(); 9629 switch (ON.getKind()) { 9630 case OffsetOfNode::Array: { 9631 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 9632 ExprResult Index = getDerived().TransformExpr(FromIndex); 9633 if (Index.isInvalid()) 9634 return ExprError(); 9635 9636 ExprChanged = ExprChanged || Index.get() != FromIndex; 9637 Comp.isBrackets = true; 9638 Comp.U.E = Index.get(); 9639 break; 9640 } 9641 9642 case OffsetOfNode::Field: 9643 case OffsetOfNode::Identifier: 9644 Comp.isBrackets = false; 9645 Comp.U.IdentInfo = ON.getFieldName(); 9646 if (!Comp.U.IdentInfo) 9647 continue; 9648 9649 break; 9650 9651 case OffsetOfNode::Base: 9652 // Will be recomputed during the rebuild. 9653 continue; 9654 } 9655 9656 Components.push_back(Comp); 9657 } 9658 9659 // If nothing changed, retain the existing expression. 9660 if (!getDerived().AlwaysRebuild() && 9661 Type == E->getTypeSourceInfo() && 9662 !ExprChanged) 9663 return E; 9664 9665 // Build a new offsetof expression. 9666 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 9667 Components, E->getRParenLoc()); 9668 } 9669 9670 template<typename Derived> 9671 ExprResult 9672 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 9673 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && 9674 "opaque value expression requires transformation"); 9675 return E; 9676 } 9677 9678 template<typename Derived> 9679 ExprResult 9680 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { 9681 return E; 9682 } 9683 9684 template<typename Derived> 9685 ExprResult 9686 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { 9687 // Rebuild the syntactic form. The original syntactic form has 9688 // opaque-value expressions in it, so strip those away and rebuild 9689 // the result. This is a really awful way of doing this, but the 9690 // better solution (rebuilding the semantic expressions and 9691 // rebinding OVEs as necessary) doesn't work; we'd need 9692 // TreeTransform to not strip away implicit conversions. 9693 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); 9694 ExprResult result = getDerived().TransformExpr(newSyntacticForm); 9695 if (result.isInvalid()) return ExprError(); 9696 9697 // If that gives us a pseudo-object result back, the pseudo-object 9698 // expression must have been an lvalue-to-rvalue conversion which we 9699 // should reapply. 9700 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) 9701 result = SemaRef.checkPseudoObjectRValue(result.get()); 9702 9703 return result; 9704 } 9705 9706 template<typename Derived> 9707 ExprResult 9708 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( 9709 UnaryExprOrTypeTraitExpr *E) { 9710 if (E->isArgumentType()) { 9711 TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 9712 9713 TypeSourceInfo *NewT = getDerived().TransformType(OldT); 9714 if (!NewT) 9715 return ExprError(); 9716 9717 if (!getDerived().AlwaysRebuild() && OldT == NewT) 9718 return E; 9719 9720 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), 9721 E->getKind(), 9722 E->getSourceRange()); 9723 } 9724 9725 // C++0x [expr.sizeof]p1: 9726 // The operand is either an expression, which is an unevaluated operand 9727 // [...] 9728 EnterExpressionEvaluationContext Unevaluated( 9729 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, 9730 Sema::ReuseLambdaContextDecl); 9731 9732 // Try to recover if we have something like sizeof(T::X) where X is a type. 9733 // Notably, there must be *exactly* one set of parens if X is a type. 9734 TypeSourceInfo *RecoveryTSI = nullptr; 9735 ExprResult SubExpr; 9736 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); 9737 if (auto *DRE = 9738 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) 9739 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( 9740 PE, DRE, false, &RecoveryTSI); 9741 else 9742 SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 9743 9744 if (RecoveryTSI) { 9745 return getDerived().RebuildUnaryExprOrTypeTrait( 9746 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); 9747 } else if (SubExpr.isInvalid()) 9748 return ExprError(); 9749 9750 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 9751 return E; 9752 9753 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), 9754 E->getOperatorLoc(), 9755 E->getKind(), 9756 E->getSourceRange()); 9757 } 9758 9759 template<typename Derived> 9760 ExprResult 9761 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 9762 ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 9763 if (LHS.isInvalid()) 9764 return ExprError(); 9765 9766 ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 9767 if (RHS.isInvalid()) 9768 return ExprError(); 9769 9770 9771 if (!getDerived().AlwaysRebuild() && 9772 LHS.get() == E->getLHS() && 9773 RHS.get() == E->getRHS()) 9774 return E; 9775 9776 return getDerived().RebuildArraySubscriptExpr( 9777 LHS.get(), 9778 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc()); 9779 } 9780 9781 template <typename Derived> 9782 ExprResult 9783 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) { 9784 ExprResult Base = getDerived().TransformExpr(E->getBase()); 9785 if (Base.isInvalid()) 9786 return ExprError(); 9787 9788 ExprResult LowerBound; 9789 if (E->getLowerBound()) { 9790 LowerBound = getDerived().TransformExpr(E->getLowerBound()); 9791 if (LowerBound.isInvalid()) 9792 return ExprError(); 9793 } 9794 9795 ExprResult Length; 9796 if (E->getLength()) { 9797 Length = getDerived().TransformExpr(E->getLength()); 9798 if (Length.isInvalid()) 9799 return ExprError(); 9800 } 9801 9802 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && 9803 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength()) 9804 return E; 9805 9806 return getDerived().RebuildOMPArraySectionExpr( 9807 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(), 9808 Length.get(), E->getRBracketLoc()); 9809 } 9810 9811 template<typename Derived> 9812 ExprResult 9813 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 9814 // Transform the callee. 9815 ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 9816 if (Callee.isInvalid()) 9817 return ExprError(); 9818 9819 // Transform arguments. 9820 bool ArgChanged = false; 9821 SmallVector<Expr*, 8> Args; 9822 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 9823 &ArgChanged)) 9824 return ExprError(); 9825 9826 if (!getDerived().AlwaysRebuild() && 9827 Callee.get() == E->getCallee() && 9828 !ArgChanged) 9829 return SemaRef.MaybeBindToTemporary(E); 9830 9831 // FIXME: Wrong source location information for the '('. 9832 SourceLocation FakeLParenLoc 9833 = ((Expr *)Callee.get())->getSourceRange().getBegin(); 9834 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 9835 Args, 9836 E->getRParenLoc()); 9837 } 9838 9839 template<typename Derived> 9840 ExprResult 9841 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 9842 ExprResult Base = getDerived().TransformExpr(E->getBase()); 9843 if (Base.isInvalid()) 9844 return ExprError(); 9845 9846 NestedNameSpecifierLoc QualifierLoc; 9847 if (E->hasQualifier()) { 9848 QualifierLoc 9849 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 9850 9851 if (!QualifierLoc) 9852 return ExprError(); 9853 } 9854 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 9855 9856 ValueDecl *Member 9857 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 9858 E->getMemberDecl())); 9859 if (!Member) 9860 return ExprError(); 9861 9862 NamedDecl *FoundDecl = E->getFoundDecl(); 9863 if (FoundDecl == E->getMemberDecl()) { 9864 FoundDecl = Member; 9865 } else { 9866 FoundDecl = cast_or_null<NamedDecl>( 9867 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 9868 if (!FoundDecl) 9869 return ExprError(); 9870 } 9871 9872 if (!getDerived().AlwaysRebuild() && 9873 Base.get() == E->getBase() && 9874 QualifierLoc == E->getQualifierLoc() && 9875 Member == E->getMemberDecl() && 9876 FoundDecl == E->getFoundDecl() && 9877 !E->hasExplicitTemplateArgs()) { 9878 9879 // Mark it referenced in the new context regardless. 9880 // FIXME: this is a bit instantiation-specific. 9881 SemaRef.MarkMemberReferenced(E); 9882 9883 return E; 9884 } 9885 9886 TemplateArgumentListInfo TransArgs; 9887 if (E->hasExplicitTemplateArgs()) { 9888 TransArgs.setLAngleLoc(E->getLAngleLoc()); 9889 TransArgs.setRAngleLoc(E->getRAngleLoc()); 9890 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 9891 E->getNumTemplateArgs(), 9892 TransArgs)) 9893 return ExprError(); 9894 } 9895 9896 // FIXME: Bogus source location for the operator 9897 SourceLocation FakeOperatorLoc = 9898 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 9899 9900 // FIXME: to do this check properly, we will need to preserve the 9901 // first-qualifier-in-scope here, just in case we had a dependent 9902 // base (and therefore couldn't do the check) and a 9903 // nested-name-qualifier (and therefore could do the lookup). 9904 NamedDecl *FirstQualifierInScope = nullptr; 9905 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo(); 9906 if (MemberNameInfo.getName()) { 9907 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo); 9908 if (!MemberNameInfo.getName()) 9909 return ExprError(); 9910 } 9911 9912 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 9913 E->isArrow(), 9914 QualifierLoc, 9915 TemplateKWLoc, 9916 MemberNameInfo, 9917 Member, 9918 FoundDecl, 9919 (E->hasExplicitTemplateArgs() 9920 ? &TransArgs : nullptr), 9921 FirstQualifierInScope); 9922 } 9923 9924 template<typename Derived> 9925 ExprResult 9926 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 9927 ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 9928 if (LHS.isInvalid()) 9929 return ExprError(); 9930 9931 ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 9932 if (RHS.isInvalid()) 9933 return ExprError(); 9934 9935 if (!getDerived().AlwaysRebuild() && 9936 LHS.get() == E->getLHS() && 9937 RHS.get() == E->getRHS()) 9938 return E; 9939 9940 Sema::FPContractStateRAII FPContractState(getSema()); 9941 getSema().FPFeatures = E->getFPFeatures(); 9942 9943 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 9944 LHS.get(), RHS.get()); 9945 } 9946 9947 template <typename Derived> 9948 ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator( 9949 CXXRewrittenBinaryOperator *E) { 9950 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm(); 9951 9952 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS)); 9953 if (LHS.isInvalid()) 9954 return ExprError(); 9955 9956 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS)); 9957 if (RHS.isInvalid()) 9958 return ExprError(); 9959 9960 if (!getDerived().AlwaysRebuild() && 9961 LHS.get() == Decomp.LHS && 9962 RHS.get() == Decomp.RHS) 9963 return E; 9964 9965 // Extract the already-resolved callee declarations so that we can restrict 9966 // ourselves to using them as the unqualified lookup results when rebuilding. 9967 UnresolvedSet<2> UnqualLookups; 9968 Expr *PossibleBinOps[] = {E->getSemanticForm(), 9969 const_cast<Expr *>(Decomp.InnerBinOp)}; 9970 for (Expr *PossibleBinOp : PossibleBinOps) { 9971 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit()); 9972 if (!Op) 9973 continue; 9974 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit()); 9975 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl())) 9976 continue; 9977 9978 // Transform the callee in case we built a call to a local extern 9979 // declaration. 9980 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl( 9981 E->getOperatorLoc(), Callee->getFoundDecl())); 9982 if (!Found) 9983 return ExprError(); 9984 UnqualLookups.addDecl(Found); 9985 } 9986 9987 return getDerived().RebuildCXXRewrittenBinaryOperator( 9988 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get()); 9989 } 9990 9991 template<typename Derived> 9992 ExprResult 9993 TreeTransform<Derived>::TransformCompoundAssignOperator( 9994 CompoundAssignOperator *E) { 9995 return getDerived().TransformBinaryOperator(E); 9996 } 9997 9998 template<typename Derived> 9999 ExprResult TreeTransform<Derived>:: 10000 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 10001 // Just rebuild the common and RHS expressions and see whether we 10002 // get any changes. 10003 10004 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 10005 if (commonExpr.isInvalid()) 10006 return ExprError(); 10007 10008 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 10009 if (rhs.isInvalid()) 10010 return ExprError(); 10011 10012 if (!getDerived().AlwaysRebuild() && 10013 commonExpr.get() == e->getCommon() && 10014 rhs.get() == e->getFalseExpr()) 10015 return e; 10016 10017 return getDerived().RebuildConditionalOperator(commonExpr.get(), 10018 e->getQuestionLoc(), 10019 nullptr, 10020 e->getColonLoc(), 10021 rhs.get()); 10022 } 10023 10024 template<typename Derived> 10025 ExprResult 10026 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 10027 ExprResult Cond = getDerived().TransformExpr(E->getCond()); 10028 if (Cond.isInvalid()) 10029 return ExprError(); 10030 10031 ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 10032 if (LHS.isInvalid()) 10033 return ExprError(); 10034 10035 ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 10036 if (RHS.isInvalid()) 10037 return ExprError(); 10038 10039 if (!getDerived().AlwaysRebuild() && 10040 Cond.get() == E->getCond() && 10041 LHS.get() == E->getLHS() && 10042 RHS.get() == E->getRHS()) 10043 return E; 10044 10045 return getDerived().RebuildConditionalOperator(Cond.get(), 10046 E->getQuestionLoc(), 10047 LHS.get(), 10048 E->getColonLoc(), 10049 RHS.get()); 10050 } 10051 10052 template<typename Derived> 10053 ExprResult 10054 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 10055 // Implicit casts are eliminated during transformation, since they 10056 // will be recomputed by semantic analysis after transformation. 10057 return getDerived().TransformExpr(E->getSubExprAsWritten()); 10058 } 10059 10060 template<typename Derived> 10061 ExprResult 10062 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 10063 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 10064 if (!Type) 10065 return ExprError(); 10066 10067 ExprResult SubExpr 10068 = getDerived().TransformExpr(E->getSubExprAsWritten()); 10069 if (SubExpr.isInvalid()) 10070 return ExprError(); 10071 10072 if (!getDerived().AlwaysRebuild() && 10073 Type == E->getTypeInfoAsWritten() && 10074 SubExpr.get() == E->getSubExpr()) 10075 return E; 10076 10077 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 10078 Type, 10079 E->getRParenLoc(), 10080 SubExpr.get()); 10081 } 10082 10083 template<typename Derived> 10084 ExprResult 10085 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 10086 TypeSourceInfo *OldT = E->getTypeSourceInfo(); 10087 TypeSourceInfo *NewT = getDerived().TransformType(OldT); 10088 if (!NewT) 10089 return ExprError(); 10090 10091 ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 10092 if (Init.isInvalid()) 10093 return ExprError(); 10094 10095 if (!getDerived().AlwaysRebuild() && 10096 OldT == NewT && 10097 Init.get() == E->getInitializer()) 10098 return SemaRef.MaybeBindToTemporary(E); 10099 10100 // Note: the expression type doesn't necessarily match the 10101 // type-as-written, but that's okay, because it should always be 10102 // derivable from the initializer. 10103 10104 return getDerived().RebuildCompoundLiteralExpr( 10105 E->getLParenLoc(), NewT, 10106 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get()); 10107 } 10108 10109 template<typename Derived> 10110 ExprResult 10111 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 10112 ExprResult Base = getDerived().TransformExpr(E->getBase()); 10113 if (Base.isInvalid()) 10114 return ExprError(); 10115 10116 if (!getDerived().AlwaysRebuild() && 10117 Base.get() == E->getBase()) 10118 return E; 10119 10120 // FIXME: Bad source location 10121 SourceLocation FakeOperatorLoc = 10122 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc()); 10123 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 10124 E->getAccessorLoc(), 10125 E->getAccessor()); 10126 } 10127 10128 template<typename Derived> 10129 ExprResult 10130 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 10131 if (InitListExpr *Syntactic = E->getSyntacticForm()) 10132 E = Syntactic; 10133 10134 bool InitChanged = false; 10135 10136 EnterExpressionEvaluationContext Context( 10137 getSema(), EnterExpressionEvaluationContext::InitList); 10138 10139 SmallVector<Expr*, 4> Inits; 10140 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 10141 Inits, &InitChanged)) 10142 return ExprError(); 10143 10144 if (!getDerived().AlwaysRebuild() && !InitChanged) { 10145 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr 10146 // in some cases. We can't reuse it in general, because the syntactic and 10147 // semantic forms are linked, and we can't know that semantic form will 10148 // match even if the syntactic form does. 10149 } 10150 10151 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, 10152 E->getRBraceLoc()); 10153 } 10154 10155 template<typename Derived> 10156 ExprResult 10157 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 10158 Designation Desig; 10159 10160 // transform the initializer value 10161 ExprResult Init = getDerived().TransformExpr(E->getInit()); 10162 if (Init.isInvalid()) 10163 return ExprError(); 10164 10165 // transform the designators. 10166 SmallVector<Expr*, 4> ArrayExprs; 10167 bool ExprChanged = false; 10168 for (const DesignatedInitExpr::Designator &D : E->designators()) { 10169 if (D.isFieldDesignator()) { 10170 Desig.AddDesignator(Designator::getField(D.getFieldName(), 10171 D.getDotLoc(), 10172 D.getFieldLoc())); 10173 if (D.getField()) { 10174 FieldDecl *Field = cast_or_null<FieldDecl>( 10175 getDerived().TransformDecl(D.getFieldLoc(), D.getField())); 10176 if (Field != D.getField()) 10177 // Rebuild the expression when the transformed FieldDecl is 10178 // different to the already assigned FieldDecl. 10179 ExprChanged = true; 10180 } else { 10181 // Ensure that the designator expression is rebuilt when there isn't 10182 // a resolved FieldDecl in the designator as we don't want to assign 10183 // a FieldDecl to a pattern designator that will be instantiated again. 10184 ExprChanged = true; 10185 } 10186 continue; 10187 } 10188 10189 if (D.isArrayDesignator()) { 10190 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); 10191 if (Index.isInvalid()) 10192 return ExprError(); 10193 10194 Desig.AddDesignator( 10195 Designator::getArray(Index.get(), D.getLBracketLoc())); 10196 10197 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); 10198 ArrayExprs.push_back(Index.get()); 10199 continue; 10200 } 10201 10202 assert(D.isArrayRangeDesignator() && "New kind of designator?"); 10203 ExprResult Start 10204 = getDerived().TransformExpr(E->getArrayRangeStart(D)); 10205 if (Start.isInvalid()) 10206 return ExprError(); 10207 10208 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D)); 10209 if (End.isInvalid()) 10210 return ExprError(); 10211 10212 Desig.AddDesignator(Designator::getArrayRange(Start.get(), 10213 End.get(), 10214 D.getLBracketLoc(), 10215 D.getEllipsisLoc())); 10216 10217 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) || 10218 End.get() != E->getArrayRangeEnd(D); 10219 10220 ArrayExprs.push_back(Start.get()); 10221 ArrayExprs.push_back(End.get()); 10222 } 10223 10224 if (!getDerived().AlwaysRebuild() && 10225 Init.get() == E->getInit() && 10226 !ExprChanged) 10227 return E; 10228 10229 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, 10230 E->getEqualOrColonLoc(), 10231 E->usesGNUSyntax(), Init.get()); 10232 } 10233 10234 // Seems that if TransformInitListExpr() only works on the syntactic form of an 10235 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. 10236 template<typename Derived> 10237 ExprResult 10238 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( 10239 DesignatedInitUpdateExpr *E) { 10240 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " 10241 "initializer"); 10242 return ExprError(); 10243 } 10244 10245 template<typename Derived> 10246 ExprResult 10247 TreeTransform<Derived>::TransformNoInitExpr( 10248 NoInitExpr *E) { 10249 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); 10250 return ExprError(); 10251 } 10252 10253 template<typename Derived> 10254 ExprResult 10255 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) { 10256 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer"); 10257 return ExprError(); 10258 } 10259 10260 template<typename Derived> 10261 ExprResult 10262 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) { 10263 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer"); 10264 return ExprError(); 10265 } 10266 10267 template<typename Derived> 10268 ExprResult 10269 TreeTransform<Derived>::TransformImplicitValueInitExpr( 10270 ImplicitValueInitExpr *E) { 10271 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName()); 10272 10273 // FIXME: Will we ever have proper type location here? Will we actually 10274 // need to transform the type? 10275 QualType T = getDerived().TransformType(E->getType()); 10276 if (T.isNull()) 10277 return ExprError(); 10278 10279 if (!getDerived().AlwaysRebuild() && 10280 T == E->getType()) 10281 return E; 10282 10283 return getDerived().RebuildImplicitValueInitExpr(T); 10284 } 10285 10286 template<typename Derived> 10287 ExprResult 10288 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 10289 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 10290 if (!TInfo) 10291 return ExprError(); 10292 10293 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 10294 if (SubExpr.isInvalid()) 10295 return ExprError(); 10296 10297 if (!getDerived().AlwaysRebuild() && 10298 TInfo == E->getWrittenTypeInfo() && 10299 SubExpr.get() == E->getSubExpr()) 10300 return E; 10301 10302 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 10303 TInfo, E->getRParenLoc()); 10304 } 10305 10306 template<typename Derived> 10307 ExprResult 10308 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 10309 bool ArgumentChanged = false; 10310 SmallVector<Expr*, 4> Inits; 10311 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 10312 &ArgumentChanged)) 10313 return ExprError(); 10314 10315 return getDerived().RebuildParenListExpr(E->getLParenLoc(), 10316 Inits, 10317 E->getRParenLoc()); 10318 } 10319 10320 /// Transform an address-of-label expression. 10321 /// 10322 /// By default, the transformation of an address-of-label expression always 10323 /// rebuilds the expression, so that the label identifier can be resolved to 10324 /// the corresponding label statement by semantic analysis. 10325 template<typename Derived> 10326 ExprResult 10327 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 10328 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 10329 E->getLabel()); 10330 if (!LD) 10331 return ExprError(); 10332 10333 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 10334 cast<LabelDecl>(LD)); 10335 } 10336 10337 template<typename Derived> 10338 ExprResult 10339 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 10340 SemaRef.ActOnStartStmtExpr(); 10341 StmtResult SubStmt 10342 = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 10343 if (SubStmt.isInvalid()) { 10344 SemaRef.ActOnStmtExprError(); 10345 return ExprError(); 10346 } 10347 10348 unsigned OldDepth = E->getTemplateDepth(); 10349 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth); 10350 10351 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth && 10352 SubStmt.get() == E->getSubStmt()) { 10353 // Calling this an 'error' is unintuitive, but it does the right thing. 10354 SemaRef.ActOnStmtExprError(); 10355 return SemaRef.MaybeBindToTemporary(E); 10356 } 10357 10358 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(), 10359 E->getRParenLoc(), NewDepth); 10360 } 10361 10362 template<typename Derived> 10363 ExprResult 10364 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 10365 ExprResult Cond = getDerived().TransformExpr(E->getCond()); 10366 if (Cond.isInvalid()) 10367 return ExprError(); 10368 10369 ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 10370 if (LHS.isInvalid()) 10371 return ExprError(); 10372 10373 ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 10374 if (RHS.isInvalid()) 10375 return ExprError(); 10376 10377 if (!getDerived().AlwaysRebuild() && 10378 Cond.get() == E->getCond() && 10379 LHS.get() == E->getLHS() && 10380 RHS.get() == E->getRHS()) 10381 return E; 10382 10383 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 10384 Cond.get(), LHS.get(), RHS.get(), 10385 E->getRParenLoc()); 10386 } 10387 10388 template<typename Derived> 10389 ExprResult 10390 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 10391 return E; 10392 } 10393 10394 template<typename Derived> 10395 ExprResult 10396 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 10397 switch (E->getOperator()) { 10398 case OO_New: 10399 case OO_Delete: 10400 case OO_Array_New: 10401 case OO_Array_Delete: 10402 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 10403 10404 case OO_Call: { 10405 // This is a call to an object's operator(). 10406 assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 10407 10408 // Transform the object itself. 10409 ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 10410 if (Object.isInvalid()) 10411 return ExprError(); 10412 10413 // FIXME: Poor location information 10414 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( 10415 static_cast<Expr *>(Object.get())->getEndLoc()); 10416 10417 // Transform the call arguments. 10418 SmallVector<Expr*, 8> Args; 10419 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 10420 Args)) 10421 return ExprError(); 10422 10423 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args, 10424 E->getEndLoc()); 10425 } 10426 10427 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 10428 case OO_##Name: 10429 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 10430 #include "clang/Basic/OperatorKinds.def" 10431 case OO_Subscript: 10432 // Handled below. 10433 break; 10434 10435 case OO_Conditional: 10436 llvm_unreachable("conditional operator is not actually overloadable"); 10437 10438 case OO_None: 10439 case NUM_OVERLOADED_OPERATORS: 10440 llvm_unreachable("not an overloaded operator?"); 10441 } 10442 10443 ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 10444 if (Callee.isInvalid()) 10445 return ExprError(); 10446 10447 ExprResult First; 10448 if (E->getOperator() == OO_Amp) 10449 First = getDerived().TransformAddressOfOperand(E->getArg(0)); 10450 else 10451 First = getDerived().TransformExpr(E->getArg(0)); 10452 if (First.isInvalid()) 10453 return ExprError(); 10454 10455 ExprResult Second; 10456 if (E->getNumArgs() == 2) { 10457 Second = getDerived().TransformExpr(E->getArg(1)); 10458 if (Second.isInvalid()) 10459 return ExprError(); 10460 } 10461 10462 if (!getDerived().AlwaysRebuild() && 10463 Callee.get() == E->getCallee() && 10464 First.get() == E->getArg(0) && 10465 (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 10466 return SemaRef.MaybeBindToTemporary(E); 10467 10468 Sema::FPContractStateRAII FPContractState(getSema()); 10469 getSema().FPFeatures = E->getFPFeatures(); 10470 10471 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 10472 E->getOperatorLoc(), 10473 Callee.get(), 10474 First.get(), 10475 Second.get()); 10476 } 10477 10478 template<typename Derived> 10479 ExprResult 10480 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 10481 return getDerived().TransformCallExpr(E); 10482 } 10483 10484 template <typename Derived> 10485 ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) { 10486 bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function && 10487 getSema().CurContext != E->getParentContext(); 10488 10489 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc) 10490 return E; 10491 10492 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(), 10493 E->getEndLoc(), 10494 getSema().CurContext); 10495 } 10496 10497 template<typename Derived> 10498 ExprResult 10499 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 10500 // Transform the callee. 10501 ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 10502 if (Callee.isInvalid()) 10503 return ExprError(); 10504 10505 // Transform exec config. 10506 ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 10507 if (EC.isInvalid()) 10508 return ExprError(); 10509 10510 // Transform arguments. 10511 bool ArgChanged = false; 10512 SmallVector<Expr*, 8> Args; 10513 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 10514 &ArgChanged)) 10515 return ExprError(); 10516 10517 if (!getDerived().AlwaysRebuild() && 10518 Callee.get() == E->getCallee() && 10519 !ArgChanged) 10520 return SemaRef.MaybeBindToTemporary(E); 10521 10522 // FIXME: Wrong source location information for the '('. 10523 SourceLocation FakeLParenLoc 10524 = ((Expr *)Callee.get())->getSourceRange().getBegin(); 10525 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 10526 Args, 10527 E->getRParenLoc(), EC.get()); 10528 } 10529 10530 template<typename Derived> 10531 ExprResult 10532 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 10533 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 10534 if (!Type) 10535 return ExprError(); 10536 10537 ExprResult SubExpr 10538 = getDerived().TransformExpr(E->getSubExprAsWritten()); 10539 if (SubExpr.isInvalid()) 10540 return ExprError(); 10541 10542 if (!getDerived().AlwaysRebuild() && 10543 Type == E->getTypeInfoAsWritten() && 10544 SubExpr.get() == E->getSubExpr()) 10545 return E; 10546 return getDerived().RebuildCXXNamedCastExpr( 10547 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), 10548 Type, E->getAngleBrackets().getEnd(), 10549 // FIXME. this should be '(' location 10550 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); 10551 } 10552 10553 template<typename Derived> 10554 ExprResult 10555 TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) { 10556 TypeSourceInfo *TSI = 10557 getDerived().TransformType(BCE->getTypeInfoAsWritten()); 10558 if (!TSI) 10559 return ExprError(); 10560 10561 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr()); 10562 if (Sub.isInvalid()) 10563 return ExprError(); 10564 10565 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI, 10566 Sub.get(), BCE->getEndLoc()); 10567 } 10568 10569 template<typename Derived> 10570 ExprResult 10571 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 10572 return getDerived().TransformCXXNamedCastExpr(E); 10573 } 10574 10575 template<typename Derived> 10576 ExprResult 10577 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 10578 return getDerived().TransformCXXNamedCastExpr(E); 10579 } 10580 10581 template<typename Derived> 10582 ExprResult 10583 TreeTransform<Derived>::TransformCXXReinterpretCastExpr( 10584 CXXReinterpretCastExpr *E) { 10585 return getDerived().TransformCXXNamedCastExpr(E); 10586 } 10587 10588 template<typename Derived> 10589 ExprResult 10590 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 10591 return getDerived().TransformCXXNamedCastExpr(E); 10592 } 10593 10594 template<typename Derived> 10595 ExprResult 10596 TreeTransform<Derived>::TransformCXXFunctionalCastExpr( 10597 CXXFunctionalCastExpr *E) { 10598 TypeSourceInfo *Type = 10599 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten()); 10600 if (!Type) 10601 return ExprError(); 10602 10603 ExprResult SubExpr 10604 = getDerived().TransformExpr(E->getSubExprAsWritten()); 10605 if (SubExpr.isInvalid()) 10606 return ExprError(); 10607 10608 if (!getDerived().AlwaysRebuild() && 10609 Type == E->getTypeInfoAsWritten() && 10610 SubExpr.get() == E->getSubExpr()) 10611 return E; 10612 10613 return getDerived().RebuildCXXFunctionalCastExpr(Type, 10614 E->getLParenLoc(), 10615 SubExpr.get(), 10616 E->getRParenLoc(), 10617 E->isListInitialization()); 10618 } 10619 10620 template<typename Derived> 10621 ExprResult 10622 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 10623 if (E->isTypeOperand()) { 10624 TypeSourceInfo *TInfo 10625 = getDerived().TransformType(E->getTypeOperandSourceInfo()); 10626 if (!TInfo) 10627 return ExprError(); 10628 10629 if (!getDerived().AlwaysRebuild() && 10630 TInfo == E->getTypeOperandSourceInfo()) 10631 return E; 10632 10633 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), 10634 TInfo, E->getEndLoc()); 10635 } 10636 10637 // We don't know whether the subexpression is potentially evaluated until 10638 // after we perform semantic analysis. We speculatively assume it is 10639 // unevaluated; it will get fixed later if the subexpression is in fact 10640 // potentially evaluated. 10641 EnterExpressionEvaluationContext Unevaluated( 10642 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, 10643 Sema::ReuseLambdaContextDecl); 10644 10645 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 10646 if (SubExpr.isInvalid()) 10647 return ExprError(); 10648 10649 if (!getDerived().AlwaysRebuild() && 10650 SubExpr.get() == E->getExprOperand()) 10651 return E; 10652 10653 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), 10654 SubExpr.get(), E->getEndLoc()); 10655 } 10656 10657 template<typename Derived> 10658 ExprResult 10659 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 10660 if (E->isTypeOperand()) { 10661 TypeSourceInfo *TInfo 10662 = getDerived().TransformType(E->getTypeOperandSourceInfo()); 10663 if (!TInfo) 10664 return ExprError(); 10665 10666 if (!getDerived().AlwaysRebuild() && 10667 TInfo == E->getTypeOperandSourceInfo()) 10668 return E; 10669 10670 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), 10671 TInfo, E->getEndLoc()); 10672 } 10673 10674 EnterExpressionEvaluationContext Unevaluated( 10675 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 10676 10677 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 10678 if (SubExpr.isInvalid()) 10679 return ExprError(); 10680 10681 if (!getDerived().AlwaysRebuild() && 10682 SubExpr.get() == E->getExprOperand()) 10683 return E; 10684 10685 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), 10686 SubExpr.get(), E->getEndLoc()); 10687 } 10688 10689 template<typename Derived> 10690 ExprResult 10691 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 10692 return E; 10693 } 10694 10695 template<typename Derived> 10696 ExprResult 10697 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 10698 CXXNullPtrLiteralExpr *E) { 10699 return E; 10700 } 10701 10702 template<typename Derived> 10703 ExprResult 10704 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 10705 QualType T = getSema().getCurrentThisType(); 10706 10707 if (!getDerived().AlwaysRebuild() && T == E->getType()) { 10708 // Mark it referenced in the new context regardless. 10709 // FIXME: this is a bit instantiation-specific. 10710 getSema().MarkThisReferenced(E); 10711 return E; 10712 } 10713 10714 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit()); 10715 } 10716 10717 template<typename Derived> 10718 ExprResult 10719 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 10720 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 10721 if (SubExpr.isInvalid()) 10722 return ExprError(); 10723 10724 if (!getDerived().AlwaysRebuild() && 10725 SubExpr.get() == E->getSubExpr()) 10726 return E; 10727 10728 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), 10729 E->isThrownVariableInScope()); 10730 } 10731 10732 template<typename Derived> 10733 ExprResult 10734 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 10735 ParmVarDecl *Param = cast_or_null<ParmVarDecl>( 10736 getDerived().TransformDecl(E->getBeginLoc(), E->getParam())); 10737 if (!Param) 10738 return ExprError(); 10739 10740 if (!getDerived().AlwaysRebuild() && Param == E->getParam() && 10741 E->getUsedContext() == SemaRef.CurContext) 10742 return E; 10743 10744 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 10745 } 10746 10747 template<typename Derived> 10748 ExprResult 10749 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { 10750 FieldDecl *Field = cast_or_null<FieldDecl>( 10751 getDerived().TransformDecl(E->getBeginLoc(), E->getField())); 10752 if (!Field) 10753 return ExprError(); 10754 10755 if (!getDerived().AlwaysRebuild() && Field == E->getField() && 10756 E->getUsedContext() == SemaRef.CurContext) 10757 return E; 10758 10759 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); 10760 } 10761 10762 template<typename Derived> 10763 ExprResult 10764 TreeTransform<Derived>::TransformCXXScalarValueInitExpr( 10765 CXXScalarValueInitExpr *E) { 10766 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 10767 if (!T) 10768 return ExprError(); 10769 10770 if (!getDerived().AlwaysRebuild() && 10771 T == E->getTypeSourceInfo()) 10772 return E; 10773 10774 return getDerived().RebuildCXXScalarValueInitExpr(T, 10775 /*FIXME:*/T->getTypeLoc().getEndLoc(), 10776 E->getRParenLoc()); 10777 } 10778 10779 template<typename Derived> 10780 ExprResult 10781 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 10782 // Transform the type that we're allocating 10783 TypeSourceInfo *AllocTypeInfo = 10784 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo()); 10785 if (!AllocTypeInfo) 10786 return ExprError(); 10787 10788 // Transform the size of the array we're allocating (if any). 10789 Optional<Expr *> ArraySize; 10790 if (Optional<Expr *> OldArraySize = E->getArraySize()) { 10791 ExprResult NewArraySize; 10792 if (*OldArraySize) { 10793 NewArraySize = getDerived().TransformExpr(*OldArraySize); 10794 if (NewArraySize.isInvalid()) 10795 return ExprError(); 10796 } 10797 ArraySize = NewArraySize.get(); 10798 } 10799 10800 // Transform the placement arguments (if any). 10801 bool ArgumentChanged = false; 10802 SmallVector<Expr*, 8> PlacementArgs; 10803 if (getDerived().TransformExprs(E->getPlacementArgs(), 10804 E->getNumPlacementArgs(), true, 10805 PlacementArgs, &ArgumentChanged)) 10806 return ExprError(); 10807 10808 // Transform the initializer (if any). 10809 Expr *OldInit = E->getInitializer(); 10810 ExprResult NewInit; 10811 if (OldInit) 10812 NewInit = getDerived().TransformInitializer(OldInit, true); 10813 if (NewInit.isInvalid()) 10814 return ExprError(); 10815 10816 // Transform new operator and delete operator. 10817 FunctionDecl *OperatorNew = nullptr; 10818 if (E->getOperatorNew()) { 10819 OperatorNew = cast_or_null<FunctionDecl>( 10820 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew())); 10821 if (!OperatorNew) 10822 return ExprError(); 10823 } 10824 10825 FunctionDecl *OperatorDelete = nullptr; 10826 if (E->getOperatorDelete()) { 10827 OperatorDelete = cast_or_null<FunctionDecl>( 10828 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); 10829 if (!OperatorDelete) 10830 return ExprError(); 10831 } 10832 10833 if (!getDerived().AlwaysRebuild() && 10834 AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 10835 ArraySize == E->getArraySize() && 10836 NewInit.get() == OldInit && 10837 OperatorNew == E->getOperatorNew() && 10838 OperatorDelete == E->getOperatorDelete() && 10839 !ArgumentChanged) { 10840 // Mark any declarations we need as referenced. 10841 // FIXME: instantiation-specific. 10842 if (OperatorNew) 10843 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew); 10844 if (OperatorDelete) 10845 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); 10846 10847 if (E->isArray() && !E->getAllocatedType()->isDependentType()) { 10848 QualType ElementType 10849 = SemaRef.Context.getBaseElementType(E->getAllocatedType()); 10850 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { 10851 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); 10852 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { 10853 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor); 10854 } 10855 } 10856 } 10857 10858 return E; 10859 } 10860 10861 QualType AllocType = AllocTypeInfo->getType(); 10862 if (!ArraySize) { 10863 // If no array size was specified, but the new expression was 10864 // instantiated with an array type (e.g., "new T" where T is 10865 // instantiated with "int[4]"), extract the outer bound from the 10866 // array type as our array size. We do this with constant and 10867 // dependently-sized array types. 10868 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 10869 if (!ArrayT) { 10870 // Do nothing 10871 } else if (const ConstantArrayType *ConsArrayT 10872 = dyn_cast<ConstantArrayType>(ArrayT)) { 10873 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), 10874 SemaRef.Context.getSizeType(), 10875 /*FIXME:*/ E->getBeginLoc()); 10876 AllocType = ConsArrayT->getElementType(); 10877 } else if (const DependentSizedArrayType *DepArrayT 10878 = dyn_cast<DependentSizedArrayType>(ArrayT)) { 10879 if (DepArrayT->getSizeExpr()) { 10880 ArraySize = DepArrayT->getSizeExpr(); 10881 AllocType = DepArrayT->getElementType(); 10882 } 10883 } 10884 } 10885 10886 return getDerived().RebuildCXXNewExpr( 10887 E->getBeginLoc(), E->isGlobalNew(), 10888 /*FIXME:*/ E->getBeginLoc(), PlacementArgs, 10889 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType, 10890 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get()); 10891 } 10892 10893 template<typename Derived> 10894 ExprResult 10895 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 10896 ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 10897 if (Operand.isInvalid()) 10898 return ExprError(); 10899 10900 // Transform the delete operator, if known. 10901 FunctionDecl *OperatorDelete = nullptr; 10902 if (E->getOperatorDelete()) { 10903 OperatorDelete = cast_or_null<FunctionDecl>( 10904 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); 10905 if (!OperatorDelete) 10906 return ExprError(); 10907 } 10908 10909 if (!getDerived().AlwaysRebuild() && 10910 Operand.get() == E->getArgument() && 10911 OperatorDelete == E->getOperatorDelete()) { 10912 // Mark any declarations we need as referenced. 10913 // FIXME: instantiation-specific. 10914 if (OperatorDelete) 10915 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); 10916 10917 if (!E->getArgument()->isTypeDependent()) { 10918 QualType Destroyed = SemaRef.Context.getBaseElementType( 10919 E->getDestroyedType()); 10920 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 10921 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 10922 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), 10923 SemaRef.LookupDestructor(Record)); 10924 } 10925 } 10926 10927 return E; 10928 } 10929 10930 return getDerived().RebuildCXXDeleteExpr( 10931 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get()); 10932 } 10933 10934 template<typename Derived> 10935 ExprResult 10936 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 10937 CXXPseudoDestructorExpr *E) { 10938 ExprResult Base = getDerived().TransformExpr(E->getBase()); 10939 if (Base.isInvalid()) 10940 return ExprError(); 10941 10942 ParsedType ObjectTypePtr; 10943 bool MayBePseudoDestructor = false; 10944 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), 10945 E->getOperatorLoc(), 10946 E->isArrow()? tok::arrow : tok::period, 10947 ObjectTypePtr, 10948 MayBePseudoDestructor); 10949 if (Base.isInvalid()) 10950 return ExprError(); 10951 10952 QualType ObjectType = ObjectTypePtr.get(); 10953 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 10954 if (QualifierLoc) { 10955 QualifierLoc 10956 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 10957 if (!QualifierLoc) 10958 return ExprError(); 10959 } 10960 CXXScopeSpec SS; 10961 SS.Adopt(QualifierLoc); 10962 10963 PseudoDestructorTypeStorage Destroyed; 10964 if (E->getDestroyedTypeInfo()) { 10965 TypeSourceInfo *DestroyedTypeInfo 10966 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 10967 ObjectType, nullptr, SS); 10968 if (!DestroyedTypeInfo) 10969 return ExprError(); 10970 Destroyed = DestroyedTypeInfo; 10971 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { 10972 // We aren't likely to be able to resolve the identifier down to a type 10973 // now anyway, so just retain the identifier. 10974 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 10975 E->getDestroyedTypeLoc()); 10976 } else { 10977 // Look for a destructor known with the given name. 10978 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 10979 *E->getDestroyedTypeIdentifier(), 10980 E->getDestroyedTypeLoc(), 10981 /*Scope=*/nullptr, 10982 SS, ObjectTypePtr, 10983 false); 10984 if (!T) 10985 return ExprError(); 10986 10987 Destroyed 10988 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 10989 E->getDestroyedTypeLoc()); 10990 } 10991 10992 TypeSourceInfo *ScopeTypeInfo = nullptr; 10993 if (E->getScopeTypeInfo()) { 10994 CXXScopeSpec EmptySS; 10995 ScopeTypeInfo = getDerived().TransformTypeInObjectScope( 10996 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); 10997 if (!ScopeTypeInfo) 10998 return ExprError(); 10999 } 11000 11001 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 11002 E->getOperatorLoc(), 11003 E->isArrow(), 11004 SS, 11005 ScopeTypeInfo, 11006 E->getColonColonLoc(), 11007 E->getTildeLoc(), 11008 Destroyed); 11009 } 11010 11011 template <typename Derived> 11012 bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old, 11013 bool RequiresADL, 11014 LookupResult &R) { 11015 // Transform all the decls. 11016 bool AllEmptyPacks = true; 11017 for (auto *OldD : Old->decls()) { 11018 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD); 11019 if (!InstD) { 11020 // Silently ignore these if a UsingShadowDecl instantiated to nothing. 11021 // This can happen because of dependent hiding. 11022 if (isa<UsingShadowDecl>(OldD)) 11023 continue; 11024 else { 11025 R.clear(); 11026 return true; 11027 } 11028 } 11029 11030 // Expand using pack declarations. 11031 NamedDecl *SingleDecl = cast<NamedDecl>(InstD); 11032 ArrayRef<NamedDecl*> Decls = SingleDecl; 11033 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD)) 11034 Decls = UPD->expansions(); 11035 11036 // Expand using declarations. 11037 for (auto *D : Decls) { 11038 if (auto *UD = dyn_cast<UsingDecl>(D)) { 11039 for (auto *SD : UD->shadows()) 11040 R.addDecl(SD); 11041 } else { 11042 R.addDecl(D); 11043 } 11044 } 11045 11046 AllEmptyPacks &= Decls.empty(); 11047 }; 11048 11049 // C++ [temp.res]/8.4.2: 11050 // The program is ill-formed, no diagnostic required, if [...] lookup for 11051 // a name in the template definition found a using-declaration, but the 11052 // lookup in the corresponding scope in the instantiation odoes not find 11053 // any declarations because the using-declaration was a pack expansion and 11054 // the corresponding pack is empty 11055 if (AllEmptyPacks && !RequiresADL) { 11056 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty) 11057 << isa<UnresolvedMemberExpr>(Old) << Old->getName(); 11058 return true; 11059 } 11060 11061 // Resolve a kind, but don't do any further analysis. If it's 11062 // ambiguous, the callee needs to deal with it. 11063 R.resolveKind(); 11064 return false; 11065 } 11066 11067 template<typename Derived> 11068 ExprResult 11069 TreeTransform<Derived>::TransformUnresolvedLookupExpr( 11070 UnresolvedLookupExpr *Old) { 11071 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 11072 Sema::LookupOrdinaryName); 11073 11074 // Transform the declaration set. 11075 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R)) 11076 return ExprError(); 11077 11078 // Rebuild the nested-name qualifier, if present. 11079 CXXScopeSpec SS; 11080 if (Old->getQualifierLoc()) { 11081 NestedNameSpecifierLoc QualifierLoc 11082 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 11083 if (!QualifierLoc) 11084 return ExprError(); 11085 11086 SS.Adopt(QualifierLoc); 11087 } 11088 11089 if (Old->getNamingClass()) { 11090 CXXRecordDecl *NamingClass 11091 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 11092 Old->getNameLoc(), 11093 Old->getNamingClass())); 11094 if (!NamingClass) { 11095 R.clear(); 11096 return ExprError(); 11097 } 11098 11099 R.setNamingClass(NamingClass); 11100 } 11101 11102 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 11103 11104 // If we have neither explicit template arguments, nor the template keyword, 11105 // it's a normal declaration name or member reference. 11106 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { 11107 NamedDecl *D = R.getAsSingle<NamedDecl>(); 11108 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an 11109 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will 11110 // give a good diagnostic. 11111 if (D && D->isCXXInstanceMember()) { 11112 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, 11113 /*TemplateArgs=*/nullptr, 11114 /*Scope=*/nullptr); 11115 } 11116 11117 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 11118 } 11119 11120 // If we have template arguments, rebuild them, then rebuild the 11121 // templateid expression. 11122 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 11123 if (Old->hasExplicitTemplateArgs() && 11124 getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 11125 Old->getNumTemplateArgs(), 11126 TransArgs)) { 11127 R.clear(); 11128 return ExprError(); 11129 } 11130 11131 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, 11132 Old->requiresADL(), &TransArgs); 11133 } 11134 11135 template<typename Derived> 11136 ExprResult 11137 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { 11138 bool ArgChanged = false; 11139 SmallVector<TypeSourceInfo *, 4> Args; 11140 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { 11141 TypeSourceInfo *From = E->getArg(I); 11142 TypeLoc FromTL = From->getTypeLoc(); 11143 if (!FromTL.getAs<PackExpansionTypeLoc>()) { 11144 TypeLocBuilder TLB; 11145 TLB.reserve(FromTL.getFullDataSize()); 11146 QualType To = getDerived().TransformType(TLB, FromTL); 11147 if (To.isNull()) 11148 return ExprError(); 11149 11150 if (To == From->getType()) 11151 Args.push_back(From); 11152 else { 11153 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 11154 ArgChanged = true; 11155 } 11156 continue; 11157 } 11158 11159 ArgChanged = true; 11160 11161 // We have a pack expansion. Instantiate it. 11162 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); 11163 TypeLoc PatternTL = ExpansionTL.getPatternLoc(); 11164 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 11165 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); 11166 11167 // Determine whether the set of unexpanded parameter packs can and should 11168 // be expanded. 11169 bool Expand = true; 11170 bool RetainExpansion = false; 11171 Optional<unsigned> OrigNumExpansions = 11172 ExpansionTL.getTypePtr()->getNumExpansions(); 11173 Optional<unsigned> NumExpansions = OrigNumExpansions; 11174 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 11175 PatternTL.getSourceRange(), 11176 Unexpanded, 11177 Expand, RetainExpansion, 11178 NumExpansions)) 11179 return ExprError(); 11180 11181 if (!Expand) { 11182 // The transform has determined that we should perform a simple 11183 // transformation on the pack expansion, producing another pack 11184 // expansion. 11185 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 11186 11187 TypeLocBuilder TLB; 11188 TLB.reserve(From->getTypeLoc().getFullDataSize()); 11189 11190 QualType To = getDerived().TransformType(TLB, PatternTL); 11191 if (To.isNull()) 11192 return ExprError(); 11193 11194 To = getDerived().RebuildPackExpansionType(To, 11195 PatternTL.getSourceRange(), 11196 ExpansionTL.getEllipsisLoc(), 11197 NumExpansions); 11198 if (To.isNull()) 11199 return ExprError(); 11200 11201 PackExpansionTypeLoc ToExpansionTL 11202 = TLB.push<PackExpansionTypeLoc>(To); 11203 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 11204 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 11205 continue; 11206 } 11207 11208 // Expand the pack expansion by substituting for each argument in the 11209 // pack(s). 11210 for (unsigned I = 0; I != *NumExpansions; ++I) { 11211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); 11212 TypeLocBuilder TLB; 11213 TLB.reserve(PatternTL.getFullDataSize()); 11214 QualType To = getDerived().TransformType(TLB, PatternTL); 11215 if (To.isNull()) 11216 return ExprError(); 11217 11218 if (To->containsUnexpandedParameterPack()) { 11219 To = getDerived().RebuildPackExpansionType(To, 11220 PatternTL.getSourceRange(), 11221 ExpansionTL.getEllipsisLoc(), 11222 NumExpansions); 11223 if (To.isNull()) 11224 return ExprError(); 11225 11226 PackExpansionTypeLoc ToExpansionTL 11227 = TLB.push<PackExpansionTypeLoc>(To); 11228 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 11229 } 11230 11231 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 11232 } 11233 11234 if (!RetainExpansion) 11235 continue; 11236 11237 // If we're supposed to retain a pack expansion, do so by temporarily 11238 // forgetting the partially-substituted parameter pack. 11239 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 11240 11241 TypeLocBuilder TLB; 11242 TLB.reserve(From->getTypeLoc().getFullDataSize()); 11243 11244 QualType To = getDerived().TransformType(TLB, PatternTL); 11245 if (To.isNull()) 11246 return ExprError(); 11247 11248 To = getDerived().RebuildPackExpansionType(To, 11249 PatternTL.getSourceRange(), 11250 ExpansionTL.getEllipsisLoc(), 11251 NumExpansions); 11252 if (To.isNull()) 11253 return ExprError(); 11254 11255 PackExpansionTypeLoc ToExpansionTL 11256 = TLB.push<PackExpansionTypeLoc>(To); 11257 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 11258 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 11259 } 11260 11261 if (!getDerived().AlwaysRebuild() && !ArgChanged) 11262 return E; 11263 11264 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args, 11265 E->getEndLoc()); 11266 } 11267 11268 template<typename Derived> 11269 ExprResult 11270 TreeTransform<Derived>::TransformConceptSpecializationExpr( 11271 ConceptSpecializationExpr *E) { 11272 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten(); 11273 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc); 11274 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 11275 Old->NumTemplateArgs, TransArgs)) 11276 return ExprError(); 11277 11278 return getDerived().RebuildConceptSpecializationExpr( 11279 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(), 11280 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(), 11281 &TransArgs); 11282 } 11283 11284 template<typename Derived> 11285 ExprResult 11286 TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) { 11287 SmallVector<ParmVarDecl*, 4> TransParams; 11288 SmallVector<QualType, 4> TransParamTypes; 11289 Sema::ExtParameterInfoBuilder ExtParamInfos; 11290 11291 // C++2a [expr.prim.req]p2 11292 // Expressions appearing within a requirement-body are unevaluated operands. 11293 EnterExpressionEvaluationContext Ctx( 11294 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 11295 11296 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create( 11297 getSema().Context, getSema().CurContext, 11298 E->getBody()->getBeginLoc()); 11299 11300 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false); 11301 11302 if (getDerived().TransformFunctionTypeParams(E->getRequiresKWLoc(), 11303 E->getLocalParameters(), 11304 /*ParamTypes=*/nullptr, 11305 /*ParamInfos=*/nullptr, 11306 TransParamTypes, &TransParams, 11307 ExtParamInfos)) 11308 return ExprError(); 11309 11310 for (ParmVarDecl *Param : TransParams) 11311 Param->setDeclContext(Body); 11312 11313 SmallVector<concepts::Requirement *, 4> TransReqs; 11314 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(), 11315 TransReqs)) 11316 return ExprError(); 11317 11318 for (concepts::Requirement *Req : TransReqs) { 11319 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) { 11320 if (ER->getReturnTypeRequirement().isTypeConstraint()) { 11321 ER->getReturnTypeRequirement() 11322 .getTypeConstraintTemplateParameterList()->getParam(0) 11323 ->setDeclContext(Body); 11324 } 11325 } 11326 } 11327 11328 return getDerived().RebuildRequiresExpr(E->getRequiresKWLoc(), Body, 11329 TransParams, TransReqs, 11330 E->getRBraceLoc()); 11331 } 11332 11333 template<typename Derived> 11334 bool TreeTransform<Derived>::TransformRequiresExprRequirements( 11335 ArrayRef<concepts::Requirement *> Reqs, 11336 SmallVectorImpl<concepts::Requirement *> &Transformed) { 11337 for (concepts::Requirement *Req : Reqs) { 11338 concepts::Requirement *TransReq = nullptr; 11339 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) 11340 TransReq = getDerived().TransformTypeRequirement(TypeReq); 11341 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) 11342 TransReq = getDerived().TransformExprRequirement(ExprReq); 11343 else 11344 TransReq = getDerived().TransformNestedRequirement( 11345 cast<concepts::NestedRequirement>(Req)); 11346 if (!TransReq) 11347 return true; 11348 Transformed.push_back(TransReq); 11349 } 11350 return false; 11351 } 11352 11353 template<typename Derived> 11354 concepts::TypeRequirement * 11355 TreeTransform<Derived>::TransformTypeRequirement( 11356 concepts::TypeRequirement *Req) { 11357 if (Req->isSubstitutionFailure()) { 11358 if (getDerived().AlwaysRebuild()) 11359 return getDerived().RebuildTypeRequirement( 11360 Req->getSubstitutionDiagnostic()); 11361 return Req; 11362 } 11363 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType()); 11364 if (!TransType) 11365 return nullptr; 11366 return getDerived().RebuildTypeRequirement(TransType); 11367 } 11368 11369 template<typename Derived> 11370 concepts::ExprRequirement * 11371 TreeTransform<Derived>::TransformExprRequirement(concepts::ExprRequirement *Req) { 11372 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr; 11373 if (Req->isExprSubstitutionFailure()) 11374 TransExpr = Req->getExprSubstitutionDiagnostic(); 11375 else { 11376 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr()); 11377 if (TransExprRes.isInvalid()) 11378 return nullptr; 11379 TransExpr = TransExprRes.get(); 11380 } 11381 11382 llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq; 11383 const auto &RetReq = Req->getReturnTypeRequirement(); 11384 if (RetReq.isEmpty()) 11385 TransRetReq.emplace(); 11386 else if (RetReq.isSubstitutionFailure()) 11387 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic()); 11388 else if (RetReq.isTypeConstraint()) { 11389 TemplateParameterList *OrigTPL = 11390 RetReq.getTypeConstraintTemplateParameterList(); 11391 TemplateParameterList *TPL = 11392 getDerived().TransformTemplateParameterList(OrigTPL); 11393 if (!TPL) 11394 return nullptr; 11395 TransRetReq.emplace(TPL); 11396 } 11397 assert(TransRetReq.hasValue() && 11398 "All code paths leading here must set TransRetReq"); 11399 if (Expr *E = TransExpr.dyn_cast<Expr *>()) 11400 return getDerived().RebuildExprRequirement(E, Req->isSimple(), 11401 Req->getNoexceptLoc(), 11402 std::move(*TransRetReq)); 11403 return getDerived().RebuildExprRequirement( 11404 TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(), 11405 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq)); 11406 } 11407 11408 template<typename Derived> 11409 concepts::NestedRequirement * 11410 TreeTransform<Derived>::TransformNestedRequirement( 11411 concepts::NestedRequirement *Req) { 11412 if (Req->isSubstitutionFailure()) { 11413 if (getDerived().AlwaysRebuild()) 11414 return getDerived().RebuildNestedRequirement( 11415 Req->getSubstitutionDiagnostic()); 11416 return Req; 11417 } 11418 ExprResult TransConstraint = 11419 getDerived().TransformExpr(Req->getConstraintExpr()); 11420 if (TransConstraint.isInvalid()) 11421 return nullptr; 11422 return getDerived().RebuildNestedRequirement(TransConstraint.get()); 11423 } 11424 11425 template<typename Derived> 11426 ExprResult 11427 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 11428 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 11429 if (!T) 11430 return ExprError(); 11431 11432 if (!getDerived().AlwaysRebuild() && 11433 T == E->getQueriedTypeSourceInfo()) 11434 return E; 11435 11436 ExprResult SubExpr; 11437 { 11438 EnterExpressionEvaluationContext Unevaluated( 11439 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 11440 SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); 11441 if (SubExpr.isInvalid()) 11442 return ExprError(); 11443 11444 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) 11445 return E; 11446 } 11447 11448 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, 11449 SubExpr.get(), E->getEndLoc()); 11450 } 11451 11452 template<typename Derived> 11453 ExprResult 11454 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { 11455 ExprResult SubExpr; 11456 { 11457 EnterExpressionEvaluationContext Unevaluated( 11458 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 11459 SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); 11460 if (SubExpr.isInvalid()) 11461 return ExprError(); 11462 11463 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) 11464 return E; 11465 } 11466 11467 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(), 11468 SubExpr.get(), E->getEndLoc()); 11469 } 11470 11471 template <typename Derived> 11472 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( 11473 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, 11474 TypeSourceInfo **RecoveryTSI) { 11475 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( 11476 DRE, AddrTaken, RecoveryTSI); 11477 11478 // Propagate both errors and recovered types, which return ExprEmpty. 11479 if (!NewDRE.isUsable()) 11480 return NewDRE; 11481 11482 // We got an expr, wrap it up in parens. 11483 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) 11484 return PE; 11485 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), 11486 PE->getRParen()); 11487 } 11488 11489 template <typename Derived> 11490 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 11491 DependentScopeDeclRefExpr *E) { 11492 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, 11493 nullptr); 11494 } 11495 11496 template<typename Derived> 11497 ExprResult 11498 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 11499 DependentScopeDeclRefExpr *E, 11500 bool IsAddressOfOperand, 11501 TypeSourceInfo **RecoveryTSI) { 11502 assert(E->getQualifierLoc()); 11503 NestedNameSpecifierLoc QualifierLoc 11504 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 11505 if (!QualifierLoc) 11506 return ExprError(); 11507 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 11508 11509 // TODO: If this is a conversion-function-id, verify that the 11510 // destination type name (if present) resolves the same way after 11511 // instantiation as it did in the local scope. 11512 11513 DeclarationNameInfo NameInfo 11514 = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 11515 if (!NameInfo.getName()) 11516 return ExprError(); 11517 11518 if (!E->hasExplicitTemplateArgs()) { 11519 if (!getDerived().AlwaysRebuild() && 11520 QualifierLoc == E->getQualifierLoc() && 11521 // Note: it is sufficient to compare the Name component of NameInfo: 11522 // if name has not changed, DNLoc has not changed either. 11523 NameInfo.getName() == E->getDeclName()) 11524 return E; 11525 11526 return getDerived().RebuildDependentScopeDeclRefExpr( 11527 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, 11528 IsAddressOfOperand, RecoveryTSI); 11529 } 11530 11531 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 11532 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 11533 E->getNumTemplateArgs(), 11534 TransArgs)) 11535 return ExprError(); 11536 11537 return getDerived().RebuildDependentScopeDeclRefExpr( 11538 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, 11539 RecoveryTSI); 11540 } 11541 11542 template<typename Derived> 11543 ExprResult 11544 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 11545 // CXXConstructExprs other than for list-initialization and 11546 // CXXTemporaryObjectExpr are always implicit, so when we have 11547 // a 1-argument construction we just transform that argument. 11548 if ((E->getNumArgs() == 1 || 11549 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && 11550 (!getDerived().DropCallArgument(E->getArg(0))) && 11551 !E->isListInitialization()) 11552 return getDerived().TransformExpr(E->getArg(0)); 11553 11554 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName()); 11555 11556 QualType T = getDerived().TransformType(E->getType()); 11557 if (T.isNull()) 11558 return ExprError(); 11559 11560 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( 11561 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); 11562 if (!Constructor) 11563 return ExprError(); 11564 11565 bool ArgumentChanged = false; 11566 SmallVector<Expr*, 8> Args; 11567 { 11568 EnterExpressionEvaluationContext Context( 11569 getSema(), EnterExpressionEvaluationContext::InitList, 11570 E->isListInitialization()); 11571 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 11572 &ArgumentChanged)) 11573 return ExprError(); 11574 } 11575 11576 if (!getDerived().AlwaysRebuild() && 11577 T == E->getType() && 11578 Constructor == E->getConstructor() && 11579 !ArgumentChanged) { 11580 // Mark the constructor as referenced. 11581 // FIXME: Instantiation-specific 11582 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); 11583 return E; 11584 } 11585 11586 return getDerived().RebuildCXXConstructExpr( 11587 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args, 11588 E->hadMultipleCandidates(), E->isListInitialization(), 11589 E->isStdInitListInitialization(), E->requiresZeroInitialization(), 11590 E->getConstructionKind(), E->getParenOrBraceRange()); 11591 } 11592 11593 template<typename Derived> 11594 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr( 11595 CXXInheritedCtorInitExpr *E) { 11596 QualType T = getDerived().TransformType(E->getType()); 11597 if (T.isNull()) 11598 return ExprError(); 11599 11600 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( 11601 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); 11602 if (!Constructor) 11603 return ExprError(); 11604 11605 if (!getDerived().AlwaysRebuild() && 11606 T == E->getType() && 11607 Constructor == E->getConstructor()) { 11608 // Mark the constructor as referenced. 11609 // FIXME: Instantiation-specific 11610 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); 11611 return E; 11612 } 11613 11614 return getDerived().RebuildCXXInheritedCtorInitExpr( 11615 T, E->getLocation(), Constructor, 11616 E->constructsVBase(), E->inheritedFromVBase()); 11617 } 11618 11619 /// Transform a C++ temporary-binding expression. 11620 /// 11621 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 11622 /// transform the subexpression and return that. 11623 template<typename Derived> 11624 ExprResult 11625 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 11626 return getDerived().TransformExpr(E->getSubExpr()); 11627 } 11628 11629 /// Transform a C++ expression that contains cleanups that should 11630 /// be run after the expression is evaluated. 11631 /// 11632 /// Since ExprWithCleanups nodes are implicitly generated, we 11633 /// just transform the subexpression and return that. 11634 template<typename Derived> 11635 ExprResult 11636 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 11637 return getDerived().TransformExpr(E->getSubExpr()); 11638 } 11639 11640 template<typename Derived> 11641 ExprResult 11642 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 11643 CXXTemporaryObjectExpr *E) { 11644 TypeSourceInfo *T = 11645 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); 11646 if (!T) 11647 return ExprError(); 11648 11649 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( 11650 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); 11651 if (!Constructor) 11652 return ExprError(); 11653 11654 bool ArgumentChanged = false; 11655 SmallVector<Expr*, 8> Args; 11656 Args.reserve(E->getNumArgs()); 11657 { 11658 EnterExpressionEvaluationContext Context( 11659 getSema(), EnterExpressionEvaluationContext::InitList, 11660 E->isListInitialization()); 11661 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 11662 &ArgumentChanged)) 11663 return ExprError(); 11664 } 11665 11666 if (!getDerived().AlwaysRebuild() && 11667 T == E->getTypeSourceInfo() && 11668 Constructor == E->getConstructor() && 11669 !ArgumentChanged) { 11670 // FIXME: Instantiation-specific 11671 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); 11672 return SemaRef.MaybeBindToTemporary(E); 11673 } 11674 11675 // FIXME: We should just pass E->isListInitialization(), but we're not 11676 // prepared to handle list-initialization without a child InitListExpr. 11677 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc(); 11678 return getDerived().RebuildCXXTemporaryObjectExpr( 11679 T, LParenLoc, Args, E->getEndLoc(), 11680 /*ListInitialization=*/LParenLoc.isInvalid()); 11681 } 11682 11683 template<typename Derived> 11684 ExprResult 11685 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { 11686 // Transform any init-capture expressions before entering the scope of the 11687 // lambda body, because they are not semantically within that scope. 11688 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; 11689 struct TransformedInitCapture { 11690 // The location of the ... if the result is retaining a pack expansion. 11691 SourceLocation EllipsisLoc; 11692 // Zero or more expansions of the init-capture. 11693 SmallVector<InitCaptureInfoTy, 4> Expansions; 11694 }; 11695 SmallVector<TransformedInitCapture, 4> InitCaptures; 11696 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin()); 11697 for (LambdaExpr::capture_iterator C = E->capture_begin(), 11698 CEnd = E->capture_end(); 11699 C != CEnd; ++C) { 11700 if (!E->isInitCapture(C)) 11701 continue; 11702 11703 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()]; 11704 VarDecl *OldVD = C->getCapturedVar(); 11705 11706 auto SubstInitCapture = [&](SourceLocation EllipsisLoc, 11707 Optional<unsigned> NumExpansions) { 11708 ExprResult NewExprInitResult = getDerived().TransformInitializer( 11709 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit); 11710 11711 if (NewExprInitResult.isInvalid()) { 11712 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType())); 11713 return; 11714 } 11715 Expr *NewExprInit = NewExprInitResult.get(); 11716 11717 QualType NewInitCaptureType = 11718 getSema().buildLambdaInitCaptureInitialization( 11719 C->getLocation(), OldVD->getType()->isReferenceType(), 11720 EllipsisLoc, NumExpansions, OldVD->getIdentifier(), 11721 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, 11722 NewExprInit); 11723 Result.Expansions.push_back( 11724 InitCaptureInfoTy(NewExprInit, NewInitCaptureType)); 11725 }; 11726 11727 // If this is an init-capture pack, consider expanding the pack now. 11728 if (OldVD->isParameterPack()) { 11729 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo() 11730 ->getTypeLoc() 11731 .castAs<PackExpansionTypeLoc>(); 11732 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 11733 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded); 11734 11735 // Determine whether the set of unexpanded parameter packs can and should 11736 // be expanded. 11737 bool Expand = true; 11738 bool RetainExpansion = false; 11739 Optional<unsigned> OrigNumExpansions = 11740 ExpansionTL.getTypePtr()->getNumExpansions(); 11741 Optional<unsigned> NumExpansions = OrigNumExpansions; 11742 if (getDerived().TryExpandParameterPacks( 11743 ExpansionTL.getEllipsisLoc(), 11744 OldVD->getInit()->getSourceRange(), Unexpanded, Expand, 11745 RetainExpansion, NumExpansions)) 11746 return ExprError(); 11747 if (Expand) { 11748 for (unsigned I = 0; I != *NumExpansions; ++I) { 11749 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 11750 SubstInitCapture(SourceLocation(), None); 11751 } 11752 } 11753 if (!Expand || RetainExpansion) { 11754 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 11755 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions); 11756 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc(); 11757 } 11758 } else { 11759 SubstInitCapture(SourceLocation(), None); 11760 } 11761 } 11762 11763 LambdaScopeInfo *LSI = getSema().PushLambdaScope(); 11764 Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); 11765 11766 // Transform the template parameters, and add them to the current 11767 // instantiation scope. The null case is handled correctly. 11768 auto TPL = getDerived().TransformTemplateParameterList( 11769 E->getTemplateParameterList()); 11770 LSI->GLTemplateParameterList = TPL; 11771 11772 // Transform the type of the original lambda's call operator. 11773 // The transformation MUST be done in the CurrentInstantiationScope since 11774 // it introduces a mapping of the original to the newly created 11775 // transformed parameters. 11776 TypeSourceInfo *NewCallOpTSI = nullptr; 11777 { 11778 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); 11779 FunctionProtoTypeLoc OldCallOpFPTL = 11780 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); 11781 11782 TypeLocBuilder NewCallOpTLBuilder; 11783 SmallVector<QualType, 4> ExceptionStorage; 11784 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. 11785 QualType NewCallOpType = TransformFunctionProtoType( 11786 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(), 11787 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { 11788 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, 11789 ExceptionStorage, Changed); 11790 }); 11791 if (NewCallOpType.isNull()) 11792 return ExprError(); 11793 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, 11794 NewCallOpType); 11795 } 11796 11797 // Transform the trailing requires clause 11798 ExprResult NewTrailingRequiresClause; 11799 if (Expr *TRC = E->getCallOperator()->getTrailingRequiresClause()) 11800 // FIXME: Concepts: Substitution into requires clause should only happen 11801 // when checking satisfaction. 11802 NewTrailingRequiresClause = getDerived().TransformExpr(TRC); 11803 11804 // Create the local class that will describe the lambda. 11805 // FIXME: KnownDependent below is wrong when substituting inside a templated 11806 // context that isn't a DeclContext (such as a variable template). 11807 CXXRecordDecl *OldClass = E->getLambdaClass(); 11808 CXXRecordDecl *Class 11809 = getSema().createLambdaClosureType(E->getIntroducerRange(), 11810 NewCallOpTSI, 11811 /*KnownDependent=*/false, 11812 E->getCaptureDefault()); 11813 getDerived().transformedLocalDecl(OldClass, {Class}); 11814 11815 Optional<std::tuple<unsigned, bool, Decl *>> Mangling; 11816 if (getDerived().ReplacingOriginal()) 11817 Mangling = std::make_tuple(OldClass->getLambdaManglingNumber(), 11818 OldClass->hasKnownLambdaInternalLinkage(), 11819 OldClass->getLambdaContextDecl()); 11820 11821 // Build the call operator. 11822 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition( 11823 Class, E->getIntroducerRange(), NewCallOpTSI, 11824 E->getCallOperator()->getEndLoc(), 11825 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(), 11826 E->getCallOperator()->getConstexprKind(), 11827 NewTrailingRequiresClause.get()); 11828 11829 LSI->CallOperator = NewCallOperator; 11830 11831 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); 11832 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator}); 11833 11834 // Number the lambda for linkage purposes if necessary. 11835 getSema().handleLambdaNumbering(Class, NewCallOperator, Mangling); 11836 11837 // Introduce the context of the call operator. 11838 Sema::ContextRAII SavedContext(getSema(), NewCallOperator, 11839 /*NewThisContext*/false); 11840 11841 // Enter the scope of the lambda. 11842 getSema().buildLambdaScope(LSI, NewCallOperator, 11843 E->getIntroducerRange(), 11844 E->getCaptureDefault(), 11845 E->getCaptureDefaultLoc(), 11846 E->hasExplicitParameters(), 11847 E->hasExplicitResultType(), 11848 E->isMutable()); 11849 11850 bool Invalid = false; 11851 11852 // Transform captures. 11853 for (LambdaExpr::capture_iterator C = E->capture_begin(), 11854 CEnd = E->capture_end(); 11855 C != CEnd; ++C) { 11856 // When we hit the first implicit capture, tell Sema that we've finished 11857 // the list of explicit captures. 11858 if (C->isImplicit()) 11859 break; 11860 11861 // Capturing 'this' is trivial. 11862 if (C->capturesThis()) { 11863 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), 11864 /*BuildAndDiagnose*/ true, nullptr, 11865 C->getCaptureKind() == LCK_StarThis); 11866 continue; 11867 } 11868 // Captured expression will be recaptured during captured variables 11869 // rebuilding. 11870 if (C->capturesVLAType()) 11871 continue; 11872 11873 // Rebuild init-captures, including the implied field declaration. 11874 if (E->isInitCapture(C)) { 11875 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()]; 11876 11877 VarDecl *OldVD = C->getCapturedVar(); 11878 llvm::SmallVector<Decl*, 4> NewVDs; 11879 11880 for (InitCaptureInfoTy &Info : NewC.Expansions) { 11881 ExprResult Init = Info.first; 11882 QualType InitQualType = Info.second; 11883 if (Init.isInvalid() || InitQualType.isNull()) { 11884 Invalid = true; 11885 break; 11886 } 11887 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( 11888 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc, 11889 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get()); 11890 if (!NewVD) { 11891 Invalid = true; 11892 break; 11893 } 11894 NewVDs.push_back(NewVD); 11895 getSema().addInitCapture(LSI, NewVD); 11896 } 11897 11898 if (Invalid) 11899 break; 11900 11901 getDerived().transformedLocalDecl(OldVD, NewVDs); 11902 continue; 11903 } 11904 11905 assert(C->capturesVariable() && "unexpected kind of lambda capture"); 11906 11907 // Determine the capture kind for Sema. 11908 Sema::TryCaptureKind Kind 11909 = C->isImplicit()? Sema::TryCapture_Implicit 11910 : C->getCaptureKind() == LCK_ByCopy 11911 ? Sema::TryCapture_ExplicitByVal 11912 : Sema::TryCapture_ExplicitByRef; 11913 SourceLocation EllipsisLoc; 11914 if (C->isPackExpansion()) { 11915 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); 11916 bool ShouldExpand = false; 11917 bool RetainExpansion = false; 11918 Optional<unsigned> NumExpansions; 11919 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), 11920 C->getLocation(), 11921 Unexpanded, 11922 ShouldExpand, RetainExpansion, 11923 NumExpansions)) { 11924 Invalid = true; 11925 continue; 11926 } 11927 11928 if (ShouldExpand) { 11929 // The transform has determined that we should perform an expansion; 11930 // transform and capture each of the arguments. 11931 // expansion of the pattern. Do so. 11932 VarDecl *Pack = C->getCapturedVar(); 11933 for (unsigned I = 0; I != *NumExpansions; ++I) { 11934 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 11935 VarDecl *CapturedVar 11936 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), 11937 Pack)); 11938 if (!CapturedVar) { 11939 Invalid = true; 11940 continue; 11941 } 11942 11943 // Capture the transformed variable. 11944 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); 11945 } 11946 11947 // FIXME: Retain a pack expansion if RetainExpansion is true. 11948 11949 continue; 11950 } 11951 11952 EllipsisLoc = C->getEllipsisLoc(); 11953 } 11954 11955 // Transform the captured variable. 11956 VarDecl *CapturedVar 11957 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), 11958 C->getCapturedVar())); 11959 if (!CapturedVar || CapturedVar->isInvalidDecl()) { 11960 Invalid = true; 11961 continue; 11962 } 11963 11964 // Capture the transformed variable. 11965 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, 11966 EllipsisLoc); 11967 } 11968 getSema().finishLambdaExplicitCaptures(LSI); 11969 11970 // FIXME: Sema's lambda-building mechanism expects us to push an expression 11971 // evaluation context even if we're not transforming the function body. 11972 getSema().PushExpressionEvaluationContext( 11973 Sema::ExpressionEvaluationContext::PotentiallyEvaluated); 11974 11975 // Instantiate the body of the lambda expression. 11976 StmtResult Body = 11977 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody()); 11978 11979 // ActOnLambda* will pop the function scope for us. 11980 FuncScopeCleanup.disable(); 11981 11982 if (Body.isInvalid()) { 11983 SavedContext.pop(); 11984 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr, 11985 /*IsInstantiation=*/true); 11986 return ExprError(); 11987 } 11988 11989 // Copy the LSI before ActOnFinishFunctionBody removes it. 11990 // FIXME: This is dumb. Store the lambda information somewhere that outlives 11991 // the call operator. 11992 auto LSICopy = *LSI; 11993 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), 11994 /*IsInstantiation*/ true); 11995 SavedContext.pop(); 11996 11997 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(), 11998 &LSICopy); 11999 } 12000 12001 template<typename Derived> 12002 StmtResult 12003 TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) { 12004 return TransformStmt(S); 12005 } 12006 12007 template<typename Derived> 12008 StmtResult 12009 TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) { 12010 // Transform captures. 12011 for (LambdaExpr::capture_iterator C = E->capture_begin(), 12012 CEnd = E->capture_end(); 12013 C != CEnd; ++C) { 12014 // When we hit the first implicit capture, tell Sema that we've finished 12015 // the list of explicit captures. 12016 if (!C->isImplicit()) 12017 continue; 12018 12019 // Capturing 'this' is trivial. 12020 if (C->capturesThis()) { 12021 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), 12022 /*BuildAndDiagnose*/ true, nullptr, 12023 C->getCaptureKind() == LCK_StarThis); 12024 continue; 12025 } 12026 // Captured expression will be recaptured during captured variables 12027 // rebuilding. 12028 if (C->capturesVLAType()) 12029 continue; 12030 12031 assert(C->capturesVariable() && "unexpected kind of lambda capture"); 12032 assert(!E->isInitCapture(C) && "implicit init-capture?"); 12033 12034 // Transform the captured variable. 12035 VarDecl *CapturedVar = cast_or_null<VarDecl>( 12036 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar())); 12037 if (!CapturedVar || CapturedVar->isInvalidDecl()) 12038 return StmtError(); 12039 12040 // Capture the transformed variable. 12041 getSema().tryCaptureVariable(CapturedVar, C->getLocation()); 12042 } 12043 12044 return S; 12045 } 12046 12047 template<typename Derived> 12048 ExprResult 12049 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 12050 CXXUnresolvedConstructExpr *E) { 12051 TypeSourceInfo *T = 12052 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); 12053 if (!T) 12054 return ExprError(); 12055 12056 bool ArgumentChanged = false; 12057 SmallVector<Expr*, 8> Args; 12058 Args.reserve(E->arg_size()); 12059 { 12060 EnterExpressionEvaluationContext Context( 12061 getSema(), EnterExpressionEvaluationContext::InitList, 12062 E->isListInitialization()); 12063 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 12064 &ArgumentChanged)) 12065 return ExprError(); 12066 } 12067 12068 if (!getDerived().AlwaysRebuild() && 12069 T == E->getTypeSourceInfo() && 12070 !ArgumentChanged) 12071 return E; 12072 12073 // FIXME: we're faking the locations of the commas 12074 return getDerived().RebuildCXXUnresolvedConstructExpr( 12075 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization()); 12076 } 12077 12078 template<typename Derived> 12079 ExprResult 12080 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 12081 CXXDependentScopeMemberExpr *E) { 12082 // Transform the base of the expression. 12083 ExprResult Base((Expr*) nullptr); 12084 Expr *OldBase; 12085 QualType BaseType; 12086 QualType ObjectType; 12087 if (!E->isImplicitAccess()) { 12088 OldBase = E->getBase(); 12089 Base = getDerived().TransformExpr(OldBase); 12090 if (Base.isInvalid()) 12091 return ExprError(); 12092 12093 // Start the member reference and compute the object's type. 12094 ParsedType ObjectTy; 12095 bool MayBePseudoDestructor = false; 12096 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), 12097 E->getOperatorLoc(), 12098 E->isArrow()? tok::arrow : tok::period, 12099 ObjectTy, 12100 MayBePseudoDestructor); 12101 if (Base.isInvalid()) 12102 return ExprError(); 12103 12104 ObjectType = ObjectTy.get(); 12105 BaseType = ((Expr*) Base.get())->getType(); 12106 } else { 12107 OldBase = nullptr; 12108 BaseType = getDerived().TransformType(E->getBaseType()); 12109 ObjectType = BaseType->castAs<PointerType>()->getPointeeType(); 12110 } 12111 12112 // Transform the first part of the nested-name-specifier that qualifies 12113 // the member name. 12114 NamedDecl *FirstQualifierInScope 12115 = getDerived().TransformFirstQualifierInScope( 12116 E->getFirstQualifierFoundInScope(), 12117 E->getQualifierLoc().getBeginLoc()); 12118 12119 NestedNameSpecifierLoc QualifierLoc; 12120 if (E->getQualifier()) { 12121 QualifierLoc 12122 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 12123 ObjectType, 12124 FirstQualifierInScope); 12125 if (!QualifierLoc) 12126 return ExprError(); 12127 } 12128 12129 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 12130 12131 // TODO: If this is a conversion-function-id, verify that the 12132 // destination type name (if present) resolves the same way after 12133 // instantiation as it did in the local scope. 12134 12135 DeclarationNameInfo NameInfo 12136 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 12137 if (!NameInfo.getName()) 12138 return ExprError(); 12139 12140 if (!E->hasExplicitTemplateArgs()) { 12141 // This is a reference to a member without an explicitly-specified 12142 // template argument list. Optimize for this common case. 12143 if (!getDerived().AlwaysRebuild() && 12144 Base.get() == OldBase && 12145 BaseType == E->getBaseType() && 12146 QualifierLoc == E->getQualifierLoc() && 12147 NameInfo.getName() == E->getMember() && 12148 FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 12149 return E; 12150 12151 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 12152 BaseType, 12153 E->isArrow(), 12154 E->getOperatorLoc(), 12155 QualifierLoc, 12156 TemplateKWLoc, 12157 FirstQualifierInScope, 12158 NameInfo, 12159 /*TemplateArgs*/nullptr); 12160 } 12161 12162 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 12163 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 12164 E->getNumTemplateArgs(), 12165 TransArgs)) 12166 return ExprError(); 12167 12168 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 12169 BaseType, 12170 E->isArrow(), 12171 E->getOperatorLoc(), 12172 QualifierLoc, 12173 TemplateKWLoc, 12174 FirstQualifierInScope, 12175 NameInfo, 12176 &TransArgs); 12177 } 12178 12179 template<typename Derived> 12180 ExprResult 12181 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 12182 // Transform the base of the expression. 12183 ExprResult Base((Expr*) nullptr); 12184 QualType BaseType; 12185 if (!Old->isImplicitAccess()) { 12186 Base = getDerived().TransformExpr(Old->getBase()); 12187 if (Base.isInvalid()) 12188 return ExprError(); 12189 Base = getSema().PerformMemberExprBaseConversion(Base.get(), 12190 Old->isArrow()); 12191 if (Base.isInvalid()) 12192 return ExprError(); 12193 BaseType = Base.get()->getType(); 12194 } else { 12195 BaseType = getDerived().TransformType(Old->getBaseType()); 12196 } 12197 12198 NestedNameSpecifierLoc QualifierLoc; 12199 if (Old->getQualifierLoc()) { 12200 QualifierLoc 12201 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 12202 if (!QualifierLoc) 12203 return ExprError(); 12204 } 12205 12206 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 12207 12208 LookupResult R(SemaRef, Old->getMemberNameInfo(), 12209 Sema::LookupOrdinaryName); 12210 12211 // Transform the declaration set. 12212 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R)) 12213 return ExprError(); 12214 12215 // Determine the naming class. 12216 if (Old->getNamingClass()) { 12217 CXXRecordDecl *NamingClass 12218 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 12219 Old->getMemberLoc(), 12220 Old->getNamingClass())); 12221 if (!NamingClass) 12222 return ExprError(); 12223 12224 R.setNamingClass(NamingClass); 12225 } 12226 12227 TemplateArgumentListInfo TransArgs; 12228 if (Old->hasExplicitTemplateArgs()) { 12229 TransArgs.setLAngleLoc(Old->getLAngleLoc()); 12230 TransArgs.setRAngleLoc(Old->getRAngleLoc()); 12231 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 12232 Old->getNumTemplateArgs(), 12233 TransArgs)) 12234 return ExprError(); 12235 } 12236 12237 // FIXME: to do this check properly, we will need to preserve the 12238 // first-qualifier-in-scope here, just in case we had a dependent 12239 // base (and therefore couldn't do the check) and a 12240 // nested-name-qualifier (and therefore could do the lookup). 12241 NamedDecl *FirstQualifierInScope = nullptr; 12242 12243 return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 12244 BaseType, 12245 Old->getOperatorLoc(), 12246 Old->isArrow(), 12247 QualifierLoc, 12248 TemplateKWLoc, 12249 FirstQualifierInScope, 12250 R, 12251 (Old->hasExplicitTemplateArgs() 12252 ? &TransArgs : nullptr)); 12253 } 12254 12255 template<typename Derived> 12256 ExprResult 12257 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 12258 EnterExpressionEvaluationContext Unevaluated( 12259 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 12260 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 12261 if (SubExpr.isInvalid()) 12262 return ExprError(); 12263 12264 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 12265 return E; 12266 12267 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 12268 } 12269 12270 template<typename Derived> 12271 ExprResult 12272 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 12273 ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 12274 if (Pattern.isInvalid()) 12275 return ExprError(); 12276 12277 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 12278 return E; 12279 12280 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 12281 E->getNumExpansions()); 12282 } 12283 12284 template<typename Derived> 12285 ExprResult 12286 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 12287 // If E is not value-dependent, then nothing will change when we transform it. 12288 // Note: This is an instantiation-centric view. 12289 if (!E->isValueDependent()) 12290 return E; 12291 12292 EnterExpressionEvaluationContext Unevaluated( 12293 getSema(), Sema::ExpressionEvaluationContext::Unevaluated); 12294 12295 ArrayRef<TemplateArgument> PackArgs; 12296 TemplateArgument ArgStorage; 12297 12298 // Find the argument list to transform. 12299 if (E->isPartiallySubstituted()) { 12300 PackArgs = E->getPartialArguments(); 12301 } else if (E->isValueDependent()) { 12302 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 12303 bool ShouldExpand = false; 12304 bool RetainExpansion = false; 12305 Optional<unsigned> NumExpansions; 12306 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 12307 Unexpanded, 12308 ShouldExpand, RetainExpansion, 12309 NumExpansions)) 12310 return ExprError(); 12311 12312 // If we need to expand the pack, build a template argument from it and 12313 // expand that. 12314 if (ShouldExpand) { 12315 auto *Pack = E->getPack(); 12316 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { 12317 ArgStorage = getSema().Context.getPackExpansionType( 12318 getSema().Context.getTypeDeclType(TTPD), None); 12319 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { 12320 ArgStorage = TemplateArgument(TemplateName(TTPD), None); 12321 } else { 12322 auto *VD = cast<ValueDecl>(Pack); 12323 ExprResult DRE = getSema().BuildDeclRefExpr( 12324 VD, VD->getType().getNonLValueExprType(getSema().Context), 12325 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue, 12326 E->getPackLoc()); 12327 if (DRE.isInvalid()) 12328 return ExprError(); 12329 ArgStorage = new (getSema().Context) PackExpansionExpr( 12330 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None); 12331 } 12332 PackArgs = ArgStorage; 12333 } 12334 } 12335 12336 // If we're not expanding the pack, just transform the decl. 12337 if (!PackArgs.size()) { 12338 auto *Pack = cast_or_null<NamedDecl>( 12339 getDerived().TransformDecl(E->getPackLoc(), E->getPack())); 12340 if (!Pack) 12341 return ExprError(); 12342 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, 12343 E->getPackLoc(), 12344 E->getRParenLoc(), None, None); 12345 } 12346 12347 // Try to compute the result without performing a partial substitution. 12348 Optional<unsigned> Result = 0; 12349 for (const TemplateArgument &Arg : PackArgs) { 12350 if (!Arg.isPackExpansion()) { 12351 Result = *Result + 1; 12352 continue; 12353 } 12354 12355 TemplateArgumentLoc ArgLoc; 12356 InventTemplateArgumentLoc(Arg, ArgLoc); 12357 12358 // Find the pattern of the pack expansion. 12359 SourceLocation Ellipsis; 12360 Optional<unsigned> OrigNumExpansions; 12361 TemplateArgumentLoc Pattern = 12362 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis, 12363 OrigNumExpansions); 12364 12365 // Substitute under the pack expansion. Do not expand the pack (yet). 12366 TemplateArgumentLoc OutPattern; 12367 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 12368 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, 12369 /*Uneval*/ true)) 12370 return true; 12371 12372 // See if we can determine the number of arguments from the result. 12373 Optional<unsigned> NumExpansions = 12374 getSema().getFullyPackExpandedSize(OutPattern.getArgument()); 12375 if (!NumExpansions) { 12376 // No: we must be in an alias template expansion, and we're going to need 12377 // to actually expand the packs. 12378 Result = None; 12379 break; 12380 } 12381 12382 Result = *Result + *NumExpansions; 12383 } 12384 12385 // Common case: we could determine the number of expansions without 12386 // substituting. 12387 if (Result) 12388 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), 12389 E->getPackLoc(), 12390 E->getRParenLoc(), *Result, None); 12391 12392 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), 12393 E->getPackLoc()); 12394 { 12395 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); 12396 typedef TemplateArgumentLocInventIterator< 12397 Derived, const TemplateArgument*> PackLocIterator; 12398 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), 12399 PackLocIterator(*this, PackArgs.end()), 12400 TransformedPackArgs, /*Uneval*/true)) 12401 return ExprError(); 12402 } 12403 12404 // Check whether we managed to fully-expand the pack. 12405 // FIXME: Is it possible for us to do so and not hit the early exit path? 12406 SmallVector<TemplateArgument, 8> Args; 12407 bool PartialSubstitution = false; 12408 for (auto &Loc : TransformedPackArgs.arguments()) { 12409 Args.push_back(Loc.getArgument()); 12410 if (Loc.getArgument().isPackExpansion()) 12411 PartialSubstitution = true; 12412 } 12413 12414 if (PartialSubstitution) 12415 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), 12416 E->getPackLoc(), 12417 E->getRParenLoc(), None, Args); 12418 12419 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), 12420 E->getPackLoc(), E->getRParenLoc(), 12421 Args.size(), None); 12422 } 12423 12424 template<typename Derived> 12425 ExprResult 12426 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 12427 SubstNonTypeTemplateParmPackExpr *E) { 12428 // Default behavior is to do nothing with this transformation. 12429 return E; 12430 } 12431 12432 template<typename Derived> 12433 ExprResult 12434 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( 12435 SubstNonTypeTemplateParmExpr *E) { 12436 // Default behavior is to do nothing with this transformation. 12437 return E; 12438 } 12439 12440 template<typename Derived> 12441 ExprResult 12442 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { 12443 // Default behavior is to do nothing with this transformation. 12444 return E; 12445 } 12446 12447 template<typename Derived> 12448 ExprResult 12449 TreeTransform<Derived>::TransformMaterializeTemporaryExpr( 12450 MaterializeTemporaryExpr *E) { 12451 return getDerived().TransformExpr(E->getSubExpr()); 12452 } 12453 12454 template<typename Derived> 12455 ExprResult 12456 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { 12457 Expr *Pattern = E->getPattern(); 12458 12459 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 12460 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 12461 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 12462 12463 // Determine whether the set of unexpanded parameter packs can and should 12464 // be expanded. 12465 bool Expand = true; 12466 bool RetainExpansion = false; 12467 Optional<unsigned> OrigNumExpansions = E->getNumExpansions(), 12468 NumExpansions = OrigNumExpansions; 12469 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), 12470 Pattern->getSourceRange(), 12471 Unexpanded, 12472 Expand, RetainExpansion, 12473 NumExpansions)) 12474 return true; 12475 12476 if (!Expand) { 12477 // Do not expand any packs here, just transform and rebuild a fold 12478 // expression. 12479 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 12480 12481 ExprResult LHS = 12482 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); 12483 if (LHS.isInvalid()) 12484 return true; 12485 12486 ExprResult RHS = 12487 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); 12488 if (RHS.isInvalid()) 12489 return true; 12490 12491 if (!getDerived().AlwaysRebuild() && 12492 LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) 12493 return E; 12494 12495 return getDerived().RebuildCXXFoldExpr( 12496 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(), 12497 RHS.get(), E->getEndLoc(), NumExpansions); 12498 } 12499 12500 // The transform has determined that we should perform an elementwise 12501 // expansion of the pattern. Do so. 12502 ExprResult Result = getDerived().TransformExpr(E->getInit()); 12503 if (Result.isInvalid()) 12504 return true; 12505 bool LeftFold = E->isLeftFold(); 12506 12507 // If we're retaining an expansion for a right fold, it is the innermost 12508 // component and takes the init (if any). 12509 if (!LeftFold && RetainExpansion) { 12510 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 12511 12512 ExprResult Out = getDerived().TransformExpr(Pattern); 12513 if (Out.isInvalid()) 12514 return true; 12515 12516 Result = getDerived().RebuildCXXFoldExpr( 12517 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(), 12518 Result.get(), E->getEndLoc(), OrigNumExpansions); 12519 if (Result.isInvalid()) 12520 return true; 12521 } 12522 12523 for (unsigned I = 0; I != *NumExpansions; ++I) { 12524 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( 12525 getSema(), LeftFold ? I : *NumExpansions - I - 1); 12526 ExprResult Out = getDerived().TransformExpr(Pattern); 12527 if (Out.isInvalid()) 12528 return true; 12529 12530 if (Out.get()->containsUnexpandedParameterPack()) { 12531 // We still have a pack; retain a pack expansion for this slice. 12532 Result = getDerived().RebuildCXXFoldExpr( 12533 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(), 12534 E->getOperator(), E->getEllipsisLoc(), 12535 LeftFold ? Out.get() : Result.get(), E->getEndLoc(), 12536 OrigNumExpansions); 12537 } else if (Result.isUsable()) { 12538 // We've got down to a single element; build a binary operator. 12539 Result = getDerived().RebuildBinaryOperator( 12540 E->getEllipsisLoc(), E->getOperator(), 12541 LeftFold ? Result.get() : Out.get(), 12542 LeftFold ? Out.get() : Result.get()); 12543 } else 12544 Result = Out; 12545 12546 if (Result.isInvalid()) 12547 return true; 12548 } 12549 12550 // If we're retaining an expansion for a left fold, it is the outermost 12551 // component and takes the complete expansion so far as its init (if any). 12552 if (LeftFold && RetainExpansion) { 12553 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 12554 12555 ExprResult Out = getDerived().TransformExpr(Pattern); 12556 if (Out.isInvalid()) 12557 return true; 12558 12559 Result = getDerived().RebuildCXXFoldExpr( 12560 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(), 12561 Out.get(), E->getEndLoc(), OrigNumExpansions); 12562 if (Result.isInvalid()) 12563 return true; 12564 } 12565 12566 // If we had no init and an empty pack, and we're not retaining an expansion, 12567 // then produce a fallback value or error. 12568 if (Result.isUnset()) 12569 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), 12570 E->getOperator()); 12571 12572 return Result; 12573 } 12574 12575 template<typename Derived> 12576 ExprResult 12577 TreeTransform<Derived>::TransformCXXStdInitializerListExpr( 12578 CXXStdInitializerListExpr *E) { 12579 return getDerived().TransformExpr(E->getSubExpr()); 12580 } 12581 12582 template<typename Derived> 12583 ExprResult 12584 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 12585 return SemaRef.MaybeBindToTemporary(E); 12586 } 12587 12588 template<typename Derived> 12589 ExprResult 12590 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { 12591 return E; 12592 } 12593 12594 template<typename Derived> 12595 ExprResult 12596 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { 12597 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 12598 if (SubExpr.isInvalid()) 12599 return ExprError(); 12600 12601 if (!getDerived().AlwaysRebuild() && 12602 SubExpr.get() == E->getSubExpr()) 12603 return E; 12604 12605 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); 12606 } 12607 12608 template<typename Derived> 12609 ExprResult 12610 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { 12611 // Transform each of the elements. 12612 SmallVector<Expr *, 8> Elements; 12613 bool ArgChanged = false; 12614 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), 12615 /*IsCall=*/false, Elements, &ArgChanged)) 12616 return ExprError(); 12617 12618 if (!getDerived().AlwaysRebuild() && !ArgChanged) 12619 return SemaRef.MaybeBindToTemporary(E); 12620 12621 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), 12622 Elements.data(), 12623 Elements.size()); 12624 } 12625 12626 template<typename Derived> 12627 ExprResult 12628 TreeTransform<Derived>::TransformObjCDictionaryLiteral( 12629 ObjCDictionaryLiteral *E) { 12630 // Transform each of the elements. 12631 SmallVector<ObjCDictionaryElement, 8> Elements; 12632 bool ArgChanged = false; 12633 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { 12634 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); 12635 12636 if (OrigElement.isPackExpansion()) { 12637 // This key/value element is a pack expansion. 12638 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 12639 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); 12640 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); 12641 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 12642 12643 // Determine whether the set of unexpanded parameter packs can 12644 // and should be expanded. 12645 bool Expand = true; 12646 bool RetainExpansion = false; 12647 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; 12648 Optional<unsigned> NumExpansions = OrigNumExpansions; 12649 SourceRange PatternRange(OrigElement.Key->getBeginLoc(), 12650 OrigElement.Value->getEndLoc()); 12651 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, 12652 PatternRange, Unexpanded, Expand, 12653 RetainExpansion, NumExpansions)) 12654 return ExprError(); 12655 12656 if (!Expand) { 12657 // The transform has determined that we should perform a simple 12658 // transformation on the pack expansion, producing another pack 12659 // expansion. 12660 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 12661 ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 12662 if (Key.isInvalid()) 12663 return ExprError(); 12664 12665 if (Key.get() != OrigElement.Key) 12666 ArgChanged = true; 12667 12668 ExprResult Value = getDerived().TransformExpr(OrigElement.Value); 12669 if (Value.isInvalid()) 12670 return ExprError(); 12671 12672 if (Value.get() != OrigElement.Value) 12673 ArgChanged = true; 12674 12675 ObjCDictionaryElement Expansion = { 12676 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions 12677 }; 12678 Elements.push_back(Expansion); 12679 continue; 12680 } 12681 12682 // Record right away that the argument was changed. This needs 12683 // to happen even if the array expands to nothing. 12684 ArgChanged = true; 12685 12686 // The transform has determined that we should perform an elementwise 12687 // expansion of the pattern. Do so. 12688 for (unsigned I = 0; I != *NumExpansions; ++I) { 12689 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 12690 ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 12691 if (Key.isInvalid()) 12692 return ExprError(); 12693 12694 ExprResult Value = getDerived().TransformExpr(OrigElement.Value); 12695 if (Value.isInvalid()) 12696 return ExprError(); 12697 12698 ObjCDictionaryElement Element = { 12699 Key.get(), Value.get(), SourceLocation(), NumExpansions 12700 }; 12701 12702 // If any unexpanded parameter packs remain, we still have a 12703 // pack expansion. 12704 // FIXME: Can this really happen? 12705 if (Key.get()->containsUnexpandedParameterPack() || 12706 Value.get()->containsUnexpandedParameterPack()) 12707 Element.EllipsisLoc = OrigElement.EllipsisLoc; 12708 12709 Elements.push_back(Element); 12710 } 12711 12712 // FIXME: Retain a pack expansion if RetainExpansion is true. 12713 12714 // We've finished with this pack expansion. 12715 continue; 12716 } 12717 12718 // Transform and check key. 12719 ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 12720 if (Key.isInvalid()) 12721 return ExprError(); 12722 12723 if (Key.get() != OrigElement.Key) 12724 ArgChanged = true; 12725 12726 // Transform and check value. 12727 ExprResult Value 12728 = getDerived().TransformExpr(OrigElement.Value); 12729 if (Value.isInvalid()) 12730 return ExprError(); 12731 12732 if (Value.get() != OrigElement.Value) 12733 ArgChanged = true; 12734 12735 ObjCDictionaryElement Element = { 12736 Key.get(), Value.get(), SourceLocation(), None 12737 }; 12738 Elements.push_back(Element); 12739 } 12740 12741 if (!getDerived().AlwaysRebuild() && !ArgChanged) 12742 return SemaRef.MaybeBindToTemporary(E); 12743 12744 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), 12745 Elements); 12746 } 12747 12748 template<typename Derived> 12749 ExprResult 12750 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 12751 TypeSourceInfo *EncodedTypeInfo 12752 = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 12753 if (!EncodedTypeInfo) 12754 return ExprError(); 12755 12756 if (!getDerived().AlwaysRebuild() && 12757 EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 12758 return E; 12759 12760 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 12761 EncodedTypeInfo, 12762 E->getRParenLoc()); 12763 } 12764 12765 template<typename Derived> 12766 ExprResult TreeTransform<Derived>:: 12767 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 12768 // This is a kind of implicit conversion, and it needs to get dropped 12769 // and recomputed for the same general reasons that ImplicitCastExprs 12770 // do, as well a more specific one: this expression is only valid when 12771 // it appears *immediately* as an argument expression. 12772 return getDerived().TransformExpr(E->getSubExpr()); 12773 } 12774 12775 template<typename Derived> 12776 ExprResult TreeTransform<Derived>:: 12777 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 12778 TypeSourceInfo *TSInfo 12779 = getDerived().TransformType(E->getTypeInfoAsWritten()); 12780 if (!TSInfo) 12781 return ExprError(); 12782 12783 ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); 12784 if (Result.isInvalid()) 12785 return ExprError(); 12786 12787 if (!getDerived().AlwaysRebuild() && 12788 TSInfo == E->getTypeInfoAsWritten() && 12789 Result.get() == E->getSubExpr()) 12790 return E; 12791 12792 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), 12793 E->getBridgeKeywordLoc(), TSInfo, 12794 Result.get()); 12795 } 12796 12797 template <typename Derived> 12798 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr( 12799 ObjCAvailabilityCheckExpr *E) { 12800 return E; 12801 } 12802 12803 template<typename Derived> 12804 ExprResult 12805 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 12806 // Transform arguments. 12807 bool ArgChanged = false; 12808 SmallVector<Expr*, 8> Args; 12809 Args.reserve(E->getNumArgs()); 12810 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 12811 &ArgChanged)) 12812 return ExprError(); 12813 12814 if (E->getReceiverKind() == ObjCMessageExpr::Class) { 12815 // Class message: transform the receiver type. 12816 TypeSourceInfo *ReceiverTypeInfo 12817 = getDerived().TransformType(E->getClassReceiverTypeInfo()); 12818 if (!ReceiverTypeInfo) 12819 return ExprError(); 12820 12821 // If nothing changed, just retain the existing message send. 12822 if (!getDerived().AlwaysRebuild() && 12823 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 12824 return SemaRef.MaybeBindToTemporary(E); 12825 12826 // Build a new class message send. 12827 SmallVector<SourceLocation, 16> SelLocs; 12828 E->getSelectorLocs(SelLocs); 12829 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 12830 E->getSelector(), 12831 SelLocs, 12832 E->getMethodDecl(), 12833 E->getLeftLoc(), 12834 Args, 12835 E->getRightLoc()); 12836 } 12837 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || 12838 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { 12839 if (!E->getMethodDecl()) 12840 return ExprError(); 12841 12842 // Build a new class message send to 'super'. 12843 SmallVector<SourceLocation, 16> SelLocs; 12844 E->getSelectorLocs(SelLocs); 12845 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), 12846 E->getSelector(), 12847 SelLocs, 12848 E->getReceiverType(), 12849 E->getMethodDecl(), 12850 E->getLeftLoc(), 12851 Args, 12852 E->getRightLoc()); 12853 } 12854 12855 // Instance message: transform the receiver 12856 assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 12857 "Only class and instance messages may be instantiated"); 12858 ExprResult Receiver 12859 = getDerived().TransformExpr(E->getInstanceReceiver()); 12860 if (Receiver.isInvalid()) 12861 return ExprError(); 12862 12863 // If nothing changed, just retain the existing message send. 12864 if (!getDerived().AlwaysRebuild() && 12865 Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 12866 return SemaRef.MaybeBindToTemporary(E); 12867 12868 // Build a new instance message send. 12869 SmallVector<SourceLocation, 16> SelLocs; 12870 E->getSelectorLocs(SelLocs); 12871 return getDerived().RebuildObjCMessageExpr(Receiver.get(), 12872 E->getSelector(), 12873 SelLocs, 12874 E->getMethodDecl(), 12875 E->getLeftLoc(), 12876 Args, 12877 E->getRightLoc()); 12878 } 12879 12880 template<typename Derived> 12881 ExprResult 12882 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 12883 return E; 12884 } 12885 12886 template<typename Derived> 12887 ExprResult 12888 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 12889 return E; 12890 } 12891 12892 template<typename Derived> 12893 ExprResult 12894 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 12895 // Transform the base expression. 12896 ExprResult Base = getDerived().TransformExpr(E->getBase()); 12897 if (Base.isInvalid()) 12898 return ExprError(); 12899 12900 // We don't need to transform the ivar; it will never change. 12901 12902 // If nothing changed, just retain the existing expression. 12903 if (!getDerived().AlwaysRebuild() && 12904 Base.get() == E->getBase()) 12905 return E; 12906 12907 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 12908 E->getLocation(), 12909 E->isArrow(), E->isFreeIvar()); 12910 } 12911 12912 template<typename Derived> 12913 ExprResult 12914 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 12915 // 'super' and types never change. Property never changes. Just 12916 // retain the existing expression. 12917 if (!E->isObjectReceiver()) 12918 return E; 12919 12920 // Transform the base expression. 12921 ExprResult Base = getDerived().TransformExpr(E->getBase()); 12922 if (Base.isInvalid()) 12923 return ExprError(); 12924 12925 // We don't need to transform the property; it will never change. 12926 12927 // If nothing changed, just retain the existing expression. 12928 if (!getDerived().AlwaysRebuild() && 12929 Base.get() == E->getBase()) 12930 return E; 12931 12932 if (E->isExplicitProperty()) 12933 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 12934 E->getExplicitProperty(), 12935 E->getLocation()); 12936 12937 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 12938 SemaRef.Context.PseudoObjectTy, 12939 E->getImplicitPropertyGetter(), 12940 E->getImplicitPropertySetter(), 12941 E->getLocation()); 12942 } 12943 12944 template<typename Derived> 12945 ExprResult 12946 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { 12947 // Transform the base expression. 12948 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); 12949 if (Base.isInvalid()) 12950 return ExprError(); 12951 12952 // Transform the key expression. 12953 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); 12954 if (Key.isInvalid()) 12955 return ExprError(); 12956 12957 // If nothing changed, just retain the existing expression. 12958 if (!getDerived().AlwaysRebuild() && 12959 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) 12960 return E; 12961 12962 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), 12963 Base.get(), Key.get(), 12964 E->getAtIndexMethodDecl(), 12965 E->setAtIndexMethodDecl()); 12966 } 12967 12968 template<typename Derived> 12969 ExprResult 12970 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 12971 // Transform the base expression. 12972 ExprResult Base = getDerived().TransformExpr(E->getBase()); 12973 if (Base.isInvalid()) 12974 return ExprError(); 12975 12976 // If nothing changed, just retain the existing expression. 12977 if (!getDerived().AlwaysRebuild() && 12978 Base.get() == E->getBase()) 12979 return E; 12980 12981 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 12982 E->getOpLoc(), 12983 E->isArrow()); 12984 } 12985 12986 template<typename Derived> 12987 ExprResult 12988 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 12989 bool ArgumentChanged = false; 12990 SmallVector<Expr*, 8> SubExprs; 12991 SubExprs.reserve(E->getNumSubExprs()); 12992 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 12993 SubExprs, &ArgumentChanged)) 12994 return ExprError(); 12995 12996 if (!getDerived().AlwaysRebuild() && 12997 !ArgumentChanged) 12998 return E; 12999 13000 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 13001 SubExprs, 13002 E->getRParenLoc()); 13003 } 13004 13005 template<typename Derived> 13006 ExprResult 13007 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { 13008 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); 13009 if (SrcExpr.isInvalid()) 13010 return ExprError(); 13011 13012 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 13013 if (!Type) 13014 return ExprError(); 13015 13016 if (!getDerived().AlwaysRebuild() && 13017 Type == E->getTypeSourceInfo() && 13018 SrcExpr.get() == E->getSrcExpr()) 13019 return E; 13020 13021 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), 13022 SrcExpr.get(), Type, 13023 E->getRParenLoc()); 13024 } 13025 13026 template<typename Derived> 13027 ExprResult 13028 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 13029 BlockDecl *oldBlock = E->getBlockDecl(); 13030 13031 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); 13032 BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 13033 13034 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 13035 blockScope->TheDecl->setBlockMissingReturnType( 13036 oldBlock->blockMissingReturnType()); 13037 13038 SmallVector<ParmVarDecl*, 4> params; 13039 SmallVector<QualType, 4> paramTypes; 13040 13041 const FunctionProtoType *exprFunctionType = E->getFunctionType(); 13042 13043 // Parameter substitution. 13044 Sema::ExtParameterInfoBuilder extParamInfos; 13045 if (getDerived().TransformFunctionTypeParams( 13046 E->getCaretLocation(), oldBlock->parameters(), nullptr, 13047 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, 13048 extParamInfos)) { 13049 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); 13050 return ExprError(); 13051 } 13052 13053 QualType exprResultType = 13054 getDerived().TransformType(exprFunctionType->getReturnType()); 13055 13056 auto epi = exprFunctionType->getExtProtoInfo(); 13057 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size()); 13058 13059 QualType functionType = 13060 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi); 13061 blockScope->FunctionType = functionType; 13062 13063 // Set the parameters on the block decl. 13064 if (!params.empty()) 13065 blockScope->TheDecl->setParams(params); 13066 13067 if (!oldBlock->blockMissingReturnType()) { 13068 blockScope->HasImplicitReturnType = false; 13069 blockScope->ReturnType = exprResultType; 13070 } 13071 13072 // Transform the body 13073 StmtResult body = getDerived().TransformStmt(E->getBody()); 13074 if (body.isInvalid()) { 13075 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); 13076 return ExprError(); 13077 } 13078 13079 #ifndef NDEBUG 13080 // In builds with assertions, make sure that we captured everything we 13081 // captured before. 13082 if (!SemaRef.getDiagnostics().hasErrorOccurred()) { 13083 for (const auto &I : oldBlock->captures()) { 13084 VarDecl *oldCapture = I.getVariable(); 13085 13086 // Ignore parameter packs. 13087 if (oldCapture->isParameterPack()) 13088 continue; 13089 13090 VarDecl *newCapture = 13091 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 13092 oldCapture)); 13093 assert(blockScope->CaptureMap.count(newCapture)); 13094 } 13095 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); 13096 } 13097 #endif 13098 13099 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 13100 /*Scope=*/nullptr); 13101 } 13102 13103 template<typename Derived> 13104 ExprResult 13105 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { 13106 llvm_unreachable("Cannot transform asType expressions yet"); 13107 } 13108 13109 template<typename Derived> 13110 ExprResult 13111 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { 13112 bool ArgumentChanged = false; 13113 SmallVector<Expr*, 8> SubExprs; 13114 SubExprs.reserve(E->getNumSubExprs()); 13115 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 13116 SubExprs, &ArgumentChanged)) 13117 return ExprError(); 13118 13119 if (!getDerived().AlwaysRebuild() && 13120 !ArgumentChanged) 13121 return E; 13122 13123 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, 13124 E->getOp(), E->getRParenLoc()); 13125 } 13126 13127 //===----------------------------------------------------------------------===// 13128 // Type reconstruction 13129 //===----------------------------------------------------------------------===// 13130 13131 template<typename Derived> 13132 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 13133 SourceLocation Star) { 13134 return SemaRef.BuildPointerType(PointeeType, Star, 13135 getDerived().getBaseEntity()); 13136 } 13137 13138 template<typename Derived> 13139 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 13140 SourceLocation Star) { 13141 return SemaRef.BuildBlockPointerType(PointeeType, Star, 13142 getDerived().getBaseEntity()); 13143 } 13144 13145 template<typename Derived> 13146 QualType 13147 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 13148 bool WrittenAsLValue, 13149 SourceLocation Sigil) { 13150 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 13151 Sigil, getDerived().getBaseEntity()); 13152 } 13153 13154 template<typename Derived> 13155 QualType 13156 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 13157 QualType ClassType, 13158 SourceLocation Sigil) { 13159 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, 13160 getDerived().getBaseEntity()); 13161 } 13162 13163 template<typename Derived> 13164 QualType TreeTransform<Derived>::RebuildObjCTypeParamType( 13165 const ObjCTypeParamDecl *Decl, 13166 SourceLocation ProtocolLAngleLoc, 13167 ArrayRef<ObjCProtocolDecl *> Protocols, 13168 ArrayRef<SourceLocation> ProtocolLocs, 13169 SourceLocation ProtocolRAngleLoc) { 13170 return SemaRef.BuildObjCTypeParamType(Decl, 13171 ProtocolLAngleLoc, Protocols, 13172 ProtocolLocs, ProtocolRAngleLoc, 13173 /*FailOnError=*/true); 13174 } 13175 13176 template<typename Derived> 13177 QualType TreeTransform<Derived>::RebuildObjCObjectType( 13178 QualType BaseType, 13179 SourceLocation Loc, 13180 SourceLocation TypeArgsLAngleLoc, 13181 ArrayRef<TypeSourceInfo *> TypeArgs, 13182 SourceLocation TypeArgsRAngleLoc, 13183 SourceLocation ProtocolLAngleLoc, 13184 ArrayRef<ObjCProtocolDecl *> Protocols, 13185 ArrayRef<SourceLocation> ProtocolLocs, 13186 SourceLocation ProtocolRAngleLoc) { 13187 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, 13188 TypeArgs, TypeArgsRAngleLoc, 13189 ProtocolLAngleLoc, Protocols, ProtocolLocs, 13190 ProtocolRAngleLoc, 13191 /*FailOnError=*/true); 13192 } 13193 13194 template<typename Derived> 13195 QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( 13196 QualType PointeeType, 13197 SourceLocation Star) { 13198 return SemaRef.Context.getObjCObjectPointerType(PointeeType); 13199 } 13200 13201 template<typename Derived> 13202 QualType 13203 TreeTransform<Derived>::RebuildArrayType(QualType ElementType, 13204 ArrayType::ArraySizeModifier SizeMod, 13205 const llvm::APInt *Size, 13206 Expr *SizeExpr, 13207 unsigned IndexTypeQuals, 13208 SourceRange BracketsRange) { 13209 if (SizeExpr || !Size) 13210 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 13211 IndexTypeQuals, BracketsRange, 13212 getDerived().getBaseEntity()); 13213 13214 QualType Types[] = { 13215 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 13216 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 13217 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 13218 }; 13219 const unsigned NumTypes = llvm::array_lengthof(Types); 13220 QualType SizeType; 13221 for (unsigned I = 0; I != NumTypes; ++I) 13222 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 13223 SizeType = Types[I]; 13224 break; 13225 } 13226 13227 // Note that we can return a VariableArrayType here in the case where 13228 // the element type was a dependent VariableArrayType. 13229 IntegerLiteral *ArraySize 13230 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, 13231 /*FIXME*/BracketsRange.getBegin()); 13232 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, 13233 IndexTypeQuals, BracketsRange, 13234 getDerived().getBaseEntity()); 13235 } 13236 13237 template<typename Derived> 13238 QualType 13239 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 13240 ArrayType::ArraySizeModifier SizeMod, 13241 const llvm::APInt &Size, 13242 Expr *SizeExpr, 13243 unsigned IndexTypeQuals, 13244 SourceRange BracketsRange) { 13245 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr, 13246 IndexTypeQuals, BracketsRange); 13247 } 13248 13249 template<typename Derived> 13250 QualType 13251 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 13252 ArrayType::ArraySizeModifier SizeMod, 13253 unsigned IndexTypeQuals, 13254 SourceRange BracketsRange) { 13255 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, 13256 IndexTypeQuals, BracketsRange); 13257 } 13258 13259 template<typename Derived> 13260 QualType 13261 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 13262 ArrayType::ArraySizeModifier SizeMod, 13263 Expr *SizeExpr, 13264 unsigned IndexTypeQuals, 13265 SourceRange BracketsRange) { 13266 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, 13267 SizeExpr, 13268 IndexTypeQuals, BracketsRange); 13269 } 13270 13271 template<typename Derived> 13272 QualType 13273 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 13274 ArrayType::ArraySizeModifier SizeMod, 13275 Expr *SizeExpr, 13276 unsigned IndexTypeQuals, 13277 SourceRange BracketsRange) { 13278 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, 13279 SizeExpr, 13280 IndexTypeQuals, BracketsRange); 13281 } 13282 13283 template <typename Derived> 13284 QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType( 13285 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) { 13286 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr, 13287 AttributeLoc); 13288 } 13289 13290 template <typename Derived> 13291 QualType 13292 TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 13293 unsigned NumElements, 13294 VectorType::VectorKind VecKind) { 13295 // FIXME: semantic checking! 13296 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 13297 } 13298 13299 template <typename Derived> 13300 QualType TreeTransform<Derived>::RebuildDependentVectorType( 13301 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, 13302 VectorType::VectorKind VecKind) { 13303 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc); 13304 } 13305 13306 template<typename Derived> 13307 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 13308 unsigned NumElements, 13309 SourceLocation AttributeLoc) { 13310 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 13311 NumElements, true); 13312 IntegerLiteral *VectorSize 13313 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 13314 AttributeLoc); 13315 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 13316 } 13317 13318 template<typename Derived> 13319 QualType 13320 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 13321 Expr *SizeExpr, 13322 SourceLocation AttributeLoc) { 13323 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 13324 } 13325 13326 template<typename Derived> 13327 QualType TreeTransform<Derived>::RebuildFunctionProtoType( 13328 QualType T, 13329 MutableArrayRef<QualType> ParamTypes, 13330 const FunctionProtoType::ExtProtoInfo &EPI) { 13331 return SemaRef.BuildFunctionType(T, ParamTypes, 13332 getDerived().getBaseLocation(), 13333 getDerived().getBaseEntity(), 13334 EPI); 13335 } 13336 13337 template<typename Derived> 13338 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 13339 return SemaRef.Context.getFunctionNoProtoType(T); 13340 } 13341 13342 template<typename Derived> 13343 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc, 13344 Decl *D) { 13345 assert(D && "no decl found"); 13346 if (D->isInvalidDecl()) return QualType(); 13347 13348 // FIXME: Doesn't account for ObjCInterfaceDecl! 13349 TypeDecl *Ty; 13350 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) { 13351 // A valid resolved using typename pack expansion decl can have multiple 13352 // UsingDecls, but they must each have exactly one type, and it must be 13353 // the same type in every case. But we must have at least one expansion! 13354 if (UPD->expansions().empty()) { 13355 getSema().Diag(Loc, diag::err_using_pack_expansion_empty) 13356 << UPD->isCXXClassMember() << UPD; 13357 return QualType(); 13358 } 13359 13360 // We might still have some unresolved types. Try to pick a resolved type 13361 // if we can. The final instantiation will check that the remaining 13362 // unresolved types instantiate to the type we pick. 13363 QualType FallbackT; 13364 QualType T; 13365 for (auto *E : UPD->expansions()) { 13366 QualType ThisT = RebuildUnresolvedUsingType(Loc, E); 13367 if (ThisT.isNull()) 13368 continue; 13369 else if (ThisT->getAs<UnresolvedUsingType>()) 13370 FallbackT = ThisT; 13371 else if (T.isNull()) 13372 T = ThisT; 13373 else 13374 assert(getSema().Context.hasSameType(ThisT, T) && 13375 "mismatched resolved types in using pack expansion"); 13376 } 13377 return T.isNull() ? FallbackT : T; 13378 } else if (auto *Using = dyn_cast<UsingDecl>(D)) { 13379 assert(Using->hasTypename() && 13380 "UnresolvedUsingTypenameDecl transformed to non-typename using"); 13381 13382 // A valid resolved using typename decl points to exactly one type decl. 13383 assert(++Using->shadow_begin() == Using->shadow_end()); 13384 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 13385 } else { 13386 assert(isa<UnresolvedUsingTypenameDecl>(D) && 13387 "UnresolvedUsingTypenameDecl transformed to non-using decl"); 13388 Ty = cast<UnresolvedUsingTypenameDecl>(D); 13389 } 13390 13391 return SemaRef.Context.getTypeDeclType(Ty); 13392 } 13393 13394 template<typename Derived> 13395 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 13396 SourceLocation Loc) { 13397 return SemaRef.BuildTypeofExprType(E, Loc); 13398 } 13399 13400 template<typename Derived> 13401 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 13402 return SemaRef.Context.getTypeOfType(Underlying); 13403 } 13404 13405 template<typename Derived> 13406 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 13407 SourceLocation Loc) { 13408 return SemaRef.BuildDecltypeType(E, Loc); 13409 } 13410 13411 template<typename Derived> 13412 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, 13413 UnaryTransformType::UTTKind UKind, 13414 SourceLocation Loc) { 13415 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); 13416 } 13417 13418 template<typename Derived> 13419 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 13420 TemplateName Template, 13421 SourceLocation TemplateNameLoc, 13422 TemplateArgumentListInfo &TemplateArgs) { 13423 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 13424 } 13425 13426 template<typename Derived> 13427 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, 13428 SourceLocation KWLoc) { 13429 return SemaRef.BuildAtomicType(ValueType, KWLoc); 13430 } 13431 13432 template<typename Derived> 13433 QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType, 13434 SourceLocation KWLoc, 13435 bool isReadPipe) { 13436 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc) 13437 : SemaRef.BuildWritePipeType(ValueType, KWLoc); 13438 } 13439 13440 template<typename Derived> 13441 TemplateName 13442 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 13443 bool TemplateKW, 13444 TemplateDecl *Template) { 13445 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, 13446 Template); 13447 } 13448 13449 template<typename Derived> 13450 TemplateName 13451 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 13452 SourceLocation TemplateKWLoc, 13453 const IdentifierInfo &Name, 13454 SourceLocation NameLoc, 13455 QualType ObjectType, 13456 NamedDecl *FirstQualifierInScope, 13457 bool AllowInjectedClassName) { 13458 UnqualifiedId TemplateName; 13459 TemplateName.setIdentifier(&Name, NameLoc); 13460 Sema::TemplateTy Template; 13461 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, 13462 SS, TemplateKWLoc, TemplateName, 13463 ParsedType::make(ObjectType), 13464 /*EnteringContext=*/false, 13465 Template, AllowInjectedClassName); 13466 return Template.get(); 13467 } 13468 13469 template<typename Derived> 13470 TemplateName 13471 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 13472 SourceLocation TemplateKWLoc, 13473 OverloadedOperatorKind Operator, 13474 SourceLocation NameLoc, 13475 QualType ObjectType, 13476 bool AllowInjectedClassName) { 13477 UnqualifiedId Name; 13478 // FIXME: Bogus location information. 13479 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; 13480 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); 13481 Sema::TemplateTy Template; 13482 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, 13483 SS, TemplateKWLoc, Name, 13484 ParsedType::make(ObjectType), 13485 /*EnteringContext=*/false, 13486 Template, AllowInjectedClassName); 13487 return Template.get(); 13488 } 13489 13490 template<typename Derived> 13491 ExprResult 13492 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 13493 SourceLocation OpLoc, 13494 Expr *OrigCallee, 13495 Expr *First, 13496 Expr *Second) { 13497 Expr *Callee = OrigCallee->IgnoreParenCasts(); 13498 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 13499 13500 if (First->getObjectKind() == OK_ObjCProperty) { 13501 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 13502 if (BinaryOperator::isAssignmentOp(Opc)) 13503 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, 13504 First, Second); 13505 ExprResult Result = SemaRef.CheckPlaceholderExpr(First); 13506 if (Result.isInvalid()) 13507 return ExprError(); 13508 First = Result.get(); 13509 } 13510 13511 if (Second && Second->getObjectKind() == OK_ObjCProperty) { 13512 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); 13513 if (Result.isInvalid()) 13514 return ExprError(); 13515 Second = Result.get(); 13516 } 13517 13518 // Determine whether this should be a builtin operation. 13519 if (Op == OO_Subscript) { 13520 if (!First->getType()->isOverloadableType() && 13521 !Second->getType()->isOverloadableType()) 13522 return getSema().CreateBuiltinArraySubscriptExpr( 13523 First, Callee->getBeginLoc(), Second, OpLoc); 13524 } else if (Op == OO_Arrow) { 13525 // -> is never a builtin operation. 13526 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); 13527 } else if (Second == nullptr || isPostIncDec) { 13528 if (!First->getType()->isOverloadableType() || 13529 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) { 13530 // The argument is not of overloadable type, or this is an expression 13531 // of the form &Class::member, so try to create a built-in unary 13532 // operation. 13533 UnaryOperatorKind Opc 13534 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 13535 13536 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 13537 } 13538 } else { 13539 if (!First->getType()->isOverloadableType() && 13540 !Second->getType()->isOverloadableType()) { 13541 // Neither of the arguments is an overloadable type, so try to 13542 // create a built-in binary operation. 13543 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 13544 ExprResult Result 13545 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 13546 if (Result.isInvalid()) 13547 return ExprError(); 13548 13549 return Result; 13550 } 13551 } 13552 13553 // Compute the transformed set of functions (and function templates) to be 13554 // used during overload resolution. 13555 UnresolvedSet<16> Functions; 13556 bool RequiresADL; 13557 13558 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 13559 Functions.append(ULE->decls_begin(), ULE->decls_end()); 13560 // If the overload could not be resolved in the template definition 13561 // (because we had a dependent argument), ADL is performed as part of 13562 // template instantiation. 13563 RequiresADL = ULE->requiresADL(); 13564 } else { 13565 // If we've resolved this to a particular non-member function, just call 13566 // that function. If we resolved it to a member function, 13567 // CreateOverloaded* will find that function for us. 13568 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); 13569 if (!isa<CXXMethodDecl>(ND)) 13570 Functions.addDecl(ND); 13571 RequiresADL = false; 13572 } 13573 13574 // Add any functions found via argument-dependent lookup. 13575 Expr *Args[2] = { First, Second }; 13576 unsigned NumArgs = 1 + (Second != nullptr); 13577 13578 // Create the overloaded operator invocation for unary operators. 13579 if (NumArgs == 1 || isPostIncDec) { 13580 UnaryOperatorKind Opc 13581 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 13582 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First, 13583 RequiresADL); 13584 } 13585 13586 if (Op == OO_Subscript) { 13587 SourceLocation LBrace; 13588 SourceLocation RBrace; 13589 13590 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { 13591 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo(); 13592 LBrace = SourceLocation::getFromRawEncoding( 13593 NameLoc.CXXOperatorName.BeginOpNameLoc); 13594 RBrace = SourceLocation::getFromRawEncoding( 13595 NameLoc.CXXOperatorName.EndOpNameLoc); 13596 } else { 13597 LBrace = Callee->getBeginLoc(); 13598 RBrace = OpLoc; 13599 } 13600 13601 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, 13602 First, Second); 13603 } 13604 13605 // Create the overloaded operator invocation for binary operators. 13606 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 13607 ExprResult Result = SemaRef.CreateOverloadedBinOp( 13608 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL); 13609 if (Result.isInvalid()) 13610 return ExprError(); 13611 13612 return Result; 13613 } 13614 13615 template<typename Derived> 13616 ExprResult 13617 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 13618 SourceLocation OperatorLoc, 13619 bool isArrow, 13620 CXXScopeSpec &SS, 13621 TypeSourceInfo *ScopeType, 13622 SourceLocation CCLoc, 13623 SourceLocation TildeLoc, 13624 PseudoDestructorTypeStorage Destroyed) { 13625 QualType BaseType = Base->getType(); 13626 if (Base->isTypeDependent() || Destroyed.getIdentifier() || 13627 (!isArrow && !BaseType->getAs<RecordType>()) || 13628 (isArrow && BaseType->getAs<PointerType>() && 13629 !BaseType->castAs<PointerType>()->getPointeeType() 13630 ->template getAs<RecordType>())){ 13631 // This pseudo-destructor expression is still a pseudo-destructor. 13632 return SemaRef.BuildPseudoDestructorExpr( 13633 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, 13634 CCLoc, TildeLoc, Destroyed); 13635 } 13636 13637 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 13638 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 13639 SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 13640 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 13641 NameInfo.setNamedTypeInfo(DestroyedType); 13642 13643 // The scope type is now known to be a valid nested name specifier 13644 // component. Tack it on to the end of the nested name specifier. 13645 if (ScopeType) { 13646 if (!ScopeType->getType()->getAs<TagType>()) { 13647 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), 13648 diag::err_expected_class_or_namespace) 13649 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; 13650 return ExprError(); 13651 } 13652 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), 13653 CCLoc); 13654 } 13655 13656 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 13657 return getSema().BuildMemberReferenceExpr(Base, BaseType, 13658 OperatorLoc, isArrow, 13659 SS, TemplateKWLoc, 13660 /*FIXME: FirstQualifier*/ nullptr, 13661 NameInfo, 13662 /*TemplateArgs*/ nullptr, 13663 /*S*/nullptr); 13664 } 13665 13666 template<typename Derived> 13667 StmtResult 13668 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { 13669 SourceLocation Loc = S->getBeginLoc(); 13670 CapturedDecl *CD = S->getCapturedDecl(); 13671 unsigned NumParams = CD->getNumParams(); 13672 unsigned ContextParamPos = CD->getContextParamPosition(); 13673 SmallVector<Sema::CapturedParamNameType, 4> Params; 13674 for (unsigned I = 0; I < NumParams; ++I) { 13675 if (I != ContextParamPos) { 13676 Params.push_back( 13677 std::make_pair( 13678 CD->getParam(I)->getName(), 13679 getDerived().TransformType(CD->getParam(I)->getType()))); 13680 } else { 13681 Params.push_back(std::make_pair(StringRef(), QualType())); 13682 } 13683 } 13684 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, 13685 S->getCapturedRegionKind(), Params); 13686 StmtResult Body; 13687 { 13688 Sema::CompoundScopeRAII CompoundScope(getSema()); 13689 Body = getDerived().TransformStmt(S->getCapturedStmt()); 13690 } 13691 13692 if (Body.isInvalid()) { 13693 getSema().ActOnCapturedRegionError(); 13694 return StmtError(); 13695 } 13696 13697 return getSema().ActOnCapturedRegionEnd(Body.get()); 13698 } 13699 13700 } // end namespace clang 13701 13702 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H 13703