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.setLocalRangeEnd(TL.getLocalRangeEnd());
5027 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5028 NewTL.setParam(i, ParamDecls[i]);
5033 template<typename Derived>
5034 bool TreeTransform<Derived>::TransformExceptionSpec(
5035 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5036 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5037 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5039 // Instantiate a dynamic noexcept expression, if any.
5040 if (ESI.Type == EST_ComputedNoexcept) {
5041 EnterExpressionEvaluationContext Unevaluated(getSema(),
5042 Sema::ConstantEvaluated);
5043 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5044 if (NoexceptExpr.isInvalid())
5047 // FIXME: This is bogus, a noexcept expression is not a condition.
5048 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
5049 if (NoexceptExpr.isInvalid())
5052 if (!NoexceptExpr.get()->isValueDependent()) {
5053 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5054 NoexceptExpr.get(), nullptr,
5055 diag::err_noexcept_needs_constant_expression,
5056 /*AllowFold*/false);
5057 if (NoexceptExpr.isInvalid())
5061 if (ESI.NoexceptExpr != NoexceptExpr.get())
5063 ESI.NoexceptExpr = NoexceptExpr.get();
5066 if (ESI.Type != EST_Dynamic)
5069 // Instantiate a dynamic exception specification's type.
5070 for (QualType T : ESI.Exceptions) {
5071 if (const PackExpansionType *PackExpansion =
5072 T->getAs<PackExpansionType>()) {
5075 // We have a pack expansion. Instantiate it.
5076 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5077 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5079 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5081 // Determine whether the set of unexpanded parameter packs can and
5084 bool Expand = false;
5085 bool RetainExpansion = false;
5086 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5087 // FIXME: Track the location of the ellipsis (and track source location
5088 // information for the types in the exception specification in general).
5089 if (getDerived().TryExpandParameterPacks(
5090 Loc, SourceRange(), Unexpanded, Expand,
5091 RetainExpansion, NumExpansions))
5095 // We can't expand this pack expansion into separate arguments yet;
5096 // just substitute into the pattern and create a new pack expansion
5098 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5099 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5103 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5104 Exceptions.push_back(U);
5108 // Substitute into the pack expansion pattern for each slice of the
5110 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5111 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5113 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5114 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5117 Exceptions.push_back(U);
5120 QualType U = getDerived().TransformType(T);
5121 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5126 Exceptions.push_back(U);
5130 ESI.Exceptions = Exceptions;
5131 if (ESI.Exceptions.empty())
5132 ESI.Type = EST_DynamicNone;
5136 template<typename Derived>
5137 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
5138 TypeLocBuilder &TLB,
5139 FunctionNoProtoTypeLoc TL) {
5140 const FunctionNoProtoType *T = TL.getTypePtr();
5141 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5142 if (ResultType.isNull())
5145 QualType Result = TL.getType();
5146 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5147 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5149 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5150 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5151 NewTL.setLParenLoc(TL.getLParenLoc());
5152 NewTL.setRParenLoc(TL.getRParenLoc());
5153 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5158 template<typename Derived> QualType
5159 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5160 UnresolvedUsingTypeLoc TL) {
5161 const UnresolvedUsingType *T = TL.getTypePtr();
5162 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5166 QualType Result = TL.getType();
5167 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5168 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
5169 if (Result.isNull())
5173 // We might get an arbitrary type spec type back. We should at
5174 // least always get a type spec type, though.
5175 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5176 NewTL.setNameLoc(TL.getNameLoc());
5181 template<typename Derived>
5182 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5183 TypedefTypeLoc TL) {
5184 const TypedefType *T = TL.getTypePtr();
5185 TypedefNameDecl *Typedef
5186 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5191 QualType Result = TL.getType();
5192 if (getDerived().AlwaysRebuild() ||
5193 Typedef != T->getDecl()) {
5194 Result = getDerived().RebuildTypedefType(Typedef);
5195 if (Result.isNull())
5199 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5200 NewTL.setNameLoc(TL.getNameLoc());
5205 template<typename Derived>
5206 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5207 TypeOfExprTypeLoc TL) {
5208 // typeof expressions are not potentially evaluated contexts
5209 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5210 Sema::ReuseLambdaContextDecl);
5212 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5216 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5220 QualType Result = TL.getType();
5221 if (getDerived().AlwaysRebuild() ||
5222 E.get() != TL.getUnderlyingExpr()) {
5223 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5224 if (Result.isNull())
5229 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5230 NewTL.setTypeofLoc(TL.getTypeofLoc());
5231 NewTL.setLParenLoc(TL.getLParenLoc());
5232 NewTL.setRParenLoc(TL.getRParenLoc());
5237 template<typename Derived>
5238 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5240 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5241 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5245 QualType Result = TL.getType();
5246 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5247 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5248 if (Result.isNull())
5252 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5253 NewTL.setTypeofLoc(TL.getTypeofLoc());
5254 NewTL.setLParenLoc(TL.getLParenLoc());
5255 NewTL.setRParenLoc(TL.getRParenLoc());
5256 NewTL.setUnderlyingTInfo(New_Under_TI);
5261 template<typename Derived>
5262 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5263 DecltypeTypeLoc TL) {
5264 const DecltypeType *T = TL.getTypePtr();
5266 // decltype expressions are not potentially evaluated contexts
5267 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5268 nullptr, /*IsDecltype=*/ true);
5270 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5274 E = getSema().ActOnDecltypeExpression(E.get());
5278 QualType Result = TL.getType();
5279 if (getDerived().AlwaysRebuild() ||
5280 E.get() != T->getUnderlyingExpr()) {
5281 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5282 if (Result.isNull())
5287 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5288 NewTL.setNameLoc(TL.getNameLoc());
5293 template<typename Derived>
5294 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5295 TypeLocBuilder &TLB,
5296 UnaryTransformTypeLoc TL) {
5297 QualType Result = TL.getType();
5298 if (Result->isDependentType()) {
5299 const UnaryTransformType *T = TL.getTypePtr();
5301 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5302 Result = getDerived().RebuildUnaryTransformType(NewBase,
5305 if (Result.isNull())
5309 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5310 NewTL.setKWLoc(TL.getKWLoc());
5311 NewTL.setParensRange(TL.getParensRange());
5312 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5316 template<typename Derived>
5317 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5319 const AutoType *T = TL.getTypePtr();
5320 QualType OldDeduced = T->getDeducedType();
5321 QualType NewDeduced;
5322 if (!OldDeduced.isNull()) {
5323 NewDeduced = getDerived().TransformType(OldDeduced);
5324 if (NewDeduced.isNull())
5328 QualType Result = TL.getType();
5329 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5330 T->isDependentType()) {
5331 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5332 if (Result.isNull())
5336 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5337 NewTL.setNameLoc(TL.getNameLoc());
5342 template<typename Derived>
5343 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5345 const RecordType *T = TL.getTypePtr();
5347 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5352 QualType Result = TL.getType();
5353 if (getDerived().AlwaysRebuild() ||
5354 Record != T->getDecl()) {
5355 Result = getDerived().RebuildRecordType(Record);
5356 if (Result.isNull())
5360 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5361 NewTL.setNameLoc(TL.getNameLoc());
5366 template<typename Derived>
5367 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5369 const EnumType *T = TL.getTypePtr();
5371 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5376 QualType Result = TL.getType();
5377 if (getDerived().AlwaysRebuild() ||
5378 Enum != T->getDecl()) {
5379 Result = getDerived().RebuildEnumType(Enum);
5380 if (Result.isNull())
5384 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5385 NewTL.setNameLoc(TL.getNameLoc());
5390 template<typename Derived>
5391 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5392 TypeLocBuilder &TLB,
5393 InjectedClassNameTypeLoc TL) {
5394 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5395 TL.getTypePtr()->getDecl());
5396 if (!D) return QualType();
5398 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5399 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5403 template<typename Derived>
5404 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5405 TypeLocBuilder &TLB,
5406 TemplateTypeParmTypeLoc TL) {
5407 return TransformTypeSpecType(TLB, TL);
5410 template<typename Derived>
5411 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5412 TypeLocBuilder &TLB,
5413 SubstTemplateTypeParmTypeLoc TL) {
5414 const SubstTemplateTypeParmType *T = TL.getTypePtr();
5416 // Substitute into the replacement type, which itself might involve something
5417 // that needs to be transformed. This only tends to occur with default
5418 // template arguments of template template parameters.
5419 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5420 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5421 if (Replacement.isNull())
5424 // Always canonicalize the replacement type.
5425 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5427 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5430 // Propagate type-source information.
5431 SubstTemplateTypeParmTypeLoc NewTL
5432 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5433 NewTL.setNameLoc(TL.getNameLoc());
5438 template<typename Derived>
5439 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5440 TypeLocBuilder &TLB,
5441 SubstTemplateTypeParmPackTypeLoc TL) {
5442 return TransformTypeSpecType(TLB, TL);
5445 template<typename Derived>
5446 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5447 TypeLocBuilder &TLB,
5448 TemplateSpecializationTypeLoc TL) {
5449 const TemplateSpecializationType *T = TL.getTypePtr();
5451 // The nested-name-specifier never matters in a TemplateSpecializationType,
5452 // because we can't have a dependent nested-name-specifier anyway.
5454 TemplateName Template
5455 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5456 TL.getTemplateNameLoc());
5457 if (Template.isNull())
5460 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5463 template<typename Derived>
5464 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5466 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5467 if (ValueType.isNull())
5470 QualType Result = TL.getType();
5471 if (getDerived().AlwaysRebuild() ||
5472 ValueType != TL.getValueLoc().getType()) {
5473 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5474 if (Result.isNull())
5478 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5479 NewTL.setKWLoc(TL.getKWLoc());
5480 NewTL.setLParenLoc(TL.getLParenLoc());
5481 NewTL.setRParenLoc(TL.getRParenLoc());
5486 template <typename Derived>
5487 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5489 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5490 if (ValueType.isNull())
5493 QualType Result = TL.getType();
5494 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5495 const PipeType *PT = Result->getAs<PipeType>();
5496 bool isReadPipe = PT->isReadOnly();
5497 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
5498 if (Result.isNull())
5502 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5503 NewTL.setKWLoc(TL.getKWLoc());
5508 /// \brief Simple iterator that traverses the template arguments in a
5509 /// container that provides a \c getArgLoc() member function.
5511 /// This iterator is intended to be used with the iterator form of
5512 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5513 template<typename ArgLocContainer>
5514 class TemplateArgumentLocContainerIterator {
5515 ArgLocContainer *Container;
5519 typedef TemplateArgumentLoc value_type;
5520 typedef TemplateArgumentLoc reference;
5521 typedef int difference_type;
5522 typedef std::input_iterator_tag iterator_category;
5525 TemplateArgumentLoc Arg;
5528 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5530 const TemplateArgumentLoc *operator->() const {
5536 TemplateArgumentLocContainerIterator() {}
5538 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5540 : Container(&Container), Index(Index) { }
5542 TemplateArgumentLocContainerIterator &operator++() {
5547 TemplateArgumentLocContainerIterator operator++(int) {
5548 TemplateArgumentLocContainerIterator Old(*this);
5553 TemplateArgumentLoc operator*() const {
5554 return Container->getArgLoc(Index);
5557 pointer operator->() const {
5558 return pointer(Container->getArgLoc(Index));
5561 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
5562 const TemplateArgumentLocContainerIterator &Y) {
5563 return X.Container == Y.Container && X.Index == Y.Index;
5566 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
5567 const TemplateArgumentLocContainerIterator &Y) {
5573 template <typename Derived>
5574 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5575 TypeLocBuilder &TLB,
5576 TemplateSpecializationTypeLoc TL,
5577 TemplateName Template) {
5578 TemplateArgumentListInfo NewTemplateArgs;
5579 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5580 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5581 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5583 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5584 ArgIterator(TL, TL.getNumArgs()),
5588 // FIXME: maybe don't rebuild if all the template arguments are the same.
5591 getDerived().RebuildTemplateSpecializationType(Template,
5592 TL.getTemplateNameLoc(),
5595 if (!Result.isNull()) {
5596 // Specializations of template template parameters are represented as
5597 // TemplateSpecializationTypes, and substitution of type alias templates
5598 // within a dependent context can transform them into
5599 // DependentTemplateSpecializationTypes.
5600 if (isa<DependentTemplateSpecializationType>(Result)) {
5601 DependentTemplateSpecializationTypeLoc NewTL
5602 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5603 NewTL.setElaboratedKeywordLoc(SourceLocation());
5604 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5605 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5606 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5607 NewTL.setLAngleLoc(TL.getLAngleLoc());
5608 NewTL.setRAngleLoc(TL.getRAngleLoc());
5609 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5610 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5614 TemplateSpecializationTypeLoc NewTL
5615 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5616 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5617 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5618 NewTL.setLAngleLoc(TL.getLAngleLoc());
5619 NewTL.setRAngleLoc(TL.getRAngleLoc());
5620 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5621 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5627 template <typename Derived>
5628 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5629 TypeLocBuilder &TLB,
5630 DependentTemplateSpecializationTypeLoc TL,
5631 TemplateName Template,
5633 TemplateArgumentListInfo NewTemplateArgs;
5634 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5635 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5636 typedef TemplateArgumentLocContainerIterator<
5637 DependentTemplateSpecializationTypeLoc> ArgIterator;
5638 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5639 ArgIterator(TL, TL.getNumArgs()),
5643 // FIXME: maybe don't rebuild if all the template arguments are the same.
5645 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5647 = getSema().Context.getDependentTemplateSpecializationType(
5648 TL.getTypePtr()->getKeyword(),
5649 DTN->getQualifier(),
5650 DTN->getIdentifier(),
5653 DependentTemplateSpecializationTypeLoc NewTL
5654 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5655 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5656 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5657 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5658 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5659 NewTL.setLAngleLoc(TL.getLAngleLoc());
5660 NewTL.setRAngleLoc(TL.getRAngleLoc());
5661 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5662 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5667 = getDerived().RebuildTemplateSpecializationType(Template,
5668 TL.getTemplateNameLoc(),
5671 if (!Result.isNull()) {
5672 /// FIXME: Wrap this in an elaborated-type-specifier?
5673 TemplateSpecializationTypeLoc NewTL
5674 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5675 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5676 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5677 NewTL.setLAngleLoc(TL.getLAngleLoc());
5678 NewTL.setRAngleLoc(TL.getRAngleLoc());
5679 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5680 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5686 template<typename Derived>
5688 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
5689 ElaboratedTypeLoc TL) {
5690 const ElaboratedType *T = TL.getTypePtr();
5692 NestedNameSpecifierLoc QualifierLoc;
5693 // NOTE: the qualifier in an ElaboratedType is optional.
5694 if (TL.getQualifierLoc()) {
5696 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5701 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5702 if (NamedT.isNull())
5705 // C++0x [dcl.type.elab]p2:
5706 // If the identifier resolves to a typedef-name or the simple-template-id
5707 // resolves to an alias template specialization, the
5708 // elaborated-type-specifier is ill-formed.
5709 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5710 if (const TemplateSpecializationType *TST =
5711 NamedT->getAs<TemplateSpecializationType>()) {
5712 TemplateName Template = TST->getTemplateName();
5713 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5714 Template.getAsTemplateDecl())) {
5715 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5716 diag::err_tag_reference_non_tag)
5717 << TAT << Sema::NTK_TypeAliasTemplate
5718 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
5719 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5724 QualType Result = TL.getType();
5725 if (getDerived().AlwaysRebuild() ||
5726 QualifierLoc != TL.getQualifierLoc() ||
5727 NamedT != T->getNamedType()) {
5728 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5730 QualifierLoc, NamedT);
5731 if (Result.isNull())
5735 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5736 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5737 NewTL.setQualifierLoc(QualifierLoc);
5741 template<typename Derived>
5742 QualType TreeTransform<Derived>::TransformAttributedType(
5743 TypeLocBuilder &TLB,
5744 AttributedTypeLoc TL) {
5745 const AttributedType *oldType = TL.getTypePtr();
5746 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5747 if (modifiedType.isNull())
5750 QualType result = TL.getType();
5752 // FIXME: dependent operand expressions?
5753 if (getDerived().AlwaysRebuild() ||
5754 modifiedType != oldType->getModifiedType()) {
5755 // TODO: this is really lame; we should really be rebuilding the
5756 // equivalent type from first principles.
5757 QualType equivalentType
5758 = getDerived().TransformType(oldType->getEquivalentType());
5759 if (equivalentType.isNull())
5762 // Check whether we can add nullability; it is only represented as
5763 // type sugar, and therefore cannot be diagnosed in any other way.
5764 if (auto nullability = oldType->getImmediateNullability()) {
5765 if (!modifiedType->canHaveNullability()) {
5766 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
5767 << DiagNullabilityKind(*nullability, false) << modifiedType;
5772 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5777 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5778 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5779 if (TL.hasAttrOperand())
5780 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5781 if (TL.hasAttrExprOperand())
5782 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5783 else if (TL.hasAttrEnumOperand())
5784 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5789 template<typename Derived>
5791 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5793 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5797 QualType Result = TL.getType();
5798 if (getDerived().AlwaysRebuild() ||
5799 Inner != TL.getInnerLoc().getType()) {
5800 Result = getDerived().RebuildParenType(Inner);
5801 if (Result.isNull())
5805 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5806 NewTL.setLParenLoc(TL.getLParenLoc());
5807 NewTL.setRParenLoc(TL.getRParenLoc());
5811 template<typename Derived>
5812 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5813 DependentNameTypeLoc TL) {
5814 const DependentNameType *T = TL.getTypePtr();
5816 NestedNameSpecifierLoc QualifierLoc
5817 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5822 = getDerived().RebuildDependentNameType(T->getKeyword(),
5823 TL.getElaboratedKeywordLoc(),
5827 if (Result.isNull())
5830 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5831 QualType NamedT = ElabT->getNamedType();
5832 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5834 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5835 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5836 NewTL.setQualifierLoc(QualifierLoc);
5838 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5839 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5840 NewTL.setQualifierLoc(QualifierLoc);
5841 NewTL.setNameLoc(TL.getNameLoc());
5846 template<typename Derived>
5847 QualType TreeTransform<Derived>::
5848 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5849 DependentTemplateSpecializationTypeLoc TL) {
5850 NestedNameSpecifierLoc QualifierLoc;
5851 if (TL.getQualifierLoc()) {
5853 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5859 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5862 template<typename Derived>
5863 QualType TreeTransform<Derived>::
5864 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5865 DependentTemplateSpecializationTypeLoc TL,
5866 NestedNameSpecifierLoc QualifierLoc) {
5867 const DependentTemplateSpecializationType *T = TL.getTypePtr();
5869 TemplateArgumentListInfo NewTemplateArgs;
5870 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5871 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5873 typedef TemplateArgumentLocContainerIterator<
5874 DependentTemplateSpecializationTypeLoc> ArgIterator;
5875 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5876 ArgIterator(TL, TL.getNumArgs()),
5881 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5884 TL.getTemplateNameLoc(),
5886 if (Result.isNull())
5889 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5890 QualType NamedT = ElabT->getNamedType();
5892 // Copy information relevant to the template specialization.
5893 TemplateSpecializationTypeLoc NamedTL
5894 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5895 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5896 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5897 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5898 NamedTL.setRAngleLoc(TL.getRAngleLoc());
5899 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5900 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5902 // Copy information relevant to the elaborated type.
5903 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5904 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5905 NewTL.setQualifierLoc(QualifierLoc);
5906 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5907 DependentTemplateSpecializationTypeLoc SpecTL
5908 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5909 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5910 SpecTL.setQualifierLoc(QualifierLoc);
5911 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5912 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5913 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5914 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5915 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5916 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5918 TemplateSpecializationTypeLoc SpecTL
5919 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5920 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5921 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5922 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5923 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5924 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5925 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5930 template<typename Derived>
5931 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5932 PackExpansionTypeLoc TL) {
5934 = getDerived().TransformType(TLB, TL.getPatternLoc());
5935 if (Pattern.isNull())
5938 QualType Result = TL.getType();
5939 if (getDerived().AlwaysRebuild() ||
5940 Pattern != TL.getPatternLoc().getType()) {
5941 Result = getDerived().RebuildPackExpansionType(Pattern,
5942 TL.getPatternLoc().getSourceRange(),
5943 TL.getEllipsisLoc(),
5944 TL.getTypePtr()->getNumExpansions());
5945 if (Result.isNull())
5949 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5950 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5954 template<typename Derived>
5956 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5957 ObjCInterfaceTypeLoc TL) {
5958 // ObjCInterfaceType is never dependent.
5959 TLB.pushFullCopy(TL);
5960 return TL.getType();
5963 template<typename Derived>
5965 TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
5966 ObjCTypeParamTypeLoc TL) {
5967 const ObjCTypeParamType *T = TL.getTypePtr();
5968 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
5969 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
5973 QualType Result = TL.getType();
5974 if (getDerived().AlwaysRebuild() ||
5975 OTP != T->getDecl()) {
5976 Result = getDerived().RebuildObjCTypeParamType(OTP,
5977 TL.getProtocolLAngleLoc(),
5978 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5979 TL.getNumProtocols()),
5980 TL.getProtocolLocs(),
5981 TL.getProtocolRAngleLoc());
5982 if (Result.isNull())
5986 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
5987 if (TL.getNumProtocols()) {
5988 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5989 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5990 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
5991 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5996 template<typename Derived>
5998 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5999 ObjCObjectTypeLoc TL) {
6000 // Transform base type.
6001 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6002 if (BaseType.isNull())
6005 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6007 // Transform type arguments.
6008 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6009 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6010 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6011 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6012 QualType TypeArg = TypeArgInfo->getType();
6013 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6016 // We have a pack expansion. Instantiate it.
6017 const auto *PackExpansion = PackExpansionLoc.getType()
6018 ->castAs<PackExpansionType>();
6019 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6020 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6022 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6024 // Determine whether the set of unexpanded parameter packs can
6025 // and should be expanded.
6026 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6027 bool Expand = false;
6028 bool RetainExpansion = false;
6029 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6030 if (getDerived().TryExpandParameterPacks(
6031 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6032 Unexpanded, Expand, RetainExpansion, NumExpansions))
6036 // We can't expand this pack expansion into separate arguments yet;
6037 // just substitute into the pattern and create a new pack expansion
6039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6041 TypeLocBuilder TypeArgBuilder;
6042 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6043 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6045 if (NewPatternType.isNull())
6048 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6049 NewPatternType, NumExpansions);
6050 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6051 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6052 NewTypeArgInfos.push_back(
6053 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6057 // Substitute into the pack expansion pattern for each slice of the
6059 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6062 TypeLocBuilder TypeArgBuilder;
6063 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6065 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6067 if (NewTypeArg.isNull())
6070 NewTypeArgInfos.push_back(
6071 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6077 TypeLocBuilder TypeArgBuilder;
6078 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6079 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6080 if (NewTypeArg.isNull())
6083 // If nothing changed, just keep the old TypeSourceInfo.
6084 if (NewTypeArg == TypeArg) {
6085 NewTypeArgInfos.push_back(TypeArgInfo);
6089 NewTypeArgInfos.push_back(
6090 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6094 QualType Result = TL.getType();
6095 if (getDerived().AlwaysRebuild() || AnyChanged) {
6096 // Rebuild the type.
6097 Result = getDerived().RebuildObjCObjectType(
6100 TL.getTypeArgsLAngleLoc(),
6102 TL.getTypeArgsRAngleLoc(),
6103 TL.getProtocolLAngleLoc(),
6104 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6105 TL.getNumProtocols()),
6106 TL.getProtocolLocs(),
6107 TL.getProtocolRAngleLoc());
6109 if (Result.isNull())
6113 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
6114 NewT.setHasBaseTypeAsWritten(true);
6115 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6116 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6117 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6118 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6119 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6120 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6121 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6122 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6126 template<typename Derived>
6128 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
6129 ObjCObjectPointerTypeLoc TL) {
6130 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6131 if (PointeeType.isNull())
6134 QualType Result = TL.getType();
6135 if (getDerived().AlwaysRebuild() ||
6136 PointeeType != TL.getPointeeLoc().getType()) {
6137 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6139 if (Result.isNull())
6143 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6144 NewT.setStarLoc(TL.getStarLoc());
6148 //===----------------------------------------------------------------------===//
6149 // Statement transformation
6150 //===----------------------------------------------------------------------===//
6151 template<typename Derived>
6153 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
6157 template<typename Derived>
6159 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6160 return getDerived().TransformCompoundStmt(S, false);
6163 template<typename Derived>
6165 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
6167 Sema::CompoundScopeRAII CompoundScope(getSema());
6169 bool SubStmtInvalid = false;
6170 bool SubStmtChanged = false;
6171 SmallVector<Stmt*, 8> Statements;
6172 for (auto *B : S->body()) {
6173 StmtResult Result = getDerived().TransformStmt(B);
6174 if (Result.isInvalid()) {
6175 // Immediately fail if this was a DeclStmt, since it's very
6176 // likely that this will cause problems for future statements.
6177 if (isa<DeclStmt>(B))
6180 // Otherwise, just keep processing substatements and fail later.
6181 SubStmtInvalid = true;
6185 SubStmtChanged = SubStmtChanged || Result.get() != B;
6186 Statements.push_back(Result.getAs<Stmt>());
6192 if (!getDerived().AlwaysRebuild() &&
6196 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6202 template<typename Derived>
6204 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6205 ExprResult LHS, RHS;
6207 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6208 Sema::ConstantEvaluated);
6210 // Transform the left-hand case value.
6211 LHS = getDerived().TransformExpr(S->getLHS());
6212 LHS = SemaRef.ActOnConstantExpression(LHS);
6213 if (LHS.isInvalid())
6216 // Transform the right-hand case value (for the GNU case-range extension).
6217 RHS = getDerived().TransformExpr(S->getRHS());
6218 RHS = SemaRef.ActOnConstantExpression(RHS);
6219 if (RHS.isInvalid())
6223 // Build the case statement.
6224 // Case statements are always rebuilt so that they will attached to their
6225 // transformed switch statement.
6226 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6228 S->getEllipsisLoc(),
6231 if (Case.isInvalid())
6234 // Transform the statement following the case
6235 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6236 if (SubStmt.isInvalid())
6239 // Attach the body to the case statement
6240 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6243 template<typename Derived>
6245 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6246 // Transform the statement following the default case
6247 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6248 if (SubStmt.isInvalid())
6251 // Default statements are always rebuilt
6252 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6256 template<typename Derived>
6258 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6259 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6260 if (SubStmt.isInvalid())
6263 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6269 // FIXME: Pass the real colon location in.
6270 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6271 cast<LabelDecl>(LD), SourceLocation(),
6275 template <typename Derived>
6276 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6280 switch (R->getKind()) {
6281 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6283 #define PRAGMA_SPELLING_ATTR(X) \
6285 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6286 #include "clang/Basic/AttrList.inc"
6292 template <typename Derived>
6293 StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6294 bool AttrsChanged = false;
6295 SmallVector<const Attr *, 1> Attrs;
6297 // Visit attributes and keep track if any are transformed.
6298 for (const auto *I : S->getAttrs()) {
6299 const Attr *R = getDerived().TransformAttr(I);
6300 AttrsChanged |= (I != R);
6304 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6305 if (SubStmt.isInvalid())
6308 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6311 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6315 template<typename Derived>
6317 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6318 // Transform the initialization statement
6319 StmtResult Init = getDerived().TransformStmt(S->getInit());
6320 if (Init.isInvalid())
6323 // Transform the condition
6324 Sema::ConditionResult Cond = getDerived().TransformCondition(
6325 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6326 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6327 : Sema::ConditionKind::Boolean);
6328 if (Cond.isInvalid())
6331 // If this is a constexpr if, determine which arm we should instantiate.
6332 llvm::Optional<bool> ConstexprConditionValue;
6333 if (S->isConstexpr())
6334 ConstexprConditionValue = Cond.getKnownValue();
6336 // Transform the "then" branch.
6338 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6339 Then = getDerived().TransformStmt(S->getThen());
6340 if (Then.isInvalid())
6343 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6346 // Transform the "else" branch.
6348 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6349 Else = getDerived().TransformStmt(S->getElse());
6350 if (Else.isInvalid())
6354 if (!getDerived().AlwaysRebuild() &&
6355 Init.get() == S->getInit() &&
6356 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6357 Then.get() == S->getThen() &&
6358 Else.get() == S->getElse())
6361 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6362 Init.get(), Then.get(), S->getElseLoc(),
6366 template<typename Derived>
6368 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6369 // Transform the initialization statement
6370 StmtResult Init = getDerived().TransformStmt(S->getInit());
6371 if (Init.isInvalid())
6374 // Transform the condition.
6375 Sema::ConditionResult Cond = getDerived().TransformCondition(
6376 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6377 Sema::ConditionKind::Switch);
6378 if (Cond.isInvalid())
6381 // Rebuild the switch statement.
6383 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6384 S->getInit(), Cond);
6385 if (Switch.isInvalid())
6388 // Transform the body of the switch statement.
6389 StmtResult Body = getDerived().TransformStmt(S->getBody());
6390 if (Body.isInvalid())
6393 // Complete the switch statement.
6394 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6398 template<typename Derived>
6400 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6401 // Transform the condition
6402 Sema::ConditionResult Cond = getDerived().TransformCondition(
6403 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6404 Sema::ConditionKind::Boolean);
6405 if (Cond.isInvalid())
6408 // Transform the body
6409 StmtResult Body = getDerived().TransformStmt(S->getBody());
6410 if (Body.isInvalid())
6413 if (!getDerived().AlwaysRebuild() &&
6414 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6415 Body.get() == S->getBody())
6418 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
6421 template<typename Derived>
6423 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6424 // Transform the body
6425 StmtResult Body = getDerived().TransformStmt(S->getBody());
6426 if (Body.isInvalid())
6429 // Transform the condition
6430 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6431 if (Cond.isInvalid())
6434 if (!getDerived().AlwaysRebuild() &&
6435 Cond.get() == S->getCond() &&
6436 Body.get() == S->getBody())
6439 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6440 /*FIXME:*/S->getWhileLoc(), Cond.get(),
6444 template<typename Derived>
6446 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6447 // Transform the initialization statement
6448 StmtResult Init = getDerived().TransformStmt(S->getInit());
6449 if (Init.isInvalid())
6452 // In OpenMP loop region loop control variable must be captured and be
6453 // private. Perform analysis of first part (if any).
6454 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6455 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6457 // Transform the condition
6458 Sema::ConditionResult Cond = getDerived().TransformCondition(
6459 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6460 Sema::ConditionKind::Boolean);
6461 if (Cond.isInvalid())
6464 // Transform the increment
6465 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6466 if (Inc.isInvalid())
6469 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6470 if (S->getInc() && !FullInc.get())
6473 // Transform the body
6474 StmtResult Body = getDerived().TransformStmt(S->getBody());
6475 if (Body.isInvalid())
6478 if (!getDerived().AlwaysRebuild() &&
6479 Init.get() == S->getInit() &&
6480 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6481 Inc.get() == S->getInc() &&
6482 Body.get() == S->getBody())
6485 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6486 Init.get(), Cond, FullInc,
6487 S->getRParenLoc(), Body.get());
6490 template<typename Derived>
6492 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6493 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6498 // Goto statements must always be rebuilt, to resolve the label.
6499 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6500 cast<LabelDecl>(LD));
6503 template<typename Derived>
6505 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6506 ExprResult Target = getDerived().TransformExpr(S->getTarget());
6507 if (Target.isInvalid())
6509 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6511 if (!getDerived().AlwaysRebuild() &&
6512 Target.get() == S->getTarget())
6515 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6519 template<typename Derived>
6521 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6525 template<typename Derived>
6527 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6531 template<typename Derived>
6533 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6534 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6535 /*NotCopyInit*/false);
6536 if (Result.isInvalid())
6539 // FIXME: We always rebuild the return statement because there is no way
6540 // to tell whether the return type of the function has changed.
6541 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6544 template<typename Derived>
6546 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6547 bool DeclChanged = false;
6548 SmallVector<Decl *, 4> Decls;
6549 for (auto *D : S->decls()) {
6550 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6554 if (Transformed != D)
6557 Decls.push_back(Transformed);
6560 if (!getDerived().AlwaysRebuild() && !DeclChanged)
6563 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6566 template<typename Derived>
6568 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6570 SmallVector<Expr*, 8> Constraints;
6571 SmallVector<Expr*, 8> Exprs;
6572 SmallVector<IdentifierInfo *, 4> Names;
6574 ExprResult AsmString;
6575 SmallVector<Expr*, 8> Clobbers;
6577 bool ExprsChanged = false;
6579 // Go through the outputs.
6580 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6581 Names.push_back(S->getOutputIdentifier(I));
6583 // No need to transform the constraint literal.
6584 Constraints.push_back(S->getOutputConstraintLiteral(I));
6586 // Transform the output expr.
6587 Expr *OutputExpr = S->getOutputExpr(I);
6588 ExprResult Result = getDerived().TransformExpr(OutputExpr);
6589 if (Result.isInvalid())
6592 ExprsChanged |= Result.get() != OutputExpr;
6594 Exprs.push_back(Result.get());
6597 // Go through the inputs.
6598 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6599 Names.push_back(S->getInputIdentifier(I));
6601 // No need to transform the constraint literal.
6602 Constraints.push_back(S->getInputConstraintLiteral(I));
6604 // Transform the input expr.
6605 Expr *InputExpr = S->getInputExpr(I);
6606 ExprResult Result = getDerived().TransformExpr(InputExpr);
6607 if (Result.isInvalid())
6610 ExprsChanged |= Result.get() != InputExpr;
6612 Exprs.push_back(Result.get());
6615 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6618 // Go through the clobbers.
6619 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6620 Clobbers.push_back(S->getClobberStringLiteral(I));
6622 // No need to transform the asm string literal.
6623 AsmString = S->getAsmString();
6624 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6625 S->isVolatile(), S->getNumOutputs(),
6626 S->getNumInputs(), Names.data(),
6627 Constraints, Exprs, AsmString.get(),
6628 Clobbers, S->getRParenLoc());
6631 template<typename Derived>
6633 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6634 ArrayRef<Token> AsmToks =
6635 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6637 bool HadError = false, HadChange = false;
6639 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6640 SmallVector<Expr*, 8> TransformedExprs;
6641 TransformedExprs.reserve(SrcExprs.size());
6642 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6643 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6644 if (!Result.isUsable()) {
6647 HadChange |= (Result.get() != SrcExprs[i]);
6648 TransformedExprs.push_back(Result.get());
6652 if (HadError) return StmtError();
6653 if (!HadChange && !getDerived().AlwaysRebuild())
6656 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6657 AsmToks, S->getAsmString(),
6658 S->getNumOutputs(), S->getNumInputs(),
6659 S->getAllConstraints(), S->getClobbers(),
6660 TransformedExprs, S->getEndLoc());
6663 // C++ Coroutines TS
6665 template<typename Derived>
6667 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6668 // The coroutine body should be re-formed by the caller if necessary.
6669 // FIXME: The coroutine body is always rebuilt by ActOnFinishFunctionBody
6670 return getDerived().TransformStmt(S->getBody());
6673 template<typename Derived>
6675 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6676 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6677 /*NotCopyInit*/false);
6678 if (Result.isInvalid())
6681 // Always rebuild; we don't know if this needs to be injected into a new
6682 // context or if the promise type has changed.
6683 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6686 template<typename Derived>
6688 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6689 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6690 /*NotCopyInit*/false);
6691 if (Result.isInvalid())
6694 // Always rebuild; we don't know if this needs to be injected into a new
6695 // context or if the promise type has changed.
6696 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6699 template<typename Derived>
6701 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6702 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6703 /*NotCopyInit*/false);
6704 if (Result.isInvalid())
6707 // Always rebuild; we don't know if this needs to be injected into a new
6708 // context or if the promise type has changed.
6709 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6712 // Objective-C Statements.
6714 template<typename Derived>
6716 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
6717 // Transform the body of the @try.
6718 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
6719 if (TryBody.isInvalid())
6722 // Transform the @catch statements (if present).
6723 bool AnyCatchChanged = false;
6724 SmallVector<Stmt*, 8> CatchStmts;
6725 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
6726 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
6727 if (Catch.isInvalid())
6729 if (Catch.get() != S->getCatchStmt(I))
6730 AnyCatchChanged = true;
6731 CatchStmts.push_back(Catch.get());
6734 // Transform the @finally statement (if present).
6736 if (S->getFinallyStmt()) {
6737 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6738 if (Finally.isInvalid())
6742 // If nothing changed, just retain this statement.
6743 if (!getDerived().AlwaysRebuild() &&
6744 TryBody.get() == S->getTryBody() &&
6746 Finally.get() == S->getFinallyStmt())
6749 // Build a new statement.
6750 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
6751 CatchStmts, Finally.get());
6754 template<typename Derived>
6756 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
6757 // Transform the @catch parameter, if there is one.
6758 VarDecl *Var = nullptr;
6759 if (VarDecl *FromVar = S->getCatchParamDecl()) {
6760 TypeSourceInfo *TSInfo = nullptr;
6761 if (FromVar->getTypeSourceInfo()) {
6762 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6769 T = TSInfo->getType();
6771 T = getDerived().TransformType(FromVar->getType());
6776 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6781 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
6782 if (Body.isInvalid())
6785 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
6790 template<typename Derived>
6792 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
6793 // Transform the body.
6794 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
6795 if (Body.isInvalid())
6798 // If nothing changed, just retain this statement.
6799 if (!getDerived().AlwaysRebuild() &&
6800 Body.get() == S->getFinallyBody())
6803 // Build a new statement.
6804 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
6808 template<typename Derived>
6810 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
6812 if (S->getThrowExpr()) {
6813 Operand = getDerived().TransformExpr(S->getThrowExpr());
6814 if (Operand.isInvalid())
6818 if (!getDerived().AlwaysRebuild() &&
6819 Operand.get() == S->getThrowExpr())
6822 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
6825 template<typename Derived>
6827 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
6828 ObjCAtSynchronizedStmt *S) {
6829 // Transform the object we are locking.
6830 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
6831 if (Object.isInvalid())
6834 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6836 if (Object.isInvalid())
6839 // Transform the body.
6840 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
6841 if (Body.isInvalid())
6844 // If nothing change, just retain the current statement.
6845 if (!getDerived().AlwaysRebuild() &&
6846 Object.get() == S->getSynchExpr() &&
6847 Body.get() == S->getSynchBody())
6850 // Build a new statement.
6851 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
6852 Object.get(), Body.get());
6855 template<typename Derived>
6857 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6858 ObjCAutoreleasePoolStmt *S) {
6859 // Transform the body.
6860 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6861 if (Body.isInvalid())
6864 // If nothing changed, just retain this statement.
6865 if (!getDerived().AlwaysRebuild() &&
6866 Body.get() == S->getSubStmt())
6869 // Build a new statement.
6870 return getDerived().RebuildObjCAutoreleasePoolStmt(
6871 S->getAtLoc(), Body.get());
6874 template<typename Derived>
6876 TreeTransform<Derived>::TransformObjCForCollectionStmt(
6877 ObjCForCollectionStmt *S) {
6878 // Transform the element statement.
6879 StmtResult Element = getDerived().TransformStmt(S->getElement());
6880 if (Element.isInvalid())
6883 // Transform the collection expression.
6884 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
6885 if (Collection.isInvalid())
6888 // Transform the body.
6889 StmtResult Body = getDerived().TransformStmt(S->getBody());
6890 if (Body.isInvalid())
6893 // If nothing changed, just retain this statement.
6894 if (!getDerived().AlwaysRebuild() &&
6895 Element.get() == S->getElement() &&
6896 Collection.get() == S->getCollection() &&
6897 Body.get() == S->getBody())
6900 // Build a new statement.
6901 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6908 template <typename Derived>
6909 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6910 // Transform the exception declaration, if any.
6911 VarDecl *Var = nullptr;
6912 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6914 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6918 Var = getDerived().RebuildExceptionDecl(
6919 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6920 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6921 if (!Var || Var->isInvalidDecl())
6925 // Transform the actual exception handler.
6926 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6927 if (Handler.isInvalid())
6930 if (!getDerived().AlwaysRebuild() && !Var &&
6931 Handler.get() == S->getHandlerBlock())
6934 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6937 template <typename Derived>
6938 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6939 // Transform the try block itself.
6940 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6941 if (TryBlock.isInvalid())
6944 // Transform the handlers.
6945 bool HandlerChanged = false;
6946 SmallVector<Stmt *, 8> Handlers;
6947 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6948 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6949 if (Handler.isInvalid())
6952 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6953 Handlers.push_back(Handler.getAs<Stmt>());
6956 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6960 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6964 template<typename Derived>
6966 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6967 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6968 if (Range.isInvalid())
6971 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6972 if (Begin.isInvalid())
6974 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6975 if (End.isInvalid())
6978 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6979 if (Cond.isInvalid())
6982 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
6983 if (Cond.isInvalid())
6986 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
6988 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6989 if (Inc.isInvalid())
6992 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
6994 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6995 if (LoopVar.isInvalid())
6998 StmtResult NewStmt = S;
6999 if (getDerived().AlwaysRebuild() ||
7000 Range.get() != S->getRangeStmt() ||
7001 Begin.get() != S->getBeginStmt() ||
7002 End.get() != S->getEndStmt() ||
7003 Cond.get() != S->getCond() ||
7004 Inc.get() != S->getInc() ||
7005 LoopVar.get() != S->getLoopVarStmt()) {
7006 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7008 S->getColonLoc(), Range.get(),
7009 Begin.get(), End.get(),
7011 Inc.get(), LoopVar.get(),
7013 if (NewStmt.isInvalid())
7017 StmtResult Body = getDerived().TransformStmt(S->getBody());
7018 if (Body.isInvalid())
7021 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7022 // it now so we have a new statement to attach the body to.
7023 if (Body.get() != S->getBody() && NewStmt.get() == S) {
7024 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7026 S->getColonLoc(), Range.get(),
7027 Begin.get(), End.get(),
7029 Inc.get(), LoopVar.get(),
7031 if (NewStmt.isInvalid())
7035 if (NewStmt.get() == S)
7038 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7041 template<typename Derived>
7043 TreeTransform<Derived>::TransformMSDependentExistsStmt(
7044 MSDependentExistsStmt *S) {
7045 // Transform the nested-name-specifier, if any.
7046 NestedNameSpecifierLoc QualifierLoc;
7047 if (S->getQualifierLoc()) {
7049 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7054 // Transform the declaration name.
7055 DeclarationNameInfo NameInfo = S->getNameInfo();
7056 if (NameInfo.getName()) {
7057 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7058 if (!NameInfo.getName())
7062 // Check whether anything changed.
7063 if (!getDerived().AlwaysRebuild() &&
7064 QualifierLoc == S->getQualifierLoc() &&
7065 NameInfo.getName() == S->getNameInfo().getName())
7068 // Determine whether this name exists, if we can.
7070 SS.Adopt(QualifierLoc);
7071 bool Dependent = false;
7072 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
7073 case Sema::IER_Exists:
7074 if (S->isIfExists())
7077 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7079 case Sema::IER_DoesNotExist:
7080 if (S->isIfNotExists())
7083 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7085 case Sema::IER_Dependent:
7089 case Sema::IER_Error:
7093 // We need to continue with the instantiation, so do so now.
7094 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7095 if (SubStmt.isInvalid())
7098 // If we have resolved the name, just transform to the substatement.
7102 // The name is still dependent, so build a dependent expression again.
7103 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7110 template<typename Derived>
7112 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7113 NestedNameSpecifierLoc QualifierLoc;
7114 if (E->getQualifierLoc()) {
7116 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7121 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7122 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7126 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7127 if (Base.isInvalid())
7130 return new (SemaRef.getASTContext())
7131 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7132 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7133 QualifierLoc, E->getMemberLoc());
7136 template <typename Derived>
7137 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7138 MSPropertySubscriptExpr *E) {
7139 auto BaseRes = getDerived().TransformExpr(E->getBase());
7140 if (BaseRes.isInvalid())
7142 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7143 if (IdxRes.isInvalid())
7146 if (!getDerived().AlwaysRebuild() &&
7147 BaseRes.get() == E->getBase() &&
7148 IdxRes.get() == E->getIdx())
7151 return getDerived().RebuildArraySubscriptExpr(
7152 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7155 template <typename Derived>
7156 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7157 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7158 if (TryBlock.isInvalid())
7161 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7162 if (Handler.isInvalid())
7165 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7166 Handler.get() == S->getHandler())
7169 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7170 TryBlock.get(), Handler.get());
7173 template <typename Derived>
7174 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7175 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7176 if (Block.isInvalid())
7179 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7182 template <typename Derived>
7183 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7184 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7185 if (FilterExpr.isInvalid())
7188 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7189 if (Block.isInvalid())
7192 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7196 template <typename Derived>
7197 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7198 if (isa<SEHFinallyStmt>(Handler))
7199 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7201 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7204 template<typename Derived>
7206 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7210 //===----------------------------------------------------------------------===//
7211 // OpenMP directive transformation
7212 //===----------------------------------------------------------------------===//
7213 template <typename Derived>
7214 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7215 OMPExecutableDirective *D) {
7217 // Transform the clauses
7218 llvm::SmallVector<OMPClause *, 16> TClauses;
7219 ArrayRef<OMPClause *> Clauses = D->clauses();
7220 TClauses.reserve(Clauses.size());
7221 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7224 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7225 OMPClause *Clause = getDerived().TransformOMPClause(*I);
7226 getDerived().getSema().EndOpenMPClause();
7228 TClauses.push_back(Clause);
7230 TClauses.push_back(nullptr);
7233 StmtResult AssociatedStmt;
7234 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7235 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7236 /*CurScope=*/nullptr);
7239 Sema::CompoundScopeRAII CompoundScope(getSema());
7240 Body = getDerived().TransformStmt(
7241 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7244 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7245 if (AssociatedStmt.isInvalid()) {
7249 if (TClauses.size() != Clauses.size()) {
7253 // Transform directive name for 'omp critical' directive.
7254 DeclarationNameInfo DirName;
7255 if (D->getDirectiveKind() == OMPD_critical) {
7256 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7257 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7259 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7260 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7261 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7262 } else if (D->getDirectiveKind() == OMPD_cancel) {
7263 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7266 return getDerived().RebuildOMPExecutableDirective(
7267 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7268 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7271 template <typename Derived>
7273 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7274 DeclarationNameInfo DirName;
7275 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7277 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7278 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7282 template <typename Derived>
7284 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7285 DeclarationNameInfo DirName;
7286 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7288 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7289 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7293 template <typename Derived>
7295 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7296 DeclarationNameInfo DirName;
7297 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7299 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7300 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7304 template <typename Derived>
7306 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7307 DeclarationNameInfo DirName;
7308 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7310 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7311 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7315 template <typename Derived>
7317 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7318 DeclarationNameInfo DirName;
7319 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7321 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7322 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7326 template <typename Derived>
7328 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7329 DeclarationNameInfo DirName;
7330 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7332 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7333 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7337 template <typename Derived>
7339 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7340 DeclarationNameInfo DirName;
7341 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7343 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7344 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7348 template <typename Derived>
7350 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7351 DeclarationNameInfo DirName;
7352 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7354 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7355 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7359 template <typename Derived>
7361 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7362 getDerived().getSema().StartOpenMPDSABlock(
7363 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7364 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7365 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7369 template <typename Derived>
7370 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7371 OMPParallelForDirective *D) {
7372 DeclarationNameInfo DirName;
7373 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7374 nullptr, D->getLocStart());
7375 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7376 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7380 template <typename Derived>
7381 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7382 OMPParallelForSimdDirective *D) {
7383 DeclarationNameInfo DirName;
7384 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7385 nullptr, D->getLocStart());
7386 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7387 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7391 template <typename Derived>
7392 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7393 OMPParallelSectionsDirective *D) {
7394 DeclarationNameInfo DirName;
7395 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7396 nullptr, D->getLocStart());
7397 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7398 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7402 template <typename Derived>
7404 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7405 DeclarationNameInfo DirName;
7406 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7408 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7409 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7413 template <typename Derived>
7414 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7415 OMPTaskyieldDirective *D) {
7416 DeclarationNameInfo DirName;
7417 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7419 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7420 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7424 template <typename Derived>
7426 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7427 DeclarationNameInfo DirName;
7428 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7430 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7431 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7435 template <typename Derived>
7437 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7438 DeclarationNameInfo DirName;
7439 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7441 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7442 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7446 template <typename Derived>
7447 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7448 OMPTaskgroupDirective *D) {
7449 DeclarationNameInfo DirName;
7450 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7452 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7453 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7457 template <typename Derived>
7459 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7460 DeclarationNameInfo DirName;
7461 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7463 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7464 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7468 template <typename Derived>
7470 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7471 DeclarationNameInfo DirName;
7472 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7474 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7475 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7479 template <typename Derived>
7481 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7482 DeclarationNameInfo DirName;
7483 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7485 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7486 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7490 template <typename Derived>
7492 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7493 DeclarationNameInfo DirName;
7494 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7496 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7497 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7501 template <typename Derived>
7502 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7503 OMPTargetDataDirective *D) {
7504 DeclarationNameInfo DirName;
7505 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7507 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7508 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7512 template <typename Derived>
7513 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7514 OMPTargetEnterDataDirective *D) {
7515 DeclarationNameInfo DirName;
7516 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7517 nullptr, D->getLocStart());
7518 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7519 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7523 template <typename Derived>
7524 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7525 OMPTargetExitDataDirective *D) {
7526 DeclarationNameInfo DirName;
7527 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7528 nullptr, D->getLocStart());
7529 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7530 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7534 template <typename Derived>
7535 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7536 OMPTargetParallelDirective *D) {
7537 DeclarationNameInfo DirName;
7538 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7539 nullptr, D->getLocStart());
7540 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7541 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7545 template <typename Derived>
7546 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7547 OMPTargetParallelForDirective *D) {
7548 DeclarationNameInfo DirName;
7549 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7550 nullptr, D->getLocStart());
7551 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7552 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7556 template <typename Derived>
7557 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7558 OMPTargetUpdateDirective *D) {
7559 DeclarationNameInfo DirName;
7560 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7561 nullptr, D->getLocStart());
7562 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7563 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7567 template <typename Derived>
7569 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7570 DeclarationNameInfo DirName;
7571 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7573 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7574 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7578 template <typename Derived>
7579 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7580 OMPCancellationPointDirective *D) {
7581 DeclarationNameInfo DirName;
7582 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7583 nullptr, D->getLocStart());
7584 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7585 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7589 template <typename Derived>
7591 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7592 DeclarationNameInfo DirName;
7593 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7595 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7596 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7600 template <typename Derived>
7602 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7603 DeclarationNameInfo DirName;
7604 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7606 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7607 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7611 template <typename Derived>
7612 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7613 OMPTaskLoopSimdDirective *D) {
7614 DeclarationNameInfo DirName;
7615 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7616 nullptr, D->getLocStart());
7617 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7618 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7622 template <typename Derived>
7623 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7624 OMPDistributeDirective *D) {
7625 DeclarationNameInfo DirName;
7626 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7628 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7629 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7633 template <typename Derived>
7634 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7635 OMPDistributeParallelForDirective *D) {
7636 DeclarationNameInfo DirName;
7637 getDerived().getSema().StartOpenMPDSABlock(
7638 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7639 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7640 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7644 template <typename Derived>
7646 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7647 OMPDistributeParallelForSimdDirective *D) {
7648 DeclarationNameInfo DirName;
7649 getDerived().getSema().StartOpenMPDSABlock(
7650 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7651 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7652 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7656 template <typename Derived>
7657 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7658 OMPDistributeSimdDirective *D) {
7659 DeclarationNameInfo DirName;
7660 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7661 nullptr, D->getLocStart());
7662 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7663 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7667 template <typename Derived>
7668 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7669 OMPTargetParallelForSimdDirective *D) {
7670 DeclarationNameInfo DirName;
7671 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7674 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7675 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7679 template <typename Derived>
7680 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7681 OMPTargetSimdDirective *D) {
7682 DeclarationNameInfo DirName;
7683 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7685 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7686 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7690 template <typename Derived>
7691 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
7692 OMPTeamsDistributeDirective *D) {
7693 DeclarationNameInfo DirName;
7694 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
7695 nullptr, D->getLocStart());
7696 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7697 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7701 template <typename Derived>
7702 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
7703 OMPTeamsDistributeSimdDirective *D) {
7704 DeclarationNameInfo DirName;
7705 getDerived().getSema().StartOpenMPDSABlock(
7706 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
7707 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7708 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7712 template <typename Derived>
7713 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
7714 OMPTeamsDistributeParallelForSimdDirective *D) {
7715 DeclarationNameInfo DirName;
7716 getDerived().getSema().StartOpenMPDSABlock(
7717 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7718 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7719 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7723 template <typename Derived>
7724 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
7725 OMPTeamsDistributeParallelForDirective *D) {
7726 DeclarationNameInfo DirName;
7727 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
7728 DirName, nullptr, D->getLocStart());
7729 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7730 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7734 template <typename Derived>
7735 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
7736 OMPTargetTeamsDirective *D) {
7737 DeclarationNameInfo DirName;
7738 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
7739 nullptr, D->getLocStart());
7740 auto Res = getDerived().TransformOMPExecutableDirective(D);
7741 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7745 template <typename Derived>
7746 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
7747 OMPTargetTeamsDistributeDirective *D) {
7748 DeclarationNameInfo DirName;
7749 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
7750 DirName, nullptr, D->getLocStart());
7751 auto Res = getDerived().TransformOMPExecutableDirective(D);
7752 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7756 template <typename Derived>
7758 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
7759 OMPTargetTeamsDistributeParallelForDirective *D) {
7760 DeclarationNameInfo DirName;
7761 getDerived().getSema().StartOpenMPDSABlock(
7762 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
7764 auto Res = getDerived().TransformOMPExecutableDirective(D);
7765 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7769 //===----------------------------------------------------------------------===//
7770 // OpenMP clause transformation
7771 //===----------------------------------------------------------------------===//
7772 template <typename Derived>
7773 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
7774 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7775 if (Cond.isInvalid())
7777 return getDerived().RebuildOMPIfClause(
7778 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7779 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
7782 template <typename Derived>
7783 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7784 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7785 if (Cond.isInvalid())
7787 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7788 C->getLParenLoc(), C->getLocEnd());
7791 template <typename Derived>
7793 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7794 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7795 if (NumThreads.isInvalid())
7797 return getDerived().RebuildOMPNumThreadsClause(
7798 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7801 template <typename Derived>
7803 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7804 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7807 return getDerived().RebuildOMPSafelenClause(
7808 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7811 template <typename Derived>
7813 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7814 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7817 return getDerived().RebuildOMPSimdlenClause(
7818 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7821 template <typename Derived>
7823 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7824 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7827 return getDerived().RebuildOMPCollapseClause(
7828 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7831 template <typename Derived>
7833 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
7834 return getDerived().RebuildOMPDefaultClause(
7835 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7836 C->getLParenLoc(), C->getLocEnd());
7839 template <typename Derived>
7841 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
7842 return getDerived().RebuildOMPProcBindClause(
7843 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7844 C->getLParenLoc(), C->getLocEnd());
7847 template <typename Derived>
7849 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7850 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7853 return getDerived().RebuildOMPScheduleClause(
7854 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
7855 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7856 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
7857 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7860 template <typename Derived>
7862 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7864 if (auto *Num = C->getNumForLoops()) {
7865 E = getDerived().TransformExpr(Num);
7869 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7870 C->getLParenLoc(), E.get());
7873 template <typename Derived>
7875 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7876 // No need to rebuild this clause, no template-dependent parameters.
7880 template <typename Derived>
7882 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7883 // No need to rebuild this clause, no template-dependent parameters.
7887 template <typename Derived>
7889 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7890 // No need to rebuild this clause, no template-dependent parameters.
7894 template <typename Derived>
7895 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7896 // No need to rebuild this clause, no template-dependent parameters.
7900 template <typename Derived>
7901 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7902 // No need to rebuild this clause, no template-dependent parameters.
7906 template <typename Derived>
7908 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7909 // No need to rebuild this clause, no template-dependent parameters.
7913 template <typename Derived>
7915 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7916 // No need to rebuild this clause, no template-dependent parameters.
7920 template <typename Derived>
7922 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7923 // No need to rebuild this clause, no template-dependent parameters.
7927 template <typename Derived>
7929 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7930 // No need to rebuild this clause, no template-dependent parameters.
7934 template <typename Derived>
7935 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7936 // No need to rebuild this clause, no template-dependent parameters.
7940 template <typename Derived>
7942 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7943 // No need to rebuild this clause, no template-dependent parameters.
7947 template <typename Derived>
7949 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
7950 llvm::SmallVector<Expr *, 16> Vars;
7951 Vars.reserve(C->varlist_size());
7952 for (auto *VE : C->varlists()) {
7953 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7954 if (EVar.isInvalid())
7956 Vars.push_back(EVar.get());
7958 return getDerived().RebuildOMPPrivateClause(
7959 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7962 template <typename Derived>
7963 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7964 OMPFirstprivateClause *C) {
7965 llvm::SmallVector<Expr *, 16> Vars;
7966 Vars.reserve(C->varlist_size());
7967 for (auto *VE : C->varlists()) {
7968 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7969 if (EVar.isInvalid())
7971 Vars.push_back(EVar.get());
7973 return getDerived().RebuildOMPFirstprivateClause(
7974 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7977 template <typename Derived>
7979 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7980 llvm::SmallVector<Expr *, 16> Vars;
7981 Vars.reserve(C->varlist_size());
7982 for (auto *VE : C->varlists()) {
7983 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7984 if (EVar.isInvalid())
7986 Vars.push_back(EVar.get());
7988 return getDerived().RebuildOMPLastprivateClause(
7989 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7992 template <typename Derived>
7994 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7995 llvm::SmallVector<Expr *, 16> Vars;
7996 Vars.reserve(C->varlist_size());
7997 for (auto *VE : C->varlists()) {
7998 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7999 if (EVar.isInvalid())
8001 Vars.push_back(EVar.get());
8003 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8004 C->getLParenLoc(), C->getLocEnd());
8007 template <typename Derived>
8009 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8010 llvm::SmallVector<Expr *, 16> Vars;
8011 Vars.reserve(C->varlist_size());
8012 for (auto *VE : C->varlists()) {
8013 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8014 if (EVar.isInvalid())
8016 Vars.push_back(EVar.get());
8018 CXXScopeSpec ReductionIdScopeSpec;
8019 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8021 DeclarationNameInfo NameInfo = C->getNameInfo();
8022 if (NameInfo.getName()) {
8023 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8024 if (!NameInfo.getName())
8027 // Build a list of all UDR decls with the same names ranged by the Scopes.
8028 // The Scope boundary is a duplication of the previous decl.
8029 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8030 for (auto *E : C->reduction_ops()) {
8031 // Transform all the decls.
8033 auto *ULE = cast<UnresolvedLookupExpr>(E);
8034 UnresolvedSet<8> Decls;
8035 for (auto *D : ULE->decls()) {
8037 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8038 Decls.addDecl(InstD, InstD->getAccess());
8040 UnresolvedReductions.push_back(
8041 UnresolvedLookupExpr::Create(
8042 SemaRef.Context, /*NamingClass=*/nullptr,
8043 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8044 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8045 Decls.begin(), Decls.end()));
8047 UnresolvedReductions.push_back(nullptr);
8049 return getDerived().RebuildOMPReductionClause(
8050 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8051 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8054 template <typename Derived>
8056 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8057 llvm::SmallVector<Expr *, 16> Vars;
8058 Vars.reserve(C->varlist_size());
8059 for (auto *VE : C->varlists()) {
8060 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8061 if (EVar.isInvalid())
8063 Vars.push_back(EVar.get());
8065 ExprResult Step = getDerived().TransformExpr(C->getStep());
8066 if (Step.isInvalid())
8068 return getDerived().RebuildOMPLinearClause(
8069 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8070 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
8073 template <typename Derived>
8075 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8076 llvm::SmallVector<Expr *, 16> Vars;
8077 Vars.reserve(C->varlist_size());
8078 for (auto *VE : C->varlists()) {
8079 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8080 if (EVar.isInvalid())
8082 Vars.push_back(EVar.get());
8084 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8085 if (Alignment.isInvalid())
8087 return getDerived().RebuildOMPAlignedClause(
8088 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8089 C->getColonLoc(), C->getLocEnd());
8092 template <typename Derived>
8094 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8095 llvm::SmallVector<Expr *, 16> Vars;
8096 Vars.reserve(C->varlist_size());
8097 for (auto *VE : C->varlists()) {
8098 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8099 if (EVar.isInvalid())
8101 Vars.push_back(EVar.get());
8103 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8104 C->getLParenLoc(), C->getLocEnd());
8107 template <typename Derived>
8109 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8110 llvm::SmallVector<Expr *, 16> Vars;
8111 Vars.reserve(C->varlist_size());
8112 for (auto *VE : C->varlists()) {
8113 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8114 if (EVar.isInvalid())
8116 Vars.push_back(EVar.get());
8118 return getDerived().RebuildOMPCopyprivateClause(
8119 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8122 template <typename Derived>
8123 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8124 llvm::SmallVector<Expr *, 16> Vars;
8125 Vars.reserve(C->varlist_size());
8126 for (auto *VE : C->varlists()) {
8127 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8128 if (EVar.isInvalid())
8130 Vars.push_back(EVar.get());
8132 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8133 C->getLParenLoc(), C->getLocEnd());
8136 template <typename Derived>
8138 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8139 llvm::SmallVector<Expr *, 16> Vars;
8140 Vars.reserve(C->varlist_size());
8141 for (auto *VE : C->varlists()) {
8142 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8143 if (EVar.isInvalid())
8145 Vars.push_back(EVar.get());
8147 return getDerived().RebuildOMPDependClause(
8148 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8149 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8152 template <typename Derived>
8154 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8155 ExprResult E = getDerived().TransformExpr(C->getDevice());
8158 return getDerived().RebuildOMPDeviceClause(
8159 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8162 template <typename Derived>
8163 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8164 llvm::SmallVector<Expr *, 16> Vars;
8165 Vars.reserve(C->varlist_size());
8166 for (auto *VE : C->varlists()) {
8167 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8168 if (EVar.isInvalid())
8170 Vars.push_back(EVar.get());
8172 return getDerived().RebuildOMPMapClause(
8173 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8174 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8175 C->getLParenLoc(), C->getLocEnd());
8178 template <typename Derived>
8180 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8181 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8184 return getDerived().RebuildOMPNumTeamsClause(
8185 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8188 template <typename Derived>
8190 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8191 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8194 return getDerived().RebuildOMPThreadLimitClause(
8195 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8198 template <typename Derived>
8200 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8201 ExprResult E = getDerived().TransformExpr(C->getPriority());
8204 return getDerived().RebuildOMPPriorityClause(
8205 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8208 template <typename Derived>
8210 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8211 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8214 return getDerived().RebuildOMPGrainsizeClause(
8215 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8218 template <typename Derived>
8220 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8221 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8224 return getDerived().RebuildOMPNumTasksClause(
8225 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8228 template <typename Derived>
8229 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8230 ExprResult E = getDerived().TransformExpr(C->getHint());
8233 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8234 C->getLParenLoc(), C->getLocEnd());
8237 template <typename Derived>
8238 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8239 OMPDistScheduleClause *C) {
8240 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8243 return getDerived().RebuildOMPDistScheduleClause(
8244 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8245 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8248 template <typename Derived>
8250 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8254 template <typename Derived>
8255 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8256 llvm::SmallVector<Expr *, 16> Vars;
8257 Vars.reserve(C->varlist_size());
8258 for (auto *VE : C->varlists()) {
8259 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8260 if (EVar.isInvalid())
8262 Vars.push_back(EVar.get());
8264 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8265 C->getLParenLoc(), C->getLocEnd());
8268 template <typename Derived>
8269 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8270 llvm::SmallVector<Expr *, 16> Vars;
8271 Vars.reserve(C->varlist_size());
8272 for (auto *VE : C->varlists()) {
8273 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8274 if (EVar.isInvalid())
8276 Vars.push_back(EVar.get());
8278 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8279 C->getLParenLoc(), C->getLocEnd());
8282 template <typename Derived>
8283 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8284 OMPUseDevicePtrClause *C) {
8285 llvm::SmallVector<Expr *, 16> Vars;
8286 Vars.reserve(C->varlist_size());
8287 for (auto *VE : C->varlists()) {
8288 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8289 if (EVar.isInvalid())
8291 Vars.push_back(EVar.get());
8293 return getDerived().RebuildOMPUseDevicePtrClause(
8294 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8297 template <typename Derived>
8299 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8300 llvm::SmallVector<Expr *, 16> Vars;
8301 Vars.reserve(C->varlist_size());
8302 for (auto *VE : C->varlists()) {
8303 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8304 if (EVar.isInvalid())
8306 Vars.push_back(EVar.get());
8308 return getDerived().RebuildOMPIsDevicePtrClause(
8309 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8312 //===----------------------------------------------------------------------===//
8313 // Expression transformation
8314 //===----------------------------------------------------------------------===//
8315 template<typename Derived>
8317 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
8318 if (!E->isTypeDependent())
8321 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8325 template<typename Derived>
8327 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
8328 NestedNameSpecifierLoc QualifierLoc;
8329 if (E->getQualifierLoc()) {
8331 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8337 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8342 DeclarationNameInfo NameInfo = E->getNameInfo();
8343 if (NameInfo.getName()) {
8344 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8345 if (!NameInfo.getName())
8349 if (!getDerived().AlwaysRebuild() &&
8350 QualifierLoc == E->getQualifierLoc() &&
8351 ND == E->getDecl() &&
8352 NameInfo.getName() == E->getDecl()->getDeclName() &&
8353 !E->hasExplicitTemplateArgs()) {
8355 // Mark it referenced in the new context regardless.
8356 // FIXME: this is a bit instantiation-specific.
8357 SemaRef.MarkDeclRefReferenced(E);
8362 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
8363 if (E->hasExplicitTemplateArgs()) {
8364 TemplateArgs = &TransArgs;
8365 TransArgs.setLAngleLoc(E->getLAngleLoc());
8366 TransArgs.setRAngleLoc(E->getRAngleLoc());
8367 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8368 E->getNumTemplateArgs(),
8373 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
8377 template<typename Derived>
8379 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
8383 template<typename Derived>
8385 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
8389 template<typename Derived>
8391 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
8395 template<typename Derived>
8397 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
8401 template<typename Derived>
8403 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
8407 template<typename Derived>
8409 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
8410 if (FunctionDecl *FD = E->getDirectCallee())
8411 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
8412 return SemaRef.MaybeBindToTemporary(E);
8415 template<typename Derived>
8417 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8418 ExprResult ControllingExpr =
8419 getDerived().TransformExpr(E->getControllingExpr());
8420 if (ControllingExpr.isInvalid())
8423 SmallVector<Expr *, 4> AssocExprs;
8424 SmallVector<TypeSourceInfo *, 4> AssocTypes;
8425 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8426 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8428 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8431 AssocTypes.push_back(AssocType);
8433 AssocTypes.push_back(nullptr);
8436 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8437 if (AssocExpr.isInvalid())
8439 AssocExprs.push_back(AssocExpr.get());
8442 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8445 ControllingExpr.get(),
8450 template<typename Derived>
8452 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
8453 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8454 if (SubExpr.isInvalid())
8457 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8460 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
8464 /// \brief The operand of a unary address-of operator has special rules: it's
8465 /// allowed to refer to a non-static member of a class even if there's no 'this'
8466 /// object available.
8467 template<typename Derived>
8469 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8470 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
8471 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
8473 return getDerived().TransformExpr(E);
8476 template<typename Derived>
8478 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
8480 if (E->getOpcode() == UO_AddrOf)
8481 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8483 SubExpr = TransformExpr(E->getSubExpr());
8484 if (SubExpr.isInvalid())
8487 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8490 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8495 template<typename Derived>
8497 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8498 // Transform the type.
8499 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8503 // Transform all of the components into components similar to what the
8505 // FIXME: It would be slightly more efficient in the non-dependent case to
8506 // just map FieldDecls, rather than requiring the rebuilder to look for
8507 // the fields again. However, __builtin_offsetof is rare enough in
8508 // template code that we don't care.
8509 bool ExprChanged = false;
8510 typedef Sema::OffsetOfComponent Component;
8511 SmallVector<Component, 4> Components;
8512 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8513 const OffsetOfNode &ON = E->getComponent(I);
8515 Comp.isBrackets = true;
8516 Comp.LocStart = ON.getSourceRange().getBegin();
8517 Comp.LocEnd = ON.getSourceRange().getEnd();
8518 switch (ON.getKind()) {
8519 case OffsetOfNode::Array: {
8520 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
8521 ExprResult Index = getDerived().TransformExpr(FromIndex);
8522 if (Index.isInvalid())
8525 ExprChanged = ExprChanged || Index.get() != FromIndex;
8526 Comp.isBrackets = true;
8527 Comp.U.E = Index.get();
8531 case OffsetOfNode::Field:
8532 case OffsetOfNode::Identifier:
8533 Comp.isBrackets = false;
8534 Comp.U.IdentInfo = ON.getFieldName();
8535 if (!Comp.U.IdentInfo)
8540 case OffsetOfNode::Base:
8541 // Will be recomputed during the rebuild.
8545 Components.push_back(Comp);
8548 // If nothing changed, retain the existing expression.
8549 if (!getDerived().AlwaysRebuild() &&
8550 Type == E->getTypeSourceInfo() &&
8554 // Build a new offsetof expression.
8555 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
8556 Components, E->getRParenLoc());
8559 template<typename Derived>
8561 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
8562 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
8563 "opaque value expression requires transformation");
8567 template<typename Derived>
8569 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8573 template<typename Derived>
8575 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
8576 // Rebuild the syntactic form. The original syntactic form has
8577 // opaque-value expressions in it, so strip those away and rebuild
8578 // the result. This is a really awful way of doing this, but the
8579 // better solution (rebuilding the semantic expressions and
8580 // rebinding OVEs as necessary) doesn't work; we'd need
8581 // TreeTransform to not strip away implicit conversions.
8582 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8583 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
8584 if (result.isInvalid()) return ExprError();
8586 // If that gives us a pseudo-object result back, the pseudo-object
8587 // expression must have been an lvalue-to-rvalue conversion which we
8589 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
8590 result = SemaRef.checkPseudoObjectRValue(result.get());
8595 template<typename Derived>
8597 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8598 UnaryExprOrTypeTraitExpr *E) {
8599 if (E->isArgumentType()) {
8600 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
8602 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8606 if (!getDerived().AlwaysRebuild() && OldT == NewT)
8609 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8611 E->getSourceRange());
8614 // C++0x [expr.sizeof]p1:
8615 // The operand is either an expression, which is an unevaluated operand
8617 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8618 Sema::ReuseLambdaContextDecl);
8620 // Try to recover if we have something like sizeof(T::X) where X is a type.
8621 // Notably, there must be *exactly* one set of parens if X is a type.
8622 TypeSourceInfo *RecoveryTSI = nullptr;
8624 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8626 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8627 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8628 PE, DRE, false, &RecoveryTSI);
8630 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8633 return getDerived().RebuildUnaryExprOrTypeTrait(
8634 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8635 } else if (SubExpr.isInvalid())
8638 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
8641 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8642 E->getOperatorLoc(),
8644 E->getSourceRange());
8647 template<typename Derived>
8649 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
8650 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8651 if (LHS.isInvalid())
8654 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8655 if (RHS.isInvalid())
8659 if (!getDerived().AlwaysRebuild() &&
8660 LHS.get() == E->getLHS() &&
8661 RHS.get() == E->getRHS())
8664 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
8665 /*FIXME:*/E->getLHS()->getLocStart(),
8667 E->getRBracketLoc());
8670 template <typename Derived>
8672 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8673 ExprResult Base = getDerived().TransformExpr(E->getBase());
8674 if (Base.isInvalid())
8677 ExprResult LowerBound;
8678 if (E->getLowerBound()) {
8679 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8680 if (LowerBound.isInvalid())
8685 if (E->getLength()) {
8686 Length = getDerived().TransformExpr(E->getLength());
8687 if (Length.isInvalid())
8691 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8692 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8695 return getDerived().RebuildOMPArraySectionExpr(
8696 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8697 Length.get(), E->getRBracketLoc());
8700 template<typename Derived>
8702 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
8703 // Transform the callee.
8704 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8705 if (Callee.isInvalid())
8708 // Transform arguments.
8709 bool ArgChanged = false;
8710 SmallVector<Expr*, 8> Args;
8711 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8715 if (!getDerived().AlwaysRebuild() &&
8716 Callee.get() == E->getCallee() &&
8718 return SemaRef.MaybeBindToTemporary(E);
8720 // FIXME: Wrong source location information for the '('.
8721 SourceLocation FakeLParenLoc
8722 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8723 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
8728 template<typename Derived>
8730 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
8731 ExprResult Base = getDerived().TransformExpr(E->getBase());
8732 if (Base.isInvalid())
8735 NestedNameSpecifierLoc QualifierLoc;
8736 if (E->hasQualifier()) {
8738 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8743 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8746 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8747 E->getMemberDecl()));
8751 NamedDecl *FoundDecl = E->getFoundDecl();
8752 if (FoundDecl == E->getMemberDecl()) {
8755 FoundDecl = cast_or_null<NamedDecl>(
8756 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8761 if (!getDerived().AlwaysRebuild() &&
8762 Base.get() == E->getBase() &&
8763 QualifierLoc == E->getQualifierLoc() &&
8764 Member == E->getMemberDecl() &&
8765 FoundDecl == E->getFoundDecl() &&
8766 !E->hasExplicitTemplateArgs()) {
8768 // Mark it referenced in the new context regardless.
8769 // FIXME: this is a bit instantiation-specific.
8770 SemaRef.MarkMemberReferenced(E);
8775 TemplateArgumentListInfo TransArgs;
8776 if (E->hasExplicitTemplateArgs()) {
8777 TransArgs.setLAngleLoc(E->getLAngleLoc());
8778 TransArgs.setRAngleLoc(E->getRAngleLoc());
8779 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8780 E->getNumTemplateArgs(),
8785 // FIXME: Bogus source location for the operator
8786 SourceLocation FakeOperatorLoc =
8787 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
8789 // FIXME: to do this check properly, we will need to preserve the
8790 // first-qualifier-in-scope here, just in case we had a dependent
8791 // base (and therefore couldn't do the check) and a
8792 // nested-name-qualifier (and therefore could do the lookup).
8793 NamedDecl *FirstQualifierInScope = nullptr;
8795 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
8799 E->getMemberNameInfo(),
8802 (E->hasExplicitTemplateArgs()
8803 ? &TransArgs : nullptr),
8804 FirstQualifierInScope);
8807 template<typename Derived>
8809 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
8810 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8811 if (LHS.isInvalid())
8814 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8815 if (RHS.isInvalid())
8818 if (!getDerived().AlwaysRebuild() &&
8819 LHS.get() == E->getLHS() &&
8820 RHS.get() == E->getRHS())
8823 Sema::FPContractStateRAII FPContractState(getSema());
8824 getSema().FPFeatures.fp_contract = E->isFPContractable();
8826 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
8827 LHS.get(), RHS.get());
8830 template<typename Derived>
8832 TreeTransform<Derived>::TransformCompoundAssignOperator(
8833 CompoundAssignOperator *E) {
8834 return getDerived().TransformBinaryOperator(E);
8837 template<typename Derived>
8838 ExprResult TreeTransform<Derived>::
8839 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8840 // Just rebuild the common and RHS expressions and see whether we
8843 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8844 if (commonExpr.isInvalid())
8847 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8848 if (rhs.isInvalid())
8851 if (!getDerived().AlwaysRebuild() &&
8852 commonExpr.get() == e->getCommon() &&
8853 rhs.get() == e->getFalseExpr())
8856 return getDerived().RebuildConditionalOperator(commonExpr.get(),
8857 e->getQuestionLoc(),
8863 template<typename Derived>
8865 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
8866 ExprResult Cond = getDerived().TransformExpr(E->getCond());
8867 if (Cond.isInvalid())
8870 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8871 if (LHS.isInvalid())
8874 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8875 if (RHS.isInvalid())
8878 if (!getDerived().AlwaysRebuild() &&
8879 Cond.get() == E->getCond() &&
8880 LHS.get() == E->getLHS() &&
8881 RHS.get() == E->getRHS())
8884 return getDerived().RebuildConditionalOperator(Cond.get(),
8885 E->getQuestionLoc(),
8891 template<typename Derived>
8893 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
8894 // Implicit casts are eliminated during transformation, since they
8895 // will be recomputed by semantic analysis after transformation.
8896 return getDerived().TransformExpr(E->getSubExprAsWritten());
8899 template<typename Derived>
8901 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
8902 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8907 = getDerived().TransformExpr(E->getSubExprAsWritten());
8908 if (SubExpr.isInvalid())
8911 if (!getDerived().AlwaysRebuild() &&
8912 Type == E->getTypeInfoAsWritten() &&
8913 SubExpr.get() == E->getSubExpr())
8916 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
8922 template<typename Derived>
8924 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
8925 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8926 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8930 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
8931 if (Init.isInvalid())
8934 if (!getDerived().AlwaysRebuild() &&
8936 Init.get() == E->getInitializer())
8937 return SemaRef.MaybeBindToTemporary(E);
8939 // Note: the expression type doesn't necessarily match the
8940 // type-as-written, but that's okay, because it should always be
8941 // derivable from the initializer.
8943 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
8944 /*FIXME:*/E->getInitializer()->getLocEnd(),
8948 template<typename Derived>
8950 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
8951 ExprResult Base = getDerived().TransformExpr(E->getBase());
8952 if (Base.isInvalid())
8955 if (!getDerived().AlwaysRebuild() &&
8956 Base.get() == E->getBase())
8959 // FIXME: Bad source location
8960 SourceLocation FakeOperatorLoc =
8961 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
8962 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
8963 E->getAccessorLoc(),
8967 template<typename Derived>
8969 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
8970 if (InitListExpr *Syntactic = E->getSyntacticForm())
8973 bool InitChanged = false;
8975 SmallVector<Expr*, 4> Inits;
8976 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
8977 Inits, &InitChanged))
8980 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8981 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8982 // in some cases. We can't reuse it in general, because the syntactic and
8983 // semantic forms are linked, and we can't know that semantic form will
8984 // match even if the syntactic form does.
8987 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
8988 E->getRBraceLoc(), E->getType());
8991 template<typename Derived>
8993 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
8996 // transform the initializer value
8997 ExprResult Init = getDerived().TransformExpr(E->getInit());
8998 if (Init.isInvalid())
9001 // transform the designators.
9002 SmallVector<Expr*, 4> ArrayExprs;
9003 bool ExprChanged = false;
9004 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9005 if (D.isFieldDesignator()) {
9006 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9010 FieldDecl *Field = cast_or_null<FieldDecl>(
9011 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9012 if (Field != D.getField())
9013 // Rebuild the expression when the transformed FieldDecl is
9014 // different to the already assigned FieldDecl.
9017 // Ensure that the designator expression is rebuilt when there isn't
9018 // a resolved FieldDecl in the designator as we don't want to assign
9019 // a FieldDecl to a pattern designator that will be instantiated again.
9025 if (D.isArrayDesignator()) {
9026 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
9027 if (Index.isInvalid())
9030 Desig.AddDesignator(
9031 Designator::getArray(Index.get(), D.getLBracketLoc()));
9033 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
9034 ArrayExprs.push_back(Index.get());
9038 assert(D.isArrayRangeDesignator() && "New kind of designator?");
9040 = getDerived().TransformExpr(E->getArrayRangeStart(D));
9041 if (Start.isInvalid())
9044 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
9045 if (End.isInvalid())
9048 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
9051 D.getEllipsisLoc()));
9053 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9054 End.get() != E->getArrayRangeEnd(D);
9056 ArrayExprs.push_back(Start.get());
9057 ArrayExprs.push_back(End.get());
9060 if (!getDerived().AlwaysRebuild() &&
9061 Init.get() == E->getInit() &&
9065 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
9066 E->getEqualOrColonLoc(),
9067 E->usesGNUSyntax(), Init.get());
9070 // Seems that if TransformInitListExpr() only works on the syntactic form of an
9071 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9072 template<typename Derived>
9074 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9075 DesignatedInitUpdateExpr *E) {
9076 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9081 template<typename Derived>
9083 TreeTransform<Derived>::TransformNoInitExpr(
9085 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9089 template<typename Derived>
9091 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9092 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9096 template<typename Derived>
9098 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9099 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9103 template<typename Derived>
9105 TreeTransform<Derived>::TransformImplicitValueInitExpr(
9106 ImplicitValueInitExpr *E) {
9107 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
9109 // FIXME: Will we ever have proper type location here? Will we actually
9110 // need to transform the type?
9111 QualType T = getDerived().TransformType(E->getType());
9115 if (!getDerived().AlwaysRebuild() &&
9119 return getDerived().RebuildImplicitValueInitExpr(T);
9122 template<typename Derived>
9124 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
9125 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9129 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9130 if (SubExpr.isInvalid())
9133 if (!getDerived().AlwaysRebuild() &&
9134 TInfo == E->getWrittenTypeInfo() &&
9135 SubExpr.get() == E->getSubExpr())
9138 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
9139 TInfo, E->getRParenLoc());
9142 template<typename Derived>
9144 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
9145 bool ArgumentChanged = false;
9146 SmallVector<Expr*, 4> Inits;
9147 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9151 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
9156 /// \brief Transform an address-of-label expression.
9158 /// By default, the transformation of an address-of-label expression always
9159 /// rebuilds the expression, so that the label identifier can be resolved to
9160 /// the corresponding label statement by semantic analysis.
9161 template<typename Derived>
9163 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
9164 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9169 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
9170 cast<LabelDecl>(LD));
9173 template<typename Derived>
9175 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
9176 SemaRef.ActOnStartStmtExpr();
9178 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
9179 if (SubStmt.isInvalid()) {
9180 SemaRef.ActOnStmtExprError();
9184 if (!getDerived().AlwaysRebuild() &&
9185 SubStmt.get() == E->getSubStmt()) {
9186 // Calling this an 'error' is unintuitive, but it does the right thing.
9187 SemaRef.ActOnStmtExprError();
9188 return SemaRef.MaybeBindToTemporary(E);
9191 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
9196 template<typename Derived>
9198 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
9199 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9200 if (Cond.isInvalid())
9203 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9204 if (LHS.isInvalid())
9207 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9208 if (RHS.isInvalid())
9211 if (!getDerived().AlwaysRebuild() &&
9212 Cond.get() == E->getCond() &&
9213 LHS.get() == E->getLHS() &&
9214 RHS.get() == E->getRHS())
9217 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
9218 Cond.get(), LHS.get(), RHS.get(),
9222 template<typename Derived>
9224 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
9228 template<typename Derived>
9230 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
9231 switch (E->getOperator()) {
9235 case OO_Array_Delete:
9236 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
9239 // This is a call to an object's operator().
9240 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9242 // Transform the object itself.
9243 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
9244 if (Object.isInvalid())
9247 // FIXME: Poor location information
9248 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9249 static_cast<Expr *>(Object.get())->getLocEnd());
9251 // Transform the call arguments.
9252 SmallVector<Expr*, 8> Args;
9253 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
9257 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
9262 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9264 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9265 #include "clang/Basic/OperatorKinds.def"
9270 case OO_Conditional:
9271 llvm_unreachable("conditional operator is not actually overloadable");
9274 case NUM_OVERLOADED_OPERATORS:
9275 llvm_unreachable("not an overloaded operator?");
9278 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9279 if (Callee.isInvalid())
9283 if (E->getOperator() == OO_Amp)
9284 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9286 First = getDerived().TransformExpr(E->getArg(0));
9287 if (First.isInvalid())
9291 if (E->getNumArgs() == 2) {
9292 Second = getDerived().TransformExpr(E->getArg(1));
9293 if (Second.isInvalid())
9297 if (!getDerived().AlwaysRebuild() &&
9298 Callee.get() == E->getCallee() &&
9299 First.get() == E->getArg(0) &&
9300 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
9301 return SemaRef.MaybeBindToTemporary(E);
9303 Sema::FPContractStateRAII FPContractState(getSema());
9304 getSema().FPFeatures.fp_contract = E->isFPContractable();
9306 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9307 E->getOperatorLoc(),
9313 template<typename Derived>
9315 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9316 return getDerived().TransformCallExpr(E);
9319 template<typename Derived>
9321 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9322 // Transform the callee.
9323 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9324 if (Callee.isInvalid())
9327 // Transform exec config.
9328 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9332 // Transform arguments.
9333 bool ArgChanged = false;
9334 SmallVector<Expr*, 8> Args;
9335 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9339 if (!getDerived().AlwaysRebuild() &&
9340 Callee.get() == E->getCallee() &&
9342 return SemaRef.MaybeBindToTemporary(E);
9344 // FIXME: Wrong source location information for the '('.
9345 SourceLocation FakeLParenLoc
9346 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9347 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9349 E->getRParenLoc(), EC.get());
9352 template<typename Derived>
9354 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
9355 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9360 = getDerived().TransformExpr(E->getSubExprAsWritten());
9361 if (SubExpr.isInvalid())
9364 if (!getDerived().AlwaysRebuild() &&
9365 Type == E->getTypeInfoAsWritten() &&
9366 SubExpr.get() == E->getSubExpr())
9368 return getDerived().RebuildCXXNamedCastExpr(
9369 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9370 Type, E->getAngleBrackets().getEnd(),
9371 // FIXME. this should be '(' location
9372 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
9375 template<typename Derived>
9377 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9378 return getDerived().TransformCXXNamedCastExpr(E);
9381 template<typename Derived>
9383 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9384 return getDerived().TransformCXXNamedCastExpr(E);
9387 template<typename Derived>
9389 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
9390 CXXReinterpretCastExpr *E) {
9391 return getDerived().TransformCXXNamedCastExpr(E);
9394 template<typename Derived>
9396 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9397 return getDerived().TransformCXXNamedCastExpr(E);
9400 template<typename Derived>
9402 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
9403 CXXFunctionalCastExpr *E) {
9404 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9409 = getDerived().TransformExpr(E->getSubExprAsWritten());
9410 if (SubExpr.isInvalid())
9413 if (!getDerived().AlwaysRebuild() &&
9414 Type == E->getTypeInfoAsWritten() &&
9415 SubExpr.get() == E->getSubExpr())
9418 return getDerived().RebuildCXXFunctionalCastExpr(Type,
9424 template<typename Derived>
9426 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
9427 if (E->isTypeOperand()) {
9428 TypeSourceInfo *TInfo
9429 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9433 if (!getDerived().AlwaysRebuild() &&
9434 TInfo == E->getTypeOperandSourceInfo())
9437 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9443 // We don't know whether the subexpression is potentially evaluated until
9444 // after we perform semantic analysis. We speculatively assume it is
9445 // unevaluated; it will get fixed later if the subexpression is in fact
9446 // potentially evaluated.
9447 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9448 Sema::ReuseLambdaContextDecl);
9450 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9451 if (SubExpr.isInvalid())
9454 if (!getDerived().AlwaysRebuild() &&
9455 SubExpr.get() == E->getExprOperand())
9458 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9464 template<typename Derived>
9466 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9467 if (E->isTypeOperand()) {
9468 TypeSourceInfo *TInfo
9469 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9473 if (!getDerived().AlwaysRebuild() &&
9474 TInfo == E->getTypeOperandSourceInfo())
9477 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9483 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9485 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9486 if (SubExpr.isInvalid())
9489 if (!getDerived().AlwaysRebuild() &&
9490 SubExpr.get() == E->getExprOperand())
9493 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9499 template<typename Derived>
9501 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
9505 template<typename Derived>
9507 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
9508 CXXNullPtrLiteralExpr *E) {
9512 template<typename Derived>
9514 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
9515 QualType T = getSema().getCurrentThisType();
9517 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9518 // Make sure that we capture 'this'.
9519 getSema().CheckCXXThisCapture(E->getLocStart());
9523 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
9526 template<typename Derived>
9528 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
9529 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9530 if (SubExpr.isInvalid())
9533 if (!getDerived().AlwaysRebuild() &&
9534 SubExpr.get() == E->getSubExpr())
9537 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9538 E->isThrownVariableInScope());
9541 template<typename Derived>
9543 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
9545 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9550 if (!getDerived().AlwaysRebuild() &&
9551 Param == E->getParam())
9554 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
9557 template<typename Derived>
9559 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9561 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9566 if (!getDerived().AlwaysRebuild() && Field == E->getField())
9569 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9572 template<typename Derived>
9574 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9575 CXXScalarValueInitExpr *E) {
9576 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9580 if (!getDerived().AlwaysRebuild() &&
9581 T == E->getTypeSourceInfo())
9584 return getDerived().RebuildCXXScalarValueInitExpr(T,
9585 /*FIXME:*/T->getTypeLoc().getEndLoc(),
9589 template<typename Derived>
9591 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
9592 // Transform the type that we're allocating
9593 TypeSourceInfo *AllocTypeInfo
9594 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9598 // Transform the size of the array we're allocating (if any).
9599 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
9600 if (ArraySize.isInvalid())
9603 // Transform the placement arguments (if any).
9604 bool ArgumentChanged = false;
9605 SmallVector<Expr*, 8> PlacementArgs;
9606 if (getDerived().TransformExprs(E->getPlacementArgs(),
9607 E->getNumPlacementArgs(), true,
9608 PlacementArgs, &ArgumentChanged))
9611 // Transform the initializer (if any).
9612 Expr *OldInit = E->getInitializer();
9615 NewInit = getDerived().TransformInitializer(OldInit, true);
9616 if (NewInit.isInvalid())
9619 // Transform new operator and delete operator.
9620 FunctionDecl *OperatorNew = nullptr;
9621 if (E->getOperatorNew()) {
9622 OperatorNew = cast_or_null<FunctionDecl>(
9623 getDerived().TransformDecl(E->getLocStart(),
9624 E->getOperatorNew()));
9629 FunctionDecl *OperatorDelete = nullptr;
9630 if (E->getOperatorDelete()) {
9631 OperatorDelete = cast_or_null<FunctionDecl>(
9632 getDerived().TransformDecl(E->getLocStart(),
9633 E->getOperatorDelete()));
9634 if (!OperatorDelete)
9638 if (!getDerived().AlwaysRebuild() &&
9639 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
9640 ArraySize.get() == E->getArraySize() &&
9641 NewInit.get() == OldInit &&
9642 OperatorNew == E->getOperatorNew() &&
9643 OperatorDelete == E->getOperatorDelete() &&
9645 // Mark any declarations we need as referenced.
9646 // FIXME: instantiation-specific.
9648 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
9650 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9652 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
9653 QualType ElementType
9654 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9655 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9656 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9657 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
9658 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
9666 QualType AllocType = AllocTypeInfo->getType();
9667 if (!ArraySize.get()) {
9668 // If no array size was specified, but the new expression was
9669 // instantiated with an array type (e.g., "new T" where T is
9670 // instantiated with "int[4]"), extract the outer bound from the
9671 // array type as our array size. We do this with constant and
9672 // dependently-sized array types.
9673 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9676 } else if (const ConstantArrayType *ConsArrayT
9677 = dyn_cast<ConstantArrayType>(ArrayT)) {
9678 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9679 SemaRef.Context.getSizeType(),
9680 /*FIXME:*/ E->getLocStart());
9681 AllocType = ConsArrayT->getElementType();
9682 } else if (const DependentSizedArrayType *DepArrayT
9683 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9684 if (DepArrayT->getSizeExpr()) {
9685 ArraySize = DepArrayT->getSizeExpr();
9686 AllocType = DepArrayT->getElementType();
9691 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9693 /*FIXME:*/E->getLocStart(),
9695 /*FIXME:*/E->getLocStart(),
9696 E->getTypeIdParens(),
9700 E->getDirectInitRange(),
9704 template<typename Derived>
9706 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
9707 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
9708 if (Operand.isInvalid())
9711 // Transform the delete operator, if known.
9712 FunctionDecl *OperatorDelete = nullptr;
9713 if (E->getOperatorDelete()) {
9714 OperatorDelete = cast_or_null<FunctionDecl>(
9715 getDerived().TransformDecl(E->getLocStart(),
9716 E->getOperatorDelete()));
9717 if (!OperatorDelete)
9721 if (!getDerived().AlwaysRebuild() &&
9722 Operand.get() == E->getArgument() &&
9723 OperatorDelete == E->getOperatorDelete()) {
9724 // Mark any declarations we need as referenced.
9725 // FIXME: instantiation-specific.
9727 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9729 if (!E->getArgument()->isTypeDependent()) {
9730 QualType Destroyed = SemaRef.Context.getBaseElementType(
9731 E->getDestroyedType());
9732 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9733 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
9734 SemaRef.MarkFunctionReferenced(E->getLocStart(),
9735 SemaRef.LookupDestructor(Record));
9742 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9743 E->isGlobalDelete(),
9748 template<typename Derived>
9750 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
9751 CXXPseudoDestructorExpr *E) {
9752 ExprResult Base = getDerived().TransformExpr(E->getBase());
9753 if (Base.isInvalid())
9756 ParsedType ObjectTypePtr;
9757 bool MayBePseudoDestructor = false;
9758 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
9759 E->getOperatorLoc(),
9760 E->isArrow()? tok::arrow : tok::period,
9762 MayBePseudoDestructor);
9763 if (Base.isInvalid())
9766 QualType ObjectType = ObjectTypePtr.get();
9767 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9770 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9775 SS.Adopt(QualifierLoc);
9777 PseudoDestructorTypeStorage Destroyed;
9778 if (E->getDestroyedTypeInfo()) {
9779 TypeSourceInfo *DestroyedTypeInfo
9780 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
9781 ObjectType, nullptr, SS);
9782 if (!DestroyedTypeInfo)
9784 Destroyed = DestroyedTypeInfo;
9785 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
9786 // We aren't likely to be able to resolve the identifier down to a type
9787 // now anyway, so just retain the identifier.
9788 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9789 E->getDestroyedTypeLoc());
9791 // Look for a destructor known with the given name.
9792 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
9793 *E->getDestroyedTypeIdentifier(),
9794 E->getDestroyedTypeLoc(),
9802 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9803 E->getDestroyedTypeLoc());
9806 TypeSourceInfo *ScopeTypeInfo = nullptr;
9807 if (E->getScopeTypeInfo()) {
9808 CXXScopeSpec EmptySS;
9809 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
9810 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
9815 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
9816 E->getOperatorLoc(),
9820 E->getColonColonLoc(),
9825 template <typename Derived>
9826 bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
9829 // Transform all the decls.
9830 bool AllEmptyPacks = true;
9831 for (auto *OldD : Old->decls()) {
9832 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
9834 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9835 // This can happen because of dependent hiding.
9836 if (isa<UsingShadowDecl>(OldD))
9844 // Expand using pack declarations.
9845 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
9846 ArrayRef<NamedDecl*> Decls = SingleDecl;
9847 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
9848 Decls = UPD->expansions();
9850 // Expand using declarations.
9851 for (auto *D : Decls) {
9852 if (auto *UD = dyn_cast<UsingDecl>(D)) {
9853 for (auto *SD : UD->shadows())
9860 AllEmptyPacks &= Decls.empty();
9863 // C++ [temp.res]/8.4.2:
9864 // The program is ill-formed, no diagnostic required, if [...] lookup for
9865 // a name in the template definition found a using-declaration, but the
9866 // lookup in the corresponding scope in the instantiation odoes not find
9867 // any declarations because the using-declaration was a pack expansion and
9868 // the corresponding pack is empty
9869 if (AllEmptyPacks && !RequiresADL) {
9870 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
9871 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
9875 // Resolve a kind, but don't do any further analysis. If it's
9876 // ambiguous, the callee needs to deal with it.
9881 template<typename Derived>
9883 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
9884 UnresolvedLookupExpr *Old) {
9885 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9886 Sema::LookupOrdinaryName);
9888 // Transform the declaration set.
9889 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
9892 // Rebuild the nested-name qualifier, if present.
9894 if (Old->getQualifierLoc()) {
9895 NestedNameSpecifierLoc QualifierLoc
9896 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9900 SS.Adopt(QualifierLoc);
9903 if (Old->getNamingClass()) {
9904 CXXRecordDecl *NamingClass
9905 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9907 Old->getNamingClass()));
9913 R.setNamingClass(NamingClass);
9916 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9918 // If we have neither explicit template arguments, nor the template keyword,
9919 // it's a normal declaration name or member reference.
9920 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9921 NamedDecl *D = R.getAsSingle<NamedDecl>();
9922 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9923 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9924 // give a good diagnostic.
9925 if (D && D->isCXXInstanceMember()) {
9926 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9927 /*TemplateArgs=*/nullptr,
9931 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9934 // If we have template arguments, rebuild them, then rebuild the
9935 // templateid expression.
9936 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
9937 if (Old->hasExplicitTemplateArgs() &&
9938 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9939 Old->getNumTemplateArgs(),
9945 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
9946 Old->requiresADL(), &TransArgs);
9949 template<typename Derived>
9951 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9952 bool ArgChanged = false;
9953 SmallVector<TypeSourceInfo *, 4> Args;
9954 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9955 TypeSourceInfo *From = E->getArg(I);
9956 TypeLoc FromTL = From->getTypeLoc();
9957 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
9959 TLB.reserve(FromTL.getFullDataSize());
9960 QualType To = getDerived().TransformType(TLB, FromTL);
9964 if (To == From->getType())
9965 Args.push_back(From);
9967 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9975 // We have a pack expansion. Instantiate it.
9976 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
9977 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9978 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9979 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
9981 // Determine whether the set of unexpanded parameter packs can and should
9984 bool RetainExpansion = false;
9985 Optional<unsigned> OrigNumExpansions =
9986 ExpansionTL.getTypePtr()->getNumExpansions();
9987 Optional<unsigned> NumExpansions = OrigNumExpansions;
9988 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9989 PatternTL.getSourceRange(),
9991 Expand, RetainExpansion,
9996 // The transform has determined that we should perform a simple
9997 // transformation on the pack expansion, producing another pack
9999 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10001 TypeLocBuilder TLB;
10002 TLB.reserve(From->getTypeLoc().getFullDataSize());
10004 QualType To = getDerived().TransformType(TLB, PatternTL);
10006 return ExprError();
10008 To = getDerived().RebuildPackExpansionType(To,
10009 PatternTL.getSourceRange(),
10010 ExpansionTL.getEllipsisLoc(),
10013 return ExprError();
10015 PackExpansionTypeLoc ToExpansionTL
10016 = TLB.push<PackExpansionTypeLoc>(To);
10017 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10018 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10022 // Expand the pack expansion by substituting for each argument in the
10024 for (unsigned I = 0; I != *NumExpansions; ++I) {
10025 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10026 TypeLocBuilder TLB;
10027 TLB.reserve(PatternTL.getFullDataSize());
10028 QualType To = getDerived().TransformType(TLB, PatternTL);
10030 return ExprError();
10032 if (To->containsUnexpandedParameterPack()) {
10033 To = getDerived().RebuildPackExpansionType(To,
10034 PatternTL.getSourceRange(),
10035 ExpansionTL.getEllipsisLoc(),
10038 return ExprError();
10040 PackExpansionTypeLoc ToExpansionTL
10041 = TLB.push<PackExpansionTypeLoc>(To);
10042 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10045 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10048 if (!RetainExpansion)
10051 // If we're supposed to retain a pack expansion, do so by temporarily
10052 // forgetting the partially-substituted parameter pack.
10053 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10055 TypeLocBuilder TLB;
10056 TLB.reserve(From->getTypeLoc().getFullDataSize());
10058 QualType To = getDerived().TransformType(TLB, PatternTL);
10060 return ExprError();
10062 To = getDerived().RebuildPackExpansionType(To,
10063 PatternTL.getSourceRange(),
10064 ExpansionTL.getEllipsisLoc(),
10067 return ExprError();
10069 PackExpansionTypeLoc ToExpansionTL
10070 = TLB.push<PackExpansionTypeLoc>(To);
10071 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10072 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10075 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10078 return getDerived().RebuildTypeTrait(E->getTrait(),
10084 template<typename Derived>
10086 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10087 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10089 return ExprError();
10091 if (!getDerived().AlwaysRebuild() &&
10092 T == E->getQueriedTypeSourceInfo())
10095 ExprResult SubExpr;
10097 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10098 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10099 if (SubExpr.isInvalid())
10100 return ExprError();
10102 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
10106 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10113 template<typename Derived>
10115 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10116 ExprResult SubExpr;
10118 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10119 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10120 if (SubExpr.isInvalid())
10121 return ExprError();
10123 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
10127 return getDerived().RebuildExpressionTrait(
10128 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10131 template <typename Derived>
10132 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10133 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10134 TypeSourceInfo **RecoveryTSI) {
10135 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10136 DRE, AddrTaken, RecoveryTSI);
10138 // Propagate both errors and recovered types, which return ExprEmpty.
10139 if (!NewDRE.isUsable())
10142 // We got an expr, wrap it up in parens.
10143 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10145 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10149 template <typename Derived>
10150 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10151 DependentScopeDeclRefExpr *E) {
10152 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10156 template<typename Derived>
10158 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10159 DependentScopeDeclRefExpr *E,
10160 bool IsAddressOfOperand,
10161 TypeSourceInfo **RecoveryTSI) {
10162 assert(E->getQualifierLoc());
10163 NestedNameSpecifierLoc QualifierLoc
10164 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10166 return ExprError();
10167 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10169 // TODO: If this is a conversion-function-id, verify that the
10170 // destination type name (if present) resolves the same way after
10171 // instantiation as it did in the local scope.
10173 DeclarationNameInfo NameInfo
10174 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10175 if (!NameInfo.getName())
10176 return ExprError();
10178 if (!E->hasExplicitTemplateArgs()) {
10179 if (!getDerived().AlwaysRebuild() &&
10180 QualifierLoc == E->getQualifierLoc() &&
10181 // Note: it is sufficient to compare the Name component of NameInfo:
10182 // if name has not changed, DNLoc has not changed either.
10183 NameInfo.getName() == E->getDeclName())
10186 return getDerived().RebuildDependentScopeDeclRefExpr(
10187 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10188 IsAddressOfOperand, RecoveryTSI);
10191 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10192 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10193 E->getNumTemplateArgs(),
10195 return ExprError();
10197 return getDerived().RebuildDependentScopeDeclRefExpr(
10198 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10202 template<typename Derived>
10204 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
10205 // CXXConstructExprs other than for list-initialization and
10206 // CXXTemporaryObjectExpr are always implicit, so when we have
10207 // a 1-argument construction we just transform that argument.
10208 if ((E->getNumArgs() == 1 ||
10209 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
10210 (!getDerived().DropCallArgument(E->getArg(0))) &&
10211 !E->isListInitialization())
10212 return getDerived().TransformExpr(E->getArg(0));
10214 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10216 QualType T = getDerived().TransformType(E->getType());
10218 return ExprError();
10220 CXXConstructorDecl *Constructor
10221 = cast_or_null<CXXConstructorDecl>(
10222 getDerived().TransformDecl(E->getLocStart(),
10223 E->getConstructor()));
10225 return ExprError();
10227 bool ArgumentChanged = false;
10228 SmallVector<Expr*, 8> Args;
10229 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10231 return ExprError();
10233 if (!getDerived().AlwaysRebuild() &&
10234 T == E->getType() &&
10235 Constructor == E->getConstructor() &&
10236 !ArgumentChanged) {
10237 // Mark the constructor as referenced.
10238 // FIXME: Instantiation-specific
10239 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10243 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
10245 E->isElidable(), Args,
10246 E->hadMultipleCandidates(),
10247 E->isListInitialization(),
10248 E->isStdInitListInitialization(),
10249 E->requiresZeroInitialization(),
10250 E->getConstructionKind(),
10251 E->getParenOrBraceRange());
10254 template<typename Derived>
10255 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10256 CXXInheritedCtorInitExpr *E) {
10257 QualType T = getDerived().TransformType(E->getType());
10259 return ExprError();
10261 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10262 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10264 return ExprError();
10266 if (!getDerived().AlwaysRebuild() &&
10267 T == E->getType() &&
10268 Constructor == E->getConstructor()) {
10269 // Mark the constructor as referenced.
10270 // FIXME: Instantiation-specific
10271 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10275 return getDerived().RebuildCXXInheritedCtorInitExpr(
10276 T, E->getLocation(), Constructor,
10277 E->constructsVBase(), E->inheritedFromVBase());
10280 /// \brief Transform a C++ temporary-binding expression.
10282 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10283 /// transform the subexpression and return that.
10284 template<typename Derived>
10286 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
10287 return getDerived().TransformExpr(E->getSubExpr());
10290 /// \brief Transform a C++ expression that contains cleanups that should
10291 /// be run after the expression is evaluated.
10293 /// Since ExprWithCleanups nodes are implicitly generated, we
10294 /// just transform the subexpression and return that.
10295 template<typename Derived>
10297 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
10298 return getDerived().TransformExpr(E->getSubExpr());
10301 template<typename Derived>
10303 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
10304 CXXTemporaryObjectExpr *E) {
10305 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10307 return ExprError();
10309 CXXConstructorDecl *Constructor
10310 = cast_or_null<CXXConstructorDecl>(
10311 getDerived().TransformDecl(E->getLocStart(),
10312 E->getConstructor()));
10314 return ExprError();
10316 bool ArgumentChanged = false;
10317 SmallVector<Expr*, 8> Args;
10318 Args.reserve(E->getNumArgs());
10319 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10321 return ExprError();
10323 if (!getDerived().AlwaysRebuild() &&
10324 T == E->getTypeSourceInfo() &&
10325 Constructor == E->getConstructor() &&
10326 !ArgumentChanged) {
10327 // FIXME: Instantiation-specific
10328 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10329 return SemaRef.MaybeBindToTemporary(E);
10332 // FIXME: Pass in E->isListInitialization().
10333 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10334 /*FIXME:*/T->getTypeLoc().getEndLoc(),
10339 template<typename Derived>
10341 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
10342 // Transform any init-capture expressions before entering the scope of the
10343 // lambda body, because they are not semantically within that scope.
10344 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
10345 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10346 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
10347 E->explicit_capture_begin());
10348 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10349 CEnd = E->capture_end();
10351 if (!E->isInitCapture(C))
10353 EnterExpressionEvaluationContext EEEC(getSema(),
10354 Sema::PotentiallyEvaluated);
10355 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10356 C->getCapturedVar()->getInit(),
10357 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
10359 if (NewExprInitResult.isInvalid())
10360 return ExprError();
10361 Expr *NewExprInit = NewExprInitResult.get();
10363 VarDecl *OldVD = C->getCapturedVar();
10364 QualType NewInitCaptureType =
10365 getSema().buildLambdaInitCaptureInitialization(
10366 C->getLocation(), OldVD->getType()->isReferenceType(),
10367 OldVD->getIdentifier(),
10368 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
10369 NewExprInitResult = NewExprInit;
10370 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10371 std::make_pair(NewExprInitResult, NewInitCaptureType);
10374 // Transform the template parameters, and add them to the current
10375 // instantiation scope. The null case is handled correctly.
10376 auto TPL = getDerived().TransformTemplateParameterList(
10377 E->getTemplateParameterList());
10379 // Transform the type of the original lambda's call operator.
10380 // The transformation MUST be done in the CurrentInstantiationScope since
10381 // it introduces a mapping of the original to the newly created
10382 // transformed parameters.
10383 TypeSourceInfo *NewCallOpTSI = nullptr;
10385 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10386 FunctionProtoTypeLoc OldCallOpFPTL =
10387 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
10389 TypeLocBuilder NewCallOpTLBuilder;
10390 SmallVector<QualType, 4> ExceptionStorage;
10391 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
10392 QualType NewCallOpType = TransformFunctionProtoType(
10393 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
10394 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10395 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10396 ExceptionStorage, Changed);
10398 if (NewCallOpType.isNull())
10399 return ExprError();
10400 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10404 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10405 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10406 LSI->GLTemplateParameterList = TPL;
10408 // Create the local class that will describe the lambda.
10409 CXXRecordDecl *Class
10410 = getSema().createLambdaClosureType(E->getIntroducerRange(),
10412 /*KnownDependent=*/false,
10413 E->getCaptureDefault());
10414 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10416 // Build the call operator.
10417 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10418 Class, E->getIntroducerRange(), NewCallOpTSI,
10419 E->getCallOperator()->getLocEnd(),
10420 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10421 E->getCallOperator()->isConstexpr());
10423 LSI->CallOperator = NewCallOperator;
10425 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10426 I != NumParams; ++I) {
10427 auto *P = NewCallOperator->getParamDecl(I);
10428 if (P->hasUninstantiatedDefaultArg()) {
10429 EnterExpressionEvaluationContext Eval(
10430 getSema(), Sema::PotentiallyEvaluatedIfUsed, P);
10431 ExprResult R = getDerived().TransformExpr(
10432 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10433 P->setDefaultArg(R.get());
10437 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
10438 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
10440 // Introduce the context of the call operator.
10441 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
10442 /*NewThisContext*/false);
10444 // Enter the scope of the lambda.
10445 getSema().buildLambdaScope(LSI, NewCallOperator,
10446 E->getIntroducerRange(),
10447 E->getCaptureDefault(),
10448 E->getCaptureDefaultLoc(),
10449 E->hasExplicitParameters(),
10450 E->hasExplicitResultType(),
10453 bool Invalid = false;
10455 // Transform captures.
10456 bool FinishedExplicitCaptures = false;
10457 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10458 CEnd = E->capture_end();
10460 // When we hit the first implicit capture, tell Sema that we've finished
10461 // the list of explicit captures.
10462 if (!FinishedExplicitCaptures && C->isImplicit()) {
10463 getSema().finishLambdaExplicitCaptures(LSI);
10464 FinishedExplicitCaptures = true;
10467 // Capturing 'this' is trivial.
10468 if (C->capturesThis()) {
10469 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10470 /*BuildAndDiagnose*/ true, nullptr,
10471 C->getCaptureKind() == LCK_StarThis);
10474 // Captured expression will be recaptured during captured variables
10476 if (C->capturesVLAType())
10479 // Rebuild init-captures, including the implied field declaration.
10480 if (E->isInitCapture(C)) {
10481 InitCaptureInfoTy InitExprTypePair =
10482 InitCaptureExprsAndTypes[C - E->capture_begin()];
10483 ExprResult Init = InitExprTypePair.first;
10484 QualType InitQualType = InitExprTypePair.second;
10485 if (Init.isInvalid() || InitQualType.isNull()) {
10489 VarDecl *OldVD = C->getCapturedVar();
10490 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
10491 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10492 OldVD->getInitStyle(), Init.get());
10496 getDerived().transformedLocalDecl(OldVD, NewVD);
10498 getSema().buildInitCaptureField(LSI, NewVD);
10502 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10504 // Determine the capture kind for Sema.
10505 Sema::TryCaptureKind Kind
10506 = C->isImplicit()? Sema::TryCapture_Implicit
10507 : C->getCaptureKind() == LCK_ByCopy
10508 ? Sema::TryCapture_ExplicitByVal
10509 : Sema::TryCapture_ExplicitByRef;
10510 SourceLocation EllipsisLoc;
10511 if (C->isPackExpansion()) {
10512 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10513 bool ShouldExpand = false;
10514 bool RetainExpansion = false;
10515 Optional<unsigned> NumExpansions;
10516 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10519 ShouldExpand, RetainExpansion,
10525 if (ShouldExpand) {
10526 // The transform has determined that we should perform an expansion;
10527 // transform and capture each of the arguments.
10528 // expansion of the pattern. Do so.
10529 VarDecl *Pack = C->getCapturedVar();
10530 for (unsigned I = 0; I != *NumExpansions; ++I) {
10531 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10532 VarDecl *CapturedVar
10533 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10535 if (!CapturedVar) {
10540 // Capture the transformed variable.
10541 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10544 // FIXME: Retain a pack expansion if RetainExpansion is true.
10549 EllipsisLoc = C->getEllipsisLoc();
10552 // Transform the captured variable.
10553 VarDecl *CapturedVar
10554 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10555 C->getCapturedVar()));
10556 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
10561 // Capture the transformed variable.
10562 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10565 if (!FinishedExplicitCaptures)
10566 getSema().finishLambdaExplicitCaptures(LSI);
10568 // Enter a new evaluation context to insulate the lambda from any
10569 // cleanups from the enclosing full-expression.
10570 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
10572 // Instantiate the body of the lambda expression.
10574 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10576 // ActOnLambda* will pop the function scope for us.
10577 FuncScopeCleanup.disable();
10579 if (Body.isInvalid()) {
10580 SavedContext.pop();
10581 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
10582 /*IsInstantiation=*/true);
10583 return ExprError();
10586 // Copy the LSI before ActOnFinishFunctionBody removes it.
10587 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10588 // the call operator.
10589 auto LSICopy = *LSI;
10590 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10591 /*IsInstantiation*/ true);
10592 SavedContext.pop();
10594 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10598 template<typename Derived>
10600 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
10601 CXXUnresolvedConstructExpr *E) {
10602 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10604 return ExprError();
10606 bool ArgumentChanged = false;
10607 SmallVector<Expr*, 8> Args;
10608 Args.reserve(E->arg_size());
10609 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
10611 return ExprError();
10613 if (!getDerived().AlwaysRebuild() &&
10614 T == E->getTypeSourceInfo() &&
10618 // FIXME: we're faking the locations of the commas
10619 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
10622 E->getRParenLoc());
10625 template<typename Derived>
10627 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
10628 CXXDependentScopeMemberExpr *E) {
10629 // Transform the base of the expression.
10630 ExprResult Base((Expr*) nullptr);
10633 QualType ObjectType;
10634 if (!E->isImplicitAccess()) {
10635 OldBase = E->getBase();
10636 Base = getDerived().TransformExpr(OldBase);
10637 if (Base.isInvalid())
10638 return ExprError();
10640 // Start the member reference and compute the object's type.
10641 ParsedType ObjectTy;
10642 bool MayBePseudoDestructor = false;
10643 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10644 E->getOperatorLoc(),
10645 E->isArrow()? tok::arrow : tok::period,
10647 MayBePseudoDestructor);
10648 if (Base.isInvalid())
10649 return ExprError();
10651 ObjectType = ObjectTy.get();
10652 BaseType = ((Expr*) Base.get())->getType();
10655 BaseType = getDerived().TransformType(E->getBaseType());
10656 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10659 // Transform the first part of the nested-name-specifier that qualifies
10660 // the member name.
10661 NamedDecl *FirstQualifierInScope
10662 = getDerived().TransformFirstQualifierInScope(
10663 E->getFirstQualifierFoundInScope(),
10664 E->getQualifierLoc().getBeginLoc());
10666 NestedNameSpecifierLoc QualifierLoc;
10667 if (E->getQualifier()) {
10669 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10671 FirstQualifierInScope);
10673 return ExprError();
10676 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10678 // TODO: If this is a conversion-function-id, verify that the
10679 // destination type name (if present) resolves the same way after
10680 // instantiation as it did in the local scope.
10682 DeclarationNameInfo NameInfo
10683 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
10684 if (!NameInfo.getName())
10685 return ExprError();
10687 if (!E->hasExplicitTemplateArgs()) {
10688 // This is a reference to a member without an explicitly-specified
10689 // template argument list. Optimize for this common case.
10690 if (!getDerived().AlwaysRebuild() &&
10691 Base.get() == OldBase &&
10692 BaseType == E->getBaseType() &&
10693 QualifierLoc == E->getQualifierLoc() &&
10694 NameInfo.getName() == E->getMember() &&
10695 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
10698 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10701 E->getOperatorLoc(),
10704 FirstQualifierInScope,
10706 /*TemplateArgs*/nullptr);
10709 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10710 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10711 E->getNumTemplateArgs(),
10713 return ExprError();
10715 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10718 E->getOperatorLoc(),
10721 FirstQualifierInScope,
10726 template<typename Derived>
10728 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
10729 // Transform the base of the expression.
10730 ExprResult Base((Expr*) nullptr);
10732 if (!Old->isImplicitAccess()) {
10733 Base = getDerived().TransformExpr(Old->getBase());
10734 if (Base.isInvalid())
10735 return ExprError();
10736 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
10738 if (Base.isInvalid())
10739 return ExprError();
10740 BaseType = Base.get()->getType();
10742 BaseType = getDerived().TransformType(Old->getBaseType());
10745 NestedNameSpecifierLoc QualifierLoc;
10746 if (Old->getQualifierLoc()) {
10748 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10750 return ExprError();
10753 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10755 LookupResult R(SemaRef, Old->getMemberNameInfo(),
10756 Sema::LookupOrdinaryName);
10758 // Transform the declaration set.
10759 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
10760 return ExprError();
10762 // Determine the naming class.
10763 if (Old->getNamingClass()) {
10764 CXXRecordDecl *NamingClass
10765 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10766 Old->getMemberLoc(),
10767 Old->getNamingClass()));
10769 return ExprError();
10771 R.setNamingClass(NamingClass);
10774 TemplateArgumentListInfo TransArgs;
10775 if (Old->hasExplicitTemplateArgs()) {
10776 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10777 TransArgs.setRAngleLoc(Old->getRAngleLoc());
10778 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10779 Old->getNumTemplateArgs(),
10781 return ExprError();
10784 // FIXME: to do this check properly, we will need to preserve the
10785 // first-qualifier-in-scope here, just in case we had a dependent
10786 // base (and therefore couldn't do the check) and a
10787 // nested-name-qualifier (and therefore could do the lookup).
10788 NamedDecl *FirstQualifierInScope = nullptr;
10790 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
10792 Old->getOperatorLoc(),
10796 FirstQualifierInScope,
10798 (Old->hasExplicitTemplateArgs()
10799 ? &TransArgs : nullptr));
10802 template<typename Derived>
10804 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
10805 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10806 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10807 if (SubExpr.isInvalid())
10808 return ExprError();
10810 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
10813 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10816 template<typename Derived>
10818 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
10819 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10820 if (Pattern.isInvalid())
10821 return ExprError();
10823 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
10826 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10827 E->getNumExpansions());
10830 template<typename Derived>
10832 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10833 // If E is not value-dependent, then nothing will change when we transform it.
10834 // Note: This is an instantiation-centric view.
10835 if (!E->isValueDependent())
10838 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
10840 ArrayRef<TemplateArgument> PackArgs;
10841 TemplateArgument ArgStorage;
10843 // Find the argument list to transform.
10844 if (E->isPartiallySubstituted()) {
10845 PackArgs = E->getPartialArguments();
10846 } else if (E->isValueDependent()) {
10847 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10848 bool ShouldExpand = false;
10849 bool RetainExpansion = false;
10850 Optional<unsigned> NumExpansions;
10851 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10853 ShouldExpand, RetainExpansion,
10855 return ExprError();
10857 // If we need to expand the pack, build a template argument from it and
10859 if (ShouldExpand) {
10860 auto *Pack = E->getPack();
10861 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10862 ArgStorage = getSema().Context.getPackExpansionType(
10863 getSema().Context.getTypeDeclType(TTPD), None);
10864 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10865 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10867 auto *VD = cast<ValueDecl>(Pack);
10868 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10869 VK_RValue, E->getPackLoc());
10870 if (DRE.isInvalid())
10871 return ExprError();
10872 ArgStorage = new (getSema().Context) PackExpansionExpr(
10873 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10875 PackArgs = ArgStorage;
10879 // If we're not expanding the pack, just transform the decl.
10880 if (!PackArgs.size()) {
10881 auto *Pack = cast_or_null<NamedDecl>(
10882 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
10884 return ExprError();
10885 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10887 E->getRParenLoc(), None, None);
10890 // Try to compute the result without performing a partial substitution.
10891 Optional<unsigned> Result = 0;
10892 for (const TemplateArgument &Arg : PackArgs) {
10893 if (!Arg.isPackExpansion()) {
10894 Result = *Result + 1;
10898 TemplateArgumentLoc ArgLoc;
10899 InventTemplateArgumentLoc(Arg, ArgLoc);
10901 // Find the pattern of the pack expansion.
10902 SourceLocation Ellipsis;
10903 Optional<unsigned> OrigNumExpansions;
10904 TemplateArgumentLoc Pattern =
10905 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
10906 OrigNumExpansions);
10908 // Substitute under the pack expansion. Do not expand the pack (yet).
10909 TemplateArgumentLoc OutPattern;
10910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10911 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
10915 // See if we can determine the number of arguments from the result.
10916 Optional<unsigned> NumExpansions =
10917 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
10918 if (!NumExpansions) {
10919 // No: we must be in an alias template expansion, and we're going to need
10920 // to actually expand the packs.
10925 Result = *Result + *NumExpansions;
10928 // Common case: we could determine the number of expansions without
10931 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10933 E->getRParenLoc(), *Result, None);
10935 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10938 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10939 typedef TemplateArgumentLocInventIterator<
10940 Derived, const TemplateArgument*> PackLocIterator;
10941 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10942 PackLocIterator(*this, PackArgs.end()),
10943 TransformedPackArgs, /*Uneval*/true))
10944 return ExprError();
10947 // Check whether we managed to fully-expand the pack.
10948 // FIXME: Is it possible for us to do so and not hit the early exit path?
10949 SmallVector<TemplateArgument, 8> Args;
10950 bool PartialSubstitution = false;
10951 for (auto &Loc : TransformedPackArgs.arguments()) {
10952 Args.push_back(Loc.getArgument());
10953 if (Loc.getArgument().isPackExpansion())
10954 PartialSubstitution = true;
10957 if (PartialSubstitution)
10958 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10960 E->getRParenLoc(), None, Args);
10962 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10963 E->getPackLoc(), E->getRParenLoc(),
10964 Args.size(), None);
10967 template<typename Derived>
10969 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10970 SubstNonTypeTemplateParmPackExpr *E) {
10971 // Default behavior is to do nothing with this transformation.
10975 template<typename Derived>
10977 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10978 SubstNonTypeTemplateParmExpr *E) {
10979 // Default behavior is to do nothing with this transformation.
10983 template<typename Derived>
10985 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10986 // Default behavior is to do nothing with this transformation.
10990 template<typename Derived>
10992 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10993 MaterializeTemporaryExpr *E) {
10994 return getDerived().TransformExpr(E->GetTemporaryExpr());
10997 template<typename Derived>
10999 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11000 Expr *Pattern = E->getPattern();
11002 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11003 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11004 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11006 // Determine whether the set of unexpanded parameter packs can and should
11008 bool Expand = true;
11009 bool RetainExpansion = false;
11010 Optional<unsigned> NumExpansions;
11011 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11012 Pattern->getSourceRange(),
11014 Expand, RetainExpansion,
11019 // Do not expand any packs here, just transform and rebuild a fold
11021 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11024 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11025 if (LHS.isInvalid())
11029 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11030 if (RHS.isInvalid())
11033 if (!getDerived().AlwaysRebuild() &&
11034 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11037 return getDerived().RebuildCXXFoldExpr(
11038 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11039 RHS.get(), E->getLocEnd());
11042 // The transform has determined that we should perform an elementwise
11043 // expansion of the pattern. Do so.
11044 ExprResult Result = getDerived().TransformExpr(E->getInit());
11045 if (Result.isInvalid())
11047 bool LeftFold = E->isLeftFold();
11049 // If we're retaining an expansion for a right fold, it is the innermost
11050 // component and takes the init (if any).
11051 if (!LeftFold && RetainExpansion) {
11052 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11054 ExprResult Out = getDerived().TransformExpr(Pattern);
11055 if (Out.isInvalid())
11058 Result = getDerived().RebuildCXXFoldExpr(
11059 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11060 Result.get(), E->getLocEnd());
11061 if (Result.isInvalid())
11065 for (unsigned I = 0; I != *NumExpansions; ++I) {
11066 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11067 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11068 ExprResult Out = getDerived().TransformExpr(Pattern);
11069 if (Out.isInvalid())
11072 if (Out.get()->containsUnexpandedParameterPack()) {
11073 // We still have a pack; retain a pack expansion for this slice.
11074 Result = getDerived().RebuildCXXFoldExpr(
11076 LeftFold ? Result.get() : Out.get(),
11077 E->getOperator(), E->getEllipsisLoc(),
11078 LeftFold ? Out.get() : Result.get(),
11080 } else if (Result.isUsable()) {
11081 // We've got down to a single element; build a binary operator.
11082 Result = getDerived().RebuildBinaryOperator(
11083 E->getEllipsisLoc(), E->getOperator(),
11084 LeftFold ? Result.get() : Out.get(),
11085 LeftFold ? Out.get() : Result.get());
11089 if (Result.isInvalid())
11093 // If we're retaining an expansion for a left fold, it is the outermost
11094 // component and takes the complete expansion so far as its init (if any).
11095 if (LeftFold && RetainExpansion) {
11096 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11098 ExprResult Out = getDerived().TransformExpr(Pattern);
11099 if (Out.isInvalid())
11102 Result = getDerived().RebuildCXXFoldExpr(
11103 E->getLocStart(), Result.get(),
11104 E->getOperator(), E->getEllipsisLoc(),
11105 Out.get(), E->getLocEnd());
11106 if (Result.isInvalid())
11110 // If we had no init and an empty pack, and we're not retaining an expansion,
11111 // then produce a fallback value or error.
11112 if (Result.isUnset())
11113 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11119 template<typename Derived>
11121 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11122 CXXStdInitializerListExpr *E) {
11123 return getDerived().TransformExpr(E->getSubExpr());
11126 template<typename Derived>
11128 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
11129 return SemaRef.MaybeBindToTemporary(E);
11132 template<typename Derived>
11134 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
11138 template<typename Derived>
11140 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11141 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11142 if (SubExpr.isInvalid())
11143 return ExprError();
11145 if (!getDerived().AlwaysRebuild() &&
11146 SubExpr.get() == E->getSubExpr())
11149 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
11152 template<typename Derived>
11154 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11155 // Transform each of the elements.
11156 SmallVector<Expr *, 8> Elements;
11157 bool ArgChanged = false;
11158 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
11159 /*IsCall=*/false, Elements, &ArgChanged))
11160 return ExprError();
11162 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11163 return SemaRef.MaybeBindToTemporary(E);
11165 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11170 template<typename Derived>
11172 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
11173 ObjCDictionaryLiteral *E) {
11174 // Transform each of the elements.
11175 SmallVector<ObjCDictionaryElement, 8> Elements;
11176 bool ArgChanged = false;
11177 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11178 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
11180 if (OrigElement.isPackExpansion()) {
11181 // This key/value element is a pack expansion.
11182 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11183 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11184 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11185 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11187 // Determine whether the set of unexpanded parameter packs can
11188 // and should be expanded.
11189 bool Expand = true;
11190 bool RetainExpansion = false;
11191 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11192 Optional<unsigned> NumExpansions = OrigNumExpansions;
11193 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11194 OrigElement.Value->getLocEnd());
11195 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11198 Expand, RetainExpansion,
11200 return ExprError();
11203 // The transform has determined that we should perform a simple
11204 // transformation on the pack expansion, producing another pack
11206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11207 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11208 if (Key.isInvalid())
11209 return ExprError();
11211 if (Key.get() != OrigElement.Key)
11214 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11215 if (Value.isInvalid())
11216 return ExprError();
11218 if (Value.get() != OrigElement.Value)
11221 ObjCDictionaryElement Expansion = {
11222 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11224 Elements.push_back(Expansion);
11228 // Record right away that the argument was changed. This needs
11229 // to happen even if the array expands to nothing.
11232 // The transform has determined that we should perform an elementwise
11233 // expansion of the pattern. Do so.
11234 for (unsigned I = 0; I != *NumExpansions; ++I) {
11235 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11236 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11237 if (Key.isInvalid())
11238 return ExprError();
11240 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11241 if (Value.isInvalid())
11242 return ExprError();
11244 ObjCDictionaryElement Element = {
11245 Key.get(), Value.get(), SourceLocation(), NumExpansions
11248 // If any unexpanded parameter packs remain, we still have a
11250 // FIXME: Can this really happen?
11251 if (Key.get()->containsUnexpandedParameterPack() ||
11252 Value.get()->containsUnexpandedParameterPack())
11253 Element.EllipsisLoc = OrigElement.EllipsisLoc;
11255 Elements.push_back(Element);
11258 // FIXME: Retain a pack expansion if RetainExpansion is true.
11260 // We've finished with this pack expansion.
11264 // Transform and check key.
11265 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11266 if (Key.isInvalid())
11267 return ExprError();
11269 if (Key.get() != OrigElement.Key)
11272 // Transform and check value.
11274 = getDerived().TransformExpr(OrigElement.Value);
11275 if (Value.isInvalid())
11276 return ExprError();
11278 if (Value.get() != OrigElement.Value)
11281 ObjCDictionaryElement Element = {
11282 Key.get(), Value.get(), SourceLocation(), None
11284 Elements.push_back(Element);
11287 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11288 return SemaRef.MaybeBindToTemporary(E);
11290 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
11294 template<typename Derived>
11296 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
11297 TypeSourceInfo *EncodedTypeInfo
11298 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11299 if (!EncodedTypeInfo)
11300 return ExprError();
11302 if (!getDerived().AlwaysRebuild() &&
11303 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
11306 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
11308 E->getRParenLoc());
11311 template<typename Derived>
11312 ExprResult TreeTransform<Derived>::
11313 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
11314 // This is a kind of implicit conversion, and it needs to get dropped
11315 // and recomputed for the same general reasons that ImplicitCastExprs
11316 // do, as well a more specific one: this expression is only valid when
11317 // it appears *immediately* as an argument expression.
11318 return getDerived().TransformExpr(E->getSubExpr());
11321 template<typename Derived>
11322 ExprResult TreeTransform<Derived>::
11323 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
11324 TypeSourceInfo *TSInfo
11325 = getDerived().TransformType(E->getTypeInfoAsWritten());
11327 return ExprError();
11329 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
11330 if (Result.isInvalid())
11331 return ExprError();
11333 if (!getDerived().AlwaysRebuild() &&
11334 TSInfo == E->getTypeInfoAsWritten() &&
11335 Result.get() == E->getSubExpr())
11338 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
11339 E->getBridgeKeywordLoc(), TSInfo,
11343 template <typename Derived>
11344 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11345 ObjCAvailabilityCheckExpr *E) {
11349 template<typename Derived>
11351 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
11352 // Transform arguments.
11353 bool ArgChanged = false;
11354 SmallVector<Expr*, 8> Args;
11355 Args.reserve(E->getNumArgs());
11356 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
11358 return ExprError();
11360 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11361 // Class message: transform the receiver type.
11362 TypeSourceInfo *ReceiverTypeInfo
11363 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11364 if (!ReceiverTypeInfo)
11365 return ExprError();
11367 // If nothing changed, just retain the existing message send.
11368 if (!getDerived().AlwaysRebuild() &&
11369 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
11370 return SemaRef.MaybeBindToTemporary(E);
11372 // Build a new class message send.
11373 SmallVector<SourceLocation, 16> SelLocs;
11374 E->getSelectorLocs(SelLocs);
11375 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11378 E->getMethodDecl(),
11383 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11384 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11385 if (!E->getMethodDecl())
11386 return ExprError();
11388 // Build a new class message send to 'super'.
11389 SmallVector<SourceLocation, 16> SelLocs;
11390 E->getSelectorLocs(SelLocs);
11391 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11394 E->getReceiverType(),
11395 E->getMethodDecl(),
11401 // Instance message: transform the receiver
11402 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11403 "Only class and instance messages may be instantiated");
11404 ExprResult Receiver
11405 = getDerived().TransformExpr(E->getInstanceReceiver());
11406 if (Receiver.isInvalid())
11407 return ExprError();
11409 // If nothing changed, just retain the existing message send.
11410 if (!getDerived().AlwaysRebuild() &&
11411 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
11412 return SemaRef.MaybeBindToTemporary(E);
11414 // Build a new instance message send.
11415 SmallVector<SourceLocation, 16> SelLocs;
11416 E->getSelectorLocs(SelLocs);
11417 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
11420 E->getMethodDecl(),
11426 template<typename Derived>
11428 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
11432 template<typename Derived>
11434 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
11438 template<typename Derived>
11440 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
11441 // Transform the base expression.
11442 ExprResult Base = getDerived().TransformExpr(E->getBase());
11443 if (Base.isInvalid())
11444 return ExprError();
11446 // We don't need to transform the ivar; it will never change.
11448 // If nothing changed, just retain the existing expression.
11449 if (!getDerived().AlwaysRebuild() &&
11450 Base.get() == E->getBase())
11453 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
11455 E->isArrow(), E->isFreeIvar());
11458 template<typename Derived>
11460 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
11461 // 'super' and types never change. Property never changes. Just
11462 // retain the existing expression.
11463 if (!E->isObjectReceiver())
11466 // Transform the base expression.
11467 ExprResult Base = getDerived().TransformExpr(E->getBase());
11468 if (Base.isInvalid())
11469 return ExprError();
11471 // We don't need to transform the property; it will never change.
11473 // If nothing changed, just retain the existing expression.
11474 if (!getDerived().AlwaysRebuild() &&
11475 Base.get() == E->getBase())
11478 if (E->isExplicitProperty())
11479 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11480 E->getExplicitProperty(),
11483 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11484 SemaRef.Context.PseudoObjectTy,
11485 E->getImplicitPropertyGetter(),
11486 E->getImplicitPropertySetter(),
11490 template<typename Derived>
11492 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11493 // Transform the base expression.
11494 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11495 if (Base.isInvalid())
11496 return ExprError();
11498 // Transform the key expression.
11499 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11500 if (Key.isInvalid())
11501 return ExprError();
11503 // If nothing changed, just retain the existing expression.
11504 if (!getDerived().AlwaysRebuild() &&
11505 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
11508 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
11509 Base.get(), Key.get(),
11510 E->getAtIndexMethodDecl(),
11511 E->setAtIndexMethodDecl());
11514 template<typename Derived>
11516 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
11517 // Transform the base expression.
11518 ExprResult Base = getDerived().TransformExpr(E->getBase());
11519 if (Base.isInvalid())
11520 return ExprError();
11522 // If nothing changed, just retain the existing expression.
11523 if (!getDerived().AlwaysRebuild() &&
11524 Base.get() == E->getBase())
11527 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
11532 template<typename Derived>
11534 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
11535 bool ArgumentChanged = false;
11536 SmallVector<Expr*, 8> SubExprs;
11537 SubExprs.reserve(E->getNumSubExprs());
11538 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11539 SubExprs, &ArgumentChanged))
11540 return ExprError();
11542 if (!getDerived().AlwaysRebuild() &&
11546 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
11548 E->getRParenLoc());
11551 template<typename Derived>
11553 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11554 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11555 if (SrcExpr.isInvalid())
11556 return ExprError();
11558 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11560 return ExprError();
11562 if (!getDerived().AlwaysRebuild() &&
11563 Type == E->getTypeSourceInfo() &&
11564 SrcExpr.get() == E->getSrcExpr())
11567 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11568 SrcExpr.get(), Type,
11569 E->getRParenLoc());
11572 template<typename Derived>
11574 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
11575 BlockDecl *oldBlock = E->getBlockDecl();
11577 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
11578 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11580 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
11581 blockScope->TheDecl->setBlockMissingReturnType(
11582 oldBlock->blockMissingReturnType());
11584 SmallVector<ParmVarDecl*, 4> params;
11585 SmallVector<QualType, 4> paramTypes;
11587 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11589 // Parameter substitution.
11590 Sema::ExtParameterInfoBuilder extParamInfos;
11591 if (getDerived().TransformFunctionTypeParams(
11592 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11593 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms,
11595 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11596 return ExprError();
11599 QualType exprResultType =
11600 getDerived().TransformType(exprFunctionType->getReturnType());
11602 auto epi = exprFunctionType->getExtProtoInfo();
11603 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11605 QualType functionType =
11606 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
11607 blockScope->FunctionType = functionType;
11609 // Set the parameters on the block decl.
11610 if (!params.empty())
11611 blockScope->TheDecl->setParams(params);
11613 if (!oldBlock->blockMissingReturnType()) {
11614 blockScope->HasImplicitReturnType = false;
11615 blockScope->ReturnType = exprResultType;
11618 // Transform the body
11619 StmtResult body = getDerived().TransformStmt(E->getBody());
11620 if (body.isInvalid()) {
11621 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11622 return ExprError();
11626 // In builds with assertions, make sure that we captured everything we
11627 // captured before.
11628 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
11629 for (const auto &I : oldBlock->captures()) {
11630 VarDecl *oldCapture = I.getVariable();
11632 // Ignore parameter packs.
11633 if (isa<ParmVarDecl>(oldCapture) &&
11634 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11637 VarDecl *newCapture =
11638 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11640 assert(blockScope->CaptureMap.count(newCapture));
11642 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
11646 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
11647 /*Scope=*/nullptr);
11650 template<typename Derived>
11652 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
11653 llvm_unreachable("Cannot transform asType expressions yet");
11656 template<typename Derived>
11658 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
11659 QualType RetTy = getDerived().TransformType(E->getType());
11660 bool ArgumentChanged = false;
11661 SmallVector<Expr*, 8> SubExprs;
11662 SubExprs.reserve(E->getNumSubExprs());
11663 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11664 SubExprs, &ArgumentChanged))
11665 return ExprError();
11667 if (!getDerived().AlwaysRebuild() &&
11671 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
11672 RetTy, E->getOp(), E->getRParenLoc());
11675 //===----------------------------------------------------------------------===//
11676 // Type reconstruction
11677 //===----------------------------------------------------------------------===//
11679 template<typename Derived>
11680 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11681 SourceLocation Star) {
11682 return SemaRef.BuildPointerType(PointeeType, Star,
11683 getDerived().getBaseEntity());
11686 template<typename Derived>
11687 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11688 SourceLocation Star) {
11689 return SemaRef.BuildBlockPointerType(PointeeType, Star,
11690 getDerived().getBaseEntity());
11693 template<typename Derived>
11695 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11696 bool WrittenAsLValue,
11697 SourceLocation Sigil) {
11698 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
11699 Sigil, getDerived().getBaseEntity());
11702 template<typename Derived>
11704 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11705 QualType ClassType,
11706 SourceLocation Sigil) {
11707 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11708 getDerived().getBaseEntity());
11711 template<typename Derived>
11712 QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
11713 const ObjCTypeParamDecl *Decl,
11714 SourceLocation ProtocolLAngleLoc,
11715 ArrayRef<ObjCProtocolDecl *> Protocols,
11716 ArrayRef<SourceLocation> ProtocolLocs,
11717 SourceLocation ProtocolRAngleLoc) {
11718 return SemaRef.BuildObjCTypeParamType(Decl,
11719 ProtocolLAngleLoc, Protocols,
11720 ProtocolLocs, ProtocolRAngleLoc,
11721 /*FailOnError=*/true);
11724 template<typename Derived>
11725 QualType TreeTransform<Derived>::RebuildObjCObjectType(
11727 SourceLocation Loc,
11728 SourceLocation TypeArgsLAngleLoc,
11729 ArrayRef<TypeSourceInfo *> TypeArgs,
11730 SourceLocation TypeArgsRAngleLoc,
11731 SourceLocation ProtocolLAngleLoc,
11732 ArrayRef<ObjCProtocolDecl *> Protocols,
11733 ArrayRef<SourceLocation> ProtocolLocs,
11734 SourceLocation ProtocolRAngleLoc) {
11735 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11736 TypeArgs, TypeArgsRAngleLoc,
11737 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11739 /*FailOnError=*/true);
11742 template<typename Derived>
11743 QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11744 QualType PointeeType,
11745 SourceLocation Star) {
11746 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11749 template<typename Derived>
11751 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11752 ArrayType::ArraySizeModifier SizeMod,
11753 const llvm::APInt *Size,
11755 unsigned IndexTypeQuals,
11756 SourceRange BracketsRange) {
11757 if (SizeExpr || !Size)
11758 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11759 IndexTypeQuals, BracketsRange,
11760 getDerived().getBaseEntity());
11762 QualType Types[] = {
11763 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11764 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11765 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
11767 const unsigned NumTypes = llvm::array_lengthof(Types);
11769 for (unsigned I = 0; I != NumTypes; ++I)
11770 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11771 SizeType = Types[I];
11775 // Note that we can return a VariableArrayType here in the case where
11776 // the element type was a dependent VariableArrayType.
11777 IntegerLiteral *ArraySize
11778 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11779 /*FIXME*/BracketsRange.getBegin());
11780 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
11781 IndexTypeQuals, BracketsRange,
11782 getDerived().getBaseEntity());
11785 template<typename Derived>
11787 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
11788 ArrayType::ArraySizeModifier SizeMod,
11789 const llvm::APInt &Size,
11790 unsigned IndexTypeQuals,
11791 SourceRange BracketsRange) {
11792 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
11793 IndexTypeQuals, BracketsRange);
11796 template<typename Derived>
11798 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
11799 ArrayType::ArraySizeModifier SizeMod,
11800 unsigned IndexTypeQuals,
11801 SourceRange BracketsRange) {
11802 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
11803 IndexTypeQuals, BracketsRange);
11806 template<typename Derived>
11808 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
11809 ArrayType::ArraySizeModifier SizeMod,
11811 unsigned IndexTypeQuals,
11812 SourceRange BracketsRange) {
11813 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11815 IndexTypeQuals, BracketsRange);
11818 template<typename Derived>
11820 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
11821 ArrayType::ArraySizeModifier SizeMod,
11823 unsigned IndexTypeQuals,
11824 SourceRange BracketsRange) {
11825 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11827 IndexTypeQuals, BracketsRange);
11830 template<typename Derived>
11831 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
11832 unsigned NumElements,
11833 VectorType::VectorKind VecKind) {
11834 // FIXME: semantic checking!
11835 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
11838 template<typename Derived>
11839 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11840 unsigned NumElements,
11841 SourceLocation AttributeLoc) {
11842 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11843 NumElements, true);
11844 IntegerLiteral *VectorSize
11845 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11847 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
11850 template<typename Derived>
11852 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
11854 SourceLocation AttributeLoc) {
11855 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
11858 template<typename Derived>
11859 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11861 MutableArrayRef<QualType> ParamTypes,
11862 const FunctionProtoType::ExtProtoInfo &EPI) {
11863 return SemaRef.BuildFunctionType(T, ParamTypes,
11864 getDerived().getBaseLocation(),
11865 getDerived().getBaseEntity(),
11869 template<typename Derived>
11870 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11871 return SemaRef.Context.getFunctionNoProtoType(T);
11874 template<typename Derived>
11875 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
11877 assert(D && "no decl found");
11878 if (D->isInvalidDecl()) return QualType();
11880 // FIXME: Doesn't account for ObjCInterfaceDecl!
11882 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
11883 // A valid resolved using typename pack expansion decl can have multiple
11884 // UsingDecls, but they must each have exactly one type, and it must be
11885 // the same type in every case. But we must have at least one expansion!
11886 if (UPD->expansions().empty()) {
11887 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
11888 << UPD->isCXXClassMember() << UPD;
11892 // We might still have some unresolved types. Try to pick a resolved type
11893 // if we can. The final instantiation will check that the remaining
11894 // unresolved types instantiate to the type we pick.
11895 QualType FallbackT;
11897 for (auto *E : UPD->expansions()) {
11898 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
11899 if (ThisT.isNull())
11901 else if (ThisT->getAs<UnresolvedUsingType>())
11903 else if (T.isNull())
11906 assert(getSema().Context.hasSameType(ThisT, T) &&
11907 "mismatched resolved types in using pack expansion");
11909 return T.isNull() ? FallbackT : T;
11910 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
11911 assert(Using->hasTypename() &&
11912 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11914 // A valid resolved using typename decl points to exactly one type decl.
11915 assert(++Using->shadow_begin() == Using->shadow_end());
11916 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
11918 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11919 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11920 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11923 return SemaRef.Context.getTypeDeclType(Ty);
11926 template<typename Derived>
11927 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11928 SourceLocation Loc) {
11929 return SemaRef.BuildTypeofExprType(E, Loc);
11932 template<typename Derived>
11933 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11934 return SemaRef.Context.getTypeOfType(Underlying);
11937 template<typename Derived>
11938 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11939 SourceLocation Loc) {
11940 return SemaRef.BuildDecltypeType(E, Loc);
11943 template<typename Derived>
11944 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11945 UnaryTransformType::UTTKind UKind,
11946 SourceLocation Loc) {
11947 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11950 template<typename Derived>
11951 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
11952 TemplateName Template,
11953 SourceLocation TemplateNameLoc,
11954 TemplateArgumentListInfo &TemplateArgs) {
11955 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
11958 template<typename Derived>
11959 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11960 SourceLocation KWLoc) {
11961 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11964 template<typename Derived>
11965 QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11966 SourceLocation KWLoc,
11968 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
11969 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
11972 template<typename Derived>
11974 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11976 TemplateDecl *Template) {
11977 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
11981 template<typename Derived>
11983 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11984 const IdentifierInfo &Name,
11985 SourceLocation NameLoc,
11986 QualType ObjectType,
11987 NamedDecl *FirstQualifierInScope) {
11988 UnqualifiedId TemplateName;
11989 TemplateName.setIdentifier(&Name, NameLoc);
11990 Sema::TemplateTy Template;
11991 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11992 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
11993 SS, TemplateKWLoc, TemplateName,
11994 ParsedType::make(ObjectType),
11995 /*EnteringContext=*/false,
11997 return Template.get();
12000 template<typename Derived>
12002 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12003 OverloadedOperatorKind Operator,
12004 SourceLocation NameLoc,
12005 QualType ObjectType) {
12006 UnqualifiedId Name;
12007 // FIXME: Bogus location information.
12008 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
12009 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
12010 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12011 Sema::TemplateTy Template;
12012 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12013 SS, TemplateKWLoc, Name,
12014 ParsedType::make(ObjectType),
12015 /*EnteringContext=*/false,
12017 return Template.get();
12020 template<typename Derived>
12022 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12023 SourceLocation OpLoc,
12027 Expr *Callee = OrigCallee->IgnoreParenCasts();
12028 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
12030 if (First->getObjectKind() == OK_ObjCProperty) {
12031 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12032 if (BinaryOperator::isAssignmentOp(Opc))
12033 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12035 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12036 if (Result.isInvalid())
12037 return ExprError();
12038 First = Result.get();
12041 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12042 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12043 if (Result.isInvalid())
12044 return ExprError();
12045 Second = Result.get();
12048 // Determine whether this should be a builtin operation.
12049 if (Op == OO_Subscript) {
12050 if (!First->getType()->isOverloadableType() &&
12051 !Second->getType()->isOverloadableType())
12052 return getSema().CreateBuiltinArraySubscriptExpr(First,
12053 Callee->getLocStart(),
12055 } else if (Op == OO_Arrow) {
12056 // -> is never a builtin operation.
12057 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12058 } else if (Second == nullptr || isPostIncDec) {
12059 if (!First->getType()->isOverloadableType()) {
12060 // The argument is not of overloadable type, so try to create a
12061 // built-in unary operation.
12062 UnaryOperatorKind Opc
12063 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12065 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
12068 if (!First->getType()->isOverloadableType() &&
12069 !Second->getType()->isOverloadableType()) {
12070 // Neither of the arguments is an overloadable type, so try to
12071 // create a built-in binary operation.
12072 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12074 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
12075 if (Result.isInvalid())
12076 return ExprError();
12082 // Compute the transformed set of functions (and function templates) to be
12083 // used during overload resolution.
12084 UnresolvedSet<16> Functions;
12086 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
12087 assert(ULE->requiresADL());
12088 Functions.append(ULE->decls_begin(), ULE->decls_end());
12090 // If we've resolved this to a particular non-member function, just call
12091 // that function. If we resolved it to a member function,
12092 // CreateOverloaded* will find that function for us.
12093 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12094 if (!isa<CXXMethodDecl>(ND))
12095 Functions.addDecl(ND);
12098 // Add any functions found via argument-dependent lookup.
12099 Expr *Args[2] = { First, Second };
12100 unsigned NumArgs = 1 + (Second != nullptr);
12102 // Create the overloaded operator invocation for unary operators.
12103 if (NumArgs == 1 || isPostIncDec) {
12104 UnaryOperatorKind Opc
12105 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12106 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
12109 if (Op == OO_Subscript) {
12110 SourceLocation LBrace;
12111 SourceLocation RBrace;
12113 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
12114 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
12115 LBrace = SourceLocation::getFromRawEncoding(
12116 NameLoc.CXXOperatorName.BeginOpNameLoc);
12117 RBrace = SourceLocation::getFromRawEncoding(
12118 NameLoc.CXXOperatorName.EndOpNameLoc);
12120 LBrace = Callee->getLocStart();
12124 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12128 // Create the overloaded operator invocation for binary operators.
12129 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12131 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12132 if (Result.isInvalid())
12133 return ExprError();
12138 template<typename Derived>
12140 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
12141 SourceLocation OperatorLoc,
12144 TypeSourceInfo *ScopeType,
12145 SourceLocation CCLoc,
12146 SourceLocation TildeLoc,
12147 PseudoDestructorTypeStorage Destroyed) {
12148 QualType BaseType = Base->getType();
12149 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
12150 (!isArrow && !BaseType->getAs<RecordType>()) ||
12151 (isArrow && BaseType->getAs<PointerType>() &&
12152 !BaseType->getAs<PointerType>()->getPointeeType()
12153 ->template getAs<RecordType>())){
12154 // This pseudo-destructor expression is still a pseudo-destructor.
12155 return SemaRef.BuildPseudoDestructorExpr(
12156 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12157 CCLoc, TildeLoc, Destroyed);
12160 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
12161 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12162 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12163 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12164 NameInfo.setNamedTypeInfo(DestroyedType);
12166 // The scope type is now known to be a valid nested name specifier
12167 // component. Tack it on to the end of the nested name specifier.
12169 if (!ScopeType->getType()->getAs<TagType>()) {
12170 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12171 diag::err_expected_class_or_namespace)
12172 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12173 return ExprError();
12175 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12179 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12180 return getSema().BuildMemberReferenceExpr(Base, BaseType,
12181 OperatorLoc, isArrow,
12183 /*FIXME: FirstQualifier*/ nullptr,
12185 /*TemplateArgs*/ nullptr,
12189 template<typename Derived>
12191 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
12192 SourceLocation Loc = S->getLocStart();
12193 CapturedDecl *CD = S->getCapturedDecl();
12194 unsigned NumParams = CD->getNumParams();
12195 unsigned ContextParamPos = CD->getContextParamPosition();
12196 SmallVector<Sema::CapturedParamNameType, 4> Params;
12197 for (unsigned I = 0; I < NumParams; ++I) {
12198 if (I != ContextParamPos) {
12201 CD->getParam(I)->getName(),
12202 getDerived().TransformType(CD->getParam(I)->getType())));
12204 Params.push_back(std::make_pair(StringRef(), QualType()));
12207 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
12208 S->getCapturedRegionKind(), Params);
12211 Sema::CompoundScopeRAII CompoundScope(getSema());
12212 Body = getDerived().TransformStmt(S->getCapturedStmt());
12215 if (Body.isInvalid()) {
12216 getSema().ActOnCapturedRegionError();
12217 return StmtError();
12220 return getSema().ActOnCapturedRegionEnd(Body.get());
12223 } // end namespace clang
12225 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H