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 function type.
840 /// By default, performs semantic analysis when building the function type.
841 /// Subclasses may override this routine to provide different behavior.
842 QualType RebuildFunctionProtoType(QualType T,
843 MutableArrayRef<QualType> ParamTypes,
844 const FunctionProtoType::ExtProtoInfo &EPI);
846 /// \brief Build a new unprototyped function type.
847 QualType RebuildFunctionNoProtoType(QualType ResultType);
849 /// \brief Rebuild an unresolved typename type, given the decl that
850 /// the UnresolvedUsingTypenameDecl was transformed to.
851 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
853 /// \brief Build a new typedef type.
854 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
855 return SemaRef.Context.getTypeDeclType(Typedef);
858 /// \brief Build a new class/struct/union type.
859 QualType RebuildRecordType(RecordDecl *Record) {
860 return SemaRef.Context.getTypeDeclType(Record);
863 /// \brief Build a new Enum type.
864 QualType RebuildEnumType(EnumDecl *Enum) {
865 return SemaRef.Context.getTypeDeclType(Enum);
868 /// \brief Build a new typeof(expr) type.
870 /// By default, performs semantic analysis when building the typeof type.
871 /// Subclasses may override this routine to provide different behavior.
872 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
874 /// \brief Build a new typeof(type) type.
876 /// By default, builds a new TypeOfType with the given underlying type.
877 QualType RebuildTypeOfType(QualType Underlying);
879 /// \brief Build a new unary transform type.
880 QualType RebuildUnaryTransformType(QualType BaseType,
881 UnaryTransformType::UTTKind UKind,
884 /// \brief Build a new C++11 decltype type.
886 /// By default, performs semantic analysis when building the decltype type.
887 /// Subclasses may override this routine to provide different behavior.
888 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
890 /// \brief Build a new C++11 auto type.
892 /// By default, builds a new AutoType with the given deduced type.
893 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
894 // Note, IsDependent is always false here: we implicitly convert an 'auto'
895 // which has been deduced to a dependent type into an undeduced 'auto', so
896 // that we'll retry deduction after the transformation.
897 return SemaRef.Context.getAutoType(Deduced, Keyword,
898 /*IsDependent*/ false);
901 /// By default, builds a new DeducedTemplateSpecializationType with the given
903 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
905 return SemaRef.Context.getDeducedTemplateSpecializationType(
906 Template, Deduced, /*IsDependent*/ false);
909 /// \brief Build a new template specialization type.
911 /// By default, performs semantic analysis when building the template
912 /// specialization type. Subclasses may override this routine to provide
913 /// different behavior.
914 QualType RebuildTemplateSpecializationType(TemplateName Template,
915 SourceLocation TemplateLoc,
916 TemplateArgumentListInfo &Args);
918 /// \brief Build a new parenthesized type.
920 /// By default, builds a new ParenType type from the inner type.
921 /// Subclasses may override this routine to provide different behavior.
922 QualType RebuildParenType(QualType InnerType) {
923 return SemaRef.BuildParenType(InnerType);
926 /// \brief Build a new qualified name type.
928 /// By default, builds a new ElaboratedType type from the keyword,
929 /// the nested-name-specifier and the named type.
930 /// Subclasses may override this routine to provide different behavior.
931 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
932 ElaboratedTypeKeyword Keyword,
933 NestedNameSpecifierLoc QualifierLoc,
935 return SemaRef.Context.getElaboratedType(Keyword,
936 QualifierLoc.getNestedNameSpecifier(),
940 /// \brief Build a new typename type that refers to a template-id.
942 /// By default, builds a new DependentNameType type from the
943 /// nested-name-specifier and the given type. Subclasses may override
944 /// this routine to provide different behavior.
945 QualType RebuildDependentTemplateSpecializationType(
946 ElaboratedTypeKeyword Keyword,
947 NestedNameSpecifierLoc QualifierLoc,
948 const IdentifierInfo *Name,
949 SourceLocation NameLoc,
950 TemplateArgumentListInfo &Args,
951 bool AllowInjectedClassName) {
952 // Rebuild the template name.
953 // TODO: avoid TemplateName abstraction
955 SS.Adopt(QualifierLoc);
956 TemplateName InstName
957 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
958 nullptr, AllowInjectedClassName);
960 if (InstName.isNull())
963 // If it's still dependent, make a dependent specialization.
964 if (InstName.getAsDependentTemplateName())
965 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
966 QualifierLoc.getNestedNameSpecifier(),
970 // Otherwise, make an elaborated type wrapping a non-dependent
973 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
974 if (T.isNull()) return QualType();
976 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
979 return SemaRef.Context.getElaboratedType(Keyword,
980 QualifierLoc.getNestedNameSpecifier(),
984 /// \brief Build a new typename type that refers to an identifier.
986 /// By default, performs semantic analysis when building the typename type
987 /// (or elaborated type). Subclasses may override this routine to provide
988 /// different behavior.
989 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
990 SourceLocation KeywordLoc,
991 NestedNameSpecifierLoc QualifierLoc,
992 const IdentifierInfo *Id,
993 SourceLocation IdLoc,
994 bool DeducedTSTContext) {
996 SS.Adopt(QualifierLoc);
998 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
999 // If the name is still dependent, just build a new dependent name type.
1000 if (!SemaRef.computeDeclContext(SS))
1001 return SemaRef.Context.getDependentNameType(Keyword,
1002 QualifierLoc.getNestedNameSpecifier(),
1006 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1007 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1009 // If a dependent name resolves to a deduced template specialization type,
1010 // check that we're in one of the syntactic contexts permitting it.
1011 if (!DeducedTSTContext) {
1012 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1013 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1014 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1015 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1016 Deduced->getTemplateName())
1017 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1018 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1019 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1026 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1028 // We had a dependent elaborated-type-specifier that has been transformed
1029 // into a non-dependent elaborated-type-specifier. Find the tag we're
1031 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1032 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1036 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1039 TagDecl *Tag = nullptr;
1040 SemaRef.LookupQualifiedName(Result, DC);
1041 switch (Result.getResultKind()) {
1042 case LookupResult::NotFound:
1043 case LookupResult::NotFoundInCurrentInstantiation:
1046 case LookupResult::Found:
1047 Tag = Result.getAsSingle<TagDecl>();
1050 case LookupResult::FoundOverloaded:
1051 case LookupResult::FoundUnresolvedValue:
1052 llvm_unreachable("Tag lookup cannot find non-tags");
1054 case LookupResult::Ambiguous:
1055 // Let the LookupResult structure handle ambiguities.
1060 // Check where the name exists but isn't a tag type and use that to emit
1061 // better diagnostics.
1062 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1063 SemaRef.LookupQualifiedName(Result, DC);
1064 switch (Result.getResultKind()) {
1065 case LookupResult::Found:
1066 case LookupResult::FoundOverloaded:
1067 case LookupResult::FoundUnresolvedValue: {
1068 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1069 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1070 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1072 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1076 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1077 << Kind << Id << DC << QualifierLoc.getSourceRange();
1083 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1085 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1086 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1090 // Build the elaborated-type-specifier type.
1091 QualType T = SemaRef.Context.getTypeDeclType(Tag);
1092 return SemaRef.Context.getElaboratedType(Keyword,
1093 QualifierLoc.getNestedNameSpecifier(),
1097 /// \brief Build a new pack expansion type.
1099 /// By default, builds a new PackExpansionType type from the given pattern.
1100 /// Subclasses may override this routine to provide different behavior.
1101 QualType RebuildPackExpansionType(QualType Pattern,
1102 SourceRange PatternRange,
1103 SourceLocation EllipsisLoc,
1104 Optional<unsigned> NumExpansions) {
1105 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1109 /// \brief Build a new atomic type given its value type.
1111 /// By default, performs semantic analysis when building the atomic type.
1112 /// Subclasses may override this routine to provide different behavior.
1113 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1115 /// \brief Build a new pipe type given its value type.
1116 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1119 /// \brief Build a new template name given a nested name specifier, a flag
1120 /// indicating whether the "template" keyword was provided, and the template
1121 /// that the template name refers to.
1123 /// By default, builds the new template name directly. Subclasses may override
1124 /// this routine to provide different behavior.
1125 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1127 TemplateDecl *Template);
1129 /// \brief Build a new template name given a nested name specifier and the
1130 /// name that is referred to as a template.
1132 /// By default, performs semantic analysis to determine whether the name can
1133 /// be resolved to a specific template, then builds the appropriate kind of
1134 /// template name. Subclasses may override this routine to provide different
1136 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1137 const IdentifierInfo &Name,
1138 SourceLocation NameLoc,
1139 QualType ObjectType,
1140 NamedDecl *FirstQualifierInScope,
1141 bool AllowInjectedClassName);
1143 /// \brief Build a new template name given a nested name specifier and the
1144 /// overloaded operator name that is referred to as a template.
1146 /// By default, performs semantic analysis to determine whether the name can
1147 /// be resolved to a specific template, then builds the appropriate kind of
1148 /// template name. Subclasses may override this routine to provide different
1150 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1151 OverloadedOperatorKind Operator,
1152 SourceLocation NameLoc,
1153 QualType ObjectType,
1154 bool AllowInjectedClassName);
1156 /// \brief Build a new template name given a template template parameter pack
1159 /// By default, performs semantic analysis to determine whether the name can
1160 /// be resolved to a specific template, then builds the appropriate kind of
1161 /// template name. Subclasses may override this routine to provide different
1163 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1164 const TemplateArgument &ArgPack) {
1165 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1168 /// \brief Build a new compound statement.
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
1172 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1173 MultiStmtArg Statements,
1174 SourceLocation RBraceLoc,
1176 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1180 /// \brief Build a new case statement.
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
1184 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1186 SourceLocation EllipsisLoc,
1188 SourceLocation ColonLoc) {
1189 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1193 /// \brief Attach the body to a new case statement.
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
1197 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1198 getSema().ActOnCaseStmtBody(S, Body);
1202 /// \brief Build a new default statement.
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
1206 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1207 SourceLocation ColonLoc,
1209 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1210 /*CurScope=*/nullptr);
1213 /// \brief Build a new label statement.
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
1217 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1218 SourceLocation ColonLoc, Stmt *SubStmt) {
1219 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1222 /// \brief Build a new label statement.
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
1226 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1227 ArrayRef<const Attr*> Attrs,
1229 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1232 /// \brief Build a new "if" statement.
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
1236 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1237 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
1238 SourceLocation ElseLoc, Stmt *Else) {
1239 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
1243 /// \brief Start building a new switch statement.
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
1247 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
1248 Sema::ConditionResult Cond) {
1249 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
1252 /// \brief Attach the body to the switch statement.
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
1256 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1257 Stmt *Switch, Stmt *Body) {
1258 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1261 /// \brief Build a new while statement.
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
1265 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1266 Sema::ConditionResult Cond, Stmt *Body) {
1267 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
1270 /// \brief Build a new do-while statement.
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
1274 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1275 SourceLocation WhileLoc, SourceLocation LParenLoc,
1276 Expr *Cond, SourceLocation RParenLoc) {
1277 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1281 /// \brief Build a new for statement.
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1286 Stmt *Init, Sema::ConditionResult Cond,
1287 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1289 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1290 Inc, RParenLoc, Body);
1293 /// \brief Build a new goto statement.
1295 /// By default, performs semantic analysis to build the new statement.
1296 /// Subclasses may override this routine to provide different behavior.
1297 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1299 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1302 /// \brief Build a new indirect goto statement.
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
1306 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1307 SourceLocation StarLoc,
1309 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1312 /// \brief Build a new return statement.
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
1316 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1317 return getSema().BuildReturnStmt(ReturnLoc, Result);
1320 /// \brief Build a new declaration statement.
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
1324 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
1325 SourceLocation StartLoc, SourceLocation EndLoc) {
1326 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1327 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1330 /// \brief Build a new inline asm statement.
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
1334 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1335 bool IsVolatile, unsigned NumOutputs,
1336 unsigned NumInputs, IdentifierInfo **Names,
1337 MultiExprArg Constraints, MultiExprArg Exprs,
1338 Expr *AsmString, MultiExprArg Clobbers,
1339 SourceLocation RParenLoc) {
1340 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1341 NumInputs, Names, Constraints, Exprs,
1342 AsmString, Clobbers, RParenLoc);
1345 /// \brief Build a new MS style inline asm statement.
1347 /// By default, performs semantic analysis to build the new statement.
1348 /// Subclasses may override this routine to provide different behavior.
1349 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1350 ArrayRef<Token> AsmToks,
1351 StringRef AsmString,
1352 unsigned NumOutputs, unsigned NumInputs,
1353 ArrayRef<StringRef> Constraints,
1354 ArrayRef<StringRef> Clobbers,
1355 ArrayRef<Expr*> Exprs,
1356 SourceLocation EndLoc) {
1357 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1358 NumOutputs, NumInputs,
1359 Constraints, Clobbers, Exprs, EndLoc);
1362 /// \brief Build a new co_return statement.
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
1366 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1368 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1371 /// \brief Build a new co_await expression.
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// Subclasses may override this routine to provide different behavior.
1375 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1377 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1380 /// \brief Build a new co_await expression.
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
1384 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1386 UnresolvedLookupExpr *Lookup) {
1387 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1390 /// \brief Build a new co_yield expression.
1392 /// By default, performs semantic analysis to build the new expression.
1393 /// Subclasses may override this routine to provide different behavior.
1394 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1395 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1398 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1399 return getSema().BuildCoroutineBodyStmt(Args);
1402 /// \brief Build a new Objective-C \@try statement.
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
1406 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1408 MultiStmtArg CatchStmts,
1410 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1414 /// \brief Rebuild an Objective-C exception declaration.
1416 /// By default, performs semantic analysis to build the new declaration.
1417 /// Subclasses may override this routine to provide different behavior.
1418 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1419 TypeSourceInfo *TInfo, QualType T) {
1420 return getSema().BuildObjCExceptionDecl(TInfo, T,
1421 ExceptionDecl->getInnerLocStart(),
1422 ExceptionDecl->getLocation(),
1423 ExceptionDecl->getIdentifier());
1426 /// \brief Build a new Objective-C \@catch statement.
1428 /// By default, performs semantic analysis to build the new statement.
1429 /// Subclasses may override this routine to provide different behavior.
1430 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1431 SourceLocation RParenLoc,
1434 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1438 /// \brief Build a new Objective-C \@finally statement.
1440 /// By default, performs semantic analysis to build the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
1442 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1444 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1447 /// \brief Build a new Objective-C \@throw statement.
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
1451 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1453 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1456 /// \brief Build a new OpenMP executable directive.
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
1460 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1461 DeclarationNameInfo DirName,
1462 OpenMPDirectiveKind CancelRegion,
1463 ArrayRef<OMPClause *> Clauses,
1464 Stmt *AStmt, SourceLocation StartLoc,
1465 SourceLocation EndLoc) {
1466 return getSema().ActOnOpenMPExecutableDirective(
1467 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1470 /// \brief Build a new OpenMP 'if' clause.
1472 /// By default, performs semantic analysis to build the new OpenMP clause.
1473 /// Subclasses may override this routine to provide different behavior.
1474 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1475 Expr *Condition, SourceLocation StartLoc,
1476 SourceLocation LParenLoc,
1477 SourceLocation NameModifierLoc,
1478 SourceLocation ColonLoc,
1479 SourceLocation EndLoc) {
1480 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1481 LParenLoc, NameModifierLoc, ColonLoc,
1485 /// \brief Build a new OpenMP 'final' clause.
1487 /// By default, performs semantic analysis to build the new OpenMP clause.
1488 /// Subclasses may override this routine to provide different behavior.
1489 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1490 SourceLocation LParenLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1496 /// \brief Build a new OpenMP 'num_threads' clause.
1498 /// By default, performs semantic analysis to build the new OpenMP clause.
1499 /// Subclasses may override this routine to provide different behavior.
1500 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1508 /// \brief Build a new OpenMP 'safelen' 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 *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1513 SourceLocation LParenLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1518 /// \brief Build a new OpenMP 'simdlen' clause.
1520 /// By default, performs semantic analysis to build the new OpenMP clause.
1521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1523 SourceLocation LParenLoc,
1524 SourceLocation EndLoc) {
1525 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1528 /// \brief Build a new OpenMP 'collapse' clause.
1530 /// By default, performs semantic analysis to build the new OpenMP clause.
1531 /// Subclasses may override this routine to provide different behavior.
1532 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1533 SourceLocation LParenLoc,
1534 SourceLocation EndLoc) {
1535 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1539 /// \brief Build a new OpenMP 'default' clause.
1541 /// By default, performs semantic analysis to build the new OpenMP clause.
1542 /// Subclasses may override this routine to provide different behavior.
1543 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1544 SourceLocation KindKwLoc,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1549 StartLoc, LParenLoc, EndLoc);
1552 /// \brief Build a new OpenMP 'proc_bind' clause.
1554 /// By default, performs semantic analysis to build the new OpenMP clause.
1555 /// Subclasses may override this routine to provide different behavior.
1556 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1557 SourceLocation KindKwLoc,
1558 SourceLocation StartLoc,
1559 SourceLocation LParenLoc,
1560 SourceLocation EndLoc) {
1561 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1562 StartLoc, LParenLoc, EndLoc);
1565 /// \brief Build a new OpenMP 'schedule' clause.
1567 /// By default, performs semantic analysis to build the new OpenMP clause.
1568 /// Subclasses may override this routine to provide different behavior.
1569 OMPClause *RebuildOMPScheduleClause(
1570 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1571 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1572 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1573 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1574 return getSema().ActOnOpenMPScheduleClause(
1575 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1579 /// \brief Build a new OpenMP 'ordered' clause.
1581 /// By default, performs semantic analysis to build the new OpenMP clause.
1582 /// Subclasses may override this routine to provide different behavior.
1583 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1584 SourceLocation EndLoc,
1585 SourceLocation LParenLoc, Expr *Num) {
1586 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1589 /// \brief Build a new OpenMP 'private' clause.
1591 /// By default, performs semantic analysis to build the new OpenMP clause.
1592 /// Subclasses may override this routine to provide different behavior.
1593 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1594 SourceLocation StartLoc,
1595 SourceLocation LParenLoc,
1596 SourceLocation EndLoc) {
1597 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1601 /// \brief Build a new OpenMP 'firstprivate' 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 *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1606 SourceLocation StartLoc,
1607 SourceLocation LParenLoc,
1608 SourceLocation EndLoc) {
1609 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1613 /// \brief Build a new OpenMP 'lastprivate' 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 *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1618 SourceLocation StartLoc,
1619 SourceLocation LParenLoc,
1620 SourceLocation EndLoc) {
1621 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1625 /// \brief Build a new OpenMP 'shared' 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 *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1630 SourceLocation StartLoc,
1631 SourceLocation LParenLoc,
1632 SourceLocation EndLoc) {
1633 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1637 /// \brief Build a new OpenMP 'reduction' clause.
1639 /// By default, performs semantic analysis to build the new statement.
1640 /// Subclasses may override this routine to provide different behavior.
1641 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 SourceLocation ColonLoc,
1645 SourceLocation EndLoc,
1646 CXXScopeSpec &ReductionIdScopeSpec,
1647 const DeclarationNameInfo &ReductionId,
1648 ArrayRef<Expr *> UnresolvedReductions) {
1649 return getSema().ActOnOpenMPReductionClause(
1650 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1651 ReductionId, UnresolvedReductions);
1654 /// Build a new OpenMP 'task_reduction' clause.
1656 /// By default, performs semantic analysis to build the new statement.
1657 /// Subclasses may override this routine to provide different behavior.
1658 OMPClause *RebuildOMPTaskReductionClause(
1659 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1660 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1661 CXXScopeSpec &ReductionIdScopeSpec,
1662 const DeclarationNameInfo &ReductionId,
1663 ArrayRef<Expr *> UnresolvedReductions) {
1664 return getSema().ActOnOpenMPTaskReductionClause(
1665 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1666 ReductionId, UnresolvedReductions);
1669 /// \brief Build a new OpenMP 'linear' clause.
1671 /// By default, performs semantic analysis to build the new OpenMP clause.
1672 /// Subclasses may override this routine to provide different behavior.
1673 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1674 SourceLocation StartLoc,
1675 SourceLocation LParenLoc,
1676 OpenMPLinearClauseKind Modifier,
1677 SourceLocation ModifierLoc,
1678 SourceLocation ColonLoc,
1679 SourceLocation EndLoc) {
1680 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1681 Modifier, ModifierLoc, ColonLoc,
1685 /// \brief Build a new OpenMP 'aligned' clause.
1687 /// By default, performs semantic analysis to build the new OpenMP clause.
1688 /// Subclasses may override this routine to provide different behavior.
1689 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1690 SourceLocation StartLoc,
1691 SourceLocation LParenLoc,
1692 SourceLocation ColonLoc,
1693 SourceLocation EndLoc) {
1694 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1695 LParenLoc, ColonLoc, EndLoc);
1698 /// \brief Build a new OpenMP 'copyin' clause.
1700 /// By default, performs semantic analysis to build the new OpenMP clause.
1701 /// Subclasses may override this routine to provide different behavior.
1702 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1703 SourceLocation StartLoc,
1704 SourceLocation LParenLoc,
1705 SourceLocation EndLoc) {
1706 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1710 /// \brief Build a new OpenMP 'copyprivate' clause.
1712 /// By default, performs semantic analysis to build the new OpenMP clause.
1713 /// Subclasses may override this routine to provide different behavior.
1714 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1715 SourceLocation StartLoc,
1716 SourceLocation LParenLoc,
1717 SourceLocation EndLoc) {
1718 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1722 /// \brief Build a new OpenMP 'flush' pseudo clause.
1724 /// By default, performs semantic analysis to build the new OpenMP clause.
1725 /// Subclasses may override this routine to provide different behavior.
1726 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1727 SourceLocation StartLoc,
1728 SourceLocation LParenLoc,
1729 SourceLocation EndLoc) {
1730 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1734 /// \brief Build a new OpenMP 'depend' pseudo clause.
1736 /// By default, performs semantic analysis to build the new OpenMP clause.
1737 /// Subclasses may override this routine to provide different behavior.
1739 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1740 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1741 SourceLocation StartLoc, SourceLocation LParenLoc,
1742 SourceLocation EndLoc) {
1743 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1744 StartLoc, LParenLoc, EndLoc);
1747 /// \brief Build a new OpenMP 'device' clause.
1749 /// By default, performs semantic analysis to build the new statement.
1750 /// Subclasses may override this routine to provide different behavior.
1751 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1752 SourceLocation LParenLoc,
1753 SourceLocation EndLoc) {
1754 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1758 /// \brief Build a new OpenMP 'map' clause.
1760 /// By default, performs semantic analysis to build the new OpenMP clause.
1761 /// Subclasses may override this routine to provide different behavior.
1763 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1764 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1765 SourceLocation MapLoc, SourceLocation ColonLoc,
1766 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1767 SourceLocation LParenLoc, SourceLocation EndLoc) {
1768 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1769 IsMapTypeImplicit, MapLoc, ColonLoc,
1770 VarList, StartLoc, LParenLoc, EndLoc);
1773 /// \brief Build a new OpenMP 'num_teams' clause.
1775 /// By default, performs semantic analysis to build the new statement.
1776 /// Subclasses may override this routine to provide different behavior.
1777 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1778 SourceLocation LParenLoc,
1779 SourceLocation EndLoc) {
1780 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1784 /// \brief Build a new OpenMP 'thread_limit' clause.
1786 /// By default, performs semantic analysis to build the new statement.
1787 /// Subclasses may override this routine to provide different behavior.
1788 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1789 SourceLocation StartLoc,
1790 SourceLocation LParenLoc,
1791 SourceLocation EndLoc) {
1792 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1796 /// \brief Build a new OpenMP 'priority' clause.
1798 /// By default, performs semantic analysis to build the new statement.
1799 /// Subclasses may override this routine to provide different behavior.
1800 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1801 SourceLocation LParenLoc,
1802 SourceLocation EndLoc) {
1803 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1807 /// \brief Build a new OpenMP 'grainsize' clause.
1809 /// By default, performs semantic analysis to build the new statement.
1810 /// Subclasses may override this routine to provide different behavior.
1811 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1812 SourceLocation LParenLoc,
1813 SourceLocation EndLoc) {
1814 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1818 /// \brief Build a new OpenMP 'num_tasks' clause.
1820 /// By default, performs semantic analysis to build the new statement.
1821 /// Subclasses may override this routine to provide different behavior.
1822 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1823 SourceLocation LParenLoc,
1824 SourceLocation EndLoc) {
1825 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1829 /// \brief Build a new OpenMP 'hint' clause.
1831 /// By default, performs semantic analysis to build the new statement.
1832 /// Subclasses may override this routine to provide different behavior.
1833 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1834 SourceLocation LParenLoc,
1835 SourceLocation EndLoc) {
1836 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1839 /// \brief Build a new OpenMP 'dist_schedule' clause.
1841 /// By default, performs semantic analysis to build the new OpenMP clause.
1842 /// Subclasses may override this routine to provide different behavior.
1844 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1845 Expr *ChunkSize, SourceLocation StartLoc,
1846 SourceLocation LParenLoc, SourceLocation KindLoc,
1847 SourceLocation CommaLoc, SourceLocation EndLoc) {
1848 return getSema().ActOnOpenMPDistScheduleClause(
1849 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1852 /// \brief Build a new OpenMP 'to' clause.
1854 /// By default, performs semantic analysis to build the new statement.
1855 /// Subclasses may override this routine to provide different behavior.
1856 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1857 SourceLocation StartLoc,
1858 SourceLocation LParenLoc,
1859 SourceLocation EndLoc) {
1860 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1863 /// \brief Build a new OpenMP 'from' clause.
1865 /// By default, performs semantic analysis to build the new statement.
1866 /// Subclasses may override this routine to provide different behavior.
1867 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1868 SourceLocation StartLoc,
1869 SourceLocation LParenLoc,
1870 SourceLocation EndLoc) {
1871 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1875 /// Build a new OpenMP 'use_device_ptr' clause.
1877 /// By default, performs semantic analysis to build the new OpenMP clause.
1878 /// Subclasses may override this routine to provide different behavior.
1879 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1880 SourceLocation StartLoc,
1881 SourceLocation LParenLoc,
1882 SourceLocation EndLoc) {
1883 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1887 /// Build a new OpenMP 'is_device_ptr' clause.
1889 /// By default, performs semantic analysis to build the new OpenMP clause.
1890 /// Subclasses may override this routine to provide different behavior.
1891 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1892 SourceLocation StartLoc,
1893 SourceLocation LParenLoc,
1894 SourceLocation EndLoc) {
1895 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1899 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1901 /// By default, performs semantic analysis to build the new statement.
1902 /// Subclasses may override this routine to provide different behavior.
1903 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1905 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1908 /// \brief Build a new Objective-C \@synchronized statement.
1910 /// By default, performs semantic analysis to build the new statement.
1911 /// Subclasses may override this routine to provide different behavior.
1912 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1913 Expr *Object, Stmt *Body) {
1914 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1917 /// \brief Build a new Objective-C \@autoreleasepool statement.
1919 /// By default, performs semantic analysis to build the new statement.
1920 /// Subclasses may override this routine to provide different behavior.
1921 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1923 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1926 /// \brief Build a new Objective-C fast enumeration statement.
1928 /// By default, performs semantic analysis to build the new statement.
1929 /// Subclasses may override this routine to provide different behavior.
1930 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1933 SourceLocation RParenLoc,
1935 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1939 if (ForEachStmt.isInvalid())
1942 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1945 /// \brief Build a new C++ exception declaration.
1947 /// By default, performs semantic analysis to build the new decaration.
1948 /// Subclasses may override this routine to provide different behavior.
1949 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1950 TypeSourceInfo *Declarator,
1951 SourceLocation StartLoc,
1952 SourceLocation IdLoc,
1953 IdentifierInfo *Id) {
1954 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1955 StartLoc, IdLoc, Id);
1957 getSema().CurContext->addDecl(Var);
1961 /// \brief Build a new C++ catch statement.
1963 /// By default, performs semantic analysis to build the new statement.
1964 /// Subclasses may override this routine to provide different behavior.
1965 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1966 VarDecl *ExceptionDecl,
1968 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1972 /// \brief Build a new C++ try statement.
1974 /// By default, performs semantic analysis to build the new statement.
1975 /// Subclasses may override this routine to provide different behavior.
1976 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1977 ArrayRef<Stmt *> Handlers) {
1978 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1981 /// \brief Build a new C++0x range-based for statement.
1983 /// By default, performs semantic analysis to build the new statement.
1984 /// Subclasses may override this routine to provide different behavior.
1985 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1986 SourceLocation CoawaitLoc,
1987 SourceLocation ColonLoc,
1988 Stmt *Range, Stmt *Begin, Stmt *End,
1989 Expr *Cond, Expr *Inc,
1991 SourceLocation RParenLoc) {
1992 // If we've just learned that the range is actually an Objective-C
1993 // collection, treat this as an Objective-C fast enumeration loop.
1994 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1995 if (RangeStmt->isSingleDecl()) {
1996 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1997 if (RangeVar->isInvalidDecl())
2000 Expr *RangeExpr = RangeVar->getInit();
2001 if (!RangeExpr->isTypeDependent() &&
2002 RangeExpr->getType()->isObjCObjectPointerType())
2003 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2009 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
2011 Cond, Inc, LoopVar, RParenLoc,
2012 Sema::BFRK_Rebuild);
2015 /// \brief Build a new C++0x range-based for statement.
2017 /// By default, performs semantic analysis to build the new statement.
2018 /// Subclasses may override this routine to provide different behavior.
2019 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
2021 NestedNameSpecifierLoc QualifierLoc,
2022 DeclarationNameInfo NameInfo,
2024 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2025 QualifierLoc, NameInfo, Nested);
2028 /// \brief Attach body to a C++0x range-based for statement.
2030 /// By default, performs semantic analysis to finish the new statement.
2031 /// Subclasses may override this routine to provide different behavior.
2032 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2033 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2036 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
2037 Stmt *TryBlock, Stmt *Handler) {
2038 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2041 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
2043 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2046 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
2047 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2050 /// \brief Build a new predefined expression.
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
2054 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2055 PredefinedExpr::IdentType IT) {
2056 return getSema().BuildPredefinedExpr(Loc, IT);
2059 /// \brief Build a new expression that references a declaration.
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
2063 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
2066 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2070 /// \brief Build a new expression that references a declaration.
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
2074 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
2076 const DeclarationNameInfo &NameInfo,
2077 TemplateArgumentListInfo *TemplateArgs) {
2079 SS.Adopt(QualifierLoc);
2081 // FIXME: loses template args.
2083 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
2086 /// \brief Build a new expression in parentheses.
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
2090 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
2091 SourceLocation RParen) {
2092 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2095 /// \brief Build a new pseudo-destructor expression.
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
2099 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2100 SourceLocation OperatorLoc,
2103 TypeSourceInfo *ScopeType,
2104 SourceLocation CCLoc,
2105 SourceLocation TildeLoc,
2106 PseudoDestructorTypeStorage Destroyed);
2108 /// \brief Build a new unary operator expression.
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
2112 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
2113 UnaryOperatorKind Opc,
2115 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2118 /// \brief Build a new builtin offsetof expression.
2120 /// By default, performs semantic analysis to build the new expression.
2121 /// Subclasses may override this routine to provide different behavior.
2122 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
2123 TypeSourceInfo *Type,
2124 ArrayRef<Sema::OffsetOfComponent> Components,
2125 SourceLocation RParenLoc) {
2126 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2130 /// \brief Build a new sizeof, alignof or vec_step expression with a
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2136 SourceLocation OpLoc,
2137 UnaryExprOrTypeTrait ExprKind,
2139 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2142 /// \brief Build a new sizeof, alignof or vec step expression with an
2143 /// expression argument.
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
2147 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2148 UnaryExprOrTypeTrait ExprKind,
2151 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2152 if (Result.isInvalid())
2158 /// \brief Build a new array subscript expression.
2160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
2162 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
2163 SourceLocation LBracketLoc,
2165 SourceLocation RBracketLoc) {
2166 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2171 /// \brief Build a new array section expression.
2173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
2175 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2177 SourceLocation ColonLoc, Expr *Length,
2178 SourceLocation RBracketLoc) {
2179 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2180 ColonLoc, Length, RBracketLoc);
2183 /// \brief Build a new call expression.
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
2187 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
2189 SourceLocation RParenLoc,
2190 Expr *ExecConfig = nullptr) {
2191 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
2192 Args, RParenLoc, ExecConfig);
2195 /// \brief Build a new member access expression.
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
2199 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
2201 NestedNameSpecifierLoc QualifierLoc,
2202 SourceLocation TemplateKWLoc,
2203 const DeclarationNameInfo &MemberNameInfo,
2205 NamedDecl *FoundDecl,
2206 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2207 NamedDecl *FirstQualifierInScope) {
2208 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2210 if (!Member->getDeclName()) {
2211 // We have a reference to an unnamed field. This is always the
2212 // base of an anonymous struct/union member access, i.e. the
2213 // field is always of record type.
2214 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
2215 assert(Member->getType()->isRecordType() &&
2216 "unnamed member not of record type?");
2219 getSema().PerformObjectMemberConversion(BaseResult.get(),
2220 QualifierLoc.getNestedNameSpecifier(),
2222 if (BaseResult.isInvalid())
2224 Base = BaseResult.get();
2225 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
2226 MemberExpr *ME = new (getSema().Context)
2227 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2228 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
2233 SS.Adopt(QualifierLoc);
2235 Base = BaseResult.get();
2236 QualType BaseType = Base->getType();
2238 if (isArrow && !BaseType->isPointerType())
2241 // FIXME: this involves duplicating earlier analysis in a lot of
2242 // cases; we should avoid this when possible.
2243 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2244 R.addDecl(FoundDecl);
2247 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2249 FirstQualifierInScope,
2250 R, ExplicitTemplateArgs,
2254 /// \brief Build a new binary operator expression.
2256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
2258 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
2259 BinaryOperatorKind Opc,
2260 Expr *LHS, Expr *RHS) {
2261 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2264 /// \brief Build a new conditional operator expression.
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
2268 ExprResult RebuildConditionalOperator(Expr *Cond,
2269 SourceLocation QuestionLoc,
2271 SourceLocation ColonLoc,
2273 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2277 /// \brief Build a new C-style cast expression.
2279 /// By default, performs semantic analysis to build the new expression.
2280 /// Subclasses may override this routine to provide different behavior.
2281 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
2282 TypeSourceInfo *TInfo,
2283 SourceLocation RParenLoc,
2285 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2289 /// \brief Build a new compound literal expression.
2291 /// By default, performs semantic analysis to build the new expression.
2292 /// Subclasses may override this routine to provide different behavior.
2293 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
2294 TypeSourceInfo *TInfo,
2295 SourceLocation RParenLoc,
2297 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2301 /// \brief Build a new extended vector element access expression.
2303 /// By default, performs semantic analysis to build the new expression.
2304 /// Subclasses may override this routine to provide different behavior.
2305 ExprResult RebuildExtVectorElementExpr(Expr *Base,
2306 SourceLocation OpLoc,
2307 SourceLocation AccessorLoc,
2308 IdentifierInfo &Accessor) {
2311 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2312 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2313 OpLoc, /*IsArrow*/ false,
2314 SS, SourceLocation(),
2315 /*FirstQualifierInScope*/ nullptr,
2317 /* TemplateArgs */ nullptr,
2321 /// \brief Build a new initializer list expression.
2323 /// By default, performs semantic analysis to build the new expression.
2324 /// Subclasses may override this routine to provide different behavior.
2325 ExprResult RebuildInitList(SourceLocation LBraceLoc,
2327 SourceLocation RBraceLoc,
2328 QualType ResultTy) {
2330 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2331 if (Result.isInvalid() || ResultTy->isDependentType())
2334 // Patch in the result type we were given, which may have been computed
2335 // when the initial InitListExpr was built.
2336 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2337 ILE->setType(ResultTy);
2341 /// \brief Build a new designated initializer expression.
2343 /// By default, performs semantic analysis to build the new expression.
2344 /// Subclasses may override this routine to provide different behavior.
2345 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
2346 MultiExprArg ArrayExprs,
2347 SourceLocation EqualOrColonLoc,
2351 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2353 if (Result.isInvalid())
2359 /// \brief Build a new value-initialized expression.
2361 /// By default, builds the implicit value initialization without performing
2362 /// any semantic analysis. Subclasses may override this routine to provide
2363 /// different behavior.
2364 ExprResult RebuildImplicitValueInitExpr(QualType T) {
2365 return new (SemaRef.Context) ImplicitValueInitExpr(T);
2368 /// \brief Build a new \c va_arg expression.
2370 /// By default, performs semantic analysis to build the new expression.
2371 /// Subclasses may override this routine to provide different behavior.
2372 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
2373 Expr *SubExpr, TypeSourceInfo *TInfo,
2374 SourceLocation RParenLoc) {
2375 return getSema().BuildVAArgExpr(BuiltinLoc,
2380 /// \brief Build a new expression list in parentheses.
2382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
2384 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
2385 MultiExprArg SubExprs,
2386 SourceLocation RParenLoc) {
2387 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2390 /// \brief Build a new address-of-label expression.
2392 /// By default, performs semantic analysis, using the name of the label
2393 /// rather than attempting to map the label statement itself.
2394 /// Subclasses may override this routine to provide different behavior.
2395 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
2396 SourceLocation LabelLoc, LabelDecl *Label) {
2397 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2400 /// \brief Build a new GNU statement expression.
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
2404 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
2406 SourceLocation RParenLoc) {
2407 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2410 /// \brief Build a new __builtin_choose_expr expression.
2412 /// By default, performs semantic analysis to build the new expression.
2413 /// Subclasses may override this routine to provide different behavior.
2414 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
2415 Expr *Cond, Expr *LHS, Expr *RHS,
2416 SourceLocation RParenLoc) {
2417 return SemaRef.ActOnChooseExpr(BuiltinLoc,
2422 /// \brief Build a new generic selection expression.
2424 /// By default, performs semantic analysis to build the new expression.
2425 /// Subclasses may override this routine to provide different behavior.
2426 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2427 SourceLocation DefaultLoc,
2428 SourceLocation RParenLoc,
2429 Expr *ControllingExpr,
2430 ArrayRef<TypeSourceInfo *> Types,
2431 ArrayRef<Expr *> Exprs) {
2432 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2433 ControllingExpr, Types, Exprs);
2436 /// \brief Build a new overloaded operator call expression.
2438 /// By default, performs semantic analysis to build the new expression.
2439 /// The semantic analysis provides the behavior of template instantiation,
2440 /// copying with transformations that turn what looks like an overloaded
2441 /// operator call into a use of a builtin operator, performing
2442 /// argument-dependent lookup, etc. Subclasses may override this routine to
2443 /// provide different behavior.
2444 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2445 SourceLocation OpLoc,
2450 /// \brief Build a new C++ "named" cast expression, such as static_cast or
2451 /// reinterpret_cast.
2453 /// By default, this routine dispatches to one of the more-specific routines
2454 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2455 /// Subclasses may override this routine to provide different behavior.
2456 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
2457 Stmt::StmtClass Class,
2458 SourceLocation LAngleLoc,
2459 TypeSourceInfo *TInfo,
2460 SourceLocation RAngleLoc,
2461 SourceLocation LParenLoc,
2463 SourceLocation RParenLoc) {
2465 case Stmt::CXXStaticCastExprClass:
2466 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2467 RAngleLoc, LParenLoc,
2468 SubExpr, RParenLoc);
2470 case Stmt::CXXDynamicCastExprClass:
2471 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2472 RAngleLoc, LParenLoc,
2473 SubExpr, RParenLoc);
2475 case Stmt::CXXReinterpretCastExprClass:
2476 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2477 RAngleLoc, LParenLoc,
2481 case Stmt::CXXConstCastExprClass:
2482 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2483 RAngleLoc, LParenLoc,
2484 SubExpr, RParenLoc);
2487 llvm_unreachable("Invalid C++ named cast");
2491 /// \brief Build a new C++ static_cast expression.
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
2495 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
2496 SourceLocation LAngleLoc,
2497 TypeSourceInfo *TInfo,
2498 SourceLocation RAngleLoc,
2499 SourceLocation LParenLoc,
2501 SourceLocation RParenLoc) {
2502 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2504 SourceRange(LAngleLoc, RAngleLoc),
2505 SourceRange(LParenLoc, RParenLoc));
2508 /// \brief Build a new C++ dynamic_cast expression.
2510 /// By default, performs semantic analysis to build the new expression.
2511 /// Subclasses may override this routine to provide different behavior.
2512 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
2513 SourceLocation LAngleLoc,
2514 TypeSourceInfo *TInfo,
2515 SourceLocation RAngleLoc,
2516 SourceLocation LParenLoc,
2518 SourceLocation RParenLoc) {
2519 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2521 SourceRange(LAngleLoc, RAngleLoc),
2522 SourceRange(LParenLoc, RParenLoc));
2525 /// \brief Build a new C++ reinterpret_cast expression.
2527 /// By default, performs semantic analysis to build the new expression.
2528 /// Subclasses may override this routine to provide different behavior.
2529 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
2530 SourceLocation LAngleLoc,
2531 TypeSourceInfo *TInfo,
2532 SourceLocation RAngleLoc,
2533 SourceLocation LParenLoc,
2535 SourceLocation RParenLoc) {
2536 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2538 SourceRange(LAngleLoc, RAngleLoc),
2539 SourceRange(LParenLoc, RParenLoc));
2542 /// \brief Build a new C++ const_cast expression.
2544 /// By default, performs semantic analysis to build the new expression.
2545 /// Subclasses may override this routine to provide different behavior.
2546 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
2547 SourceLocation LAngleLoc,
2548 TypeSourceInfo *TInfo,
2549 SourceLocation RAngleLoc,
2550 SourceLocation LParenLoc,
2552 SourceLocation RParenLoc) {
2553 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2555 SourceRange(LAngleLoc, RAngleLoc),
2556 SourceRange(LParenLoc, RParenLoc));
2559 /// \brief Build a new C++ functional-style cast expression.
2561 /// By default, performs semantic analysis to build the new expression.
2562 /// Subclasses may override this routine to provide different behavior.
2563 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2564 SourceLocation LParenLoc,
2566 SourceLocation RParenLoc) {
2567 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2568 MultiExprArg(&Sub, 1),
2572 /// \brief Build a new C++ typeid(type) expression.
2574 /// By default, performs semantic analysis to build the new expression.
2575 /// Subclasses may override this routine to provide different behavior.
2576 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2577 SourceLocation TypeidLoc,
2578 TypeSourceInfo *Operand,
2579 SourceLocation RParenLoc) {
2580 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2585 /// \brief Build a new C++ typeid(expr) expression.
2587 /// By default, performs semantic analysis to build the new expression.
2588 /// Subclasses may override this routine to provide different behavior.
2589 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2590 SourceLocation TypeidLoc,
2592 SourceLocation RParenLoc) {
2593 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2597 /// \brief Build a new C++ __uuidof(type) expression.
2599 /// By default, performs semantic analysis to build the new expression.
2600 /// Subclasses may override this routine to provide different behavior.
2601 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2602 SourceLocation TypeidLoc,
2603 TypeSourceInfo *Operand,
2604 SourceLocation RParenLoc) {
2605 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2609 /// \brief Build a new C++ __uuidof(expr) expression.
2611 /// By default, performs semantic analysis to build the new expression.
2612 /// Subclasses may override this routine to provide different behavior.
2613 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2614 SourceLocation TypeidLoc,
2616 SourceLocation RParenLoc) {
2617 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2621 /// \brief Build a new C++ "this" expression.
2623 /// By default, builds a new "this" expression without performing any
2624 /// semantic analysis. Subclasses may override this routine to provide
2625 /// different behavior.
2626 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
2629 getSema().CheckCXXThisCapture(ThisLoc);
2630 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2633 /// \brief Build a new C++ throw expression.
2635 /// By default, performs semantic analysis to build the new expression.
2636 /// Subclasses may override this routine to provide different behavior.
2637 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2638 bool IsThrownVariableInScope) {
2639 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2642 /// \brief Build a new C++ default-argument expression.
2644 /// By default, builds a new default-argument expression, which does not
2645 /// require any semantic analysis. Subclasses may override this routine to
2646 /// provide different behavior.
2647 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
2648 ParmVarDecl *Param) {
2649 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2652 /// \brief Build a new C++11 default-initialization expression.
2654 /// By default, builds a new default field initialization expression, which
2655 /// does not require any semantic analysis. Subclasses may override this
2656 /// routine to provide different behavior.
2657 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2659 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2662 /// \brief Build a new C++ zero-initialization expression.
2664 /// By default, performs semantic analysis to build the new expression.
2665 /// Subclasses may override this routine to provide different behavior.
2666 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2667 SourceLocation LParenLoc,
2668 SourceLocation RParenLoc) {
2669 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2673 /// \brief Build a new C++ "new" expression.
2675 /// By default, performs semantic analysis to build the new expression.
2676 /// Subclasses may override this routine to provide different behavior.
2677 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
2679 SourceLocation PlacementLParen,
2680 MultiExprArg PlacementArgs,
2681 SourceLocation PlacementRParen,
2682 SourceRange TypeIdParens,
2683 QualType AllocatedType,
2684 TypeSourceInfo *AllocatedTypeInfo,
2686 SourceRange DirectInitRange,
2687 Expr *Initializer) {
2688 return getSema().BuildCXXNew(StartLoc, UseGlobal,
2700 /// \brief Build a new C++ "delete" expression.
2702 /// By default, performs semantic analysis to build the new expression.
2703 /// Subclasses may override this routine to provide different behavior.
2704 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2705 bool IsGlobalDelete,
2708 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2712 /// \brief Build a new type trait expression.
2714 /// By default, performs semantic analysis to build the new expression.
2715 /// Subclasses may override this routine to provide different behavior.
2716 ExprResult RebuildTypeTrait(TypeTrait Trait,
2717 SourceLocation StartLoc,
2718 ArrayRef<TypeSourceInfo *> Args,
2719 SourceLocation RParenLoc) {
2720 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2723 /// \brief Build a new array type trait expression.
2725 /// By default, performs semantic analysis to build the new expression.
2726 /// Subclasses may override this routine to provide different behavior.
2727 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2728 SourceLocation StartLoc,
2729 TypeSourceInfo *TSInfo,
2731 SourceLocation RParenLoc) {
2732 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2735 /// \brief Build a new expression trait expression.
2737 /// By default, performs semantic analysis to build the new expression.
2738 /// Subclasses may override this routine to provide different behavior.
2739 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2740 SourceLocation StartLoc,
2742 SourceLocation RParenLoc) {
2743 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2746 /// \brief Build a new (previously unresolved) declaration reference
2749 /// By default, performs semantic analysis to build the new expression.
2750 /// Subclasses may override this routine to provide different behavior.
2751 ExprResult RebuildDependentScopeDeclRefExpr(
2752 NestedNameSpecifierLoc QualifierLoc,
2753 SourceLocation TemplateKWLoc,
2754 const DeclarationNameInfo &NameInfo,
2755 const TemplateArgumentListInfo *TemplateArgs,
2756 bool IsAddressOfOperand,
2757 TypeSourceInfo **RecoveryTSI) {
2759 SS.Adopt(QualifierLoc);
2761 if (TemplateArgs || TemplateKWLoc.isValid())
2762 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2765 return getSema().BuildQualifiedDeclarationNameExpr(
2766 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2769 /// \brief Build a new template-id expression.
2771 /// By default, performs semantic analysis to build the new expression.
2772 /// Subclasses may override this routine to provide different behavior.
2773 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2774 SourceLocation TemplateKWLoc,
2777 const TemplateArgumentListInfo *TemplateArgs) {
2778 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2782 /// \brief Build a new object-construction expression.
2784 /// By default, performs semantic analysis to build the new expression.
2785 /// Subclasses may override this routine to provide different behavior.
2786 ExprResult RebuildCXXConstructExpr(QualType T,
2788 CXXConstructorDecl *Constructor,
2791 bool HadMultipleCandidates,
2792 bool ListInitialization,
2793 bool StdInitListInitialization,
2794 bool RequiresZeroInit,
2795 CXXConstructExpr::ConstructionKind ConstructKind,
2796 SourceRange ParenRange) {
2797 SmallVector<Expr*, 8> ConvertedArgs;
2798 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2802 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
2805 HadMultipleCandidates,
2807 StdInitListInitialization,
2808 RequiresZeroInit, ConstructKind,
2812 /// \brief Build a new implicit construction via inherited constructor
2814 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2815 CXXConstructorDecl *Constructor,
2816 bool ConstructsVBase,
2817 bool InheritedFromVBase) {
2818 return new (getSema().Context) CXXInheritedCtorInitExpr(
2819 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2822 /// \brief Build a new object-construction expression.
2824 /// By default, performs semantic analysis to build the new expression.
2825 /// Subclasses may override this routine to provide different behavior.
2826 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2827 SourceLocation LParenLoc,
2829 SourceLocation RParenLoc) {
2830 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2836 /// \brief Build a new object-construction expression.
2838 /// By default, performs semantic analysis to build the new expression.
2839 /// Subclasses may override this routine to provide different behavior.
2840 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2841 SourceLocation LParenLoc,
2843 SourceLocation RParenLoc) {
2844 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2850 /// \brief Build a new member reference expression.
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
2854 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2857 SourceLocation OperatorLoc,
2858 NestedNameSpecifierLoc QualifierLoc,
2859 SourceLocation TemplateKWLoc,
2860 NamedDecl *FirstQualifierInScope,
2861 const DeclarationNameInfo &MemberNameInfo,
2862 const TemplateArgumentListInfo *TemplateArgs) {
2864 SS.Adopt(QualifierLoc);
2866 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2867 OperatorLoc, IsArrow,
2869 FirstQualifierInScope,
2871 TemplateArgs, /*S*/nullptr);
2874 /// \brief Build a new member reference expression.
2876 /// By default, performs semantic analysis to build the new expression.
2877 /// Subclasses may override this routine to provide different behavior.
2878 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2879 SourceLocation OperatorLoc,
2881 NestedNameSpecifierLoc QualifierLoc,
2882 SourceLocation TemplateKWLoc,
2883 NamedDecl *FirstQualifierInScope,
2885 const TemplateArgumentListInfo *TemplateArgs) {
2887 SS.Adopt(QualifierLoc);
2889 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2890 OperatorLoc, IsArrow,
2892 FirstQualifierInScope,
2893 R, TemplateArgs, /*S*/nullptr);
2896 /// \brief Build a new noexcept expression.
2898 /// By default, performs semantic analysis to build the new expression.
2899 /// Subclasses may override this routine to provide different behavior.
2900 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2901 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2904 /// \brief Build a new expression to compute the length of a parameter pack.
2905 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2907 SourceLocation PackLoc,
2908 SourceLocation RParenLoc,
2909 Optional<unsigned> Length,
2910 ArrayRef<TemplateArgument> PartialArgs) {
2911 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2912 RParenLoc, Length, PartialArgs);
2915 /// \brief Build a new Objective-C boxed expression.
2917 /// By default, performs semantic analysis to build the new expression.
2918 /// Subclasses may override this routine to provide different behavior.
2919 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2920 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2923 /// \brief Build a new Objective-C array literal.
2925 /// By default, performs semantic analysis to build the new expression.
2926 /// Subclasses may override this routine to provide different behavior.
2927 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2928 Expr **Elements, unsigned NumElements) {
2929 return getSema().BuildObjCArrayLiteral(Range,
2930 MultiExprArg(Elements, NumElements));
2933 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2934 Expr *Base, Expr *Key,
2935 ObjCMethodDecl *getterMethod,
2936 ObjCMethodDecl *setterMethod) {
2937 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2938 getterMethod, setterMethod);
2941 /// \brief Build a new Objective-C dictionary literal.
2943 /// By default, performs semantic analysis to build the new expression.
2944 /// Subclasses may override this routine to provide different behavior.
2945 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2946 MutableArrayRef<ObjCDictionaryElement> Elements) {
2947 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
2950 /// \brief Build a new Objective-C \@encode expression.
2952 /// By default, performs semantic analysis to build the new expression.
2953 /// Subclasses may override this routine to provide different behavior.
2954 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2955 TypeSourceInfo *EncodeTypeInfo,
2956 SourceLocation RParenLoc) {
2957 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2960 /// \brief Build a new Objective-C class message.
2961 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2963 ArrayRef<SourceLocation> SelectorLocs,
2964 ObjCMethodDecl *Method,
2965 SourceLocation LBracLoc,
2967 SourceLocation RBracLoc) {
2968 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2969 ReceiverTypeInfo->getType(),
2970 /*SuperLoc=*/SourceLocation(),
2971 Sel, Method, LBracLoc, SelectorLocs,
2975 /// \brief Build a new Objective-C instance message.
2976 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2978 ArrayRef<SourceLocation> SelectorLocs,
2979 ObjCMethodDecl *Method,
2980 SourceLocation LBracLoc,
2982 SourceLocation RBracLoc) {
2983 return SemaRef.BuildInstanceMessage(Receiver,
2984 Receiver->getType(),
2985 /*SuperLoc=*/SourceLocation(),
2986 Sel, Method, LBracLoc, SelectorLocs,
2990 /// \brief Build a new Objective-C instance/class message to 'super'.
2991 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2993 ArrayRef<SourceLocation> SelectorLocs,
2995 ObjCMethodDecl *Method,
2996 SourceLocation LBracLoc,
2998 SourceLocation RBracLoc) {
2999 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3002 Sel, Method, LBracLoc, SelectorLocs,
3004 : SemaRef.BuildClassMessage(nullptr,
3007 Sel, Method, LBracLoc, SelectorLocs,
3013 /// \brief Build a new Objective-C ivar reference expression.
3015 /// By default, performs semantic analysis to build the new expression.
3016 /// Subclasses may override this routine to provide different behavior.
3017 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
3018 SourceLocation IvarLoc,
3019 bool IsArrow, bool IsFreeIvar) {
3021 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3022 ExprResult Result = getSema().BuildMemberReferenceExpr(
3023 BaseArg, BaseArg->getType(),
3024 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3025 /*FirstQualifierInScope=*/nullptr, NameInfo,
3026 /*TemplateArgs=*/nullptr,
3028 if (IsFreeIvar && Result.isUsable())
3029 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3033 /// \brief Build a new Objective-C property reference expression.
3035 /// By default, performs semantic analysis to build the new expression.
3036 /// Subclasses may override this routine to provide different behavior.
3037 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
3038 ObjCPropertyDecl *Property,
3039 SourceLocation PropertyLoc) {
3041 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3042 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3043 /*FIXME:*/PropertyLoc,
3045 SS, SourceLocation(),
3046 /*FirstQualifierInScope=*/nullptr,
3048 /*TemplateArgs=*/nullptr,
3052 /// \brief Build a new Objective-C property reference expression.
3054 /// By default, performs semantic analysis to build the new expression.
3055 /// Subclasses may override this routine to provide different behavior.
3056 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3057 ObjCMethodDecl *Getter,
3058 ObjCMethodDecl *Setter,
3059 SourceLocation PropertyLoc) {
3060 // Since these expressions can only be value-dependent, we do not
3061 // need to perform semantic analysis again.
3063 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3064 VK_LValue, OK_ObjCProperty,
3065 PropertyLoc, Base));
3068 /// \brief Build a new Objective-C "isa" expression.
3070 /// By default, performs semantic analysis to build the new expression.
3071 /// Subclasses may override this routine to provide different behavior.
3072 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
3073 SourceLocation OpLoc, bool IsArrow) {
3075 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3076 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3078 SS, SourceLocation(),
3079 /*FirstQualifierInScope=*/nullptr,
3081 /*TemplateArgs=*/nullptr,
3085 /// \brief Build a new shuffle vector expression.
3087 /// By default, performs semantic analysis to build the new expression.
3088 /// Subclasses may override this routine to provide different behavior.
3089 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
3090 MultiExprArg SubExprs,
3091 SourceLocation RParenLoc) {
3092 // Find the declaration for __builtin_shufflevector
3093 const IdentifierInfo &Name
3094 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3095 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3096 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3097 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3099 // Build a reference to the __builtin_shufflevector builtin
3100 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3101 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3102 SemaRef.Context.BuiltinFnTy,
3103 VK_RValue, BuiltinLoc);
3104 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3105 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3106 CK_BuiltinFnToFnPtr).get();
3108 // Build the CallExpr
3109 ExprResult TheCall = new (SemaRef.Context) CallExpr(
3110 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3111 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
3113 // Type-check the __builtin_shufflevector expression.
3114 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3117 /// \brief Build a new convert vector expression.
3118 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3119 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3120 SourceLocation RParenLoc) {
3121 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3122 BuiltinLoc, RParenLoc);
3125 /// \brief Build a new template argument pack expansion.
3127 /// By default, performs semantic analysis to build a new pack expansion
3128 /// for a template argument. Subclasses may override this routine to provide
3129 /// different behavior.
3130 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
3131 SourceLocation EllipsisLoc,
3132 Optional<unsigned> NumExpansions) {
3133 switch (Pattern.getArgument().getKind()) {
3134 case TemplateArgument::Expression: {
3136 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3137 EllipsisLoc, NumExpansions);
3138 if (Result.isInvalid())
3139 return TemplateArgumentLoc();
3141 return TemplateArgumentLoc(Result.get(), Result.get());
3144 case TemplateArgument::Template:
3145 return TemplateArgumentLoc(TemplateArgument(
3146 Pattern.getArgument().getAsTemplate(),
3148 Pattern.getTemplateQualifierLoc(),
3149 Pattern.getTemplateNameLoc(),
3152 case TemplateArgument::Null:
3153 case TemplateArgument::Integral:
3154 case TemplateArgument::Declaration:
3155 case TemplateArgument::Pack:
3156 case TemplateArgument::TemplateExpansion:
3157 case TemplateArgument::NullPtr:
3158 llvm_unreachable("Pack expansion pattern has no parameter packs");
3160 case TemplateArgument::Type:
3161 if (TypeSourceInfo *Expansion
3162 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3165 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3170 return TemplateArgumentLoc();
3173 /// \brief Build a new expression pack expansion.
3175 /// By default, performs semantic analysis to build a new pack expansion
3176 /// for an expression. Subclasses may override this routine to provide
3177 /// different behavior.
3178 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
3179 Optional<unsigned> NumExpansions) {
3180 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3183 /// \brief Build a new C++1z fold-expression.
3185 /// By default, performs semantic analysis in order to build a new fold
3187 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3188 BinaryOperatorKind Operator,
3189 SourceLocation EllipsisLoc, Expr *RHS,
3190 SourceLocation RParenLoc) {
3191 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3195 /// \brief Build an empty C++1z fold-expression with the given operator.
3197 /// By default, produces the fallback value for the fold-expression, or
3198 /// produce an error if there is no fallback value.
3199 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3200 BinaryOperatorKind Operator) {
3201 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3204 /// \brief Build a new atomic operation expression.
3206 /// By default, performs semantic analysis to build the new expression.
3207 /// Subclasses may override this routine to provide different behavior.
3208 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3209 MultiExprArg SubExprs,
3211 AtomicExpr::AtomicOp Op,
3212 SourceLocation RParenLoc) {
3213 // Just create the expression; there is not any interesting semantic
3214 // analysis here because we can't actually build an AtomicExpr until
3215 // we are sure it is semantically sound.
3216 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3221 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3222 QualType ObjectType,
3223 NamedDecl *FirstQualifierInScope,
3226 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3227 QualType ObjectType,
3228 NamedDecl *FirstQualifierInScope,
3231 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3232 NamedDecl *FirstQualifierInScope,
3235 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3236 DependentNameTypeLoc TL,
3237 bool DeducibleTSTContext);
3240 template<typename Derived>
3241 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
3245 switch (S->getStmtClass()) {
3246 case Stmt::NoStmtClass: break;
3248 // Transform individual statement nodes
3249 #define STMT(Node, Parent) \
3250 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3251 #define ABSTRACT_STMT(Node)
3252 #define EXPR(Node, Parent)
3253 #include "clang/AST/StmtNodes.inc"
3255 // Transform expressions by calling TransformExpr.
3256 #define STMT(Node, Parent)
3257 #define ABSTRACT_STMT(Stmt)
3258 #define EXPR(Node, Parent) case Stmt::Node##Class:
3259 #include "clang/AST/StmtNodes.inc"
3261 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3265 return getSema().ActOnExprStmt(E);
3272 template<typename Derived>
3273 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3277 switch (S->getClauseKind()) {
3279 // Transform individual clause nodes
3280 #define OPENMP_CLAUSE(Name, Class) \
3281 case OMPC_ ## Name : \
3282 return getDerived().Transform ## Class(cast<Class>(S));
3283 #include "clang/Basic/OpenMPKinds.def"
3290 template<typename Derived>
3291 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
3295 switch (E->getStmtClass()) {
3296 case Stmt::NoStmtClass: break;
3297 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3298 #define ABSTRACT_STMT(Stmt)
3299 #define EXPR(Node, Parent) \
3300 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3301 #include "clang/AST/StmtNodes.inc"
3307 template<typename Derived>
3308 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
3310 // Initializers are instantiated like expressions, except that various outer
3311 // layers are stripped.
3315 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3316 Init = ExprTemp->getSubExpr();
3318 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3319 Init = AIL->getCommonExpr();
3321 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3322 Init = MTE->GetTemporaryExpr();
3324 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3325 Init = Binder->getSubExpr();
3327 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3328 Init = ICE->getSubExprAsWritten();
3330 if (CXXStdInitializerListExpr *ILE =
3331 dyn_cast<CXXStdInitializerListExpr>(Init))
3332 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3334 // If this is copy-initialization, we only need to reconstruct
3335 // InitListExprs. Other forms of copy-initialization will be a no-op if
3336 // the initializer is already the right type.
3337 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3338 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3339 return getDerived().TransformExpr(Init);
3341 // Revert value-initialization back to empty parens.
3342 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3343 SourceRange Parens = VIE->getSourceRange();
3344 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3348 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3349 if (isa<ImplicitValueInitExpr>(Init))
3350 return getDerived().RebuildParenListExpr(SourceLocation(), None,
3353 // Revert initialization by constructor back to a parenthesized or braced list
3354 // of expressions. Any other form of initializer can just be reused directly.
3355 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3356 return getDerived().TransformExpr(Init);
3358 // If the initialization implicitly converted an initializer list to a
3359 // std::initializer_list object, unwrap the std::initializer_list too.
3360 if (Construct && Construct->isStdInitListInitialization())
3361 return TransformInitializer(Construct->getArg(0), NotCopyInit);
3363 SmallVector<Expr*, 8> NewArgs;
3364 bool ArgChanged = false;
3365 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3366 /*IsCall*/true, NewArgs, &ArgChanged))
3369 // If this was list initialization, revert to list form.
3370 if (Construct->isListInitialization())
3371 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3372 Construct->getLocEnd(),
3373 Construct->getType());
3375 // Build a ParenListExpr to represent anything else.
3376 SourceRange Parens = Construct->getParenOrBraceRange();
3377 if (Parens.isInvalid()) {
3378 // This was a variable declaration's initialization for which no initializer
3380 assert(NewArgs.empty() &&
3381 "no parens or braces but have direct init with arguments?");
3384 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3388 template<typename Derived>
3389 bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
3392 SmallVectorImpl<Expr *> &Outputs,
3394 for (unsigned I = 0; I != NumInputs; ++I) {
3395 // If requested, drop call arguments that need to be dropped.
3396 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3403 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3404 Expr *Pattern = Expansion->getPattern();
3406 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3407 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3408 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3410 // Determine whether the set of unexpanded parameter packs can and should
3413 bool RetainExpansion = false;
3414 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3415 Optional<unsigned> NumExpansions = OrigNumExpansions;
3416 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3417 Pattern->getSourceRange(),
3419 Expand, RetainExpansion,
3424 // The transform has determined that we should perform a simple
3425 // transformation on the pack expansion, producing another pack
3427 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3428 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3429 if (OutPattern.isInvalid())
3432 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3433 Expansion->getEllipsisLoc(),
3435 if (Out.isInvalid())
3440 Outputs.push_back(Out.get());
3444 // Record right away that the argument was changed. This needs
3445 // to happen even if the array expands to nothing.
3446 if (ArgChanged) *ArgChanged = true;
3448 // The transform has determined that we should perform an elementwise
3449 // expansion of the pattern. Do so.
3450 for (unsigned I = 0; I != *NumExpansions; ++I) {
3451 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3452 ExprResult Out = getDerived().TransformExpr(Pattern);
3453 if (Out.isInvalid())
3456 if (Out.get()->containsUnexpandedParameterPack()) {
3457 Out = getDerived().RebuildPackExpansion(
3458 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3459 if (Out.isInvalid())
3463 Outputs.push_back(Out.get());
3466 // If we're supposed to retain a pack expansion, do so by temporarily
3467 // forgetting the partially-substituted parameter pack.
3468 if (RetainExpansion) {
3469 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3471 ExprResult Out = getDerived().TransformExpr(Pattern);
3472 if (Out.isInvalid())
3475 Out = getDerived().RebuildPackExpansion(
3476 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3477 if (Out.isInvalid())
3480 Outputs.push_back(Out.get());
3487 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3488 : getDerived().TransformExpr(Inputs[I]);
3489 if (Result.isInvalid())
3492 if (Result.get() != Inputs[I] && ArgChanged)
3495 Outputs.push_back(Result.get());
3501 template <typename Derived>
3502 Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3503 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3505 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3506 getDerived().TransformDefinition(Var->getLocation(), Var));
3509 return Sema::ConditionError();
3511 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3515 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3517 if (CondExpr.isInvalid())
3518 return Sema::ConditionError();
3520 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3523 return Sema::ConditionResult();
3526 template<typename Derived>
3527 NestedNameSpecifierLoc
3528 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3529 NestedNameSpecifierLoc NNS,
3530 QualType ObjectType,
3531 NamedDecl *FirstQualifierInScope) {
3532 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
3533 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3534 Qualifier = Qualifier.getPrefix())
3535 Qualifiers.push_back(Qualifier);
3538 while (!Qualifiers.empty()) {
3539 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3540 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
3542 switch (QNNS->getKind()) {
3543 case NestedNameSpecifier::Identifier: {
3544 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3545 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3546 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3547 SS, FirstQualifierInScope, false))
3548 return NestedNameSpecifierLoc();
3552 case NestedNameSpecifier::Namespace: {
3554 = cast_or_null<NamespaceDecl>(
3555 getDerived().TransformDecl(
3556 Q.getLocalBeginLoc(),
3557 QNNS->getAsNamespace()));
3558 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3562 case NestedNameSpecifier::NamespaceAlias: {
3563 NamespaceAliasDecl *Alias
3564 = cast_or_null<NamespaceAliasDecl>(
3565 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3566 QNNS->getAsNamespaceAlias()));
3567 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3568 Q.getLocalEndLoc());
3572 case NestedNameSpecifier::Global:
3573 // There is no meaningful transformation that one could perform on the
3575 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3578 case NestedNameSpecifier::Super: {
3580 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3581 SourceLocation(), QNNS->getAsRecordDecl()));
3582 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3586 case NestedNameSpecifier::TypeSpecWithTemplate:
3587 case NestedNameSpecifier::TypeSpec: {
3588 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3589 FirstQualifierInScope, SS);
3592 return NestedNameSpecifierLoc();
3594 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3595 (SemaRef.getLangOpts().CPlusPlus11 &&
3596 TL.getType()->isEnumeralType())) {
3597 assert(!TL.getType().hasLocalQualifiers() &&
3598 "Can't get cv-qualifiers here");
3599 if (TL.getType()->isEnumeralType())
3600 SemaRef.Diag(TL.getBeginLoc(),
3601 diag::warn_cxx98_compat_enum_nested_name_spec);
3602 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3603 Q.getLocalEndLoc());
3606 // If the nested-name-specifier is an invalid type def, don't emit an
3607 // error because a previous error should have already been emitted.
3608 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3609 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3610 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3611 << TL.getType() << SS.getRange();
3613 return NestedNameSpecifierLoc();
3617 // The qualifier-in-scope and object type only apply to the leftmost entity.
3618 FirstQualifierInScope = nullptr;
3619 ObjectType = QualType();
3622 // Don't rebuild the nested-name-specifier if we don't have to.
3623 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3624 !getDerived().AlwaysRebuild())
3627 // If we can re-use the source-location data from the original
3628 // nested-name-specifier, do so.
3629 if (SS.location_size() == NNS.getDataLength() &&
3630 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3631 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3633 // Allocate new nested-name-specifier location information.
3634 return SS.getWithLocInContext(SemaRef.Context);
3637 template<typename Derived>
3639 TreeTransform<Derived>
3640 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
3641 DeclarationName Name = NameInfo.getName();
3643 return DeclarationNameInfo();
3645 switch (Name.getNameKind()) {
3646 case DeclarationName::Identifier:
3647 case DeclarationName::ObjCZeroArgSelector:
3648 case DeclarationName::ObjCOneArgSelector:
3649 case DeclarationName::ObjCMultiArgSelector:
3650 case DeclarationName::CXXOperatorName:
3651 case DeclarationName::CXXLiteralOperatorName:
3652 case DeclarationName::CXXUsingDirective:
3655 case DeclarationName::CXXDeductionGuideName: {
3656 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3657 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3658 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3660 return DeclarationNameInfo();
3662 DeclarationNameInfo NewNameInfo(NameInfo);
3663 NewNameInfo.setName(
3664 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3668 case DeclarationName::CXXConstructorName:
3669 case DeclarationName::CXXDestructorName:
3670 case DeclarationName::CXXConversionFunctionName: {
3671 TypeSourceInfo *NewTInfo;
3672 CanQualType NewCanTy;
3673 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3674 NewTInfo = getDerived().TransformType(OldTInfo);
3676 return DeclarationNameInfo();
3677 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3681 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3682 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3684 return DeclarationNameInfo();
3685 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3688 DeclarationName NewName
3689 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3691 DeclarationNameInfo NewNameInfo(NameInfo);
3692 NewNameInfo.setName(NewName);
3693 NewNameInfo.setNamedTypeInfo(NewTInfo);
3698 llvm_unreachable("Unknown name kind.");
3701 template<typename Derived>
3703 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3705 SourceLocation NameLoc,
3706 QualType ObjectType,
3707 NamedDecl *FirstQualifierInScope,
3708 bool AllowInjectedClassName) {
3709 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3710 TemplateDecl *Template = QTN->getTemplateDecl();
3711 assert(Template && "qualified template name must refer to a template");
3713 TemplateDecl *TransTemplate
3714 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3717 return TemplateName();
3719 if (!getDerived().AlwaysRebuild() &&
3720 SS.getScopeRep() == QTN->getQualifier() &&
3721 TransTemplate == Template)
3724 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3728 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3729 if (SS.getScopeRep()) {
3730 // These apply to the scope specifier, not the template.
3731 ObjectType = QualType();
3732 FirstQualifierInScope = nullptr;
3735 if (!getDerived().AlwaysRebuild() &&
3736 SS.getScopeRep() == DTN->getQualifier() &&
3737 ObjectType.isNull())
3740 if (DTN->isIdentifier()) {
3741 return getDerived().RebuildTemplateName(SS,
3742 *DTN->getIdentifier(),
3745 FirstQualifierInScope,
3746 AllowInjectedClassName);
3749 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3750 ObjectType, AllowInjectedClassName);
3753 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3754 TemplateDecl *TransTemplate
3755 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3758 return TemplateName();
3760 if (!getDerived().AlwaysRebuild() &&
3761 TransTemplate == Template)
3764 return TemplateName(TransTemplate);
3767 if (SubstTemplateTemplateParmPackStorage *SubstPack
3768 = Name.getAsSubstTemplateTemplateParmPack()) {
3769 TemplateTemplateParmDecl *TransParam
3770 = cast_or_null<TemplateTemplateParmDecl>(
3771 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3773 return TemplateName();
3775 if (!getDerived().AlwaysRebuild() &&
3776 TransParam == SubstPack->getParameterPack())
3779 return getDerived().RebuildTemplateName(TransParam,
3780 SubstPack->getArgumentPack());
3783 // These should be getting filtered out before they reach the AST.
3784 llvm_unreachable("overloaded function decl survived to here");
3787 template<typename Derived>
3788 void TreeTransform<Derived>::InventTemplateArgumentLoc(
3789 const TemplateArgument &Arg,
3790 TemplateArgumentLoc &Output) {
3791 SourceLocation Loc = getDerived().getBaseLocation();
3792 switch (Arg.getKind()) {
3793 case TemplateArgument::Null:
3794 llvm_unreachable("null template argument in TreeTransform");
3797 case TemplateArgument::Type:
3798 Output = TemplateArgumentLoc(Arg,
3799 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3803 case TemplateArgument::Template:
3804 case TemplateArgument::TemplateExpansion: {
3805 NestedNameSpecifierLocBuilder Builder;
3806 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
3807 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3808 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3809 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3810 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3812 if (Arg.getKind() == TemplateArgument::Template)
3813 Output = TemplateArgumentLoc(Arg,
3814 Builder.getWithLocInContext(SemaRef.Context),
3817 Output = TemplateArgumentLoc(Arg,
3818 Builder.getWithLocInContext(SemaRef.Context),
3824 case TemplateArgument::Expression:
3825 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3828 case TemplateArgument::Declaration:
3829 case TemplateArgument::Integral:
3830 case TemplateArgument::Pack:
3831 case TemplateArgument::NullPtr:
3832 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
3837 template<typename Derived>
3838 bool TreeTransform<Derived>::TransformTemplateArgument(
3839 const TemplateArgumentLoc &Input,
3840 TemplateArgumentLoc &Output, bool Uneval) {
3841 const TemplateArgument &Arg = Input.getArgument();
3842 switch (Arg.getKind()) {
3843 case TemplateArgument::Null:
3844 case TemplateArgument::Integral:
3845 case TemplateArgument::Pack:
3846 case TemplateArgument::Declaration:
3847 case TemplateArgument::NullPtr:
3848 llvm_unreachable("Unexpected TemplateArgument");
3850 case TemplateArgument::Type: {
3851 TypeSourceInfo *DI = Input.getTypeSourceInfo();
3853 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3855 DI = getDerived().TransformType(DI);
3856 if (!DI) return true;
3858 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3862 case TemplateArgument::Template: {
3863 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3865 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3871 SS.Adopt(QualifierLoc);
3872 TemplateName Template
3873 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3874 Input.getTemplateNameLoc());
3875 if (Template.isNull())
3878 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3879 Input.getTemplateNameLoc());
3883 case TemplateArgument::TemplateExpansion:
3884 llvm_unreachable("Caller should expand pack expansions");
3886 case TemplateArgument::Expression: {
3887 // Template argument expressions are constant expressions.
3888 EnterExpressionEvaluationContext Unevaluated(
3890 ? Sema::ExpressionEvaluationContext::Unevaluated
3891 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
3893 Expr *InputExpr = Input.getSourceExpression();
3894 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3896 ExprResult E = getDerived().TransformExpr(InputExpr);
3897 E = SemaRef.ActOnConstantExpression(E);
3898 if (E.isInvalid()) return true;
3899 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3904 // Work around bogus GCC warning
3908 /// \brief Iterator adaptor that invents template argument location information
3909 /// for each of the template arguments in its underlying iterator.
3910 template<typename Derived, typename InputIterator>
3911 class TemplateArgumentLocInventIterator {
3912 TreeTransform<Derived> &Self;
3916 typedef TemplateArgumentLoc value_type;
3917 typedef TemplateArgumentLoc reference;
3918 typedef typename std::iterator_traits<InputIterator>::difference_type
3920 typedef std::input_iterator_tag iterator_category;
3923 TemplateArgumentLoc Arg;
3926 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3928 const TemplateArgumentLoc *operator->() const { return &Arg; }
3931 TemplateArgumentLocInventIterator() { }
3933 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3935 : Self(Self), Iter(Iter) { }
3937 TemplateArgumentLocInventIterator &operator++() {
3942 TemplateArgumentLocInventIterator operator++(int) {
3943 TemplateArgumentLocInventIterator Old(*this);
3948 reference operator*() const {
3949 TemplateArgumentLoc Result;
3950 Self.InventTemplateArgumentLoc(*Iter, Result);
3954 pointer operator->() const { return pointer(**this); }
3956 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3957 const TemplateArgumentLocInventIterator &Y) {
3958 return X.Iter == Y.Iter;
3961 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3962 const TemplateArgumentLocInventIterator &Y) {
3963 return X.Iter != Y.Iter;
3967 template<typename Derived>
3968 template<typename InputIterator>
3969 bool TreeTransform<Derived>::TransformTemplateArguments(
3970 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3972 for (; First != Last; ++First) {
3973 TemplateArgumentLoc Out;
3974 TemplateArgumentLoc In = *First;
3976 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3977 // Unpack argument packs, which we translate them into separate
3979 // FIXME: We could do much better if we could guarantee that the
3980 // TemplateArgumentLocInfo for the pack expansion would be usable for
3981 // all of the template arguments in the argument pack.
3982 typedef TemplateArgumentLocInventIterator<Derived,
3983 TemplateArgument::pack_iterator>
3985 if (TransformTemplateArguments(PackLocIterator(*this,
3986 In.getArgument().pack_begin()),
3987 PackLocIterator(*this,
3988 In.getArgument().pack_end()),
3995 if (In.getArgument().isPackExpansion()) {
3996 // We have a pack expansion, for which we will be substituting into
3998 SourceLocation Ellipsis;
3999 Optional<unsigned> OrigNumExpansions;
4000 TemplateArgumentLoc Pattern
4001 = getSema().getTemplateArgumentPackExpansionPattern(
4002 In, Ellipsis, OrigNumExpansions);
4004 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4005 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4006 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4008 // Determine whether the set of unexpanded parameter packs can and should
4011 bool RetainExpansion = false;
4012 Optional<unsigned> NumExpansions = OrigNumExpansions;
4013 if (getDerived().TryExpandParameterPacks(Ellipsis,
4014 Pattern.getSourceRange(),
4022 // The transform has determined that we should perform a simple
4023 // transformation on the pack expansion, producing another pack
4025 TemplateArgumentLoc OutPattern;
4026 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4027 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4030 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4032 if (Out.getArgument().isNull())
4035 Outputs.addArgument(Out);
4039 // The transform has determined that we should perform an elementwise
4040 // expansion of the pattern. Do so.
4041 for (unsigned I = 0; I != *NumExpansions; ++I) {
4042 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4044 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4047 if (Out.getArgument().containsUnexpandedParameterPack()) {
4048 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4050 if (Out.getArgument().isNull())
4054 Outputs.addArgument(Out);
4057 // If we're supposed to retain a pack expansion, do so by temporarily
4058 // forgetting the partially-substituted parameter pack.
4059 if (RetainExpansion) {
4060 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4062 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4065 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4067 if (Out.getArgument().isNull())
4070 Outputs.addArgument(Out);
4077 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4080 Outputs.addArgument(Out);
4087 //===----------------------------------------------------------------------===//
4088 // Type transformation
4089 //===----------------------------------------------------------------------===//
4091 template<typename Derived>
4092 QualType TreeTransform<Derived>::TransformType(QualType T) {
4093 if (getDerived().AlreadyTransformed(T))
4096 // Temporary workaround. All of these transformations should
4097 // eventually turn into transformations on TypeLocs.
4098 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4099 getDerived().getBaseLocation());
4101 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4106 return NewDI->getType();
4109 template<typename Derived>
4110 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
4111 // Refine the base location to the type's location.
4112 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4113 getDerived().getBaseEntity());
4114 if (getDerived().AlreadyTransformed(DI->getType()))
4119 TypeLoc TL = DI->getTypeLoc();
4120 TLB.reserve(TL.getFullDataSize());
4122 QualType Result = getDerived().TransformType(TLB, TL);
4123 if (Result.isNull())
4126 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4129 template<typename Derived>
4131 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
4132 switch (T.getTypeLocClass()) {
4133 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4134 #define TYPELOC(CLASS, PARENT) \
4135 case TypeLoc::CLASS: \
4136 return getDerived().Transform##CLASS##Type(TLB, \
4137 T.castAs<CLASS##TypeLoc>());
4138 #include "clang/AST/TypeLocNodes.def"
4141 llvm_unreachable("unhandled type loc!");
4144 template<typename Derived>
4145 QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4146 if (!isa<DependentNameType>(T))
4147 return TransformType(T);
4149 if (getDerived().AlreadyTransformed(T))
4151 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4152 getDerived().getBaseLocation());
4153 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4154 return NewDI ? NewDI->getType() : QualType();
4157 template<typename Derived>
4159 TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4160 if (!isa<DependentNameType>(DI->getType()))
4161 return TransformType(DI);
4163 // Refine the base location to the type's location.
4164 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4165 getDerived().getBaseEntity());
4166 if (getDerived().AlreadyTransformed(DI->getType()))
4171 TypeLoc TL = DI->getTypeLoc();
4172 TLB.reserve(TL.getFullDataSize());
4175 auto QTL = TL.getAs<QualifiedTypeLoc>();
4177 TL = QTL.getUnqualifiedLoc();
4179 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4181 QualType Result = getDerived().TransformDependentNameType(
4182 TLB, DNTL, /*DeducedTSTContext*/true);
4183 if (Result.isNull())
4187 Result = getDerived().RebuildQualifiedType(
4188 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4189 TLB.TypeWasModifiedSafely(Result);
4192 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4195 template<typename Derived>
4197 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
4198 QualifiedTypeLoc T) {
4199 Qualifiers Quals = T.getType().getLocalQualifiers();
4201 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4202 if (Result.isNull())
4205 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4207 // RebuildQualifiedType might have updated the type, but not in a way
4208 // that invalidates the TypeLoc. (There's no location information for
4210 TLB.TypeWasModifiedSafely(Result);
4215 template<typename Derived>
4216 QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4220 // [When] adding cv-qualifications on top of the function type [...] the
4221 // cv-qualifiers are ignored.
4223 // when the cv-qualifiers are introduced through the use of a typedef-name
4224 // or decltype-specifier [...] the cv-qualifiers are ignored.
4225 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4226 // applied to a reference type.
4227 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4228 if (T->isFunctionType() || T->isReferenceType())
4231 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4233 if (Quals.hasObjCLifetime()) {
4234 if (!T->isObjCLifetimeType() && !T->isDependentType())
4235 Quals.removeObjCLifetime();
4236 else if (T.getObjCLifetime()) {
4238 // A lifetime qualifier applied to a substituted template parameter
4239 // overrides the lifetime qualifier from the template argument.
4240 const AutoType *AutoTy;
4241 if (const SubstTemplateTypeParmType *SubstTypeParam
4242 = dyn_cast<SubstTemplateTypeParmType>(T)) {
4243 QualType Replacement = SubstTypeParam->getReplacementType();
4244 Qualifiers Qs = Replacement.getQualifiers();
4245 Qs.removeObjCLifetime();
4246 Replacement = SemaRef.Context.getQualifiedType(
4247 Replacement.getUnqualifiedType(), Qs);
4248 T = SemaRef.Context.getSubstTemplateTypeParmType(
4249 SubstTypeParam->getReplacedParameter(), Replacement);
4250 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
4251 // 'auto' types behave the same way as template parameters.
4252 QualType Deduced = AutoTy->getDeducedType();
4253 Qualifiers Qs = Deduced.getQualifiers();
4254 Qs.removeObjCLifetime();
4256 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4257 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4258 AutoTy->isDependentType());
4260 // Otherwise, complain about the addition of a qualifier to an
4261 // already-qualified type.
4262 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4263 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
4264 Quals.removeObjCLifetime();
4269 return SemaRef.BuildQualifiedType(T, Loc, Quals);
4272 template<typename Derived>
4274 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4275 QualType ObjectType,
4276 NamedDecl *UnqualLookup,
4278 if (getDerived().AlreadyTransformed(TL.getType()))
4281 TypeSourceInfo *TSI =
4282 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4284 return TSI->getTypeLoc();
4288 template<typename Derived>
4290 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4291 QualType ObjectType,
4292 NamedDecl *UnqualLookup,
4294 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4297 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4301 template <typename Derived>
4302 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4303 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4305 QualType T = TL.getType();
4306 assert(!getDerived().AlreadyTransformed(T));
4311 if (isa<TemplateSpecializationType>(T)) {
4312 TemplateSpecializationTypeLoc SpecTL =
4313 TL.castAs<TemplateSpecializationTypeLoc>();
4315 TemplateName Template = getDerived().TransformTemplateName(
4316 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4317 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
4318 if (Template.isNull())
4321 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4323 } else if (isa<DependentTemplateSpecializationType>(T)) {
4324 DependentTemplateSpecializationTypeLoc SpecTL =
4325 TL.castAs<DependentTemplateSpecializationTypeLoc>();
4327 TemplateName Template
4328 = getDerived().RebuildTemplateName(SS,
4329 *SpecTL.getTypePtr()->getIdentifier(),
4330 SpecTL.getTemplateNameLoc(),
4331 ObjectType, UnqualLookup,
4332 /*AllowInjectedClassName*/true);
4333 if (Template.isNull())
4336 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4341 // Nothing special needs to be done for these.
4342 Result = getDerived().TransformType(TLB, TL);
4345 if (Result.isNull())
4348 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4351 template <class TyLoc> static inline
4352 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4353 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4354 NewT.setNameLoc(T.getNameLoc());
4358 template<typename Derived>
4359 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4361 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4362 NewT.setBuiltinLoc(T.getBuiltinLoc());
4363 if (T.needsExtraLocalData())
4364 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4368 template<typename Derived>
4369 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4372 return TransformTypeSpecType(TLB, T);
4375 template <typename Derived>
4376 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4377 AdjustedTypeLoc TL) {
4378 // Adjustments applied during transformation are handled elsewhere.
4379 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4382 template<typename Derived>
4383 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4384 DecayedTypeLoc TL) {
4385 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4386 if (OriginalType.isNull())
4389 QualType Result = TL.getType();
4390 if (getDerived().AlwaysRebuild() ||
4391 OriginalType != TL.getOriginalLoc().getType())
4392 Result = SemaRef.Context.getDecayedType(OriginalType);
4393 TLB.push<DecayedTypeLoc>(Result);
4394 // Nothing to set for DecayedTypeLoc.
4398 template<typename Derived>
4399 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4400 PointerTypeLoc TL) {
4401 QualType PointeeType
4402 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4403 if (PointeeType.isNull())
4406 QualType Result = TL.getType();
4407 if (PointeeType->getAs<ObjCObjectType>()) {
4408 // A dependent pointer type 'T *' has is being transformed such
4409 // that an Objective-C class type is being replaced for 'T'. The
4410 // resulting pointer type is an ObjCObjectPointerType, not a
4412 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4414 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4415 NewT.setStarLoc(TL.getStarLoc());
4419 if (getDerived().AlwaysRebuild() ||
4420 PointeeType != TL.getPointeeLoc().getType()) {
4421 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4422 if (Result.isNull())
4426 // Objective-C ARC can add lifetime qualifiers to the type that we're
4428 TLB.TypeWasModifiedSafely(Result->getPointeeType());
4430 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4431 NewT.setSigilLoc(TL.getSigilLoc());
4435 template<typename Derived>
4437 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4438 BlockPointerTypeLoc TL) {
4439 QualType PointeeType
4440 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4441 if (PointeeType.isNull())
4444 QualType Result = TL.getType();
4445 if (getDerived().AlwaysRebuild() ||
4446 PointeeType != TL.getPointeeLoc().getType()) {
4447 Result = getDerived().RebuildBlockPointerType(PointeeType,
4449 if (Result.isNull())
4453 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4454 NewT.setSigilLoc(TL.getSigilLoc());
4458 /// Transforms a reference type. Note that somewhat paradoxically we
4459 /// don't care whether the type itself is an l-value type or an r-value
4460 /// type; we only care if the type was *written* as an l-value type
4461 /// or an r-value type.
4462 template<typename Derived>
4464 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
4465 ReferenceTypeLoc TL) {
4466 const ReferenceType *T = TL.getTypePtr();
4468 // Note that this works with the pointee-as-written.
4469 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4470 if (PointeeType.isNull())
4473 QualType Result = TL.getType();
4474 if (getDerived().AlwaysRebuild() ||
4475 PointeeType != T->getPointeeTypeAsWritten()) {
4476 Result = getDerived().RebuildReferenceType(PointeeType,
4477 T->isSpelledAsLValue(),
4479 if (Result.isNull())
4483 // Objective-C ARC can add lifetime qualifiers to the type that we're
4485 TLB.TypeWasModifiedSafely(
4486 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4488 // r-value references can be rebuilt as l-value references.
4489 ReferenceTypeLoc NewTL;
4490 if (isa<LValueReferenceType>(Result))
4491 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4493 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4494 NewTL.setSigilLoc(TL.getSigilLoc());
4499 template<typename Derived>
4501 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
4502 LValueReferenceTypeLoc TL) {
4503 return TransformReferenceType(TLB, TL);
4506 template<typename Derived>
4508 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
4509 RValueReferenceTypeLoc TL) {
4510 return TransformReferenceType(TLB, TL);
4513 template<typename Derived>
4515 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
4516 MemberPointerTypeLoc TL) {
4517 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4518 if (PointeeType.isNull())
4521 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4522 TypeSourceInfo *NewClsTInfo = nullptr;
4524 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4529 const MemberPointerType *T = TL.getTypePtr();
4530 QualType OldClsType = QualType(T->getClass(), 0);
4531 QualType NewClsType;
4533 NewClsType = NewClsTInfo->getType();
4535 NewClsType = getDerived().TransformType(OldClsType);
4536 if (NewClsType.isNull())
4540 QualType Result = TL.getType();
4541 if (getDerived().AlwaysRebuild() ||
4542 PointeeType != T->getPointeeType() ||
4543 NewClsType != OldClsType) {
4544 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4546 if (Result.isNull())
4550 // If we had to adjust the pointee type when building a member pointer, make
4551 // sure to push TypeLoc info for it.
4552 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4553 if (MPT && PointeeType != MPT->getPointeeType()) {
4554 assert(isa<AdjustedType>(MPT->getPointeeType()));
4555 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4558 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4559 NewTL.setSigilLoc(TL.getSigilLoc());
4560 NewTL.setClassTInfo(NewClsTInfo);
4565 template<typename Derived>
4567 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4568 ConstantArrayTypeLoc TL) {
4569 const ConstantArrayType *T = TL.getTypePtr();
4570 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4571 if (ElementType.isNull())
4574 QualType Result = TL.getType();
4575 if (getDerived().AlwaysRebuild() ||
4576 ElementType != T->getElementType()) {
4577 Result = getDerived().RebuildConstantArrayType(ElementType,
4578 T->getSizeModifier(),
4580 T->getIndexTypeCVRQualifiers(),
4581 TL.getBracketsRange());
4582 if (Result.isNull())
4586 // We might have either a ConstantArrayType or a VariableArrayType now:
4587 // a ConstantArrayType is allowed to have an element type which is a
4588 // VariableArrayType if the type is dependent. Fortunately, all array
4589 // types have the same location layout.
4590 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4591 NewTL.setLBracketLoc(TL.getLBracketLoc());
4592 NewTL.setRBracketLoc(TL.getRBracketLoc());
4594 Expr *Size = TL.getSizeExpr();
4596 EnterExpressionEvaluationContext Unevaluated(
4597 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4598 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4599 Size = SemaRef.ActOnConstantExpression(Size).get();
4601 NewTL.setSizeExpr(Size);
4606 template<typename Derived>
4607 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4608 TypeLocBuilder &TLB,
4609 IncompleteArrayTypeLoc TL) {
4610 const IncompleteArrayType *T = TL.getTypePtr();
4611 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4612 if (ElementType.isNull())
4615 QualType Result = TL.getType();
4616 if (getDerived().AlwaysRebuild() ||
4617 ElementType != T->getElementType()) {
4618 Result = getDerived().RebuildIncompleteArrayType(ElementType,
4619 T->getSizeModifier(),
4620 T->getIndexTypeCVRQualifiers(),
4621 TL.getBracketsRange());
4622 if (Result.isNull())
4626 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4627 NewTL.setLBracketLoc(TL.getLBracketLoc());
4628 NewTL.setRBracketLoc(TL.getRBracketLoc());
4629 NewTL.setSizeExpr(nullptr);
4634 template<typename Derived>
4636 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4637 VariableArrayTypeLoc TL) {
4638 const VariableArrayType *T = TL.getTypePtr();
4639 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4640 if (ElementType.isNull())
4643 ExprResult SizeResult;
4645 EnterExpressionEvaluationContext Context(
4646 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
4647 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4649 if (SizeResult.isInvalid())
4651 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
4652 if (SizeResult.isInvalid())
4655 Expr *Size = SizeResult.get();
4657 QualType Result = TL.getType();
4658 if (getDerived().AlwaysRebuild() ||
4659 ElementType != T->getElementType() ||
4660 Size != T->getSizeExpr()) {
4661 Result = getDerived().RebuildVariableArrayType(ElementType,
4662 T->getSizeModifier(),
4664 T->getIndexTypeCVRQualifiers(),
4665 TL.getBracketsRange());
4666 if (Result.isNull())
4670 // We might have constant size array now, but fortunately it has the same
4672 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4673 NewTL.setLBracketLoc(TL.getLBracketLoc());
4674 NewTL.setRBracketLoc(TL.getRBracketLoc());
4675 NewTL.setSizeExpr(Size);
4680 template<typename Derived>
4682 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4683 DependentSizedArrayTypeLoc TL) {
4684 const DependentSizedArrayType *T = TL.getTypePtr();
4685 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4686 if (ElementType.isNull())
4689 // Array bounds are constant expressions.
4690 EnterExpressionEvaluationContext Unevaluated(
4691 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4693 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4694 Expr *origSize = TL.getSizeExpr();
4695 if (!origSize) origSize = T->getSizeExpr();
4697 ExprResult sizeResult
4698 = getDerived().TransformExpr(origSize);
4699 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4700 if (sizeResult.isInvalid())
4703 Expr *size = sizeResult.get();
4705 QualType Result = TL.getType();
4706 if (getDerived().AlwaysRebuild() ||
4707 ElementType != T->getElementType() ||
4709 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4710 T->getSizeModifier(),
4712 T->getIndexTypeCVRQualifiers(),
4713 TL.getBracketsRange());
4714 if (Result.isNull())
4718 // We might have any sort of array type now, but fortunately they
4719 // all have the same location layout.
4720 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4721 NewTL.setLBracketLoc(TL.getLBracketLoc());
4722 NewTL.setRBracketLoc(TL.getRBracketLoc());
4723 NewTL.setSizeExpr(size);
4728 template<typename Derived>
4729 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4730 TypeLocBuilder &TLB,
4731 DependentSizedExtVectorTypeLoc TL) {
4732 const DependentSizedExtVectorType *T = TL.getTypePtr();
4734 // FIXME: ext vector locs should be nested
4735 QualType ElementType = getDerived().TransformType(T->getElementType());
4736 if (ElementType.isNull())
4739 // Vector sizes are constant expressions.
4740 EnterExpressionEvaluationContext Unevaluated(
4741 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4743 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4744 Size = SemaRef.ActOnConstantExpression(Size);
4745 if (Size.isInvalid())
4748 QualType Result = TL.getType();
4749 if (getDerived().AlwaysRebuild() ||
4750 ElementType != T->getElementType() ||
4751 Size.get() != T->getSizeExpr()) {
4752 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4754 T->getAttributeLoc());
4755 if (Result.isNull())
4759 // Result might be dependent or not.
4760 if (isa<DependentSizedExtVectorType>(Result)) {
4761 DependentSizedExtVectorTypeLoc NewTL
4762 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4763 NewTL.setNameLoc(TL.getNameLoc());
4765 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4766 NewTL.setNameLoc(TL.getNameLoc());
4772 template<typename Derived>
4773 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4775 const VectorType *T = TL.getTypePtr();
4776 QualType ElementType = getDerived().TransformType(T->getElementType());
4777 if (ElementType.isNull())
4780 QualType Result = TL.getType();
4781 if (getDerived().AlwaysRebuild() ||
4782 ElementType != T->getElementType()) {
4783 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4784 T->getVectorKind());
4785 if (Result.isNull())
4789 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4790 NewTL.setNameLoc(TL.getNameLoc());
4795 template<typename Derived>
4796 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4797 ExtVectorTypeLoc TL) {
4798 const VectorType *T = TL.getTypePtr();
4799 QualType ElementType = getDerived().TransformType(T->getElementType());
4800 if (ElementType.isNull())
4803 QualType Result = TL.getType();
4804 if (getDerived().AlwaysRebuild() ||
4805 ElementType != T->getElementType()) {
4806 Result = getDerived().RebuildExtVectorType(ElementType,
4807 T->getNumElements(),
4808 /*FIXME*/ SourceLocation());
4809 if (Result.isNull())
4813 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4814 NewTL.setNameLoc(TL.getNameLoc());
4819 template <typename Derived>
4820 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4821 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4822 bool ExpectParameterPack) {
4823 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4824 TypeSourceInfo *NewDI = nullptr;
4826 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4827 // If we're substituting into a pack expansion type and we know the
4828 // length we want to expand to, just substitute for the pattern.
4829 TypeLoc OldTL = OldDI->getTypeLoc();
4830 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4833 TypeLoc NewTL = OldDI->getTypeLoc();
4834 TLB.reserve(NewTL.getFullDataSize());
4836 QualType Result = getDerived().TransformType(TLB,
4837 OldExpansionTL.getPatternLoc());
4838 if (Result.isNull())
4841 Result = RebuildPackExpansionType(Result,
4842 OldExpansionTL.getPatternLoc().getSourceRange(),
4843 OldExpansionTL.getEllipsisLoc(),
4845 if (Result.isNull())
4848 PackExpansionTypeLoc NewExpansionTL
4849 = TLB.push<PackExpansionTypeLoc>(Result);
4850 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4851 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4853 NewDI = getDerived().TransformType(OldDI);
4857 if (NewDI == OldDI && indexAdjustment == 0)
4860 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4861 OldParm->getDeclContext(),
4862 OldParm->getInnerLocStart(),
4863 OldParm->getLocation(),
4864 OldParm->getIdentifier(),
4867 OldParm->getStorageClass(),
4868 /* DefArg */ nullptr);
4869 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4870 OldParm->getFunctionScopeIndex() + indexAdjustment);
4874 template <typename Derived>
4875 bool TreeTransform<Derived>::TransformFunctionTypeParams(
4876 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4877 const QualType *ParamTypes,
4878 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4879 SmallVectorImpl<QualType> &OutParamTypes,
4880 SmallVectorImpl<ParmVarDecl *> *PVars,
4881 Sema::ExtParameterInfoBuilder &PInfos) {
4882 int indexAdjustment = 0;
4884 unsigned NumParams = Params.size();
4885 for (unsigned i = 0; i != NumParams; ++i) {
4886 if (ParmVarDecl *OldParm = Params[i]) {
4887 assert(OldParm->getFunctionScopeIndex() == i);
4889 Optional<unsigned> NumExpansions;
4890 ParmVarDecl *NewParm = nullptr;
4891 if (OldParm->isParameterPack()) {
4892 // We have a function parameter pack that may need to be expanded.
4893 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4895 // Find the parameter packs that could be expanded.
4896 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4897 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4898 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4899 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4900 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4902 // Determine whether we should expand the parameter packs.
4903 bool ShouldExpand = false;
4904 bool RetainExpansion = false;
4905 Optional<unsigned> OrigNumExpansions =
4906 ExpansionTL.getTypePtr()->getNumExpansions();
4907 NumExpansions = OrigNumExpansions;
4908 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4909 Pattern.getSourceRange(),
4918 // Expand the function parameter pack into multiple, separate
4920 getDerived().ExpandingFunctionParameterPack(OldParm);
4921 for (unsigned I = 0; I != *NumExpansions; ++I) {
4922 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4923 ParmVarDecl *NewParm
4924 = getDerived().TransformFunctionTypeParam(OldParm,
4927 /*ExpectParameterPack=*/false);
4932 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4933 OutParamTypes.push_back(NewParm->getType());
4935 PVars->push_back(NewParm);
4938 // If we're supposed to retain a pack expansion, do so by temporarily
4939 // forgetting the partially-substituted parameter pack.
4940 if (RetainExpansion) {
4941 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4942 ParmVarDecl *NewParm
4943 = getDerived().TransformFunctionTypeParam(OldParm,
4946 /*ExpectParameterPack=*/false);
4951 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4952 OutParamTypes.push_back(NewParm->getType());
4954 PVars->push_back(NewParm);
4957 // The next parameter should have the same adjustment as the
4958 // last thing we pushed, but we post-incremented indexAdjustment
4959 // on every push. Also, if we push nothing, the adjustment should
4963 // We're done with the pack expansion.
4967 // We'll substitute the parameter now without expanding the pack
4969 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4970 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4973 /*ExpectParameterPack=*/true);
4975 NewParm = getDerived().TransformFunctionTypeParam(
4976 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4983 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4984 OutParamTypes.push_back(NewParm->getType());
4986 PVars->push_back(NewParm);
4990 // Deal with the possibility that we don't have a parameter
4991 // declaration for this parameter.
4992 QualType OldType = ParamTypes[i];
4993 bool IsPackExpansion = false;
4994 Optional<unsigned> NumExpansions;
4996 if (const PackExpansionType *Expansion
4997 = dyn_cast<PackExpansionType>(OldType)) {
4998 // We have a function parameter pack that may need to be expanded.
4999 QualType Pattern = Expansion->getPattern();
5000 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5001 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5003 // Determine whether we should expand the parameter packs.
5004 bool ShouldExpand = false;
5005 bool RetainExpansion = false;
5006 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
5015 // Expand the function parameter pack into multiple, separate
5017 for (unsigned I = 0; I != *NumExpansions; ++I) {
5018 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5019 QualType NewType = getDerived().TransformType(Pattern);
5020 if (NewType.isNull())
5023 if (NewType->containsUnexpandedParameterPack()) {
5025 getSema().getASTContext().getPackExpansionType(NewType, None);
5027 if (NewType.isNull())
5032 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5033 OutParamTypes.push_back(NewType);
5035 PVars->push_back(nullptr);
5038 // We're done with the pack expansion.
5042 // If we're supposed to retain a pack expansion, do so by temporarily
5043 // forgetting the partially-substituted parameter pack.
5044 if (RetainExpansion) {
5045 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5046 QualType NewType = getDerived().TransformType(Pattern);
5047 if (NewType.isNull())
5051 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5052 OutParamTypes.push_back(NewType);
5054 PVars->push_back(nullptr);
5057 // We'll substitute the parameter now without expanding the pack
5059 OldType = Expansion->getPattern();
5060 IsPackExpansion = true;
5061 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5062 NewType = getDerived().TransformType(OldType);
5064 NewType = getDerived().TransformType(OldType);
5067 if (NewType.isNull())
5070 if (IsPackExpansion)
5071 NewType = getSema().Context.getPackExpansionType(NewType,
5075 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5076 OutParamTypes.push_back(NewType);
5078 PVars->push_back(nullptr);
5083 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5084 if (ParmVarDecl *parm = (*PVars)[i])
5085 assert(parm->getFunctionScopeIndex() == i);
5092 template<typename Derived>
5094 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
5095 FunctionProtoTypeLoc TL) {
5096 SmallVector<QualType, 4> ExceptionStorage;
5097 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
5098 return getDerived().TransformFunctionProtoType(
5099 TLB, TL, nullptr, 0,
5100 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5101 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5102 ExceptionStorage, Changed);
5106 template<typename Derived> template<typename Fn>
5107 QualType TreeTransform<Derived>::TransformFunctionProtoType(
5108 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5109 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
5111 // Transform the parameters and return type.
5113 // We are required to instantiate the params and return type in source order.
5114 // When the function has a trailing return type, we instantiate the
5115 // parameters before the return type, since the return type can then refer
5116 // to the parameters themselves (via decltype, sizeof, etc.).
5118 SmallVector<QualType, 4> ParamTypes;
5119 SmallVector<ParmVarDecl*, 4> ParamDecls;
5120 Sema::ExtParameterInfoBuilder ExtParamInfos;
5121 const FunctionProtoType *T = TL.getTypePtr();
5123 QualType ResultType;
5125 if (T->hasTrailingReturn()) {
5126 if (getDerived().TransformFunctionTypeParams(
5127 TL.getBeginLoc(), TL.getParams(),
5128 TL.getTypePtr()->param_type_begin(),
5129 T->getExtParameterInfosOrNull(),
5130 ParamTypes, &ParamDecls, ExtParamInfos))
5134 // C++11 [expr.prim.general]p3:
5135 // If a declaration declares a member function or member function
5136 // template of a class X, the expression this is a prvalue of type
5137 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
5138 // and the end of the function-definition, member-declarator, or
5140 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
5142 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5143 if (ResultType.isNull())
5148 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5149 if (ResultType.isNull())
5152 if (getDerived().TransformFunctionTypeParams(
5153 TL.getBeginLoc(), TL.getParams(),
5154 TL.getTypePtr()->param_type_begin(),
5155 T->getExtParameterInfosOrNull(),
5156 ParamTypes, &ParamDecls, ExtParamInfos))
5160 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5162 bool EPIChanged = false;
5163 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5166 // Handle extended parameter information.
5167 if (auto NewExtParamInfos =
5168 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5169 if (!EPI.ExtParameterInfos ||
5170 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5171 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5174 EPI.ExtParameterInfos = NewExtParamInfos;
5175 } else if (EPI.ExtParameterInfos) {
5177 EPI.ExtParameterInfos = nullptr;
5180 QualType Result = TL.getType();
5181 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
5182 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
5183 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
5184 if (Result.isNull())
5188 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
5189 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5190 NewTL.setLParenLoc(TL.getLParenLoc());
5191 NewTL.setRParenLoc(TL.getRParenLoc());
5192 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
5193 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5194 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5195 NewTL.setParam(i, ParamDecls[i]);
5200 template<typename Derived>
5201 bool TreeTransform<Derived>::TransformExceptionSpec(
5202 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5203 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5204 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5206 // Instantiate a dynamic noexcept expression, if any.
5207 if (ESI.Type == EST_ComputedNoexcept) {
5208 EnterExpressionEvaluationContext Unevaluated(
5209 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
5210 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5211 if (NoexceptExpr.isInvalid())
5214 // FIXME: This is bogus, a noexcept expression is not a condition.
5215 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
5216 if (NoexceptExpr.isInvalid())
5219 if (!NoexceptExpr.get()->isValueDependent()) {
5220 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5221 NoexceptExpr.get(), nullptr,
5222 diag::err_noexcept_needs_constant_expression,
5223 /*AllowFold*/false);
5224 if (NoexceptExpr.isInvalid())
5228 if (ESI.NoexceptExpr != NoexceptExpr.get())
5230 ESI.NoexceptExpr = NoexceptExpr.get();
5233 if (ESI.Type != EST_Dynamic)
5236 // Instantiate a dynamic exception specification's type.
5237 for (QualType T : ESI.Exceptions) {
5238 if (const PackExpansionType *PackExpansion =
5239 T->getAs<PackExpansionType>()) {
5242 // We have a pack expansion. Instantiate it.
5243 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5244 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5246 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5248 // Determine whether the set of unexpanded parameter packs can and
5251 bool Expand = false;
5252 bool RetainExpansion = false;
5253 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5254 // FIXME: Track the location of the ellipsis (and track source location
5255 // information for the types in the exception specification in general).
5256 if (getDerived().TryExpandParameterPacks(
5257 Loc, SourceRange(), Unexpanded, Expand,
5258 RetainExpansion, NumExpansions))
5262 // We can't expand this pack expansion into separate arguments yet;
5263 // just substitute into the pattern and create a new pack expansion
5265 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5266 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5270 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5271 Exceptions.push_back(U);
5275 // Substitute into the pack expansion pattern for each slice of the
5277 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5278 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5280 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5281 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5284 Exceptions.push_back(U);
5287 QualType U = getDerived().TransformType(T);
5288 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5293 Exceptions.push_back(U);
5297 ESI.Exceptions = Exceptions;
5298 if (ESI.Exceptions.empty())
5299 ESI.Type = EST_DynamicNone;
5303 template<typename Derived>
5304 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
5305 TypeLocBuilder &TLB,
5306 FunctionNoProtoTypeLoc TL) {
5307 const FunctionNoProtoType *T = TL.getTypePtr();
5308 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5309 if (ResultType.isNull())
5312 QualType Result = TL.getType();
5313 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5314 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5316 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5317 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5318 NewTL.setLParenLoc(TL.getLParenLoc());
5319 NewTL.setRParenLoc(TL.getRParenLoc());
5320 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5325 template<typename Derived> QualType
5326 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5327 UnresolvedUsingTypeLoc TL) {
5328 const UnresolvedUsingType *T = TL.getTypePtr();
5329 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5333 QualType Result = TL.getType();
5334 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5335 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
5336 if (Result.isNull())
5340 // We might get an arbitrary type spec type back. We should at
5341 // least always get a type spec type, though.
5342 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5343 NewTL.setNameLoc(TL.getNameLoc());
5348 template<typename Derived>
5349 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5350 TypedefTypeLoc TL) {
5351 const TypedefType *T = TL.getTypePtr();
5352 TypedefNameDecl *Typedef
5353 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5358 QualType Result = TL.getType();
5359 if (getDerived().AlwaysRebuild() ||
5360 Typedef != T->getDecl()) {
5361 Result = getDerived().RebuildTypedefType(Typedef);
5362 if (Result.isNull())
5366 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5367 NewTL.setNameLoc(TL.getNameLoc());
5372 template<typename Derived>
5373 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5374 TypeOfExprTypeLoc TL) {
5375 // typeof expressions are not potentially evaluated contexts
5376 EnterExpressionEvaluationContext Unevaluated(
5377 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5378 Sema::ReuseLambdaContextDecl);
5380 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5384 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5388 QualType Result = TL.getType();
5389 if (getDerived().AlwaysRebuild() ||
5390 E.get() != TL.getUnderlyingExpr()) {
5391 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5392 if (Result.isNull())
5397 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5398 NewTL.setTypeofLoc(TL.getTypeofLoc());
5399 NewTL.setLParenLoc(TL.getLParenLoc());
5400 NewTL.setRParenLoc(TL.getRParenLoc());
5405 template<typename Derived>
5406 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5408 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5409 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5413 QualType Result = TL.getType();
5414 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5415 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5416 if (Result.isNull())
5420 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5421 NewTL.setTypeofLoc(TL.getTypeofLoc());
5422 NewTL.setLParenLoc(TL.getLParenLoc());
5423 NewTL.setRParenLoc(TL.getRParenLoc());
5424 NewTL.setUnderlyingTInfo(New_Under_TI);
5429 template<typename Derived>
5430 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5431 DecltypeTypeLoc TL) {
5432 const DecltypeType *T = TL.getTypePtr();
5434 // decltype expressions are not potentially evaluated contexts
5435 EnterExpressionEvaluationContext Unevaluated(
5436 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
5437 /*IsDecltype=*/true);
5439 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5443 E = getSema().ActOnDecltypeExpression(E.get());
5447 QualType Result = TL.getType();
5448 if (getDerived().AlwaysRebuild() ||
5449 E.get() != T->getUnderlyingExpr()) {
5450 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5451 if (Result.isNull())
5456 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5457 NewTL.setNameLoc(TL.getNameLoc());
5462 template<typename Derived>
5463 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5464 TypeLocBuilder &TLB,
5465 UnaryTransformTypeLoc TL) {
5466 QualType Result = TL.getType();
5467 if (Result->isDependentType()) {
5468 const UnaryTransformType *T = TL.getTypePtr();
5470 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5471 Result = getDerived().RebuildUnaryTransformType(NewBase,
5474 if (Result.isNull())
5478 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5479 NewTL.setKWLoc(TL.getKWLoc());
5480 NewTL.setParensRange(TL.getParensRange());
5481 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5485 template<typename Derived>
5486 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5488 const AutoType *T = TL.getTypePtr();
5489 QualType OldDeduced = T->getDeducedType();
5490 QualType NewDeduced;
5491 if (!OldDeduced.isNull()) {
5492 NewDeduced = getDerived().TransformType(OldDeduced);
5493 if (NewDeduced.isNull())
5497 QualType Result = TL.getType();
5498 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5499 T->isDependentType()) {
5500 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5501 if (Result.isNull())
5505 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5506 NewTL.setNameLoc(TL.getNameLoc());
5511 template<typename Derived>
5512 QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5513 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5514 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5517 TemplateName TemplateName = getDerived().TransformTemplateName(
5518 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5519 if (TemplateName.isNull())
5522 QualType OldDeduced = T->getDeducedType();
5523 QualType NewDeduced;
5524 if (!OldDeduced.isNull()) {
5525 NewDeduced = getDerived().TransformType(OldDeduced);
5526 if (NewDeduced.isNull())
5530 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5531 TemplateName, NewDeduced);
5532 if (Result.isNull())
5535 DeducedTemplateSpecializationTypeLoc NewTL =
5536 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5537 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5542 template<typename Derived>
5543 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5545 const RecordType *T = TL.getTypePtr();
5547 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5552 QualType Result = TL.getType();
5553 if (getDerived().AlwaysRebuild() ||
5554 Record != T->getDecl()) {
5555 Result = getDerived().RebuildRecordType(Record);
5556 if (Result.isNull())
5560 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5561 NewTL.setNameLoc(TL.getNameLoc());
5566 template<typename Derived>
5567 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5569 const EnumType *T = TL.getTypePtr();
5571 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5576 QualType Result = TL.getType();
5577 if (getDerived().AlwaysRebuild() ||
5578 Enum != T->getDecl()) {
5579 Result = getDerived().RebuildEnumType(Enum);
5580 if (Result.isNull())
5584 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5585 NewTL.setNameLoc(TL.getNameLoc());
5590 template<typename Derived>
5591 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5592 TypeLocBuilder &TLB,
5593 InjectedClassNameTypeLoc TL) {
5594 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5595 TL.getTypePtr()->getDecl());
5596 if (!D) return QualType();
5598 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5599 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5603 template<typename Derived>
5604 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5605 TypeLocBuilder &TLB,
5606 TemplateTypeParmTypeLoc TL) {
5607 return TransformTypeSpecType(TLB, TL);
5610 template<typename Derived>
5611 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5612 TypeLocBuilder &TLB,
5613 SubstTemplateTypeParmTypeLoc TL) {
5614 const SubstTemplateTypeParmType *T = TL.getTypePtr();
5616 // Substitute into the replacement type, which itself might involve something
5617 // that needs to be transformed. This only tends to occur with default
5618 // template arguments of template template parameters.
5619 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5620 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5621 if (Replacement.isNull())
5624 // Always canonicalize the replacement type.
5625 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5627 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5630 // Propagate type-source information.
5631 SubstTemplateTypeParmTypeLoc NewTL
5632 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5633 NewTL.setNameLoc(TL.getNameLoc());
5638 template<typename Derived>
5639 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5640 TypeLocBuilder &TLB,
5641 SubstTemplateTypeParmPackTypeLoc TL) {
5642 return TransformTypeSpecType(TLB, TL);
5645 template<typename Derived>
5646 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5647 TypeLocBuilder &TLB,
5648 TemplateSpecializationTypeLoc TL) {
5649 const TemplateSpecializationType *T = TL.getTypePtr();
5651 // The nested-name-specifier never matters in a TemplateSpecializationType,
5652 // because we can't have a dependent nested-name-specifier anyway.
5654 TemplateName Template
5655 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5656 TL.getTemplateNameLoc());
5657 if (Template.isNull())
5660 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5663 template<typename Derived>
5664 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5666 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5667 if (ValueType.isNull())
5670 QualType Result = TL.getType();
5671 if (getDerived().AlwaysRebuild() ||
5672 ValueType != TL.getValueLoc().getType()) {
5673 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5674 if (Result.isNull())
5678 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5679 NewTL.setKWLoc(TL.getKWLoc());
5680 NewTL.setLParenLoc(TL.getLParenLoc());
5681 NewTL.setRParenLoc(TL.getRParenLoc());
5686 template <typename Derived>
5687 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5689 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5690 if (ValueType.isNull())
5693 QualType Result = TL.getType();
5694 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5695 const PipeType *PT = Result->getAs<PipeType>();
5696 bool isReadPipe = PT->isReadOnly();
5697 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
5698 if (Result.isNull())
5702 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5703 NewTL.setKWLoc(TL.getKWLoc());
5708 /// \brief Simple iterator that traverses the template arguments in a
5709 /// container that provides a \c getArgLoc() member function.
5711 /// This iterator is intended to be used with the iterator form of
5712 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5713 template<typename ArgLocContainer>
5714 class TemplateArgumentLocContainerIterator {
5715 ArgLocContainer *Container;
5719 typedef TemplateArgumentLoc value_type;
5720 typedef TemplateArgumentLoc reference;
5721 typedef int difference_type;
5722 typedef std::input_iterator_tag iterator_category;
5725 TemplateArgumentLoc Arg;
5728 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5730 const TemplateArgumentLoc *operator->() const {
5736 TemplateArgumentLocContainerIterator() {}
5738 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5740 : Container(&Container), Index(Index) { }
5742 TemplateArgumentLocContainerIterator &operator++() {
5747 TemplateArgumentLocContainerIterator operator++(int) {
5748 TemplateArgumentLocContainerIterator Old(*this);
5753 TemplateArgumentLoc operator*() const {
5754 return Container->getArgLoc(Index);
5757 pointer operator->() const {
5758 return pointer(Container->getArgLoc(Index));
5761 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
5762 const TemplateArgumentLocContainerIterator &Y) {
5763 return X.Container == Y.Container && X.Index == Y.Index;
5766 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
5767 const TemplateArgumentLocContainerIterator &Y) {
5773 template <typename Derived>
5774 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5775 TypeLocBuilder &TLB,
5776 TemplateSpecializationTypeLoc TL,
5777 TemplateName Template) {
5778 TemplateArgumentListInfo NewTemplateArgs;
5779 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5780 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5781 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5783 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5784 ArgIterator(TL, TL.getNumArgs()),
5788 // FIXME: maybe don't rebuild if all the template arguments are the same.
5791 getDerived().RebuildTemplateSpecializationType(Template,
5792 TL.getTemplateNameLoc(),
5795 if (!Result.isNull()) {
5796 // Specializations of template template parameters are represented as
5797 // TemplateSpecializationTypes, and substitution of type alias templates
5798 // within a dependent context can transform them into
5799 // DependentTemplateSpecializationTypes.
5800 if (isa<DependentTemplateSpecializationType>(Result)) {
5801 DependentTemplateSpecializationTypeLoc NewTL
5802 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5803 NewTL.setElaboratedKeywordLoc(SourceLocation());
5804 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5805 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5806 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5807 NewTL.setLAngleLoc(TL.getLAngleLoc());
5808 NewTL.setRAngleLoc(TL.getRAngleLoc());
5809 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5810 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5814 TemplateSpecializationTypeLoc NewTL
5815 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5816 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5817 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5818 NewTL.setLAngleLoc(TL.getLAngleLoc());
5819 NewTL.setRAngleLoc(TL.getRAngleLoc());
5820 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5821 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5827 template <typename Derived>
5828 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5829 TypeLocBuilder &TLB,
5830 DependentTemplateSpecializationTypeLoc TL,
5831 TemplateName Template,
5833 TemplateArgumentListInfo NewTemplateArgs;
5834 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5835 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5836 typedef TemplateArgumentLocContainerIterator<
5837 DependentTemplateSpecializationTypeLoc> ArgIterator;
5838 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5839 ArgIterator(TL, TL.getNumArgs()),
5843 // FIXME: maybe don't rebuild if all the template arguments are the same.
5845 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5847 = getSema().Context.getDependentTemplateSpecializationType(
5848 TL.getTypePtr()->getKeyword(),
5849 DTN->getQualifier(),
5850 DTN->getIdentifier(),
5853 DependentTemplateSpecializationTypeLoc NewTL
5854 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5855 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5856 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5857 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5858 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5859 NewTL.setLAngleLoc(TL.getLAngleLoc());
5860 NewTL.setRAngleLoc(TL.getRAngleLoc());
5861 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5862 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5867 = getDerived().RebuildTemplateSpecializationType(Template,
5868 TL.getTemplateNameLoc(),
5871 if (!Result.isNull()) {
5872 /// FIXME: Wrap this in an elaborated-type-specifier?
5873 TemplateSpecializationTypeLoc NewTL
5874 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5875 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5876 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5877 NewTL.setLAngleLoc(TL.getLAngleLoc());
5878 NewTL.setRAngleLoc(TL.getRAngleLoc());
5879 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5880 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5886 template<typename Derived>
5888 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
5889 ElaboratedTypeLoc TL) {
5890 const ElaboratedType *T = TL.getTypePtr();
5892 NestedNameSpecifierLoc QualifierLoc;
5893 // NOTE: the qualifier in an ElaboratedType is optional.
5894 if (TL.getQualifierLoc()) {
5896 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5901 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5902 if (NamedT.isNull())
5905 // C++0x [dcl.type.elab]p2:
5906 // If the identifier resolves to a typedef-name or the simple-template-id
5907 // resolves to an alias template specialization, the
5908 // elaborated-type-specifier is ill-formed.
5909 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5910 if (const TemplateSpecializationType *TST =
5911 NamedT->getAs<TemplateSpecializationType>()) {
5912 TemplateName Template = TST->getTemplateName();
5913 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5914 Template.getAsTemplateDecl())) {
5915 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5916 diag::err_tag_reference_non_tag)
5917 << TAT << Sema::NTK_TypeAliasTemplate
5918 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
5919 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5924 QualType Result = TL.getType();
5925 if (getDerived().AlwaysRebuild() ||
5926 QualifierLoc != TL.getQualifierLoc() ||
5927 NamedT != T->getNamedType()) {
5928 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5930 QualifierLoc, NamedT);
5931 if (Result.isNull())
5935 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5936 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5937 NewTL.setQualifierLoc(QualifierLoc);
5941 template<typename Derived>
5942 QualType TreeTransform<Derived>::TransformAttributedType(
5943 TypeLocBuilder &TLB,
5944 AttributedTypeLoc TL) {
5945 const AttributedType *oldType = TL.getTypePtr();
5946 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5947 if (modifiedType.isNull())
5950 QualType result = TL.getType();
5952 // FIXME: dependent operand expressions?
5953 if (getDerived().AlwaysRebuild() ||
5954 modifiedType != oldType->getModifiedType()) {
5955 // TODO: this is really lame; we should really be rebuilding the
5956 // equivalent type from first principles.
5957 QualType equivalentType
5958 = getDerived().TransformType(oldType->getEquivalentType());
5959 if (equivalentType.isNull())
5962 // Check whether we can add nullability; it is only represented as
5963 // type sugar, and therefore cannot be diagnosed in any other way.
5964 if (auto nullability = oldType->getImmediateNullability()) {
5965 if (!modifiedType->canHaveNullability()) {
5966 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
5967 << DiagNullabilityKind(*nullability, false) << modifiedType;
5972 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5977 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5978 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5979 if (TL.hasAttrOperand())
5980 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5981 if (TL.hasAttrExprOperand())
5982 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5983 else if (TL.hasAttrEnumOperand())
5984 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5989 template<typename Derived>
5991 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5993 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5997 QualType Result = TL.getType();
5998 if (getDerived().AlwaysRebuild() ||
5999 Inner != TL.getInnerLoc().getType()) {
6000 Result = getDerived().RebuildParenType(Inner);
6001 if (Result.isNull())
6005 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6006 NewTL.setLParenLoc(TL.getLParenLoc());
6007 NewTL.setRParenLoc(TL.getRParenLoc());
6011 template<typename Derived>
6012 QualType TreeTransform<Derived>::TransformDependentNameType(
6013 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6014 return TransformDependentNameType(TLB, TL, false);
6017 template<typename Derived>
6018 QualType TreeTransform<Derived>::TransformDependentNameType(
6019 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
6020 const DependentNameType *T = TL.getTypePtr();
6022 NestedNameSpecifierLoc QualifierLoc
6023 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6028 = getDerived().RebuildDependentNameType(T->getKeyword(),
6029 TL.getElaboratedKeywordLoc(),
6034 if (Result.isNull())
6037 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6038 QualType NamedT = ElabT->getNamedType();
6039 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6041 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6042 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6043 NewTL.setQualifierLoc(QualifierLoc);
6045 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
6046 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6047 NewTL.setQualifierLoc(QualifierLoc);
6048 NewTL.setNameLoc(TL.getNameLoc());
6053 template<typename Derived>
6054 QualType TreeTransform<Derived>::
6055 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6056 DependentTemplateSpecializationTypeLoc TL) {
6057 NestedNameSpecifierLoc QualifierLoc;
6058 if (TL.getQualifierLoc()) {
6060 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6066 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
6069 template<typename Derived>
6070 QualType TreeTransform<Derived>::
6071 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6072 DependentTemplateSpecializationTypeLoc TL,
6073 NestedNameSpecifierLoc QualifierLoc) {
6074 const DependentTemplateSpecializationType *T = TL.getTypePtr();
6076 TemplateArgumentListInfo NewTemplateArgs;
6077 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6078 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6080 typedef TemplateArgumentLocContainerIterator<
6081 DependentTemplateSpecializationTypeLoc> ArgIterator;
6082 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6083 ArgIterator(TL, TL.getNumArgs()),
6087 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6088 T->getKeyword(), QualifierLoc, T->getIdentifier(),
6089 TL.getTemplateNameLoc(), NewTemplateArgs,
6090 /*AllowInjectedClassName*/ false);
6091 if (Result.isNull())
6094 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6095 QualType NamedT = ElabT->getNamedType();
6097 // Copy information relevant to the template specialization.
6098 TemplateSpecializationTypeLoc NamedTL
6099 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
6100 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6101 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6102 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6103 NamedTL.setRAngleLoc(TL.getRAngleLoc());
6104 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6105 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6107 // Copy information relevant to the elaborated type.
6108 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6109 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6110 NewTL.setQualifierLoc(QualifierLoc);
6111 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6112 DependentTemplateSpecializationTypeLoc SpecTL
6113 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
6114 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6115 SpecTL.setQualifierLoc(QualifierLoc);
6116 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6117 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6118 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6119 SpecTL.setRAngleLoc(TL.getRAngleLoc());
6120 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6121 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6123 TemplateSpecializationTypeLoc SpecTL
6124 = TLB.push<TemplateSpecializationTypeLoc>(Result);
6125 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6126 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6127 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6128 SpecTL.setRAngleLoc(TL.getRAngleLoc());
6129 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6130 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6135 template<typename Derived>
6136 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6137 PackExpansionTypeLoc TL) {
6139 = getDerived().TransformType(TLB, TL.getPatternLoc());
6140 if (Pattern.isNull())
6143 QualType Result = TL.getType();
6144 if (getDerived().AlwaysRebuild() ||
6145 Pattern != TL.getPatternLoc().getType()) {
6146 Result = getDerived().RebuildPackExpansionType(Pattern,
6147 TL.getPatternLoc().getSourceRange(),
6148 TL.getEllipsisLoc(),
6149 TL.getTypePtr()->getNumExpansions());
6150 if (Result.isNull())
6154 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6155 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6159 template<typename Derived>
6161 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
6162 ObjCInterfaceTypeLoc TL) {
6163 // ObjCInterfaceType is never dependent.
6164 TLB.pushFullCopy(TL);
6165 return TL.getType();
6168 template<typename Derived>
6170 TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6171 ObjCTypeParamTypeLoc TL) {
6172 const ObjCTypeParamType *T = TL.getTypePtr();
6173 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6174 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6178 QualType Result = TL.getType();
6179 if (getDerived().AlwaysRebuild() ||
6180 OTP != T->getDecl()) {
6181 Result = getDerived().RebuildObjCTypeParamType(OTP,
6182 TL.getProtocolLAngleLoc(),
6183 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6184 TL.getNumProtocols()),
6185 TL.getProtocolLocs(),
6186 TL.getProtocolRAngleLoc());
6187 if (Result.isNull())
6191 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6192 if (TL.getNumProtocols()) {
6193 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6194 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6195 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6196 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6201 template<typename Derived>
6203 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
6204 ObjCObjectTypeLoc TL) {
6205 // Transform base type.
6206 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6207 if (BaseType.isNull())
6210 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6212 // Transform type arguments.
6213 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6214 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6215 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6216 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6217 QualType TypeArg = TypeArgInfo->getType();
6218 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6221 // We have a pack expansion. Instantiate it.
6222 const auto *PackExpansion = PackExpansionLoc.getType()
6223 ->castAs<PackExpansionType>();
6224 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6225 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6227 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6229 // Determine whether the set of unexpanded parameter packs can
6230 // and should be expanded.
6231 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6232 bool Expand = false;
6233 bool RetainExpansion = false;
6234 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6235 if (getDerived().TryExpandParameterPacks(
6236 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6237 Unexpanded, Expand, RetainExpansion, NumExpansions))
6241 // We can't expand this pack expansion into separate arguments yet;
6242 // just substitute into the pattern and create a new pack expansion
6244 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6246 TypeLocBuilder TypeArgBuilder;
6247 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6248 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6250 if (NewPatternType.isNull())
6253 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6254 NewPatternType, NumExpansions);
6255 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6256 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6257 NewTypeArgInfos.push_back(
6258 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6262 // Substitute into the pack expansion pattern for each slice of the
6264 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6265 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6267 TypeLocBuilder TypeArgBuilder;
6268 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6270 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6272 if (NewTypeArg.isNull())
6275 NewTypeArgInfos.push_back(
6276 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6282 TypeLocBuilder TypeArgBuilder;
6283 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6284 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6285 if (NewTypeArg.isNull())
6288 // If nothing changed, just keep the old TypeSourceInfo.
6289 if (NewTypeArg == TypeArg) {
6290 NewTypeArgInfos.push_back(TypeArgInfo);
6294 NewTypeArgInfos.push_back(
6295 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6299 QualType Result = TL.getType();
6300 if (getDerived().AlwaysRebuild() || AnyChanged) {
6301 // Rebuild the type.
6302 Result = getDerived().RebuildObjCObjectType(
6305 TL.getTypeArgsLAngleLoc(),
6307 TL.getTypeArgsRAngleLoc(),
6308 TL.getProtocolLAngleLoc(),
6309 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6310 TL.getNumProtocols()),
6311 TL.getProtocolLocs(),
6312 TL.getProtocolRAngleLoc());
6314 if (Result.isNull())
6318 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
6319 NewT.setHasBaseTypeAsWritten(true);
6320 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6321 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6322 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6323 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6324 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6325 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6326 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6327 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6331 template<typename Derived>
6333 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
6334 ObjCObjectPointerTypeLoc TL) {
6335 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6336 if (PointeeType.isNull())
6339 QualType Result = TL.getType();
6340 if (getDerived().AlwaysRebuild() ||
6341 PointeeType != TL.getPointeeLoc().getType()) {
6342 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6344 if (Result.isNull())
6348 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6349 NewT.setStarLoc(TL.getStarLoc());
6353 //===----------------------------------------------------------------------===//
6354 // Statement transformation
6355 //===----------------------------------------------------------------------===//
6356 template<typename Derived>
6358 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
6362 template<typename Derived>
6364 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6365 return getDerived().TransformCompoundStmt(S, false);
6368 template<typename Derived>
6370 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
6372 Sema::CompoundScopeRAII CompoundScope(getSema());
6374 bool SubStmtInvalid = false;
6375 bool SubStmtChanged = false;
6376 SmallVector<Stmt*, 8> Statements;
6377 for (auto *B : S->body()) {
6378 StmtResult Result = getDerived().TransformStmt(B);
6379 if (Result.isInvalid()) {
6380 // Immediately fail if this was a DeclStmt, since it's very
6381 // likely that this will cause problems for future statements.
6382 if (isa<DeclStmt>(B))
6385 // Otherwise, just keep processing substatements and fail later.
6386 SubStmtInvalid = true;
6390 SubStmtChanged = SubStmtChanged || Result.get() != B;
6391 Statements.push_back(Result.getAs<Stmt>());
6397 if (!getDerived().AlwaysRebuild() &&
6401 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6407 template<typename Derived>
6409 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6410 ExprResult LHS, RHS;
6412 EnterExpressionEvaluationContext Unevaluated(
6413 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
6415 // Transform the left-hand case value.
6416 LHS = getDerived().TransformExpr(S->getLHS());
6417 LHS = SemaRef.ActOnConstantExpression(LHS);
6418 if (LHS.isInvalid())
6421 // Transform the right-hand case value (for the GNU case-range extension).
6422 RHS = getDerived().TransformExpr(S->getRHS());
6423 RHS = SemaRef.ActOnConstantExpression(RHS);
6424 if (RHS.isInvalid())
6428 // Build the case statement.
6429 // Case statements are always rebuilt so that they will attached to their
6430 // transformed switch statement.
6431 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6433 S->getEllipsisLoc(),
6436 if (Case.isInvalid())
6439 // Transform the statement following the case
6440 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6441 if (SubStmt.isInvalid())
6444 // Attach the body to the case statement
6445 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6448 template<typename Derived>
6450 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6451 // Transform the statement following the default case
6452 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6453 if (SubStmt.isInvalid())
6456 // Default statements are always rebuilt
6457 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6461 template<typename Derived>
6463 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6464 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6465 if (SubStmt.isInvalid())
6468 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6474 // FIXME: Pass the real colon location in.
6475 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6476 cast<LabelDecl>(LD), SourceLocation(),
6480 template <typename Derived>
6481 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6485 switch (R->getKind()) {
6486 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6488 #define PRAGMA_SPELLING_ATTR(X) \
6490 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6491 #include "clang/Basic/AttrList.inc"
6497 template <typename Derived>
6498 StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6499 bool AttrsChanged = false;
6500 SmallVector<const Attr *, 1> Attrs;
6502 // Visit attributes and keep track if any are transformed.
6503 for (const auto *I : S->getAttrs()) {
6504 const Attr *R = getDerived().TransformAttr(I);
6505 AttrsChanged |= (I != R);
6509 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6510 if (SubStmt.isInvalid())
6513 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6516 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6520 template<typename Derived>
6522 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6523 // Transform the initialization statement
6524 StmtResult Init = getDerived().TransformStmt(S->getInit());
6525 if (Init.isInvalid())
6528 // Transform the condition
6529 Sema::ConditionResult Cond = getDerived().TransformCondition(
6530 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6531 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6532 : Sema::ConditionKind::Boolean);
6533 if (Cond.isInvalid())
6536 // If this is a constexpr if, determine which arm we should instantiate.
6537 llvm::Optional<bool> ConstexprConditionValue;
6538 if (S->isConstexpr())
6539 ConstexprConditionValue = Cond.getKnownValue();
6541 // Transform the "then" branch.
6543 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6544 Then = getDerived().TransformStmt(S->getThen());
6545 if (Then.isInvalid())
6548 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6551 // Transform the "else" branch.
6553 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6554 Else = getDerived().TransformStmt(S->getElse());
6555 if (Else.isInvalid())
6559 if (!getDerived().AlwaysRebuild() &&
6560 Init.get() == S->getInit() &&
6561 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6562 Then.get() == S->getThen() &&
6563 Else.get() == S->getElse())
6566 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6567 Init.get(), Then.get(), S->getElseLoc(),
6571 template<typename Derived>
6573 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6574 // Transform the initialization statement
6575 StmtResult Init = getDerived().TransformStmt(S->getInit());
6576 if (Init.isInvalid())
6579 // Transform the condition.
6580 Sema::ConditionResult Cond = getDerived().TransformCondition(
6581 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6582 Sema::ConditionKind::Switch);
6583 if (Cond.isInvalid())
6586 // Rebuild the switch statement.
6588 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6589 S->getInit(), Cond);
6590 if (Switch.isInvalid())
6593 // Transform the body of the switch statement.
6594 StmtResult Body = getDerived().TransformStmt(S->getBody());
6595 if (Body.isInvalid())
6598 // Complete the switch statement.
6599 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6603 template<typename Derived>
6605 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6606 // Transform the condition
6607 Sema::ConditionResult Cond = getDerived().TransformCondition(
6608 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6609 Sema::ConditionKind::Boolean);
6610 if (Cond.isInvalid())
6613 // Transform the body
6614 StmtResult Body = getDerived().TransformStmt(S->getBody());
6615 if (Body.isInvalid())
6618 if (!getDerived().AlwaysRebuild() &&
6619 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6620 Body.get() == S->getBody())
6623 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
6626 template<typename Derived>
6628 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6629 // Transform the body
6630 StmtResult Body = getDerived().TransformStmt(S->getBody());
6631 if (Body.isInvalid())
6634 // Transform the condition
6635 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6636 if (Cond.isInvalid())
6639 if (!getDerived().AlwaysRebuild() &&
6640 Cond.get() == S->getCond() &&
6641 Body.get() == S->getBody())
6644 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6645 /*FIXME:*/S->getWhileLoc(), Cond.get(),
6649 template<typename Derived>
6651 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6652 // Transform the initialization statement
6653 StmtResult Init = getDerived().TransformStmt(S->getInit());
6654 if (Init.isInvalid())
6657 // In OpenMP loop region loop control variable must be captured and be
6658 // private. Perform analysis of first part (if any).
6659 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6660 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6662 // Transform the condition
6663 Sema::ConditionResult Cond = getDerived().TransformCondition(
6664 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6665 Sema::ConditionKind::Boolean);
6666 if (Cond.isInvalid())
6669 // Transform the increment
6670 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6671 if (Inc.isInvalid())
6674 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6675 if (S->getInc() && !FullInc.get())
6678 // Transform the body
6679 StmtResult Body = getDerived().TransformStmt(S->getBody());
6680 if (Body.isInvalid())
6683 if (!getDerived().AlwaysRebuild() &&
6684 Init.get() == S->getInit() &&
6685 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6686 Inc.get() == S->getInc() &&
6687 Body.get() == S->getBody())
6690 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6691 Init.get(), Cond, FullInc,
6692 S->getRParenLoc(), Body.get());
6695 template<typename Derived>
6697 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6698 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6703 // Goto statements must always be rebuilt, to resolve the label.
6704 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6705 cast<LabelDecl>(LD));
6708 template<typename Derived>
6710 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6711 ExprResult Target = getDerived().TransformExpr(S->getTarget());
6712 if (Target.isInvalid())
6714 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6716 if (!getDerived().AlwaysRebuild() &&
6717 Target.get() == S->getTarget())
6720 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6724 template<typename Derived>
6726 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6730 template<typename Derived>
6732 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6736 template<typename Derived>
6738 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6739 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6740 /*NotCopyInit*/false);
6741 if (Result.isInvalid())
6744 // FIXME: We always rebuild the return statement because there is no way
6745 // to tell whether the return type of the function has changed.
6746 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6749 template<typename Derived>
6751 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6752 bool DeclChanged = false;
6753 SmallVector<Decl *, 4> Decls;
6754 for (auto *D : S->decls()) {
6755 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6759 if (Transformed != D)
6762 Decls.push_back(Transformed);
6765 if (!getDerived().AlwaysRebuild() && !DeclChanged)
6768 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6771 template<typename Derived>
6773 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6775 SmallVector<Expr*, 8> Constraints;
6776 SmallVector<Expr*, 8> Exprs;
6777 SmallVector<IdentifierInfo *, 4> Names;
6779 ExprResult AsmString;
6780 SmallVector<Expr*, 8> Clobbers;
6782 bool ExprsChanged = false;
6784 // Go through the outputs.
6785 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6786 Names.push_back(S->getOutputIdentifier(I));
6788 // No need to transform the constraint literal.
6789 Constraints.push_back(S->getOutputConstraintLiteral(I));
6791 // Transform the output expr.
6792 Expr *OutputExpr = S->getOutputExpr(I);
6793 ExprResult Result = getDerived().TransformExpr(OutputExpr);
6794 if (Result.isInvalid())
6797 ExprsChanged |= Result.get() != OutputExpr;
6799 Exprs.push_back(Result.get());
6802 // Go through the inputs.
6803 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6804 Names.push_back(S->getInputIdentifier(I));
6806 // No need to transform the constraint literal.
6807 Constraints.push_back(S->getInputConstraintLiteral(I));
6809 // Transform the input expr.
6810 Expr *InputExpr = S->getInputExpr(I);
6811 ExprResult Result = getDerived().TransformExpr(InputExpr);
6812 if (Result.isInvalid())
6815 ExprsChanged |= Result.get() != InputExpr;
6817 Exprs.push_back(Result.get());
6820 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6823 // Go through the clobbers.
6824 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6825 Clobbers.push_back(S->getClobberStringLiteral(I));
6827 // No need to transform the asm string literal.
6828 AsmString = S->getAsmString();
6829 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6830 S->isVolatile(), S->getNumOutputs(),
6831 S->getNumInputs(), Names.data(),
6832 Constraints, Exprs, AsmString.get(),
6833 Clobbers, S->getRParenLoc());
6836 template<typename Derived>
6838 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6839 ArrayRef<Token> AsmToks =
6840 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6842 bool HadError = false, HadChange = false;
6844 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6845 SmallVector<Expr*, 8> TransformedExprs;
6846 TransformedExprs.reserve(SrcExprs.size());
6847 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6848 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6849 if (!Result.isUsable()) {
6852 HadChange |= (Result.get() != SrcExprs[i]);
6853 TransformedExprs.push_back(Result.get());
6857 if (HadError) return StmtError();
6858 if (!HadChange && !getDerived().AlwaysRebuild())
6861 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6862 AsmToks, S->getAsmString(),
6863 S->getNumOutputs(), S->getNumInputs(),
6864 S->getAllConstraints(), S->getClobbers(),
6865 TransformedExprs, S->getEndLoc());
6868 // C++ Coroutines TS
6870 template<typename Derived>
6872 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6873 auto *ScopeInfo = SemaRef.getCurFunction();
6874 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
6875 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
6876 ScopeInfo->NeedsCoroutineSuspends &&
6877 ScopeInfo->CoroutineSuspends.first == nullptr &&
6878 ScopeInfo->CoroutineSuspends.second == nullptr &&
6879 "expected clean scope info");
6881 // Set that we have (possibly-invalid) suspend points before we do anything
6883 ScopeInfo->setNeedsCoroutineSuspends(false);
6885 // The new CoroutinePromise object needs to be built and put into the current
6886 // FunctionScopeInfo before any transformations or rebuilding occurs.
6887 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
6890 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
6891 ScopeInfo->CoroutinePromise = Promise;
6893 // Transform the implicit coroutine statements we built during the initial
6895 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
6896 if (InitSuspend.isInvalid())
6898 StmtResult FinalSuspend =
6899 getDerived().TransformStmt(S->getFinalSuspendStmt());
6900 if (FinalSuspend.isInvalid())
6902 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
6903 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
6905 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
6906 if (BodyRes.isInvalid())
6909 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
6910 if (Builder.isInvalid())
6913 Expr *ReturnObject = S->getReturnValueInit();
6914 assert(ReturnObject && "the return object is expected to be valid");
6915 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
6916 /*NoCopyInit*/ false);
6917 if (Res.isInvalid())
6919 Builder.ReturnValue = Res.get();
6921 if (S->hasDependentPromiseType()) {
6922 assert(!Promise->getType()->isDependentType() &&
6923 "the promise type must no longer be dependent");
6924 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
6925 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
6926 "these nodes should not have been built yet");
6927 if (!Builder.buildDependentStatements())
6930 if (auto *OnFallthrough = S->getFallthroughHandler()) {
6931 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
6932 if (Res.isInvalid())
6934 Builder.OnFallthrough = Res.get();
6937 if (auto *OnException = S->getExceptionHandler()) {
6938 StmtResult Res = getDerived().TransformStmt(OnException);
6939 if (Res.isInvalid())
6941 Builder.OnException = Res.get();
6944 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
6945 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
6946 if (Res.isInvalid())
6948 Builder.ReturnStmtOnAllocFailure = Res.get();
6951 // Transform any additional statements we may have already built
6952 assert(S->getAllocate() && S->getDeallocate() &&
6953 "allocation and deallocation calls must already be built");
6954 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
6955 if (AllocRes.isInvalid())
6957 Builder.Allocate = AllocRes.get();
6959 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
6960 if (DeallocRes.isInvalid())
6962 Builder.Deallocate = DeallocRes.get();
6964 assert(S->getResultDecl() && "ResultDecl must already be built");
6965 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
6966 if (ResultDecl.isInvalid())
6968 Builder.ResultDecl = ResultDecl.get();
6970 if (auto *ReturnStmt = S->getReturnStmt()) {
6971 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
6972 if (Res.isInvalid())
6974 Builder.ReturnStmt = Res.get();
6977 if (!Builder.buildParameterMoves())
6980 return getDerived().RebuildCoroutineBodyStmt(Builder);
6983 template<typename Derived>
6985 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6986 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6987 /*NotCopyInit*/false);
6988 if (Result.isInvalid())
6991 // Always rebuild; we don't know if this needs to be injected into a new
6992 // context or if the promise type has changed.
6993 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
6997 template<typename Derived>
6999 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7000 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7001 /*NotCopyInit*/false);
7002 if (Result.isInvalid())
7005 // Always rebuild; we don't know if this needs to be injected into a new
7006 // context or if the promise type has changed.
7007 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7011 template <typename Derived>
7013 TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7014 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7015 /*NotCopyInit*/ false);
7016 if (OperandResult.isInvalid())
7019 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7020 E->getOperatorCoawaitLookup());
7022 if (LookupResult.isInvalid())
7025 // Always rebuild; we don't know if this needs to be injected into a new
7026 // context or if the promise type has changed.
7027 return getDerived().RebuildDependentCoawaitExpr(
7028 E->getKeywordLoc(), OperandResult.get(),
7029 cast<UnresolvedLookupExpr>(LookupResult.get()));
7032 template<typename Derived>
7034 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7035 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7036 /*NotCopyInit*/false);
7037 if (Result.isInvalid())
7040 // Always rebuild; we don't know if this needs to be injected into a new
7041 // context or if the promise type has changed.
7042 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7045 // Objective-C Statements.
7047 template<typename Derived>
7049 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
7050 // Transform the body of the @try.
7051 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
7052 if (TryBody.isInvalid())
7055 // Transform the @catch statements (if present).
7056 bool AnyCatchChanged = false;
7057 SmallVector<Stmt*, 8> CatchStmts;
7058 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
7059 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
7060 if (Catch.isInvalid())
7062 if (Catch.get() != S->getCatchStmt(I))
7063 AnyCatchChanged = true;
7064 CatchStmts.push_back(Catch.get());
7067 // Transform the @finally statement (if present).
7069 if (S->getFinallyStmt()) {
7070 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7071 if (Finally.isInvalid())
7075 // If nothing changed, just retain this statement.
7076 if (!getDerived().AlwaysRebuild() &&
7077 TryBody.get() == S->getTryBody() &&
7079 Finally.get() == S->getFinallyStmt())
7082 // Build a new statement.
7083 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
7084 CatchStmts, Finally.get());
7087 template<typename Derived>
7089 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
7090 // Transform the @catch parameter, if there is one.
7091 VarDecl *Var = nullptr;
7092 if (VarDecl *FromVar = S->getCatchParamDecl()) {
7093 TypeSourceInfo *TSInfo = nullptr;
7094 if (FromVar->getTypeSourceInfo()) {
7095 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7102 T = TSInfo->getType();
7104 T = getDerived().TransformType(FromVar->getType());
7109 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7114 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
7115 if (Body.isInvalid())
7118 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
7123 template<typename Derived>
7125 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
7126 // Transform the body.
7127 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
7128 if (Body.isInvalid())
7131 // If nothing changed, just retain this statement.
7132 if (!getDerived().AlwaysRebuild() &&
7133 Body.get() == S->getFinallyBody())
7136 // Build a new statement.
7137 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
7141 template<typename Derived>
7143 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
7145 if (S->getThrowExpr()) {
7146 Operand = getDerived().TransformExpr(S->getThrowExpr());
7147 if (Operand.isInvalid())
7151 if (!getDerived().AlwaysRebuild() &&
7152 Operand.get() == S->getThrowExpr())
7155 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
7158 template<typename Derived>
7160 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
7161 ObjCAtSynchronizedStmt *S) {
7162 // Transform the object we are locking.
7163 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
7164 if (Object.isInvalid())
7167 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7169 if (Object.isInvalid())
7172 // Transform the body.
7173 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
7174 if (Body.isInvalid())
7177 // If nothing change, just retain the current statement.
7178 if (!getDerived().AlwaysRebuild() &&
7179 Object.get() == S->getSynchExpr() &&
7180 Body.get() == S->getSynchBody())
7183 // Build a new statement.
7184 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
7185 Object.get(), Body.get());
7188 template<typename Derived>
7190 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7191 ObjCAutoreleasePoolStmt *S) {
7192 // Transform the body.
7193 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7194 if (Body.isInvalid())
7197 // If nothing changed, just retain this statement.
7198 if (!getDerived().AlwaysRebuild() &&
7199 Body.get() == S->getSubStmt())
7202 // Build a new statement.
7203 return getDerived().RebuildObjCAutoreleasePoolStmt(
7204 S->getAtLoc(), Body.get());
7207 template<typename Derived>
7209 TreeTransform<Derived>::TransformObjCForCollectionStmt(
7210 ObjCForCollectionStmt *S) {
7211 // Transform the element statement.
7212 StmtResult Element = getDerived().TransformStmt(S->getElement());
7213 if (Element.isInvalid())
7216 // Transform the collection expression.
7217 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
7218 if (Collection.isInvalid())
7221 // Transform the body.
7222 StmtResult Body = getDerived().TransformStmt(S->getBody());
7223 if (Body.isInvalid())
7226 // If nothing changed, just retain this statement.
7227 if (!getDerived().AlwaysRebuild() &&
7228 Element.get() == S->getElement() &&
7229 Collection.get() == S->getCollection() &&
7230 Body.get() == S->getBody())
7233 // Build a new statement.
7234 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
7241 template <typename Derived>
7242 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
7243 // Transform the exception declaration, if any.
7244 VarDecl *Var = nullptr;
7245 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7247 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
7251 Var = getDerived().RebuildExceptionDecl(
7252 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7253 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
7254 if (!Var || Var->isInvalidDecl())
7258 // Transform the actual exception handler.
7259 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
7260 if (Handler.isInvalid())
7263 if (!getDerived().AlwaysRebuild() && !Var &&
7264 Handler.get() == S->getHandlerBlock())
7267 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
7270 template <typename Derived>
7271 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
7272 // Transform the try block itself.
7273 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7274 if (TryBlock.isInvalid())
7277 // Transform the handlers.
7278 bool HandlerChanged = false;
7279 SmallVector<Stmt *, 8> Handlers;
7280 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
7281 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
7282 if (Handler.isInvalid())
7285 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
7286 Handlers.push_back(Handler.getAs<Stmt>());
7289 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7293 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
7297 template<typename Derived>
7299 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7300 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7301 if (Range.isInvalid())
7304 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7305 if (Begin.isInvalid())
7307 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7308 if (End.isInvalid())
7311 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7312 if (Cond.isInvalid())
7315 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
7316 if (Cond.isInvalid())
7319 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
7321 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7322 if (Inc.isInvalid())
7325 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
7327 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7328 if (LoopVar.isInvalid())
7331 StmtResult NewStmt = S;
7332 if (getDerived().AlwaysRebuild() ||
7333 Range.get() != S->getRangeStmt() ||
7334 Begin.get() != S->getBeginStmt() ||
7335 End.get() != S->getEndStmt() ||
7336 Cond.get() != S->getCond() ||
7337 Inc.get() != S->getInc() ||
7338 LoopVar.get() != S->getLoopVarStmt()) {
7339 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7341 S->getColonLoc(), Range.get(),
7342 Begin.get(), End.get(),
7344 Inc.get(), LoopVar.get(),
7346 if (NewStmt.isInvalid())
7350 StmtResult Body = getDerived().TransformStmt(S->getBody());
7351 if (Body.isInvalid())
7354 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7355 // it now so we have a new statement to attach the body to.
7356 if (Body.get() != S->getBody() && NewStmt.get() == S) {
7357 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7359 S->getColonLoc(), Range.get(),
7360 Begin.get(), End.get(),
7362 Inc.get(), LoopVar.get(),
7364 if (NewStmt.isInvalid())
7368 if (NewStmt.get() == S)
7371 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7374 template<typename Derived>
7376 TreeTransform<Derived>::TransformMSDependentExistsStmt(
7377 MSDependentExistsStmt *S) {
7378 // Transform the nested-name-specifier, if any.
7379 NestedNameSpecifierLoc QualifierLoc;
7380 if (S->getQualifierLoc()) {
7382 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7387 // Transform the declaration name.
7388 DeclarationNameInfo NameInfo = S->getNameInfo();
7389 if (NameInfo.getName()) {
7390 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7391 if (!NameInfo.getName())
7395 // Check whether anything changed.
7396 if (!getDerived().AlwaysRebuild() &&
7397 QualifierLoc == S->getQualifierLoc() &&
7398 NameInfo.getName() == S->getNameInfo().getName())
7401 // Determine whether this name exists, if we can.
7403 SS.Adopt(QualifierLoc);
7404 bool Dependent = false;
7405 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
7406 case Sema::IER_Exists:
7407 if (S->isIfExists())
7410 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7412 case Sema::IER_DoesNotExist:
7413 if (S->isIfNotExists())
7416 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7418 case Sema::IER_Dependent:
7422 case Sema::IER_Error:
7426 // We need to continue with the instantiation, so do so now.
7427 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7428 if (SubStmt.isInvalid())
7431 // If we have resolved the name, just transform to the substatement.
7435 // The name is still dependent, so build a dependent expression again.
7436 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7443 template<typename Derived>
7445 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7446 NestedNameSpecifierLoc QualifierLoc;
7447 if (E->getQualifierLoc()) {
7449 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7454 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7455 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7459 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7460 if (Base.isInvalid())
7463 return new (SemaRef.getASTContext())
7464 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7465 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7466 QualifierLoc, E->getMemberLoc());
7469 template <typename Derived>
7470 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7471 MSPropertySubscriptExpr *E) {
7472 auto BaseRes = getDerived().TransformExpr(E->getBase());
7473 if (BaseRes.isInvalid())
7475 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7476 if (IdxRes.isInvalid())
7479 if (!getDerived().AlwaysRebuild() &&
7480 BaseRes.get() == E->getBase() &&
7481 IdxRes.get() == E->getIdx())
7484 return getDerived().RebuildArraySubscriptExpr(
7485 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7488 template <typename Derived>
7489 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7490 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7491 if (TryBlock.isInvalid())
7494 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7495 if (Handler.isInvalid())
7498 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7499 Handler.get() == S->getHandler())
7502 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7503 TryBlock.get(), Handler.get());
7506 template <typename Derived>
7507 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7508 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7509 if (Block.isInvalid())
7512 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7515 template <typename Derived>
7516 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7517 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7518 if (FilterExpr.isInvalid())
7521 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7522 if (Block.isInvalid())
7525 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7529 template <typename Derived>
7530 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7531 if (isa<SEHFinallyStmt>(Handler))
7532 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7534 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7537 template<typename Derived>
7539 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7543 //===----------------------------------------------------------------------===//
7544 // OpenMP directive transformation
7545 //===----------------------------------------------------------------------===//
7546 template <typename Derived>
7547 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7548 OMPExecutableDirective *D) {
7550 // Transform the clauses
7551 llvm::SmallVector<OMPClause *, 16> TClauses;
7552 ArrayRef<OMPClause *> Clauses = D->clauses();
7553 TClauses.reserve(Clauses.size());
7554 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7557 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7558 OMPClause *Clause = getDerived().TransformOMPClause(*I);
7559 getDerived().getSema().EndOpenMPClause();
7561 TClauses.push_back(Clause);
7563 TClauses.push_back(nullptr);
7566 StmtResult AssociatedStmt;
7567 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7568 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7569 /*CurScope=*/nullptr);
7572 Sema::CompoundScopeRAII CompoundScope(getSema());
7573 int ThisCaptureLevel =
7574 Sema::getOpenMPCaptureLevels(D->getDirectiveKind());
7575 Stmt *CS = D->getAssociatedStmt();
7576 while (--ThisCaptureLevel >= 0)
7577 CS = cast<CapturedStmt>(CS)->getCapturedStmt();
7578 Body = getDerived().TransformStmt(CS);
7581 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7582 if (AssociatedStmt.isInvalid()) {
7586 if (TClauses.size() != Clauses.size()) {
7590 // Transform directive name for 'omp critical' directive.
7591 DeclarationNameInfo DirName;
7592 if (D->getDirectiveKind() == OMPD_critical) {
7593 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7594 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7596 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7597 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7598 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7599 } else if (D->getDirectiveKind() == OMPD_cancel) {
7600 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7603 return getDerived().RebuildOMPExecutableDirective(
7604 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7605 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7608 template <typename Derived>
7610 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7611 DeclarationNameInfo DirName;
7612 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7614 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7615 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7619 template <typename Derived>
7621 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7622 DeclarationNameInfo DirName;
7623 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7625 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7626 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7630 template <typename Derived>
7632 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7633 DeclarationNameInfo DirName;
7634 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7636 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7637 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7641 template <typename Derived>
7643 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7644 DeclarationNameInfo DirName;
7645 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7647 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7648 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7652 template <typename Derived>
7654 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7655 DeclarationNameInfo DirName;
7656 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7658 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7659 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7663 template <typename Derived>
7665 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7666 DeclarationNameInfo DirName;
7667 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7669 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7670 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7674 template <typename Derived>
7676 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7677 DeclarationNameInfo DirName;
7678 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7680 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7681 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7685 template <typename Derived>
7687 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7688 DeclarationNameInfo DirName;
7689 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7691 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7692 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7696 template <typename Derived>
7698 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7699 getDerived().getSema().StartOpenMPDSABlock(
7700 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7701 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7702 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7706 template <typename Derived>
7707 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7708 OMPParallelForDirective *D) {
7709 DeclarationNameInfo DirName;
7710 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7711 nullptr, D->getLocStart());
7712 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7713 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7717 template <typename Derived>
7718 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7719 OMPParallelForSimdDirective *D) {
7720 DeclarationNameInfo DirName;
7721 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7722 nullptr, D->getLocStart());
7723 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7724 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7728 template <typename Derived>
7729 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7730 OMPParallelSectionsDirective *D) {
7731 DeclarationNameInfo DirName;
7732 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7733 nullptr, D->getLocStart());
7734 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7735 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7739 template <typename Derived>
7741 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7742 DeclarationNameInfo DirName;
7743 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7745 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7746 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7750 template <typename Derived>
7751 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7752 OMPTaskyieldDirective *D) {
7753 DeclarationNameInfo DirName;
7754 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7756 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7757 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7761 template <typename Derived>
7763 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7764 DeclarationNameInfo DirName;
7765 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7767 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7768 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7772 template <typename Derived>
7774 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7775 DeclarationNameInfo DirName;
7776 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7778 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7779 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7783 template <typename Derived>
7784 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7785 OMPTaskgroupDirective *D) {
7786 DeclarationNameInfo DirName;
7787 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7789 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7790 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7794 template <typename Derived>
7796 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7797 DeclarationNameInfo DirName;
7798 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7800 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7801 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7805 template <typename Derived>
7807 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7808 DeclarationNameInfo DirName;
7809 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7811 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7812 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7816 template <typename Derived>
7818 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7819 DeclarationNameInfo DirName;
7820 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7822 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7823 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7827 template <typename Derived>
7829 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7830 DeclarationNameInfo DirName;
7831 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7833 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7834 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7838 template <typename Derived>
7839 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7840 OMPTargetDataDirective *D) {
7841 DeclarationNameInfo DirName;
7842 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7844 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7845 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7849 template <typename Derived>
7850 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7851 OMPTargetEnterDataDirective *D) {
7852 DeclarationNameInfo DirName;
7853 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7854 nullptr, D->getLocStart());
7855 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7856 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7860 template <typename Derived>
7861 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7862 OMPTargetExitDataDirective *D) {
7863 DeclarationNameInfo DirName;
7864 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7865 nullptr, D->getLocStart());
7866 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7867 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7871 template <typename Derived>
7872 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7873 OMPTargetParallelDirective *D) {
7874 DeclarationNameInfo DirName;
7875 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7876 nullptr, D->getLocStart());
7877 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7878 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7882 template <typename Derived>
7883 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7884 OMPTargetParallelForDirective *D) {
7885 DeclarationNameInfo DirName;
7886 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7887 nullptr, D->getLocStart());
7888 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7889 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7893 template <typename Derived>
7894 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7895 OMPTargetUpdateDirective *D) {
7896 DeclarationNameInfo DirName;
7897 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7898 nullptr, D->getLocStart());
7899 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7900 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7904 template <typename Derived>
7906 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7907 DeclarationNameInfo DirName;
7908 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7910 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7911 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7915 template <typename Derived>
7916 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7917 OMPCancellationPointDirective *D) {
7918 DeclarationNameInfo DirName;
7919 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7920 nullptr, D->getLocStart());
7921 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7922 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7926 template <typename Derived>
7928 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7929 DeclarationNameInfo DirName;
7930 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7932 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7933 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7937 template <typename Derived>
7939 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7940 DeclarationNameInfo DirName;
7941 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7943 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7944 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7948 template <typename Derived>
7949 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7950 OMPTaskLoopSimdDirective *D) {
7951 DeclarationNameInfo DirName;
7952 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7953 nullptr, D->getLocStart());
7954 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7955 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7959 template <typename Derived>
7960 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7961 OMPDistributeDirective *D) {
7962 DeclarationNameInfo DirName;
7963 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7965 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7966 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7970 template <typename Derived>
7971 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7972 OMPDistributeParallelForDirective *D) {
7973 DeclarationNameInfo DirName;
7974 getDerived().getSema().StartOpenMPDSABlock(
7975 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7976 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7977 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7981 template <typename Derived>
7983 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7984 OMPDistributeParallelForSimdDirective *D) {
7985 DeclarationNameInfo DirName;
7986 getDerived().getSema().StartOpenMPDSABlock(
7987 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7988 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7989 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7993 template <typename Derived>
7994 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7995 OMPDistributeSimdDirective *D) {
7996 DeclarationNameInfo DirName;
7997 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7998 nullptr, D->getLocStart());
7999 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8000 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8004 template <typename Derived>
8005 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8006 OMPTargetParallelForSimdDirective *D) {
8007 DeclarationNameInfo DirName;
8008 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8012 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8016 template <typename Derived>
8017 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8018 OMPTargetSimdDirective *D) {
8019 DeclarationNameInfo DirName;
8020 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8022 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8023 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8027 template <typename Derived>
8028 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8029 OMPTeamsDistributeDirective *D) {
8030 DeclarationNameInfo DirName;
8031 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8032 nullptr, D->getLocStart());
8033 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8034 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8038 template <typename Derived>
8039 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8040 OMPTeamsDistributeSimdDirective *D) {
8041 DeclarationNameInfo DirName;
8042 getDerived().getSema().StartOpenMPDSABlock(
8043 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8044 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8045 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8049 template <typename Derived>
8050 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8051 OMPTeamsDistributeParallelForSimdDirective *D) {
8052 DeclarationNameInfo DirName;
8053 getDerived().getSema().StartOpenMPDSABlock(
8054 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8055 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8056 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8060 template <typename Derived>
8061 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8062 OMPTeamsDistributeParallelForDirective *D) {
8063 DeclarationNameInfo DirName;
8064 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8065 DirName, nullptr, D->getLocStart());
8066 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8067 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8071 template <typename Derived>
8072 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8073 OMPTargetTeamsDirective *D) {
8074 DeclarationNameInfo DirName;
8075 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8076 nullptr, D->getLocStart());
8077 auto Res = getDerived().TransformOMPExecutableDirective(D);
8078 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8082 template <typename Derived>
8083 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8084 OMPTargetTeamsDistributeDirective *D) {
8085 DeclarationNameInfo DirName;
8086 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8087 DirName, nullptr, D->getLocStart());
8088 auto Res = getDerived().TransformOMPExecutableDirective(D);
8089 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8093 template <typename Derived>
8095 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8096 OMPTargetTeamsDistributeParallelForDirective *D) {
8097 DeclarationNameInfo DirName;
8098 getDerived().getSema().StartOpenMPDSABlock(
8099 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8101 auto Res = getDerived().TransformOMPExecutableDirective(D);
8102 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8106 template <typename Derived>
8107 StmtResult TreeTransform<Derived>::
8108 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8109 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8110 DeclarationNameInfo DirName;
8111 getDerived().getSema().StartOpenMPDSABlock(
8112 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8114 auto Res = getDerived().TransformOMPExecutableDirective(D);
8115 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8119 template <typename Derived>
8121 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8122 OMPTargetTeamsDistributeSimdDirective *D) {
8123 DeclarationNameInfo DirName;
8124 getDerived().getSema().StartOpenMPDSABlock(
8125 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8126 auto Res = getDerived().TransformOMPExecutableDirective(D);
8127 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8132 //===----------------------------------------------------------------------===//
8133 // OpenMP clause transformation
8134 //===----------------------------------------------------------------------===//
8135 template <typename Derived>
8136 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
8137 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8138 if (Cond.isInvalid())
8140 return getDerived().RebuildOMPIfClause(
8141 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8142 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
8145 template <typename Derived>
8146 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8147 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8148 if (Cond.isInvalid())
8150 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8151 C->getLParenLoc(), C->getLocEnd());
8154 template <typename Derived>
8156 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8157 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8158 if (NumThreads.isInvalid())
8160 return getDerived().RebuildOMPNumThreadsClause(
8161 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8164 template <typename Derived>
8166 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8167 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8170 return getDerived().RebuildOMPSafelenClause(
8171 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8174 template <typename Derived>
8176 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8177 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8180 return getDerived().RebuildOMPSimdlenClause(
8181 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8184 template <typename Derived>
8186 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8187 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8190 return getDerived().RebuildOMPCollapseClause(
8191 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8194 template <typename Derived>
8196 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
8197 return getDerived().RebuildOMPDefaultClause(
8198 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8199 C->getLParenLoc(), C->getLocEnd());
8202 template <typename Derived>
8204 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
8205 return getDerived().RebuildOMPProcBindClause(
8206 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8207 C->getLParenLoc(), C->getLocEnd());
8210 template <typename Derived>
8212 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8213 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8216 return getDerived().RebuildOMPScheduleClause(
8217 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
8218 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8219 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
8220 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8223 template <typename Derived>
8225 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
8227 if (auto *Num = C->getNumForLoops()) {
8228 E = getDerived().TransformExpr(Num);
8232 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8233 C->getLParenLoc(), E.get());
8236 template <typename Derived>
8238 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8239 // No need to rebuild this clause, no template-dependent parameters.
8243 template <typename Derived>
8245 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8246 // No need to rebuild this clause, no template-dependent parameters.
8250 template <typename Derived>
8252 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8253 // No need to rebuild this clause, no template-dependent parameters.
8257 template <typename Derived>
8258 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8259 // No need to rebuild this clause, no template-dependent parameters.
8263 template <typename Derived>
8264 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8265 // No need to rebuild this clause, no template-dependent parameters.
8269 template <typename Derived>
8271 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8272 // No need to rebuild this clause, no template-dependent parameters.
8276 template <typename Derived>
8278 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8279 // No need to rebuild this clause, no template-dependent parameters.
8283 template <typename Derived>
8285 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8286 // No need to rebuild this clause, no template-dependent parameters.
8290 template <typename Derived>
8292 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8293 // No need to rebuild this clause, no template-dependent parameters.
8297 template <typename Derived>
8298 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8299 // No need to rebuild this clause, no template-dependent parameters.
8303 template <typename Derived>
8305 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8306 // No need to rebuild this clause, no template-dependent parameters.
8310 template <typename Derived>
8312 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
8313 llvm::SmallVector<Expr *, 16> Vars;
8314 Vars.reserve(C->varlist_size());
8315 for (auto *VE : C->varlists()) {
8316 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8317 if (EVar.isInvalid())
8319 Vars.push_back(EVar.get());
8321 return getDerived().RebuildOMPPrivateClause(
8322 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8325 template <typename Derived>
8326 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8327 OMPFirstprivateClause *C) {
8328 llvm::SmallVector<Expr *, 16> Vars;
8329 Vars.reserve(C->varlist_size());
8330 for (auto *VE : C->varlists()) {
8331 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8332 if (EVar.isInvalid())
8334 Vars.push_back(EVar.get());
8336 return getDerived().RebuildOMPFirstprivateClause(
8337 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8340 template <typename Derived>
8342 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8343 llvm::SmallVector<Expr *, 16> Vars;
8344 Vars.reserve(C->varlist_size());
8345 for (auto *VE : C->varlists()) {
8346 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8347 if (EVar.isInvalid())
8349 Vars.push_back(EVar.get());
8351 return getDerived().RebuildOMPLastprivateClause(
8352 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8355 template <typename Derived>
8357 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8358 llvm::SmallVector<Expr *, 16> Vars;
8359 Vars.reserve(C->varlist_size());
8360 for (auto *VE : C->varlists()) {
8361 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8362 if (EVar.isInvalid())
8364 Vars.push_back(EVar.get());
8366 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8367 C->getLParenLoc(), C->getLocEnd());
8370 template <typename Derived>
8372 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8373 llvm::SmallVector<Expr *, 16> Vars;
8374 Vars.reserve(C->varlist_size());
8375 for (auto *VE : C->varlists()) {
8376 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8377 if (EVar.isInvalid())
8379 Vars.push_back(EVar.get());
8381 CXXScopeSpec ReductionIdScopeSpec;
8382 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8384 DeclarationNameInfo NameInfo = C->getNameInfo();
8385 if (NameInfo.getName()) {
8386 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8387 if (!NameInfo.getName())
8390 // Build a list of all UDR decls with the same names ranged by the Scopes.
8391 // The Scope boundary is a duplication of the previous decl.
8392 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8393 for (auto *E : C->reduction_ops()) {
8394 // Transform all the decls.
8396 auto *ULE = cast<UnresolvedLookupExpr>(E);
8397 UnresolvedSet<8> Decls;
8398 for (auto *D : ULE->decls()) {
8400 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8401 Decls.addDecl(InstD, InstD->getAccess());
8403 UnresolvedReductions.push_back(
8404 UnresolvedLookupExpr::Create(
8405 SemaRef.Context, /*NamingClass=*/nullptr,
8406 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8407 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8408 Decls.begin(), Decls.end()));
8410 UnresolvedReductions.push_back(nullptr);
8412 return getDerived().RebuildOMPReductionClause(
8413 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8414 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8417 template <typename Derived>
8418 OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8419 OMPTaskReductionClause *C) {
8420 llvm::SmallVector<Expr *, 16> Vars;
8421 Vars.reserve(C->varlist_size());
8422 for (auto *VE : C->varlists()) {
8423 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8424 if (EVar.isInvalid())
8426 Vars.push_back(EVar.get());
8428 CXXScopeSpec ReductionIdScopeSpec;
8429 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8431 DeclarationNameInfo NameInfo = C->getNameInfo();
8432 if (NameInfo.getName()) {
8433 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8434 if (!NameInfo.getName())
8437 // Build a list of all UDR decls with the same names ranged by the Scopes.
8438 // The Scope boundary is a duplication of the previous decl.
8439 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8440 for (auto *E : C->reduction_ops()) {
8441 // Transform all the decls.
8443 auto *ULE = cast<UnresolvedLookupExpr>(E);
8444 UnresolvedSet<8> Decls;
8445 for (auto *D : ULE->decls()) {
8447 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8448 Decls.addDecl(InstD, InstD->getAccess());
8450 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8451 SemaRef.Context, /*NamingClass=*/nullptr,
8452 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8453 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8455 UnresolvedReductions.push_back(nullptr);
8457 return getDerived().RebuildOMPTaskReductionClause(
8458 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8459 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8462 template <typename Derived>
8464 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8465 llvm::SmallVector<Expr *, 16> Vars;
8466 Vars.reserve(C->varlist_size());
8467 for (auto *VE : C->varlists()) {
8468 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8469 if (EVar.isInvalid())
8471 Vars.push_back(EVar.get());
8473 ExprResult Step = getDerived().TransformExpr(C->getStep());
8474 if (Step.isInvalid())
8476 return getDerived().RebuildOMPLinearClause(
8477 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8478 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
8481 template <typename Derived>
8483 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8484 llvm::SmallVector<Expr *, 16> Vars;
8485 Vars.reserve(C->varlist_size());
8486 for (auto *VE : C->varlists()) {
8487 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8488 if (EVar.isInvalid())
8490 Vars.push_back(EVar.get());
8492 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8493 if (Alignment.isInvalid())
8495 return getDerived().RebuildOMPAlignedClause(
8496 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8497 C->getColonLoc(), C->getLocEnd());
8500 template <typename Derived>
8502 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8503 llvm::SmallVector<Expr *, 16> Vars;
8504 Vars.reserve(C->varlist_size());
8505 for (auto *VE : C->varlists()) {
8506 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8507 if (EVar.isInvalid())
8509 Vars.push_back(EVar.get());
8511 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8512 C->getLParenLoc(), C->getLocEnd());
8515 template <typename Derived>
8517 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8518 llvm::SmallVector<Expr *, 16> Vars;
8519 Vars.reserve(C->varlist_size());
8520 for (auto *VE : C->varlists()) {
8521 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8522 if (EVar.isInvalid())
8524 Vars.push_back(EVar.get());
8526 return getDerived().RebuildOMPCopyprivateClause(
8527 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8530 template <typename Derived>
8531 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8532 llvm::SmallVector<Expr *, 16> Vars;
8533 Vars.reserve(C->varlist_size());
8534 for (auto *VE : C->varlists()) {
8535 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8536 if (EVar.isInvalid())
8538 Vars.push_back(EVar.get());
8540 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8541 C->getLParenLoc(), C->getLocEnd());
8544 template <typename Derived>
8546 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8547 llvm::SmallVector<Expr *, 16> Vars;
8548 Vars.reserve(C->varlist_size());
8549 for (auto *VE : C->varlists()) {
8550 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8551 if (EVar.isInvalid())
8553 Vars.push_back(EVar.get());
8555 return getDerived().RebuildOMPDependClause(
8556 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8557 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8560 template <typename Derived>
8562 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8563 ExprResult E = getDerived().TransformExpr(C->getDevice());
8566 return getDerived().RebuildOMPDeviceClause(
8567 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8570 template <typename Derived>
8571 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8572 llvm::SmallVector<Expr *, 16> Vars;
8573 Vars.reserve(C->varlist_size());
8574 for (auto *VE : C->varlists()) {
8575 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8576 if (EVar.isInvalid())
8578 Vars.push_back(EVar.get());
8580 return getDerived().RebuildOMPMapClause(
8581 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8582 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8583 C->getLParenLoc(), C->getLocEnd());
8586 template <typename Derived>
8588 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8589 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8592 return getDerived().RebuildOMPNumTeamsClause(
8593 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8596 template <typename Derived>
8598 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8599 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8602 return getDerived().RebuildOMPThreadLimitClause(
8603 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8606 template <typename Derived>
8608 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8609 ExprResult E = getDerived().TransformExpr(C->getPriority());
8612 return getDerived().RebuildOMPPriorityClause(
8613 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8616 template <typename Derived>
8618 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8619 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8622 return getDerived().RebuildOMPGrainsizeClause(
8623 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8626 template <typename Derived>
8628 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8629 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8632 return getDerived().RebuildOMPNumTasksClause(
8633 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8636 template <typename Derived>
8637 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8638 ExprResult E = getDerived().TransformExpr(C->getHint());
8641 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8642 C->getLParenLoc(), C->getLocEnd());
8645 template <typename Derived>
8646 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8647 OMPDistScheduleClause *C) {
8648 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8651 return getDerived().RebuildOMPDistScheduleClause(
8652 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8653 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8656 template <typename Derived>
8658 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8662 template <typename Derived>
8663 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *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().RebuildOMPToClause(Vars, C->getLocStart(),
8673 C->getLParenLoc(), C->getLocEnd());
8676 template <typename Derived>
8677 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8678 llvm::SmallVector<Expr *, 16> Vars;
8679 Vars.reserve(C->varlist_size());
8680 for (auto *VE : C->varlists()) {
8681 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8682 if (EVar.isInvalid())
8684 Vars.push_back(EVar.get());
8686 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8687 C->getLParenLoc(), C->getLocEnd());
8690 template <typename Derived>
8691 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8692 OMPUseDevicePtrClause *C) {
8693 llvm::SmallVector<Expr *, 16> Vars;
8694 Vars.reserve(C->varlist_size());
8695 for (auto *VE : C->varlists()) {
8696 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8697 if (EVar.isInvalid())
8699 Vars.push_back(EVar.get());
8701 return getDerived().RebuildOMPUseDevicePtrClause(
8702 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8705 template <typename Derived>
8707 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8708 llvm::SmallVector<Expr *, 16> Vars;
8709 Vars.reserve(C->varlist_size());
8710 for (auto *VE : C->varlists()) {
8711 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8712 if (EVar.isInvalid())
8714 Vars.push_back(EVar.get());
8716 return getDerived().RebuildOMPIsDevicePtrClause(
8717 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8720 //===----------------------------------------------------------------------===//
8721 // Expression transformation
8722 //===----------------------------------------------------------------------===//
8723 template<typename Derived>
8725 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
8726 if (!E->isTypeDependent())
8729 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8733 template<typename Derived>
8735 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
8736 NestedNameSpecifierLoc QualifierLoc;
8737 if (E->getQualifierLoc()) {
8739 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8745 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8750 DeclarationNameInfo NameInfo = E->getNameInfo();
8751 if (NameInfo.getName()) {
8752 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8753 if (!NameInfo.getName())
8757 if (!getDerived().AlwaysRebuild() &&
8758 QualifierLoc == E->getQualifierLoc() &&
8759 ND == E->getDecl() &&
8760 NameInfo.getName() == E->getDecl()->getDeclName() &&
8761 !E->hasExplicitTemplateArgs()) {
8763 // Mark it referenced in the new context regardless.
8764 // FIXME: this is a bit instantiation-specific.
8765 SemaRef.MarkDeclRefReferenced(E);
8770 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
8771 if (E->hasExplicitTemplateArgs()) {
8772 TemplateArgs = &TransArgs;
8773 TransArgs.setLAngleLoc(E->getLAngleLoc());
8774 TransArgs.setRAngleLoc(E->getRAngleLoc());
8775 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8776 E->getNumTemplateArgs(),
8781 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
8785 template<typename Derived>
8787 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
8791 template<typename Derived>
8793 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
8797 template<typename Derived>
8799 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
8803 template<typename Derived>
8805 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
8809 template<typename Derived>
8811 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
8815 template<typename Derived>
8817 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
8818 if (FunctionDecl *FD = E->getDirectCallee())
8819 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
8820 return SemaRef.MaybeBindToTemporary(E);
8823 template<typename Derived>
8825 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8826 ExprResult ControllingExpr =
8827 getDerived().TransformExpr(E->getControllingExpr());
8828 if (ControllingExpr.isInvalid())
8831 SmallVector<Expr *, 4> AssocExprs;
8832 SmallVector<TypeSourceInfo *, 4> AssocTypes;
8833 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8834 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8836 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8839 AssocTypes.push_back(AssocType);
8841 AssocTypes.push_back(nullptr);
8844 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8845 if (AssocExpr.isInvalid())
8847 AssocExprs.push_back(AssocExpr.get());
8850 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8853 ControllingExpr.get(),
8858 template<typename Derived>
8860 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
8861 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8862 if (SubExpr.isInvalid())
8865 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8868 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
8872 /// \brief The operand of a unary address-of operator has special rules: it's
8873 /// allowed to refer to a non-static member of a class even if there's no 'this'
8874 /// object available.
8875 template<typename Derived>
8877 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8878 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
8879 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
8881 return getDerived().TransformExpr(E);
8884 template<typename Derived>
8886 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
8888 if (E->getOpcode() == UO_AddrOf)
8889 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8891 SubExpr = TransformExpr(E->getSubExpr());
8892 if (SubExpr.isInvalid())
8895 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8898 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8903 template<typename Derived>
8905 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8906 // Transform the type.
8907 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8911 // Transform all of the components into components similar to what the
8913 // FIXME: It would be slightly more efficient in the non-dependent case to
8914 // just map FieldDecls, rather than requiring the rebuilder to look for
8915 // the fields again. However, __builtin_offsetof is rare enough in
8916 // template code that we don't care.
8917 bool ExprChanged = false;
8918 typedef Sema::OffsetOfComponent Component;
8919 SmallVector<Component, 4> Components;
8920 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8921 const OffsetOfNode &ON = E->getComponent(I);
8923 Comp.isBrackets = true;
8924 Comp.LocStart = ON.getSourceRange().getBegin();
8925 Comp.LocEnd = ON.getSourceRange().getEnd();
8926 switch (ON.getKind()) {
8927 case OffsetOfNode::Array: {
8928 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
8929 ExprResult Index = getDerived().TransformExpr(FromIndex);
8930 if (Index.isInvalid())
8933 ExprChanged = ExprChanged || Index.get() != FromIndex;
8934 Comp.isBrackets = true;
8935 Comp.U.E = Index.get();
8939 case OffsetOfNode::Field:
8940 case OffsetOfNode::Identifier:
8941 Comp.isBrackets = false;
8942 Comp.U.IdentInfo = ON.getFieldName();
8943 if (!Comp.U.IdentInfo)
8948 case OffsetOfNode::Base:
8949 // Will be recomputed during the rebuild.
8953 Components.push_back(Comp);
8956 // If nothing changed, retain the existing expression.
8957 if (!getDerived().AlwaysRebuild() &&
8958 Type == E->getTypeSourceInfo() &&
8962 // Build a new offsetof expression.
8963 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
8964 Components, E->getRParenLoc());
8967 template<typename Derived>
8969 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
8970 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
8971 "opaque value expression requires transformation");
8975 template<typename Derived>
8977 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8981 template<typename Derived>
8983 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
8984 // Rebuild the syntactic form. The original syntactic form has
8985 // opaque-value expressions in it, so strip those away and rebuild
8986 // the result. This is a really awful way of doing this, but the
8987 // better solution (rebuilding the semantic expressions and
8988 // rebinding OVEs as necessary) doesn't work; we'd need
8989 // TreeTransform to not strip away implicit conversions.
8990 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8991 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
8992 if (result.isInvalid()) return ExprError();
8994 // If that gives us a pseudo-object result back, the pseudo-object
8995 // expression must have been an lvalue-to-rvalue conversion which we
8997 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
8998 result = SemaRef.checkPseudoObjectRValue(result.get());
9003 template<typename Derived>
9005 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9006 UnaryExprOrTypeTraitExpr *E) {
9007 if (E->isArgumentType()) {
9008 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
9010 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9014 if (!getDerived().AlwaysRebuild() && OldT == NewT)
9017 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9019 E->getSourceRange());
9022 // C++0x [expr.sizeof]p1:
9023 // The operand is either an expression, which is an unevaluated operand
9025 EnterExpressionEvaluationContext Unevaluated(
9026 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9027 Sema::ReuseLambdaContextDecl);
9029 // Try to recover if we have something like sizeof(T::X) where X is a type.
9030 // Notably, there must be *exactly* one set of parens if X is a type.
9031 TypeSourceInfo *RecoveryTSI = nullptr;
9033 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9035 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9036 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9037 PE, DRE, false, &RecoveryTSI);
9039 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9042 return getDerived().RebuildUnaryExprOrTypeTrait(
9043 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9044 } else if (SubExpr.isInvalid())
9047 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
9050 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9051 E->getOperatorLoc(),
9053 E->getSourceRange());
9056 template<typename Derived>
9058 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
9059 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9060 if (LHS.isInvalid())
9063 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9064 if (RHS.isInvalid())
9068 if (!getDerived().AlwaysRebuild() &&
9069 LHS.get() == E->getLHS() &&
9070 RHS.get() == E->getRHS())
9073 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
9074 /*FIXME:*/E->getLHS()->getLocStart(),
9076 E->getRBracketLoc());
9079 template <typename Derived>
9081 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9082 ExprResult Base = getDerived().TransformExpr(E->getBase());
9083 if (Base.isInvalid())
9086 ExprResult LowerBound;
9087 if (E->getLowerBound()) {
9088 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9089 if (LowerBound.isInvalid())
9094 if (E->getLength()) {
9095 Length = getDerived().TransformExpr(E->getLength());
9096 if (Length.isInvalid())
9100 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9101 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9104 return getDerived().RebuildOMPArraySectionExpr(
9105 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9106 Length.get(), E->getRBracketLoc());
9109 template<typename Derived>
9111 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
9112 // Transform the callee.
9113 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9114 if (Callee.isInvalid())
9117 // Transform arguments.
9118 bool ArgChanged = false;
9119 SmallVector<Expr*, 8> Args;
9120 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9124 if (!getDerived().AlwaysRebuild() &&
9125 Callee.get() == E->getCallee() &&
9127 return SemaRef.MaybeBindToTemporary(E);
9129 // FIXME: Wrong source location information for the '('.
9130 SourceLocation FakeLParenLoc
9131 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9132 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9137 template<typename Derived>
9139 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
9140 ExprResult Base = getDerived().TransformExpr(E->getBase());
9141 if (Base.isInvalid())
9144 NestedNameSpecifierLoc QualifierLoc;
9145 if (E->hasQualifier()) {
9147 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9152 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9155 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9156 E->getMemberDecl()));
9160 NamedDecl *FoundDecl = E->getFoundDecl();
9161 if (FoundDecl == E->getMemberDecl()) {
9164 FoundDecl = cast_or_null<NamedDecl>(
9165 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9170 if (!getDerived().AlwaysRebuild() &&
9171 Base.get() == E->getBase() &&
9172 QualifierLoc == E->getQualifierLoc() &&
9173 Member == E->getMemberDecl() &&
9174 FoundDecl == E->getFoundDecl() &&
9175 !E->hasExplicitTemplateArgs()) {
9177 // Mark it referenced in the new context regardless.
9178 // FIXME: this is a bit instantiation-specific.
9179 SemaRef.MarkMemberReferenced(E);
9184 TemplateArgumentListInfo TransArgs;
9185 if (E->hasExplicitTemplateArgs()) {
9186 TransArgs.setLAngleLoc(E->getLAngleLoc());
9187 TransArgs.setRAngleLoc(E->getRAngleLoc());
9188 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9189 E->getNumTemplateArgs(),
9194 // FIXME: Bogus source location for the operator
9195 SourceLocation FakeOperatorLoc =
9196 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
9198 // FIXME: to do this check properly, we will need to preserve the
9199 // first-qualifier-in-scope here, just in case we had a dependent
9200 // base (and therefore couldn't do the check) and a
9201 // nested-name-qualifier (and therefore could do the lookup).
9202 NamedDecl *FirstQualifierInScope = nullptr;
9203 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9204 if (MemberNameInfo.getName()) {
9205 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9206 if (!MemberNameInfo.getName())
9210 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
9217 (E->hasExplicitTemplateArgs()
9218 ? &TransArgs : nullptr),
9219 FirstQualifierInScope);
9222 template<typename Derived>
9224 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
9225 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9226 if (LHS.isInvalid())
9229 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9230 if (RHS.isInvalid())
9233 if (!getDerived().AlwaysRebuild() &&
9234 LHS.get() == E->getLHS() &&
9235 RHS.get() == E->getRHS())
9238 Sema::FPContractStateRAII FPContractState(getSema());
9239 getSema().FPFeatures = E->getFPFeatures();
9241 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
9242 LHS.get(), RHS.get());
9245 template<typename Derived>
9247 TreeTransform<Derived>::TransformCompoundAssignOperator(
9248 CompoundAssignOperator *E) {
9249 return getDerived().TransformBinaryOperator(E);
9252 template<typename Derived>
9253 ExprResult TreeTransform<Derived>::
9254 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9255 // Just rebuild the common and RHS expressions and see whether we
9258 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9259 if (commonExpr.isInvalid())
9262 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9263 if (rhs.isInvalid())
9266 if (!getDerived().AlwaysRebuild() &&
9267 commonExpr.get() == e->getCommon() &&
9268 rhs.get() == e->getFalseExpr())
9271 return getDerived().RebuildConditionalOperator(commonExpr.get(),
9272 e->getQuestionLoc(),
9278 template<typename Derived>
9280 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
9281 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9282 if (Cond.isInvalid())
9285 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9286 if (LHS.isInvalid())
9289 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9290 if (RHS.isInvalid())
9293 if (!getDerived().AlwaysRebuild() &&
9294 Cond.get() == E->getCond() &&
9295 LHS.get() == E->getLHS() &&
9296 RHS.get() == E->getRHS())
9299 return getDerived().RebuildConditionalOperator(Cond.get(),
9300 E->getQuestionLoc(),
9306 template<typename Derived>
9308 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
9309 // Implicit casts are eliminated during transformation, since they
9310 // will be recomputed by semantic analysis after transformation.
9311 return getDerived().TransformExpr(E->getSubExprAsWritten());
9314 template<typename Derived>
9316 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
9317 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9322 = getDerived().TransformExpr(E->getSubExprAsWritten());
9323 if (SubExpr.isInvalid())
9326 if (!getDerived().AlwaysRebuild() &&
9327 Type == E->getTypeInfoAsWritten() &&
9328 SubExpr.get() == E->getSubExpr())
9331 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
9337 template<typename Derived>
9339 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
9340 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9341 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9345 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
9346 if (Init.isInvalid())
9349 if (!getDerived().AlwaysRebuild() &&
9351 Init.get() == E->getInitializer())
9352 return SemaRef.MaybeBindToTemporary(E);
9354 // Note: the expression type doesn't necessarily match the
9355 // type-as-written, but that's okay, because it should always be
9356 // derivable from the initializer.
9358 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
9359 /*FIXME:*/E->getInitializer()->getLocEnd(),
9363 template<typename Derived>
9365 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
9366 ExprResult Base = getDerived().TransformExpr(E->getBase());
9367 if (Base.isInvalid())
9370 if (!getDerived().AlwaysRebuild() &&
9371 Base.get() == E->getBase())
9374 // FIXME: Bad source location
9375 SourceLocation FakeOperatorLoc =
9376 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
9377 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
9378 E->getAccessorLoc(),
9382 template<typename Derived>
9384 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
9385 if (InitListExpr *Syntactic = E->getSyntacticForm())
9388 bool InitChanged = false;
9390 SmallVector<Expr*, 4> Inits;
9391 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
9392 Inits, &InitChanged))
9395 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9396 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9397 // in some cases. We can't reuse it in general, because the syntactic and
9398 // semantic forms are linked, and we can't know that semantic form will
9399 // match even if the syntactic form does.
9402 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
9403 E->getRBraceLoc(), E->getType());
9406 template<typename Derived>
9408 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
9411 // transform the initializer value
9412 ExprResult Init = getDerived().TransformExpr(E->getInit());
9413 if (Init.isInvalid())
9416 // transform the designators.
9417 SmallVector<Expr*, 4> ArrayExprs;
9418 bool ExprChanged = false;
9419 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9420 if (D.isFieldDesignator()) {
9421 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9425 FieldDecl *Field = cast_or_null<FieldDecl>(
9426 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9427 if (Field != D.getField())
9428 // Rebuild the expression when the transformed FieldDecl is
9429 // different to the already assigned FieldDecl.
9432 // Ensure that the designator expression is rebuilt when there isn't
9433 // a resolved FieldDecl in the designator as we don't want to assign
9434 // a FieldDecl to a pattern designator that will be instantiated again.
9440 if (D.isArrayDesignator()) {
9441 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
9442 if (Index.isInvalid())
9445 Desig.AddDesignator(
9446 Designator::getArray(Index.get(), D.getLBracketLoc()));
9448 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
9449 ArrayExprs.push_back(Index.get());
9453 assert(D.isArrayRangeDesignator() && "New kind of designator?");
9455 = getDerived().TransformExpr(E->getArrayRangeStart(D));
9456 if (Start.isInvalid())
9459 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
9460 if (End.isInvalid())
9463 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
9466 D.getEllipsisLoc()));
9468 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9469 End.get() != E->getArrayRangeEnd(D);
9471 ArrayExprs.push_back(Start.get());
9472 ArrayExprs.push_back(End.get());
9475 if (!getDerived().AlwaysRebuild() &&
9476 Init.get() == E->getInit() &&
9480 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
9481 E->getEqualOrColonLoc(),
9482 E->usesGNUSyntax(), Init.get());
9485 // Seems that if TransformInitListExpr() only works on the syntactic form of an
9486 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9487 template<typename Derived>
9489 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9490 DesignatedInitUpdateExpr *E) {
9491 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9496 template<typename Derived>
9498 TreeTransform<Derived>::TransformNoInitExpr(
9500 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9504 template<typename Derived>
9506 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9507 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9511 template<typename Derived>
9513 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9514 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9518 template<typename Derived>
9520 TreeTransform<Derived>::TransformImplicitValueInitExpr(
9521 ImplicitValueInitExpr *E) {
9522 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
9524 // FIXME: Will we ever have proper type location here? Will we actually
9525 // need to transform the type?
9526 QualType T = getDerived().TransformType(E->getType());
9530 if (!getDerived().AlwaysRebuild() &&
9534 return getDerived().RebuildImplicitValueInitExpr(T);
9537 template<typename Derived>
9539 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
9540 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9544 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9545 if (SubExpr.isInvalid())
9548 if (!getDerived().AlwaysRebuild() &&
9549 TInfo == E->getWrittenTypeInfo() &&
9550 SubExpr.get() == E->getSubExpr())
9553 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
9554 TInfo, E->getRParenLoc());
9557 template<typename Derived>
9559 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
9560 bool ArgumentChanged = false;
9561 SmallVector<Expr*, 4> Inits;
9562 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9566 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
9571 /// \brief Transform an address-of-label expression.
9573 /// By default, the transformation of an address-of-label expression always
9574 /// rebuilds the expression, so that the label identifier can be resolved to
9575 /// the corresponding label statement by semantic analysis.
9576 template<typename Derived>
9578 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
9579 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9584 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
9585 cast<LabelDecl>(LD));
9588 template<typename Derived>
9590 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
9591 SemaRef.ActOnStartStmtExpr();
9593 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
9594 if (SubStmt.isInvalid()) {
9595 SemaRef.ActOnStmtExprError();
9599 if (!getDerived().AlwaysRebuild() &&
9600 SubStmt.get() == E->getSubStmt()) {
9601 // Calling this an 'error' is unintuitive, but it does the right thing.
9602 SemaRef.ActOnStmtExprError();
9603 return SemaRef.MaybeBindToTemporary(E);
9606 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
9611 template<typename Derived>
9613 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
9614 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9615 if (Cond.isInvalid())
9618 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9619 if (LHS.isInvalid())
9622 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9623 if (RHS.isInvalid())
9626 if (!getDerived().AlwaysRebuild() &&
9627 Cond.get() == E->getCond() &&
9628 LHS.get() == E->getLHS() &&
9629 RHS.get() == E->getRHS())
9632 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
9633 Cond.get(), LHS.get(), RHS.get(),
9637 template<typename Derived>
9639 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
9643 template<typename Derived>
9645 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
9646 switch (E->getOperator()) {
9650 case OO_Array_Delete:
9651 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
9654 // This is a call to an object's operator().
9655 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9657 // Transform the object itself.
9658 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
9659 if (Object.isInvalid())
9662 // FIXME: Poor location information
9663 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9664 static_cast<Expr *>(Object.get())->getLocEnd());
9666 // Transform the call arguments.
9667 SmallVector<Expr*, 8> Args;
9668 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
9672 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
9677 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9679 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9680 #include "clang/Basic/OperatorKinds.def"
9685 case OO_Conditional:
9686 llvm_unreachable("conditional operator is not actually overloadable");
9689 case NUM_OVERLOADED_OPERATORS:
9690 llvm_unreachable("not an overloaded operator?");
9693 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9694 if (Callee.isInvalid())
9698 if (E->getOperator() == OO_Amp)
9699 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9701 First = getDerived().TransformExpr(E->getArg(0));
9702 if (First.isInvalid())
9706 if (E->getNumArgs() == 2) {
9707 Second = getDerived().TransformExpr(E->getArg(1));
9708 if (Second.isInvalid())
9712 if (!getDerived().AlwaysRebuild() &&
9713 Callee.get() == E->getCallee() &&
9714 First.get() == E->getArg(0) &&
9715 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
9716 return SemaRef.MaybeBindToTemporary(E);
9718 Sema::FPContractStateRAII FPContractState(getSema());
9719 getSema().FPFeatures = E->getFPFeatures();
9721 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9722 E->getOperatorLoc(),
9728 template<typename Derived>
9730 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9731 return getDerived().TransformCallExpr(E);
9734 template<typename Derived>
9736 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9737 // Transform the callee.
9738 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9739 if (Callee.isInvalid())
9742 // Transform exec config.
9743 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9747 // Transform arguments.
9748 bool ArgChanged = false;
9749 SmallVector<Expr*, 8> Args;
9750 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9754 if (!getDerived().AlwaysRebuild() &&
9755 Callee.get() == E->getCallee() &&
9757 return SemaRef.MaybeBindToTemporary(E);
9759 // FIXME: Wrong source location information for the '('.
9760 SourceLocation FakeLParenLoc
9761 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9762 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9764 E->getRParenLoc(), EC.get());
9767 template<typename Derived>
9769 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
9770 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9775 = getDerived().TransformExpr(E->getSubExprAsWritten());
9776 if (SubExpr.isInvalid())
9779 if (!getDerived().AlwaysRebuild() &&
9780 Type == E->getTypeInfoAsWritten() &&
9781 SubExpr.get() == E->getSubExpr())
9783 return getDerived().RebuildCXXNamedCastExpr(
9784 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9785 Type, E->getAngleBrackets().getEnd(),
9786 // FIXME. this should be '(' location
9787 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
9790 template<typename Derived>
9792 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9793 return getDerived().TransformCXXNamedCastExpr(E);
9796 template<typename Derived>
9798 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9799 return getDerived().TransformCXXNamedCastExpr(E);
9802 template<typename Derived>
9804 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
9805 CXXReinterpretCastExpr *E) {
9806 return getDerived().TransformCXXNamedCastExpr(E);
9809 template<typename Derived>
9811 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9812 return getDerived().TransformCXXNamedCastExpr(E);
9815 template<typename Derived>
9817 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
9818 CXXFunctionalCastExpr *E) {
9819 TypeSourceInfo *Type =
9820 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
9825 = getDerived().TransformExpr(E->getSubExprAsWritten());
9826 if (SubExpr.isInvalid())
9829 if (!getDerived().AlwaysRebuild() &&
9830 Type == E->getTypeInfoAsWritten() &&
9831 SubExpr.get() == E->getSubExpr())
9834 return getDerived().RebuildCXXFunctionalCastExpr(Type,
9840 template<typename Derived>
9842 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
9843 if (E->isTypeOperand()) {
9844 TypeSourceInfo *TInfo
9845 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9849 if (!getDerived().AlwaysRebuild() &&
9850 TInfo == E->getTypeOperandSourceInfo())
9853 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9859 // We don't know whether the subexpression is potentially evaluated until
9860 // after we perform semantic analysis. We speculatively assume it is
9861 // unevaluated; it will get fixed later if the subexpression is in fact
9862 // potentially evaluated.
9863 EnterExpressionEvaluationContext Unevaluated(
9864 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9865 Sema::ReuseLambdaContextDecl);
9867 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9868 if (SubExpr.isInvalid())
9871 if (!getDerived().AlwaysRebuild() &&
9872 SubExpr.get() == E->getExprOperand())
9875 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9881 template<typename Derived>
9883 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9884 if (E->isTypeOperand()) {
9885 TypeSourceInfo *TInfo
9886 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9890 if (!getDerived().AlwaysRebuild() &&
9891 TInfo == E->getTypeOperandSourceInfo())
9894 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9900 EnterExpressionEvaluationContext Unevaluated(
9901 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
9903 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9904 if (SubExpr.isInvalid())
9907 if (!getDerived().AlwaysRebuild() &&
9908 SubExpr.get() == E->getExprOperand())
9911 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9917 template<typename Derived>
9919 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
9923 template<typename Derived>
9925 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
9926 CXXNullPtrLiteralExpr *E) {
9930 template<typename Derived>
9932 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
9933 QualType T = getSema().getCurrentThisType();
9935 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9936 // Make sure that we capture 'this'.
9937 getSema().CheckCXXThisCapture(E->getLocStart());
9941 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
9944 template<typename Derived>
9946 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
9947 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9948 if (SubExpr.isInvalid())
9951 if (!getDerived().AlwaysRebuild() &&
9952 SubExpr.get() == E->getSubExpr())
9955 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9956 E->isThrownVariableInScope());
9959 template<typename Derived>
9961 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
9963 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9968 if (!getDerived().AlwaysRebuild() &&
9969 Param == E->getParam())
9972 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
9975 template<typename Derived>
9977 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9979 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9984 if (!getDerived().AlwaysRebuild() && Field == E->getField())
9987 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9990 template<typename Derived>
9992 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9993 CXXScalarValueInitExpr *E) {
9994 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9998 if (!getDerived().AlwaysRebuild() &&
9999 T == E->getTypeSourceInfo())
10002 return getDerived().RebuildCXXScalarValueInitExpr(T,
10003 /*FIXME:*/T->getTypeLoc().getEndLoc(),
10004 E->getRParenLoc());
10007 template<typename Derived>
10009 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
10010 // Transform the type that we're allocating
10011 TypeSourceInfo *AllocTypeInfo =
10012 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
10013 if (!AllocTypeInfo)
10014 return ExprError();
10016 // Transform the size of the array we're allocating (if any).
10017 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
10018 if (ArraySize.isInvalid())
10019 return ExprError();
10021 // Transform the placement arguments (if any).
10022 bool ArgumentChanged = false;
10023 SmallVector<Expr*, 8> PlacementArgs;
10024 if (getDerived().TransformExprs(E->getPlacementArgs(),
10025 E->getNumPlacementArgs(), true,
10026 PlacementArgs, &ArgumentChanged))
10027 return ExprError();
10029 // Transform the initializer (if any).
10030 Expr *OldInit = E->getInitializer();
10031 ExprResult NewInit;
10033 NewInit = getDerived().TransformInitializer(OldInit, true);
10034 if (NewInit.isInvalid())
10035 return ExprError();
10037 // Transform new operator and delete operator.
10038 FunctionDecl *OperatorNew = nullptr;
10039 if (E->getOperatorNew()) {
10040 OperatorNew = cast_or_null<FunctionDecl>(
10041 getDerived().TransformDecl(E->getLocStart(),
10042 E->getOperatorNew()));
10044 return ExprError();
10047 FunctionDecl *OperatorDelete = nullptr;
10048 if (E->getOperatorDelete()) {
10049 OperatorDelete = cast_or_null<FunctionDecl>(
10050 getDerived().TransformDecl(E->getLocStart(),
10051 E->getOperatorDelete()));
10052 if (!OperatorDelete)
10053 return ExprError();
10056 if (!getDerived().AlwaysRebuild() &&
10057 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
10058 ArraySize.get() == E->getArraySize() &&
10059 NewInit.get() == OldInit &&
10060 OperatorNew == E->getOperatorNew() &&
10061 OperatorDelete == E->getOperatorDelete() &&
10062 !ArgumentChanged) {
10063 // Mark any declarations we need as referenced.
10064 // FIXME: instantiation-specific.
10066 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
10067 if (OperatorDelete)
10068 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
10070 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
10071 QualType ElementType
10072 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10073 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10074 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10075 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
10076 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
10084 QualType AllocType = AllocTypeInfo->getType();
10085 if (!ArraySize.get()) {
10086 // If no array size was specified, but the new expression was
10087 // instantiated with an array type (e.g., "new T" where T is
10088 // instantiated with "int[4]"), extract the outer bound from the
10089 // array type as our array size. We do this with constant and
10090 // dependently-sized array types.
10091 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10094 } else if (const ConstantArrayType *ConsArrayT
10095 = dyn_cast<ConstantArrayType>(ArrayT)) {
10096 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10097 SemaRef.Context.getSizeType(),
10098 /*FIXME:*/ E->getLocStart());
10099 AllocType = ConsArrayT->getElementType();
10100 } else if (const DependentSizedArrayType *DepArrayT
10101 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10102 if (DepArrayT->getSizeExpr()) {
10103 ArraySize = DepArrayT->getSizeExpr();
10104 AllocType = DepArrayT->getElementType();
10109 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10111 /*FIXME:*/E->getLocStart(),
10113 /*FIXME:*/E->getLocStart(),
10114 E->getTypeIdParens(),
10118 E->getDirectInitRange(),
10122 template<typename Derived>
10124 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
10125 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
10126 if (Operand.isInvalid())
10127 return ExprError();
10129 // Transform the delete operator, if known.
10130 FunctionDecl *OperatorDelete = nullptr;
10131 if (E->getOperatorDelete()) {
10132 OperatorDelete = cast_or_null<FunctionDecl>(
10133 getDerived().TransformDecl(E->getLocStart(),
10134 E->getOperatorDelete()));
10135 if (!OperatorDelete)
10136 return ExprError();
10139 if (!getDerived().AlwaysRebuild() &&
10140 Operand.get() == E->getArgument() &&
10141 OperatorDelete == E->getOperatorDelete()) {
10142 // Mark any declarations we need as referenced.
10143 // FIXME: instantiation-specific.
10144 if (OperatorDelete)
10145 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
10147 if (!E->getArgument()->isTypeDependent()) {
10148 QualType Destroyed = SemaRef.Context.getBaseElementType(
10149 E->getDestroyedType());
10150 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10151 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
10152 SemaRef.MarkFunctionReferenced(E->getLocStart(),
10153 SemaRef.LookupDestructor(Record));
10160 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10161 E->isGlobalDelete(),
10166 template<typename Derived>
10168 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
10169 CXXPseudoDestructorExpr *E) {
10170 ExprResult Base = getDerived().TransformExpr(E->getBase());
10171 if (Base.isInvalid())
10172 return ExprError();
10174 ParsedType ObjectTypePtr;
10175 bool MayBePseudoDestructor = false;
10176 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10177 E->getOperatorLoc(),
10178 E->isArrow()? tok::arrow : tok::period,
10180 MayBePseudoDestructor);
10181 if (Base.isInvalid())
10182 return ExprError();
10184 QualType ObjectType = ObjectTypePtr.get();
10185 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10186 if (QualifierLoc) {
10188 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10190 return ExprError();
10193 SS.Adopt(QualifierLoc);
10195 PseudoDestructorTypeStorage Destroyed;
10196 if (E->getDestroyedTypeInfo()) {
10197 TypeSourceInfo *DestroyedTypeInfo
10198 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
10199 ObjectType, nullptr, SS);
10200 if (!DestroyedTypeInfo)
10201 return ExprError();
10202 Destroyed = DestroyedTypeInfo;
10203 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
10204 // We aren't likely to be able to resolve the identifier down to a type
10205 // now anyway, so just retain the identifier.
10206 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10207 E->getDestroyedTypeLoc());
10209 // Look for a destructor known with the given name.
10210 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
10211 *E->getDestroyedTypeIdentifier(),
10212 E->getDestroyedTypeLoc(),
10217 return ExprError();
10220 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10221 E->getDestroyedTypeLoc());
10224 TypeSourceInfo *ScopeTypeInfo = nullptr;
10225 if (E->getScopeTypeInfo()) {
10226 CXXScopeSpec EmptySS;
10227 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
10228 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
10229 if (!ScopeTypeInfo)
10230 return ExprError();
10233 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
10234 E->getOperatorLoc(),
10238 E->getColonColonLoc(),
10243 template <typename Derived>
10244 bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10247 // Transform all the decls.
10248 bool AllEmptyPacks = true;
10249 for (auto *OldD : Old->decls()) {
10250 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10252 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10253 // This can happen because of dependent hiding.
10254 if (isa<UsingShadowDecl>(OldD))
10262 // Expand using pack declarations.
10263 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10264 ArrayRef<NamedDecl*> Decls = SingleDecl;
10265 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10266 Decls = UPD->expansions();
10268 // Expand using declarations.
10269 for (auto *D : Decls) {
10270 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10271 for (auto *SD : UD->shadows())
10278 AllEmptyPacks &= Decls.empty();
10281 // C++ [temp.res]/8.4.2:
10282 // The program is ill-formed, no diagnostic required, if [...] lookup for
10283 // a name in the template definition found a using-declaration, but the
10284 // lookup in the corresponding scope in the instantiation odoes not find
10285 // any declarations because the using-declaration was a pack expansion and
10286 // the corresponding pack is empty
10287 if (AllEmptyPacks && !RequiresADL) {
10288 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10289 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10293 // Resolve a kind, but don't do any further analysis. If it's
10294 // ambiguous, the callee needs to deal with it.
10299 template<typename Derived>
10301 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
10302 UnresolvedLookupExpr *Old) {
10303 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10304 Sema::LookupOrdinaryName);
10306 // Transform the declaration set.
10307 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10308 return ExprError();
10310 // Rebuild the nested-name qualifier, if present.
10312 if (Old->getQualifierLoc()) {
10313 NestedNameSpecifierLoc QualifierLoc
10314 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10316 return ExprError();
10318 SS.Adopt(QualifierLoc);
10321 if (Old->getNamingClass()) {
10322 CXXRecordDecl *NamingClass
10323 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10325 Old->getNamingClass()));
10326 if (!NamingClass) {
10328 return ExprError();
10331 R.setNamingClass(NamingClass);
10334 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10336 // If we have neither explicit template arguments, nor the template keyword,
10337 // it's a normal declaration name or member reference.
10338 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10339 NamedDecl *D = R.getAsSingle<NamedDecl>();
10340 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10341 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10342 // give a good diagnostic.
10343 if (D && D->isCXXInstanceMember()) {
10344 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10345 /*TemplateArgs=*/nullptr,
10346 /*Scope=*/nullptr);
10349 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
10352 // If we have template arguments, rebuild them, then rebuild the
10353 // templateid expression.
10354 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
10355 if (Old->hasExplicitTemplateArgs() &&
10356 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10357 Old->getNumTemplateArgs(),
10360 return ExprError();
10363 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
10364 Old->requiresADL(), &TransArgs);
10367 template<typename Derived>
10369 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10370 bool ArgChanged = false;
10371 SmallVector<TypeSourceInfo *, 4> Args;
10372 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10373 TypeSourceInfo *From = E->getArg(I);
10374 TypeLoc FromTL = From->getTypeLoc();
10375 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
10376 TypeLocBuilder TLB;
10377 TLB.reserve(FromTL.getFullDataSize());
10378 QualType To = getDerived().TransformType(TLB, FromTL);
10380 return ExprError();
10382 if (To == From->getType())
10383 Args.push_back(From);
10385 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10393 // We have a pack expansion. Instantiate it.
10394 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
10395 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10396 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10397 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
10399 // Determine whether the set of unexpanded parameter packs can and should
10401 bool Expand = true;
10402 bool RetainExpansion = false;
10403 Optional<unsigned> OrigNumExpansions =
10404 ExpansionTL.getTypePtr()->getNumExpansions();
10405 Optional<unsigned> NumExpansions = OrigNumExpansions;
10406 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10407 PatternTL.getSourceRange(),
10409 Expand, RetainExpansion,
10411 return ExprError();
10414 // The transform has determined that we should perform a simple
10415 // transformation on the pack expansion, producing another pack
10417 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10419 TypeLocBuilder TLB;
10420 TLB.reserve(From->getTypeLoc().getFullDataSize());
10422 QualType To = getDerived().TransformType(TLB, PatternTL);
10424 return ExprError();
10426 To = getDerived().RebuildPackExpansionType(To,
10427 PatternTL.getSourceRange(),
10428 ExpansionTL.getEllipsisLoc(),
10431 return ExprError();
10433 PackExpansionTypeLoc ToExpansionTL
10434 = TLB.push<PackExpansionTypeLoc>(To);
10435 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10436 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10440 // Expand the pack expansion by substituting for each argument in the
10442 for (unsigned I = 0; I != *NumExpansions; ++I) {
10443 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10444 TypeLocBuilder TLB;
10445 TLB.reserve(PatternTL.getFullDataSize());
10446 QualType To = getDerived().TransformType(TLB, PatternTL);
10448 return ExprError();
10450 if (To->containsUnexpandedParameterPack()) {
10451 To = getDerived().RebuildPackExpansionType(To,
10452 PatternTL.getSourceRange(),
10453 ExpansionTL.getEllipsisLoc(),
10456 return ExprError();
10458 PackExpansionTypeLoc ToExpansionTL
10459 = TLB.push<PackExpansionTypeLoc>(To);
10460 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10463 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10466 if (!RetainExpansion)
10469 // If we're supposed to retain a pack expansion, do so by temporarily
10470 // forgetting the partially-substituted parameter pack.
10471 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10473 TypeLocBuilder TLB;
10474 TLB.reserve(From->getTypeLoc().getFullDataSize());
10476 QualType To = getDerived().TransformType(TLB, PatternTL);
10478 return ExprError();
10480 To = getDerived().RebuildPackExpansionType(To,
10481 PatternTL.getSourceRange(),
10482 ExpansionTL.getEllipsisLoc(),
10485 return ExprError();
10487 PackExpansionTypeLoc ToExpansionTL
10488 = TLB.push<PackExpansionTypeLoc>(To);
10489 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10490 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10493 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10496 return getDerived().RebuildTypeTrait(E->getTrait(),
10502 template<typename Derived>
10504 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10505 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10507 return ExprError();
10509 if (!getDerived().AlwaysRebuild() &&
10510 T == E->getQueriedTypeSourceInfo())
10513 ExprResult SubExpr;
10515 EnterExpressionEvaluationContext Unevaluated(
10516 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
10517 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10518 if (SubExpr.isInvalid())
10519 return ExprError();
10521 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
10525 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10532 template<typename Derived>
10534 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10535 ExprResult SubExpr;
10537 EnterExpressionEvaluationContext Unevaluated(
10538 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
10539 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10540 if (SubExpr.isInvalid())
10541 return ExprError();
10543 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
10547 return getDerived().RebuildExpressionTrait(
10548 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10551 template <typename Derived>
10552 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10553 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10554 TypeSourceInfo **RecoveryTSI) {
10555 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10556 DRE, AddrTaken, RecoveryTSI);
10558 // Propagate both errors and recovered types, which return ExprEmpty.
10559 if (!NewDRE.isUsable())
10562 // We got an expr, wrap it up in parens.
10563 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10565 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10569 template <typename Derived>
10570 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10571 DependentScopeDeclRefExpr *E) {
10572 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10576 template<typename Derived>
10578 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10579 DependentScopeDeclRefExpr *E,
10580 bool IsAddressOfOperand,
10581 TypeSourceInfo **RecoveryTSI) {
10582 assert(E->getQualifierLoc());
10583 NestedNameSpecifierLoc QualifierLoc
10584 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10586 return ExprError();
10587 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10589 // TODO: If this is a conversion-function-id, verify that the
10590 // destination type name (if present) resolves the same way after
10591 // instantiation as it did in the local scope.
10593 DeclarationNameInfo NameInfo
10594 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10595 if (!NameInfo.getName())
10596 return ExprError();
10598 if (!E->hasExplicitTemplateArgs()) {
10599 if (!getDerived().AlwaysRebuild() &&
10600 QualifierLoc == E->getQualifierLoc() &&
10601 // Note: it is sufficient to compare the Name component of NameInfo:
10602 // if name has not changed, DNLoc has not changed either.
10603 NameInfo.getName() == E->getDeclName())
10606 return getDerived().RebuildDependentScopeDeclRefExpr(
10607 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10608 IsAddressOfOperand, RecoveryTSI);
10611 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10612 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10613 E->getNumTemplateArgs(),
10615 return ExprError();
10617 return getDerived().RebuildDependentScopeDeclRefExpr(
10618 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10622 template<typename Derived>
10624 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
10625 // CXXConstructExprs other than for list-initialization and
10626 // CXXTemporaryObjectExpr are always implicit, so when we have
10627 // a 1-argument construction we just transform that argument.
10628 if ((E->getNumArgs() == 1 ||
10629 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
10630 (!getDerived().DropCallArgument(E->getArg(0))) &&
10631 !E->isListInitialization())
10632 return getDerived().TransformExpr(E->getArg(0));
10634 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10636 QualType T = getDerived().TransformType(E->getType());
10638 return ExprError();
10640 CXXConstructorDecl *Constructor
10641 = cast_or_null<CXXConstructorDecl>(
10642 getDerived().TransformDecl(E->getLocStart(),
10643 E->getConstructor()));
10645 return ExprError();
10647 bool ArgumentChanged = false;
10648 SmallVector<Expr*, 8> Args;
10649 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10651 return ExprError();
10653 if (!getDerived().AlwaysRebuild() &&
10654 T == E->getType() &&
10655 Constructor == E->getConstructor() &&
10656 !ArgumentChanged) {
10657 // Mark the constructor as referenced.
10658 // FIXME: Instantiation-specific
10659 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10663 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
10665 E->isElidable(), Args,
10666 E->hadMultipleCandidates(),
10667 E->isListInitialization(),
10668 E->isStdInitListInitialization(),
10669 E->requiresZeroInitialization(),
10670 E->getConstructionKind(),
10671 E->getParenOrBraceRange());
10674 template<typename Derived>
10675 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10676 CXXInheritedCtorInitExpr *E) {
10677 QualType T = getDerived().TransformType(E->getType());
10679 return ExprError();
10681 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10682 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10684 return ExprError();
10686 if (!getDerived().AlwaysRebuild() &&
10687 T == E->getType() &&
10688 Constructor == E->getConstructor()) {
10689 // Mark the constructor as referenced.
10690 // FIXME: Instantiation-specific
10691 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10695 return getDerived().RebuildCXXInheritedCtorInitExpr(
10696 T, E->getLocation(), Constructor,
10697 E->constructsVBase(), E->inheritedFromVBase());
10700 /// \brief Transform a C++ temporary-binding expression.
10702 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10703 /// transform the subexpression and return that.
10704 template<typename Derived>
10706 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
10707 return getDerived().TransformExpr(E->getSubExpr());
10710 /// \brief Transform a C++ expression that contains cleanups that should
10711 /// be run after the expression is evaluated.
10713 /// Since ExprWithCleanups nodes are implicitly generated, we
10714 /// just transform the subexpression and return that.
10715 template<typename Derived>
10717 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
10718 return getDerived().TransformExpr(E->getSubExpr());
10721 template<typename Derived>
10723 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
10724 CXXTemporaryObjectExpr *E) {
10725 TypeSourceInfo *T =
10726 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
10728 return ExprError();
10730 CXXConstructorDecl *Constructor
10731 = cast_or_null<CXXConstructorDecl>(
10732 getDerived().TransformDecl(E->getLocStart(),
10733 E->getConstructor()));
10735 return ExprError();
10737 bool ArgumentChanged = false;
10738 SmallVector<Expr*, 8> Args;
10739 Args.reserve(E->getNumArgs());
10740 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10742 return ExprError();
10744 if (!getDerived().AlwaysRebuild() &&
10745 T == E->getTypeSourceInfo() &&
10746 Constructor == E->getConstructor() &&
10747 !ArgumentChanged) {
10748 // FIXME: Instantiation-specific
10749 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10750 return SemaRef.MaybeBindToTemporary(E);
10753 // FIXME: Pass in E->isListInitialization().
10754 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10755 /*FIXME:*/T->getTypeLoc().getEndLoc(),
10760 template<typename Derived>
10762 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
10763 // Transform any init-capture expressions before entering the scope of the
10764 // lambda body, because they are not semantically within that scope.
10765 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
10766 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10767 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
10768 E->explicit_capture_begin());
10769 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10770 CEnd = E->capture_end();
10772 if (!E->isInitCapture(C))
10774 EnterExpressionEvaluationContext EEEC(
10775 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
10776 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10777 C->getCapturedVar()->getInit(),
10778 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
10780 if (NewExprInitResult.isInvalid())
10781 return ExprError();
10782 Expr *NewExprInit = NewExprInitResult.get();
10784 VarDecl *OldVD = C->getCapturedVar();
10785 QualType NewInitCaptureType =
10786 getSema().buildLambdaInitCaptureInitialization(
10787 C->getLocation(), OldVD->getType()->isReferenceType(),
10788 OldVD->getIdentifier(),
10789 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
10790 NewExprInitResult = NewExprInit;
10791 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10792 std::make_pair(NewExprInitResult, NewInitCaptureType);
10795 // Transform the template parameters, and add them to the current
10796 // instantiation scope. The null case is handled correctly.
10797 auto TPL = getDerived().TransformTemplateParameterList(
10798 E->getTemplateParameterList());
10800 // Transform the type of the original lambda's call operator.
10801 // The transformation MUST be done in the CurrentInstantiationScope since
10802 // it introduces a mapping of the original to the newly created
10803 // transformed parameters.
10804 TypeSourceInfo *NewCallOpTSI = nullptr;
10806 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10807 FunctionProtoTypeLoc OldCallOpFPTL =
10808 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
10810 TypeLocBuilder NewCallOpTLBuilder;
10811 SmallVector<QualType, 4> ExceptionStorage;
10812 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
10813 QualType NewCallOpType = TransformFunctionProtoType(
10814 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
10815 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10816 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10817 ExceptionStorage, Changed);
10819 if (NewCallOpType.isNull())
10820 return ExprError();
10821 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10825 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10826 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10827 LSI->GLTemplateParameterList = TPL;
10829 // Create the local class that will describe the lambda.
10830 CXXRecordDecl *Class
10831 = getSema().createLambdaClosureType(E->getIntroducerRange(),
10833 /*KnownDependent=*/false,
10834 E->getCaptureDefault());
10835 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10837 // Build the call operator.
10838 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10839 Class, E->getIntroducerRange(), NewCallOpTSI,
10840 E->getCallOperator()->getLocEnd(),
10841 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10842 E->getCallOperator()->isConstexpr());
10844 LSI->CallOperator = NewCallOperator;
10846 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10847 I != NumParams; ++I) {
10848 auto *P = NewCallOperator->getParamDecl(I);
10849 if (P->hasUninstantiatedDefaultArg()) {
10850 EnterExpressionEvaluationContext Eval(
10852 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
10853 ExprResult R = getDerived().TransformExpr(
10854 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10855 P->setDefaultArg(R.get());
10859 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
10860 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
10862 // Introduce the context of the call operator.
10863 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
10864 /*NewThisContext*/false);
10866 // Enter the scope of the lambda.
10867 getSema().buildLambdaScope(LSI, NewCallOperator,
10868 E->getIntroducerRange(),
10869 E->getCaptureDefault(),
10870 E->getCaptureDefaultLoc(),
10871 E->hasExplicitParameters(),
10872 E->hasExplicitResultType(),
10875 bool Invalid = false;
10877 // Transform captures.
10878 bool FinishedExplicitCaptures = false;
10879 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10880 CEnd = E->capture_end();
10882 // When we hit the first implicit capture, tell Sema that we've finished
10883 // the list of explicit captures.
10884 if (!FinishedExplicitCaptures && C->isImplicit()) {
10885 getSema().finishLambdaExplicitCaptures(LSI);
10886 FinishedExplicitCaptures = true;
10889 // Capturing 'this' is trivial.
10890 if (C->capturesThis()) {
10891 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10892 /*BuildAndDiagnose*/ true, nullptr,
10893 C->getCaptureKind() == LCK_StarThis);
10896 // Captured expression will be recaptured during captured variables
10898 if (C->capturesVLAType())
10901 // Rebuild init-captures, including the implied field declaration.
10902 if (E->isInitCapture(C)) {
10903 InitCaptureInfoTy InitExprTypePair =
10904 InitCaptureExprsAndTypes[C - E->capture_begin()];
10905 ExprResult Init = InitExprTypePair.first;
10906 QualType InitQualType = InitExprTypePair.second;
10907 if (Init.isInvalid() || InitQualType.isNull()) {
10911 VarDecl *OldVD = C->getCapturedVar();
10912 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
10913 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10914 OldVD->getInitStyle(), Init.get());
10918 getDerived().transformedLocalDecl(OldVD, NewVD);
10920 getSema().buildInitCaptureField(LSI, NewVD);
10924 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10926 // Determine the capture kind for Sema.
10927 Sema::TryCaptureKind Kind
10928 = C->isImplicit()? Sema::TryCapture_Implicit
10929 : C->getCaptureKind() == LCK_ByCopy
10930 ? Sema::TryCapture_ExplicitByVal
10931 : Sema::TryCapture_ExplicitByRef;
10932 SourceLocation EllipsisLoc;
10933 if (C->isPackExpansion()) {
10934 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10935 bool ShouldExpand = false;
10936 bool RetainExpansion = false;
10937 Optional<unsigned> NumExpansions;
10938 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10941 ShouldExpand, RetainExpansion,
10947 if (ShouldExpand) {
10948 // The transform has determined that we should perform an expansion;
10949 // transform and capture each of the arguments.
10950 // expansion of the pattern. Do so.
10951 VarDecl *Pack = C->getCapturedVar();
10952 for (unsigned I = 0; I != *NumExpansions; ++I) {
10953 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10954 VarDecl *CapturedVar
10955 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10957 if (!CapturedVar) {
10962 // Capture the transformed variable.
10963 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10966 // FIXME: Retain a pack expansion if RetainExpansion is true.
10971 EllipsisLoc = C->getEllipsisLoc();
10974 // Transform the captured variable.
10975 VarDecl *CapturedVar
10976 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10977 C->getCapturedVar()));
10978 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
10983 // Capture the transformed variable.
10984 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10987 if (!FinishedExplicitCaptures)
10988 getSema().finishLambdaExplicitCaptures(LSI);
10990 // Enter a new evaluation context to insulate the lambda from any
10991 // cleanups from the enclosing full-expression.
10992 getSema().PushExpressionEvaluationContext(
10993 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
10995 // Instantiate the body of the lambda expression.
10997 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10999 // ActOnLambda* will pop the function scope for us.
11000 FuncScopeCleanup.disable();
11002 if (Body.isInvalid()) {
11003 SavedContext.pop();
11004 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
11005 /*IsInstantiation=*/true);
11006 return ExprError();
11009 // Copy the LSI before ActOnFinishFunctionBody removes it.
11010 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11011 // the call operator.
11012 auto LSICopy = *LSI;
11013 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11014 /*IsInstantiation*/ true);
11015 SavedContext.pop();
11017 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11021 template<typename Derived>
11023 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
11024 CXXUnresolvedConstructExpr *E) {
11025 TypeSourceInfo *T =
11026 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
11028 return ExprError();
11030 bool ArgumentChanged = false;
11031 SmallVector<Expr*, 8> Args;
11032 Args.reserve(E->arg_size());
11033 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11035 return ExprError();
11037 if (!getDerived().AlwaysRebuild() &&
11038 T == E->getTypeSourceInfo() &&
11042 // FIXME: we're faking the locations of the commas
11043 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
11046 E->getRParenLoc());
11049 template<typename Derived>
11051 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
11052 CXXDependentScopeMemberExpr *E) {
11053 // Transform the base of the expression.
11054 ExprResult Base((Expr*) nullptr);
11057 QualType ObjectType;
11058 if (!E->isImplicitAccess()) {
11059 OldBase = E->getBase();
11060 Base = getDerived().TransformExpr(OldBase);
11061 if (Base.isInvalid())
11062 return ExprError();
11064 // Start the member reference and compute the object's type.
11065 ParsedType ObjectTy;
11066 bool MayBePseudoDestructor = false;
11067 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
11068 E->getOperatorLoc(),
11069 E->isArrow()? tok::arrow : tok::period,
11071 MayBePseudoDestructor);
11072 if (Base.isInvalid())
11073 return ExprError();
11075 ObjectType = ObjectTy.get();
11076 BaseType = ((Expr*) Base.get())->getType();
11079 BaseType = getDerived().TransformType(E->getBaseType());
11080 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11083 // Transform the first part of the nested-name-specifier that qualifies
11084 // the member name.
11085 NamedDecl *FirstQualifierInScope
11086 = getDerived().TransformFirstQualifierInScope(
11087 E->getFirstQualifierFoundInScope(),
11088 E->getQualifierLoc().getBeginLoc());
11090 NestedNameSpecifierLoc QualifierLoc;
11091 if (E->getQualifier()) {
11093 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11095 FirstQualifierInScope);
11097 return ExprError();
11100 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11102 // TODO: If this is a conversion-function-id, verify that the
11103 // destination type name (if present) resolves the same way after
11104 // instantiation as it did in the local scope.
11106 DeclarationNameInfo NameInfo
11107 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
11108 if (!NameInfo.getName())
11109 return ExprError();
11111 if (!E->hasExplicitTemplateArgs()) {
11112 // This is a reference to a member without an explicitly-specified
11113 // template argument list. Optimize for this common case.
11114 if (!getDerived().AlwaysRebuild() &&
11115 Base.get() == OldBase &&
11116 BaseType == E->getBaseType() &&
11117 QualifierLoc == E->getQualifierLoc() &&
11118 NameInfo.getName() == E->getMember() &&
11119 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
11122 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
11125 E->getOperatorLoc(),
11128 FirstQualifierInScope,
11130 /*TemplateArgs*/nullptr);
11133 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
11134 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11135 E->getNumTemplateArgs(),
11137 return ExprError();
11139 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
11142 E->getOperatorLoc(),
11145 FirstQualifierInScope,
11150 template<typename Derived>
11152 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
11153 // Transform the base of the expression.
11154 ExprResult Base((Expr*) nullptr);
11156 if (!Old->isImplicitAccess()) {
11157 Base = getDerived().TransformExpr(Old->getBase());
11158 if (Base.isInvalid())
11159 return ExprError();
11160 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
11162 if (Base.isInvalid())
11163 return ExprError();
11164 BaseType = Base.get()->getType();
11166 BaseType = getDerived().TransformType(Old->getBaseType());
11169 NestedNameSpecifierLoc QualifierLoc;
11170 if (Old->getQualifierLoc()) {
11172 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11174 return ExprError();
11177 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11179 LookupResult R(SemaRef, Old->getMemberNameInfo(),
11180 Sema::LookupOrdinaryName);
11182 // Transform the declaration set.
11183 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11184 return ExprError();
11186 // Determine the naming class.
11187 if (Old->getNamingClass()) {
11188 CXXRecordDecl *NamingClass
11189 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
11190 Old->getMemberLoc(),
11191 Old->getNamingClass()));
11193 return ExprError();
11195 R.setNamingClass(NamingClass);
11198 TemplateArgumentListInfo TransArgs;
11199 if (Old->hasExplicitTemplateArgs()) {
11200 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11201 TransArgs.setRAngleLoc(Old->getRAngleLoc());
11202 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11203 Old->getNumTemplateArgs(),
11205 return ExprError();
11208 // FIXME: to do this check properly, we will need to preserve the
11209 // first-qualifier-in-scope here, just in case we had a dependent
11210 // base (and therefore couldn't do the check) and a
11211 // nested-name-qualifier (and therefore could do the lookup).
11212 NamedDecl *FirstQualifierInScope = nullptr;
11214 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
11216 Old->getOperatorLoc(),
11220 FirstQualifierInScope,
11222 (Old->hasExplicitTemplateArgs()
11223 ? &TransArgs : nullptr));
11226 template<typename Derived>
11228 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
11229 EnterExpressionEvaluationContext Unevaluated(
11230 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
11231 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11232 if (SubExpr.isInvalid())
11233 return ExprError();
11235 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
11238 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11241 template<typename Derived>
11243 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
11244 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11245 if (Pattern.isInvalid())
11246 return ExprError();
11248 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
11251 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11252 E->getNumExpansions());
11255 template<typename Derived>
11257 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11258 // If E is not value-dependent, then nothing will change when we transform it.
11259 // Note: This is an instantiation-centric view.
11260 if (!E->isValueDependent())
11263 EnterExpressionEvaluationContext Unevaluated(
11264 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
11266 ArrayRef<TemplateArgument> PackArgs;
11267 TemplateArgument ArgStorage;
11269 // Find the argument list to transform.
11270 if (E->isPartiallySubstituted()) {
11271 PackArgs = E->getPartialArguments();
11272 } else if (E->isValueDependent()) {
11273 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11274 bool ShouldExpand = false;
11275 bool RetainExpansion = false;
11276 Optional<unsigned> NumExpansions;
11277 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11279 ShouldExpand, RetainExpansion,
11281 return ExprError();
11283 // If we need to expand the pack, build a template argument from it and
11285 if (ShouldExpand) {
11286 auto *Pack = E->getPack();
11287 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11288 ArgStorage = getSema().Context.getPackExpansionType(
11289 getSema().Context.getTypeDeclType(TTPD), None);
11290 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11291 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11293 auto *VD = cast<ValueDecl>(Pack);
11294 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11295 VK_RValue, E->getPackLoc());
11296 if (DRE.isInvalid())
11297 return ExprError();
11298 ArgStorage = new (getSema().Context) PackExpansionExpr(
11299 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11301 PackArgs = ArgStorage;
11305 // If we're not expanding the pack, just transform the decl.
11306 if (!PackArgs.size()) {
11307 auto *Pack = cast_or_null<NamedDecl>(
11308 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
11310 return ExprError();
11311 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11313 E->getRParenLoc(), None, None);
11316 // Try to compute the result without performing a partial substitution.
11317 Optional<unsigned> Result = 0;
11318 for (const TemplateArgument &Arg : PackArgs) {
11319 if (!Arg.isPackExpansion()) {
11320 Result = *Result + 1;
11324 TemplateArgumentLoc ArgLoc;
11325 InventTemplateArgumentLoc(Arg, ArgLoc);
11327 // Find the pattern of the pack expansion.
11328 SourceLocation Ellipsis;
11329 Optional<unsigned> OrigNumExpansions;
11330 TemplateArgumentLoc Pattern =
11331 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11332 OrigNumExpansions);
11334 // Substitute under the pack expansion. Do not expand the pack (yet).
11335 TemplateArgumentLoc OutPattern;
11336 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11337 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11341 // See if we can determine the number of arguments from the result.
11342 Optional<unsigned> NumExpansions =
11343 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11344 if (!NumExpansions) {
11345 // No: we must be in an alias template expansion, and we're going to need
11346 // to actually expand the packs.
11351 Result = *Result + *NumExpansions;
11354 // Common case: we could determine the number of expansions without
11357 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11359 E->getRParenLoc(), *Result, None);
11361 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11364 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11365 typedef TemplateArgumentLocInventIterator<
11366 Derived, const TemplateArgument*> PackLocIterator;
11367 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11368 PackLocIterator(*this, PackArgs.end()),
11369 TransformedPackArgs, /*Uneval*/true))
11370 return ExprError();
11373 // Check whether we managed to fully-expand the pack.
11374 // FIXME: Is it possible for us to do so and not hit the early exit path?
11375 SmallVector<TemplateArgument, 8> Args;
11376 bool PartialSubstitution = false;
11377 for (auto &Loc : TransformedPackArgs.arguments()) {
11378 Args.push_back(Loc.getArgument());
11379 if (Loc.getArgument().isPackExpansion())
11380 PartialSubstitution = true;
11383 if (PartialSubstitution)
11384 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11386 E->getRParenLoc(), None, Args);
11388 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11389 E->getPackLoc(), E->getRParenLoc(),
11390 Args.size(), None);
11393 template<typename Derived>
11395 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11396 SubstNonTypeTemplateParmPackExpr *E) {
11397 // Default behavior is to do nothing with this transformation.
11401 template<typename Derived>
11403 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11404 SubstNonTypeTemplateParmExpr *E) {
11405 // Default behavior is to do nothing with this transformation.
11409 template<typename Derived>
11411 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11412 // Default behavior is to do nothing with this transformation.
11416 template<typename Derived>
11418 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11419 MaterializeTemporaryExpr *E) {
11420 return getDerived().TransformExpr(E->GetTemporaryExpr());
11423 template<typename Derived>
11425 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11426 Expr *Pattern = E->getPattern();
11428 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11429 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11430 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11432 // Determine whether the set of unexpanded parameter packs can and should
11434 bool Expand = true;
11435 bool RetainExpansion = false;
11436 Optional<unsigned> NumExpansions;
11437 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11438 Pattern->getSourceRange(),
11440 Expand, RetainExpansion,
11445 // Do not expand any packs here, just transform and rebuild a fold
11447 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11450 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11451 if (LHS.isInvalid())
11455 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11456 if (RHS.isInvalid())
11459 if (!getDerived().AlwaysRebuild() &&
11460 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11463 return getDerived().RebuildCXXFoldExpr(
11464 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11465 RHS.get(), E->getLocEnd());
11468 // The transform has determined that we should perform an elementwise
11469 // expansion of the pattern. Do so.
11470 ExprResult Result = getDerived().TransformExpr(E->getInit());
11471 if (Result.isInvalid())
11473 bool LeftFold = E->isLeftFold();
11475 // If we're retaining an expansion for a right fold, it is the innermost
11476 // component and takes the init (if any).
11477 if (!LeftFold && RetainExpansion) {
11478 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11480 ExprResult Out = getDerived().TransformExpr(Pattern);
11481 if (Out.isInvalid())
11484 Result = getDerived().RebuildCXXFoldExpr(
11485 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11486 Result.get(), E->getLocEnd());
11487 if (Result.isInvalid())
11491 for (unsigned I = 0; I != *NumExpansions; ++I) {
11492 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11493 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11494 ExprResult Out = getDerived().TransformExpr(Pattern);
11495 if (Out.isInvalid())
11498 if (Out.get()->containsUnexpandedParameterPack()) {
11499 // We still have a pack; retain a pack expansion for this slice.
11500 Result = getDerived().RebuildCXXFoldExpr(
11502 LeftFold ? Result.get() : Out.get(),
11503 E->getOperator(), E->getEllipsisLoc(),
11504 LeftFold ? Out.get() : Result.get(),
11506 } else if (Result.isUsable()) {
11507 // We've got down to a single element; build a binary operator.
11508 Result = getDerived().RebuildBinaryOperator(
11509 E->getEllipsisLoc(), E->getOperator(),
11510 LeftFold ? Result.get() : Out.get(),
11511 LeftFold ? Out.get() : Result.get());
11515 if (Result.isInvalid())
11519 // If we're retaining an expansion for a left fold, it is the outermost
11520 // component and takes the complete expansion so far as its init (if any).
11521 if (LeftFold && RetainExpansion) {
11522 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11524 ExprResult Out = getDerived().TransformExpr(Pattern);
11525 if (Out.isInvalid())
11528 Result = getDerived().RebuildCXXFoldExpr(
11529 E->getLocStart(), Result.get(),
11530 E->getOperator(), E->getEllipsisLoc(),
11531 Out.get(), E->getLocEnd());
11532 if (Result.isInvalid())
11536 // If we had no init and an empty pack, and we're not retaining an expansion,
11537 // then produce a fallback value or error.
11538 if (Result.isUnset())
11539 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11545 template<typename Derived>
11547 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11548 CXXStdInitializerListExpr *E) {
11549 return getDerived().TransformExpr(E->getSubExpr());
11552 template<typename Derived>
11554 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
11555 return SemaRef.MaybeBindToTemporary(E);
11558 template<typename Derived>
11560 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
11564 template<typename Derived>
11566 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11567 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11568 if (SubExpr.isInvalid())
11569 return ExprError();
11571 if (!getDerived().AlwaysRebuild() &&
11572 SubExpr.get() == E->getSubExpr())
11575 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
11578 template<typename Derived>
11580 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11581 // Transform each of the elements.
11582 SmallVector<Expr *, 8> Elements;
11583 bool ArgChanged = false;
11584 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
11585 /*IsCall=*/false, Elements, &ArgChanged))
11586 return ExprError();
11588 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11589 return SemaRef.MaybeBindToTemporary(E);
11591 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11596 template<typename Derived>
11598 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
11599 ObjCDictionaryLiteral *E) {
11600 // Transform each of the elements.
11601 SmallVector<ObjCDictionaryElement, 8> Elements;
11602 bool ArgChanged = false;
11603 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11604 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
11606 if (OrigElement.isPackExpansion()) {
11607 // This key/value element is a pack expansion.
11608 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11609 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11610 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11611 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11613 // Determine whether the set of unexpanded parameter packs can
11614 // and should be expanded.
11615 bool Expand = true;
11616 bool RetainExpansion = false;
11617 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11618 Optional<unsigned> NumExpansions = OrigNumExpansions;
11619 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11620 OrigElement.Value->getLocEnd());
11621 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11624 Expand, RetainExpansion,
11626 return ExprError();
11629 // The transform has determined that we should perform a simple
11630 // transformation on the pack expansion, producing another pack
11632 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11633 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11634 if (Key.isInvalid())
11635 return ExprError();
11637 if (Key.get() != OrigElement.Key)
11640 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11641 if (Value.isInvalid())
11642 return ExprError();
11644 if (Value.get() != OrigElement.Value)
11647 ObjCDictionaryElement Expansion = {
11648 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11650 Elements.push_back(Expansion);
11654 // Record right away that the argument was changed. This needs
11655 // to happen even if the array expands to nothing.
11658 // The transform has determined that we should perform an elementwise
11659 // expansion of the pattern. Do so.
11660 for (unsigned I = 0; I != *NumExpansions; ++I) {
11661 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11662 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11663 if (Key.isInvalid())
11664 return ExprError();
11666 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11667 if (Value.isInvalid())
11668 return ExprError();
11670 ObjCDictionaryElement Element = {
11671 Key.get(), Value.get(), SourceLocation(), NumExpansions
11674 // If any unexpanded parameter packs remain, we still have a
11676 // FIXME: Can this really happen?
11677 if (Key.get()->containsUnexpandedParameterPack() ||
11678 Value.get()->containsUnexpandedParameterPack())
11679 Element.EllipsisLoc = OrigElement.EllipsisLoc;
11681 Elements.push_back(Element);
11684 // FIXME: Retain a pack expansion if RetainExpansion is true.
11686 // We've finished with this pack expansion.
11690 // Transform and check key.
11691 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11692 if (Key.isInvalid())
11693 return ExprError();
11695 if (Key.get() != OrigElement.Key)
11698 // Transform and check value.
11700 = getDerived().TransformExpr(OrigElement.Value);
11701 if (Value.isInvalid())
11702 return ExprError();
11704 if (Value.get() != OrigElement.Value)
11707 ObjCDictionaryElement Element = {
11708 Key.get(), Value.get(), SourceLocation(), None
11710 Elements.push_back(Element);
11713 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11714 return SemaRef.MaybeBindToTemporary(E);
11716 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
11720 template<typename Derived>
11722 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
11723 TypeSourceInfo *EncodedTypeInfo
11724 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11725 if (!EncodedTypeInfo)
11726 return ExprError();
11728 if (!getDerived().AlwaysRebuild() &&
11729 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
11732 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
11734 E->getRParenLoc());
11737 template<typename Derived>
11738 ExprResult TreeTransform<Derived>::
11739 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
11740 // This is a kind of implicit conversion, and it needs to get dropped
11741 // and recomputed for the same general reasons that ImplicitCastExprs
11742 // do, as well a more specific one: this expression is only valid when
11743 // it appears *immediately* as an argument expression.
11744 return getDerived().TransformExpr(E->getSubExpr());
11747 template<typename Derived>
11748 ExprResult TreeTransform<Derived>::
11749 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
11750 TypeSourceInfo *TSInfo
11751 = getDerived().TransformType(E->getTypeInfoAsWritten());
11753 return ExprError();
11755 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
11756 if (Result.isInvalid())
11757 return ExprError();
11759 if (!getDerived().AlwaysRebuild() &&
11760 TSInfo == E->getTypeInfoAsWritten() &&
11761 Result.get() == E->getSubExpr())
11764 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
11765 E->getBridgeKeywordLoc(), TSInfo,
11769 template <typename Derived>
11770 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11771 ObjCAvailabilityCheckExpr *E) {
11775 template<typename Derived>
11777 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
11778 // Transform arguments.
11779 bool ArgChanged = false;
11780 SmallVector<Expr*, 8> Args;
11781 Args.reserve(E->getNumArgs());
11782 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
11784 return ExprError();
11786 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11787 // Class message: transform the receiver type.
11788 TypeSourceInfo *ReceiverTypeInfo
11789 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11790 if (!ReceiverTypeInfo)
11791 return ExprError();
11793 // If nothing changed, just retain the existing message send.
11794 if (!getDerived().AlwaysRebuild() &&
11795 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
11796 return SemaRef.MaybeBindToTemporary(E);
11798 // Build a new class message send.
11799 SmallVector<SourceLocation, 16> SelLocs;
11800 E->getSelectorLocs(SelLocs);
11801 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11804 E->getMethodDecl(),
11809 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11810 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11811 if (!E->getMethodDecl())
11812 return ExprError();
11814 // Build a new class message send to 'super'.
11815 SmallVector<SourceLocation, 16> SelLocs;
11816 E->getSelectorLocs(SelLocs);
11817 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11820 E->getReceiverType(),
11821 E->getMethodDecl(),
11827 // Instance message: transform the receiver
11828 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11829 "Only class and instance messages may be instantiated");
11830 ExprResult Receiver
11831 = getDerived().TransformExpr(E->getInstanceReceiver());
11832 if (Receiver.isInvalid())
11833 return ExprError();
11835 // If nothing changed, just retain the existing message send.
11836 if (!getDerived().AlwaysRebuild() &&
11837 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
11838 return SemaRef.MaybeBindToTemporary(E);
11840 // Build a new instance message send.
11841 SmallVector<SourceLocation, 16> SelLocs;
11842 E->getSelectorLocs(SelLocs);
11843 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
11846 E->getMethodDecl(),
11852 template<typename Derived>
11854 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
11858 template<typename Derived>
11860 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
11864 template<typename Derived>
11866 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
11867 // Transform the base expression.
11868 ExprResult Base = getDerived().TransformExpr(E->getBase());
11869 if (Base.isInvalid())
11870 return ExprError();
11872 // We don't need to transform the ivar; it will never change.
11874 // If nothing changed, just retain the existing expression.
11875 if (!getDerived().AlwaysRebuild() &&
11876 Base.get() == E->getBase())
11879 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
11881 E->isArrow(), E->isFreeIvar());
11884 template<typename Derived>
11886 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
11887 // 'super' and types never change. Property never changes. Just
11888 // retain the existing expression.
11889 if (!E->isObjectReceiver())
11892 // Transform the base expression.
11893 ExprResult Base = getDerived().TransformExpr(E->getBase());
11894 if (Base.isInvalid())
11895 return ExprError();
11897 // We don't need to transform the property; it will never change.
11899 // If nothing changed, just retain the existing expression.
11900 if (!getDerived().AlwaysRebuild() &&
11901 Base.get() == E->getBase())
11904 if (E->isExplicitProperty())
11905 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11906 E->getExplicitProperty(),
11909 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11910 SemaRef.Context.PseudoObjectTy,
11911 E->getImplicitPropertyGetter(),
11912 E->getImplicitPropertySetter(),
11916 template<typename Derived>
11918 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11919 // Transform the base expression.
11920 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11921 if (Base.isInvalid())
11922 return ExprError();
11924 // Transform the key expression.
11925 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11926 if (Key.isInvalid())
11927 return ExprError();
11929 // If nothing changed, just retain the existing expression.
11930 if (!getDerived().AlwaysRebuild() &&
11931 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
11934 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
11935 Base.get(), Key.get(),
11936 E->getAtIndexMethodDecl(),
11937 E->setAtIndexMethodDecl());
11940 template<typename Derived>
11942 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
11943 // Transform the base expression.
11944 ExprResult Base = getDerived().TransformExpr(E->getBase());
11945 if (Base.isInvalid())
11946 return ExprError();
11948 // If nothing changed, just retain the existing expression.
11949 if (!getDerived().AlwaysRebuild() &&
11950 Base.get() == E->getBase())
11953 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
11958 template<typename Derived>
11960 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
11961 bool ArgumentChanged = false;
11962 SmallVector<Expr*, 8> SubExprs;
11963 SubExprs.reserve(E->getNumSubExprs());
11964 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11965 SubExprs, &ArgumentChanged))
11966 return ExprError();
11968 if (!getDerived().AlwaysRebuild() &&
11972 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
11974 E->getRParenLoc());
11977 template<typename Derived>
11979 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11980 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11981 if (SrcExpr.isInvalid())
11982 return ExprError();
11984 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11986 return ExprError();
11988 if (!getDerived().AlwaysRebuild() &&
11989 Type == E->getTypeSourceInfo() &&
11990 SrcExpr.get() == E->getSrcExpr())
11993 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11994 SrcExpr.get(), Type,
11995 E->getRParenLoc());
11998 template<typename Derived>
12000 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
12001 BlockDecl *oldBlock = E->getBlockDecl();
12003 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
12004 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12006 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
12007 blockScope->TheDecl->setBlockMissingReturnType(
12008 oldBlock->blockMissingReturnType());
12010 SmallVector<ParmVarDecl*, 4> params;
12011 SmallVector<QualType, 4> paramTypes;
12013 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12015 // Parameter substitution.
12016 Sema::ExtParameterInfoBuilder extParamInfos;
12017 if (getDerived().TransformFunctionTypeParams(
12018 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12019 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms,
12021 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
12022 return ExprError();
12025 QualType exprResultType =
12026 getDerived().TransformType(exprFunctionType->getReturnType());
12028 auto epi = exprFunctionType->getExtProtoInfo();
12029 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12031 QualType functionType =
12032 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
12033 blockScope->FunctionType = functionType;
12035 // Set the parameters on the block decl.
12036 if (!params.empty())
12037 blockScope->TheDecl->setParams(params);
12039 if (!oldBlock->blockMissingReturnType()) {
12040 blockScope->HasImplicitReturnType = false;
12041 blockScope->ReturnType = exprResultType;
12044 // Transform the body
12045 StmtResult body = getDerived().TransformStmt(E->getBody());
12046 if (body.isInvalid()) {
12047 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
12048 return ExprError();
12052 // In builds with assertions, make sure that we captured everything we
12053 // captured before.
12054 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
12055 for (const auto &I : oldBlock->captures()) {
12056 VarDecl *oldCapture = I.getVariable();
12058 // Ignore parameter packs.
12059 if (isa<ParmVarDecl>(oldCapture) &&
12060 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12063 VarDecl *newCapture =
12064 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12066 assert(blockScope->CaptureMap.count(newCapture));
12068 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
12072 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
12073 /*Scope=*/nullptr);
12076 template<typename Derived>
12078 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
12079 llvm_unreachable("Cannot transform asType expressions yet");
12082 template<typename Derived>
12084 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
12085 QualType RetTy = getDerived().TransformType(E->getType());
12086 bool ArgumentChanged = false;
12087 SmallVector<Expr*, 8> SubExprs;
12088 SubExprs.reserve(E->getNumSubExprs());
12089 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12090 SubExprs, &ArgumentChanged))
12091 return ExprError();
12093 if (!getDerived().AlwaysRebuild() &&
12097 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
12098 RetTy, E->getOp(), E->getRParenLoc());
12101 //===----------------------------------------------------------------------===//
12102 // Type reconstruction
12103 //===----------------------------------------------------------------------===//
12105 template<typename Derived>
12106 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12107 SourceLocation Star) {
12108 return SemaRef.BuildPointerType(PointeeType, Star,
12109 getDerived().getBaseEntity());
12112 template<typename Derived>
12113 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12114 SourceLocation Star) {
12115 return SemaRef.BuildBlockPointerType(PointeeType, Star,
12116 getDerived().getBaseEntity());
12119 template<typename Derived>
12121 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12122 bool WrittenAsLValue,
12123 SourceLocation Sigil) {
12124 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
12125 Sigil, getDerived().getBaseEntity());
12128 template<typename Derived>
12130 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12131 QualType ClassType,
12132 SourceLocation Sigil) {
12133 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12134 getDerived().getBaseEntity());
12137 template<typename Derived>
12138 QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12139 const ObjCTypeParamDecl *Decl,
12140 SourceLocation ProtocolLAngleLoc,
12141 ArrayRef<ObjCProtocolDecl *> Protocols,
12142 ArrayRef<SourceLocation> ProtocolLocs,
12143 SourceLocation ProtocolRAngleLoc) {
12144 return SemaRef.BuildObjCTypeParamType(Decl,
12145 ProtocolLAngleLoc, Protocols,
12146 ProtocolLocs, ProtocolRAngleLoc,
12147 /*FailOnError=*/true);
12150 template<typename Derived>
12151 QualType TreeTransform<Derived>::RebuildObjCObjectType(
12153 SourceLocation Loc,
12154 SourceLocation TypeArgsLAngleLoc,
12155 ArrayRef<TypeSourceInfo *> TypeArgs,
12156 SourceLocation TypeArgsRAngleLoc,
12157 SourceLocation ProtocolLAngleLoc,
12158 ArrayRef<ObjCProtocolDecl *> Protocols,
12159 ArrayRef<SourceLocation> ProtocolLocs,
12160 SourceLocation ProtocolRAngleLoc) {
12161 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12162 TypeArgs, TypeArgsRAngleLoc,
12163 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12165 /*FailOnError=*/true);
12168 template<typename Derived>
12169 QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12170 QualType PointeeType,
12171 SourceLocation Star) {
12172 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12175 template<typename Derived>
12177 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12178 ArrayType::ArraySizeModifier SizeMod,
12179 const llvm::APInt *Size,
12181 unsigned IndexTypeQuals,
12182 SourceRange BracketsRange) {
12183 if (SizeExpr || !Size)
12184 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12185 IndexTypeQuals, BracketsRange,
12186 getDerived().getBaseEntity());
12188 QualType Types[] = {
12189 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12190 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12191 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
12193 const unsigned NumTypes = llvm::array_lengthof(Types);
12195 for (unsigned I = 0; I != NumTypes; ++I)
12196 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12197 SizeType = Types[I];
12201 // Note that we can return a VariableArrayType here in the case where
12202 // the element type was a dependent VariableArrayType.
12203 IntegerLiteral *ArraySize
12204 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12205 /*FIXME*/BracketsRange.getBegin());
12206 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
12207 IndexTypeQuals, BracketsRange,
12208 getDerived().getBaseEntity());
12211 template<typename Derived>
12213 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
12214 ArrayType::ArraySizeModifier SizeMod,
12215 const llvm::APInt &Size,
12216 unsigned IndexTypeQuals,
12217 SourceRange BracketsRange) {
12218 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
12219 IndexTypeQuals, BracketsRange);
12222 template<typename Derived>
12224 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
12225 ArrayType::ArraySizeModifier SizeMod,
12226 unsigned IndexTypeQuals,
12227 SourceRange BracketsRange) {
12228 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
12229 IndexTypeQuals, BracketsRange);
12232 template<typename Derived>
12234 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
12235 ArrayType::ArraySizeModifier SizeMod,
12237 unsigned IndexTypeQuals,
12238 SourceRange BracketsRange) {
12239 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
12241 IndexTypeQuals, BracketsRange);
12244 template<typename Derived>
12246 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
12247 ArrayType::ArraySizeModifier SizeMod,
12249 unsigned IndexTypeQuals,
12250 SourceRange BracketsRange) {
12251 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
12253 IndexTypeQuals, BracketsRange);
12256 template<typename Derived>
12257 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12258 unsigned NumElements,
12259 VectorType::VectorKind VecKind) {
12260 // FIXME: semantic checking!
12261 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
12264 template<typename Derived>
12265 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12266 unsigned NumElements,
12267 SourceLocation AttributeLoc) {
12268 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12269 NumElements, true);
12270 IntegerLiteral *VectorSize
12271 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12273 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
12276 template<typename Derived>
12278 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
12280 SourceLocation AttributeLoc) {
12281 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
12284 template<typename Derived>
12285 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12287 MutableArrayRef<QualType> ParamTypes,
12288 const FunctionProtoType::ExtProtoInfo &EPI) {
12289 return SemaRef.BuildFunctionType(T, ParamTypes,
12290 getDerived().getBaseLocation(),
12291 getDerived().getBaseEntity(),
12295 template<typename Derived>
12296 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12297 return SemaRef.Context.getFunctionNoProtoType(T);
12300 template<typename Derived>
12301 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12303 assert(D && "no decl found");
12304 if (D->isInvalidDecl()) return QualType();
12306 // FIXME: Doesn't account for ObjCInterfaceDecl!
12308 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12309 // A valid resolved using typename pack expansion decl can have multiple
12310 // UsingDecls, but they must each have exactly one type, and it must be
12311 // the same type in every case. But we must have at least one expansion!
12312 if (UPD->expansions().empty()) {
12313 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12314 << UPD->isCXXClassMember() << UPD;
12318 // We might still have some unresolved types. Try to pick a resolved type
12319 // if we can. The final instantiation will check that the remaining
12320 // unresolved types instantiate to the type we pick.
12321 QualType FallbackT;
12323 for (auto *E : UPD->expansions()) {
12324 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12325 if (ThisT.isNull())
12327 else if (ThisT->getAs<UnresolvedUsingType>())
12329 else if (T.isNull())
12332 assert(getSema().Context.hasSameType(ThisT, T) &&
12333 "mismatched resolved types in using pack expansion");
12335 return T.isNull() ? FallbackT : T;
12336 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
12337 assert(Using->hasTypename() &&
12338 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12340 // A valid resolved using typename decl points to exactly one type decl.
12341 assert(++Using->shadow_begin() == Using->shadow_end());
12342 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
12344 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12345 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12346 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12349 return SemaRef.Context.getTypeDeclType(Ty);
12352 template<typename Derived>
12353 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12354 SourceLocation Loc) {
12355 return SemaRef.BuildTypeofExprType(E, Loc);
12358 template<typename Derived>
12359 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12360 return SemaRef.Context.getTypeOfType(Underlying);
12363 template<typename Derived>
12364 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12365 SourceLocation Loc) {
12366 return SemaRef.BuildDecltypeType(E, Loc);
12369 template<typename Derived>
12370 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12371 UnaryTransformType::UTTKind UKind,
12372 SourceLocation Loc) {
12373 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12376 template<typename Derived>
12377 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
12378 TemplateName Template,
12379 SourceLocation TemplateNameLoc,
12380 TemplateArgumentListInfo &TemplateArgs) {
12381 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
12384 template<typename Derived>
12385 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12386 SourceLocation KWLoc) {
12387 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12390 template<typename Derived>
12391 QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
12392 SourceLocation KWLoc,
12394 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12395 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
12398 template<typename Derived>
12400 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12402 TemplateDecl *Template) {
12403 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
12407 template<typename Derived>
12409 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12410 const IdentifierInfo &Name,
12411 SourceLocation NameLoc,
12412 QualType ObjectType,
12413 NamedDecl *FirstQualifierInScope,
12414 bool AllowInjectedClassName) {
12415 UnqualifiedId TemplateName;
12416 TemplateName.setIdentifier(&Name, NameLoc);
12417 Sema::TemplateTy Template;
12418 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12419 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12420 SS, TemplateKWLoc, TemplateName,
12421 ParsedType::make(ObjectType),
12422 /*EnteringContext=*/false,
12423 Template, AllowInjectedClassName);
12424 return Template.get();
12427 template<typename Derived>
12429 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12430 OverloadedOperatorKind Operator,
12431 SourceLocation NameLoc,
12432 QualType ObjectType,
12433 bool AllowInjectedClassName) {
12434 UnqualifiedId Name;
12435 // FIXME: Bogus location information.
12436 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
12437 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
12438 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12439 Sema::TemplateTy Template;
12440 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12441 SS, TemplateKWLoc, Name,
12442 ParsedType::make(ObjectType),
12443 /*EnteringContext=*/false,
12444 Template, AllowInjectedClassName);
12445 return Template.get();
12448 template<typename Derived>
12450 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12451 SourceLocation OpLoc,
12455 Expr *Callee = OrigCallee->IgnoreParenCasts();
12456 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
12458 if (First->getObjectKind() == OK_ObjCProperty) {
12459 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12460 if (BinaryOperator::isAssignmentOp(Opc))
12461 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12463 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12464 if (Result.isInvalid())
12465 return ExprError();
12466 First = Result.get();
12469 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12470 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12471 if (Result.isInvalid())
12472 return ExprError();
12473 Second = Result.get();
12476 // Determine whether this should be a builtin operation.
12477 if (Op == OO_Subscript) {
12478 if (!First->getType()->isOverloadableType() &&
12479 !Second->getType()->isOverloadableType())
12480 return getSema().CreateBuiltinArraySubscriptExpr(First,
12481 Callee->getLocStart(),
12483 } else if (Op == OO_Arrow) {
12484 // -> is never a builtin operation.
12485 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12486 } else if (Second == nullptr || isPostIncDec) {
12487 if (!First->getType()->isOverloadableType()) {
12488 // The argument is not of overloadable type, so try to create a
12489 // built-in unary operation.
12490 UnaryOperatorKind Opc
12491 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12493 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
12496 if (!First->getType()->isOverloadableType() &&
12497 !Second->getType()->isOverloadableType()) {
12498 // Neither of the arguments is an overloadable type, so try to
12499 // create a built-in binary operation.
12500 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12502 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
12503 if (Result.isInvalid())
12504 return ExprError();
12510 // Compute the transformed set of functions (and function templates) to be
12511 // used during overload resolution.
12512 UnresolvedSet<16> Functions;
12514 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
12515 assert(ULE->requiresADL());
12516 Functions.append(ULE->decls_begin(), ULE->decls_end());
12518 // If we've resolved this to a particular non-member function, just call
12519 // that function. If we resolved it to a member function,
12520 // CreateOverloaded* will find that function for us.
12521 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12522 if (!isa<CXXMethodDecl>(ND))
12523 Functions.addDecl(ND);
12526 // Add any functions found via argument-dependent lookup.
12527 Expr *Args[2] = { First, Second };
12528 unsigned NumArgs = 1 + (Second != nullptr);
12530 // Create the overloaded operator invocation for unary operators.
12531 if (NumArgs == 1 || isPostIncDec) {
12532 UnaryOperatorKind Opc
12533 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12534 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
12537 if (Op == OO_Subscript) {
12538 SourceLocation LBrace;
12539 SourceLocation RBrace;
12541 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
12542 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
12543 LBrace = SourceLocation::getFromRawEncoding(
12544 NameLoc.CXXOperatorName.BeginOpNameLoc);
12545 RBrace = SourceLocation::getFromRawEncoding(
12546 NameLoc.CXXOperatorName.EndOpNameLoc);
12548 LBrace = Callee->getLocStart();
12552 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12556 // Create the overloaded operator invocation for binary operators.
12557 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12559 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12560 if (Result.isInvalid())
12561 return ExprError();
12566 template<typename Derived>
12568 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
12569 SourceLocation OperatorLoc,
12572 TypeSourceInfo *ScopeType,
12573 SourceLocation CCLoc,
12574 SourceLocation TildeLoc,
12575 PseudoDestructorTypeStorage Destroyed) {
12576 QualType BaseType = Base->getType();
12577 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
12578 (!isArrow && !BaseType->getAs<RecordType>()) ||
12579 (isArrow && BaseType->getAs<PointerType>() &&
12580 !BaseType->getAs<PointerType>()->getPointeeType()
12581 ->template getAs<RecordType>())){
12582 // This pseudo-destructor expression is still a pseudo-destructor.
12583 return SemaRef.BuildPseudoDestructorExpr(
12584 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12585 CCLoc, TildeLoc, Destroyed);
12588 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
12589 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12590 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12591 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12592 NameInfo.setNamedTypeInfo(DestroyedType);
12594 // The scope type is now known to be a valid nested name specifier
12595 // component. Tack it on to the end of the nested name specifier.
12597 if (!ScopeType->getType()->getAs<TagType>()) {
12598 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12599 diag::err_expected_class_or_namespace)
12600 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12601 return ExprError();
12603 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12607 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12608 return getSema().BuildMemberReferenceExpr(Base, BaseType,
12609 OperatorLoc, isArrow,
12611 /*FIXME: FirstQualifier*/ nullptr,
12613 /*TemplateArgs*/ nullptr,
12617 template<typename Derived>
12619 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
12620 SourceLocation Loc = S->getLocStart();
12621 CapturedDecl *CD = S->getCapturedDecl();
12622 unsigned NumParams = CD->getNumParams();
12623 unsigned ContextParamPos = CD->getContextParamPosition();
12624 SmallVector<Sema::CapturedParamNameType, 4> Params;
12625 for (unsigned I = 0; I < NumParams; ++I) {
12626 if (I != ContextParamPos) {
12629 CD->getParam(I)->getName(),
12630 getDerived().TransformType(CD->getParam(I)->getType())));
12632 Params.push_back(std::make_pair(StringRef(), QualType()));
12635 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
12636 S->getCapturedRegionKind(), Params);
12639 Sema::CompoundScopeRAII CompoundScope(getSema());
12640 Body = getDerived().TransformStmt(S->getCapturedStmt());
12643 if (Body.isInvalid()) {
12644 getSema().ActOnCapturedRegionError();
12645 return StmtError();
12648 return getSema().ActOnCapturedRegionEnd(Body.get());
12651 } // end namespace clang
12653 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H