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 /// 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 /// overriding 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 /// 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 /// 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 /// Initializes a new tree transformer.
124 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
126 /// Retrieves a reference to the derived class.
127 Derived &getDerived() { return static_cast<Derived&>(*this); }
129 /// 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 /// Retrieves a reference to the semantic analysis object used for
138 /// this tree transform.
139 Sema &getSema() const { return SemaRef; }
141 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// "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 /// "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 /// Note to the derived class when a function parameter pack is
282 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
284 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
582 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
583 TemplateArgumentLoc &ArgLoc);
585 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// Build a new potentially dependently-sized extended vector type
822 /// given the element type and 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 RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
827 SourceLocation AttributeLoc,
828 VectorType::VectorKind);
830 /// Build a new extended vector type given the element type and
831 /// number of elements.
833 /// By default, performs semantic analysis when building the vector type.
834 /// Subclasses may override this routine to provide different behavior.
835 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
836 SourceLocation AttributeLoc);
838 /// Build a new potentially dependently-sized extended vector type
839 /// given the element type and number of elements.
841 /// By default, performs semantic analysis when building the vector type.
842 /// Subclasses may override this routine to provide different behavior.
843 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
845 SourceLocation AttributeLoc);
847 /// Build a new DependentAddressSpaceType or return the pointee
848 /// type variable with the correct address space (retrieved from
849 /// AddrSpaceExpr) applied to it. The former will be returned in cases
850 /// where the address space remains dependent.
852 /// By default, performs semantic analysis when building the type with address
853 /// space applied. Subclasses may override this routine to provide different
855 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
857 SourceLocation AttributeLoc);
859 /// Build a new function type.
861 /// By default, performs semantic analysis when building the function type.
862 /// Subclasses may override this routine to provide different behavior.
863 QualType RebuildFunctionProtoType(QualType T,
864 MutableArrayRef<QualType> ParamTypes,
865 const FunctionProtoType::ExtProtoInfo &EPI);
867 /// Build a new unprototyped function type.
868 QualType RebuildFunctionNoProtoType(QualType ResultType);
870 /// Rebuild an unresolved typename type, given the decl that
871 /// the UnresolvedUsingTypenameDecl was transformed to.
872 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
874 /// Build a new typedef type.
875 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
876 return SemaRef.Context.getTypeDeclType(Typedef);
879 /// Build a new class/struct/union type.
880 QualType RebuildRecordType(RecordDecl *Record) {
881 return SemaRef.Context.getTypeDeclType(Record);
884 /// Build a new Enum type.
885 QualType RebuildEnumType(EnumDecl *Enum) {
886 return SemaRef.Context.getTypeDeclType(Enum);
889 /// Build a new typeof(expr) type.
891 /// By default, performs semantic analysis when building the typeof type.
892 /// Subclasses may override this routine to provide different behavior.
893 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
895 /// Build a new typeof(type) type.
897 /// By default, builds a new TypeOfType with the given underlying type.
898 QualType RebuildTypeOfType(QualType Underlying);
900 /// Build a new unary transform type.
901 QualType RebuildUnaryTransformType(QualType BaseType,
902 UnaryTransformType::UTTKind UKind,
905 /// Build a new C++11 decltype type.
907 /// By default, performs semantic analysis when building the decltype type.
908 /// Subclasses may override this routine to provide different behavior.
909 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
911 /// Build a new C++11 auto type.
913 /// By default, builds a new AutoType with the given deduced type.
914 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
915 // Note, IsDependent is always false here: we implicitly convert an 'auto'
916 // which has been deduced to a dependent type into an undeduced 'auto', so
917 // that we'll retry deduction after the transformation.
918 return SemaRef.Context.getAutoType(Deduced, Keyword,
919 /*IsDependent*/ false);
922 /// By default, builds a new DeducedTemplateSpecializationType with the given
924 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
926 return SemaRef.Context.getDeducedTemplateSpecializationType(
927 Template, Deduced, /*IsDependent*/ false);
930 /// Build a new template specialization type.
932 /// By default, performs semantic analysis when building the template
933 /// specialization type. Subclasses may override this routine to provide
934 /// different behavior.
935 QualType RebuildTemplateSpecializationType(TemplateName Template,
936 SourceLocation TemplateLoc,
937 TemplateArgumentListInfo &Args);
939 /// Build a new parenthesized type.
941 /// By default, builds a new ParenType type from the inner type.
942 /// Subclasses may override this routine to provide different behavior.
943 QualType RebuildParenType(QualType InnerType) {
944 return SemaRef.BuildParenType(InnerType);
947 /// Build a new qualified name type.
949 /// By default, builds a new ElaboratedType type from the keyword,
950 /// the nested-name-specifier and the named type.
951 /// Subclasses may override this routine to provide different behavior.
952 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
953 ElaboratedTypeKeyword Keyword,
954 NestedNameSpecifierLoc QualifierLoc,
956 return SemaRef.Context.getElaboratedType(Keyword,
957 QualifierLoc.getNestedNameSpecifier(),
961 /// Build a new typename type that refers to a template-id.
963 /// By default, builds a new DependentNameType type from the
964 /// nested-name-specifier and the given type. Subclasses may override
965 /// this routine to provide different behavior.
966 QualType RebuildDependentTemplateSpecializationType(
967 ElaboratedTypeKeyword Keyword,
968 NestedNameSpecifierLoc QualifierLoc,
969 SourceLocation TemplateKWLoc,
970 const IdentifierInfo *Name,
971 SourceLocation NameLoc,
972 TemplateArgumentListInfo &Args,
973 bool AllowInjectedClassName) {
974 // Rebuild the template name.
975 // TODO: avoid TemplateName abstraction
977 SS.Adopt(QualifierLoc);
978 TemplateName InstName = getDerived().RebuildTemplateName(
979 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
980 AllowInjectedClassName);
982 if (InstName.isNull())
985 // If it's still dependent, make a dependent specialization.
986 if (InstName.getAsDependentTemplateName())
987 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
988 QualifierLoc.getNestedNameSpecifier(),
992 // Otherwise, make an elaborated type wrapping a non-dependent
995 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
996 if (T.isNull()) return QualType();
998 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
1001 return SemaRef.Context.getElaboratedType(Keyword,
1002 QualifierLoc.getNestedNameSpecifier(),
1006 /// Build a new typename type that refers to an identifier.
1008 /// By default, performs semantic analysis when building the typename type
1009 /// (or elaborated type). Subclasses may override this routine to provide
1010 /// different behavior.
1011 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
1012 SourceLocation KeywordLoc,
1013 NestedNameSpecifierLoc QualifierLoc,
1014 const IdentifierInfo *Id,
1015 SourceLocation IdLoc,
1016 bool DeducedTSTContext) {
1018 SS.Adopt(QualifierLoc);
1020 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1021 // If the name is still dependent, just build a new dependent name type.
1022 if (!SemaRef.computeDeclContext(SS))
1023 return SemaRef.Context.getDependentNameType(Keyword,
1024 QualifierLoc.getNestedNameSpecifier(),
1028 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1029 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1031 // If a dependent name resolves to a deduced template specialization type,
1032 // check that we're in one of the syntactic contexts permitting it.
1033 if (!DeducedTSTContext) {
1034 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1035 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1036 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1037 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1038 Deduced->getTemplateName())
1039 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1040 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1041 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1048 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1050 // We had a dependent elaborated-type-specifier that has been transformed
1051 // into a non-dependent elaborated-type-specifier. Find the tag we're
1053 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1054 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1058 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1061 TagDecl *Tag = nullptr;
1062 SemaRef.LookupQualifiedName(Result, DC);
1063 switch (Result.getResultKind()) {
1064 case LookupResult::NotFound:
1065 case LookupResult::NotFoundInCurrentInstantiation:
1068 case LookupResult::Found:
1069 Tag = Result.getAsSingle<TagDecl>();
1072 case LookupResult::FoundOverloaded:
1073 case LookupResult::FoundUnresolvedValue:
1074 llvm_unreachable("Tag lookup cannot find non-tags");
1076 case LookupResult::Ambiguous:
1077 // Let the LookupResult structure handle ambiguities.
1082 // Check where the name exists but isn't a tag type and use that to emit
1083 // better diagnostics.
1084 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1085 SemaRef.LookupQualifiedName(Result, DC);
1086 switch (Result.getResultKind()) {
1087 case LookupResult::Found:
1088 case LookupResult::FoundOverloaded:
1089 case LookupResult::FoundUnresolvedValue: {
1090 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1091 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1092 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1094 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1098 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1099 << Kind << Id << DC << QualifierLoc.getSourceRange();
1105 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1107 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1108 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1112 // Build the elaborated-type-specifier type.
1113 QualType T = SemaRef.Context.getTypeDeclType(Tag);
1114 return SemaRef.Context.getElaboratedType(Keyword,
1115 QualifierLoc.getNestedNameSpecifier(),
1119 /// Build a new pack expansion type.
1121 /// By default, builds a new PackExpansionType type from the given pattern.
1122 /// Subclasses may override this routine to provide different behavior.
1123 QualType RebuildPackExpansionType(QualType Pattern,
1124 SourceRange PatternRange,
1125 SourceLocation EllipsisLoc,
1126 Optional<unsigned> NumExpansions) {
1127 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1131 /// Build a new atomic type given its value type.
1133 /// By default, performs semantic analysis when building the atomic type.
1134 /// Subclasses may override this routine to provide different behavior.
1135 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1137 /// Build a new pipe type given its value type.
1138 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1141 /// Build a new template name given a nested name specifier, a flag
1142 /// indicating whether the "template" keyword was provided, and the template
1143 /// that the template name refers to.
1145 /// By default, builds the new template name directly. Subclasses may override
1146 /// this routine to provide different behavior.
1147 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1149 TemplateDecl *Template);
1151 /// Build a new template name given a nested name specifier and the
1152 /// name that is referred to as a template.
1154 /// By default, performs semantic analysis to determine whether the name can
1155 /// be resolved to a specific template, then builds the appropriate kind of
1156 /// template name. Subclasses may override this routine to provide different
1158 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1159 SourceLocation TemplateKWLoc,
1160 const IdentifierInfo &Name,
1161 SourceLocation NameLoc, QualType ObjectType,
1162 NamedDecl *FirstQualifierInScope,
1163 bool AllowInjectedClassName);
1165 /// Build a new template name given a nested name specifier and the
1166 /// overloaded operator name that is referred to as a template.
1168 /// By default, performs semantic analysis to determine whether the name can
1169 /// be resolved to a specific template, then builds the appropriate kind of
1170 /// template name. Subclasses may override this routine to provide different
1172 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1173 SourceLocation TemplateKWLoc,
1174 OverloadedOperatorKind Operator,
1175 SourceLocation NameLoc, QualType ObjectType,
1176 bool AllowInjectedClassName);
1178 /// Build a new template name given a template template parameter pack
1181 /// By default, performs semantic analysis to determine whether the name can
1182 /// be resolved to a specific template, then builds the appropriate kind of
1183 /// template name. Subclasses may override this routine to provide different
1185 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1186 const TemplateArgument &ArgPack) {
1187 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1190 /// Build a new compound statement.
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
1194 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1195 MultiStmtArg Statements,
1196 SourceLocation RBraceLoc,
1198 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1202 /// Build a new case statement.
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
1206 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1208 SourceLocation EllipsisLoc,
1210 SourceLocation ColonLoc) {
1211 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1215 /// Attach the body to a new case statement.
1217 /// By default, performs semantic analysis to build the new statement.
1218 /// Subclasses may override this routine to provide different behavior.
1219 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1220 getSema().ActOnCaseStmtBody(S, Body);
1224 /// Build a new default statement.
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
1228 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1229 SourceLocation ColonLoc,
1231 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1232 /*CurScope=*/nullptr);
1235 /// Build a new label statement.
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
1239 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1240 SourceLocation ColonLoc, Stmt *SubStmt) {
1241 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1244 /// Build a new label statement.
1246 /// By default, performs semantic analysis to build the new statement.
1247 /// Subclasses may override this routine to provide different behavior.
1248 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1249 ArrayRef<const Attr*> Attrs,
1251 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1254 /// Build a new "if" statement.
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
1258 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1259 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
1260 SourceLocation ElseLoc, Stmt *Else) {
1261 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
1265 /// Start building a new switch statement.
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
1269 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
1270 Sema::ConditionResult Cond) {
1271 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
1274 /// Attach the body to the switch statement.
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
1278 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1279 Stmt *Switch, Stmt *Body) {
1280 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1283 /// Build a new while statement.
1285 /// By default, performs semantic analysis to build the new statement.
1286 /// Subclasses may override this routine to provide different behavior.
1287 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1288 Sema::ConditionResult Cond, Stmt *Body) {
1289 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
1292 /// Build a new do-while statement.
1294 /// By default, performs semantic analysis to build the new statement.
1295 /// Subclasses may override this routine to provide different behavior.
1296 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1297 SourceLocation WhileLoc, SourceLocation LParenLoc,
1298 Expr *Cond, SourceLocation RParenLoc) {
1299 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1303 /// Build a new for statement.
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1308 Stmt *Init, Sema::ConditionResult Cond,
1309 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1311 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1312 Inc, RParenLoc, Body);
1315 /// Build a new goto statement.
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
1319 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1321 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1324 /// Build a new indirect goto statement.
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
1328 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1329 SourceLocation StarLoc,
1331 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1334 /// Build a new return statement.
1336 /// By default, performs semantic analysis to build the new statement.
1337 /// Subclasses may override this routine to provide different behavior.
1338 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1339 return getSema().BuildReturnStmt(ReturnLoc, Result);
1342 /// Build a new declaration statement.
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
1346 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
1347 SourceLocation StartLoc, SourceLocation EndLoc) {
1348 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1349 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1352 /// Build a new inline asm statement.
1354 /// By default, performs semantic analysis to build the new statement.
1355 /// Subclasses may override this routine to provide different behavior.
1356 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1357 bool IsVolatile, unsigned NumOutputs,
1358 unsigned NumInputs, IdentifierInfo **Names,
1359 MultiExprArg Constraints, MultiExprArg Exprs,
1360 Expr *AsmString, MultiExprArg Clobbers,
1361 SourceLocation RParenLoc) {
1362 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1363 NumInputs, Names, Constraints, Exprs,
1364 AsmString, Clobbers, RParenLoc);
1367 /// Build a new MS style inline asm statement.
1369 /// By default, performs semantic analysis to build the new statement.
1370 /// Subclasses may override this routine to provide different behavior.
1371 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1372 ArrayRef<Token> AsmToks,
1373 StringRef AsmString,
1374 unsigned NumOutputs, unsigned NumInputs,
1375 ArrayRef<StringRef> Constraints,
1376 ArrayRef<StringRef> Clobbers,
1377 ArrayRef<Expr*> Exprs,
1378 SourceLocation EndLoc) {
1379 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1380 NumOutputs, NumInputs,
1381 Constraints, Clobbers, Exprs, EndLoc);
1384 /// Build a new co_return statement.
1386 /// By default, performs semantic analysis to build the new statement.
1387 /// Subclasses may override this routine to provide different behavior.
1388 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1390 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1393 /// Build a new co_await expression.
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
1397 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1399 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1402 /// Build a new co_await expression.
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
1406 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1408 UnresolvedLookupExpr *Lookup) {
1409 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1412 /// Build a new co_yield expression.
1414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
1416 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1417 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1420 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1421 return getSema().BuildCoroutineBodyStmt(Args);
1424 /// Build a new Objective-C \@try statement.
1426 /// By default, performs semantic analysis to build the new statement.
1427 /// Subclasses may override this routine to provide different behavior.
1428 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1430 MultiStmtArg CatchStmts,
1432 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1436 /// Rebuild an Objective-C exception declaration.
1438 /// By default, performs semantic analysis to build the new declaration.
1439 /// Subclasses may override this routine to provide different behavior.
1440 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1441 TypeSourceInfo *TInfo, QualType T) {
1442 return getSema().BuildObjCExceptionDecl(TInfo, T,
1443 ExceptionDecl->getInnerLocStart(),
1444 ExceptionDecl->getLocation(),
1445 ExceptionDecl->getIdentifier());
1448 /// Build a new Objective-C \@catch statement.
1450 /// By default, performs semantic analysis to build the new statement.
1451 /// Subclasses may override this routine to provide different behavior.
1452 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1453 SourceLocation RParenLoc,
1456 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1460 /// Build a new Objective-C \@finally statement.
1462 /// By default, performs semantic analysis to build the new statement.
1463 /// Subclasses may override this routine to provide different behavior.
1464 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1466 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1469 /// Build a new Objective-C \@throw statement.
1471 /// By default, performs semantic analysis to build the new statement.
1472 /// Subclasses may override this routine to provide different behavior.
1473 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1475 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1478 /// Build a new OpenMP executable directive.
1480 /// By default, performs semantic analysis to build the new statement.
1481 /// Subclasses may override this routine to provide different behavior.
1482 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1483 DeclarationNameInfo DirName,
1484 OpenMPDirectiveKind CancelRegion,
1485 ArrayRef<OMPClause *> Clauses,
1486 Stmt *AStmt, SourceLocation StartLoc,
1487 SourceLocation EndLoc) {
1488 return getSema().ActOnOpenMPExecutableDirective(
1489 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1492 /// Build a new OpenMP 'if' clause.
1494 /// By default, performs semantic analysis to build the new OpenMP clause.
1495 /// Subclasses may override this routine to provide different behavior.
1496 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1497 Expr *Condition, SourceLocation StartLoc,
1498 SourceLocation LParenLoc,
1499 SourceLocation NameModifierLoc,
1500 SourceLocation ColonLoc,
1501 SourceLocation EndLoc) {
1502 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1503 LParenLoc, NameModifierLoc, ColonLoc,
1507 /// Build a new OpenMP 'final' clause.
1509 /// By default, performs semantic analysis to build the new OpenMP clause.
1510 /// Subclasses may override this routine to provide different behavior.
1511 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1512 SourceLocation LParenLoc,
1513 SourceLocation EndLoc) {
1514 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1518 /// Build a new OpenMP 'num_threads' 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 *RebuildOMPNumThreadsClause(Expr *NumThreads,
1523 SourceLocation StartLoc,
1524 SourceLocation LParenLoc,
1525 SourceLocation EndLoc) {
1526 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1530 /// Build a new OpenMP 'safelen' clause.
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1535 SourceLocation LParenLoc,
1536 SourceLocation EndLoc) {
1537 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1540 /// Build a new OpenMP 'simdlen' clause.
1542 /// By default, performs semantic analysis to build the new OpenMP clause.
1543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1545 SourceLocation LParenLoc,
1546 SourceLocation EndLoc) {
1547 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1550 /// Build a new OpenMP 'collapse' clause.
1552 /// By default, performs semantic analysis to build the new OpenMP clause.
1553 /// Subclasses may override this routine to provide different behavior.
1554 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1555 SourceLocation LParenLoc,
1556 SourceLocation EndLoc) {
1557 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1561 /// Build a new OpenMP 'default' clause.
1563 /// By default, performs semantic analysis to build the new OpenMP clause.
1564 /// Subclasses may override this routine to provide different behavior.
1565 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1566 SourceLocation KindKwLoc,
1567 SourceLocation StartLoc,
1568 SourceLocation LParenLoc,
1569 SourceLocation EndLoc) {
1570 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1571 StartLoc, LParenLoc, EndLoc);
1574 /// Build a new OpenMP 'proc_bind' clause.
1576 /// By default, performs semantic analysis to build the new OpenMP clause.
1577 /// Subclasses may override this routine to provide different behavior.
1578 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1579 SourceLocation KindKwLoc,
1580 SourceLocation StartLoc,
1581 SourceLocation LParenLoc,
1582 SourceLocation EndLoc) {
1583 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1584 StartLoc, LParenLoc, EndLoc);
1587 /// Build a new OpenMP 'schedule' clause.
1589 /// By default, performs semantic analysis to build the new OpenMP clause.
1590 /// Subclasses may override this routine to provide different behavior.
1591 OMPClause *RebuildOMPScheduleClause(
1592 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1593 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1594 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1595 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1596 return getSema().ActOnOpenMPScheduleClause(
1597 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1601 /// Build a new OpenMP 'ordered' 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 *RebuildOMPOrderedClause(SourceLocation StartLoc,
1606 SourceLocation EndLoc,
1607 SourceLocation LParenLoc, Expr *Num) {
1608 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1611 /// Build a new OpenMP 'private' clause.
1613 /// By default, performs semantic analysis to build the new OpenMP clause.
1614 /// Subclasses may override this routine to provide different behavior.
1615 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1616 SourceLocation StartLoc,
1617 SourceLocation LParenLoc,
1618 SourceLocation EndLoc) {
1619 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1623 /// Build a new OpenMP 'firstprivate' clause.
1625 /// By default, performs semantic analysis to build the new OpenMP clause.
1626 /// Subclasses may override this routine to provide different behavior.
1627 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1628 SourceLocation StartLoc,
1629 SourceLocation LParenLoc,
1630 SourceLocation EndLoc) {
1631 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1635 /// Build a new OpenMP 'lastprivate' clause.
1637 /// By default, performs semantic analysis to build the new OpenMP clause.
1638 /// Subclasses may override this routine to provide different behavior.
1639 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1640 SourceLocation StartLoc,
1641 SourceLocation LParenLoc,
1642 SourceLocation EndLoc) {
1643 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1647 /// Build a new OpenMP 'shared' clause.
1649 /// By default, performs semantic analysis to build the new OpenMP clause.
1650 /// Subclasses may override this routine to provide different behavior.
1651 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1652 SourceLocation StartLoc,
1653 SourceLocation LParenLoc,
1654 SourceLocation EndLoc) {
1655 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1659 /// Build a new OpenMP 'reduction' clause.
1661 /// By default, performs semantic analysis to build the new statement.
1662 /// Subclasses may override this routine to provide different behavior.
1663 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1664 SourceLocation StartLoc,
1665 SourceLocation LParenLoc,
1666 SourceLocation ColonLoc,
1667 SourceLocation EndLoc,
1668 CXXScopeSpec &ReductionIdScopeSpec,
1669 const DeclarationNameInfo &ReductionId,
1670 ArrayRef<Expr *> UnresolvedReductions) {
1671 return getSema().ActOnOpenMPReductionClause(
1672 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1673 ReductionId, UnresolvedReductions);
1676 /// Build a new OpenMP 'task_reduction' clause.
1678 /// By default, performs semantic analysis to build the new statement.
1679 /// Subclasses may override this routine to provide different behavior.
1680 OMPClause *RebuildOMPTaskReductionClause(
1681 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1682 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1683 CXXScopeSpec &ReductionIdScopeSpec,
1684 const DeclarationNameInfo &ReductionId,
1685 ArrayRef<Expr *> UnresolvedReductions) {
1686 return getSema().ActOnOpenMPTaskReductionClause(
1687 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1688 ReductionId, UnresolvedReductions);
1691 /// Build a new OpenMP 'in_reduction' clause.
1693 /// By default, performs semantic analysis to build the new statement.
1694 /// Subclasses may override this routine to provide different behavior.
1696 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1697 SourceLocation LParenLoc, SourceLocation ColonLoc,
1698 SourceLocation EndLoc,
1699 CXXScopeSpec &ReductionIdScopeSpec,
1700 const DeclarationNameInfo &ReductionId,
1701 ArrayRef<Expr *> UnresolvedReductions) {
1702 return getSema().ActOnOpenMPInReductionClause(
1703 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1704 ReductionId, UnresolvedReductions);
1707 /// Build a new OpenMP 'linear' clause.
1709 /// By default, performs semantic analysis to build the new OpenMP clause.
1710 /// Subclasses may override this routine to provide different behavior.
1711 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1712 SourceLocation StartLoc,
1713 SourceLocation LParenLoc,
1714 OpenMPLinearClauseKind Modifier,
1715 SourceLocation ModifierLoc,
1716 SourceLocation ColonLoc,
1717 SourceLocation EndLoc) {
1718 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1719 Modifier, ModifierLoc, ColonLoc,
1723 /// Build a new OpenMP 'aligned' clause.
1725 /// By default, performs semantic analysis to build the new OpenMP clause.
1726 /// Subclasses may override this routine to provide different behavior.
1727 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1728 SourceLocation StartLoc,
1729 SourceLocation LParenLoc,
1730 SourceLocation ColonLoc,
1731 SourceLocation EndLoc) {
1732 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1733 LParenLoc, ColonLoc, EndLoc);
1736 /// Build a new OpenMP 'copyin' clause.
1738 /// By default, performs semantic analysis to build the new OpenMP clause.
1739 /// Subclasses may override this routine to provide different behavior.
1740 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1741 SourceLocation StartLoc,
1742 SourceLocation LParenLoc,
1743 SourceLocation EndLoc) {
1744 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1748 /// Build a new OpenMP 'copyprivate' clause.
1750 /// By default, performs semantic analysis to build the new OpenMP clause.
1751 /// Subclasses may override this routine to provide different behavior.
1752 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1753 SourceLocation StartLoc,
1754 SourceLocation LParenLoc,
1755 SourceLocation EndLoc) {
1756 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1760 /// Build a new OpenMP 'flush' pseudo clause.
1762 /// By default, performs semantic analysis to build the new OpenMP clause.
1763 /// Subclasses may override this routine to provide different behavior.
1764 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1772 /// Build a new OpenMP 'depend' pseudo clause.
1774 /// By default, performs semantic analysis to build the new OpenMP clause.
1775 /// Subclasses may override this routine to provide different behavior.
1777 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1778 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1779 SourceLocation StartLoc, SourceLocation LParenLoc,
1780 SourceLocation EndLoc) {
1781 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1782 StartLoc, LParenLoc, EndLoc);
1785 /// Build a new OpenMP 'device' clause.
1787 /// By default, performs semantic analysis to build the new statement.
1788 /// Subclasses may override this routine to provide different behavior.
1789 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1790 SourceLocation LParenLoc,
1791 SourceLocation EndLoc) {
1792 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1796 /// Build a new OpenMP 'map' clause.
1798 /// By default, performs semantic analysis to build the new OpenMP clause.
1799 /// Subclasses may override this routine to provide different behavior.
1801 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1802 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1803 SourceLocation MapLoc, SourceLocation ColonLoc,
1804 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1805 SourceLocation LParenLoc, SourceLocation EndLoc) {
1806 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1807 IsMapTypeImplicit, MapLoc, ColonLoc,
1808 VarList, StartLoc, LParenLoc, EndLoc);
1811 /// Build a new OpenMP 'num_teams' clause.
1813 /// By default, performs semantic analysis to build the new statement.
1814 /// Subclasses may override this routine to provide different behavior.
1815 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1816 SourceLocation LParenLoc,
1817 SourceLocation EndLoc) {
1818 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1822 /// Build a new OpenMP 'thread_limit' clause.
1824 /// By default, performs semantic analysis to build the new statement.
1825 /// Subclasses may override this routine to provide different behavior.
1826 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1827 SourceLocation StartLoc,
1828 SourceLocation LParenLoc,
1829 SourceLocation EndLoc) {
1830 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1834 /// Build a new OpenMP 'priority' clause.
1836 /// By default, performs semantic analysis to build the new statement.
1837 /// Subclasses may override this routine to provide different behavior.
1838 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1839 SourceLocation LParenLoc,
1840 SourceLocation EndLoc) {
1841 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1845 /// Build a new OpenMP 'grainsize' clause.
1847 /// By default, performs semantic analysis to build the new statement.
1848 /// Subclasses may override this routine to provide different behavior.
1849 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1850 SourceLocation LParenLoc,
1851 SourceLocation EndLoc) {
1852 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1856 /// Build a new OpenMP 'num_tasks' clause.
1858 /// By default, performs semantic analysis to build the new statement.
1859 /// Subclasses may override this routine to provide different behavior.
1860 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1861 SourceLocation LParenLoc,
1862 SourceLocation EndLoc) {
1863 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1867 /// Build a new OpenMP 'hint' clause.
1869 /// By default, performs semantic analysis to build the new statement.
1870 /// Subclasses may override this routine to provide different behavior.
1871 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1872 SourceLocation LParenLoc,
1873 SourceLocation EndLoc) {
1874 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1877 /// Build a new OpenMP 'dist_schedule' clause.
1879 /// By default, performs semantic analysis to build the new OpenMP clause.
1880 /// Subclasses may override this routine to provide different behavior.
1882 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1883 Expr *ChunkSize, SourceLocation StartLoc,
1884 SourceLocation LParenLoc, SourceLocation KindLoc,
1885 SourceLocation CommaLoc, SourceLocation EndLoc) {
1886 return getSema().ActOnOpenMPDistScheduleClause(
1887 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1890 /// Build a new OpenMP 'to' clause.
1892 /// By default, performs semantic analysis to build the new statement.
1893 /// Subclasses may override this routine to provide different behavior.
1894 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1895 SourceLocation StartLoc,
1896 SourceLocation LParenLoc,
1897 SourceLocation EndLoc) {
1898 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1901 /// Build a new OpenMP 'from' clause.
1903 /// By default, performs semantic analysis to build the new statement.
1904 /// Subclasses may override this routine to provide different behavior.
1905 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1906 SourceLocation StartLoc,
1907 SourceLocation LParenLoc,
1908 SourceLocation EndLoc) {
1909 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1913 /// Build a new OpenMP 'use_device_ptr' clause.
1915 /// By default, performs semantic analysis to build the new OpenMP clause.
1916 /// Subclasses may override this routine to provide different behavior.
1917 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1918 SourceLocation StartLoc,
1919 SourceLocation LParenLoc,
1920 SourceLocation EndLoc) {
1921 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1925 /// Build a new OpenMP 'is_device_ptr' clause.
1927 /// By default, performs semantic analysis to build the new OpenMP clause.
1928 /// Subclasses may override this routine to provide different behavior.
1929 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1930 SourceLocation StartLoc,
1931 SourceLocation LParenLoc,
1932 SourceLocation EndLoc) {
1933 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1937 /// Rebuild the operand to an Objective-C \@synchronized statement.
1939 /// By default, performs semantic analysis to build the new statement.
1940 /// Subclasses may override this routine to provide different behavior.
1941 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1943 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1946 /// Build a new Objective-C \@synchronized statement.
1948 /// By default, performs semantic analysis to build the new statement.
1949 /// Subclasses may override this routine to provide different behavior.
1950 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1951 Expr *Object, Stmt *Body) {
1952 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1955 /// Build a new Objective-C \@autoreleasepool statement.
1957 /// By default, performs semantic analysis to build the new statement.
1958 /// Subclasses may override this routine to provide different behavior.
1959 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1961 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1964 /// Build a new Objective-C fast enumeration statement.
1966 /// By default, performs semantic analysis to build the new statement.
1967 /// Subclasses may override this routine to provide different behavior.
1968 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1971 SourceLocation RParenLoc,
1973 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1977 if (ForEachStmt.isInvalid())
1980 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1983 /// Build a new C++ exception declaration.
1985 /// By default, performs semantic analysis to build the new decaration.
1986 /// Subclasses may override this routine to provide different behavior.
1987 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1988 TypeSourceInfo *Declarator,
1989 SourceLocation StartLoc,
1990 SourceLocation IdLoc,
1991 IdentifierInfo *Id) {
1992 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1993 StartLoc, IdLoc, Id);
1995 getSema().CurContext->addDecl(Var);
1999 /// Build a new C++ catch statement.
2001 /// By default, performs semantic analysis to build the new statement.
2002 /// Subclasses may override this routine to provide different behavior.
2003 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
2004 VarDecl *ExceptionDecl,
2006 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2010 /// Build a new C++ try statement.
2012 /// By default, performs semantic analysis to build the new statement.
2013 /// Subclasses may override this routine to provide different behavior.
2014 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2015 ArrayRef<Stmt *> Handlers) {
2016 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2019 /// Build a new C++0x range-based for statement.
2021 /// By default, performs semantic analysis to build the new statement.
2022 /// Subclasses may override this routine to provide different behavior.
2023 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
2024 SourceLocation CoawaitLoc,
2025 SourceLocation ColonLoc,
2026 Stmt *Range, Stmt *Begin, Stmt *End,
2027 Expr *Cond, Expr *Inc,
2029 SourceLocation RParenLoc) {
2030 // If we've just learned that the range is actually an Objective-C
2031 // collection, treat this as an Objective-C fast enumeration loop.
2032 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2033 if (RangeStmt->isSingleDecl()) {
2034 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2035 if (RangeVar->isInvalidDecl())
2038 Expr *RangeExpr = RangeVar->getInit();
2039 if (!RangeExpr->isTypeDependent() &&
2040 RangeExpr->getType()->isObjCObjectPointerType())
2041 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2047 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
2049 Cond, Inc, LoopVar, RParenLoc,
2050 Sema::BFRK_Rebuild);
2053 /// Build a new C++0x range-based for statement.
2055 /// By default, performs semantic analysis to build the new statement.
2056 /// Subclasses may override this routine to provide different behavior.
2057 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
2059 NestedNameSpecifierLoc QualifierLoc,
2060 DeclarationNameInfo NameInfo,
2062 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2063 QualifierLoc, NameInfo, Nested);
2066 /// Attach body to a C++0x range-based for statement.
2068 /// By default, performs semantic analysis to finish the new statement.
2069 /// Subclasses may override this routine to provide different behavior.
2070 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2071 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2074 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
2075 Stmt *TryBlock, Stmt *Handler) {
2076 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2079 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
2081 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2084 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
2085 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2088 /// Build a new predefined expression.
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
2092 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2093 PredefinedExpr::IdentType IT) {
2094 return getSema().BuildPredefinedExpr(Loc, IT);
2097 /// Build a new expression that references a declaration.
2099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
2101 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
2104 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2108 /// Build a new expression that references a declaration.
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
2112 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
2114 const DeclarationNameInfo &NameInfo,
2115 TemplateArgumentListInfo *TemplateArgs) {
2117 SS.Adopt(QualifierLoc);
2119 // FIXME: loses template args.
2121 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
2124 /// Build a new expression in parentheses.
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
2128 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
2129 SourceLocation RParen) {
2130 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2133 /// Build a new pseudo-destructor expression.
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
2137 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2138 SourceLocation OperatorLoc,
2141 TypeSourceInfo *ScopeType,
2142 SourceLocation CCLoc,
2143 SourceLocation TildeLoc,
2144 PseudoDestructorTypeStorage Destroyed);
2146 /// Build a new unary operator expression.
2148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
2150 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
2151 UnaryOperatorKind Opc,
2153 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2156 /// Build a new builtin offsetof expression.
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
2160 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
2161 TypeSourceInfo *Type,
2162 ArrayRef<Sema::OffsetOfComponent> Components,
2163 SourceLocation RParenLoc) {
2164 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2168 /// Build a new sizeof, alignof or vec_step expression with a
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
2173 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2174 SourceLocation OpLoc,
2175 UnaryExprOrTypeTrait ExprKind,
2177 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2180 /// Build a new sizeof, alignof or vec step expression with an
2181 /// expression argument.
2183 /// By default, performs semantic analysis to build the new expression.
2184 /// Subclasses may override this routine to provide different behavior.
2185 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2186 UnaryExprOrTypeTrait ExprKind,
2189 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2190 if (Result.isInvalid())
2196 /// Build a new array subscript expression.
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
2200 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
2201 SourceLocation LBracketLoc,
2203 SourceLocation RBracketLoc) {
2204 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2209 /// Build a new array section expression.
2211 /// By default, performs semantic analysis to build the new expression.
2212 /// Subclasses may override this routine to provide different behavior.
2213 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2215 SourceLocation ColonLoc, Expr *Length,
2216 SourceLocation RBracketLoc) {
2217 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2218 ColonLoc, Length, RBracketLoc);
2221 /// Build a new call expression.
2223 /// By default, performs semantic analysis to build the new expression.
2224 /// Subclasses may override this routine to provide different behavior.
2225 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
2227 SourceLocation RParenLoc,
2228 Expr *ExecConfig = nullptr) {
2229 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
2230 Args, RParenLoc, ExecConfig);
2233 /// Build a new member access expression.
2235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
2237 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
2239 NestedNameSpecifierLoc QualifierLoc,
2240 SourceLocation TemplateKWLoc,
2241 const DeclarationNameInfo &MemberNameInfo,
2243 NamedDecl *FoundDecl,
2244 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2245 NamedDecl *FirstQualifierInScope) {
2246 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2248 if (!Member->getDeclName()) {
2249 // We have a reference to an unnamed field. This is always the
2250 // base of an anonymous struct/union member access, i.e. the
2251 // field is always of record type.
2252 assert(Member->getType()->isRecordType() &&
2253 "unnamed member not of record type?");
2256 getSema().PerformObjectMemberConversion(BaseResult.get(),
2257 QualifierLoc.getNestedNameSpecifier(),
2259 if (BaseResult.isInvalid())
2261 Base = BaseResult.get();
2263 CXXScopeSpec EmptySS;
2264 return getSema().BuildFieldReferenceExpr(
2265 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2266 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
2270 SS.Adopt(QualifierLoc);
2272 Base = BaseResult.get();
2273 QualType BaseType = Base->getType();
2275 if (isArrow && !BaseType->isPointerType())
2278 // FIXME: this involves duplicating earlier analysis in a lot of
2279 // cases; we should avoid this when possible.
2280 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2281 R.addDecl(FoundDecl);
2284 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2286 FirstQualifierInScope,
2287 R, ExplicitTemplateArgs,
2291 /// Build a new binary operator expression.
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
2295 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
2296 BinaryOperatorKind Opc,
2297 Expr *LHS, Expr *RHS) {
2298 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2301 /// Build a new conditional operator expression.
2303 /// By default, performs semantic analysis to build the new expression.
2304 /// Subclasses may override this routine to provide different behavior.
2305 ExprResult RebuildConditionalOperator(Expr *Cond,
2306 SourceLocation QuestionLoc,
2308 SourceLocation ColonLoc,
2310 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2314 /// Build a new C-style cast expression.
2316 /// By default, performs semantic analysis to build the new expression.
2317 /// Subclasses may override this routine to provide different behavior.
2318 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
2319 TypeSourceInfo *TInfo,
2320 SourceLocation RParenLoc,
2322 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2326 /// Build a new compound literal expression.
2328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
2330 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
2331 TypeSourceInfo *TInfo,
2332 SourceLocation RParenLoc,
2334 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2338 /// Build a new extended vector element access expression.
2340 /// By default, performs semantic analysis to build the new expression.
2341 /// Subclasses may override this routine to provide different behavior.
2342 ExprResult RebuildExtVectorElementExpr(Expr *Base,
2343 SourceLocation OpLoc,
2344 SourceLocation AccessorLoc,
2345 IdentifierInfo &Accessor) {
2348 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2349 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2350 OpLoc, /*IsArrow*/ false,
2351 SS, SourceLocation(),
2352 /*FirstQualifierInScope*/ nullptr,
2354 /* TemplateArgs */ nullptr,
2358 /// Build a new initializer list expression.
2360 /// By default, performs semantic analysis to build the new expression.
2361 /// Subclasses may override this routine to provide different behavior.
2362 ExprResult RebuildInitList(SourceLocation LBraceLoc,
2364 SourceLocation RBraceLoc) {
2365 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2368 /// Build a new designated initializer expression.
2370 /// By default, performs semantic analysis to build the new expression.
2371 /// Subclasses may override this routine to provide different behavior.
2372 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
2373 MultiExprArg ArrayExprs,
2374 SourceLocation EqualOrColonLoc,
2378 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2380 if (Result.isInvalid())
2386 /// Build a new value-initialized expression.
2388 /// By default, builds the implicit value initialization without performing
2389 /// any semantic analysis. Subclasses may override this routine to provide
2390 /// different behavior.
2391 ExprResult RebuildImplicitValueInitExpr(QualType T) {
2392 return new (SemaRef.Context) ImplicitValueInitExpr(T);
2395 /// Build a new \c va_arg expression.
2397 /// By default, performs semantic analysis to build the new expression.
2398 /// Subclasses may override this routine to provide different behavior.
2399 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
2400 Expr *SubExpr, TypeSourceInfo *TInfo,
2401 SourceLocation RParenLoc) {
2402 return getSema().BuildVAArgExpr(BuiltinLoc,
2407 /// Build a new expression list in parentheses.
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
2411 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
2412 MultiExprArg SubExprs,
2413 SourceLocation RParenLoc) {
2414 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2417 /// Build a new address-of-label expression.
2419 /// By default, performs semantic analysis, using the name of the label
2420 /// rather than attempting to map the label statement itself.
2421 /// Subclasses may override this routine to provide different behavior.
2422 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
2423 SourceLocation LabelLoc, LabelDecl *Label) {
2424 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2427 /// Build a new GNU statement expression.
2429 /// By default, performs semantic analysis to build the new expression.
2430 /// Subclasses may override this routine to provide different behavior.
2431 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
2433 SourceLocation RParenLoc) {
2434 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2437 /// Build a new __builtin_choose_expr expression.
2439 /// By default, performs semantic analysis to build the new expression.
2440 /// Subclasses may override this routine to provide different behavior.
2441 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
2442 Expr *Cond, Expr *LHS, Expr *RHS,
2443 SourceLocation RParenLoc) {
2444 return SemaRef.ActOnChooseExpr(BuiltinLoc,
2449 /// Build a new generic selection expression.
2451 /// By default, performs semantic analysis to build the new expression.
2452 /// Subclasses may override this routine to provide different behavior.
2453 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2454 SourceLocation DefaultLoc,
2455 SourceLocation RParenLoc,
2456 Expr *ControllingExpr,
2457 ArrayRef<TypeSourceInfo *> Types,
2458 ArrayRef<Expr *> Exprs) {
2459 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2460 ControllingExpr, Types, Exprs);
2463 /// Build a new overloaded operator call expression.
2465 /// By default, performs semantic analysis to build the new expression.
2466 /// The semantic analysis provides the behavior of template instantiation,
2467 /// copying with transformations that turn what looks like an overloaded
2468 /// operator call into a use of a builtin operator, performing
2469 /// argument-dependent lookup, etc. Subclasses may override this routine to
2470 /// provide different behavior.
2471 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2472 SourceLocation OpLoc,
2477 /// Build a new C++ "named" cast expression, such as static_cast or
2478 /// reinterpret_cast.
2480 /// By default, this routine dispatches to one of the more-specific routines
2481 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
2484 Stmt::StmtClass Class,
2485 SourceLocation LAngleLoc,
2486 TypeSourceInfo *TInfo,
2487 SourceLocation RAngleLoc,
2488 SourceLocation LParenLoc,
2490 SourceLocation RParenLoc) {
2492 case Stmt::CXXStaticCastExprClass:
2493 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2494 RAngleLoc, LParenLoc,
2495 SubExpr, RParenLoc);
2497 case Stmt::CXXDynamicCastExprClass:
2498 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2499 RAngleLoc, LParenLoc,
2500 SubExpr, RParenLoc);
2502 case Stmt::CXXReinterpretCastExprClass:
2503 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2504 RAngleLoc, LParenLoc,
2508 case Stmt::CXXConstCastExprClass:
2509 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2510 RAngleLoc, LParenLoc,
2511 SubExpr, RParenLoc);
2514 llvm_unreachable("Invalid C++ named cast");
2518 /// Build a new C++ static_cast expression.
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// Subclasses may override this routine to provide different behavior.
2522 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
2523 SourceLocation LAngleLoc,
2524 TypeSourceInfo *TInfo,
2525 SourceLocation RAngleLoc,
2526 SourceLocation LParenLoc,
2528 SourceLocation RParenLoc) {
2529 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2531 SourceRange(LAngleLoc, RAngleLoc),
2532 SourceRange(LParenLoc, RParenLoc));
2535 /// Build a new C++ dynamic_cast expression.
2537 /// By default, performs semantic analysis to build the new expression.
2538 /// Subclasses may override this routine to provide different behavior.
2539 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
2540 SourceLocation LAngleLoc,
2541 TypeSourceInfo *TInfo,
2542 SourceLocation RAngleLoc,
2543 SourceLocation LParenLoc,
2545 SourceLocation RParenLoc) {
2546 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2548 SourceRange(LAngleLoc, RAngleLoc),
2549 SourceRange(LParenLoc, RParenLoc));
2552 /// Build a new C++ reinterpret_cast expression.
2554 /// By default, performs semantic analysis to build the new expression.
2555 /// Subclasses may override this routine to provide different behavior.
2556 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
2557 SourceLocation LAngleLoc,
2558 TypeSourceInfo *TInfo,
2559 SourceLocation RAngleLoc,
2560 SourceLocation LParenLoc,
2562 SourceLocation RParenLoc) {
2563 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2565 SourceRange(LAngleLoc, RAngleLoc),
2566 SourceRange(LParenLoc, RParenLoc));
2569 /// Build a new C++ const_cast expression.
2571 /// By default, performs semantic analysis to build the new expression.
2572 /// Subclasses may override this routine to provide different behavior.
2573 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
2574 SourceLocation LAngleLoc,
2575 TypeSourceInfo *TInfo,
2576 SourceLocation RAngleLoc,
2577 SourceLocation LParenLoc,
2579 SourceLocation RParenLoc) {
2580 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2582 SourceRange(LAngleLoc, RAngleLoc),
2583 SourceRange(LParenLoc, RParenLoc));
2586 /// Build a new C++ functional-style cast expression.
2588 /// By default, performs semantic analysis to build the new expression.
2589 /// Subclasses may override this routine to provide different behavior.
2590 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2591 SourceLocation LParenLoc,
2593 SourceLocation RParenLoc,
2594 bool ListInitialization) {
2595 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2596 MultiExprArg(&Sub, 1), RParenLoc,
2597 ListInitialization);
2600 /// Build a new C++ typeid(type) expression.
2602 /// By default, performs semantic analysis to build the new expression.
2603 /// Subclasses may override this routine to provide different behavior.
2604 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2605 SourceLocation TypeidLoc,
2606 TypeSourceInfo *Operand,
2607 SourceLocation RParenLoc) {
2608 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2613 /// Build a new C++ typeid(expr) expression.
2615 /// By default, performs semantic analysis to build the new expression.
2616 /// Subclasses may override this routine to provide different behavior.
2617 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2618 SourceLocation TypeidLoc,
2620 SourceLocation RParenLoc) {
2621 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2625 /// Build a new C++ __uuidof(type) expression.
2627 /// By default, performs semantic analysis to build the new expression.
2628 /// Subclasses may override this routine to provide different behavior.
2629 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2630 SourceLocation TypeidLoc,
2631 TypeSourceInfo *Operand,
2632 SourceLocation RParenLoc) {
2633 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2637 /// Build a new C++ __uuidof(expr) expression.
2639 /// By default, performs semantic analysis to build the new expression.
2640 /// Subclasses may override this routine to provide different behavior.
2641 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2642 SourceLocation TypeidLoc,
2644 SourceLocation RParenLoc) {
2645 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2649 /// Build a new C++ "this" expression.
2651 /// By default, builds a new "this" expression without performing any
2652 /// semantic analysis. Subclasses may override this routine to provide
2653 /// different behavior.
2654 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
2657 getSema().CheckCXXThisCapture(ThisLoc);
2658 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2661 /// Build a new C++ throw expression.
2663 /// By default, performs semantic analysis to build the new expression.
2664 /// Subclasses may override this routine to provide different behavior.
2665 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2666 bool IsThrownVariableInScope) {
2667 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2670 /// Build a new C++ default-argument expression.
2672 /// By default, builds a new default-argument expression, which does not
2673 /// require any semantic analysis. Subclasses may override this routine to
2674 /// provide different behavior.
2675 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
2676 ParmVarDecl *Param) {
2677 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2680 /// Build a new C++11 default-initialization expression.
2682 /// By default, builds a new default field initialization expression, which
2683 /// does not require any semantic analysis. Subclasses may override this
2684 /// routine to provide different behavior.
2685 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2687 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2690 /// Build a new C++ zero-initialization expression.
2692 /// By default, performs semantic analysis to build the new expression.
2693 /// Subclasses may override this routine to provide different behavior.
2694 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2695 SourceLocation LParenLoc,
2696 SourceLocation RParenLoc) {
2697 return getSema().BuildCXXTypeConstructExpr(
2698 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
2701 /// Build a new C++ "new" expression.
2703 /// By default, performs semantic analysis to build the new expression.
2704 /// Subclasses may override this routine to provide different behavior.
2705 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
2707 SourceLocation PlacementLParen,
2708 MultiExprArg PlacementArgs,
2709 SourceLocation PlacementRParen,
2710 SourceRange TypeIdParens,
2711 QualType AllocatedType,
2712 TypeSourceInfo *AllocatedTypeInfo,
2714 SourceRange DirectInitRange,
2715 Expr *Initializer) {
2716 return getSema().BuildCXXNew(StartLoc, UseGlobal,
2728 /// Build a new C++ "delete" expression.
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
2732 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2733 bool IsGlobalDelete,
2736 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2740 /// Build a new type trait expression.
2742 /// By default, performs semantic analysis to build the new expression.
2743 /// Subclasses may override this routine to provide different behavior.
2744 ExprResult RebuildTypeTrait(TypeTrait Trait,
2745 SourceLocation StartLoc,
2746 ArrayRef<TypeSourceInfo *> Args,
2747 SourceLocation RParenLoc) {
2748 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2751 /// Build a new array type trait expression.
2753 /// By default, performs semantic analysis to build the new expression.
2754 /// Subclasses may override this routine to provide different behavior.
2755 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2756 SourceLocation StartLoc,
2757 TypeSourceInfo *TSInfo,
2759 SourceLocation RParenLoc) {
2760 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2763 /// Build a new expression trait expression.
2765 /// By default, performs semantic analysis to build the new expression.
2766 /// Subclasses may override this routine to provide different behavior.
2767 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2768 SourceLocation StartLoc,
2770 SourceLocation RParenLoc) {
2771 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2774 /// Build a new (previously unresolved) declaration reference
2777 /// By default, performs semantic analysis to build the new expression.
2778 /// Subclasses may override this routine to provide different behavior.
2779 ExprResult RebuildDependentScopeDeclRefExpr(
2780 NestedNameSpecifierLoc QualifierLoc,
2781 SourceLocation TemplateKWLoc,
2782 const DeclarationNameInfo &NameInfo,
2783 const TemplateArgumentListInfo *TemplateArgs,
2784 bool IsAddressOfOperand,
2785 TypeSourceInfo **RecoveryTSI) {
2787 SS.Adopt(QualifierLoc);
2789 if (TemplateArgs || TemplateKWLoc.isValid())
2790 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2793 return getSema().BuildQualifiedDeclarationNameExpr(
2794 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2797 /// Build a new template-id expression.
2799 /// By default, performs semantic analysis to build the new expression.
2800 /// Subclasses may override this routine to provide different behavior.
2801 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2802 SourceLocation TemplateKWLoc,
2805 const TemplateArgumentListInfo *TemplateArgs) {
2806 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2810 /// Build a new object-construction expression.
2812 /// By default, performs semantic analysis to build the new expression.
2813 /// Subclasses may override this routine to provide different behavior.
2814 ExprResult RebuildCXXConstructExpr(QualType T,
2816 CXXConstructorDecl *Constructor,
2819 bool HadMultipleCandidates,
2820 bool ListInitialization,
2821 bool StdInitListInitialization,
2822 bool RequiresZeroInit,
2823 CXXConstructExpr::ConstructionKind ConstructKind,
2824 SourceRange ParenRange) {
2825 SmallVector<Expr*, 8> ConvertedArgs;
2826 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2830 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
2833 HadMultipleCandidates,
2835 StdInitListInitialization,
2836 RequiresZeroInit, ConstructKind,
2840 /// Build a new implicit construction via inherited constructor
2842 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2843 CXXConstructorDecl *Constructor,
2844 bool ConstructsVBase,
2845 bool InheritedFromVBase) {
2846 return new (getSema().Context) CXXInheritedCtorInitExpr(
2847 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2850 /// Build a new object-construction expression.
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
2854 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2855 SourceLocation LParenOrBraceLoc,
2857 SourceLocation RParenOrBraceLoc,
2858 bool ListInitialization) {
2859 return getSema().BuildCXXTypeConstructExpr(
2860 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
2863 /// Build a new object-construction expression.
2865 /// By default, performs semantic analysis to build the new expression.
2866 /// Subclasses may override this routine to provide different behavior.
2867 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2868 SourceLocation LParenLoc,
2870 SourceLocation RParenLoc,
2871 bool ListInitialization) {
2872 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2873 RParenLoc, ListInitialization);
2876 /// Build a new member reference expression.
2878 /// By default, performs semantic analysis to build the new expression.
2879 /// Subclasses may override this routine to provide different behavior.
2880 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2883 SourceLocation OperatorLoc,
2884 NestedNameSpecifierLoc QualifierLoc,
2885 SourceLocation TemplateKWLoc,
2886 NamedDecl *FirstQualifierInScope,
2887 const DeclarationNameInfo &MemberNameInfo,
2888 const TemplateArgumentListInfo *TemplateArgs) {
2890 SS.Adopt(QualifierLoc);
2892 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2893 OperatorLoc, IsArrow,
2895 FirstQualifierInScope,
2897 TemplateArgs, /*S*/nullptr);
2900 /// Build a new member reference expression.
2902 /// By default, performs semantic analysis to build the new expression.
2903 /// Subclasses may override this routine to provide different behavior.
2904 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2905 SourceLocation OperatorLoc,
2907 NestedNameSpecifierLoc QualifierLoc,
2908 SourceLocation TemplateKWLoc,
2909 NamedDecl *FirstQualifierInScope,
2911 const TemplateArgumentListInfo *TemplateArgs) {
2913 SS.Adopt(QualifierLoc);
2915 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2916 OperatorLoc, IsArrow,
2918 FirstQualifierInScope,
2919 R, TemplateArgs, /*S*/nullptr);
2922 /// Build a new noexcept expression.
2924 /// By default, performs semantic analysis to build the new expression.
2925 /// Subclasses may override this routine to provide different behavior.
2926 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2927 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2930 /// Build a new expression to compute the length of a parameter pack.
2931 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2933 SourceLocation PackLoc,
2934 SourceLocation RParenLoc,
2935 Optional<unsigned> Length,
2936 ArrayRef<TemplateArgument> PartialArgs) {
2937 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2938 RParenLoc, Length, PartialArgs);
2941 /// Build a new Objective-C boxed expression.
2943 /// By default, performs semantic analysis to build the new expression.
2944 /// Subclasses may override this routine to provide different behavior.
2945 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2946 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2949 /// Build a new Objective-C array literal.
2951 /// By default, performs semantic analysis to build the new expression.
2952 /// Subclasses may override this routine to provide different behavior.
2953 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2954 Expr **Elements, unsigned NumElements) {
2955 return getSema().BuildObjCArrayLiteral(Range,
2956 MultiExprArg(Elements, NumElements));
2959 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2960 Expr *Base, Expr *Key,
2961 ObjCMethodDecl *getterMethod,
2962 ObjCMethodDecl *setterMethod) {
2963 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2964 getterMethod, setterMethod);
2967 /// Build a new Objective-C dictionary literal.
2969 /// By default, performs semantic analysis to build the new expression.
2970 /// Subclasses may override this routine to provide different behavior.
2971 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2972 MutableArrayRef<ObjCDictionaryElement> Elements) {
2973 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
2976 /// Build a new Objective-C \@encode expression.
2978 /// By default, performs semantic analysis to build the new expression.
2979 /// Subclasses may override this routine to provide different behavior.
2980 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2981 TypeSourceInfo *EncodeTypeInfo,
2982 SourceLocation RParenLoc) {
2983 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2986 /// Build a new Objective-C class message.
2987 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2989 ArrayRef<SourceLocation> SelectorLocs,
2990 ObjCMethodDecl *Method,
2991 SourceLocation LBracLoc,
2993 SourceLocation RBracLoc) {
2994 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2995 ReceiverTypeInfo->getType(),
2996 /*SuperLoc=*/SourceLocation(),
2997 Sel, Method, LBracLoc, SelectorLocs,
3001 /// Build a new Objective-C instance message.
3002 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
3004 ArrayRef<SourceLocation> SelectorLocs,
3005 ObjCMethodDecl *Method,
3006 SourceLocation LBracLoc,
3008 SourceLocation RBracLoc) {
3009 return SemaRef.BuildInstanceMessage(Receiver,
3010 Receiver->getType(),
3011 /*SuperLoc=*/SourceLocation(),
3012 Sel, Method, LBracLoc, SelectorLocs,
3016 /// Build a new Objective-C instance/class message to 'super'.
3017 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3019 ArrayRef<SourceLocation> SelectorLocs,
3021 ObjCMethodDecl *Method,
3022 SourceLocation LBracLoc,
3024 SourceLocation RBracLoc) {
3025 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3028 Sel, Method, LBracLoc, SelectorLocs,
3030 : SemaRef.BuildClassMessage(nullptr,
3033 Sel, Method, LBracLoc, SelectorLocs,
3039 /// Build a new Objective-C ivar reference expression.
3041 /// By default, performs semantic analysis to build the new expression.
3042 /// Subclasses may override this routine to provide different behavior.
3043 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
3044 SourceLocation IvarLoc,
3045 bool IsArrow, bool IsFreeIvar) {
3047 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3048 ExprResult Result = getSema().BuildMemberReferenceExpr(
3049 BaseArg, BaseArg->getType(),
3050 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3051 /*FirstQualifierInScope=*/nullptr, NameInfo,
3052 /*TemplateArgs=*/nullptr,
3054 if (IsFreeIvar && Result.isUsable())
3055 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3059 /// Build a new Objective-C property reference expression.
3061 /// By default, performs semantic analysis to build the new expression.
3062 /// Subclasses may override this routine to provide different behavior.
3063 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
3064 ObjCPropertyDecl *Property,
3065 SourceLocation PropertyLoc) {
3067 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3068 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3069 /*FIXME:*/PropertyLoc,
3071 SS, SourceLocation(),
3072 /*FirstQualifierInScope=*/nullptr,
3074 /*TemplateArgs=*/nullptr,
3078 /// Build a new Objective-C property reference expression.
3080 /// By default, performs semantic analysis to build the new expression.
3081 /// Subclasses may override this routine to provide different behavior.
3082 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3083 ObjCMethodDecl *Getter,
3084 ObjCMethodDecl *Setter,
3085 SourceLocation PropertyLoc) {
3086 // Since these expressions can only be value-dependent, we do not
3087 // need to perform semantic analysis again.
3089 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3090 VK_LValue, OK_ObjCProperty,
3091 PropertyLoc, Base));
3094 /// Build a new Objective-C "isa" expression.
3096 /// By default, performs semantic analysis to build the new expression.
3097 /// Subclasses may override this routine to provide different behavior.
3098 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
3099 SourceLocation OpLoc, bool IsArrow) {
3101 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3102 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3104 SS, SourceLocation(),
3105 /*FirstQualifierInScope=*/nullptr,
3107 /*TemplateArgs=*/nullptr,
3111 /// Build a new shuffle vector expression.
3113 /// By default, performs semantic analysis to build the new expression.
3114 /// Subclasses may override this routine to provide different behavior.
3115 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
3116 MultiExprArg SubExprs,
3117 SourceLocation RParenLoc) {
3118 // Find the declaration for __builtin_shufflevector
3119 const IdentifierInfo &Name
3120 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3121 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3122 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3123 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3125 // Build a reference to the __builtin_shufflevector builtin
3126 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3127 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3128 SemaRef.Context.BuiltinFnTy,
3129 VK_RValue, BuiltinLoc);
3130 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3131 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3132 CK_BuiltinFnToFnPtr).get();
3134 // Build the CallExpr
3135 ExprResult TheCall = new (SemaRef.Context) CallExpr(
3136 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3137 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
3139 // Type-check the __builtin_shufflevector expression.
3140 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3143 /// Build a new convert vector expression.
3144 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3145 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3146 SourceLocation RParenLoc) {
3147 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3148 BuiltinLoc, RParenLoc);
3151 /// Build a new template argument pack expansion.
3153 /// By default, performs semantic analysis to build a new pack expansion
3154 /// for a template argument. Subclasses may override this routine to provide
3155 /// different behavior.
3156 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
3157 SourceLocation EllipsisLoc,
3158 Optional<unsigned> NumExpansions) {
3159 switch (Pattern.getArgument().getKind()) {
3160 case TemplateArgument::Expression: {
3162 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3163 EllipsisLoc, NumExpansions);
3164 if (Result.isInvalid())
3165 return TemplateArgumentLoc();
3167 return TemplateArgumentLoc(Result.get(), Result.get());
3170 case TemplateArgument::Template:
3171 return TemplateArgumentLoc(TemplateArgument(
3172 Pattern.getArgument().getAsTemplate(),
3174 Pattern.getTemplateQualifierLoc(),
3175 Pattern.getTemplateNameLoc(),
3178 case TemplateArgument::Null:
3179 case TemplateArgument::Integral:
3180 case TemplateArgument::Declaration:
3181 case TemplateArgument::Pack:
3182 case TemplateArgument::TemplateExpansion:
3183 case TemplateArgument::NullPtr:
3184 llvm_unreachable("Pack expansion pattern has no parameter packs");
3186 case TemplateArgument::Type:
3187 if (TypeSourceInfo *Expansion
3188 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3191 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3196 return TemplateArgumentLoc();
3199 /// Build a new expression pack expansion.
3201 /// By default, performs semantic analysis to build a new pack expansion
3202 /// for an expression. Subclasses may override this routine to provide
3203 /// different behavior.
3204 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
3205 Optional<unsigned> NumExpansions) {
3206 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3209 /// Build a new C++1z fold-expression.
3211 /// By default, performs semantic analysis in order to build a new fold
3213 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3214 BinaryOperatorKind Operator,
3215 SourceLocation EllipsisLoc, Expr *RHS,
3216 SourceLocation RParenLoc) {
3217 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3221 /// Build an empty C++1z fold-expression with the given operator.
3223 /// By default, produces the fallback value for the fold-expression, or
3224 /// produce an error if there is no fallback value.
3225 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3226 BinaryOperatorKind Operator) {
3227 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3230 /// Build a new atomic operation expression.
3232 /// By default, performs semantic analysis to build the new expression.
3233 /// Subclasses may override this routine to provide different behavior.
3234 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3235 MultiExprArg SubExprs,
3237 AtomicExpr::AtomicOp Op,
3238 SourceLocation RParenLoc) {
3239 // Just create the expression; there is not any interesting semantic
3240 // analysis here because we can't actually build an AtomicExpr until
3241 // we are sure it is semantically sound.
3242 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3247 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3248 QualType ObjectType,
3249 NamedDecl *FirstQualifierInScope,
3252 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3253 QualType ObjectType,
3254 NamedDecl *FirstQualifierInScope,
3257 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3258 NamedDecl *FirstQualifierInScope,
3261 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3262 DependentNameTypeLoc TL,
3263 bool DeducibleTSTContext);
3266 template<typename Derived>
3267 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
3271 switch (S->getStmtClass()) {
3272 case Stmt::NoStmtClass: break;
3274 // Transform individual statement nodes
3275 #define STMT(Node, Parent) \
3276 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3277 #define ABSTRACT_STMT(Node)
3278 #define EXPR(Node, Parent)
3279 #include "clang/AST/StmtNodes.inc"
3281 // Transform expressions by calling TransformExpr.
3282 #define STMT(Node, Parent)
3283 #define ABSTRACT_STMT(Stmt)
3284 #define EXPR(Node, Parent) case Stmt::Node##Class:
3285 #include "clang/AST/StmtNodes.inc"
3287 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3291 return getSema().ActOnExprStmt(E);
3298 template<typename Derived>
3299 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3303 switch (S->getClauseKind()) {
3305 // Transform individual clause nodes
3306 #define OPENMP_CLAUSE(Name, Class) \
3307 case OMPC_ ## Name : \
3308 return getDerived().Transform ## Class(cast<Class>(S));
3309 #include "clang/Basic/OpenMPKinds.def"
3316 template<typename Derived>
3317 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
3321 switch (E->getStmtClass()) {
3322 case Stmt::NoStmtClass: break;
3323 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3324 #define ABSTRACT_STMT(Stmt)
3325 #define EXPR(Node, Parent) \
3326 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3327 #include "clang/AST/StmtNodes.inc"
3333 template<typename Derived>
3334 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
3336 // Initializers are instantiated like expressions, except that various outer
3337 // layers are stripped.
3341 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3342 Init = ExprTemp->getSubExpr();
3344 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3345 Init = AIL->getCommonExpr();
3347 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3348 Init = MTE->GetTemporaryExpr();
3350 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3351 Init = Binder->getSubExpr();
3353 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3354 Init = ICE->getSubExprAsWritten();
3356 if (CXXStdInitializerListExpr *ILE =
3357 dyn_cast<CXXStdInitializerListExpr>(Init))
3358 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3360 // If this is copy-initialization, we only need to reconstruct
3361 // InitListExprs. Other forms of copy-initialization will be a no-op if
3362 // the initializer is already the right type.
3363 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3364 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3365 return getDerived().TransformExpr(Init);
3367 // Revert value-initialization back to empty parens.
3368 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3369 SourceRange Parens = VIE->getSourceRange();
3370 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3374 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3375 if (isa<ImplicitValueInitExpr>(Init))
3376 return getDerived().RebuildParenListExpr(SourceLocation(), None,
3379 // Revert initialization by constructor back to a parenthesized or braced list
3380 // of expressions. Any other form of initializer can just be reused directly.
3381 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3382 return getDerived().TransformExpr(Init);
3384 // If the initialization implicitly converted an initializer list to a
3385 // std::initializer_list object, unwrap the std::initializer_list too.
3386 if (Construct && Construct->isStdInitListInitialization())
3387 return TransformInitializer(Construct->getArg(0), NotCopyInit);
3389 SmallVector<Expr*, 8> NewArgs;
3390 bool ArgChanged = false;
3391 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3392 /*IsCall*/true, NewArgs, &ArgChanged))
3395 // If this was list initialization, revert to syntactic list form.
3396 if (Construct->isListInitialization())
3397 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3398 Construct->getLocEnd());
3400 // Build a ParenListExpr to represent anything else.
3401 SourceRange Parens = Construct->getParenOrBraceRange();
3402 if (Parens.isInvalid()) {
3403 // This was a variable declaration's initialization for which no initializer
3405 assert(NewArgs.empty() &&
3406 "no parens or braces but have direct init with arguments?");
3409 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3413 template<typename Derived>
3414 bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
3417 SmallVectorImpl<Expr *> &Outputs,
3419 for (unsigned I = 0; I != NumInputs; ++I) {
3420 // If requested, drop call arguments that need to be dropped.
3421 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3428 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3429 Expr *Pattern = Expansion->getPattern();
3431 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3432 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3433 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3435 // Determine whether the set of unexpanded parameter packs can and should
3438 bool RetainExpansion = false;
3439 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3440 Optional<unsigned> NumExpansions = OrigNumExpansions;
3441 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3442 Pattern->getSourceRange(),
3444 Expand, RetainExpansion,
3449 // The transform has determined that we should perform a simple
3450 // transformation on the pack expansion, producing another pack
3452 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3453 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3454 if (OutPattern.isInvalid())
3457 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3458 Expansion->getEllipsisLoc(),
3460 if (Out.isInvalid())
3465 Outputs.push_back(Out.get());
3469 // Record right away that the argument was changed. This needs
3470 // to happen even if the array expands to nothing.
3471 if (ArgChanged) *ArgChanged = true;
3473 // The transform has determined that we should perform an elementwise
3474 // expansion of the pattern. Do so.
3475 for (unsigned I = 0; I != *NumExpansions; ++I) {
3476 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3477 ExprResult Out = getDerived().TransformExpr(Pattern);
3478 if (Out.isInvalid())
3481 if (Out.get()->containsUnexpandedParameterPack()) {
3482 Out = getDerived().RebuildPackExpansion(
3483 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3484 if (Out.isInvalid())
3488 Outputs.push_back(Out.get());
3491 // If we're supposed to retain a pack expansion, do so by temporarily
3492 // forgetting the partially-substituted parameter pack.
3493 if (RetainExpansion) {
3494 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3496 ExprResult Out = getDerived().TransformExpr(Pattern);
3497 if (Out.isInvalid())
3500 Out = getDerived().RebuildPackExpansion(
3501 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3502 if (Out.isInvalid())
3505 Outputs.push_back(Out.get());
3512 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3513 : getDerived().TransformExpr(Inputs[I]);
3514 if (Result.isInvalid())
3517 if (Result.get() != Inputs[I] && ArgChanged)
3520 Outputs.push_back(Result.get());
3526 template <typename Derived>
3527 Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3528 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3530 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3531 getDerived().TransformDefinition(Var->getLocation(), Var));
3534 return Sema::ConditionError();
3536 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3540 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3542 if (CondExpr.isInvalid())
3543 return Sema::ConditionError();
3545 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3548 return Sema::ConditionResult();
3551 template<typename Derived>
3552 NestedNameSpecifierLoc
3553 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3554 NestedNameSpecifierLoc NNS,
3555 QualType ObjectType,
3556 NamedDecl *FirstQualifierInScope) {
3557 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
3558 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3559 Qualifier = Qualifier.getPrefix())
3560 Qualifiers.push_back(Qualifier);
3563 while (!Qualifiers.empty()) {
3564 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3565 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
3567 switch (QNNS->getKind()) {
3568 case NestedNameSpecifier::Identifier: {
3569 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3570 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3571 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3572 SS, FirstQualifierInScope, false))
3573 return NestedNameSpecifierLoc();
3577 case NestedNameSpecifier::Namespace: {
3579 = cast_or_null<NamespaceDecl>(
3580 getDerived().TransformDecl(
3581 Q.getLocalBeginLoc(),
3582 QNNS->getAsNamespace()));
3583 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3587 case NestedNameSpecifier::NamespaceAlias: {
3588 NamespaceAliasDecl *Alias
3589 = cast_or_null<NamespaceAliasDecl>(
3590 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3591 QNNS->getAsNamespaceAlias()));
3592 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3593 Q.getLocalEndLoc());
3597 case NestedNameSpecifier::Global:
3598 // There is no meaningful transformation that one could perform on the
3600 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3603 case NestedNameSpecifier::Super: {
3605 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3606 SourceLocation(), QNNS->getAsRecordDecl()));
3607 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3611 case NestedNameSpecifier::TypeSpecWithTemplate:
3612 case NestedNameSpecifier::TypeSpec: {
3613 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3614 FirstQualifierInScope, SS);
3617 return NestedNameSpecifierLoc();
3619 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3620 (SemaRef.getLangOpts().CPlusPlus11 &&
3621 TL.getType()->isEnumeralType())) {
3622 assert(!TL.getType().hasLocalQualifiers() &&
3623 "Can't get cv-qualifiers here");
3624 if (TL.getType()->isEnumeralType())
3625 SemaRef.Diag(TL.getBeginLoc(),
3626 diag::warn_cxx98_compat_enum_nested_name_spec);
3627 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3628 Q.getLocalEndLoc());
3631 // If the nested-name-specifier is an invalid type def, don't emit an
3632 // error because a previous error should have already been emitted.
3633 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3634 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3635 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3636 << TL.getType() << SS.getRange();
3638 return NestedNameSpecifierLoc();
3642 // The qualifier-in-scope and object type only apply to the leftmost entity.
3643 FirstQualifierInScope = nullptr;
3644 ObjectType = QualType();
3647 // Don't rebuild the nested-name-specifier if we don't have to.
3648 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3649 !getDerived().AlwaysRebuild())
3652 // If we can re-use the source-location data from the original
3653 // nested-name-specifier, do so.
3654 if (SS.location_size() == NNS.getDataLength() &&
3655 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3656 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3658 // Allocate new nested-name-specifier location information.
3659 return SS.getWithLocInContext(SemaRef.Context);
3662 template<typename Derived>
3664 TreeTransform<Derived>
3665 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
3666 DeclarationName Name = NameInfo.getName();
3668 return DeclarationNameInfo();
3670 switch (Name.getNameKind()) {
3671 case DeclarationName::Identifier:
3672 case DeclarationName::ObjCZeroArgSelector:
3673 case DeclarationName::ObjCOneArgSelector:
3674 case DeclarationName::ObjCMultiArgSelector:
3675 case DeclarationName::CXXOperatorName:
3676 case DeclarationName::CXXLiteralOperatorName:
3677 case DeclarationName::CXXUsingDirective:
3680 case DeclarationName::CXXDeductionGuideName: {
3681 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3682 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3683 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3685 return DeclarationNameInfo();
3687 DeclarationNameInfo NewNameInfo(NameInfo);
3688 NewNameInfo.setName(
3689 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3693 case DeclarationName::CXXConstructorName:
3694 case DeclarationName::CXXDestructorName:
3695 case DeclarationName::CXXConversionFunctionName: {
3696 TypeSourceInfo *NewTInfo;
3697 CanQualType NewCanTy;
3698 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3699 NewTInfo = getDerived().TransformType(OldTInfo);
3701 return DeclarationNameInfo();
3702 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3706 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3707 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3709 return DeclarationNameInfo();
3710 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3713 DeclarationName NewName
3714 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3716 DeclarationNameInfo NewNameInfo(NameInfo);
3717 NewNameInfo.setName(NewName);
3718 NewNameInfo.setNamedTypeInfo(NewTInfo);
3723 llvm_unreachable("Unknown name kind.");
3726 template<typename Derived>
3728 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3730 SourceLocation NameLoc,
3731 QualType ObjectType,
3732 NamedDecl *FirstQualifierInScope,
3733 bool AllowInjectedClassName) {
3734 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3735 TemplateDecl *Template = QTN->getTemplateDecl();
3736 assert(Template && "qualified template name must refer to a template");
3738 TemplateDecl *TransTemplate
3739 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3742 return TemplateName();
3744 if (!getDerived().AlwaysRebuild() &&
3745 SS.getScopeRep() == QTN->getQualifier() &&
3746 TransTemplate == Template)
3749 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3753 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3754 if (SS.getScopeRep()) {
3755 // These apply to the scope specifier, not the template.
3756 ObjectType = QualType();
3757 FirstQualifierInScope = nullptr;
3760 if (!getDerived().AlwaysRebuild() &&
3761 SS.getScopeRep() == DTN->getQualifier() &&
3762 ObjectType.isNull())
3765 // FIXME: Preserve the location of the "template" keyword.
3766 SourceLocation TemplateKWLoc = NameLoc;
3768 if (DTN->isIdentifier()) {
3769 return getDerived().RebuildTemplateName(SS,
3771 *DTN->getIdentifier(),
3774 FirstQualifierInScope,
3775 AllowInjectedClassName);
3778 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3779 DTN->getOperator(), NameLoc,
3780 ObjectType, AllowInjectedClassName);
3783 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3784 TemplateDecl *TransTemplate
3785 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3788 return TemplateName();
3790 if (!getDerived().AlwaysRebuild() &&
3791 TransTemplate == Template)
3794 return TemplateName(TransTemplate);
3797 if (SubstTemplateTemplateParmPackStorage *SubstPack
3798 = Name.getAsSubstTemplateTemplateParmPack()) {
3799 TemplateTemplateParmDecl *TransParam
3800 = cast_or_null<TemplateTemplateParmDecl>(
3801 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3803 return TemplateName();
3805 if (!getDerived().AlwaysRebuild() &&
3806 TransParam == SubstPack->getParameterPack())
3809 return getDerived().RebuildTemplateName(TransParam,
3810 SubstPack->getArgumentPack());
3813 // These should be getting filtered out before they reach the AST.
3814 llvm_unreachable("overloaded function decl survived to here");
3817 template<typename Derived>
3818 void TreeTransform<Derived>::InventTemplateArgumentLoc(
3819 const TemplateArgument &Arg,
3820 TemplateArgumentLoc &Output) {
3821 SourceLocation Loc = getDerived().getBaseLocation();
3822 switch (Arg.getKind()) {
3823 case TemplateArgument::Null:
3824 llvm_unreachable("null template argument in TreeTransform");
3827 case TemplateArgument::Type:
3828 Output = TemplateArgumentLoc(Arg,
3829 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3833 case TemplateArgument::Template:
3834 case TemplateArgument::TemplateExpansion: {
3835 NestedNameSpecifierLocBuilder Builder;
3836 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
3837 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3838 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3839 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3840 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3842 if (Arg.getKind() == TemplateArgument::Template)
3843 Output = TemplateArgumentLoc(Arg,
3844 Builder.getWithLocInContext(SemaRef.Context),
3847 Output = TemplateArgumentLoc(Arg,
3848 Builder.getWithLocInContext(SemaRef.Context),
3854 case TemplateArgument::Expression:
3855 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3858 case TemplateArgument::Declaration:
3859 case TemplateArgument::Integral:
3860 case TemplateArgument::Pack:
3861 case TemplateArgument::NullPtr:
3862 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
3867 template<typename Derived>
3868 bool TreeTransform<Derived>::TransformTemplateArgument(
3869 const TemplateArgumentLoc &Input,
3870 TemplateArgumentLoc &Output, bool Uneval) {
3871 EnterExpressionEvaluationContext EEEC(
3872 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated,
3873 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
3874 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
3875 const TemplateArgument &Arg = Input.getArgument();
3876 switch (Arg.getKind()) {
3877 case TemplateArgument::Null:
3878 case TemplateArgument::Integral:
3879 case TemplateArgument::Pack:
3880 case TemplateArgument::Declaration:
3881 case TemplateArgument::NullPtr:
3882 llvm_unreachable("Unexpected TemplateArgument");
3884 case TemplateArgument::Type: {
3885 TypeSourceInfo *DI = Input.getTypeSourceInfo();
3887 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3889 DI = getDerived().TransformType(DI);
3890 if (!DI) return true;
3892 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3896 case TemplateArgument::Template: {
3897 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3899 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3905 SS.Adopt(QualifierLoc);
3906 TemplateName Template
3907 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3908 Input.getTemplateNameLoc());
3909 if (Template.isNull())
3912 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3913 Input.getTemplateNameLoc());
3917 case TemplateArgument::TemplateExpansion:
3918 llvm_unreachable("Caller should expand pack expansions");
3920 case TemplateArgument::Expression: {
3921 // Template argument expressions are constant expressions.
3922 EnterExpressionEvaluationContext Unevaluated(
3924 ? Sema::ExpressionEvaluationContext::Unevaluated
3925 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
3927 Expr *InputExpr = Input.getSourceExpression();
3928 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3930 ExprResult E = getDerived().TransformExpr(InputExpr);
3931 E = SemaRef.ActOnConstantExpression(E);
3932 if (E.isInvalid()) return true;
3933 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3938 // Work around bogus GCC warning
3942 /// Iterator adaptor that invents template argument location information
3943 /// for each of the template arguments in its underlying iterator.
3944 template<typename Derived, typename InputIterator>
3945 class TemplateArgumentLocInventIterator {
3946 TreeTransform<Derived> &Self;
3950 typedef TemplateArgumentLoc value_type;
3951 typedef TemplateArgumentLoc reference;
3952 typedef typename std::iterator_traits<InputIterator>::difference_type
3954 typedef std::input_iterator_tag iterator_category;
3957 TemplateArgumentLoc Arg;
3960 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3962 const TemplateArgumentLoc *operator->() const { return &Arg; }
3965 TemplateArgumentLocInventIterator() { }
3967 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3969 : Self(Self), Iter(Iter) { }
3971 TemplateArgumentLocInventIterator &operator++() {
3976 TemplateArgumentLocInventIterator operator++(int) {
3977 TemplateArgumentLocInventIterator Old(*this);
3982 reference operator*() const {
3983 TemplateArgumentLoc Result;
3984 Self.InventTemplateArgumentLoc(*Iter, Result);
3988 pointer operator->() const { return pointer(**this); }
3990 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3991 const TemplateArgumentLocInventIterator &Y) {
3992 return X.Iter == Y.Iter;
3995 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3996 const TemplateArgumentLocInventIterator &Y) {
3997 return X.Iter != Y.Iter;
4001 template<typename Derived>
4002 template<typename InputIterator>
4003 bool TreeTransform<Derived>::TransformTemplateArguments(
4004 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4006 for (; First != Last; ++First) {
4007 TemplateArgumentLoc Out;
4008 TemplateArgumentLoc In = *First;
4010 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4011 // Unpack argument packs, which we translate them into separate
4013 // FIXME: We could do much better if we could guarantee that the
4014 // TemplateArgumentLocInfo for the pack expansion would be usable for
4015 // all of the template arguments in the argument pack.
4016 typedef TemplateArgumentLocInventIterator<Derived,
4017 TemplateArgument::pack_iterator>
4019 if (TransformTemplateArguments(PackLocIterator(*this,
4020 In.getArgument().pack_begin()),
4021 PackLocIterator(*this,
4022 In.getArgument().pack_end()),
4029 if (In.getArgument().isPackExpansion()) {
4030 // We have a pack expansion, for which we will be substituting into
4032 SourceLocation Ellipsis;
4033 Optional<unsigned> OrigNumExpansions;
4034 TemplateArgumentLoc Pattern
4035 = getSema().getTemplateArgumentPackExpansionPattern(
4036 In, Ellipsis, OrigNumExpansions);
4038 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4039 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4040 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4042 // Determine whether the set of unexpanded parameter packs can and should
4045 bool RetainExpansion = false;
4046 Optional<unsigned> NumExpansions = OrigNumExpansions;
4047 if (getDerived().TryExpandParameterPacks(Ellipsis,
4048 Pattern.getSourceRange(),
4056 // The transform has determined that we should perform a simple
4057 // transformation on the pack expansion, producing another pack
4059 TemplateArgumentLoc OutPattern;
4060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4061 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4064 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4066 if (Out.getArgument().isNull())
4069 Outputs.addArgument(Out);
4073 // The transform has determined that we should perform an elementwise
4074 // expansion of the pattern. Do so.
4075 for (unsigned I = 0; I != *NumExpansions; ++I) {
4076 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4078 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4081 if (Out.getArgument().containsUnexpandedParameterPack()) {
4082 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4084 if (Out.getArgument().isNull())
4088 Outputs.addArgument(Out);
4091 // If we're supposed to retain a pack expansion, do so by temporarily
4092 // forgetting the partially-substituted parameter pack.
4093 if (RetainExpansion) {
4094 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4096 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4099 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4101 if (Out.getArgument().isNull())
4104 Outputs.addArgument(Out);
4111 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4114 Outputs.addArgument(Out);
4121 //===----------------------------------------------------------------------===//
4122 // Type transformation
4123 //===----------------------------------------------------------------------===//
4125 template<typename Derived>
4126 QualType TreeTransform<Derived>::TransformType(QualType T) {
4127 if (getDerived().AlreadyTransformed(T))
4130 // Temporary workaround. All of these transformations should
4131 // eventually turn into transformations on TypeLocs.
4132 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4133 getDerived().getBaseLocation());
4135 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4140 return NewDI->getType();
4143 template<typename Derived>
4144 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
4145 // Refine the base location to the type's location.
4146 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4147 getDerived().getBaseEntity());
4148 if (getDerived().AlreadyTransformed(DI->getType()))
4153 TypeLoc TL = DI->getTypeLoc();
4154 TLB.reserve(TL.getFullDataSize());
4156 QualType Result = getDerived().TransformType(TLB, TL);
4157 if (Result.isNull())
4160 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4163 template<typename Derived>
4165 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
4166 switch (T.getTypeLocClass()) {
4167 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4168 #define TYPELOC(CLASS, PARENT) \
4169 case TypeLoc::CLASS: \
4170 return getDerived().Transform##CLASS##Type(TLB, \
4171 T.castAs<CLASS##TypeLoc>());
4172 #include "clang/AST/TypeLocNodes.def"
4175 llvm_unreachable("unhandled type loc!");
4178 template<typename Derived>
4179 QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4180 if (!isa<DependentNameType>(T))
4181 return TransformType(T);
4183 if (getDerived().AlreadyTransformed(T))
4185 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4186 getDerived().getBaseLocation());
4187 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4188 return NewDI ? NewDI->getType() : QualType();
4191 template<typename Derived>
4193 TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4194 if (!isa<DependentNameType>(DI->getType()))
4195 return TransformType(DI);
4197 // Refine the base location to the type's location.
4198 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4199 getDerived().getBaseEntity());
4200 if (getDerived().AlreadyTransformed(DI->getType()))
4205 TypeLoc TL = DI->getTypeLoc();
4206 TLB.reserve(TL.getFullDataSize());
4208 auto QTL = TL.getAs<QualifiedTypeLoc>();
4210 TL = QTL.getUnqualifiedLoc();
4212 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4214 QualType Result = getDerived().TransformDependentNameType(
4215 TLB, DNTL, /*DeducedTSTContext*/true);
4216 if (Result.isNull())
4220 Result = getDerived().RebuildQualifiedType(
4221 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4222 TLB.TypeWasModifiedSafely(Result);
4225 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4228 template<typename Derived>
4230 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
4231 QualifiedTypeLoc T) {
4232 Qualifiers Quals = T.getType().getLocalQualifiers();
4234 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4235 if (Result.isNull())
4238 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4240 // RebuildQualifiedType might have updated the type, but not in a way
4241 // that invalidates the TypeLoc. (There's no location information for
4243 TLB.TypeWasModifiedSafely(Result);
4248 template<typename Derived>
4249 QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4253 // [When] adding cv-qualifications on top of the function type [...] the
4254 // cv-qualifiers are ignored.
4256 // when the cv-qualifiers are introduced through the use of a typedef-name
4257 // or decltype-specifier [...] the cv-qualifiers are ignored.
4258 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4259 // applied to a reference type.
4260 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4261 if (T->isFunctionType() || T->isReferenceType())
4264 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4266 if (Quals.hasObjCLifetime()) {
4267 if (!T->isObjCLifetimeType() && !T->isDependentType())
4268 Quals.removeObjCLifetime();
4269 else if (T.getObjCLifetime()) {
4271 // A lifetime qualifier applied to a substituted template parameter
4272 // overrides the lifetime qualifier from the template argument.
4273 const AutoType *AutoTy;
4274 if (const SubstTemplateTypeParmType *SubstTypeParam
4275 = dyn_cast<SubstTemplateTypeParmType>(T)) {
4276 QualType Replacement = SubstTypeParam->getReplacementType();
4277 Qualifiers Qs = Replacement.getQualifiers();
4278 Qs.removeObjCLifetime();
4279 Replacement = SemaRef.Context.getQualifiedType(
4280 Replacement.getUnqualifiedType(), Qs);
4281 T = SemaRef.Context.getSubstTemplateTypeParmType(
4282 SubstTypeParam->getReplacedParameter(), Replacement);
4283 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
4284 // 'auto' types behave the same way as template parameters.
4285 QualType Deduced = AutoTy->getDeducedType();
4286 Qualifiers Qs = Deduced.getQualifiers();
4287 Qs.removeObjCLifetime();
4289 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4290 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4291 AutoTy->isDependentType());
4293 // Otherwise, complain about the addition of a qualifier to an
4294 // already-qualified type.
4295 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4296 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
4297 Quals.removeObjCLifetime();
4302 return SemaRef.BuildQualifiedType(T, Loc, Quals);
4305 template<typename Derived>
4307 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4308 QualType ObjectType,
4309 NamedDecl *UnqualLookup,
4311 if (getDerived().AlreadyTransformed(TL.getType()))
4314 TypeSourceInfo *TSI =
4315 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4317 return TSI->getTypeLoc();
4321 template<typename Derived>
4323 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4324 QualType ObjectType,
4325 NamedDecl *UnqualLookup,
4327 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4330 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4334 template <typename Derived>
4335 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4336 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4338 QualType T = TL.getType();
4339 assert(!getDerived().AlreadyTransformed(T));
4344 if (isa<TemplateSpecializationType>(T)) {
4345 TemplateSpecializationTypeLoc SpecTL =
4346 TL.castAs<TemplateSpecializationTypeLoc>();
4348 TemplateName Template = getDerived().TransformTemplateName(
4349 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4350 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
4351 if (Template.isNull())
4354 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4356 } else if (isa<DependentTemplateSpecializationType>(T)) {
4357 DependentTemplateSpecializationTypeLoc SpecTL =
4358 TL.castAs<DependentTemplateSpecializationTypeLoc>();
4360 TemplateName Template
4361 = getDerived().RebuildTemplateName(SS,
4362 SpecTL.getTemplateKeywordLoc(),
4363 *SpecTL.getTypePtr()->getIdentifier(),
4364 SpecTL.getTemplateNameLoc(),
4365 ObjectType, UnqualLookup,
4366 /*AllowInjectedClassName*/true);
4367 if (Template.isNull())
4370 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4375 // Nothing special needs to be done for these.
4376 Result = getDerived().TransformType(TLB, TL);
4379 if (Result.isNull())
4382 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4385 template <class TyLoc> static inline
4386 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4387 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4388 NewT.setNameLoc(T.getNameLoc());
4392 template<typename Derived>
4393 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4395 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4396 NewT.setBuiltinLoc(T.getBuiltinLoc());
4397 if (T.needsExtraLocalData())
4398 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4402 template<typename Derived>
4403 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4406 return TransformTypeSpecType(TLB, T);
4409 template <typename Derived>
4410 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4411 AdjustedTypeLoc TL) {
4412 // Adjustments applied during transformation are handled elsewhere.
4413 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4416 template<typename Derived>
4417 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4418 DecayedTypeLoc TL) {
4419 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4420 if (OriginalType.isNull())
4423 QualType Result = TL.getType();
4424 if (getDerived().AlwaysRebuild() ||
4425 OriginalType != TL.getOriginalLoc().getType())
4426 Result = SemaRef.Context.getDecayedType(OriginalType);
4427 TLB.push<DecayedTypeLoc>(Result);
4428 // Nothing to set for DecayedTypeLoc.
4432 template<typename Derived>
4433 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4434 PointerTypeLoc TL) {
4435 QualType PointeeType
4436 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4437 if (PointeeType.isNull())
4440 QualType Result = TL.getType();
4441 if (PointeeType->getAs<ObjCObjectType>()) {
4442 // A dependent pointer type 'T *' has is being transformed such
4443 // that an Objective-C class type is being replaced for 'T'. The
4444 // resulting pointer type is an ObjCObjectPointerType, not a
4446 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4448 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4449 NewT.setStarLoc(TL.getStarLoc());
4453 if (getDerived().AlwaysRebuild() ||
4454 PointeeType != TL.getPointeeLoc().getType()) {
4455 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4456 if (Result.isNull())
4460 // Objective-C ARC can add lifetime qualifiers to the type that we're
4462 TLB.TypeWasModifiedSafely(Result->getPointeeType());
4464 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4465 NewT.setSigilLoc(TL.getSigilLoc());
4469 template<typename Derived>
4471 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4472 BlockPointerTypeLoc TL) {
4473 QualType PointeeType
4474 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4475 if (PointeeType.isNull())
4478 QualType Result = TL.getType();
4479 if (getDerived().AlwaysRebuild() ||
4480 PointeeType != TL.getPointeeLoc().getType()) {
4481 Result = getDerived().RebuildBlockPointerType(PointeeType,
4483 if (Result.isNull())
4487 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4488 NewT.setSigilLoc(TL.getSigilLoc());
4492 /// Transforms a reference type. Note that somewhat paradoxically we
4493 /// don't care whether the type itself is an l-value type or an r-value
4494 /// type; we only care if the type was *written* as an l-value type
4495 /// or an r-value type.
4496 template<typename Derived>
4498 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
4499 ReferenceTypeLoc TL) {
4500 const ReferenceType *T = TL.getTypePtr();
4502 // Note that this works with the pointee-as-written.
4503 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4504 if (PointeeType.isNull())
4507 QualType Result = TL.getType();
4508 if (getDerived().AlwaysRebuild() ||
4509 PointeeType != T->getPointeeTypeAsWritten()) {
4510 Result = getDerived().RebuildReferenceType(PointeeType,
4511 T->isSpelledAsLValue(),
4513 if (Result.isNull())
4517 // Objective-C ARC can add lifetime qualifiers to the type that we're
4519 TLB.TypeWasModifiedSafely(
4520 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4522 // r-value references can be rebuilt as l-value references.
4523 ReferenceTypeLoc NewTL;
4524 if (isa<LValueReferenceType>(Result))
4525 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4527 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4528 NewTL.setSigilLoc(TL.getSigilLoc());
4533 template<typename Derived>
4535 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
4536 LValueReferenceTypeLoc TL) {
4537 return TransformReferenceType(TLB, TL);
4540 template<typename Derived>
4542 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
4543 RValueReferenceTypeLoc TL) {
4544 return TransformReferenceType(TLB, TL);
4547 template<typename Derived>
4549 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
4550 MemberPointerTypeLoc TL) {
4551 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4552 if (PointeeType.isNull())
4555 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4556 TypeSourceInfo *NewClsTInfo = nullptr;
4558 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4563 const MemberPointerType *T = TL.getTypePtr();
4564 QualType OldClsType = QualType(T->getClass(), 0);
4565 QualType NewClsType;
4567 NewClsType = NewClsTInfo->getType();
4569 NewClsType = getDerived().TransformType(OldClsType);
4570 if (NewClsType.isNull())
4574 QualType Result = TL.getType();
4575 if (getDerived().AlwaysRebuild() ||
4576 PointeeType != T->getPointeeType() ||
4577 NewClsType != OldClsType) {
4578 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4580 if (Result.isNull())
4584 // If we had to adjust the pointee type when building a member pointer, make
4585 // sure to push TypeLoc info for it.
4586 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4587 if (MPT && PointeeType != MPT->getPointeeType()) {
4588 assert(isa<AdjustedType>(MPT->getPointeeType()));
4589 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4592 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4593 NewTL.setSigilLoc(TL.getSigilLoc());
4594 NewTL.setClassTInfo(NewClsTInfo);
4599 template<typename Derived>
4601 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4602 ConstantArrayTypeLoc TL) {
4603 const ConstantArrayType *T = TL.getTypePtr();
4604 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4605 if (ElementType.isNull())
4608 QualType Result = TL.getType();
4609 if (getDerived().AlwaysRebuild() ||
4610 ElementType != T->getElementType()) {
4611 Result = getDerived().RebuildConstantArrayType(ElementType,
4612 T->getSizeModifier(),
4614 T->getIndexTypeCVRQualifiers(),
4615 TL.getBracketsRange());
4616 if (Result.isNull())
4620 // We might have either a ConstantArrayType or a VariableArrayType now:
4621 // a ConstantArrayType is allowed to have an element type which is a
4622 // VariableArrayType if the type is dependent. Fortunately, all array
4623 // types have the same location layout.
4624 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4625 NewTL.setLBracketLoc(TL.getLBracketLoc());
4626 NewTL.setRBracketLoc(TL.getRBracketLoc());
4628 Expr *Size = TL.getSizeExpr();
4630 EnterExpressionEvaluationContext Unevaluated(
4631 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4632 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4633 Size = SemaRef.ActOnConstantExpression(Size).get();
4635 NewTL.setSizeExpr(Size);
4640 template<typename Derived>
4641 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4642 TypeLocBuilder &TLB,
4643 IncompleteArrayTypeLoc TL) {
4644 const IncompleteArrayType *T = TL.getTypePtr();
4645 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4646 if (ElementType.isNull())
4649 QualType Result = TL.getType();
4650 if (getDerived().AlwaysRebuild() ||
4651 ElementType != T->getElementType()) {
4652 Result = getDerived().RebuildIncompleteArrayType(ElementType,
4653 T->getSizeModifier(),
4654 T->getIndexTypeCVRQualifiers(),
4655 TL.getBracketsRange());
4656 if (Result.isNull())
4660 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4661 NewTL.setLBracketLoc(TL.getLBracketLoc());
4662 NewTL.setRBracketLoc(TL.getRBracketLoc());
4663 NewTL.setSizeExpr(nullptr);
4668 template<typename Derived>
4670 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4671 VariableArrayTypeLoc TL) {
4672 const VariableArrayType *T = TL.getTypePtr();
4673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4674 if (ElementType.isNull())
4677 ExprResult SizeResult;
4679 EnterExpressionEvaluationContext Context(
4680 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
4681 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4683 if (SizeResult.isInvalid())
4685 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
4686 if (SizeResult.isInvalid())
4689 Expr *Size = SizeResult.get();
4691 QualType Result = TL.getType();
4692 if (getDerived().AlwaysRebuild() ||
4693 ElementType != T->getElementType() ||
4694 Size != T->getSizeExpr()) {
4695 Result = getDerived().RebuildVariableArrayType(ElementType,
4696 T->getSizeModifier(),
4698 T->getIndexTypeCVRQualifiers(),
4699 TL.getBracketsRange());
4700 if (Result.isNull())
4704 // We might have constant size array now, but fortunately it has the same
4706 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4707 NewTL.setLBracketLoc(TL.getLBracketLoc());
4708 NewTL.setRBracketLoc(TL.getRBracketLoc());
4709 NewTL.setSizeExpr(Size);
4714 template<typename Derived>
4716 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4717 DependentSizedArrayTypeLoc TL) {
4718 const DependentSizedArrayType *T = TL.getTypePtr();
4719 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4720 if (ElementType.isNull())
4723 // Array bounds are constant expressions.
4724 EnterExpressionEvaluationContext Unevaluated(
4725 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4727 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4728 Expr *origSize = TL.getSizeExpr();
4729 if (!origSize) origSize = T->getSizeExpr();
4731 ExprResult sizeResult
4732 = getDerived().TransformExpr(origSize);
4733 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4734 if (sizeResult.isInvalid())
4737 Expr *size = sizeResult.get();
4739 QualType Result = TL.getType();
4740 if (getDerived().AlwaysRebuild() ||
4741 ElementType != T->getElementType() ||
4743 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4744 T->getSizeModifier(),
4746 T->getIndexTypeCVRQualifiers(),
4747 TL.getBracketsRange());
4748 if (Result.isNull())
4752 // We might have any sort of array type now, but fortunately they
4753 // all have the same location layout.
4754 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4755 NewTL.setLBracketLoc(TL.getLBracketLoc());
4756 NewTL.setRBracketLoc(TL.getRBracketLoc());
4757 NewTL.setSizeExpr(size);
4762 template <typename Derived>
4763 QualType TreeTransform<Derived>::TransformDependentVectorType(
4764 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4765 const DependentVectorType *T = TL.getTypePtr();
4766 QualType ElementType = getDerived().TransformType(T->getElementType());
4767 if (ElementType.isNull())
4770 EnterExpressionEvaluationContext Unevaluated(
4771 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4773 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4774 Size = SemaRef.ActOnConstantExpression(Size);
4775 if (Size.isInvalid())
4778 QualType Result = TL.getType();
4779 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4780 Size.get() != T->getSizeExpr()) {
4781 Result = getDerived().RebuildDependentVectorType(
4782 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4783 if (Result.isNull())
4787 // Result might be dependent or not.
4788 if (isa<DependentVectorType>(Result)) {
4789 DependentVectorTypeLoc NewTL =
4790 TLB.push<DependentVectorTypeLoc>(Result);
4791 NewTL.setNameLoc(TL.getNameLoc());
4793 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4794 NewTL.setNameLoc(TL.getNameLoc());
4800 template<typename Derived>
4801 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4802 TypeLocBuilder &TLB,
4803 DependentSizedExtVectorTypeLoc TL) {
4804 const DependentSizedExtVectorType *T = TL.getTypePtr();
4806 // FIXME: ext vector locs should be nested
4807 QualType ElementType = getDerived().TransformType(T->getElementType());
4808 if (ElementType.isNull())
4811 // Vector sizes are constant expressions.
4812 EnterExpressionEvaluationContext Unevaluated(
4813 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4815 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4816 Size = SemaRef.ActOnConstantExpression(Size);
4817 if (Size.isInvalid())
4820 QualType Result = TL.getType();
4821 if (getDerived().AlwaysRebuild() ||
4822 ElementType != T->getElementType() ||
4823 Size.get() != T->getSizeExpr()) {
4824 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4826 T->getAttributeLoc());
4827 if (Result.isNull())
4831 // Result might be dependent or not.
4832 if (isa<DependentSizedExtVectorType>(Result)) {
4833 DependentSizedExtVectorTypeLoc NewTL
4834 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4835 NewTL.setNameLoc(TL.getNameLoc());
4837 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4838 NewTL.setNameLoc(TL.getNameLoc());
4844 template <typename Derived>
4845 QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4846 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4847 const DependentAddressSpaceType *T = TL.getTypePtr();
4849 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4851 if (pointeeType.isNull())
4854 // Address spaces are constant expressions.
4855 EnterExpressionEvaluationContext Unevaluated(
4856 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4858 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4859 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4860 if (AddrSpace.isInvalid())
4863 QualType Result = TL.getType();
4864 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4865 AddrSpace.get() != T->getAddrSpaceExpr()) {
4866 Result = getDerived().RebuildDependentAddressSpaceType(
4867 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4868 if (Result.isNull())
4872 // Result might be dependent or not.
4873 if (isa<DependentAddressSpaceType>(Result)) {
4874 DependentAddressSpaceTypeLoc NewTL =
4875 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4877 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4878 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4879 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4882 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4883 Result, getDerived().getBaseLocation());
4884 TransformType(TLB, DI->getTypeLoc());
4890 template <typename Derived>
4891 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4893 const VectorType *T = TL.getTypePtr();
4894 QualType ElementType = getDerived().TransformType(T->getElementType());
4895 if (ElementType.isNull())
4898 QualType Result = TL.getType();
4899 if (getDerived().AlwaysRebuild() ||
4900 ElementType != T->getElementType()) {
4901 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4902 T->getVectorKind());
4903 if (Result.isNull())
4907 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4908 NewTL.setNameLoc(TL.getNameLoc());
4913 template<typename Derived>
4914 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4915 ExtVectorTypeLoc TL) {
4916 const VectorType *T = TL.getTypePtr();
4917 QualType ElementType = getDerived().TransformType(T->getElementType());
4918 if (ElementType.isNull())
4921 QualType Result = TL.getType();
4922 if (getDerived().AlwaysRebuild() ||
4923 ElementType != T->getElementType()) {
4924 Result = getDerived().RebuildExtVectorType(ElementType,
4925 T->getNumElements(),
4926 /*FIXME*/ SourceLocation());
4927 if (Result.isNull())
4931 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4932 NewTL.setNameLoc(TL.getNameLoc());
4937 template <typename Derived>
4938 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4939 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4940 bool ExpectParameterPack) {
4941 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4942 TypeSourceInfo *NewDI = nullptr;
4944 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4945 // If we're substituting into a pack expansion type and we know the
4946 // length we want to expand to, just substitute for the pattern.
4947 TypeLoc OldTL = OldDI->getTypeLoc();
4948 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4951 TypeLoc NewTL = OldDI->getTypeLoc();
4952 TLB.reserve(NewTL.getFullDataSize());
4954 QualType Result = getDerived().TransformType(TLB,
4955 OldExpansionTL.getPatternLoc());
4956 if (Result.isNull())
4959 Result = RebuildPackExpansionType(Result,
4960 OldExpansionTL.getPatternLoc().getSourceRange(),
4961 OldExpansionTL.getEllipsisLoc(),
4963 if (Result.isNull())
4966 PackExpansionTypeLoc NewExpansionTL
4967 = TLB.push<PackExpansionTypeLoc>(Result);
4968 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4969 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4971 NewDI = getDerived().TransformType(OldDI);
4975 if (NewDI == OldDI && indexAdjustment == 0)
4978 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4979 OldParm->getDeclContext(),
4980 OldParm->getInnerLocStart(),
4981 OldParm->getLocation(),
4982 OldParm->getIdentifier(),
4985 OldParm->getStorageClass(),
4986 /* DefArg */ nullptr);
4987 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4988 OldParm->getFunctionScopeIndex() + indexAdjustment);
4992 template <typename Derived>
4993 bool TreeTransform<Derived>::TransformFunctionTypeParams(
4994 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4995 const QualType *ParamTypes,
4996 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4997 SmallVectorImpl<QualType> &OutParamTypes,
4998 SmallVectorImpl<ParmVarDecl *> *PVars,
4999 Sema::ExtParameterInfoBuilder &PInfos) {
5000 int indexAdjustment = 0;
5002 unsigned NumParams = Params.size();
5003 for (unsigned i = 0; i != NumParams; ++i) {
5004 if (ParmVarDecl *OldParm = Params[i]) {
5005 assert(OldParm->getFunctionScopeIndex() == i);
5007 Optional<unsigned> NumExpansions;
5008 ParmVarDecl *NewParm = nullptr;
5009 if (OldParm->isParameterPack()) {
5010 // We have a function parameter pack that may need to be expanded.
5011 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5013 // Find the parameter packs that could be expanded.
5014 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
5015 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
5016 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5017 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
5018 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5020 // Determine whether we should expand the parameter packs.
5021 bool ShouldExpand = false;
5022 bool RetainExpansion = false;
5023 Optional<unsigned> OrigNumExpansions =
5024 ExpansionTL.getTypePtr()->getNumExpansions();
5025 NumExpansions = OrigNumExpansions;
5026 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5027 Pattern.getSourceRange(),
5036 // Expand the function parameter pack into multiple, separate
5038 getDerived().ExpandingFunctionParameterPack(OldParm);
5039 for (unsigned I = 0; I != *NumExpansions; ++I) {
5040 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5041 ParmVarDecl *NewParm
5042 = getDerived().TransformFunctionTypeParam(OldParm,
5045 /*ExpectParameterPack=*/false);
5050 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5051 OutParamTypes.push_back(NewParm->getType());
5053 PVars->push_back(NewParm);
5056 // If we're supposed to retain a pack expansion, do so by temporarily
5057 // forgetting the partially-substituted parameter pack.
5058 if (RetainExpansion) {
5059 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5060 ParmVarDecl *NewParm
5061 = getDerived().TransformFunctionTypeParam(OldParm,
5064 /*ExpectParameterPack=*/false);
5069 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5070 OutParamTypes.push_back(NewParm->getType());
5072 PVars->push_back(NewParm);
5075 // The next parameter should have the same adjustment as the
5076 // last thing we pushed, but we post-incremented indexAdjustment
5077 // on every push. Also, if we push nothing, the adjustment should
5081 // We're done with the pack expansion.
5085 // We'll substitute the parameter now without expanding the pack
5087 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5088 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
5091 /*ExpectParameterPack=*/true);
5093 NewParm = getDerived().TransformFunctionTypeParam(
5094 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
5101 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5102 OutParamTypes.push_back(NewParm->getType());
5104 PVars->push_back(NewParm);
5108 // Deal with the possibility that we don't have a parameter
5109 // declaration for this parameter.
5110 QualType OldType = ParamTypes[i];
5111 bool IsPackExpansion = false;
5112 Optional<unsigned> NumExpansions;
5114 if (const PackExpansionType *Expansion
5115 = dyn_cast<PackExpansionType>(OldType)) {
5116 // We have a function parameter pack that may need to be expanded.
5117 QualType Pattern = Expansion->getPattern();
5118 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5119 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5121 // Determine whether we should expand the parameter packs.
5122 bool ShouldExpand = false;
5123 bool RetainExpansion = false;
5124 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
5133 // Expand the function parameter pack into multiple, separate
5135 for (unsigned I = 0; I != *NumExpansions; ++I) {
5136 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5137 QualType NewType = getDerived().TransformType(Pattern);
5138 if (NewType.isNull())
5141 if (NewType->containsUnexpandedParameterPack()) {
5143 getSema().getASTContext().getPackExpansionType(NewType, None);
5145 if (NewType.isNull())
5150 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5151 OutParamTypes.push_back(NewType);
5153 PVars->push_back(nullptr);
5156 // We're done with the pack expansion.
5160 // If we're supposed to retain a pack expansion, do so by temporarily
5161 // forgetting the partially-substituted parameter pack.
5162 if (RetainExpansion) {
5163 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5164 QualType NewType = getDerived().TransformType(Pattern);
5165 if (NewType.isNull())
5169 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5170 OutParamTypes.push_back(NewType);
5172 PVars->push_back(nullptr);
5175 // We'll substitute the parameter now without expanding the pack
5177 OldType = Expansion->getPattern();
5178 IsPackExpansion = true;
5179 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5180 NewType = getDerived().TransformType(OldType);
5182 NewType = getDerived().TransformType(OldType);
5185 if (NewType.isNull())
5188 if (IsPackExpansion)
5189 NewType = getSema().Context.getPackExpansionType(NewType,
5193 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5194 OutParamTypes.push_back(NewType);
5196 PVars->push_back(nullptr);
5201 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5202 if (ParmVarDecl *parm = (*PVars)[i])
5203 assert(parm->getFunctionScopeIndex() == i);
5210 template<typename Derived>
5212 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
5213 FunctionProtoTypeLoc TL) {
5214 SmallVector<QualType, 4> ExceptionStorage;
5215 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
5216 return getDerived().TransformFunctionProtoType(
5217 TLB, TL, nullptr, 0,
5218 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5219 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5220 ExceptionStorage, Changed);
5224 template<typename Derived> template<typename Fn>
5225 QualType TreeTransform<Derived>::TransformFunctionProtoType(
5226 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5227 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
5229 // Transform the parameters and return type.
5231 // We are required to instantiate the params and return type in source order.
5232 // When the function has a trailing return type, we instantiate the
5233 // parameters before the return type, since the return type can then refer
5234 // to the parameters themselves (via decltype, sizeof, etc.).
5236 SmallVector<QualType, 4> ParamTypes;
5237 SmallVector<ParmVarDecl*, 4> ParamDecls;
5238 Sema::ExtParameterInfoBuilder ExtParamInfos;
5239 const FunctionProtoType *T = TL.getTypePtr();
5241 QualType ResultType;
5243 if (T->hasTrailingReturn()) {
5244 if (getDerived().TransformFunctionTypeParams(
5245 TL.getBeginLoc(), TL.getParams(),
5246 TL.getTypePtr()->param_type_begin(),
5247 T->getExtParameterInfosOrNull(),
5248 ParamTypes, &ParamDecls, ExtParamInfos))
5252 // C++11 [expr.prim.general]p3:
5253 // If a declaration declares a member function or member function
5254 // template of a class X, the expression this is a prvalue of type
5255 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
5256 // and the end of the function-definition, member-declarator, or
5258 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
5260 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5261 if (ResultType.isNull())
5266 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5267 if (ResultType.isNull())
5270 if (getDerived().TransformFunctionTypeParams(
5271 TL.getBeginLoc(), TL.getParams(),
5272 TL.getTypePtr()->param_type_begin(),
5273 T->getExtParameterInfosOrNull(),
5274 ParamTypes, &ParamDecls, ExtParamInfos))
5278 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5280 bool EPIChanged = false;
5281 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5284 // Handle extended parameter information.
5285 if (auto NewExtParamInfos =
5286 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5287 if (!EPI.ExtParameterInfos ||
5288 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5289 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5292 EPI.ExtParameterInfos = NewExtParamInfos;
5293 } else if (EPI.ExtParameterInfos) {
5295 EPI.ExtParameterInfos = nullptr;
5298 QualType Result = TL.getType();
5299 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
5300 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
5301 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
5302 if (Result.isNull())
5306 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
5307 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5308 NewTL.setLParenLoc(TL.getLParenLoc());
5309 NewTL.setRParenLoc(TL.getRParenLoc());
5310 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
5311 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5312 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5313 NewTL.setParam(i, ParamDecls[i]);
5318 template<typename Derived>
5319 bool TreeTransform<Derived>::TransformExceptionSpec(
5320 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5321 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5322 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5324 // Instantiate a dynamic noexcept expression, if any.
5325 if (isComputedNoexcept(ESI.Type)) {
5326 EnterExpressionEvaluationContext Unevaluated(
5327 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
5328 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5329 if (NoexceptExpr.isInvalid())
5332 ExceptionSpecificationType EST = ESI.Type;
5334 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
5335 if (NoexceptExpr.isInvalid())
5338 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
5340 ESI.NoexceptExpr = NoexceptExpr.get();
5344 if (ESI.Type != EST_Dynamic)
5347 // Instantiate a dynamic exception specification's type.
5348 for (QualType T : ESI.Exceptions) {
5349 if (const PackExpansionType *PackExpansion =
5350 T->getAs<PackExpansionType>()) {
5353 // We have a pack expansion. Instantiate it.
5354 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5355 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5357 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5359 // Determine whether the set of unexpanded parameter packs can and
5362 bool Expand = false;
5363 bool RetainExpansion = false;
5364 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5365 // FIXME: Track the location of the ellipsis (and track source location
5366 // information for the types in the exception specification in general).
5367 if (getDerived().TryExpandParameterPacks(
5368 Loc, SourceRange(), Unexpanded, Expand,
5369 RetainExpansion, NumExpansions))
5373 // We can't expand this pack expansion into separate arguments yet;
5374 // just substitute into the pattern and create a new pack expansion
5376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5377 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5381 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5382 Exceptions.push_back(U);
5386 // Substitute into the pack expansion pattern for each slice of the
5388 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5389 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5391 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5392 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5395 Exceptions.push_back(U);
5398 QualType U = getDerived().TransformType(T);
5399 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5404 Exceptions.push_back(U);
5408 ESI.Exceptions = Exceptions;
5409 if (ESI.Exceptions.empty())
5410 ESI.Type = EST_DynamicNone;
5414 template<typename Derived>
5415 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
5416 TypeLocBuilder &TLB,
5417 FunctionNoProtoTypeLoc TL) {
5418 const FunctionNoProtoType *T = TL.getTypePtr();
5419 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5420 if (ResultType.isNull())
5423 QualType Result = TL.getType();
5424 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5425 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5427 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5428 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5429 NewTL.setLParenLoc(TL.getLParenLoc());
5430 NewTL.setRParenLoc(TL.getRParenLoc());
5431 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5436 template<typename Derived> QualType
5437 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5438 UnresolvedUsingTypeLoc TL) {
5439 const UnresolvedUsingType *T = TL.getTypePtr();
5440 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5444 QualType Result = TL.getType();
5445 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5446 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
5447 if (Result.isNull())
5451 // We might get an arbitrary type spec type back. We should at
5452 // least always get a type spec type, though.
5453 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5454 NewTL.setNameLoc(TL.getNameLoc());
5459 template<typename Derived>
5460 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5461 TypedefTypeLoc TL) {
5462 const TypedefType *T = TL.getTypePtr();
5463 TypedefNameDecl *Typedef
5464 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5469 QualType Result = TL.getType();
5470 if (getDerived().AlwaysRebuild() ||
5471 Typedef != T->getDecl()) {
5472 Result = getDerived().RebuildTypedefType(Typedef);
5473 if (Result.isNull())
5477 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5478 NewTL.setNameLoc(TL.getNameLoc());
5483 template<typename Derived>
5484 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5485 TypeOfExprTypeLoc TL) {
5486 // typeof expressions are not potentially evaluated contexts
5487 EnterExpressionEvaluationContext Unevaluated(
5488 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5489 Sema::ReuseLambdaContextDecl);
5491 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5495 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5499 QualType Result = TL.getType();
5500 if (getDerived().AlwaysRebuild() ||
5501 E.get() != TL.getUnderlyingExpr()) {
5502 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5503 if (Result.isNull())
5508 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5509 NewTL.setTypeofLoc(TL.getTypeofLoc());
5510 NewTL.setLParenLoc(TL.getLParenLoc());
5511 NewTL.setRParenLoc(TL.getRParenLoc());
5516 template<typename Derived>
5517 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5519 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5520 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5524 QualType Result = TL.getType();
5525 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5526 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5527 if (Result.isNull())
5531 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5532 NewTL.setTypeofLoc(TL.getTypeofLoc());
5533 NewTL.setLParenLoc(TL.getLParenLoc());
5534 NewTL.setRParenLoc(TL.getRParenLoc());
5535 NewTL.setUnderlyingTInfo(New_Under_TI);
5540 template<typename Derived>
5541 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5542 DecltypeTypeLoc TL) {
5543 const DecltypeType *T = TL.getTypePtr();
5545 // decltype expressions are not potentially evaluated contexts
5546 EnterExpressionEvaluationContext Unevaluated(
5547 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
5548 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
5550 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5554 E = getSema().ActOnDecltypeExpression(E.get());
5558 QualType Result = TL.getType();
5559 if (getDerived().AlwaysRebuild() ||
5560 E.get() != T->getUnderlyingExpr()) {
5561 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5562 if (Result.isNull())
5567 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5568 NewTL.setNameLoc(TL.getNameLoc());
5573 template<typename Derived>
5574 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5575 TypeLocBuilder &TLB,
5576 UnaryTransformTypeLoc TL) {
5577 QualType Result = TL.getType();
5578 if (Result->isDependentType()) {
5579 const UnaryTransformType *T = TL.getTypePtr();
5581 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5582 Result = getDerived().RebuildUnaryTransformType(NewBase,
5585 if (Result.isNull())
5589 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5590 NewTL.setKWLoc(TL.getKWLoc());
5591 NewTL.setParensRange(TL.getParensRange());
5592 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5596 template<typename Derived>
5597 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5599 const AutoType *T = TL.getTypePtr();
5600 QualType OldDeduced = T->getDeducedType();
5601 QualType NewDeduced;
5602 if (!OldDeduced.isNull()) {
5603 NewDeduced = getDerived().TransformType(OldDeduced);
5604 if (NewDeduced.isNull())
5608 QualType Result = TL.getType();
5609 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5610 T->isDependentType()) {
5611 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5612 if (Result.isNull())
5616 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5617 NewTL.setNameLoc(TL.getNameLoc());
5622 template<typename Derived>
5623 QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5624 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5625 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5628 TemplateName TemplateName = getDerived().TransformTemplateName(
5629 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5630 if (TemplateName.isNull())
5633 QualType OldDeduced = T->getDeducedType();
5634 QualType NewDeduced;
5635 if (!OldDeduced.isNull()) {
5636 NewDeduced = getDerived().TransformType(OldDeduced);
5637 if (NewDeduced.isNull())
5641 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5642 TemplateName, NewDeduced);
5643 if (Result.isNull())
5646 DeducedTemplateSpecializationTypeLoc NewTL =
5647 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5648 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5653 template<typename Derived>
5654 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5656 const RecordType *T = TL.getTypePtr();
5658 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5663 QualType Result = TL.getType();
5664 if (getDerived().AlwaysRebuild() ||
5665 Record != T->getDecl()) {
5666 Result = getDerived().RebuildRecordType(Record);
5667 if (Result.isNull())
5671 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5672 NewTL.setNameLoc(TL.getNameLoc());
5677 template<typename Derived>
5678 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5680 const EnumType *T = TL.getTypePtr();
5682 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5687 QualType Result = TL.getType();
5688 if (getDerived().AlwaysRebuild() ||
5689 Enum != T->getDecl()) {
5690 Result = getDerived().RebuildEnumType(Enum);
5691 if (Result.isNull())
5695 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5696 NewTL.setNameLoc(TL.getNameLoc());
5701 template<typename Derived>
5702 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5703 TypeLocBuilder &TLB,
5704 InjectedClassNameTypeLoc TL) {
5705 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5706 TL.getTypePtr()->getDecl());
5707 if (!D) return QualType();
5709 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5710 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5714 template<typename Derived>
5715 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5716 TypeLocBuilder &TLB,
5717 TemplateTypeParmTypeLoc TL) {
5718 return TransformTypeSpecType(TLB, TL);
5721 template<typename Derived>
5722 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5723 TypeLocBuilder &TLB,
5724 SubstTemplateTypeParmTypeLoc TL) {
5725 const SubstTemplateTypeParmType *T = TL.getTypePtr();
5727 // Substitute into the replacement type, which itself might involve something
5728 // that needs to be transformed. This only tends to occur with default
5729 // template arguments of template template parameters.
5730 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5731 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5732 if (Replacement.isNull())
5735 // Always canonicalize the replacement type.
5736 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5738 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5741 // Propagate type-source information.
5742 SubstTemplateTypeParmTypeLoc NewTL
5743 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5744 NewTL.setNameLoc(TL.getNameLoc());
5749 template<typename Derived>
5750 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5751 TypeLocBuilder &TLB,
5752 SubstTemplateTypeParmPackTypeLoc TL) {
5753 return TransformTypeSpecType(TLB, TL);
5756 template<typename Derived>
5757 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5758 TypeLocBuilder &TLB,
5759 TemplateSpecializationTypeLoc TL) {
5760 const TemplateSpecializationType *T = TL.getTypePtr();
5762 // The nested-name-specifier never matters in a TemplateSpecializationType,
5763 // because we can't have a dependent nested-name-specifier anyway.
5765 TemplateName Template
5766 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5767 TL.getTemplateNameLoc());
5768 if (Template.isNull())
5771 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5774 template<typename Derived>
5775 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5777 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5778 if (ValueType.isNull())
5781 QualType Result = TL.getType();
5782 if (getDerived().AlwaysRebuild() ||
5783 ValueType != TL.getValueLoc().getType()) {
5784 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5785 if (Result.isNull())
5789 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5790 NewTL.setKWLoc(TL.getKWLoc());
5791 NewTL.setLParenLoc(TL.getLParenLoc());
5792 NewTL.setRParenLoc(TL.getRParenLoc());
5797 template <typename Derived>
5798 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5800 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5801 if (ValueType.isNull())
5804 QualType Result = TL.getType();
5805 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5806 const PipeType *PT = Result->getAs<PipeType>();
5807 bool isReadPipe = PT->isReadOnly();
5808 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
5809 if (Result.isNull())
5813 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5814 NewTL.setKWLoc(TL.getKWLoc());
5819 /// Simple iterator that traverses the template arguments in a
5820 /// container that provides a \c getArgLoc() member function.
5822 /// This iterator is intended to be used with the iterator form of
5823 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5824 template<typename ArgLocContainer>
5825 class TemplateArgumentLocContainerIterator {
5826 ArgLocContainer *Container;
5830 typedef TemplateArgumentLoc value_type;
5831 typedef TemplateArgumentLoc reference;
5832 typedef int difference_type;
5833 typedef std::input_iterator_tag iterator_category;
5836 TemplateArgumentLoc Arg;
5839 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5841 const TemplateArgumentLoc *operator->() const {
5847 TemplateArgumentLocContainerIterator() {}
5849 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5851 : Container(&Container), Index(Index) { }
5853 TemplateArgumentLocContainerIterator &operator++() {
5858 TemplateArgumentLocContainerIterator operator++(int) {
5859 TemplateArgumentLocContainerIterator Old(*this);
5864 TemplateArgumentLoc operator*() const {
5865 return Container->getArgLoc(Index);
5868 pointer operator->() const {
5869 return pointer(Container->getArgLoc(Index));
5872 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
5873 const TemplateArgumentLocContainerIterator &Y) {
5874 return X.Container == Y.Container && X.Index == Y.Index;
5877 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
5878 const TemplateArgumentLocContainerIterator &Y) {
5884 template <typename Derived>
5885 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5886 TypeLocBuilder &TLB,
5887 TemplateSpecializationTypeLoc TL,
5888 TemplateName Template) {
5889 TemplateArgumentListInfo NewTemplateArgs;
5890 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5891 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5892 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5894 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5895 ArgIterator(TL, TL.getNumArgs()),
5899 // FIXME: maybe don't rebuild if all the template arguments are the same.
5902 getDerived().RebuildTemplateSpecializationType(Template,
5903 TL.getTemplateNameLoc(),
5906 if (!Result.isNull()) {
5907 // Specializations of template template parameters are represented as
5908 // TemplateSpecializationTypes, and substitution of type alias templates
5909 // within a dependent context can transform them into
5910 // DependentTemplateSpecializationTypes.
5911 if (isa<DependentTemplateSpecializationType>(Result)) {
5912 DependentTemplateSpecializationTypeLoc NewTL
5913 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5914 NewTL.setElaboratedKeywordLoc(SourceLocation());
5915 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5916 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5917 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5918 NewTL.setLAngleLoc(TL.getLAngleLoc());
5919 NewTL.setRAngleLoc(TL.getRAngleLoc());
5920 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5921 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5925 TemplateSpecializationTypeLoc NewTL
5926 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5927 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5928 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5929 NewTL.setLAngleLoc(TL.getLAngleLoc());
5930 NewTL.setRAngleLoc(TL.getRAngleLoc());
5931 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5932 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5938 template <typename Derived>
5939 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5940 TypeLocBuilder &TLB,
5941 DependentTemplateSpecializationTypeLoc TL,
5942 TemplateName Template,
5944 TemplateArgumentListInfo NewTemplateArgs;
5945 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5946 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5947 typedef TemplateArgumentLocContainerIterator<
5948 DependentTemplateSpecializationTypeLoc> ArgIterator;
5949 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5950 ArgIterator(TL, TL.getNumArgs()),
5954 // FIXME: maybe don't rebuild if all the template arguments are the same.
5956 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5958 = getSema().Context.getDependentTemplateSpecializationType(
5959 TL.getTypePtr()->getKeyword(),
5960 DTN->getQualifier(),
5961 DTN->getIdentifier(),
5964 DependentTemplateSpecializationTypeLoc NewTL
5965 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5966 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5967 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5968 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5969 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5970 NewTL.setLAngleLoc(TL.getLAngleLoc());
5971 NewTL.setRAngleLoc(TL.getRAngleLoc());
5972 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5973 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5978 = getDerived().RebuildTemplateSpecializationType(Template,
5979 TL.getTemplateNameLoc(),
5982 if (!Result.isNull()) {
5983 /// FIXME: Wrap this in an elaborated-type-specifier?
5984 TemplateSpecializationTypeLoc NewTL
5985 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5986 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5987 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5988 NewTL.setLAngleLoc(TL.getLAngleLoc());
5989 NewTL.setRAngleLoc(TL.getRAngleLoc());
5990 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5991 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5997 template<typename Derived>
5999 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
6000 ElaboratedTypeLoc TL) {
6001 const ElaboratedType *T = TL.getTypePtr();
6003 NestedNameSpecifierLoc QualifierLoc;
6004 // NOTE: the qualifier in an ElaboratedType is optional.
6005 if (TL.getQualifierLoc()) {
6007 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6012 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6013 if (NamedT.isNull())
6016 // C++0x [dcl.type.elab]p2:
6017 // If the identifier resolves to a typedef-name or the simple-template-id
6018 // resolves to an alias template specialization, the
6019 // elaborated-type-specifier is ill-formed.
6020 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6021 if (const TemplateSpecializationType *TST =
6022 NamedT->getAs<TemplateSpecializationType>()) {
6023 TemplateName Template = TST->getTemplateName();
6024 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6025 Template.getAsTemplateDecl())) {
6026 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
6027 diag::err_tag_reference_non_tag)
6028 << TAT << Sema::NTK_TypeAliasTemplate
6029 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
6030 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6035 QualType Result = TL.getType();
6036 if (getDerived().AlwaysRebuild() ||
6037 QualifierLoc != TL.getQualifierLoc() ||
6038 NamedT != T->getNamedType()) {
6039 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
6041 QualifierLoc, NamedT);
6042 if (Result.isNull())
6046 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6047 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6048 NewTL.setQualifierLoc(QualifierLoc);
6052 template<typename Derived>
6053 QualType TreeTransform<Derived>::TransformAttributedType(
6054 TypeLocBuilder &TLB,
6055 AttributedTypeLoc TL) {
6056 const AttributedType *oldType = TL.getTypePtr();
6057 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6058 if (modifiedType.isNull())
6061 QualType result = TL.getType();
6063 // FIXME: dependent operand expressions?
6064 if (getDerived().AlwaysRebuild() ||
6065 modifiedType != oldType->getModifiedType()) {
6066 // TODO: this is really lame; we should really be rebuilding the
6067 // equivalent type from first principles.
6068 QualType equivalentType
6069 = getDerived().TransformType(oldType->getEquivalentType());
6070 if (equivalentType.isNull())
6073 // Check whether we can add nullability; it is only represented as
6074 // type sugar, and therefore cannot be diagnosed in any other way.
6075 if (auto nullability = oldType->getImmediateNullability()) {
6076 if (!modifiedType->canHaveNullability()) {
6077 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
6078 << DiagNullabilityKind(*nullability, false) << modifiedType;
6083 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
6088 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
6089 newTL.setAttrNameLoc(TL.getAttrNameLoc());
6090 if (TL.hasAttrOperand())
6091 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6092 if (TL.hasAttrExprOperand())
6093 newTL.setAttrExprOperand(TL.getAttrExprOperand());
6094 else if (TL.hasAttrEnumOperand())
6095 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
6100 template<typename Derived>
6102 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6104 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6108 QualType Result = TL.getType();
6109 if (getDerived().AlwaysRebuild() ||
6110 Inner != TL.getInnerLoc().getType()) {
6111 Result = getDerived().RebuildParenType(Inner);
6112 if (Result.isNull())
6116 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6117 NewTL.setLParenLoc(TL.getLParenLoc());
6118 NewTL.setRParenLoc(TL.getRParenLoc());
6122 template<typename Derived>
6123 QualType TreeTransform<Derived>::TransformDependentNameType(
6124 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6125 return TransformDependentNameType(TLB, TL, false);
6128 template<typename Derived>
6129 QualType TreeTransform<Derived>::TransformDependentNameType(
6130 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
6131 const DependentNameType *T = TL.getTypePtr();
6133 NestedNameSpecifierLoc QualifierLoc
6134 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6139 = getDerived().RebuildDependentNameType(T->getKeyword(),
6140 TL.getElaboratedKeywordLoc(),
6145 if (Result.isNull())
6148 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6149 QualType NamedT = ElabT->getNamedType();
6150 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6152 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6153 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6154 NewTL.setQualifierLoc(QualifierLoc);
6156 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
6157 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6158 NewTL.setQualifierLoc(QualifierLoc);
6159 NewTL.setNameLoc(TL.getNameLoc());
6164 template<typename Derived>
6165 QualType TreeTransform<Derived>::
6166 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6167 DependentTemplateSpecializationTypeLoc TL) {
6168 NestedNameSpecifierLoc QualifierLoc;
6169 if (TL.getQualifierLoc()) {
6171 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6177 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
6180 template<typename Derived>
6181 QualType TreeTransform<Derived>::
6182 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6183 DependentTemplateSpecializationTypeLoc TL,
6184 NestedNameSpecifierLoc QualifierLoc) {
6185 const DependentTemplateSpecializationType *T = TL.getTypePtr();
6187 TemplateArgumentListInfo NewTemplateArgs;
6188 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6189 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6191 typedef TemplateArgumentLocContainerIterator<
6192 DependentTemplateSpecializationTypeLoc> ArgIterator;
6193 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6194 ArgIterator(TL, TL.getNumArgs()),
6198 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6199 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6200 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
6201 /*AllowInjectedClassName*/ false);
6202 if (Result.isNull())
6205 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6206 QualType NamedT = ElabT->getNamedType();
6208 // Copy information relevant to the template specialization.
6209 TemplateSpecializationTypeLoc NamedTL
6210 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
6211 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6212 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6213 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6214 NamedTL.setRAngleLoc(TL.getRAngleLoc());
6215 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6216 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6218 // Copy information relevant to the elaborated type.
6219 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6220 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6221 NewTL.setQualifierLoc(QualifierLoc);
6222 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6223 DependentTemplateSpecializationTypeLoc SpecTL
6224 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
6225 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6226 SpecTL.setQualifierLoc(QualifierLoc);
6227 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6228 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6229 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6230 SpecTL.setRAngleLoc(TL.getRAngleLoc());
6231 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6232 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6234 TemplateSpecializationTypeLoc SpecTL
6235 = TLB.push<TemplateSpecializationTypeLoc>(Result);
6236 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
6237 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6238 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6239 SpecTL.setRAngleLoc(TL.getRAngleLoc());
6240 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6241 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6246 template<typename Derived>
6247 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6248 PackExpansionTypeLoc TL) {
6250 = getDerived().TransformType(TLB, TL.getPatternLoc());
6251 if (Pattern.isNull())
6254 QualType Result = TL.getType();
6255 if (getDerived().AlwaysRebuild() ||
6256 Pattern != TL.getPatternLoc().getType()) {
6257 Result = getDerived().RebuildPackExpansionType(Pattern,
6258 TL.getPatternLoc().getSourceRange(),
6259 TL.getEllipsisLoc(),
6260 TL.getTypePtr()->getNumExpansions());
6261 if (Result.isNull())
6265 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6266 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6270 template<typename Derived>
6272 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
6273 ObjCInterfaceTypeLoc TL) {
6274 // ObjCInterfaceType is never dependent.
6275 TLB.pushFullCopy(TL);
6276 return TL.getType();
6279 template<typename Derived>
6281 TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6282 ObjCTypeParamTypeLoc TL) {
6283 const ObjCTypeParamType *T = TL.getTypePtr();
6284 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6285 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6289 QualType Result = TL.getType();
6290 if (getDerived().AlwaysRebuild() ||
6291 OTP != T->getDecl()) {
6292 Result = getDerived().RebuildObjCTypeParamType(OTP,
6293 TL.getProtocolLAngleLoc(),
6294 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6295 TL.getNumProtocols()),
6296 TL.getProtocolLocs(),
6297 TL.getProtocolRAngleLoc());
6298 if (Result.isNull())
6302 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6303 if (TL.getNumProtocols()) {
6304 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6305 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6306 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6307 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6312 template<typename Derived>
6314 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
6315 ObjCObjectTypeLoc TL) {
6316 // Transform base type.
6317 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6318 if (BaseType.isNull())
6321 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6323 // Transform type arguments.
6324 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6325 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6326 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6327 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6328 QualType TypeArg = TypeArgInfo->getType();
6329 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6332 // We have a pack expansion. Instantiate it.
6333 const auto *PackExpansion = PackExpansionLoc.getType()
6334 ->castAs<PackExpansionType>();
6335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6336 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6338 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6340 // Determine whether the set of unexpanded parameter packs can
6341 // and should be expanded.
6342 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6343 bool Expand = false;
6344 bool RetainExpansion = false;
6345 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6346 if (getDerived().TryExpandParameterPacks(
6347 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6348 Unexpanded, Expand, RetainExpansion, NumExpansions))
6352 // We can't expand this pack expansion into separate arguments yet;
6353 // just substitute into the pattern and create a new pack expansion
6355 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6357 TypeLocBuilder TypeArgBuilder;
6358 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6359 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6361 if (NewPatternType.isNull())
6364 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6365 NewPatternType, NumExpansions);
6366 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6367 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6368 NewTypeArgInfos.push_back(
6369 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6373 // Substitute into the pack expansion pattern for each slice of the
6375 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6378 TypeLocBuilder TypeArgBuilder;
6379 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6381 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6383 if (NewTypeArg.isNull())
6386 NewTypeArgInfos.push_back(
6387 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6393 TypeLocBuilder TypeArgBuilder;
6394 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6395 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6396 if (NewTypeArg.isNull())
6399 // If nothing changed, just keep the old TypeSourceInfo.
6400 if (NewTypeArg == TypeArg) {
6401 NewTypeArgInfos.push_back(TypeArgInfo);
6405 NewTypeArgInfos.push_back(
6406 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6410 QualType Result = TL.getType();
6411 if (getDerived().AlwaysRebuild() || AnyChanged) {
6412 // Rebuild the type.
6413 Result = getDerived().RebuildObjCObjectType(
6416 TL.getTypeArgsLAngleLoc(),
6418 TL.getTypeArgsRAngleLoc(),
6419 TL.getProtocolLAngleLoc(),
6420 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6421 TL.getNumProtocols()),
6422 TL.getProtocolLocs(),
6423 TL.getProtocolRAngleLoc());
6425 if (Result.isNull())
6429 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
6430 NewT.setHasBaseTypeAsWritten(true);
6431 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6432 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6433 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6434 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6435 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6436 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6437 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6438 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6442 template<typename Derived>
6444 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
6445 ObjCObjectPointerTypeLoc TL) {
6446 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6447 if (PointeeType.isNull())
6450 QualType Result = TL.getType();
6451 if (getDerived().AlwaysRebuild() ||
6452 PointeeType != TL.getPointeeLoc().getType()) {
6453 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6455 if (Result.isNull())
6459 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6460 NewT.setStarLoc(TL.getStarLoc());
6464 //===----------------------------------------------------------------------===//
6465 // Statement transformation
6466 //===----------------------------------------------------------------------===//
6467 template<typename Derived>
6469 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
6473 template<typename Derived>
6475 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6476 return getDerived().TransformCompoundStmt(S, false);
6479 template<typename Derived>
6481 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
6483 Sema::CompoundScopeRAII CompoundScope(getSema());
6485 bool SubStmtInvalid = false;
6486 bool SubStmtChanged = false;
6487 SmallVector<Stmt*, 8> Statements;
6488 for (auto *B : S->body()) {
6489 StmtResult Result = getDerived().TransformStmt(B);
6490 if (Result.isInvalid()) {
6491 // Immediately fail if this was a DeclStmt, since it's very
6492 // likely that this will cause problems for future statements.
6493 if (isa<DeclStmt>(B))
6496 // Otherwise, just keep processing substatements and fail later.
6497 SubStmtInvalid = true;
6501 SubStmtChanged = SubStmtChanged || Result.get() != B;
6502 Statements.push_back(Result.getAs<Stmt>());
6508 if (!getDerived().AlwaysRebuild() &&
6512 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6518 template<typename Derived>
6520 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6521 ExprResult LHS, RHS;
6523 EnterExpressionEvaluationContext Unevaluated(
6524 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
6526 // Transform the left-hand case value.
6527 LHS = getDerived().TransformExpr(S->getLHS());
6528 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
6529 if (LHS.isInvalid())
6532 // Transform the right-hand case value (for the GNU case-range extension).
6533 RHS = getDerived().TransformExpr(S->getRHS());
6534 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
6535 if (RHS.isInvalid())
6539 // Build the case statement.
6540 // Case statements are always rebuilt so that they will attached to their
6541 // transformed switch statement.
6542 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6544 S->getEllipsisLoc(),
6547 if (Case.isInvalid())
6550 // Transform the statement following the case
6551 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6552 if (SubStmt.isInvalid())
6555 // Attach the body to the case statement
6556 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6559 template<typename Derived>
6561 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6562 // Transform the statement following the default case
6563 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6564 if (SubStmt.isInvalid())
6567 // Default statements are always rebuilt
6568 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6572 template<typename Derived>
6574 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6575 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6576 if (SubStmt.isInvalid())
6579 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6585 // FIXME: Pass the real colon location in.
6586 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6587 cast<LabelDecl>(LD), SourceLocation(),
6591 template <typename Derived>
6592 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6596 switch (R->getKind()) {
6597 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6599 #define PRAGMA_SPELLING_ATTR(X) \
6601 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6602 #include "clang/Basic/AttrList.inc"
6608 template <typename Derived>
6609 StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6610 bool AttrsChanged = false;
6611 SmallVector<const Attr *, 1> Attrs;
6613 // Visit attributes and keep track if any are transformed.
6614 for (const auto *I : S->getAttrs()) {
6615 const Attr *R = getDerived().TransformAttr(I);
6616 AttrsChanged |= (I != R);
6620 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6621 if (SubStmt.isInvalid())
6624 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6627 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6631 template<typename Derived>
6633 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6634 // Transform the initialization statement
6635 StmtResult Init = getDerived().TransformStmt(S->getInit());
6636 if (Init.isInvalid())
6639 // Transform the condition
6640 Sema::ConditionResult Cond = getDerived().TransformCondition(
6641 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6642 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6643 : Sema::ConditionKind::Boolean);
6644 if (Cond.isInvalid())
6647 // If this is a constexpr if, determine which arm we should instantiate.
6648 llvm::Optional<bool> ConstexprConditionValue;
6649 if (S->isConstexpr())
6650 ConstexprConditionValue = Cond.getKnownValue();
6652 // Transform the "then" branch.
6654 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6655 Then = getDerived().TransformStmt(S->getThen());
6656 if (Then.isInvalid())
6659 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6662 // Transform the "else" branch.
6664 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6665 Else = getDerived().TransformStmt(S->getElse());
6666 if (Else.isInvalid())
6670 if (!getDerived().AlwaysRebuild() &&
6671 Init.get() == S->getInit() &&
6672 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6673 Then.get() == S->getThen() &&
6674 Else.get() == S->getElse())
6677 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6678 Init.get(), Then.get(), S->getElseLoc(),
6682 template<typename Derived>
6684 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6685 // Transform the initialization statement
6686 StmtResult Init = getDerived().TransformStmt(S->getInit());
6687 if (Init.isInvalid())
6690 // Transform the condition.
6691 Sema::ConditionResult Cond = getDerived().TransformCondition(
6692 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6693 Sema::ConditionKind::Switch);
6694 if (Cond.isInvalid())
6697 // Rebuild the switch statement.
6699 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
6700 if (Switch.isInvalid())
6703 // Transform the body of the switch statement.
6704 StmtResult Body = getDerived().TransformStmt(S->getBody());
6705 if (Body.isInvalid())
6708 // Complete the switch statement.
6709 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6713 template<typename Derived>
6715 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6716 // Transform the condition
6717 Sema::ConditionResult Cond = getDerived().TransformCondition(
6718 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6719 Sema::ConditionKind::Boolean);
6720 if (Cond.isInvalid())
6723 // Transform the body
6724 StmtResult Body = getDerived().TransformStmt(S->getBody());
6725 if (Body.isInvalid())
6728 if (!getDerived().AlwaysRebuild() &&
6729 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6730 Body.get() == S->getBody())
6733 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
6736 template<typename Derived>
6738 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6739 // Transform the body
6740 StmtResult Body = getDerived().TransformStmt(S->getBody());
6741 if (Body.isInvalid())
6744 // Transform the condition
6745 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6746 if (Cond.isInvalid())
6749 if (!getDerived().AlwaysRebuild() &&
6750 Cond.get() == S->getCond() &&
6751 Body.get() == S->getBody())
6754 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6755 /*FIXME:*/S->getWhileLoc(), Cond.get(),
6759 template<typename Derived>
6761 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6762 // Transform the initialization statement
6763 StmtResult Init = getDerived().TransformStmt(S->getInit());
6764 if (Init.isInvalid())
6767 // In OpenMP loop region loop control variable must be captured and be
6768 // private. Perform analysis of first part (if any).
6769 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6770 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6772 // Transform the condition
6773 Sema::ConditionResult Cond = getDerived().TransformCondition(
6774 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6775 Sema::ConditionKind::Boolean);
6776 if (Cond.isInvalid())
6779 // Transform the increment
6780 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6781 if (Inc.isInvalid())
6784 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6785 if (S->getInc() && !FullInc.get())
6788 // Transform the body
6789 StmtResult Body = getDerived().TransformStmt(S->getBody());
6790 if (Body.isInvalid())
6793 if (!getDerived().AlwaysRebuild() &&
6794 Init.get() == S->getInit() &&
6795 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6796 Inc.get() == S->getInc() &&
6797 Body.get() == S->getBody())
6800 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6801 Init.get(), Cond, FullInc,
6802 S->getRParenLoc(), Body.get());
6805 template<typename Derived>
6807 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6808 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6813 // Goto statements must always be rebuilt, to resolve the label.
6814 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6815 cast<LabelDecl>(LD));
6818 template<typename Derived>
6820 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6821 ExprResult Target = getDerived().TransformExpr(S->getTarget());
6822 if (Target.isInvalid())
6824 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6826 if (!getDerived().AlwaysRebuild() &&
6827 Target.get() == S->getTarget())
6830 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6834 template<typename Derived>
6836 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6840 template<typename Derived>
6842 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6846 template<typename Derived>
6848 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6849 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6850 /*NotCopyInit*/false);
6851 if (Result.isInvalid())
6854 // FIXME: We always rebuild the return statement because there is no way
6855 // to tell whether the return type of the function has changed.
6856 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6859 template<typename Derived>
6861 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6862 bool DeclChanged = false;
6863 SmallVector<Decl *, 4> Decls;
6864 for (auto *D : S->decls()) {
6865 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6869 if (Transformed != D)
6872 Decls.push_back(Transformed);
6875 if (!getDerived().AlwaysRebuild() && !DeclChanged)
6878 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6881 template<typename Derived>
6883 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6885 SmallVector<Expr*, 8> Constraints;
6886 SmallVector<Expr*, 8> Exprs;
6887 SmallVector<IdentifierInfo *, 4> Names;
6889 ExprResult AsmString;
6890 SmallVector<Expr*, 8> Clobbers;
6892 bool ExprsChanged = false;
6894 // Go through the outputs.
6895 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6896 Names.push_back(S->getOutputIdentifier(I));
6898 // No need to transform the constraint literal.
6899 Constraints.push_back(S->getOutputConstraintLiteral(I));
6901 // Transform the output expr.
6902 Expr *OutputExpr = S->getOutputExpr(I);
6903 ExprResult Result = getDerived().TransformExpr(OutputExpr);
6904 if (Result.isInvalid())
6907 ExprsChanged |= Result.get() != OutputExpr;
6909 Exprs.push_back(Result.get());
6912 // Go through the inputs.
6913 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6914 Names.push_back(S->getInputIdentifier(I));
6916 // No need to transform the constraint literal.
6917 Constraints.push_back(S->getInputConstraintLiteral(I));
6919 // Transform the input expr.
6920 Expr *InputExpr = S->getInputExpr(I);
6921 ExprResult Result = getDerived().TransformExpr(InputExpr);
6922 if (Result.isInvalid())
6925 ExprsChanged |= Result.get() != InputExpr;
6927 Exprs.push_back(Result.get());
6930 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6933 // Go through the clobbers.
6934 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6935 Clobbers.push_back(S->getClobberStringLiteral(I));
6937 // No need to transform the asm string literal.
6938 AsmString = S->getAsmString();
6939 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6940 S->isVolatile(), S->getNumOutputs(),
6941 S->getNumInputs(), Names.data(),
6942 Constraints, Exprs, AsmString.get(),
6943 Clobbers, S->getRParenLoc());
6946 template<typename Derived>
6948 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6949 ArrayRef<Token> AsmToks =
6950 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6952 bool HadError = false, HadChange = false;
6954 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6955 SmallVector<Expr*, 8> TransformedExprs;
6956 TransformedExprs.reserve(SrcExprs.size());
6957 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6958 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6959 if (!Result.isUsable()) {
6962 HadChange |= (Result.get() != SrcExprs[i]);
6963 TransformedExprs.push_back(Result.get());
6967 if (HadError) return StmtError();
6968 if (!HadChange && !getDerived().AlwaysRebuild())
6971 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6972 AsmToks, S->getAsmString(),
6973 S->getNumOutputs(), S->getNumInputs(),
6974 S->getAllConstraints(), S->getClobbers(),
6975 TransformedExprs, S->getEndLoc());
6978 // C++ Coroutines TS
6980 template<typename Derived>
6982 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6983 auto *ScopeInfo = SemaRef.getCurFunction();
6984 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
6985 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
6986 ScopeInfo->NeedsCoroutineSuspends &&
6987 ScopeInfo->CoroutineSuspends.first == nullptr &&
6988 ScopeInfo->CoroutineSuspends.second == nullptr &&
6989 "expected clean scope info");
6991 // Set that we have (possibly-invalid) suspend points before we do anything
6993 ScopeInfo->setNeedsCoroutineSuspends(false);
6995 // The new CoroutinePromise object needs to be built and put into the current
6996 // FunctionScopeInfo before any transformations or rebuilding occurs.
6997 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
6999 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7002 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
7003 ScopeInfo->CoroutinePromise = Promise;
7005 // Transform the implicit coroutine statements we built during the initial
7007 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7008 if (InitSuspend.isInvalid())
7010 StmtResult FinalSuspend =
7011 getDerived().TransformStmt(S->getFinalSuspendStmt());
7012 if (FinalSuspend.isInvalid())
7014 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7015 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
7017 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7018 if (BodyRes.isInvalid())
7021 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7022 if (Builder.isInvalid())
7025 Expr *ReturnObject = S->getReturnValueInit();
7026 assert(ReturnObject && "the return object is expected to be valid");
7027 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7028 /*NoCopyInit*/ false);
7029 if (Res.isInvalid())
7031 Builder.ReturnValue = Res.get();
7033 if (S->hasDependentPromiseType()) {
7034 assert(!Promise->getType()->isDependentType() &&
7035 "the promise type must no longer be dependent");
7036 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7037 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7038 "these nodes should not have been built yet");
7039 if (!Builder.buildDependentStatements())
7042 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7043 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7044 if (Res.isInvalid())
7046 Builder.OnFallthrough = Res.get();
7049 if (auto *OnException = S->getExceptionHandler()) {
7050 StmtResult Res = getDerived().TransformStmt(OnException);
7051 if (Res.isInvalid())
7053 Builder.OnException = Res.get();
7056 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7057 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7058 if (Res.isInvalid())
7060 Builder.ReturnStmtOnAllocFailure = Res.get();
7063 // Transform any additional statements we may have already built
7064 assert(S->getAllocate() && S->getDeallocate() &&
7065 "allocation and deallocation calls must already be built");
7066 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7067 if (AllocRes.isInvalid())
7069 Builder.Allocate = AllocRes.get();
7071 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7072 if (DeallocRes.isInvalid())
7074 Builder.Deallocate = DeallocRes.get();
7076 assert(S->getResultDecl() && "ResultDecl must already be built");
7077 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7078 if (ResultDecl.isInvalid())
7080 Builder.ResultDecl = ResultDecl.get();
7082 if (auto *ReturnStmt = S->getReturnStmt()) {
7083 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7084 if (Res.isInvalid())
7086 Builder.ReturnStmt = Res.get();
7090 return getDerived().RebuildCoroutineBodyStmt(Builder);
7093 template<typename Derived>
7095 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7096 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7097 /*NotCopyInit*/false);
7098 if (Result.isInvalid())
7101 // Always rebuild; we don't know if this needs to be injected into a new
7102 // context or if the promise type has changed.
7103 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7107 template<typename Derived>
7109 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7110 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7111 /*NotCopyInit*/false);
7112 if (Result.isInvalid())
7115 // Always rebuild; we don't know if this needs to be injected into a new
7116 // context or if the promise type has changed.
7117 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7121 template <typename Derived>
7123 TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7124 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7125 /*NotCopyInit*/ false);
7126 if (OperandResult.isInvalid())
7129 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7130 E->getOperatorCoawaitLookup());
7132 if (LookupResult.isInvalid())
7135 // Always rebuild; we don't know if this needs to be injected into a new
7136 // context or if the promise type has changed.
7137 return getDerived().RebuildDependentCoawaitExpr(
7138 E->getKeywordLoc(), OperandResult.get(),
7139 cast<UnresolvedLookupExpr>(LookupResult.get()));
7142 template<typename Derived>
7144 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7145 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7146 /*NotCopyInit*/false);
7147 if (Result.isInvalid())
7150 // Always rebuild; we don't know if this needs to be injected into a new
7151 // context or if the promise type has changed.
7152 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7155 // Objective-C Statements.
7157 template<typename Derived>
7159 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
7160 // Transform the body of the @try.
7161 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
7162 if (TryBody.isInvalid())
7165 // Transform the @catch statements (if present).
7166 bool AnyCatchChanged = false;
7167 SmallVector<Stmt*, 8> CatchStmts;
7168 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
7169 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
7170 if (Catch.isInvalid())
7172 if (Catch.get() != S->getCatchStmt(I))
7173 AnyCatchChanged = true;
7174 CatchStmts.push_back(Catch.get());
7177 // Transform the @finally statement (if present).
7179 if (S->getFinallyStmt()) {
7180 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7181 if (Finally.isInvalid())
7185 // If nothing changed, just retain this statement.
7186 if (!getDerived().AlwaysRebuild() &&
7187 TryBody.get() == S->getTryBody() &&
7189 Finally.get() == S->getFinallyStmt())
7192 // Build a new statement.
7193 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
7194 CatchStmts, Finally.get());
7197 template<typename Derived>
7199 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
7200 // Transform the @catch parameter, if there is one.
7201 VarDecl *Var = nullptr;
7202 if (VarDecl *FromVar = S->getCatchParamDecl()) {
7203 TypeSourceInfo *TSInfo = nullptr;
7204 if (FromVar->getTypeSourceInfo()) {
7205 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7212 T = TSInfo->getType();
7214 T = getDerived().TransformType(FromVar->getType());
7219 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7224 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
7225 if (Body.isInvalid())
7228 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
7233 template<typename Derived>
7235 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
7236 // Transform the body.
7237 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
7238 if (Body.isInvalid())
7241 // If nothing changed, just retain this statement.
7242 if (!getDerived().AlwaysRebuild() &&
7243 Body.get() == S->getFinallyBody())
7246 // Build a new statement.
7247 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
7251 template<typename Derived>
7253 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
7255 if (S->getThrowExpr()) {
7256 Operand = getDerived().TransformExpr(S->getThrowExpr());
7257 if (Operand.isInvalid())
7261 if (!getDerived().AlwaysRebuild() &&
7262 Operand.get() == S->getThrowExpr())
7265 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
7268 template<typename Derived>
7270 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
7271 ObjCAtSynchronizedStmt *S) {
7272 // Transform the object we are locking.
7273 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
7274 if (Object.isInvalid())
7277 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7279 if (Object.isInvalid())
7282 // Transform the body.
7283 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
7284 if (Body.isInvalid())
7287 // If nothing change, just retain the current statement.
7288 if (!getDerived().AlwaysRebuild() &&
7289 Object.get() == S->getSynchExpr() &&
7290 Body.get() == S->getSynchBody())
7293 // Build a new statement.
7294 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
7295 Object.get(), Body.get());
7298 template<typename Derived>
7300 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7301 ObjCAutoreleasePoolStmt *S) {
7302 // Transform the body.
7303 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7304 if (Body.isInvalid())
7307 // If nothing changed, just retain this statement.
7308 if (!getDerived().AlwaysRebuild() &&
7309 Body.get() == S->getSubStmt())
7312 // Build a new statement.
7313 return getDerived().RebuildObjCAutoreleasePoolStmt(
7314 S->getAtLoc(), Body.get());
7317 template<typename Derived>
7319 TreeTransform<Derived>::TransformObjCForCollectionStmt(
7320 ObjCForCollectionStmt *S) {
7321 // Transform the element statement.
7322 StmtResult Element = getDerived().TransformStmt(S->getElement());
7323 if (Element.isInvalid())
7326 // Transform the collection expression.
7327 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
7328 if (Collection.isInvalid())
7331 // Transform the body.
7332 StmtResult Body = getDerived().TransformStmt(S->getBody());
7333 if (Body.isInvalid())
7336 // If nothing changed, just retain this statement.
7337 if (!getDerived().AlwaysRebuild() &&
7338 Element.get() == S->getElement() &&
7339 Collection.get() == S->getCollection() &&
7340 Body.get() == S->getBody())
7343 // Build a new statement.
7344 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
7351 template <typename Derived>
7352 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
7353 // Transform the exception declaration, if any.
7354 VarDecl *Var = nullptr;
7355 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7357 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
7361 Var = getDerived().RebuildExceptionDecl(
7362 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7363 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
7364 if (!Var || Var->isInvalidDecl())
7368 // Transform the actual exception handler.
7369 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
7370 if (Handler.isInvalid())
7373 if (!getDerived().AlwaysRebuild() && !Var &&
7374 Handler.get() == S->getHandlerBlock())
7377 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
7380 template <typename Derived>
7381 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
7382 // Transform the try block itself.
7383 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7384 if (TryBlock.isInvalid())
7387 // Transform the handlers.
7388 bool HandlerChanged = false;
7389 SmallVector<Stmt *, 8> Handlers;
7390 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
7391 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
7392 if (Handler.isInvalid())
7395 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
7396 Handlers.push_back(Handler.getAs<Stmt>());
7399 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7403 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
7407 template<typename Derived>
7409 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7410 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7411 if (Range.isInvalid())
7414 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7415 if (Begin.isInvalid())
7417 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7418 if (End.isInvalid())
7421 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7422 if (Cond.isInvalid())
7425 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
7426 if (Cond.isInvalid())
7429 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
7431 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7432 if (Inc.isInvalid())
7435 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
7437 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7438 if (LoopVar.isInvalid())
7441 StmtResult NewStmt = S;
7442 if (getDerived().AlwaysRebuild() ||
7443 Range.get() != S->getRangeStmt() ||
7444 Begin.get() != S->getBeginStmt() ||
7445 End.get() != S->getEndStmt() ||
7446 Cond.get() != S->getCond() ||
7447 Inc.get() != S->getInc() ||
7448 LoopVar.get() != S->getLoopVarStmt()) {
7449 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7451 S->getColonLoc(), Range.get(),
7452 Begin.get(), End.get(),
7454 Inc.get(), LoopVar.get(),
7456 if (NewStmt.isInvalid())
7460 StmtResult Body = getDerived().TransformStmt(S->getBody());
7461 if (Body.isInvalid())
7464 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7465 // it now so we have a new statement to attach the body to.
7466 if (Body.get() != S->getBody() && NewStmt.get() == S) {
7467 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7469 S->getColonLoc(), Range.get(),
7470 Begin.get(), End.get(),
7472 Inc.get(), LoopVar.get(),
7474 if (NewStmt.isInvalid())
7478 if (NewStmt.get() == S)
7481 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7484 template<typename Derived>
7486 TreeTransform<Derived>::TransformMSDependentExistsStmt(
7487 MSDependentExistsStmt *S) {
7488 // Transform the nested-name-specifier, if any.
7489 NestedNameSpecifierLoc QualifierLoc;
7490 if (S->getQualifierLoc()) {
7492 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7497 // Transform the declaration name.
7498 DeclarationNameInfo NameInfo = S->getNameInfo();
7499 if (NameInfo.getName()) {
7500 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7501 if (!NameInfo.getName())
7505 // Check whether anything changed.
7506 if (!getDerived().AlwaysRebuild() &&
7507 QualifierLoc == S->getQualifierLoc() &&
7508 NameInfo.getName() == S->getNameInfo().getName())
7511 // Determine whether this name exists, if we can.
7513 SS.Adopt(QualifierLoc);
7514 bool Dependent = false;
7515 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
7516 case Sema::IER_Exists:
7517 if (S->isIfExists())
7520 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7522 case Sema::IER_DoesNotExist:
7523 if (S->isIfNotExists())
7526 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7528 case Sema::IER_Dependent:
7532 case Sema::IER_Error:
7536 // We need to continue with the instantiation, so do so now.
7537 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7538 if (SubStmt.isInvalid())
7541 // If we have resolved the name, just transform to the substatement.
7545 // The name is still dependent, so build a dependent expression again.
7546 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7553 template<typename Derived>
7555 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7556 NestedNameSpecifierLoc QualifierLoc;
7557 if (E->getQualifierLoc()) {
7559 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7564 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7565 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7569 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7570 if (Base.isInvalid())
7573 return new (SemaRef.getASTContext())
7574 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7575 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7576 QualifierLoc, E->getMemberLoc());
7579 template <typename Derived>
7580 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7581 MSPropertySubscriptExpr *E) {
7582 auto BaseRes = getDerived().TransformExpr(E->getBase());
7583 if (BaseRes.isInvalid())
7585 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7586 if (IdxRes.isInvalid())
7589 if (!getDerived().AlwaysRebuild() &&
7590 BaseRes.get() == E->getBase() &&
7591 IdxRes.get() == E->getIdx())
7594 return getDerived().RebuildArraySubscriptExpr(
7595 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7598 template <typename Derived>
7599 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7600 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7601 if (TryBlock.isInvalid())
7604 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7605 if (Handler.isInvalid())
7608 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7609 Handler.get() == S->getHandler())
7612 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7613 TryBlock.get(), Handler.get());
7616 template <typename Derived>
7617 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7618 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7619 if (Block.isInvalid())
7622 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7625 template <typename Derived>
7626 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7627 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7628 if (FilterExpr.isInvalid())
7631 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7632 if (Block.isInvalid())
7635 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7639 template <typename Derived>
7640 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7641 if (isa<SEHFinallyStmt>(Handler))
7642 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7644 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7647 template<typename Derived>
7649 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7653 //===----------------------------------------------------------------------===//
7654 // OpenMP directive transformation
7655 //===----------------------------------------------------------------------===//
7656 template <typename Derived>
7657 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7658 OMPExecutableDirective *D) {
7660 // Transform the clauses
7661 llvm::SmallVector<OMPClause *, 16> TClauses;
7662 ArrayRef<OMPClause *> Clauses = D->clauses();
7663 TClauses.reserve(Clauses.size());
7664 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7667 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7668 OMPClause *Clause = getDerived().TransformOMPClause(*I);
7669 getDerived().getSema().EndOpenMPClause();
7671 TClauses.push_back(Clause);
7673 TClauses.push_back(nullptr);
7676 StmtResult AssociatedStmt;
7677 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7678 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7679 /*CurScope=*/nullptr);
7682 Sema::CompoundScopeRAII CompoundScope(getSema());
7683 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
7684 Body = getDerived().TransformStmt(CS);
7687 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7688 if (AssociatedStmt.isInvalid()) {
7692 if (TClauses.size() != Clauses.size()) {
7696 // Transform directive name for 'omp critical' directive.
7697 DeclarationNameInfo DirName;
7698 if (D->getDirectiveKind() == OMPD_critical) {
7699 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7700 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7702 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7703 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7704 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7705 } else if (D->getDirectiveKind() == OMPD_cancel) {
7706 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7709 return getDerived().RebuildOMPExecutableDirective(
7710 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7711 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7714 template <typename Derived>
7716 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7717 DeclarationNameInfo DirName;
7718 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7720 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7721 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7725 template <typename Derived>
7727 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7728 DeclarationNameInfo DirName;
7729 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7731 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7732 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7736 template <typename Derived>
7738 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7739 DeclarationNameInfo DirName;
7740 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7742 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7743 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7747 template <typename Derived>
7749 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7750 DeclarationNameInfo DirName;
7751 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7753 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7754 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7758 template <typename Derived>
7760 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7761 DeclarationNameInfo DirName;
7762 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7764 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7765 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7769 template <typename Derived>
7771 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7772 DeclarationNameInfo DirName;
7773 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7775 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7776 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7780 template <typename Derived>
7782 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7783 DeclarationNameInfo DirName;
7784 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7786 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7787 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7791 template <typename Derived>
7793 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7794 DeclarationNameInfo DirName;
7795 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7797 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7798 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7802 template <typename Derived>
7804 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7805 getDerived().getSema().StartOpenMPDSABlock(
7806 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7807 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7808 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7812 template <typename Derived>
7813 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7814 OMPParallelForDirective *D) {
7815 DeclarationNameInfo DirName;
7816 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7817 nullptr, D->getLocStart());
7818 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7819 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7823 template <typename Derived>
7824 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7825 OMPParallelForSimdDirective *D) {
7826 DeclarationNameInfo DirName;
7827 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7828 nullptr, D->getLocStart());
7829 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7830 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7834 template <typename Derived>
7835 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7836 OMPParallelSectionsDirective *D) {
7837 DeclarationNameInfo DirName;
7838 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7839 nullptr, D->getLocStart());
7840 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7841 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7845 template <typename Derived>
7847 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7848 DeclarationNameInfo DirName;
7849 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7851 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7852 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7856 template <typename Derived>
7857 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7858 OMPTaskyieldDirective *D) {
7859 DeclarationNameInfo DirName;
7860 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7862 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7863 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7867 template <typename Derived>
7869 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7870 DeclarationNameInfo DirName;
7871 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7873 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7874 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7878 template <typename Derived>
7880 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7881 DeclarationNameInfo DirName;
7882 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7884 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7885 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7889 template <typename Derived>
7890 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7891 OMPTaskgroupDirective *D) {
7892 DeclarationNameInfo DirName;
7893 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7895 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7896 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7900 template <typename Derived>
7902 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7903 DeclarationNameInfo DirName;
7904 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7906 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7907 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7911 template <typename Derived>
7913 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7914 DeclarationNameInfo DirName;
7915 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7917 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7918 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7922 template <typename Derived>
7924 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7925 DeclarationNameInfo DirName;
7926 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7928 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7929 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7933 template <typename Derived>
7935 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7936 DeclarationNameInfo DirName;
7937 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7939 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7940 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7944 template <typename Derived>
7945 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7946 OMPTargetDataDirective *D) {
7947 DeclarationNameInfo DirName;
7948 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7950 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7951 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7955 template <typename Derived>
7956 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7957 OMPTargetEnterDataDirective *D) {
7958 DeclarationNameInfo DirName;
7959 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7960 nullptr, D->getLocStart());
7961 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7962 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7966 template <typename Derived>
7967 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7968 OMPTargetExitDataDirective *D) {
7969 DeclarationNameInfo DirName;
7970 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7971 nullptr, D->getLocStart());
7972 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7973 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7977 template <typename Derived>
7978 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7979 OMPTargetParallelDirective *D) {
7980 DeclarationNameInfo DirName;
7981 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7982 nullptr, D->getLocStart());
7983 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7984 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7988 template <typename Derived>
7989 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7990 OMPTargetParallelForDirective *D) {
7991 DeclarationNameInfo DirName;
7992 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7993 nullptr, D->getLocStart());
7994 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7995 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7999 template <typename Derived>
8000 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8001 OMPTargetUpdateDirective *D) {
8002 DeclarationNameInfo DirName;
8003 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
8004 nullptr, D->getLocStart());
8005 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8006 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8010 template <typename Derived>
8012 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8013 DeclarationNameInfo DirName;
8014 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
8016 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8017 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8021 template <typename Derived>
8022 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8023 OMPCancellationPointDirective *D) {
8024 DeclarationNameInfo DirName;
8025 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
8026 nullptr, D->getLocStart());
8027 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8028 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8032 template <typename Derived>
8034 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8035 DeclarationNameInfo DirName;
8036 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
8038 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8039 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8043 template <typename Derived>
8045 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8046 DeclarationNameInfo DirName;
8047 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
8049 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8050 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8054 template <typename Derived>
8055 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8056 OMPTaskLoopSimdDirective *D) {
8057 DeclarationNameInfo DirName;
8058 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
8059 nullptr, D->getLocStart());
8060 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8061 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8065 template <typename Derived>
8066 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8067 OMPDistributeDirective *D) {
8068 DeclarationNameInfo DirName;
8069 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
8071 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8072 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8076 template <typename Derived>
8077 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8078 OMPDistributeParallelForDirective *D) {
8079 DeclarationNameInfo DirName;
8080 getDerived().getSema().StartOpenMPDSABlock(
8081 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
8082 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8083 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8087 template <typename Derived>
8089 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8090 OMPDistributeParallelForSimdDirective *D) {
8091 DeclarationNameInfo DirName;
8092 getDerived().getSema().StartOpenMPDSABlock(
8093 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8094 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8095 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8099 template <typename Derived>
8100 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8101 OMPDistributeSimdDirective *D) {
8102 DeclarationNameInfo DirName;
8103 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
8104 nullptr, D->getLocStart());
8105 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8106 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8110 template <typename Derived>
8111 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8112 OMPTargetParallelForSimdDirective *D) {
8113 DeclarationNameInfo DirName;
8114 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8117 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8118 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8122 template <typename Derived>
8123 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8124 OMPTargetSimdDirective *D) {
8125 DeclarationNameInfo DirName;
8126 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8128 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8129 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8133 template <typename Derived>
8134 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8135 OMPTeamsDistributeDirective *D) {
8136 DeclarationNameInfo DirName;
8137 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8138 nullptr, D->getLocStart());
8139 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8140 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8144 template <typename Derived>
8145 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8146 OMPTeamsDistributeSimdDirective *D) {
8147 DeclarationNameInfo DirName;
8148 getDerived().getSema().StartOpenMPDSABlock(
8149 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8150 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8151 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8155 template <typename Derived>
8156 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8157 OMPTeamsDistributeParallelForSimdDirective *D) {
8158 DeclarationNameInfo DirName;
8159 getDerived().getSema().StartOpenMPDSABlock(
8160 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8161 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8162 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8166 template <typename Derived>
8167 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8168 OMPTeamsDistributeParallelForDirective *D) {
8169 DeclarationNameInfo DirName;
8170 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8171 DirName, nullptr, D->getLocStart());
8172 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8173 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8177 template <typename Derived>
8178 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8179 OMPTargetTeamsDirective *D) {
8180 DeclarationNameInfo DirName;
8181 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8182 nullptr, D->getLocStart());
8183 auto Res = getDerived().TransformOMPExecutableDirective(D);
8184 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8188 template <typename Derived>
8189 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8190 OMPTargetTeamsDistributeDirective *D) {
8191 DeclarationNameInfo DirName;
8192 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8193 DirName, nullptr, D->getLocStart());
8194 auto Res = getDerived().TransformOMPExecutableDirective(D);
8195 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8199 template <typename Derived>
8201 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8202 OMPTargetTeamsDistributeParallelForDirective *D) {
8203 DeclarationNameInfo DirName;
8204 getDerived().getSema().StartOpenMPDSABlock(
8205 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8207 auto Res = getDerived().TransformOMPExecutableDirective(D);
8208 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8212 template <typename Derived>
8213 StmtResult TreeTransform<Derived>::
8214 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8215 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8216 DeclarationNameInfo DirName;
8217 getDerived().getSema().StartOpenMPDSABlock(
8218 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8220 auto Res = getDerived().TransformOMPExecutableDirective(D);
8221 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8225 template <typename Derived>
8227 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8228 OMPTargetTeamsDistributeSimdDirective *D) {
8229 DeclarationNameInfo DirName;
8230 getDerived().getSema().StartOpenMPDSABlock(
8231 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8232 auto Res = getDerived().TransformOMPExecutableDirective(D);
8233 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8238 //===----------------------------------------------------------------------===//
8239 // OpenMP clause transformation
8240 //===----------------------------------------------------------------------===//
8241 template <typename Derived>
8242 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
8243 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8244 if (Cond.isInvalid())
8246 return getDerived().RebuildOMPIfClause(
8247 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8248 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
8251 template <typename Derived>
8252 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8253 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8254 if (Cond.isInvalid())
8256 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8257 C->getLParenLoc(), C->getLocEnd());
8260 template <typename Derived>
8262 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8263 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8264 if (NumThreads.isInvalid())
8266 return getDerived().RebuildOMPNumThreadsClause(
8267 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8270 template <typename Derived>
8272 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8273 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8276 return getDerived().RebuildOMPSafelenClause(
8277 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8280 template <typename Derived>
8282 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8283 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8286 return getDerived().RebuildOMPSimdlenClause(
8287 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8290 template <typename Derived>
8292 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8293 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8296 return getDerived().RebuildOMPCollapseClause(
8297 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8300 template <typename Derived>
8302 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
8303 return getDerived().RebuildOMPDefaultClause(
8304 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8305 C->getLParenLoc(), C->getLocEnd());
8308 template <typename Derived>
8310 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
8311 return getDerived().RebuildOMPProcBindClause(
8312 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8313 C->getLParenLoc(), C->getLocEnd());
8316 template <typename Derived>
8318 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8319 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8322 return getDerived().RebuildOMPScheduleClause(
8323 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
8324 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8325 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
8326 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8329 template <typename Derived>
8331 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
8333 if (auto *Num = C->getNumForLoops()) {
8334 E = getDerived().TransformExpr(Num);
8338 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8339 C->getLParenLoc(), E.get());
8342 template <typename Derived>
8344 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8345 // No need to rebuild this clause, no template-dependent parameters.
8349 template <typename Derived>
8351 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8352 // No need to rebuild this clause, no template-dependent parameters.
8356 template <typename Derived>
8358 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8359 // No need to rebuild this clause, no template-dependent parameters.
8363 template <typename Derived>
8364 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8365 // No need to rebuild this clause, no template-dependent parameters.
8369 template <typename Derived>
8370 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8371 // No need to rebuild this clause, no template-dependent parameters.
8375 template <typename Derived>
8377 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8378 // No need to rebuild this clause, no template-dependent parameters.
8382 template <typename Derived>
8384 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8385 // No need to rebuild this clause, no template-dependent parameters.
8389 template <typename Derived>
8391 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8392 // No need to rebuild this clause, no template-dependent parameters.
8396 template <typename Derived>
8398 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8399 // No need to rebuild this clause, no template-dependent parameters.
8403 template <typename Derived>
8404 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8405 // No need to rebuild this clause, no template-dependent parameters.
8409 template <typename Derived>
8411 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8412 // No need to rebuild this clause, no template-dependent parameters.
8416 template <typename Derived>
8418 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
8419 llvm::SmallVector<Expr *, 16> Vars;
8420 Vars.reserve(C->varlist_size());
8421 for (auto *VE : C->varlists()) {
8422 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8423 if (EVar.isInvalid())
8425 Vars.push_back(EVar.get());
8427 return getDerived().RebuildOMPPrivateClause(
8428 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8431 template <typename Derived>
8432 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8433 OMPFirstprivateClause *C) {
8434 llvm::SmallVector<Expr *, 16> Vars;
8435 Vars.reserve(C->varlist_size());
8436 for (auto *VE : C->varlists()) {
8437 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8438 if (EVar.isInvalid())
8440 Vars.push_back(EVar.get());
8442 return getDerived().RebuildOMPFirstprivateClause(
8443 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8446 template <typename Derived>
8448 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8449 llvm::SmallVector<Expr *, 16> Vars;
8450 Vars.reserve(C->varlist_size());
8451 for (auto *VE : C->varlists()) {
8452 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8453 if (EVar.isInvalid())
8455 Vars.push_back(EVar.get());
8457 return getDerived().RebuildOMPLastprivateClause(
8458 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8461 template <typename Derived>
8463 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8464 llvm::SmallVector<Expr *, 16> Vars;
8465 Vars.reserve(C->varlist_size());
8466 for (auto *VE : C->varlists()) {
8467 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8468 if (EVar.isInvalid())
8470 Vars.push_back(EVar.get());
8472 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8473 C->getLParenLoc(), C->getLocEnd());
8476 template <typename Derived>
8478 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8479 llvm::SmallVector<Expr *, 16> Vars;
8480 Vars.reserve(C->varlist_size());
8481 for (auto *VE : C->varlists()) {
8482 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8483 if (EVar.isInvalid())
8485 Vars.push_back(EVar.get());
8487 CXXScopeSpec ReductionIdScopeSpec;
8488 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8490 DeclarationNameInfo NameInfo = C->getNameInfo();
8491 if (NameInfo.getName()) {
8492 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8493 if (!NameInfo.getName())
8496 // Build a list of all UDR decls with the same names ranged by the Scopes.
8497 // The Scope boundary is a duplication of the previous decl.
8498 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8499 for (auto *E : C->reduction_ops()) {
8500 // Transform all the decls.
8502 auto *ULE = cast<UnresolvedLookupExpr>(E);
8503 UnresolvedSet<8> Decls;
8504 for (auto *D : ULE->decls()) {
8506 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8507 Decls.addDecl(InstD, InstD->getAccess());
8509 UnresolvedReductions.push_back(
8510 UnresolvedLookupExpr::Create(
8511 SemaRef.Context, /*NamingClass=*/nullptr,
8512 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8513 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8514 Decls.begin(), Decls.end()));
8516 UnresolvedReductions.push_back(nullptr);
8518 return getDerived().RebuildOMPReductionClause(
8519 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8520 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8523 template <typename Derived>
8524 OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8525 OMPTaskReductionClause *C) {
8526 llvm::SmallVector<Expr *, 16> Vars;
8527 Vars.reserve(C->varlist_size());
8528 for (auto *VE : C->varlists()) {
8529 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8530 if (EVar.isInvalid())
8532 Vars.push_back(EVar.get());
8534 CXXScopeSpec ReductionIdScopeSpec;
8535 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8537 DeclarationNameInfo NameInfo = C->getNameInfo();
8538 if (NameInfo.getName()) {
8539 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8540 if (!NameInfo.getName())
8543 // Build a list of all UDR decls with the same names ranged by the Scopes.
8544 // The Scope boundary is a duplication of the previous decl.
8545 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8546 for (auto *E : C->reduction_ops()) {
8547 // Transform all the decls.
8549 auto *ULE = cast<UnresolvedLookupExpr>(E);
8550 UnresolvedSet<8> Decls;
8551 for (auto *D : ULE->decls()) {
8553 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8554 Decls.addDecl(InstD, InstD->getAccess());
8556 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8557 SemaRef.Context, /*NamingClass=*/nullptr,
8558 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8559 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8561 UnresolvedReductions.push_back(nullptr);
8563 return getDerived().RebuildOMPTaskReductionClause(
8564 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8565 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8568 template <typename Derived>
8570 TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8571 llvm::SmallVector<Expr *, 16> Vars;
8572 Vars.reserve(C->varlist_size());
8573 for (auto *VE : C->varlists()) {
8574 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8575 if (EVar.isInvalid())
8577 Vars.push_back(EVar.get());
8579 CXXScopeSpec ReductionIdScopeSpec;
8580 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8582 DeclarationNameInfo NameInfo = C->getNameInfo();
8583 if (NameInfo.getName()) {
8584 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8585 if (!NameInfo.getName())
8588 // Build a list of all UDR decls with the same names ranged by the Scopes.
8589 // The Scope boundary is a duplication of the previous decl.
8590 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8591 for (auto *E : C->reduction_ops()) {
8592 // Transform all the decls.
8594 auto *ULE = cast<UnresolvedLookupExpr>(E);
8595 UnresolvedSet<8> Decls;
8596 for (auto *D : ULE->decls()) {
8598 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8599 Decls.addDecl(InstD, InstD->getAccess());
8601 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8602 SemaRef.Context, /*NamingClass=*/nullptr,
8603 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8604 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8606 UnresolvedReductions.push_back(nullptr);
8608 return getDerived().RebuildOMPInReductionClause(
8609 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8610 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8613 template <typename Derived>
8615 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8616 llvm::SmallVector<Expr *, 16> Vars;
8617 Vars.reserve(C->varlist_size());
8618 for (auto *VE : C->varlists()) {
8619 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8620 if (EVar.isInvalid())
8622 Vars.push_back(EVar.get());
8624 ExprResult Step = getDerived().TransformExpr(C->getStep());
8625 if (Step.isInvalid())
8627 return getDerived().RebuildOMPLinearClause(
8628 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8629 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
8632 template <typename Derived>
8634 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8635 llvm::SmallVector<Expr *, 16> Vars;
8636 Vars.reserve(C->varlist_size());
8637 for (auto *VE : C->varlists()) {
8638 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8639 if (EVar.isInvalid())
8641 Vars.push_back(EVar.get());
8643 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8644 if (Alignment.isInvalid())
8646 return getDerived().RebuildOMPAlignedClause(
8647 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8648 C->getColonLoc(), C->getLocEnd());
8651 template <typename Derived>
8653 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8654 llvm::SmallVector<Expr *, 16> Vars;
8655 Vars.reserve(C->varlist_size());
8656 for (auto *VE : C->varlists()) {
8657 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8658 if (EVar.isInvalid())
8660 Vars.push_back(EVar.get());
8662 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8663 C->getLParenLoc(), C->getLocEnd());
8666 template <typename Derived>
8668 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8669 llvm::SmallVector<Expr *, 16> Vars;
8670 Vars.reserve(C->varlist_size());
8671 for (auto *VE : C->varlists()) {
8672 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8673 if (EVar.isInvalid())
8675 Vars.push_back(EVar.get());
8677 return getDerived().RebuildOMPCopyprivateClause(
8678 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8681 template <typename Derived>
8682 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8683 llvm::SmallVector<Expr *, 16> Vars;
8684 Vars.reserve(C->varlist_size());
8685 for (auto *VE : C->varlists()) {
8686 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8687 if (EVar.isInvalid())
8689 Vars.push_back(EVar.get());
8691 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8692 C->getLParenLoc(), C->getLocEnd());
8695 template <typename Derived>
8697 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8698 llvm::SmallVector<Expr *, 16> Vars;
8699 Vars.reserve(C->varlist_size());
8700 for (auto *VE : C->varlists()) {
8701 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8702 if (EVar.isInvalid())
8704 Vars.push_back(EVar.get());
8706 return getDerived().RebuildOMPDependClause(
8707 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8708 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8711 template <typename Derived>
8713 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8714 ExprResult E = getDerived().TransformExpr(C->getDevice());
8717 return getDerived().RebuildOMPDeviceClause(
8718 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8721 template <typename Derived>
8722 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8723 llvm::SmallVector<Expr *, 16> Vars;
8724 Vars.reserve(C->varlist_size());
8725 for (auto *VE : C->varlists()) {
8726 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8727 if (EVar.isInvalid())
8729 Vars.push_back(EVar.get());
8731 return getDerived().RebuildOMPMapClause(
8732 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8733 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8734 C->getLParenLoc(), C->getLocEnd());
8737 template <typename Derived>
8739 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8740 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8743 return getDerived().RebuildOMPNumTeamsClause(
8744 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8747 template <typename Derived>
8749 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8750 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8753 return getDerived().RebuildOMPThreadLimitClause(
8754 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8757 template <typename Derived>
8759 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8760 ExprResult E = getDerived().TransformExpr(C->getPriority());
8763 return getDerived().RebuildOMPPriorityClause(
8764 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8767 template <typename Derived>
8769 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8770 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8773 return getDerived().RebuildOMPGrainsizeClause(
8774 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8777 template <typename Derived>
8779 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8780 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8783 return getDerived().RebuildOMPNumTasksClause(
8784 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8787 template <typename Derived>
8788 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8789 ExprResult E = getDerived().TransformExpr(C->getHint());
8792 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8793 C->getLParenLoc(), C->getLocEnd());
8796 template <typename Derived>
8797 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8798 OMPDistScheduleClause *C) {
8799 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8802 return getDerived().RebuildOMPDistScheduleClause(
8803 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8804 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8807 template <typename Derived>
8809 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8813 template <typename Derived>
8814 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8815 llvm::SmallVector<Expr *, 16> Vars;
8816 Vars.reserve(C->varlist_size());
8817 for (auto *VE : C->varlists()) {
8818 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8819 if (EVar.isInvalid())
8821 Vars.push_back(EVar.get());
8823 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8824 C->getLParenLoc(), C->getLocEnd());
8827 template <typename Derived>
8828 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8829 llvm::SmallVector<Expr *, 16> Vars;
8830 Vars.reserve(C->varlist_size());
8831 for (auto *VE : C->varlists()) {
8832 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8833 if (EVar.isInvalid())
8835 Vars.push_back(EVar.get());
8837 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8838 C->getLParenLoc(), C->getLocEnd());
8841 template <typename Derived>
8842 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8843 OMPUseDevicePtrClause *C) {
8844 llvm::SmallVector<Expr *, 16> Vars;
8845 Vars.reserve(C->varlist_size());
8846 for (auto *VE : C->varlists()) {
8847 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8848 if (EVar.isInvalid())
8850 Vars.push_back(EVar.get());
8852 return getDerived().RebuildOMPUseDevicePtrClause(
8853 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8856 template <typename Derived>
8858 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8859 llvm::SmallVector<Expr *, 16> Vars;
8860 Vars.reserve(C->varlist_size());
8861 for (auto *VE : C->varlists()) {
8862 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8863 if (EVar.isInvalid())
8865 Vars.push_back(EVar.get());
8867 return getDerived().RebuildOMPIsDevicePtrClause(
8868 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8871 //===----------------------------------------------------------------------===//
8872 // Expression transformation
8873 //===----------------------------------------------------------------------===//
8874 template<typename Derived>
8876 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
8877 if (!E->isTypeDependent())
8880 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8884 template<typename Derived>
8886 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
8887 NestedNameSpecifierLoc QualifierLoc;
8888 if (E->getQualifierLoc()) {
8890 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8896 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8901 DeclarationNameInfo NameInfo = E->getNameInfo();
8902 if (NameInfo.getName()) {
8903 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8904 if (!NameInfo.getName())
8908 if (!getDerived().AlwaysRebuild() &&
8909 QualifierLoc == E->getQualifierLoc() &&
8910 ND == E->getDecl() &&
8911 NameInfo.getName() == E->getDecl()->getDeclName() &&
8912 !E->hasExplicitTemplateArgs()) {
8914 // Mark it referenced in the new context regardless.
8915 // FIXME: this is a bit instantiation-specific.
8916 SemaRef.MarkDeclRefReferenced(E);
8921 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
8922 if (E->hasExplicitTemplateArgs()) {
8923 TemplateArgs = &TransArgs;
8924 TransArgs.setLAngleLoc(E->getLAngleLoc());
8925 TransArgs.setRAngleLoc(E->getRAngleLoc());
8926 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8927 E->getNumTemplateArgs(),
8932 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
8936 template<typename Derived>
8938 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
8942 template <typename Derived>
8943 ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
8944 FixedPointLiteral *E) {
8948 template<typename Derived>
8950 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
8954 template<typename Derived>
8956 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
8960 template<typename Derived>
8962 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
8966 template<typename Derived>
8968 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
8972 template<typename Derived>
8974 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
8975 if (FunctionDecl *FD = E->getDirectCallee())
8976 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
8977 return SemaRef.MaybeBindToTemporary(E);
8980 template<typename Derived>
8982 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8983 ExprResult ControllingExpr =
8984 getDerived().TransformExpr(E->getControllingExpr());
8985 if (ControllingExpr.isInvalid())
8988 SmallVector<Expr *, 4> AssocExprs;
8989 SmallVector<TypeSourceInfo *, 4> AssocTypes;
8990 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8991 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8993 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8996 AssocTypes.push_back(AssocType);
8998 AssocTypes.push_back(nullptr);
9001 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
9002 if (AssocExpr.isInvalid())
9004 AssocExprs.push_back(AssocExpr.get());
9007 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9010 ControllingExpr.get(),
9015 template<typename Derived>
9017 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
9018 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9019 if (SubExpr.isInvalid())
9022 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
9025 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
9029 /// The operand of a unary address-of operator has special rules: it's
9030 /// allowed to refer to a non-static member of a class even if there's no 'this'
9031 /// object available.
9032 template<typename Derived>
9034 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9035 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
9036 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
9038 return getDerived().TransformExpr(E);
9041 template<typename Derived>
9043 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
9045 if (E->getOpcode() == UO_AddrOf)
9046 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9048 SubExpr = TransformExpr(E->getSubExpr());
9049 if (SubExpr.isInvalid())
9052 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
9055 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9060 template<typename Derived>
9062 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9063 // Transform the type.
9064 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9068 // Transform all of the components into components similar to what the
9070 // FIXME: It would be slightly more efficient in the non-dependent case to
9071 // just map FieldDecls, rather than requiring the rebuilder to look for
9072 // the fields again. However, __builtin_offsetof is rare enough in
9073 // template code that we don't care.
9074 bool ExprChanged = false;
9075 typedef Sema::OffsetOfComponent Component;
9076 SmallVector<Component, 4> Components;
9077 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
9078 const OffsetOfNode &ON = E->getComponent(I);
9080 Comp.isBrackets = true;
9081 Comp.LocStart = ON.getSourceRange().getBegin();
9082 Comp.LocEnd = ON.getSourceRange().getEnd();
9083 switch (ON.getKind()) {
9084 case OffsetOfNode::Array: {
9085 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
9086 ExprResult Index = getDerived().TransformExpr(FromIndex);
9087 if (Index.isInvalid())
9090 ExprChanged = ExprChanged || Index.get() != FromIndex;
9091 Comp.isBrackets = true;
9092 Comp.U.E = Index.get();
9096 case OffsetOfNode::Field:
9097 case OffsetOfNode::Identifier:
9098 Comp.isBrackets = false;
9099 Comp.U.IdentInfo = ON.getFieldName();
9100 if (!Comp.U.IdentInfo)
9105 case OffsetOfNode::Base:
9106 // Will be recomputed during the rebuild.
9110 Components.push_back(Comp);
9113 // If nothing changed, retain the existing expression.
9114 if (!getDerived().AlwaysRebuild() &&
9115 Type == E->getTypeSourceInfo() &&
9119 // Build a new offsetof expression.
9120 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
9121 Components, E->getRParenLoc());
9124 template<typename Derived>
9126 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
9127 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
9128 "opaque value expression requires transformation");
9132 template<typename Derived>
9134 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9138 template<typename Derived>
9140 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
9141 // Rebuild the syntactic form. The original syntactic form has
9142 // opaque-value expressions in it, so strip those away and rebuild
9143 // the result. This is a really awful way of doing this, but the
9144 // better solution (rebuilding the semantic expressions and
9145 // rebinding OVEs as necessary) doesn't work; we'd need
9146 // TreeTransform to not strip away implicit conversions.
9147 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9148 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
9149 if (result.isInvalid()) return ExprError();
9151 // If that gives us a pseudo-object result back, the pseudo-object
9152 // expression must have been an lvalue-to-rvalue conversion which we
9154 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
9155 result = SemaRef.checkPseudoObjectRValue(result.get());
9160 template<typename Derived>
9162 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9163 UnaryExprOrTypeTraitExpr *E) {
9164 if (E->isArgumentType()) {
9165 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
9167 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9171 if (!getDerived().AlwaysRebuild() && OldT == NewT)
9174 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9176 E->getSourceRange());
9179 // C++0x [expr.sizeof]p1:
9180 // The operand is either an expression, which is an unevaluated operand
9182 EnterExpressionEvaluationContext Unevaluated(
9183 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9184 Sema::ReuseLambdaContextDecl);
9186 // Try to recover if we have something like sizeof(T::X) where X is a type.
9187 // Notably, there must be *exactly* one set of parens if X is a type.
9188 TypeSourceInfo *RecoveryTSI = nullptr;
9190 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9192 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9193 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9194 PE, DRE, false, &RecoveryTSI);
9196 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9199 return getDerived().RebuildUnaryExprOrTypeTrait(
9200 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9201 } else if (SubExpr.isInvalid())
9204 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
9207 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9208 E->getOperatorLoc(),
9210 E->getSourceRange());
9213 template<typename Derived>
9215 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
9216 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9217 if (LHS.isInvalid())
9220 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9221 if (RHS.isInvalid())
9225 if (!getDerived().AlwaysRebuild() &&
9226 LHS.get() == E->getLHS() &&
9227 RHS.get() == E->getRHS())
9230 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
9231 /*FIXME:*/E->getLHS()->getLocStart(),
9233 E->getRBracketLoc());
9236 template <typename Derived>
9238 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9239 ExprResult Base = getDerived().TransformExpr(E->getBase());
9240 if (Base.isInvalid())
9243 ExprResult LowerBound;
9244 if (E->getLowerBound()) {
9245 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9246 if (LowerBound.isInvalid())
9251 if (E->getLength()) {
9252 Length = getDerived().TransformExpr(E->getLength());
9253 if (Length.isInvalid())
9257 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9258 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9261 return getDerived().RebuildOMPArraySectionExpr(
9262 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9263 Length.get(), E->getRBracketLoc());
9266 template<typename Derived>
9268 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
9269 // Transform the callee.
9270 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9271 if (Callee.isInvalid())
9274 // Transform arguments.
9275 bool ArgChanged = false;
9276 SmallVector<Expr*, 8> Args;
9277 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9281 if (!getDerived().AlwaysRebuild() &&
9282 Callee.get() == E->getCallee() &&
9284 return SemaRef.MaybeBindToTemporary(E);
9286 // FIXME: Wrong source location information for the '('.
9287 SourceLocation FakeLParenLoc
9288 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9289 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9294 template<typename Derived>
9296 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
9297 ExprResult Base = getDerived().TransformExpr(E->getBase());
9298 if (Base.isInvalid())
9301 NestedNameSpecifierLoc QualifierLoc;
9302 if (E->hasQualifier()) {
9304 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9309 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9312 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9313 E->getMemberDecl()));
9317 NamedDecl *FoundDecl = E->getFoundDecl();
9318 if (FoundDecl == E->getMemberDecl()) {
9321 FoundDecl = cast_or_null<NamedDecl>(
9322 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9327 if (!getDerived().AlwaysRebuild() &&
9328 Base.get() == E->getBase() &&
9329 QualifierLoc == E->getQualifierLoc() &&
9330 Member == E->getMemberDecl() &&
9331 FoundDecl == E->getFoundDecl() &&
9332 !E->hasExplicitTemplateArgs()) {
9334 // Mark it referenced in the new context regardless.
9335 // FIXME: this is a bit instantiation-specific.
9336 SemaRef.MarkMemberReferenced(E);
9341 TemplateArgumentListInfo TransArgs;
9342 if (E->hasExplicitTemplateArgs()) {
9343 TransArgs.setLAngleLoc(E->getLAngleLoc());
9344 TransArgs.setRAngleLoc(E->getRAngleLoc());
9345 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9346 E->getNumTemplateArgs(),
9351 // FIXME: Bogus source location for the operator
9352 SourceLocation FakeOperatorLoc =
9353 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
9355 // FIXME: to do this check properly, we will need to preserve the
9356 // first-qualifier-in-scope here, just in case we had a dependent
9357 // base (and therefore couldn't do the check) and a
9358 // nested-name-qualifier (and therefore could do the lookup).
9359 NamedDecl *FirstQualifierInScope = nullptr;
9360 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9361 if (MemberNameInfo.getName()) {
9362 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9363 if (!MemberNameInfo.getName())
9367 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
9374 (E->hasExplicitTemplateArgs()
9375 ? &TransArgs : nullptr),
9376 FirstQualifierInScope);
9379 template<typename Derived>
9381 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
9382 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9383 if (LHS.isInvalid())
9386 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9387 if (RHS.isInvalid())
9390 if (!getDerived().AlwaysRebuild() &&
9391 LHS.get() == E->getLHS() &&
9392 RHS.get() == E->getRHS())
9395 Sema::FPContractStateRAII FPContractState(getSema());
9396 getSema().FPFeatures = E->getFPFeatures();
9398 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
9399 LHS.get(), RHS.get());
9402 template<typename Derived>
9404 TreeTransform<Derived>::TransformCompoundAssignOperator(
9405 CompoundAssignOperator *E) {
9406 return getDerived().TransformBinaryOperator(E);
9409 template<typename Derived>
9410 ExprResult TreeTransform<Derived>::
9411 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9412 // Just rebuild the common and RHS expressions and see whether we
9415 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9416 if (commonExpr.isInvalid())
9419 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9420 if (rhs.isInvalid())
9423 if (!getDerived().AlwaysRebuild() &&
9424 commonExpr.get() == e->getCommon() &&
9425 rhs.get() == e->getFalseExpr())
9428 return getDerived().RebuildConditionalOperator(commonExpr.get(),
9429 e->getQuestionLoc(),
9435 template<typename Derived>
9437 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
9438 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9439 if (Cond.isInvalid())
9442 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9443 if (LHS.isInvalid())
9446 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9447 if (RHS.isInvalid())
9450 if (!getDerived().AlwaysRebuild() &&
9451 Cond.get() == E->getCond() &&
9452 LHS.get() == E->getLHS() &&
9453 RHS.get() == E->getRHS())
9456 return getDerived().RebuildConditionalOperator(Cond.get(),
9457 E->getQuestionLoc(),
9463 template<typename Derived>
9465 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
9466 // Implicit casts are eliminated during transformation, since they
9467 // will be recomputed by semantic analysis after transformation.
9468 return getDerived().TransformExpr(E->getSubExprAsWritten());
9471 template<typename Derived>
9473 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
9474 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9479 = getDerived().TransformExpr(E->getSubExprAsWritten());
9480 if (SubExpr.isInvalid())
9483 if (!getDerived().AlwaysRebuild() &&
9484 Type == E->getTypeInfoAsWritten() &&
9485 SubExpr.get() == E->getSubExpr())
9488 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
9494 template<typename Derived>
9496 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
9497 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9498 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9502 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
9503 if (Init.isInvalid())
9506 if (!getDerived().AlwaysRebuild() &&
9508 Init.get() == E->getInitializer())
9509 return SemaRef.MaybeBindToTemporary(E);
9511 // Note: the expression type doesn't necessarily match the
9512 // type-as-written, but that's okay, because it should always be
9513 // derivable from the initializer.
9515 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
9516 /*FIXME:*/E->getInitializer()->getLocEnd(),
9520 template<typename Derived>
9522 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
9523 ExprResult Base = getDerived().TransformExpr(E->getBase());
9524 if (Base.isInvalid())
9527 if (!getDerived().AlwaysRebuild() &&
9528 Base.get() == E->getBase())
9531 // FIXME: Bad source location
9532 SourceLocation FakeOperatorLoc =
9533 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
9534 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
9535 E->getAccessorLoc(),
9539 template<typename Derived>
9541 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
9542 if (InitListExpr *Syntactic = E->getSyntacticForm())
9545 bool InitChanged = false;
9547 SmallVector<Expr*, 4> Inits;
9548 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
9549 Inits, &InitChanged))
9552 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9553 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9554 // in some cases. We can't reuse it in general, because the syntactic and
9555 // semantic forms are linked, and we can't know that semantic form will
9556 // match even if the syntactic form does.
9559 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
9563 template<typename Derived>
9565 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
9568 // transform the initializer value
9569 ExprResult Init = getDerived().TransformExpr(E->getInit());
9570 if (Init.isInvalid())
9573 // transform the designators.
9574 SmallVector<Expr*, 4> ArrayExprs;
9575 bool ExprChanged = false;
9576 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9577 if (D.isFieldDesignator()) {
9578 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9582 FieldDecl *Field = cast_or_null<FieldDecl>(
9583 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9584 if (Field != D.getField())
9585 // Rebuild the expression when the transformed FieldDecl is
9586 // different to the already assigned FieldDecl.
9589 // Ensure that the designator expression is rebuilt when there isn't
9590 // a resolved FieldDecl in the designator as we don't want to assign
9591 // a FieldDecl to a pattern designator that will be instantiated again.
9597 if (D.isArrayDesignator()) {
9598 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
9599 if (Index.isInvalid())
9602 Desig.AddDesignator(
9603 Designator::getArray(Index.get(), D.getLBracketLoc()));
9605 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
9606 ArrayExprs.push_back(Index.get());
9610 assert(D.isArrayRangeDesignator() && "New kind of designator?");
9612 = getDerived().TransformExpr(E->getArrayRangeStart(D));
9613 if (Start.isInvalid())
9616 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
9617 if (End.isInvalid())
9620 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
9623 D.getEllipsisLoc()));
9625 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9626 End.get() != E->getArrayRangeEnd(D);
9628 ArrayExprs.push_back(Start.get());
9629 ArrayExprs.push_back(End.get());
9632 if (!getDerived().AlwaysRebuild() &&
9633 Init.get() == E->getInit() &&
9637 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
9638 E->getEqualOrColonLoc(),
9639 E->usesGNUSyntax(), Init.get());
9642 // Seems that if TransformInitListExpr() only works on the syntactic form of an
9643 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9644 template<typename Derived>
9646 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9647 DesignatedInitUpdateExpr *E) {
9648 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9653 template<typename Derived>
9655 TreeTransform<Derived>::TransformNoInitExpr(
9657 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9661 template<typename Derived>
9663 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9664 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9668 template<typename Derived>
9670 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9671 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9675 template<typename Derived>
9677 TreeTransform<Derived>::TransformImplicitValueInitExpr(
9678 ImplicitValueInitExpr *E) {
9679 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
9681 // FIXME: Will we ever have proper type location here? Will we actually
9682 // need to transform the type?
9683 QualType T = getDerived().TransformType(E->getType());
9687 if (!getDerived().AlwaysRebuild() &&
9691 return getDerived().RebuildImplicitValueInitExpr(T);
9694 template<typename Derived>
9696 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
9697 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9701 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9702 if (SubExpr.isInvalid())
9705 if (!getDerived().AlwaysRebuild() &&
9706 TInfo == E->getWrittenTypeInfo() &&
9707 SubExpr.get() == E->getSubExpr())
9710 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
9711 TInfo, E->getRParenLoc());
9714 template<typename Derived>
9716 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
9717 bool ArgumentChanged = false;
9718 SmallVector<Expr*, 4> Inits;
9719 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9723 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
9728 /// Transform an address-of-label expression.
9730 /// By default, the transformation of an address-of-label expression always
9731 /// rebuilds the expression, so that the label identifier can be resolved to
9732 /// the corresponding label statement by semantic analysis.
9733 template<typename Derived>
9735 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
9736 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9741 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
9742 cast<LabelDecl>(LD));
9745 template<typename Derived>
9747 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
9748 SemaRef.ActOnStartStmtExpr();
9750 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
9751 if (SubStmt.isInvalid()) {
9752 SemaRef.ActOnStmtExprError();
9756 if (!getDerived().AlwaysRebuild() &&
9757 SubStmt.get() == E->getSubStmt()) {
9758 // Calling this an 'error' is unintuitive, but it does the right thing.
9759 SemaRef.ActOnStmtExprError();
9760 return SemaRef.MaybeBindToTemporary(E);
9763 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
9768 template<typename Derived>
9770 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
9771 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9772 if (Cond.isInvalid())
9775 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9776 if (LHS.isInvalid())
9779 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9780 if (RHS.isInvalid())
9783 if (!getDerived().AlwaysRebuild() &&
9784 Cond.get() == E->getCond() &&
9785 LHS.get() == E->getLHS() &&
9786 RHS.get() == E->getRHS())
9789 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
9790 Cond.get(), LHS.get(), RHS.get(),
9794 template<typename Derived>
9796 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
9800 template<typename Derived>
9802 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
9803 switch (E->getOperator()) {
9807 case OO_Array_Delete:
9808 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
9811 // This is a call to an object's operator().
9812 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9814 // Transform the object itself.
9815 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
9816 if (Object.isInvalid())
9819 // FIXME: Poor location information
9820 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9821 static_cast<Expr *>(Object.get())->getLocEnd());
9823 // Transform the call arguments.
9824 SmallVector<Expr*, 8> Args;
9825 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
9829 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
9834 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9836 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9837 #include "clang/Basic/OperatorKinds.def"
9842 case OO_Conditional:
9843 llvm_unreachable("conditional operator is not actually overloadable");
9846 case NUM_OVERLOADED_OPERATORS:
9847 llvm_unreachable("not an overloaded operator?");
9850 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9851 if (Callee.isInvalid())
9855 if (E->getOperator() == OO_Amp)
9856 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9858 First = getDerived().TransformExpr(E->getArg(0));
9859 if (First.isInvalid())
9863 if (E->getNumArgs() == 2) {
9864 Second = getDerived().TransformExpr(E->getArg(1));
9865 if (Second.isInvalid())
9869 if (!getDerived().AlwaysRebuild() &&
9870 Callee.get() == E->getCallee() &&
9871 First.get() == E->getArg(0) &&
9872 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
9873 return SemaRef.MaybeBindToTemporary(E);
9875 Sema::FPContractStateRAII FPContractState(getSema());
9876 getSema().FPFeatures = E->getFPFeatures();
9878 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9879 E->getOperatorLoc(),
9885 template<typename Derived>
9887 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9888 return getDerived().TransformCallExpr(E);
9891 template<typename Derived>
9893 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9894 // Transform the callee.
9895 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9896 if (Callee.isInvalid())
9899 // Transform exec config.
9900 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9904 // Transform arguments.
9905 bool ArgChanged = false;
9906 SmallVector<Expr*, 8> Args;
9907 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9911 if (!getDerived().AlwaysRebuild() &&
9912 Callee.get() == E->getCallee() &&
9914 return SemaRef.MaybeBindToTemporary(E);
9916 // FIXME: Wrong source location information for the '('.
9917 SourceLocation FakeLParenLoc
9918 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9919 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9921 E->getRParenLoc(), EC.get());
9924 template<typename Derived>
9926 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
9927 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9932 = getDerived().TransformExpr(E->getSubExprAsWritten());
9933 if (SubExpr.isInvalid())
9936 if (!getDerived().AlwaysRebuild() &&
9937 Type == E->getTypeInfoAsWritten() &&
9938 SubExpr.get() == E->getSubExpr())
9940 return getDerived().RebuildCXXNamedCastExpr(
9941 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9942 Type, E->getAngleBrackets().getEnd(),
9943 // FIXME. this should be '(' location
9944 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
9947 template<typename Derived>
9949 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9950 return getDerived().TransformCXXNamedCastExpr(E);
9953 template<typename Derived>
9955 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9956 return getDerived().TransformCXXNamedCastExpr(E);
9959 template<typename Derived>
9961 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
9962 CXXReinterpretCastExpr *E) {
9963 return getDerived().TransformCXXNamedCastExpr(E);
9966 template<typename Derived>
9968 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9969 return getDerived().TransformCXXNamedCastExpr(E);
9972 template<typename Derived>
9974 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
9975 CXXFunctionalCastExpr *E) {
9976 TypeSourceInfo *Type =
9977 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
9982 = getDerived().TransformExpr(E->getSubExprAsWritten());
9983 if (SubExpr.isInvalid())
9986 if (!getDerived().AlwaysRebuild() &&
9987 Type == E->getTypeInfoAsWritten() &&
9988 SubExpr.get() == E->getSubExpr())
9991 return getDerived().RebuildCXXFunctionalCastExpr(Type,
9995 E->isListInitialization());
9998 template<typename Derived>
10000 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
10001 if (E->isTypeOperand()) {
10002 TypeSourceInfo *TInfo
10003 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10005 return ExprError();
10007 if (!getDerived().AlwaysRebuild() &&
10008 TInfo == E->getTypeOperandSourceInfo())
10011 return getDerived().RebuildCXXTypeidExpr(E->getType(),
10017 // We don't know whether the subexpression is potentially evaluated until
10018 // after we perform semantic analysis. We speculatively assume it is
10019 // unevaluated; it will get fixed later if the subexpression is in fact
10020 // potentially evaluated.
10021 EnterExpressionEvaluationContext Unevaluated(
10022 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10023 Sema::ReuseLambdaContextDecl);
10025 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10026 if (SubExpr.isInvalid())
10027 return ExprError();
10029 if (!getDerived().AlwaysRebuild() &&
10030 SubExpr.get() == E->getExprOperand())
10033 return getDerived().RebuildCXXTypeidExpr(E->getType(),
10039 template<typename Derived>
10041 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10042 if (E->isTypeOperand()) {
10043 TypeSourceInfo *TInfo
10044 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10046 return ExprError();
10048 if (!getDerived().AlwaysRebuild() &&
10049 TInfo == E->getTypeOperandSourceInfo())
10052 return getDerived().RebuildCXXUuidofExpr(E->getType(),
10058 EnterExpressionEvaluationContext Unevaluated(
10059 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
10061 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10062 if (SubExpr.isInvalid())
10063 return ExprError();
10065 if (!getDerived().AlwaysRebuild() &&
10066 SubExpr.get() == E->getExprOperand())
10069 return getDerived().RebuildCXXUuidofExpr(E->getType(),
10075 template<typename Derived>
10077 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
10081 template<typename Derived>
10083 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
10084 CXXNullPtrLiteralExpr *E) {
10088 template<typename Derived>
10090 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
10091 QualType T = getSema().getCurrentThisType();
10093 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
10094 // Make sure that we capture 'this'.
10095 getSema().CheckCXXThisCapture(E->getLocStart());
10099 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
10102 template<typename Derived>
10104 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
10105 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10106 if (SubExpr.isInvalid())
10107 return ExprError();
10109 if (!getDerived().AlwaysRebuild() &&
10110 SubExpr.get() == E->getSubExpr())
10113 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10114 E->isThrownVariableInScope());
10117 template<typename Derived>
10119 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
10121 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
10124 return ExprError();
10126 if (!getDerived().AlwaysRebuild() &&
10127 Param == E->getParam())
10130 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
10133 template<typename Derived>
10135 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
10137 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
10140 return ExprError();
10142 if (!getDerived().AlwaysRebuild() && Field == E->getField())
10145 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10148 template<typename Derived>
10150 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10151 CXXScalarValueInitExpr *E) {
10152 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10154 return ExprError();
10156 if (!getDerived().AlwaysRebuild() &&
10157 T == E->getTypeSourceInfo())
10160 return getDerived().RebuildCXXScalarValueInitExpr(T,
10161 /*FIXME:*/T->getTypeLoc().getEndLoc(),
10162 E->getRParenLoc());
10165 template<typename Derived>
10167 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
10168 // Transform the type that we're allocating
10169 TypeSourceInfo *AllocTypeInfo =
10170 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
10171 if (!AllocTypeInfo)
10172 return ExprError();
10174 // Transform the size of the array we're allocating (if any).
10175 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
10176 if (ArraySize.isInvalid())
10177 return ExprError();
10179 // Transform the placement arguments (if any).
10180 bool ArgumentChanged = false;
10181 SmallVector<Expr*, 8> PlacementArgs;
10182 if (getDerived().TransformExprs(E->getPlacementArgs(),
10183 E->getNumPlacementArgs(), true,
10184 PlacementArgs, &ArgumentChanged))
10185 return ExprError();
10187 // Transform the initializer (if any).
10188 Expr *OldInit = E->getInitializer();
10189 ExprResult NewInit;
10191 NewInit = getDerived().TransformInitializer(OldInit, true);
10192 if (NewInit.isInvalid())
10193 return ExprError();
10195 // Transform new operator and delete operator.
10196 FunctionDecl *OperatorNew = nullptr;
10197 if (E->getOperatorNew()) {
10198 OperatorNew = cast_or_null<FunctionDecl>(
10199 getDerived().TransformDecl(E->getLocStart(),
10200 E->getOperatorNew()));
10202 return ExprError();
10205 FunctionDecl *OperatorDelete = nullptr;
10206 if (E->getOperatorDelete()) {
10207 OperatorDelete = cast_or_null<FunctionDecl>(
10208 getDerived().TransformDecl(E->getLocStart(),
10209 E->getOperatorDelete()));
10210 if (!OperatorDelete)
10211 return ExprError();
10214 if (!getDerived().AlwaysRebuild() &&
10215 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
10216 ArraySize.get() == E->getArraySize() &&
10217 NewInit.get() == OldInit &&
10218 OperatorNew == E->getOperatorNew() &&
10219 OperatorDelete == E->getOperatorDelete() &&
10220 !ArgumentChanged) {
10221 // Mark any declarations we need as referenced.
10222 // FIXME: instantiation-specific.
10224 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
10225 if (OperatorDelete)
10226 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
10228 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
10229 QualType ElementType
10230 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10231 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10232 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10233 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
10234 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
10242 QualType AllocType = AllocTypeInfo->getType();
10243 if (!ArraySize.get()) {
10244 // If no array size was specified, but the new expression was
10245 // instantiated with an array type (e.g., "new T" where T is
10246 // instantiated with "int[4]"), extract the outer bound from the
10247 // array type as our array size. We do this with constant and
10248 // dependently-sized array types.
10249 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10252 } else if (const ConstantArrayType *ConsArrayT
10253 = dyn_cast<ConstantArrayType>(ArrayT)) {
10254 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10255 SemaRef.Context.getSizeType(),
10256 /*FIXME:*/ E->getLocStart());
10257 AllocType = ConsArrayT->getElementType();
10258 } else if (const DependentSizedArrayType *DepArrayT
10259 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10260 if (DepArrayT->getSizeExpr()) {
10261 ArraySize = DepArrayT->getSizeExpr();
10262 AllocType = DepArrayT->getElementType();
10267 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10269 /*FIXME:*/E->getLocStart(),
10271 /*FIXME:*/E->getLocStart(),
10272 E->getTypeIdParens(),
10276 E->getDirectInitRange(),
10280 template<typename Derived>
10282 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
10283 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
10284 if (Operand.isInvalid())
10285 return ExprError();
10287 // Transform the delete operator, if known.
10288 FunctionDecl *OperatorDelete = nullptr;
10289 if (E->getOperatorDelete()) {
10290 OperatorDelete = cast_or_null<FunctionDecl>(
10291 getDerived().TransformDecl(E->getLocStart(),
10292 E->getOperatorDelete()));
10293 if (!OperatorDelete)
10294 return ExprError();
10297 if (!getDerived().AlwaysRebuild() &&
10298 Operand.get() == E->getArgument() &&
10299 OperatorDelete == E->getOperatorDelete()) {
10300 // Mark any declarations we need as referenced.
10301 // FIXME: instantiation-specific.
10302 if (OperatorDelete)
10303 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
10305 if (!E->getArgument()->isTypeDependent()) {
10306 QualType Destroyed = SemaRef.Context.getBaseElementType(
10307 E->getDestroyedType());
10308 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10309 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
10310 SemaRef.MarkFunctionReferenced(E->getLocStart(),
10311 SemaRef.LookupDestructor(Record));
10318 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10319 E->isGlobalDelete(),
10324 template<typename Derived>
10326 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
10327 CXXPseudoDestructorExpr *E) {
10328 ExprResult Base = getDerived().TransformExpr(E->getBase());
10329 if (Base.isInvalid())
10330 return ExprError();
10332 ParsedType ObjectTypePtr;
10333 bool MayBePseudoDestructor = false;
10334 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10335 E->getOperatorLoc(),
10336 E->isArrow()? tok::arrow : tok::period,
10338 MayBePseudoDestructor);
10339 if (Base.isInvalid())
10340 return ExprError();
10342 QualType ObjectType = ObjectTypePtr.get();
10343 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10344 if (QualifierLoc) {
10346 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10348 return ExprError();
10351 SS.Adopt(QualifierLoc);
10353 PseudoDestructorTypeStorage Destroyed;
10354 if (E->getDestroyedTypeInfo()) {
10355 TypeSourceInfo *DestroyedTypeInfo
10356 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
10357 ObjectType, nullptr, SS);
10358 if (!DestroyedTypeInfo)
10359 return ExprError();
10360 Destroyed = DestroyedTypeInfo;
10361 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
10362 // We aren't likely to be able to resolve the identifier down to a type
10363 // now anyway, so just retain the identifier.
10364 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10365 E->getDestroyedTypeLoc());
10367 // Look for a destructor known with the given name.
10368 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
10369 *E->getDestroyedTypeIdentifier(),
10370 E->getDestroyedTypeLoc(),
10375 return ExprError();
10378 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10379 E->getDestroyedTypeLoc());
10382 TypeSourceInfo *ScopeTypeInfo = nullptr;
10383 if (E->getScopeTypeInfo()) {
10384 CXXScopeSpec EmptySS;
10385 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
10386 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
10387 if (!ScopeTypeInfo)
10388 return ExprError();
10391 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
10392 E->getOperatorLoc(),
10396 E->getColonColonLoc(),
10401 template <typename Derived>
10402 bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10405 // Transform all the decls.
10406 bool AllEmptyPacks = true;
10407 for (auto *OldD : Old->decls()) {
10408 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10410 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10411 // This can happen because of dependent hiding.
10412 if (isa<UsingShadowDecl>(OldD))
10420 // Expand using pack declarations.
10421 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10422 ArrayRef<NamedDecl*> Decls = SingleDecl;
10423 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10424 Decls = UPD->expansions();
10426 // Expand using declarations.
10427 for (auto *D : Decls) {
10428 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10429 for (auto *SD : UD->shadows())
10436 AllEmptyPacks &= Decls.empty();
10439 // C++ [temp.res]/8.4.2:
10440 // The program is ill-formed, no diagnostic required, if [...] lookup for
10441 // a name in the template definition found a using-declaration, but the
10442 // lookup in the corresponding scope in the instantiation odoes not find
10443 // any declarations because the using-declaration was a pack expansion and
10444 // the corresponding pack is empty
10445 if (AllEmptyPacks && !RequiresADL) {
10446 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10447 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
10451 // Resolve a kind, but don't do any further analysis. If it's
10452 // ambiguous, the callee needs to deal with it.
10457 template<typename Derived>
10459 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
10460 UnresolvedLookupExpr *Old) {
10461 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10462 Sema::LookupOrdinaryName);
10464 // Transform the declaration set.
10465 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10466 return ExprError();
10468 // Rebuild the nested-name qualifier, if present.
10470 if (Old->getQualifierLoc()) {
10471 NestedNameSpecifierLoc QualifierLoc
10472 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10474 return ExprError();
10476 SS.Adopt(QualifierLoc);
10479 if (Old->getNamingClass()) {
10480 CXXRecordDecl *NamingClass
10481 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10483 Old->getNamingClass()));
10484 if (!NamingClass) {
10486 return ExprError();
10489 R.setNamingClass(NamingClass);
10492 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10494 // If we have neither explicit template arguments, nor the template keyword,
10495 // it's a normal declaration name or member reference.
10496 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10497 NamedDecl *D = R.getAsSingle<NamedDecl>();
10498 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10499 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10500 // give a good diagnostic.
10501 if (D && D->isCXXInstanceMember()) {
10502 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10503 /*TemplateArgs=*/nullptr,
10504 /*Scope=*/nullptr);
10507 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
10510 // If we have template arguments, rebuild them, then rebuild the
10511 // templateid expression.
10512 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
10513 if (Old->hasExplicitTemplateArgs() &&
10514 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10515 Old->getNumTemplateArgs(),
10518 return ExprError();
10521 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
10522 Old->requiresADL(), &TransArgs);
10525 template<typename Derived>
10527 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10528 bool ArgChanged = false;
10529 SmallVector<TypeSourceInfo *, 4> Args;
10530 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10531 TypeSourceInfo *From = E->getArg(I);
10532 TypeLoc FromTL = From->getTypeLoc();
10533 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
10534 TypeLocBuilder TLB;
10535 TLB.reserve(FromTL.getFullDataSize());
10536 QualType To = getDerived().TransformType(TLB, FromTL);
10538 return ExprError();
10540 if (To == From->getType())
10541 Args.push_back(From);
10543 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10551 // We have a pack expansion. Instantiate it.
10552 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
10553 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10554 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10555 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
10557 // Determine whether the set of unexpanded parameter packs can and should
10559 bool Expand = true;
10560 bool RetainExpansion = false;
10561 Optional<unsigned> OrigNumExpansions =
10562 ExpansionTL.getTypePtr()->getNumExpansions();
10563 Optional<unsigned> NumExpansions = OrigNumExpansions;
10564 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10565 PatternTL.getSourceRange(),
10567 Expand, RetainExpansion,
10569 return ExprError();
10572 // The transform has determined that we should perform a simple
10573 // transformation on the pack expansion, producing another pack
10575 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10577 TypeLocBuilder TLB;
10578 TLB.reserve(From->getTypeLoc().getFullDataSize());
10580 QualType To = getDerived().TransformType(TLB, PatternTL);
10582 return ExprError();
10584 To = getDerived().RebuildPackExpansionType(To,
10585 PatternTL.getSourceRange(),
10586 ExpansionTL.getEllipsisLoc(),
10589 return ExprError();
10591 PackExpansionTypeLoc ToExpansionTL
10592 = TLB.push<PackExpansionTypeLoc>(To);
10593 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10594 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10598 // Expand the pack expansion by substituting for each argument in the
10600 for (unsigned I = 0; I != *NumExpansions; ++I) {
10601 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10602 TypeLocBuilder TLB;
10603 TLB.reserve(PatternTL.getFullDataSize());
10604 QualType To = getDerived().TransformType(TLB, PatternTL);
10606 return ExprError();
10608 if (To->containsUnexpandedParameterPack()) {
10609 To = getDerived().RebuildPackExpansionType(To,
10610 PatternTL.getSourceRange(),
10611 ExpansionTL.getEllipsisLoc(),
10614 return ExprError();
10616 PackExpansionTypeLoc ToExpansionTL
10617 = TLB.push<PackExpansionTypeLoc>(To);
10618 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10621 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10624 if (!RetainExpansion)
10627 // If we're supposed to retain a pack expansion, do so by temporarily
10628 // forgetting the partially-substituted parameter pack.
10629 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10631 TypeLocBuilder TLB;
10632 TLB.reserve(From->getTypeLoc().getFullDataSize());
10634 QualType To = getDerived().TransformType(TLB, PatternTL);
10636 return ExprError();
10638 To = getDerived().RebuildPackExpansionType(To,
10639 PatternTL.getSourceRange(),
10640 ExpansionTL.getEllipsisLoc(),
10643 return ExprError();
10645 PackExpansionTypeLoc ToExpansionTL
10646 = TLB.push<PackExpansionTypeLoc>(To);
10647 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10648 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10651 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10654 return getDerived().RebuildTypeTrait(E->getTrait(),
10660 template<typename Derived>
10662 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10663 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10665 return ExprError();
10667 if (!getDerived().AlwaysRebuild() &&
10668 T == E->getQueriedTypeSourceInfo())
10671 ExprResult SubExpr;
10673 EnterExpressionEvaluationContext Unevaluated(
10674 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
10675 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10676 if (SubExpr.isInvalid())
10677 return ExprError();
10679 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
10683 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10690 template<typename Derived>
10692 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10693 ExprResult SubExpr;
10695 EnterExpressionEvaluationContext Unevaluated(
10696 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
10697 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10698 if (SubExpr.isInvalid())
10699 return ExprError();
10701 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
10705 return getDerived().RebuildExpressionTrait(
10706 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10709 template <typename Derived>
10710 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10711 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10712 TypeSourceInfo **RecoveryTSI) {
10713 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10714 DRE, AddrTaken, RecoveryTSI);
10716 // Propagate both errors and recovered types, which return ExprEmpty.
10717 if (!NewDRE.isUsable())
10720 // We got an expr, wrap it up in parens.
10721 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10723 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10727 template <typename Derived>
10728 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10729 DependentScopeDeclRefExpr *E) {
10730 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10734 template<typename Derived>
10736 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10737 DependentScopeDeclRefExpr *E,
10738 bool IsAddressOfOperand,
10739 TypeSourceInfo **RecoveryTSI) {
10740 assert(E->getQualifierLoc());
10741 NestedNameSpecifierLoc QualifierLoc
10742 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10744 return ExprError();
10745 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10747 // TODO: If this is a conversion-function-id, verify that the
10748 // destination type name (if present) resolves the same way after
10749 // instantiation as it did in the local scope.
10751 DeclarationNameInfo NameInfo
10752 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10753 if (!NameInfo.getName())
10754 return ExprError();
10756 if (!E->hasExplicitTemplateArgs()) {
10757 if (!getDerived().AlwaysRebuild() &&
10758 QualifierLoc == E->getQualifierLoc() &&
10759 // Note: it is sufficient to compare the Name component of NameInfo:
10760 // if name has not changed, DNLoc has not changed either.
10761 NameInfo.getName() == E->getDeclName())
10764 return getDerived().RebuildDependentScopeDeclRefExpr(
10765 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10766 IsAddressOfOperand, RecoveryTSI);
10769 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10770 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10771 E->getNumTemplateArgs(),
10773 return ExprError();
10775 return getDerived().RebuildDependentScopeDeclRefExpr(
10776 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10780 template<typename Derived>
10782 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
10783 // CXXConstructExprs other than for list-initialization and
10784 // CXXTemporaryObjectExpr are always implicit, so when we have
10785 // a 1-argument construction we just transform that argument.
10786 if ((E->getNumArgs() == 1 ||
10787 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
10788 (!getDerived().DropCallArgument(E->getArg(0))) &&
10789 !E->isListInitialization())
10790 return getDerived().TransformExpr(E->getArg(0));
10792 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10794 QualType T = getDerived().TransformType(E->getType());
10796 return ExprError();
10798 CXXConstructorDecl *Constructor
10799 = cast_or_null<CXXConstructorDecl>(
10800 getDerived().TransformDecl(E->getLocStart(),
10801 E->getConstructor()));
10803 return ExprError();
10805 bool ArgumentChanged = false;
10806 SmallVector<Expr*, 8> Args;
10807 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10809 return ExprError();
10811 if (!getDerived().AlwaysRebuild() &&
10812 T == E->getType() &&
10813 Constructor == E->getConstructor() &&
10814 !ArgumentChanged) {
10815 // Mark the constructor as referenced.
10816 // FIXME: Instantiation-specific
10817 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10821 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
10823 E->isElidable(), Args,
10824 E->hadMultipleCandidates(),
10825 E->isListInitialization(),
10826 E->isStdInitListInitialization(),
10827 E->requiresZeroInitialization(),
10828 E->getConstructionKind(),
10829 E->getParenOrBraceRange());
10832 template<typename Derived>
10833 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10834 CXXInheritedCtorInitExpr *E) {
10835 QualType T = getDerived().TransformType(E->getType());
10837 return ExprError();
10839 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10840 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10842 return ExprError();
10844 if (!getDerived().AlwaysRebuild() &&
10845 T == E->getType() &&
10846 Constructor == E->getConstructor()) {
10847 // Mark the constructor as referenced.
10848 // FIXME: Instantiation-specific
10849 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10853 return getDerived().RebuildCXXInheritedCtorInitExpr(
10854 T, E->getLocation(), Constructor,
10855 E->constructsVBase(), E->inheritedFromVBase());
10858 /// Transform a C++ temporary-binding expression.
10860 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10861 /// transform the subexpression and return that.
10862 template<typename Derived>
10864 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
10865 return getDerived().TransformExpr(E->getSubExpr());
10868 /// Transform a C++ expression that contains cleanups that should
10869 /// be run after the expression is evaluated.
10871 /// Since ExprWithCleanups nodes are implicitly generated, we
10872 /// just transform the subexpression and return that.
10873 template<typename Derived>
10875 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
10876 return getDerived().TransformExpr(E->getSubExpr());
10879 template<typename Derived>
10881 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
10882 CXXTemporaryObjectExpr *E) {
10883 TypeSourceInfo *T =
10884 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
10886 return ExprError();
10888 CXXConstructorDecl *Constructor
10889 = cast_or_null<CXXConstructorDecl>(
10890 getDerived().TransformDecl(E->getLocStart(),
10891 E->getConstructor()));
10893 return ExprError();
10895 bool ArgumentChanged = false;
10896 SmallVector<Expr*, 8> Args;
10897 Args.reserve(E->getNumArgs());
10898 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10900 return ExprError();
10902 if (!getDerived().AlwaysRebuild() &&
10903 T == E->getTypeSourceInfo() &&
10904 Constructor == E->getConstructor() &&
10905 !ArgumentChanged) {
10906 // FIXME: Instantiation-specific
10907 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10908 return SemaRef.MaybeBindToTemporary(E);
10911 // FIXME: We should just pass E->isListInitialization(), but we're not
10912 // prepared to handle list-initialization without a child InitListExpr.
10913 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
10914 return getDerived().RebuildCXXTemporaryObjectExpr(
10915 T, LParenLoc, Args, E->getLocEnd(),
10916 /*ListInitialization=*/LParenLoc.isInvalid());
10919 template<typename Derived>
10921 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
10922 // Transform any init-capture expressions before entering the scope of the
10923 // lambda body, because they are not semantically within that scope.
10924 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
10925 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10926 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
10927 E->explicit_capture_begin());
10928 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10929 CEnd = E->capture_end();
10931 if (!E->isInitCapture(C))
10933 EnterExpressionEvaluationContext EEEC(
10934 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
10935 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10936 C->getCapturedVar()->getInit(),
10937 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
10939 if (NewExprInitResult.isInvalid())
10940 return ExprError();
10941 Expr *NewExprInit = NewExprInitResult.get();
10943 VarDecl *OldVD = C->getCapturedVar();
10944 QualType NewInitCaptureType =
10945 getSema().buildLambdaInitCaptureInitialization(
10946 C->getLocation(), OldVD->getType()->isReferenceType(),
10947 OldVD->getIdentifier(),
10948 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
10949 NewExprInitResult = NewExprInit;
10950 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10951 std::make_pair(NewExprInitResult, NewInitCaptureType);
10954 // Transform the template parameters, and add them to the current
10955 // instantiation scope. The null case is handled correctly.
10956 auto TPL = getDerived().TransformTemplateParameterList(
10957 E->getTemplateParameterList());
10959 // Transform the type of the original lambda's call operator.
10960 // The transformation MUST be done in the CurrentInstantiationScope since
10961 // it introduces a mapping of the original to the newly created
10962 // transformed parameters.
10963 TypeSourceInfo *NewCallOpTSI = nullptr;
10965 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10966 FunctionProtoTypeLoc OldCallOpFPTL =
10967 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
10969 TypeLocBuilder NewCallOpTLBuilder;
10970 SmallVector<QualType, 4> ExceptionStorage;
10971 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
10972 QualType NewCallOpType = TransformFunctionProtoType(
10973 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
10974 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10975 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10976 ExceptionStorage, Changed);
10978 if (NewCallOpType.isNull())
10979 return ExprError();
10980 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10984 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10985 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10986 LSI->GLTemplateParameterList = TPL;
10988 // Create the local class that will describe the lambda.
10989 CXXRecordDecl *Class
10990 = getSema().createLambdaClosureType(E->getIntroducerRange(),
10992 /*KnownDependent=*/false,
10993 E->getCaptureDefault());
10994 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10996 // Build the call operator.
10997 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10998 Class, E->getIntroducerRange(), NewCallOpTSI,
10999 E->getCallOperator()->getLocEnd(),
11000 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
11001 E->getCallOperator()->isConstexpr());
11003 LSI->CallOperator = NewCallOperator;
11005 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11006 I != NumParams; ++I) {
11007 auto *P = NewCallOperator->getParamDecl(I);
11008 if (P->hasUninstantiatedDefaultArg()) {
11009 EnterExpressionEvaluationContext Eval(
11011 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
11012 ExprResult R = getDerived().TransformExpr(
11013 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11014 P->setDefaultArg(R.get());
11018 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
11019 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
11021 // Introduce the context of the call operator.
11022 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
11023 /*NewThisContext*/false);
11025 // Enter the scope of the lambda.
11026 getSema().buildLambdaScope(LSI, NewCallOperator,
11027 E->getIntroducerRange(),
11028 E->getCaptureDefault(),
11029 E->getCaptureDefaultLoc(),
11030 E->hasExplicitParameters(),
11031 E->hasExplicitResultType(),
11034 bool Invalid = false;
11036 // Transform captures.
11037 bool FinishedExplicitCaptures = false;
11038 for (LambdaExpr::capture_iterator C = E->capture_begin(),
11039 CEnd = E->capture_end();
11041 // When we hit the first implicit capture, tell Sema that we've finished
11042 // the list of explicit captures.
11043 if (!FinishedExplicitCaptures && C->isImplicit()) {
11044 getSema().finishLambdaExplicitCaptures(LSI);
11045 FinishedExplicitCaptures = true;
11048 // Capturing 'this' is trivial.
11049 if (C->capturesThis()) {
11050 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11051 /*BuildAndDiagnose*/ true, nullptr,
11052 C->getCaptureKind() == LCK_StarThis);
11055 // Captured expression will be recaptured during captured variables
11057 if (C->capturesVLAType())
11060 // Rebuild init-captures, including the implied field declaration.
11061 if (E->isInitCapture(C)) {
11062 InitCaptureInfoTy InitExprTypePair =
11063 InitCaptureExprsAndTypes[C - E->capture_begin()];
11064 ExprResult Init = InitExprTypePair.first;
11065 QualType InitQualType = InitExprTypePair.second;
11066 if (Init.isInvalid() || InitQualType.isNull()) {
11070 VarDecl *OldVD = C->getCapturedVar();
11071 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
11072 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
11073 OldVD->getInitStyle(), Init.get());
11077 getDerived().transformedLocalDecl(OldVD, NewVD);
11079 getSema().buildInitCaptureField(LSI, NewVD);
11083 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11085 // Determine the capture kind for Sema.
11086 Sema::TryCaptureKind Kind
11087 = C->isImplicit()? Sema::TryCapture_Implicit
11088 : C->getCaptureKind() == LCK_ByCopy
11089 ? Sema::TryCapture_ExplicitByVal
11090 : Sema::TryCapture_ExplicitByRef;
11091 SourceLocation EllipsisLoc;
11092 if (C->isPackExpansion()) {
11093 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11094 bool ShouldExpand = false;
11095 bool RetainExpansion = false;
11096 Optional<unsigned> NumExpansions;
11097 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11100 ShouldExpand, RetainExpansion,
11106 if (ShouldExpand) {
11107 // The transform has determined that we should perform an expansion;
11108 // transform and capture each of the arguments.
11109 // expansion of the pattern. Do so.
11110 VarDecl *Pack = C->getCapturedVar();
11111 for (unsigned I = 0; I != *NumExpansions; ++I) {
11112 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11113 VarDecl *CapturedVar
11114 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
11116 if (!CapturedVar) {
11121 // Capture the transformed variable.
11122 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11125 // FIXME: Retain a pack expansion if RetainExpansion is true.
11130 EllipsisLoc = C->getEllipsisLoc();
11133 // Transform the captured variable.
11134 VarDecl *CapturedVar
11135 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
11136 C->getCapturedVar()));
11137 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
11142 // Capture the transformed variable.
11143 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11146 if (!FinishedExplicitCaptures)
11147 getSema().finishLambdaExplicitCaptures(LSI);
11149 // Enter a new evaluation context to insulate the lambda from any
11150 // cleanups from the enclosing full-expression.
11151 getSema().PushExpressionEvaluationContext(
11152 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
11154 // Instantiate the body of the lambda expression.
11156 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11158 // ActOnLambda* will pop the function scope for us.
11159 FuncScopeCleanup.disable();
11161 if (Body.isInvalid()) {
11162 SavedContext.pop();
11163 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
11164 /*IsInstantiation=*/true);
11165 return ExprError();
11168 // Copy the LSI before ActOnFinishFunctionBody removes it.
11169 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11170 // the call operator.
11171 auto LSICopy = *LSI;
11172 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11173 /*IsInstantiation*/ true);
11174 SavedContext.pop();
11176 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11180 template<typename Derived>
11182 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
11183 CXXUnresolvedConstructExpr *E) {
11184 TypeSourceInfo *T =
11185 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
11187 return ExprError();
11189 bool ArgumentChanged = false;
11190 SmallVector<Expr*, 8> Args;
11191 Args.reserve(E->arg_size());
11192 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11194 return ExprError();
11196 if (!getDerived().AlwaysRebuild() &&
11197 T == E->getTypeSourceInfo() &&
11201 // FIXME: we're faking the locations of the commas
11202 return getDerived().RebuildCXXUnresolvedConstructExpr(
11203 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
11206 template<typename Derived>
11208 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
11209 CXXDependentScopeMemberExpr *E) {
11210 // Transform the base of the expression.
11211 ExprResult Base((Expr*) nullptr);
11214 QualType ObjectType;
11215 if (!E->isImplicitAccess()) {
11216 OldBase = E->getBase();
11217 Base = getDerived().TransformExpr(OldBase);
11218 if (Base.isInvalid())
11219 return ExprError();
11221 // Start the member reference and compute the object's type.
11222 ParsedType ObjectTy;
11223 bool MayBePseudoDestructor = false;
11224 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
11225 E->getOperatorLoc(),
11226 E->isArrow()? tok::arrow : tok::period,
11228 MayBePseudoDestructor);
11229 if (Base.isInvalid())
11230 return ExprError();
11232 ObjectType = ObjectTy.get();
11233 BaseType = ((Expr*) Base.get())->getType();
11236 BaseType = getDerived().TransformType(E->getBaseType());
11237 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11240 // Transform the first part of the nested-name-specifier that qualifies
11241 // the member name.
11242 NamedDecl *FirstQualifierInScope
11243 = getDerived().TransformFirstQualifierInScope(
11244 E->getFirstQualifierFoundInScope(),
11245 E->getQualifierLoc().getBeginLoc());
11247 NestedNameSpecifierLoc QualifierLoc;
11248 if (E->getQualifier()) {
11250 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11252 FirstQualifierInScope);
11254 return ExprError();
11257 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11259 // TODO: If this is a conversion-function-id, verify that the
11260 // destination type name (if present) resolves the same way after
11261 // instantiation as it did in the local scope.
11263 DeclarationNameInfo NameInfo
11264 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
11265 if (!NameInfo.getName())
11266 return ExprError();
11268 if (!E->hasExplicitTemplateArgs()) {
11269 // This is a reference to a member without an explicitly-specified
11270 // template argument list. Optimize for this common case.
11271 if (!getDerived().AlwaysRebuild() &&
11272 Base.get() == OldBase &&
11273 BaseType == E->getBaseType() &&
11274 QualifierLoc == E->getQualifierLoc() &&
11275 NameInfo.getName() == E->getMember() &&
11276 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
11279 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
11282 E->getOperatorLoc(),
11285 FirstQualifierInScope,
11287 /*TemplateArgs*/nullptr);
11290 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
11291 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11292 E->getNumTemplateArgs(),
11294 return ExprError();
11296 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
11299 E->getOperatorLoc(),
11302 FirstQualifierInScope,
11307 template<typename Derived>
11309 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
11310 // Transform the base of the expression.
11311 ExprResult Base((Expr*) nullptr);
11313 if (!Old->isImplicitAccess()) {
11314 Base = getDerived().TransformExpr(Old->getBase());
11315 if (Base.isInvalid())
11316 return ExprError();
11317 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
11319 if (Base.isInvalid())
11320 return ExprError();
11321 BaseType = Base.get()->getType();
11323 BaseType = getDerived().TransformType(Old->getBaseType());
11326 NestedNameSpecifierLoc QualifierLoc;
11327 if (Old->getQualifierLoc()) {
11329 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11331 return ExprError();
11334 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11336 LookupResult R(SemaRef, Old->getMemberNameInfo(),
11337 Sema::LookupOrdinaryName);
11339 // Transform the declaration set.
11340 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11341 return ExprError();
11343 // Determine the naming class.
11344 if (Old->getNamingClass()) {
11345 CXXRecordDecl *NamingClass
11346 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
11347 Old->getMemberLoc(),
11348 Old->getNamingClass()));
11350 return ExprError();
11352 R.setNamingClass(NamingClass);
11355 TemplateArgumentListInfo TransArgs;
11356 if (Old->hasExplicitTemplateArgs()) {
11357 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11358 TransArgs.setRAngleLoc(Old->getRAngleLoc());
11359 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11360 Old->getNumTemplateArgs(),
11362 return ExprError();
11365 // FIXME: to do this check properly, we will need to preserve the
11366 // first-qualifier-in-scope here, just in case we had a dependent
11367 // base (and therefore couldn't do the check) and a
11368 // nested-name-qualifier (and therefore could do the lookup).
11369 NamedDecl *FirstQualifierInScope = nullptr;
11371 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
11373 Old->getOperatorLoc(),
11377 FirstQualifierInScope,
11379 (Old->hasExplicitTemplateArgs()
11380 ? &TransArgs : nullptr));
11383 template<typename Derived>
11385 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
11386 EnterExpressionEvaluationContext Unevaluated(
11387 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
11388 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11389 if (SubExpr.isInvalid())
11390 return ExprError();
11392 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
11395 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11398 template<typename Derived>
11400 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
11401 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11402 if (Pattern.isInvalid())
11403 return ExprError();
11405 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
11408 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11409 E->getNumExpansions());
11412 template<typename Derived>
11414 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11415 // If E is not value-dependent, then nothing will change when we transform it.
11416 // Note: This is an instantiation-centric view.
11417 if (!E->isValueDependent())
11420 EnterExpressionEvaluationContext Unevaluated(
11421 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
11423 ArrayRef<TemplateArgument> PackArgs;
11424 TemplateArgument ArgStorage;
11426 // Find the argument list to transform.
11427 if (E->isPartiallySubstituted()) {
11428 PackArgs = E->getPartialArguments();
11429 } else if (E->isValueDependent()) {
11430 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11431 bool ShouldExpand = false;
11432 bool RetainExpansion = false;
11433 Optional<unsigned> NumExpansions;
11434 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11436 ShouldExpand, RetainExpansion,
11438 return ExprError();
11440 // If we need to expand the pack, build a template argument from it and
11442 if (ShouldExpand) {
11443 auto *Pack = E->getPack();
11444 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11445 ArgStorage = getSema().Context.getPackExpansionType(
11446 getSema().Context.getTypeDeclType(TTPD), None);
11447 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11448 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11450 auto *VD = cast<ValueDecl>(Pack);
11451 ExprResult DRE = getSema().BuildDeclRefExpr(
11452 VD, VD->getType().getNonLValueExprType(getSema().Context),
11453 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11455 if (DRE.isInvalid())
11456 return ExprError();
11457 ArgStorage = new (getSema().Context) PackExpansionExpr(
11458 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11460 PackArgs = ArgStorage;
11464 // If we're not expanding the pack, just transform the decl.
11465 if (!PackArgs.size()) {
11466 auto *Pack = cast_or_null<NamedDecl>(
11467 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
11469 return ExprError();
11470 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11472 E->getRParenLoc(), None, None);
11475 // Try to compute the result without performing a partial substitution.
11476 Optional<unsigned> Result = 0;
11477 for (const TemplateArgument &Arg : PackArgs) {
11478 if (!Arg.isPackExpansion()) {
11479 Result = *Result + 1;
11483 TemplateArgumentLoc ArgLoc;
11484 InventTemplateArgumentLoc(Arg, ArgLoc);
11486 // Find the pattern of the pack expansion.
11487 SourceLocation Ellipsis;
11488 Optional<unsigned> OrigNumExpansions;
11489 TemplateArgumentLoc Pattern =
11490 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11491 OrigNumExpansions);
11493 // Substitute under the pack expansion. Do not expand the pack (yet).
11494 TemplateArgumentLoc OutPattern;
11495 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11496 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11500 // See if we can determine the number of arguments from the result.
11501 Optional<unsigned> NumExpansions =
11502 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11503 if (!NumExpansions) {
11504 // No: we must be in an alias template expansion, and we're going to need
11505 // to actually expand the packs.
11510 Result = *Result + *NumExpansions;
11513 // Common case: we could determine the number of expansions without
11516 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11518 E->getRParenLoc(), *Result, None);
11520 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11523 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11524 typedef TemplateArgumentLocInventIterator<
11525 Derived, const TemplateArgument*> PackLocIterator;
11526 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11527 PackLocIterator(*this, PackArgs.end()),
11528 TransformedPackArgs, /*Uneval*/true))
11529 return ExprError();
11532 // Check whether we managed to fully-expand the pack.
11533 // FIXME: Is it possible for us to do so and not hit the early exit path?
11534 SmallVector<TemplateArgument, 8> Args;
11535 bool PartialSubstitution = false;
11536 for (auto &Loc : TransformedPackArgs.arguments()) {
11537 Args.push_back(Loc.getArgument());
11538 if (Loc.getArgument().isPackExpansion())
11539 PartialSubstitution = true;
11542 if (PartialSubstitution)
11543 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11545 E->getRParenLoc(), None, Args);
11547 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11548 E->getPackLoc(), E->getRParenLoc(),
11549 Args.size(), None);
11552 template<typename Derived>
11554 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11555 SubstNonTypeTemplateParmPackExpr *E) {
11556 // Default behavior is to do nothing with this transformation.
11560 template<typename Derived>
11562 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11563 SubstNonTypeTemplateParmExpr *E) {
11564 // Default behavior is to do nothing with this transformation.
11568 template<typename Derived>
11570 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11571 // Default behavior is to do nothing with this transformation.
11575 template<typename Derived>
11577 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11578 MaterializeTemporaryExpr *E) {
11579 return getDerived().TransformExpr(E->GetTemporaryExpr());
11582 template<typename Derived>
11584 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11585 Expr *Pattern = E->getPattern();
11587 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11588 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11589 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11591 // Determine whether the set of unexpanded parameter packs can and should
11593 bool Expand = true;
11594 bool RetainExpansion = false;
11595 Optional<unsigned> NumExpansions;
11596 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11597 Pattern->getSourceRange(),
11599 Expand, RetainExpansion,
11604 // Do not expand any packs here, just transform and rebuild a fold
11606 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11609 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11610 if (LHS.isInvalid())
11614 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11615 if (RHS.isInvalid())
11618 if (!getDerived().AlwaysRebuild() &&
11619 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11622 return getDerived().RebuildCXXFoldExpr(
11623 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11624 RHS.get(), E->getLocEnd());
11627 // The transform has determined that we should perform an elementwise
11628 // expansion of the pattern. Do so.
11629 ExprResult Result = getDerived().TransformExpr(E->getInit());
11630 if (Result.isInvalid())
11632 bool LeftFold = E->isLeftFold();
11634 // If we're retaining an expansion for a right fold, it is the innermost
11635 // component and takes the init (if any).
11636 if (!LeftFold && RetainExpansion) {
11637 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11639 ExprResult Out = getDerived().TransformExpr(Pattern);
11640 if (Out.isInvalid())
11643 Result = getDerived().RebuildCXXFoldExpr(
11644 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11645 Result.get(), E->getLocEnd());
11646 if (Result.isInvalid())
11650 for (unsigned I = 0; I != *NumExpansions; ++I) {
11651 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11652 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11653 ExprResult Out = getDerived().TransformExpr(Pattern);
11654 if (Out.isInvalid())
11657 if (Out.get()->containsUnexpandedParameterPack()) {
11658 // We still have a pack; retain a pack expansion for this slice.
11659 Result = getDerived().RebuildCXXFoldExpr(
11661 LeftFold ? Result.get() : Out.get(),
11662 E->getOperator(), E->getEllipsisLoc(),
11663 LeftFold ? Out.get() : Result.get(),
11665 } else if (Result.isUsable()) {
11666 // We've got down to a single element; build a binary operator.
11667 Result = getDerived().RebuildBinaryOperator(
11668 E->getEllipsisLoc(), E->getOperator(),
11669 LeftFold ? Result.get() : Out.get(),
11670 LeftFold ? Out.get() : Result.get());
11674 if (Result.isInvalid())
11678 // If we're retaining an expansion for a left fold, it is the outermost
11679 // component and takes the complete expansion so far as its init (if any).
11680 if (LeftFold && RetainExpansion) {
11681 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11683 ExprResult Out = getDerived().TransformExpr(Pattern);
11684 if (Out.isInvalid())
11687 Result = getDerived().RebuildCXXFoldExpr(
11688 E->getLocStart(), Result.get(),
11689 E->getOperator(), E->getEllipsisLoc(),
11690 Out.get(), E->getLocEnd());
11691 if (Result.isInvalid())
11695 // If we had no init and an empty pack, and we're not retaining an expansion,
11696 // then produce a fallback value or error.
11697 if (Result.isUnset())
11698 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11704 template<typename Derived>
11706 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11707 CXXStdInitializerListExpr *E) {
11708 return getDerived().TransformExpr(E->getSubExpr());
11711 template<typename Derived>
11713 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
11714 return SemaRef.MaybeBindToTemporary(E);
11717 template<typename Derived>
11719 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
11723 template<typename Derived>
11725 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11726 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11727 if (SubExpr.isInvalid())
11728 return ExprError();
11730 if (!getDerived().AlwaysRebuild() &&
11731 SubExpr.get() == E->getSubExpr())
11734 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
11737 template<typename Derived>
11739 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11740 // Transform each of the elements.
11741 SmallVector<Expr *, 8> Elements;
11742 bool ArgChanged = false;
11743 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
11744 /*IsCall=*/false, Elements, &ArgChanged))
11745 return ExprError();
11747 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11748 return SemaRef.MaybeBindToTemporary(E);
11750 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11755 template<typename Derived>
11757 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
11758 ObjCDictionaryLiteral *E) {
11759 // Transform each of the elements.
11760 SmallVector<ObjCDictionaryElement, 8> Elements;
11761 bool ArgChanged = false;
11762 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11763 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
11765 if (OrigElement.isPackExpansion()) {
11766 // This key/value element is a pack expansion.
11767 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11768 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11769 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11770 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11772 // Determine whether the set of unexpanded parameter packs can
11773 // and should be expanded.
11774 bool Expand = true;
11775 bool RetainExpansion = false;
11776 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11777 Optional<unsigned> NumExpansions = OrigNumExpansions;
11778 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11779 OrigElement.Value->getLocEnd());
11780 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11783 Expand, RetainExpansion,
11785 return ExprError();
11788 // The transform has determined that we should perform a simple
11789 // transformation on the pack expansion, producing another pack
11791 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11792 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11793 if (Key.isInvalid())
11794 return ExprError();
11796 if (Key.get() != OrigElement.Key)
11799 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11800 if (Value.isInvalid())
11801 return ExprError();
11803 if (Value.get() != OrigElement.Value)
11806 ObjCDictionaryElement Expansion = {
11807 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11809 Elements.push_back(Expansion);
11813 // Record right away that the argument was changed. This needs
11814 // to happen even if the array expands to nothing.
11817 // The transform has determined that we should perform an elementwise
11818 // expansion of the pattern. Do so.
11819 for (unsigned I = 0; I != *NumExpansions; ++I) {
11820 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11821 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11822 if (Key.isInvalid())
11823 return ExprError();
11825 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11826 if (Value.isInvalid())
11827 return ExprError();
11829 ObjCDictionaryElement Element = {
11830 Key.get(), Value.get(), SourceLocation(), NumExpansions
11833 // If any unexpanded parameter packs remain, we still have a
11835 // FIXME: Can this really happen?
11836 if (Key.get()->containsUnexpandedParameterPack() ||
11837 Value.get()->containsUnexpandedParameterPack())
11838 Element.EllipsisLoc = OrigElement.EllipsisLoc;
11840 Elements.push_back(Element);
11843 // FIXME: Retain a pack expansion if RetainExpansion is true.
11845 // We've finished with this pack expansion.
11849 // Transform and check key.
11850 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11851 if (Key.isInvalid())
11852 return ExprError();
11854 if (Key.get() != OrigElement.Key)
11857 // Transform and check value.
11859 = getDerived().TransformExpr(OrigElement.Value);
11860 if (Value.isInvalid())
11861 return ExprError();
11863 if (Value.get() != OrigElement.Value)
11866 ObjCDictionaryElement Element = {
11867 Key.get(), Value.get(), SourceLocation(), None
11869 Elements.push_back(Element);
11872 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11873 return SemaRef.MaybeBindToTemporary(E);
11875 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
11879 template<typename Derived>
11881 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
11882 TypeSourceInfo *EncodedTypeInfo
11883 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11884 if (!EncodedTypeInfo)
11885 return ExprError();
11887 if (!getDerived().AlwaysRebuild() &&
11888 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
11891 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
11893 E->getRParenLoc());
11896 template<typename Derived>
11897 ExprResult TreeTransform<Derived>::
11898 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
11899 // This is a kind of implicit conversion, and it needs to get dropped
11900 // and recomputed for the same general reasons that ImplicitCastExprs
11901 // do, as well a more specific one: this expression is only valid when
11902 // it appears *immediately* as an argument expression.
11903 return getDerived().TransformExpr(E->getSubExpr());
11906 template<typename Derived>
11907 ExprResult TreeTransform<Derived>::
11908 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
11909 TypeSourceInfo *TSInfo
11910 = getDerived().TransformType(E->getTypeInfoAsWritten());
11912 return ExprError();
11914 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
11915 if (Result.isInvalid())
11916 return ExprError();
11918 if (!getDerived().AlwaysRebuild() &&
11919 TSInfo == E->getTypeInfoAsWritten() &&
11920 Result.get() == E->getSubExpr())
11923 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
11924 E->getBridgeKeywordLoc(), TSInfo,
11928 template <typename Derived>
11929 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11930 ObjCAvailabilityCheckExpr *E) {
11934 template<typename Derived>
11936 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
11937 // Transform arguments.
11938 bool ArgChanged = false;
11939 SmallVector<Expr*, 8> Args;
11940 Args.reserve(E->getNumArgs());
11941 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
11943 return ExprError();
11945 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11946 // Class message: transform the receiver type.
11947 TypeSourceInfo *ReceiverTypeInfo
11948 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11949 if (!ReceiverTypeInfo)
11950 return ExprError();
11952 // If nothing changed, just retain the existing message send.
11953 if (!getDerived().AlwaysRebuild() &&
11954 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
11955 return SemaRef.MaybeBindToTemporary(E);
11957 // Build a new class message send.
11958 SmallVector<SourceLocation, 16> SelLocs;
11959 E->getSelectorLocs(SelLocs);
11960 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11963 E->getMethodDecl(),
11968 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11969 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11970 if (!E->getMethodDecl())
11971 return ExprError();
11973 // Build a new class message send to 'super'.
11974 SmallVector<SourceLocation, 16> SelLocs;
11975 E->getSelectorLocs(SelLocs);
11976 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11979 E->getReceiverType(),
11980 E->getMethodDecl(),
11986 // Instance message: transform the receiver
11987 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11988 "Only class and instance messages may be instantiated");
11989 ExprResult Receiver
11990 = getDerived().TransformExpr(E->getInstanceReceiver());
11991 if (Receiver.isInvalid())
11992 return ExprError();
11994 // If nothing changed, just retain the existing message send.
11995 if (!getDerived().AlwaysRebuild() &&
11996 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
11997 return SemaRef.MaybeBindToTemporary(E);
11999 // Build a new instance message send.
12000 SmallVector<SourceLocation, 16> SelLocs;
12001 E->getSelectorLocs(SelLocs);
12002 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
12005 E->getMethodDecl(),
12011 template<typename Derived>
12013 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
12017 template<typename Derived>
12019 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
12023 template<typename Derived>
12025 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
12026 // Transform the base expression.
12027 ExprResult Base = getDerived().TransformExpr(E->getBase());
12028 if (Base.isInvalid())
12029 return ExprError();
12031 // We don't need to transform the ivar; it will never change.
12033 // If nothing changed, just retain the existing expression.
12034 if (!getDerived().AlwaysRebuild() &&
12035 Base.get() == E->getBase())
12038 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
12040 E->isArrow(), E->isFreeIvar());
12043 template<typename Derived>
12045 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
12046 // 'super' and types never change. Property never changes. Just
12047 // retain the existing expression.
12048 if (!E->isObjectReceiver())
12051 // Transform the base expression.
12052 ExprResult Base = getDerived().TransformExpr(E->getBase());
12053 if (Base.isInvalid())
12054 return ExprError();
12056 // We don't need to transform the property; it will never change.
12058 // If nothing changed, just retain the existing expression.
12059 if (!getDerived().AlwaysRebuild() &&
12060 Base.get() == E->getBase())
12063 if (E->isExplicitProperty())
12064 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12065 E->getExplicitProperty(),
12068 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12069 SemaRef.Context.PseudoObjectTy,
12070 E->getImplicitPropertyGetter(),
12071 E->getImplicitPropertySetter(),
12075 template<typename Derived>
12077 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12078 // Transform the base expression.
12079 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12080 if (Base.isInvalid())
12081 return ExprError();
12083 // Transform the key expression.
12084 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12085 if (Key.isInvalid())
12086 return ExprError();
12088 // If nothing changed, just retain the existing expression.
12089 if (!getDerived().AlwaysRebuild() &&
12090 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
12093 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
12094 Base.get(), Key.get(),
12095 E->getAtIndexMethodDecl(),
12096 E->setAtIndexMethodDecl());
12099 template<typename Derived>
12101 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
12102 // Transform the base expression.
12103 ExprResult Base = getDerived().TransformExpr(E->getBase());
12104 if (Base.isInvalid())
12105 return ExprError();
12107 // If nothing changed, just retain the existing expression.
12108 if (!getDerived().AlwaysRebuild() &&
12109 Base.get() == E->getBase())
12112 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
12117 template<typename Derived>
12119 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
12120 bool ArgumentChanged = false;
12121 SmallVector<Expr*, 8> SubExprs;
12122 SubExprs.reserve(E->getNumSubExprs());
12123 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12124 SubExprs, &ArgumentChanged))
12125 return ExprError();
12127 if (!getDerived().AlwaysRebuild() &&
12131 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
12133 E->getRParenLoc());
12136 template<typename Derived>
12138 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12139 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12140 if (SrcExpr.isInvalid())
12141 return ExprError();
12143 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12145 return ExprError();
12147 if (!getDerived().AlwaysRebuild() &&
12148 Type == E->getTypeSourceInfo() &&
12149 SrcExpr.get() == E->getSrcExpr())
12152 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12153 SrcExpr.get(), Type,
12154 E->getRParenLoc());
12157 template<typename Derived>
12159 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
12160 BlockDecl *oldBlock = E->getBlockDecl();
12162 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
12163 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12165 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
12166 blockScope->TheDecl->setBlockMissingReturnType(
12167 oldBlock->blockMissingReturnType());
12169 SmallVector<ParmVarDecl*, 4> params;
12170 SmallVector<QualType, 4> paramTypes;
12172 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12174 // Parameter substitution.
12175 Sema::ExtParameterInfoBuilder extParamInfos;
12176 if (getDerived().TransformFunctionTypeParams(
12177 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12178 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms,
12180 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
12181 return ExprError();
12184 QualType exprResultType =
12185 getDerived().TransformType(exprFunctionType->getReturnType());
12187 auto epi = exprFunctionType->getExtProtoInfo();
12188 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12190 QualType functionType =
12191 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
12192 blockScope->FunctionType = functionType;
12194 // Set the parameters on the block decl.
12195 if (!params.empty())
12196 blockScope->TheDecl->setParams(params);
12198 if (!oldBlock->blockMissingReturnType()) {
12199 blockScope->HasImplicitReturnType = false;
12200 blockScope->ReturnType = exprResultType;
12203 // Transform the body
12204 StmtResult body = getDerived().TransformStmt(E->getBody());
12205 if (body.isInvalid()) {
12206 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
12207 return ExprError();
12211 // In builds with assertions, make sure that we captured everything we
12212 // captured before.
12213 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
12214 for (const auto &I : oldBlock->captures()) {
12215 VarDecl *oldCapture = I.getVariable();
12217 // Ignore parameter packs.
12218 if (isa<ParmVarDecl>(oldCapture) &&
12219 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12222 VarDecl *newCapture =
12223 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12225 assert(blockScope->CaptureMap.count(newCapture));
12227 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
12231 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
12232 /*Scope=*/nullptr);
12235 template<typename Derived>
12237 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
12238 llvm_unreachable("Cannot transform asType expressions yet");
12241 template<typename Derived>
12243 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
12244 QualType RetTy = getDerived().TransformType(E->getType());
12245 bool ArgumentChanged = false;
12246 SmallVector<Expr*, 8> SubExprs;
12247 SubExprs.reserve(E->getNumSubExprs());
12248 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12249 SubExprs, &ArgumentChanged))
12250 return ExprError();
12252 if (!getDerived().AlwaysRebuild() &&
12256 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
12257 RetTy, E->getOp(), E->getRParenLoc());
12260 //===----------------------------------------------------------------------===//
12261 // Type reconstruction
12262 //===----------------------------------------------------------------------===//
12264 template<typename Derived>
12265 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12266 SourceLocation Star) {
12267 return SemaRef.BuildPointerType(PointeeType, Star,
12268 getDerived().getBaseEntity());
12271 template<typename Derived>
12272 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12273 SourceLocation Star) {
12274 return SemaRef.BuildBlockPointerType(PointeeType, Star,
12275 getDerived().getBaseEntity());
12278 template<typename Derived>
12280 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12281 bool WrittenAsLValue,
12282 SourceLocation Sigil) {
12283 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
12284 Sigil, getDerived().getBaseEntity());
12287 template<typename Derived>
12289 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12290 QualType ClassType,
12291 SourceLocation Sigil) {
12292 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12293 getDerived().getBaseEntity());
12296 template<typename Derived>
12297 QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12298 const ObjCTypeParamDecl *Decl,
12299 SourceLocation ProtocolLAngleLoc,
12300 ArrayRef<ObjCProtocolDecl *> Protocols,
12301 ArrayRef<SourceLocation> ProtocolLocs,
12302 SourceLocation ProtocolRAngleLoc) {
12303 return SemaRef.BuildObjCTypeParamType(Decl,
12304 ProtocolLAngleLoc, Protocols,
12305 ProtocolLocs, ProtocolRAngleLoc,
12306 /*FailOnError=*/true);
12309 template<typename Derived>
12310 QualType TreeTransform<Derived>::RebuildObjCObjectType(
12312 SourceLocation Loc,
12313 SourceLocation TypeArgsLAngleLoc,
12314 ArrayRef<TypeSourceInfo *> TypeArgs,
12315 SourceLocation TypeArgsRAngleLoc,
12316 SourceLocation ProtocolLAngleLoc,
12317 ArrayRef<ObjCProtocolDecl *> Protocols,
12318 ArrayRef<SourceLocation> ProtocolLocs,
12319 SourceLocation ProtocolRAngleLoc) {
12320 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12321 TypeArgs, TypeArgsRAngleLoc,
12322 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12324 /*FailOnError=*/true);
12327 template<typename Derived>
12328 QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12329 QualType PointeeType,
12330 SourceLocation Star) {
12331 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12334 template<typename Derived>
12336 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12337 ArrayType::ArraySizeModifier SizeMod,
12338 const llvm::APInt *Size,
12340 unsigned IndexTypeQuals,
12341 SourceRange BracketsRange) {
12342 if (SizeExpr || !Size)
12343 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12344 IndexTypeQuals, BracketsRange,
12345 getDerived().getBaseEntity());
12347 QualType Types[] = {
12348 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12349 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12350 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
12352 const unsigned NumTypes = llvm::array_lengthof(Types);
12354 for (unsigned I = 0; I != NumTypes; ++I)
12355 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12356 SizeType = Types[I];
12360 // Note that we can return a VariableArrayType here in the case where
12361 // the element type was a dependent VariableArrayType.
12362 IntegerLiteral *ArraySize
12363 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12364 /*FIXME*/BracketsRange.getBegin());
12365 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
12366 IndexTypeQuals, BracketsRange,
12367 getDerived().getBaseEntity());
12370 template<typename Derived>
12372 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
12373 ArrayType::ArraySizeModifier SizeMod,
12374 const llvm::APInt &Size,
12375 unsigned IndexTypeQuals,
12376 SourceRange BracketsRange) {
12377 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
12378 IndexTypeQuals, BracketsRange);
12381 template<typename Derived>
12383 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
12384 ArrayType::ArraySizeModifier SizeMod,
12385 unsigned IndexTypeQuals,
12386 SourceRange BracketsRange) {
12387 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
12388 IndexTypeQuals, BracketsRange);
12391 template<typename Derived>
12393 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
12394 ArrayType::ArraySizeModifier SizeMod,
12396 unsigned IndexTypeQuals,
12397 SourceRange BracketsRange) {
12398 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
12400 IndexTypeQuals, BracketsRange);
12403 template<typename Derived>
12405 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
12406 ArrayType::ArraySizeModifier SizeMod,
12408 unsigned IndexTypeQuals,
12409 SourceRange BracketsRange) {
12410 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
12412 IndexTypeQuals, BracketsRange);
12415 template <typename Derived>
12416 QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12417 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12418 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12422 template <typename Derived>
12424 TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12425 unsigned NumElements,
12426 VectorType::VectorKind VecKind) {
12427 // FIXME: semantic checking!
12428 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
12431 template <typename Derived>
12432 QualType TreeTransform<Derived>::RebuildDependentVectorType(
12433 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12434 VectorType::VectorKind VecKind) {
12435 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12438 template<typename Derived>
12439 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12440 unsigned NumElements,
12441 SourceLocation AttributeLoc) {
12442 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12443 NumElements, true);
12444 IntegerLiteral *VectorSize
12445 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12447 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
12450 template<typename Derived>
12452 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
12454 SourceLocation AttributeLoc) {
12455 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
12458 template<typename Derived>
12459 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12461 MutableArrayRef<QualType> ParamTypes,
12462 const FunctionProtoType::ExtProtoInfo &EPI) {
12463 return SemaRef.BuildFunctionType(T, ParamTypes,
12464 getDerived().getBaseLocation(),
12465 getDerived().getBaseEntity(),
12469 template<typename Derived>
12470 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12471 return SemaRef.Context.getFunctionNoProtoType(T);
12474 template<typename Derived>
12475 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12477 assert(D && "no decl found");
12478 if (D->isInvalidDecl()) return QualType();
12480 // FIXME: Doesn't account for ObjCInterfaceDecl!
12482 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12483 // A valid resolved using typename pack expansion decl can have multiple
12484 // UsingDecls, but they must each have exactly one type, and it must be
12485 // the same type in every case. But we must have at least one expansion!
12486 if (UPD->expansions().empty()) {
12487 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12488 << UPD->isCXXClassMember() << UPD;
12492 // We might still have some unresolved types. Try to pick a resolved type
12493 // if we can. The final instantiation will check that the remaining
12494 // unresolved types instantiate to the type we pick.
12495 QualType FallbackT;
12497 for (auto *E : UPD->expansions()) {
12498 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12499 if (ThisT.isNull())
12501 else if (ThisT->getAs<UnresolvedUsingType>())
12503 else if (T.isNull())
12506 assert(getSema().Context.hasSameType(ThisT, T) &&
12507 "mismatched resolved types in using pack expansion");
12509 return T.isNull() ? FallbackT : T;
12510 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
12511 assert(Using->hasTypename() &&
12512 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12514 // A valid resolved using typename decl points to exactly one type decl.
12515 assert(++Using->shadow_begin() == Using->shadow_end());
12516 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
12518 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12519 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12520 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12523 return SemaRef.Context.getTypeDeclType(Ty);
12526 template<typename Derived>
12527 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12528 SourceLocation Loc) {
12529 return SemaRef.BuildTypeofExprType(E, Loc);
12532 template<typename Derived>
12533 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12534 return SemaRef.Context.getTypeOfType(Underlying);
12537 template<typename Derived>
12538 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12539 SourceLocation Loc) {
12540 return SemaRef.BuildDecltypeType(E, Loc);
12543 template<typename Derived>
12544 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12545 UnaryTransformType::UTTKind UKind,
12546 SourceLocation Loc) {
12547 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12550 template<typename Derived>
12551 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
12552 TemplateName Template,
12553 SourceLocation TemplateNameLoc,
12554 TemplateArgumentListInfo &TemplateArgs) {
12555 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
12558 template<typename Derived>
12559 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12560 SourceLocation KWLoc) {
12561 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12564 template<typename Derived>
12565 QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
12566 SourceLocation KWLoc,
12568 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12569 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
12572 template<typename Derived>
12574 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12576 TemplateDecl *Template) {
12577 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
12581 template<typename Derived>
12583 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12584 SourceLocation TemplateKWLoc,
12585 const IdentifierInfo &Name,
12586 SourceLocation NameLoc,
12587 QualType ObjectType,
12588 NamedDecl *FirstQualifierInScope,
12589 bool AllowInjectedClassName) {
12590 UnqualifiedId TemplateName;
12591 TemplateName.setIdentifier(&Name, NameLoc);
12592 Sema::TemplateTy Template;
12593 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12594 SS, TemplateKWLoc, TemplateName,
12595 ParsedType::make(ObjectType),
12596 /*EnteringContext=*/false,
12597 Template, AllowInjectedClassName);
12598 return Template.get();
12601 template<typename Derived>
12603 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12604 SourceLocation TemplateKWLoc,
12605 OverloadedOperatorKind Operator,
12606 SourceLocation NameLoc,
12607 QualType ObjectType,
12608 bool AllowInjectedClassName) {
12609 UnqualifiedId Name;
12610 // FIXME: Bogus location information.
12611 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
12612 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
12613 Sema::TemplateTy Template;
12614 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12615 SS, TemplateKWLoc, Name,
12616 ParsedType::make(ObjectType),
12617 /*EnteringContext=*/false,
12618 Template, AllowInjectedClassName);
12619 return Template.get();
12622 template<typename Derived>
12624 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12625 SourceLocation OpLoc,
12629 Expr *Callee = OrigCallee->IgnoreParenCasts();
12630 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
12632 if (First->getObjectKind() == OK_ObjCProperty) {
12633 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12634 if (BinaryOperator::isAssignmentOp(Opc))
12635 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12637 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12638 if (Result.isInvalid())
12639 return ExprError();
12640 First = Result.get();
12643 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12644 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12645 if (Result.isInvalid())
12646 return ExprError();
12647 Second = Result.get();
12650 // Determine whether this should be a builtin operation.
12651 if (Op == OO_Subscript) {
12652 if (!First->getType()->isOverloadableType() &&
12653 !Second->getType()->isOverloadableType())
12654 return getSema().CreateBuiltinArraySubscriptExpr(First,
12655 Callee->getLocStart(),
12657 } else if (Op == OO_Arrow) {
12658 // -> is never a builtin operation.
12659 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12660 } else if (Second == nullptr || isPostIncDec) {
12661 if (!First->getType()->isOverloadableType() ||
12662 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
12663 // The argument is not of overloadable type, or this is an expression
12664 // of the form &Class::member, so try to create a built-in unary
12666 UnaryOperatorKind Opc
12667 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12669 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
12672 if (!First->getType()->isOverloadableType() &&
12673 !Second->getType()->isOverloadableType()) {
12674 // Neither of the arguments is an overloadable type, so try to
12675 // create a built-in binary operation.
12676 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12678 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
12679 if (Result.isInvalid())
12680 return ExprError();
12686 // Compute the transformed set of functions (and function templates) to be
12687 // used during overload resolution.
12688 UnresolvedSet<16> Functions;
12691 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
12692 Functions.append(ULE->decls_begin(), ULE->decls_end());
12693 // If the overload could not be resolved in the template definition
12694 // (because we had a dependent argument), ADL is performed as part of
12695 // template instantiation.
12696 RequiresADL = ULE->requiresADL();
12698 // If we've resolved this to a particular non-member function, just call
12699 // that function. If we resolved it to a member function,
12700 // CreateOverloaded* will find that function for us.
12701 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12702 if (!isa<CXXMethodDecl>(ND))
12703 Functions.addDecl(ND);
12704 RequiresADL = false;
12707 // Add any functions found via argument-dependent lookup.
12708 Expr *Args[2] = { First, Second };
12709 unsigned NumArgs = 1 + (Second != nullptr);
12711 // Create the overloaded operator invocation for unary operators.
12712 if (NumArgs == 1 || isPostIncDec) {
12713 UnaryOperatorKind Opc
12714 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12715 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
12719 if (Op == OO_Subscript) {
12720 SourceLocation LBrace;
12721 SourceLocation RBrace;
12723 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
12724 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
12725 LBrace = SourceLocation::getFromRawEncoding(
12726 NameLoc.CXXOperatorName.BeginOpNameLoc);
12727 RBrace = SourceLocation::getFromRawEncoding(
12728 NameLoc.CXXOperatorName.EndOpNameLoc);
12730 LBrace = Callee->getLocStart();
12734 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12738 // Create the overloaded operator invocation for binary operators.
12739 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12740 ExprResult Result = SemaRef.CreateOverloadedBinOp(
12741 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
12742 if (Result.isInvalid())
12743 return ExprError();
12748 template<typename Derived>
12750 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
12751 SourceLocation OperatorLoc,
12754 TypeSourceInfo *ScopeType,
12755 SourceLocation CCLoc,
12756 SourceLocation TildeLoc,
12757 PseudoDestructorTypeStorage Destroyed) {
12758 QualType BaseType = Base->getType();
12759 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
12760 (!isArrow && !BaseType->getAs<RecordType>()) ||
12761 (isArrow && BaseType->getAs<PointerType>() &&
12762 !BaseType->getAs<PointerType>()->getPointeeType()
12763 ->template getAs<RecordType>())){
12764 // This pseudo-destructor expression is still a pseudo-destructor.
12765 return SemaRef.BuildPseudoDestructorExpr(
12766 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12767 CCLoc, TildeLoc, Destroyed);
12770 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
12771 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12772 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12773 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12774 NameInfo.setNamedTypeInfo(DestroyedType);
12776 // The scope type is now known to be a valid nested name specifier
12777 // component. Tack it on to the end of the nested name specifier.
12779 if (!ScopeType->getType()->getAs<TagType>()) {
12780 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12781 diag::err_expected_class_or_namespace)
12782 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12783 return ExprError();
12785 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12789 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12790 return getSema().BuildMemberReferenceExpr(Base, BaseType,
12791 OperatorLoc, isArrow,
12793 /*FIXME: FirstQualifier*/ nullptr,
12795 /*TemplateArgs*/ nullptr,
12799 template<typename Derived>
12801 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
12802 SourceLocation Loc = S->getLocStart();
12803 CapturedDecl *CD = S->getCapturedDecl();
12804 unsigned NumParams = CD->getNumParams();
12805 unsigned ContextParamPos = CD->getContextParamPosition();
12806 SmallVector<Sema::CapturedParamNameType, 4> Params;
12807 for (unsigned I = 0; I < NumParams; ++I) {
12808 if (I != ContextParamPos) {
12811 CD->getParam(I)->getName(),
12812 getDerived().TransformType(CD->getParam(I)->getType())));
12814 Params.push_back(std::make_pair(StringRef(), QualType()));
12817 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
12818 S->getCapturedRegionKind(), Params);
12821 Sema::CompoundScopeRAII CompoundScope(getSema());
12822 Body = getDerived().TransformStmt(S->getCapturedStmt());
12825 if (Body.isInvalid()) {
12826 getSema().ActOnCapturedRegionError();
12827 return StmtError();
12830 return getSema().ActOnCapturedRegionEnd(Body.get());
12833 } // end namespace clang
12835 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H