1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===//
9 // This file implements a semantic tree transformation that takes a given
10 // AST and rebuilds it, possibly transforming some nodes in the process.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15 #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
17 #include "CoroutineStmtBuilder.h"
18 #include "TypeLocBuilder.h"
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/DeclObjC.h"
21 #include "clang/AST/DeclTemplate.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/ExprCXX.h"
24 #include "clang/AST/ExprObjC.h"
25 #include "clang/AST/ExprOpenMP.h"
26 #include "clang/AST/Stmt.h"
27 #include "clang/AST/StmtCXX.h"
28 #include "clang/AST/StmtObjC.h"
29 #include "clang/AST/StmtOpenMP.h"
30 #include "clang/Sema/Designator.h"
31 #include "clang/Sema/Lookup.h"
32 #include "clang/Sema/Ownership.h"
33 #include "clang/Sema/ParsedTemplate.h"
34 #include "clang/Sema/ScopeInfo.h"
35 #include "clang/Sema/SemaDiagnostic.h"
36 #include "clang/Sema/SemaInternal.h"
37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/Support/ErrorHandling.h"
44 /// \brief A semantic tree transformation that allows one to transform one
45 /// abstract syntax tree into another.
47 /// A new tree transformation is defined by creating a new subclass \c X of
48 /// \c TreeTransform<X> and then overriding certain operations to provide
49 /// behavior specific to that transformation. For example, template
50 /// instantiation is implemented as a tree transformation where the
51 /// transformation of TemplateTypeParmType nodes involves substituting the
52 /// template arguments for their corresponding template parameters; a similar
53 /// transformation is performed for non-type template parameters and
54 /// template template parameters.
56 /// This tree-transformation template uses static polymorphism to allow
57 /// subclasses to customize any of its operations. Thus, a subclass can
58 /// override any of the transformation or rebuild operators by providing an
59 /// operation with the same signature as the default implementation. The
60 /// overridding function should not be virtual.
62 /// Semantic tree transformations are split into two stages, either of which
63 /// can be replaced by a subclass. The "transform" step transforms an AST node
64 /// or the parts of an AST node using the various transformation functions,
65 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
66 /// node of the appropriate kind from the pieces. The default transformation
67 /// routines recursively transform the operands to composite AST nodes (e.g.,
68 /// the pointee type of a PointerType node) and, if any of those operand nodes
69 /// were changed by the transformation, invokes the rebuild operation to create
72 /// Subclasses can customize the transformation at various levels. The
73 /// most coarse-grained transformations involve replacing TransformType(),
74 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
75 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
76 /// new implementations.
78 /// For more fine-grained transformations, subclasses can replace any of the
79 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
80 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
81 /// replacing TransformTemplateTypeParmType() allows template instantiation
82 /// to substitute template arguments for their corresponding template
83 /// parameters. Additionally, subclasses can override the \c RebuildXXX
84 /// functions to control how AST nodes are rebuilt when their operands change.
85 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
86 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
87 /// be able to use more efficient rebuild steps.
89 /// There are a handful of other functions that can be overridden, allowing one
90 /// to avoid traversing nodes that don't need any transformation
91 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
92 /// operands have not changed (\c AlwaysRebuild()), and customize the
93 /// default locations and entity names used for type-checking
94 /// (\c getBaseLocation(), \c getBaseEntity()).
95 template<typename Derived>
97 /// \brief Private RAII object that helps us forget and then re-remember
98 /// the template argument corresponding to a partially-substituted parameter
100 class ForgetPartiallySubstitutedPackRAII {
102 TemplateArgument Old;
105 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
106 Old = Self.ForgetPartiallySubstitutedPack();
109 ~ForgetPartiallySubstitutedPackRAII() {
110 Self.RememberPartiallySubstitutedPack(Old);
117 /// \brief The set of local declarations that have been transformed, for
118 /// cases where we are forced to build new declarations within the transformer
119 /// rather than in the subclass (e.g., lambda closure types).
120 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
123 /// \brief Initializes a new tree transformer.
124 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
126 /// \brief Retrieves a reference to the derived class.
127 Derived &getDerived() { return static_cast<Derived&>(*this); }
129 /// \brief Retrieves a reference to the derived class.
130 const Derived &getDerived() const {
131 return static_cast<const Derived&>(*this);
134 static inline ExprResult Owned(Expr *E) { return E; }
135 static inline StmtResult Owned(Stmt *S) { return S; }
137 /// \brief Retrieves a reference to the semantic analysis object used for
138 /// this tree transform.
139 Sema &getSema() const { return SemaRef; }
141 /// \brief Whether the transformation should always rebuild AST nodes, even
142 /// if none of the children have changed.
144 /// Subclasses may override this function to specify when the transformation
145 /// should rebuild all AST nodes.
147 /// We must always rebuild all AST nodes when performing variadic template
148 /// pack expansion, in order to avoid violating the AST invariant that each
149 /// statement node appears at most once in its containing declaration.
150 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
152 /// \brief Returns the location of the entity being transformed, if that
153 /// information was not available elsewhere in the AST.
155 /// By default, returns no source-location information. Subclasses can
156 /// provide an alternative implementation that provides better location
158 SourceLocation getBaseLocation() { return SourceLocation(); }
160 /// \brief Returns the name of the entity being transformed, if that
161 /// information was not available elsewhere in the AST.
163 /// By default, returns an empty name. Subclasses can provide an alternative
164 /// implementation with a more precise name.
165 DeclarationName getBaseEntity() { return DeclarationName(); }
167 /// \brief Sets the "base" location and entity when that
168 /// information is known based on another transformation.
170 /// By default, the source location and entity are ignored. Subclasses can
171 /// override this function to provide a customized implementation.
172 void setBase(SourceLocation Loc, DeclarationName Entity) { }
174 /// \brief RAII object that temporarily sets the base location and entity
175 /// used for reporting diagnostics in types.
176 class TemporaryBase {
178 SourceLocation OldLocation;
179 DeclarationName OldEntity;
182 TemporaryBase(TreeTransform &Self, SourceLocation Location,
183 DeclarationName Entity) : Self(Self) {
184 OldLocation = Self.getDerived().getBaseLocation();
185 OldEntity = Self.getDerived().getBaseEntity();
187 if (Location.isValid())
188 Self.getDerived().setBase(Location, Entity);
192 Self.getDerived().setBase(OldLocation, OldEntity);
196 /// \brief Determine whether the given type \p T has already been
199 /// Subclasses can provide an alternative implementation of this routine
200 /// to short-circuit evaluation when it is known that a given type will
201 /// not change. For example, template instantiation need not traverse
202 /// non-dependent types.
203 bool AlreadyTransformed(QualType T) {
207 /// \brief Determine whether the given call argument should be dropped, e.g.,
208 /// because it is a default argument.
210 /// Subclasses can provide an alternative implementation of this routine to
211 /// determine which kinds of call arguments get dropped. By default,
212 /// CXXDefaultArgument nodes are dropped (prior to transformation).
213 bool DropCallArgument(Expr *E) {
214 return E->isDefaultArgument();
217 /// \brief Determine whether we should expand a pack expansion with the
218 /// given set of parameter packs into separate arguments by repeatedly
219 /// transforming the pattern.
221 /// By default, the transformer never tries to expand pack expansions.
222 /// Subclasses can override this routine to provide different behavior.
224 /// \param EllipsisLoc The location of the ellipsis that identifies the
227 /// \param PatternRange The source range that covers the entire pattern of
228 /// the pack expansion.
230 /// \param Unexpanded The set of unexpanded parameter packs within the
233 /// \param ShouldExpand Will be set to \c true if the transformer should
234 /// expand the corresponding pack expansions into separate arguments. When
235 /// set, \c NumExpansions must also be set.
237 /// \param RetainExpansion Whether the caller should add an unexpanded
238 /// pack expansion after all of the expanded arguments. This is used
239 /// when extending explicitly-specified template argument packs per
240 /// C++0x [temp.arg.explicit]p9.
242 /// \param NumExpansions The number of separate arguments that will be in
243 /// the expanded form of the corresponding pack expansion. This is both an
244 /// input and an output parameter, which can be set by the caller if the
245 /// number of expansions is known a priori (e.g., due to a prior substitution)
246 /// and will be set by the callee when the number of expansions is known.
247 /// The callee must set this value when \c ShouldExpand is \c true; it may
248 /// set this value in other cases.
250 /// \returns true if an error occurred (e.g., because the parameter packs
251 /// are to be instantiated with arguments of different lengths), false
252 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
254 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
255 SourceRange PatternRange,
256 ArrayRef<UnexpandedParameterPack> Unexpanded,
258 bool &RetainExpansion,
259 Optional<unsigned> &NumExpansions) {
260 ShouldExpand = false;
264 /// \brief "Forget" about the partially-substituted pack template argument,
265 /// when performing an instantiation that must preserve the parameter pack
268 /// This routine is meant to be overridden by the template instantiator.
269 TemplateArgument ForgetPartiallySubstitutedPack() {
270 return TemplateArgument();
273 /// \brief "Remember" the partially-substituted pack template argument
274 /// after performing an instantiation that must preserve the parameter pack
277 /// This routine is meant to be overridden by the template instantiator.
278 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
280 /// \brief Note to the derived class when a function parameter pack is
282 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
284 /// \brief Transforms the given type into another type.
286 /// By default, this routine transforms a type by creating a
287 /// TypeSourceInfo for it and delegating to the appropriate
288 /// function. This is expensive, but we don't mind, because
289 /// this method is deprecated anyway; all users should be
290 /// switched to storing TypeSourceInfos.
292 /// \returns the transformed type.
293 QualType TransformType(QualType T);
295 /// \brief Transforms the given type-with-location into a new
296 /// type-with-location.
298 /// By default, this routine transforms a type by delegating to the
299 /// appropriate TransformXXXType to build a new type. Subclasses
300 /// may override this function (to take over all type
301 /// transformations) or some set of the TransformXXXType functions
302 /// to alter the transformation.
303 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
305 /// \brief Transform the given type-with-location into a new
306 /// type, collecting location information in the given builder
309 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
311 /// \brief Transform a type that is permitted to produce a
312 /// DeducedTemplateSpecializationType.
314 /// This is used in the (relatively rare) contexts where it is acceptable
315 /// for transformation to produce a class template type with deduced
316 /// template arguments.
318 QualType TransformTypeWithDeducedTST(QualType T);
319 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
322 /// \brief Transform the given statement.
324 /// By default, this routine transforms a statement by delegating to the
325 /// appropriate TransformXXXStmt function to transform a specific kind of
326 /// statement or the TransformExpr() function to transform an expression.
327 /// Subclasses may override this function to transform statements using some
330 /// \returns the transformed statement.
331 StmtResult TransformStmt(Stmt *S);
333 /// \brief Transform the given statement.
335 /// By default, this routine transforms a statement by delegating to the
336 /// appropriate TransformOMPXXXClause function to transform a specific kind
337 /// of clause. Subclasses may override this function to transform statements
338 /// using some other mechanism.
340 /// \returns the transformed OpenMP clause.
341 OMPClause *TransformOMPClause(OMPClause *S);
343 /// \brief Transform the given attribute.
345 /// By default, this routine transforms a statement by delegating to the
346 /// appropriate TransformXXXAttr function to transform a specific kind
347 /// of attribute. Subclasses may override this function to transform
348 /// attributed statements using some other mechanism.
350 /// \returns the transformed attribute
351 const Attr *TransformAttr(const Attr *S);
353 /// \brief Transform the specified attribute.
355 /// Subclasses should override the transformation of attributes with a pragma
356 /// spelling to transform expressions stored within the attribute.
358 /// \returns the transformed attribute.
360 #define PRAGMA_SPELLING_ATTR(X) \
361 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
362 #include "clang/Basic/AttrList.inc"
364 /// \brief Transform the given expression.
366 /// By default, this routine transforms an expression by delegating to the
367 /// appropriate TransformXXXExpr function to build a new expression.
368 /// Subclasses may override this function to transform expressions using some
371 /// \returns the transformed expression.
372 ExprResult TransformExpr(Expr *E);
374 /// \brief Transform the given initializer.
376 /// By default, this routine transforms an initializer by stripping off the
377 /// semantic nodes added by initialization, then passing the result to
378 /// TransformExpr or TransformExprs.
380 /// \returns the transformed initializer.
381 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
383 /// \brief Transform the given list of expressions.
385 /// This routine transforms a list of expressions by invoking
386 /// \c TransformExpr() for each subexpression. However, it also provides
387 /// support for variadic templates by expanding any pack expansions (if the
388 /// derived class permits such expansion) along the way. When pack expansions
389 /// are present, the number of outputs may not equal the number of inputs.
391 /// \param Inputs The set of expressions to be transformed.
393 /// \param NumInputs The number of expressions in \c Inputs.
395 /// \param IsCall If \c true, then this transform is being performed on
396 /// function-call arguments, and any arguments that should be dropped, will
399 /// \param Outputs The transformed input expressions will be added to this
402 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
403 /// due to transformation.
405 /// \returns true if an error occurred, false otherwise.
406 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
407 SmallVectorImpl<Expr *> &Outputs,
408 bool *ArgChanged = nullptr);
410 /// \brief Transform the given declaration, which is referenced from a type
413 /// By default, acts as the identity function on declarations, unless the
414 /// transformer has had to transform the declaration itself. Subclasses
415 /// may override this function to provide alternate behavior.
416 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
417 llvm::DenseMap<Decl *, Decl *>::iterator Known
418 = TransformedLocalDecls.find(D);
419 if (Known != TransformedLocalDecls.end())
420 return Known->second;
425 /// \brief Transform the specified condition.
427 /// By default, this transforms the variable and expression and rebuilds
429 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
431 Sema::ConditionKind Kind);
433 /// \brief Transform the attributes associated with the given declaration and
434 /// place them on the new declaration.
436 /// By default, this operation does nothing. Subclasses may override this
437 /// behavior to transform attributes.
438 void transformAttrs(Decl *Old, Decl *New) { }
440 /// \brief Note that a local declaration has been transformed by this
443 /// Local declarations are typically transformed via a call to
444 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
445 /// the transformer itself has to transform the declarations. This routine
446 /// can be overridden by a subclass that keeps track of such mappings.
447 void transformedLocalDecl(Decl *Old, Decl *New) {
448 TransformedLocalDecls[Old] = New;
451 /// \brief Transform the definition of the given declaration.
453 /// By default, invokes TransformDecl() to transform the declaration.
454 /// Subclasses may override this function to provide alternate behavior.
455 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
456 return getDerived().TransformDecl(Loc, D);
459 /// \brief Transform the given declaration, which was the first part of a
460 /// nested-name-specifier in a member access expression.
462 /// This specific declaration transformation only applies to the first
463 /// identifier in a nested-name-specifier of a member access expression, e.g.,
464 /// the \c T in \c x->T::member
466 /// By default, invokes TransformDecl() to transform the declaration.
467 /// Subclasses may override this function to provide alternate behavior.
468 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
469 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
472 /// Transform the set of declarations in an OverloadExpr.
473 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
476 /// \brief Transform the given nested-name-specifier with source-location
479 /// By default, transforms all of the types and declarations within the
480 /// nested-name-specifier. Subclasses may override this function to provide
481 /// alternate behavior.
482 NestedNameSpecifierLoc
483 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
484 QualType ObjectType = QualType(),
485 NamedDecl *FirstQualifierInScope = nullptr);
487 /// \brief Transform the given declaration name.
489 /// By default, transforms the types of conversion function, constructor,
490 /// and destructor names and then (if needed) rebuilds the declaration name.
491 /// Identifiers and selectors are returned unmodified. Sublcasses may
492 /// override this function to provide alternate behavior.
494 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
496 /// \brief Transform the given template name.
498 /// \param SS The nested-name-specifier that qualifies the template
499 /// name. This nested-name-specifier must already have been transformed.
501 /// \param Name The template name to transform.
503 /// \param NameLoc The source location of the template name.
505 /// \param ObjectType If we're translating a template name within a member
506 /// access expression, this is the type of the object whose member template
507 /// is being referenced.
509 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
510 /// also refers to a name within the current (lexical) scope, this is the
511 /// declaration it refers to.
513 /// By default, transforms the template name by transforming the declarations
514 /// and nested-name-specifiers that occur within the template name.
515 /// Subclasses may override this function to provide alternate behavior.
517 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
518 SourceLocation NameLoc,
519 QualType ObjectType = QualType(),
520 NamedDecl *FirstQualifierInScope = nullptr,
521 bool AllowInjectedClassName = false);
523 /// \brief Transform the given template argument.
525 /// By default, this operation transforms the type, expression, or
526 /// declaration stored within the template argument and constructs a
527 /// new template argument from the transformed result. Subclasses may
528 /// override this function to provide alternate behavior.
530 /// Returns true if there was an error.
531 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
532 TemplateArgumentLoc &Output,
533 bool Uneval = false);
535 /// \brief Transform the given set of template arguments.
537 /// By default, this operation transforms all of the template arguments
538 /// in the input set using \c TransformTemplateArgument(), and appends
539 /// the transformed arguments to the output list.
541 /// Note that this overload of \c TransformTemplateArguments() is merely
542 /// a convenience function. Subclasses that wish to override this behavior
543 /// should override the iterator-based member template version.
545 /// \param Inputs The set of template arguments to be transformed.
547 /// \param NumInputs The number of template arguments in \p Inputs.
549 /// \param Outputs The set of transformed template arguments output by this
552 /// Returns true if an error occurred.
553 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
555 TemplateArgumentListInfo &Outputs,
556 bool Uneval = false) {
557 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
561 /// \brief Transform the given set of template arguments.
563 /// By default, this operation transforms all of the template arguments
564 /// in the input set using \c TransformTemplateArgument(), and appends
565 /// the transformed arguments to the output list.
567 /// \param First An iterator to the first template argument.
569 /// \param Last An iterator one step past the last template argument.
571 /// \param Outputs The set of transformed template arguments output by this
574 /// Returns true if an error occurred.
575 template<typename InputIterator>
576 bool TransformTemplateArguments(InputIterator First,
578 TemplateArgumentListInfo &Outputs,
579 bool Uneval = false);
581 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
582 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
583 TemplateArgumentLoc &ArgLoc);
585 /// \brief Fakes up a TypeSourceInfo for a type.
586 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
587 return SemaRef.Context.getTrivialTypeSourceInfo(T,
588 getDerived().getBaseLocation());
591 #define ABSTRACT_TYPELOC(CLASS, PARENT)
592 #define TYPELOC(CLASS, PARENT) \
593 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
594 #include "clang/AST/TypeLocNodes.def"
596 template<typename Fn>
597 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
598 FunctionProtoTypeLoc TL,
599 CXXRecordDecl *ThisContext,
600 unsigned ThisTypeQuals,
601 Fn TransformExceptionSpec);
603 bool TransformExceptionSpec(SourceLocation Loc,
604 FunctionProtoType::ExceptionSpecInfo &ESI,
605 SmallVectorImpl<QualType> &Exceptions,
608 StmtResult TransformSEHHandler(Stmt *Handler);
611 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
612 TemplateSpecializationTypeLoc TL,
613 TemplateName Template);
616 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
617 DependentTemplateSpecializationTypeLoc TL,
618 TemplateName Template,
621 QualType TransformDependentTemplateSpecializationType(
622 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
623 NestedNameSpecifierLoc QualifierLoc);
625 /// \brief Transforms the parameters of a function type into the
628 /// The result vectors should be kept in sync; null entries in the
629 /// variables vector are acceptable.
631 /// Return true on error.
632 bool TransformFunctionTypeParams(
633 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
634 const QualType *ParamTypes,
635 const FunctionProtoType::ExtParameterInfo *ParamInfos,
636 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
637 Sema::ExtParameterInfoBuilder &PInfos);
639 /// \brief Transforms a single function-type parameter. Return null
642 /// \param indexAdjustment - A number to add to the parameter's
643 /// scope index; can be negative
644 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
646 Optional<unsigned> NumExpansions,
647 bool ExpectParameterPack);
649 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
651 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
652 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
654 TemplateParameterList *TransformTemplateParameterList(
655 TemplateParameterList *TPL) {
659 ExprResult TransformAddressOfOperand(Expr *E);
661 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
662 bool IsAddressOfOperand,
663 TypeSourceInfo **RecoveryTSI);
665 ExprResult TransformParenDependentScopeDeclRefExpr(
666 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
667 TypeSourceInfo **RecoveryTSI);
669 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
671 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
672 // amount of stack usage with clang.
673 #define STMT(Node, Parent) \
674 LLVM_ATTRIBUTE_NOINLINE \
675 StmtResult Transform##Node(Node *S);
676 #define EXPR(Node, Parent) \
677 LLVM_ATTRIBUTE_NOINLINE \
678 ExprResult Transform##Node(Node *E);
679 #define ABSTRACT_STMT(Stmt)
680 #include "clang/AST/StmtNodes.inc"
682 #define OPENMP_CLAUSE(Name, Class) \
683 LLVM_ATTRIBUTE_NOINLINE \
684 OMPClause *Transform ## Class(Class *S);
685 #include "clang/Basic/OpenMPKinds.def"
687 /// \brief Build a new qualified type given its unqualified type and type
690 /// By default, this routine adds type qualifiers only to types that can
691 /// have qualifiers, and silently suppresses those qualifiers that are not
692 /// permitted. Subclasses may override this routine to provide different
694 QualType RebuildQualifiedType(QualType T, SourceLocation Loc,
697 /// \brief Build a new pointer type given its pointee type.
699 /// By default, performs semantic analysis when building the pointer type.
700 /// Subclasses may override this routine to provide different behavior.
701 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
703 /// \brief Build a new block pointer type given its pointee type.
705 /// By default, performs semantic analysis when building the block pointer
706 /// type. Subclasses may override this routine to provide different behavior.
707 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
709 /// \brief Build a new reference type given the type it references.
711 /// By default, performs semantic analysis when building the
712 /// reference type. Subclasses may override this routine to provide
713 /// different behavior.
715 /// \param LValue whether the type was written with an lvalue sigil
716 /// or an rvalue sigil.
717 QualType RebuildReferenceType(QualType ReferentType,
719 SourceLocation Sigil);
721 /// \brief Build a new member pointer type given the pointee type and the
722 /// class type it refers into.
724 /// By default, performs semantic analysis when building the member pointer
725 /// type. Subclasses may override this routine to provide different behavior.
726 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
727 SourceLocation Sigil);
729 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
730 SourceLocation ProtocolLAngleLoc,
731 ArrayRef<ObjCProtocolDecl *> Protocols,
732 ArrayRef<SourceLocation> ProtocolLocs,
733 SourceLocation ProtocolRAngleLoc);
735 /// \brief Build an Objective-C object type.
737 /// By default, performs semantic analysis when building the object type.
738 /// Subclasses may override this routine to provide different behavior.
739 QualType RebuildObjCObjectType(QualType BaseType,
741 SourceLocation TypeArgsLAngleLoc,
742 ArrayRef<TypeSourceInfo *> TypeArgs,
743 SourceLocation TypeArgsRAngleLoc,
744 SourceLocation ProtocolLAngleLoc,
745 ArrayRef<ObjCProtocolDecl *> Protocols,
746 ArrayRef<SourceLocation> ProtocolLocs,
747 SourceLocation ProtocolRAngleLoc);
749 /// \brief Build a new Objective-C object pointer type given the pointee type.
751 /// By default, directly builds the pointer type, with no additional semantic
753 QualType RebuildObjCObjectPointerType(QualType PointeeType,
754 SourceLocation Star);
756 /// \brief Build a new array type given the element type, size
757 /// modifier, size of the array (if known), size expression, and index type
760 /// By default, performs semantic analysis when building the array type.
761 /// Subclasses may override this routine to provide different behavior.
762 /// Also by default, all of the other Rebuild*Array
763 QualType RebuildArrayType(QualType ElementType,
764 ArrayType::ArraySizeModifier SizeMod,
765 const llvm::APInt *Size,
767 unsigned IndexTypeQuals,
768 SourceRange BracketsRange);
770 /// \brief Build a new constant array type given the element type, size
771 /// modifier, (known) size of the array, and index type qualifiers.
773 /// By default, performs semantic analysis when building the array type.
774 /// Subclasses may override this routine to provide different behavior.
775 QualType RebuildConstantArrayType(QualType ElementType,
776 ArrayType::ArraySizeModifier SizeMod,
777 const llvm::APInt &Size,
778 unsigned IndexTypeQuals,
779 SourceRange BracketsRange);
781 /// \brief Build a new incomplete array type given the element type, size
782 /// modifier, and index type qualifiers.
784 /// By default, performs semantic analysis when building the array type.
785 /// Subclasses may override this routine to provide different behavior.
786 QualType RebuildIncompleteArrayType(QualType ElementType,
787 ArrayType::ArraySizeModifier SizeMod,
788 unsigned IndexTypeQuals,
789 SourceRange BracketsRange);
791 /// \brief Build a new variable-length array type given the element type,
792 /// size modifier, size expression, and index type qualifiers.
794 /// By default, performs semantic analysis when building the array type.
795 /// Subclasses may override this routine to provide different behavior.
796 QualType RebuildVariableArrayType(QualType ElementType,
797 ArrayType::ArraySizeModifier SizeMod,
799 unsigned IndexTypeQuals,
800 SourceRange BracketsRange);
802 /// \brief Build a new dependent-sized array type given the element type,
803 /// size modifier, size expression, and index type qualifiers.
805 /// By default, performs semantic analysis when building the array type.
806 /// Subclasses may override this routine to provide different behavior.
807 QualType RebuildDependentSizedArrayType(QualType ElementType,
808 ArrayType::ArraySizeModifier SizeMod,
810 unsigned IndexTypeQuals,
811 SourceRange BracketsRange);
813 /// \brief Build a new vector type given the element type and
814 /// number of elements.
816 /// By default, performs semantic analysis when building the vector type.
817 /// Subclasses may override this routine to provide different behavior.
818 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
819 VectorType::VectorKind VecKind);
821 /// \brief Build a new extended vector type given the element type and
822 /// number of elements.
824 /// By default, performs semantic analysis when building the vector type.
825 /// Subclasses may override this routine to provide different behavior.
826 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
827 SourceLocation AttributeLoc);
829 /// \brief Build a new potentially dependently-sized extended vector type
830 /// given the element type and number of elements.
832 /// By default, performs semantic analysis when building the vector type.
833 /// Subclasses may override this routine to provide different behavior.
834 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
836 SourceLocation AttributeLoc);
838 /// \brief Build a new DependentAddressSpaceType or return the pointee
839 /// type variable with the correct address space (retrieved from
840 /// AddrSpaceExpr) applied to it. The former will be returned in cases
841 /// where the address space remains dependent.
843 /// By default, performs semantic analysis when building the type with address
844 /// space applied. Subclasses may override this routine to provide different
846 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
848 SourceLocation AttributeLoc);
850 /// \brief Build a new function type.
852 /// By default, performs semantic analysis when building the function type.
853 /// Subclasses may override this routine to provide different behavior.
854 QualType RebuildFunctionProtoType(QualType T,
855 MutableArrayRef<QualType> ParamTypes,
856 const FunctionProtoType::ExtProtoInfo &EPI);
858 /// \brief Build a new unprototyped function type.
859 QualType RebuildFunctionNoProtoType(QualType ResultType);
861 /// \brief Rebuild an unresolved typename type, given the decl that
862 /// the UnresolvedUsingTypenameDecl was transformed to.
863 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
865 /// \brief Build a new typedef type.
866 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
867 return SemaRef.Context.getTypeDeclType(Typedef);
870 /// \brief Build a new class/struct/union type.
871 QualType RebuildRecordType(RecordDecl *Record) {
872 return SemaRef.Context.getTypeDeclType(Record);
875 /// \brief Build a new Enum type.
876 QualType RebuildEnumType(EnumDecl *Enum) {
877 return SemaRef.Context.getTypeDeclType(Enum);
880 /// \brief Build a new typeof(expr) type.
882 /// By default, performs semantic analysis when building the typeof type.
883 /// Subclasses may override this routine to provide different behavior.
884 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
886 /// \brief Build a new typeof(type) type.
888 /// By default, builds a new TypeOfType with the given underlying type.
889 QualType RebuildTypeOfType(QualType Underlying);
891 /// \brief Build a new unary transform type.
892 QualType RebuildUnaryTransformType(QualType BaseType,
893 UnaryTransformType::UTTKind UKind,
896 /// \brief Build a new C++11 decltype type.
898 /// By default, performs semantic analysis when building the decltype type.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
902 /// \brief Build a new C++11 auto type.
904 /// By default, builds a new AutoType with the given deduced type.
905 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
906 // Note, IsDependent is always false here: we implicitly convert an 'auto'
907 // which has been deduced to a dependent type into an undeduced 'auto', so
908 // that we'll retry deduction after the transformation.
909 return SemaRef.Context.getAutoType(Deduced, Keyword,
910 /*IsDependent*/ false);
913 /// By default, builds a new DeducedTemplateSpecializationType with the given
915 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
917 return SemaRef.Context.getDeducedTemplateSpecializationType(
918 Template, Deduced, /*IsDependent*/ false);
921 /// \brief Build a new template specialization type.
923 /// By default, performs semantic analysis when building the template
924 /// specialization type. Subclasses may override this routine to provide
925 /// different behavior.
926 QualType RebuildTemplateSpecializationType(TemplateName Template,
927 SourceLocation TemplateLoc,
928 TemplateArgumentListInfo &Args);
930 /// \brief Build a new parenthesized type.
932 /// By default, builds a new ParenType type from the inner type.
933 /// Subclasses may override this routine to provide different behavior.
934 QualType RebuildParenType(QualType InnerType) {
935 return SemaRef.BuildParenType(InnerType);
938 /// \brief Build a new qualified name type.
940 /// By default, builds a new ElaboratedType type from the keyword,
941 /// the nested-name-specifier and the named type.
942 /// Subclasses may override this routine to provide different behavior.
943 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
944 ElaboratedTypeKeyword Keyword,
945 NestedNameSpecifierLoc QualifierLoc,
947 return SemaRef.Context.getElaboratedType(Keyword,
948 QualifierLoc.getNestedNameSpecifier(),
952 /// \brief Build a new typename type that refers to a template-id.
954 /// By default, builds a new DependentNameType type from the
955 /// nested-name-specifier and the given type. Subclasses may override
956 /// this routine to provide different behavior.
957 QualType RebuildDependentTemplateSpecializationType(
958 ElaboratedTypeKeyword Keyword,
959 NestedNameSpecifierLoc QualifierLoc,
960 const IdentifierInfo *Name,
961 SourceLocation NameLoc,
962 TemplateArgumentListInfo &Args,
963 bool AllowInjectedClassName) {
964 // Rebuild the template name.
965 // TODO: avoid TemplateName abstraction
967 SS.Adopt(QualifierLoc);
968 TemplateName InstName
969 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
970 nullptr, AllowInjectedClassName);
972 if (InstName.isNull())
975 // If it's still dependent, make a dependent specialization.
976 if (InstName.getAsDependentTemplateName())
977 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
978 QualifierLoc.getNestedNameSpecifier(),
982 // Otherwise, make an elaborated type wrapping a non-dependent
985 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
986 if (T.isNull()) return QualType();
988 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
991 return SemaRef.Context.getElaboratedType(Keyword,
992 QualifierLoc.getNestedNameSpecifier(),
996 /// \brief Build a new typename type that refers to an identifier.
998 /// By default, performs semantic analysis when building the typename type
999 /// (or elaborated type). Subclasses may override this routine to provide
1000 /// different behavior.
1001 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
1002 SourceLocation KeywordLoc,
1003 NestedNameSpecifierLoc QualifierLoc,
1004 const IdentifierInfo *Id,
1005 SourceLocation IdLoc,
1006 bool DeducedTSTContext) {
1008 SS.Adopt(QualifierLoc);
1010 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1011 // If the name is still dependent, just build a new dependent name type.
1012 if (!SemaRef.computeDeclContext(SS))
1013 return SemaRef.Context.getDependentNameType(Keyword,
1014 QualifierLoc.getNestedNameSpecifier(),
1018 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1019 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1021 // If a dependent name resolves to a deduced template specialization type,
1022 // check that we're in one of the syntactic contexts permitting it.
1023 if (!DeducedTSTContext) {
1024 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1025 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1026 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1027 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1028 Deduced->getTemplateName())
1029 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1030 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1031 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1038 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1040 // We had a dependent elaborated-type-specifier that has been transformed
1041 // into a non-dependent elaborated-type-specifier. Find the tag we're
1043 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1044 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1048 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1051 TagDecl *Tag = nullptr;
1052 SemaRef.LookupQualifiedName(Result, DC);
1053 switch (Result.getResultKind()) {
1054 case LookupResult::NotFound:
1055 case LookupResult::NotFoundInCurrentInstantiation:
1058 case LookupResult::Found:
1059 Tag = Result.getAsSingle<TagDecl>();
1062 case LookupResult::FoundOverloaded:
1063 case LookupResult::FoundUnresolvedValue:
1064 llvm_unreachable("Tag lookup cannot find non-tags");
1066 case LookupResult::Ambiguous:
1067 // Let the LookupResult structure handle ambiguities.
1072 // Check where the name exists but isn't a tag type and use that to emit
1073 // better diagnostics.
1074 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1075 SemaRef.LookupQualifiedName(Result, DC);
1076 switch (Result.getResultKind()) {
1077 case LookupResult::Found:
1078 case LookupResult::FoundOverloaded:
1079 case LookupResult::FoundUnresolvedValue: {
1080 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1081 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1082 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1084 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1088 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1089 << Kind << Id << DC << QualifierLoc.getSourceRange();
1095 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1097 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1098 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1102 // Build the elaborated-type-specifier type.
1103 QualType T = SemaRef.Context.getTypeDeclType(Tag);
1104 return SemaRef.Context.getElaboratedType(Keyword,
1105 QualifierLoc.getNestedNameSpecifier(),
1109 /// \brief Build a new pack expansion type.
1111 /// By default, builds a new PackExpansionType type from the given pattern.
1112 /// Subclasses may override this routine to provide different behavior.
1113 QualType RebuildPackExpansionType(QualType Pattern,
1114 SourceRange PatternRange,
1115 SourceLocation EllipsisLoc,
1116 Optional<unsigned> NumExpansions) {
1117 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1121 /// \brief Build a new atomic type given its value type.
1123 /// By default, performs semantic analysis when building the atomic type.
1124 /// Subclasses may override this routine to provide different behavior.
1125 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1127 /// \brief Build a new pipe type given its value type.
1128 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1131 /// \brief Build a new template name given a nested name specifier, a flag
1132 /// indicating whether the "template" keyword was provided, and the template
1133 /// that the template name refers to.
1135 /// By default, builds the new template name directly. Subclasses may override
1136 /// this routine to provide different behavior.
1137 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1139 TemplateDecl *Template);
1141 /// \brief Build a new template name given a nested name specifier and the
1142 /// name that is referred to as a template.
1144 /// By default, performs semantic analysis to determine whether the name can
1145 /// be resolved to a specific template, then builds the appropriate kind of
1146 /// template name. Subclasses may override this routine to provide different
1148 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1149 const IdentifierInfo &Name,
1150 SourceLocation NameLoc,
1151 QualType ObjectType,
1152 NamedDecl *FirstQualifierInScope,
1153 bool AllowInjectedClassName);
1155 /// \brief Build a new template name given a nested name specifier and the
1156 /// overloaded operator name that is referred to as a template.
1158 /// By default, performs semantic analysis to determine whether the name can
1159 /// be resolved to a specific template, then builds the appropriate kind of
1160 /// template name. Subclasses may override this routine to provide different
1162 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1163 OverloadedOperatorKind Operator,
1164 SourceLocation NameLoc,
1165 QualType ObjectType,
1166 bool AllowInjectedClassName);
1168 /// \brief Build a new template name given a template template parameter pack
1171 /// By default, performs semantic analysis to determine whether the name can
1172 /// be resolved to a specific template, then builds the appropriate kind of
1173 /// template name. Subclasses may override this routine to provide different
1175 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1176 const TemplateArgument &ArgPack) {
1177 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1180 /// \brief Build a new compound statement.
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
1184 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1185 MultiStmtArg Statements,
1186 SourceLocation RBraceLoc,
1188 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1192 /// \brief Build a new case statement.
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
1196 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1198 SourceLocation EllipsisLoc,
1200 SourceLocation ColonLoc) {
1201 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1205 /// \brief Attach the body to a new case statement.
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
1209 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1210 getSema().ActOnCaseStmtBody(S, Body);
1214 /// \brief Build a new default statement.
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
1218 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1219 SourceLocation ColonLoc,
1221 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1222 /*CurScope=*/nullptr);
1225 /// \brief Build a new label statement.
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
1229 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1230 SourceLocation ColonLoc, Stmt *SubStmt) {
1231 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1234 /// \brief Build a new label statement.
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
1238 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1239 ArrayRef<const Attr*> Attrs,
1241 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1244 /// \brief Build a new "if" statement.
1246 /// By default, performs semantic analysis to build the new statement.
1247 /// Subclasses may override this routine to provide different behavior.
1248 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1249 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
1250 SourceLocation ElseLoc, Stmt *Else) {
1251 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
1255 /// \brief Start building a new switch statement.
1257 /// By default, performs semantic analysis to build the new statement.
1258 /// Subclasses may override this routine to provide different behavior.
1259 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
1260 Sema::ConditionResult Cond) {
1261 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
1264 /// \brief Attach the body to the switch statement.
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
1268 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1269 Stmt *Switch, Stmt *Body) {
1270 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1273 /// \brief Build a new while statement.
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
1277 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1278 Sema::ConditionResult Cond, Stmt *Body) {
1279 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
1282 /// \brief Build a new do-while statement.
1284 /// By default, performs semantic analysis to build the new statement.
1285 /// Subclasses may override this routine to provide different behavior.
1286 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1287 SourceLocation WhileLoc, SourceLocation LParenLoc,
1288 Expr *Cond, SourceLocation RParenLoc) {
1289 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1293 /// \brief Build a new for statement.
1295 /// By default, performs semantic analysis to build the new statement.
1296 /// Subclasses may override this routine to provide different behavior.
1297 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1298 Stmt *Init, Sema::ConditionResult Cond,
1299 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1301 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1302 Inc, RParenLoc, Body);
1305 /// \brief Build a new goto statement.
1307 /// By default, performs semantic analysis to build the new statement.
1308 /// Subclasses may override this routine to provide different behavior.
1309 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1311 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1314 /// \brief Build a new indirect goto statement.
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
1318 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1319 SourceLocation StarLoc,
1321 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1324 /// \brief Build a new return statement.
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
1328 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1329 return getSema().BuildReturnStmt(ReturnLoc, Result);
1332 /// \brief Build a new declaration statement.
1334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
1336 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
1337 SourceLocation StartLoc, SourceLocation EndLoc) {
1338 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1339 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1342 /// \brief Build a new inline asm statement.
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
1346 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1347 bool IsVolatile, unsigned NumOutputs,
1348 unsigned NumInputs, IdentifierInfo **Names,
1349 MultiExprArg Constraints, MultiExprArg Exprs,
1350 Expr *AsmString, MultiExprArg Clobbers,
1351 SourceLocation RParenLoc) {
1352 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1353 NumInputs, Names, Constraints, Exprs,
1354 AsmString, Clobbers, RParenLoc);
1357 /// \brief Build a new MS style inline asm statement.
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1361 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1362 ArrayRef<Token> AsmToks,
1363 StringRef AsmString,
1364 unsigned NumOutputs, unsigned NumInputs,
1365 ArrayRef<StringRef> Constraints,
1366 ArrayRef<StringRef> Clobbers,
1367 ArrayRef<Expr*> Exprs,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1370 NumOutputs, NumInputs,
1371 Constraints, Clobbers, Exprs, EndLoc);
1374 /// \brief Build a new co_return statement.
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
1378 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1380 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1383 /// \brief Build a new co_await expression.
1385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
1387 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1389 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1392 /// \brief Build a new co_await expression.
1394 /// By default, performs semantic analysis to build the new expression.
1395 /// Subclasses may override this routine to provide different behavior.
1396 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1398 UnresolvedLookupExpr *Lookup) {
1399 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1402 /// \brief Build a new co_yield expression.
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
1406 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1407 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1410 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1411 return getSema().BuildCoroutineBodyStmt(Args);
1414 /// \brief Build a new Objective-C \@try statement.
1416 /// By default, performs semantic analysis to build the new statement.
1417 /// Subclasses may override this routine to provide different behavior.
1418 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1420 MultiStmtArg CatchStmts,
1422 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1426 /// \brief Rebuild an Objective-C exception declaration.
1428 /// By default, performs semantic analysis to build the new declaration.
1429 /// Subclasses may override this routine to provide different behavior.
1430 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1431 TypeSourceInfo *TInfo, QualType T) {
1432 return getSema().BuildObjCExceptionDecl(TInfo, T,
1433 ExceptionDecl->getInnerLocStart(),
1434 ExceptionDecl->getLocation(),
1435 ExceptionDecl->getIdentifier());
1438 /// \brief Build a new Objective-C \@catch statement.
1440 /// By default, performs semantic analysis to build the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
1442 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1443 SourceLocation RParenLoc,
1446 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1450 /// \brief Build a new Objective-C \@finally statement.
1452 /// By default, performs semantic analysis to build the new statement.
1453 /// Subclasses may override this routine to provide different behavior.
1454 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1456 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1459 /// \brief Build a new Objective-C \@throw statement.
1461 /// By default, performs semantic analysis to build the new statement.
1462 /// Subclasses may override this routine to provide different behavior.
1463 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1465 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1468 /// \brief Build a new OpenMP executable directive.
1470 /// By default, performs semantic analysis to build the new statement.
1471 /// Subclasses may override this routine to provide different behavior.
1472 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1473 DeclarationNameInfo DirName,
1474 OpenMPDirectiveKind CancelRegion,
1475 ArrayRef<OMPClause *> Clauses,
1476 Stmt *AStmt, SourceLocation StartLoc,
1477 SourceLocation EndLoc) {
1478 return getSema().ActOnOpenMPExecutableDirective(
1479 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1482 /// \brief Build a new OpenMP 'if' clause.
1484 /// By default, performs semantic analysis to build the new OpenMP clause.
1485 /// Subclasses may override this routine to provide different behavior.
1486 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1487 Expr *Condition, SourceLocation StartLoc,
1488 SourceLocation LParenLoc,
1489 SourceLocation NameModifierLoc,
1490 SourceLocation ColonLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1493 LParenLoc, NameModifierLoc, ColonLoc,
1497 /// \brief Build a new OpenMP 'final' clause.
1499 /// By default, performs semantic analysis to build the new OpenMP clause.
1500 /// Subclasses may override this routine to provide different behavior.
1501 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1508 /// \brief Build a new OpenMP 'num_threads' clause.
1510 /// By default, performs semantic analysis to build the new OpenMP clause.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation EndLoc) {
1516 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1520 /// \brief Build a new OpenMP 'safelen' clause.
1522 /// By default, performs semantic analysis to build the new OpenMP clause.
1523 /// Subclasses may override this routine to provide different behavior.
1524 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1530 /// \brief Build a new OpenMP 'simdlen' clause.
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1535 SourceLocation LParenLoc,
1536 SourceLocation EndLoc) {
1537 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1540 /// \brief Build a new OpenMP 'collapse' clause.
1542 /// By default, performs semantic analysis to build the new OpenMP clause.
1543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1545 SourceLocation LParenLoc,
1546 SourceLocation EndLoc) {
1547 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1551 /// \brief Build a new OpenMP 'default' clause.
1553 /// By default, performs semantic analysis to build the new OpenMP clause.
1554 /// Subclasses may override this routine to provide different behavior.
1555 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1556 SourceLocation KindKwLoc,
1557 SourceLocation StartLoc,
1558 SourceLocation LParenLoc,
1559 SourceLocation EndLoc) {
1560 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1561 StartLoc, LParenLoc, EndLoc);
1564 /// \brief Build a new OpenMP 'proc_bind' clause.
1566 /// By default, performs semantic analysis to build the new OpenMP clause.
1567 /// Subclasses may override this routine to provide different behavior.
1568 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1569 SourceLocation KindKwLoc,
1570 SourceLocation StartLoc,
1571 SourceLocation LParenLoc,
1572 SourceLocation EndLoc) {
1573 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1574 StartLoc, LParenLoc, EndLoc);
1577 /// \brief Build a new OpenMP 'schedule' clause.
1579 /// By default, performs semantic analysis to build the new OpenMP clause.
1580 /// Subclasses may override this routine to provide different behavior.
1581 OMPClause *RebuildOMPScheduleClause(
1582 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1583 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1584 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1585 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1586 return getSema().ActOnOpenMPScheduleClause(
1587 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1591 /// \brief Build a new OpenMP 'ordered' clause.
1593 /// By default, performs semantic analysis to build the new OpenMP clause.
1594 /// Subclasses may override this routine to provide different behavior.
1595 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1596 SourceLocation EndLoc,
1597 SourceLocation LParenLoc, Expr *Num) {
1598 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1601 /// \brief Build a new OpenMP 'private' clause.
1603 /// By default, performs semantic analysis to build the new OpenMP clause.
1604 /// Subclasses may override this routine to provide different behavior.
1605 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1606 SourceLocation StartLoc,
1607 SourceLocation LParenLoc,
1608 SourceLocation EndLoc) {
1609 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1613 /// \brief Build a new OpenMP 'firstprivate' clause.
1615 /// By default, performs semantic analysis to build the new OpenMP clause.
1616 /// Subclasses may override this routine to provide different behavior.
1617 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1618 SourceLocation StartLoc,
1619 SourceLocation LParenLoc,
1620 SourceLocation EndLoc) {
1621 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1625 /// \brief Build a new OpenMP 'lastprivate' clause.
1627 /// By default, performs semantic analysis to build the new OpenMP clause.
1628 /// Subclasses may override this routine to provide different behavior.
1629 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1630 SourceLocation StartLoc,
1631 SourceLocation LParenLoc,
1632 SourceLocation EndLoc) {
1633 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1637 /// \brief Build a new OpenMP 'shared' clause.
1639 /// By default, performs semantic analysis to build the new OpenMP clause.
1640 /// Subclasses may override this routine to provide different behavior.
1641 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 SourceLocation EndLoc) {
1645 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1649 /// \brief Build a new OpenMP 'reduction' clause.
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1653 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1654 SourceLocation StartLoc,
1655 SourceLocation LParenLoc,
1656 SourceLocation ColonLoc,
1657 SourceLocation EndLoc,
1658 CXXScopeSpec &ReductionIdScopeSpec,
1659 const DeclarationNameInfo &ReductionId,
1660 ArrayRef<Expr *> UnresolvedReductions) {
1661 return getSema().ActOnOpenMPReductionClause(
1662 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1663 ReductionId, UnresolvedReductions);
1666 /// Build a new OpenMP 'task_reduction' clause.
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
1670 OMPClause *RebuildOMPTaskReductionClause(
1671 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1672 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1673 CXXScopeSpec &ReductionIdScopeSpec,
1674 const DeclarationNameInfo &ReductionId,
1675 ArrayRef<Expr *> UnresolvedReductions) {
1676 return getSema().ActOnOpenMPTaskReductionClause(
1677 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1678 ReductionId, UnresolvedReductions);
1681 /// Build a new OpenMP 'in_reduction' clause.
1683 /// By default, performs semantic analysis to build the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
1686 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1687 SourceLocation LParenLoc, SourceLocation ColonLoc,
1688 SourceLocation EndLoc,
1689 CXXScopeSpec &ReductionIdScopeSpec,
1690 const DeclarationNameInfo &ReductionId,
1691 ArrayRef<Expr *> UnresolvedReductions) {
1692 return getSema().ActOnOpenMPInReductionClause(
1693 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1694 ReductionId, UnresolvedReductions);
1697 /// \brief Build a new OpenMP 'linear' clause.
1699 /// By default, performs semantic analysis to build the new OpenMP clause.
1700 /// Subclasses may override this routine to provide different behavior.
1701 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1702 SourceLocation StartLoc,
1703 SourceLocation LParenLoc,
1704 OpenMPLinearClauseKind Modifier,
1705 SourceLocation ModifierLoc,
1706 SourceLocation ColonLoc,
1707 SourceLocation EndLoc) {
1708 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1709 Modifier, ModifierLoc, ColonLoc,
1713 /// \brief Build a new OpenMP 'aligned' clause.
1715 /// By default, performs semantic analysis to build the new OpenMP clause.
1716 /// Subclasses may override this routine to provide different behavior.
1717 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1718 SourceLocation StartLoc,
1719 SourceLocation LParenLoc,
1720 SourceLocation ColonLoc,
1721 SourceLocation EndLoc) {
1722 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1723 LParenLoc, ColonLoc, EndLoc);
1726 /// \brief Build a new OpenMP 'copyin' clause.
1728 /// By default, performs semantic analysis to build the new OpenMP clause.
1729 /// Subclasses may override this routine to provide different behavior.
1730 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1731 SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1738 /// \brief Build a new OpenMP 'copyprivate' clause.
1740 /// By default, performs semantic analysis to build the new OpenMP clause.
1741 /// Subclasses may override this routine to provide different behavior.
1742 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1743 SourceLocation StartLoc,
1744 SourceLocation LParenLoc,
1745 SourceLocation EndLoc) {
1746 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1750 /// \brief Build a new OpenMP 'flush' pseudo clause.
1752 /// By default, performs semantic analysis to build the new OpenMP clause.
1753 /// Subclasses may override this routine to provide different behavior.
1754 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1755 SourceLocation StartLoc,
1756 SourceLocation LParenLoc,
1757 SourceLocation EndLoc) {
1758 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1762 /// \brief Build a new OpenMP 'depend' pseudo clause.
1764 /// By default, performs semantic analysis to build the new OpenMP clause.
1765 /// Subclasses may override this routine to provide different behavior.
1767 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1768 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1769 SourceLocation StartLoc, SourceLocation LParenLoc,
1770 SourceLocation EndLoc) {
1771 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1772 StartLoc, LParenLoc, EndLoc);
1775 /// \brief Build a new OpenMP 'device' clause.
1777 /// By default, performs semantic analysis to build the new statement.
1778 /// Subclasses may override this routine to provide different behavior.
1779 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
1782 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1786 /// \brief Build a new OpenMP 'map' clause.
1788 /// By default, performs semantic analysis to build the new OpenMP clause.
1789 /// Subclasses may override this routine to provide different behavior.
1791 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1792 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1793 SourceLocation MapLoc, SourceLocation ColonLoc,
1794 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1795 SourceLocation LParenLoc, SourceLocation EndLoc) {
1796 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1797 IsMapTypeImplicit, MapLoc, ColonLoc,
1798 VarList, StartLoc, LParenLoc, EndLoc);
1801 /// \brief Build a new OpenMP 'num_teams' clause.
1803 /// By default, performs semantic analysis to build the new statement.
1804 /// Subclasses may override this routine to provide different behavior.
1805 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1806 SourceLocation LParenLoc,
1807 SourceLocation EndLoc) {
1808 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1812 /// \brief Build a new OpenMP 'thread_limit' clause.
1814 /// By default, performs semantic analysis to build the new statement.
1815 /// Subclasses may override this routine to provide different behavior.
1816 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1817 SourceLocation StartLoc,
1818 SourceLocation LParenLoc,
1819 SourceLocation EndLoc) {
1820 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1824 /// \brief Build a new OpenMP 'priority' clause.
1826 /// By default, performs semantic analysis to build the new statement.
1827 /// Subclasses may override this routine to provide different behavior.
1828 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1829 SourceLocation LParenLoc,
1830 SourceLocation EndLoc) {
1831 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1835 /// \brief Build a new OpenMP 'grainsize' clause.
1837 /// By default, performs semantic analysis to build the new statement.
1838 /// Subclasses may override this routine to provide different behavior.
1839 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1840 SourceLocation LParenLoc,
1841 SourceLocation EndLoc) {
1842 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1846 /// \brief Build a new OpenMP 'num_tasks' clause.
1848 /// By default, performs semantic analysis to build the new statement.
1849 /// Subclasses may override this routine to provide different behavior.
1850 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1851 SourceLocation LParenLoc,
1852 SourceLocation EndLoc) {
1853 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1857 /// \brief Build a new OpenMP 'hint' clause.
1859 /// By default, performs semantic analysis to build the new statement.
1860 /// Subclasses may override this routine to provide different behavior.
1861 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1862 SourceLocation LParenLoc,
1863 SourceLocation EndLoc) {
1864 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1867 /// \brief Build a new OpenMP 'dist_schedule' clause.
1869 /// By default, performs semantic analysis to build the new OpenMP clause.
1870 /// Subclasses may override this routine to provide different behavior.
1872 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1873 Expr *ChunkSize, SourceLocation StartLoc,
1874 SourceLocation LParenLoc, SourceLocation KindLoc,
1875 SourceLocation CommaLoc, SourceLocation EndLoc) {
1876 return getSema().ActOnOpenMPDistScheduleClause(
1877 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1880 /// \brief Build a new OpenMP 'to' clause.
1882 /// By default, performs semantic analysis to build the new statement.
1883 /// Subclasses may override this routine to provide different behavior.
1884 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1885 SourceLocation StartLoc,
1886 SourceLocation LParenLoc,
1887 SourceLocation EndLoc) {
1888 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1891 /// \brief Build a new OpenMP 'from' clause.
1893 /// By default, performs semantic analysis to build the new statement.
1894 /// Subclasses may override this routine to provide different behavior.
1895 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1896 SourceLocation StartLoc,
1897 SourceLocation LParenLoc,
1898 SourceLocation EndLoc) {
1899 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1903 /// Build a new OpenMP 'use_device_ptr' clause.
1905 /// By default, performs semantic analysis to build the new OpenMP clause.
1906 /// Subclasses may override this routine to provide different behavior.
1907 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1908 SourceLocation StartLoc,
1909 SourceLocation LParenLoc,
1910 SourceLocation EndLoc) {
1911 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1915 /// Build a new OpenMP 'is_device_ptr' clause.
1917 /// By default, performs semantic analysis to build the new OpenMP clause.
1918 /// Subclasses may override this routine to provide different behavior.
1919 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1920 SourceLocation StartLoc,
1921 SourceLocation LParenLoc,
1922 SourceLocation EndLoc) {
1923 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1927 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1929 /// By default, performs semantic analysis to build the new statement.
1930 /// Subclasses may override this routine to provide different behavior.
1931 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1933 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1936 /// \brief Build a new Objective-C \@synchronized statement.
1938 /// By default, performs semantic analysis to build the new statement.
1939 /// Subclasses may override this routine to provide different behavior.
1940 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1941 Expr *Object, Stmt *Body) {
1942 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1945 /// \brief Build a new Objective-C \@autoreleasepool statement.
1947 /// By default, performs semantic analysis to build the new statement.
1948 /// Subclasses may override this routine to provide different behavior.
1949 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1951 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1954 /// \brief Build a new Objective-C fast enumeration statement.
1956 /// By default, performs semantic analysis to build the new statement.
1957 /// Subclasses may override this routine to provide different behavior.
1958 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1961 SourceLocation RParenLoc,
1963 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1967 if (ForEachStmt.isInvalid())
1970 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1973 /// \brief Build a new C++ exception declaration.
1975 /// By default, performs semantic analysis to build the new decaration.
1976 /// Subclasses may override this routine to provide different behavior.
1977 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1978 TypeSourceInfo *Declarator,
1979 SourceLocation StartLoc,
1980 SourceLocation IdLoc,
1981 IdentifierInfo *Id) {
1982 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1983 StartLoc, IdLoc, Id);
1985 getSema().CurContext->addDecl(Var);
1989 /// \brief Build a new C++ catch statement.
1991 /// By default, performs semantic analysis to build the new statement.
1992 /// Subclasses may override this routine to provide different behavior.
1993 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1994 VarDecl *ExceptionDecl,
1996 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2000 /// \brief Build a new C++ try statement.
2002 /// By default, performs semantic analysis to build the new statement.
2003 /// Subclasses may override this routine to provide different behavior.
2004 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2005 ArrayRef<Stmt *> Handlers) {
2006 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2009 /// \brief Build a new C++0x range-based for statement.
2011 /// By default, performs semantic analysis to build the new statement.
2012 /// Subclasses may override this routine to provide different behavior.
2013 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
2014 SourceLocation CoawaitLoc,
2015 SourceLocation ColonLoc,
2016 Stmt *Range, Stmt *Begin, Stmt *End,
2017 Expr *Cond, Expr *Inc,
2019 SourceLocation RParenLoc) {
2020 // If we've just learned that the range is actually an Objective-C
2021 // collection, treat this as an Objective-C fast enumeration loop.
2022 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2023 if (RangeStmt->isSingleDecl()) {
2024 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2025 if (RangeVar->isInvalidDecl())
2028 Expr *RangeExpr = RangeVar->getInit();
2029 if (!RangeExpr->isTypeDependent() &&
2030 RangeExpr->getType()->isObjCObjectPointerType())
2031 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2037 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
2039 Cond, Inc, LoopVar, RParenLoc,
2040 Sema::BFRK_Rebuild);
2043 /// \brief Build a new C++0x range-based for statement.
2045 /// By default, performs semantic analysis to build the new statement.
2046 /// Subclasses may override this routine to provide different behavior.
2047 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
2049 NestedNameSpecifierLoc QualifierLoc,
2050 DeclarationNameInfo NameInfo,
2052 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2053 QualifierLoc, NameInfo, Nested);
2056 /// \brief Attach body to a C++0x range-based for statement.
2058 /// By default, performs semantic analysis to finish the new statement.
2059 /// Subclasses may override this routine to provide different behavior.
2060 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2061 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2064 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
2065 Stmt *TryBlock, Stmt *Handler) {
2066 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2069 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
2071 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2074 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
2075 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2078 /// \brief Build a new predefined expression.
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
2082 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2083 PredefinedExpr::IdentType IT) {
2084 return getSema().BuildPredefinedExpr(Loc, IT);
2087 /// \brief Build a new expression that references a declaration.
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
2091 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
2094 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2098 /// \brief Build a new expression that references a declaration.
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
2102 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
2104 const DeclarationNameInfo &NameInfo,
2105 TemplateArgumentListInfo *TemplateArgs) {
2107 SS.Adopt(QualifierLoc);
2109 // FIXME: loses template args.
2111 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
2114 /// \brief Build a new expression in parentheses.
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
2118 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
2119 SourceLocation RParen) {
2120 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2123 /// \brief Build a new pseudo-destructor expression.
2125 /// By default, performs semantic analysis to build the new expression.
2126 /// Subclasses may override this routine to provide different behavior.
2127 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2128 SourceLocation OperatorLoc,
2131 TypeSourceInfo *ScopeType,
2132 SourceLocation CCLoc,
2133 SourceLocation TildeLoc,
2134 PseudoDestructorTypeStorage Destroyed);
2136 /// \brief Build a new unary operator expression.
2138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
2140 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
2141 UnaryOperatorKind Opc,
2143 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2146 /// \brief Build a new builtin offsetof expression.
2148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
2150 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
2151 TypeSourceInfo *Type,
2152 ArrayRef<Sema::OffsetOfComponent> Components,
2153 SourceLocation RParenLoc) {
2154 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2158 /// \brief Build a new sizeof, alignof or vec_step expression with a
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
2163 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2164 SourceLocation OpLoc,
2165 UnaryExprOrTypeTrait ExprKind,
2167 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2170 /// \brief Build a new sizeof, alignof or vec step expression with an
2171 /// expression argument.
2173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
2175 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2176 UnaryExprOrTypeTrait ExprKind,
2179 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2180 if (Result.isInvalid())
2186 /// \brief Build a new array subscript expression.
2188 /// By default, performs semantic analysis to build the new expression.
2189 /// Subclasses may override this routine to provide different behavior.
2190 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
2191 SourceLocation LBracketLoc,
2193 SourceLocation RBracketLoc) {
2194 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2199 /// \brief Build a new array section expression.
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
2203 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2205 SourceLocation ColonLoc, Expr *Length,
2206 SourceLocation RBracketLoc) {
2207 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2208 ColonLoc, Length, RBracketLoc);
2211 /// \brief Build a new call expression.
2213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
2215 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
2217 SourceLocation RParenLoc,
2218 Expr *ExecConfig = nullptr) {
2219 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
2220 Args, RParenLoc, ExecConfig);
2223 /// \brief Build a new member access expression.
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
2227 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
2229 NestedNameSpecifierLoc QualifierLoc,
2230 SourceLocation TemplateKWLoc,
2231 const DeclarationNameInfo &MemberNameInfo,
2233 NamedDecl *FoundDecl,
2234 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2235 NamedDecl *FirstQualifierInScope) {
2236 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2238 if (!Member->getDeclName()) {
2239 // We have a reference to an unnamed field. This is always the
2240 // base of an anonymous struct/union member access, i.e. the
2241 // field is always of record type.
2242 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
2243 assert(Member->getType()->isRecordType() &&
2244 "unnamed member not of record type?");
2247 getSema().PerformObjectMemberConversion(BaseResult.get(),
2248 QualifierLoc.getNestedNameSpecifier(),
2250 if (BaseResult.isInvalid())
2252 Base = BaseResult.get();
2253 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
2254 MemberExpr *ME = new (getSema().Context)
2255 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2256 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
2261 SS.Adopt(QualifierLoc);
2263 Base = BaseResult.get();
2264 QualType BaseType = Base->getType();
2266 if (isArrow && !BaseType->isPointerType())
2269 // FIXME: this involves duplicating earlier analysis in a lot of
2270 // cases; we should avoid this when possible.
2271 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2272 R.addDecl(FoundDecl);
2275 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2277 FirstQualifierInScope,
2278 R, ExplicitTemplateArgs,
2282 /// \brief Build a new binary operator expression.
2284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
2286 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
2287 BinaryOperatorKind Opc,
2288 Expr *LHS, Expr *RHS) {
2289 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2292 /// \brief Build a new conditional operator expression.
2294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
2296 ExprResult RebuildConditionalOperator(Expr *Cond,
2297 SourceLocation QuestionLoc,
2299 SourceLocation ColonLoc,
2301 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2305 /// \brief Build a new C-style cast expression.
2307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
2309 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
2310 TypeSourceInfo *TInfo,
2311 SourceLocation RParenLoc,
2313 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2317 /// \brief Build a new compound literal expression.
2319 /// By default, performs semantic analysis to build the new expression.
2320 /// Subclasses may override this routine to provide different behavior.
2321 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
2322 TypeSourceInfo *TInfo,
2323 SourceLocation RParenLoc,
2325 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2329 /// \brief Build a new extended vector element access expression.
2331 /// By default, performs semantic analysis to build the new expression.
2332 /// Subclasses may override this routine to provide different behavior.
2333 ExprResult RebuildExtVectorElementExpr(Expr *Base,
2334 SourceLocation OpLoc,
2335 SourceLocation AccessorLoc,
2336 IdentifierInfo &Accessor) {
2339 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2340 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2341 OpLoc, /*IsArrow*/ false,
2342 SS, SourceLocation(),
2343 /*FirstQualifierInScope*/ nullptr,
2345 /* TemplateArgs */ nullptr,
2349 /// \brief Build a new initializer list expression.
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
2353 ExprResult RebuildInitList(SourceLocation LBraceLoc,
2355 SourceLocation RBraceLoc,
2356 QualType ResultTy) {
2358 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2359 if (Result.isInvalid() || ResultTy->isDependentType())
2362 // Patch in the result type we were given, which may have been computed
2363 // when the initial InitListExpr was built.
2364 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2365 ILE->setType(ResultTy);
2369 /// \brief Build a new designated initializer expression.
2371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
2373 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
2374 MultiExprArg ArrayExprs,
2375 SourceLocation EqualOrColonLoc,
2379 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2381 if (Result.isInvalid())
2387 /// \brief Build a new value-initialized expression.
2389 /// By default, builds the implicit value initialization without performing
2390 /// any semantic analysis. Subclasses may override this routine to provide
2391 /// different behavior.
2392 ExprResult RebuildImplicitValueInitExpr(QualType T) {
2393 return new (SemaRef.Context) ImplicitValueInitExpr(T);
2396 /// \brief Build a new \c va_arg expression.
2398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
2400 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
2401 Expr *SubExpr, TypeSourceInfo *TInfo,
2402 SourceLocation RParenLoc) {
2403 return getSema().BuildVAArgExpr(BuiltinLoc,
2408 /// \brief Build a new expression list in parentheses.
2410 /// By default, performs semantic analysis to build the new expression.
2411 /// Subclasses may override this routine to provide different behavior.
2412 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
2413 MultiExprArg SubExprs,
2414 SourceLocation RParenLoc) {
2415 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2418 /// \brief Build a new address-of-label expression.
2420 /// By default, performs semantic analysis, using the name of the label
2421 /// rather than attempting to map the label statement itself.
2422 /// Subclasses may override this routine to provide different behavior.
2423 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
2424 SourceLocation LabelLoc, LabelDecl *Label) {
2425 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2428 /// \brief Build a new GNU statement expression.
2430 /// By default, performs semantic analysis to build the new expression.
2431 /// Subclasses may override this routine to provide different behavior.
2432 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
2434 SourceLocation RParenLoc) {
2435 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2438 /// \brief Build a new __builtin_choose_expr expression.
2440 /// By default, performs semantic analysis to build the new expression.
2441 /// Subclasses may override this routine to provide different behavior.
2442 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
2443 Expr *Cond, Expr *LHS, Expr *RHS,
2444 SourceLocation RParenLoc) {
2445 return SemaRef.ActOnChooseExpr(BuiltinLoc,
2450 /// \brief Build a new generic selection expression.
2452 /// By default, performs semantic analysis to build the new expression.
2453 /// Subclasses may override this routine to provide different behavior.
2454 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2455 SourceLocation DefaultLoc,
2456 SourceLocation RParenLoc,
2457 Expr *ControllingExpr,
2458 ArrayRef<TypeSourceInfo *> Types,
2459 ArrayRef<Expr *> Exprs) {
2460 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2461 ControllingExpr, Types, Exprs);
2464 /// \brief Build a new overloaded operator call expression.
2466 /// By default, performs semantic analysis to build the new expression.
2467 /// The semantic analysis provides the behavior of template instantiation,
2468 /// copying with transformations that turn what looks like an overloaded
2469 /// operator call into a use of a builtin operator, performing
2470 /// argument-dependent lookup, etc. Subclasses may override this routine to
2471 /// provide different behavior.
2472 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2473 SourceLocation OpLoc,
2478 /// \brief Build a new C++ "named" cast expression, such as static_cast or
2479 /// reinterpret_cast.
2481 /// By default, this routine dispatches to one of the more-specific routines
2482 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2483 /// Subclasses may override this routine to provide different behavior.
2484 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
2485 Stmt::StmtClass Class,
2486 SourceLocation LAngleLoc,
2487 TypeSourceInfo *TInfo,
2488 SourceLocation RAngleLoc,
2489 SourceLocation LParenLoc,
2491 SourceLocation RParenLoc) {
2493 case Stmt::CXXStaticCastExprClass:
2494 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2495 RAngleLoc, LParenLoc,
2496 SubExpr, RParenLoc);
2498 case Stmt::CXXDynamicCastExprClass:
2499 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2500 RAngleLoc, LParenLoc,
2501 SubExpr, RParenLoc);
2503 case Stmt::CXXReinterpretCastExprClass:
2504 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2505 RAngleLoc, LParenLoc,
2509 case Stmt::CXXConstCastExprClass:
2510 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2511 RAngleLoc, LParenLoc,
2512 SubExpr, RParenLoc);
2515 llvm_unreachable("Invalid C++ named cast");
2519 /// \brief Build a new C++ static_cast expression.
2521 /// By default, performs semantic analysis to build the new expression.
2522 /// Subclasses may override this routine to provide different behavior.
2523 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
2524 SourceLocation LAngleLoc,
2525 TypeSourceInfo *TInfo,
2526 SourceLocation RAngleLoc,
2527 SourceLocation LParenLoc,
2529 SourceLocation RParenLoc) {
2530 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2532 SourceRange(LAngleLoc, RAngleLoc),
2533 SourceRange(LParenLoc, RParenLoc));
2536 /// \brief Build a new C++ dynamic_cast expression.
2538 /// By default, performs semantic analysis to build the new expression.
2539 /// Subclasses may override this routine to provide different behavior.
2540 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
2541 SourceLocation LAngleLoc,
2542 TypeSourceInfo *TInfo,
2543 SourceLocation RAngleLoc,
2544 SourceLocation LParenLoc,
2546 SourceLocation RParenLoc) {
2547 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2549 SourceRange(LAngleLoc, RAngleLoc),
2550 SourceRange(LParenLoc, RParenLoc));
2553 /// \brief Build a new C++ reinterpret_cast expression.
2555 /// By default, performs semantic analysis to build the new expression.
2556 /// Subclasses may override this routine to provide different behavior.
2557 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
2558 SourceLocation LAngleLoc,
2559 TypeSourceInfo *TInfo,
2560 SourceLocation RAngleLoc,
2561 SourceLocation LParenLoc,
2563 SourceLocation RParenLoc) {
2564 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2566 SourceRange(LAngleLoc, RAngleLoc),
2567 SourceRange(LParenLoc, RParenLoc));
2570 /// \brief Build a new C++ const_cast expression.
2572 /// By default, performs semantic analysis to build the new expression.
2573 /// Subclasses may override this routine to provide different behavior.
2574 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
2575 SourceLocation LAngleLoc,
2576 TypeSourceInfo *TInfo,
2577 SourceLocation RAngleLoc,
2578 SourceLocation LParenLoc,
2580 SourceLocation RParenLoc) {
2581 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2583 SourceRange(LAngleLoc, RAngleLoc),
2584 SourceRange(LParenLoc, RParenLoc));
2587 /// \brief Build a new C++ functional-style cast expression.
2589 /// By default, performs semantic analysis to build the new expression.
2590 /// Subclasses may override this routine to provide different behavior.
2591 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2592 SourceLocation LParenLoc,
2594 SourceLocation RParenLoc) {
2595 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2596 MultiExprArg(&Sub, 1),
2600 /// \brief Build a new C++ typeid(type) expression.
2602 /// By default, performs semantic analysis to build the new expression.
2603 /// Subclasses may override this routine to provide different behavior.
2604 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2605 SourceLocation TypeidLoc,
2606 TypeSourceInfo *Operand,
2607 SourceLocation RParenLoc) {
2608 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2613 /// \brief Build a new C++ typeid(expr) expression.
2615 /// By default, performs semantic analysis to build the new expression.
2616 /// Subclasses may override this routine to provide different behavior.
2617 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2618 SourceLocation TypeidLoc,
2620 SourceLocation RParenLoc) {
2621 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2625 /// \brief Build a new C++ __uuidof(type) expression.
2627 /// By default, performs semantic analysis to build the new expression.
2628 /// Subclasses may override this routine to provide different behavior.
2629 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2630 SourceLocation TypeidLoc,
2631 TypeSourceInfo *Operand,
2632 SourceLocation RParenLoc) {
2633 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2637 /// \brief Build a new C++ __uuidof(expr) expression.
2639 /// By default, performs semantic analysis to build the new expression.
2640 /// Subclasses may override this routine to provide different behavior.
2641 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2642 SourceLocation TypeidLoc,
2644 SourceLocation RParenLoc) {
2645 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2649 /// \brief Build a new C++ "this" expression.
2651 /// By default, builds a new "this" expression without performing any
2652 /// semantic analysis. Subclasses may override this routine to provide
2653 /// different behavior.
2654 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
2657 getSema().CheckCXXThisCapture(ThisLoc);
2658 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2661 /// \brief Build a new C++ throw expression.
2663 /// By default, performs semantic analysis to build the new expression.
2664 /// Subclasses may override this routine to provide different behavior.
2665 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2666 bool IsThrownVariableInScope) {
2667 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2670 /// \brief Build a new C++ default-argument expression.
2672 /// By default, builds a new default-argument expression, which does not
2673 /// require any semantic analysis. Subclasses may override this routine to
2674 /// provide different behavior.
2675 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
2676 ParmVarDecl *Param) {
2677 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2680 /// \brief Build a new C++11 default-initialization expression.
2682 /// By default, builds a new default field initialization expression, which
2683 /// does not require any semantic analysis. Subclasses may override this
2684 /// routine to provide different behavior.
2685 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2687 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2690 /// \brief Build a new C++ zero-initialization expression.
2692 /// By default, performs semantic analysis to build the new expression.
2693 /// Subclasses may override this routine to provide different behavior.
2694 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2695 SourceLocation LParenLoc,
2696 SourceLocation RParenLoc) {
2697 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2701 /// \brief Build a new C++ "new" expression.
2703 /// By default, performs semantic analysis to build the new expression.
2704 /// Subclasses may override this routine to provide different behavior.
2705 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
2707 SourceLocation PlacementLParen,
2708 MultiExprArg PlacementArgs,
2709 SourceLocation PlacementRParen,
2710 SourceRange TypeIdParens,
2711 QualType AllocatedType,
2712 TypeSourceInfo *AllocatedTypeInfo,
2714 SourceRange DirectInitRange,
2715 Expr *Initializer) {
2716 return getSema().BuildCXXNew(StartLoc, UseGlobal,
2728 /// \brief Build a new C++ "delete" expression.
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
2732 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2733 bool IsGlobalDelete,
2736 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2740 /// \brief Build a new type trait expression.
2742 /// By default, performs semantic analysis to build the new expression.
2743 /// Subclasses may override this routine to provide different behavior.
2744 ExprResult RebuildTypeTrait(TypeTrait Trait,
2745 SourceLocation StartLoc,
2746 ArrayRef<TypeSourceInfo *> Args,
2747 SourceLocation RParenLoc) {
2748 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2751 /// \brief Build a new array type trait expression.
2753 /// By default, performs semantic analysis to build the new expression.
2754 /// Subclasses may override this routine to provide different behavior.
2755 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2756 SourceLocation StartLoc,
2757 TypeSourceInfo *TSInfo,
2759 SourceLocation RParenLoc) {
2760 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2763 /// \brief Build a new expression trait expression.
2765 /// By default, performs semantic analysis to build the new expression.
2766 /// Subclasses may override this routine to provide different behavior.
2767 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2768 SourceLocation StartLoc,
2770 SourceLocation RParenLoc) {
2771 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2774 /// \brief Build a new (previously unresolved) declaration reference
2777 /// By default, performs semantic analysis to build the new expression.
2778 /// Subclasses may override this routine to provide different behavior.
2779 ExprResult RebuildDependentScopeDeclRefExpr(
2780 NestedNameSpecifierLoc QualifierLoc,
2781 SourceLocation TemplateKWLoc,
2782 const DeclarationNameInfo &NameInfo,
2783 const TemplateArgumentListInfo *TemplateArgs,
2784 bool IsAddressOfOperand,
2785 TypeSourceInfo **RecoveryTSI) {
2787 SS.Adopt(QualifierLoc);
2789 if (TemplateArgs || TemplateKWLoc.isValid())
2790 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2793 return getSema().BuildQualifiedDeclarationNameExpr(
2794 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2797 /// \brief Build a new template-id expression.
2799 /// By default, performs semantic analysis to build the new expression.
2800 /// Subclasses may override this routine to provide different behavior.
2801 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2802 SourceLocation TemplateKWLoc,
2805 const TemplateArgumentListInfo *TemplateArgs) {
2806 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2810 /// \brief Build a new object-construction expression.
2812 /// By default, performs semantic analysis to build the new expression.
2813 /// Subclasses may override this routine to provide different behavior.
2814 ExprResult RebuildCXXConstructExpr(QualType T,
2816 CXXConstructorDecl *Constructor,
2819 bool HadMultipleCandidates,
2820 bool ListInitialization,
2821 bool StdInitListInitialization,
2822 bool RequiresZeroInit,
2823 CXXConstructExpr::ConstructionKind ConstructKind,
2824 SourceRange ParenRange) {
2825 SmallVector<Expr*, 8> ConvertedArgs;
2826 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2830 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
2833 HadMultipleCandidates,
2835 StdInitListInitialization,
2836 RequiresZeroInit, ConstructKind,
2840 /// \brief Build a new implicit construction via inherited constructor
2842 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2843 CXXConstructorDecl *Constructor,
2844 bool ConstructsVBase,
2845 bool InheritedFromVBase) {
2846 return new (getSema().Context) CXXInheritedCtorInitExpr(
2847 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2850 /// \brief Build a new object-construction expression.
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
2854 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2855 SourceLocation LParenLoc,
2857 SourceLocation RParenLoc) {
2858 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2864 /// \brief Build a new object-construction expression.
2866 /// By default, performs semantic analysis to build the new expression.
2867 /// Subclasses may override this routine to provide different behavior.
2868 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2869 SourceLocation LParenLoc,
2871 SourceLocation RParenLoc) {
2872 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2878 /// \brief Build a new member reference expression.
2880 /// By default, performs semantic analysis to build the new expression.
2881 /// Subclasses may override this routine to provide different behavior.
2882 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2885 SourceLocation OperatorLoc,
2886 NestedNameSpecifierLoc QualifierLoc,
2887 SourceLocation TemplateKWLoc,
2888 NamedDecl *FirstQualifierInScope,
2889 const DeclarationNameInfo &MemberNameInfo,
2890 const TemplateArgumentListInfo *TemplateArgs) {
2892 SS.Adopt(QualifierLoc);
2894 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2895 OperatorLoc, IsArrow,
2897 FirstQualifierInScope,
2899 TemplateArgs, /*S*/nullptr);
2902 /// \brief Build a new member reference expression.
2904 /// By default, performs semantic analysis to build the new expression.
2905 /// Subclasses may override this routine to provide different behavior.
2906 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2907 SourceLocation OperatorLoc,
2909 NestedNameSpecifierLoc QualifierLoc,
2910 SourceLocation TemplateKWLoc,
2911 NamedDecl *FirstQualifierInScope,
2913 const TemplateArgumentListInfo *TemplateArgs) {
2915 SS.Adopt(QualifierLoc);
2917 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2918 OperatorLoc, IsArrow,
2920 FirstQualifierInScope,
2921 R, TemplateArgs, /*S*/nullptr);
2924 /// \brief Build a new noexcept expression.
2926 /// By default, performs semantic analysis to build the new expression.
2927 /// Subclasses may override this routine to provide different behavior.
2928 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2929 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2932 /// \brief Build a new expression to compute the length of a parameter pack.
2933 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2935 SourceLocation PackLoc,
2936 SourceLocation RParenLoc,
2937 Optional<unsigned> Length,
2938 ArrayRef<TemplateArgument> PartialArgs) {
2939 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2940 RParenLoc, Length, PartialArgs);
2943 /// \brief Build a new Objective-C boxed expression.
2945 /// By default, performs semantic analysis to build the new expression.
2946 /// Subclasses may override this routine to provide different behavior.
2947 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2948 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2951 /// \brief Build a new Objective-C array literal.
2953 /// By default, performs semantic analysis to build the new expression.
2954 /// Subclasses may override this routine to provide different behavior.
2955 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2956 Expr **Elements, unsigned NumElements) {
2957 return getSema().BuildObjCArrayLiteral(Range,
2958 MultiExprArg(Elements, NumElements));
2961 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2962 Expr *Base, Expr *Key,
2963 ObjCMethodDecl *getterMethod,
2964 ObjCMethodDecl *setterMethod) {
2965 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2966 getterMethod, setterMethod);
2969 /// \brief Build a new Objective-C dictionary literal.
2971 /// By default, performs semantic analysis to build the new expression.
2972 /// Subclasses may override this routine to provide different behavior.
2973 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2974 MutableArrayRef<ObjCDictionaryElement> Elements) {
2975 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
2978 /// \brief Build a new Objective-C \@encode expression.
2980 /// By default, performs semantic analysis to build the new expression.
2981 /// Subclasses may override this routine to provide different behavior.
2982 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2983 TypeSourceInfo *EncodeTypeInfo,
2984 SourceLocation RParenLoc) {
2985 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2988 /// \brief Build a new Objective-C class message.
2989 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2991 ArrayRef<SourceLocation> SelectorLocs,
2992 ObjCMethodDecl *Method,
2993 SourceLocation LBracLoc,
2995 SourceLocation RBracLoc) {
2996 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2997 ReceiverTypeInfo->getType(),
2998 /*SuperLoc=*/SourceLocation(),
2999 Sel, Method, LBracLoc, SelectorLocs,
3003 /// \brief Build a new Objective-C instance message.
3004 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
3006 ArrayRef<SourceLocation> SelectorLocs,
3007 ObjCMethodDecl *Method,
3008 SourceLocation LBracLoc,
3010 SourceLocation RBracLoc) {
3011 return SemaRef.BuildInstanceMessage(Receiver,
3012 Receiver->getType(),
3013 /*SuperLoc=*/SourceLocation(),
3014 Sel, Method, LBracLoc, SelectorLocs,
3018 /// \brief Build a new Objective-C instance/class message to 'super'.
3019 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3021 ArrayRef<SourceLocation> SelectorLocs,
3023 ObjCMethodDecl *Method,
3024 SourceLocation LBracLoc,
3026 SourceLocation RBracLoc) {
3027 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3030 Sel, Method, LBracLoc, SelectorLocs,
3032 : SemaRef.BuildClassMessage(nullptr,
3035 Sel, Method, LBracLoc, SelectorLocs,
3041 /// \brief Build a new Objective-C ivar reference expression.
3043 /// By default, performs semantic analysis to build the new expression.
3044 /// Subclasses may override this routine to provide different behavior.
3045 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
3046 SourceLocation IvarLoc,
3047 bool IsArrow, bool IsFreeIvar) {
3049 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3050 ExprResult Result = getSema().BuildMemberReferenceExpr(
3051 BaseArg, BaseArg->getType(),
3052 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3053 /*FirstQualifierInScope=*/nullptr, NameInfo,
3054 /*TemplateArgs=*/nullptr,
3056 if (IsFreeIvar && Result.isUsable())
3057 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3061 /// \brief Build a new Objective-C property reference expression.
3063 /// By default, performs semantic analysis to build the new expression.
3064 /// Subclasses may override this routine to provide different behavior.
3065 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
3066 ObjCPropertyDecl *Property,
3067 SourceLocation PropertyLoc) {
3069 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3070 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3071 /*FIXME:*/PropertyLoc,
3073 SS, SourceLocation(),
3074 /*FirstQualifierInScope=*/nullptr,
3076 /*TemplateArgs=*/nullptr,
3080 /// \brief Build a new Objective-C property reference expression.
3082 /// By default, performs semantic analysis to build the new expression.
3083 /// Subclasses may override this routine to provide different behavior.
3084 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3085 ObjCMethodDecl *Getter,
3086 ObjCMethodDecl *Setter,
3087 SourceLocation PropertyLoc) {
3088 // Since these expressions can only be value-dependent, we do not
3089 // need to perform semantic analysis again.
3091 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3092 VK_LValue, OK_ObjCProperty,
3093 PropertyLoc, Base));
3096 /// \brief Build a new Objective-C "isa" expression.
3098 /// By default, performs semantic analysis to build the new expression.
3099 /// Subclasses may override this routine to provide different behavior.
3100 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
3101 SourceLocation OpLoc, bool IsArrow) {
3103 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3104 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3106 SS, SourceLocation(),
3107 /*FirstQualifierInScope=*/nullptr,
3109 /*TemplateArgs=*/nullptr,
3113 /// \brief Build a new shuffle vector expression.
3115 /// By default, performs semantic analysis to build the new expression.
3116 /// Subclasses may override this routine to provide different behavior.
3117 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
3118 MultiExprArg SubExprs,
3119 SourceLocation RParenLoc) {
3120 // Find the declaration for __builtin_shufflevector
3121 const IdentifierInfo &Name
3122 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3123 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3124 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3125 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3127 // Build a reference to the __builtin_shufflevector builtin
3128 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3129 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3130 SemaRef.Context.BuiltinFnTy,
3131 VK_RValue, BuiltinLoc);
3132 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3133 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3134 CK_BuiltinFnToFnPtr).get();
3136 // Build the CallExpr
3137 ExprResult TheCall = new (SemaRef.Context) CallExpr(
3138 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3139 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
3141 // Type-check the __builtin_shufflevector expression.
3142 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3145 /// \brief Build a new convert vector expression.
3146 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3147 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3148 SourceLocation RParenLoc) {
3149 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3150 BuiltinLoc, RParenLoc);
3153 /// \brief Build a new template argument pack expansion.
3155 /// By default, performs semantic analysis to build a new pack expansion
3156 /// for a template argument. Subclasses may override this routine to provide
3157 /// different behavior.
3158 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
3159 SourceLocation EllipsisLoc,
3160 Optional<unsigned> NumExpansions) {
3161 switch (Pattern.getArgument().getKind()) {
3162 case TemplateArgument::Expression: {
3164 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3165 EllipsisLoc, NumExpansions);
3166 if (Result.isInvalid())
3167 return TemplateArgumentLoc();
3169 return TemplateArgumentLoc(Result.get(), Result.get());
3172 case TemplateArgument::Template:
3173 return TemplateArgumentLoc(TemplateArgument(
3174 Pattern.getArgument().getAsTemplate(),
3176 Pattern.getTemplateQualifierLoc(),
3177 Pattern.getTemplateNameLoc(),
3180 case TemplateArgument::Null:
3181 case TemplateArgument::Integral:
3182 case TemplateArgument::Declaration:
3183 case TemplateArgument::Pack:
3184 case TemplateArgument::TemplateExpansion:
3185 case TemplateArgument::NullPtr:
3186 llvm_unreachable("Pack expansion pattern has no parameter packs");
3188 case TemplateArgument::Type:
3189 if (TypeSourceInfo *Expansion
3190 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3193 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3198 return TemplateArgumentLoc();
3201 /// \brief Build a new expression pack expansion.
3203 /// By default, performs semantic analysis to build a new pack expansion
3204 /// for an expression. Subclasses may override this routine to provide
3205 /// different behavior.
3206 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
3207 Optional<unsigned> NumExpansions) {
3208 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3211 /// \brief Build a new C++1z fold-expression.
3213 /// By default, performs semantic analysis in order to build a new fold
3215 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3216 BinaryOperatorKind Operator,
3217 SourceLocation EllipsisLoc, Expr *RHS,
3218 SourceLocation RParenLoc) {
3219 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3223 /// \brief Build an empty C++1z fold-expression with the given operator.
3225 /// By default, produces the fallback value for the fold-expression, or
3226 /// produce an error if there is no fallback value.
3227 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3228 BinaryOperatorKind Operator) {
3229 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3232 /// \brief Build a new atomic operation expression.
3234 /// By default, performs semantic analysis to build the new expression.
3235 /// Subclasses may override this routine to provide different behavior.
3236 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3237 MultiExprArg SubExprs,
3239 AtomicExpr::AtomicOp Op,
3240 SourceLocation RParenLoc) {
3241 // Just create the expression; there is not any interesting semantic
3242 // analysis here because we can't actually build an AtomicExpr until
3243 // we are sure it is semantically sound.
3244 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3249 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3250 QualType ObjectType,
3251 NamedDecl *FirstQualifierInScope,
3254 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3255 QualType ObjectType,
3256 NamedDecl *FirstQualifierInScope,
3259 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3260 NamedDecl *FirstQualifierInScope,
3263 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3264 DependentNameTypeLoc TL,
3265 bool DeducibleTSTContext);
3268 template<typename Derived>
3269 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
3273 switch (S->getStmtClass()) {
3274 case Stmt::NoStmtClass: break;
3276 // Transform individual statement nodes
3277 #define STMT(Node, Parent) \
3278 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3279 #define ABSTRACT_STMT(Node)
3280 #define EXPR(Node, Parent)
3281 #include "clang/AST/StmtNodes.inc"
3283 // Transform expressions by calling TransformExpr.
3284 #define STMT(Node, Parent)
3285 #define ABSTRACT_STMT(Stmt)
3286 #define EXPR(Node, Parent) case Stmt::Node##Class:
3287 #include "clang/AST/StmtNodes.inc"
3289 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3293 return getSema().ActOnExprStmt(E);
3300 template<typename Derived>
3301 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3305 switch (S->getClauseKind()) {
3307 // Transform individual clause nodes
3308 #define OPENMP_CLAUSE(Name, Class) \
3309 case OMPC_ ## Name : \
3310 return getDerived().Transform ## Class(cast<Class>(S));
3311 #include "clang/Basic/OpenMPKinds.def"
3318 template<typename Derived>
3319 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
3323 switch (E->getStmtClass()) {
3324 case Stmt::NoStmtClass: break;
3325 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3326 #define ABSTRACT_STMT(Stmt)
3327 #define EXPR(Node, Parent) \
3328 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3329 #include "clang/AST/StmtNodes.inc"
3335 template<typename Derived>
3336 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
3338 // Initializers are instantiated like expressions, except that various outer
3339 // layers are stripped.
3343 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3344 Init = ExprTemp->getSubExpr();
3346 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3347 Init = AIL->getCommonExpr();
3349 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3350 Init = MTE->GetTemporaryExpr();
3352 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3353 Init = Binder->getSubExpr();
3355 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3356 Init = ICE->getSubExprAsWritten();
3358 if (CXXStdInitializerListExpr *ILE =
3359 dyn_cast<CXXStdInitializerListExpr>(Init))
3360 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3362 // If this is copy-initialization, we only need to reconstruct
3363 // InitListExprs. Other forms of copy-initialization will be a no-op if
3364 // the initializer is already the right type.
3365 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3366 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3367 return getDerived().TransformExpr(Init);
3369 // Revert value-initialization back to empty parens.
3370 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3371 SourceRange Parens = VIE->getSourceRange();
3372 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3376 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3377 if (isa<ImplicitValueInitExpr>(Init))
3378 return getDerived().RebuildParenListExpr(SourceLocation(), None,
3381 // Revert initialization by constructor back to a parenthesized or braced list
3382 // of expressions. Any other form of initializer can just be reused directly.
3383 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3384 return getDerived().TransformExpr(Init);
3386 // If the initialization implicitly converted an initializer list to a
3387 // std::initializer_list object, unwrap the std::initializer_list too.
3388 if (Construct && Construct->isStdInitListInitialization())
3389 return TransformInitializer(Construct->getArg(0), NotCopyInit);
3391 SmallVector<Expr*, 8> NewArgs;
3392 bool ArgChanged = false;
3393 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3394 /*IsCall*/true, NewArgs, &ArgChanged))
3397 // If this was list initialization, revert to list form.
3398 if (Construct->isListInitialization())
3399 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3400 Construct->getLocEnd(),
3401 Construct->getType());
3403 // Build a ParenListExpr to represent anything else.
3404 SourceRange Parens = Construct->getParenOrBraceRange();
3405 if (Parens.isInvalid()) {
3406 // This was a variable declaration's initialization for which no initializer
3408 assert(NewArgs.empty() &&
3409 "no parens or braces but have direct init with arguments?");
3412 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3416 template<typename Derived>
3417 bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
3420 SmallVectorImpl<Expr *> &Outputs,
3422 for (unsigned I = 0; I != NumInputs; ++I) {
3423 // If requested, drop call arguments that need to be dropped.
3424 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3431 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3432 Expr *Pattern = Expansion->getPattern();
3434 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3435 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3436 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3438 // Determine whether the set of unexpanded parameter packs can and should
3441 bool RetainExpansion = false;
3442 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3443 Optional<unsigned> NumExpansions = OrigNumExpansions;
3444 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3445 Pattern->getSourceRange(),
3447 Expand, RetainExpansion,
3452 // The transform has determined that we should perform a simple
3453 // transformation on the pack expansion, producing another pack
3455 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3456 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3457 if (OutPattern.isInvalid())
3460 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3461 Expansion->getEllipsisLoc(),
3463 if (Out.isInvalid())
3468 Outputs.push_back(Out.get());
3472 // Record right away that the argument was changed. This needs
3473 // to happen even if the array expands to nothing.
3474 if (ArgChanged) *ArgChanged = true;
3476 // The transform has determined that we should perform an elementwise
3477 // expansion of the pattern. Do so.
3478 for (unsigned I = 0; I != *NumExpansions; ++I) {
3479 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3480 ExprResult Out = getDerived().TransformExpr(Pattern);
3481 if (Out.isInvalid())
3484 if (Out.get()->containsUnexpandedParameterPack()) {
3485 Out = getDerived().RebuildPackExpansion(
3486 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3487 if (Out.isInvalid())
3491 Outputs.push_back(Out.get());
3494 // If we're supposed to retain a pack expansion, do so by temporarily
3495 // forgetting the partially-substituted parameter pack.
3496 if (RetainExpansion) {
3497 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3499 ExprResult Out = getDerived().TransformExpr(Pattern);
3500 if (Out.isInvalid())
3503 Out = getDerived().RebuildPackExpansion(
3504 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3505 if (Out.isInvalid())
3508 Outputs.push_back(Out.get());
3515 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3516 : getDerived().TransformExpr(Inputs[I]);
3517 if (Result.isInvalid())
3520 if (Result.get() != Inputs[I] && ArgChanged)
3523 Outputs.push_back(Result.get());
3529 template <typename Derived>
3530 Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3531 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3533 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3534 getDerived().TransformDefinition(Var->getLocation(), Var));
3537 return Sema::ConditionError();
3539 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3543 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3545 if (CondExpr.isInvalid())
3546 return Sema::ConditionError();
3548 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3551 return Sema::ConditionResult();
3554 template<typename Derived>
3555 NestedNameSpecifierLoc
3556 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3557 NestedNameSpecifierLoc NNS,
3558 QualType ObjectType,
3559 NamedDecl *FirstQualifierInScope) {
3560 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
3561 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3562 Qualifier = Qualifier.getPrefix())
3563 Qualifiers.push_back(Qualifier);
3566 while (!Qualifiers.empty()) {
3567 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3568 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
3570 switch (QNNS->getKind()) {
3571 case NestedNameSpecifier::Identifier: {
3572 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3573 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3574 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3575 SS, FirstQualifierInScope, false))
3576 return NestedNameSpecifierLoc();
3580 case NestedNameSpecifier::Namespace: {
3582 = cast_or_null<NamespaceDecl>(
3583 getDerived().TransformDecl(
3584 Q.getLocalBeginLoc(),
3585 QNNS->getAsNamespace()));
3586 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3590 case NestedNameSpecifier::NamespaceAlias: {
3591 NamespaceAliasDecl *Alias
3592 = cast_or_null<NamespaceAliasDecl>(
3593 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3594 QNNS->getAsNamespaceAlias()));
3595 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3596 Q.getLocalEndLoc());
3600 case NestedNameSpecifier::Global:
3601 // There is no meaningful transformation that one could perform on the
3603 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3606 case NestedNameSpecifier::Super: {
3608 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3609 SourceLocation(), QNNS->getAsRecordDecl()));
3610 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3614 case NestedNameSpecifier::TypeSpecWithTemplate:
3615 case NestedNameSpecifier::TypeSpec: {
3616 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3617 FirstQualifierInScope, SS);
3620 return NestedNameSpecifierLoc();
3622 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3623 (SemaRef.getLangOpts().CPlusPlus11 &&
3624 TL.getType()->isEnumeralType())) {
3625 assert(!TL.getType().hasLocalQualifiers() &&
3626 "Can't get cv-qualifiers here");
3627 if (TL.getType()->isEnumeralType())
3628 SemaRef.Diag(TL.getBeginLoc(),
3629 diag::warn_cxx98_compat_enum_nested_name_spec);
3630 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3631 Q.getLocalEndLoc());
3634 // If the nested-name-specifier is an invalid type def, don't emit an
3635 // error because a previous error should have already been emitted.
3636 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3637 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3638 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3639 << TL.getType() << SS.getRange();
3641 return NestedNameSpecifierLoc();
3645 // The qualifier-in-scope and object type only apply to the leftmost entity.
3646 FirstQualifierInScope = nullptr;
3647 ObjectType = QualType();
3650 // Don't rebuild the nested-name-specifier if we don't have to.
3651 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3652 !getDerived().AlwaysRebuild())
3655 // If we can re-use the source-location data from the original
3656 // nested-name-specifier, do so.
3657 if (SS.location_size() == NNS.getDataLength() &&
3658 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3659 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3661 // Allocate new nested-name-specifier location information.
3662 return SS.getWithLocInContext(SemaRef.Context);
3665 template<typename Derived>
3667 TreeTransform<Derived>
3668 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
3669 DeclarationName Name = NameInfo.getName();
3671 return DeclarationNameInfo();
3673 switch (Name.getNameKind()) {
3674 case DeclarationName::Identifier:
3675 case DeclarationName::ObjCZeroArgSelector:
3676 case DeclarationName::ObjCOneArgSelector:
3677 case DeclarationName::ObjCMultiArgSelector:
3678 case DeclarationName::CXXOperatorName:
3679 case DeclarationName::CXXLiteralOperatorName:
3680 case DeclarationName::CXXUsingDirective:
3683 case DeclarationName::CXXDeductionGuideName: {
3684 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3685 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3686 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3688 return DeclarationNameInfo();
3690 DeclarationNameInfo NewNameInfo(NameInfo);
3691 NewNameInfo.setName(
3692 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3696 case DeclarationName::CXXConstructorName:
3697 case DeclarationName::CXXDestructorName:
3698 case DeclarationName::CXXConversionFunctionName: {
3699 TypeSourceInfo *NewTInfo;
3700 CanQualType NewCanTy;
3701 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3702 NewTInfo = getDerived().TransformType(OldTInfo);
3704 return DeclarationNameInfo();
3705 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3709 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3710 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3712 return DeclarationNameInfo();
3713 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3716 DeclarationName NewName
3717 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3719 DeclarationNameInfo NewNameInfo(NameInfo);
3720 NewNameInfo.setName(NewName);
3721 NewNameInfo.setNamedTypeInfo(NewTInfo);
3726 llvm_unreachable("Unknown name kind.");
3729 template<typename Derived>
3731 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3733 SourceLocation NameLoc,
3734 QualType ObjectType,
3735 NamedDecl *FirstQualifierInScope,
3736 bool AllowInjectedClassName) {
3737 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3738 TemplateDecl *Template = QTN->getTemplateDecl();
3739 assert(Template && "qualified template name must refer to a template");
3741 TemplateDecl *TransTemplate
3742 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3745 return TemplateName();
3747 if (!getDerived().AlwaysRebuild() &&
3748 SS.getScopeRep() == QTN->getQualifier() &&
3749 TransTemplate == Template)
3752 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3756 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3757 if (SS.getScopeRep()) {
3758 // These apply to the scope specifier, not the template.
3759 ObjectType = QualType();
3760 FirstQualifierInScope = nullptr;
3763 if (!getDerived().AlwaysRebuild() &&
3764 SS.getScopeRep() == DTN->getQualifier() &&
3765 ObjectType.isNull())
3768 if (DTN->isIdentifier()) {
3769 return getDerived().RebuildTemplateName(SS,
3770 *DTN->getIdentifier(),
3773 FirstQualifierInScope,
3774 AllowInjectedClassName);
3777 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3778 ObjectType, AllowInjectedClassName);
3781 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3782 TemplateDecl *TransTemplate
3783 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3786 return TemplateName();
3788 if (!getDerived().AlwaysRebuild() &&
3789 TransTemplate == Template)
3792 return TemplateName(TransTemplate);
3795 if (SubstTemplateTemplateParmPackStorage *SubstPack
3796 = Name.getAsSubstTemplateTemplateParmPack()) {
3797 TemplateTemplateParmDecl *TransParam
3798 = cast_or_null<TemplateTemplateParmDecl>(
3799 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3801 return TemplateName();
3803 if (!getDerived().AlwaysRebuild() &&
3804 TransParam == SubstPack->getParameterPack())
3807 return getDerived().RebuildTemplateName(TransParam,
3808 SubstPack->getArgumentPack());
3811 // These should be getting filtered out before they reach the AST.
3812 llvm_unreachable("overloaded function decl survived to here");
3815 template<typename Derived>
3816 void TreeTransform<Derived>::InventTemplateArgumentLoc(
3817 const TemplateArgument &Arg,
3818 TemplateArgumentLoc &Output) {
3819 SourceLocation Loc = getDerived().getBaseLocation();
3820 switch (Arg.getKind()) {
3821 case TemplateArgument::Null:
3822 llvm_unreachable("null template argument in TreeTransform");
3825 case TemplateArgument::Type:
3826 Output = TemplateArgumentLoc(Arg,
3827 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3831 case TemplateArgument::Template:
3832 case TemplateArgument::TemplateExpansion: {
3833 NestedNameSpecifierLocBuilder Builder;
3834 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
3835 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3836 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3837 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3838 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3840 if (Arg.getKind() == TemplateArgument::Template)
3841 Output = TemplateArgumentLoc(Arg,
3842 Builder.getWithLocInContext(SemaRef.Context),
3845 Output = TemplateArgumentLoc(Arg,
3846 Builder.getWithLocInContext(SemaRef.Context),
3852 case TemplateArgument::Expression:
3853 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3856 case TemplateArgument::Declaration:
3857 case TemplateArgument::Integral:
3858 case TemplateArgument::Pack:
3859 case TemplateArgument::NullPtr:
3860 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
3865 template<typename Derived>
3866 bool TreeTransform<Derived>::TransformTemplateArgument(
3867 const TemplateArgumentLoc &Input,
3868 TemplateArgumentLoc &Output, bool Uneval) {
3869 const TemplateArgument &Arg = Input.getArgument();
3870 switch (Arg.getKind()) {
3871 case TemplateArgument::Null:
3872 case TemplateArgument::Integral:
3873 case TemplateArgument::Pack:
3874 case TemplateArgument::Declaration:
3875 case TemplateArgument::NullPtr:
3876 llvm_unreachable("Unexpected TemplateArgument");
3878 case TemplateArgument::Type: {
3879 TypeSourceInfo *DI = Input.getTypeSourceInfo();
3881 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3883 DI = getDerived().TransformType(DI);
3884 if (!DI) return true;
3886 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3890 case TemplateArgument::Template: {
3891 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3893 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3899 SS.Adopt(QualifierLoc);
3900 TemplateName Template
3901 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3902 Input.getTemplateNameLoc());
3903 if (Template.isNull())
3906 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3907 Input.getTemplateNameLoc());
3911 case TemplateArgument::TemplateExpansion:
3912 llvm_unreachable("Caller should expand pack expansions");
3914 case TemplateArgument::Expression: {
3915 // Template argument expressions are constant expressions.
3916 EnterExpressionEvaluationContext Unevaluated(
3918 ? Sema::ExpressionEvaluationContext::Unevaluated
3919 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
3921 Expr *InputExpr = Input.getSourceExpression();
3922 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3924 ExprResult E = getDerived().TransformExpr(InputExpr);
3925 E = SemaRef.ActOnConstantExpression(E);
3926 if (E.isInvalid()) return true;
3927 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3932 // Work around bogus GCC warning
3936 /// \brief Iterator adaptor that invents template argument location information
3937 /// for each of the template arguments in its underlying iterator.
3938 template<typename Derived, typename InputIterator>
3939 class TemplateArgumentLocInventIterator {
3940 TreeTransform<Derived> &Self;
3944 typedef TemplateArgumentLoc value_type;
3945 typedef TemplateArgumentLoc reference;
3946 typedef typename std::iterator_traits<InputIterator>::difference_type
3948 typedef std::input_iterator_tag iterator_category;
3951 TemplateArgumentLoc Arg;
3954 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3956 const TemplateArgumentLoc *operator->() const { return &Arg; }
3959 TemplateArgumentLocInventIterator() { }
3961 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3963 : Self(Self), Iter(Iter) { }
3965 TemplateArgumentLocInventIterator &operator++() {
3970 TemplateArgumentLocInventIterator operator++(int) {
3971 TemplateArgumentLocInventIterator Old(*this);
3976 reference operator*() const {
3977 TemplateArgumentLoc Result;
3978 Self.InventTemplateArgumentLoc(*Iter, Result);
3982 pointer operator->() const { return pointer(**this); }
3984 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3985 const TemplateArgumentLocInventIterator &Y) {
3986 return X.Iter == Y.Iter;
3989 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3990 const TemplateArgumentLocInventIterator &Y) {
3991 return X.Iter != Y.Iter;
3995 template<typename Derived>
3996 template<typename InputIterator>
3997 bool TreeTransform<Derived>::TransformTemplateArguments(
3998 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4000 for (; First != Last; ++First) {
4001 TemplateArgumentLoc Out;
4002 TemplateArgumentLoc In = *First;
4004 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4005 // Unpack argument packs, which we translate them into separate
4007 // FIXME: We could do much better if we could guarantee that the
4008 // TemplateArgumentLocInfo for the pack expansion would be usable for
4009 // all of the template arguments in the argument pack.
4010 typedef TemplateArgumentLocInventIterator<Derived,
4011 TemplateArgument::pack_iterator>
4013 if (TransformTemplateArguments(PackLocIterator(*this,
4014 In.getArgument().pack_begin()),
4015 PackLocIterator(*this,
4016 In.getArgument().pack_end()),
4023 if (In.getArgument().isPackExpansion()) {
4024 // We have a pack expansion, for which we will be substituting into
4026 SourceLocation Ellipsis;
4027 Optional<unsigned> OrigNumExpansions;
4028 TemplateArgumentLoc Pattern
4029 = getSema().getTemplateArgumentPackExpansionPattern(
4030 In, Ellipsis, OrigNumExpansions);
4032 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4033 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4034 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4036 // Determine whether the set of unexpanded parameter packs can and should
4039 bool RetainExpansion = false;
4040 Optional<unsigned> NumExpansions = OrigNumExpansions;
4041 if (getDerived().TryExpandParameterPacks(Ellipsis,
4042 Pattern.getSourceRange(),
4050 // The transform has determined that we should perform a simple
4051 // transformation on the pack expansion, producing another pack
4053 TemplateArgumentLoc OutPattern;
4054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4055 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4058 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4060 if (Out.getArgument().isNull())
4063 Outputs.addArgument(Out);
4067 // The transform has determined that we should perform an elementwise
4068 // expansion of the pattern. Do so.
4069 for (unsigned I = 0; I != *NumExpansions; ++I) {
4070 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4072 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4075 if (Out.getArgument().containsUnexpandedParameterPack()) {
4076 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4078 if (Out.getArgument().isNull())
4082 Outputs.addArgument(Out);
4085 // If we're supposed to retain a pack expansion, do so by temporarily
4086 // forgetting the partially-substituted parameter pack.
4087 if (RetainExpansion) {
4088 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4090 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4093 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4095 if (Out.getArgument().isNull())
4098 Outputs.addArgument(Out);
4105 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4108 Outputs.addArgument(Out);
4115 //===----------------------------------------------------------------------===//
4116 // Type transformation
4117 //===----------------------------------------------------------------------===//
4119 template<typename Derived>
4120 QualType TreeTransform<Derived>::TransformType(QualType T) {
4121 if (getDerived().AlreadyTransformed(T))
4124 // Temporary workaround. All of these transformations should
4125 // eventually turn into transformations on TypeLocs.
4126 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4127 getDerived().getBaseLocation());
4129 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4134 return NewDI->getType();
4137 template<typename Derived>
4138 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
4139 // Refine the base location to the type's location.
4140 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4141 getDerived().getBaseEntity());
4142 if (getDerived().AlreadyTransformed(DI->getType()))
4147 TypeLoc TL = DI->getTypeLoc();
4148 TLB.reserve(TL.getFullDataSize());
4150 QualType Result = getDerived().TransformType(TLB, TL);
4151 if (Result.isNull())
4154 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4157 template<typename Derived>
4159 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
4160 switch (T.getTypeLocClass()) {
4161 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4162 #define TYPELOC(CLASS, PARENT) \
4163 case TypeLoc::CLASS: \
4164 return getDerived().Transform##CLASS##Type(TLB, \
4165 T.castAs<CLASS##TypeLoc>());
4166 #include "clang/AST/TypeLocNodes.def"
4169 llvm_unreachable("unhandled type loc!");
4172 template<typename Derived>
4173 QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4174 if (!isa<DependentNameType>(T))
4175 return TransformType(T);
4177 if (getDerived().AlreadyTransformed(T))
4179 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4180 getDerived().getBaseLocation());
4181 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4182 return NewDI ? NewDI->getType() : QualType();
4185 template<typename Derived>
4187 TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4188 if (!isa<DependentNameType>(DI->getType()))
4189 return TransformType(DI);
4191 // Refine the base location to the type's location.
4192 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4193 getDerived().getBaseEntity());
4194 if (getDerived().AlreadyTransformed(DI->getType()))
4199 TypeLoc TL = DI->getTypeLoc();
4200 TLB.reserve(TL.getFullDataSize());
4202 auto QTL = TL.getAs<QualifiedTypeLoc>();
4204 TL = QTL.getUnqualifiedLoc();
4206 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4208 QualType Result = getDerived().TransformDependentNameType(
4209 TLB, DNTL, /*DeducedTSTContext*/true);
4210 if (Result.isNull())
4214 Result = getDerived().RebuildQualifiedType(
4215 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4216 TLB.TypeWasModifiedSafely(Result);
4219 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4222 template<typename Derived>
4224 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
4225 QualifiedTypeLoc T) {
4226 Qualifiers Quals = T.getType().getLocalQualifiers();
4228 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4229 if (Result.isNull())
4232 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4234 // RebuildQualifiedType might have updated the type, but not in a way
4235 // that invalidates the TypeLoc. (There's no location information for
4237 TLB.TypeWasModifiedSafely(Result);
4242 template<typename Derived>
4243 QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4247 // [When] adding cv-qualifications on top of the function type [...] the
4248 // cv-qualifiers are ignored.
4250 // when the cv-qualifiers are introduced through the use of a typedef-name
4251 // or decltype-specifier [...] the cv-qualifiers are ignored.
4252 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4253 // applied to a reference type.
4254 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4255 if (T->isFunctionType() || T->isReferenceType())
4258 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4260 if (Quals.hasObjCLifetime()) {
4261 if (!T->isObjCLifetimeType() && !T->isDependentType())
4262 Quals.removeObjCLifetime();
4263 else if (T.getObjCLifetime()) {
4265 // A lifetime qualifier applied to a substituted template parameter
4266 // overrides the lifetime qualifier from the template argument.
4267 const AutoType *AutoTy;
4268 if (const SubstTemplateTypeParmType *SubstTypeParam
4269 = dyn_cast<SubstTemplateTypeParmType>(T)) {
4270 QualType Replacement = SubstTypeParam->getReplacementType();
4271 Qualifiers Qs = Replacement.getQualifiers();
4272 Qs.removeObjCLifetime();
4273 Replacement = SemaRef.Context.getQualifiedType(
4274 Replacement.getUnqualifiedType(), Qs);
4275 T = SemaRef.Context.getSubstTemplateTypeParmType(
4276 SubstTypeParam->getReplacedParameter(), Replacement);
4277 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
4278 // 'auto' types behave the same way as template parameters.
4279 QualType Deduced = AutoTy->getDeducedType();
4280 Qualifiers Qs = Deduced.getQualifiers();
4281 Qs.removeObjCLifetime();
4283 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4284 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4285 AutoTy->isDependentType());
4287 // Otherwise, complain about the addition of a qualifier to an
4288 // already-qualified type.
4289 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4290 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
4291 Quals.removeObjCLifetime();
4296 return SemaRef.BuildQualifiedType(T, Loc, Quals);
4299 template<typename Derived>
4301 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4302 QualType ObjectType,
4303 NamedDecl *UnqualLookup,
4305 if (getDerived().AlreadyTransformed(TL.getType()))
4308 TypeSourceInfo *TSI =
4309 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4311 return TSI->getTypeLoc();
4315 template<typename Derived>
4317 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4318 QualType ObjectType,
4319 NamedDecl *UnqualLookup,
4321 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4324 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4328 template <typename Derived>
4329 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4330 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4332 QualType T = TL.getType();
4333 assert(!getDerived().AlreadyTransformed(T));
4338 if (isa<TemplateSpecializationType>(T)) {
4339 TemplateSpecializationTypeLoc SpecTL =
4340 TL.castAs<TemplateSpecializationTypeLoc>();
4342 TemplateName Template = getDerived().TransformTemplateName(
4343 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4344 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
4345 if (Template.isNull())
4348 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4350 } else if (isa<DependentTemplateSpecializationType>(T)) {
4351 DependentTemplateSpecializationTypeLoc SpecTL =
4352 TL.castAs<DependentTemplateSpecializationTypeLoc>();
4354 TemplateName Template
4355 = getDerived().RebuildTemplateName(SS,
4356 *SpecTL.getTypePtr()->getIdentifier(),
4357 SpecTL.getTemplateNameLoc(),
4358 ObjectType, UnqualLookup,
4359 /*AllowInjectedClassName*/true);
4360 if (Template.isNull())
4363 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4368 // Nothing special needs to be done for these.
4369 Result = getDerived().TransformType(TLB, TL);
4372 if (Result.isNull())
4375 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4378 template <class TyLoc> static inline
4379 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4380 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4381 NewT.setNameLoc(T.getNameLoc());
4385 template<typename Derived>
4386 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4388 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4389 NewT.setBuiltinLoc(T.getBuiltinLoc());
4390 if (T.needsExtraLocalData())
4391 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4395 template<typename Derived>
4396 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4399 return TransformTypeSpecType(TLB, T);
4402 template <typename Derived>
4403 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4404 AdjustedTypeLoc TL) {
4405 // Adjustments applied during transformation are handled elsewhere.
4406 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4409 template<typename Derived>
4410 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4411 DecayedTypeLoc TL) {
4412 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4413 if (OriginalType.isNull())
4416 QualType Result = TL.getType();
4417 if (getDerived().AlwaysRebuild() ||
4418 OriginalType != TL.getOriginalLoc().getType())
4419 Result = SemaRef.Context.getDecayedType(OriginalType);
4420 TLB.push<DecayedTypeLoc>(Result);
4421 // Nothing to set for DecayedTypeLoc.
4425 template<typename Derived>
4426 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4427 PointerTypeLoc TL) {
4428 QualType PointeeType
4429 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4430 if (PointeeType.isNull())
4433 QualType Result = TL.getType();
4434 if (PointeeType->getAs<ObjCObjectType>()) {
4435 // A dependent pointer type 'T *' has is being transformed such
4436 // that an Objective-C class type is being replaced for 'T'. The
4437 // resulting pointer type is an ObjCObjectPointerType, not a
4439 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4441 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4442 NewT.setStarLoc(TL.getStarLoc());
4446 if (getDerived().AlwaysRebuild() ||
4447 PointeeType != TL.getPointeeLoc().getType()) {
4448 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4449 if (Result.isNull())
4453 // Objective-C ARC can add lifetime qualifiers to the type that we're
4455 TLB.TypeWasModifiedSafely(Result->getPointeeType());
4457 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4458 NewT.setSigilLoc(TL.getSigilLoc());
4462 template<typename Derived>
4464 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4465 BlockPointerTypeLoc TL) {
4466 QualType PointeeType
4467 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4468 if (PointeeType.isNull())
4471 QualType Result = TL.getType();
4472 if (getDerived().AlwaysRebuild() ||
4473 PointeeType != TL.getPointeeLoc().getType()) {
4474 Result = getDerived().RebuildBlockPointerType(PointeeType,
4476 if (Result.isNull())
4480 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4481 NewT.setSigilLoc(TL.getSigilLoc());
4485 /// Transforms a reference type. Note that somewhat paradoxically we
4486 /// don't care whether the type itself is an l-value type or an r-value
4487 /// type; we only care if the type was *written* as an l-value type
4488 /// or an r-value type.
4489 template<typename Derived>
4491 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
4492 ReferenceTypeLoc TL) {
4493 const ReferenceType *T = TL.getTypePtr();
4495 // Note that this works with the pointee-as-written.
4496 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4497 if (PointeeType.isNull())
4500 QualType Result = TL.getType();
4501 if (getDerived().AlwaysRebuild() ||
4502 PointeeType != T->getPointeeTypeAsWritten()) {
4503 Result = getDerived().RebuildReferenceType(PointeeType,
4504 T->isSpelledAsLValue(),
4506 if (Result.isNull())
4510 // Objective-C ARC can add lifetime qualifiers to the type that we're
4512 TLB.TypeWasModifiedSafely(
4513 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4515 // r-value references can be rebuilt as l-value references.
4516 ReferenceTypeLoc NewTL;
4517 if (isa<LValueReferenceType>(Result))
4518 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4520 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4521 NewTL.setSigilLoc(TL.getSigilLoc());
4526 template<typename Derived>
4528 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
4529 LValueReferenceTypeLoc TL) {
4530 return TransformReferenceType(TLB, TL);
4533 template<typename Derived>
4535 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
4536 RValueReferenceTypeLoc TL) {
4537 return TransformReferenceType(TLB, TL);
4540 template<typename Derived>
4542 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
4543 MemberPointerTypeLoc TL) {
4544 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4545 if (PointeeType.isNull())
4548 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4549 TypeSourceInfo *NewClsTInfo = nullptr;
4551 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4556 const MemberPointerType *T = TL.getTypePtr();
4557 QualType OldClsType = QualType(T->getClass(), 0);
4558 QualType NewClsType;
4560 NewClsType = NewClsTInfo->getType();
4562 NewClsType = getDerived().TransformType(OldClsType);
4563 if (NewClsType.isNull())
4567 QualType Result = TL.getType();
4568 if (getDerived().AlwaysRebuild() ||
4569 PointeeType != T->getPointeeType() ||
4570 NewClsType != OldClsType) {
4571 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4573 if (Result.isNull())
4577 // If we had to adjust the pointee type when building a member pointer, make
4578 // sure to push TypeLoc info for it.
4579 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4580 if (MPT && PointeeType != MPT->getPointeeType()) {
4581 assert(isa<AdjustedType>(MPT->getPointeeType()));
4582 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4585 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4586 NewTL.setSigilLoc(TL.getSigilLoc());
4587 NewTL.setClassTInfo(NewClsTInfo);
4592 template<typename Derived>
4594 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4595 ConstantArrayTypeLoc TL) {
4596 const ConstantArrayType *T = TL.getTypePtr();
4597 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4598 if (ElementType.isNull())
4601 QualType Result = TL.getType();
4602 if (getDerived().AlwaysRebuild() ||
4603 ElementType != T->getElementType()) {
4604 Result = getDerived().RebuildConstantArrayType(ElementType,
4605 T->getSizeModifier(),
4607 T->getIndexTypeCVRQualifiers(),
4608 TL.getBracketsRange());
4609 if (Result.isNull())
4613 // We might have either a ConstantArrayType or a VariableArrayType now:
4614 // a ConstantArrayType is allowed to have an element type which is a
4615 // VariableArrayType if the type is dependent. Fortunately, all array
4616 // types have the same location layout.
4617 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4618 NewTL.setLBracketLoc(TL.getLBracketLoc());
4619 NewTL.setRBracketLoc(TL.getRBracketLoc());
4621 Expr *Size = TL.getSizeExpr();
4623 EnterExpressionEvaluationContext Unevaluated(
4624 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4625 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4626 Size = SemaRef.ActOnConstantExpression(Size).get();
4628 NewTL.setSizeExpr(Size);
4633 template<typename Derived>
4634 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4635 TypeLocBuilder &TLB,
4636 IncompleteArrayTypeLoc TL) {
4637 const IncompleteArrayType *T = TL.getTypePtr();
4638 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4639 if (ElementType.isNull())
4642 QualType Result = TL.getType();
4643 if (getDerived().AlwaysRebuild() ||
4644 ElementType != T->getElementType()) {
4645 Result = getDerived().RebuildIncompleteArrayType(ElementType,
4646 T->getSizeModifier(),
4647 T->getIndexTypeCVRQualifiers(),
4648 TL.getBracketsRange());
4649 if (Result.isNull())
4653 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4654 NewTL.setLBracketLoc(TL.getLBracketLoc());
4655 NewTL.setRBracketLoc(TL.getRBracketLoc());
4656 NewTL.setSizeExpr(nullptr);
4661 template<typename Derived>
4663 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4664 VariableArrayTypeLoc TL) {
4665 const VariableArrayType *T = TL.getTypePtr();
4666 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4667 if (ElementType.isNull())
4670 ExprResult SizeResult;
4672 EnterExpressionEvaluationContext Context(
4673 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
4674 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4676 if (SizeResult.isInvalid())
4678 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
4679 if (SizeResult.isInvalid())
4682 Expr *Size = SizeResult.get();
4684 QualType Result = TL.getType();
4685 if (getDerived().AlwaysRebuild() ||
4686 ElementType != T->getElementType() ||
4687 Size != T->getSizeExpr()) {
4688 Result = getDerived().RebuildVariableArrayType(ElementType,
4689 T->getSizeModifier(),
4691 T->getIndexTypeCVRQualifiers(),
4692 TL.getBracketsRange());
4693 if (Result.isNull())
4697 // We might have constant size array now, but fortunately it has the same
4699 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4700 NewTL.setLBracketLoc(TL.getLBracketLoc());
4701 NewTL.setRBracketLoc(TL.getRBracketLoc());
4702 NewTL.setSizeExpr(Size);
4707 template<typename Derived>
4709 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4710 DependentSizedArrayTypeLoc TL) {
4711 const DependentSizedArrayType *T = TL.getTypePtr();
4712 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4713 if (ElementType.isNull())
4716 // Array bounds are constant expressions.
4717 EnterExpressionEvaluationContext Unevaluated(
4718 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4720 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4721 Expr *origSize = TL.getSizeExpr();
4722 if (!origSize) origSize = T->getSizeExpr();
4724 ExprResult sizeResult
4725 = getDerived().TransformExpr(origSize);
4726 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4727 if (sizeResult.isInvalid())
4730 Expr *size = sizeResult.get();
4732 QualType Result = TL.getType();
4733 if (getDerived().AlwaysRebuild() ||
4734 ElementType != T->getElementType() ||
4736 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4737 T->getSizeModifier(),
4739 T->getIndexTypeCVRQualifiers(),
4740 TL.getBracketsRange());
4741 if (Result.isNull())
4745 // We might have any sort of array type now, but fortunately they
4746 // all have the same location layout.
4747 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4748 NewTL.setLBracketLoc(TL.getLBracketLoc());
4749 NewTL.setRBracketLoc(TL.getRBracketLoc());
4750 NewTL.setSizeExpr(size);
4755 template<typename Derived>
4756 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4757 TypeLocBuilder &TLB,
4758 DependentSizedExtVectorTypeLoc TL) {
4759 const DependentSizedExtVectorType *T = TL.getTypePtr();
4761 // FIXME: ext vector locs should be nested
4762 QualType ElementType = getDerived().TransformType(T->getElementType());
4763 if (ElementType.isNull())
4766 // Vector sizes are constant expressions.
4767 EnterExpressionEvaluationContext Unevaluated(
4768 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4770 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4771 Size = SemaRef.ActOnConstantExpression(Size);
4772 if (Size.isInvalid())
4775 QualType Result = TL.getType();
4776 if (getDerived().AlwaysRebuild() ||
4777 ElementType != T->getElementType() ||
4778 Size.get() != T->getSizeExpr()) {
4779 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4781 T->getAttributeLoc());
4782 if (Result.isNull())
4786 // Result might be dependent or not.
4787 if (isa<DependentSizedExtVectorType>(Result)) {
4788 DependentSizedExtVectorTypeLoc NewTL
4789 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4790 NewTL.setNameLoc(TL.getNameLoc());
4792 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4793 NewTL.setNameLoc(TL.getNameLoc());
4799 template <typename Derived>
4800 QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4801 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4802 const DependentAddressSpaceType *T = TL.getTypePtr();
4804 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4806 if (pointeeType.isNull())
4809 // Address spaces are constant expressions.
4810 EnterExpressionEvaluationContext Unevaluated(
4811 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4813 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4814 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4815 if (AddrSpace.isInvalid())
4818 QualType Result = TL.getType();
4819 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4820 AddrSpace.get() != T->getAddrSpaceExpr()) {
4821 Result = getDerived().RebuildDependentAddressSpaceType(
4822 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4823 if (Result.isNull())
4827 // Result might be dependent or not.
4828 if (isa<DependentAddressSpaceType>(Result)) {
4829 DependentAddressSpaceTypeLoc NewTL =
4830 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4832 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4833 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4834 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4837 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4838 Result, getDerived().getBaseLocation());
4839 TransformType(TLB, DI->getTypeLoc());
4845 template <typename Derived>
4846 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4848 const VectorType *T = TL.getTypePtr();
4849 QualType ElementType = getDerived().TransformType(T->getElementType());
4850 if (ElementType.isNull())
4853 QualType Result = TL.getType();
4854 if (getDerived().AlwaysRebuild() ||
4855 ElementType != T->getElementType()) {
4856 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4857 T->getVectorKind());
4858 if (Result.isNull())
4862 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4863 NewTL.setNameLoc(TL.getNameLoc());
4868 template<typename Derived>
4869 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4870 ExtVectorTypeLoc TL) {
4871 const VectorType *T = TL.getTypePtr();
4872 QualType ElementType = getDerived().TransformType(T->getElementType());
4873 if (ElementType.isNull())
4876 QualType Result = TL.getType();
4877 if (getDerived().AlwaysRebuild() ||
4878 ElementType != T->getElementType()) {
4879 Result = getDerived().RebuildExtVectorType(ElementType,
4880 T->getNumElements(),
4881 /*FIXME*/ SourceLocation());
4882 if (Result.isNull())
4886 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4887 NewTL.setNameLoc(TL.getNameLoc());
4892 template <typename Derived>
4893 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4894 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4895 bool ExpectParameterPack) {
4896 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4897 TypeSourceInfo *NewDI = nullptr;
4899 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4900 // If we're substituting into a pack expansion type and we know the
4901 // length we want to expand to, just substitute for the pattern.
4902 TypeLoc OldTL = OldDI->getTypeLoc();
4903 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4906 TypeLoc NewTL = OldDI->getTypeLoc();
4907 TLB.reserve(NewTL.getFullDataSize());
4909 QualType Result = getDerived().TransformType(TLB,
4910 OldExpansionTL.getPatternLoc());
4911 if (Result.isNull())
4914 Result = RebuildPackExpansionType(Result,
4915 OldExpansionTL.getPatternLoc().getSourceRange(),
4916 OldExpansionTL.getEllipsisLoc(),
4918 if (Result.isNull())
4921 PackExpansionTypeLoc NewExpansionTL
4922 = TLB.push<PackExpansionTypeLoc>(Result);
4923 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4924 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4926 NewDI = getDerived().TransformType(OldDI);
4930 if (NewDI == OldDI && indexAdjustment == 0)
4933 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4934 OldParm->getDeclContext(),
4935 OldParm->getInnerLocStart(),
4936 OldParm->getLocation(),
4937 OldParm->getIdentifier(),
4940 OldParm->getStorageClass(),
4941 /* DefArg */ nullptr);
4942 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4943 OldParm->getFunctionScopeIndex() + indexAdjustment);
4947 template <typename Derived>
4948 bool TreeTransform<Derived>::TransformFunctionTypeParams(
4949 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4950 const QualType *ParamTypes,
4951 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4952 SmallVectorImpl<QualType> &OutParamTypes,
4953 SmallVectorImpl<ParmVarDecl *> *PVars,
4954 Sema::ExtParameterInfoBuilder &PInfos) {
4955 int indexAdjustment = 0;
4957 unsigned NumParams = Params.size();
4958 for (unsigned i = 0; i != NumParams; ++i) {
4959 if (ParmVarDecl *OldParm = Params[i]) {
4960 assert(OldParm->getFunctionScopeIndex() == i);
4962 Optional<unsigned> NumExpansions;
4963 ParmVarDecl *NewParm = nullptr;
4964 if (OldParm->isParameterPack()) {
4965 // We have a function parameter pack that may need to be expanded.
4966 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4968 // Find the parameter packs that could be expanded.
4969 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4970 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4971 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4972 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4973 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4975 // Determine whether we should expand the parameter packs.
4976 bool ShouldExpand = false;
4977 bool RetainExpansion = false;
4978 Optional<unsigned> OrigNumExpansions =
4979 ExpansionTL.getTypePtr()->getNumExpansions();
4980 NumExpansions = OrigNumExpansions;
4981 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4982 Pattern.getSourceRange(),
4991 // Expand the function parameter pack into multiple, separate
4993 getDerived().ExpandingFunctionParameterPack(OldParm);
4994 for (unsigned I = 0; I != *NumExpansions; ++I) {
4995 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4996 ParmVarDecl *NewParm
4997 = getDerived().TransformFunctionTypeParam(OldParm,
5000 /*ExpectParameterPack=*/false);
5005 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5006 OutParamTypes.push_back(NewParm->getType());
5008 PVars->push_back(NewParm);
5011 // If we're supposed to retain a pack expansion, do so by temporarily
5012 // forgetting the partially-substituted parameter pack.
5013 if (RetainExpansion) {
5014 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5015 ParmVarDecl *NewParm
5016 = getDerived().TransformFunctionTypeParam(OldParm,
5019 /*ExpectParameterPack=*/false);
5024 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5025 OutParamTypes.push_back(NewParm->getType());
5027 PVars->push_back(NewParm);
5030 // The next parameter should have the same adjustment as the
5031 // last thing we pushed, but we post-incremented indexAdjustment
5032 // on every push. Also, if we push nothing, the adjustment should
5036 // We're done with the pack expansion.
5040 // We'll substitute the parameter now without expanding the pack
5042 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5043 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
5046 /*ExpectParameterPack=*/true);
5048 NewParm = getDerived().TransformFunctionTypeParam(
5049 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
5056 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5057 OutParamTypes.push_back(NewParm->getType());
5059 PVars->push_back(NewParm);
5063 // Deal with the possibility that we don't have a parameter
5064 // declaration for this parameter.
5065 QualType OldType = ParamTypes[i];
5066 bool IsPackExpansion = false;
5067 Optional<unsigned> NumExpansions;
5069 if (const PackExpansionType *Expansion
5070 = dyn_cast<PackExpansionType>(OldType)) {
5071 // We have a function parameter pack that may need to be expanded.
5072 QualType Pattern = Expansion->getPattern();
5073 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5074 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5076 // Determine whether we should expand the parameter packs.
5077 bool ShouldExpand = false;
5078 bool RetainExpansion = false;
5079 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
5088 // Expand the function parameter pack into multiple, separate
5090 for (unsigned I = 0; I != *NumExpansions; ++I) {
5091 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5092 QualType NewType = getDerived().TransformType(Pattern);
5093 if (NewType.isNull())
5096 if (NewType->containsUnexpandedParameterPack()) {
5098 getSema().getASTContext().getPackExpansionType(NewType, None);
5100 if (NewType.isNull())
5105 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5106 OutParamTypes.push_back(NewType);
5108 PVars->push_back(nullptr);
5111 // We're done with the pack expansion.
5115 // If we're supposed to retain a pack expansion, do so by temporarily
5116 // forgetting the partially-substituted parameter pack.
5117 if (RetainExpansion) {
5118 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5119 QualType NewType = getDerived().TransformType(Pattern);
5120 if (NewType.isNull())
5124 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5125 OutParamTypes.push_back(NewType);
5127 PVars->push_back(nullptr);
5130 // We'll substitute the parameter now without expanding the pack
5132 OldType = Expansion->getPattern();
5133 IsPackExpansion = true;
5134 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5135 NewType = getDerived().TransformType(OldType);
5137 NewType = getDerived().TransformType(OldType);
5140 if (NewType.isNull())
5143 if (IsPackExpansion)
5144 NewType = getSema().Context.getPackExpansionType(NewType,
5148 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5149 OutParamTypes.push_back(NewType);
5151 PVars->push_back(nullptr);
5156 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5157 if (ParmVarDecl *parm = (*PVars)[i])
5158 assert(parm->getFunctionScopeIndex() == i);
5165 template<typename Derived>
5167 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
5168 FunctionProtoTypeLoc TL) {
5169 SmallVector<QualType, 4> ExceptionStorage;
5170 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
5171 return getDerived().TransformFunctionProtoType(
5172 TLB, TL, nullptr, 0,
5173 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5174 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5175 ExceptionStorage, Changed);
5179 template<typename Derived> template<typename Fn>
5180 QualType TreeTransform<Derived>::TransformFunctionProtoType(
5181 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5182 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
5184 // Transform the parameters and return type.
5186 // We are required to instantiate the params and return type in source order.
5187 // When the function has a trailing return type, we instantiate the
5188 // parameters before the return type, since the return type can then refer
5189 // to the parameters themselves (via decltype, sizeof, etc.).
5191 SmallVector<QualType, 4> ParamTypes;
5192 SmallVector<ParmVarDecl*, 4> ParamDecls;
5193 Sema::ExtParameterInfoBuilder ExtParamInfos;
5194 const FunctionProtoType *T = TL.getTypePtr();
5196 QualType ResultType;
5198 if (T->hasTrailingReturn()) {
5199 if (getDerived().TransformFunctionTypeParams(
5200 TL.getBeginLoc(), TL.getParams(),
5201 TL.getTypePtr()->param_type_begin(),
5202 T->getExtParameterInfosOrNull(),
5203 ParamTypes, &ParamDecls, ExtParamInfos))
5207 // C++11 [expr.prim.general]p3:
5208 // If a declaration declares a member function or member function
5209 // template of a class X, the expression this is a prvalue of type
5210 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
5211 // and the end of the function-definition, member-declarator, or
5213 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
5215 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5216 if (ResultType.isNull())
5221 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5222 if (ResultType.isNull())
5225 if (getDerived().TransformFunctionTypeParams(
5226 TL.getBeginLoc(), TL.getParams(),
5227 TL.getTypePtr()->param_type_begin(),
5228 T->getExtParameterInfosOrNull(),
5229 ParamTypes, &ParamDecls, ExtParamInfos))
5233 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5235 bool EPIChanged = false;
5236 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5239 // Handle extended parameter information.
5240 if (auto NewExtParamInfos =
5241 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5242 if (!EPI.ExtParameterInfos ||
5243 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5244 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5247 EPI.ExtParameterInfos = NewExtParamInfos;
5248 } else if (EPI.ExtParameterInfos) {
5250 EPI.ExtParameterInfos = nullptr;
5253 QualType Result = TL.getType();
5254 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
5255 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
5256 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
5257 if (Result.isNull())
5261 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
5262 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5263 NewTL.setLParenLoc(TL.getLParenLoc());
5264 NewTL.setRParenLoc(TL.getRParenLoc());
5265 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
5266 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5267 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5268 NewTL.setParam(i, ParamDecls[i]);
5273 template<typename Derived>
5274 bool TreeTransform<Derived>::TransformExceptionSpec(
5275 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5276 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5277 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5279 // Instantiate a dynamic noexcept expression, if any.
5280 if (ESI.Type == EST_ComputedNoexcept) {
5281 EnterExpressionEvaluationContext Unevaluated(
5282 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
5283 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5284 if (NoexceptExpr.isInvalid())
5287 // FIXME: This is bogus, a noexcept expression is not a condition.
5288 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
5289 if (NoexceptExpr.isInvalid())
5292 if (!NoexceptExpr.get()->isValueDependent()) {
5293 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5294 NoexceptExpr.get(), nullptr,
5295 diag::err_noexcept_needs_constant_expression,
5296 /*AllowFold*/false);
5297 if (NoexceptExpr.isInvalid())
5301 if (ESI.NoexceptExpr != NoexceptExpr.get())
5303 ESI.NoexceptExpr = NoexceptExpr.get();
5306 if (ESI.Type != EST_Dynamic)
5309 // Instantiate a dynamic exception specification's type.
5310 for (QualType T : ESI.Exceptions) {
5311 if (const PackExpansionType *PackExpansion =
5312 T->getAs<PackExpansionType>()) {
5315 // We have a pack expansion. Instantiate it.
5316 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5317 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5319 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5321 // Determine whether the set of unexpanded parameter packs can and
5324 bool Expand = false;
5325 bool RetainExpansion = false;
5326 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5327 // FIXME: Track the location of the ellipsis (and track source location
5328 // information for the types in the exception specification in general).
5329 if (getDerived().TryExpandParameterPacks(
5330 Loc, SourceRange(), Unexpanded, Expand,
5331 RetainExpansion, NumExpansions))
5335 // We can't expand this pack expansion into separate arguments yet;
5336 // just substitute into the pattern and create a new pack expansion
5338 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5339 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5343 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5344 Exceptions.push_back(U);
5348 // Substitute into the pack expansion pattern for each slice of the
5350 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5351 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5353 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5354 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5357 Exceptions.push_back(U);
5360 QualType U = getDerived().TransformType(T);
5361 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5366 Exceptions.push_back(U);
5370 ESI.Exceptions = Exceptions;
5371 if (ESI.Exceptions.empty())
5372 ESI.Type = EST_DynamicNone;
5376 template<typename Derived>
5377 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
5378 TypeLocBuilder &TLB,
5379 FunctionNoProtoTypeLoc TL) {
5380 const FunctionNoProtoType *T = TL.getTypePtr();
5381 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5382 if (ResultType.isNull())
5385 QualType Result = TL.getType();
5386 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5387 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5389 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5390 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5391 NewTL.setLParenLoc(TL.getLParenLoc());
5392 NewTL.setRParenLoc(TL.getRParenLoc());
5393 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5398 template<typename Derived> QualType
5399 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5400 UnresolvedUsingTypeLoc TL) {
5401 const UnresolvedUsingType *T = TL.getTypePtr();
5402 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5406 QualType Result = TL.getType();
5407 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5408 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
5409 if (Result.isNull())
5413 // We might get an arbitrary type spec type back. We should at
5414 // least always get a type spec type, though.
5415 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5416 NewTL.setNameLoc(TL.getNameLoc());
5421 template<typename Derived>
5422 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5423 TypedefTypeLoc TL) {
5424 const TypedefType *T = TL.getTypePtr();
5425 TypedefNameDecl *Typedef
5426 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5431 QualType Result = TL.getType();
5432 if (getDerived().AlwaysRebuild() ||
5433 Typedef != T->getDecl()) {
5434 Result = getDerived().RebuildTypedefType(Typedef);
5435 if (Result.isNull())
5439 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5440 NewTL.setNameLoc(TL.getNameLoc());
5445 template<typename Derived>
5446 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5447 TypeOfExprTypeLoc TL) {
5448 // typeof expressions are not potentially evaluated contexts
5449 EnterExpressionEvaluationContext Unevaluated(
5450 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5451 Sema::ReuseLambdaContextDecl);
5453 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5457 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5461 QualType Result = TL.getType();
5462 if (getDerived().AlwaysRebuild() ||
5463 E.get() != TL.getUnderlyingExpr()) {
5464 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5465 if (Result.isNull())
5470 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5471 NewTL.setTypeofLoc(TL.getTypeofLoc());
5472 NewTL.setLParenLoc(TL.getLParenLoc());
5473 NewTL.setRParenLoc(TL.getRParenLoc());
5478 template<typename Derived>
5479 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5481 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5482 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5486 QualType Result = TL.getType();
5487 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5488 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5489 if (Result.isNull())
5493 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5494 NewTL.setTypeofLoc(TL.getTypeofLoc());
5495 NewTL.setLParenLoc(TL.getLParenLoc());
5496 NewTL.setRParenLoc(TL.getRParenLoc());
5497 NewTL.setUnderlyingTInfo(New_Under_TI);
5502 template<typename Derived>
5503 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5504 DecltypeTypeLoc TL) {
5505 const DecltypeType *T = TL.getTypePtr();
5507 // decltype expressions are not potentially evaluated contexts
5508 EnterExpressionEvaluationContext Unevaluated(
5509 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
5510 /*IsDecltype=*/true);
5512 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5516 E = getSema().ActOnDecltypeExpression(E.get());
5520 QualType Result = TL.getType();
5521 if (getDerived().AlwaysRebuild() ||
5522 E.get() != T->getUnderlyingExpr()) {
5523 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5524 if (Result.isNull())
5529 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5530 NewTL.setNameLoc(TL.getNameLoc());
5535 template<typename Derived>
5536 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5537 TypeLocBuilder &TLB,
5538 UnaryTransformTypeLoc TL) {
5539 QualType Result = TL.getType();
5540 if (Result->isDependentType()) {
5541 const UnaryTransformType *T = TL.getTypePtr();
5543 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5544 Result = getDerived().RebuildUnaryTransformType(NewBase,
5547 if (Result.isNull())
5551 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5552 NewTL.setKWLoc(TL.getKWLoc());
5553 NewTL.setParensRange(TL.getParensRange());
5554 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5558 template<typename Derived>
5559 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5561 const AutoType *T = TL.getTypePtr();
5562 QualType OldDeduced = T->getDeducedType();
5563 QualType NewDeduced;
5564 if (!OldDeduced.isNull()) {
5565 NewDeduced = getDerived().TransformType(OldDeduced);
5566 if (NewDeduced.isNull())
5570 QualType Result = TL.getType();
5571 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5572 T->isDependentType()) {
5573 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5574 if (Result.isNull())
5578 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5579 NewTL.setNameLoc(TL.getNameLoc());
5584 template<typename Derived>
5585 QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5586 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5587 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5590 TemplateName TemplateName = getDerived().TransformTemplateName(
5591 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5592 if (TemplateName.isNull())
5595 QualType OldDeduced = T->getDeducedType();
5596 QualType NewDeduced;
5597 if (!OldDeduced.isNull()) {
5598 NewDeduced = getDerived().TransformType(OldDeduced);
5599 if (NewDeduced.isNull())
5603 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5604 TemplateName, NewDeduced);
5605 if (Result.isNull())
5608 DeducedTemplateSpecializationTypeLoc NewTL =
5609 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5610 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5615 template<typename Derived>
5616 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5618 const RecordType *T = TL.getTypePtr();
5620 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5625 QualType Result = TL.getType();
5626 if (getDerived().AlwaysRebuild() ||
5627 Record != T->getDecl()) {
5628 Result = getDerived().RebuildRecordType(Record);
5629 if (Result.isNull())
5633 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5634 NewTL.setNameLoc(TL.getNameLoc());
5639 template<typename Derived>
5640 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5642 const EnumType *T = TL.getTypePtr();
5644 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5649 QualType Result = TL.getType();
5650 if (getDerived().AlwaysRebuild() ||
5651 Enum != T->getDecl()) {
5652 Result = getDerived().RebuildEnumType(Enum);
5653 if (Result.isNull())
5657 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5658 NewTL.setNameLoc(TL.getNameLoc());
5663 template<typename Derived>
5664 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5665 TypeLocBuilder &TLB,
5666 InjectedClassNameTypeLoc TL) {
5667 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5668 TL.getTypePtr()->getDecl());
5669 if (!D) return QualType();
5671 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5672 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5676 template<typename Derived>
5677 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5678 TypeLocBuilder &TLB,
5679 TemplateTypeParmTypeLoc TL) {
5680 return TransformTypeSpecType(TLB, TL);
5683 template<typename Derived>
5684 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5685 TypeLocBuilder &TLB,
5686 SubstTemplateTypeParmTypeLoc TL) {
5687 const SubstTemplateTypeParmType *T = TL.getTypePtr();
5689 // Substitute into the replacement type, which itself might involve something
5690 // that needs to be transformed. This only tends to occur with default
5691 // template arguments of template template parameters.
5692 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5693 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5694 if (Replacement.isNull())
5697 // Always canonicalize the replacement type.
5698 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5700 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5703 // Propagate type-source information.
5704 SubstTemplateTypeParmTypeLoc NewTL
5705 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5706 NewTL.setNameLoc(TL.getNameLoc());
5711 template<typename Derived>
5712 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5713 TypeLocBuilder &TLB,
5714 SubstTemplateTypeParmPackTypeLoc TL) {
5715 return TransformTypeSpecType(TLB, TL);
5718 template<typename Derived>
5719 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5720 TypeLocBuilder &TLB,
5721 TemplateSpecializationTypeLoc TL) {
5722 const TemplateSpecializationType *T = TL.getTypePtr();
5724 // The nested-name-specifier never matters in a TemplateSpecializationType,
5725 // because we can't have a dependent nested-name-specifier anyway.
5727 TemplateName Template
5728 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5729 TL.getTemplateNameLoc());
5730 if (Template.isNull())
5733 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5736 template<typename Derived>
5737 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5739 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5740 if (ValueType.isNull())
5743 QualType Result = TL.getType();
5744 if (getDerived().AlwaysRebuild() ||
5745 ValueType != TL.getValueLoc().getType()) {
5746 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5747 if (Result.isNull())
5751 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5752 NewTL.setKWLoc(TL.getKWLoc());
5753 NewTL.setLParenLoc(TL.getLParenLoc());
5754 NewTL.setRParenLoc(TL.getRParenLoc());
5759 template <typename Derived>
5760 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5762 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5763 if (ValueType.isNull())
5766 QualType Result = TL.getType();
5767 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5768 const PipeType *PT = Result->getAs<PipeType>();
5769 bool isReadPipe = PT->isReadOnly();
5770 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
5771 if (Result.isNull())
5775 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5776 NewTL.setKWLoc(TL.getKWLoc());
5781 /// \brief Simple iterator that traverses the template arguments in a
5782 /// container that provides a \c getArgLoc() member function.
5784 /// This iterator is intended to be used with the iterator form of
5785 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5786 template<typename ArgLocContainer>
5787 class TemplateArgumentLocContainerIterator {
5788 ArgLocContainer *Container;
5792 typedef TemplateArgumentLoc value_type;
5793 typedef TemplateArgumentLoc reference;
5794 typedef int difference_type;
5795 typedef std::input_iterator_tag iterator_category;
5798 TemplateArgumentLoc Arg;
5801 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5803 const TemplateArgumentLoc *operator->() const {
5809 TemplateArgumentLocContainerIterator() {}
5811 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5813 : Container(&Container), Index(Index) { }
5815 TemplateArgumentLocContainerIterator &operator++() {
5820 TemplateArgumentLocContainerIterator operator++(int) {
5821 TemplateArgumentLocContainerIterator Old(*this);
5826 TemplateArgumentLoc operator*() const {
5827 return Container->getArgLoc(Index);
5830 pointer operator->() const {
5831 return pointer(Container->getArgLoc(Index));
5834 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
5835 const TemplateArgumentLocContainerIterator &Y) {
5836 return X.Container == Y.Container && X.Index == Y.Index;
5839 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
5840 const TemplateArgumentLocContainerIterator &Y) {
5846 template <typename Derived>
5847 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5848 TypeLocBuilder &TLB,
5849 TemplateSpecializationTypeLoc TL,
5850 TemplateName Template) {
5851 TemplateArgumentListInfo NewTemplateArgs;
5852 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5853 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5854 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5856 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5857 ArgIterator(TL, TL.getNumArgs()),
5861 // FIXME: maybe don't rebuild if all the template arguments are the same.
5864 getDerived().RebuildTemplateSpecializationType(Template,
5865 TL.getTemplateNameLoc(),
5868 if (!Result.isNull()) {
5869 // Specializations of template template parameters are represented as
5870 // TemplateSpecializationTypes, and substitution of type alias templates
5871 // within a dependent context can transform them into
5872 // DependentTemplateSpecializationTypes.
5873 if (isa<DependentTemplateSpecializationType>(Result)) {
5874 DependentTemplateSpecializationTypeLoc NewTL
5875 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5876 NewTL.setElaboratedKeywordLoc(SourceLocation());
5877 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5878 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5879 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5880 NewTL.setLAngleLoc(TL.getLAngleLoc());
5881 NewTL.setRAngleLoc(TL.getRAngleLoc());
5882 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5883 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5887 TemplateSpecializationTypeLoc NewTL
5888 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5889 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5890 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5891 NewTL.setLAngleLoc(TL.getLAngleLoc());
5892 NewTL.setRAngleLoc(TL.getRAngleLoc());
5893 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5894 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5900 template <typename Derived>
5901 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5902 TypeLocBuilder &TLB,
5903 DependentTemplateSpecializationTypeLoc TL,
5904 TemplateName Template,
5906 TemplateArgumentListInfo NewTemplateArgs;
5907 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5908 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5909 typedef TemplateArgumentLocContainerIterator<
5910 DependentTemplateSpecializationTypeLoc> ArgIterator;
5911 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5912 ArgIterator(TL, TL.getNumArgs()),
5916 // FIXME: maybe don't rebuild if all the template arguments are the same.
5918 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5920 = getSema().Context.getDependentTemplateSpecializationType(
5921 TL.getTypePtr()->getKeyword(),
5922 DTN->getQualifier(),
5923 DTN->getIdentifier(),
5926 DependentTemplateSpecializationTypeLoc NewTL
5927 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5928 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5929 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5930 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5931 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5932 NewTL.setLAngleLoc(TL.getLAngleLoc());
5933 NewTL.setRAngleLoc(TL.getRAngleLoc());
5934 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5935 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5940 = getDerived().RebuildTemplateSpecializationType(Template,
5941 TL.getTemplateNameLoc(),
5944 if (!Result.isNull()) {
5945 /// FIXME: Wrap this in an elaborated-type-specifier?
5946 TemplateSpecializationTypeLoc NewTL
5947 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5948 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5949 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5950 NewTL.setLAngleLoc(TL.getLAngleLoc());
5951 NewTL.setRAngleLoc(TL.getRAngleLoc());
5952 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5953 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5959 template<typename Derived>
5961 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
5962 ElaboratedTypeLoc TL) {
5963 const ElaboratedType *T = TL.getTypePtr();
5965 NestedNameSpecifierLoc QualifierLoc;
5966 // NOTE: the qualifier in an ElaboratedType is optional.
5967 if (TL.getQualifierLoc()) {
5969 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5974 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5975 if (NamedT.isNull())
5978 // C++0x [dcl.type.elab]p2:
5979 // If the identifier resolves to a typedef-name or the simple-template-id
5980 // resolves to an alias template specialization, the
5981 // elaborated-type-specifier is ill-formed.
5982 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5983 if (const TemplateSpecializationType *TST =
5984 NamedT->getAs<TemplateSpecializationType>()) {
5985 TemplateName Template = TST->getTemplateName();
5986 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5987 Template.getAsTemplateDecl())) {
5988 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5989 diag::err_tag_reference_non_tag)
5990 << TAT << Sema::NTK_TypeAliasTemplate
5991 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
5992 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5997 QualType Result = TL.getType();
5998 if (getDerived().AlwaysRebuild() ||
5999 QualifierLoc != TL.getQualifierLoc() ||
6000 NamedT != T->getNamedType()) {
6001 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
6003 QualifierLoc, NamedT);
6004 if (Result.isNull())
6008 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6009 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6010 NewTL.setQualifierLoc(QualifierLoc);
6014 template<typename Derived>
6015 QualType TreeTransform<Derived>::TransformAttributedType(
6016 TypeLocBuilder &TLB,
6017 AttributedTypeLoc TL) {
6018 const AttributedType *oldType = TL.getTypePtr();
6019 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6020 if (modifiedType.isNull())
6023 QualType result = TL.getType();
6025 // FIXME: dependent operand expressions?
6026 if (getDerived().AlwaysRebuild() ||
6027 modifiedType != oldType->getModifiedType()) {
6028 // TODO: this is really lame; we should really be rebuilding the
6029 // equivalent type from first principles.
6030 QualType equivalentType
6031 = getDerived().TransformType(oldType->getEquivalentType());
6032 if (equivalentType.isNull())
6035 // Check whether we can add nullability; it is only represented as
6036 // type sugar, and therefore cannot be diagnosed in any other way.
6037 if (auto nullability = oldType->getImmediateNullability()) {
6038 if (!modifiedType->canHaveNullability()) {
6039 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
6040 << DiagNullabilityKind(*nullability, false) << modifiedType;
6045 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
6050 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
6051 newTL.setAttrNameLoc(TL.getAttrNameLoc());
6052 if (TL.hasAttrOperand())
6053 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6054 if (TL.hasAttrExprOperand())
6055 newTL.setAttrExprOperand(TL.getAttrExprOperand());
6056 else if (TL.hasAttrEnumOperand())
6057 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
6062 template<typename Derived>
6064 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6066 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6070 QualType Result = TL.getType();
6071 if (getDerived().AlwaysRebuild() ||
6072 Inner != TL.getInnerLoc().getType()) {
6073 Result = getDerived().RebuildParenType(Inner);
6074 if (Result.isNull())
6078 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6079 NewTL.setLParenLoc(TL.getLParenLoc());
6080 NewTL.setRParenLoc(TL.getRParenLoc());
6084 template<typename Derived>
6085 QualType TreeTransform<Derived>::TransformDependentNameType(
6086 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6087 return TransformDependentNameType(TLB, TL, false);
6090 template<typename Derived>
6091 QualType TreeTransform<Derived>::TransformDependentNameType(
6092 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
6093 const DependentNameType *T = TL.getTypePtr();
6095 NestedNameSpecifierLoc QualifierLoc
6096 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6101 = getDerived().RebuildDependentNameType(T->getKeyword(),
6102 TL.getElaboratedKeywordLoc(),
6107 if (Result.isNull())
6110 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6111 QualType NamedT = ElabT->getNamedType();
6112 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6114 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6115 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6116 NewTL.setQualifierLoc(QualifierLoc);
6118 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
6119 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6120 NewTL.setQualifierLoc(QualifierLoc);
6121 NewTL.setNameLoc(TL.getNameLoc());
6126 template<typename Derived>
6127 QualType TreeTransform<Derived>::
6128 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6129 DependentTemplateSpecializationTypeLoc TL) {
6130 NestedNameSpecifierLoc QualifierLoc;
6131 if (TL.getQualifierLoc()) {
6133 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6139 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
6142 template<typename Derived>
6143 QualType TreeTransform<Derived>::
6144 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6145 DependentTemplateSpecializationTypeLoc TL,
6146 NestedNameSpecifierLoc QualifierLoc) {
6147 const DependentTemplateSpecializationType *T = TL.getTypePtr();
6149 TemplateArgumentListInfo NewTemplateArgs;
6150 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6151 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6153 typedef TemplateArgumentLocContainerIterator<
6154 DependentTemplateSpecializationTypeLoc> ArgIterator;
6155 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6156 ArgIterator(TL, TL.getNumArgs()),
6160 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6161 T->getKeyword(), QualifierLoc, T->getIdentifier(),
6162 TL.getTemplateNameLoc(), NewTemplateArgs,
6163 /*AllowInjectedClassName*/ false);
6164 if (Result.isNull())
6167 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6168 QualType NamedT = ElabT->getNamedType();
6170 // Copy information relevant to the template specialization.
6171 TemplateSpecializationTypeLoc NamedTL
6172 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
6173 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6174 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6175 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6176 NamedTL.setRAngleLoc(TL.getRAngleLoc());
6177 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6178 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6180 // Copy information relevant to the elaborated type.
6181 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6182 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6183 NewTL.setQualifierLoc(QualifierLoc);
6184 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6185 DependentTemplateSpecializationTypeLoc SpecTL
6186 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
6187 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6188 SpecTL.setQualifierLoc(QualifierLoc);
6189 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6190 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6191 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6192 SpecTL.setRAngleLoc(TL.getRAngleLoc());
6193 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6194 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6196 TemplateSpecializationTypeLoc SpecTL
6197 = TLB.push<TemplateSpecializationTypeLoc>(Result);
6198 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6199 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6200 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6201 SpecTL.setRAngleLoc(TL.getRAngleLoc());
6202 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6203 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6208 template<typename Derived>
6209 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6210 PackExpansionTypeLoc TL) {
6212 = getDerived().TransformType(TLB, TL.getPatternLoc());
6213 if (Pattern.isNull())
6216 QualType Result = TL.getType();
6217 if (getDerived().AlwaysRebuild() ||
6218 Pattern != TL.getPatternLoc().getType()) {
6219 Result = getDerived().RebuildPackExpansionType(Pattern,
6220 TL.getPatternLoc().getSourceRange(),
6221 TL.getEllipsisLoc(),
6222 TL.getTypePtr()->getNumExpansions());
6223 if (Result.isNull())
6227 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6228 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6232 template<typename Derived>
6234 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
6235 ObjCInterfaceTypeLoc TL) {
6236 // ObjCInterfaceType is never dependent.
6237 TLB.pushFullCopy(TL);
6238 return TL.getType();
6241 template<typename Derived>
6243 TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6244 ObjCTypeParamTypeLoc TL) {
6245 const ObjCTypeParamType *T = TL.getTypePtr();
6246 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6247 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6251 QualType Result = TL.getType();
6252 if (getDerived().AlwaysRebuild() ||
6253 OTP != T->getDecl()) {
6254 Result = getDerived().RebuildObjCTypeParamType(OTP,
6255 TL.getProtocolLAngleLoc(),
6256 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6257 TL.getNumProtocols()),
6258 TL.getProtocolLocs(),
6259 TL.getProtocolRAngleLoc());
6260 if (Result.isNull())
6264 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6265 if (TL.getNumProtocols()) {
6266 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6267 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6268 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6269 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6274 template<typename Derived>
6276 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
6277 ObjCObjectTypeLoc TL) {
6278 // Transform base type.
6279 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6280 if (BaseType.isNull())
6283 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6285 // Transform type arguments.
6286 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6287 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6288 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6289 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6290 QualType TypeArg = TypeArgInfo->getType();
6291 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6294 // We have a pack expansion. Instantiate it.
6295 const auto *PackExpansion = PackExpansionLoc.getType()
6296 ->castAs<PackExpansionType>();
6297 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6298 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6300 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6302 // Determine whether the set of unexpanded parameter packs can
6303 // and should be expanded.
6304 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6305 bool Expand = false;
6306 bool RetainExpansion = false;
6307 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6308 if (getDerived().TryExpandParameterPacks(
6309 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6310 Unexpanded, Expand, RetainExpansion, NumExpansions))
6314 // We can't expand this pack expansion into separate arguments yet;
6315 // just substitute into the pattern and create a new pack expansion
6317 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6319 TypeLocBuilder TypeArgBuilder;
6320 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6321 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6323 if (NewPatternType.isNull())
6326 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6327 NewPatternType, NumExpansions);
6328 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6329 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6330 NewTypeArgInfos.push_back(
6331 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6335 // Substitute into the pack expansion pattern for each slice of the
6337 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6338 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6340 TypeLocBuilder TypeArgBuilder;
6341 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6343 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6345 if (NewTypeArg.isNull())
6348 NewTypeArgInfos.push_back(
6349 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6355 TypeLocBuilder TypeArgBuilder;
6356 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6357 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6358 if (NewTypeArg.isNull())
6361 // If nothing changed, just keep the old TypeSourceInfo.
6362 if (NewTypeArg == TypeArg) {
6363 NewTypeArgInfos.push_back(TypeArgInfo);
6367 NewTypeArgInfos.push_back(
6368 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6372 QualType Result = TL.getType();
6373 if (getDerived().AlwaysRebuild() || AnyChanged) {
6374 // Rebuild the type.
6375 Result = getDerived().RebuildObjCObjectType(
6378 TL.getTypeArgsLAngleLoc(),
6380 TL.getTypeArgsRAngleLoc(),
6381 TL.getProtocolLAngleLoc(),
6382 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6383 TL.getNumProtocols()),
6384 TL.getProtocolLocs(),
6385 TL.getProtocolRAngleLoc());
6387 if (Result.isNull())
6391 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
6392 NewT.setHasBaseTypeAsWritten(true);
6393 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6394 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6395 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6396 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6397 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6398 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6399 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6400 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6404 template<typename Derived>
6406 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
6407 ObjCObjectPointerTypeLoc TL) {
6408 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6409 if (PointeeType.isNull())
6412 QualType Result = TL.getType();
6413 if (getDerived().AlwaysRebuild() ||
6414 PointeeType != TL.getPointeeLoc().getType()) {
6415 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6417 if (Result.isNull())
6421 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6422 NewT.setStarLoc(TL.getStarLoc());
6426 //===----------------------------------------------------------------------===//
6427 // Statement transformation
6428 //===----------------------------------------------------------------------===//
6429 template<typename Derived>
6431 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
6435 template<typename Derived>
6437 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6438 return getDerived().TransformCompoundStmt(S, false);
6441 template<typename Derived>
6443 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
6445 Sema::CompoundScopeRAII CompoundScope(getSema());
6447 bool SubStmtInvalid = false;
6448 bool SubStmtChanged = false;
6449 SmallVector<Stmt*, 8> Statements;
6450 for (auto *B : S->body()) {
6451 StmtResult Result = getDerived().TransformStmt(B);
6452 if (Result.isInvalid()) {
6453 // Immediately fail if this was a DeclStmt, since it's very
6454 // likely that this will cause problems for future statements.
6455 if (isa<DeclStmt>(B))
6458 // Otherwise, just keep processing substatements and fail later.
6459 SubStmtInvalid = true;
6463 SubStmtChanged = SubStmtChanged || Result.get() != B;
6464 Statements.push_back(Result.getAs<Stmt>());
6470 if (!getDerived().AlwaysRebuild() &&
6474 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6480 template<typename Derived>
6482 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6483 ExprResult LHS, RHS;
6485 EnterExpressionEvaluationContext Unevaluated(
6486 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
6488 // Transform the left-hand case value.
6489 LHS = getDerived().TransformExpr(S->getLHS());
6490 LHS = SemaRef.ActOnConstantExpression(LHS);
6491 if (LHS.isInvalid())
6494 // Transform the right-hand case value (for the GNU case-range extension).
6495 RHS = getDerived().TransformExpr(S->getRHS());
6496 RHS = SemaRef.ActOnConstantExpression(RHS);
6497 if (RHS.isInvalid())
6501 // Build the case statement.
6502 // Case statements are always rebuilt so that they will attached to their
6503 // transformed switch statement.
6504 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6506 S->getEllipsisLoc(),
6509 if (Case.isInvalid())
6512 // Transform the statement following the case
6513 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6514 if (SubStmt.isInvalid())
6517 // Attach the body to the case statement
6518 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6521 template<typename Derived>
6523 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6524 // Transform the statement following the default case
6525 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6526 if (SubStmt.isInvalid())
6529 // Default statements are always rebuilt
6530 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6534 template<typename Derived>
6536 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6537 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6538 if (SubStmt.isInvalid())
6541 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6547 // FIXME: Pass the real colon location in.
6548 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6549 cast<LabelDecl>(LD), SourceLocation(),
6553 template <typename Derived>
6554 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6558 switch (R->getKind()) {
6559 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6561 #define PRAGMA_SPELLING_ATTR(X) \
6563 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6564 #include "clang/Basic/AttrList.inc"
6570 template <typename Derived>
6571 StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6572 bool AttrsChanged = false;
6573 SmallVector<const Attr *, 1> Attrs;
6575 // Visit attributes and keep track if any are transformed.
6576 for (const auto *I : S->getAttrs()) {
6577 const Attr *R = getDerived().TransformAttr(I);
6578 AttrsChanged |= (I != R);
6582 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6583 if (SubStmt.isInvalid())
6586 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6589 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6593 template<typename Derived>
6595 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6596 // Transform the initialization statement
6597 StmtResult Init = getDerived().TransformStmt(S->getInit());
6598 if (Init.isInvalid())
6601 // Transform the condition
6602 Sema::ConditionResult Cond = getDerived().TransformCondition(
6603 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6604 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6605 : Sema::ConditionKind::Boolean);
6606 if (Cond.isInvalid())
6609 // If this is a constexpr if, determine which arm we should instantiate.
6610 llvm::Optional<bool> ConstexprConditionValue;
6611 if (S->isConstexpr())
6612 ConstexprConditionValue = Cond.getKnownValue();
6614 // Transform the "then" branch.
6616 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6617 Then = getDerived().TransformStmt(S->getThen());
6618 if (Then.isInvalid())
6621 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6624 // Transform the "else" branch.
6626 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6627 Else = getDerived().TransformStmt(S->getElse());
6628 if (Else.isInvalid())
6632 if (!getDerived().AlwaysRebuild() &&
6633 Init.get() == S->getInit() &&
6634 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6635 Then.get() == S->getThen() &&
6636 Else.get() == S->getElse())
6639 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6640 Init.get(), Then.get(), S->getElseLoc(),
6644 template<typename Derived>
6646 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6647 // Transform the initialization statement
6648 StmtResult Init = getDerived().TransformStmt(S->getInit());
6649 if (Init.isInvalid())
6652 // Transform the condition.
6653 Sema::ConditionResult Cond = getDerived().TransformCondition(
6654 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6655 Sema::ConditionKind::Switch);
6656 if (Cond.isInvalid())
6659 // Rebuild the switch statement.
6661 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
6662 if (Switch.isInvalid())
6665 // Transform the body of the switch statement.
6666 StmtResult Body = getDerived().TransformStmt(S->getBody());
6667 if (Body.isInvalid())
6670 // Complete the switch statement.
6671 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6675 template<typename Derived>
6677 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6678 // Transform the condition
6679 Sema::ConditionResult Cond = getDerived().TransformCondition(
6680 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6681 Sema::ConditionKind::Boolean);
6682 if (Cond.isInvalid())
6685 // Transform the body
6686 StmtResult Body = getDerived().TransformStmt(S->getBody());
6687 if (Body.isInvalid())
6690 if (!getDerived().AlwaysRebuild() &&
6691 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6692 Body.get() == S->getBody())
6695 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
6698 template<typename Derived>
6700 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6701 // Transform the body
6702 StmtResult Body = getDerived().TransformStmt(S->getBody());
6703 if (Body.isInvalid())
6706 // Transform the condition
6707 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6708 if (Cond.isInvalid())
6711 if (!getDerived().AlwaysRebuild() &&
6712 Cond.get() == S->getCond() &&
6713 Body.get() == S->getBody())
6716 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6717 /*FIXME:*/S->getWhileLoc(), Cond.get(),
6721 template<typename Derived>
6723 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6724 // Transform the initialization statement
6725 StmtResult Init = getDerived().TransformStmt(S->getInit());
6726 if (Init.isInvalid())
6729 // In OpenMP loop region loop control variable must be captured and be
6730 // private. Perform analysis of first part (if any).
6731 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6732 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6734 // Transform the condition
6735 Sema::ConditionResult Cond = getDerived().TransformCondition(
6736 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6737 Sema::ConditionKind::Boolean);
6738 if (Cond.isInvalid())
6741 // Transform the increment
6742 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6743 if (Inc.isInvalid())
6746 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6747 if (S->getInc() && !FullInc.get())
6750 // Transform the body
6751 StmtResult Body = getDerived().TransformStmt(S->getBody());
6752 if (Body.isInvalid())
6755 if (!getDerived().AlwaysRebuild() &&
6756 Init.get() == S->getInit() &&
6757 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6758 Inc.get() == S->getInc() &&
6759 Body.get() == S->getBody())
6762 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6763 Init.get(), Cond, FullInc,
6764 S->getRParenLoc(), Body.get());
6767 template<typename Derived>
6769 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6770 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6775 // Goto statements must always be rebuilt, to resolve the label.
6776 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6777 cast<LabelDecl>(LD));
6780 template<typename Derived>
6782 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6783 ExprResult Target = getDerived().TransformExpr(S->getTarget());
6784 if (Target.isInvalid())
6786 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6788 if (!getDerived().AlwaysRebuild() &&
6789 Target.get() == S->getTarget())
6792 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6796 template<typename Derived>
6798 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6802 template<typename Derived>
6804 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6808 template<typename Derived>
6810 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6811 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6812 /*NotCopyInit*/false);
6813 if (Result.isInvalid())
6816 // FIXME: We always rebuild the return statement because there is no way
6817 // to tell whether the return type of the function has changed.
6818 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6821 template<typename Derived>
6823 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6824 bool DeclChanged = false;
6825 SmallVector<Decl *, 4> Decls;
6826 for (auto *D : S->decls()) {
6827 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6831 if (Transformed != D)
6834 Decls.push_back(Transformed);
6837 if (!getDerived().AlwaysRebuild() && !DeclChanged)
6840 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6843 template<typename Derived>
6845 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6847 SmallVector<Expr*, 8> Constraints;
6848 SmallVector<Expr*, 8> Exprs;
6849 SmallVector<IdentifierInfo *, 4> Names;
6851 ExprResult AsmString;
6852 SmallVector<Expr*, 8> Clobbers;
6854 bool ExprsChanged = false;
6856 // Go through the outputs.
6857 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6858 Names.push_back(S->getOutputIdentifier(I));
6860 // No need to transform the constraint literal.
6861 Constraints.push_back(S->getOutputConstraintLiteral(I));
6863 // Transform the output expr.
6864 Expr *OutputExpr = S->getOutputExpr(I);
6865 ExprResult Result = getDerived().TransformExpr(OutputExpr);
6866 if (Result.isInvalid())
6869 ExprsChanged |= Result.get() != OutputExpr;
6871 Exprs.push_back(Result.get());
6874 // Go through the inputs.
6875 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6876 Names.push_back(S->getInputIdentifier(I));
6878 // No need to transform the constraint literal.
6879 Constraints.push_back(S->getInputConstraintLiteral(I));
6881 // Transform the input expr.
6882 Expr *InputExpr = S->getInputExpr(I);
6883 ExprResult Result = getDerived().TransformExpr(InputExpr);
6884 if (Result.isInvalid())
6887 ExprsChanged |= Result.get() != InputExpr;
6889 Exprs.push_back(Result.get());
6892 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6895 // Go through the clobbers.
6896 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6897 Clobbers.push_back(S->getClobberStringLiteral(I));
6899 // No need to transform the asm string literal.
6900 AsmString = S->getAsmString();
6901 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6902 S->isVolatile(), S->getNumOutputs(),
6903 S->getNumInputs(), Names.data(),
6904 Constraints, Exprs, AsmString.get(),
6905 Clobbers, S->getRParenLoc());
6908 template<typename Derived>
6910 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6911 ArrayRef<Token> AsmToks =
6912 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6914 bool HadError = false, HadChange = false;
6916 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6917 SmallVector<Expr*, 8> TransformedExprs;
6918 TransformedExprs.reserve(SrcExprs.size());
6919 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6920 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6921 if (!Result.isUsable()) {
6924 HadChange |= (Result.get() != SrcExprs[i]);
6925 TransformedExprs.push_back(Result.get());
6929 if (HadError) return StmtError();
6930 if (!HadChange && !getDerived().AlwaysRebuild())
6933 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6934 AsmToks, S->getAsmString(),
6935 S->getNumOutputs(), S->getNumInputs(),
6936 S->getAllConstraints(), S->getClobbers(),
6937 TransformedExprs, S->getEndLoc());
6940 // C++ Coroutines TS
6942 template<typename Derived>
6944 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6945 auto *ScopeInfo = SemaRef.getCurFunction();
6946 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
6947 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
6948 ScopeInfo->NeedsCoroutineSuspends &&
6949 ScopeInfo->CoroutineSuspends.first == nullptr &&
6950 ScopeInfo->CoroutineSuspends.second == nullptr &&
6951 "expected clean scope info");
6953 // Set that we have (possibly-invalid) suspend points before we do anything
6955 ScopeInfo->setNeedsCoroutineSuspends(false);
6957 // The new CoroutinePromise object needs to be built and put into the current
6958 // FunctionScopeInfo before any transformations or rebuilding occurs.
6959 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
6962 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
6963 ScopeInfo->CoroutinePromise = Promise;
6965 // Transform the implicit coroutine statements we built during the initial
6967 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
6968 if (InitSuspend.isInvalid())
6970 StmtResult FinalSuspend =
6971 getDerived().TransformStmt(S->getFinalSuspendStmt());
6972 if (FinalSuspend.isInvalid())
6974 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
6975 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
6977 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
6978 if (BodyRes.isInvalid())
6981 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
6982 if (Builder.isInvalid())
6985 Expr *ReturnObject = S->getReturnValueInit();
6986 assert(ReturnObject && "the return object is expected to be valid");
6987 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
6988 /*NoCopyInit*/ false);
6989 if (Res.isInvalid())
6991 Builder.ReturnValue = Res.get();
6993 if (S->hasDependentPromiseType()) {
6994 assert(!Promise->getType()->isDependentType() &&
6995 "the promise type must no longer be dependent");
6996 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
6997 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
6998 "these nodes should not have been built yet");
6999 if (!Builder.buildDependentStatements())
7002 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7003 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7004 if (Res.isInvalid())
7006 Builder.OnFallthrough = Res.get();
7009 if (auto *OnException = S->getExceptionHandler()) {
7010 StmtResult Res = getDerived().TransformStmt(OnException);
7011 if (Res.isInvalid())
7013 Builder.OnException = Res.get();
7016 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7017 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7018 if (Res.isInvalid())
7020 Builder.ReturnStmtOnAllocFailure = Res.get();
7023 // Transform any additional statements we may have already built
7024 assert(S->getAllocate() && S->getDeallocate() &&
7025 "allocation and deallocation calls must already be built");
7026 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7027 if (AllocRes.isInvalid())
7029 Builder.Allocate = AllocRes.get();
7031 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7032 if (DeallocRes.isInvalid())
7034 Builder.Deallocate = DeallocRes.get();
7036 assert(S->getResultDecl() && "ResultDecl must already be built");
7037 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7038 if (ResultDecl.isInvalid())
7040 Builder.ResultDecl = ResultDecl.get();
7042 if (auto *ReturnStmt = S->getReturnStmt()) {
7043 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7044 if (Res.isInvalid())
7046 Builder.ReturnStmt = Res.get();
7049 if (!Builder.buildParameterMoves())
7052 return getDerived().RebuildCoroutineBodyStmt(Builder);
7055 template<typename Derived>
7057 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7058 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7059 /*NotCopyInit*/false);
7060 if (Result.isInvalid())
7063 // Always rebuild; we don't know if this needs to be injected into a new
7064 // context or if the promise type has changed.
7065 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7069 template<typename Derived>
7071 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7072 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7073 /*NotCopyInit*/false);
7074 if (Result.isInvalid())
7077 // Always rebuild; we don't know if this needs to be injected into a new
7078 // context or if the promise type has changed.
7079 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7083 template <typename Derived>
7085 TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7086 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7087 /*NotCopyInit*/ false);
7088 if (OperandResult.isInvalid())
7091 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7092 E->getOperatorCoawaitLookup());
7094 if (LookupResult.isInvalid())
7097 // Always rebuild; we don't know if this needs to be injected into a new
7098 // context or if the promise type has changed.
7099 return getDerived().RebuildDependentCoawaitExpr(
7100 E->getKeywordLoc(), OperandResult.get(),
7101 cast<UnresolvedLookupExpr>(LookupResult.get()));
7104 template<typename Derived>
7106 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7107 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7108 /*NotCopyInit*/false);
7109 if (Result.isInvalid())
7112 // Always rebuild; we don't know if this needs to be injected into a new
7113 // context or if the promise type has changed.
7114 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7117 // Objective-C Statements.
7119 template<typename Derived>
7121 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
7122 // Transform the body of the @try.
7123 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
7124 if (TryBody.isInvalid())
7127 // Transform the @catch statements (if present).
7128 bool AnyCatchChanged = false;
7129 SmallVector<Stmt*, 8> CatchStmts;
7130 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
7131 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
7132 if (Catch.isInvalid())
7134 if (Catch.get() != S->getCatchStmt(I))
7135 AnyCatchChanged = true;
7136 CatchStmts.push_back(Catch.get());
7139 // Transform the @finally statement (if present).
7141 if (S->getFinallyStmt()) {
7142 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7143 if (Finally.isInvalid())
7147 // If nothing changed, just retain this statement.
7148 if (!getDerived().AlwaysRebuild() &&
7149 TryBody.get() == S->getTryBody() &&
7151 Finally.get() == S->getFinallyStmt())
7154 // Build a new statement.
7155 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
7156 CatchStmts, Finally.get());
7159 template<typename Derived>
7161 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
7162 // Transform the @catch parameter, if there is one.
7163 VarDecl *Var = nullptr;
7164 if (VarDecl *FromVar = S->getCatchParamDecl()) {
7165 TypeSourceInfo *TSInfo = nullptr;
7166 if (FromVar->getTypeSourceInfo()) {
7167 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7174 T = TSInfo->getType();
7176 T = getDerived().TransformType(FromVar->getType());
7181 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7186 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
7187 if (Body.isInvalid())
7190 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
7195 template<typename Derived>
7197 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
7198 // Transform the body.
7199 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
7200 if (Body.isInvalid())
7203 // If nothing changed, just retain this statement.
7204 if (!getDerived().AlwaysRebuild() &&
7205 Body.get() == S->getFinallyBody())
7208 // Build a new statement.
7209 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
7213 template<typename Derived>
7215 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
7217 if (S->getThrowExpr()) {
7218 Operand = getDerived().TransformExpr(S->getThrowExpr());
7219 if (Operand.isInvalid())
7223 if (!getDerived().AlwaysRebuild() &&
7224 Operand.get() == S->getThrowExpr())
7227 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
7230 template<typename Derived>
7232 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
7233 ObjCAtSynchronizedStmt *S) {
7234 // Transform the object we are locking.
7235 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
7236 if (Object.isInvalid())
7239 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7241 if (Object.isInvalid())
7244 // Transform the body.
7245 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
7246 if (Body.isInvalid())
7249 // If nothing change, just retain the current statement.
7250 if (!getDerived().AlwaysRebuild() &&
7251 Object.get() == S->getSynchExpr() &&
7252 Body.get() == S->getSynchBody())
7255 // Build a new statement.
7256 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
7257 Object.get(), Body.get());
7260 template<typename Derived>
7262 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7263 ObjCAutoreleasePoolStmt *S) {
7264 // Transform the body.
7265 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7266 if (Body.isInvalid())
7269 // If nothing changed, just retain this statement.
7270 if (!getDerived().AlwaysRebuild() &&
7271 Body.get() == S->getSubStmt())
7274 // Build a new statement.
7275 return getDerived().RebuildObjCAutoreleasePoolStmt(
7276 S->getAtLoc(), Body.get());
7279 template<typename Derived>
7281 TreeTransform<Derived>::TransformObjCForCollectionStmt(
7282 ObjCForCollectionStmt *S) {
7283 // Transform the element statement.
7284 StmtResult Element = getDerived().TransformStmt(S->getElement());
7285 if (Element.isInvalid())
7288 // Transform the collection expression.
7289 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
7290 if (Collection.isInvalid())
7293 // Transform the body.
7294 StmtResult Body = getDerived().TransformStmt(S->getBody());
7295 if (Body.isInvalid())
7298 // If nothing changed, just retain this statement.
7299 if (!getDerived().AlwaysRebuild() &&
7300 Element.get() == S->getElement() &&
7301 Collection.get() == S->getCollection() &&
7302 Body.get() == S->getBody())
7305 // Build a new statement.
7306 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
7313 template <typename Derived>
7314 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
7315 // Transform the exception declaration, if any.
7316 VarDecl *Var = nullptr;
7317 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7319 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
7323 Var = getDerived().RebuildExceptionDecl(
7324 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7325 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
7326 if (!Var || Var->isInvalidDecl())
7330 // Transform the actual exception handler.
7331 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
7332 if (Handler.isInvalid())
7335 if (!getDerived().AlwaysRebuild() && !Var &&
7336 Handler.get() == S->getHandlerBlock())
7339 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
7342 template <typename Derived>
7343 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
7344 // Transform the try block itself.
7345 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7346 if (TryBlock.isInvalid())
7349 // Transform the handlers.
7350 bool HandlerChanged = false;
7351 SmallVector<Stmt *, 8> Handlers;
7352 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
7353 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
7354 if (Handler.isInvalid())
7357 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
7358 Handlers.push_back(Handler.getAs<Stmt>());
7361 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7365 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
7369 template<typename Derived>
7371 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7372 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7373 if (Range.isInvalid())
7376 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7377 if (Begin.isInvalid())
7379 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7380 if (End.isInvalid())
7383 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7384 if (Cond.isInvalid())
7387 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
7388 if (Cond.isInvalid())
7391 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
7393 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7394 if (Inc.isInvalid())
7397 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
7399 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7400 if (LoopVar.isInvalid())
7403 StmtResult NewStmt = S;
7404 if (getDerived().AlwaysRebuild() ||
7405 Range.get() != S->getRangeStmt() ||
7406 Begin.get() != S->getBeginStmt() ||
7407 End.get() != S->getEndStmt() ||
7408 Cond.get() != S->getCond() ||
7409 Inc.get() != S->getInc() ||
7410 LoopVar.get() != S->getLoopVarStmt()) {
7411 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7413 S->getColonLoc(), Range.get(),
7414 Begin.get(), End.get(),
7416 Inc.get(), LoopVar.get(),
7418 if (NewStmt.isInvalid())
7422 StmtResult Body = getDerived().TransformStmt(S->getBody());
7423 if (Body.isInvalid())
7426 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7427 // it now so we have a new statement to attach the body to.
7428 if (Body.get() != S->getBody() && NewStmt.get() == S) {
7429 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7431 S->getColonLoc(), Range.get(),
7432 Begin.get(), End.get(),
7434 Inc.get(), LoopVar.get(),
7436 if (NewStmt.isInvalid())
7440 if (NewStmt.get() == S)
7443 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7446 template<typename Derived>
7448 TreeTransform<Derived>::TransformMSDependentExistsStmt(
7449 MSDependentExistsStmt *S) {
7450 // Transform the nested-name-specifier, if any.
7451 NestedNameSpecifierLoc QualifierLoc;
7452 if (S->getQualifierLoc()) {
7454 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7459 // Transform the declaration name.
7460 DeclarationNameInfo NameInfo = S->getNameInfo();
7461 if (NameInfo.getName()) {
7462 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7463 if (!NameInfo.getName())
7467 // Check whether anything changed.
7468 if (!getDerived().AlwaysRebuild() &&
7469 QualifierLoc == S->getQualifierLoc() &&
7470 NameInfo.getName() == S->getNameInfo().getName())
7473 // Determine whether this name exists, if we can.
7475 SS.Adopt(QualifierLoc);
7476 bool Dependent = false;
7477 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
7478 case Sema::IER_Exists:
7479 if (S->isIfExists())
7482 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7484 case Sema::IER_DoesNotExist:
7485 if (S->isIfNotExists())
7488 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7490 case Sema::IER_Dependent:
7494 case Sema::IER_Error:
7498 // We need to continue with the instantiation, so do so now.
7499 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7500 if (SubStmt.isInvalid())
7503 // If we have resolved the name, just transform to the substatement.
7507 // The name is still dependent, so build a dependent expression again.
7508 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7515 template<typename Derived>
7517 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7518 NestedNameSpecifierLoc QualifierLoc;
7519 if (E->getQualifierLoc()) {
7521 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7526 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7527 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7531 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7532 if (Base.isInvalid())
7535 return new (SemaRef.getASTContext())
7536 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7537 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7538 QualifierLoc, E->getMemberLoc());
7541 template <typename Derived>
7542 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7543 MSPropertySubscriptExpr *E) {
7544 auto BaseRes = getDerived().TransformExpr(E->getBase());
7545 if (BaseRes.isInvalid())
7547 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7548 if (IdxRes.isInvalid())
7551 if (!getDerived().AlwaysRebuild() &&
7552 BaseRes.get() == E->getBase() &&
7553 IdxRes.get() == E->getIdx())
7556 return getDerived().RebuildArraySubscriptExpr(
7557 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7560 template <typename Derived>
7561 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7562 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7563 if (TryBlock.isInvalid())
7566 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7567 if (Handler.isInvalid())
7570 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7571 Handler.get() == S->getHandler())
7574 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7575 TryBlock.get(), Handler.get());
7578 template <typename Derived>
7579 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7580 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7581 if (Block.isInvalid())
7584 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7587 template <typename Derived>
7588 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7589 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7590 if (FilterExpr.isInvalid())
7593 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7594 if (Block.isInvalid())
7597 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7601 template <typename Derived>
7602 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7603 if (isa<SEHFinallyStmt>(Handler))
7604 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7606 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7609 template<typename Derived>
7611 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7615 //===----------------------------------------------------------------------===//
7616 // OpenMP directive transformation
7617 //===----------------------------------------------------------------------===//
7618 template <typename Derived>
7619 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7620 OMPExecutableDirective *D) {
7622 // Transform the clauses
7623 llvm::SmallVector<OMPClause *, 16> TClauses;
7624 ArrayRef<OMPClause *> Clauses = D->clauses();
7625 TClauses.reserve(Clauses.size());
7626 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7629 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7630 OMPClause *Clause = getDerived().TransformOMPClause(*I);
7631 getDerived().getSema().EndOpenMPClause();
7633 TClauses.push_back(Clause);
7635 TClauses.push_back(nullptr);
7638 StmtResult AssociatedStmt;
7639 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7640 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7641 /*CurScope=*/nullptr);
7644 Sema::CompoundScopeRAII CompoundScope(getSema());
7645 int ThisCaptureLevel =
7646 Sema::getOpenMPCaptureLevels(D->getDirectiveKind());
7647 Stmt *CS = D->getAssociatedStmt();
7648 while (--ThisCaptureLevel >= 0)
7649 CS = cast<CapturedStmt>(CS)->getCapturedStmt();
7650 Body = getDerived().TransformStmt(CS);
7653 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7654 if (AssociatedStmt.isInvalid()) {
7658 if (TClauses.size() != Clauses.size()) {
7662 // Transform directive name for 'omp critical' directive.
7663 DeclarationNameInfo DirName;
7664 if (D->getDirectiveKind() == OMPD_critical) {
7665 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7666 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7668 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7669 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7670 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7671 } else if (D->getDirectiveKind() == OMPD_cancel) {
7672 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7675 return getDerived().RebuildOMPExecutableDirective(
7676 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7677 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7680 template <typename Derived>
7682 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7683 DeclarationNameInfo DirName;
7684 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7686 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7687 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7691 template <typename Derived>
7693 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7694 DeclarationNameInfo DirName;
7695 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7697 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7698 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7702 template <typename Derived>
7704 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7705 DeclarationNameInfo DirName;
7706 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7708 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7709 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7713 template <typename Derived>
7715 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7716 DeclarationNameInfo DirName;
7717 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7719 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7720 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7724 template <typename Derived>
7726 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7727 DeclarationNameInfo DirName;
7728 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7730 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7731 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7735 template <typename Derived>
7737 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7738 DeclarationNameInfo DirName;
7739 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7741 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7742 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7746 template <typename Derived>
7748 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7749 DeclarationNameInfo DirName;
7750 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7752 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7753 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7757 template <typename Derived>
7759 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7760 DeclarationNameInfo DirName;
7761 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7763 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7764 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7768 template <typename Derived>
7770 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7771 getDerived().getSema().StartOpenMPDSABlock(
7772 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7773 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7774 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7778 template <typename Derived>
7779 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7780 OMPParallelForDirective *D) {
7781 DeclarationNameInfo DirName;
7782 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7783 nullptr, D->getLocStart());
7784 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7785 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7789 template <typename Derived>
7790 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7791 OMPParallelForSimdDirective *D) {
7792 DeclarationNameInfo DirName;
7793 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7794 nullptr, D->getLocStart());
7795 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7796 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7800 template <typename Derived>
7801 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7802 OMPParallelSectionsDirective *D) {
7803 DeclarationNameInfo DirName;
7804 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7805 nullptr, D->getLocStart());
7806 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7807 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7811 template <typename Derived>
7813 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7814 DeclarationNameInfo DirName;
7815 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7817 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7818 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7822 template <typename Derived>
7823 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7824 OMPTaskyieldDirective *D) {
7825 DeclarationNameInfo DirName;
7826 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7828 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7829 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7833 template <typename Derived>
7835 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7836 DeclarationNameInfo DirName;
7837 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7839 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7840 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7844 template <typename Derived>
7846 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7847 DeclarationNameInfo DirName;
7848 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7850 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7851 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7855 template <typename Derived>
7856 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7857 OMPTaskgroupDirective *D) {
7858 DeclarationNameInfo DirName;
7859 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7861 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7862 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7866 template <typename Derived>
7868 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7869 DeclarationNameInfo DirName;
7870 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7872 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7873 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7877 template <typename Derived>
7879 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7880 DeclarationNameInfo DirName;
7881 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7883 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7884 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7888 template <typename Derived>
7890 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7891 DeclarationNameInfo DirName;
7892 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7894 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7895 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7899 template <typename Derived>
7901 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7902 DeclarationNameInfo DirName;
7903 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7905 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7906 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7910 template <typename Derived>
7911 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7912 OMPTargetDataDirective *D) {
7913 DeclarationNameInfo DirName;
7914 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7916 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7917 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7921 template <typename Derived>
7922 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7923 OMPTargetEnterDataDirective *D) {
7924 DeclarationNameInfo DirName;
7925 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7926 nullptr, D->getLocStart());
7927 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7928 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7932 template <typename Derived>
7933 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7934 OMPTargetExitDataDirective *D) {
7935 DeclarationNameInfo DirName;
7936 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7937 nullptr, D->getLocStart());
7938 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7939 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7943 template <typename Derived>
7944 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7945 OMPTargetParallelDirective *D) {
7946 DeclarationNameInfo DirName;
7947 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7948 nullptr, D->getLocStart());
7949 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7950 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7954 template <typename Derived>
7955 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7956 OMPTargetParallelForDirective *D) {
7957 DeclarationNameInfo DirName;
7958 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7959 nullptr, D->getLocStart());
7960 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7961 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7965 template <typename Derived>
7966 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7967 OMPTargetUpdateDirective *D) {
7968 DeclarationNameInfo DirName;
7969 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7970 nullptr, D->getLocStart());
7971 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7972 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7976 template <typename Derived>
7978 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7979 DeclarationNameInfo DirName;
7980 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7982 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7983 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7987 template <typename Derived>
7988 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7989 OMPCancellationPointDirective *D) {
7990 DeclarationNameInfo DirName;
7991 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7992 nullptr, D->getLocStart());
7993 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7994 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7998 template <typename Derived>
8000 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8001 DeclarationNameInfo DirName;
8002 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
8004 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8005 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8009 template <typename Derived>
8011 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8012 DeclarationNameInfo DirName;
8013 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
8015 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8016 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8020 template <typename Derived>
8021 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8022 OMPTaskLoopSimdDirective *D) {
8023 DeclarationNameInfo DirName;
8024 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
8025 nullptr, D->getLocStart());
8026 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8027 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8031 template <typename Derived>
8032 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8033 OMPDistributeDirective *D) {
8034 DeclarationNameInfo DirName;
8035 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
8037 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8038 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8042 template <typename Derived>
8043 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8044 OMPDistributeParallelForDirective *D) {
8045 DeclarationNameInfo DirName;
8046 getDerived().getSema().StartOpenMPDSABlock(
8047 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
8048 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8049 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8053 template <typename Derived>
8055 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8056 OMPDistributeParallelForSimdDirective *D) {
8057 DeclarationNameInfo DirName;
8058 getDerived().getSema().StartOpenMPDSABlock(
8059 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8060 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8061 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8065 template <typename Derived>
8066 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8067 OMPDistributeSimdDirective *D) {
8068 DeclarationNameInfo DirName;
8069 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
8070 nullptr, D->getLocStart());
8071 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8072 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8076 template <typename Derived>
8077 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8078 OMPTargetParallelForSimdDirective *D) {
8079 DeclarationNameInfo DirName;
8080 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8083 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8084 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8088 template <typename Derived>
8089 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8090 OMPTargetSimdDirective *D) {
8091 DeclarationNameInfo DirName;
8092 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8094 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8095 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8099 template <typename Derived>
8100 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8101 OMPTeamsDistributeDirective *D) {
8102 DeclarationNameInfo DirName;
8103 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8104 nullptr, D->getLocStart());
8105 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8106 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8110 template <typename Derived>
8111 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8112 OMPTeamsDistributeSimdDirective *D) {
8113 DeclarationNameInfo DirName;
8114 getDerived().getSema().StartOpenMPDSABlock(
8115 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8116 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8117 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8121 template <typename Derived>
8122 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8123 OMPTeamsDistributeParallelForSimdDirective *D) {
8124 DeclarationNameInfo DirName;
8125 getDerived().getSema().StartOpenMPDSABlock(
8126 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8127 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8128 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8132 template <typename Derived>
8133 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8134 OMPTeamsDistributeParallelForDirective *D) {
8135 DeclarationNameInfo DirName;
8136 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8137 DirName, nullptr, D->getLocStart());
8138 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8139 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8143 template <typename Derived>
8144 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8145 OMPTargetTeamsDirective *D) {
8146 DeclarationNameInfo DirName;
8147 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8148 nullptr, D->getLocStart());
8149 auto Res = getDerived().TransformOMPExecutableDirective(D);
8150 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8154 template <typename Derived>
8155 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8156 OMPTargetTeamsDistributeDirective *D) {
8157 DeclarationNameInfo DirName;
8158 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8159 DirName, nullptr, D->getLocStart());
8160 auto Res = getDerived().TransformOMPExecutableDirective(D);
8161 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8165 template <typename Derived>
8167 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8168 OMPTargetTeamsDistributeParallelForDirective *D) {
8169 DeclarationNameInfo DirName;
8170 getDerived().getSema().StartOpenMPDSABlock(
8171 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8173 auto Res = getDerived().TransformOMPExecutableDirective(D);
8174 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8178 template <typename Derived>
8179 StmtResult TreeTransform<Derived>::
8180 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8181 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8182 DeclarationNameInfo DirName;
8183 getDerived().getSema().StartOpenMPDSABlock(
8184 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8186 auto Res = getDerived().TransformOMPExecutableDirective(D);
8187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8191 template <typename Derived>
8193 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8194 OMPTargetTeamsDistributeSimdDirective *D) {
8195 DeclarationNameInfo DirName;
8196 getDerived().getSema().StartOpenMPDSABlock(
8197 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8198 auto Res = getDerived().TransformOMPExecutableDirective(D);
8199 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8204 //===----------------------------------------------------------------------===//
8205 // OpenMP clause transformation
8206 //===----------------------------------------------------------------------===//
8207 template <typename Derived>
8208 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
8209 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8210 if (Cond.isInvalid())
8212 return getDerived().RebuildOMPIfClause(
8213 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8214 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
8217 template <typename Derived>
8218 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8219 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8220 if (Cond.isInvalid())
8222 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8223 C->getLParenLoc(), C->getLocEnd());
8226 template <typename Derived>
8228 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8229 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8230 if (NumThreads.isInvalid())
8232 return getDerived().RebuildOMPNumThreadsClause(
8233 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8236 template <typename Derived>
8238 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8239 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8242 return getDerived().RebuildOMPSafelenClause(
8243 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8246 template <typename Derived>
8248 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8249 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8252 return getDerived().RebuildOMPSimdlenClause(
8253 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8256 template <typename Derived>
8258 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8259 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8262 return getDerived().RebuildOMPCollapseClause(
8263 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8266 template <typename Derived>
8268 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
8269 return getDerived().RebuildOMPDefaultClause(
8270 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8271 C->getLParenLoc(), C->getLocEnd());
8274 template <typename Derived>
8276 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
8277 return getDerived().RebuildOMPProcBindClause(
8278 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8279 C->getLParenLoc(), C->getLocEnd());
8282 template <typename Derived>
8284 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8285 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8288 return getDerived().RebuildOMPScheduleClause(
8289 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
8290 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8291 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
8292 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8295 template <typename Derived>
8297 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
8299 if (auto *Num = C->getNumForLoops()) {
8300 E = getDerived().TransformExpr(Num);
8304 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8305 C->getLParenLoc(), E.get());
8308 template <typename Derived>
8310 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8311 // No need to rebuild this clause, no template-dependent parameters.
8315 template <typename Derived>
8317 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8318 // No need to rebuild this clause, no template-dependent parameters.
8322 template <typename Derived>
8324 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8325 // No need to rebuild this clause, no template-dependent parameters.
8329 template <typename Derived>
8330 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8331 // No need to rebuild this clause, no template-dependent parameters.
8335 template <typename Derived>
8336 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8337 // No need to rebuild this clause, no template-dependent parameters.
8341 template <typename Derived>
8343 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8344 // No need to rebuild this clause, no template-dependent parameters.
8348 template <typename Derived>
8350 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8351 // No need to rebuild this clause, no template-dependent parameters.
8355 template <typename Derived>
8357 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8358 // No need to rebuild this clause, no template-dependent parameters.
8362 template <typename Derived>
8364 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8365 // No need to rebuild this clause, no template-dependent parameters.
8369 template <typename Derived>
8370 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8371 // No need to rebuild this clause, no template-dependent parameters.
8375 template <typename Derived>
8377 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8378 // No need to rebuild this clause, no template-dependent parameters.
8382 template <typename Derived>
8384 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
8385 llvm::SmallVector<Expr *, 16> Vars;
8386 Vars.reserve(C->varlist_size());
8387 for (auto *VE : C->varlists()) {
8388 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8389 if (EVar.isInvalid())
8391 Vars.push_back(EVar.get());
8393 return getDerived().RebuildOMPPrivateClause(
8394 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8397 template <typename Derived>
8398 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8399 OMPFirstprivateClause *C) {
8400 llvm::SmallVector<Expr *, 16> Vars;
8401 Vars.reserve(C->varlist_size());
8402 for (auto *VE : C->varlists()) {
8403 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8404 if (EVar.isInvalid())
8406 Vars.push_back(EVar.get());
8408 return getDerived().RebuildOMPFirstprivateClause(
8409 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8412 template <typename Derived>
8414 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8415 llvm::SmallVector<Expr *, 16> Vars;
8416 Vars.reserve(C->varlist_size());
8417 for (auto *VE : C->varlists()) {
8418 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8419 if (EVar.isInvalid())
8421 Vars.push_back(EVar.get());
8423 return getDerived().RebuildOMPLastprivateClause(
8424 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8427 template <typename Derived>
8429 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8430 llvm::SmallVector<Expr *, 16> Vars;
8431 Vars.reserve(C->varlist_size());
8432 for (auto *VE : C->varlists()) {
8433 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8434 if (EVar.isInvalid())
8436 Vars.push_back(EVar.get());
8438 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8439 C->getLParenLoc(), C->getLocEnd());
8442 template <typename Derived>
8444 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8445 llvm::SmallVector<Expr *, 16> Vars;
8446 Vars.reserve(C->varlist_size());
8447 for (auto *VE : C->varlists()) {
8448 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8449 if (EVar.isInvalid())
8451 Vars.push_back(EVar.get());
8453 CXXScopeSpec ReductionIdScopeSpec;
8454 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8456 DeclarationNameInfo NameInfo = C->getNameInfo();
8457 if (NameInfo.getName()) {
8458 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8459 if (!NameInfo.getName())
8462 // Build a list of all UDR decls with the same names ranged by the Scopes.
8463 // The Scope boundary is a duplication of the previous decl.
8464 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8465 for (auto *E : C->reduction_ops()) {
8466 // Transform all the decls.
8468 auto *ULE = cast<UnresolvedLookupExpr>(E);
8469 UnresolvedSet<8> Decls;
8470 for (auto *D : ULE->decls()) {
8472 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8473 Decls.addDecl(InstD, InstD->getAccess());
8475 UnresolvedReductions.push_back(
8476 UnresolvedLookupExpr::Create(
8477 SemaRef.Context, /*NamingClass=*/nullptr,
8478 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8479 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8480 Decls.begin(), Decls.end()));
8482 UnresolvedReductions.push_back(nullptr);
8484 return getDerived().RebuildOMPReductionClause(
8485 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8486 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8489 template <typename Derived>
8490 OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8491 OMPTaskReductionClause *C) {
8492 llvm::SmallVector<Expr *, 16> Vars;
8493 Vars.reserve(C->varlist_size());
8494 for (auto *VE : C->varlists()) {
8495 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8496 if (EVar.isInvalid())
8498 Vars.push_back(EVar.get());
8500 CXXScopeSpec ReductionIdScopeSpec;
8501 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8503 DeclarationNameInfo NameInfo = C->getNameInfo();
8504 if (NameInfo.getName()) {
8505 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8506 if (!NameInfo.getName())
8509 // Build a list of all UDR decls with the same names ranged by the Scopes.
8510 // The Scope boundary is a duplication of the previous decl.
8511 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8512 for (auto *E : C->reduction_ops()) {
8513 // Transform all the decls.
8515 auto *ULE = cast<UnresolvedLookupExpr>(E);
8516 UnresolvedSet<8> Decls;
8517 for (auto *D : ULE->decls()) {
8519 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8520 Decls.addDecl(InstD, InstD->getAccess());
8522 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8523 SemaRef.Context, /*NamingClass=*/nullptr,
8524 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8525 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8527 UnresolvedReductions.push_back(nullptr);
8529 return getDerived().RebuildOMPTaskReductionClause(
8530 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8531 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8534 template <typename Derived>
8536 TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8537 llvm::SmallVector<Expr *, 16> Vars;
8538 Vars.reserve(C->varlist_size());
8539 for (auto *VE : C->varlists()) {
8540 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8541 if (EVar.isInvalid())
8543 Vars.push_back(EVar.get());
8545 CXXScopeSpec ReductionIdScopeSpec;
8546 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8548 DeclarationNameInfo NameInfo = C->getNameInfo();
8549 if (NameInfo.getName()) {
8550 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8551 if (!NameInfo.getName())
8554 // Build a list of all UDR decls with the same names ranged by the Scopes.
8555 // The Scope boundary is a duplication of the previous decl.
8556 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8557 for (auto *E : C->reduction_ops()) {
8558 // Transform all the decls.
8560 auto *ULE = cast<UnresolvedLookupExpr>(E);
8561 UnresolvedSet<8> Decls;
8562 for (auto *D : ULE->decls()) {
8564 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8565 Decls.addDecl(InstD, InstD->getAccess());
8567 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8568 SemaRef.Context, /*NamingClass=*/nullptr,
8569 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8570 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8572 UnresolvedReductions.push_back(nullptr);
8574 return getDerived().RebuildOMPInReductionClause(
8575 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8576 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8579 template <typename Derived>
8581 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8582 llvm::SmallVector<Expr *, 16> Vars;
8583 Vars.reserve(C->varlist_size());
8584 for (auto *VE : C->varlists()) {
8585 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8586 if (EVar.isInvalid())
8588 Vars.push_back(EVar.get());
8590 ExprResult Step = getDerived().TransformExpr(C->getStep());
8591 if (Step.isInvalid())
8593 return getDerived().RebuildOMPLinearClause(
8594 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8595 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
8598 template <typename Derived>
8600 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8601 llvm::SmallVector<Expr *, 16> Vars;
8602 Vars.reserve(C->varlist_size());
8603 for (auto *VE : C->varlists()) {
8604 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8605 if (EVar.isInvalid())
8607 Vars.push_back(EVar.get());
8609 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8610 if (Alignment.isInvalid())
8612 return getDerived().RebuildOMPAlignedClause(
8613 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8614 C->getColonLoc(), C->getLocEnd());
8617 template <typename Derived>
8619 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8620 llvm::SmallVector<Expr *, 16> Vars;
8621 Vars.reserve(C->varlist_size());
8622 for (auto *VE : C->varlists()) {
8623 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8624 if (EVar.isInvalid())
8626 Vars.push_back(EVar.get());
8628 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8629 C->getLParenLoc(), C->getLocEnd());
8632 template <typename Derived>
8634 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8635 llvm::SmallVector<Expr *, 16> Vars;
8636 Vars.reserve(C->varlist_size());
8637 for (auto *VE : C->varlists()) {
8638 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8639 if (EVar.isInvalid())
8641 Vars.push_back(EVar.get());
8643 return getDerived().RebuildOMPCopyprivateClause(
8644 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8647 template <typename Derived>
8648 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8649 llvm::SmallVector<Expr *, 16> Vars;
8650 Vars.reserve(C->varlist_size());
8651 for (auto *VE : C->varlists()) {
8652 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8653 if (EVar.isInvalid())
8655 Vars.push_back(EVar.get());
8657 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8658 C->getLParenLoc(), C->getLocEnd());
8661 template <typename Derived>
8663 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8664 llvm::SmallVector<Expr *, 16> Vars;
8665 Vars.reserve(C->varlist_size());
8666 for (auto *VE : C->varlists()) {
8667 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8668 if (EVar.isInvalid())
8670 Vars.push_back(EVar.get());
8672 return getDerived().RebuildOMPDependClause(
8673 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8674 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8677 template <typename Derived>
8679 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8680 ExprResult E = getDerived().TransformExpr(C->getDevice());
8683 return getDerived().RebuildOMPDeviceClause(
8684 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8687 template <typename Derived>
8688 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8689 llvm::SmallVector<Expr *, 16> Vars;
8690 Vars.reserve(C->varlist_size());
8691 for (auto *VE : C->varlists()) {
8692 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8693 if (EVar.isInvalid())
8695 Vars.push_back(EVar.get());
8697 return getDerived().RebuildOMPMapClause(
8698 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8699 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8700 C->getLParenLoc(), C->getLocEnd());
8703 template <typename Derived>
8705 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8706 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8709 return getDerived().RebuildOMPNumTeamsClause(
8710 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8713 template <typename Derived>
8715 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8716 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8719 return getDerived().RebuildOMPThreadLimitClause(
8720 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8723 template <typename Derived>
8725 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8726 ExprResult E = getDerived().TransformExpr(C->getPriority());
8729 return getDerived().RebuildOMPPriorityClause(
8730 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8733 template <typename Derived>
8735 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8736 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8739 return getDerived().RebuildOMPGrainsizeClause(
8740 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8743 template <typename Derived>
8745 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8746 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8749 return getDerived().RebuildOMPNumTasksClause(
8750 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8753 template <typename Derived>
8754 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8755 ExprResult E = getDerived().TransformExpr(C->getHint());
8758 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8759 C->getLParenLoc(), C->getLocEnd());
8762 template <typename Derived>
8763 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8764 OMPDistScheduleClause *C) {
8765 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8768 return getDerived().RebuildOMPDistScheduleClause(
8769 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8770 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8773 template <typename Derived>
8775 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8779 template <typename Derived>
8780 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8781 llvm::SmallVector<Expr *, 16> Vars;
8782 Vars.reserve(C->varlist_size());
8783 for (auto *VE : C->varlists()) {
8784 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8785 if (EVar.isInvalid())
8787 Vars.push_back(EVar.get());
8789 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8790 C->getLParenLoc(), C->getLocEnd());
8793 template <typename Derived>
8794 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8795 llvm::SmallVector<Expr *, 16> Vars;
8796 Vars.reserve(C->varlist_size());
8797 for (auto *VE : C->varlists()) {
8798 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8799 if (EVar.isInvalid())
8801 Vars.push_back(EVar.get());
8803 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8804 C->getLParenLoc(), C->getLocEnd());
8807 template <typename Derived>
8808 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8809 OMPUseDevicePtrClause *C) {
8810 llvm::SmallVector<Expr *, 16> Vars;
8811 Vars.reserve(C->varlist_size());
8812 for (auto *VE : C->varlists()) {
8813 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8814 if (EVar.isInvalid())
8816 Vars.push_back(EVar.get());
8818 return getDerived().RebuildOMPUseDevicePtrClause(
8819 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8822 template <typename Derived>
8824 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8825 llvm::SmallVector<Expr *, 16> Vars;
8826 Vars.reserve(C->varlist_size());
8827 for (auto *VE : C->varlists()) {
8828 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8829 if (EVar.isInvalid())
8831 Vars.push_back(EVar.get());
8833 return getDerived().RebuildOMPIsDevicePtrClause(
8834 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8837 //===----------------------------------------------------------------------===//
8838 // Expression transformation
8839 //===----------------------------------------------------------------------===//
8840 template<typename Derived>
8842 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
8843 if (!E->isTypeDependent())
8846 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8850 template<typename Derived>
8852 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
8853 NestedNameSpecifierLoc QualifierLoc;
8854 if (E->getQualifierLoc()) {
8856 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8862 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8867 DeclarationNameInfo NameInfo = E->getNameInfo();
8868 if (NameInfo.getName()) {
8869 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8870 if (!NameInfo.getName())
8874 if (!getDerived().AlwaysRebuild() &&
8875 QualifierLoc == E->getQualifierLoc() &&
8876 ND == E->getDecl() &&
8877 NameInfo.getName() == E->getDecl()->getDeclName() &&
8878 !E->hasExplicitTemplateArgs()) {
8880 // Mark it referenced in the new context regardless.
8881 // FIXME: this is a bit instantiation-specific.
8882 SemaRef.MarkDeclRefReferenced(E);
8887 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
8888 if (E->hasExplicitTemplateArgs()) {
8889 TemplateArgs = &TransArgs;
8890 TransArgs.setLAngleLoc(E->getLAngleLoc());
8891 TransArgs.setRAngleLoc(E->getRAngleLoc());
8892 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8893 E->getNumTemplateArgs(),
8898 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
8902 template<typename Derived>
8904 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
8908 template<typename Derived>
8910 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
8914 template<typename Derived>
8916 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
8920 template<typename Derived>
8922 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
8926 template<typename Derived>
8928 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
8932 template<typename Derived>
8934 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
8935 if (FunctionDecl *FD = E->getDirectCallee())
8936 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
8937 return SemaRef.MaybeBindToTemporary(E);
8940 template<typename Derived>
8942 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8943 ExprResult ControllingExpr =
8944 getDerived().TransformExpr(E->getControllingExpr());
8945 if (ControllingExpr.isInvalid())
8948 SmallVector<Expr *, 4> AssocExprs;
8949 SmallVector<TypeSourceInfo *, 4> AssocTypes;
8950 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8951 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8953 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8956 AssocTypes.push_back(AssocType);
8958 AssocTypes.push_back(nullptr);
8961 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8962 if (AssocExpr.isInvalid())
8964 AssocExprs.push_back(AssocExpr.get());
8967 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8970 ControllingExpr.get(),
8975 template<typename Derived>
8977 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
8978 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8979 if (SubExpr.isInvalid())
8982 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8985 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
8989 /// \brief The operand of a unary address-of operator has special rules: it's
8990 /// allowed to refer to a non-static member of a class even if there's no 'this'
8991 /// object available.
8992 template<typename Derived>
8994 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8995 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
8996 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
8998 return getDerived().TransformExpr(E);
9001 template<typename Derived>
9003 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
9005 if (E->getOpcode() == UO_AddrOf)
9006 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9008 SubExpr = TransformExpr(E->getSubExpr());
9009 if (SubExpr.isInvalid())
9012 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
9015 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9020 template<typename Derived>
9022 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9023 // Transform the type.
9024 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9028 // Transform all of the components into components similar to what the
9030 // FIXME: It would be slightly more efficient in the non-dependent case to
9031 // just map FieldDecls, rather than requiring the rebuilder to look for
9032 // the fields again. However, __builtin_offsetof is rare enough in
9033 // template code that we don't care.
9034 bool ExprChanged = false;
9035 typedef Sema::OffsetOfComponent Component;
9036 SmallVector<Component, 4> Components;
9037 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
9038 const OffsetOfNode &ON = E->getComponent(I);
9040 Comp.isBrackets = true;
9041 Comp.LocStart = ON.getSourceRange().getBegin();
9042 Comp.LocEnd = ON.getSourceRange().getEnd();
9043 switch (ON.getKind()) {
9044 case OffsetOfNode::Array: {
9045 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
9046 ExprResult Index = getDerived().TransformExpr(FromIndex);
9047 if (Index.isInvalid())
9050 ExprChanged = ExprChanged || Index.get() != FromIndex;
9051 Comp.isBrackets = true;
9052 Comp.U.E = Index.get();
9056 case OffsetOfNode::Field:
9057 case OffsetOfNode::Identifier:
9058 Comp.isBrackets = false;
9059 Comp.U.IdentInfo = ON.getFieldName();
9060 if (!Comp.U.IdentInfo)
9065 case OffsetOfNode::Base:
9066 // Will be recomputed during the rebuild.
9070 Components.push_back(Comp);
9073 // If nothing changed, retain the existing expression.
9074 if (!getDerived().AlwaysRebuild() &&
9075 Type == E->getTypeSourceInfo() &&
9079 // Build a new offsetof expression.
9080 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
9081 Components, E->getRParenLoc());
9084 template<typename Derived>
9086 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
9087 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
9088 "opaque value expression requires transformation");
9092 template<typename Derived>
9094 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9098 template<typename Derived>
9100 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
9101 // Rebuild the syntactic form. The original syntactic form has
9102 // opaque-value expressions in it, so strip those away and rebuild
9103 // the result. This is a really awful way of doing this, but the
9104 // better solution (rebuilding the semantic expressions and
9105 // rebinding OVEs as necessary) doesn't work; we'd need
9106 // TreeTransform to not strip away implicit conversions.
9107 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9108 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
9109 if (result.isInvalid()) return ExprError();
9111 // If that gives us a pseudo-object result back, the pseudo-object
9112 // expression must have been an lvalue-to-rvalue conversion which we
9114 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
9115 result = SemaRef.checkPseudoObjectRValue(result.get());
9120 template<typename Derived>
9122 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9123 UnaryExprOrTypeTraitExpr *E) {
9124 if (E->isArgumentType()) {
9125 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
9127 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9131 if (!getDerived().AlwaysRebuild() && OldT == NewT)
9134 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9136 E->getSourceRange());
9139 // C++0x [expr.sizeof]p1:
9140 // The operand is either an expression, which is an unevaluated operand
9142 EnterExpressionEvaluationContext Unevaluated(
9143 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9144 Sema::ReuseLambdaContextDecl);
9146 // Try to recover if we have something like sizeof(T::X) where X is a type.
9147 // Notably, there must be *exactly* one set of parens if X is a type.
9148 TypeSourceInfo *RecoveryTSI = nullptr;
9150 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9152 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9153 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9154 PE, DRE, false, &RecoveryTSI);
9156 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9159 return getDerived().RebuildUnaryExprOrTypeTrait(
9160 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9161 } else if (SubExpr.isInvalid())
9164 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
9167 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9168 E->getOperatorLoc(),
9170 E->getSourceRange());
9173 template<typename Derived>
9175 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
9176 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9177 if (LHS.isInvalid())
9180 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9181 if (RHS.isInvalid())
9185 if (!getDerived().AlwaysRebuild() &&
9186 LHS.get() == E->getLHS() &&
9187 RHS.get() == E->getRHS())
9190 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
9191 /*FIXME:*/E->getLHS()->getLocStart(),
9193 E->getRBracketLoc());
9196 template <typename Derived>
9198 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9199 ExprResult Base = getDerived().TransformExpr(E->getBase());
9200 if (Base.isInvalid())
9203 ExprResult LowerBound;
9204 if (E->getLowerBound()) {
9205 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9206 if (LowerBound.isInvalid())
9211 if (E->getLength()) {
9212 Length = getDerived().TransformExpr(E->getLength());
9213 if (Length.isInvalid())
9217 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9218 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9221 return getDerived().RebuildOMPArraySectionExpr(
9222 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9223 Length.get(), E->getRBracketLoc());
9226 template<typename Derived>
9228 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
9229 // Transform the callee.
9230 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9231 if (Callee.isInvalid())
9234 // Transform arguments.
9235 bool ArgChanged = false;
9236 SmallVector<Expr*, 8> Args;
9237 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9241 if (!getDerived().AlwaysRebuild() &&
9242 Callee.get() == E->getCallee() &&
9244 return SemaRef.MaybeBindToTemporary(E);
9246 // FIXME: Wrong source location information for the '('.
9247 SourceLocation FakeLParenLoc
9248 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9249 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9254 template<typename Derived>
9256 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
9257 ExprResult Base = getDerived().TransformExpr(E->getBase());
9258 if (Base.isInvalid())
9261 NestedNameSpecifierLoc QualifierLoc;
9262 if (E->hasQualifier()) {
9264 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9269 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9272 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9273 E->getMemberDecl()));
9277 NamedDecl *FoundDecl = E->getFoundDecl();
9278 if (FoundDecl == E->getMemberDecl()) {
9281 FoundDecl = cast_or_null<NamedDecl>(
9282 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9287 if (!getDerived().AlwaysRebuild() &&
9288 Base.get() == E->getBase() &&
9289 QualifierLoc == E->getQualifierLoc() &&
9290 Member == E->getMemberDecl() &&
9291 FoundDecl == E->getFoundDecl() &&
9292 !E->hasExplicitTemplateArgs()) {
9294 // Mark it referenced in the new context regardless.
9295 // FIXME: this is a bit instantiation-specific.
9296 SemaRef.MarkMemberReferenced(E);
9301 TemplateArgumentListInfo TransArgs;
9302 if (E->hasExplicitTemplateArgs()) {
9303 TransArgs.setLAngleLoc(E->getLAngleLoc());
9304 TransArgs.setRAngleLoc(E->getRAngleLoc());
9305 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9306 E->getNumTemplateArgs(),
9311 // FIXME: Bogus source location for the operator
9312 SourceLocation FakeOperatorLoc =
9313 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
9315 // FIXME: to do this check properly, we will need to preserve the
9316 // first-qualifier-in-scope here, just in case we had a dependent
9317 // base (and therefore couldn't do the check) and a
9318 // nested-name-qualifier (and therefore could do the lookup).
9319 NamedDecl *FirstQualifierInScope = nullptr;
9320 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9321 if (MemberNameInfo.getName()) {
9322 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9323 if (!MemberNameInfo.getName())
9327 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
9334 (E->hasExplicitTemplateArgs()
9335 ? &TransArgs : nullptr),
9336 FirstQualifierInScope);
9339 template<typename Derived>
9341 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
9342 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9343 if (LHS.isInvalid())
9346 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9347 if (RHS.isInvalid())
9350 if (!getDerived().AlwaysRebuild() &&
9351 LHS.get() == E->getLHS() &&
9352 RHS.get() == E->getRHS())
9355 Sema::FPContractStateRAII FPContractState(getSema());
9356 getSema().FPFeatures = E->getFPFeatures();
9358 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
9359 LHS.get(), RHS.get());
9362 template<typename Derived>
9364 TreeTransform<Derived>::TransformCompoundAssignOperator(
9365 CompoundAssignOperator *E) {
9366 return getDerived().TransformBinaryOperator(E);
9369 template<typename Derived>
9370 ExprResult TreeTransform<Derived>::
9371 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9372 // Just rebuild the common and RHS expressions and see whether we
9375 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9376 if (commonExpr.isInvalid())
9379 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9380 if (rhs.isInvalid())
9383 if (!getDerived().AlwaysRebuild() &&
9384 commonExpr.get() == e->getCommon() &&
9385 rhs.get() == e->getFalseExpr())
9388 return getDerived().RebuildConditionalOperator(commonExpr.get(),
9389 e->getQuestionLoc(),
9395 template<typename Derived>
9397 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
9398 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9399 if (Cond.isInvalid())
9402 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9403 if (LHS.isInvalid())
9406 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9407 if (RHS.isInvalid())
9410 if (!getDerived().AlwaysRebuild() &&
9411 Cond.get() == E->getCond() &&
9412 LHS.get() == E->getLHS() &&
9413 RHS.get() == E->getRHS())
9416 return getDerived().RebuildConditionalOperator(Cond.get(),
9417 E->getQuestionLoc(),
9423 template<typename Derived>
9425 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
9426 // Implicit casts are eliminated during transformation, since they
9427 // will be recomputed by semantic analysis after transformation.
9428 return getDerived().TransformExpr(E->getSubExprAsWritten());
9431 template<typename Derived>
9433 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
9434 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9439 = getDerived().TransformExpr(E->getSubExprAsWritten());
9440 if (SubExpr.isInvalid())
9443 if (!getDerived().AlwaysRebuild() &&
9444 Type == E->getTypeInfoAsWritten() &&
9445 SubExpr.get() == E->getSubExpr())
9448 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
9454 template<typename Derived>
9456 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
9457 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9458 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9462 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
9463 if (Init.isInvalid())
9466 if (!getDerived().AlwaysRebuild() &&
9468 Init.get() == E->getInitializer())
9469 return SemaRef.MaybeBindToTemporary(E);
9471 // Note: the expression type doesn't necessarily match the
9472 // type-as-written, but that's okay, because it should always be
9473 // derivable from the initializer.
9475 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
9476 /*FIXME:*/E->getInitializer()->getLocEnd(),
9480 template<typename Derived>
9482 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
9483 ExprResult Base = getDerived().TransformExpr(E->getBase());
9484 if (Base.isInvalid())
9487 if (!getDerived().AlwaysRebuild() &&
9488 Base.get() == E->getBase())
9491 // FIXME: Bad source location
9492 SourceLocation FakeOperatorLoc =
9493 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
9494 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
9495 E->getAccessorLoc(),
9499 template<typename Derived>
9501 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
9502 if (InitListExpr *Syntactic = E->getSyntacticForm())
9505 bool InitChanged = false;
9507 SmallVector<Expr*, 4> Inits;
9508 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
9509 Inits, &InitChanged))
9512 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9513 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9514 // in some cases. We can't reuse it in general, because the syntactic and
9515 // semantic forms are linked, and we can't know that semantic form will
9516 // match even if the syntactic form does.
9519 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
9520 E->getRBraceLoc(), E->getType());
9523 template<typename Derived>
9525 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
9528 // transform the initializer value
9529 ExprResult Init = getDerived().TransformExpr(E->getInit());
9530 if (Init.isInvalid())
9533 // transform the designators.
9534 SmallVector<Expr*, 4> ArrayExprs;
9535 bool ExprChanged = false;
9536 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9537 if (D.isFieldDesignator()) {
9538 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9542 FieldDecl *Field = cast_or_null<FieldDecl>(
9543 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9544 if (Field != D.getField())
9545 // Rebuild the expression when the transformed FieldDecl is
9546 // different to the already assigned FieldDecl.
9549 // Ensure that the designator expression is rebuilt when there isn't
9550 // a resolved FieldDecl in the designator as we don't want to assign
9551 // a FieldDecl to a pattern designator that will be instantiated again.
9557 if (D.isArrayDesignator()) {
9558 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
9559 if (Index.isInvalid())
9562 Desig.AddDesignator(
9563 Designator::getArray(Index.get(), D.getLBracketLoc()));
9565 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
9566 ArrayExprs.push_back(Index.get());
9570 assert(D.isArrayRangeDesignator() && "New kind of designator?");
9572 = getDerived().TransformExpr(E->getArrayRangeStart(D));
9573 if (Start.isInvalid())
9576 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
9577 if (End.isInvalid())
9580 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
9583 D.getEllipsisLoc()));
9585 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9586 End.get() != E->getArrayRangeEnd(D);
9588 ArrayExprs.push_back(Start.get());
9589 ArrayExprs.push_back(End.get());
9592 if (!getDerived().AlwaysRebuild() &&
9593 Init.get() == E->getInit() &&
9597 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
9598 E->getEqualOrColonLoc(),
9599 E->usesGNUSyntax(), Init.get());
9602 // Seems that if TransformInitListExpr() only works on the syntactic form of an
9603 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9604 template<typename Derived>
9606 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9607 DesignatedInitUpdateExpr *E) {
9608 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9613 template<typename Derived>
9615 TreeTransform<Derived>::TransformNoInitExpr(
9617 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9621 template<typename Derived>
9623 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9624 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9628 template<typename Derived>
9630 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9631 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9635 template<typename Derived>
9637 TreeTransform<Derived>::TransformImplicitValueInitExpr(
9638 ImplicitValueInitExpr *E) {
9639 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
9641 // FIXME: Will we ever have proper type location here? Will we actually
9642 // need to transform the type?
9643 QualType T = getDerived().TransformType(E->getType());
9647 if (!getDerived().AlwaysRebuild() &&
9651 return getDerived().RebuildImplicitValueInitExpr(T);
9654 template<typename Derived>
9656 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
9657 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9661 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9662 if (SubExpr.isInvalid())
9665 if (!getDerived().AlwaysRebuild() &&
9666 TInfo == E->getWrittenTypeInfo() &&
9667 SubExpr.get() == E->getSubExpr())
9670 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
9671 TInfo, E->getRParenLoc());
9674 template<typename Derived>
9676 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
9677 bool ArgumentChanged = false;
9678 SmallVector<Expr*, 4> Inits;
9679 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9683 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
9688 /// \brief Transform an address-of-label expression.
9690 /// By default, the transformation of an address-of-label expression always
9691 /// rebuilds the expression, so that the label identifier can be resolved to
9692 /// the corresponding label statement by semantic analysis.
9693 template<typename Derived>
9695 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
9696 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9701 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
9702 cast<LabelDecl>(LD));
9705 template<typename Derived>
9707 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
9708 SemaRef.ActOnStartStmtExpr();
9710 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
9711 if (SubStmt.isInvalid()) {
9712 SemaRef.ActOnStmtExprError();
9716 if (!getDerived().AlwaysRebuild() &&
9717 SubStmt.get() == E->getSubStmt()) {
9718 // Calling this an 'error' is unintuitive, but it does the right thing.
9719 SemaRef.ActOnStmtExprError();
9720 return SemaRef.MaybeBindToTemporary(E);
9723 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
9728 template<typename Derived>
9730 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
9731 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9732 if (Cond.isInvalid())
9735 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9736 if (LHS.isInvalid())
9739 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9740 if (RHS.isInvalid())
9743 if (!getDerived().AlwaysRebuild() &&
9744 Cond.get() == E->getCond() &&
9745 LHS.get() == E->getLHS() &&
9746 RHS.get() == E->getRHS())
9749 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
9750 Cond.get(), LHS.get(), RHS.get(),
9754 template<typename Derived>
9756 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
9760 template<typename Derived>
9762 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
9763 switch (E->getOperator()) {
9767 case OO_Array_Delete:
9768 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
9771 // This is a call to an object's operator().
9772 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9774 // Transform the object itself.
9775 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
9776 if (Object.isInvalid())
9779 // FIXME: Poor location information
9780 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9781 static_cast<Expr *>(Object.get())->getLocEnd());
9783 // Transform the call arguments.
9784 SmallVector<Expr*, 8> Args;
9785 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
9789 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
9794 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9796 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9797 #include "clang/Basic/OperatorKinds.def"
9802 case OO_Conditional:
9803 llvm_unreachable("conditional operator is not actually overloadable");
9806 case NUM_OVERLOADED_OPERATORS:
9807 llvm_unreachable("not an overloaded operator?");
9810 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9811 if (Callee.isInvalid())
9815 if (E->getOperator() == OO_Amp)
9816 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9818 First = getDerived().TransformExpr(E->getArg(0));
9819 if (First.isInvalid())
9823 if (E->getNumArgs() == 2) {
9824 Second = getDerived().TransformExpr(E->getArg(1));
9825 if (Second.isInvalid())
9829 if (!getDerived().AlwaysRebuild() &&
9830 Callee.get() == E->getCallee() &&
9831 First.get() == E->getArg(0) &&
9832 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
9833 return SemaRef.MaybeBindToTemporary(E);
9835 Sema::FPContractStateRAII FPContractState(getSema());
9836 getSema().FPFeatures = E->getFPFeatures();
9838 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9839 E->getOperatorLoc(),
9845 template<typename Derived>
9847 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9848 return getDerived().TransformCallExpr(E);
9851 template<typename Derived>
9853 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9854 // Transform the callee.
9855 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9856 if (Callee.isInvalid())
9859 // Transform exec config.
9860 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9864 // Transform arguments.
9865 bool ArgChanged = false;
9866 SmallVector<Expr*, 8> Args;
9867 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9871 if (!getDerived().AlwaysRebuild() &&
9872 Callee.get() == E->getCallee() &&
9874 return SemaRef.MaybeBindToTemporary(E);
9876 // FIXME: Wrong source location information for the '('.
9877 SourceLocation FakeLParenLoc
9878 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9879 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9881 E->getRParenLoc(), EC.get());
9884 template<typename Derived>
9886 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
9887 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9892 = getDerived().TransformExpr(E->getSubExprAsWritten());
9893 if (SubExpr.isInvalid())
9896 if (!getDerived().AlwaysRebuild() &&
9897 Type == E->getTypeInfoAsWritten() &&
9898 SubExpr.get() == E->getSubExpr())
9900 return getDerived().RebuildCXXNamedCastExpr(
9901 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9902 Type, E->getAngleBrackets().getEnd(),
9903 // FIXME. this should be '(' location
9904 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
9907 template<typename Derived>
9909 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9910 return getDerived().TransformCXXNamedCastExpr(E);
9913 template<typename Derived>
9915 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9916 return getDerived().TransformCXXNamedCastExpr(E);
9919 template<typename Derived>
9921 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
9922 CXXReinterpretCastExpr *E) {
9923 return getDerived().TransformCXXNamedCastExpr(E);
9926 template<typename Derived>
9928 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9929 return getDerived().TransformCXXNamedCastExpr(E);
9932 template<typename Derived>
9934 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
9935 CXXFunctionalCastExpr *E) {
9936 TypeSourceInfo *Type =
9937 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
9942 = getDerived().TransformExpr(E->getSubExprAsWritten());
9943 if (SubExpr.isInvalid())
9946 if (!getDerived().AlwaysRebuild() &&
9947 Type == E->getTypeInfoAsWritten() &&
9948 SubExpr.get() == E->getSubExpr())
9951 return getDerived().RebuildCXXFunctionalCastExpr(Type,
9957 template<typename Derived>
9959 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
9960 if (E->isTypeOperand()) {
9961 TypeSourceInfo *TInfo
9962 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9966 if (!getDerived().AlwaysRebuild() &&
9967 TInfo == E->getTypeOperandSourceInfo())
9970 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9976 // We don't know whether the subexpression is potentially evaluated until
9977 // after we perform semantic analysis. We speculatively assume it is
9978 // unevaluated; it will get fixed later if the subexpression is in fact
9979 // potentially evaluated.
9980 EnterExpressionEvaluationContext Unevaluated(
9981 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9982 Sema::ReuseLambdaContextDecl);
9984 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9985 if (SubExpr.isInvalid())
9988 if (!getDerived().AlwaysRebuild() &&
9989 SubExpr.get() == E->getExprOperand())
9992 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9998 template<typename Derived>
10000 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10001 if (E->isTypeOperand()) {
10002 TypeSourceInfo *TInfo
10003 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10005 return ExprError();
10007 if (!getDerived().AlwaysRebuild() &&
10008 TInfo == E->getTypeOperandSourceInfo())
10011 return getDerived().RebuildCXXUuidofExpr(E->getType(),
10017 EnterExpressionEvaluationContext Unevaluated(
10018 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
10020 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10021 if (SubExpr.isInvalid())
10022 return ExprError();
10024 if (!getDerived().AlwaysRebuild() &&
10025 SubExpr.get() == E->getExprOperand())
10028 return getDerived().RebuildCXXUuidofExpr(E->getType(),
10034 template<typename Derived>
10036 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
10040 template<typename Derived>
10042 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
10043 CXXNullPtrLiteralExpr *E) {
10047 template<typename Derived>
10049 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
10050 QualType T = getSema().getCurrentThisType();
10052 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
10053 // Make sure that we capture 'this'.
10054 getSema().CheckCXXThisCapture(E->getLocStart());
10058 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
10061 template<typename Derived>
10063 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
10064 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10065 if (SubExpr.isInvalid())
10066 return ExprError();
10068 if (!getDerived().AlwaysRebuild() &&
10069 SubExpr.get() == E->getSubExpr())
10072 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10073 E->isThrownVariableInScope());
10076 template<typename Derived>
10078 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
10080 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
10083 return ExprError();
10085 if (!getDerived().AlwaysRebuild() &&
10086 Param == E->getParam())
10089 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
10092 template<typename Derived>
10094 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
10096 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
10099 return ExprError();
10101 if (!getDerived().AlwaysRebuild() && Field == E->getField())
10104 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10107 template<typename Derived>
10109 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10110 CXXScalarValueInitExpr *E) {
10111 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10113 return ExprError();
10115 if (!getDerived().AlwaysRebuild() &&
10116 T == E->getTypeSourceInfo())
10119 return getDerived().RebuildCXXScalarValueInitExpr(T,
10120 /*FIXME:*/T->getTypeLoc().getEndLoc(),
10121 E->getRParenLoc());
10124 template<typename Derived>
10126 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
10127 // Transform the type that we're allocating
10128 TypeSourceInfo *AllocTypeInfo =
10129 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
10130 if (!AllocTypeInfo)
10131 return ExprError();
10133 // Transform the size of the array we're allocating (if any).
10134 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
10135 if (ArraySize.isInvalid())
10136 return ExprError();
10138 // Transform the placement arguments (if any).
10139 bool ArgumentChanged = false;
10140 SmallVector<Expr*, 8> PlacementArgs;
10141 if (getDerived().TransformExprs(E->getPlacementArgs(),
10142 E->getNumPlacementArgs(), true,
10143 PlacementArgs, &ArgumentChanged))
10144 return ExprError();
10146 // Transform the initializer (if any).
10147 Expr *OldInit = E->getInitializer();
10148 ExprResult NewInit;
10150 NewInit = getDerived().TransformInitializer(OldInit, true);
10151 if (NewInit.isInvalid())
10152 return ExprError();
10154 // Transform new operator and delete operator.
10155 FunctionDecl *OperatorNew = nullptr;
10156 if (E->getOperatorNew()) {
10157 OperatorNew = cast_or_null<FunctionDecl>(
10158 getDerived().TransformDecl(E->getLocStart(),
10159 E->getOperatorNew()));
10161 return ExprError();
10164 FunctionDecl *OperatorDelete = nullptr;
10165 if (E->getOperatorDelete()) {
10166 OperatorDelete = cast_or_null<FunctionDecl>(
10167 getDerived().TransformDecl(E->getLocStart(),
10168 E->getOperatorDelete()));
10169 if (!OperatorDelete)
10170 return ExprError();
10173 if (!getDerived().AlwaysRebuild() &&
10174 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
10175 ArraySize.get() == E->getArraySize() &&
10176 NewInit.get() == OldInit &&
10177 OperatorNew == E->getOperatorNew() &&
10178 OperatorDelete == E->getOperatorDelete() &&
10179 !ArgumentChanged) {
10180 // Mark any declarations we need as referenced.
10181 // FIXME: instantiation-specific.
10183 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
10184 if (OperatorDelete)
10185 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
10187 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
10188 QualType ElementType
10189 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10190 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10191 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10192 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
10193 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
10201 QualType AllocType = AllocTypeInfo->getType();
10202 if (!ArraySize.get()) {
10203 // If no array size was specified, but the new expression was
10204 // instantiated with an array type (e.g., "new T" where T is
10205 // instantiated with "int[4]"), extract the outer bound from the
10206 // array type as our array size. We do this with constant and
10207 // dependently-sized array types.
10208 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10211 } else if (const ConstantArrayType *ConsArrayT
10212 = dyn_cast<ConstantArrayType>(ArrayT)) {
10213 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10214 SemaRef.Context.getSizeType(),
10215 /*FIXME:*/ E->getLocStart());
10216 AllocType = ConsArrayT->getElementType();
10217 } else if (const DependentSizedArrayType *DepArrayT
10218 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10219 if (DepArrayT->getSizeExpr()) {
10220 ArraySize = DepArrayT->getSizeExpr();
10221 AllocType = DepArrayT->getElementType();
10226 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10228 /*FIXME:*/E->getLocStart(),
10230 /*FIXME:*/E->getLocStart(),
10231 E->getTypeIdParens(),
10235 E->getDirectInitRange(),
10239 template<typename Derived>
10241 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
10242 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
10243 if (Operand.isInvalid())
10244 return ExprError();
10246 // Transform the delete operator, if known.
10247 FunctionDecl *OperatorDelete = nullptr;
10248 if (E->getOperatorDelete()) {
10249 OperatorDelete = cast_or_null<FunctionDecl>(
10250 getDerived().TransformDecl(E->getLocStart(),
10251 E->getOperatorDelete()));
10252 if (!OperatorDelete)
10253 return ExprError();
10256 if (!getDerived().AlwaysRebuild() &&
10257 Operand.get() == E->getArgument() &&
10258 OperatorDelete == E->getOperatorDelete()) {
10259 // Mark any declarations we need as referenced.
10260 // FIXME: instantiation-specific.
10261 if (OperatorDelete)
10262 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
10264 if (!E->getArgument()->isTypeDependent()) {
10265 QualType Destroyed = SemaRef.Context.getBaseElementType(
10266 E->getDestroyedType());
10267 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10268 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
10269 SemaRef.MarkFunctionReferenced(E->getLocStart(),
10270 SemaRef.LookupDestructor(Record));
10277 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10278 E->isGlobalDelete(),
10283 template<typename Derived>
10285 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
10286 CXXPseudoDestructorExpr *E) {
10287 ExprResult Base = getDerived().TransformExpr(E->getBase());
10288 if (Base.isInvalid())
10289 return ExprError();
10291 ParsedType ObjectTypePtr;
10292 bool MayBePseudoDestructor = false;
10293 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10294 E->getOperatorLoc(),
10295 E->isArrow()? tok::arrow : tok::period,
10297 MayBePseudoDestructor);
10298 if (Base.isInvalid())
10299 return ExprError();
10301 QualType ObjectType = ObjectTypePtr.get();
10302 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10303 if (QualifierLoc) {
10305 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10307 return ExprError();
10310 SS.Adopt(QualifierLoc);
10312 PseudoDestructorTypeStorage Destroyed;
10313 if (E->getDestroyedTypeInfo()) {
10314 TypeSourceInfo *DestroyedTypeInfo
10315 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
10316 ObjectType, nullptr, SS);
10317 if (!DestroyedTypeInfo)
10318 return ExprError();
10319 Destroyed = DestroyedTypeInfo;
10320 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
10321 // We aren't likely to be able to resolve the identifier down to a type
10322 // now anyway, so just retain the identifier.
10323 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10324 E->getDestroyedTypeLoc());
10326 // Look for a destructor known with the given name.
10327 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
10328 *E->getDestroyedTypeIdentifier(),
10329 E->getDestroyedTypeLoc(),
10334 return ExprError();
10337 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10338 E->getDestroyedTypeLoc());
10341 TypeSourceInfo *ScopeTypeInfo = nullptr;
10342 if (E->getScopeTypeInfo()) {
10343 CXXScopeSpec EmptySS;
10344 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
10345 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
10346 if (!ScopeTypeInfo)
10347 return ExprError();
10350 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
10351 E->getOperatorLoc(),
10355 E->getColonColonLoc(),
10360 template <typename Derived>
10361 bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10364 // Transform all the decls.
10365 bool AllEmptyPacks = true;
10366 for (auto *OldD : Old->decls()) {
10367 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10369 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10370 // This can happen because of dependent hiding.
10371 if (isa<UsingShadowDecl>(OldD))
10379 // Expand using pack declarations.
10380 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10381 ArrayRef<NamedDecl*> Decls = SingleDecl;
10382 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10383 Decls = UPD->expansions();
10385 // Expand using declarations.
10386 for (auto *D : Decls) {
10387 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10388 for (auto *SD : UD->shadows())
10395 AllEmptyPacks &= Decls.empty();
10398 // C++ [temp.res]/8.4.2:
10399 // The program is ill-formed, no diagnostic required, if [...] lookup for
10400 // a name in the template definition found a using-declaration, but the
10401 // lookup in the corresponding scope in the instantiation odoes not find
10402 // any declarations because the using-declaration was a pack expansion and
10403 // the corresponding pack is empty
10404 if (AllEmptyPacks && !RequiresADL) {
10405 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10406 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10410 // Resolve a kind, but don't do any further analysis. If it's
10411 // ambiguous, the callee needs to deal with it.
10416 template<typename Derived>
10418 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
10419 UnresolvedLookupExpr *Old) {
10420 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10421 Sema::LookupOrdinaryName);
10423 // Transform the declaration set.
10424 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10425 return ExprError();
10427 // Rebuild the nested-name qualifier, if present.
10429 if (Old->getQualifierLoc()) {
10430 NestedNameSpecifierLoc QualifierLoc
10431 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10433 return ExprError();
10435 SS.Adopt(QualifierLoc);
10438 if (Old->getNamingClass()) {
10439 CXXRecordDecl *NamingClass
10440 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10442 Old->getNamingClass()));
10443 if (!NamingClass) {
10445 return ExprError();
10448 R.setNamingClass(NamingClass);
10451 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10453 // If we have neither explicit template arguments, nor the template keyword,
10454 // it's a normal declaration name or member reference.
10455 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10456 NamedDecl *D = R.getAsSingle<NamedDecl>();
10457 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10458 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10459 // give a good diagnostic.
10460 if (D && D->isCXXInstanceMember()) {
10461 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10462 /*TemplateArgs=*/nullptr,
10463 /*Scope=*/nullptr);
10466 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
10469 // If we have template arguments, rebuild them, then rebuild the
10470 // templateid expression.
10471 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
10472 if (Old->hasExplicitTemplateArgs() &&
10473 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10474 Old->getNumTemplateArgs(),
10477 return ExprError();
10480 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
10481 Old->requiresADL(), &TransArgs);
10484 template<typename Derived>
10486 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10487 bool ArgChanged = false;
10488 SmallVector<TypeSourceInfo *, 4> Args;
10489 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10490 TypeSourceInfo *From = E->getArg(I);
10491 TypeLoc FromTL = From->getTypeLoc();
10492 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
10493 TypeLocBuilder TLB;
10494 TLB.reserve(FromTL.getFullDataSize());
10495 QualType To = getDerived().TransformType(TLB, FromTL);
10497 return ExprError();
10499 if (To == From->getType())
10500 Args.push_back(From);
10502 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10510 // We have a pack expansion. Instantiate it.
10511 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
10512 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10513 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10514 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
10516 // Determine whether the set of unexpanded parameter packs can and should
10518 bool Expand = true;
10519 bool RetainExpansion = false;
10520 Optional<unsigned> OrigNumExpansions =
10521 ExpansionTL.getTypePtr()->getNumExpansions();
10522 Optional<unsigned> NumExpansions = OrigNumExpansions;
10523 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10524 PatternTL.getSourceRange(),
10526 Expand, RetainExpansion,
10528 return ExprError();
10531 // The transform has determined that we should perform a simple
10532 // transformation on the pack expansion, producing another pack
10534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10536 TypeLocBuilder TLB;
10537 TLB.reserve(From->getTypeLoc().getFullDataSize());
10539 QualType To = getDerived().TransformType(TLB, PatternTL);
10541 return ExprError();
10543 To = getDerived().RebuildPackExpansionType(To,
10544 PatternTL.getSourceRange(),
10545 ExpansionTL.getEllipsisLoc(),
10548 return ExprError();
10550 PackExpansionTypeLoc ToExpansionTL
10551 = TLB.push<PackExpansionTypeLoc>(To);
10552 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10553 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10557 // Expand the pack expansion by substituting for each argument in the
10559 for (unsigned I = 0; I != *NumExpansions; ++I) {
10560 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10561 TypeLocBuilder TLB;
10562 TLB.reserve(PatternTL.getFullDataSize());
10563 QualType To = getDerived().TransformType(TLB, PatternTL);
10565 return ExprError();
10567 if (To->containsUnexpandedParameterPack()) {
10568 To = getDerived().RebuildPackExpansionType(To,
10569 PatternTL.getSourceRange(),
10570 ExpansionTL.getEllipsisLoc(),
10573 return ExprError();
10575 PackExpansionTypeLoc ToExpansionTL
10576 = TLB.push<PackExpansionTypeLoc>(To);
10577 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10580 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10583 if (!RetainExpansion)
10586 // If we're supposed to retain a pack expansion, do so by temporarily
10587 // forgetting the partially-substituted parameter pack.
10588 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10590 TypeLocBuilder TLB;
10591 TLB.reserve(From->getTypeLoc().getFullDataSize());
10593 QualType To = getDerived().TransformType(TLB, PatternTL);
10595 return ExprError();
10597 To = getDerived().RebuildPackExpansionType(To,
10598 PatternTL.getSourceRange(),
10599 ExpansionTL.getEllipsisLoc(),
10602 return ExprError();
10604 PackExpansionTypeLoc ToExpansionTL
10605 = TLB.push<PackExpansionTypeLoc>(To);
10606 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10607 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10610 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10613 return getDerived().RebuildTypeTrait(E->getTrait(),
10619 template<typename Derived>
10621 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10622 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10624 return ExprError();
10626 if (!getDerived().AlwaysRebuild() &&
10627 T == E->getQueriedTypeSourceInfo())
10630 ExprResult SubExpr;
10632 EnterExpressionEvaluationContext Unevaluated(
10633 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
10634 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10635 if (SubExpr.isInvalid())
10636 return ExprError();
10638 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
10642 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10649 template<typename Derived>
10651 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10652 ExprResult SubExpr;
10654 EnterExpressionEvaluationContext Unevaluated(
10655 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
10656 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10657 if (SubExpr.isInvalid())
10658 return ExprError();
10660 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
10664 return getDerived().RebuildExpressionTrait(
10665 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10668 template <typename Derived>
10669 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10670 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10671 TypeSourceInfo **RecoveryTSI) {
10672 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10673 DRE, AddrTaken, RecoveryTSI);
10675 // Propagate both errors and recovered types, which return ExprEmpty.
10676 if (!NewDRE.isUsable())
10679 // We got an expr, wrap it up in parens.
10680 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10682 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10686 template <typename Derived>
10687 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10688 DependentScopeDeclRefExpr *E) {
10689 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10693 template<typename Derived>
10695 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10696 DependentScopeDeclRefExpr *E,
10697 bool IsAddressOfOperand,
10698 TypeSourceInfo **RecoveryTSI) {
10699 assert(E->getQualifierLoc());
10700 NestedNameSpecifierLoc QualifierLoc
10701 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10703 return ExprError();
10704 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10706 // TODO: If this is a conversion-function-id, verify that the
10707 // destination type name (if present) resolves the same way after
10708 // instantiation as it did in the local scope.
10710 DeclarationNameInfo NameInfo
10711 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10712 if (!NameInfo.getName())
10713 return ExprError();
10715 if (!E->hasExplicitTemplateArgs()) {
10716 if (!getDerived().AlwaysRebuild() &&
10717 QualifierLoc == E->getQualifierLoc() &&
10718 // Note: it is sufficient to compare the Name component of NameInfo:
10719 // if name has not changed, DNLoc has not changed either.
10720 NameInfo.getName() == E->getDeclName())
10723 return getDerived().RebuildDependentScopeDeclRefExpr(
10724 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10725 IsAddressOfOperand, RecoveryTSI);
10728 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10729 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10730 E->getNumTemplateArgs(),
10732 return ExprError();
10734 return getDerived().RebuildDependentScopeDeclRefExpr(
10735 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10739 template<typename Derived>
10741 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
10742 // CXXConstructExprs other than for list-initialization and
10743 // CXXTemporaryObjectExpr are always implicit, so when we have
10744 // a 1-argument construction we just transform that argument.
10745 if ((E->getNumArgs() == 1 ||
10746 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
10747 (!getDerived().DropCallArgument(E->getArg(0))) &&
10748 !E->isListInitialization())
10749 return getDerived().TransformExpr(E->getArg(0));
10751 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10753 QualType T = getDerived().TransformType(E->getType());
10755 return ExprError();
10757 CXXConstructorDecl *Constructor
10758 = cast_or_null<CXXConstructorDecl>(
10759 getDerived().TransformDecl(E->getLocStart(),
10760 E->getConstructor()));
10762 return ExprError();
10764 bool ArgumentChanged = false;
10765 SmallVector<Expr*, 8> Args;
10766 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10768 return ExprError();
10770 if (!getDerived().AlwaysRebuild() &&
10771 T == E->getType() &&
10772 Constructor == E->getConstructor() &&
10773 !ArgumentChanged) {
10774 // Mark the constructor as referenced.
10775 // FIXME: Instantiation-specific
10776 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10780 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
10782 E->isElidable(), Args,
10783 E->hadMultipleCandidates(),
10784 E->isListInitialization(),
10785 E->isStdInitListInitialization(),
10786 E->requiresZeroInitialization(),
10787 E->getConstructionKind(),
10788 E->getParenOrBraceRange());
10791 template<typename Derived>
10792 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10793 CXXInheritedCtorInitExpr *E) {
10794 QualType T = getDerived().TransformType(E->getType());
10796 return ExprError();
10798 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10799 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10801 return ExprError();
10803 if (!getDerived().AlwaysRebuild() &&
10804 T == E->getType() &&
10805 Constructor == E->getConstructor()) {
10806 // Mark the constructor as referenced.
10807 // FIXME: Instantiation-specific
10808 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10812 return getDerived().RebuildCXXInheritedCtorInitExpr(
10813 T, E->getLocation(), Constructor,
10814 E->constructsVBase(), E->inheritedFromVBase());
10817 /// \brief Transform a C++ temporary-binding expression.
10819 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10820 /// transform the subexpression and return that.
10821 template<typename Derived>
10823 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
10824 return getDerived().TransformExpr(E->getSubExpr());
10827 /// \brief Transform a C++ expression that contains cleanups that should
10828 /// be run after the expression is evaluated.
10830 /// Since ExprWithCleanups nodes are implicitly generated, we
10831 /// just transform the subexpression and return that.
10832 template<typename Derived>
10834 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
10835 return getDerived().TransformExpr(E->getSubExpr());
10838 template<typename Derived>
10840 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
10841 CXXTemporaryObjectExpr *E) {
10842 TypeSourceInfo *T =
10843 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
10845 return ExprError();
10847 CXXConstructorDecl *Constructor
10848 = cast_or_null<CXXConstructorDecl>(
10849 getDerived().TransformDecl(E->getLocStart(),
10850 E->getConstructor()));
10852 return ExprError();
10854 bool ArgumentChanged = false;
10855 SmallVector<Expr*, 8> Args;
10856 Args.reserve(E->getNumArgs());
10857 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10859 return ExprError();
10861 if (!getDerived().AlwaysRebuild() &&
10862 T == E->getTypeSourceInfo() &&
10863 Constructor == E->getConstructor() &&
10864 !ArgumentChanged) {
10865 // FIXME: Instantiation-specific
10866 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10867 return SemaRef.MaybeBindToTemporary(E);
10870 // FIXME: Pass in E->isListInitialization().
10871 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10872 /*FIXME:*/T->getTypeLoc().getEndLoc(),
10877 template<typename Derived>
10879 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
10880 // Transform any init-capture expressions before entering the scope of the
10881 // lambda body, because they are not semantically within that scope.
10882 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
10883 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10884 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
10885 E->explicit_capture_begin());
10886 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10887 CEnd = E->capture_end();
10889 if (!E->isInitCapture(C))
10891 EnterExpressionEvaluationContext EEEC(
10892 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
10893 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10894 C->getCapturedVar()->getInit(),
10895 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
10897 if (NewExprInitResult.isInvalid())
10898 return ExprError();
10899 Expr *NewExprInit = NewExprInitResult.get();
10901 VarDecl *OldVD = C->getCapturedVar();
10902 QualType NewInitCaptureType =
10903 getSema().buildLambdaInitCaptureInitialization(
10904 C->getLocation(), OldVD->getType()->isReferenceType(),
10905 OldVD->getIdentifier(),
10906 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
10907 NewExprInitResult = NewExprInit;
10908 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10909 std::make_pair(NewExprInitResult, NewInitCaptureType);
10912 // Transform the template parameters, and add them to the current
10913 // instantiation scope. The null case is handled correctly.
10914 auto TPL = getDerived().TransformTemplateParameterList(
10915 E->getTemplateParameterList());
10917 // Transform the type of the original lambda's call operator.
10918 // The transformation MUST be done in the CurrentInstantiationScope since
10919 // it introduces a mapping of the original to the newly created
10920 // transformed parameters.
10921 TypeSourceInfo *NewCallOpTSI = nullptr;
10923 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10924 FunctionProtoTypeLoc OldCallOpFPTL =
10925 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
10927 TypeLocBuilder NewCallOpTLBuilder;
10928 SmallVector<QualType, 4> ExceptionStorage;
10929 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
10930 QualType NewCallOpType = TransformFunctionProtoType(
10931 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
10932 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10933 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10934 ExceptionStorage, Changed);
10936 if (NewCallOpType.isNull())
10937 return ExprError();
10938 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10942 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10943 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10944 LSI->GLTemplateParameterList = TPL;
10946 // Create the local class that will describe the lambda.
10947 CXXRecordDecl *Class
10948 = getSema().createLambdaClosureType(E->getIntroducerRange(),
10950 /*KnownDependent=*/false,
10951 E->getCaptureDefault());
10952 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10954 // Build the call operator.
10955 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10956 Class, E->getIntroducerRange(), NewCallOpTSI,
10957 E->getCallOperator()->getLocEnd(),
10958 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10959 E->getCallOperator()->isConstexpr());
10961 LSI->CallOperator = NewCallOperator;
10963 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10964 I != NumParams; ++I) {
10965 auto *P = NewCallOperator->getParamDecl(I);
10966 if (P->hasUninstantiatedDefaultArg()) {
10967 EnterExpressionEvaluationContext Eval(
10969 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
10970 ExprResult R = getDerived().TransformExpr(
10971 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10972 P->setDefaultArg(R.get());
10976 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
10977 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
10979 // Introduce the context of the call operator.
10980 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
10981 /*NewThisContext*/false);
10983 // Enter the scope of the lambda.
10984 getSema().buildLambdaScope(LSI, NewCallOperator,
10985 E->getIntroducerRange(),
10986 E->getCaptureDefault(),
10987 E->getCaptureDefaultLoc(),
10988 E->hasExplicitParameters(),
10989 E->hasExplicitResultType(),
10992 bool Invalid = false;
10994 // Transform captures.
10995 bool FinishedExplicitCaptures = false;
10996 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10997 CEnd = E->capture_end();
10999 // When we hit the first implicit capture, tell Sema that we've finished
11000 // the list of explicit captures.
11001 if (!FinishedExplicitCaptures && C->isImplicit()) {
11002 getSema().finishLambdaExplicitCaptures(LSI);
11003 FinishedExplicitCaptures = true;
11006 // Capturing 'this' is trivial.
11007 if (C->capturesThis()) {
11008 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11009 /*BuildAndDiagnose*/ true, nullptr,
11010 C->getCaptureKind() == LCK_StarThis);
11013 // Captured expression will be recaptured during captured variables
11015 if (C->capturesVLAType())
11018 // Rebuild init-captures, including the implied field declaration.
11019 if (E->isInitCapture(C)) {
11020 InitCaptureInfoTy InitExprTypePair =
11021 InitCaptureExprsAndTypes[C - E->capture_begin()];
11022 ExprResult Init = InitExprTypePair.first;
11023 QualType InitQualType = InitExprTypePair.second;
11024 if (Init.isInvalid() || InitQualType.isNull()) {
11028 VarDecl *OldVD = C->getCapturedVar();
11029 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
11030 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
11031 OldVD->getInitStyle(), Init.get());
11035 getDerived().transformedLocalDecl(OldVD, NewVD);
11037 getSema().buildInitCaptureField(LSI, NewVD);
11041 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11043 // Determine the capture kind for Sema.
11044 Sema::TryCaptureKind Kind
11045 = C->isImplicit()? Sema::TryCapture_Implicit
11046 : C->getCaptureKind() == LCK_ByCopy
11047 ? Sema::TryCapture_ExplicitByVal
11048 : Sema::TryCapture_ExplicitByRef;
11049 SourceLocation EllipsisLoc;
11050 if (C->isPackExpansion()) {
11051 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11052 bool ShouldExpand = false;
11053 bool RetainExpansion = false;
11054 Optional<unsigned> NumExpansions;
11055 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11058 ShouldExpand, RetainExpansion,
11064 if (ShouldExpand) {
11065 // The transform has determined that we should perform an expansion;
11066 // transform and capture each of the arguments.
11067 // expansion of the pattern. Do so.
11068 VarDecl *Pack = C->getCapturedVar();
11069 for (unsigned I = 0; I != *NumExpansions; ++I) {
11070 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11071 VarDecl *CapturedVar
11072 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
11074 if (!CapturedVar) {
11079 // Capture the transformed variable.
11080 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11083 // FIXME: Retain a pack expansion if RetainExpansion is true.
11088 EllipsisLoc = C->getEllipsisLoc();
11091 // Transform the captured variable.
11092 VarDecl *CapturedVar
11093 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
11094 C->getCapturedVar()));
11095 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
11100 // Capture the transformed variable.
11101 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11104 if (!FinishedExplicitCaptures)
11105 getSema().finishLambdaExplicitCaptures(LSI);
11107 // Enter a new evaluation context to insulate the lambda from any
11108 // cleanups from the enclosing full-expression.
11109 getSema().PushExpressionEvaluationContext(
11110 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
11112 // Instantiate the body of the lambda expression.
11114 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11116 // ActOnLambda* will pop the function scope for us.
11117 FuncScopeCleanup.disable();
11119 if (Body.isInvalid()) {
11120 SavedContext.pop();
11121 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
11122 /*IsInstantiation=*/true);
11123 return ExprError();
11126 // Copy the LSI before ActOnFinishFunctionBody removes it.
11127 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11128 // the call operator.
11129 auto LSICopy = *LSI;
11130 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11131 /*IsInstantiation*/ true);
11132 SavedContext.pop();
11134 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11138 template<typename Derived>
11140 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
11141 CXXUnresolvedConstructExpr *E) {
11142 TypeSourceInfo *T =
11143 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
11145 return ExprError();
11147 bool ArgumentChanged = false;
11148 SmallVector<Expr*, 8> Args;
11149 Args.reserve(E->arg_size());
11150 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11152 return ExprError();
11154 if (!getDerived().AlwaysRebuild() &&
11155 T == E->getTypeSourceInfo() &&
11159 // FIXME: we're faking the locations of the commas
11160 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
11163 E->getRParenLoc());
11166 template<typename Derived>
11168 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
11169 CXXDependentScopeMemberExpr *E) {
11170 // Transform the base of the expression.
11171 ExprResult Base((Expr*) nullptr);
11174 QualType ObjectType;
11175 if (!E->isImplicitAccess()) {
11176 OldBase = E->getBase();
11177 Base = getDerived().TransformExpr(OldBase);
11178 if (Base.isInvalid())
11179 return ExprError();
11181 // Start the member reference and compute the object's type.
11182 ParsedType ObjectTy;
11183 bool MayBePseudoDestructor = false;
11184 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
11185 E->getOperatorLoc(),
11186 E->isArrow()? tok::arrow : tok::period,
11188 MayBePseudoDestructor);
11189 if (Base.isInvalid())
11190 return ExprError();
11192 ObjectType = ObjectTy.get();
11193 BaseType = ((Expr*) Base.get())->getType();
11196 BaseType = getDerived().TransformType(E->getBaseType());
11197 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11200 // Transform the first part of the nested-name-specifier that qualifies
11201 // the member name.
11202 NamedDecl *FirstQualifierInScope
11203 = getDerived().TransformFirstQualifierInScope(
11204 E->getFirstQualifierFoundInScope(),
11205 E->getQualifierLoc().getBeginLoc());
11207 NestedNameSpecifierLoc QualifierLoc;
11208 if (E->getQualifier()) {
11210 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11212 FirstQualifierInScope);
11214 return ExprError();
11217 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11219 // TODO: If this is a conversion-function-id, verify that the
11220 // destination type name (if present) resolves the same way after
11221 // instantiation as it did in the local scope.
11223 DeclarationNameInfo NameInfo
11224 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
11225 if (!NameInfo.getName())
11226 return ExprError();
11228 if (!E->hasExplicitTemplateArgs()) {
11229 // This is a reference to a member without an explicitly-specified
11230 // template argument list. Optimize for this common case.
11231 if (!getDerived().AlwaysRebuild() &&
11232 Base.get() == OldBase &&
11233 BaseType == E->getBaseType() &&
11234 QualifierLoc == E->getQualifierLoc() &&
11235 NameInfo.getName() == E->getMember() &&
11236 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
11239 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
11242 E->getOperatorLoc(),
11245 FirstQualifierInScope,
11247 /*TemplateArgs*/nullptr);
11250 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
11251 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11252 E->getNumTemplateArgs(),
11254 return ExprError();
11256 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
11259 E->getOperatorLoc(),
11262 FirstQualifierInScope,
11267 template<typename Derived>
11269 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
11270 // Transform the base of the expression.
11271 ExprResult Base((Expr*) nullptr);
11273 if (!Old->isImplicitAccess()) {
11274 Base = getDerived().TransformExpr(Old->getBase());
11275 if (Base.isInvalid())
11276 return ExprError();
11277 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
11279 if (Base.isInvalid())
11280 return ExprError();
11281 BaseType = Base.get()->getType();
11283 BaseType = getDerived().TransformType(Old->getBaseType());
11286 NestedNameSpecifierLoc QualifierLoc;
11287 if (Old->getQualifierLoc()) {
11289 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11291 return ExprError();
11294 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11296 LookupResult R(SemaRef, Old->getMemberNameInfo(),
11297 Sema::LookupOrdinaryName);
11299 // Transform the declaration set.
11300 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11301 return ExprError();
11303 // Determine the naming class.
11304 if (Old->getNamingClass()) {
11305 CXXRecordDecl *NamingClass
11306 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
11307 Old->getMemberLoc(),
11308 Old->getNamingClass()));
11310 return ExprError();
11312 R.setNamingClass(NamingClass);
11315 TemplateArgumentListInfo TransArgs;
11316 if (Old->hasExplicitTemplateArgs()) {
11317 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11318 TransArgs.setRAngleLoc(Old->getRAngleLoc());
11319 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11320 Old->getNumTemplateArgs(),
11322 return ExprError();
11325 // FIXME: to do this check properly, we will need to preserve the
11326 // first-qualifier-in-scope here, just in case we had a dependent
11327 // base (and therefore couldn't do the check) and a
11328 // nested-name-qualifier (and therefore could do the lookup).
11329 NamedDecl *FirstQualifierInScope = nullptr;
11331 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
11333 Old->getOperatorLoc(),
11337 FirstQualifierInScope,
11339 (Old->hasExplicitTemplateArgs()
11340 ? &TransArgs : nullptr));
11343 template<typename Derived>
11345 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
11346 EnterExpressionEvaluationContext Unevaluated(
11347 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
11348 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11349 if (SubExpr.isInvalid())
11350 return ExprError();
11352 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
11355 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11358 template<typename Derived>
11360 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
11361 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11362 if (Pattern.isInvalid())
11363 return ExprError();
11365 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
11368 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11369 E->getNumExpansions());
11372 template<typename Derived>
11374 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11375 // If E is not value-dependent, then nothing will change when we transform it.
11376 // Note: This is an instantiation-centric view.
11377 if (!E->isValueDependent())
11380 EnterExpressionEvaluationContext Unevaluated(
11381 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
11383 ArrayRef<TemplateArgument> PackArgs;
11384 TemplateArgument ArgStorage;
11386 // Find the argument list to transform.
11387 if (E->isPartiallySubstituted()) {
11388 PackArgs = E->getPartialArguments();
11389 } else if (E->isValueDependent()) {
11390 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11391 bool ShouldExpand = false;
11392 bool RetainExpansion = false;
11393 Optional<unsigned> NumExpansions;
11394 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11396 ShouldExpand, RetainExpansion,
11398 return ExprError();
11400 // If we need to expand the pack, build a template argument from it and
11402 if (ShouldExpand) {
11403 auto *Pack = E->getPack();
11404 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11405 ArgStorage = getSema().Context.getPackExpansionType(
11406 getSema().Context.getTypeDeclType(TTPD), None);
11407 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11408 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11410 auto *VD = cast<ValueDecl>(Pack);
11411 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11412 VK_RValue, E->getPackLoc());
11413 if (DRE.isInvalid())
11414 return ExprError();
11415 ArgStorage = new (getSema().Context) PackExpansionExpr(
11416 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11418 PackArgs = ArgStorage;
11422 // If we're not expanding the pack, just transform the decl.
11423 if (!PackArgs.size()) {
11424 auto *Pack = cast_or_null<NamedDecl>(
11425 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
11427 return ExprError();
11428 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11430 E->getRParenLoc(), None, None);
11433 // Try to compute the result without performing a partial substitution.
11434 Optional<unsigned> Result = 0;
11435 for (const TemplateArgument &Arg : PackArgs) {
11436 if (!Arg.isPackExpansion()) {
11437 Result = *Result + 1;
11441 TemplateArgumentLoc ArgLoc;
11442 InventTemplateArgumentLoc(Arg, ArgLoc);
11444 // Find the pattern of the pack expansion.
11445 SourceLocation Ellipsis;
11446 Optional<unsigned> OrigNumExpansions;
11447 TemplateArgumentLoc Pattern =
11448 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11449 OrigNumExpansions);
11451 // Substitute under the pack expansion. Do not expand the pack (yet).
11452 TemplateArgumentLoc OutPattern;
11453 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11454 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11458 // See if we can determine the number of arguments from the result.
11459 Optional<unsigned> NumExpansions =
11460 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11461 if (!NumExpansions) {
11462 // No: we must be in an alias template expansion, and we're going to need
11463 // to actually expand the packs.
11468 Result = *Result + *NumExpansions;
11471 // Common case: we could determine the number of expansions without
11474 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11476 E->getRParenLoc(), *Result, None);
11478 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11481 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11482 typedef TemplateArgumentLocInventIterator<
11483 Derived, const TemplateArgument*> PackLocIterator;
11484 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11485 PackLocIterator(*this, PackArgs.end()),
11486 TransformedPackArgs, /*Uneval*/true))
11487 return ExprError();
11490 // Check whether we managed to fully-expand the pack.
11491 // FIXME: Is it possible for us to do so and not hit the early exit path?
11492 SmallVector<TemplateArgument, 8> Args;
11493 bool PartialSubstitution = false;
11494 for (auto &Loc : TransformedPackArgs.arguments()) {
11495 Args.push_back(Loc.getArgument());
11496 if (Loc.getArgument().isPackExpansion())
11497 PartialSubstitution = true;
11500 if (PartialSubstitution)
11501 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11503 E->getRParenLoc(), None, Args);
11505 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11506 E->getPackLoc(), E->getRParenLoc(),
11507 Args.size(), None);
11510 template<typename Derived>
11512 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11513 SubstNonTypeTemplateParmPackExpr *E) {
11514 // Default behavior is to do nothing with this transformation.
11518 template<typename Derived>
11520 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11521 SubstNonTypeTemplateParmExpr *E) {
11522 // Default behavior is to do nothing with this transformation.
11526 template<typename Derived>
11528 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11529 // Default behavior is to do nothing with this transformation.
11533 template<typename Derived>
11535 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11536 MaterializeTemporaryExpr *E) {
11537 return getDerived().TransformExpr(E->GetTemporaryExpr());
11540 template<typename Derived>
11542 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11543 Expr *Pattern = E->getPattern();
11545 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11546 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11547 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11549 // Determine whether the set of unexpanded parameter packs can and should
11551 bool Expand = true;
11552 bool RetainExpansion = false;
11553 Optional<unsigned> NumExpansions;
11554 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11555 Pattern->getSourceRange(),
11557 Expand, RetainExpansion,
11562 // Do not expand any packs here, just transform and rebuild a fold
11564 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11567 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11568 if (LHS.isInvalid())
11572 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11573 if (RHS.isInvalid())
11576 if (!getDerived().AlwaysRebuild() &&
11577 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11580 return getDerived().RebuildCXXFoldExpr(
11581 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11582 RHS.get(), E->getLocEnd());
11585 // The transform has determined that we should perform an elementwise
11586 // expansion of the pattern. Do so.
11587 ExprResult Result = getDerived().TransformExpr(E->getInit());
11588 if (Result.isInvalid())
11590 bool LeftFold = E->isLeftFold();
11592 // If we're retaining an expansion for a right fold, it is the innermost
11593 // component and takes the init (if any).
11594 if (!LeftFold && RetainExpansion) {
11595 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11597 ExprResult Out = getDerived().TransformExpr(Pattern);
11598 if (Out.isInvalid())
11601 Result = getDerived().RebuildCXXFoldExpr(
11602 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11603 Result.get(), E->getLocEnd());
11604 if (Result.isInvalid())
11608 for (unsigned I = 0; I != *NumExpansions; ++I) {
11609 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11610 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11611 ExprResult Out = getDerived().TransformExpr(Pattern);
11612 if (Out.isInvalid())
11615 if (Out.get()->containsUnexpandedParameterPack()) {
11616 // We still have a pack; retain a pack expansion for this slice.
11617 Result = getDerived().RebuildCXXFoldExpr(
11619 LeftFold ? Result.get() : Out.get(),
11620 E->getOperator(), E->getEllipsisLoc(),
11621 LeftFold ? Out.get() : Result.get(),
11623 } else if (Result.isUsable()) {
11624 // We've got down to a single element; build a binary operator.
11625 Result = getDerived().RebuildBinaryOperator(
11626 E->getEllipsisLoc(), E->getOperator(),
11627 LeftFold ? Result.get() : Out.get(),
11628 LeftFold ? Out.get() : Result.get());
11632 if (Result.isInvalid())
11636 // If we're retaining an expansion for a left fold, it is the outermost
11637 // component and takes the complete expansion so far as its init (if any).
11638 if (LeftFold && RetainExpansion) {
11639 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11641 ExprResult Out = getDerived().TransformExpr(Pattern);
11642 if (Out.isInvalid())
11645 Result = getDerived().RebuildCXXFoldExpr(
11646 E->getLocStart(), Result.get(),
11647 E->getOperator(), E->getEllipsisLoc(),
11648 Out.get(), E->getLocEnd());
11649 if (Result.isInvalid())
11653 // If we had no init and an empty pack, and we're not retaining an expansion,
11654 // then produce a fallback value or error.
11655 if (Result.isUnset())
11656 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11662 template<typename Derived>
11664 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11665 CXXStdInitializerListExpr *E) {
11666 return getDerived().TransformExpr(E->getSubExpr());
11669 template<typename Derived>
11671 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
11672 return SemaRef.MaybeBindToTemporary(E);
11675 template<typename Derived>
11677 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
11681 template<typename Derived>
11683 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11684 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11685 if (SubExpr.isInvalid())
11686 return ExprError();
11688 if (!getDerived().AlwaysRebuild() &&
11689 SubExpr.get() == E->getSubExpr())
11692 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
11695 template<typename Derived>
11697 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11698 // Transform each of the elements.
11699 SmallVector<Expr *, 8> Elements;
11700 bool ArgChanged = false;
11701 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
11702 /*IsCall=*/false, Elements, &ArgChanged))
11703 return ExprError();
11705 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11706 return SemaRef.MaybeBindToTemporary(E);
11708 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11713 template<typename Derived>
11715 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
11716 ObjCDictionaryLiteral *E) {
11717 // Transform each of the elements.
11718 SmallVector<ObjCDictionaryElement, 8> Elements;
11719 bool ArgChanged = false;
11720 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11721 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
11723 if (OrigElement.isPackExpansion()) {
11724 // This key/value element is a pack expansion.
11725 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11726 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11727 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11728 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11730 // Determine whether the set of unexpanded parameter packs can
11731 // and should be expanded.
11732 bool Expand = true;
11733 bool RetainExpansion = false;
11734 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11735 Optional<unsigned> NumExpansions = OrigNumExpansions;
11736 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11737 OrigElement.Value->getLocEnd());
11738 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11741 Expand, RetainExpansion,
11743 return ExprError();
11746 // The transform has determined that we should perform a simple
11747 // transformation on the pack expansion, producing another pack
11749 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11750 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11751 if (Key.isInvalid())
11752 return ExprError();
11754 if (Key.get() != OrigElement.Key)
11757 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11758 if (Value.isInvalid())
11759 return ExprError();
11761 if (Value.get() != OrigElement.Value)
11764 ObjCDictionaryElement Expansion = {
11765 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11767 Elements.push_back(Expansion);
11771 // Record right away that the argument was changed. This needs
11772 // to happen even if the array expands to nothing.
11775 // The transform has determined that we should perform an elementwise
11776 // expansion of the pattern. Do so.
11777 for (unsigned I = 0; I != *NumExpansions; ++I) {
11778 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11779 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11780 if (Key.isInvalid())
11781 return ExprError();
11783 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11784 if (Value.isInvalid())
11785 return ExprError();
11787 ObjCDictionaryElement Element = {
11788 Key.get(), Value.get(), SourceLocation(), NumExpansions
11791 // If any unexpanded parameter packs remain, we still have a
11793 // FIXME: Can this really happen?
11794 if (Key.get()->containsUnexpandedParameterPack() ||
11795 Value.get()->containsUnexpandedParameterPack())
11796 Element.EllipsisLoc = OrigElement.EllipsisLoc;
11798 Elements.push_back(Element);
11801 // FIXME: Retain a pack expansion if RetainExpansion is true.
11803 // We've finished with this pack expansion.
11807 // Transform and check key.
11808 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11809 if (Key.isInvalid())
11810 return ExprError();
11812 if (Key.get() != OrigElement.Key)
11815 // Transform and check value.
11817 = getDerived().TransformExpr(OrigElement.Value);
11818 if (Value.isInvalid())
11819 return ExprError();
11821 if (Value.get() != OrigElement.Value)
11824 ObjCDictionaryElement Element = {
11825 Key.get(), Value.get(), SourceLocation(), None
11827 Elements.push_back(Element);
11830 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11831 return SemaRef.MaybeBindToTemporary(E);
11833 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
11837 template<typename Derived>
11839 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
11840 TypeSourceInfo *EncodedTypeInfo
11841 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11842 if (!EncodedTypeInfo)
11843 return ExprError();
11845 if (!getDerived().AlwaysRebuild() &&
11846 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
11849 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
11851 E->getRParenLoc());
11854 template<typename Derived>
11855 ExprResult TreeTransform<Derived>::
11856 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
11857 // This is a kind of implicit conversion, and it needs to get dropped
11858 // and recomputed for the same general reasons that ImplicitCastExprs
11859 // do, as well a more specific one: this expression is only valid when
11860 // it appears *immediately* as an argument expression.
11861 return getDerived().TransformExpr(E->getSubExpr());
11864 template<typename Derived>
11865 ExprResult TreeTransform<Derived>::
11866 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
11867 TypeSourceInfo *TSInfo
11868 = getDerived().TransformType(E->getTypeInfoAsWritten());
11870 return ExprError();
11872 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
11873 if (Result.isInvalid())
11874 return ExprError();
11876 if (!getDerived().AlwaysRebuild() &&
11877 TSInfo == E->getTypeInfoAsWritten() &&
11878 Result.get() == E->getSubExpr())
11881 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
11882 E->getBridgeKeywordLoc(), TSInfo,
11886 template <typename Derived>
11887 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11888 ObjCAvailabilityCheckExpr *E) {
11892 template<typename Derived>
11894 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
11895 // Transform arguments.
11896 bool ArgChanged = false;
11897 SmallVector<Expr*, 8> Args;
11898 Args.reserve(E->getNumArgs());
11899 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
11901 return ExprError();
11903 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11904 // Class message: transform the receiver type.
11905 TypeSourceInfo *ReceiverTypeInfo
11906 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11907 if (!ReceiverTypeInfo)
11908 return ExprError();
11910 // If nothing changed, just retain the existing message send.
11911 if (!getDerived().AlwaysRebuild() &&
11912 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
11913 return SemaRef.MaybeBindToTemporary(E);
11915 // Build a new class message send.
11916 SmallVector<SourceLocation, 16> SelLocs;
11917 E->getSelectorLocs(SelLocs);
11918 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11921 E->getMethodDecl(),
11926 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11927 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11928 if (!E->getMethodDecl())
11929 return ExprError();
11931 // Build a new class message send to 'super'.
11932 SmallVector<SourceLocation, 16> SelLocs;
11933 E->getSelectorLocs(SelLocs);
11934 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11937 E->getReceiverType(),
11938 E->getMethodDecl(),
11944 // Instance message: transform the receiver
11945 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11946 "Only class and instance messages may be instantiated");
11947 ExprResult Receiver
11948 = getDerived().TransformExpr(E->getInstanceReceiver());
11949 if (Receiver.isInvalid())
11950 return ExprError();
11952 // If nothing changed, just retain the existing message send.
11953 if (!getDerived().AlwaysRebuild() &&
11954 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
11955 return SemaRef.MaybeBindToTemporary(E);
11957 // Build a new instance message send.
11958 SmallVector<SourceLocation, 16> SelLocs;
11959 E->getSelectorLocs(SelLocs);
11960 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
11963 E->getMethodDecl(),
11969 template<typename Derived>
11971 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
11975 template<typename Derived>
11977 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
11981 template<typename Derived>
11983 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
11984 // Transform the base expression.
11985 ExprResult Base = getDerived().TransformExpr(E->getBase());
11986 if (Base.isInvalid())
11987 return ExprError();
11989 // We don't need to transform the ivar; it will never change.
11991 // If nothing changed, just retain the existing expression.
11992 if (!getDerived().AlwaysRebuild() &&
11993 Base.get() == E->getBase())
11996 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
11998 E->isArrow(), E->isFreeIvar());
12001 template<typename Derived>
12003 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
12004 // 'super' and types never change. Property never changes. Just
12005 // retain the existing expression.
12006 if (!E->isObjectReceiver())
12009 // Transform the base expression.
12010 ExprResult Base = getDerived().TransformExpr(E->getBase());
12011 if (Base.isInvalid())
12012 return ExprError();
12014 // We don't need to transform the property; it will never change.
12016 // If nothing changed, just retain the existing expression.
12017 if (!getDerived().AlwaysRebuild() &&
12018 Base.get() == E->getBase())
12021 if (E->isExplicitProperty())
12022 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12023 E->getExplicitProperty(),
12026 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12027 SemaRef.Context.PseudoObjectTy,
12028 E->getImplicitPropertyGetter(),
12029 E->getImplicitPropertySetter(),
12033 template<typename Derived>
12035 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12036 // Transform the base expression.
12037 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12038 if (Base.isInvalid())
12039 return ExprError();
12041 // Transform the key expression.
12042 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12043 if (Key.isInvalid())
12044 return ExprError();
12046 // If nothing changed, just retain the existing expression.
12047 if (!getDerived().AlwaysRebuild() &&
12048 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
12051 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
12052 Base.get(), Key.get(),
12053 E->getAtIndexMethodDecl(),
12054 E->setAtIndexMethodDecl());
12057 template<typename Derived>
12059 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
12060 // Transform the base expression.
12061 ExprResult Base = getDerived().TransformExpr(E->getBase());
12062 if (Base.isInvalid())
12063 return ExprError();
12065 // If nothing changed, just retain the existing expression.
12066 if (!getDerived().AlwaysRebuild() &&
12067 Base.get() == E->getBase())
12070 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
12075 template<typename Derived>
12077 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
12078 bool ArgumentChanged = false;
12079 SmallVector<Expr*, 8> SubExprs;
12080 SubExprs.reserve(E->getNumSubExprs());
12081 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12082 SubExprs, &ArgumentChanged))
12083 return ExprError();
12085 if (!getDerived().AlwaysRebuild() &&
12089 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
12091 E->getRParenLoc());
12094 template<typename Derived>
12096 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12097 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12098 if (SrcExpr.isInvalid())
12099 return ExprError();
12101 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12103 return ExprError();
12105 if (!getDerived().AlwaysRebuild() &&
12106 Type == E->getTypeSourceInfo() &&
12107 SrcExpr.get() == E->getSrcExpr())
12110 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12111 SrcExpr.get(), Type,
12112 E->getRParenLoc());
12115 template<typename Derived>
12117 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
12118 BlockDecl *oldBlock = E->getBlockDecl();
12120 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
12121 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12123 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
12124 blockScope->TheDecl->setBlockMissingReturnType(
12125 oldBlock->blockMissingReturnType());
12127 SmallVector<ParmVarDecl*, 4> params;
12128 SmallVector<QualType, 4> paramTypes;
12130 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12132 // Parameter substitution.
12133 Sema::ExtParameterInfoBuilder extParamInfos;
12134 if (getDerived().TransformFunctionTypeParams(
12135 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12136 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms,
12138 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
12139 return ExprError();
12142 QualType exprResultType =
12143 getDerived().TransformType(exprFunctionType->getReturnType());
12145 auto epi = exprFunctionType->getExtProtoInfo();
12146 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12148 QualType functionType =
12149 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
12150 blockScope->FunctionType = functionType;
12152 // Set the parameters on the block decl.
12153 if (!params.empty())
12154 blockScope->TheDecl->setParams(params);
12156 if (!oldBlock->blockMissingReturnType()) {
12157 blockScope->HasImplicitReturnType = false;
12158 blockScope->ReturnType = exprResultType;
12161 // Transform the body
12162 StmtResult body = getDerived().TransformStmt(E->getBody());
12163 if (body.isInvalid()) {
12164 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
12165 return ExprError();
12169 // In builds with assertions, make sure that we captured everything we
12170 // captured before.
12171 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
12172 for (const auto &I : oldBlock->captures()) {
12173 VarDecl *oldCapture = I.getVariable();
12175 // Ignore parameter packs.
12176 if (isa<ParmVarDecl>(oldCapture) &&
12177 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12180 VarDecl *newCapture =
12181 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12183 assert(blockScope->CaptureMap.count(newCapture));
12185 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
12189 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
12190 /*Scope=*/nullptr);
12193 template<typename Derived>
12195 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
12196 llvm_unreachable("Cannot transform asType expressions yet");
12199 template<typename Derived>
12201 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
12202 QualType RetTy = getDerived().TransformType(E->getType());
12203 bool ArgumentChanged = false;
12204 SmallVector<Expr*, 8> SubExprs;
12205 SubExprs.reserve(E->getNumSubExprs());
12206 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12207 SubExprs, &ArgumentChanged))
12208 return ExprError();
12210 if (!getDerived().AlwaysRebuild() &&
12214 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
12215 RetTy, E->getOp(), E->getRParenLoc());
12218 //===----------------------------------------------------------------------===//
12219 // Type reconstruction
12220 //===----------------------------------------------------------------------===//
12222 template<typename Derived>
12223 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12224 SourceLocation Star) {
12225 return SemaRef.BuildPointerType(PointeeType, Star,
12226 getDerived().getBaseEntity());
12229 template<typename Derived>
12230 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12231 SourceLocation Star) {
12232 return SemaRef.BuildBlockPointerType(PointeeType, Star,
12233 getDerived().getBaseEntity());
12236 template<typename Derived>
12238 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12239 bool WrittenAsLValue,
12240 SourceLocation Sigil) {
12241 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
12242 Sigil, getDerived().getBaseEntity());
12245 template<typename Derived>
12247 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12248 QualType ClassType,
12249 SourceLocation Sigil) {
12250 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12251 getDerived().getBaseEntity());
12254 template<typename Derived>
12255 QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12256 const ObjCTypeParamDecl *Decl,
12257 SourceLocation ProtocolLAngleLoc,
12258 ArrayRef<ObjCProtocolDecl *> Protocols,
12259 ArrayRef<SourceLocation> ProtocolLocs,
12260 SourceLocation ProtocolRAngleLoc) {
12261 return SemaRef.BuildObjCTypeParamType(Decl,
12262 ProtocolLAngleLoc, Protocols,
12263 ProtocolLocs, ProtocolRAngleLoc,
12264 /*FailOnError=*/true);
12267 template<typename Derived>
12268 QualType TreeTransform<Derived>::RebuildObjCObjectType(
12270 SourceLocation Loc,
12271 SourceLocation TypeArgsLAngleLoc,
12272 ArrayRef<TypeSourceInfo *> TypeArgs,
12273 SourceLocation TypeArgsRAngleLoc,
12274 SourceLocation ProtocolLAngleLoc,
12275 ArrayRef<ObjCProtocolDecl *> Protocols,
12276 ArrayRef<SourceLocation> ProtocolLocs,
12277 SourceLocation ProtocolRAngleLoc) {
12278 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12279 TypeArgs, TypeArgsRAngleLoc,
12280 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12282 /*FailOnError=*/true);
12285 template<typename Derived>
12286 QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12287 QualType PointeeType,
12288 SourceLocation Star) {
12289 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12292 template<typename Derived>
12294 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12295 ArrayType::ArraySizeModifier SizeMod,
12296 const llvm::APInt *Size,
12298 unsigned IndexTypeQuals,
12299 SourceRange BracketsRange) {
12300 if (SizeExpr || !Size)
12301 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12302 IndexTypeQuals, BracketsRange,
12303 getDerived().getBaseEntity());
12305 QualType Types[] = {
12306 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12307 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12308 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
12310 const unsigned NumTypes = llvm::array_lengthof(Types);
12312 for (unsigned I = 0; I != NumTypes; ++I)
12313 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12314 SizeType = Types[I];
12318 // Note that we can return a VariableArrayType here in the case where
12319 // the element type was a dependent VariableArrayType.
12320 IntegerLiteral *ArraySize
12321 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12322 /*FIXME*/BracketsRange.getBegin());
12323 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
12324 IndexTypeQuals, BracketsRange,
12325 getDerived().getBaseEntity());
12328 template<typename Derived>
12330 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
12331 ArrayType::ArraySizeModifier SizeMod,
12332 const llvm::APInt &Size,
12333 unsigned IndexTypeQuals,
12334 SourceRange BracketsRange) {
12335 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
12336 IndexTypeQuals, BracketsRange);
12339 template<typename Derived>
12341 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
12342 ArrayType::ArraySizeModifier SizeMod,
12343 unsigned IndexTypeQuals,
12344 SourceRange BracketsRange) {
12345 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
12346 IndexTypeQuals, BracketsRange);
12349 template<typename Derived>
12351 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
12352 ArrayType::ArraySizeModifier SizeMod,
12354 unsigned IndexTypeQuals,
12355 SourceRange BracketsRange) {
12356 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
12358 IndexTypeQuals, BracketsRange);
12361 template<typename Derived>
12363 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
12364 ArrayType::ArraySizeModifier SizeMod,
12366 unsigned IndexTypeQuals,
12367 SourceRange BracketsRange) {
12368 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
12370 IndexTypeQuals, BracketsRange);
12373 template <typename Derived>
12374 QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12375 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12376 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12380 template <typename Derived>
12382 TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12383 unsigned NumElements,
12384 VectorType::VectorKind VecKind) {
12385 // FIXME: semantic checking!
12386 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
12389 template<typename Derived>
12390 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12391 unsigned NumElements,
12392 SourceLocation AttributeLoc) {
12393 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12394 NumElements, true);
12395 IntegerLiteral *VectorSize
12396 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12398 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
12401 template<typename Derived>
12403 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
12405 SourceLocation AttributeLoc) {
12406 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
12409 template<typename Derived>
12410 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12412 MutableArrayRef<QualType> ParamTypes,
12413 const FunctionProtoType::ExtProtoInfo &EPI) {
12414 return SemaRef.BuildFunctionType(T, ParamTypes,
12415 getDerived().getBaseLocation(),
12416 getDerived().getBaseEntity(),
12420 template<typename Derived>
12421 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12422 return SemaRef.Context.getFunctionNoProtoType(T);
12425 template<typename Derived>
12426 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12428 assert(D && "no decl found");
12429 if (D->isInvalidDecl()) return QualType();
12431 // FIXME: Doesn't account for ObjCInterfaceDecl!
12433 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12434 // A valid resolved using typename pack expansion decl can have multiple
12435 // UsingDecls, but they must each have exactly one type, and it must be
12436 // the same type in every case. But we must have at least one expansion!
12437 if (UPD->expansions().empty()) {
12438 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12439 << UPD->isCXXClassMember() << UPD;
12443 // We might still have some unresolved types. Try to pick a resolved type
12444 // if we can. The final instantiation will check that the remaining
12445 // unresolved types instantiate to the type we pick.
12446 QualType FallbackT;
12448 for (auto *E : UPD->expansions()) {
12449 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12450 if (ThisT.isNull())
12452 else if (ThisT->getAs<UnresolvedUsingType>())
12454 else if (T.isNull())
12457 assert(getSema().Context.hasSameType(ThisT, T) &&
12458 "mismatched resolved types in using pack expansion");
12460 return T.isNull() ? FallbackT : T;
12461 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
12462 assert(Using->hasTypename() &&
12463 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12465 // A valid resolved using typename decl points to exactly one type decl.
12466 assert(++Using->shadow_begin() == Using->shadow_end());
12467 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
12469 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12470 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12471 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12474 return SemaRef.Context.getTypeDeclType(Ty);
12477 template<typename Derived>
12478 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12479 SourceLocation Loc) {
12480 return SemaRef.BuildTypeofExprType(E, Loc);
12483 template<typename Derived>
12484 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12485 return SemaRef.Context.getTypeOfType(Underlying);
12488 template<typename Derived>
12489 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12490 SourceLocation Loc) {
12491 return SemaRef.BuildDecltypeType(E, Loc);
12494 template<typename Derived>
12495 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12496 UnaryTransformType::UTTKind UKind,
12497 SourceLocation Loc) {
12498 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12501 template<typename Derived>
12502 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
12503 TemplateName Template,
12504 SourceLocation TemplateNameLoc,
12505 TemplateArgumentListInfo &TemplateArgs) {
12506 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
12509 template<typename Derived>
12510 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12511 SourceLocation KWLoc) {
12512 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12515 template<typename Derived>
12516 QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
12517 SourceLocation KWLoc,
12519 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12520 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
12523 template<typename Derived>
12525 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12527 TemplateDecl *Template) {
12528 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
12532 template<typename Derived>
12534 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12535 const IdentifierInfo &Name,
12536 SourceLocation NameLoc,
12537 QualType ObjectType,
12538 NamedDecl *FirstQualifierInScope,
12539 bool AllowInjectedClassName) {
12540 UnqualifiedId TemplateName;
12541 TemplateName.setIdentifier(&Name, NameLoc);
12542 Sema::TemplateTy Template;
12543 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12544 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12545 SS, TemplateKWLoc, TemplateName,
12546 ParsedType::make(ObjectType),
12547 /*EnteringContext=*/false,
12548 Template, AllowInjectedClassName);
12549 return Template.get();
12552 template<typename Derived>
12554 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12555 OverloadedOperatorKind Operator,
12556 SourceLocation NameLoc,
12557 QualType ObjectType,
12558 bool AllowInjectedClassName) {
12559 UnqualifiedId Name;
12560 // FIXME: Bogus location information.
12561 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
12562 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
12563 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12564 Sema::TemplateTy Template;
12565 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12566 SS, TemplateKWLoc, Name,
12567 ParsedType::make(ObjectType),
12568 /*EnteringContext=*/false,
12569 Template, AllowInjectedClassName);
12570 return Template.get();
12573 template<typename Derived>
12575 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12576 SourceLocation OpLoc,
12580 Expr *Callee = OrigCallee->IgnoreParenCasts();
12581 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
12583 if (First->getObjectKind() == OK_ObjCProperty) {
12584 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12585 if (BinaryOperator::isAssignmentOp(Opc))
12586 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12588 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12589 if (Result.isInvalid())
12590 return ExprError();
12591 First = Result.get();
12594 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12595 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12596 if (Result.isInvalid())
12597 return ExprError();
12598 Second = Result.get();
12601 // Determine whether this should be a builtin operation.
12602 if (Op == OO_Subscript) {
12603 if (!First->getType()->isOverloadableType() &&
12604 !Second->getType()->isOverloadableType())
12605 return getSema().CreateBuiltinArraySubscriptExpr(First,
12606 Callee->getLocStart(),
12608 } else if (Op == OO_Arrow) {
12609 // -> is never a builtin operation.
12610 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12611 } else if (Second == nullptr || isPostIncDec) {
12612 if (!First->getType()->isOverloadableType()) {
12613 // The argument is not of overloadable type, so try to create a
12614 // built-in unary operation.
12615 UnaryOperatorKind Opc
12616 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12618 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
12621 if (!First->getType()->isOverloadableType() &&
12622 !Second->getType()->isOverloadableType()) {
12623 // Neither of the arguments is an overloadable type, so try to
12624 // create a built-in binary operation.
12625 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12627 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
12628 if (Result.isInvalid())
12629 return ExprError();
12635 // Compute the transformed set of functions (and function templates) to be
12636 // used during overload resolution.
12637 UnresolvedSet<16> Functions;
12640 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
12641 Functions.append(ULE->decls_begin(), ULE->decls_end());
12642 // If the overload could not be resolved in the template definition
12643 // (because we had a dependent argument), ADL is performed as part of
12644 // template instantiation.
12645 RequiresADL = ULE->requiresADL();
12647 // If we've resolved this to a particular non-member function, just call
12648 // that function. If we resolved it to a member function,
12649 // CreateOverloaded* will find that function for us.
12650 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12651 if (!isa<CXXMethodDecl>(ND))
12652 Functions.addDecl(ND);
12653 RequiresADL = false;
12656 // Add any functions found via argument-dependent lookup.
12657 Expr *Args[2] = { First, Second };
12658 unsigned NumArgs = 1 + (Second != nullptr);
12660 // Create the overloaded operator invocation for unary operators.
12661 if (NumArgs == 1 || isPostIncDec) {
12662 UnaryOperatorKind Opc
12663 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12664 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
12668 if (Op == OO_Subscript) {
12669 SourceLocation LBrace;
12670 SourceLocation RBrace;
12672 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
12673 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
12674 LBrace = SourceLocation::getFromRawEncoding(
12675 NameLoc.CXXOperatorName.BeginOpNameLoc);
12676 RBrace = SourceLocation::getFromRawEncoding(
12677 NameLoc.CXXOperatorName.EndOpNameLoc);
12679 LBrace = Callee->getLocStart();
12683 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12687 // Create the overloaded operator invocation for binary operators.
12688 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12689 ExprResult Result = SemaRef.CreateOverloadedBinOp(
12690 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
12691 if (Result.isInvalid())
12692 return ExprError();
12697 template<typename Derived>
12699 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
12700 SourceLocation OperatorLoc,
12703 TypeSourceInfo *ScopeType,
12704 SourceLocation CCLoc,
12705 SourceLocation TildeLoc,
12706 PseudoDestructorTypeStorage Destroyed) {
12707 QualType BaseType = Base->getType();
12708 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
12709 (!isArrow && !BaseType->getAs<RecordType>()) ||
12710 (isArrow && BaseType->getAs<PointerType>() &&
12711 !BaseType->getAs<PointerType>()->getPointeeType()
12712 ->template getAs<RecordType>())){
12713 // This pseudo-destructor expression is still a pseudo-destructor.
12714 return SemaRef.BuildPseudoDestructorExpr(
12715 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12716 CCLoc, TildeLoc, Destroyed);
12719 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
12720 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12721 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12722 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12723 NameInfo.setNamedTypeInfo(DestroyedType);
12725 // The scope type is now known to be a valid nested name specifier
12726 // component. Tack it on to the end of the nested name specifier.
12728 if (!ScopeType->getType()->getAs<TagType>()) {
12729 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12730 diag::err_expected_class_or_namespace)
12731 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12732 return ExprError();
12734 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12738 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12739 return getSema().BuildMemberReferenceExpr(Base, BaseType,
12740 OperatorLoc, isArrow,
12742 /*FIXME: FirstQualifier*/ nullptr,
12744 /*TemplateArgs*/ nullptr,
12748 template<typename Derived>
12750 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
12751 SourceLocation Loc = S->getLocStart();
12752 CapturedDecl *CD = S->getCapturedDecl();
12753 unsigned NumParams = CD->getNumParams();
12754 unsigned ContextParamPos = CD->getContextParamPosition();
12755 SmallVector<Sema::CapturedParamNameType, 4> Params;
12756 for (unsigned I = 0; I < NumParams; ++I) {
12757 if (I != ContextParamPos) {
12760 CD->getParam(I)->getName(),
12761 getDerived().TransformType(CD->getParam(I)->getType())));
12763 Params.push_back(std::make_pair(StringRef(), QualType()));
12766 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
12767 S->getCapturedRegionKind(), Params);
12770 Sema::CompoundScopeRAII CompoundScope(getSema());
12771 Body = getDerived().TransformStmt(S->getCapturedStmt());
12774 if (Body.isInvalid()) {
12775 getSema().ActOnCapturedRegionError();
12776 return StmtError();
12779 return getSema().ActOnCapturedRegionEnd(Body.get());
12782 } // end namespace clang
12784 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H