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 "TypeLocBuilder.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/ExprCXX.h"
23 #include "clang/AST/ExprObjC.h"
24 #include "clang/AST/ExprOpenMP.h"
25 #include "clang/AST/Stmt.h"
26 #include "clang/AST/StmtCXX.h"
27 #include "clang/AST/StmtObjC.h"
28 #include "clang/AST/StmtOpenMP.h"
29 #include "clang/Sema/Designator.h"
30 #include "clang/Sema/Lookup.h"
31 #include "clang/Sema/Ownership.h"
32 #include "clang/Sema/ParsedTemplate.h"
33 #include "clang/Sema/ScopeInfo.h"
34 #include "clang/Sema/SemaDiagnostic.h"
35 #include "clang/Sema/SemaInternal.h"
36 #include "llvm/ADT/ArrayRef.h"
37 #include "llvm/Support/ErrorHandling.h"
43 /// \brief A semantic tree transformation that allows one to transform one
44 /// abstract syntax tree into another.
46 /// A new tree transformation is defined by creating a new subclass \c X of
47 /// \c TreeTransform<X> and then overriding certain operations to provide
48 /// behavior specific to that transformation. For example, template
49 /// instantiation is implemented as a tree transformation where the
50 /// transformation of TemplateTypeParmType nodes involves substituting the
51 /// template arguments for their corresponding template parameters; a similar
52 /// transformation is performed for non-type template parameters and
53 /// template template parameters.
55 /// This tree-transformation template uses static polymorphism to allow
56 /// subclasses to customize any of its operations. Thus, a subclass can
57 /// override any of the transformation or rebuild operators by providing an
58 /// operation with the same signature as the default implementation. The
59 /// overridding function should not be virtual.
61 /// Semantic tree transformations are split into two stages, either of which
62 /// can be replaced by a subclass. The "transform" step transforms an AST node
63 /// or the parts of an AST node using the various transformation functions,
64 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
65 /// node of the appropriate kind from the pieces. The default transformation
66 /// routines recursively transform the operands to composite AST nodes (e.g.,
67 /// the pointee type of a PointerType node) and, if any of those operand nodes
68 /// were changed by the transformation, invokes the rebuild operation to create
71 /// Subclasses can customize the transformation at various levels. The
72 /// most coarse-grained transformations involve replacing TransformType(),
73 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
74 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
75 /// new implementations.
77 /// For more fine-grained transformations, subclasses can replace any of the
78 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
79 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
80 /// replacing TransformTemplateTypeParmType() allows template instantiation
81 /// to substitute template arguments for their corresponding template
82 /// parameters. Additionally, subclasses can override the \c RebuildXXX
83 /// functions to control how AST nodes are rebuilt when their operands change.
84 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
85 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
86 /// be able to use more efficient rebuild steps.
88 /// There are a handful of other functions that can be overridden, allowing one
89 /// to avoid traversing nodes that don't need any transformation
90 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91 /// operands have not changed (\c AlwaysRebuild()), and customize the
92 /// default locations and entity names used for type-checking
93 /// (\c getBaseLocation(), \c getBaseEntity()).
94 template<typename Derived>
96 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
99 class ForgetPartiallySubstitutedPackRAII {
101 TemplateArgument Old;
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
122 /// \brief Initializes a new tree transformer.
123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
128 /// \brief Retrieves a reference to the derived class.
129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
154 /// By default, returns no source-location information. Subclasses can
155 /// provide an alternative implementation that provides better location
157 SourceLocation getBaseLocation() { return SourceLocation(); }
159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
182 DeclarationName Entity) : Self(Self) {
183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
191 Self.getDerived().setBase(OldLocation, OldEntity);
195 /// \brief Determine whether the given type \p T has already been
198 /// Subclasses can provide an alternative implementation of this routine
199 /// to short-circuit evaluation when it is known that a given type will
200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
220 /// By default, the transformer never tries to expand pack expansions.
221 /// Subclasses can override this routine to provide different behavior.
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
229 /// \param Unexpanded The set of unexpanded parameter packs within the
232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
241 /// \param NumExpansions The number of separate arguments that will be in
242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
255 ArrayRef<UnexpandedParameterPack> Unexpanded,
257 bool &RetainExpansion,
258 Optional<unsigned> &NumExpansions) {
259 ShouldExpand = false;
263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
279 /// \brief Note to the derived class when a function parameter pack is
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
283 /// \brief Transforms the given type into another type.
285 /// By default, this routine transforms a type by creating a
286 /// TypeSourceInfo for it and delegating to the appropriate
287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
289 /// switched to storing TypeSourceInfos.
291 /// \returns the transformed type.
292 QualType TransformType(QualType T);
294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
310 /// \brief Transform the given statement.
312 /// By default, this routine transforms a statement by delegating to the
313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
318 /// \returns the transformed statement.
319 StmtResult TransformStmt(Stmt *S);
321 /// \brief Transform the given statement.
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
331 /// \brief Transform the given attribute.
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
341 /// \brief Transform the specified attribute.
343 /// Subclasses should override the transformation of attributes with a pragma
344 /// spelling to transform expressions stored within the attribute.
346 /// \returns the transformed attribute.
348 #define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350 #include "clang/Basic/AttrList.inc"
352 /// \brief Transform the given expression.
354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
359 /// \returns the transformed expression.
360 ExprResult TransformExpr(Expr *E);
362 /// \brief Transform the given initializer.
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
368 /// \returns the transformed initializer.
369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
371 /// \brief Transform the given list of expressions.
373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
379 /// \param Inputs The set of expressions to be transformed.
381 /// \param NumInputs The number of expressions in \c Inputs.
383 /// \param IsCall If \c true, then this transform is being performed on
384 /// function-call arguments, and any arguments that should be dropped, will
387 /// \param Outputs The transformed input expressions will be added to this
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
393 /// \returns true if an error occurred, false otherwise.
394 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
395 SmallVectorImpl<Expr *> &Outputs,
396 bool *ArgChanged = nullptr);
398 /// \brief Transform the given declaration, which is referenced from a type
401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
403 /// may override this function to provide alternate behavior.
404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
413 /// \brief Transform the specified condition.
415 /// By default, this transforms the variable and expression and rebuilds
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
419 Sema::ConditionKind Kind);
421 /// \brief Transform the attributes associated with the given declaration and
422 /// place them on the new declaration.
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
426 void transformAttrs(Decl *Old, Decl *New) { }
428 /// \brief Note that a local declaration has been transformed by this
431 /// Local declarations are typically transformed via a call to
432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
439 /// \brief Transform the definition of the given declaration.
441 /// By default, invokes TransformDecl() to transform the declaration.
442 /// Subclasses may override this function to provide alternate behavior.
443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
450 /// This specific declaration transformation only applies to the first
451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
460 /// Transform the set of declarations in an OverloadExpr.
461 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
464 /// \brief Transform the given nested-name-specifier with source-location
467 /// By default, transforms all of the types and declarations within the
468 /// nested-name-specifier. Subclasses may override this function to provide
469 /// alternate behavior.
470 NestedNameSpecifierLoc
471 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
472 QualType ObjectType = QualType(),
473 NamedDecl *FirstQualifierInScope = nullptr);
475 /// \brief Transform the given declaration name.
477 /// By default, transforms the types of conversion function, constructor,
478 /// and destructor names and then (if needed) rebuilds the declaration name.
479 /// Identifiers and selectors are returned unmodified. Sublcasses may
480 /// override this function to provide alternate behavior.
482 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
484 /// \brief Transform the given template name.
486 /// \param SS The nested-name-specifier that qualifies the template
487 /// name. This nested-name-specifier must already have been transformed.
489 /// \param Name The template name to transform.
491 /// \param NameLoc The source location of the template name.
493 /// \param ObjectType If we're translating a template name within a member
494 /// access expression, this is the type of the object whose member template
495 /// is being referenced.
497 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
498 /// also refers to a name within the current (lexical) scope, this is the
499 /// declaration it refers to.
501 /// By default, transforms the template name by transforming the declarations
502 /// and nested-name-specifiers that occur within the template name.
503 /// Subclasses may override this function to provide alternate behavior.
505 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
506 SourceLocation NameLoc,
507 QualType ObjectType = QualType(),
508 NamedDecl *FirstQualifierInScope = nullptr);
510 /// \brief Transform the given template argument.
512 /// By default, this operation transforms the type, expression, or
513 /// declaration stored within the template argument and constructs a
514 /// new template argument from the transformed result. Subclasses may
515 /// override this function to provide alternate behavior.
517 /// Returns true if there was an error.
518 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
519 TemplateArgumentLoc &Output,
520 bool Uneval = false);
522 /// \brief Transform the given set of template arguments.
524 /// By default, this operation transforms all of the template arguments
525 /// in the input set using \c TransformTemplateArgument(), and appends
526 /// the transformed arguments to the output list.
528 /// Note that this overload of \c TransformTemplateArguments() is merely
529 /// a convenience function. Subclasses that wish to override this behavior
530 /// should override the iterator-based member template version.
532 /// \param Inputs The set of template arguments to be transformed.
534 /// \param NumInputs The number of template arguments in \p Inputs.
536 /// \param Outputs The set of transformed template arguments output by this
539 /// Returns true if an error occurred.
540 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
542 TemplateArgumentListInfo &Outputs,
543 bool Uneval = false) {
544 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
548 /// \brief Transform the given set of template arguments.
550 /// By default, this operation transforms all of the template arguments
551 /// in the input set using \c TransformTemplateArgument(), and appends
552 /// the transformed arguments to the output list.
554 /// \param First An iterator to the first template argument.
556 /// \param Last An iterator one step past the last template argument.
558 /// \param Outputs The set of transformed template arguments output by this
561 /// Returns true if an error occurred.
562 template<typename InputIterator>
563 bool TransformTemplateArguments(InputIterator First,
565 TemplateArgumentListInfo &Outputs,
566 bool Uneval = false);
568 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
569 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
570 TemplateArgumentLoc &ArgLoc);
572 /// \brief Fakes up a TypeSourceInfo for a type.
573 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
574 return SemaRef.Context.getTrivialTypeSourceInfo(T,
575 getDerived().getBaseLocation());
578 #define ABSTRACT_TYPELOC(CLASS, PARENT)
579 #define TYPELOC(CLASS, PARENT) \
580 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
581 #include "clang/AST/TypeLocNodes.def"
583 template<typename Fn>
584 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
585 FunctionProtoTypeLoc TL,
586 CXXRecordDecl *ThisContext,
587 unsigned ThisTypeQuals,
588 Fn TransformExceptionSpec);
590 bool TransformExceptionSpec(SourceLocation Loc,
591 FunctionProtoType::ExceptionSpecInfo &ESI,
592 SmallVectorImpl<QualType> &Exceptions,
595 StmtResult TransformSEHHandler(Stmt *Handler);
598 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
599 TemplateSpecializationTypeLoc TL,
600 TemplateName Template);
603 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
604 DependentTemplateSpecializationTypeLoc TL,
605 TemplateName Template,
608 QualType TransformDependentTemplateSpecializationType(
609 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
610 NestedNameSpecifierLoc QualifierLoc);
612 /// \brief Transforms the parameters of a function type into the
615 /// The result vectors should be kept in sync; null entries in the
616 /// variables vector are acceptable.
618 /// Return true on error.
619 bool TransformFunctionTypeParams(
620 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
621 const QualType *ParamTypes,
622 const FunctionProtoType::ExtParameterInfo *ParamInfos,
623 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
624 Sema::ExtParameterInfoBuilder &PInfos);
626 /// \brief Transforms a single function-type parameter. Return null
629 /// \param indexAdjustment - A number to add to the parameter's
630 /// scope index; can be negative
631 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
633 Optional<unsigned> NumExpansions,
634 bool ExpectParameterPack);
636 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
638 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
639 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
641 TemplateParameterList *TransformTemplateParameterList(
642 TemplateParameterList *TPL) {
646 ExprResult TransformAddressOfOperand(Expr *E);
648 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
649 bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
652 ExprResult TransformParenDependentScopeDeclRefExpr(
653 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
654 TypeSourceInfo **RecoveryTSI);
656 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
658 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
659 // amount of stack usage with clang.
660 #define STMT(Node, Parent) \
661 LLVM_ATTRIBUTE_NOINLINE \
662 StmtResult Transform##Node(Node *S);
663 #define EXPR(Node, Parent) \
664 LLVM_ATTRIBUTE_NOINLINE \
665 ExprResult Transform##Node(Node *E);
666 #define ABSTRACT_STMT(Stmt)
667 #include "clang/AST/StmtNodes.inc"
669 #define OPENMP_CLAUSE(Name, Class) \
670 LLVM_ATTRIBUTE_NOINLINE \
671 OMPClause *Transform ## Class(Class *S);
672 #include "clang/Basic/OpenMPKinds.def"
674 /// \brief Build a new pointer type given its pointee type.
676 /// By default, performs semantic analysis when building the pointer type.
677 /// Subclasses may override this routine to provide different behavior.
678 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
680 /// \brief Build a new block pointer type given its pointee type.
682 /// By default, performs semantic analysis when building the block pointer
683 /// type. Subclasses may override this routine to provide different behavior.
684 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
686 /// \brief Build a new reference type given the type it references.
688 /// By default, performs semantic analysis when building the
689 /// reference type. Subclasses may override this routine to provide
690 /// different behavior.
692 /// \param LValue whether the type was written with an lvalue sigil
693 /// or an rvalue sigil.
694 QualType RebuildReferenceType(QualType ReferentType,
696 SourceLocation Sigil);
698 /// \brief Build a new member pointer type given the pointee type and the
699 /// class type it refers into.
701 /// By default, performs semantic analysis when building the member pointer
702 /// type. Subclasses may override this routine to provide different behavior.
703 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
704 SourceLocation Sigil);
706 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
707 SourceLocation ProtocolLAngleLoc,
708 ArrayRef<ObjCProtocolDecl *> Protocols,
709 ArrayRef<SourceLocation> ProtocolLocs,
710 SourceLocation ProtocolRAngleLoc);
712 /// \brief Build an Objective-C object type.
714 /// By default, performs semantic analysis when building the object type.
715 /// Subclasses may override this routine to provide different behavior.
716 QualType RebuildObjCObjectType(QualType BaseType,
718 SourceLocation TypeArgsLAngleLoc,
719 ArrayRef<TypeSourceInfo *> TypeArgs,
720 SourceLocation TypeArgsRAngleLoc,
721 SourceLocation ProtocolLAngleLoc,
722 ArrayRef<ObjCProtocolDecl *> Protocols,
723 ArrayRef<SourceLocation> ProtocolLocs,
724 SourceLocation ProtocolRAngleLoc);
726 /// \brief Build a new Objective-C object pointer type given the pointee type.
728 /// By default, directly builds the pointer type, with no additional semantic
730 QualType RebuildObjCObjectPointerType(QualType PointeeType,
731 SourceLocation Star);
733 /// \brief Build a new array type given the element type, size
734 /// modifier, size of the array (if known), size expression, and index type
737 /// By default, performs semantic analysis when building the array type.
738 /// Subclasses may override this routine to provide different behavior.
739 /// Also by default, all of the other Rebuild*Array
740 QualType RebuildArrayType(QualType ElementType,
741 ArrayType::ArraySizeModifier SizeMod,
742 const llvm::APInt *Size,
744 unsigned IndexTypeQuals,
745 SourceRange BracketsRange);
747 /// \brief Build a new constant array type given the element type, size
748 /// modifier, (known) size of the array, and index type qualifiers.
750 /// By default, performs semantic analysis when building the array type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType RebuildConstantArrayType(QualType ElementType,
753 ArrayType::ArraySizeModifier SizeMod,
754 const llvm::APInt &Size,
755 unsigned IndexTypeQuals,
756 SourceRange BracketsRange);
758 /// \brief Build a new incomplete array type given the element type, size
759 /// modifier, and index type qualifiers.
761 /// By default, performs semantic analysis when building the array type.
762 /// Subclasses may override this routine to provide different behavior.
763 QualType RebuildIncompleteArrayType(QualType ElementType,
764 ArrayType::ArraySizeModifier SizeMod,
765 unsigned IndexTypeQuals,
766 SourceRange BracketsRange);
768 /// \brief Build a new variable-length array type given the element type,
769 /// size modifier, size expression, and index type qualifiers.
771 /// By default, performs semantic analysis when building the array type.
772 /// Subclasses may override this routine to provide different behavior.
773 QualType RebuildVariableArrayType(QualType ElementType,
774 ArrayType::ArraySizeModifier SizeMod,
776 unsigned IndexTypeQuals,
777 SourceRange BracketsRange);
779 /// \brief Build a new dependent-sized array type given the element type,
780 /// size modifier, size expression, and index type qualifiers.
782 /// By default, performs semantic analysis when building the array type.
783 /// Subclasses may override this routine to provide different behavior.
784 QualType RebuildDependentSizedArrayType(QualType ElementType,
785 ArrayType::ArraySizeModifier SizeMod,
787 unsigned IndexTypeQuals,
788 SourceRange BracketsRange);
790 /// \brief Build a new vector type given the element type and
791 /// number of elements.
793 /// By default, performs semantic analysis when building the vector type.
794 /// Subclasses may override this routine to provide different behavior.
795 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
796 VectorType::VectorKind VecKind);
798 /// \brief Build a new extended vector type given the element type and
799 /// number of elements.
801 /// By default, performs semantic analysis when building the vector type.
802 /// Subclasses may override this routine to provide different behavior.
803 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
804 SourceLocation AttributeLoc);
806 /// \brief Build a new potentially dependently-sized extended vector type
807 /// given the element type and number of elements.
809 /// By default, performs semantic analysis when building the vector type.
810 /// Subclasses may override this routine to provide different behavior.
811 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
813 SourceLocation AttributeLoc);
815 /// \brief Build a new function type.
817 /// By default, performs semantic analysis when building the function type.
818 /// Subclasses may override this routine to provide different behavior.
819 QualType RebuildFunctionProtoType(QualType T,
820 MutableArrayRef<QualType> ParamTypes,
821 const FunctionProtoType::ExtProtoInfo &EPI);
823 /// \brief Build a new unprototyped function type.
824 QualType RebuildFunctionNoProtoType(QualType ResultType);
826 /// \brief Rebuild an unresolved typename type, given the decl that
827 /// the UnresolvedUsingTypenameDecl was transformed to.
828 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
830 /// \brief Build a new typedef type.
831 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
832 return SemaRef.Context.getTypeDeclType(Typedef);
835 /// \brief Build a new class/struct/union type.
836 QualType RebuildRecordType(RecordDecl *Record) {
837 return SemaRef.Context.getTypeDeclType(Record);
840 /// \brief Build a new Enum type.
841 QualType RebuildEnumType(EnumDecl *Enum) {
842 return SemaRef.Context.getTypeDeclType(Enum);
845 /// \brief Build a new typeof(expr) type.
847 /// By default, performs semantic analysis when building the typeof type.
848 /// Subclasses may override this routine to provide different behavior.
849 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
851 /// \brief Build a new typeof(type) type.
853 /// By default, builds a new TypeOfType with the given underlying type.
854 QualType RebuildTypeOfType(QualType Underlying);
856 /// \brief Build a new unary transform type.
857 QualType RebuildUnaryTransformType(QualType BaseType,
858 UnaryTransformType::UTTKind UKind,
861 /// \brief Build a new C++11 decltype type.
863 /// By default, performs semantic analysis when building the decltype type.
864 /// Subclasses may override this routine to provide different behavior.
865 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
867 /// \brief Build a new C++11 auto type.
869 /// By default, builds a new AutoType with the given deduced type.
870 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
871 // Note, IsDependent is always false here: we implicitly convert an 'auto'
872 // which has been deduced to a dependent type into an undeduced 'auto', so
873 // that we'll retry deduction after the transformation.
874 return SemaRef.Context.getAutoType(Deduced, Keyword,
875 /*IsDependent*/ false);
878 /// \brief Build a new template specialization type.
880 /// By default, performs semantic analysis when building the template
881 /// specialization type. Subclasses may override this routine to provide
882 /// different behavior.
883 QualType RebuildTemplateSpecializationType(TemplateName Template,
884 SourceLocation TemplateLoc,
885 TemplateArgumentListInfo &Args);
887 /// \brief Build a new parenthesized type.
889 /// By default, builds a new ParenType type from the inner type.
890 /// Subclasses may override this routine to provide different behavior.
891 QualType RebuildParenType(QualType InnerType) {
892 return SemaRef.Context.getParenType(InnerType);
895 /// \brief Build a new qualified name type.
897 /// By default, builds a new ElaboratedType type from the keyword,
898 /// the nested-name-specifier and the named type.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
901 ElaboratedTypeKeyword Keyword,
902 NestedNameSpecifierLoc QualifierLoc,
904 return SemaRef.Context.getElaboratedType(Keyword,
905 QualifierLoc.getNestedNameSpecifier(),
909 /// \brief Build a new typename type that refers to a template-id.
911 /// By default, builds a new DependentNameType type from the
912 /// nested-name-specifier and the given type. Subclasses may override
913 /// this routine to provide different behavior.
914 QualType RebuildDependentTemplateSpecializationType(
915 ElaboratedTypeKeyword Keyword,
916 NestedNameSpecifierLoc QualifierLoc,
917 const IdentifierInfo *Name,
918 SourceLocation NameLoc,
919 TemplateArgumentListInfo &Args) {
920 // Rebuild the template name.
921 // TODO: avoid TemplateName abstraction
923 SS.Adopt(QualifierLoc);
924 TemplateName InstName
925 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
928 if (InstName.isNull())
931 // If it's still dependent, make a dependent specialization.
932 if (InstName.getAsDependentTemplateName())
933 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
934 QualifierLoc.getNestedNameSpecifier(),
938 // Otherwise, make an elaborated type wrapping a non-dependent
941 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
942 if (T.isNull()) return QualType();
944 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
947 return SemaRef.Context.getElaboratedType(Keyword,
948 QualifierLoc.getNestedNameSpecifier(),
952 /// \brief Build a new typename type that refers to an identifier.
954 /// By default, performs semantic analysis when building the typename type
955 /// (or elaborated type). Subclasses may override this routine to provide
956 /// different behavior.
957 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
958 SourceLocation KeywordLoc,
959 NestedNameSpecifierLoc QualifierLoc,
960 const IdentifierInfo *Id,
961 SourceLocation IdLoc) {
963 SS.Adopt(QualifierLoc);
965 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
966 // If the name is still dependent, just build a new dependent name type.
967 if (!SemaRef.computeDeclContext(SS))
968 return SemaRef.Context.getDependentNameType(Keyword,
969 QualifierLoc.getNestedNameSpecifier(),
973 if (Keyword == ETK_None || Keyword == ETK_Typename)
974 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
977 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
979 // We had a dependent elaborated-type-specifier that has been transformed
980 // into a non-dependent elaborated-type-specifier. Find the tag we're
982 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
983 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
987 if (SemaRef.RequireCompleteDeclContext(SS, DC))
990 TagDecl *Tag = nullptr;
991 SemaRef.LookupQualifiedName(Result, DC);
992 switch (Result.getResultKind()) {
993 case LookupResult::NotFound:
994 case LookupResult::NotFoundInCurrentInstantiation:
997 case LookupResult::Found:
998 Tag = Result.getAsSingle<TagDecl>();
1001 case LookupResult::FoundOverloaded:
1002 case LookupResult::FoundUnresolvedValue:
1003 llvm_unreachable("Tag lookup cannot find non-tags");
1005 case LookupResult::Ambiguous:
1006 // Let the LookupResult structure handle ambiguities.
1011 // Check where the name exists but isn't a tag type and use that to emit
1012 // better diagnostics.
1013 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1014 SemaRef.LookupQualifiedName(Result, DC);
1015 switch (Result.getResultKind()) {
1016 case LookupResult::Found:
1017 case LookupResult::FoundOverloaded:
1018 case LookupResult::FoundUnresolvedValue: {
1019 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1020 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1021 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1023 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1027 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1028 << Kind << Id << DC << QualifierLoc.getSourceRange();
1034 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1036 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1037 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1041 // Build the elaborated-type-specifier type.
1042 QualType T = SemaRef.Context.getTypeDeclType(Tag);
1043 return SemaRef.Context.getElaboratedType(Keyword,
1044 QualifierLoc.getNestedNameSpecifier(),
1048 /// \brief Build a new pack expansion type.
1050 /// By default, builds a new PackExpansionType type from the given pattern.
1051 /// Subclasses may override this routine to provide different behavior.
1052 QualType RebuildPackExpansionType(QualType Pattern,
1053 SourceRange PatternRange,
1054 SourceLocation EllipsisLoc,
1055 Optional<unsigned> NumExpansions) {
1056 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1060 /// \brief Build a new atomic type given its value type.
1062 /// By default, performs semantic analysis when building the atomic type.
1063 /// Subclasses may override this routine to provide different behavior.
1064 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1066 /// \brief Build a new pipe type given its value type.
1067 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1070 /// \brief Build a new template name given a nested name specifier, a flag
1071 /// indicating whether the "template" keyword was provided, and the template
1072 /// that the template name refers to.
1074 /// By default, builds the new template name directly. Subclasses may override
1075 /// this routine to provide different behavior.
1076 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1078 TemplateDecl *Template);
1080 /// \brief Build a new template name given a nested name specifier and the
1081 /// name that is referred to as a template.
1083 /// By default, performs semantic analysis to determine whether the name can
1084 /// be resolved to a specific template, then builds the appropriate kind of
1085 /// template name. Subclasses may override this routine to provide different
1087 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1088 const IdentifierInfo &Name,
1089 SourceLocation NameLoc,
1090 QualType ObjectType,
1091 NamedDecl *FirstQualifierInScope);
1093 /// \brief Build a new template name given a nested name specifier and the
1094 /// overloaded operator name that is referred to as a template.
1096 /// By default, performs semantic analysis to determine whether the name can
1097 /// be resolved to a specific template, then builds the appropriate kind of
1098 /// template name. Subclasses may override this routine to provide different
1100 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1101 OverloadedOperatorKind Operator,
1102 SourceLocation NameLoc,
1103 QualType ObjectType);
1105 /// \brief Build a new template name given a template template parameter pack
1108 /// By default, performs semantic analysis to determine whether the name can
1109 /// be resolved to a specific template, then builds the appropriate kind of
1110 /// template name. Subclasses may override this routine to provide different
1112 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1113 const TemplateArgument &ArgPack) {
1114 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1117 /// \brief Build a new compound statement.
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
1121 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1122 MultiStmtArg Statements,
1123 SourceLocation RBraceLoc,
1125 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1129 /// \brief Build a new case statement.
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
1133 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1135 SourceLocation EllipsisLoc,
1137 SourceLocation ColonLoc) {
1138 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1142 /// \brief Attach the body to a new case statement.
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
1146 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1147 getSema().ActOnCaseStmtBody(S, Body);
1151 /// \brief Build a new default statement.
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
1155 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1156 SourceLocation ColonLoc,
1158 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1159 /*CurScope=*/nullptr);
1162 /// \brief Build a new label statement.
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
1166 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1167 SourceLocation ColonLoc, Stmt *SubStmt) {
1168 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1171 /// \brief Build a new label statement.
1173 /// By default, performs semantic analysis to build the new statement.
1174 /// Subclasses may override this routine to provide different behavior.
1175 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1176 ArrayRef<const Attr*> Attrs,
1178 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1181 /// \brief Build a new "if" statement.
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
1185 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1186 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
1187 SourceLocation ElseLoc, Stmt *Else) {
1188 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
1192 /// \brief Start building a new switch statement.
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
1196 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
1197 Sema::ConditionResult Cond) {
1198 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
1201 /// \brief Attach the body to the switch statement.
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
1205 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1206 Stmt *Switch, Stmt *Body) {
1207 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1210 /// \brief Build a new while statement.
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
1214 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1215 Sema::ConditionResult Cond, Stmt *Body) {
1216 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
1219 /// \brief Build a new do-while statement.
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
1223 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1224 SourceLocation WhileLoc, SourceLocation LParenLoc,
1225 Expr *Cond, SourceLocation RParenLoc) {
1226 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1230 /// \brief Build a new for statement.
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
1234 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1235 Stmt *Init, Sema::ConditionResult Cond,
1236 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1238 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1239 Inc, RParenLoc, Body);
1242 /// \brief Build a new goto statement.
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
1246 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1248 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1251 /// \brief Build a new indirect goto statement.
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
1255 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1256 SourceLocation StarLoc,
1258 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1261 /// \brief Build a new return statement.
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
1265 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1266 return getSema().BuildReturnStmt(ReturnLoc, Result);
1269 /// \brief Build a new declaration statement.
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
1273 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
1274 SourceLocation StartLoc, SourceLocation EndLoc) {
1275 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1276 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1279 /// \brief Build a new inline asm statement.
1281 /// By default, performs semantic analysis to build the new statement.
1282 /// Subclasses may override this routine to provide different behavior.
1283 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1284 bool IsVolatile, unsigned NumOutputs,
1285 unsigned NumInputs, IdentifierInfo **Names,
1286 MultiExprArg Constraints, MultiExprArg Exprs,
1287 Expr *AsmString, MultiExprArg Clobbers,
1288 SourceLocation RParenLoc) {
1289 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1290 NumInputs, Names, Constraints, Exprs,
1291 AsmString, Clobbers, RParenLoc);
1294 /// \brief Build a new MS style inline asm statement.
1296 /// By default, performs semantic analysis to build the new statement.
1297 /// Subclasses may override this routine to provide different behavior.
1298 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1299 ArrayRef<Token> AsmToks,
1300 StringRef AsmString,
1301 unsigned NumOutputs, unsigned NumInputs,
1302 ArrayRef<StringRef> Constraints,
1303 ArrayRef<StringRef> Clobbers,
1304 ArrayRef<Expr*> Exprs,
1305 SourceLocation EndLoc) {
1306 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1307 NumOutputs, NumInputs,
1308 Constraints, Clobbers, Exprs, EndLoc);
1311 /// \brief Build a new co_return statement.
1313 /// By default, performs semantic analysis to build the new statement.
1314 /// Subclasses may override this routine to provide different behavior.
1315 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1316 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1319 /// \brief Build a new co_await expression.
1321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1324 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1327 /// \brief Build a new co_yield expression.
1329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
1331 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1332 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1335 /// \brief Build a new Objective-C \@try statement.
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
1339 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1341 MultiStmtArg CatchStmts,
1343 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1347 /// \brief Rebuild an Objective-C exception declaration.
1349 /// By default, performs semantic analysis to build the new declaration.
1350 /// Subclasses may override this routine to provide different behavior.
1351 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1352 TypeSourceInfo *TInfo, QualType T) {
1353 return getSema().BuildObjCExceptionDecl(TInfo, T,
1354 ExceptionDecl->getInnerLocStart(),
1355 ExceptionDecl->getLocation(),
1356 ExceptionDecl->getIdentifier());
1359 /// \brief Build a new Objective-C \@catch statement.
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
1363 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1364 SourceLocation RParenLoc,
1367 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1371 /// \brief Build a new Objective-C \@finally statement.
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
1375 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1377 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1380 /// \brief Build a new Objective-C \@throw statement.
1382 /// By default, performs semantic analysis to build the new statement.
1383 /// Subclasses may override this routine to provide different behavior.
1384 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1386 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1389 /// \brief Build a new OpenMP executable directive.
1391 /// By default, performs semantic analysis to build the new statement.
1392 /// Subclasses may override this routine to provide different behavior.
1393 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1394 DeclarationNameInfo DirName,
1395 OpenMPDirectiveKind CancelRegion,
1396 ArrayRef<OMPClause *> Clauses,
1397 Stmt *AStmt, SourceLocation StartLoc,
1398 SourceLocation EndLoc) {
1399 return getSema().ActOnOpenMPExecutableDirective(
1400 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1403 /// \brief Build a new OpenMP 'if' clause.
1405 /// By default, performs semantic analysis to build the new OpenMP clause.
1406 /// Subclasses may override this routine to provide different behavior.
1407 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1408 Expr *Condition, SourceLocation StartLoc,
1409 SourceLocation LParenLoc,
1410 SourceLocation NameModifierLoc,
1411 SourceLocation ColonLoc,
1412 SourceLocation EndLoc) {
1413 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1414 LParenLoc, NameModifierLoc, ColonLoc,
1418 /// \brief Build a new OpenMP 'final' clause.
1420 /// By default, performs semantic analysis to build the new OpenMP clause.
1421 /// Subclasses may override this routine to provide different behavior.
1422 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1423 SourceLocation LParenLoc,
1424 SourceLocation EndLoc) {
1425 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1429 /// \brief Build a new OpenMP 'num_threads' clause.
1431 /// By default, performs semantic analysis to build the new OpenMP clause.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1434 SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1441 /// \brief Build a new OpenMP 'safelen' clause.
1443 /// By default, performs semantic analysis to build the new OpenMP clause.
1444 /// Subclasses may override this routine to provide different behavior.
1445 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1446 SourceLocation LParenLoc,
1447 SourceLocation EndLoc) {
1448 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1451 /// \brief Build a new OpenMP 'simdlen' clause.
1453 /// By default, performs semantic analysis to build the new OpenMP clause.
1454 /// Subclasses may override this routine to provide different behavior.
1455 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1456 SourceLocation LParenLoc,
1457 SourceLocation EndLoc) {
1458 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1461 /// \brief Build a new OpenMP 'collapse' clause.
1463 /// By default, performs semantic analysis to build the new OpenMP clause.
1464 /// Subclasses may override this routine to provide different behavior.
1465 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1466 SourceLocation LParenLoc,
1467 SourceLocation EndLoc) {
1468 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1472 /// \brief Build a new OpenMP 'default' clause.
1474 /// By default, performs semantic analysis to build the new OpenMP clause.
1475 /// Subclasses may override this routine to provide different behavior.
1476 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1477 SourceLocation KindKwLoc,
1478 SourceLocation StartLoc,
1479 SourceLocation LParenLoc,
1480 SourceLocation EndLoc) {
1481 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1482 StartLoc, LParenLoc, EndLoc);
1485 /// \brief Build a new OpenMP 'proc_bind' clause.
1487 /// By default, performs semantic analysis to build the new OpenMP clause.
1488 /// Subclasses may override this routine to provide different behavior.
1489 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1490 SourceLocation KindKwLoc,
1491 SourceLocation StartLoc,
1492 SourceLocation LParenLoc,
1493 SourceLocation EndLoc) {
1494 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1495 StartLoc, LParenLoc, EndLoc);
1498 /// \brief Build a new OpenMP 'schedule' clause.
1500 /// By default, performs semantic analysis to build the new OpenMP clause.
1501 /// Subclasses may override this routine to provide different behavior.
1502 OMPClause *RebuildOMPScheduleClause(
1503 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1504 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1505 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1506 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1507 return getSema().ActOnOpenMPScheduleClause(
1508 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1512 /// \brief Build a new OpenMP 'ordered' clause.
1514 /// By default, performs semantic analysis to build the new OpenMP clause.
1515 /// Subclasses may override this routine to provide different behavior.
1516 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1517 SourceLocation EndLoc,
1518 SourceLocation LParenLoc, Expr *Num) {
1519 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1522 /// \brief Build a new OpenMP 'private' clause.
1524 /// By default, performs semantic analysis to build the new OpenMP clause.
1525 /// Subclasses may override this routine to provide different behavior.
1526 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1527 SourceLocation StartLoc,
1528 SourceLocation LParenLoc,
1529 SourceLocation EndLoc) {
1530 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1534 /// \brief Build a new OpenMP 'firstprivate' clause.
1536 /// By default, performs semantic analysis to build the new OpenMP clause.
1537 /// Subclasses may override this routine to provide different behavior.
1538 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1539 SourceLocation StartLoc,
1540 SourceLocation LParenLoc,
1541 SourceLocation EndLoc) {
1542 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1546 /// \brief Build a new OpenMP 'lastprivate' clause.
1548 /// By default, performs semantic analysis to build the new OpenMP clause.
1549 /// Subclasses may override this routine to provide different behavior.
1550 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1551 SourceLocation StartLoc,
1552 SourceLocation LParenLoc,
1553 SourceLocation EndLoc) {
1554 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1558 /// \brief Build a new OpenMP 'shared' clause.
1560 /// By default, performs semantic analysis to build the new OpenMP clause.
1561 /// Subclasses may override this routine to provide different behavior.
1562 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1563 SourceLocation StartLoc,
1564 SourceLocation LParenLoc,
1565 SourceLocation EndLoc) {
1566 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1570 /// \brief Build a new OpenMP 'reduction' clause.
1572 /// By default, performs semantic analysis to build the new statement.
1573 /// Subclasses may override this routine to provide different behavior.
1574 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1575 SourceLocation StartLoc,
1576 SourceLocation LParenLoc,
1577 SourceLocation ColonLoc,
1578 SourceLocation EndLoc,
1579 CXXScopeSpec &ReductionIdScopeSpec,
1580 const DeclarationNameInfo &ReductionId,
1581 ArrayRef<Expr *> UnresolvedReductions) {
1582 return getSema().ActOnOpenMPReductionClause(
1583 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1584 ReductionId, UnresolvedReductions);
1587 /// \brief Build a new OpenMP 'linear' 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 *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1592 SourceLocation StartLoc,
1593 SourceLocation LParenLoc,
1594 OpenMPLinearClauseKind Modifier,
1595 SourceLocation ModifierLoc,
1596 SourceLocation ColonLoc,
1597 SourceLocation EndLoc) {
1598 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1599 Modifier, ModifierLoc, ColonLoc,
1603 /// \brief Build a new OpenMP 'aligned' clause.
1605 /// By default, performs semantic analysis to build the new OpenMP clause.
1606 /// Subclasses may override this routine to provide different behavior.
1607 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1608 SourceLocation StartLoc,
1609 SourceLocation LParenLoc,
1610 SourceLocation ColonLoc,
1611 SourceLocation EndLoc) {
1612 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1613 LParenLoc, ColonLoc, EndLoc);
1616 /// \brief Build a new OpenMP 'copyin' clause.
1618 /// By default, performs semantic analysis to build the new OpenMP clause.
1619 /// Subclasses may override this routine to provide different behavior.
1620 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1621 SourceLocation StartLoc,
1622 SourceLocation LParenLoc,
1623 SourceLocation EndLoc) {
1624 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1628 /// \brief Build a new OpenMP 'copyprivate' clause.
1630 /// By default, performs semantic analysis to build the new OpenMP clause.
1631 /// Subclasses may override this routine to provide different behavior.
1632 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1633 SourceLocation StartLoc,
1634 SourceLocation LParenLoc,
1635 SourceLocation EndLoc) {
1636 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1640 /// \brief Build a new OpenMP 'flush' pseudo clause.
1642 /// By default, performs semantic analysis to build the new OpenMP clause.
1643 /// Subclasses may override this routine to provide different behavior.
1644 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1645 SourceLocation StartLoc,
1646 SourceLocation LParenLoc,
1647 SourceLocation EndLoc) {
1648 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1652 /// \brief Build a new OpenMP 'depend' pseudo clause.
1654 /// By default, performs semantic analysis to build the new OpenMP clause.
1655 /// Subclasses may override this routine to provide different behavior.
1657 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1658 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1659 SourceLocation StartLoc, SourceLocation LParenLoc,
1660 SourceLocation EndLoc) {
1661 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1662 StartLoc, LParenLoc, EndLoc);
1665 /// \brief Build a new OpenMP 'device' clause.
1667 /// By default, performs semantic analysis to build the new statement.
1668 /// Subclasses may override this routine to provide different behavior.
1669 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1670 SourceLocation LParenLoc,
1671 SourceLocation EndLoc) {
1672 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1676 /// \brief Build a new OpenMP 'map' clause.
1678 /// By default, performs semantic analysis to build the new OpenMP clause.
1679 /// Subclasses may override this routine to provide different behavior.
1681 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1682 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1683 SourceLocation MapLoc, SourceLocation ColonLoc,
1684 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1685 SourceLocation LParenLoc, SourceLocation EndLoc) {
1686 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1687 IsMapTypeImplicit, MapLoc, ColonLoc,
1688 VarList, StartLoc, LParenLoc, EndLoc);
1691 /// \brief Build a new OpenMP 'num_teams' clause.
1693 /// By default, performs semantic analysis to build the new statement.
1694 /// Subclasses may override this routine to provide different behavior.
1695 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1696 SourceLocation LParenLoc,
1697 SourceLocation EndLoc) {
1698 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1702 /// \brief Build a new OpenMP 'thread_limit' clause.
1704 /// By default, performs semantic analysis to build the new statement.
1705 /// Subclasses may override this routine to provide different behavior.
1706 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1707 SourceLocation StartLoc,
1708 SourceLocation LParenLoc,
1709 SourceLocation EndLoc) {
1710 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1714 /// \brief Build a new OpenMP 'priority' clause.
1716 /// By default, performs semantic analysis to build the new statement.
1717 /// Subclasses may override this routine to provide different behavior.
1718 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1719 SourceLocation LParenLoc,
1720 SourceLocation EndLoc) {
1721 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1725 /// \brief Build a new OpenMP 'grainsize' clause.
1727 /// By default, performs semantic analysis to build the new statement.
1728 /// Subclasses may override this routine to provide different behavior.
1729 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1730 SourceLocation LParenLoc,
1731 SourceLocation EndLoc) {
1732 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1736 /// \brief Build a new OpenMP 'num_tasks' clause.
1738 /// By default, performs semantic analysis to build the new statement.
1739 /// Subclasses may override this routine to provide different behavior.
1740 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1741 SourceLocation LParenLoc,
1742 SourceLocation EndLoc) {
1743 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1747 /// \brief Build a new OpenMP 'hint' clause.
1749 /// By default, performs semantic analysis to build the new statement.
1750 /// Subclasses may override this routine to provide different behavior.
1751 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1752 SourceLocation LParenLoc,
1753 SourceLocation EndLoc) {
1754 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1757 /// \brief Build a new OpenMP 'dist_schedule' clause.
1759 /// By default, performs semantic analysis to build the new OpenMP clause.
1760 /// Subclasses may override this routine to provide different behavior.
1762 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1763 Expr *ChunkSize, SourceLocation StartLoc,
1764 SourceLocation LParenLoc, SourceLocation KindLoc,
1765 SourceLocation CommaLoc, SourceLocation EndLoc) {
1766 return getSema().ActOnOpenMPDistScheduleClause(
1767 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1770 /// \brief Build a new OpenMP 'to' clause.
1772 /// By default, performs semantic analysis to build the new statement.
1773 /// Subclasses may override this routine to provide different behavior.
1774 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1775 SourceLocation StartLoc,
1776 SourceLocation LParenLoc,
1777 SourceLocation EndLoc) {
1778 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1781 /// \brief Build a new OpenMP 'from' clause.
1783 /// By default, performs semantic analysis to build the new statement.
1784 /// Subclasses may override this routine to provide different behavior.
1785 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1786 SourceLocation StartLoc,
1787 SourceLocation LParenLoc,
1788 SourceLocation EndLoc) {
1789 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1793 /// Build a new OpenMP 'use_device_ptr' clause.
1795 /// By default, performs semantic analysis to build the new OpenMP clause.
1796 /// Subclasses may override this routine to provide different behavior.
1797 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1798 SourceLocation StartLoc,
1799 SourceLocation LParenLoc,
1800 SourceLocation EndLoc) {
1801 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1805 /// Build a new OpenMP 'is_device_ptr' clause.
1807 /// By default, performs semantic analysis to build the new OpenMP clause.
1808 /// Subclasses may override this routine to provide different behavior.
1809 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1810 SourceLocation StartLoc,
1811 SourceLocation LParenLoc,
1812 SourceLocation EndLoc) {
1813 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1817 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1819 /// By default, performs semantic analysis to build the new statement.
1820 /// Subclasses may override this routine to provide different behavior.
1821 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1823 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1826 /// \brief Build a new Objective-C \@synchronized statement.
1828 /// By default, performs semantic analysis to build the new statement.
1829 /// Subclasses may override this routine to provide different behavior.
1830 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1831 Expr *Object, Stmt *Body) {
1832 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1835 /// \brief Build a new Objective-C \@autoreleasepool statement.
1837 /// By default, performs semantic analysis to build the new statement.
1838 /// Subclasses may override this routine to provide different behavior.
1839 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1841 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1844 /// \brief Build a new Objective-C fast enumeration statement.
1846 /// By default, performs semantic analysis to build the new statement.
1847 /// Subclasses may override this routine to provide different behavior.
1848 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1851 SourceLocation RParenLoc,
1853 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1857 if (ForEachStmt.isInvalid())
1860 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1863 /// \brief Build a new C++ exception declaration.
1865 /// By default, performs semantic analysis to build the new decaration.
1866 /// Subclasses may override this routine to provide different behavior.
1867 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1868 TypeSourceInfo *Declarator,
1869 SourceLocation StartLoc,
1870 SourceLocation IdLoc,
1871 IdentifierInfo *Id) {
1872 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1873 StartLoc, IdLoc, Id);
1875 getSema().CurContext->addDecl(Var);
1879 /// \brief Build a new C++ catch statement.
1881 /// By default, performs semantic analysis to build the new statement.
1882 /// Subclasses may override this routine to provide different behavior.
1883 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1884 VarDecl *ExceptionDecl,
1886 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1890 /// \brief Build a new C++ try statement.
1892 /// By default, performs semantic analysis to build the new statement.
1893 /// Subclasses may override this routine to provide different behavior.
1894 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1895 ArrayRef<Stmt *> Handlers) {
1896 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1899 /// \brief Build a new C++0x range-based for statement.
1901 /// By default, performs semantic analysis to build the new statement.
1902 /// Subclasses may override this routine to provide different behavior.
1903 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1904 SourceLocation CoawaitLoc,
1905 SourceLocation ColonLoc,
1906 Stmt *Range, Stmt *Begin, Stmt *End,
1907 Expr *Cond, Expr *Inc,
1909 SourceLocation RParenLoc) {
1910 // If we've just learned that the range is actually an Objective-C
1911 // collection, treat this as an Objective-C fast enumeration loop.
1912 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1913 if (RangeStmt->isSingleDecl()) {
1914 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1915 if (RangeVar->isInvalidDecl())
1918 Expr *RangeExpr = RangeVar->getInit();
1919 if (!RangeExpr->isTypeDependent() &&
1920 RangeExpr->getType()->isObjCObjectPointerType())
1921 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1927 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1929 Cond, Inc, LoopVar, RParenLoc,
1930 Sema::BFRK_Rebuild);
1933 /// \brief Build a new C++0x range-based for statement.
1935 /// By default, performs semantic analysis to build the new statement.
1936 /// Subclasses may override this routine to provide different behavior.
1937 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1939 NestedNameSpecifierLoc QualifierLoc,
1940 DeclarationNameInfo NameInfo,
1942 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1943 QualifierLoc, NameInfo, Nested);
1946 /// \brief Attach body to a C++0x range-based for statement.
1948 /// By default, performs semantic analysis to finish the new statement.
1949 /// Subclasses may override this routine to provide different behavior.
1950 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1951 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1954 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1955 Stmt *TryBlock, Stmt *Handler) {
1956 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
1959 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
1961 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
1964 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1965 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
1968 /// \brief Build a new predefined expression.
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
1972 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1973 PredefinedExpr::IdentType IT) {
1974 return getSema().BuildPredefinedExpr(Loc, IT);
1977 /// \brief Build a new expression that references a declaration.
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
1981 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1984 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1988 /// \brief Build a new expression that references a declaration.
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
1992 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1994 const DeclarationNameInfo &NameInfo,
1995 TemplateArgumentListInfo *TemplateArgs) {
1997 SS.Adopt(QualifierLoc);
1999 // FIXME: loses template args.
2001 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
2004 /// \brief Build a new expression in parentheses.
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
2008 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
2009 SourceLocation RParen) {
2010 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2013 /// \brief Build a new pseudo-destructor expression.
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
2017 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2018 SourceLocation OperatorLoc,
2021 TypeSourceInfo *ScopeType,
2022 SourceLocation CCLoc,
2023 SourceLocation TildeLoc,
2024 PseudoDestructorTypeStorage Destroyed);
2026 /// \brief Build a new unary operator expression.
2028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
2030 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
2031 UnaryOperatorKind Opc,
2033 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2036 /// \brief Build a new builtin offsetof expression.
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
2040 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
2041 TypeSourceInfo *Type,
2042 ArrayRef<Sema::OffsetOfComponent> Components,
2043 SourceLocation RParenLoc) {
2044 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2048 /// \brief Build a new sizeof, alignof or vec_step expression with a
2051 /// By default, performs semantic analysis to build the new expression.
2052 /// Subclasses may override this routine to provide different behavior.
2053 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2054 SourceLocation OpLoc,
2055 UnaryExprOrTypeTrait ExprKind,
2057 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2060 /// \brief Build a new sizeof, alignof or vec step expression with an
2061 /// expression argument.
2063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
2065 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2066 UnaryExprOrTypeTrait ExprKind,
2069 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2070 if (Result.isInvalid())
2076 /// \brief Build a new array subscript expression.
2078 /// By default, performs semantic analysis to build the new expression.
2079 /// Subclasses may override this routine to provide different behavior.
2080 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
2081 SourceLocation LBracketLoc,
2083 SourceLocation RBracketLoc) {
2084 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2089 /// \brief Build a new array section expression.
2091 /// By default, performs semantic analysis to build the new expression.
2092 /// Subclasses may override this routine to provide different behavior.
2093 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2095 SourceLocation ColonLoc, Expr *Length,
2096 SourceLocation RBracketLoc) {
2097 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2098 ColonLoc, Length, RBracketLoc);
2101 /// \brief Build a new call expression.
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
2105 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
2107 SourceLocation RParenLoc,
2108 Expr *ExecConfig = nullptr) {
2109 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
2110 Args, RParenLoc, ExecConfig);
2113 /// \brief Build a new member access expression.
2115 /// By default, performs semantic analysis to build the new expression.
2116 /// Subclasses may override this routine to provide different behavior.
2117 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
2119 NestedNameSpecifierLoc QualifierLoc,
2120 SourceLocation TemplateKWLoc,
2121 const DeclarationNameInfo &MemberNameInfo,
2123 NamedDecl *FoundDecl,
2124 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2125 NamedDecl *FirstQualifierInScope) {
2126 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2128 if (!Member->getDeclName()) {
2129 // We have a reference to an unnamed field. This is always the
2130 // base of an anonymous struct/union member access, i.e. the
2131 // field is always of record type.
2132 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
2133 assert(Member->getType()->isRecordType() &&
2134 "unnamed member not of record type?");
2137 getSema().PerformObjectMemberConversion(BaseResult.get(),
2138 QualifierLoc.getNestedNameSpecifier(),
2140 if (BaseResult.isInvalid())
2142 Base = BaseResult.get();
2143 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
2144 MemberExpr *ME = new (getSema().Context)
2145 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2146 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
2151 SS.Adopt(QualifierLoc);
2153 Base = BaseResult.get();
2154 QualType BaseType = Base->getType();
2156 // FIXME: this involves duplicating earlier analysis in a lot of
2157 // cases; we should avoid this when possible.
2158 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2159 R.addDecl(FoundDecl);
2162 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2164 FirstQualifierInScope,
2165 R, ExplicitTemplateArgs,
2169 /// \brief Build a new binary operator expression.
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
2173 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
2174 BinaryOperatorKind Opc,
2175 Expr *LHS, Expr *RHS) {
2176 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2179 /// \brief Build a new conditional operator expression.
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
2183 ExprResult RebuildConditionalOperator(Expr *Cond,
2184 SourceLocation QuestionLoc,
2186 SourceLocation ColonLoc,
2188 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2192 /// \brief Build a new C-style cast expression.
2194 /// By default, performs semantic analysis to build the new expression.
2195 /// Subclasses may override this routine to provide different behavior.
2196 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
2197 TypeSourceInfo *TInfo,
2198 SourceLocation RParenLoc,
2200 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2204 /// \brief Build a new compound literal expression.
2206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
2208 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
2209 TypeSourceInfo *TInfo,
2210 SourceLocation RParenLoc,
2212 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2216 /// \brief Build a new extended vector element access expression.
2218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
2220 ExprResult RebuildExtVectorElementExpr(Expr *Base,
2221 SourceLocation OpLoc,
2222 SourceLocation AccessorLoc,
2223 IdentifierInfo &Accessor) {
2226 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2227 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2228 OpLoc, /*IsArrow*/ false,
2229 SS, SourceLocation(),
2230 /*FirstQualifierInScope*/ nullptr,
2232 /* TemplateArgs */ nullptr,
2236 /// \brief Build a new initializer list expression.
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
2240 ExprResult RebuildInitList(SourceLocation LBraceLoc,
2242 SourceLocation RBraceLoc,
2243 QualType ResultTy) {
2245 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2246 if (Result.isInvalid() || ResultTy->isDependentType())
2249 // Patch in the result type we were given, which may have been computed
2250 // when the initial InitListExpr was built.
2251 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2252 ILE->setType(ResultTy);
2256 /// \brief Build a new designated initializer expression.
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
2260 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
2261 MultiExprArg ArrayExprs,
2262 SourceLocation EqualOrColonLoc,
2266 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2268 if (Result.isInvalid())
2274 /// \brief Build a new value-initialized expression.
2276 /// By default, builds the implicit value initialization without performing
2277 /// any semantic analysis. Subclasses may override this routine to provide
2278 /// different behavior.
2279 ExprResult RebuildImplicitValueInitExpr(QualType T) {
2280 return new (SemaRef.Context) ImplicitValueInitExpr(T);
2283 /// \brief Build a new \c va_arg expression.
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
2287 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
2288 Expr *SubExpr, TypeSourceInfo *TInfo,
2289 SourceLocation RParenLoc) {
2290 return getSema().BuildVAArgExpr(BuiltinLoc,
2295 /// \brief Build a new expression list in parentheses.
2297 /// By default, performs semantic analysis to build the new expression.
2298 /// Subclasses may override this routine to provide different behavior.
2299 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
2300 MultiExprArg SubExprs,
2301 SourceLocation RParenLoc) {
2302 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2305 /// \brief Build a new address-of-label expression.
2307 /// By default, performs semantic analysis, using the name of the label
2308 /// rather than attempting to map the label statement itself.
2309 /// Subclasses may override this routine to provide different behavior.
2310 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
2311 SourceLocation LabelLoc, LabelDecl *Label) {
2312 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2315 /// \brief Build a new GNU statement expression.
2317 /// By default, performs semantic analysis to build the new expression.
2318 /// Subclasses may override this routine to provide different behavior.
2319 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
2321 SourceLocation RParenLoc) {
2322 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2325 /// \brief Build a new __builtin_choose_expr expression.
2327 /// By default, performs semantic analysis to build the new expression.
2328 /// Subclasses may override this routine to provide different behavior.
2329 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
2330 Expr *Cond, Expr *LHS, Expr *RHS,
2331 SourceLocation RParenLoc) {
2332 return SemaRef.ActOnChooseExpr(BuiltinLoc,
2337 /// \brief Build a new generic selection expression.
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
2341 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2342 SourceLocation DefaultLoc,
2343 SourceLocation RParenLoc,
2344 Expr *ControllingExpr,
2345 ArrayRef<TypeSourceInfo *> Types,
2346 ArrayRef<Expr *> Exprs) {
2347 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2348 ControllingExpr, Types, Exprs);
2351 /// \brief Build a new overloaded operator call expression.
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// The semantic analysis provides the behavior of template instantiation,
2355 /// copying with transformations that turn what looks like an overloaded
2356 /// operator call into a use of a builtin operator, performing
2357 /// argument-dependent lookup, etc. Subclasses may override this routine to
2358 /// provide different behavior.
2359 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2360 SourceLocation OpLoc,
2365 /// \brief Build a new C++ "named" cast expression, such as static_cast or
2366 /// reinterpret_cast.
2368 /// By default, this routine dispatches to one of the more-specific routines
2369 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2370 /// Subclasses may override this routine to provide different behavior.
2371 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
2372 Stmt::StmtClass Class,
2373 SourceLocation LAngleLoc,
2374 TypeSourceInfo *TInfo,
2375 SourceLocation RAngleLoc,
2376 SourceLocation LParenLoc,
2378 SourceLocation RParenLoc) {
2380 case Stmt::CXXStaticCastExprClass:
2381 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2382 RAngleLoc, LParenLoc,
2383 SubExpr, RParenLoc);
2385 case Stmt::CXXDynamicCastExprClass:
2386 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2387 RAngleLoc, LParenLoc,
2388 SubExpr, RParenLoc);
2390 case Stmt::CXXReinterpretCastExprClass:
2391 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2392 RAngleLoc, LParenLoc,
2396 case Stmt::CXXConstCastExprClass:
2397 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2398 RAngleLoc, LParenLoc,
2399 SubExpr, RParenLoc);
2402 llvm_unreachable("Invalid C++ named cast");
2406 /// \brief Build a new C++ static_cast expression.
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
2410 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
2411 SourceLocation LAngleLoc,
2412 TypeSourceInfo *TInfo,
2413 SourceLocation RAngleLoc,
2414 SourceLocation LParenLoc,
2416 SourceLocation RParenLoc) {
2417 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2419 SourceRange(LAngleLoc, RAngleLoc),
2420 SourceRange(LParenLoc, RParenLoc));
2423 /// \brief Build a new C++ dynamic_cast expression.
2425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
2427 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
2428 SourceLocation LAngleLoc,
2429 TypeSourceInfo *TInfo,
2430 SourceLocation RAngleLoc,
2431 SourceLocation LParenLoc,
2433 SourceLocation RParenLoc) {
2434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2436 SourceRange(LAngleLoc, RAngleLoc),
2437 SourceRange(LParenLoc, RParenLoc));
2440 /// \brief Build a new C++ reinterpret_cast expression.
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
2444 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
2445 SourceLocation LAngleLoc,
2446 TypeSourceInfo *TInfo,
2447 SourceLocation RAngleLoc,
2448 SourceLocation LParenLoc,
2450 SourceLocation RParenLoc) {
2451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2453 SourceRange(LAngleLoc, RAngleLoc),
2454 SourceRange(LParenLoc, RParenLoc));
2457 /// \brief Build a new C++ const_cast expression.
2459 /// By default, performs semantic analysis to build the new expression.
2460 /// Subclasses may override this routine to provide different behavior.
2461 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
2462 SourceLocation LAngleLoc,
2463 TypeSourceInfo *TInfo,
2464 SourceLocation RAngleLoc,
2465 SourceLocation LParenLoc,
2467 SourceLocation RParenLoc) {
2468 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2470 SourceRange(LAngleLoc, RAngleLoc),
2471 SourceRange(LParenLoc, RParenLoc));
2474 /// \brief Build a new C++ functional-style cast expression.
2476 /// By default, performs semantic analysis to build the new expression.
2477 /// Subclasses may override this routine to provide different behavior.
2478 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2479 SourceLocation LParenLoc,
2481 SourceLocation RParenLoc) {
2482 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2483 MultiExprArg(&Sub, 1),
2487 /// \brief Build a new C++ typeid(type) expression.
2489 /// By default, performs semantic analysis to build the new expression.
2490 /// Subclasses may override this routine to provide different behavior.
2491 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2492 SourceLocation TypeidLoc,
2493 TypeSourceInfo *Operand,
2494 SourceLocation RParenLoc) {
2495 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2500 /// \brief Build a new C++ typeid(expr) expression.
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
2504 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2505 SourceLocation TypeidLoc,
2507 SourceLocation RParenLoc) {
2508 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2512 /// \brief Build a new C++ __uuidof(type) expression.
2514 /// By default, performs semantic analysis to build the new expression.
2515 /// Subclasses may override this routine to provide different behavior.
2516 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2517 SourceLocation TypeidLoc,
2518 TypeSourceInfo *Operand,
2519 SourceLocation RParenLoc) {
2520 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2524 /// \brief Build a new C++ __uuidof(expr) expression.
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
2528 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2529 SourceLocation TypeidLoc,
2531 SourceLocation RParenLoc) {
2532 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2536 /// \brief Build a new C++ "this" expression.
2538 /// By default, builds a new "this" expression without performing any
2539 /// semantic analysis. Subclasses may override this routine to provide
2540 /// different behavior.
2541 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
2544 getSema().CheckCXXThisCapture(ThisLoc);
2545 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2548 /// \brief Build a new C++ throw expression.
2550 /// By default, performs semantic analysis to build the new expression.
2551 /// Subclasses may override this routine to provide different behavior.
2552 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2553 bool IsThrownVariableInScope) {
2554 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2557 /// \brief Build a new C++ default-argument expression.
2559 /// By default, builds a new default-argument expression, which does not
2560 /// require any semantic analysis. Subclasses may override this routine to
2561 /// provide different behavior.
2562 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
2563 ParmVarDecl *Param) {
2564 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2567 /// \brief Build a new C++11 default-initialization expression.
2569 /// By default, builds a new default field initialization expression, which
2570 /// does not require any semantic analysis. Subclasses may override this
2571 /// routine to provide different behavior.
2572 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2574 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2577 /// \brief Build a new C++ zero-initialization expression.
2579 /// By default, performs semantic analysis to build the new expression.
2580 /// Subclasses may override this routine to provide different behavior.
2581 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2582 SourceLocation LParenLoc,
2583 SourceLocation RParenLoc) {
2584 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2588 /// \brief Build a new C++ "new" expression.
2590 /// By default, performs semantic analysis to build the new expression.
2591 /// Subclasses may override this routine to provide different behavior.
2592 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
2594 SourceLocation PlacementLParen,
2595 MultiExprArg PlacementArgs,
2596 SourceLocation PlacementRParen,
2597 SourceRange TypeIdParens,
2598 QualType AllocatedType,
2599 TypeSourceInfo *AllocatedTypeInfo,
2601 SourceRange DirectInitRange,
2602 Expr *Initializer) {
2603 return getSema().BuildCXXNew(StartLoc, UseGlobal,
2615 /// \brief Build a new C++ "delete" expression.
2617 /// By default, performs semantic analysis to build the new expression.
2618 /// Subclasses may override this routine to provide different behavior.
2619 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2620 bool IsGlobalDelete,
2623 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2627 /// \brief Build a new type trait expression.
2629 /// By default, performs semantic analysis to build the new expression.
2630 /// Subclasses may override this routine to provide different behavior.
2631 ExprResult RebuildTypeTrait(TypeTrait Trait,
2632 SourceLocation StartLoc,
2633 ArrayRef<TypeSourceInfo *> Args,
2634 SourceLocation RParenLoc) {
2635 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2638 /// \brief Build a new array type trait expression.
2640 /// By default, performs semantic analysis to build the new expression.
2641 /// Subclasses may override this routine to provide different behavior.
2642 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2643 SourceLocation StartLoc,
2644 TypeSourceInfo *TSInfo,
2646 SourceLocation RParenLoc) {
2647 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2650 /// \brief Build a new expression trait expression.
2652 /// By default, performs semantic analysis to build the new expression.
2653 /// Subclasses may override this routine to provide different behavior.
2654 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2655 SourceLocation StartLoc,
2657 SourceLocation RParenLoc) {
2658 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2661 /// \brief Build a new (previously unresolved) declaration reference
2664 /// By default, performs semantic analysis to build the new expression.
2665 /// Subclasses may override this routine to provide different behavior.
2666 ExprResult RebuildDependentScopeDeclRefExpr(
2667 NestedNameSpecifierLoc QualifierLoc,
2668 SourceLocation TemplateKWLoc,
2669 const DeclarationNameInfo &NameInfo,
2670 const TemplateArgumentListInfo *TemplateArgs,
2671 bool IsAddressOfOperand,
2672 TypeSourceInfo **RecoveryTSI) {
2674 SS.Adopt(QualifierLoc);
2676 if (TemplateArgs || TemplateKWLoc.isValid())
2677 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2680 return getSema().BuildQualifiedDeclarationNameExpr(
2681 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2684 /// \brief Build a new template-id expression.
2686 /// By default, performs semantic analysis to build the new expression.
2687 /// Subclasses may override this routine to provide different behavior.
2688 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2689 SourceLocation TemplateKWLoc,
2692 const TemplateArgumentListInfo *TemplateArgs) {
2693 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2697 /// \brief Build a new object-construction expression.
2699 /// By default, performs semantic analysis to build the new expression.
2700 /// Subclasses may override this routine to provide different behavior.
2701 ExprResult RebuildCXXConstructExpr(QualType T,
2703 CXXConstructorDecl *Constructor,
2706 bool HadMultipleCandidates,
2707 bool ListInitialization,
2708 bool StdInitListInitialization,
2709 bool RequiresZeroInit,
2710 CXXConstructExpr::ConstructionKind ConstructKind,
2711 SourceRange ParenRange) {
2712 SmallVector<Expr*, 8> ConvertedArgs;
2713 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2717 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
2720 HadMultipleCandidates,
2722 StdInitListInitialization,
2723 RequiresZeroInit, ConstructKind,
2727 /// \brief Build a new implicit construction via inherited constructor
2729 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2730 CXXConstructorDecl *Constructor,
2731 bool ConstructsVBase,
2732 bool InheritedFromVBase) {
2733 return new (getSema().Context) CXXInheritedCtorInitExpr(
2734 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2737 /// \brief Build a new object-construction expression.
2739 /// By default, performs semantic analysis to build the new expression.
2740 /// Subclasses may override this routine to provide different behavior.
2741 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2742 SourceLocation LParenLoc,
2744 SourceLocation RParenLoc) {
2745 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2751 /// \brief Build a new object-construction expression.
2753 /// By default, performs semantic analysis to build the new expression.
2754 /// Subclasses may override this routine to provide different behavior.
2755 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2756 SourceLocation LParenLoc,
2758 SourceLocation RParenLoc) {
2759 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2765 /// \brief Build a new member reference expression.
2767 /// By default, performs semantic analysis to build the new expression.
2768 /// Subclasses may override this routine to provide different behavior.
2769 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2772 SourceLocation OperatorLoc,
2773 NestedNameSpecifierLoc QualifierLoc,
2774 SourceLocation TemplateKWLoc,
2775 NamedDecl *FirstQualifierInScope,
2776 const DeclarationNameInfo &MemberNameInfo,
2777 const TemplateArgumentListInfo *TemplateArgs) {
2779 SS.Adopt(QualifierLoc);
2781 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2782 OperatorLoc, IsArrow,
2784 FirstQualifierInScope,
2786 TemplateArgs, /*S*/nullptr);
2789 /// \brief Build a new member reference expression.
2791 /// By default, performs semantic analysis to build the new expression.
2792 /// Subclasses may override this routine to provide different behavior.
2793 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2794 SourceLocation OperatorLoc,
2796 NestedNameSpecifierLoc QualifierLoc,
2797 SourceLocation TemplateKWLoc,
2798 NamedDecl *FirstQualifierInScope,
2800 const TemplateArgumentListInfo *TemplateArgs) {
2802 SS.Adopt(QualifierLoc);
2804 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2805 OperatorLoc, IsArrow,
2807 FirstQualifierInScope,
2808 R, TemplateArgs, /*S*/nullptr);
2811 /// \brief Build a new noexcept expression.
2813 /// By default, performs semantic analysis to build the new expression.
2814 /// Subclasses may override this routine to provide different behavior.
2815 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2816 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2819 /// \brief Build a new expression to compute the length of a parameter pack.
2820 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2822 SourceLocation PackLoc,
2823 SourceLocation RParenLoc,
2824 Optional<unsigned> Length,
2825 ArrayRef<TemplateArgument> PartialArgs) {
2826 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2827 RParenLoc, Length, PartialArgs);
2830 /// \brief Build a new Objective-C boxed expression.
2832 /// By default, performs semantic analysis to build the new expression.
2833 /// Subclasses may override this routine to provide different behavior.
2834 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2835 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2838 /// \brief Build a new Objective-C array literal.
2840 /// By default, performs semantic analysis to build the new expression.
2841 /// Subclasses may override this routine to provide different behavior.
2842 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2843 Expr **Elements, unsigned NumElements) {
2844 return getSema().BuildObjCArrayLiteral(Range,
2845 MultiExprArg(Elements, NumElements));
2848 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2849 Expr *Base, Expr *Key,
2850 ObjCMethodDecl *getterMethod,
2851 ObjCMethodDecl *setterMethod) {
2852 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2853 getterMethod, setterMethod);
2856 /// \brief Build a new Objective-C dictionary literal.
2858 /// By default, performs semantic analysis to build the new expression.
2859 /// Subclasses may override this routine to provide different behavior.
2860 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2861 MutableArrayRef<ObjCDictionaryElement> Elements) {
2862 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
2865 /// \brief Build a new Objective-C \@encode expression.
2867 /// By default, performs semantic analysis to build the new expression.
2868 /// Subclasses may override this routine to provide different behavior.
2869 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2870 TypeSourceInfo *EncodeTypeInfo,
2871 SourceLocation RParenLoc) {
2872 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2875 /// \brief Build a new Objective-C class message.
2876 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2878 ArrayRef<SourceLocation> SelectorLocs,
2879 ObjCMethodDecl *Method,
2880 SourceLocation LBracLoc,
2882 SourceLocation RBracLoc) {
2883 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2884 ReceiverTypeInfo->getType(),
2885 /*SuperLoc=*/SourceLocation(),
2886 Sel, Method, LBracLoc, SelectorLocs,
2890 /// \brief Build a new Objective-C instance message.
2891 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2893 ArrayRef<SourceLocation> SelectorLocs,
2894 ObjCMethodDecl *Method,
2895 SourceLocation LBracLoc,
2897 SourceLocation RBracLoc) {
2898 return SemaRef.BuildInstanceMessage(Receiver,
2899 Receiver->getType(),
2900 /*SuperLoc=*/SourceLocation(),
2901 Sel, Method, LBracLoc, SelectorLocs,
2905 /// \brief Build a new Objective-C instance/class message to 'super'.
2906 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2908 ArrayRef<SourceLocation> SelectorLocs,
2910 ObjCMethodDecl *Method,
2911 SourceLocation LBracLoc,
2913 SourceLocation RBracLoc) {
2914 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2917 Sel, Method, LBracLoc, SelectorLocs,
2919 : SemaRef.BuildClassMessage(nullptr,
2922 Sel, Method, LBracLoc, SelectorLocs,
2928 /// \brief Build a new Objective-C ivar reference expression.
2930 /// By default, performs semantic analysis to build the new expression.
2931 /// Subclasses may override this routine to provide different behavior.
2932 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2933 SourceLocation IvarLoc,
2934 bool IsArrow, bool IsFreeIvar) {
2935 // FIXME: We lose track of the IsFreeIvar bit.
2937 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2938 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2939 /*FIXME:*/IvarLoc, IsArrow,
2940 SS, SourceLocation(),
2941 /*FirstQualifierInScope=*/nullptr,
2943 /*TemplateArgs=*/nullptr,
2947 /// \brief Build a new Objective-C property reference expression.
2949 /// By default, performs semantic analysis to build the new expression.
2950 /// Subclasses may override this routine to provide different behavior.
2951 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2952 ObjCPropertyDecl *Property,
2953 SourceLocation PropertyLoc) {
2955 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2956 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2957 /*FIXME:*/PropertyLoc,
2959 SS, SourceLocation(),
2960 /*FirstQualifierInScope=*/nullptr,
2962 /*TemplateArgs=*/nullptr,
2966 /// \brief Build a new Objective-C property reference expression.
2968 /// By default, performs semantic analysis to build the new expression.
2969 /// Subclasses may override this routine to provide different behavior.
2970 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2971 ObjCMethodDecl *Getter,
2972 ObjCMethodDecl *Setter,
2973 SourceLocation PropertyLoc) {
2974 // Since these expressions can only be value-dependent, we do not
2975 // need to perform semantic analysis again.
2977 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2978 VK_LValue, OK_ObjCProperty,
2979 PropertyLoc, Base));
2982 /// \brief Build a new Objective-C "isa" expression.
2984 /// By default, performs semantic analysis to build the new expression.
2985 /// Subclasses may override this routine to provide different behavior.
2986 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2987 SourceLocation OpLoc, bool IsArrow) {
2989 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2990 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2992 SS, SourceLocation(),
2993 /*FirstQualifierInScope=*/nullptr,
2995 /*TemplateArgs=*/nullptr,
2999 /// \brief Build a new shuffle vector expression.
3001 /// By default, performs semantic analysis to build the new expression.
3002 /// Subclasses may override this routine to provide different behavior.
3003 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
3004 MultiExprArg SubExprs,
3005 SourceLocation RParenLoc) {
3006 // Find the declaration for __builtin_shufflevector
3007 const IdentifierInfo &Name
3008 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3009 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3010 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3011 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3013 // Build a reference to the __builtin_shufflevector builtin
3014 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3015 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3016 SemaRef.Context.BuiltinFnTy,
3017 VK_RValue, BuiltinLoc);
3018 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3019 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3020 CK_BuiltinFnToFnPtr).get();
3022 // Build the CallExpr
3023 ExprResult TheCall = new (SemaRef.Context) CallExpr(
3024 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3025 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
3027 // Type-check the __builtin_shufflevector expression.
3028 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3031 /// \brief Build a new convert vector expression.
3032 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3033 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3034 SourceLocation RParenLoc) {
3035 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3036 BuiltinLoc, RParenLoc);
3039 /// \brief Build a new template argument pack expansion.
3041 /// By default, performs semantic analysis to build a new pack expansion
3042 /// for a template argument. Subclasses may override this routine to provide
3043 /// different behavior.
3044 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
3045 SourceLocation EllipsisLoc,
3046 Optional<unsigned> NumExpansions) {
3047 switch (Pattern.getArgument().getKind()) {
3048 case TemplateArgument::Expression: {
3050 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3051 EllipsisLoc, NumExpansions);
3052 if (Result.isInvalid())
3053 return TemplateArgumentLoc();
3055 return TemplateArgumentLoc(Result.get(), Result.get());
3058 case TemplateArgument::Template:
3059 return TemplateArgumentLoc(TemplateArgument(
3060 Pattern.getArgument().getAsTemplate(),
3062 Pattern.getTemplateQualifierLoc(),
3063 Pattern.getTemplateNameLoc(),
3066 case TemplateArgument::Null:
3067 case TemplateArgument::Integral:
3068 case TemplateArgument::Declaration:
3069 case TemplateArgument::Pack:
3070 case TemplateArgument::TemplateExpansion:
3071 case TemplateArgument::NullPtr:
3072 llvm_unreachable("Pack expansion pattern has no parameter packs");
3074 case TemplateArgument::Type:
3075 if (TypeSourceInfo *Expansion
3076 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3079 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3084 return TemplateArgumentLoc();
3087 /// \brief Build a new expression pack expansion.
3089 /// By default, performs semantic analysis to build a new pack expansion
3090 /// for an expression. Subclasses may override this routine to provide
3091 /// different behavior.
3092 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
3093 Optional<unsigned> NumExpansions) {
3094 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3097 /// \brief Build a new C++1z fold-expression.
3099 /// By default, performs semantic analysis in order to build a new fold
3101 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3102 BinaryOperatorKind Operator,
3103 SourceLocation EllipsisLoc, Expr *RHS,
3104 SourceLocation RParenLoc) {
3105 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3109 /// \brief Build an empty C++1z fold-expression with the given operator.
3111 /// By default, produces the fallback value for the fold-expression, or
3112 /// produce an error if there is no fallback value.
3113 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3114 BinaryOperatorKind Operator) {
3115 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3118 /// \brief Build a new atomic operation expression.
3120 /// By default, performs semantic analysis to build the new expression.
3121 /// Subclasses may override this routine to provide different behavior.
3122 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3123 MultiExprArg SubExprs,
3125 AtomicExpr::AtomicOp Op,
3126 SourceLocation RParenLoc) {
3127 // Just create the expression; there is not any interesting semantic
3128 // analysis here because we can't actually build an AtomicExpr until
3129 // we are sure it is semantically sound.
3130 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3135 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3136 QualType ObjectType,
3137 NamedDecl *FirstQualifierInScope,
3140 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3141 QualType ObjectType,
3142 NamedDecl *FirstQualifierInScope,
3145 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3146 NamedDecl *FirstQualifierInScope,
3150 template<typename Derived>
3151 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
3155 switch (S->getStmtClass()) {
3156 case Stmt::NoStmtClass: break;
3158 // Transform individual statement nodes
3159 #define STMT(Node, Parent) \
3160 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3161 #define ABSTRACT_STMT(Node)
3162 #define EXPR(Node, Parent)
3163 #include "clang/AST/StmtNodes.inc"
3165 // Transform expressions by calling TransformExpr.
3166 #define STMT(Node, Parent)
3167 #define ABSTRACT_STMT(Stmt)
3168 #define EXPR(Node, Parent) case Stmt::Node##Class:
3169 #include "clang/AST/StmtNodes.inc"
3171 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3175 return getSema().ActOnExprStmt(E);
3182 template<typename Derived>
3183 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3187 switch (S->getClauseKind()) {
3189 // Transform individual clause nodes
3190 #define OPENMP_CLAUSE(Name, Class) \
3191 case OMPC_ ## Name : \
3192 return getDerived().Transform ## Class(cast<Class>(S));
3193 #include "clang/Basic/OpenMPKinds.def"
3200 template<typename Derived>
3201 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
3205 switch (E->getStmtClass()) {
3206 case Stmt::NoStmtClass: break;
3207 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3208 #define ABSTRACT_STMT(Stmt)
3209 #define EXPR(Node, Parent) \
3210 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3211 #include "clang/AST/StmtNodes.inc"
3217 template<typename Derived>
3218 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
3220 // Initializers are instantiated like expressions, except that various outer
3221 // layers are stripped.
3225 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3226 Init = ExprTemp->getSubExpr();
3228 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3229 Init = AIL->getCommonExpr();
3231 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3232 Init = MTE->GetTemporaryExpr();
3234 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3235 Init = Binder->getSubExpr();
3237 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3238 Init = ICE->getSubExprAsWritten();
3240 if (CXXStdInitializerListExpr *ILE =
3241 dyn_cast<CXXStdInitializerListExpr>(Init))
3242 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3244 // If this is copy-initialization, we only need to reconstruct
3245 // InitListExprs. Other forms of copy-initialization will be a no-op if
3246 // the initializer is already the right type.
3247 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3248 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3249 return getDerived().TransformExpr(Init);
3251 // Revert value-initialization back to empty parens.
3252 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3253 SourceRange Parens = VIE->getSourceRange();
3254 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3258 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3259 if (isa<ImplicitValueInitExpr>(Init))
3260 return getDerived().RebuildParenListExpr(SourceLocation(), None,
3263 // Revert initialization by constructor back to a parenthesized or braced list
3264 // of expressions. Any other form of initializer can just be reused directly.
3265 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3266 return getDerived().TransformExpr(Init);
3268 // If the initialization implicitly converted an initializer list to a
3269 // std::initializer_list object, unwrap the std::initializer_list too.
3270 if (Construct && Construct->isStdInitListInitialization())
3271 return TransformInitializer(Construct->getArg(0), NotCopyInit);
3273 SmallVector<Expr*, 8> NewArgs;
3274 bool ArgChanged = false;
3275 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3276 /*IsCall*/true, NewArgs, &ArgChanged))
3279 // If this was list initialization, revert to list form.
3280 if (Construct->isListInitialization())
3281 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3282 Construct->getLocEnd(),
3283 Construct->getType());
3285 // Build a ParenListExpr to represent anything else.
3286 SourceRange Parens = Construct->getParenOrBraceRange();
3287 if (Parens.isInvalid()) {
3288 // This was a variable declaration's initialization for which no initializer
3290 assert(NewArgs.empty() &&
3291 "no parens or braces but have direct init with arguments?");
3294 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3298 template<typename Derived>
3299 bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
3302 SmallVectorImpl<Expr *> &Outputs,
3304 for (unsigned I = 0; I != NumInputs; ++I) {
3305 // If requested, drop call arguments that need to be dropped.
3306 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3313 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3314 Expr *Pattern = Expansion->getPattern();
3316 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3317 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3318 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3320 // Determine whether the set of unexpanded parameter packs can and should
3323 bool RetainExpansion = false;
3324 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3325 Optional<unsigned> NumExpansions = OrigNumExpansions;
3326 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3327 Pattern->getSourceRange(),
3329 Expand, RetainExpansion,
3334 // The transform has determined that we should perform a simple
3335 // transformation on the pack expansion, producing another pack
3337 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3338 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3339 if (OutPattern.isInvalid())
3342 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3343 Expansion->getEllipsisLoc(),
3345 if (Out.isInvalid())
3350 Outputs.push_back(Out.get());
3354 // Record right away that the argument was changed. This needs
3355 // to happen even if the array expands to nothing.
3356 if (ArgChanged) *ArgChanged = true;
3358 // The transform has determined that we should perform an elementwise
3359 // expansion of the pattern. Do so.
3360 for (unsigned I = 0; I != *NumExpansions; ++I) {
3361 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3362 ExprResult Out = getDerived().TransformExpr(Pattern);
3363 if (Out.isInvalid())
3366 if (Out.get()->containsUnexpandedParameterPack()) {
3367 Out = getDerived().RebuildPackExpansion(
3368 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3369 if (Out.isInvalid())
3373 Outputs.push_back(Out.get());
3376 // If we're supposed to retain a pack expansion, do so by temporarily
3377 // forgetting the partially-substituted parameter pack.
3378 if (RetainExpansion) {
3379 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3381 ExprResult Out = getDerived().TransformExpr(Pattern);
3382 if (Out.isInvalid())
3385 Out = getDerived().RebuildPackExpansion(
3386 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3387 if (Out.isInvalid())
3390 Outputs.push_back(Out.get());
3397 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3398 : getDerived().TransformExpr(Inputs[I]);
3399 if (Result.isInvalid())
3402 if (Result.get() != Inputs[I] && ArgChanged)
3405 Outputs.push_back(Result.get());
3411 template <typename Derived>
3412 Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3413 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3415 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3416 getDerived().TransformDefinition(Var->getLocation(), Var));
3419 return Sema::ConditionError();
3421 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3425 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3427 if (CondExpr.isInvalid())
3428 return Sema::ConditionError();
3430 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3433 return Sema::ConditionResult();
3436 template<typename Derived>
3437 NestedNameSpecifierLoc
3438 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3439 NestedNameSpecifierLoc NNS,
3440 QualType ObjectType,
3441 NamedDecl *FirstQualifierInScope) {
3442 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
3443 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3444 Qualifier = Qualifier.getPrefix())
3445 Qualifiers.push_back(Qualifier);
3448 while (!Qualifiers.empty()) {
3449 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3450 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
3452 switch (QNNS->getKind()) {
3453 case NestedNameSpecifier::Identifier: {
3454 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3455 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3456 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3457 SS, FirstQualifierInScope, false))
3458 return NestedNameSpecifierLoc();
3462 case NestedNameSpecifier::Namespace: {
3464 = cast_or_null<NamespaceDecl>(
3465 getDerived().TransformDecl(
3466 Q.getLocalBeginLoc(),
3467 QNNS->getAsNamespace()));
3468 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3472 case NestedNameSpecifier::NamespaceAlias: {
3473 NamespaceAliasDecl *Alias
3474 = cast_or_null<NamespaceAliasDecl>(
3475 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3476 QNNS->getAsNamespaceAlias()));
3477 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3478 Q.getLocalEndLoc());
3482 case NestedNameSpecifier::Global:
3483 // There is no meaningful transformation that one could perform on the
3485 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3488 case NestedNameSpecifier::Super: {
3490 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3491 SourceLocation(), QNNS->getAsRecordDecl()));
3492 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3496 case NestedNameSpecifier::TypeSpecWithTemplate:
3497 case NestedNameSpecifier::TypeSpec: {
3498 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3499 FirstQualifierInScope, SS);
3502 return NestedNameSpecifierLoc();
3504 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3505 (SemaRef.getLangOpts().CPlusPlus11 &&
3506 TL.getType()->isEnumeralType())) {
3507 assert(!TL.getType().hasLocalQualifiers() &&
3508 "Can't get cv-qualifiers here");
3509 if (TL.getType()->isEnumeralType())
3510 SemaRef.Diag(TL.getBeginLoc(),
3511 diag::warn_cxx98_compat_enum_nested_name_spec);
3512 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3513 Q.getLocalEndLoc());
3516 // If the nested-name-specifier is an invalid type def, don't emit an
3517 // error because a previous error should have already been emitted.
3518 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3519 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3520 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3521 << TL.getType() << SS.getRange();
3523 return NestedNameSpecifierLoc();
3527 // The qualifier-in-scope and object type only apply to the leftmost entity.
3528 FirstQualifierInScope = nullptr;
3529 ObjectType = QualType();
3532 // Don't rebuild the nested-name-specifier if we don't have to.
3533 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3534 !getDerived().AlwaysRebuild())
3537 // If we can re-use the source-location data from the original
3538 // nested-name-specifier, do so.
3539 if (SS.location_size() == NNS.getDataLength() &&
3540 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3541 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3543 // Allocate new nested-name-specifier location information.
3544 return SS.getWithLocInContext(SemaRef.Context);
3547 template<typename Derived>
3549 TreeTransform<Derived>
3550 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
3551 DeclarationName Name = NameInfo.getName();
3553 return DeclarationNameInfo();
3555 switch (Name.getNameKind()) {
3556 case DeclarationName::Identifier:
3557 case DeclarationName::ObjCZeroArgSelector:
3558 case DeclarationName::ObjCOneArgSelector:
3559 case DeclarationName::ObjCMultiArgSelector:
3560 case DeclarationName::CXXOperatorName:
3561 case DeclarationName::CXXLiteralOperatorName:
3562 case DeclarationName::CXXUsingDirective:
3565 case DeclarationName::CXXConstructorName:
3566 case DeclarationName::CXXDestructorName:
3567 case DeclarationName::CXXConversionFunctionName: {
3568 TypeSourceInfo *NewTInfo;
3569 CanQualType NewCanTy;
3570 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3571 NewTInfo = getDerived().TransformType(OldTInfo);
3573 return DeclarationNameInfo();
3574 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3578 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3579 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3581 return DeclarationNameInfo();
3582 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3585 DeclarationName NewName
3586 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3588 DeclarationNameInfo NewNameInfo(NameInfo);
3589 NewNameInfo.setName(NewName);
3590 NewNameInfo.setNamedTypeInfo(NewTInfo);
3595 llvm_unreachable("Unknown name kind.");
3598 template<typename Derived>
3600 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3602 SourceLocation NameLoc,
3603 QualType ObjectType,
3604 NamedDecl *FirstQualifierInScope) {
3605 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3606 TemplateDecl *Template = QTN->getTemplateDecl();
3607 assert(Template && "qualified template name must refer to a template");
3609 TemplateDecl *TransTemplate
3610 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3613 return TemplateName();
3615 if (!getDerived().AlwaysRebuild() &&
3616 SS.getScopeRep() == QTN->getQualifier() &&
3617 TransTemplate == Template)
3620 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3624 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3625 if (SS.getScopeRep()) {
3626 // These apply to the scope specifier, not the template.
3627 ObjectType = QualType();
3628 FirstQualifierInScope = nullptr;
3631 if (!getDerived().AlwaysRebuild() &&
3632 SS.getScopeRep() == DTN->getQualifier() &&
3633 ObjectType.isNull())
3636 if (DTN->isIdentifier()) {
3637 return getDerived().RebuildTemplateName(SS,
3638 *DTN->getIdentifier(),
3641 FirstQualifierInScope);
3644 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3648 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3649 TemplateDecl *TransTemplate
3650 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3653 return TemplateName();
3655 if (!getDerived().AlwaysRebuild() &&
3656 TransTemplate == Template)
3659 return TemplateName(TransTemplate);
3662 if (SubstTemplateTemplateParmPackStorage *SubstPack
3663 = Name.getAsSubstTemplateTemplateParmPack()) {
3664 TemplateTemplateParmDecl *TransParam
3665 = cast_or_null<TemplateTemplateParmDecl>(
3666 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3668 return TemplateName();
3670 if (!getDerived().AlwaysRebuild() &&
3671 TransParam == SubstPack->getParameterPack())
3674 return getDerived().RebuildTemplateName(TransParam,
3675 SubstPack->getArgumentPack());
3678 // These should be getting filtered out before they reach the AST.
3679 llvm_unreachable("overloaded function decl survived to here");
3682 template<typename Derived>
3683 void TreeTransform<Derived>::InventTemplateArgumentLoc(
3684 const TemplateArgument &Arg,
3685 TemplateArgumentLoc &Output) {
3686 SourceLocation Loc = getDerived().getBaseLocation();
3687 switch (Arg.getKind()) {
3688 case TemplateArgument::Null:
3689 llvm_unreachable("null template argument in TreeTransform");
3692 case TemplateArgument::Type:
3693 Output = TemplateArgumentLoc(Arg,
3694 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3698 case TemplateArgument::Template:
3699 case TemplateArgument::TemplateExpansion: {
3700 NestedNameSpecifierLocBuilder Builder;
3701 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
3702 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3703 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3704 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3705 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3707 if (Arg.getKind() == TemplateArgument::Template)
3708 Output = TemplateArgumentLoc(Arg,
3709 Builder.getWithLocInContext(SemaRef.Context),
3712 Output = TemplateArgumentLoc(Arg,
3713 Builder.getWithLocInContext(SemaRef.Context),
3719 case TemplateArgument::Expression:
3720 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3723 case TemplateArgument::Declaration:
3724 case TemplateArgument::Integral:
3725 case TemplateArgument::Pack:
3726 case TemplateArgument::NullPtr:
3727 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
3732 template<typename Derived>
3733 bool TreeTransform<Derived>::TransformTemplateArgument(
3734 const TemplateArgumentLoc &Input,
3735 TemplateArgumentLoc &Output, bool Uneval) {
3736 const TemplateArgument &Arg = Input.getArgument();
3737 switch (Arg.getKind()) {
3738 case TemplateArgument::Null:
3739 case TemplateArgument::Integral:
3740 case TemplateArgument::Pack:
3741 case TemplateArgument::Declaration:
3742 case TemplateArgument::NullPtr:
3743 llvm_unreachable("Unexpected TemplateArgument");
3745 case TemplateArgument::Type: {
3746 TypeSourceInfo *DI = Input.getTypeSourceInfo();
3748 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3750 DI = getDerived().TransformType(DI);
3751 if (!DI) return true;
3753 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3757 case TemplateArgument::Template: {
3758 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3760 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3766 SS.Adopt(QualifierLoc);
3767 TemplateName Template
3768 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3769 Input.getTemplateNameLoc());
3770 if (Template.isNull())
3773 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3774 Input.getTemplateNameLoc());
3778 case TemplateArgument::TemplateExpansion:
3779 llvm_unreachable("Caller should expand pack expansions");
3781 case TemplateArgument::Expression: {
3782 // Template argument expressions are constant expressions.
3783 EnterExpressionEvaluationContext Unevaluated(
3784 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
3786 Expr *InputExpr = Input.getSourceExpression();
3787 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3789 ExprResult E = getDerived().TransformExpr(InputExpr);
3790 E = SemaRef.ActOnConstantExpression(E);
3791 if (E.isInvalid()) return true;
3792 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3797 // Work around bogus GCC warning
3801 /// \brief Iterator adaptor that invents template argument location information
3802 /// for each of the template arguments in its underlying iterator.
3803 template<typename Derived, typename InputIterator>
3804 class TemplateArgumentLocInventIterator {
3805 TreeTransform<Derived> &Self;
3809 typedef TemplateArgumentLoc value_type;
3810 typedef TemplateArgumentLoc reference;
3811 typedef typename std::iterator_traits<InputIterator>::difference_type
3813 typedef std::input_iterator_tag iterator_category;
3816 TemplateArgumentLoc Arg;
3819 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3821 const TemplateArgumentLoc *operator->() const { return &Arg; }
3824 TemplateArgumentLocInventIterator() { }
3826 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3828 : Self(Self), Iter(Iter) { }
3830 TemplateArgumentLocInventIterator &operator++() {
3835 TemplateArgumentLocInventIterator operator++(int) {
3836 TemplateArgumentLocInventIterator Old(*this);
3841 reference operator*() const {
3842 TemplateArgumentLoc Result;
3843 Self.InventTemplateArgumentLoc(*Iter, Result);
3847 pointer operator->() const { return pointer(**this); }
3849 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3850 const TemplateArgumentLocInventIterator &Y) {
3851 return X.Iter == Y.Iter;
3854 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3855 const TemplateArgumentLocInventIterator &Y) {
3856 return X.Iter != Y.Iter;
3860 template<typename Derived>
3861 template<typename InputIterator>
3862 bool TreeTransform<Derived>::TransformTemplateArguments(
3863 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3865 for (; First != Last; ++First) {
3866 TemplateArgumentLoc Out;
3867 TemplateArgumentLoc In = *First;
3869 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3870 // Unpack argument packs, which we translate them into separate
3872 // FIXME: We could do much better if we could guarantee that the
3873 // TemplateArgumentLocInfo for the pack expansion would be usable for
3874 // all of the template arguments in the argument pack.
3875 typedef TemplateArgumentLocInventIterator<Derived,
3876 TemplateArgument::pack_iterator>
3878 if (TransformTemplateArguments(PackLocIterator(*this,
3879 In.getArgument().pack_begin()),
3880 PackLocIterator(*this,
3881 In.getArgument().pack_end()),
3888 if (In.getArgument().isPackExpansion()) {
3889 // We have a pack expansion, for which we will be substituting into
3891 SourceLocation Ellipsis;
3892 Optional<unsigned> OrigNumExpansions;
3893 TemplateArgumentLoc Pattern
3894 = getSema().getTemplateArgumentPackExpansionPattern(
3895 In, Ellipsis, OrigNumExpansions);
3897 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3898 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3899 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3901 // Determine whether the set of unexpanded parameter packs can and should
3904 bool RetainExpansion = false;
3905 Optional<unsigned> NumExpansions = OrigNumExpansions;
3906 if (getDerived().TryExpandParameterPacks(Ellipsis,
3907 Pattern.getSourceRange(),
3915 // The transform has determined that we should perform a simple
3916 // transformation on the pack expansion, producing another pack
3918 TemplateArgumentLoc OutPattern;
3919 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3920 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
3923 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3925 if (Out.getArgument().isNull())
3928 Outputs.addArgument(Out);
3932 // The transform has determined that we should perform an elementwise
3933 // expansion of the pattern. Do so.
3934 for (unsigned I = 0; I != *NumExpansions; ++I) {
3935 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3937 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
3940 if (Out.getArgument().containsUnexpandedParameterPack()) {
3941 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3943 if (Out.getArgument().isNull())
3947 Outputs.addArgument(Out);
3950 // If we're supposed to retain a pack expansion, do so by temporarily
3951 // forgetting the partially-substituted parameter pack.
3952 if (RetainExpansion) {
3953 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3955 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
3958 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3960 if (Out.getArgument().isNull())
3963 Outputs.addArgument(Out);
3970 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
3973 Outputs.addArgument(Out);
3980 //===----------------------------------------------------------------------===//
3981 // Type transformation
3982 //===----------------------------------------------------------------------===//
3984 template<typename Derived>
3985 QualType TreeTransform<Derived>::TransformType(QualType T) {
3986 if (getDerived().AlreadyTransformed(T))
3989 // Temporary workaround. All of these transformations should
3990 // eventually turn into transformations on TypeLocs.
3991 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3992 getDerived().getBaseLocation());
3994 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3999 return NewDI->getType();
4002 template<typename Derived>
4003 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
4004 // Refine the base location to the type's location.
4005 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4006 getDerived().getBaseEntity());
4007 if (getDerived().AlreadyTransformed(DI->getType()))
4012 TypeLoc TL = DI->getTypeLoc();
4013 TLB.reserve(TL.getFullDataSize());
4015 QualType Result = getDerived().TransformType(TLB, TL);
4016 if (Result.isNull())
4019 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4022 template<typename Derived>
4024 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
4025 switch (T.getTypeLocClass()) {
4026 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4027 #define TYPELOC(CLASS, PARENT) \
4028 case TypeLoc::CLASS: \
4029 return getDerived().Transform##CLASS##Type(TLB, \
4030 T.castAs<CLASS##TypeLoc>());
4031 #include "clang/AST/TypeLocNodes.def"
4034 llvm_unreachable("unhandled type loc!");
4037 /// FIXME: By default, this routine adds type qualifiers only to types
4038 /// that can have qualifiers, and silently suppresses those qualifiers
4039 /// that are not permitted (e.g., qualifiers on reference or function
4040 /// types). This is the right thing for template instantiation, but
4041 /// probably not for other clients.
4042 template<typename Derived>
4044 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
4045 QualifiedTypeLoc T) {
4046 Qualifiers Quals = T.getType().getLocalQualifiers();
4048 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4049 if (Result.isNull())
4052 // Silently suppress qualifiers if the result type can't be qualified.
4053 // FIXME: this is the right thing for template instantiation, but
4054 // probably not for other clients.
4055 if (Result->isFunctionType() || Result->isReferenceType())
4058 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4060 if (Quals.hasObjCLifetime()) {
4061 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4062 Quals.removeObjCLifetime();
4063 else if (Result.getObjCLifetime()) {
4065 // A lifetime qualifier applied to a substituted template parameter
4066 // overrides the lifetime qualifier from the template argument.
4067 const AutoType *AutoTy;
4068 if (const SubstTemplateTypeParmType *SubstTypeParam
4069 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4070 QualType Replacement = SubstTypeParam->getReplacementType();
4071 Qualifiers Qs = Replacement.getQualifiers();
4072 Qs.removeObjCLifetime();
4074 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4076 Result = SemaRef.Context.getSubstTemplateTypeParmType(
4077 SubstTypeParam->getReplacedParameter(),
4079 TLB.TypeWasModifiedSafely(Result);
4080 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4081 // 'auto' types behave the same way as template parameters.
4082 QualType Deduced = AutoTy->getDeducedType();
4083 Qualifiers Qs = Deduced.getQualifiers();
4084 Qs.removeObjCLifetime();
4085 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4087 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4088 AutoTy->isDependentType());
4089 TLB.TypeWasModifiedSafely(Result);
4091 // Otherwise, complain about the addition of a qualifier to an
4092 // already-qualified type.
4093 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
4094 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
4097 Quals.removeObjCLifetime();
4101 if (!Quals.empty()) {
4102 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
4103 // BuildQualifiedType might not add qualifiers if they are invalid.
4104 if (Result.hasLocalQualifiers())
4105 TLB.push<QualifiedTypeLoc>(Result);
4106 // No location information to preserve.
4112 template<typename Derived>
4114 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4115 QualType ObjectType,
4116 NamedDecl *UnqualLookup,
4118 if (getDerived().AlreadyTransformed(TL.getType()))
4121 TypeSourceInfo *TSI =
4122 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4124 return TSI->getTypeLoc();
4128 template<typename Derived>
4130 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4131 QualType ObjectType,
4132 NamedDecl *UnqualLookup,
4134 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4137 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4141 template <typename Derived>
4142 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4143 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4145 QualType T = TL.getType();
4146 assert(!getDerived().AlreadyTransformed(T));
4151 if (isa<TemplateSpecializationType>(T)) {
4152 TemplateSpecializationTypeLoc SpecTL =
4153 TL.castAs<TemplateSpecializationTypeLoc>();
4155 TemplateName Template
4156 = getDerived().TransformTemplateName(SS,
4157 SpecTL.getTypePtr()->getTemplateName(),
4158 SpecTL.getTemplateNameLoc(),
4159 ObjectType, UnqualLookup);
4160 if (Template.isNull())
4163 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4165 } else if (isa<DependentTemplateSpecializationType>(T)) {
4166 DependentTemplateSpecializationTypeLoc SpecTL =
4167 TL.castAs<DependentTemplateSpecializationTypeLoc>();
4169 TemplateName Template
4170 = getDerived().RebuildTemplateName(SS,
4171 *SpecTL.getTypePtr()->getIdentifier(),
4172 SpecTL.getTemplateNameLoc(),
4173 ObjectType, UnqualLookup);
4174 if (Template.isNull())
4177 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4182 // Nothing special needs to be done for these.
4183 Result = getDerived().TransformType(TLB, TL);
4186 if (Result.isNull())
4189 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4192 template <class TyLoc> static inline
4193 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4194 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4195 NewT.setNameLoc(T.getNameLoc());
4199 template<typename Derived>
4200 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4202 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4203 NewT.setBuiltinLoc(T.getBuiltinLoc());
4204 if (T.needsExtraLocalData())
4205 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4209 template<typename Derived>
4210 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4213 return TransformTypeSpecType(TLB, T);
4216 template <typename Derived>
4217 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4218 AdjustedTypeLoc TL) {
4219 // Adjustments applied during transformation are handled elsewhere.
4220 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4223 template<typename Derived>
4224 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4225 DecayedTypeLoc TL) {
4226 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4227 if (OriginalType.isNull())
4230 QualType Result = TL.getType();
4231 if (getDerived().AlwaysRebuild() ||
4232 OriginalType != TL.getOriginalLoc().getType())
4233 Result = SemaRef.Context.getDecayedType(OriginalType);
4234 TLB.push<DecayedTypeLoc>(Result);
4235 // Nothing to set for DecayedTypeLoc.
4239 template<typename Derived>
4240 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4241 PointerTypeLoc TL) {
4242 QualType PointeeType
4243 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4244 if (PointeeType.isNull())
4247 QualType Result = TL.getType();
4248 if (PointeeType->getAs<ObjCObjectType>()) {
4249 // A dependent pointer type 'T *' has is being transformed such
4250 // that an Objective-C class type is being replaced for 'T'. The
4251 // resulting pointer type is an ObjCObjectPointerType, not a
4253 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4255 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4256 NewT.setStarLoc(TL.getStarLoc());
4260 if (getDerived().AlwaysRebuild() ||
4261 PointeeType != TL.getPointeeLoc().getType()) {
4262 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4263 if (Result.isNull())
4267 // Objective-C ARC can add lifetime qualifiers to the type that we're
4269 TLB.TypeWasModifiedSafely(Result->getPointeeType());
4271 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4272 NewT.setSigilLoc(TL.getSigilLoc());
4276 template<typename Derived>
4278 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4279 BlockPointerTypeLoc TL) {
4280 QualType PointeeType
4281 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4282 if (PointeeType.isNull())
4285 QualType Result = TL.getType();
4286 if (getDerived().AlwaysRebuild() ||
4287 PointeeType != TL.getPointeeLoc().getType()) {
4288 Result = getDerived().RebuildBlockPointerType(PointeeType,
4290 if (Result.isNull())
4294 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4295 NewT.setSigilLoc(TL.getSigilLoc());
4299 /// Transforms a reference type. Note that somewhat paradoxically we
4300 /// don't care whether the type itself is an l-value type or an r-value
4301 /// type; we only care if the type was *written* as an l-value type
4302 /// or an r-value type.
4303 template<typename Derived>
4305 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
4306 ReferenceTypeLoc TL) {
4307 const ReferenceType *T = TL.getTypePtr();
4309 // Note that this works with the pointee-as-written.
4310 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4311 if (PointeeType.isNull())
4314 QualType Result = TL.getType();
4315 if (getDerived().AlwaysRebuild() ||
4316 PointeeType != T->getPointeeTypeAsWritten()) {
4317 Result = getDerived().RebuildReferenceType(PointeeType,
4318 T->isSpelledAsLValue(),
4320 if (Result.isNull())
4324 // Objective-C ARC can add lifetime qualifiers to the type that we're
4326 TLB.TypeWasModifiedSafely(
4327 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4329 // r-value references can be rebuilt as l-value references.
4330 ReferenceTypeLoc NewTL;
4331 if (isa<LValueReferenceType>(Result))
4332 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4334 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4335 NewTL.setSigilLoc(TL.getSigilLoc());
4340 template<typename Derived>
4342 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
4343 LValueReferenceTypeLoc TL) {
4344 return TransformReferenceType(TLB, TL);
4347 template<typename Derived>
4349 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
4350 RValueReferenceTypeLoc TL) {
4351 return TransformReferenceType(TLB, TL);
4354 template<typename Derived>
4356 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
4357 MemberPointerTypeLoc TL) {
4358 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4359 if (PointeeType.isNull())
4362 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4363 TypeSourceInfo *NewClsTInfo = nullptr;
4365 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4370 const MemberPointerType *T = TL.getTypePtr();
4371 QualType OldClsType = QualType(T->getClass(), 0);
4372 QualType NewClsType;
4374 NewClsType = NewClsTInfo->getType();
4376 NewClsType = getDerived().TransformType(OldClsType);
4377 if (NewClsType.isNull())
4381 QualType Result = TL.getType();
4382 if (getDerived().AlwaysRebuild() ||
4383 PointeeType != T->getPointeeType() ||
4384 NewClsType != OldClsType) {
4385 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4387 if (Result.isNull())
4391 // If we had to adjust the pointee type when building a member pointer, make
4392 // sure to push TypeLoc info for it.
4393 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4394 if (MPT && PointeeType != MPT->getPointeeType()) {
4395 assert(isa<AdjustedType>(MPT->getPointeeType()));
4396 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4399 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4400 NewTL.setSigilLoc(TL.getSigilLoc());
4401 NewTL.setClassTInfo(NewClsTInfo);
4406 template<typename Derived>
4408 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4409 ConstantArrayTypeLoc TL) {
4410 const ConstantArrayType *T = TL.getTypePtr();
4411 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4412 if (ElementType.isNull())
4415 QualType Result = TL.getType();
4416 if (getDerived().AlwaysRebuild() ||
4417 ElementType != T->getElementType()) {
4418 Result = getDerived().RebuildConstantArrayType(ElementType,
4419 T->getSizeModifier(),
4421 T->getIndexTypeCVRQualifiers(),
4422 TL.getBracketsRange());
4423 if (Result.isNull())
4427 // We might have either a ConstantArrayType or a VariableArrayType now:
4428 // a ConstantArrayType is allowed to have an element type which is a
4429 // VariableArrayType if the type is dependent. Fortunately, all array
4430 // types have the same location layout.
4431 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4432 NewTL.setLBracketLoc(TL.getLBracketLoc());
4433 NewTL.setRBracketLoc(TL.getRBracketLoc());
4435 Expr *Size = TL.getSizeExpr();
4437 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4438 Sema::ConstantEvaluated);
4439 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4440 Size = SemaRef.ActOnConstantExpression(Size).get();
4442 NewTL.setSizeExpr(Size);
4447 template<typename Derived>
4448 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4449 TypeLocBuilder &TLB,
4450 IncompleteArrayTypeLoc TL) {
4451 const IncompleteArrayType *T = TL.getTypePtr();
4452 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4453 if (ElementType.isNull())
4456 QualType Result = TL.getType();
4457 if (getDerived().AlwaysRebuild() ||
4458 ElementType != T->getElementType()) {
4459 Result = getDerived().RebuildIncompleteArrayType(ElementType,
4460 T->getSizeModifier(),
4461 T->getIndexTypeCVRQualifiers(),
4462 TL.getBracketsRange());
4463 if (Result.isNull())
4467 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4468 NewTL.setLBracketLoc(TL.getLBracketLoc());
4469 NewTL.setRBracketLoc(TL.getRBracketLoc());
4470 NewTL.setSizeExpr(nullptr);
4475 template<typename Derived>
4477 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4478 VariableArrayTypeLoc TL) {
4479 const VariableArrayType *T = TL.getTypePtr();
4480 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4481 if (ElementType.isNull())
4484 ExprResult SizeResult
4485 = getDerived().TransformExpr(T->getSizeExpr());
4486 if (SizeResult.isInvalid())
4489 Expr *Size = SizeResult.get();
4491 QualType Result = TL.getType();
4492 if (getDerived().AlwaysRebuild() ||
4493 ElementType != T->getElementType() ||
4494 Size != T->getSizeExpr()) {
4495 Result = getDerived().RebuildVariableArrayType(ElementType,
4496 T->getSizeModifier(),
4498 T->getIndexTypeCVRQualifiers(),
4499 TL.getBracketsRange());
4500 if (Result.isNull())
4504 // We might have constant size array now, but fortunately it has the same
4506 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4507 NewTL.setLBracketLoc(TL.getLBracketLoc());
4508 NewTL.setRBracketLoc(TL.getRBracketLoc());
4509 NewTL.setSizeExpr(Size);
4514 template<typename Derived>
4516 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4517 DependentSizedArrayTypeLoc TL) {
4518 const DependentSizedArrayType *T = TL.getTypePtr();
4519 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4520 if (ElementType.isNull())
4523 // Array bounds are constant expressions.
4524 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4525 Sema::ConstantEvaluated);
4527 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4528 Expr *origSize = TL.getSizeExpr();
4529 if (!origSize) origSize = T->getSizeExpr();
4531 ExprResult sizeResult
4532 = getDerived().TransformExpr(origSize);
4533 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4534 if (sizeResult.isInvalid())
4537 Expr *size = sizeResult.get();
4539 QualType Result = TL.getType();
4540 if (getDerived().AlwaysRebuild() ||
4541 ElementType != T->getElementType() ||
4543 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4544 T->getSizeModifier(),
4546 T->getIndexTypeCVRQualifiers(),
4547 TL.getBracketsRange());
4548 if (Result.isNull())
4552 // We might have any sort of array type now, but fortunately they
4553 // all have the same location layout.
4554 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4555 NewTL.setLBracketLoc(TL.getLBracketLoc());
4556 NewTL.setRBracketLoc(TL.getRBracketLoc());
4557 NewTL.setSizeExpr(size);
4562 template<typename Derived>
4563 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4564 TypeLocBuilder &TLB,
4565 DependentSizedExtVectorTypeLoc TL) {
4566 const DependentSizedExtVectorType *T = TL.getTypePtr();
4568 // FIXME: ext vector locs should be nested
4569 QualType ElementType = getDerived().TransformType(T->getElementType());
4570 if (ElementType.isNull())
4573 // Vector sizes are constant expressions.
4574 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4575 Sema::ConstantEvaluated);
4577 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4578 Size = SemaRef.ActOnConstantExpression(Size);
4579 if (Size.isInvalid())
4582 QualType Result = TL.getType();
4583 if (getDerived().AlwaysRebuild() ||
4584 ElementType != T->getElementType() ||
4585 Size.get() != T->getSizeExpr()) {
4586 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4588 T->getAttributeLoc());
4589 if (Result.isNull())
4593 // Result might be dependent or not.
4594 if (isa<DependentSizedExtVectorType>(Result)) {
4595 DependentSizedExtVectorTypeLoc NewTL
4596 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4597 NewTL.setNameLoc(TL.getNameLoc());
4599 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4600 NewTL.setNameLoc(TL.getNameLoc());
4606 template<typename Derived>
4607 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4609 const VectorType *T = TL.getTypePtr();
4610 QualType ElementType = getDerived().TransformType(T->getElementType());
4611 if (ElementType.isNull())
4614 QualType Result = TL.getType();
4615 if (getDerived().AlwaysRebuild() ||
4616 ElementType != T->getElementType()) {
4617 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4618 T->getVectorKind());
4619 if (Result.isNull())
4623 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4624 NewTL.setNameLoc(TL.getNameLoc());
4629 template<typename Derived>
4630 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4631 ExtVectorTypeLoc TL) {
4632 const VectorType *T = TL.getTypePtr();
4633 QualType ElementType = getDerived().TransformType(T->getElementType());
4634 if (ElementType.isNull())
4637 QualType Result = TL.getType();
4638 if (getDerived().AlwaysRebuild() ||
4639 ElementType != T->getElementType()) {
4640 Result = getDerived().RebuildExtVectorType(ElementType,
4641 T->getNumElements(),
4642 /*FIXME*/ SourceLocation());
4643 if (Result.isNull())
4647 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4648 NewTL.setNameLoc(TL.getNameLoc());
4653 template <typename Derived>
4654 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4655 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4656 bool ExpectParameterPack) {
4657 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4658 TypeSourceInfo *NewDI = nullptr;
4660 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4661 // If we're substituting into a pack expansion type and we know the
4662 // length we want to expand to, just substitute for the pattern.
4663 TypeLoc OldTL = OldDI->getTypeLoc();
4664 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4667 TypeLoc NewTL = OldDI->getTypeLoc();
4668 TLB.reserve(NewTL.getFullDataSize());
4670 QualType Result = getDerived().TransformType(TLB,
4671 OldExpansionTL.getPatternLoc());
4672 if (Result.isNull())
4675 Result = RebuildPackExpansionType(Result,
4676 OldExpansionTL.getPatternLoc().getSourceRange(),
4677 OldExpansionTL.getEllipsisLoc(),
4679 if (Result.isNull())
4682 PackExpansionTypeLoc NewExpansionTL
4683 = TLB.push<PackExpansionTypeLoc>(Result);
4684 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4685 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4687 NewDI = getDerived().TransformType(OldDI);
4691 if (NewDI == OldDI && indexAdjustment == 0)
4694 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4695 OldParm->getDeclContext(),
4696 OldParm->getInnerLocStart(),
4697 OldParm->getLocation(),
4698 OldParm->getIdentifier(),
4701 OldParm->getStorageClass(),
4702 /* DefArg */ nullptr);
4703 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4704 OldParm->getFunctionScopeIndex() + indexAdjustment);
4708 template <typename Derived>
4709 bool TreeTransform<Derived>::TransformFunctionTypeParams(
4710 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4711 const QualType *ParamTypes,
4712 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4713 SmallVectorImpl<QualType> &OutParamTypes,
4714 SmallVectorImpl<ParmVarDecl *> *PVars,
4715 Sema::ExtParameterInfoBuilder &PInfos) {
4716 int indexAdjustment = 0;
4718 unsigned NumParams = Params.size();
4719 for (unsigned i = 0; i != NumParams; ++i) {
4720 if (ParmVarDecl *OldParm = Params[i]) {
4721 assert(OldParm->getFunctionScopeIndex() == i);
4723 Optional<unsigned> NumExpansions;
4724 ParmVarDecl *NewParm = nullptr;
4725 if (OldParm->isParameterPack()) {
4726 // We have a function parameter pack that may need to be expanded.
4727 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4729 // Find the parameter packs that could be expanded.
4730 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4731 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4732 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4733 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4734 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4736 // Determine whether we should expand the parameter packs.
4737 bool ShouldExpand = false;
4738 bool RetainExpansion = false;
4739 Optional<unsigned> OrigNumExpansions =
4740 ExpansionTL.getTypePtr()->getNumExpansions();
4741 NumExpansions = OrigNumExpansions;
4742 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4743 Pattern.getSourceRange(),
4752 // Expand the function parameter pack into multiple, separate
4754 getDerived().ExpandingFunctionParameterPack(OldParm);
4755 for (unsigned I = 0; I != *NumExpansions; ++I) {
4756 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4757 ParmVarDecl *NewParm
4758 = getDerived().TransformFunctionTypeParam(OldParm,
4761 /*ExpectParameterPack=*/false);
4766 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4767 OutParamTypes.push_back(NewParm->getType());
4769 PVars->push_back(NewParm);
4772 // If we're supposed to retain a pack expansion, do so by temporarily
4773 // forgetting the partially-substituted parameter pack.
4774 if (RetainExpansion) {
4775 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4776 ParmVarDecl *NewParm
4777 = getDerived().TransformFunctionTypeParam(OldParm,
4780 /*ExpectParameterPack=*/false);
4785 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4786 OutParamTypes.push_back(NewParm->getType());
4788 PVars->push_back(NewParm);
4791 // The next parameter should have the same adjustment as the
4792 // last thing we pushed, but we post-incremented indexAdjustment
4793 // on every push. Also, if we push nothing, the adjustment should
4797 // We're done with the pack expansion.
4801 // We'll substitute the parameter now without expanding the pack
4803 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4804 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4807 /*ExpectParameterPack=*/true);
4809 NewParm = getDerived().TransformFunctionTypeParam(
4810 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4817 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4818 OutParamTypes.push_back(NewParm->getType());
4820 PVars->push_back(NewParm);
4824 // Deal with the possibility that we don't have a parameter
4825 // declaration for this parameter.
4826 QualType OldType = ParamTypes[i];
4827 bool IsPackExpansion = false;
4828 Optional<unsigned> NumExpansions;
4830 if (const PackExpansionType *Expansion
4831 = dyn_cast<PackExpansionType>(OldType)) {
4832 // We have a function parameter pack that may need to be expanded.
4833 QualType Pattern = Expansion->getPattern();
4834 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4835 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4837 // Determine whether we should expand the parameter packs.
4838 bool ShouldExpand = false;
4839 bool RetainExpansion = false;
4840 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4849 // Expand the function parameter pack into multiple, separate
4851 for (unsigned I = 0; I != *NumExpansions; ++I) {
4852 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4853 QualType NewType = getDerived().TransformType(Pattern);
4854 if (NewType.isNull())
4857 if (NewType->containsUnexpandedParameterPack()) {
4859 getSema().getASTContext().getPackExpansionType(NewType, None);
4861 if (NewType.isNull())
4866 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4867 OutParamTypes.push_back(NewType);
4869 PVars->push_back(nullptr);
4872 // We're done with the pack expansion.
4876 // If we're supposed to retain a pack expansion, do so by temporarily
4877 // forgetting the partially-substituted parameter pack.
4878 if (RetainExpansion) {
4879 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4880 QualType NewType = getDerived().TransformType(Pattern);
4881 if (NewType.isNull())
4885 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4886 OutParamTypes.push_back(NewType);
4888 PVars->push_back(nullptr);
4891 // We'll substitute the parameter now without expanding the pack
4893 OldType = Expansion->getPattern();
4894 IsPackExpansion = true;
4895 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4896 NewType = getDerived().TransformType(OldType);
4898 NewType = getDerived().TransformType(OldType);
4901 if (NewType.isNull())
4904 if (IsPackExpansion)
4905 NewType = getSema().Context.getPackExpansionType(NewType,
4909 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4910 OutParamTypes.push_back(NewType);
4912 PVars->push_back(nullptr);
4917 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4918 if (ParmVarDecl *parm = (*PVars)[i])
4919 assert(parm->getFunctionScopeIndex() == i);
4926 template<typename Derived>
4928 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4929 FunctionProtoTypeLoc TL) {
4930 SmallVector<QualType, 4> ExceptionStorage;
4931 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
4932 return getDerived().TransformFunctionProtoType(
4933 TLB, TL, nullptr, 0,
4934 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4935 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4936 ExceptionStorage, Changed);
4940 template<typename Derived> template<typename Fn>
4941 QualType TreeTransform<Derived>::TransformFunctionProtoType(
4942 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4943 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
4945 // Transform the parameters and return type.
4947 // We are required to instantiate the params and return type in source order.
4948 // When the function has a trailing return type, we instantiate the
4949 // parameters before the return type, since the return type can then refer
4950 // to the parameters themselves (via decltype, sizeof, etc.).
4952 SmallVector<QualType, 4> ParamTypes;
4953 SmallVector<ParmVarDecl*, 4> ParamDecls;
4954 Sema::ExtParameterInfoBuilder ExtParamInfos;
4955 const FunctionProtoType *T = TL.getTypePtr();
4957 QualType ResultType;
4959 if (T->hasTrailingReturn()) {
4960 if (getDerived().TransformFunctionTypeParams(
4961 TL.getBeginLoc(), TL.getParams(),
4962 TL.getTypePtr()->param_type_begin(),
4963 T->getExtParameterInfosOrNull(),
4964 ParamTypes, &ParamDecls, ExtParamInfos))
4968 // C++11 [expr.prim.general]p3:
4969 // If a declaration declares a member function or member function
4970 // template of a class X, the expression this is a prvalue of type
4971 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4972 // and the end of the function-definition, member-declarator, or
4974 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4976 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4977 if (ResultType.isNull())
4982 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4983 if (ResultType.isNull())
4986 if (getDerived().TransformFunctionTypeParams(
4987 TL.getBeginLoc(), TL.getParams(),
4988 TL.getTypePtr()->param_type_begin(),
4989 T->getExtParameterInfosOrNull(),
4990 ParamTypes, &ParamDecls, ExtParamInfos))
4994 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4996 bool EPIChanged = false;
4997 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5000 // Handle extended parameter information.
5001 if (auto NewExtParamInfos =
5002 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5003 if (!EPI.ExtParameterInfos ||
5004 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5005 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5008 EPI.ExtParameterInfos = NewExtParamInfos;
5009 } else if (EPI.ExtParameterInfos) {
5011 EPI.ExtParameterInfos = nullptr;
5014 QualType Result = TL.getType();
5015 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
5016 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
5017 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
5018 if (Result.isNull())
5022 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
5023 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5024 NewTL.setLParenLoc(TL.getLParenLoc());
5025 NewTL.setRParenLoc(TL.getRParenLoc());
5026 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
5027 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5028 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5029 NewTL.setParam(i, ParamDecls[i]);
5034 template<typename Derived>
5035 bool TreeTransform<Derived>::TransformExceptionSpec(
5036 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5037 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5038 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5040 // Instantiate a dynamic noexcept expression, if any.
5041 if (ESI.Type == EST_ComputedNoexcept) {
5042 EnterExpressionEvaluationContext Unevaluated(getSema(),
5043 Sema::ConstantEvaluated);
5044 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5045 if (NoexceptExpr.isInvalid())
5048 // FIXME: This is bogus, a noexcept expression is not a condition.
5049 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
5050 if (NoexceptExpr.isInvalid())
5053 if (!NoexceptExpr.get()->isValueDependent()) {
5054 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5055 NoexceptExpr.get(), nullptr,
5056 diag::err_noexcept_needs_constant_expression,
5057 /*AllowFold*/false);
5058 if (NoexceptExpr.isInvalid())
5062 if (ESI.NoexceptExpr != NoexceptExpr.get())
5064 ESI.NoexceptExpr = NoexceptExpr.get();
5067 if (ESI.Type != EST_Dynamic)
5070 // Instantiate a dynamic exception specification's type.
5071 for (QualType T : ESI.Exceptions) {
5072 if (const PackExpansionType *PackExpansion =
5073 T->getAs<PackExpansionType>()) {
5076 // We have a pack expansion. Instantiate it.
5077 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5078 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5080 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5082 // Determine whether the set of unexpanded parameter packs can and
5085 bool Expand = false;
5086 bool RetainExpansion = false;
5087 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5088 // FIXME: Track the location of the ellipsis (and track source location
5089 // information for the types in the exception specification in general).
5090 if (getDerived().TryExpandParameterPacks(
5091 Loc, SourceRange(), Unexpanded, Expand,
5092 RetainExpansion, NumExpansions))
5096 // We can't expand this pack expansion into separate arguments yet;
5097 // just substitute into the pattern and create a new pack expansion
5099 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5100 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5104 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5105 Exceptions.push_back(U);
5109 // Substitute into the pack expansion pattern for each slice of the
5111 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5112 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5114 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5115 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5118 Exceptions.push_back(U);
5121 QualType U = getDerived().TransformType(T);
5122 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5127 Exceptions.push_back(U);
5131 ESI.Exceptions = Exceptions;
5132 if (ESI.Exceptions.empty())
5133 ESI.Type = EST_DynamicNone;
5137 template<typename Derived>
5138 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
5139 TypeLocBuilder &TLB,
5140 FunctionNoProtoTypeLoc TL) {
5141 const FunctionNoProtoType *T = TL.getTypePtr();
5142 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5143 if (ResultType.isNull())
5146 QualType Result = TL.getType();
5147 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5148 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5150 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5151 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5152 NewTL.setLParenLoc(TL.getLParenLoc());
5153 NewTL.setRParenLoc(TL.getRParenLoc());
5154 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5159 template<typename Derived> QualType
5160 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5161 UnresolvedUsingTypeLoc TL) {
5162 const UnresolvedUsingType *T = TL.getTypePtr();
5163 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5167 QualType Result = TL.getType();
5168 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5169 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
5170 if (Result.isNull())
5174 // We might get an arbitrary type spec type back. We should at
5175 // least always get a type spec type, though.
5176 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5177 NewTL.setNameLoc(TL.getNameLoc());
5182 template<typename Derived>
5183 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5184 TypedefTypeLoc TL) {
5185 const TypedefType *T = TL.getTypePtr();
5186 TypedefNameDecl *Typedef
5187 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5192 QualType Result = TL.getType();
5193 if (getDerived().AlwaysRebuild() ||
5194 Typedef != T->getDecl()) {
5195 Result = getDerived().RebuildTypedefType(Typedef);
5196 if (Result.isNull())
5200 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5201 NewTL.setNameLoc(TL.getNameLoc());
5206 template<typename Derived>
5207 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5208 TypeOfExprTypeLoc TL) {
5209 // typeof expressions are not potentially evaluated contexts
5210 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5211 Sema::ReuseLambdaContextDecl);
5213 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5217 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5221 QualType Result = TL.getType();
5222 if (getDerived().AlwaysRebuild() ||
5223 E.get() != TL.getUnderlyingExpr()) {
5224 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5225 if (Result.isNull())
5230 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5231 NewTL.setTypeofLoc(TL.getTypeofLoc());
5232 NewTL.setLParenLoc(TL.getLParenLoc());
5233 NewTL.setRParenLoc(TL.getRParenLoc());
5238 template<typename Derived>
5239 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5241 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5242 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5246 QualType Result = TL.getType();
5247 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5248 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5249 if (Result.isNull())
5253 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5254 NewTL.setTypeofLoc(TL.getTypeofLoc());
5255 NewTL.setLParenLoc(TL.getLParenLoc());
5256 NewTL.setRParenLoc(TL.getRParenLoc());
5257 NewTL.setUnderlyingTInfo(New_Under_TI);
5262 template<typename Derived>
5263 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5264 DecltypeTypeLoc TL) {
5265 const DecltypeType *T = TL.getTypePtr();
5267 // decltype expressions are not potentially evaluated contexts
5268 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5269 nullptr, /*IsDecltype=*/ true);
5271 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5275 E = getSema().ActOnDecltypeExpression(E.get());
5279 QualType Result = TL.getType();
5280 if (getDerived().AlwaysRebuild() ||
5281 E.get() != T->getUnderlyingExpr()) {
5282 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5283 if (Result.isNull())
5288 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5289 NewTL.setNameLoc(TL.getNameLoc());
5294 template<typename Derived>
5295 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5296 TypeLocBuilder &TLB,
5297 UnaryTransformTypeLoc TL) {
5298 QualType Result = TL.getType();
5299 if (Result->isDependentType()) {
5300 const UnaryTransformType *T = TL.getTypePtr();
5302 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5303 Result = getDerived().RebuildUnaryTransformType(NewBase,
5306 if (Result.isNull())
5310 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5311 NewTL.setKWLoc(TL.getKWLoc());
5312 NewTL.setParensRange(TL.getParensRange());
5313 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5317 template<typename Derived>
5318 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5320 const AutoType *T = TL.getTypePtr();
5321 QualType OldDeduced = T->getDeducedType();
5322 QualType NewDeduced;
5323 if (!OldDeduced.isNull()) {
5324 NewDeduced = getDerived().TransformType(OldDeduced);
5325 if (NewDeduced.isNull())
5329 QualType Result = TL.getType();
5330 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5331 T->isDependentType()) {
5332 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5333 if (Result.isNull())
5337 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5338 NewTL.setNameLoc(TL.getNameLoc());
5343 template<typename Derived>
5344 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5346 const RecordType *T = TL.getTypePtr();
5348 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5353 QualType Result = TL.getType();
5354 if (getDerived().AlwaysRebuild() ||
5355 Record != T->getDecl()) {
5356 Result = getDerived().RebuildRecordType(Record);
5357 if (Result.isNull())
5361 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5362 NewTL.setNameLoc(TL.getNameLoc());
5367 template<typename Derived>
5368 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5370 const EnumType *T = TL.getTypePtr();
5372 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5377 QualType Result = TL.getType();
5378 if (getDerived().AlwaysRebuild() ||
5379 Enum != T->getDecl()) {
5380 Result = getDerived().RebuildEnumType(Enum);
5381 if (Result.isNull())
5385 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5386 NewTL.setNameLoc(TL.getNameLoc());
5391 template<typename Derived>
5392 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5393 TypeLocBuilder &TLB,
5394 InjectedClassNameTypeLoc TL) {
5395 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5396 TL.getTypePtr()->getDecl());
5397 if (!D) return QualType();
5399 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5400 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5404 template<typename Derived>
5405 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5406 TypeLocBuilder &TLB,
5407 TemplateTypeParmTypeLoc TL) {
5408 return TransformTypeSpecType(TLB, TL);
5411 template<typename Derived>
5412 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5413 TypeLocBuilder &TLB,
5414 SubstTemplateTypeParmTypeLoc TL) {
5415 const SubstTemplateTypeParmType *T = TL.getTypePtr();
5417 // Substitute into the replacement type, which itself might involve something
5418 // that needs to be transformed. This only tends to occur with default
5419 // template arguments of template template parameters.
5420 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5421 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5422 if (Replacement.isNull())
5425 // Always canonicalize the replacement type.
5426 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5428 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5431 // Propagate type-source information.
5432 SubstTemplateTypeParmTypeLoc NewTL
5433 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5434 NewTL.setNameLoc(TL.getNameLoc());
5439 template<typename Derived>
5440 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5441 TypeLocBuilder &TLB,
5442 SubstTemplateTypeParmPackTypeLoc TL) {
5443 return TransformTypeSpecType(TLB, TL);
5446 template<typename Derived>
5447 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5448 TypeLocBuilder &TLB,
5449 TemplateSpecializationTypeLoc TL) {
5450 const TemplateSpecializationType *T = TL.getTypePtr();
5452 // The nested-name-specifier never matters in a TemplateSpecializationType,
5453 // because we can't have a dependent nested-name-specifier anyway.
5455 TemplateName Template
5456 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5457 TL.getTemplateNameLoc());
5458 if (Template.isNull())
5461 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5464 template<typename Derived>
5465 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5467 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5468 if (ValueType.isNull())
5471 QualType Result = TL.getType();
5472 if (getDerived().AlwaysRebuild() ||
5473 ValueType != TL.getValueLoc().getType()) {
5474 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5475 if (Result.isNull())
5479 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5480 NewTL.setKWLoc(TL.getKWLoc());
5481 NewTL.setLParenLoc(TL.getLParenLoc());
5482 NewTL.setRParenLoc(TL.getRParenLoc());
5487 template <typename Derived>
5488 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5490 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5491 if (ValueType.isNull())
5494 QualType Result = TL.getType();
5495 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5496 const PipeType *PT = Result->getAs<PipeType>();
5497 bool isReadPipe = PT->isReadOnly();
5498 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
5499 if (Result.isNull())
5503 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5504 NewTL.setKWLoc(TL.getKWLoc());
5509 /// \brief Simple iterator that traverses the template arguments in a
5510 /// container that provides a \c getArgLoc() member function.
5512 /// This iterator is intended to be used with the iterator form of
5513 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5514 template<typename ArgLocContainer>
5515 class TemplateArgumentLocContainerIterator {
5516 ArgLocContainer *Container;
5520 typedef TemplateArgumentLoc value_type;
5521 typedef TemplateArgumentLoc reference;
5522 typedef int difference_type;
5523 typedef std::input_iterator_tag iterator_category;
5526 TemplateArgumentLoc Arg;
5529 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5531 const TemplateArgumentLoc *operator->() const {
5537 TemplateArgumentLocContainerIterator() {}
5539 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5541 : Container(&Container), Index(Index) { }
5543 TemplateArgumentLocContainerIterator &operator++() {
5548 TemplateArgumentLocContainerIterator operator++(int) {
5549 TemplateArgumentLocContainerIterator Old(*this);
5554 TemplateArgumentLoc operator*() const {
5555 return Container->getArgLoc(Index);
5558 pointer operator->() const {
5559 return pointer(Container->getArgLoc(Index));
5562 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
5563 const TemplateArgumentLocContainerIterator &Y) {
5564 return X.Container == Y.Container && X.Index == Y.Index;
5567 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
5568 const TemplateArgumentLocContainerIterator &Y) {
5574 template <typename Derived>
5575 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5576 TypeLocBuilder &TLB,
5577 TemplateSpecializationTypeLoc TL,
5578 TemplateName Template) {
5579 TemplateArgumentListInfo NewTemplateArgs;
5580 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5581 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5582 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5584 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5585 ArgIterator(TL, TL.getNumArgs()),
5589 // FIXME: maybe don't rebuild if all the template arguments are the same.
5592 getDerived().RebuildTemplateSpecializationType(Template,
5593 TL.getTemplateNameLoc(),
5596 if (!Result.isNull()) {
5597 // Specializations of template template parameters are represented as
5598 // TemplateSpecializationTypes, and substitution of type alias templates
5599 // within a dependent context can transform them into
5600 // DependentTemplateSpecializationTypes.
5601 if (isa<DependentTemplateSpecializationType>(Result)) {
5602 DependentTemplateSpecializationTypeLoc NewTL
5603 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5604 NewTL.setElaboratedKeywordLoc(SourceLocation());
5605 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5606 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5607 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5608 NewTL.setLAngleLoc(TL.getLAngleLoc());
5609 NewTL.setRAngleLoc(TL.getRAngleLoc());
5610 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5611 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5615 TemplateSpecializationTypeLoc NewTL
5616 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5617 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5618 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5619 NewTL.setLAngleLoc(TL.getLAngleLoc());
5620 NewTL.setRAngleLoc(TL.getRAngleLoc());
5621 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5622 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5628 template <typename Derived>
5629 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5630 TypeLocBuilder &TLB,
5631 DependentTemplateSpecializationTypeLoc TL,
5632 TemplateName Template,
5634 TemplateArgumentListInfo NewTemplateArgs;
5635 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5636 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5637 typedef TemplateArgumentLocContainerIterator<
5638 DependentTemplateSpecializationTypeLoc> ArgIterator;
5639 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5640 ArgIterator(TL, TL.getNumArgs()),
5644 // FIXME: maybe don't rebuild if all the template arguments are the same.
5646 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5648 = getSema().Context.getDependentTemplateSpecializationType(
5649 TL.getTypePtr()->getKeyword(),
5650 DTN->getQualifier(),
5651 DTN->getIdentifier(),
5654 DependentTemplateSpecializationTypeLoc NewTL
5655 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5656 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5657 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5658 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5659 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5660 NewTL.setLAngleLoc(TL.getLAngleLoc());
5661 NewTL.setRAngleLoc(TL.getRAngleLoc());
5662 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5663 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5668 = getDerived().RebuildTemplateSpecializationType(Template,
5669 TL.getTemplateNameLoc(),
5672 if (!Result.isNull()) {
5673 /// FIXME: Wrap this in an elaborated-type-specifier?
5674 TemplateSpecializationTypeLoc NewTL
5675 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5676 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5677 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5678 NewTL.setLAngleLoc(TL.getLAngleLoc());
5679 NewTL.setRAngleLoc(TL.getRAngleLoc());
5680 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5681 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5687 template<typename Derived>
5689 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
5690 ElaboratedTypeLoc TL) {
5691 const ElaboratedType *T = TL.getTypePtr();
5693 NestedNameSpecifierLoc QualifierLoc;
5694 // NOTE: the qualifier in an ElaboratedType is optional.
5695 if (TL.getQualifierLoc()) {
5697 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5702 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5703 if (NamedT.isNull())
5706 // C++0x [dcl.type.elab]p2:
5707 // If the identifier resolves to a typedef-name or the simple-template-id
5708 // resolves to an alias template specialization, the
5709 // elaborated-type-specifier is ill-formed.
5710 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5711 if (const TemplateSpecializationType *TST =
5712 NamedT->getAs<TemplateSpecializationType>()) {
5713 TemplateName Template = TST->getTemplateName();
5714 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5715 Template.getAsTemplateDecl())) {
5716 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5717 diag::err_tag_reference_non_tag)
5718 << TAT << Sema::NTK_TypeAliasTemplate
5719 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
5720 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5725 QualType Result = TL.getType();
5726 if (getDerived().AlwaysRebuild() ||
5727 QualifierLoc != TL.getQualifierLoc() ||
5728 NamedT != T->getNamedType()) {
5729 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5731 QualifierLoc, NamedT);
5732 if (Result.isNull())
5736 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5737 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5738 NewTL.setQualifierLoc(QualifierLoc);
5742 template<typename Derived>
5743 QualType TreeTransform<Derived>::TransformAttributedType(
5744 TypeLocBuilder &TLB,
5745 AttributedTypeLoc TL) {
5746 const AttributedType *oldType = TL.getTypePtr();
5747 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5748 if (modifiedType.isNull())
5751 QualType result = TL.getType();
5753 // FIXME: dependent operand expressions?
5754 if (getDerived().AlwaysRebuild() ||
5755 modifiedType != oldType->getModifiedType()) {
5756 // TODO: this is really lame; we should really be rebuilding the
5757 // equivalent type from first principles.
5758 QualType equivalentType
5759 = getDerived().TransformType(oldType->getEquivalentType());
5760 if (equivalentType.isNull())
5763 // Check whether we can add nullability; it is only represented as
5764 // type sugar, and therefore cannot be diagnosed in any other way.
5765 if (auto nullability = oldType->getImmediateNullability()) {
5766 if (!modifiedType->canHaveNullability()) {
5767 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
5768 << DiagNullabilityKind(*nullability, false) << modifiedType;
5773 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5778 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5779 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5780 if (TL.hasAttrOperand())
5781 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5782 if (TL.hasAttrExprOperand())
5783 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5784 else if (TL.hasAttrEnumOperand())
5785 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5790 template<typename Derived>
5792 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5794 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5798 QualType Result = TL.getType();
5799 if (getDerived().AlwaysRebuild() ||
5800 Inner != TL.getInnerLoc().getType()) {
5801 Result = getDerived().RebuildParenType(Inner);
5802 if (Result.isNull())
5806 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5807 NewTL.setLParenLoc(TL.getLParenLoc());
5808 NewTL.setRParenLoc(TL.getRParenLoc());
5812 template<typename Derived>
5813 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5814 DependentNameTypeLoc TL) {
5815 const DependentNameType *T = TL.getTypePtr();
5817 NestedNameSpecifierLoc QualifierLoc
5818 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5823 = getDerived().RebuildDependentNameType(T->getKeyword(),
5824 TL.getElaboratedKeywordLoc(),
5828 if (Result.isNull())
5831 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5832 QualType NamedT = ElabT->getNamedType();
5833 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5835 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5836 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5837 NewTL.setQualifierLoc(QualifierLoc);
5839 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5840 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5841 NewTL.setQualifierLoc(QualifierLoc);
5842 NewTL.setNameLoc(TL.getNameLoc());
5847 template<typename Derived>
5848 QualType TreeTransform<Derived>::
5849 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5850 DependentTemplateSpecializationTypeLoc TL) {
5851 NestedNameSpecifierLoc QualifierLoc;
5852 if (TL.getQualifierLoc()) {
5854 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5860 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5863 template<typename Derived>
5864 QualType TreeTransform<Derived>::
5865 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5866 DependentTemplateSpecializationTypeLoc TL,
5867 NestedNameSpecifierLoc QualifierLoc) {
5868 const DependentTemplateSpecializationType *T = TL.getTypePtr();
5870 TemplateArgumentListInfo NewTemplateArgs;
5871 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5872 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5874 typedef TemplateArgumentLocContainerIterator<
5875 DependentTemplateSpecializationTypeLoc> ArgIterator;
5876 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5877 ArgIterator(TL, TL.getNumArgs()),
5882 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5885 TL.getTemplateNameLoc(),
5887 if (Result.isNull())
5890 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5891 QualType NamedT = ElabT->getNamedType();
5893 // Copy information relevant to the template specialization.
5894 TemplateSpecializationTypeLoc NamedTL
5895 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5896 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5897 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5898 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5899 NamedTL.setRAngleLoc(TL.getRAngleLoc());
5900 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5901 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5903 // Copy information relevant to the elaborated type.
5904 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5905 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5906 NewTL.setQualifierLoc(QualifierLoc);
5907 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5908 DependentTemplateSpecializationTypeLoc SpecTL
5909 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5910 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5911 SpecTL.setQualifierLoc(QualifierLoc);
5912 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5913 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5914 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5915 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5916 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5917 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5919 TemplateSpecializationTypeLoc SpecTL
5920 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5921 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5922 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5923 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5924 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5925 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5926 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5931 template<typename Derived>
5932 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5933 PackExpansionTypeLoc TL) {
5935 = getDerived().TransformType(TLB, TL.getPatternLoc());
5936 if (Pattern.isNull())
5939 QualType Result = TL.getType();
5940 if (getDerived().AlwaysRebuild() ||
5941 Pattern != TL.getPatternLoc().getType()) {
5942 Result = getDerived().RebuildPackExpansionType(Pattern,
5943 TL.getPatternLoc().getSourceRange(),
5944 TL.getEllipsisLoc(),
5945 TL.getTypePtr()->getNumExpansions());
5946 if (Result.isNull())
5950 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5951 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5955 template<typename Derived>
5957 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5958 ObjCInterfaceTypeLoc TL) {
5959 // ObjCInterfaceType is never dependent.
5960 TLB.pushFullCopy(TL);
5961 return TL.getType();
5964 template<typename Derived>
5966 TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
5967 ObjCTypeParamTypeLoc TL) {
5968 const ObjCTypeParamType *T = TL.getTypePtr();
5969 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
5970 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
5974 QualType Result = TL.getType();
5975 if (getDerived().AlwaysRebuild() ||
5976 OTP != T->getDecl()) {
5977 Result = getDerived().RebuildObjCTypeParamType(OTP,
5978 TL.getProtocolLAngleLoc(),
5979 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5980 TL.getNumProtocols()),
5981 TL.getProtocolLocs(),
5982 TL.getProtocolRAngleLoc());
5983 if (Result.isNull())
5987 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
5988 if (TL.getNumProtocols()) {
5989 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5990 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5991 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
5992 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5997 template<typename Derived>
5999 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
6000 ObjCObjectTypeLoc TL) {
6001 // Transform base type.
6002 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6003 if (BaseType.isNull())
6006 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6008 // Transform type arguments.
6009 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6010 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6011 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6012 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6013 QualType TypeArg = TypeArgInfo->getType();
6014 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6017 // We have a pack expansion. Instantiate it.
6018 const auto *PackExpansion = PackExpansionLoc.getType()
6019 ->castAs<PackExpansionType>();
6020 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6021 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6023 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6025 // Determine whether the set of unexpanded parameter packs can
6026 // and should be expanded.
6027 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6028 bool Expand = false;
6029 bool RetainExpansion = false;
6030 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6031 if (getDerived().TryExpandParameterPacks(
6032 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6033 Unexpanded, Expand, RetainExpansion, NumExpansions))
6037 // We can't expand this pack expansion into separate arguments yet;
6038 // just substitute into the pattern and create a new pack expansion
6040 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6042 TypeLocBuilder TypeArgBuilder;
6043 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6044 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6046 if (NewPatternType.isNull())
6049 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6050 NewPatternType, NumExpansions);
6051 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6052 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6053 NewTypeArgInfos.push_back(
6054 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6058 // Substitute into the pack expansion pattern for each slice of the
6060 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6061 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6063 TypeLocBuilder TypeArgBuilder;
6064 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6066 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6068 if (NewTypeArg.isNull())
6071 NewTypeArgInfos.push_back(
6072 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6078 TypeLocBuilder TypeArgBuilder;
6079 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6080 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6081 if (NewTypeArg.isNull())
6084 // If nothing changed, just keep the old TypeSourceInfo.
6085 if (NewTypeArg == TypeArg) {
6086 NewTypeArgInfos.push_back(TypeArgInfo);
6090 NewTypeArgInfos.push_back(
6091 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6095 QualType Result = TL.getType();
6096 if (getDerived().AlwaysRebuild() || AnyChanged) {
6097 // Rebuild the type.
6098 Result = getDerived().RebuildObjCObjectType(
6101 TL.getTypeArgsLAngleLoc(),
6103 TL.getTypeArgsRAngleLoc(),
6104 TL.getProtocolLAngleLoc(),
6105 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6106 TL.getNumProtocols()),
6107 TL.getProtocolLocs(),
6108 TL.getProtocolRAngleLoc());
6110 if (Result.isNull())
6114 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
6115 NewT.setHasBaseTypeAsWritten(true);
6116 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6117 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6118 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6119 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6120 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6121 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6122 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6123 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6127 template<typename Derived>
6129 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
6130 ObjCObjectPointerTypeLoc TL) {
6131 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6132 if (PointeeType.isNull())
6135 QualType Result = TL.getType();
6136 if (getDerived().AlwaysRebuild() ||
6137 PointeeType != TL.getPointeeLoc().getType()) {
6138 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6140 if (Result.isNull())
6144 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6145 NewT.setStarLoc(TL.getStarLoc());
6149 //===----------------------------------------------------------------------===//
6150 // Statement transformation
6151 //===----------------------------------------------------------------------===//
6152 template<typename Derived>
6154 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
6158 template<typename Derived>
6160 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6161 return getDerived().TransformCompoundStmt(S, false);
6164 template<typename Derived>
6166 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
6168 Sema::CompoundScopeRAII CompoundScope(getSema());
6170 bool SubStmtInvalid = false;
6171 bool SubStmtChanged = false;
6172 SmallVector<Stmt*, 8> Statements;
6173 for (auto *B : S->body()) {
6174 StmtResult Result = getDerived().TransformStmt(B);
6175 if (Result.isInvalid()) {
6176 // Immediately fail if this was a DeclStmt, since it's very
6177 // likely that this will cause problems for future statements.
6178 if (isa<DeclStmt>(B))
6181 // Otherwise, just keep processing substatements and fail later.
6182 SubStmtInvalid = true;
6186 SubStmtChanged = SubStmtChanged || Result.get() != B;
6187 Statements.push_back(Result.getAs<Stmt>());
6193 if (!getDerived().AlwaysRebuild() &&
6197 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6203 template<typename Derived>
6205 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6206 ExprResult LHS, RHS;
6208 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6209 Sema::ConstantEvaluated);
6211 // Transform the left-hand case value.
6212 LHS = getDerived().TransformExpr(S->getLHS());
6213 LHS = SemaRef.ActOnConstantExpression(LHS);
6214 if (LHS.isInvalid())
6217 // Transform the right-hand case value (for the GNU case-range extension).
6218 RHS = getDerived().TransformExpr(S->getRHS());
6219 RHS = SemaRef.ActOnConstantExpression(RHS);
6220 if (RHS.isInvalid())
6224 // Build the case statement.
6225 // Case statements are always rebuilt so that they will attached to their
6226 // transformed switch statement.
6227 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6229 S->getEllipsisLoc(),
6232 if (Case.isInvalid())
6235 // Transform the statement following the case
6236 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6237 if (SubStmt.isInvalid())
6240 // Attach the body to the case statement
6241 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6244 template<typename Derived>
6246 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6247 // Transform the statement following the default case
6248 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6249 if (SubStmt.isInvalid())
6252 // Default statements are always rebuilt
6253 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6257 template<typename Derived>
6259 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6260 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6261 if (SubStmt.isInvalid())
6264 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6270 // FIXME: Pass the real colon location in.
6271 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6272 cast<LabelDecl>(LD), SourceLocation(),
6276 template <typename Derived>
6277 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6281 switch (R->getKind()) {
6282 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6284 #define PRAGMA_SPELLING_ATTR(X) \
6286 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6287 #include "clang/Basic/AttrList.inc"
6293 template <typename Derived>
6294 StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6295 bool AttrsChanged = false;
6296 SmallVector<const Attr *, 1> Attrs;
6298 // Visit attributes and keep track if any are transformed.
6299 for (const auto *I : S->getAttrs()) {
6300 const Attr *R = getDerived().TransformAttr(I);
6301 AttrsChanged |= (I != R);
6305 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6306 if (SubStmt.isInvalid())
6309 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6312 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6316 template<typename Derived>
6318 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6319 // Transform the initialization statement
6320 StmtResult Init = getDerived().TransformStmt(S->getInit());
6321 if (Init.isInvalid())
6324 // Transform the condition
6325 Sema::ConditionResult Cond = getDerived().TransformCondition(
6326 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6327 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6328 : Sema::ConditionKind::Boolean);
6329 if (Cond.isInvalid())
6332 // If this is a constexpr if, determine which arm we should instantiate.
6333 llvm::Optional<bool> ConstexprConditionValue;
6334 if (S->isConstexpr())
6335 ConstexprConditionValue = Cond.getKnownValue();
6337 // Transform the "then" branch.
6339 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6340 Then = getDerived().TransformStmt(S->getThen());
6341 if (Then.isInvalid())
6344 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6347 // Transform the "else" branch.
6349 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6350 Else = getDerived().TransformStmt(S->getElse());
6351 if (Else.isInvalid())
6355 if (!getDerived().AlwaysRebuild() &&
6356 Init.get() == S->getInit() &&
6357 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6358 Then.get() == S->getThen() &&
6359 Else.get() == S->getElse())
6362 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6363 Init.get(), Then.get(), S->getElseLoc(),
6367 template<typename Derived>
6369 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6370 // Transform the initialization statement
6371 StmtResult Init = getDerived().TransformStmt(S->getInit());
6372 if (Init.isInvalid())
6375 // Transform the condition.
6376 Sema::ConditionResult Cond = getDerived().TransformCondition(
6377 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6378 Sema::ConditionKind::Switch);
6379 if (Cond.isInvalid())
6382 // Rebuild the switch statement.
6384 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6385 S->getInit(), Cond);
6386 if (Switch.isInvalid())
6389 // Transform the body of the switch statement.
6390 StmtResult Body = getDerived().TransformStmt(S->getBody());
6391 if (Body.isInvalid())
6394 // Complete the switch statement.
6395 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6399 template<typename Derived>
6401 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6402 // Transform the condition
6403 Sema::ConditionResult Cond = getDerived().TransformCondition(
6404 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6405 Sema::ConditionKind::Boolean);
6406 if (Cond.isInvalid())
6409 // Transform the body
6410 StmtResult Body = getDerived().TransformStmt(S->getBody());
6411 if (Body.isInvalid())
6414 if (!getDerived().AlwaysRebuild() &&
6415 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6416 Body.get() == S->getBody())
6419 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
6422 template<typename Derived>
6424 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6425 // Transform the body
6426 StmtResult Body = getDerived().TransformStmt(S->getBody());
6427 if (Body.isInvalid())
6430 // Transform the condition
6431 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6432 if (Cond.isInvalid())
6435 if (!getDerived().AlwaysRebuild() &&
6436 Cond.get() == S->getCond() &&
6437 Body.get() == S->getBody())
6440 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6441 /*FIXME:*/S->getWhileLoc(), Cond.get(),
6445 template<typename Derived>
6447 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6448 // Transform the initialization statement
6449 StmtResult Init = getDerived().TransformStmt(S->getInit());
6450 if (Init.isInvalid())
6453 // In OpenMP loop region loop control variable must be captured and be
6454 // private. Perform analysis of first part (if any).
6455 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6456 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6458 // Transform the condition
6459 Sema::ConditionResult Cond = getDerived().TransformCondition(
6460 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6461 Sema::ConditionKind::Boolean);
6462 if (Cond.isInvalid())
6465 // Transform the increment
6466 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6467 if (Inc.isInvalid())
6470 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6471 if (S->getInc() && !FullInc.get())
6474 // Transform the body
6475 StmtResult Body = getDerived().TransformStmt(S->getBody());
6476 if (Body.isInvalid())
6479 if (!getDerived().AlwaysRebuild() &&
6480 Init.get() == S->getInit() &&
6481 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6482 Inc.get() == S->getInc() &&
6483 Body.get() == S->getBody())
6486 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6487 Init.get(), Cond, FullInc,
6488 S->getRParenLoc(), Body.get());
6491 template<typename Derived>
6493 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6494 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6499 // Goto statements must always be rebuilt, to resolve the label.
6500 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6501 cast<LabelDecl>(LD));
6504 template<typename Derived>
6506 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6507 ExprResult Target = getDerived().TransformExpr(S->getTarget());
6508 if (Target.isInvalid())
6510 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6512 if (!getDerived().AlwaysRebuild() &&
6513 Target.get() == S->getTarget())
6516 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6520 template<typename Derived>
6522 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6526 template<typename Derived>
6528 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6532 template<typename Derived>
6534 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6535 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6536 /*NotCopyInit*/false);
6537 if (Result.isInvalid())
6540 // FIXME: We always rebuild the return statement because there is no way
6541 // to tell whether the return type of the function has changed.
6542 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6545 template<typename Derived>
6547 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6548 bool DeclChanged = false;
6549 SmallVector<Decl *, 4> Decls;
6550 for (auto *D : S->decls()) {
6551 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6555 if (Transformed != D)
6558 Decls.push_back(Transformed);
6561 if (!getDerived().AlwaysRebuild() && !DeclChanged)
6564 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6567 template<typename Derived>
6569 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6571 SmallVector<Expr*, 8> Constraints;
6572 SmallVector<Expr*, 8> Exprs;
6573 SmallVector<IdentifierInfo *, 4> Names;
6575 ExprResult AsmString;
6576 SmallVector<Expr*, 8> Clobbers;
6578 bool ExprsChanged = false;
6580 // Go through the outputs.
6581 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6582 Names.push_back(S->getOutputIdentifier(I));
6584 // No need to transform the constraint literal.
6585 Constraints.push_back(S->getOutputConstraintLiteral(I));
6587 // Transform the output expr.
6588 Expr *OutputExpr = S->getOutputExpr(I);
6589 ExprResult Result = getDerived().TransformExpr(OutputExpr);
6590 if (Result.isInvalid())
6593 ExprsChanged |= Result.get() != OutputExpr;
6595 Exprs.push_back(Result.get());
6598 // Go through the inputs.
6599 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6600 Names.push_back(S->getInputIdentifier(I));
6602 // No need to transform the constraint literal.
6603 Constraints.push_back(S->getInputConstraintLiteral(I));
6605 // Transform the input expr.
6606 Expr *InputExpr = S->getInputExpr(I);
6607 ExprResult Result = getDerived().TransformExpr(InputExpr);
6608 if (Result.isInvalid())
6611 ExprsChanged |= Result.get() != InputExpr;
6613 Exprs.push_back(Result.get());
6616 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6619 // Go through the clobbers.
6620 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6621 Clobbers.push_back(S->getClobberStringLiteral(I));
6623 // No need to transform the asm string literal.
6624 AsmString = S->getAsmString();
6625 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6626 S->isVolatile(), S->getNumOutputs(),
6627 S->getNumInputs(), Names.data(),
6628 Constraints, Exprs, AsmString.get(),
6629 Clobbers, S->getRParenLoc());
6632 template<typename Derived>
6634 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6635 ArrayRef<Token> AsmToks =
6636 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6638 bool HadError = false, HadChange = false;
6640 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6641 SmallVector<Expr*, 8> TransformedExprs;
6642 TransformedExprs.reserve(SrcExprs.size());
6643 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6644 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6645 if (!Result.isUsable()) {
6648 HadChange |= (Result.get() != SrcExprs[i]);
6649 TransformedExprs.push_back(Result.get());
6653 if (HadError) return StmtError();
6654 if (!HadChange && !getDerived().AlwaysRebuild())
6657 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6658 AsmToks, S->getAsmString(),
6659 S->getNumOutputs(), S->getNumInputs(),
6660 S->getAllConstraints(), S->getClobbers(),
6661 TransformedExprs, S->getEndLoc());
6664 // C++ Coroutines TS
6666 template<typename Derived>
6668 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6669 // The coroutine body should be re-formed by the caller if necessary.
6670 // FIXME: The coroutine body is always rebuilt by ActOnFinishFunctionBody
6671 return getDerived().TransformStmt(S->getBody());
6674 template<typename Derived>
6676 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6677 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6678 /*NotCopyInit*/false);
6679 if (Result.isInvalid())
6682 // Always rebuild; we don't know if this needs to be injected into a new
6683 // context or if the promise type has changed.
6684 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6687 template<typename Derived>
6689 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6690 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6691 /*NotCopyInit*/false);
6692 if (Result.isInvalid())
6695 // Always rebuild; we don't know if this needs to be injected into a new
6696 // context or if the promise type has changed.
6697 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6700 template<typename Derived>
6702 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6703 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6704 /*NotCopyInit*/false);
6705 if (Result.isInvalid())
6708 // Always rebuild; we don't know if this needs to be injected into a new
6709 // context or if the promise type has changed.
6710 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6713 // Objective-C Statements.
6715 template<typename Derived>
6717 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
6718 // Transform the body of the @try.
6719 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
6720 if (TryBody.isInvalid())
6723 // Transform the @catch statements (if present).
6724 bool AnyCatchChanged = false;
6725 SmallVector<Stmt*, 8> CatchStmts;
6726 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
6727 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
6728 if (Catch.isInvalid())
6730 if (Catch.get() != S->getCatchStmt(I))
6731 AnyCatchChanged = true;
6732 CatchStmts.push_back(Catch.get());
6735 // Transform the @finally statement (if present).
6737 if (S->getFinallyStmt()) {
6738 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6739 if (Finally.isInvalid())
6743 // If nothing changed, just retain this statement.
6744 if (!getDerived().AlwaysRebuild() &&
6745 TryBody.get() == S->getTryBody() &&
6747 Finally.get() == S->getFinallyStmt())
6750 // Build a new statement.
6751 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
6752 CatchStmts, Finally.get());
6755 template<typename Derived>
6757 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
6758 // Transform the @catch parameter, if there is one.
6759 VarDecl *Var = nullptr;
6760 if (VarDecl *FromVar = S->getCatchParamDecl()) {
6761 TypeSourceInfo *TSInfo = nullptr;
6762 if (FromVar->getTypeSourceInfo()) {
6763 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6770 T = TSInfo->getType();
6772 T = getDerived().TransformType(FromVar->getType());
6777 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6782 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
6783 if (Body.isInvalid())
6786 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
6791 template<typename Derived>
6793 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
6794 // Transform the body.
6795 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
6796 if (Body.isInvalid())
6799 // If nothing changed, just retain this statement.
6800 if (!getDerived().AlwaysRebuild() &&
6801 Body.get() == S->getFinallyBody())
6804 // Build a new statement.
6805 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
6809 template<typename Derived>
6811 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
6813 if (S->getThrowExpr()) {
6814 Operand = getDerived().TransformExpr(S->getThrowExpr());
6815 if (Operand.isInvalid())
6819 if (!getDerived().AlwaysRebuild() &&
6820 Operand.get() == S->getThrowExpr())
6823 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
6826 template<typename Derived>
6828 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
6829 ObjCAtSynchronizedStmt *S) {
6830 // Transform the object we are locking.
6831 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
6832 if (Object.isInvalid())
6835 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6837 if (Object.isInvalid())
6840 // Transform the body.
6841 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
6842 if (Body.isInvalid())
6845 // If nothing change, just retain the current statement.
6846 if (!getDerived().AlwaysRebuild() &&
6847 Object.get() == S->getSynchExpr() &&
6848 Body.get() == S->getSynchBody())
6851 // Build a new statement.
6852 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
6853 Object.get(), Body.get());
6856 template<typename Derived>
6858 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6859 ObjCAutoreleasePoolStmt *S) {
6860 // Transform the body.
6861 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6862 if (Body.isInvalid())
6865 // If nothing changed, just retain this statement.
6866 if (!getDerived().AlwaysRebuild() &&
6867 Body.get() == S->getSubStmt())
6870 // Build a new statement.
6871 return getDerived().RebuildObjCAutoreleasePoolStmt(
6872 S->getAtLoc(), Body.get());
6875 template<typename Derived>
6877 TreeTransform<Derived>::TransformObjCForCollectionStmt(
6878 ObjCForCollectionStmt *S) {
6879 // Transform the element statement.
6880 StmtResult Element = getDerived().TransformStmt(S->getElement());
6881 if (Element.isInvalid())
6884 // Transform the collection expression.
6885 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
6886 if (Collection.isInvalid())
6889 // Transform the body.
6890 StmtResult Body = getDerived().TransformStmt(S->getBody());
6891 if (Body.isInvalid())
6894 // If nothing changed, just retain this statement.
6895 if (!getDerived().AlwaysRebuild() &&
6896 Element.get() == S->getElement() &&
6897 Collection.get() == S->getCollection() &&
6898 Body.get() == S->getBody())
6901 // Build a new statement.
6902 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6909 template <typename Derived>
6910 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6911 // Transform the exception declaration, if any.
6912 VarDecl *Var = nullptr;
6913 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6915 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6919 Var = getDerived().RebuildExceptionDecl(
6920 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6921 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6922 if (!Var || Var->isInvalidDecl())
6926 // Transform the actual exception handler.
6927 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6928 if (Handler.isInvalid())
6931 if (!getDerived().AlwaysRebuild() && !Var &&
6932 Handler.get() == S->getHandlerBlock())
6935 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6938 template <typename Derived>
6939 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6940 // Transform the try block itself.
6941 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6942 if (TryBlock.isInvalid())
6945 // Transform the handlers.
6946 bool HandlerChanged = false;
6947 SmallVector<Stmt *, 8> Handlers;
6948 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6949 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6950 if (Handler.isInvalid())
6953 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6954 Handlers.push_back(Handler.getAs<Stmt>());
6957 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6961 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6965 template<typename Derived>
6967 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6968 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6969 if (Range.isInvalid())
6972 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6973 if (Begin.isInvalid())
6975 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6976 if (End.isInvalid())
6979 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6980 if (Cond.isInvalid())
6983 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
6984 if (Cond.isInvalid())
6987 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
6989 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6990 if (Inc.isInvalid())
6993 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
6995 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6996 if (LoopVar.isInvalid())
6999 StmtResult NewStmt = S;
7000 if (getDerived().AlwaysRebuild() ||
7001 Range.get() != S->getRangeStmt() ||
7002 Begin.get() != S->getBeginStmt() ||
7003 End.get() != S->getEndStmt() ||
7004 Cond.get() != S->getCond() ||
7005 Inc.get() != S->getInc() ||
7006 LoopVar.get() != S->getLoopVarStmt()) {
7007 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7009 S->getColonLoc(), Range.get(),
7010 Begin.get(), End.get(),
7012 Inc.get(), LoopVar.get(),
7014 if (NewStmt.isInvalid())
7018 StmtResult Body = getDerived().TransformStmt(S->getBody());
7019 if (Body.isInvalid())
7022 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7023 // it now so we have a new statement to attach the body to.
7024 if (Body.get() != S->getBody() && NewStmt.get() == S) {
7025 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7027 S->getColonLoc(), Range.get(),
7028 Begin.get(), End.get(),
7030 Inc.get(), LoopVar.get(),
7032 if (NewStmt.isInvalid())
7036 if (NewStmt.get() == S)
7039 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7042 template<typename Derived>
7044 TreeTransform<Derived>::TransformMSDependentExistsStmt(
7045 MSDependentExistsStmt *S) {
7046 // Transform the nested-name-specifier, if any.
7047 NestedNameSpecifierLoc QualifierLoc;
7048 if (S->getQualifierLoc()) {
7050 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7055 // Transform the declaration name.
7056 DeclarationNameInfo NameInfo = S->getNameInfo();
7057 if (NameInfo.getName()) {
7058 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7059 if (!NameInfo.getName())
7063 // Check whether anything changed.
7064 if (!getDerived().AlwaysRebuild() &&
7065 QualifierLoc == S->getQualifierLoc() &&
7066 NameInfo.getName() == S->getNameInfo().getName())
7069 // Determine whether this name exists, if we can.
7071 SS.Adopt(QualifierLoc);
7072 bool Dependent = false;
7073 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
7074 case Sema::IER_Exists:
7075 if (S->isIfExists())
7078 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7080 case Sema::IER_DoesNotExist:
7081 if (S->isIfNotExists())
7084 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7086 case Sema::IER_Dependent:
7090 case Sema::IER_Error:
7094 // We need to continue with the instantiation, so do so now.
7095 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7096 if (SubStmt.isInvalid())
7099 // If we have resolved the name, just transform to the substatement.
7103 // The name is still dependent, so build a dependent expression again.
7104 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7111 template<typename Derived>
7113 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7114 NestedNameSpecifierLoc QualifierLoc;
7115 if (E->getQualifierLoc()) {
7117 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7122 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7123 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7127 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7128 if (Base.isInvalid())
7131 return new (SemaRef.getASTContext())
7132 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7133 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7134 QualifierLoc, E->getMemberLoc());
7137 template <typename Derived>
7138 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7139 MSPropertySubscriptExpr *E) {
7140 auto BaseRes = getDerived().TransformExpr(E->getBase());
7141 if (BaseRes.isInvalid())
7143 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7144 if (IdxRes.isInvalid())
7147 if (!getDerived().AlwaysRebuild() &&
7148 BaseRes.get() == E->getBase() &&
7149 IdxRes.get() == E->getIdx())
7152 return getDerived().RebuildArraySubscriptExpr(
7153 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7156 template <typename Derived>
7157 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7158 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7159 if (TryBlock.isInvalid())
7162 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7163 if (Handler.isInvalid())
7166 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7167 Handler.get() == S->getHandler())
7170 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7171 TryBlock.get(), Handler.get());
7174 template <typename Derived>
7175 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7176 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7177 if (Block.isInvalid())
7180 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7183 template <typename Derived>
7184 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7185 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7186 if (FilterExpr.isInvalid())
7189 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7190 if (Block.isInvalid())
7193 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7197 template <typename Derived>
7198 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7199 if (isa<SEHFinallyStmt>(Handler))
7200 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7202 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7205 template<typename Derived>
7207 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7211 //===----------------------------------------------------------------------===//
7212 // OpenMP directive transformation
7213 //===----------------------------------------------------------------------===//
7214 template <typename Derived>
7215 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7216 OMPExecutableDirective *D) {
7218 // Transform the clauses
7219 llvm::SmallVector<OMPClause *, 16> TClauses;
7220 ArrayRef<OMPClause *> Clauses = D->clauses();
7221 TClauses.reserve(Clauses.size());
7222 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7225 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7226 OMPClause *Clause = getDerived().TransformOMPClause(*I);
7227 getDerived().getSema().EndOpenMPClause();
7229 TClauses.push_back(Clause);
7231 TClauses.push_back(nullptr);
7234 StmtResult AssociatedStmt;
7235 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7236 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7237 /*CurScope=*/nullptr);
7240 Sema::CompoundScopeRAII CompoundScope(getSema());
7241 Body = getDerived().TransformStmt(
7242 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7245 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7246 if (AssociatedStmt.isInvalid()) {
7250 if (TClauses.size() != Clauses.size()) {
7254 // Transform directive name for 'omp critical' directive.
7255 DeclarationNameInfo DirName;
7256 if (D->getDirectiveKind() == OMPD_critical) {
7257 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7258 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7260 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7261 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7262 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7263 } else if (D->getDirectiveKind() == OMPD_cancel) {
7264 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7267 return getDerived().RebuildOMPExecutableDirective(
7268 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7269 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7272 template <typename Derived>
7274 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7275 DeclarationNameInfo DirName;
7276 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7278 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7279 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7283 template <typename Derived>
7285 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7286 DeclarationNameInfo DirName;
7287 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7289 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7290 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7294 template <typename Derived>
7296 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7297 DeclarationNameInfo DirName;
7298 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7300 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7301 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7305 template <typename Derived>
7307 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7308 DeclarationNameInfo DirName;
7309 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7311 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7312 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7316 template <typename Derived>
7318 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7319 DeclarationNameInfo DirName;
7320 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7322 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7323 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7327 template <typename Derived>
7329 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7330 DeclarationNameInfo DirName;
7331 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7333 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7334 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7338 template <typename Derived>
7340 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7341 DeclarationNameInfo DirName;
7342 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7344 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7345 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7349 template <typename Derived>
7351 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7352 DeclarationNameInfo DirName;
7353 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7355 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7356 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7360 template <typename Derived>
7362 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7363 getDerived().getSema().StartOpenMPDSABlock(
7364 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7365 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7366 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7370 template <typename Derived>
7371 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7372 OMPParallelForDirective *D) {
7373 DeclarationNameInfo DirName;
7374 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7375 nullptr, D->getLocStart());
7376 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7377 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7381 template <typename Derived>
7382 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7383 OMPParallelForSimdDirective *D) {
7384 DeclarationNameInfo DirName;
7385 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7386 nullptr, D->getLocStart());
7387 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7388 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7392 template <typename Derived>
7393 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7394 OMPParallelSectionsDirective *D) {
7395 DeclarationNameInfo DirName;
7396 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7397 nullptr, D->getLocStart());
7398 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7399 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7403 template <typename Derived>
7405 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7406 DeclarationNameInfo DirName;
7407 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7409 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7410 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7414 template <typename Derived>
7415 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7416 OMPTaskyieldDirective *D) {
7417 DeclarationNameInfo DirName;
7418 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7420 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7421 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7425 template <typename Derived>
7427 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7428 DeclarationNameInfo DirName;
7429 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7431 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7432 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7436 template <typename Derived>
7438 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7439 DeclarationNameInfo DirName;
7440 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7442 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7443 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7447 template <typename Derived>
7448 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7449 OMPTaskgroupDirective *D) {
7450 DeclarationNameInfo DirName;
7451 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7453 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7454 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7458 template <typename Derived>
7460 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7461 DeclarationNameInfo DirName;
7462 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7464 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7465 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7469 template <typename Derived>
7471 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7472 DeclarationNameInfo DirName;
7473 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7475 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7476 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7480 template <typename Derived>
7482 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7483 DeclarationNameInfo DirName;
7484 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7486 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7487 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7491 template <typename Derived>
7493 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7494 DeclarationNameInfo DirName;
7495 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7497 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7498 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7502 template <typename Derived>
7503 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7504 OMPTargetDataDirective *D) {
7505 DeclarationNameInfo DirName;
7506 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7508 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7509 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7513 template <typename Derived>
7514 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7515 OMPTargetEnterDataDirective *D) {
7516 DeclarationNameInfo DirName;
7517 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7518 nullptr, D->getLocStart());
7519 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7520 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7524 template <typename Derived>
7525 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7526 OMPTargetExitDataDirective *D) {
7527 DeclarationNameInfo DirName;
7528 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7529 nullptr, D->getLocStart());
7530 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7531 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7535 template <typename Derived>
7536 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7537 OMPTargetParallelDirective *D) {
7538 DeclarationNameInfo DirName;
7539 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7540 nullptr, D->getLocStart());
7541 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7542 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7546 template <typename Derived>
7547 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7548 OMPTargetParallelForDirective *D) {
7549 DeclarationNameInfo DirName;
7550 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7551 nullptr, D->getLocStart());
7552 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7553 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7557 template <typename Derived>
7558 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7559 OMPTargetUpdateDirective *D) {
7560 DeclarationNameInfo DirName;
7561 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7562 nullptr, D->getLocStart());
7563 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7564 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7568 template <typename Derived>
7570 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7571 DeclarationNameInfo DirName;
7572 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7574 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7575 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7579 template <typename Derived>
7580 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7581 OMPCancellationPointDirective *D) {
7582 DeclarationNameInfo DirName;
7583 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7584 nullptr, D->getLocStart());
7585 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7586 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7590 template <typename Derived>
7592 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7593 DeclarationNameInfo DirName;
7594 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7596 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7597 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7601 template <typename Derived>
7603 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7604 DeclarationNameInfo DirName;
7605 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7607 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7608 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7612 template <typename Derived>
7613 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7614 OMPTaskLoopSimdDirective *D) {
7615 DeclarationNameInfo DirName;
7616 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7617 nullptr, D->getLocStart());
7618 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7619 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7623 template <typename Derived>
7624 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7625 OMPDistributeDirective *D) {
7626 DeclarationNameInfo DirName;
7627 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7629 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7630 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7634 template <typename Derived>
7635 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7636 OMPDistributeParallelForDirective *D) {
7637 DeclarationNameInfo DirName;
7638 getDerived().getSema().StartOpenMPDSABlock(
7639 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7640 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7641 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7645 template <typename Derived>
7647 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7648 OMPDistributeParallelForSimdDirective *D) {
7649 DeclarationNameInfo DirName;
7650 getDerived().getSema().StartOpenMPDSABlock(
7651 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7652 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7653 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7657 template <typename Derived>
7658 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7659 OMPDistributeSimdDirective *D) {
7660 DeclarationNameInfo DirName;
7661 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7662 nullptr, D->getLocStart());
7663 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7664 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7668 template <typename Derived>
7669 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7670 OMPTargetParallelForSimdDirective *D) {
7671 DeclarationNameInfo DirName;
7672 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7675 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7676 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7680 template <typename Derived>
7681 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7682 OMPTargetSimdDirective *D) {
7683 DeclarationNameInfo DirName;
7684 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7686 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7687 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7691 template <typename Derived>
7692 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
7693 OMPTeamsDistributeDirective *D) {
7694 DeclarationNameInfo DirName;
7695 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
7696 nullptr, D->getLocStart());
7697 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7698 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7702 template <typename Derived>
7703 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
7704 OMPTeamsDistributeSimdDirective *D) {
7705 DeclarationNameInfo DirName;
7706 getDerived().getSema().StartOpenMPDSABlock(
7707 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
7708 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7709 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7713 template <typename Derived>
7714 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
7715 OMPTeamsDistributeParallelForSimdDirective *D) {
7716 DeclarationNameInfo DirName;
7717 getDerived().getSema().StartOpenMPDSABlock(
7718 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7719 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7720 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7724 template <typename Derived>
7725 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
7726 OMPTeamsDistributeParallelForDirective *D) {
7727 DeclarationNameInfo DirName;
7728 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
7729 DirName, nullptr, D->getLocStart());
7730 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7731 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7735 template <typename Derived>
7736 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
7737 OMPTargetTeamsDirective *D) {
7738 DeclarationNameInfo DirName;
7739 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
7740 nullptr, D->getLocStart());
7741 auto Res = getDerived().TransformOMPExecutableDirective(D);
7742 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7746 template <typename Derived>
7747 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
7748 OMPTargetTeamsDistributeDirective *D) {
7749 DeclarationNameInfo DirName;
7750 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
7751 DirName, nullptr, D->getLocStart());
7752 auto Res = getDerived().TransformOMPExecutableDirective(D);
7753 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7757 template <typename Derived>
7759 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
7760 OMPTargetTeamsDistributeParallelForDirective *D) {
7761 DeclarationNameInfo DirName;
7762 getDerived().getSema().StartOpenMPDSABlock(
7763 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
7765 auto Res = getDerived().TransformOMPExecutableDirective(D);
7766 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7770 template <typename Derived>
7771 StmtResult TreeTransform<Derived>::
7772 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
7773 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
7774 DeclarationNameInfo DirName;
7775 getDerived().getSema().StartOpenMPDSABlock(
7776 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
7778 auto Res = getDerived().TransformOMPExecutableDirective(D);
7779 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7783 template <typename Derived>
7785 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
7786 OMPTargetTeamsDistributeSimdDirective *D) {
7787 DeclarationNameInfo DirName;
7788 getDerived().getSema().StartOpenMPDSABlock(
7789 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
7790 auto Res = getDerived().TransformOMPExecutableDirective(D);
7791 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7796 //===----------------------------------------------------------------------===//
7797 // OpenMP clause transformation
7798 //===----------------------------------------------------------------------===//
7799 template <typename Derived>
7800 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
7801 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7802 if (Cond.isInvalid())
7804 return getDerived().RebuildOMPIfClause(
7805 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7806 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
7809 template <typename Derived>
7810 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7811 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7812 if (Cond.isInvalid())
7814 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7815 C->getLParenLoc(), C->getLocEnd());
7818 template <typename Derived>
7820 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7821 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7822 if (NumThreads.isInvalid())
7824 return getDerived().RebuildOMPNumThreadsClause(
7825 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7828 template <typename Derived>
7830 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7831 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7834 return getDerived().RebuildOMPSafelenClause(
7835 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7838 template <typename Derived>
7840 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7841 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7844 return getDerived().RebuildOMPSimdlenClause(
7845 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7848 template <typename Derived>
7850 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7851 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7854 return getDerived().RebuildOMPCollapseClause(
7855 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7858 template <typename Derived>
7860 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
7861 return getDerived().RebuildOMPDefaultClause(
7862 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7863 C->getLParenLoc(), C->getLocEnd());
7866 template <typename Derived>
7868 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
7869 return getDerived().RebuildOMPProcBindClause(
7870 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7871 C->getLParenLoc(), C->getLocEnd());
7874 template <typename Derived>
7876 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7877 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7880 return getDerived().RebuildOMPScheduleClause(
7881 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
7882 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7883 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
7884 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7887 template <typename Derived>
7889 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7891 if (auto *Num = C->getNumForLoops()) {
7892 E = getDerived().TransformExpr(Num);
7896 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7897 C->getLParenLoc(), E.get());
7900 template <typename Derived>
7902 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7903 // No need to rebuild this clause, no template-dependent parameters.
7907 template <typename Derived>
7909 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7910 // No need to rebuild this clause, no template-dependent parameters.
7914 template <typename Derived>
7916 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7917 // No need to rebuild this clause, no template-dependent parameters.
7921 template <typename Derived>
7922 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7923 // No need to rebuild this clause, no template-dependent parameters.
7927 template <typename Derived>
7928 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7929 // No need to rebuild this clause, no template-dependent parameters.
7933 template <typename Derived>
7935 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7936 // No need to rebuild this clause, no template-dependent parameters.
7940 template <typename Derived>
7942 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7943 // No need to rebuild this clause, no template-dependent parameters.
7947 template <typename Derived>
7949 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7950 // No need to rebuild this clause, no template-dependent parameters.
7954 template <typename Derived>
7956 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7957 // No need to rebuild this clause, no template-dependent parameters.
7961 template <typename Derived>
7962 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7963 // No need to rebuild this clause, no template-dependent parameters.
7967 template <typename Derived>
7969 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7970 // No need to rebuild this clause, no template-dependent parameters.
7974 template <typename Derived>
7976 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
7977 llvm::SmallVector<Expr *, 16> Vars;
7978 Vars.reserve(C->varlist_size());
7979 for (auto *VE : C->varlists()) {
7980 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7981 if (EVar.isInvalid())
7983 Vars.push_back(EVar.get());
7985 return getDerived().RebuildOMPPrivateClause(
7986 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7989 template <typename Derived>
7990 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7991 OMPFirstprivateClause *C) {
7992 llvm::SmallVector<Expr *, 16> Vars;
7993 Vars.reserve(C->varlist_size());
7994 for (auto *VE : C->varlists()) {
7995 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7996 if (EVar.isInvalid())
7998 Vars.push_back(EVar.get());
8000 return getDerived().RebuildOMPFirstprivateClause(
8001 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8004 template <typename Derived>
8006 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8007 llvm::SmallVector<Expr *, 16> Vars;
8008 Vars.reserve(C->varlist_size());
8009 for (auto *VE : C->varlists()) {
8010 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8011 if (EVar.isInvalid())
8013 Vars.push_back(EVar.get());
8015 return getDerived().RebuildOMPLastprivateClause(
8016 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8019 template <typename Derived>
8021 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8022 llvm::SmallVector<Expr *, 16> Vars;
8023 Vars.reserve(C->varlist_size());
8024 for (auto *VE : C->varlists()) {
8025 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8026 if (EVar.isInvalid())
8028 Vars.push_back(EVar.get());
8030 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8031 C->getLParenLoc(), C->getLocEnd());
8034 template <typename Derived>
8036 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8037 llvm::SmallVector<Expr *, 16> Vars;
8038 Vars.reserve(C->varlist_size());
8039 for (auto *VE : C->varlists()) {
8040 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8041 if (EVar.isInvalid())
8043 Vars.push_back(EVar.get());
8045 CXXScopeSpec ReductionIdScopeSpec;
8046 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8048 DeclarationNameInfo NameInfo = C->getNameInfo();
8049 if (NameInfo.getName()) {
8050 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8051 if (!NameInfo.getName())
8054 // Build a list of all UDR decls with the same names ranged by the Scopes.
8055 // The Scope boundary is a duplication of the previous decl.
8056 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8057 for (auto *E : C->reduction_ops()) {
8058 // Transform all the decls.
8060 auto *ULE = cast<UnresolvedLookupExpr>(E);
8061 UnresolvedSet<8> Decls;
8062 for (auto *D : ULE->decls()) {
8064 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8065 Decls.addDecl(InstD, InstD->getAccess());
8067 UnresolvedReductions.push_back(
8068 UnresolvedLookupExpr::Create(
8069 SemaRef.Context, /*NamingClass=*/nullptr,
8070 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8071 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8072 Decls.begin(), Decls.end()));
8074 UnresolvedReductions.push_back(nullptr);
8076 return getDerived().RebuildOMPReductionClause(
8077 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8078 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8081 template <typename Derived>
8083 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8084 llvm::SmallVector<Expr *, 16> Vars;
8085 Vars.reserve(C->varlist_size());
8086 for (auto *VE : C->varlists()) {
8087 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8088 if (EVar.isInvalid())
8090 Vars.push_back(EVar.get());
8092 ExprResult Step = getDerived().TransformExpr(C->getStep());
8093 if (Step.isInvalid())
8095 return getDerived().RebuildOMPLinearClause(
8096 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8097 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
8100 template <typename Derived>
8102 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8103 llvm::SmallVector<Expr *, 16> Vars;
8104 Vars.reserve(C->varlist_size());
8105 for (auto *VE : C->varlists()) {
8106 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8107 if (EVar.isInvalid())
8109 Vars.push_back(EVar.get());
8111 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8112 if (Alignment.isInvalid())
8114 return getDerived().RebuildOMPAlignedClause(
8115 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8116 C->getColonLoc(), C->getLocEnd());
8119 template <typename Derived>
8121 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8122 llvm::SmallVector<Expr *, 16> Vars;
8123 Vars.reserve(C->varlist_size());
8124 for (auto *VE : C->varlists()) {
8125 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8126 if (EVar.isInvalid())
8128 Vars.push_back(EVar.get());
8130 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8131 C->getLParenLoc(), C->getLocEnd());
8134 template <typename Derived>
8136 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8137 llvm::SmallVector<Expr *, 16> Vars;
8138 Vars.reserve(C->varlist_size());
8139 for (auto *VE : C->varlists()) {
8140 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8141 if (EVar.isInvalid())
8143 Vars.push_back(EVar.get());
8145 return getDerived().RebuildOMPCopyprivateClause(
8146 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8149 template <typename Derived>
8150 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8151 llvm::SmallVector<Expr *, 16> Vars;
8152 Vars.reserve(C->varlist_size());
8153 for (auto *VE : C->varlists()) {
8154 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8155 if (EVar.isInvalid())
8157 Vars.push_back(EVar.get());
8159 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8160 C->getLParenLoc(), C->getLocEnd());
8163 template <typename Derived>
8165 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8166 llvm::SmallVector<Expr *, 16> Vars;
8167 Vars.reserve(C->varlist_size());
8168 for (auto *VE : C->varlists()) {
8169 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8170 if (EVar.isInvalid())
8172 Vars.push_back(EVar.get());
8174 return getDerived().RebuildOMPDependClause(
8175 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8176 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8179 template <typename Derived>
8181 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8182 ExprResult E = getDerived().TransformExpr(C->getDevice());
8185 return getDerived().RebuildOMPDeviceClause(
8186 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8189 template <typename Derived>
8190 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8191 llvm::SmallVector<Expr *, 16> Vars;
8192 Vars.reserve(C->varlist_size());
8193 for (auto *VE : C->varlists()) {
8194 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8195 if (EVar.isInvalid())
8197 Vars.push_back(EVar.get());
8199 return getDerived().RebuildOMPMapClause(
8200 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8201 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8202 C->getLParenLoc(), C->getLocEnd());
8205 template <typename Derived>
8207 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8208 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8211 return getDerived().RebuildOMPNumTeamsClause(
8212 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8215 template <typename Derived>
8217 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8218 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8221 return getDerived().RebuildOMPThreadLimitClause(
8222 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8225 template <typename Derived>
8227 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8228 ExprResult E = getDerived().TransformExpr(C->getPriority());
8231 return getDerived().RebuildOMPPriorityClause(
8232 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8235 template <typename Derived>
8237 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8238 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8241 return getDerived().RebuildOMPGrainsizeClause(
8242 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8245 template <typename Derived>
8247 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8248 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8251 return getDerived().RebuildOMPNumTasksClause(
8252 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8255 template <typename Derived>
8256 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8257 ExprResult E = getDerived().TransformExpr(C->getHint());
8260 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8261 C->getLParenLoc(), C->getLocEnd());
8264 template <typename Derived>
8265 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8266 OMPDistScheduleClause *C) {
8267 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8270 return getDerived().RebuildOMPDistScheduleClause(
8271 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8272 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8275 template <typename Derived>
8277 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8281 template <typename Derived>
8282 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8283 llvm::SmallVector<Expr *, 16> Vars;
8284 Vars.reserve(C->varlist_size());
8285 for (auto *VE : C->varlists()) {
8286 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8287 if (EVar.isInvalid())
8289 Vars.push_back(EVar.get());
8291 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8292 C->getLParenLoc(), C->getLocEnd());
8295 template <typename Derived>
8296 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8297 llvm::SmallVector<Expr *, 16> Vars;
8298 Vars.reserve(C->varlist_size());
8299 for (auto *VE : C->varlists()) {
8300 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8301 if (EVar.isInvalid())
8303 Vars.push_back(EVar.get());
8305 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8306 C->getLParenLoc(), C->getLocEnd());
8309 template <typename Derived>
8310 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8311 OMPUseDevicePtrClause *C) {
8312 llvm::SmallVector<Expr *, 16> Vars;
8313 Vars.reserve(C->varlist_size());
8314 for (auto *VE : C->varlists()) {
8315 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8316 if (EVar.isInvalid())
8318 Vars.push_back(EVar.get());
8320 return getDerived().RebuildOMPUseDevicePtrClause(
8321 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8324 template <typename Derived>
8326 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8327 llvm::SmallVector<Expr *, 16> Vars;
8328 Vars.reserve(C->varlist_size());
8329 for (auto *VE : C->varlists()) {
8330 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8331 if (EVar.isInvalid())
8333 Vars.push_back(EVar.get());
8335 return getDerived().RebuildOMPIsDevicePtrClause(
8336 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8339 //===----------------------------------------------------------------------===//
8340 // Expression transformation
8341 //===----------------------------------------------------------------------===//
8342 template<typename Derived>
8344 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
8345 if (!E->isTypeDependent())
8348 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8352 template<typename Derived>
8354 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
8355 NestedNameSpecifierLoc QualifierLoc;
8356 if (E->getQualifierLoc()) {
8358 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8364 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8369 DeclarationNameInfo NameInfo = E->getNameInfo();
8370 if (NameInfo.getName()) {
8371 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8372 if (!NameInfo.getName())
8376 if (!getDerived().AlwaysRebuild() &&
8377 QualifierLoc == E->getQualifierLoc() &&
8378 ND == E->getDecl() &&
8379 NameInfo.getName() == E->getDecl()->getDeclName() &&
8380 !E->hasExplicitTemplateArgs()) {
8382 // Mark it referenced in the new context regardless.
8383 // FIXME: this is a bit instantiation-specific.
8384 SemaRef.MarkDeclRefReferenced(E);
8389 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
8390 if (E->hasExplicitTemplateArgs()) {
8391 TemplateArgs = &TransArgs;
8392 TransArgs.setLAngleLoc(E->getLAngleLoc());
8393 TransArgs.setRAngleLoc(E->getRAngleLoc());
8394 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8395 E->getNumTemplateArgs(),
8400 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
8404 template<typename Derived>
8406 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
8410 template<typename Derived>
8412 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
8416 template<typename Derived>
8418 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
8422 template<typename Derived>
8424 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
8428 template<typename Derived>
8430 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
8434 template<typename Derived>
8436 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
8437 if (FunctionDecl *FD = E->getDirectCallee())
8438 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
8439 return SemaRef.MaybeBindToTemporary(E);
8442 template<typename Derived>
8444 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8445 ExprResult ControllingExpr =
8446 getDerived().TransformExpr(E->getControllingExpr());
8447 if (ControllingExpr.isInvalid())
8450 SmallVector<Expr *, 4> AssocExprs;
8451 SmallVector<TypeSourceInfo *, 4> AssocTypes;
8452 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8453 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8455 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8458 AssocTypes.push_back(AssocType);
8460 AssocTypes.push_back(nullptr);
8463 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8464 if (AssocExpr.isInvalid())
8466 AssocExprs.push_back(AssocExpr.get());
8469 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8472 ControllingExpr.get(),
8477 template<typename Derived>
8479 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
8480 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8481 if (SubExpr.isInvalid())
8484 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8487 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
8491 /// \brief The operand of a unary address-of operator has special rules: it's
8492 /// allowed to refer to a non-static member of a class even if there's no 'this'
8493 /// object available.
8494 template<typename Derived>
8496 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8497 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
8498 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
8500 return getDerived().TransformExpr(E);
8503 template<typename Derived>
8505 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
8507 if (E->getOpcode() == UO_AddrOf)
8508 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8510 SubExpr = TransformExpr(E->getSubExpr());
8511 if (SubExpr.isInvalid())
8514 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8517 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8522 template<typename Derived>
8524 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8525 // Transform the type.
8526 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8530 // Transform all of the components into components similar to what the
8532 // FIXME: It would be slightly more efficient in the non-dependent case to
8533 // just map FieldDecls, rather than requiring the rebuilder to look for
8534 // the fields again. However, __builtin_offsetof is rare enough in
8535 // template code that we don't care.
8536 bool ExprChanged = false;
8537 typedef Sema::OffsetOfComponent Component;
8538 SmallVector<Component, 4> Components;
8539 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8540 const OffsetOfNode &ON = E->getComponent(I);
8542 Comp.isBrackets = true;
8543 Comp.LocStart = ON.getSourceRange().getBegin();
8544 Comp.LocEnd = ON.getSourceRange().getEnd();
8545 switch (ON.getKind()) {
8546 case OffsetOfNode::Array: {
8547 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
8548 ExprResult Index = getDerived().TransformExpr(FromIndex);
8549 if (Index.isInvalid())
8552 ExprChanged = ExprChanged || Index.get() != FromIndex;
8553 Comp.isBrackets = true;
8554 Comp.U.E = Index.get();
8558 case OffsetOfNode::Field:
8559 case OffsetOfNode::Identifier:
8560 Comp.isBrackets = false;
8561 Comp.U.IdentInfo = ON.getFieldName();
8562 if (!Comp.U.IdentInfo)
8567 case OffsetOfNode::Base:
8568 // Will be recomputed during the rebuild.
8572 Components.push_back(Comp);
8575 // If nothing changed, retain the existing expression.
8576 if (!getDerived().AlwaysRebuild() &&
8577 Type == E->getTypeSourceInfo() &&
8581 // Build a new offsetof expression.
8582 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
8583 Components, E->getRParenLoc());
8586 template<typename Derived>
8588 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
8589 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
8590 "opaque value expression requires transformation");
8594 template<typename Derived>
8596 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8600 template<typename Derived>
8602 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
8603 // Rebuild the syntactic form. The original syntactic form has
8604 // opaque-value expressions in it, so strip those away and rebuild
8605 // the result. This is a really awful way of doing this, but the
8606 // better solution (rebuilding the semantic expressions and
8607 // rebinding OVEs as necessary) doesn't work; we'd need
8608 // TreeTransform to not strip away implicit conversions.
8609 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8610 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
8611 if (result.isInvalid()) return ExprError();
8613 // If that gives us a pseudo-object result back, the pseudo-object
8614 // expression must have been an lvalue-to-rvalue conversion which we
8616 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
8617 result = SemaRef.checkPseudoObjectRValue(result.get());
8622 template<typename Derived>
8624 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8625 UnaryExprOrTypeTraitExpr *E) {
8626 if (E->isArgumentType()) {
8627 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
8629 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8633 if (!getDerived().AlwaysRebuild() && OldT == NewT)
8636 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8638 E->getSourceRange());
8641 // C++0x [expr.sizeof]p1:
8642 // The operand is either an expression, which is an unevaluated operand
8644 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8645 Sema::ReuseLambdaContextDecl);
8647 // Try to recover if we have something like sizeof(T::X) where X is a type.
8648 // Notably, there must be *exactly* one set of parens if X is a type.
8649 TypeSourceInfo *RecoveryTSI = nullptr;
8651 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8653 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8654 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8655 PE, DRE, false, &RecoveryTSI);
8657 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8660 return getDerived().RebuildUnaryExprOrTypeTrait(
8661 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8662 } else if (SubExpr.isInvalid())
8665 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
8668 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8669 E->getOperatorLoc(),
8671 E->getSourceRange());
8674 template<typename Derived>
8676 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
8677 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8678 if (LHS.isInvalid())
8681 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8682 if (RHS.isInvalid())
8686 if (!getDerived().AlwaysRebuild() &&
8687 LHS.get() == E->getLHS() &&
8688 RHS.get() == E->getRHS())
8691 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
8692 /*FIXME:*/E->getLHS()->getLocStart(),
8694 E->getRBracketLoc());
8697 template <typename Derived>
8699 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8700 ExprResult Base = getDerived().TransformExpr(E->getBase());
8701 if (Base.isInvalid())
8704 ExprResult LowerBound;
8705 if (E->getLowerBound()) {
8706 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8707 if (LowerBound.isInvalid())
8712 if (E->getLength()) {
8713 Length = getDerived().TransformExpr(E->getLength());
8714 if (Length.isInvalid())
8718 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8719 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8722 return getDerived().RebuildOMPArraySectionExpr(
8723 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8724 Length.get(), E->getRBracketLoc());
8727 template<typename Derived>
8729 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
8730 // Transform the callee.
8731 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8732 if (Callee.isInvalid())
8735 // Transform arguments.
8736 bool ArgChanged = false;
8737 SmallVector<Expr*, 8> Args;
8738 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8742 if (!getDerived().AlwaysRebuild() &&
8743 Callee.get() == E->getCallee() &&
8745 return SemaRef.MaybeBindToTemporary(E);
8747 // FIXME: Wrong source location information for the '('.
8748 SourceLocation FakeLParenLoc
8749 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8750 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
8755 template<typename Derived>
8757 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
8758 ExprResult Base = getDerived().TransformExpr(E->getBase());
8759 if (Base.isInvalid())
8762 NestedNameSpecifierLoc QualifierLoc;
8763 if (E->hasQualifier()) {
8765 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8770 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8773 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8774 E->getMemberDecl()));
8778 NamedDecl *FoundDecl = E->getFoundDecl();
8779 if (FoundDecl == E->getMemberDecl()) {
8782 FoundDecl = cast_or_null<NamedDecl>(
8783 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8788 if (!getDerived().AlwaysRebuild() &&
8789 Base.get() == E->getBase() &&
8790 QualifierLoc == E->getQualifierLoc() &&
8791 Member == E->getMemberDecl() &&
8792 FoundDecl == E->getFoundDecl() &&
8793 !E->hasExplicitTemplateArgs()) {
8795 // Mark it referenced in the new context regardless.
8796 // FIXME: this is a bit instantiation-specific.
8797 SemaRef.MarkMemberReferenced(E);
8802 TemplateArgumentListInfo TransArgs;
8803 if (E->hasExplicitTemplateArgs()) {
8804 TransArgs.setLAngleLoc(E->getLAngleLoc());
8805 TransArgs.setRAngleLoc(E->getRAngleLoc());
8806 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8807 E->getNumTemplateArgs(),
8812 // FIXME: Bogus source location for the operator
8813 SourceLocation FakeOperatorLoc =
8814 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
8816 // FIXME: to do this check properly, we will need to preserve the
8817 // first-qualifier-in-scope here, just in case we had a dependent
8818 // base (and therefore couldn't do the check) and a
8819 // nested-name-qualifier (and therefore could do the lookup).
8820 NamedDecl *FirstQualifierInScope = nullptr;
8822 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
8826 E->getMemberNameInfo(),
8829 (E->hasExplicitTemplateArgs()
8830 ? &TransArgs : nullptr),
8831 FirstQualifierInScope);
8834 template<typename Derived>
8836 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
8837 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8838 if (LHS.isInvalid())
8841 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8842 if (RHS.isInvalid())
8845 if (!getDerived().AlwaysRebuild() &&
8846 LHS.get() == E->getLHS() &&
8847 RHS.get() == E->getRHS())
8850 Sema::FPContractStateRAII FPContractState(getSema());
8851 getSema().FPFeatures.fp_contract = E->isFPContractable();
8853 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
8854 LHS.get(), RHS.get());
8857 template<typename Derived>
8859 TreeTransform<Derived>::TransformCompoundAssignOperator(
8860 CompoundAssignOperator *E) {
8861 return getDerived().TransformBinaryOperator(E);
8864 template<typename Derived>
8865 ExprResult TreeTransform<Derived>::
8866 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8867 // Just rebuild the common and RHS expressions and see whether we
8870 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8871 if (commonExpr.isInvalid())
8874 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8875 if (rhs.isInvalid())
8878 if (!getDerived().AlwaysRebuild() &&
8879 commonExpr.get() == e->getCommon() &&
8880 rhs.get() == e->getFalseExpr())
8883 return getDerived().RebuildConditionalOperator(commonExpr.get(),
8884 e->getQuestionLoc(),
8890 template<typename Derived>
8892 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
8893 ExprResult Cond = getDerived().TransformExpr(E->getCond());
8894 if (Cond.isInvalid())
8897 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8898 if (LHS.isInvalid())
8901 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8902 if (RHS.isInvalid())
8905 if (!getDerived().AlwaysRebuild() &&
8906 Cond.get() == E->getCond() &&
8907 LHS.get() == E->getLHS() &&
8908 RHS.get() == E->getRHS())
8911 return getDerived().RebuildConditionalOperator(Cond.get(),
8912 E->getQuestionLoc(),
8918 template<typename Derived>
8920 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
8921 // Implicit casts are eliminated during transformation, since they
8922 // will be recomputed by semantic analysis after transformation.
8923 return getDerived().TransformExpr(E->getSubExprAsWritten());
8926 template<typename Derived>
8928 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
8929 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8934 = getDerived().TransformExpr(E->getSubExprAsWritten());
8935 if (SubExpr.isInvalid())
8938 if (!getDerived().AlwaysRebuild() &&
8939 Type == E->getTypeInfoAsWritten() &&
8940 SubExpr.get() == E->getSubExpr())
8943 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
8949 template<typename Derived>
8951 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
8952 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8953 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8957 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
8958 if (Init.isInvalid())
8961 if (!getDerived().AlwaysRebuild() &&
8963 Init.get() == E->getInitializer())
8964 return SemaRef.MaybeBindToTemporary(E);
8966 // Note: the expression type doesn't necessarily match the
8967 // type-as-written, but that's okay, because it should always be
8968 // derivable from the initializer.
8970 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
8971 /*FIXME:*/E->getInitializer()->getLocEnd(),
8975 template<typename Derived>
8977 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
8978 ExprResult Base = getDerived().TransformExpr(E->getBase());
8979 if (Base.isInvalid())
8982 if (!getDerived().AlwaysRebuild() &&
8983 Base.get() == E->getBase())
8986 // FIXME: Bad source location
8987 SourceLocation FakeOperatorLoc =
8988 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
8989 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
8990 E->getAccessorLoc(),
8994 template<typename Derived>
8996 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
8997 if (InitListExpr *Syntactic = E->getSyntacticForm())
9000 bool InitChanged = false;
9002 SmallVector<Expr*, 4> Inits;
9003 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
9004 Inits, &InitChanged))
9007 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9008 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9009 // in some cases. We can't reuse it in general, because the syntactic and
9010 // semantic forms are linked, and we can't know that semantic form will
9011 // match even if the syntactic form does.
9014 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
9015 E->getRBraceLoc(), E->getType());
9018 template<typename Derived>
9020 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
9023 // transform the initializer value
9024 ExprResult Init = getDerived().TransformExpr(E->getInit());
9025 if (Init.isInvalid())
9028 // transform the designators.
9029 SmallVector<Expr*, 4> ArrayExprs;
9030 bool ExprChanged = false;
9031 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9032 if (D.isFieldDesignator()) {
9033 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9037 FieldDecl *Field = cast_or_null<FieldDecl>(
9038 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9039 if (Field != D.getField())
9040 // Rebuild the expression when the transformed FieldDecl is
9041 // different to the already assigned FieldDecl.
9044 // Ensure that the designator expression is rebuilt when there isn't
9045 // a resolved FieldDecl in the designator as we don't want to assign
9046 // a FieldDecl to a pattern designator that will be instantiated again.
9052 if (D.isArrayDesignator()) {
9053 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
9054 if (Index.isInvalid())
9057 Desig.AddDesignator(
9058 Designator::getArray(Index.get(), D.getLBracketLoc()));
9060 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
9061 ArrayExprs.push_back(Index.get());
9065 assert(D.isArrayRangeDesignator() && "New kind of designator?");
9067 = getDerived().TransformExpr(E->getArrayRangeStart(D));
9068 if (Start.isInvalid())
9071 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
9072 if (End.isInvalid())
9075 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
9078 D.getEllipsisLoc()));
9080 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9081 End.get() != E->getArrayRangeEnd(D);
9083 ArrayExprs.push_back(Start.get());
9084 ArrayExprs.push_back(End.get());
9087 if (!getDerived().AlwaysRebuild() &&
9088 Init.get() == E->getInit() &&
9092 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
9093 E->getEqualOrColonLoc(),
9094 E->usesGNUSyntax(), Init.get());
9097 // Seems that if TransformInitListExpr() only works on the syntactic form of an
9098 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9099 template<typename Derived>
9101 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9102 DesignatedInitUpdateExpr *E) {
9103 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9108 template<typename Derived>
9110 TreeTransform<Derived>::TransformNoInitExpr(
9112 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9116 template<typename Derived>
9118 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9119 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9123 template<typename Derived>
9125 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9126 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9130 template<typename Derived>
9132 TreeTransform<Derived>::TransformImplicitValueInitExpr(
9133 ImplicitValueInitExpr *E) {
9134 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
9136 // FIXME: Will we ever have proper type location here? Will we actually
9137 // need to transform the type?
9138 QualType T = getDerived().TransformType(E->getType());
9142 if (!getDerived().AlwaysRebuild() &&
9146 return getDerived().RebuildImplicitValueInitExpr(T);
9149 template<typename Derived>
9151 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
9152 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9156 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9157 if (SubExpr.isInvalid())
9160 if (!getDerived().AlwaysRebuild() &&
9161 TInfo == E->getWrittenTypeInfo() &&
9162 SubExpr.get() == E->getSubExpr())
9165 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
9166 TInfo, E->getRParenLoc());
9169 template<typename Derived>
9171 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
9172 bool ArgumentChanged = false;
9173 SmallVector<Expr*, 4> Inits;
9174 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9178 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
9183 /// \brief Transform an address-of-label expression.
9185 /// By default, the transformation of an address-of-label expression always
9186 /// rebuilds the expression, so that the label identifier can be resolved to
9187 /// the corresponding label statement by semantic analysis.
9188 template<typename Derived>
9190 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
9191 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9196 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
9197 cast<LabelDecl>(LD));
9200 template<typename Derived>
9202 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
9203 SemaRef.ActOnStartStmtExpr();
9205 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
9206 if (SubStmt.isInvalid()) {
9207 SemaRef.ActOnStmtExprError();
9211 if (!getDerived().AlwaysRebuild() &&
9212 SubStmt.get() == E->getSubStmt()) {
9213 // Calling this an 'error' is unintuitive, but it does the right thing.
9214 SemaRef.ActOnStmtExprError();
9215 return SemaRef.MaybeBindToTemporary(E);
9218 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
9223 template<typename Derived>
9225 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
9226 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9227 if (Cond.isInvalid())
9230 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9231 if (LHS.isInvalid())
9234 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9235 if (RHS.isInvalid())
9238 if (!getDerived().AlwaysRebuild() &&
9239 Cond.get() == E->getCond() &&
9240 LHS.get() == E->getLHS() &&
9241 RHS.get() == E->getRHS())
9244 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
9245 Cond.get(), LHS.get(), RHS.get(),
9249 template<typename Derived>
9251 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
9255 template<typename Derived>
9257 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
9258 switch (E->getOperator()) {
9262 case OO_Array_Delete:
9263 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
9266 // This is a call to an object's operator().
9267 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9269 // Transform the object itself.
9270 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
9271 if (Object.isInvalid())
9274 // FIXME: Poor location information
9275 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9276 static_cast<Expr *>(Object.get())->getLocEnd());
9278 // Transform the call arguments.
9279 SmallVector<Expr*, 8> Args;
9280 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
9284 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
9289 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9291 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9292 #include "clang/Basic/OperatorKinds.def"
9297 case OO_Conditional:
9298 llvm_unreachable("conditional operator is not actually overloadable");
9301 case NUM_OVERLOADED_OPERATORS:
9302 llvm_unreachable("not an overloaded operator?");
9305 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9306 if (Callee.isInvalid())
9310 if (E->getOperator() == OO_Amp)
9311 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9313 First = getDerived().TransformExpr(E->getArg(0));
9314 if (First.isInvalid())
9318 if (E->getNumArgs() == 2) {
9319 Second = getDerived().TransformExpr(E->getArg(1));
9320 if (Second.isInvalid())
9324 if (!getDerived().AlwaysRebuild() &&
9325 Callee.get() == E->getCallee() &&
9326 First.get() == E->getArg(0) &&
9327 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
9328 return SemaRef.MaybeBindToTemporary(E);
9330 Sema::FPContractStateRAII FPContractState(getSema());
9331 getSema().FPFeatures.fp_contract = E->isFPContractable();
9333 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9334 E->getOperatorLoc(),
9340 template<typename Derived>
9342 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9343 return getDerived().TransformCallExpr(E);
9346 template<typename Derived>
9348 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9349 // Transform the callee.
9350 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9351 if (Callee.isInvalid())
9354 // Transform exec config.
9355 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9359 // Transform arguments.
9360 bool ArgChanged = false;
9361 SmallVector<Expr*, 8> Args;
9362 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9366 if (!getDerived().AlwaysRebuild() &&
9367 Callee.get() == E->getCallee() &&
9369 return SemaRef.MaybeBindToTemporary(E);
9371 // FIXME: Wrong source location information for the '('.
9372 SourceLocation FakeLParenLoc
9373 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9374 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9376 E->getRParenLoc(), EC.get());
9379 template<typename Derived>
9381 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
9382 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9387 = getDerived().TransformExpr(E->getSubExprAsWritten());
9388 if (SubExpr.isInvalid())
9391 if (!getDerived().AlwaysRebuild() &&
9392 Type == E->getTypeInfoAsWritten() &&
9393 SubExpr.get() == E->getSubExpr())
9395 return getDerived().RebuildCXXNamedCastExpr(
9396 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9397 Type, E->getAngleBrackets().getEnd(),
9398 // FIXME. this should be '(' location
9399 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
9402 template<typename Derived>
9404 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9405 return getDerived().TransformCXXNamedCastExpr(E);
9408 template<typename Derived>
9410 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9411 return getDerived().TransformCXXNamedCastExpr(E);
9414 template<typename Derived>
9416 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
9417 CXXReinterpretCastExpr *E) {
9418 return getDerived().TransformCXXNamedCastExpr(E);
9421 template<typename Derived>
9423 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9424 return getDerived().TransformCXXNamedCastExpr(E);
9427 template<typename Derived>
9429 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
9430 CXXFunctionalCastExpr *E) {
9431 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9436 = getDerived().TransformExpr(E->getSubExprAsWritten());
9437 if (SubExpr.isInvalid())
9440 if (!getDerived().AlwaysRebuild() &&
9441 Type == E->getTypeInfoAsWritten() &&
9442 SubExpr.get() == E->getSubExpr())
9445 return getDerived().RebuildCXXFunctionalCastExpr(Type,
9451 template<typename Derived>
9453 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
9454 if (E->isTypeOperand()) {
9455 TypeSourceInfo *TInfo
9456 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9460 if (!getDerived().AlwaysRebuild() &&
9461 TInfo == E->getTypeOperandSourceInfo())
9464 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9470 // We don't know whether the subexpression is potentially evaluated until
9471 // after we perform semantic analysis. We speculatively assume it is
9472 // unevaluated; it will get fixed later if the subexpression is in fact
9473 // potentially evaluated.
9474 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9475 Sema::ReuseLambdaContextDecl);
9477 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9478 if (SubExpr.isInvalid())
9481 if (!getDerived().AlwaysRebuild() &&
9482 SubExpr.get() == E->getExprOperand())
9485 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9491 template<typename Derived>
9493 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9494 if (E->isTypeOperand()) {
9495 TypeSourceInfo *TInfo
9496 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9500 if (!getDerived().AlwaysRebuild() &&
9501 TInfo == E->getTypeOperandSourceInfo())
9504 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9510 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9512 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9513 if (SubExpr.isInvalid())
9516 if (!getDerived().AlwaysRebuild() &&
9517 SubExpr.get() == E->getExprOperand())
9520 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9526 template<typename Derived>
9528 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
9532 template<typename Derived>
9534 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
9535 CXXNullPtrLiteralExpr *E) {
9539 template<typename Derived>
9541 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
9542 QualType T = getSema().getCurrentThisType();
9544 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9545 // Make sure that we capture 'this'.
9546 getSema().CheckCXXThisCapture(E->getLocStart());
9550 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
9553 template<typename Derived>
9555 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
9556 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9557 if (SubExpr.isInvalid())
9560 if (!getDerived().AlwaysRebuild() &&
9561 SubExpr.get() == E->getSubExpr())
9564 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9565 E->isThrownVariableInScope());
9568 template<typename Derived>
9570 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
9572 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9577 if (!getDerived().AlwaysRebuild() &&
9578 Param == E->getParam())
9581 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
9584 template<typename Derived>
9586 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9588 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9593 if (!getDerived().AlwaysRebuild() && Field == E->getField())
9596 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9599 template<typename Derived>
9601 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9602 CXXScalarValueInitExpr *E) {
9603 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9607 if (!getDerived().AlwaysRebuild() &&
9608 T == E->getTypeSourceInfo())
9611 return getDerived().RebuildCXXScalarValueInitExpr(T,
9612 /*FIXME:*/T->getTypeLoc().getEndLoc(),
9616 template<typename Derived>
9618 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
9619 // Transform the type that we're allocating
9620 TypeSourceInfo *AllocTypeInfo
9621 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9625 // Transform the size of the array we're allocating (if any).
9626 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
9627 if (ArraySize.isInvalid())
9630 // Transform the placement arguments (if any).
9631 bool ArgumentChanged = false;
9632 SmallVector<Expr*, 8> PlacementArgs;
9633 if (getDerived().TransformExprs(E->getPlacementArgs(),
9634 E->getNumPlacementArgs(), true,
9635 PlacementArgs, &ArgumentChanged))
9638 // Transform the initializer (if any).
9639 Expr *OldInit = E->getInitializer();
9642 NewInit = getDerived().TransformInitializer(OldInit, true);
9643 if (NewInit.isInvalid())
9646 // Transform new operator and delete operator.
9647 FunctionDecl *OperatorNew = nullptr;
9648 if (E->getOperatorNew()) {
9649 OperatorNew = cast_or_null<FunctionDecl>(
9650 getDerived().TransformDecl(E->getLocStart(),
9651 E->getOperatorNew()));
9656 FunctionDecl *OperatorDelete = nullptr;
9657 if (E->getOperatorDelete()) {
9658 OperatorDelete = cast_or_null<FunctionDecl>(
9659 getDerived().TransformDecl(E->getLocStart(),
9660 E->getOperatorDelete()));
9661 if (!OperatorDelete)
9665 if (!getDerived().AlwaysRebuild() &&
9666 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
9667 ArraySize.get() == E->getArraySize() &&
9668 NewInit.get() == OldInit &&
9669 OperatorNew == E->getOperatorNew() &&
9670 OperatorDelete == E->getOperatorDelete() &&
9672 // Mark any declarations we need as referenced.
9673 // FIXME: instantiation-specific.
9675 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
9677 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9679 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
9680 QualType ElementType
9681 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9682 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9683 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9684 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
9685 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
9693 QualType AllocType = AllocTypeInfo->getType();
9694 if (!ArraySize.get()) {
9695 // If no array size was specified, but the new expression was
9696 // instantiated with an array type (e.g., "new T" where T is
9697 // instantiated with "int[4]"), extract the outer bound from the
9698 // array type as our array size. We do this with constant and
9699 // dependently-sized array types.
9700 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9703 } else if (const ConstantArrayType *ConsArrayT
9704 = dyn_cast<ConstantArrayType>(ArrayT)) {
9705 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9706 SemaRef.Context.getSizeType(),
9707 /*FIXME:*/ E->getLocStart());
9708 AllocType = ConsArrayT->getElementType();
9709 } else if (const DependentSizedArrayType *DepArrayT
9710 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9711 if (DepArrayT->getSizeExpr()) {
9712 ArraySize = DepArrayT->getSizeExpr();
9713 AllocType = DepArrayT->getElementType();
9718 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9720 /*FIXME:*/E->getLocStart(),
9722 /*FIXME:*/E->getLocStart(),
9723 E->getTypeIdParens(),
9727 E->getDirectInitRange(),
9731 template<typename Derived>
9733 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
9734 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
9735 if (Operand.isInvalid())
9738 // Transform the delete operator, if known.
9739 FunctionDecl *OperatorDelete = nullptr;
9740 if (E->getOperatorDelete()) {
9741 OperatorDelete = cast_or_null<FunctionDecl>(
9742 getDerived().TransformDecl(E->getLocStart(),
9743 E->getOperatorDelete()));
9744 if (!OperatorDelete)
9748 if (!getDerived().AlwaysRebuild() &&
9749 Operand.get() == E->getArgument() &&
9750 OperatorDelete == E->getOperatorDelete()) {
9751 // Mark any declarations we need as referenced.
9752 // FIXME: instantiation-specific.
9754 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9756 if (!E->getArgument()->isTypeDependent()) {
9757 QualType Destroyed = SemaRef.Context.getBaseElementType(
9758 E->getDestroyedType());
9759 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9760 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
9761 SemaRef.MarkFunctionReferenced(E->getLocStart(),
9762 SemaRef.LookupDestructor(Record));
9769 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9770 E->isGlobalDelete(),
9775 template<typename Derived>
9777 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
9778 CXXPseudoDestructorExpr *E) {
9779 ExprResult Base = getDerived().TransformExpr(E->getBase());
9780 if (Base.isInvalid())
9783 ParsedType ObjectTypePtr;
9784 bool MayBePseudoDestructor = false;
9785 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
9786 E->getOperatorLoc(),
9787 E->isArrow()? tok::arrow : tok::period,
9789 MayBePseudoDestructor);
9790 if (Base.isInvalid())
9793 QualType ObjectType = ObjectTypePtr.get();
9794 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9797 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9802 SS.Adopt(QualifierLoc);
9804 PseudoDestructorTypeStorage Destroyed;
9805 if (E->getDestroyedTypeInfo()) {
9806 TypeSourceInfo *DestroyedTypeInfo
9807 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
9808 ObjectType, nullptr, SS);
9809 if (!DestroyedTypeInfo)
9811 Destroyed = DestroyedTypeInfo;
9812 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
9813 // We aren't likely to be able to resolve the identifier down to a type
9814 // now anyway, so just retain the identifier.
9815 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9816 E->getDestroyedTypeLoc());
9818 // Look for a destructor known with the given name.
9819 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
9820 *E->getDestroyedTypeIdentifier(),
9821 E->getDestroyedTypeLoc(),
9829 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9830 E->getDestroyedTypeLoc());
9833 TypeSourceInfo *ScopeTypeInfo = nullptr;
9834 if (E->getScopeTypeInfo()) {
9835 CXXScopeSpec EmptySS;
9836 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
9837 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
9842 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
9843 E->getOperatorLoc(),
9847 E->getColonColonLoc(),
9852 template <typename Derived>
9853 bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
9856 // Transform all the decls.
9857 bool AllEmptyPacks = true;
9858 for (auto *OldD : Old->decls()) {
9859 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
9861 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9862 // This can happen because of dependent hiding.
9863 if (isa<UsingShadowDecl>(OldD))
9871 // Expand using pack declarations.
9872 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
9873 ArrayRef<NamedDecl*> Decls = SingleDecl;
9874 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
9875 Decls = UPD->expansions();
9877 // Expand using declarations.
9878 for (auto *D : Decls) {
9879 if (auto *UD = dyn_cast<UsingDecl>(D)) {
9880 for (auto *SD : UD->shadows())
9887 AllEmptyPacks &= Decls.empty();
9890 // C++ [temp.res]/8.4.2:
9891 // The program is ill-formed, no diagnostic required, if [...] lookup for
9892 // a name in the template definition found a using-declaration, but the
9893 // lookup in the corresponding scope in the instantiation odoes not find
9894 // any declarations because the using-declaration was a pack expansion and
9895 // the corresponding pack is empty
9896 if (AllEmptyPacks && !RequiresADL) {
9897 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
9898 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
9902 // Resolve a kind, but don't do any further analysis. If it's
9903 // ambiguous, the callee needs to deal with it.
9908 template<typename Derived>
9910 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
9911 UnresolvedLookupExpr *Old) {
9912 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9913 Sema::LookupOrdinaryName);
9915 // Transform the declaration set.
9916 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
9919 // Rebuild the nested-name qualifier, if present.
9921 if (Old->getQualifierLoc()) {
9922 NestedNameSpecifierLoc QualifierLoc
9923 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9927 SS.Adopt(QualifierLoc);
9930 if (Old->getNamingClass()) {
9931 CXXRecordDecl *NamingClass
9932 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9934 Old->getNamingClass()));
9940 R.setNamingClass(NamingClass);
9943 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9945 // If we have neither explicit template arguments, nor the template keyword,
9946 // it's a normal declaration name or member reference.
9947 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9948 NamedDecl *D = R.getAsSingle<NamedDecl>();
9949 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9950 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9951 // give a good diagnostic.
9952 if (D && D->isCXXInstanceMember()) {
9953 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9954 /*TemplateArgs=*/nullptr,
9958 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9961 // If we have template arguments, rebuild them, then rebuild the
9962 // templateid expression.
9963 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
9964 if (Old->hasExplicitTemplateArgs() &&
9965 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9966 Old->getNumTemplateArgs(),
9972 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
9973 Old->requiresADL(), &TransArgs);
9976 template<typename Derived>
9978 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9979 bool ArgChanged = false;
9980 SmallVector<TypeSourceInfo *, 4> Args;
9981 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9982 TypeSourceInfo *From = E->getArg(I);
9983 TypeLoc FromTL = From->getTypeLoc();
9984 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
9986 TLB.reserve(FromTL.getFullDataSize());
9987 QualType To = getDerived().TransformType(TLB, FromTL);
9991 if (To == From->getType())
9992 Args.push_back(From);
9994 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10002 // We have a pack expansion. Instantiate it.
10003 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
10004 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10005 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10006 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
10008 // Determine whether the set of unexpanded parameter packs can and should
10010 bool Expand = true;
10011 bool RetainExpansion = false;
10012 Optional<unsigned> OrigNumExpansions =
10013 ExpansionTL.getTypePtr()->getNumExpansions();
10014 Optional<unsigned> NumExpansions = OrigNumExpansions;
10015 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10016 PatternTL.getSourceRange(),
10018 Expand, RetainExpansion,
10020 return ExprError();
10023 // The transform has determined that we should perform a simple
10024 // transformation on the pack expansion, producing another pack
10026 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10028 TypeLocBuilder TLB;
10029 TLB.reserve(From->getTypeLoc().getFullDataSize());
10031 QualType To = getDerived().TransformType(TLB, PatternTL);
10033 return ExprError();
10035 To = getDerived().RebuildPackExpansionType(To,
10036 PatternTL.getSourceRange(),
10037 ExpansionTL.getEllipsisLoc(),
10040 return ExprError();
10042 PackExpansionTypeLoc ToExpansionTL
10043 = TLB.push<PackExpansionTypeLoc>(To);
10044 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10045 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10049 // Expand the pack expansion by substituting for each argument in the
10051 for (unsigned I = 0; I != *NumExpansions; ++I) {
10052 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10053 TypeLocBuilder TLB;
10054 TLB.reserve(PatternTL.getFullDataSize());
10055 QualType To = getDerived().TransformType(TLB, PatternTL);
10057 return ExprError();
10059 if (To->containsUnexpandedParameterPack()) {
10060 To = getDerived().RebuildPackExpansionType(To,
10061 PatternTL.getSourceRange(),
10062 ExpansionTL.getEllipsisLoc(),
10065 return ExprError();
10067 PackExpansionTypeLoc ToExpansionTL
10068 = TLB.push<PackExpansionTypeLoc>(To);
10069 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10072 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10075 if (!RetainExpansion)
10078 // If we're supposed to retain a pack expansion, do so by temporarily
10079 // forgetting the partially-substituted parameter pack.
10080 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10082 TypeLocBuilder TLB;
10083 TLB.reserve(From->getTypeLoc().getFullDataSize());
10085 QualType To = getDerived().TransformType(TLB, PatternTL);
10087 return ExprError();
10089 To = getDerived().RebuildPackExpansionType(To,
10090 PatternTL.getSourceRange(),
10091 ExpansionTL.getEllipsisLoc(),
10094 return ExprError();
10096 PackExpansionTypeLoc ToExpansionTL
10097 = TLB.push<PackExpansionTypeLoc>(To);
10098 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10099 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10102 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10105 return getDerived().RebuildTypeTrait(E->getTrait(),
10111 template<typename Derived>
10113 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10114 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10116 return ExprError();
10118 if (!getDerived().AlwaysRebuild() &&
10119 T == E->getQueriedTypeSourceInfo())
10122 ExprResult SubExpr;
10124 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10125 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10126 if (SubExpr.isInvalid())
10127 return ExprError();
10129 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
10133 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10140 template<typename Derived>
10142 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10143 ExprResult SubExpr;
10145 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10146 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10147 if (SubExpr.isInvalid())
10148 return ExprError();
10150 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
10154 return getDerived().RebuildExpressionTrait(
10155 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10158 template <typename Derived>
10159 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10160 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10161 TypeSourceInfo **RecoveryTSI) {
10162 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10163 DRE, AddrTaken, RecoveryTSI);
10165 // Propagate both errors and recovered types, which return ExprEmpty.
10166 if (!NewDRE.isUsable())
10169 // We got an expr, wrap it up in parens.
10170 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10172 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10176 template <typename Derived>
10177 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10178 DependentScopeDeclRefExpr *E) {
10179 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10183 template<typename Derived>
10185 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10186 DependentScopeDeclRefExpr *E,
10187 bool IsAddressOfOperand,
10188 TypeSourceInfo **RecoveryTSI) {
10189 assert(E->getQualifierLoc());
10190 NestedNameSpecifierLoc QualifierLoc
10191 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10193 return ExprError();
10194 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10196 // TODO: If this is a conversion-function-id, verify that the
10197 // destination type name (if present) resolves the same way after
10198 // instantiation as it did in the local scope.
10200 DeclarationNameInfo NameInfo
10201 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10202 if (!NameInfo.getName())
10203 return ExprError();
10205 if (!E->hasExplicitTemplateArgs()) {
10206 if (!getDerived().AlwaysRebuild() &&
10207 QualifierLoc == E->getQualifierLoc() &&
10208 // Note: it is sufficient to compare the Name component of NameInfo:
10209 // if name has not changed, DNLoc has not changed either.
10210 NameInfo.getName() == E->getDeclName())
10213 return getDerived().RebuildDependentScopeDeclRefExpr(
10214 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10215 IsAddressOfOperand, RecoveryTSI);
10218 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10219 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10220 E->getNumTemplateArgs(),
10222 return ExprError();
10224 return getDerived().RebuildDependentScopeDeclRefExpr(
10225 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10229 template<typename Derived>
10231 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
10232 // CXXConstructExprs other than for list-initialization and
10233 // CXXTemporaryObjectExpr are always implicit, so when we have
10234 // a 1-argument construction we just transform that argument.
10235 if ((E->getNumArgs() == 1 ||
10236 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
10237 (!getDerived().DropCallArgument(E->getArg(0))) &&
10238 !E->isListInitialization())
10239 return getDerived().TransformExpr(E->getArg(0));
10241 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10243 QualType T = getDerived().TransformType(E->getType());
10245 return ExprError();
10247 CXXConstructorDecl *Constructor
10248 = cast_or_null<CXXConstructorDecl>(
10249 getDerived().TransformDecl(E->getLocStart(),
10250 E->getConstructor()));
10252 return ExprError();
10254 bool ArgumentChanged = false;
10255 SmallVector<Expr*, 8> Args;
10256 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10258 return ExprError();
10260 if (!getDerived().AlwaysRebuild() &&
10261 T == E->getType() &&
10262 Constructor == E->getConstructor() &&
10263 !ArgumentChanged) {
10264 // Mark the constructor as referenced.
10265 // FIXME: Instantiation-specific
10266 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10270 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
10272 E->isElidable(), Args,
10273 E->hadMultipleCandidates(),
10274 E->isListInitialization(),
10275 E->isStdInitListInitialization(),
10276 E->requiresZeroInitialization(),
10277 E->getConstructionKind(),
10278 E->getParenOrBraceRange());
10281 template<typename Derived>
10282 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10283 CXXInheritedCtorInitExpr *E) {
10284 QualType T = getDerived().TransformType(E->getType());
10286 return ExprError();
10288 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10289 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10291 return ExprError();
10293 if (!getDerived().AlwaysRebuild() &&
10294 T == E->getType() &&
10295 Constructor == E->getConstructor()) {
10296 // Mark the constructor as referenced.
10297 // FIXME: Instantiation-specific
10298 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10302 return getDerived().RebuildCXXInheritedCtorInitExpr(
10303 T, E->getLocation(), Constructor,
10304 E->constructsVBase(), E->inheritedFromVBase());
10307 /// \brief Transform a C++ temporary-binding expression.
10309 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10310 /// transform the subexpression and return that.
10311 template<typename Derived>
10313 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
10314 return getDerived().TransformExpr(E->getSubExpr());
10317 /// \brief Transform a C++ expression that contains cleanups that should
10318 /// be run after the expression is evaluated.
10320 /// Since ExprWithCleanups nodes are implicitly generated, we
10321 /// just transform the subexpression and return that.
10322 template<typename Derived>
10324 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
10325 return getDerived().TransformExpr(E->getSubExpr());
10328 template<typename Derived>
10330 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
10331 CXXTemporaryObjectExpr *E) {
10332 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10334 return ExprError();
10336 CXXConstructorDecl *Constructor
10337 = cast_or_null<CXXConstructorDecl>(
10338 getDerived().TransformDecl(E->getLocStart(),
10339 E->getConstructor()));
10341 return ExprError();
10343 bool ArgumentChanged = false;
10344 SmallVector<Expr*, 8> Args;
10345 Args.reserve(E->getNumArgs());
10346 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10348 return ExprError();
10350 if (!getDerived().AlwaysRebuild() &&
10351 T == E->getTypeSourceInfo() &&
10352 Constructor == E->getConstructor() &&
10353 !ArgumentChanged) {
10354 // FIXME: Instantiation-specific
10355 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10356 return SemaRef.MaybeBindToTemporary(E);
10359 // FIXME: Pass in E->isListInitialization().
10360 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10361 /*FIXME:*/T->getTypeLoc().getEndLoc(),
10366 template<typename Derived>
10368 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
10369 // Transform any init-capture expressions before entering the scope of the
10370 // lambda body, because they are not semantically within that scope.
10371 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
10372 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10373 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
10374 E->explicit_capture_begin());
10375 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10376 CEnd = E->capture_end();
10378 if (!E->isInitCapture(C))
10380 EnterExpressionEvaluationContext EEEC(getSema(),
10381 Sema::PotentiallyEvaluated);
10382 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10383 C->getCapturedVar()->getInit(),
10384 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
10386 if (NewExprInitResult.isInvalid())
10387 return ExprError();
10388 Expr *NewExprInit = NewExprInitResult.get();
10390 VarDecl *OldVD = C->getCapturedVar();
10391 QualType NewInitCaptureType =
10392 getSema().buildLambdaInitCaptureInitialization(
10393 C->getLocation(), OldVD->getType()->isReferenceType(),
10394 OldVD->getIdentifier(),
10395 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
10396 NewExprInitResult = NewExprInit;
10397 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10398 std::make_pair(NewExprInitResult, NewInitCaptureType);
10401 // Transform the template parameters, and add them to the current
10402 // instantiation scope. The null case is handled correctly.
10403 auto TPL = getDerived().TransformTemplateParameterList(
10404 E->getTemplateParameterList());
10406 // Transform the type of the original lambda's call operator.
10407 // The transformation MUST be done in the CurrentInstantiationScope since
10408 // it introduces a mapping of the original to the newly created
10409 // transformed parameters.
10410 TypeSourceInfo *NewCallOpTSI = nullptr;
10412 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10413 FunctionProtoTypeLoc OldCallOpFPTL =
10414 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
10416 TypeLocBuilder NewCallOpTLBuilder;
10417 SmallVector<QualType, 4> ExceptionStorage;
10418 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
10419 QualType NewCallOpType = TransformFunctionProtoType(
10420 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
10421 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10422 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10423 ExceptionStorage, Changed);
10425 if (NewCallOpType.isNull())
10426 return ExprError();
10427 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10431 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10432 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10433 LSI->GLTemplateParameterList = TPL;
10435 // Create the local class that will describe the lambda.
10436 CXXRecordDecl *Class
10437 = getSema().createLambdaClosureType(E->getIntroducerRange(),
10439 /*KnownDependent=*/false,
10440 E->getCaptureDefault());
10441 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10443 // Build the call operator.
10444 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10445 Class, E->getIntroducerRange(), NewCallOpTSI,
10446 E->getCallOperator()->getLocEnd(),
10447 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10448 E->getCallOperator()->isConstexpr());
10450 LSI->CallOperator = NewCallOperator;
10452 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10453 I != NumParams; ++I) {
10454 auto *P = NewCallOperator->getParamDecl(I);
10455 if (P->hasUninstantiatedDefaultArg()) {
10456 EnterExpressionEvaluationContext Eval(
10457 getSema(), Sema::PotentiallyEvaluatedIfUsed, P);
10458 ExprResult R = getDerived().TransformExpr(
10459 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10460 P->setDefaultArg(R.get());
10464 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
10465 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
10467 // Introduce the context of the call operator.
10468 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
10469 /*NewThisContext*/false);
10471 // Enter the scope of the lambda.
10472 getSema().buildLambdaScope(LSI, NewCallOperator,
10473 E->getIntroducerRange(),
10474 E->getCaptureDefault(),
10475 E->getCaptureDefaultLoc(),
10476 E->hasExplicitParameters(),
10477 E->hasExplicitResultType(),
10480 bool Invalid = false;
10482 // Transform captures.
10483 bool FinishedExplicitCaptures = false;
10484 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10485 CEnd = E->capture_end();
10487 // When we hit the first implicit capture, tell Sema that we've finished
10488 // the list of explicit captures.
10489 if (!FinishedExplicitCaptures && C->isImplicit()) {
10490 getSema().finishLambdaExplicitCaptures(LSI);
10491 FinishedExplicitCaptures = true;
10494 // Capturing 'this' is trivial.
10495 if (C->capturesThis()) {
10496 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10497 /*BuildAndDiagnose*/ true, nullptr,
10498 C->getCaptureKind() == LCK_StarThis);
10501 // Captured expression will be recaptured during captured variables
10503 if (C->capturesVLAType())
10506 // Rebuild init-captures, including the implied field declaration.
10507 if (E->isInitCapture(C)) {
10508 InitCaptureInfoTy InitExprTypePair =
10509 InitCaptureExprsAndTypes[C - E->capture_begin()];
10510 ExprResult Init = InitExprTypePair.first;
10511 QualType InitQualType = InitExprTypePair.second;
10512 if (Init.isInvalid() || InitQualType.isNull()) {
10516 VarDecl *OldVD = C->getCapturedVar();
10517 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
10518 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10519 OldVD->getInitStyle(), Init.get());
10523 getDerived().transformedLocalDecl(OldVD, NewVD);
10525 getSema().buildInitCaptureField(LSI, NewVD);
10529 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10531 // Determine the capture kind for Sema.
10532 Sema::TryCaptureKind Kind
10533 = C->isImplicit()? Sema::TryCapture_Implicit
10534 : C->getCaptureKind() == LCK_ByCopy
10535 ? Sema::TryCapture_ExplicitByVal
10536 : Sema::TryCapture_ExplicitByRef;
10537 SourceLocation EllipsisLoc;
10538 if (C->isPackExpansion()) {
10539 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10540 bool ShouldExpand = false;
10541 bool RetainExpansion = false;
10542 Optional<unsigned> NumExpansions;
10543 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10546 ShouldExpand, RetainExpansion,
10552 if (ShouldExpand) {
10553 // The transform has determined that we should perform an expansion;
10554 // transform and capture each of the arguments.
10555 // expansion of the pattern. Do so.
10556 VarDecl *Pack = C->getCapturedVar();
10557 for (unsigned I = 0; I != *NumExpansions; ++I) {
10558 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10559 VarDecl *CapturedVar
10560 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10562 if (!CapturedVar) {
10567 // Capture the transformed variable.
10568 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10571 // FIXME: Retain a pack expansion if RetainExpansion is true.
10576 EllipsisLoc = C->getEllipsisLoc();
10579 // Transform the captured variable.
10580 VarDecl *CapturedVar
10581 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10582 C->getCapturedVar()));
10583 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
10588 // Capture the transformed variable.
10589 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10592 if (!FinishedExplicitCaptures)
10593 getSema().finishLambdaExplicitCaptures(LSI);
10595 // Enter a new evaluation context to insulate the lambda from any
10596 // cleanups from the enclosing full-expression.
10597 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
10599 // Instantiate the body of the lambda expression.
10601 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10603 // ActOnLambda* will pop the function scope for us.
10604 FuncScopeCleanup.disable();
10606 if (Body.isInvalid()) {
10607 SavedContext.pop();
10608 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
10609 /*IsInstantiation=*/true);
10610 return ExprError();
10613 // Copy the LSI before ActOnFinishFunctionBody removes it.
10614 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10615 // the call operator.
10616 auto LSICopy = *LSI;
10617 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10618 /*IsInstantiation*/ true);
10619 SavedContext.pop();
10621 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10625 template<typename Derived>
10627 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
10628 CXXUnresolvedConstructExpr *E) {
10629 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10631 return ExprError();
10633 bool ArgumentChanged = false;
10634 SmallVector<Expr*, 8> Args;
10635 Args.reserve(E->arg_size());
10636 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
10638 return ExprError();
10640 if (!getDerived().AlwaysRebuild() &&
10641 T == E->getTypeSourceInfo() &&
10645 // FIXME: we're faking the locations of the commas
10646 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
10649 E->getRParenLoc());
10652 template<typename Derived>
10654 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
10655 CXXDependentScopeMemberExpr *E) {
10656 // Transform the base of the expression.
10657 ExprResult Base((Expr*) nullptr);
10660 QualType ObjectType;
10661 if (!E->isImplicitAccess()) {
10662 OldBase = E->getBase();
10663 Base = getDerived().TransformExpr(OldBase);
10664 if (Base.isInvalid())
10665 return ExprError();
10667 // Start the member reference and compute the object's type.
10668 ParsedType ObjectTy;
10669 bool MayBePseudoDestructor = false;
10670 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10671 E->getOperatorLoc(),
10672 E->isArrow()? tok::arrow : tok::period,
10674 MayBePseudoDestructor);
10675 if (Base.isInvalid())
10676 return ExprError();
10678 ObjectType = ObjectTy.get();
10679 BaseType = ((Expr*) Base.get())->getType();
10682 BaseType = getDerived().TransformType(E->getBaseType());
10683 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10686 // Transform the first part of the nested-name-specifier that qualifies
10687 // the member name.
10688 NamedDecl *FirstQualifierInScope
10689 = getDerived().TransformFirstQualifierInScope(
10690 E->getFirstQualifierFoundInScope(),
10691 E->getQualifierLoc().getBeginLoc());
10693 NestedNameSpecifierLoc QualifierLoc;
10694 if (E->getQualifier()) {
10696 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10698 FirstQualifierInScope);
10700 return ExprError();
10703 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10705 // TODO: If this is a conversion-function-id, verify that the
10706 // destination type name (if present) resolves the same way after
10707 // instantiation as it did in the local scope.
10709 DeclarationNameInfo NameInfo
10710 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
10711 if (!NameInfo.getName())
10712 return ExprError();
10714 if (!E->hasExplicitTemplateArgs()) {
10715 // This is a reference to a member without an explicitly-specified
10716 // template argument list. Optimize for this common case.
10717 if (!getDerived().AlwaysRebuild() &&
10718 Base.get() == OldBase &&
10719 BaseType == E->getBaseType() &&
10720 QualifierLoc == E->getQualifierLoc() &&
10721 NameInfo.getName() == E->getMember() &&
10722 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
10725 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10728 E->getOperatorLoc(),
10731 FirstQualifierInScope,
10733 /*TemplateArgs*/nullptr);
10736 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10737 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10738 E->getNumTemplateArgs(),
10740 return ExprError();
10742 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10745 E->getOperatorLoc(),
10748 FirstQualifierInScope,
10753 template<typename Derived>
10755 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
10756 // Transform the base of the expression.
10757 ExprResult Base((Expr*) nullptr);
10759 if (!Old->isImplicitAccess()) {
10760 Base = getDerived().TransformExpr(Old->getBase());
10761 if (Base.isInvalid())
10762 return ExprError();
10763 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
10765 if (Base.isInvalid())
10766 return ExprError();
10767 BaseType = Base.get()->getType();
10769 BaseType = getDerived().TransformType(Old->getBaseType());
10772 NestedNameSpecifierLoc QualifierLoc;
10773 if (Old->getQualifierLoc()) {
10775 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10777 return ExprError();
10780 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10782 LookupResult R(SemaRef, Old->getMemberNameInfo(),
10783 Sema::LookupOrdinaryName);
10785 // Transform the declaration set.
10786 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
10787 return ExprError();
10789 // Determine the naming class.
10790 if (Old->getNamingClass()) {
10791 CXXRecordDecl *NamingClass
10792 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10793 Old->getMemberLoc(),
10794 Old->getNamingClass()));
10796 return ExprError();
10798 R.setNamingClass(NamingClass);
10801 TemplateArgumentListInfo TransArgs;
10802 if (Old->hasExplicitTemplateArgs()) {
10803 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10804 TransArgs.setRAngleLoc(Old->getRAngleLoc());
10805 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10806 Old->getNumTemplateArgs(),
10808 return ExprError();
10811 // FIXME: to do this check properly, we will need to preserve the
10812 // first-qualifier-in-scope here, just in case we had a dependent
10813 // base (and therefore couldn't do the check) and a
10814 // nested-name-qualifier (and therefore could do the lookup).
10815 NamedDecl *FirstQualifierInScope = nullptr;
10817 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
10819 Old->getOperatorLoc(),
10823 FirstQualifierInScope,
10825 (Old->hasExplicitTemplateArgs()
10826 ? &TransArgs : nullptr));
10829 template<typename Derived>
10831 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
10832 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10833 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10834 if (SubExpr.isInvalid())
10835 return ExprError();
10837 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
10840 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10843 template<typename Derived>
10845 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
10846 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10847 if (Pattern.isInvalid())
10848 return ExprError();
10850 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
10853 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10854 E->getNumExpansions());
10857 template<typename Derived>
10859 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10860 // If E is not value-dependent, then nothing will change when we transform it.
10861 // Note: This is an instantiation-centric view.
10862 if (!E->isValueDependent())
10865 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
10867 ArrayRef<TemplateArgument> PackArgs;
10868 TemplateArgument ArgStorage;
10870 // Find the argument list to transform.
10871 if (E->isPartiallySubstituted()) {
10872 PackArgs = E->getPartialArguments();
10873 } else if (E->isValueDependent()) {
10874 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10875 bool ShouldExpand = false;
10876 bool RetainExpansion = false;
10877 Optional<unsigned> NumExpansions;
10878 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10880 ShouldExpand, RetainExpansion,
10882 return ExprError();
10884 // If we need to expand the pack, build a template argument from it and
10886 if (ShouldExpand) {
10887 auto *Pack = E->getPack();
10888 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10889 ArgStorage = getSema().Context.getPackExpansionType(
10890 getSema().Context.getTypeDeclType(TTPD), None);
10891 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10892 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10894 auto *VD = cast<ValueDecl>(Pack);
10895 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10896 VK_RValue, E->getPackLoc());
10897 if (DRE.isInvalid())
10898 return ExprError();
10899 ArgStorage = new (getSema().Context) PackExpansionExpr(
10900 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10902 PackArgs = ArgStorage;
10906 // If we're not expanding the pack, just transform the decl.
10907 if (!PackArgs.size()) {
10908 auto *Pack = cast_or_null<NamedDecl>(
10909 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
10911 return ExprError();
10912 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10914 E->getRParenLoc(), None, None);
10917 // Try to compute the result without performing a partial substitution.
10918 Optional<unsigned> Result = 0;
10919 for (const TemplateArgument &Arg : PackArgs) {
10920 if (!Arg.isPackExpansion()) {
10921 Result = *Result + 1;
10925 TemplateArgumentLoc ArgLoc;
10926 InventTemplateArgumentLoc(Arg, ArgLoc);
10928 // Find the pattern of the pack expansion.
10929 SourceLocation Ellipsis;
10930 Optional<unsigned> OrigNumExpansions;
10931 TemplateArgumentLoc Pattern =
10932 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
10933 OrigNumExpansions);
10935 // Substitute under the pack expansion. Do not expand the pack (yet).
10936 TemplateArgumentLoc OutPattern;
10937 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10938 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
10942 // See if we can determine the number of arguments from the result.
10943 Optional<unsigned> NumExpansions =
10944 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
10945 if (!NumExpansions) {
10946 // No: we must be in an alias template expansion, and we're going to need
10947 // to actually expand the packs.
10952 Result = *Result + *NumExpansions;
10955 // Common case: we could determine the number of expansions without
10958 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10960 E->getRParenLoc(), *Result, None);
10962 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10965 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10966 typedef TemplateArgumentLocInventIterator<
10967 Derived, const TemplateArgument*> PackLocIterator;
10968 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10969 PackLocIterator(*this, PackArgs.end()),
10970 TransformedPackArgs, /*Uneval*/true))
10971 return ExprError();
10974 // Check whether we managed to fully-expand the pack.
10975 // FIXME: Is it possible for us to do so and not hit the early exit path?
10976 SmallVector<TemplateArgument, 8> Args;
10977 bool PartialSubstitution = false;
10978 for (auto &Loc : TransformedPackArgs.arguments()) {
10979 Args.push_back(Loc.getArgument());
10980 if (Loc.getArgument().isPackExpansion())
10981 PartialSubstitution = true;
10984 if (PartialSubstitution)
10985 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10987 E->getRParenLoc(), None, Args);
10989 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10990 E->getPackLoc(), E->getRParenLoc(),
10991 Args.size(), None);
10994 template<typename Derived>
10996 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10997 SubstNonTypeTemplateParmPackExpr *E) {
10998 // Default behavior is to do nothing with this transformation.
11002 template<typename Derived>
11004 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11005 SubstNonTypeTemplateParmExpr *E) {
11006 // Default behavior is to do nothing with this transformation.
11010 template<typename Derived>
11012 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11013 // Default behavior is to do nothing with this transformation.
11017 template<typename Derived>
11019 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11020 MaterializeTemporaryExpr *E) {
11021 return getDerived().TransformExpr(E->GetTemporaryExpr());
11024 template<typename Derived>
11026 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11027 Expr *Pattern = E->getPattern();
11029 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11030 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11031 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11033 // Determine whether the set of unexpanded parameter packs can and should
11035 bool Expand = true;
11036 bool RetainExpansion = false;
11037 Optional<unsigned> NumExpansions;
11038 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11039 Pattern->getSourceRange(),
11041 Expand, RetainExpansion,
11046 // Do not expand any packs here, just transform and rebuild a fold
11048 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11051 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11052 if (LHS.isInvalid())
11056 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11057 if (RHS.isInvalid())
11060 if (!getDerived().AlwaysRebuild() &&
11061 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11064 return getDerived().RebuildCXXFoldExpr(
11065 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11066 RHS.get(), E->getLocEnd());
11069 // The transform has determined that we should perform an elementwise
11070 // expansion of the pattern. Do so.
11071 ExprResult Result = getDerived().TransformExpr(E->getInit());
11072 if (Result.isInvalid())
11074 bool LeftFold = E->isLeftFold();
11076 // If we're retaining an expansion for a right fold, it is the innermost
11077 // component and takes the init (if any).
11078 if (!LeftFold && RetainExpansion) {
11079 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11081 ExprResult Out = getDerived().TransformExpr(Pattern);
11082 if (Out.isInvalid())
11085 Result = getDerived().RebuildCXXFoldExpr(
11086 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11087 Result.get(), E->getLocEnd());
11088 if (Result.isInvalid())
11092 for (unsigned I = 0; I != *NumExpansions; ++I) {
11093 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11094 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11095 ExprResult Out = getDerived().TransformExpr(Pattern);
11096 if (Out.isInvalid())
11099 if (Out.get()->containsUnexpandedParameterPack()) {
11100 // We still have a pack; retain a pack expansion for this slice.
11101 Result = getDerived().RebuildCXXFoldExpr(
11103 LeftFold ? Result.get() : Out.get(),
11104 E->getOperator(), E->getEllipsisLoc(),
11105 LeftFold ? Out.get() : Result.get(),
11107 } else if (Result.isUsable()) {
11108 // We've got down to a single element; build a binary operator.
11109 Result = getDerived().RebuildBinaryOperator(
11110 E->getEllipsisLoc(), E->getOperator(),
11111 LeftFold ? Result.get() : Out.get(),
11112 LeftFold ? Out.get() : Result.get());
11116 if (Result.isInvalid())
11120 // If we're retaining an expansion for a left fold, it is the outermost
11121 // component and takes the complete expansion so far as its init (if any).
11122 if (LeftFold && RetainExpansion) {
11123 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11125 ExprResult Out = getDerived().TransformExpr(Pattern);
11126 if (Out.isInvalid())
11129 Result = getDerived().RebuildCXXFoldExpr(
11130 E->getLocStart(), Result.get(),
11131 E->getOperator(), E->getEllipsisLoc(),
11132 Out.get(), E->getLocEnd());
11133 if (Result.isInvalid())
11137 // If we had no init and an empty pack, and we're not retaining an expansion,
11138 // then produce a fallback value or error.
11139 if (Result.isUnset())
11140 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11146 template<typename Derived>
11148 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11149 CXXStdInitializerListExpr *E) {
11150 return getDerived().TransformExpr(E->getSubExpr());
11153 template<typename Derived>
11155 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
11156 return SemaRef.MaybeBindToTemporary(E);
11159 template<typename Derived>
11161 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
11165 template<typename Derived>
11167 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11168 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11169 if (SubExpr.isInvalid())
11170 return ExprError();
11172 if (!getDerived().AlwaysRebuild() &&
11173 SubExpr.get() == E->getSubExpr())
11176 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
11179 template<typename Derived>
11181 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11182 // Transform each of the elements.
11183 SmallVector<Expr *, 8> Elements;
11184 bool ArgChanged = false;
11185 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
11186 /*IsCall=*/false, Elements, &ArgChanged))
11187 return ExprError();
11189 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11190 return SemaRef.MaybeBindToTemporary(E);
11192 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11197 template<typename Derived>
11199 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
11200 ObjCDictionaryLiteral *E) {
11201 // Transform each of the elements.
11202 SmallVector<ObjCDictionaryElement, 8> Elements;
11203 bool ArgChanged = false;
11204 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11205 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
11207 if (OrigElement.isPackExpansion()) {
11208 // This key/value element is a pack expansion.
11209 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11210 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11211 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11212 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11214 // Determine whether the set of unexpanded parameter packs can
11215 // and should be expanded.
11216 bool Expand = true;
11217 bool RetainExpansion = false;
11218 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11219 Optional<unsigned> NumExpansions = OrigNumExpansions;
11220 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11221 OrigElement.Value->getLocEnd());
11222 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11225 Expand, RetainExpansion,
11227 return ExprError();
11230 // The transform has determined that we should perform a simple
11231 // transformation on the pack expansion, producing another pack
11233 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11234 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11235 if (Key.isInvalid())
11236 return ExprError();
11238 if (Key.get() != OrigElement.Key)
11241 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11242 if (Value.isInvalid())
11243 return ExprError();
11245 if (Value.get() != OrigElement.Value)
11248 ObjCDictionaryElement Expansion = {
11249 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11251 Elements.push_back(Expansion);
11255 // Record right away that the argument was changed. This needs
11256 // to happen even if the array expands to nothing.
11259 // The transform has determined that we should perform an elementwise
11260 // expansion of the pattern. Do so.
11261 for (unsigned I = 0; I != *NumExpansions; ++I) {
11262 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11263 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11264 if (Key.isInvalid())
11265 return ExprError();
11267 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11268 if (Value.isInvalid())
11269 return ExprError();
11271 ObjCDictionaryElement Element = {
11272 Key.get(), Value.get(), SourceLocation(), NumExpansions
11275 // If any unexpanded parameter packs remain, we still have a
11277 // FIXME: Can this really happen?
11278 if (Key.get()->containsUnexpandedParameterPack() ||
11279 Value.get()->containsUnexpandedParameterPack())
11280 Element.EllipsisLoc = OrigElement.EllipsisLoc;
11282 Elements.push_back(Element);
11285 // FIXME: Retain a pack expansion if RetainExpansion is true.
11287 // We've finished with this pack expansion.
11291 // Transform and check key.
11292 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11293 if (Key.isInvalid())
11294 return ExprError();
11296 if (Key.get() != OrigElement.Key)
11299 // Transform and check value.
11301 = getDerived().TransformExpr(OrigElement.Value);
11302 if (Value.isInvalid())
11303 return ExprError();
11305 if (Value.get() != OrigElement.Value)
11308 ObjCDictionaryElement Element = {
11309 Key.get(), Value.get(), SourceLocation(), None
11311 Elements.push_back(Element);
11314 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11315 return SemaRef.MaybeBindToTemporary(E);
11317 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
11321 template<typename Derived>
11323 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
11324 TypeSourceInfo *EncodedTypeInfo
11325 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11326 if (!EncodedTypeInfo)
11327 return ExprError();
11329 if (!getDerived().AlwaysRebuild() &&
11330 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
11333 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
11335 E->getRParenLoc());
11338 template<typename Derived>
11339 ExprResult TreeTransform<Derived>::
11340 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
11341 // This is a kind of implicit conversion, and it needs to get dropped
11342 // and recomputed for the same general reasons that ImplicitCastExprs
11343 // do, as well a more specific one: this expression is only valid when
11344 // it appears *immediately* as an argument expression.
11345 return getDerived().TransformExpr(E->getSubExpr());
11348 template<typename Derived>
11349 ExprResult TreeTransform<Derived>::
11350 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
11351 TypeSourceInfo *TSInfo
11352 = getDerived().TransformType(E->getTypeInfoAsWritten());
11354 return ExprError();
11356 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
11357 if (Result.isInvalid())
11358 return ExprError();
11360 if (!getDerived().AlwaysRebuild() &&
11361 TSInfo == E->getTypeInfoAsWritten() &&
11362 Result.get() == E->getSubExpr())
11365 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
11366 E->getBridgeKeywordLoc(), TSInfo,
11370 template <typename Derived>
11371 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11372 ObjCAvailabilityCheckExpr *E) {
11376 template<typename Derived>
11378 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
11379 // Transform arguments.
11380 bool ArgChanged = false;
11381 SmallVector<Expr*, 8> Args;
11382 Args.reserve(E->getNumArgs());
11383 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
11385 return ExprError();
11387 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11388 // Class message: transform the receiver type.
11389 TypeSourceInfo *ReceiverTypeInfo
11390 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11391 if (!ReceiverTypeInfo)
11392 return ExprError();
11394 // If nothing changed, just retain the existing message send.
11395 if (!getDerived().AlwaysRebuild() &&
11396 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
11397 return SemaRef.MaybeBindToTemporary(E);
11399 // Build a new class message send.
11400 SmallVector<SourceLocation, 16> SelLocs;
11401 E->getSelectorLocs(SelLocs);
11402 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11405 E->getMethodDecl(),
11410 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11411 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11412 if (!E->getMethodDecl())
11413 return ExprError();
11415 // Build a new class message send to 'super'.
11416 SmallVector<SourceLocation, 16> SelLocs;
11417 E->getSelectorLocs(SelLocs);
11418 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11421 E->getReceiverType(),
11422 E->getMethodDecl(),
11428 // Instance message: transform the receiver
11429 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11430 "Only class and instance messages may be instantiated");
11431 ExprResult Receiver
11432 = getDerived().TransformExpr(E->getInstanceReceiver());
11433 if (Receiver.isInvalid())
11434 return ExprError();
11436 // If nothing changed, just retain the existing message send.
11437 if (!getDerived().AlwaysRebuild() &&
11438 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
11439 return SemaRef.MaybeBindToTemporary(E);
11441 // Build a new instance message send.
11442 SmallVector<SourceLocation, 16> SelLocs;
11443 E->getSelectorLocs(SelLocs);
11444 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
11447 E->getMethodDecl(),
11453 template<typename Derived>
11455 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
11459 template<typename Derived>
11461 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
11465 template<typename Derived>
11467 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
11468 // Transform the base expression.
11469 ExprResult Base = getDerived().TransformExpr(E->getBase());
11470 if (Base.isInvalid())
11471 return ExprError();
11473 // We don't need to transform the ivar; it will never change.
11475 // If nothing changed, just retain the existing expression.
11476 if (!getDerived().AlwaysRebuild() &&
11477 Base.get() == E->getBase())
11480 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
11482 E->isArrow(), E->isFreeIvar());
11485 template<typename Derived>
11487 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
11488 // 'super' and types never change. Property never changes. Just
11489 // retain the existing expression.
11490 if (!E->isObjectReceiver())
11493 // Transform the base expression.
11494 ExprResult Base = getDerived().TransformExpr(E->getBase());
11495 if (Base.isInvalid())
11496 return ExprError();
11498 // We don't need to transform the property; it will never change.
11500 // If nothing changed, just retain the existing expression.
11501 if (!getDerived().AlwaysRebuild() &&
11502 Base.get() == E->getBase())
11505 if (E->isExplicitProperty())
11506 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11507 E->getExplicitProperty(),
11510 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11511 SemaRef.Context.PseudoObjectTy,
11512 E->getImplicitPropertyGetter(),
11513 E->getImplicitPropertySetter(),
11517 template<typename Derived>
11519 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11520 // Transform the base expression.
11521 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11522 if (Base.isInvalid())
11523 return ExprError();
11525 // Transform the key expression.
11526 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11527 if (Key.isInvalid())
11528 return ExprError();
11530 // If nothing changed, just retain the existing expression.
11531 if (!getDerived().AlwaysRebuild() &&
11532 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
11535 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
11536 Base.get(), Key.get(),
11537 E->getAtIndexMethodDecl(),
11538 E->setAtIndexMethodDecl());
11541 template<typename Derived>
11543 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
11544 // Transform the base expression.
11545 ExprResult Base = getDerived().TransformExpr(E->getBase());
11546 if (Base.isInvalid())
11547 return ExprError();
11549 // If nothing changed, just retain the existing expression.
11550 if (!getDerived().AlwaysRebuild() &&
11551 Base.get() == E->getBase())
11554 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
11559 template<typename Derived>
11561 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
11562 bool ArgumentChanged = false;
11563 SmallVector<Expr*, 8> SubExprs;
11564 SubExprs.reserve(E->getNumSubExprs());
11565 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11566 SubExprs, &ArgumentChanged))
11567 return ExprError();
11569 if (!getDerived().AlwaysRebuild() &&
11573 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
11575 E->getRParenLoc());
11578 template<typename Derived>
11580 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11581 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11582 if (SrcExpr.isInvalid())
11583 return ExprError();
11585 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11587 return ExprError();
11589 if (!getDerived().AlwaysRebuild() &&
11590 Type == E->getTypeSourceInfo() &&
11591 SrcExpr.get() == E->getSrcExpr())
11594 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11595 SrcExpr.get(), Type,
11596 E->getRParenLoc());
11599 template<typename Derived>
11601 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
11602 BlockDecl *oldBlock = E->getBlockDecl();
11604 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
11605 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11607 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
11608 blockScope->TheDecl->setBlockMissingReturnType(
11609 oldBlock->blockMissingReturnType());
11611 SmallVector<ParmVarDecl*, 4> params;
11612 SmallVector<QualType, 4> paramTypes;
11614 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11616 // Parameter substitution.
11617 Sema::ExtParameterInfoBuilder extParamInfos;
11618 if (getDerived().TransformFunctionTypeParams(
11619 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11620 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms,
11622 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11623 return ExprError();
11626 QualType exprResultType =
11627 getDerived().TransformType(exprFunctionType->getReturnType());
11629 auto epi = exprFunctionType->getExtProtoInfo();
11630 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11632 QualType functionType =
11633 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
11634 blockScope->FunctionType = functionType;
11636 // Set the parameters on the block decl.
11637 if (!params.empty())
11638 blockScope->TheDecl->setParams(params);
11640 if (!oldBlock->blockMissingReturnType()) {
11641 blockScope->HasImplicitReturnType = false;
11642 blockScope->ReturnType = exprResultType;
11645 // Transform the body
11646 StmtResult body = getDerived().TransformStmt(E->getBody());
11647 if (body.isInvalid()) {
11648 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11649 return ExprError();
11653 // In builds with assertions, make sure that we captured everything we
11654 // captured before.
11655 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
11656 for (const auto &I : oldBlock->captures()) {
11657 VarDecl *oldCapture = I.getVariable();
11659 // Ignore parameter packs.
11660 if (isa<ParmVarDecl>(oldCapture) &&
11661 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11664 VarDecl *newCapture =
11665 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11667 assert(blockScope->CaptureMap.count(newCapture));
11669 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
11673 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
11674 /*Scope=*/nullptr);
11677 template<typename Derived>
11679 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
11680 llvm_unreachable("Cannot transform asType expressions yet");
11683 template<typename Derived>
11685 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
11686 QualType RetTy = getDerived().TransformType(E->getType());
11687 bool ArgumentChanged = false;
11688 SmallVector<Expr*, 8> SubExprs;
11689 SubExprs.reserve(E->getNumSubExprs());
11690 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11691 SubExprs, &ArgumentChanged))
11692 return ExprError();
11694 if (!getDerived().AlwaysRebuild() &&
11698 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
11699 RetTy, E->getOp(), E->getRParenLoc());
11702 //===----------------------------------------------------------------------===//
11703 // Type reconstruction
11704 //===----------------------------------------------------------------------===//
11706 template<typename Derived>
11707 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11708 SourceLocation Star) {
11709 return SemaRef.BuildPointerType(PointeeType, Star,
11710 getDerived().getBaseEntity());
11713 template<typename Derived>
11714 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11715 SourceLocation Star) {
11716 return SemaRef.BuildBlockPointerType(PointeeType, Star,
11717 getDerived().getBaseEntity());
11720 template<typename Derived>
11722 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11723 bool WrittenAsLValue,
11724 SourceLocation Sigil) {
11725 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
11726 Sigil, getDerived().getBaseEntity());
11729 template<typename Derived>
11731 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11732 QualType ClassType,
11733 SourceLocation Sigil) {
11734 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11735 getDerived().getBaseEntity());
11738 template<typename Derived>
11739 QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
11740 const ObjCTypeParamDecl *Decl,
11741 SourceLocation ProtocolLAngleLoc,
11742 ArrayRef<ObjCProtocolDecl *> Protocols,
11743 ArrayRef<SourceLocation> ProtocolLocs,
11744 SourceLocation ProtocolRAngleLoc) {
11745 return SemaRef.BuildObjCTypeParamType(Decl,
11746 ProtocolLAngleLoc, Protocols,
11747 ProtocolLocs, ProtocolRAngleLoc,
11748 /*FailOnError=*/true);
11751 template<typename Derived>
11752 QualType TreeTransform<Derived>::RebuildObjCObjectType(
11754 SourceLocation Loc,
11755 SourceLocation TypeArgsLAngleLoc,
11756 ArrayRef<TypeSourceInfo *> TypeArgs,
11757 SourceLocation TypeArgsRAngleLoc,
11758 SourceLocation ProtocolLAngleLoc,
11759 ArrayRef<ObjCProtocolDecl *> Protocols,
11760 ArrayRef<SourceLocation> ProtocolLocs,
11761 SourceLocation ProtocolRAngleLoc) {
11762 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11763 TypeArgs, TypeArgsRAngleLoc,
11764 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11766 /*FailOnError=*/true);
11769 template<typename Derived>
11770 QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11771 QualType PointeeType,
11772 SourceLocation Star) {
11773 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11776 template<typename Derived>
11778 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11779 ArrayType::ArraySizeModifier SizeMod,
11780 const llvm::APInt *Size,
11782 unsigned IndexTypeQuals,
11783 SourceRange BracketsRange) {
11784 if (SizeExpr || !Size)
11785 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11786 IndexTypeQuals, BracketsRange,
11787 getDerived().getBaseEntity());
11789 QualType Types[] = {
11790 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11791 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11792 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
11794 const unsigned NumTypes = llvm::array_lengthof(Types);
11796 for (unsigned I = 0; I != NumTypes; ++I)
11797 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11798 SizeType = Types[I];
11802 // Note that we can return a VariableArrayType here in the case where
11803 // the element type was a dependent VariableArrayType.
11804 IntegerLiteral *ArraySize
11805 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11806 /*FIXME*/BracketsRange.getBegin());
11807 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
11808 IndexTypeQuals, BracketsRange,
11809 getDerived().getBaseEntity());
11812 template<typename Derived>
11814 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
11815 ArrayType::ArraySizeModifier SizeMod,
11816 const llvm::APInt &Size,
11817 unsigned IndexTypeQuals,
11818 SourceRange BracketsRange) {
11819 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
11820 IndexTypeQuals, BracketsRange);
11823 template<typename Derived>
11825 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
11826 ArrayType::ArraySizeModifier SizeMod,
11827 unsigned IndexTypeQuals,
11828 SourceRange BracketsRange) {
11829 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
11830 IndexTypeQuals, BracketsRange);
11833 template<typename Derived>
11835 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
11836 ArrayType::ArraySizeModifier SizeMod,
11838 unsigned IndexTypeQuals,
11839 SourceRange BracketsRange) {
11840 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11842 IndexTypeQuals, BracketsRange);
11845 template<typename Derived>
11847 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
11848 ArrayType::ArraySizeModifier SizeMod,
11850 unsigned IndexTypeQuals,
11851 SourceRange BracketsRange) {
11852 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11854 IndexTypeQuals, BracketsRange);
11857 template<typename Derived>
11858 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
11859 unsigned NumElements,
11860 VectorType::VectorKind VecKind) {
11861 // FIXME: semantic checking!
11862 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
11865 template<typename Derived>
11866 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11867 unsigned NumElements,
11868 SourceLocation AttributeLoc) {
11869 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11870 NumElements, true);
11871 IntegerLiteral *VectorSize
11872 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11874 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
11877 template<typename Derived>
11879 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
11881 SourceLocation AttributeLoc) {
11882 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
11885 template<typename Derived>
11886 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11888 MutableArrayRef<QualType> ParamTypes,
11889 const FunctionProtoType::ExtProtoInfo &EPI) {
11890 return SemaRef.BuildFunctionType(T, ParamTypes,
11891 getDerived().getBaseLocation(),
11892 getDerived().getBaseEntity(),
11896 template<typename Derived>
11897 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11898 return SemaRef.Context.getFunctionNoProtoType(T);
11901 template<typename Derived>
11902 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
11904 assert(D && "no decl found");
11905 if (D->isInvalidDecl()) return QualType();
11907 // FIXME: Doesn't account for ObjCInterfaceDecl!
11909 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
11910 // A valid resolved using typename pack expansion decl can have multiple
11911 // UsingDecls, but they must each have exactly one type, and it must be
11912 // the same type in every case. But we must have at least one expansion!
11913 if (UPD->expansions().empty()) {
11914 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
11915 << UPD->isCXXClassMember() << UPD;
11919 // We might still have some unresolved types. Try to pick a resolved type
11920 // if we can. The final instantiation will check that the remaining
11921 // unresolved types instantiate to the type we pick.
11922 QualType FallbackT;
11924 for (auto *E : UPD->expansions()) {
11925 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
11926 if (ThisT.isNull())
11928 else if (ThisT->getAs<UnresolvedUsingType>())
11930 else if (T.isNull())
11933 assert(getSema().Context.hasSameType(ThisT, T) &&
11934 "mismatched resolved types in using pack expansion");
11936 return T.isNull() ? FallbackT : T;
11937 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
11938 assert(Using->hasTypename() &&
11939 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11941 // A valid resolved using typename decl points to exactly one type decl.
11942 assert(++Using->shadow_begin() == Using->shadow_end());
11943 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
11945 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11946 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11947 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11950 return SemaRef.Context.getTypeDeclType(Ty);
11953 template<typename Derived>
11954 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11955 SourceLocation Loc) {
11956 return SemaRef.BuildTypeofExprType(E, Loc);
11959 template<typename Derived>
11960 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11961 return SemaRef.Context.getTypeOfType(Underlying);
11964 template<typename Derived>
11965 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11966 SourceLocation Loc) {
11967 return SemaRef.BuildDecltypeType(E, Loc);
11970 template<typename Derived>
11971 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11972 UnaryTransformType::UTTKind UKind,
11973 SourceLocation Loc) {
11974 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11977 template<typename Derived>
11978 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
11979 TemplateName Template,
11980 SourceLocation TemplateNameLoc,
11981 TemplateArgumentListInfo &TemplateArgs) {
11982 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
11985 template<typename Derived>
11986 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11987 SourceLocation KWLoc) {
11988 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11991 template<typename Derived>
11992 QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11993 SourceLocation KWLoc,
11995 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
11996 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
11999 template<typename Derived>
12001 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12003 TemplateDecl *Template) {
12004 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
12008 template<typename Derived>
12010 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12011 const IdentifierInfo &Name,
12012 SourceLocation NameLoc,
12013 QualType ObjectType,
12014 NamedDecl *FirstQualifierInScope) {
12015 UnqualifiedId TemplateName;
12016 TemplateName.setIdentifier(&Name, NameLoc);
12017 Sema::TemplateTy Template;
12018 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12019 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12020 SS, TemplateKWLoc, TemplateName,
12021 ParsedType::make(ObjectType),
12022 /*EnteringContext=*/false,
12024 return Template.get();
12027 template<typename Derived>
12029 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12030 OverloadedOperatorKind Operator,
12031 SourceLocation NameLoc,
12032 QualType ObjectType) {
12033 UnqualifiedId Name;
12034 // FIXME: Bogus location information.
12035 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
12036 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
12037 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12038 Sema::TemplateTy Template;
12039 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12040 SS, TemplateKWLoc, Name,
12041 ParsedType::make(ObjectType),
12042 /*EnteringContext=*/false,
12044 return Template.get();
12047 template<typename Derived>
12049 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12050 SourceLocation OpLoc,
12054 Expr *Callee = OrigCallee->IgnoreParenCasts();
12055 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
12057 if (First->getObjectKind() == OK_ObjCProperty) {
12058 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12059 if (BinaryOperator::isAssignmentOp(Opc))
12060 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12062 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12063 if (Result.isInvalid())
12064 return ExprError();
12065 First = Result.get();
12068 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12069 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12070 if (Result.isInvalid())
12071 return ExprError();
12072 Second = Result.get();
12075 // Determine whether this should be a builtin operation.
12076 if (Op == OO_Subscript) {
12077 if (!First->getType()->isOverloadableType() &&
12078 !Second->getType()->isOverloadableType())
12079 return getSema().CreateBuiltinArraySubscriptExpr(First,
12080 Callee->getLocStart(),
12082 } else if (Op == OO_Arrow) {
12083 // -> is never a builtin operation.
12084 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12085 } else if (Second == nullptr || isPostIncDec) {
12086 if (!First->getType()->isOverloadableType()) {
12087 // The argument is not of overloadable type, so try to create a
12088 // built-in unary operation.
12089 UnaryOperatorKind Opc
12090 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12092 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
12095 if (!First->getType()->isOverloadableType() &&
12096 !Second->getType()->isOverloadableType()) {
12097 // Neither of the arguments is an overloadable type, so try to
12098 // create a built-in binary operation.
12099 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12101 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
12102 if (Result.isInvalid())
12103 return ExprError();
12109 // Compute the transformed set of functions (and function templates) to be
12110 // used during overload resolution.
12111 UnresolvedSet<16> Functions;
12113 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
12114 assert(ULE->requiresADL());
12115 Functions.append(ULE->decls_begin(), ULE->decls_end());
12117 // If we've resolved this to a particular non-member function, just call
12118 // that function. If we resolved it to a member function,
12119 // CreateOverloaded* will find that function for us.
12120 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12121 if (!isa<CXXMethodDecl>(ND))
12122 Functions.addDecl(ND);
12125 // Add any functions found via argument-dependent lookup.
12126 Expr *Args[2] = { First, Second };
12127 unsigned NumArgs = 1 + (Second != nullptr);
12129 // Create the overloaded operator invocation for unary operators.
12130 if (NumArgs == 1 || isPostIncDec) {
12131 UnaryOperatorKind Opc
12132 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12133 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
12136 if (Op == OO_Subscript) {
12137 SourceLocation LBrace;
12138 SourceLocation RBrace;
12140 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
12141 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
12142 LBrace = SourceLocation::getFromRawEncoding(
12143 NameLoc.CXXOperatorName.BeginOpNameLoc);
12144 RBrace = SourceLocation::getFromRawEncoding(
12145 NameLoc.CXXOperatorName.EndOpNameLoc);
12147 LBrace = Callee->getLocStart();
12151 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12155 // Create the overloaded operator invocation for binary operators.
12156 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12158 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12159 if (Result.isInvalid())
12160 return ExprError();
12165 template<typename Derived>
12167 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
12168 SourceLocation OperatorLoc,
12171 TypeSourceInfo *ScopeType,
12172 SourceLocation CCLoc,
12173 SourceLocation TildeLoc,
12174 PseudoDestructorTypeStorage Destroyed) {
12175 QualType BaseType = Base->getType();
12176 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
12177 (!isArrow && !BaseType->getAs<RecordType>()) ||
12178 (isArrow && BaseType->getAs<PointerType>() &&
12179 !BaseType->getAs<PointerType>()->getPointeeType()
12180 ->template getAs<RecordType>())){
12181 // This pseudo-destructor expression is still a pseudo-destructor.
12182 return SemaRef.BuildPseudoDestructorExpr(
12183 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12184 CCLoc, TildeLoc, Destroyed);
12187 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
12188 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12189 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12190 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12191 NameInfo.setNamedTypeInfo(DestroyedType);
12193 // The scope type is now known to be a valid nested name specifier
12194 // component. Tack it on to the end of the nested name specifier.
12196 if (!ScopeType->getType()->getAs<TagType>()) {
12197 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12198 diag::err_expected_class_or_namespace)
12199 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12200 return ExprError();
12202 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12206 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12207 return getSema().BuildMemberReferenceExpr(Base, BaseType,
12208 OperatorLoc, isArrow,
12210 /*FIXME: FirstQualifier*/ nullptr,
12212 /*TemplateArgs*/ nullptr,
12216 template<typename Derived>
12218 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
12219 SourceLocation Loc = S->getLocStart();
12220 CapturedDecl *CD = S->getCapturedDecl();
12221 unsigned NumParams = CD->getNumParams();
12222 unsigned ContextParamPos = CD->getContextParamPosition();
12223 SmallVector<Sema::CapturedParamNameType, 4> Params;
12224 for (unsigned I = 0; I < NumParams; ++I) {
12225 if (I != ContextParamPos) {
12228 CD->getParam(I)->getName(),
12229 getDerived().TransformType(CD->getParam(I)->getType())));
12231 Params.push_back(std::make_pair(StringRef(), QualType()));
12234 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
12235 S->getCapturedRegionKind(), Params);
12238 Sema::CompoundScopeRAII CompoundScope(getSema());
12239 Body = getDerived().TransformStmt(S->getCapturedStmt());
12242 if (Body.isInvalid()) {
12243 getSema().ActOnCapturedRegionError();
12244 return StmtError();
12247 return getSema().ActOnCapturedRegionEnd(Body.get());
12250 } // end namespace clang
12252 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H