1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===//
8 // This file implements a semantic tree transformation that takes a given
9 // AST and rebuilds it, possibly transforming some nodes in the process.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14 #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
16 #include "CoroutineStmtBuilder.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/ExprConcepts.h"
23 #include "clang/AST/ExprCXX.h"
24 #include "clang/AST/ExprObjC.h"
25 #include "clang/AST/ExprOpenMP.h"
26 #include "clang/AST/OpenMPClause.h"
27 #include "clang/AST/Stmt.h"
28 #include "clang/AST/StmtCXX.h"
29 #include "clang/AST/StmtObjC.h"
30 #include "clang/AST/StmtOpenMP.h"
31 #include "clang/Basic/DiagnosticParse.h"
32 #include "clang/Basic/OpenMPKinds.h"
33 #include "clang/Sema/Designator.h"
34 #include "clang/Sema/Lookup.h"
35 #include "clang/Sema/Ownership.h"
36 #include "clang/Sema/ParsedTemplate.h"
37 #include "clang/Sema/ScopeInfo.h"
38 #include "clang/Sema/SemaDiagnostic.h"
39 #include "clang/Sema/SemaInternal.h"
40 #include "llvm/ADT/ArrayRef.h"
41 #include "llvm/Support/ErrorHandling.h"
44 using namespace llvm::omp
;
49 /// A semantic tree transformation that allows one to transform one
50 /// abstract syntax tree into another.
52 /// A new tree transformation is defined by creating a new subclass \c X of
53 /// \c TreeTransform<X> and then overriding certain operations to provide
54 /// behavior specific to that transformation. For example, template
55 /// instantiation is implemented as a tree transformation where the
56 /// transformation of TemplateTypeParmType nodes involves substituting the
57 /// template arguments for their corresponding template parameters; a similar
58 /// transformation is performed for non-type template parameters and
59 /// template template parameters.
61 /// This tree-transformation template uses static polymorphism to allow
62 /// subclasses to customize any of its operations. Thus, a subclass can
63 /// override any of the transformation or rebuild operators by providing an
64 /// operation with the same signature as the default implementation. The
65 /// overriding function should not be virtual.
67 /// Semantic tree transformations are split into two stages, either of which
68 /// can be replaced by a subclass. The "transform" step transforms an AST node
69 /// or the parts of an AST node using the various transformation functions,
70 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
71 /// node of the appropriate kind from the pieces. The default transformation
72 /// routines recursively transform the operands to composite AST nodes (e.g.,
73 /// the pointee type of a PointerType node) and, if any of those operand nodes
74 /// were changed by the transformation, invokes the rebuild operation to create
77 /// Subclasses can customize the transformation at various levels. The
78 /// most coarse-grained transformations involve replacing TransformType(),
79 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
80 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
81 /// new implementations.
83 /// For more fine-grained transformations, subclasses can replace any of the
84 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
85 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
86 /// replacing TransformTemplateTypeParmType() allows template instantiation
87 /// to substitute template arguments for their corresponding template
88 /// parameters. Additionally, subclasses can override the \c RebuildXXX
89 /// functions to control how AST nodes are rebuilt when their operands change.
90 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
91 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
92 /// be able to use more efficient rebuild steps.
94 /// There are a handful of other functions that can be overridden, allowing one
95 /// to avoid traversing nodes that don't need any transformation
96 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
97 /// operands have not changed (\c AlwaysRebuild()), and customize the
98 /// default locations and entity names used for type-checking
99 /// (\c getBaseLocation(), \c getBaseEntity()).
100 template<typename Derived
>
101 class TreeTransform
{
102 /// Private RAII object that helps us forget and then re-remember
103 /// the template argument corresponding to a partially-substituted parameter
105 class ForgetPartiallySubstitutedPackRAII
{
107 TemplateArgument Old
;
110 ForgetPartiallySubstitutedPackRAII(Derived
&Self
) : Self(Self
) {
111 Old
= Self
.ForgetPartiallySubstitutedPack();
114 ~ForgetPartiallySubstitutedPackRAII() {
115 Self
.RememberPartiallySubstitutedPack(Old
);
122 /// The set of local declarations that have been transformed, for
123 /// cases where we are forced to build new declarations within the transformer
124 /// rather than in the subclass (e.g., lambda closure types).
125 llvm::DenseMap
<Decl
*, Decl
*> TransformedLocalDecls
;
128 /// Initializes a new tree transformer.
129 TreeTransform(Sema
&SemaRef
) : SemaRef(SemaRef
) { }
131 /// Retrieves a reference to the derived class.
132 Derived
&getDerived() { return static_cast<Derived
&>(*this); }
134 /// Retrieves a reference to the derived class.
135 const Derived
&getDerived() const {
136 return static_cast<const Derived
&>(*this);
139 static inline ExprResult
Owned(Expr
*E
) { return E
; }
140 static inline StmtResult
Owned(Stmt
*S
) { return S
; }
142 /// Retrieves a reference to the semantic analysis object used for
143 /// this tree transform.
144 Sema
&getSema() const { return SemaRef
; }
146 /// Whether the transformation should always rebuild AST nodes, even
147 /// if none of the children have changed.
149 /// Subclasses may override this function to specify when the transformation
150 /// should rebuild all AST nodes.
152 /// We must always rebuild all AST nodes when performing variadic template
153 /// pack expansion, in order to avoid violating the AST invariant that each
154 /// statement node appears at most once in its containing declaration.
155 bool AlwaysRebuild() { return SemaRef
.ArgumentPackSubstitutionIndex
!= -1; }
157 /// Whether the transformation is forming an expression or statement that
158 /// replaces the original. In this case, we'll reuse mangling numbers from
159 /// existing lambdas.
160 bool ReplacingOriginal() { return false; }
162 /// Wether CXXConstructExpr can be skipped when they are implicit.
163 /// They will be reconstructed when used if needed.
164 /// This is useful when the user that cause rebuilding of the
165 /// CXXConstructExpr is outside of the expression at which the TreeTransform
167 bool AllowSkippingCXXConstructExpr() { return true; }
169 /// Returns the location of the entity being transformed, if that
170 /// information was not available elsewhere in the AST.
172 /// By default, returns no source-location information. Subclasses can
173 /// provide an alternative implementation that provides better location
175 SourceLocation
getBaseLocation() { return SourceLocation(); }
177 /// Returns the name of the entity being transformed, if that
178 /// information was not available elsewhere in the AST.
180 /// By default, returns an empty name. Subclasses can provide an alternative
181 /// implementation with a more precise name.
182 DeclarationName
getBaseEntity() { return DeclarationName(); }
184 /// Sets the "base" location and entity when that
185 /// information is known based on another transformation.
187 /// By default, the source location and entity are ignored. Subclasses can
188 /// override this function to provide a customized implementation.
189 void setBase(SourceLocation Loc
, DeclarationName Entity
) { }
191 /// RAII object that temporarily sets the base location and entity
192 /// used for reporting diagnostics in types.
193 class TemporaryBase
{
195 SourceLocation OldLocation
;
196 DeclarationName OldEntity
;
199 TemporaryBase(TreeTransform
&Self
, SourceLocation Location
,
200 DeclarationName Entity
) : Self(Self
) {
201 OldLocation
= Self
.getDerived().getBaseLocation();
202 OldEntity
= Self
.getDerived().getBaseEntity();
204 if (Location
.isValid())
205 Self
.getDerived().setBase(Location
, Entity
);
209 Self
.getDerived().setBase(OldLocation
, OldEntity
);
213 /// Determine whether the given type \p T has already been
216 /// Subclasses can provide an alternative implementation of this routine
217 /// to short-circuit evaluation when it is known that a given type will
218 /// not change. For example, template instantiation need not traverse
219 /// non-dependent types.
220 bool AlreadyTransformed(QualType T
) {
224 /// Transform a template parameter depth level.
226 /// During a transformation that transforms template parameters, this maps
227 /// an old template parameter depth to a new depth.
228 unsigned TransformTemplateDepth(unsigned Depth
) {
232 /// Determine whether the given call argument should be dropped, e.g.,
233 /// because it is a default argument.
235 /// Subclasses can provide an alternative implementation of this routine to
236 /// determine which kinds of call arguments get dropped. By default,
237 /// CXXDefaultArgument nodes are dropped (prior to transformation).
238 bool DropCallArgument(Expr
*E
) {
239 return E
->isDefaultArgument();
242 /// Determine whether we should expand a pack expansion with the
243 /// given set of parameter packs into separate arguments by repeatedly
244 /// transforming the pattern.
246 /// By default, the transformer never tries to expand pack expansions.
247 /// Subclasses can override this routine to provide different behavior.
249 /// \param EllipsisLoc The location of the ellipsis that identifies the
252 /// \param PatternRange The source range that covers the entire pattern of
253 /// the pack expansion.
255 /// \param Unexpanded The set of unexpanded parameter packs within the
258 /// \param ShouldExpand Will be set to \c true if the transformer should
259 /// expand the corresponding pack expansions into separate arguments. When
260 /// set, \c NumExpansions must also be set.
262 /// \param RetainExpansion Whether the caller should add an unexpanded
263 /// pack expansion after all of the expanded arguments. This is used
264 /// when extending explicitly-specified template argument packs per
265 /// C++0x [temp.arg.explicit]p9.
267 /// \param NumExpansions The number of separate arguments that will be in
268 /// the expanded form of the corresponding pack expansion. This is both an
269 /// input and an output parameter, which can be set by the caller if the
270 /// number of expansions is known a priori (e.g., due to a prior substitution)
271 /// and will be set by the callee when the number of expansions is known.
272 /// The callee must set this value when \c ShouldExpand is \c true; it may
273 /// set this value in other cases.
275 /// \returns true if an error occurred (e.g., because the parameter packs
276 /// are to be instantiated with arguments of different lengths), false
277 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
279 bool TryExpandParameterPacks(SourceLocation EllipsisLoc
,
280 SourceRange PatternRange
,
281 ArrayRef
<UnexpandedParameterPack
> Unexpanded
,
283 bool &RetainExpansion
,
284 Optional
<unsigned> &NumExpansions
) {
285 ShouldExpand
= false;
289 /// "Forget" about the partially-substituted pack template argument,
290 /// when performing an instantiation that must preserve the parameter pack
293 /// This routine is meant to be overridden by the template instantiator.
294 TemplateArgument
ForgetPartiallySubstitutedPack() {
295 return TemplateArgument();
298 /// "Remember" the partially-substituted pack template argument
299 /// after performing an instantiation that must preserve the parameter pack
302 /// This routine is meant to be overridden by the template instantiator.
303 void RememberPartiallySubstitutedPack(TemplateArgument Arg
) { }
305 /// Note to the derived class when a function parameter pack is
307 void ExpandingFunctionParameterPack(ParmVarDecl
*Pack
) { }
309 /// Transforms the given type into another type.
311 /// By default, this routine transforms a type by creating a
312 /// TypeSourceInfo for it and delegating to the appropriate
313 /// function. This is expensive, but we don't mind, because
314 /// this method is deprecated anyway; all users should be
315 /// switched to storing TypeSourceInfos.
317 /// \returns the transformed type.
318 QualType
TransformType(QualType T
);
320 /// Transforms the given type-with-location into a new
321 /// type-with-location.
323 /// By default, this routine transforms a type by delegating to the
324 /// appropriate TransformXXXType to build a new type. Subclasses
325 /// may override this function (to take over all type
326 /// transformations) or some set of the TransformXXXType functions
327 /// to alter the transformation.
328 TypeSourceInfo
*TransformType(TypeSourceInfo
*DI
);
330 /// Transform the given type-with-location into a new
331 /// type, collecting location information in the given builder
334 QualType
TransformType(TypeLocBuilder
&TLB
, TypeLoc TL
);
336 /// Transform a type that is permitted to produce a
337 /// DeducedTemplateSpecializationType.
339 /// This is used in the (relatively rare) contexts where it is acceptable
340 /// for transformation to produce a class template type with deduced
341 /// template arguments.
343 QualType
TransformTypeWithDeducedTST(QualType T
);
344 TypeSourceInfo
*TransformTypeWithDeducedTST(TypeSourceInfo
*DI
);
347 /// The reason why the value of a statement is not discarded, if any.
348 enum StmtDiscardKind
{
354 /// Transform the given statement.
356 /// By default, this routine transforms a statement by delegating to the
357 /// appropriate TransformXXXStmt function to transform a specific kind of
358 /// statement or the TransformExpr() function to transform an expression.
359 /// Subclasses may override this function to transform statements using some
362 /// \returns the transformed statement.
363 StmtResult
TransformStmt(Stmt
*S
, StmtDiscardKind SDK
= SDK_Discarded
);
365 /// Transform the given statement.
367 /// By default, this routine transforms a statement by delegating to the
368 /// appropriate TransformOMPXXXClause function to transform a specific kind
369 /// of clause. Subclasses may override this function to transform statements
370 /// using some other mechanism.
372 /// \returns the transformed OpenMP clause.
373 OMPClause
*TransformOMPClause(OMPClause
*S
);
375 /// Transform the given attribute.
377 /// By default, this routine transforms a statement by delegating to the
378 /// appropriate TransformXXXAttr function to transform a specific kind
379 /// of attribute. Subclasses may override this function to transform
380 /// attributed statements using some other mechanism.
382 /// \returns the transformed attribute
383 const Attr
*TransformAttr(const Attr
*S
);
385 /// Transform the specified attribute.
387 /// Subclasses should override the transformation of attributes with a pragma
388 /// spelling to transform expressions stored within the attribute.
390 /// \returns the transformed attribute.
392 #define PRAGMA_SPELLING_ATTR(X) \
393 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
394 #include "clang/Basic/AttrList.inc"
396 /// Transform the given expression.
398 /// By default, this routine transforms an expression by delegating to the
399 /// appropriate TransformXXXExpr function to build a new expression.
400 /// Subclasses may override this function to transform expressions using some
403 /// \returns the transformed expression.
404 ExprResult
TransformExpr(Expr
*E
);
406 /// Transform the given initializer.
408 /// By default, this routine transforms an initializer by stripping off the
409 /// semantic nodes added by initialization, then passing the result to
410 /// TransformExpr or TransformExprs.
412 /// \returns the transformed initializer.
413 ExprResult
TransformInitializer(Expr
*Init
, bool NotCopyInit
);
415 /// Transform the given list of expressions.
417 /// This routine transforms a list of expressions by invoking
418 /// \c TransformExpr() for each subexpression. However, it also provides
419 /// support for variadic templates by expanding any pack expansions (if the
420 /// derived class permits such expansion) along the way. When pack expansions
421 /// are present, the number of outputs may not equal the number of inputs.
423 /// \param Inputs The set of expressions to be transformed.
425 /// \param NumInputs The number of expressions in \c Inputs.
427 /// \param IsCall If \c true, then this transform is being performed on
428 /// function-call arguments, and any arguments that should be dropped, will
431 /// \param Outputs The transformed input expressions will be added to this
434 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
435 /// due to transformation.
437 /// \returns true if an error occurred, false otherwise.
438 bool TransformExprs(Expr
*const *Inputs
, unsigned NumInputs
, bool IsCall
,
439 SmallVectorImpl
<Expr
*> &Outputs
,
440 bool *ArgChanged
= nullptr);
442 /// Transform the given declaration, which is referenced from a type
445 /// By default, acts as the identity function on declarations, unless the
446 /// transformer has had to transform the declaration itself. Subclasses
447 /// may override this function to provide alternate behavior.
448 Decl
*TransformDecl(SourceLocation Loc
, Decl
*D
) {
449 llvm::DenseMap
<Decl
*, Decl
*>::iterator Known
450 = TransformedLocalDecls
.find(D
);
451 if (Known
!= TransformedLocalDecls
.end())
452 return Known
->second
;
457 /// Transform the specified condition.
459 /// By default, this transforms the variable and expression and rebuilds
461 Sema::ConditionResult
TransformCondition(SourceLocation Loc
, VarDecl
*Var
,
463 Sema::ConditionKind Kind
);
465 /// Transform the attributes associated with the given declaration and
466 /// place them on the new declaration.
468 /// By default, this operation does nothing. Subclasses may override this
469 /// behavior to transform attributes.
470 void transformAttrs(Decl
*Old
, Decl
*New
) { }
472 /// Note that a local declaration has been transformed by this
475 /// Local declarations are typically transformed via a call to
476 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
477 /// the transformer itself has to transform the declarations. This routine
478 /// can be overridden by a subclass that keeps track of such mappings.
479 void transformedLocalDecl(Decl
*Old
, ArrayRef
<Decl
*> New
) {
480 assert(New
.size() == 1 &&
481 "must override transformedLocalDecl if performing pack expansion");
482 TransformedLocalDecls
[Old
] = New
.front();
485 /// Transform the definition of the given declaration.
487 /// By default, invokes TransformDecl() to transform the declaration.
488 /// Subclasses may override this function to provide alternate behavior.
489 Decl
*TransformDefinition(SourceLocation Loc
, Decl
*D
) {
490 return getDerived().TransformDecl(Loc
, D
);
493 /// Transform the given declaration, which was the first part of a
494 /// nested-name-specifier in a member access expression.
496 /// This specific declaration transformation only applies to the first
497 /// identifier in a nested-name-specifier of a member access expression, e.g.,
498 /// the \c T in \c x->T::member
500 /// By default, invokes TransformDecl() to transform the declaration.
501 /// Subclasses may override this function to provide alternate behavior.
502 NamedDecl
*TransformFirstQualifierInScope(NamedDecl
*D
, SourceLocation Loc
) {
503 return cast_or_null
<NamedDecl
>(getDerived().TransformDecl(Loc
, D
));
506 /// Transform the set of declarations in an OverloadExpr.
507 bool TransformOverloadExprDecls(OverloadExpr
*Old
, bool RequiresADL
,
510 /// Transform the given nested-name-specifier with source-location
513 /// By default, transforms all of the types and declarations within the
514 /// nested-name-specifier. Subclasses may override this function to provide
515 /// alternate behavior.
516 NestedNameSpecifierLoc
517 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS
,
518 QualType ObjectType
= QualType(),
519 NamedDecl
*FirstQualifierInScope
= nullptr);
521 /// Transform the given declaration name.
523 /// By default, transforms the types of conversion function, constructor,
524 /// and destructor names and then (if needed) rebuilds the declaration name.
525 /// Identifiers and selectors are returned unmodified. Subclasses may
526 /// override this function to provide alternate behavior.
528 TransformDeclarationNameInfo(const DeclarationNameInfo
&NameInfo
);
530 bool TransformRequiresExprRequirements(ArrayRef
<concepts::Requirement
*> Reqs
,
531 llvm::SmallVectorImpl
<concepts::Requirement
*> &Transformed
);
532 concepts::TypeRequirement
*
533 TransformTypeRequirement(concepts::TypeRequirement
*Req
);
534 concepts::ExprRequirement
*
535 TransformExprRequirement(concepts::ExprRequirement
*Req
);
536 concepts::NestedRequirement
*
537 TransformNestedRequirement(concepts::NestedRequirement
*Req
);
539 /// Transform the given template name.
541 /// \param SS The nested-name-specifier that qualifies the template
542 /// name. This nested-name-specifier must already have been transformed.
544 /// \param Name The template name to transform.
546 /// \param NameLoc The source location of the template name.
548 /// \param ObjectType If we're translating a template name within a member
549 /// access expression, this is the type of the object whose member template
550 /// is being referenced.
552 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
553 /// also refers to a name within the current (lexical) scope, this is the
554 /// declaration it refers to.
556 /// By default, transforms the template name by transforming the declarations
557 /// and nested-name-specifiers that occur within the template name.
558 /// Subclasses may override this function to provide alternate behavior.
560 TransformTemplateName(CXXScopeSpec
&SS
, TemplateName Name
,
561 SourceLocation NameLoc
,
562 QualType ObjectType
= QualType(),
563 NamedDecl
*FirstQualifierInScope
= nullptr,
564 bool AllowInjectedClassName
= false);
566 /// Transform the given template argument.
568 /// By default, this operation transforms the type, expression, or
569 /// declaration stored within the template argument and constructs a
570 /// new template argument from the transformed result. Subclasses may
571 /// override this function to provide alternate behavior.
573 /// Returns true if there was an error.
574 bool TransformTemplateArgument(const TemplateArgumentLoc
&Input
,
575 TemplateArgumentLoc
&Output
,
576 bool Uneval
= false);
578 /// Transform the given set of template arguments.
580 /// By default, this operation transforms all of the template arguments
581 /// in the input set using \c TransformTemplateArgument(), and appends
582 /// the transformed arguments to the output list.
584 /// Note that this overload of \c TransformTemplateArguments() is merely
585 /// a convenience function. Subclasses that wish to override this behavior
586 /// should override the iterator-based member template version.
588 /// \param Inputs The set of template arguments to be transformed.
590 /// \param NumInputs The number of template arguments in \p Inputs.
592 /// \param Outputs The set of transformed template arguments output by this
595 /// Returns true if an error occurred.
596 bool TransformTemplateArguments(const TemplateArgumentLoc
*Inputs
,
598 TemplateArgumentListInfo
&Outputs
,
599 bool Uneval
= false) {
600 return TransformTemplateArguments(Inputs
, Inputs
+ NumInputs
, Outputs
,
604 /// Transform the given set of template arguments.
606 /// By default, this operation transforms all of the template arguments
607 /// in the input set using \c TransformTemplateArgument(), and appends
608 /// the transformed arguments to the output list.
610 /// \param First An iterator to the first template argument.
612 /// \param Last An iterator one step past the last template argument.
614 /// \param Outputs The set of transformed template arguments output by this
617 /// Returns true if an error occurred.
618 template<typename InputIterator
>
619 bool TransformTemplateArguments(InputIterator First
,
621 TemplateArgumentListInfo
&Outputs
,
622 bool Uneval
= false);
624 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
625 void InventTemplateArgumentLoc(const TemplateArgument
&Arg
,
626 TemplateArgumentLoc
&ArgLoc
);
628 /// Fakes up a TypeSourceInfo for a type.
629 TypeSourceInfo
*InventTypeSourceInfo(QualType T
) {
630 return SemaRef
.Context
.getTrivialTypeSourceInfo(T
,
631 getDerived().getBaseLocation());
634 #define ABSTRACT_TYPELOC(CLASS, PARENT)
635 #define TYPELOC(CLASS, PARENT) \
636 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
637 #include "clang/AST/TypeLocNodes.def"
639 template<typename Fn
>
640 QualType
TransformFunctionProtoType(TypeLocBuilder
&TLB
,
641 FunctionProtoTypeLoc TL
,
642 CXXRecordDecl
*ThisContext
,
643 Qualifiers ThisTypeQuals
,
644 Fn TransformExceptionSpec
);
646 bool TransformExceptionSpec(SourceLocation Loc
,
647 FunctionProtoType::ExceptionSpecInfo
&ESI
,
648 SmallVectorImpl
<QualType
> &Exceptions
,
651 StmtResult
TransformSEHHandler(Stmt
*Handler
);
654 TransformTemplateSpecializationType(TypeLocBuilder
&TLB
,
655 TemplateSpecializationTypeLoc TL
,
656 TemplateName Template
);
659 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
660 DependentTemplateSpecializationTypeLoc TL
,
661 TemplateName Template
,
664 QualType
TransformDependentTemplateSpecializationType(
665 TypeLocBuilder
&TLB
, DependentTemplateSpecializationTypeLoc TL
,
666 NestedNameSpecifierLoc QualifierLoc
);
668 /// Transforms the parameters of a function type into the
671 /// The result vectors should be kept in sync; null entries in the
672 /// variables vector are acceptable.
674 /// Return true on error.
675 bool TransformFunctionTypeParams(
676 SourceLocation Loc
, ArrayRef
<ParmVarDecl
*> Params
,
677 const QualType
*ParamTypes
,
678 const FunctionProtoType::ExtParameterInfo
*ParamInfos
,
679 SmallVectorImpl
<QualType
> &PTypes
, SmallVectorImpl
<ParmVarDecl
*> *PVars
,
680 Sema::ExtParameterInfoBuilder
&PInfos
);
682 /// Transforms a single function-type parameter. Return null
685 /// \param indexAdjustment - A number to add to the parameter's
686 /// scope index; can be negative
687 ParmVarDecl
*TransformFunctionTypeParam(ParmVarDecl
*OldParm
,
689 Optional
<unsigned> NumExpansions
,
690 bool ExpectParameterPack
);
692 /// Transform the body of a lambda-expression.
693 StmtResult
TransformLambdaBody(LambdaExpr
*E
, Stmt
*Body
);
694 /// Alternative implementation of TransformLambdaBody that skips transforming
696 StmtResult
SkipLambdaBody(LambdaExpr
*E
, Stmt
*Body
);
698 QualType
TransformReferenceType(TypeLocBuilder
&TLB
, ReferenceTypeLoc TL
);
700 StmtResult
TransformCompoundStmt(CompoundStmt
*S
, bool IsStmtExpr
);
701 ExprResult
TransformCXXNamedCastExpr(CXXNamedCastExpr
*E
);
703 TemplateParameterList
*TransformTemplateParameterList(
704 TemplateParameterList
*TPL
) {
708 ExprResult
TransformAddressOfOperand(Expr
*E
);
710 ExprResult
TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr
*E
,
711 bool IsAddressOfOperand
,
712 TypeSourceInfo
**RecoveryTSI
);
714 ExprResult
TransformParenDependentScopeDeclRefExpr(
715 ParenExpr
*PE
, DependentScopeDeclRefExpr
*DRE
, bool IsAddressOfOperand
,
716 TypeSourceInfo
**RecoveryTSI
);
718 StmtResult
TransformOMPExecutableDirective(OMPExecutableDirective
*S
);
720 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
721 // amount of stack usage with clang.
722 #define STMT(Node, Parent) \
723 LLVM_ATTRIBUTE_NOINLINE \
724 StmtResult Transform##Node(Node *S);
725 #define VALUESTMT(Node, Parent) \
726 LLVM_ATTRIBUTE_NOINLINE \
727 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
728 #define EXPR(Node, Parent) \
729 LLVM_ATTRIBUTE_NOINLINE \
730 ExprResult Transform##Node(Node *E);
731 #define ABSTRACT_STMT(Stmt)
732 #include "clang/AST/StmtNodes.inc"
734 #define GEN_CLANG_CLAUSE_CLASS
735 #define CLAUSE_CLASS(Enum, Str, Class) \
736 LLVM_ATTRIBUTE_NOINLINE \
737 OMPClause *Transform##Class(Class *S);
738 #include "llvm/Frontend/OpenMP/OMP.inc"
740 /// Build a new qualified type given its unqualified type and type location.
742 /// By default, this routine adds type qualifiers only to types that can
743 /// have qualifiers, and silently suppresses those qualifiers that are not
744 /// permitted. Subclasses may override this routine to provide different
746 QualType
RebuildQualifiedType(QualType T
, QualifiedTypeLoc TL
);
748 /// Build a new pointer type given its pointee type.
750 /// By default, performs semantic analysis when building the pointer type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType
RebuildPointerType(QualType PointeeType
, SourceLocation Sigil
);
754 /// Build a new block pointer type given its pointee type.
756 /// By default, performs semantic analysis when building the block pointer
757 /// type. Subclasses may override this routine to provide different behavior.
758 QualType
RebuildBlockPointerType(QualType PointeeType
, SourceLocation Sigil
);
760 /// Build a new reference type given the type it references.
762 /// By default, performs semantic analysis when building the
763 /// reference type. Subclasses may override this routine to provide
764 /// different behavior.
766 /// \param LValue whether the type was written with an lvalue sigil
767 /// or an rvalue sigil.
768 QualType
RebuildReferenceType(QualType ReferentType
,
770 SourceLocation Sigil
);
772 /// Build a new member pointer type given the pointee type and the
773 /// class type it refers into.
775 /// By default, performs semantic analysis when building the member pointer
776 /// type. Subclasses may override this routine to provide different behavior.
777 QualType
RebuildMemberPointerType(QualType PointeeType
, QualType ClassType
,
778 SourceLocation Sigil
);
780 QualType
RebuildObjCTypeParamType(const ObjCTypeParamDecl
*Decl
,
781 SourceLocation ProtocolLAngleLoc
,
782 ArrayRef
<ObjCProtocolDecl
*> Protocols
,
783 ArrayRef
<SourceLocation
> ProtocolLocs
,
784 SourceLocation ProtocolRAngleLoc
);
786 /// Build an Objective-C object type.
788 /// By default, performs semantic analysis when building the object type.
789 /// Subclasses may override this routine to provide different behavior.
790 QualType
RebuildObjCObjectType(QualType BaseType
,
792 SourceLocation TypeArgsLAngleLoc
,
793 ArrayRef
<TypeSourceInfo
*> TypeArgs
,
794 SourceLocation TypeArgsRAngleLoc
,
795 SourceLocation ProtocolLAngleLoc
,
796 ArrayRef
<ObjCProtocolDecl
*> Protocols
,
797 ArrayRef
<SourceLocation
> ProtocolLocs
,
798 SourceLocation ProtocolRAngleLoc
);
800 /// Build a new Objective-C object pointer type given the pointee type.
802 /// By default, directly builds the pointer type, with no additional semantic
804 QualType
RebuildObjCObjectPointerType(QualType PointeeType
,
805 SourceLocation Star
);
807 /// Build a new array type given the element type, size
808 /// modifier, size of the array (if known), size expression, and index type
811 /// By default, performs semantic analysis when building the array type.
812 /// Subclasses may override this routine to provide different behavior.
813 /// Also by default, all of the other Rebuild*Array
814 QualType
RebuildArrayType(QualType ElementType
,
815 ArrayType::ArraySizeModifier SizeMod
,
816 const llvm::APInt
*Size
,
818 unsigned IndexTypeQuals
,
819 SourceRange BracketsRange
);
821 /// Build a new constant array type given the element type, size
822 /// modifier, (known) size of the array, and index type qualifiers.
824 /// By default, performs semantic analysis when building the array type.
825 /// Subclasses may override this routine to provide different behavior.
826 QualType
RebuildConstantArrayType(QualType ElementType
,
827 ArrayType::ArraySizeModifier SizeMod
,
828 const llvm::APInt
&Size
,
830 unsigned IndexTypeQuals
,
831 SourceRange BracketsRange
);
833 /// Build a new incomplete array type given the element type, size
834 /// modifier, and index type qualifiers.
836 /// By default, performs semantic analysis when building the array type.
837 /// Subclasses may override this routine to provide different behavior.
838 QualType
RebuildIncompleteArrayType(QualType ElementType
,
839 ArrayType::ArraySizeModifier SizeMod
,
840 unsigned IndexTypeQuals
,
841 SourceRange BracketsRange
);
843 /// Build a new variable-length array type given the element type,
844 /// size modifier, size expression, and index type qualifiers.
846 /// By default, performs semantic analysis when building the array type.
847 /// Subclasses may override this routine to provide different behavior.
848 QualType
RebuildVariableArrayType(QualType ElementType
,
849 ArrayType::ArraySizeModifier SizeMod
,
851 unsigned IndexTypeQuals
,
852 SourceRange BracketsRange
);
854 /// Build a new dependent-sized array type given the element type,
855 /// size modifier, size expression, and index type qualifiers.
857 /// By default, performs semantic analysis when building the array type.
858 /// Subclasses may override this routine to provide different behavior.
859 QualType
RebuildDependentSizedArrayType(QualType ElementType
,
860 ArrayType::ArraySizeModifier SizeMod
,
862 unsigned IndexTypeQuals
,
863 SourceRange BracketsRange
);
865 /// Build a new vector type given the element type and
866 /// number of elements.
868 /// By default, performs semantic analysis when building the vector type.
869 /// Subclasses may override this routine to provide different behavior.
870 QualType
RebuildVectorType(QualType ElementType
, unsigned NumElements
,
871 VectorType::VectorKind VecKind
);
873 /// Build a new potentially dependently-sized extended vector type
874 /// given the element type and number of elements.
876 /// By default, performs semantic analysis when building the vector type.
877 /// Subclasses may override this routine to provide different behavior.
878 QualType
RebuildDependentVectorType(QualType ElementType
, Expr
*SizeExpr
,
879 SourceLocation AttributeLoc
,
880 VectorType::VectorKind
);
882 /// Build a new extended vector type given the element type and
883 /// number of elements.
885 /// By default, performs semantic analysis when building the vector type.
886 /// Subclasses may override this routine to provide different behavior.
887 QualType
RebuildExtVectorType(QualType ElementType
, unsigned NumElements
,
888 SourceLocation AttributeLoc
);
890 /// Build a new potentially dependently-sized extended vector type
891 /// given the element type and number of elements.
893 /// By default, performs semantic analysis when building the vector type.
894 /// Subclasses may override this routine to provide different behavior.
895 QualType
RebuildDependentSizedExtVectorType(QualType ElementType
,
897 SourceLocation AttributeLoc
);
899 /// Build a new matrix type given the element type and dimensions.
900 QualType
RebuildConstantMatrixType(QualType ElementType
, unsigned NumRows
,
901 unsigned NumColumns
);
903 /// Build a new matrix type given the type and dependently-defined
905 QualType
RebuildDependentSizedMatrixType(QualType ElementType
, Expr
*RowExpr
,
907 SourceLocation AttributeLoc
);
909 /// Build a new DependentAddressSpaceType or return the pointee
910 /// type variable with the correct address space (retrieved from
911 /// AddrSpaceExpr) applied to it. The former will be returned in cases
912 /// where the address space remains dependent.
914 /// By default, performs semantic analysis when building the type with address
915 /// space applied. Subclasses may override this routine to provide different
917 QualType
RebuildDependentAddressSpaceType(QualType PointeeType
,
919 SourceLocation AttributeLoc
);
921 /// Build a new function type.
923 /// By default, performs semantic analysis when building the function type.
924 /// Subclasses may override this routine to provide different behavior.
925 QualType
RebuildFunctionProtoType(QualType T
,
926 MutableArrayRef
<QualType
> ParamTypes
,
927 const FunctionProtoType::ExtProtoInfo
&EPI
);
929 /// Build a new unprototyped function type.
930 QualType
RebuildFunctionNoProtoType(QualType ResultType
);
932 /// Rebuild an unresolved typename type, given the decl that
933 /// the UnresolvedUsingTypenameDecl was transformed to.
934 QualType
RebuildUnresolvedUsingType(SourceLocation NameLoc
, Decl
*D
);
936 /// Build a new type found via an alias.
937 QualType
RebuildUsingType(UsingShadowDecl
*Found
, QualType Underlying
) {
938 return SemaRef
.Context
.getUsingType(Found
, Underlying
);
941 /// Build a new typedef type.
942 QualType
RebuildTypedefType(TypedefNameDecl
*Typedef
) {
943 return SemaRef
.Context
.getTypeDeclType(Typedef
);
946 /// Build a new MacroDefined type.
947 QualType
RebuildMacroQualifiedType(QualType T
,
948 const IdentifierInfo
*MacroII
) {
949 return SemaRef
.Context
.getMacroQualifiedType(T
, MacroII
);
952 /// Build a new class/struct/union type.
953 QualType
RebuildRecordType(RecordDecl
*Record
) {
954 return SemaRef
.Context
.getTypeDeclType(Record
);
957 /// Build a new Enum type.
958 QualType
RebuildEnumType(EnumDecl
*Enum
) {
959 return SemaRef
.Context
.getTypeDeclType(Enum
);
962 /// Build a new typeof(expr) type.
964 /// By default, performs semantic analysis when building the typeof type.
965 /// Subclasses may override this routine to provide different behavior.
966 QualType
RebuildTypeOfExprType(Expr
*Underlying
, SourceLocation Loc
);
968 /// Build a new typeof(type) type.
970 /// By default, builds a new TypeOfType with the given underlying type.
971 QualType
RebuildTypeOfType(QualType Underlying
);
973 /// Build a new unary transform type.
974 QualType
RebuildUnaryTransformType(QualType BaseType
,
975 UnaryTransformType::UTTKind UKind
,
978 /// Build a new C++11 decltype type.
980 /// By default, performs semantic analysis when building the decltype type.
981 /// Subclasses may override this routine to provide different behavior.
982 QualType
RebuildDecltypeType(Expr
*Underlying
, SourceLocation Loc
);
984 /// Build a new C++11 auto type.
986 /// By default, builds a new AutoType with the given deduced type.
987 QualType
RebuildAutoType(QualType Deduced
, AutoTypeKeyword Keyword
,
988 ConceptDecl
*TypeConstraintConcept
,
989 ArrayRef
<TemplateArgument
> TypeConstraintArgs
) {
990 // Note, IsDependent is always false here: we implicitly convert an 'auto'
991 // which has been deduced to a dependent type into an undeduced 'auto', so
992 // that we'll retry deduction after the transformation.
993 return SemaRef
.Context
.getAutoType(Deduced
, Keyword
,
994 /*IsDependent*/ false, /*IsPack=*/false,
995 TypeConstraintConcept
,
999 /// By default, builds a new DeducedTemplateSpecializationType with the given
1001 QualType
RebuildDeducedTemplateSpecializationType(TemplateName Template
,
1003 return SemaRef
.Context
.getDeducedTemplateSpecializationType(
1004 Template
, Deduced
, /*IsDependent*/ false);
1007 /// Build a new template specialization type.
1009 /// By default, performs semantic analysis when building the template
1010 /// specialization type. Subclasses may override this routine to provide
1011 /// different behavior.
1012 QualType
RebuildTemplateSpecializationType(TemplateName Template
,
1013 SourceLocation TemplateLoc
,
1014 TemplateArgumentListInfo
&Args
);
1016 /// Build a new parenthesized type.
1018 /// By default, builds a new ParenType type from the inner type.
1019 /// Subclasses may override this routine to provide different behavior.
1020 QualType
RebuildParenType(QualType InnerType
) {
1021 return SemaRef
.BuildParenType(InnerType
);
1024 /// Build a new qualified name type.
1026 /// By default, builds a new ElaboratedType type from the keyword,
1027 /// the nested-name-specifier and the named type.
1028 /// Subclasses may override this routine to provide different behavior.
1029 QualType
RebuildElaboratedType(SourceLocation KeywordLoc
,
1030 ElaboratedTypeKeyword Keyword
,
1031 NestedNameSpecifierLoc QualifierLoc
,
1033 return SemaRef
.Context
.getElaboratedType(Keyword
,
1034 QualifierLoc
.getNestedNameSpecifier(),
1038 /// Build a new typename type that refers to a template-id.
1040 /// By default, builds a new DependentNameType type from the
1041 /// nested-name-specifier and the given type. Subclasses may override
1042 /// this routine to provide different behavior.
1043 QualType
RebuildDependentTemplateSpecializationType(
1044 ElaboratedTypeKeyword Keyword
,
1045 NestedNameSpecifierLoc QualifierLoc
,
1046 SourceLocation TemplateKWLoc
,
1047 const IdentifierInfo
*Name
,
1048 SourceLocation NameLoc
,
1049 TemplateArgumentListInfo
&Args
,
1050 bool AllowInjectedClassName
) {
1051 // Rebuild the template name.
1052 // TODO: avoid TemplateName abstraction
1054 SS
.Adopt(QualifierLoc
);
1055 TemplateName InstName
= getDerived().RebuildTemplateName(
1056 SS
, TemplateKWLoc
, *Name
, NameLoc
, QualType(), nullptr,
1057 AllowInjectedClassName
);
1059 if (InstName
.isNull())
1062 // If it's still dependent, make a dependent specialization.
1063 if (InstName
.getAsDependentTemplateName())
1064 return SemaRef
.Context
.getDependentTemplateSpecializationType(Keyword
,
1065 QualifierLoc
.getNestedNameSpecifier(),
1069 // Otherwise, make an elaborated type wrapping a non-dependent
1072 getDerived().RebuildTemplateSpecializationType(InstName
, NameLoc
, Args
);
1075 return SemaRef
.Context
.getElaboratedType(
1076 Keyword
, QualifierLoc
.getNestedNameSpecifier(), T
);
1079 /// Build a new typename type that refers to an identifier.
1081 /// By default, performs semantic analysis when building the typename type
1082 /// (or elaborated type). Subclasses may override this routine to provide
1083 /// different behavior.
1084 QualType
RebuildDependentNameType(ElaboratedTypeKeyword Keyword
,
1085 SourceLocation KeywordLoc
,
1086 NestedNameSpecifierLoc QualifierLoc
,
1087 const IdentifierInfo
*Id
,
1088 SourceLocation IdLoc
,
1089 bool DeducedTSTContext
) {
1091 SS
.Adopt(QualifierLoc
);
1093 if (QualifierLoc
.getNestedNameSpecifier()->isDependent()) {
1094 // If the name is still dependent, just build a new dependent name type.
1095 if (!SemaRef
.computeDeclContext(SS
))
1096 return SemaRef
.Context
.getDependentNameType(Keyword
,
1097 QualifierLoc
.getNestedNameSpecifier(),
1101 if (Keyword
== ETK_None
|| Keyword
== ETK_Typename
) {
1102 return SemaRef
.CheckTypenameType(Keyword
, KeywordLoc
, QualifierLoc
,
1103 *Id
, IdLoc
, DeducedTSTContext
);
1106 TagTypeKind Kind
= TypeWithKeyword::getTagTypeKindForKeyword(Keyword
);
1108 // We had a dependent elaborated-type-specifier that has been transformed
1109 // into a non-dependent elaborated-type-specifier. Find the tag we're
1111 LookupResult
Result(SemaRef
, Id
, IdLoc
, Sema::LookupTagName
);
1112 DeclContext
*DC
= SemaRef
.computeDeclContext(SS
, false);
1116 if (SemaRef
.RequireCompleteDeclContext(SS
, DC
))
1119 TagDecl
*Tag
= nullptr;
1120 SemaRef
.LookupQualifiedName(Result
, DC
);
1121 switch (Result
.getResultKind()) {
1122 case LookupResult::NotFound
:
1123 case LookupResult::NotFoundInCurrentInstantiation
:
1126 case LookupResult::Found
:
1127 Tag
= Result
.getAsSingle
<TagDecl
>();
1130 case LookupResult::FoundOverloaded
:
1131 case LookupResult::FoundUnresolvedValue
:
1132 llvm_unreachable("Tag lookup cannot find non-tags");
1134 case LookupResult::Ambiguous
:
1135 // Let the LookupResult structure handle ambiguities.
1140 // Check where the name exists but isn't a tag type and use that to emit
1141 // better diagnostics.
1142 LookupResult
Result(SemaRef
, Id
, IdLoc
, Sema::LookupTagName
);
1143 SemaRef
.LookupQualifiedName(Result
, DC
);
1144 switch (Result
.getResultKind()) {
1145 case LookupResult::Found
:
1146 case LookupResult::FoundOverloaded
:
1147 case LookupResult::FoundUnresolvedValue
: {
1148 NamedDecl
*SomeDecl
= Result
.getRepresentativeDecl();
1149 Sema::NonTagKind NTK
= SemaRef
.getNonTagTypeDeclKind(SomeDecl
, Kind
);
1150 SemaRef
.Diag(IdLoc
, diag::err_tag_reference_non_tag
) << SomeDecl
1152 SemaRef
.Diag(SomeDecl
->getLocation(), diag::note_declared_at
);
1156 SemaRef
.Diag(IdLoc
, diag::err_not_tag_in_scope
)
1157 << Kind
<< Id
<< DC
<< QualifierLoc
.getSourceRange();
1163 if (!SemaRef
.isAcceptableTagRedeclaration(Tag
, Kind
, /*isDefinition*/false,
1165 SemaRef
.Diag(KeywordLoc
, diag::err_use_with_wrong_tag
) << Id
;
1166 SemaRef
.Diag(Tag
->getLocation(), diag::note_previous_use
);
1170 // Build the elaborated-type-specifier type.
1171 QualType T
= SemaRef
.Context
.getTypeDeclType(Tag
);
1172 return SemaRef
.Context
.getElaboratedType(Keyword
,
1173 QualifierLoc
.getNestedNameSpecifier(),
1177 /// Build a new pack expansion type.
1179 /// By default, builds a new PackExpansionType type from the given pattern.
1180 /// Subclasses may override this routine to provide different behavior.
1181 QualType
RebuildPackExpansionType(QualType Pattern
,
1182 SourceRange PatternRange
,
1183 SourceLocation EllipsisLoc
,
1184 Optional
<unsigned> NumExpansions
) {
1185 return getSema().CheckPackExpansion(Pattern
, PatternRange
, EllipsisLoc
,
1189 /// Build a new atomic type given its value type.
1191 /// By default, performs semantic analysis when building the atomic type.
1192 /// Subclasses may override this routine to provide different behavior.
1193 QualType
RebuildAtomicType(QualType ValueType
, SourceLocation KWLoc
);
1195 /// Build a new pipe type given its value type.
1196 QualType
RebuildPipeType(QualType ValueType
, SourceLocation KWLoc
,
1199 /// Build a bit-precise int given its value type.
1200 QualType
RebuildBitIntType(bool IsUnsigned
, unsigned NumBits
,
1201 SourceLocation Loc
);
1203 /// Build a dependent bit-precise int given its value type.
1204 QualType
RebuildDependentBitIntType(bool IsUnsigned
, Expr
*NumBitsExpr
,
1205 SourceLocation Loc
);
1207 /// Build a new template name given a nested name specifier, a flag
1208 /// indicating whether the "template" keyword was provided, and the template
1209 /// that the template name refers to.
1211 /// By default, builds the new template name directly. Subclasses may override
1212 /// this routine to provide different behavior.
1213 TemplateName
RebuildTemplateName(CXXScopeSpec
&SS
,
1215 TemplateDecl
*Template
);
1217 /// Build a new template name given a nested name specifier and the
1218 /// name that is referred to as a template.
1220 /// By default, performs semantic analysis to determine whether the name can
1221 /// be resolved to a specific template, then builds the appropriate kind of
1222 /// template name. Subclasses may override this routine to provide different
1224 TemplateName
RebuildTemplateName(CXXScopeSpec
&SS
,
1225 SourceLocation TemplateKWLoc
,
1226 const IdentifierInfo
&Name
,
1227 SourceLocation NameLoc
, QualType ObjectType
,
1228 NamedDecl
*FirstQualifierInScope
,
1229 bool AllowInjectedClassName
);
1231 /// Build a new template name given a nested name specifier and the
1232 /// overloaded operator name that is referred to as a template.
1234 /// By default, performs semantic analysis to determine whether the name can
1235 /// be resolved to a specific template, then builds the appropriate kind of
1236 /// template name. Subclasses may override this routine to provide different
1238 TemplateName
RebuildTemplateName(CXXScopeSpec
&SS
,
1239 SourceLocation TemplateKWLoc
,
1240 OverloadedOperatorKind Operator
,
1241 SourceLocation NameLoc
, QualType ObjectType
,
1242 bool AllowInjectedClassName
);
1244 /// Build a new template name given a template template parameter pack
1247 /// By default, performs semantic analysis to determine whether the name can
1248 /// be resolved to a specific template, then builds the appropriate kind of
1249 /// template name. Subclasses may override this routine to provide different
1251 TemplateName
RebuildTemplateName(TemplateTemplateParmDecl
*Param
,
1252 const TemplateArgument
&ArgPack
) {
1253 return getSema().Context
.getSubstTemplateTemplateParmPack(Param
, ArgPack
);
1256 /// Build a new compound statement.
1258 /// By default, performs semantic analysis to build the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
1260 StmtResult
RebuildCompoundStmt(SourceLocation LBraceLoc
,
1261 MultiStmtArg Statements
,
1262 SourceLocation RBraceLoc
,
1264 return getSema().ActOnCompoundStmt(LBraceLoc
, RBraceLoc
, Statements
,
1268 /// Build a new case statement.
1270 /// By default, performs semantic analysis to build the new statement.
1271 /// Subclasses may override this routine to provide different behavior.
1272 StmtResult
RebuildCaseStmt(SourceLocation CaseLoc
,
1274 SourceLocation EllipsisLoc
,
1276 SourceLocation ColonLoc
) {
1277 return getSema().ActOnCaseStmt(CaseLoc
, LHS
, EllipsisLoc
, RHS
,
1281 /// Attach the body to a new case statement.
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult
RebuildCaseStmtBody(Stmt
*S
, Stmt
*Body
) {
1286 getSema().ActOnCaseStmtBody(S
, Body
);
1290 /// Build a new default statement.
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 StmtResult
RebuildDefaultStmt(SourceLocation DefaultLoc
,
1295 SourceLocation ColonLoc
,
1297 return getSema().ActOnDefaultStmt(DefaultLoc
, ColonLoc
, SubStmt
,
1298 /*CurScope=*/nullptr);
1301 /// Build a new label statement.
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
1305 StmtResult
RebuildLabelStmt(SourceLocation IdentLoc
, LabelDecl
*L
,
1306 SourceLocation ColonLoc
, Stmt
*SubStmt
) {
1307 return SemaRef
.ActOnLabelStmt(IdentLoc
, L
, ColonLoc
, SubStmt
);
1310 /// Build a new attributed statement.
1312 /// By default, performs semantic analysis to build the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
1314 StmtResult
RebuildAttributedStmt(SourceLocation AttrLoc
,
1315 ArrayRef
<const Attr
*> Attrs
,
1317 return SemaRef
.BuildAttributedStmt(AttrLoc
, Attrs
, SubStmt
);
1320 /// Build a new "if" statement.
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
1324 StmtResult
RebuildIfStmt(SourceLocation IfLoc
, IfStatementKind Kind
,
1325 SourceLocation LParenLoc
, Sema::ConditionResult Cond
,
1326 SourceLocation RParenLoc
, Stmt
*Init
, Stmt
*Then
,
1327 SourceLocation ElseLoc
, Stmt
*Else
) {
1328 return getSema().ActOnIfStmt(IfLoc
, Kind
, LParenLoc
, Init
, Cond
, RParenLoc
,
1329 Then
, ElseLoc
, Else
);
1332 /// Start building a new switch statement.
1334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
1336 StmtResult
RebuildSwitchStmtStart(SourceLocation SwitchLoc
,
1337 SourceLocation LParenLoc
, Stmt
*Init
,
1338 Sema::ConditionResult Cond
,
1339 SourceLocation RParenLoc
) {
1340 return getSema().ActOnStartOfSwitchStmt(SwitchLoc
, LParenLoc
, Init
, Cond
,
1344 /// Attach the body to the switch statement.
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
1348 StmtResult
RebuildSwitchStmtBody(SourceLocation SwitchLoc
,
1349 Stmt
*Switch
, Stmt
*Body
) {
1350 return getSema().ActOnFinishSwitchStmt(SwitchLoc
, Switch
, Body
);
1353 /// Build a new while statement.
1355 /// By default, performs semantic analysis to build the new statement.
1356 /// Subclasses may override this routine to provide different behavior.
1357 StmtResult
RebuildWhileStmt(SourceLocation WhileLoc
, SourceLocation LParenLoc
,
1358 Sema::ConditionResult Cond
,
1359 SourceLocation RParenLoc
, Stmt
*Body
) {
1360 return getSema().ActOnWhileStmt(WhileLoc
, LParenLoc
, Cond
, RParenLoc
, Body
);
1363 /// Build a new do-while statement.
1365 /// By default, performs semantic analysis to build the new statement.
1366 /// Subclasses may override this routine to provide different behavior.
1367 StmtResult
RebuildDoStmt(SourceLocation DoLoc
, Stmt
*Body
,
1368 SourceLocation WhileLoc
, SourceLocation LParenLoc
,
1369 Expr
*Cond
, SourceLocation RParenLoc
) {
1370 return getSema().ActOnDoStmt(DoLoc
, Body
, WhileLoc
, LParenLoc
,
1374 /// Build a new for statement.
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
1378 StmtResult
RebuildForStmt(SourceLocation ForLoc
, SourceLocation LParenLoc
,
1379 Stmt
*Init
, Sema::ConditionResult Cond
,
1380 Sema::FullExprArg Inc
, SourceLocation RParenLoc
,
1382 return getSema().ActOnForStmt(ForLoc
, LParenLoc
, Init
, Cond
,
1383 Inc
, RParenLoc
, Body
);
1386 /// Build a new goto statement.
1388 /// By default, performs semantic analysis to build the new statement.
1389 /// Subclasses may override this routine to provide different behavior.
1390 StmtResult
RebuildGotoStmt(SourceLocation GotoLoc
, SourceLocation LabelLoc
,
1392 return getSema().ActOnGotoStmt(GotoLoc
, LabelLoc
, Label
);
1395 /// Build a new indirect goto statement.
1397 /// By default, performs semantic analysis to build the new statement.
1398 /// Subclasses may override this routine to provide different behavior.
1399 StmtResult
RebuildIndirectGotoStmt(SourceLocation GotoLoc
,
1400 SourceLocation StarLoc
,
1402 return getSema().ActOnIndirectGotoStmt(GotoLoc
, StarLoc
, Target
);
1405 /// Build a new return statement.
1407 /// By default, performs semantic analysis to build the new statement.
1408 /// Subclasses may override this routine to provide different behavior.
1409 StmtResult
RebuildReturnStmt(SourceLocation ReturnLoc
, Expr
*Result
) {
1410 return getSema().BuildReturnStmt(ReturnLoc
, Result
);
1413 /// Build a new declaration statement.
1415 /// By default, performs semantic analysis to build the new statement.
1416 /// Subclasses may override this routine to provide different behavior.
1417 StmtResult
RebuildDeclStmt(MutableArrayRef
<Decl
*> Decls
,
1418 SourceLocation StartLoc
, SourceLocation EndLoc
) {
1419 Sema::DeclGroupPtrTy DG
= getSema().BuildDeclaratorGroup(Decls
);
1420 return getSema().ActOnDeclStmt(DG
, StartLoc
, EndLoc
);
1423 /// Build a new inline asm statement.
1425 /// By default, performs semantic analysis to build the new statement.
1426 /// Subclasses may override this routine to provide different behavior.
1427 StmtResult
RebuildGCCAsmStmt(SourceLocation AsmLoc
, bool IsSimple
,
1428 bool IsVolatile
, unsigned NumOutputs
,
1429 unsigned NumInputs
, IdentifierInfo
**Names
,
1430 MultiExprArg Constraints
, MultiExprArg Exprs
,
1431 Expr
*AsmString
, MultiExprArg Clobbers
,
1433 SourceLocation RParenLoc
) {
1434 return getSema().ActOnGCCAsmStmt(AsmLoc
, IsSimple
, IsVolatile
, NumOutputs
,
1435 NumInputs
, Names
, Constraints
, Exprs
,
1436 AsmString
, Clobbers
, NumLabels
, RParenLoc
);
1439 /// Build a new MS style inline asm statement.
1441 /// By default, performs semantic analysis to build the new statement.
1442 /// Subclasses may override this routine to provide different behavior.
1443 StmtResult
RebuildMSAsmStmt(SourceLocation AsmLoc
, SourceLocation LBraceLoc
,
1444 ArrayRef
<Token
> AsmToks
,
1445 StringRef AsmString
,
1446 unsigned NumOutputs
, unsigned NumInputs
,
1447 ArrayRef
<StringRef
> Constraints
,
1448 ArrayRef
<StringRef
> Clobbers
,
1449 ArrayRef
<Expr
*> Exprs
,
1450 SourceLocation EndLoc
) {
1451 return getSema().ActOnMSAsmStmt(AsmLoc
, LBraceLoc
, AsmToks
, AsmString
,
1452 NumOutputs
, NumInputs
,
1453 Constraints
, Clobbers
, Exprs
, EndLoc
);
1456 /// Build a new co_return statement.
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
1460 StmtResult
RebuildCoreturnStmt(SourceLocation CoreturnLoc
, Expr
*Result
,
1462 return getSema().BuildCoreturnStmt(CoreturnLoc
, Result
, IsImplicit
);
1465 /// Build a new co_await expression.
1467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
1469 ExprResult
RebuildCoawaitExpr(SourceLocation CoawaitLoc
, Expr
*Operand
,
1470 UnresolvedLookupExpr
*OpCoawaitLookup
,
1472 // This function rebuilds a coawait-expr given its operator.
1473 // For an explicit coawait-expr, the rebuild involves the full set
1474 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1475 // including calling await_transform().
1476 // For an implicit coawait-expr, we need to rebuild the "operator
1477 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1478 // This mirrors how the implicit CoawaitExpr is originally created
1479 // in Sema::ActOnCoroutineBodyStart().
1481 ExprResult Suspend
= getSema().BuildOperatorCoawaitCall(
1482 CoawaitLoc
, Operand
, OpCoawaitLookup
);
1483 if (Suspend
.isInvalid())
1485 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc
, Operand
,
1486 Suspend
.get(), true);
1489 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc
, Operand
,
1493 /// Build a new co_await expression.
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
1497 ExprResult
RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc
,
1499 UnresolvedLookupExpr
*Lookup
) {
1500 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc
, Result
, Lookup
);
1503 /// Build a new co_yield expression.
1505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
1507 ExprResult
RebuildCoyieldExpr(SourceLocation CoyieldLoc
, Expr
*Result
) {
1508 return getSema().BuildCoyieldExpr(CoyieldLoc
, Result
);
1511 StmtResult
RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args
) {
1512 return getSema().BuildCoroutineBodyStmt(Args
);
1515 /// Build a new Objective-C \@try statement.
1517 /// By default, performs semantic analysis to build the new statement.
1518 /// Subclasses may override this routine to provide different behavior.
1519 StmtResult
RebuildObjCAtTryStmt(SourceLocation AtLoc
,
1521 MultiStmtArg CatchStmts
,
1523 return getSema().ActOnObjCAtTryStmt(AtLoc
, TryBody
, CatchStmts
,
1527 /// Rebuild an Objective-C exception declaration.
1529 /// By default, performs semantic analysis to build the new declaration.
1530 /// Subclasses may override this routine to provide different behavior.
1531 VarDecl
*RebuildObjCExceptionDecl(VarDecl
*ExceptionDecl
,
1532 TypeSourceInfo
*TInfo
, QualType T
) {
1533 return getSema().BuildObjCExceptionDecl(TInfo
, T
,
1534 ExceptionDecl
->getInnerLocStart(),
1535 ExceptionDecl
->getLocation(),
1536 ExceptionDecl
->getIdentifier());
1539 /// Build a new Objective-C \@catch statement.
1541 /// By default, performs semantic analysis to build the new statement.
1542 /// Subclasses may override this routine to provide different behavior.
1543 StmtResult
RebuildObjCAtCatchStmt(SourceLocation AtLoc
,
1544 SourceLocation RParenLoc
,
1547 return getSema().ActOnObjCAtCatchStmt(AtLoc
, RParenLoc
,
1551 /// Build a new Objective-C \@finally statement.
1553 /// By default, performs semantic analysis to build the new statement.
1554 /// Subclasses may override this routine to provide different behavior.
1555 StmtResult
RebuildObjCAtFinallyStmt(SourceLocation AtLoc
,
1557 return getSema().ActOnObjCAtFinallyStmt(AtLoc
, Body
);
1560 /// Build a new Objective-C \@throw statement.
1562 /// By default, performs semantic analysis to build the new statement.
1563 /// Subclasses may override this routine to provide different behavior.
1564 StmtResult
RebuildObjCAtThrowStmt(SourceLocation AtLoc
,
1566 return getSema().BuildObjCAtThrowStmt(AtLoc
, Operand
);
1569 /// Build a new OpenMP Canonical loop.
1571 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1572 /// OMPCanonicalLoop.
1573 StmtResult
RebuildOMPCanonicalLoop(Stmt
*LoopStmt
) {
1574 return getSema().ActOnOpenMPCanonicalLoop(LoopStmt
);
1577 /// Build a new OpenMP executable directive.
1579 /// By default, performs semantic analysis to build the new statement.
1580 /// Subclasses may override this routine to provide different behavior.
1581 StmtResult
RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind
,
1582 DeclarationNameInfo DirName
,
1583 OpenMPDirectiveKind CancelRegion
,
1584 ArrayRef
<OMPClause
*> Clauses
,
1585 Stmt
*AStmt
, SourceLocation StartLoc
,
1586 SourceLocation EndLoc
) {
1587 return getSema().ActOnOpenMPExecutableDirective(
1588 Kind
, DirName
, CancelRegion
, Clauses
, AStmt
, StartLoc
, EndLoc
);
1591 /// Build a new OpenMP 'if' clause.
1593 /// By default, performs semantic analysis to build the new OpenMP clause.
1594 /// Subclasses may override this routine to provide different behavior.
1595 OMPClause
*RebuildOMPIfClause(OpenMPDirectiveKind NameModifier
,
1596 Expr
*Condition
, SourceLocation StartLoc
,
1597 SourceLocation LParenLoc
,
1598 SourceLocation NameModifierLoc
,
1599 SourceLocation ColonLoc
,
1600 SourceLocation EndLoc
) {
1601 return getSema().ActOnOpenMPIfClause(NameModifier
, Condition
, StartLoc
,
1602 LParenLoc
, NameModifierLoc
, ColonLoc
,
1606 /// Build a new OpenMP 'final' clause.
1608 /// By default, performs semantic analysis to build the new OpenMP clause.
1609 /// Subclasses may override this routine to provide different behavior.
1610 OMPClause
*RebuildOMPFinalClause(Expr
*Condition
, SourceLocation StartLoc
,
1611 SourceLocation LParenLoc
,
1612 SourceLocation EndLoc
) {
1613 return getSema().ActOnOpenMPFinalClause(Condition
, StartLoc
, LParenLoc
,
1617 /// Build a new OpenMP 'num_threads' clause.
1619 /// By default, performs semantic analysis to build the new OpenMP clause.
1620 /// Subclasses may override this routine to provide different behavior.
1621 OMPClause
*RebuildOMPNumThreadsClause(Expr
*NumThreads
,
1622 SourceLocation StartLoc
,
1623 SourceLocation LParenLoc
,
1624 SourceLocation EndLoc
) {
1625 return getSema().ActOnOpenMPNumThreadsClause(NumThreads
, StartLoc
,
1629 /// Build a new OpenMP 'safelen' clause.
1631 /// By default, performs semantic analysis to build the new OpenMP clause.
1632 /// Subclasses may override this routine to provide different behavior.
1633 OMPClause
*RebuildOMPSafelenClause(Expr
*Len
, SourceLocation StartLoc
,
1634 SourceLocation LParenLoc
,
1635 SourceLocation EndLoc
) {
1636 return getSema().ActOnOpenMPSafelenClause(Len
, StartLoc
, LParenLoc
, EndLoc
);
1639 /// Build a new OpenMP 'simdlen' clause.
1641 /// By default, performs semantic analysis to build the new OpenMP clause.
1642 /// Subclasses may override this routine to provide different behavior.
1643 OMPClause
*RebuildOMPSimdlenClause(Expr
*Len
, SourceLocation StartLoc
,
1644 SourceLocation LParenLoc
,
1645 SourceLocation EndLoc
) {
1646 return getSema().ActOnOpenMPSimdlenClause(Len
, StartLoc
, LParenLoc
, EndLoc
);
1649 OMPClause
*RebuildOMPSizesClause(ArrayRef
<Expr
*> Sizes
,
1650 SourceLocation StartLoc
,
1651 SourceLocation LParenLoc
,
1652 SourceLocation EndLoc
) {
1653 return getSema().ActOnOpenMPSizesClause(Sizes
, StartLoc
, LParenLoc
, EndLoc
);
1656 /// Build a new OpenMP 'full' clause.
1657 OMPClause
*RebuildOMPFullClause(SourceLocation StartLoc
,
1658 SourceLocation EndLoc
) {
1659 return getSema().ActOnOpenMPFullClause(StartLoc
, EndLoc
);
1662 /// Build a new OpenMP 'partial' clause.
1663 OMPClause
*RebuildOMPPartialClause(Expr
*Factor
, SourceLocation StartLoc
,
1664 SourceLocation LParenLoc
,
1665 SourceLocation EndLoc
) {
1666 return getSema().ActOnOpenMPPartialClause(Factor
, StartLoc
, LParenLoc
,
1670 /// Build a new OpenMP 'allocator' clause.
1672 /// By default, performs semantic analysis to build the new OpenMP clause.
1673 /// Subclasses may override this routine to provide different behavior.
1674 OMPClause
*RebuildOMPAllocatorClause(Expr
*A
, SourceLocation StartLoc
,
1675 SourceLocation LParenLoc
,
1676 SourceLocation EndLoc
) {
1677 return getSema().ActOnOpenMPAllocatorClause(A
, StartLoc
, LParenLoc
, EndLoc
);
1680 /// Build a new OpenMP 'collapse' clause.
1682 /// By default, performs semantic analysis to build the new OpenMP clause.
1683 /// Subclasses may override this routine to provide different behavior.
1684 OMPClause
*RebuildOMPCollapseClause(Expr
*Num
, SourceLocation StartLoc
,
1685 SourceLocation LParenLoc
,
1686 SourceLocation EndLoc
) {
1687 return getSema().ActOnOpenMPCollapseClause(Num
, StartLoc
, LParenLoc
,
1691 /// Build a new OpenMP 'default' clause.
1693 /// By default, performs semantic analysis to build the new OpenMP clause.
1694 /// Subclasses may override this routine to provide different behavior.
1695 OMPClause
*RebuildOMPDefaultClause(DefaultKind Kind
, SourceLocation KindKwLoc
,
1696 SourceLocation StartLoc
,
1697 SourceLocation LParenLoc
,
1698 SourceLocation EndLoc
) {
1699 return getSema().ActOnOpenMPDefaultClause(Kind
, KindKwLoc
,
1700 StartLoc
, LParenLoc
, EndLoc
);
1703 /// Build a new OpenMP 'proc_bind' clause.
1705 /// By default, performs semantic analysis to build the new OpenMP clause.
1706 /// Subclasses may override this routine to provide different behavior.
1707 OMPClause
*RebuildOMPProcBindClause(ProcBindKind Kind
,
1708 SourceLocation KindKwLoc
,
1709 SourceLocation StartLoc
,
1710 SourceLocation LParenLoc
,
1711 SourceLocation EndLoc
) {
1712 return getSema().ActOnOpenMPProcBindClause(Kind
, KindKwLoc
,
1713 StartLoc
, LParenLoc
, EndLoc
);
1716 /// Build a new OpenMP 'schedule' clause.
1718 /// By default, performs semantic analysis to build the new OpenMP clause.
1719 /// Subclasses may override this routine to provide different behavior.
1720 OMPClause
*RebuildOMPScheduleClause(
1721 OpenMPScheduleClauseModifier M1
, OpenMPScheduleClauseModifier M2
,
1722 OpenMPScheduleClauseKind Kind
, Expr
*ChunkSize
, SourceLocation StartLoc
,
1723 SourceLocation LParenLoc
, SourceLocation M1Loc
, SourceLocation M2Loc
,
1724 SourceLocation KindLoc
, SourceLocation CommaLoc
, SourceLocation EndLoc
) {
1725 return getSema().ActOnOpenMPScheduleClause(
1726 M1
, M2
, Kind
, ChunkSize
, StartLoc
, LParenLoc
, M1Loc
, M2Loc
, KindLoc
,
1730 /// Build a new OpenMP 'ordered' clause.
1732 /// By default, performs semantic analysis to build the new OpenMP clause.
1733 /// Subclasses may override this routine to provide different behavior.
1734 OMPClause
*RebuildOMPOrderedClause(SourceLocation StartLoc
,
1735 SourceLocation EndLoc
,
1736 SourceLocation LParenLoc
, Expr
*Num
) {
1737 return getSema().ActOnOpenMPOrderedClause(StartLoc
, EndLoc
, LParenLoc
, Num
);
1740 /// Build a new OpenMP 'private' clause.
1742 /// By default, performs semantic analysis to build the new OpenMP clause.
1743 /// Subclasses may override this routine to provide different behavior.
1744 OMPClause
*RebuildOMPPrivateClause(ArrayRef
<Expr
*> VarList
,
1745 SourceLocation StartLoc
,
1746 SourceLocation LParenLoc
,
1747 SourceLocation EndLoc
) {
1748 return getSema().ActOnOpenMPPrivateClause(VarList
, StartLoc
, LParenLoc
,
1752 /// Build a new OpenMP 'firstprivate' clause.
1754 /// By default, performs semantic analysis to build the new OpenMP clause.
1755 /// Subclasses may override this routine to provide different behavior.
1756 OMPClause
*RebuildOMPFirstprivateClause(ArrayRef
<Expr
*> VarList
,
1757 SourceLocation StartLoc
,
1758 SourceLocation LParenLoc
,
1759 SourceLocation EndLoc
) {
1760 return getSema().ActOnOpenMPFirstprivateClause(VarList
, StartLoc
, LParenLoc
,
1764 /// Build a new OpenMP 'lastprivate' clause.
1766 /// By default, performs semantic analysis to build the new OpenMP clause.
1767 /// Subclasses may override this routine to provide different behavior.
1768 OMPClause
*RebuildOMPLastprivateClause(ArrayRef
<Expr
*> VarList
,
1769 OpenMPLastprivateModifier LPKind
,
1770 SourceLocation LPKindLoc
,
1771 SourceLocation ColonLoc
,
1772 SourceLocation StartLoc
,
1773 SourceLocation LParenLoc
,
1774 SourceLocation EndLoc
) {
1775 return getSema().ActOnOpenMPLastprivateClause(
1776 VarList
, LPKind
, LPKindLoc
, ColonLoc
, StartLoc
, LParenLoc
, EndLoc
);
1779 /// Build a new OpenMP 'shared' clause.
1781 /// By default, performs semantic analysis to build the new OpenMP clause.
1782 /// Subclasses may override this routine to provide different behavior.
1783 OMPClause
*RebuildOMPSharedClause(ArrayRef
<Expr
*> VarList
,
1784 SourceLocation StartLoc
,
1785 SourceLocation LParenLoc
,
1786 SourceLocation EndLoc
) {
1787 return getSema().ActOnOpenMPSharedClause(VarList
, StartLoc
, LParenLoc
,
1791 /// Build a new OpenMP 'reduction' clause.
1793 /// By default, performs semantic analysis to build the new statement.
1794 /// Subclasses may override this routine to provide different behavior.
1795 OMPClause
*RebuildOMPReductionClause(
1796 ArrayRef
<Expr
*> VarList
, OpenMPReductionClauseModifier Modifier
,
1797 SourceLocation StartLoc
, SourceLocation LParenLoc
,
1798 SourceLocation ModifierLoc
, SourceLocation ColonLoc
,
1799 SourceLocation EndLoc
, CXXScopeSpec
&ReductionIdScopeSpec
,
1800 const DeclarationNameInfo
&ReductionId
,
1801 ArrayRef
<Expr
*> UnresolvedReductions
) {
1802 return getSema().ActOnOpenMPReductionClause(
1803 VarList
, Modifier
, StartLoc
, LParenLoc
, ModifierLoc
, ColonLoc
, EndLoc
,
1804 ReductionIdScopeSpec
, ReductionId
, UnresolvedReductions
);
1807 /// Build a new OpenMP 'task_reduction' clause.
1809 /// By default, performs semantic analysis to build the new statement.
1810 /// Subclasses may override this routine to provide different behavior.
1811 OMPClause
*RebuildOMPTaskReductionClause(
1812 ArrayRef
<Expr
*> VarList
, SourceLocation StartLoc
,
1813 SourceLocation LParenLoc
, SourceLocation ColonLoc
, SourceLocation EndLoc
,
1814 CXXScopeSpec
&ReductionIdScopeSpec
,
1815 const DeclarationNameInfo
&ReductionId
,
1816 ArrayRef
<Expr
*> UnresolvedReductions
) {
1817 return getSema().ActOnOpenMPTaskReductionClause(
1818 VarList
, StartLoc
, LParenLoc
, ColonLoc
, EndLoc
, ReductionIdScopeSpec
,
1819 ReductionId
, UnresolvedReductions
);
1822 /// Build a new OpenMP 'in_reduction' clause.
1824 /// By default, performs semantic analysis to build the new statement.
1825 /// Subclasses may override this routine to provide different behavior.
1827 RebuildOMPInReductionClause(ArrayRef
<Expr
*> VarList
, SourceLocation StartLoc
,
1828 SourceLocation LParenLoc
, SourceLocation ColonLoc
,
1829 SourceLocation EndLoc
,
1830 CXXScopeSpec
&ReductionIdScopeSpec
,
1831 const DeclarationNameInfo
&ReductionId
,
1832 ArrayRef
<Expr
*> UnresolvedReductions
) {
1833 return getSema().ActOnOpenMPInReductionClause(
1834 VarList
, StartLoc
, LParenLoc
, ColonLoc
, EndLoc
, ReductionIdScopeSpec
,
1835 ReductionId
, UnresolvedReductions
);
1838 /// Build a new OpenMP 'linear' clause.
1840 /// By default, performs semantic analysis to build the new OpenMP clause.
1841 /// Subclasses may override this routine to provide different behavior.
1842 OMPClause
*RebuildOMPLinearClause(ArrayRef
<Expr
*> VarList
, Expr
*Step
,
1843 SourceLocation StartLoc
,
1844 SourceLocation LParenLoc
,
1845 OpenMPLinearClauseKind Modifier
,
1846 SourceLocation ModifierLoc
,
1847 SourceLocation ColonLoc
,
1848 SourceLocation EndLoc
) {
1849 return getSema().ActOnOpenMPLinearClause(VarList
, Step
, StartLoc
, LParenLoc
,
1850 Modifier
, ModifierLoc
, ColonLoc
,
1854 /// Build a new OpenMP 'aligned' clause.
1856 /// By default, performs semantic analysis to build the new OpenMP clause.
1857 /// Subclasses may override this routine to provide different behavior.
1858 OMPClause
*RebuildOMPAlignedClause(ArrayRef
<Expr
*> VarList
, Expr
*Alignment
,
1859 SourceLocation StartLoc
,
1860 SourceLocation LParenLoc
,
1861 SourceLocation ColonLoc
,
1862 SourceLocation EndLoc
) {
1863 return getSema().ActOnOpenMPAlignedClause(VarList
, Alignment
, StartLoc
,
1864 LParenLoc
, ColonLoc
, EndLoc
);
1867 /// Build a new OpenMP 'copyin' clause.
1869 /// By default, performs semantic analysis to build the new OpenMP clause.
1870 /// Subclasses may override this routine to provide different behavior.
1871 OMPClause
*RebuildOMPCopyinClause(ArrayRef
<Expr
*> VarList
,
1872 SourceLocation StartLoc
,
1873 SourceLocation LParenLoc
,
1874 SourceLocation EndLoc
) {
1875 return getSema().ActOnOpenMPCopyinClause(VarList
, StartLoc
, LParenLoc
,
1879 /// Build a new OpenMP 'copyprivate' clause.
1881 /// By default, performs semantic analysis to build the new OpenMP clause.
1882 /// Subclasses may override this routine to provide different behavior.
1883 OMPClause
*RebuildOMPCopyprivateClause(ArrayRef
<Expr
*> VarList
,
1884 SourceLocation StartLoc
,
1885 SourceLocation LParenLoc
,
1886 SourceLocation EndLoc
) {
1887 return getSema().ActOnOpenMPCopyprivateClause(VarList
, StartLoc
, LParenLoc
,
1891 /// Build a new OpenMP 'flush' pseudo clause.
1893 /// By default, performs semantic analysis to build the new OpenMP clause.
1894 /// Subclasses may override this routine to provide different behavior.
1895 OMPClause
*RebuildOMPFlushClause(ArrayRef
<Expr
*> VarList
,
1896 SourceLocation StartLoc
,
1897 SourceLocation LParenLoc
,
1898 SourceLocation EndLoc
) {
1899 return getSema().ActOnOpenMPFlushClause(VarList
, StartLoc
, LParenLoc
,
1903 /// Build a new OpenMP 'depobj' pseudo clause.
1905 /// By default, performs semantic analysis to build the new OpenMP clause.
1906 /// Subclasses may override this routine to provide different behavior.
1907 OMPClause
*RebuildOMPDepobjClause(Expr
*Depobj
, SourceLocation StartLoc
,
1908 SourceLocation LParenLoc
,
1909 SourceLocation EndLoc
) {
1910 return getSema().ActOnOpenMPDepobjClause(Depobj
, StartLoc
, LParenLoc
,
1914 /// Build a new OpenMP 'depend' pseudo clause.
1916 /// By default, performs semantic analysis to build the new OpenMP clause.
1917 /// Subclasses may override this routine to provide different behavior.
1918 OMPClause
*RebuildOMPDependClause(OMPDependClause::DependDataTy Data
,
1919 Expr
*DepModifier
, ArrayRef
<Expr
*> VarList
,
1920 SourceLocation StartLoc
,
1921 SourceLocation LParenLoc
,
1922 SourceLocation EndLoc
) {
1923 return getSema().ActOnOpenMPDependClause(Data
, DepModifier
, VarList
,
1924 StartLoc
, LParenLoc
, EndLoc
);
1927 /// Build a new OpenMP 'device' clause.
1929 /// By default, performs semantic analysis to build the new statement.
1930 /// Subclasses may override this routine to provide different behavior.
1931 OMPClause
*RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier
,
1932 Expr
*Device
, SourceLocation StartLoc
,
1933 SourceLocation LParenLoc
,
1934 SourceLocation ModifierLoc
,
1935 SourceLocation EndLoc
) {
1936 return getSema().ActOnOpenMPDeviceClause(Modifier
, Device
, StartLoc
,
1937 LParenLoc
, ModifierLoc
, EndLoc
);
1940 /// Build a new OpenMP 'map' clause.
1942 /// By default, performs semantic analysis to build the new OpenMP clause.
1943 /// Subclasses may override this routine to provide different behavior.
1944 OMPClause
*RebuildOMPMapClause(
1945 ArrayRef
<OpenMPMapModifierKind
> MapTypeModifiers
,
1946 ArrayRef
<SourceLocation
> MapTypeModifiersLoc
,
1947 CXXScopeSpec MapperIdScopeSpec
, DeclarationNameInfo MapperId
,
1948 OpenMPMapClauseKind MapType
, bool IsMapTypeImplicit
,
1949 SourceLocation MapLoc
, SourceLocation ColonLoc
, ArrayRef
<Expr
*> VarList
,
1950 const OMPVarListLocTy
&Locs
, ArrayRef
<Expr
*> UnresolvedMappers
) {
1951 return getSema().ActOnOpenMPMapClause(
1952 MapTypeModifiers
, MapTypeModifiersLoc
, MapperIdScopeSpec
, MapperId
,
1953 MapType
, IsMapTypeImplicit
, MapLoc
, ColonLoc
, VarList
, Locs
,
1954 /*NoDiagnose=*/false, UnresolvedMappers
);
1957 /// Build a new OpenMP 'allocate' clause.
1959 /// By default, performs semantic analysis to build the new OpenMP clause.
1960 /// Subclasses may override this routine to provide different behavior.
1961 OMPClause
*RebuildOMPAllocateClause(Expr
*Allocate
, ArrayRef
<Expr
*> VarList
,
1962 SourceLocation StartLoc
,
1963 SourceLocation LParenLoc
,
1964 SourceLocation ColonLoc
,
1965 SourceLocation EndLoc
) {
1966 return getSema().ActOnOpenMPAllocateClause(Allocate
, VarList
, StartLoc
,
1967 LParenLoc
, ColonLoc
, EndLoc
);
1970 /// Build a new OpenMP 'num_teams' clause.
1972 /// By default, performs semantic analysis to build the new statement.
1973 /// Subclasses may override this routine to provide different behavior.
1974 OMPClause
*RebuildOMPNumTeamsClause(Expr
*NumTeams
, SourceLocation StartLoc
,
1975 SourceLocation LParenLoc
,
1976 SourceLocation EndLoc
) {
1977 return getSema().ActOnOpenMPNumTeamsClause(NumTeams
, StartLoc
, LParenLoc
,
1981 /// Build a new OpenMP 'thread_limit' clause.
1983 /// By default, performs semantic analysis to build the new statement.
1984 /// Subclasses may override this routine to provide different behavior.
1985 OMPClause
*RebuildOMPThreadLimitClause(Expr
*ThreadLimit
,
1986 SourceLocation StartLoc
,
1987 SourceLocation LParenLoc
,
1988 SourceLocation EndLoc
) {
1989 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit
, StartLoc
,
1993 /// Build a new OpenMP 'priority' clause.
1995 /// By default, performs semantic analysis to build the new statement.
1996 /// Subclasses may override this routine to provide different behavior.
1997 OMPClause
*RebuildOMPPriorityClause(Expr
*Priority
, SourceLocation StartLoc
,
1998 SourceLocation LParenLoc
,
1999 SourceLocation EndLoc
) {
2000 return getSema().ActOnOpenMPPriorityClause(Priority
, StartLoc
, LParenLoc
,
2004 /// Build a new OpenMP 'grainsize' clause.
2006 /// By default, performs semantic analysis to build the new statement.
2007 /// Subclasses may override this routine to provide different behavior.
2008 OMPClause
*RebuildOMPGrainsizeClause(Expr
*Grainsize
, SourceLocation StartLoc
,
2009 SourceLocation LParenLoc
,
2010 SourceLocation EndLoc
) {
2011 return getSema().ActOnOpenMPGrainsizeClause(Grainsize
, StartLoc
, LParenLoc
,
2015 /// Build a new OpenMP 'num_tasks' clause.
2017 /// By default, performs semantic analysis to build the new statement.
2018 /// Subclasses may override this routine to provide different behavior.
2019 OMPClause
*RebuildOMPNumTasksClause(Expr
*NumTasks
, SourceLocation StartLoc
,
2020 SourceLocation LParenLoc
,
2021 SourceLocation EndLoc
) {
2022 return getSema().ActOnOpenMPNumTasksClause(NumTasks
, StartLoc
, LParenLoc
,
2026 /// Build a new OpenMP 'hint' clause.
2028 /// By default, performs semantic analysis to build the new statement.
2029 /// Subclasses may override this routine to provide different behavior.
2030 OMPClause
*RebuildOMPHintClause(Expr
*Hint
, SourceLocation StartLoc
,
2031 SourceLocation LParenLoc
,
2032 SourceLocation EndLoc
) {
2033 return getSema().ActOnOpenMPHintClause(Hint
, StartLoc
, LParenLoc
, EndLoc
);
2036 /// Build a new OpenMP 'detach' clause.
2038 /// By default, performs semantic analysis to build the new statement.
2039 /// Subclasses may override this routine to provide different behavior.
2040 OMPClause
*RebuildOMPDetachClause(Expr
*Evt
, SourceLocation StartLoc
,
2041 SourceLocation LParenLoc
,
2042 SourceLocation EndLoc
) {
2043 return getSema().ActOnOpenMPDetachClause(Evt
, StartLoc
, LParenLoc
, EndLoc
);
2046 /// Build a new OpenMP 'dist_schedule' clause.
2048 /// By default, performs semantic analysis to build the new OpenMP clause.
2049 /// Subclasses may override this routine to provide different behavior.
2051 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind
,
2052 Expr
*ChunkSize
, SourceLocation StartLoc
,
2053 SourceLocation LParenLoc
, SourceLocation KindLoc
,
2054 SourceLocation CommaLoc
, SourceLocation EndLoc
) {
2055 return getSema().ActOnOpenMPDistScheduleClause(
2056 Kind
, ChunkSize
, StartLoc
, LParenLoc
, KindLoc
, CommaLoc
, EndLoc
);
2059 /// Build a new OpenMP 'to' clause.
2061 /// By default, performs semantic analysis to build the new statement.
2062 /// Subclasses may override this routine to provide different behavior.
2064 RebuildOMPToClause(ArrayRef
<OpenMPMotionModifierKind
> MotionModifiers
,
2065 ArrayRef
<SourceLocation
> MotionModifiersLoc
,
2066 CXXScopeSpec
&MapperIdScopeSpec
,
2067 DeclarationNameInfo
&MapperId
, SourceLocation ColonLoc
,
2068 ArrayRef
<Expr
*> VarList
, const OMPVarListLocTy
&Locs
,
2069 ArrayRef
<Expr
*> UnresolvedMappers
) {
2070 return getSema().ActOnOpenMPToClause(MotionModifiers
, MotionModifiersLoc
,
2071 MapperIdScopeSpec
, MapperId
, ColonLoc
,
2072 VarList
, Locs
, UnresolvedMappers
);
2075 /// Build a new OpenMP 'from' clause.
2077 /// By default, performs semantic analysis to build the new statement.
2078 /// Subclasses may override this routine to provide different behavior.
2080 RebuildOMPFromClause(ArrayRef
<OpenMPMotionModifierKind
> MotionModifiers
,
2081 ArrayRef
<SourceLocation
> MotionModifiersLoc
,
2082 CXXScopeSpec
&MapperIdScopeSpec
,
2083 DeclarationNameInfo
&MapperId
, SourceLocation ColonLoc
,
2084 ArrayRef
<Expr
*> VarList
, const OMPVarListLocTy
&Locs
,
2085 ArrayRef
<Expr
*> UnresolvedMappers
) {
2086 return getSema().ActOnOpenMPFromClause(
2087 MotionModifiers
, MotionModifiersLoc
, MapperIdScopeSpec
, MapperId
,
2088 ColonLoc
, VarList
, Locs
, UnresolvedMappers
);
2091 /// Build a new OpenMP 'use_device_ptr' clause.
2093 /// By default, performs semantic analysis to build the new OpenMP clause.
2094 /// Subclasses may override this routine to provide different behavior.
2095 OMPClause
*RebuildOMPUseDevicePtrClause(ArrayRef
<Expr
*> VarList
,
2096 const OMPVarListLocTy
&Locs
) {
2097 return getSema().ActOnOpenMPUseDevicePtrClause(VarList
, Locs
);
2100 /// Build a new OpenMP 'use_device_addr' clause.
2102 /// By default, performs semantic analysis to build the new OpenMP clause.
2103 /// Subclasses may override this routine to provide different behavior.
2104 OMPClause
*RebuildOMPUseDeviceAddrClause(ArrayRef
<Expr
*> VarList
,
2105 const OMPVarListLocTy
&Locs
) {
2106 return getSema().ActOnOpenMPUseDeviceAddrClause(VarList
, Locs
);
2109 /// Build a new OpenMP 'is_device_ptr' clause.
2111 /// By default, performs semantic analysis to build the new OpenMP clause.
2112 /// Subclasses may override this routine to provide different behavior.
2113 OMPClause
*RebuildOMPIsDevicePtrClause(ArrayRef
<Expr
*> VarList
,
2114 const OMPVarListLocTy
&Locs
) {
2115 return getSema().ActOnOpenMPIsDevicePtrClause(VarList
, Locs
);
2118 /// Build a new OpenMP 'has_device_addr' clause.
2120 /// By default, performs semantic analysis to build the new OpenMP clause.
2121 /// Subclasses may override this routine to provide different behavior.
2122 OMPClause
*RebuildOMPHasDeviceAddrClause(ArrayRef
<Expr
*> VarList
,
2123 const OMPVarListLocTy
&Locs
) {
2124 return getSema().ActOnOpenMPHasDeviceAddrClause(VarList
, Locs
);
2127 /// Build a new OpenMP 'defaultmap' clause.
2129 /// By default, performs semantic analysis to build the new OpenMP clause.
2130 /// Subclasses may override this routine to provide different behavior.
2131 OMPClause
*RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M
,
2132 OpenMPDefaultmapClauseKind Kind
,
2133 SourceLocation StartLoc
,
2134 SourceLocation LParenLoc
,
2135 SourceLocation MLoc
,
2136 SourceLocation KindLoc
,
2137 SourceLocation EndLoc
) {
2138 return getSema().ActOnOpenMPDefaultmapClause(M
, Kind
, StartLoc
, LParenLoc
,
2139 MLoc
, KindLoc
, EndLoc
);
2142 /// Build a new OpenMP 'nontemporal' clause.
2144 /// By default, performs semantic analysis to build the new OpenMP clause.
2145 /// Subclasses may override this routine to provide different behavior.
2146 OMPClause
*RebuildOMPNontemporalClause(ArrayRef
<Expr
*> VarList
,
2147 SourceLocation StartLoc
,
2148 SourceLocation LParenLoc
,
2149 SourceLocation EndLoc
) {
2150 return getSema().ActOnOpenMPNontemporalClause(VarList
, StartLoc
, LParenLoc
,
2154 /// Build a new OpenMP 'inclusive' clause.
2156 /// By default, performs semantic analysis to build the new OpenMP clause.
2157 /// Subclasses may override this routine to provide different behavior.
2158 OMPClause
*RebuildOMPInclusiveClause(ArrayRef
<Expr
*> VarList
,
2159 SourceLocation StartLoc
,
2160 SourceLocation LParenLoc
,
2161 SourceLocation EndLoc
) {
2162 return getSema().ActOnOpenMPInclusiveClause(VarList
, StartLoc
, LParenLoc
,
2166 /// Build a new OpenMP 'exclusive' clause.
2168 /// By default, performs semantic analysis to build the new OpenMP clause.
2169 /// Subclasses may override this routine to provide different behavior.
2170 OMPClause
*RebuildOMPExclusiveClause(ArrayRef
<Expr
*> VarList
,
2171 SourceLocation StartLoc
,
2172 SourceLocation LParenLoc
,
2173 SourceLocation EndLoc
) {
2174 return getSema().ActOnOpenMPExclusiveClause(VarList
, StartLoc
, LParenLoc
,
2178 /// Build a new OpenMP 'uses_allocators' clause.
2180 /// By default, performs semantic analysis to build the new OpenMP clause.
2181 /// Subclasses may override this routine to provide different behavior.
2182 OMPClause
*RebuildOMPUsesAllocatorsClause(
2183 ArrayRef
<Sema::UsesAllocatorsData
> Data
, SourceLocation StartLoc
,
2184 SourceLocation LParenLoc
, SourceLocation EndLoc
) {
2185 return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc
, LParenLoc
, EndLoc
,
2189 /// Build a new OpenMP 'affinity' clause.
2191 /// By default, performs semantic analysis to build the new OpenMP clause.
2192 /// Subclasses may override this routine to provide different behavior.
2193 OMPClause
*RebuildOMPAffinityClause(SourceLocation StartLoc
,
2194 SourceLocation LParenLoc
,
2195 SourceLocation ColonLoc
,
2196 SourceLocation EndLoc
, Expr
*Modifier
,
2197 ArrayRef
<Expr
*> Locators
) {
2198 return getSema().ActOnOpenMPAffinityClause(StartLoc
, LParenLoc
, ColonLoc
,
2199 EndLoc
, Modifier
, Locators
);
2202 /// Build a new OpenMP 'order' clause.
2204 /// By default, performs semantic analysis to build the new OpenMP clause.
2205 /// Subclasses may override this routine to provide different behavior.
2206 OMPClause
*RebuildOMPOrderClause(OpenMPOrderClauseKind Kind
,
2207 SourceLocation KindKwLoc
,
2208 SourceLocation StartLoc
,
2209 SourceLocation LParenLoc
,
2210 SourceLocation EndLoc
) {
2211 return getSema().ActOnOpenMPOrderClause(Kind
, KindKwLoc
, StartLoc
,
2215 /// Build a new OpenMP 'init' clause.
2217 /// By default, performs semantic analysis to build the new OpenMP clause.
2218 /// Subclasses may override this routine to provide different behavior.
2219 OMPClause
*RebuildOMPInitClause(Expr
*InteropVar
, OMPInteropInfo
&InteropInfo
,
2220 SourceLocation StartLoc
,
2221 SourceLocation LParenLoc
,
2222 SourceLocation VarLoc
,
2223 SourceLocation EndLoc
) {
2224 return getSema().ActOnOpenMPInitClause(InteropVar
, InteropInfo
, StartLoc
,
2225 LParenLoc
, VarLoc
, EndLoc
);
2228 /// Build a new OpenMP 'use' clause.
2230 /// By default, performs semantic analysis to build the new OpenMP clause.
2231 /// Subclasses may override this routine to provide different behavior.
2232 OMPClause
*RebuildOMPUseClause(Expr
*InteropVar
, SourceLocation StartLoc
,
2233 SourceLocation LParenLoc
,
2234 SourceLocation VarLoc
, SourceLocation EndLoc
) {
2235 return getSema().ActOnOpenMPUseClause(InteropVar
, StartLoc
, LParenLoc
,
2239 /// Build a new OpenMP 'destroy' clause.
2241 /// By default, performs semantic analysis to build the new OpenMP clause.
2242 /// Subclasses may override this routine to provide different behavior.
2243 OMPClause
*RebuildOMPDestroyClause(Expr
*InteropVar
, SourceLocation StartLoc
,
2244 SourceLocation LParenLoc
,
2245 SourceLocation VarLoc
,
2246 SourceLocation EndLoc
) {
2247 return getSema().ActOnOpenMPDestroyClause(InteropVar
, StartLoc
, LParenLoc
,
2251 /// Build a new OpenMP 'novariants' clause.
2253 /// By default, performs semantic analysis to build the new OpenMP clause.
2254 /// Subclasses may override this routine to provide different behavior.
2255 OMPClause
*RebuildOMPNovariantsClause(Expr
*Condition
,
2256 SourceLocation StartLoc
,
2257 SourceLocation LParenLoc
,
2258 SourceLocation EndLoc
) {
2259 return getSema().ActOnOpenMPNovariantsClause(Condition
, StartLoc
, LParenLoc
,
2263 /// Build a new OpenMP 'nocontext' clause.
2265 /// By default, performs semantic analysis to build the new OpenMP clause.
2266 /// Subclasses may override this routine to provide different behavior.
2267 OMPClause
*RebuildOMPNocontextClause(Expr
*Condition
, SourceLocation StartLoc
,
2268 SourceLocation LParenLoc
,
2269 SourceLocation EndLoc
) {
2270 return getSema().ActOnOpenMPNocontextClause(Condition
, StartLoc
, LParenLoc
,
2274 /// Build a new OpenMP 'filter' clause.
2276 /// By default, performs semantic analysis to build the new OpenMP clause.
2277 /// Subclasses may override this routine to provide different behavior.
2278 OMPClause
*RebuildOMPFilterClause(Expr
*ThreadID
, SourceLocation StartLoc
,
2279 SourceLocation LParenLoc
,
2280 SourceLocation EndLoc
) {
2281 return getSema().ActOnOpenMPFilterClause(ThreadID
, StartLoc
, LParenLoc
,
2285 /// Build a new OpenMP 'bind' clause.
2287 /// By default, performs semantic analysis to build the new OpenMP clause.
2288 /// Subclasses may override this routine to provide different behavior.
2289 OMPClause
*RebuildOMPBindClause(OpenMPBindClauseKind Kind
,
2290 SourceLocation KindLoc
,
2291 SourceLocation StartLoc
,
2292 SourceLocation LParenLoc
,
2293 SourceLocation EndLoc
) {
2294 return getSema().ActOnOpenMPBindClause(Kind
, KindLoc
, StartLoc
, LParenLoc
,
2298 /// Build a new OpenMP 'align' clause.
2300 /// By default, performs semantic analysis to build the new OpenMP clause.
2301 /// Subclasses may override this routine to provide different behavior.
2302 OMPClause
*RebuildOMPAlignClause(Expr
*A
, SourceLocation StartLoc
,
2303 SourceLocation LParenLoc
,
2304 SourceLocation EndLoc
) {
2305 return getSema().ActOnOpenMPAlignClause(A
, StartLoc
, LParenLoc
, EndLoc
);
2308 /// Rebuild the operand to an Objective-C \@synchronized statement.
2310 /// By default, performs semantic analysis to build the new statement.
2311 /// Subclasses may override this routine to provide different behavior.
2312 ExprResult
RebuildObjCAtSynchronizedOperand(SourceLocation atLoc
,
2314 return getSema().ActOnObjCAtSynchronizedOperand(atLoc
, object
);
2317 /// Build a new Objective-C \@synchronized statement.
2319 /// By default, performs semantic analysis to build the new statement.
2320 /// Subclasses may override this routine to provide different behavior.
2321 StmtResult
RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc
,
2322 Expr
*Object
, Stmt
*Body
) {
2323 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc
, Object
, Body
);
2326 /// Build a new Objective-C \@autoreleasepool statement.
2328 /// By default, performs semantic analysis to build the new statement.
2329 /// Subclasses may override this routine to provide different behavior.
2330 StmtResult
RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc
,
2332 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc
, Body
);
2335 /// Build a new Objective-C fast enumeration statement.
2337 /// By default, performs semantic analysis to build the new statement.
2338 /// Subclasses may override this routine to provide different behavior.
2339 StmtResult
RebuildObjCForCollectionStmt(SourceLocation ForLoc
,
2342 SourceLocation RParenLoc
,
2344 StmtResult ForEachStmt
= getSema().ActOnObjCForCollectionStmt(ForLoc
,
2348 if (ForEachStmt
.isInvalid())
2351 return getSema().FinishObjCForCollectionStmt(ForEachStmt
.get(), Body
);
2354 /// Build a new C++ exception declaration.
2356 /// By default, performs semantic analysis to build the new decaration.
2357 /// Subclasses may override this routine to provide different behavior.
2358 VarDecl
*RebuildExceptionDecl(VarDecl
*ExceptionDecl
,
2359 TypeSourceInfo
*Declarator
,
2360 SourceLocation StartLoc
,
2361 SourceLocation IdLoc
,
2362 IdentifierInfo
*Id
) {
2363 VarDecl
*Var
= getSema().BuildExceptionDeclaration(nullptr, Declarator
,
2364 StartLoc
, IdLoc
, Id
);
2366 getSema().CurContext
->addDecl(Var
);
2370 /// Build a new C++ catch statement.
2372 /// By default, performs semantic analysis to build the new statement.
2373 /// Subclasses may override this routine to provide different behavior.
2374 StmtResult
RebuildCXXCatchStmt(SourceLocation CatchLoc
,
2375 VarDecl
*ExceptionDecl
,
2377 return Owned(new (getSema().Context
) CXXCatchStmt(CatchLoc
, ExceptionDecl
,
2381 /// Build a new C++ try statement.
2383 /// By default, performs semantic analysis to build the new statement.
2384 /// Subclasses may override this routine to provide different behavior.
2385 StmtResult
RebuildCXXTryStmt(SourceLocation TryLoc
, Stmt
*TryBlock
,
2386 ArrayRef
<Stmt
*> Handlers
) {
2387 return getSema().ActOnCXXTryBlock(TryLoc
, TryBlock
, Handlers
);
2390 /// Build a new C++0x range-based for statement.
2392 /// By default, performs semantic analysis to build the new statement.
2393 /// Subclasses may override this routine to provide different behavior.
2394 StmtResult
RebuildCXXForRangeStmt(SourceLocation ForLoc
,
2395 SourceLocation CoawaitLoc
, Stmt
*Init
,
2396 SourceLocation ColonLoc
, Stmt
*Range
,
2397 Stmt
*Begin
, Stmt
*End
, Expr
*Cond
,
2398 Expr
*Inc
, Stmt
*LoopVar
,
2399 SourceLocation RParenLoc
) {
2400 // If we've just learned that the range is actually an Objective-C
2401 // collection, treat this as an Objective-C fast enumeration loop.
2402 if (DeclStmt
*RangeStmt
= dyn_cast
<DeclStmt
>(Range
)) {
2403 if (RangeStmt
->isSingleDecl()) {
2404 if (VarDecl
*RangeVar
= dyn_cast
<VarDecl
>(RangeStmt
->getSingleDecl())) {
2405 if (RangeVar
->isInvalidDecl())
2408 Expr
*RangeExpr
= RangeVar
->getInit();
2409 if (!RangeExpr
->isTypeDependent() &&
2410 RangeExpr
->getType()->isObjCObjectPointerType()) {
2411 // FIXME: Support init-statements in Objective-C++20 ranged for
2414 return SemaRef
.Diag(Init
->getBeginLoc(),
2415 diag::err_objc_for_range_init_stmt
)
2416 << Init
->getSourceRange();
2418 return getSema().ActOnObjCForCollectionStmt(ForLoc
, LoopVar
,
2419 RangeExpr
, RParenLoc
);
2425 return getSema().BuildCXXForRangeStmt(ForLoc
, CoawaitLoc
, Init
, ColonLoc
,
2426 Range
, Begin
, End
, Cond
, Inc
, LoopVar
,
2427 RParenLoc
, Sema::BFRK_Rebuild
);
2430 /// Build a new C++0x range-based for statement.
2432 /// By default, performs semantic analysis to build the new statement.
2433 /// Subclasses may override this routine to provide different behavior.
2434 StmtResult
RebuildMSDependentExistsStmt(SourceLocation KeywordLoc
,
2436 NestedNameSpecifierLoc QualifierLoc
,
2437 DeclarationNameInfo NameInfo
,
2439 return getSema().BuildMSDependentExistsStmt(KeywordLoc
, IsIfExists
,
2440 QualifierLoc
, NameInfo
, Nested
);
2443 /// Attach body to a C++0x range-based for statement.
2445 /// By default, performs semantic analysis to finish the new statement.
2446 /// Subclasses may override this routine to provide different behavior.
2447 StmtResult
FinishCXXForRangeStmt(Stmt
*ForRange
, Stmt
*Body
) {
2448 return getSema().FinishCXXForRangeStmt(ForRange
, Body
);
2451 StmtResult
RebuildSEHTryStmt(bool IsCXXTry
, SourceLocation TryLoc
,
2452 Stmt
*TryBlock
, Stmt
*Handler
) {
2453 return getSema().ActOnSEHTryBlock(IsCXXTry
, TryLoc
, TryBlock
, Handler
);
2456 StmtResult
RebuildSEHExceptStmt(SourceLocation Loc
, Expr
*FilterExpr
,
2458 return getSema().ActOnSEHExceptBlock(Loc
, FilterExpr
, Block
);
2461 StmtResult
RebuildSEHFinallyStmt(SourceLocation Loc
, Stmt
*Block
) {
2462 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc
, Block
);
2465 ExprResult
RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc
,
2466 SourceLocation LParen
,
2467 SourceLocation RParen
,
2468 TypeSourceInfo
*TSI
) {
2469 return getSema().BuildSYCLUniqueStableNameExpr(OpLoc
, LParen
, RParen
, TSI
);
2472 /// Build a new predefined expression.
2474 /// By default, performs semantic analysis to build the new expression.
2475 /// Subclasses may override this routine to provide different behavior.
2476 ExprResult
RebuildPredefinedExpr(SourceLocation Loc
,
2477 PredefinedExpr::IdentKind IK
) {
2478 return getSema().BuildPredefinedExpr(Loc
, IK
);
2481 /// Build a new expression that references a declaration.
2483 /// By default, performs semantic analysis to build the new expression.
2484 /// Subclasses may override this routine to provide different behavior.
2485 ExprResult
RebuildDeclarationNameExpr(const CXXScopeSpec
&SS
,
2488 return getSema().BuildDeclarationNameExpr(SS
, R
, RequiresADL
);
2492 /// Build a new expression that references a declaration.
2494 /// By default, performs semantic analysis to build the new expression.
2495 /// Subclasses may override this routine to provide different behavior.
2496 ExprResult
RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc
,
2498 const DeclarationNameInfo
&NameInfo
,
2500 TemplateArgumentListInfo
*TemplateArgs
) {
2502 SS
.Adopt(QualifierLoc
);
2503 return getSema().BuildDeclarationNameExpr(SS
, NameInfo
, VD
, Found
,
2507 /// Build a new expression in parentheses.
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
2511 ExprResult
RebuildParenExpr(Expr
*SubExpr
, SourceLocation LParen
,
2512 SourceLocation RParen
) {
2513 return getSema().ActOnParenExpr(LParen
, RParen
, SubExpr
);
2516 /// Build a new pseudo-destructor expression.
2518 /// By default, performs semantic analysis to build the new expression.
2519 /// Subclasses may override this routine to provide different behavior.
2520 ExprResult
RebuildCXXPseudoDestructorExpr(Expr
*Base
,
2521 SourceLocation OperatorLoc
,
2524 TypeSourceInfo
*ScopeType
,
2525 SourceLocation CCLoc
,
2526 SourceLocation TildeLoc
,
2527 PseudoDestructorTypeStorage Destroyed
);
2529 /// Build a new unary operator expression.
2531 /// By default, performs semantic analysis to build the new expression.
2532 /// Subclasses may override this routine to provide different behavior.
2533 ExprResult
RebuildUnaryOperator(SourceLocation OpLoc
,
2534 UnaryOperatorKind Opc
,
2536 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc
, Opc
, SubExpr
);
2539 /// Build a new builtin offsetof expression.
2541 /// By default, performs semantic analysis to build the new expression.
2542 /// Subclasses may override this routine to provide different behavior.
2543 ExprResult
RebuildOffsetOfExpr(SourceLocation OperatorLoc
,
2544 TypeSourceInfo
*Type
,
2545 ArrayRef
<Sema::OffsetOfComponent
> Components
,
2546 SourceLocation RParenLoc
) {
2547 return getSema().BuildBuiltinOffsetOf(OperatorLoc
, Type
, Components
,
2551 /// Build a new sizeof, alignof or vec_step expression with a
2554 /// By default, performs semantic analysis to build the new expression.
2555 /// Subclasses may override this routine to provide different behavior.
2556 ExprResult
RebuildUnaryExprOrTypeTrait(TypeSourceInfo
*TInfo
,
2557 SourceLocation OpLoc
,
2558 UnaryExprOrTypeTrait ExprKind
,
2560 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo
, OpLoc
, ExprKind
, R
);
2563 /// Build a new sizeof, alignof or vec step expression with an
2564 /// expression argument.
2566 /// By default, performs semantic analysis to build the new expression.
2567 /// Subclasses may override this routine to provide different behavior.
2568 ExprResult
RebuildUnaryExprOrTypeTrait(Expr
*SubExpr
, SourceLocation OpLoc
,
2569 UnaryExprOrTypeTrait ExprKind
,
2572 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr
, OpLoc
, ExprKind
);
2573 if (Result
.isInvalid())
2579 /// Build a new array subscript expression.
2581 /// By default, performs semantic analysis to build the new expression.
2582 /// Subclasses may override this routine to provide different behavior.
2583 ExprResult
RebuildArraySubscriptExpr(Expr
*LHS
,
2584 SourceLocation LBracketLoc
,
2586 SourceLocation RBracketLoc
) {
2587 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS
,
2592 /// Build a new matrix subscript expression.
2594 /// By default, performs semantic analysis to build the new expression.
2595 /// Subclasses may override this routine to provide different behavior.
2596 ExprResult
RebuildMatrixSubscriptExpr(Expr
*Base
, Expr
*RowIdx
,
2598 SourceLocation RBracketLoc
) {
2599 return getSema().CreateBuiltinMatrixSubscriptExpr(Base
, RowIdx
, ColumnIdx
,
2603 /// Build a new array section expression.
2605 /// By default, performs semantic analysis to build the new expression.
2606 /// Subclasses may override this routine to provide different behavior.
2607 ExprResult
RebuildOMPArraySectionExpr(Expr
*Base
, SourceLocation LBracketLoc
,
2609 SourceLocation ColonLocFirst
,
2610 SourceLocation ColonLocSecond
,
2611 Expr
*Length
, Expr
*Stride
,
2612 SourceLocation RBracketLoc
) {
2613 return getSema().ActOnOMPArraySectionExpr(Base
, LBracketLoc
, LowerBound
,
2614 ColonLocFirst
, ColonLocSecond
,
2615 Length
, Stride
, RBracketLoc
);
2618 /// Build a new array shaping expression.
2620 /// By default, performs semantic analysis to build the new expression.
2621 /// Subclasses may override this routine to provide different behavior.
2622 ExprResult
RebuildOMPArrayShapingExpr(Expr
*Base
, SourceLocation LParenLoc
,
2623 SourceLocation RParenLoc
,
2624 ArrayRef
<Expr
*> Dims
,
2625 ArrayRef
<SourceRange
> BracketsRanges
) {
2626 return getSema().ActOnOMPArrayShapingExpr(Base
, LParenLoc
, RParenLoc
, Dims
,
2630 /// Build a new iterator expression.
2632 /// By default, performs semantic analysis to build the new expression.
2633 /// Subclasses may override this routine to provide different behavior.
2634 ExprResult
RebuildOMPIteratorExpr(
2635 SourceLocation IteratorKwLoc
, SourceLocation LLoc
, SourceLocation RLoc
,
2636 ArrayRef
<Sema::OMPIteratorData
> Data
) {
2637 return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc
,
2641 /// Build a new call expression.
2643 /// By default, performs semantic analysis to build the new expression.
2644 /// Subclasses may override this routine to provide different behavior.
2645 ExprResult
RebuildCallExpr(Expr
*Callee
, SourceLocation LParenLoc
,
2647 SourceLocation RParenLoc
,
2648 Expr
*ExecConfig
= nullptr) {
2649 return getSema().ActOnCallExpr(
2650 /*Scope=*/nullptr, Callee
, LParenLoc
, Args
, RParenLoc
, ExecConfig
);
2653 ExprResult
RebuildCxxSubscriptExpr(Expr
*Callee
, SourceLocation LParenLoc
,
2655 SourceLocation RParenLoc
) {
2656 return getSema().ActOnArraySubscriptExpr(
2657 /*Scope=*/nullptr, Callee
, LParenLoc
, Args
, RParenLoc
);
2660 /// Build a new member access expression.
2662 /// By default, performs semantic analysis to build the new expression.
2663 /// Subclasses may override this routine to provide different behavior.
2664 ExprResult
RebuildMemberExpr(Expr
*Base
, SourceLocation OpLoc
,
2666 NestedNameSpecifierLoc QualifierLoc
,
2667 SourceLocation TemplateKWLoc
,
2668 const DeclarationNameInfo
&MemberNameInfo
,
2670 NamedDecl
*FoundDecl
,
2671 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
2672 NamedDecl
*FirstQualifierInScope
) {
2673 ExprResult BaseResult
= getSema().PerformMemberExprBaseConversion(Base
,
2675 if (!Member
->getDeclName()) {
2676 // We have a reference to an unnamed field. This is always the
2677 // base of an anonymous struct/union member access, i.e. the
2678 // field is always of record type.
2679 assert(Member
->getType()->isRecordType() &&
2680 "unnamed member not of record type?");
2683 getSema().PerformObjectMemberConversion(BaseResult
.get(),
2684 QualifierLoc
.getNestedNameSpecifier(),
2686 if (BaseResult
.isInvalid())
2688 Base
= BaseResult
.get();
2690 CXXScopeSpec EmptySS
;
2691 return getSema().BuildFieldReferenceExpr(
2692 Base
, isArrow
, OpLoc
, EmptySS
, cast
<FieldDecl
>(Member
),
2693 DeclAccessPair::make(FoundDecl
, FoundDecl
->getAccess()), MemberNameInfo
);
2697 SS
.Adopt(QualifierLoc
);
2699 Base
= BaseResult
.get();
2700 QualType BaseType
= Base
->getType();
2702 if (isArrow
&& !BaseType
->isPointerType())
2705 // FIXME: this involves duplicating earlier analysis in a lot of
2706 // cases; we should avoid this when possible.
2707 LookupResult
R(getSema(), MemberNameInfo
, Sema::LookupMemberName
);
2708 R
.addDecl(FoundDecl
);
2711 return getSema().BuildMemberReferenceExpr(Base
, BaseType
, OpLoc
, isArrow
,
2713 FirstQualifierInScope
,
2714 R
, ExplicitTemplateArgs
,
2718 /// Build a new binary operator expression.
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
2722 ExprResult
RebuildBinaryOperator(SourceLocation OpLoc
,
2723 BinaryOperatorKind Opc
,
2724 Expr
*LHS
, Expr
*RHS
) {
2725 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc
, Opc
, LHS
, RHS
);
2728 /// Build a new rewritten operator expression.
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
2732 ExprResult
RebuildCXXRewrittenBinaryOperator(
2733 SourceLocation OpLoc
, BinaryOperatorKind Opcode
,
2734 const UnresolvedSetImpl
&UnqualLookups
, Expr
*LHS
, Expr
*RHS
) {
2735 return getSema().CreateOverloadedBinOp(OpLoc
, Opcode
, UnqualLookups
, LHS
,
2736 RHS
, /*RequiresADL*/false);
2739 /// Build a new conditional operator expression.
2741 /// By default, performs semantic analysis to build the new expression.
2742 /// Subclasses may override this routine to provide different behavior.
2743 ExprResult
RebuildConditionalOperator(Expr
*Cond
,
2744 SourceLocation QuestionLoc
,
2746 SourceLocation ColonLoc
,
2748 return getSema().ActOnConditionalOp(QuestionLoc
, ColonLoc
, Cond
,
2752 /// Build a new C-style cast expression.
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
2756 ExprResult
RebuildCStyleCastExpr(SourceLocation LParenLoc
,
2757 TypeSourceInfo
*TInfo
,
2758 SourceLocation RParenLoc
,
2760 return getSema().BuildCStyleCastExpr(LParenLoc
, TInfo
, RParenLoc
,
2764 /// Build a new compound literal expression.
2766 /// By default, performs semantic analysis to build the new expression.
2767 /// Subclasses may override this routine to provide different behavior.
2768 ExprResult
RebuildCompoundLiteralExpr(SourceLocation LParenLoc
,
2769 TypeSourceInfo
*TInfo
,
2770 SourceLocation RParenLoc
,
2772 return getSema().BuildCompoundLiteralExpr(LParenLoc
, TInfo
, RParenLoc
,
2776 /// Build a new extended vector element access expression.
2778 /// By default, performs semantic analysis to build the new expression.
2779 /// Subclasses may override this routine to provide different behavior.
2780 ExprResult
RebuildExtVectorElementExpr(Expr
*Base
,
2781 SourceLocation OpLoc
,
2782 SourceLocation AccessorLoc
,
2783 IdentifierInfo
&Accessor
) {
2786 DeclarationNameInfo
NameInfo(&Accessor
, AccessorLoc
);
2787 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
2788 OpLoc
, /*IsArrow*/ false,
2789 SS
, SourceLocation(),
2790 /*FirstQualifierInScope*/ nullptr,
2792 /* TemplateArgs */ nullptr,
2796 /// Build a new initializer list expression.
2798 /// By default, performs semantic analysis to build the new expression.
2799 /// Subclasses may override this routine to provide different behavior.
2800 ExprResult
RebuildInitList(SourceLocation LBraceLoc
,
2802 SourceLocation RBraceLoc
) {
2803 return SemaRef
.BuildInitList(LBraceLoc
, Inits
, RBraceLoc
);
2806 /// Build a new designated initializer expression.
2808 /// By default, performs semantic analysis to build the new expression.
2809 /// Subclasses may override this routine to provide different behavior.
2810 ExprResult
RebuildDesignatedInitExpr(Designation
&Desig
,
2811 MultiExprArg ArrayExprs
,
2812 SourceLocation EqualOrColonLoc
,
2816 = SemaRef
.ActOnDesignatedInitializer(Desig
, EqualOrColonLoc
, GNUSyntax
,
2818 if (Result
.isInvalid())
2824 /// Build a new value-initialized expression.
2826 /// By default, builds the implicit value initialization without performing
2827 /// any semantic analysis. Subclasses may override this routine to provide
2828 /// different behavior.
2829 ExprResult
RebuildImplicitValueInitExpr(QualType T
) {
2830 return new (SemaRef
.Context
) ImplicitValueInitExpr(T
);
2833 /// Build a new \c va_arg expression.
2835 /// By default, performs semantic analysis to build the new expression.
2836 /// Subclasses may override this routine to provide different behavior.
2837 ExprResult
RebuildVAArgExpr(SourceLocation BuiltinLoc
,
2838 Expr
*SubExpr
, TypeSourceInfo
*TInfo
,
2839 SourceLocation RParenLoc
) {
2840 return getSema().BuildVAArgExpr(BuiltinLoc
,
2845 /// Build a new expression list in parentheses.
2847 /// By default, performs semantic analysis to build the new expression.
2848 /// Subclasses may override this routine to provide different behavior.
2849 ExprResult
RebuildParenListExpr(SourceLocation LParenLoc
,
2850 MultiExprArg SubExprs
,
2851 SourceLocation RParenLoc
) {
2852 return getSema().ActOnParenListExpr(LParenLoc
, RParenLoc
, SubExprs
);
2855 /// Build a new address-of-label expression.
2857 /// By default, performs semantic analysis, using the name of the label
2858 /// rather than attempting to map the label statement itself.
2859 /// Subclasses may override this routine to provide different behavior.
2860 ExprResult
RebuildAddrLabelExpr(SourceLocation AmpAmpLoc
,
2861 SourceLocation LabelLoc
, LabelDecl
*Label
) {
2862 return getSema().ActOnAddrLabel(AmpAmpLoc
, LabelLoc
, Label
);
2865 /// Build a new GNU statement expression.
2867 /// By default, performs semantic analysis to build the new expression.
2868 /// Subclasses may override this routine to provide different behavior.
2869 ExprResult
RebuildStmtExpr(SourceLocation LParenLoc
, Stmt
*SubStmt
,
2870 SourceLocation RParenLoc
, unsigned TemplateDepth
) {
2871 return getSema().BuildStmtExpr(LParenLoc
, SubStmt
, RParenLoc
,
2875 /// Build a new __builtin_choose_expr expression.
2877 /// By default, performs semantic analysis to build the new expression.
2878 /// Subclasses may override this routine to provide different behavior.
2879 ExprResult
RebuildChooseExpr(SourceLocation BuiltinLoc
,
2880 Expr
*Cond
, Expr
*LHS
, Expr
*RHS
,
2881 SourceLocation RParenLoc
) {
2882 return SemaRef
.ActOnChooseExpr(BuiltinLoc
,
2887 /// Build a new generic selection expression.
2889 /// By default, performs semantic analysis to build the new expression.
2890 /// Subclasses may override this routine to provide different behavior.
2891 ExprResult
RebuildGenericSelectionExpr(SourceLocation KeyLoc
,
2892 SourceLocation DefaultLoc
,
2893 SourceLocation RParenLoc
,
2894 Expr
*ControllingExpr
,
2895 ArrayRef
<TypeSourceInfo
*> Types
,
2896 ArrayRef
<Expr
*> Exprs
) {
2897 return getSema().CreateGenericSelectionExpr(KeyLoc
, DefaultLoc
, RParenLoc
,
2898 ControllingExpr
, Types
, Exprs
);
2901 /// Build a new overloaded operator call expression.
2903 /// By default, performs semantic analysis to build the new expression.
2904 /// The semantic analysis provides the behavior of template instantiation,
2905 /// copying with transformations that turn what looks like an overloaded
2906 /// operator call into a use of a builtin operator, performing
2907 /// argument-dependent lookup, etc. Subclasses may override this routine to
2908 /// provide different behavior.
2909 ExprResult
RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op
,
2910 SourceLocation OpLoc
,
2915 /// Build a new C++ "named" cast expression, such as static_cast or
2916 /// reinterpret_cast.
2918 /// By default, this routine dispatches to one of the more-specific routines
2919 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2920 /// Subclasses may override this routine to provide different behavior.
2921 ExprResult
RebuildCXXNamedCastExpr(SourceLocation OpLoc
,
2922 Stmt::StmtClass Class
,
2923 SourceLocation LAngleLoc
,
2924 TypeSourceInfo
*TInfo
,
2925 SourceLocation RAngleLoc
,
2926 SourceLocation LParenLoc
,
2928 SourceLocation RParenLoc
) {
2930 case Stmt::CXXStaticCastExprClass
:
2931 return getDerived().RebuildCXXStaticCastExpr(OpLoc
, LAngleLoc
, TInfo
,
2932 RAngleLoc
, LParenLoc
,
2933 SubExpr
, RParenLoc
);
2935 case Stmt::CXXDynamicCastExprClass
:
2936 return getDerived().RebuildCXXDynamicCastExpr(OpLoc
, LAngleLoc
, TInfo
,
2937 RAngleLoc
, LParenLoc
,
2938 SubExpr
, RParenLoc
);
2940 case Stmt::CXXReinterpretCastExprClass
:
2941 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc
, LAngleLoc
, TInfo
,
2942 RAngleLoc
, LParenLoc
,
2946 case Stmt::CXXConstCastExprClass
:
2947 return getDerived().RebuildCXXConstCastExpr(OpLoc
, LAngleLoc
, TInfo
,
2948 RAngleLoc
, LParenLoc
,
2949 SubExpr
, RParenLoc
);
2951 case Stmt::CXXAddrspaceCastExprClass
:
2952 return getDerived().RebuildCXXAddrspaceCastExpr(
2953 OpLoc
, LAngleLoc
, TInfo
, RAngleLoc
, LParenLoc
, SubExpr
, RParenLoc
);
2956 llvm_unreachable("Invalid C++ named cast");
2960 /// Build a new C++ static_cast expression.
2962 /// By default, performs semantic analysis to build the new expression.
2963 /// Subclasses may override this routine to provide different behavior.
2964 ExprResult
RebuildCXXStaticCastExpr(SourceLocation OpLoc
,
2965 SourceLocation LAngleLoc
,
2966 TypeSourceInfo
*TInfo
,
2967 SourceLocation RAngleLoc
,
2968 SourceLocation LParenLoc
,
2970 SourceLocation RParenLoc
) {
2971 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_static_cast
,
2973 SourceRange(LAngleLoc
, RAngleLoc
),
2974 SourceRange(LParenLoc
, RParenLoc
));
2977 /// Build a new C++ dynamic_cast expression.
2979 /// By default, performs semantic analysis to build the new expression.
2980 /// Subclasses may override this routine to provide different behavior.
2981 ExprResult
RebuildCXXDynamicCastExpr(SourceLocation OpLoc
,
2982 SourceLocation LAngleLoc
,
2983 TypeSourceInfo
*TInfo
,
2984 SourceLocation RAngleLoc
,
2985 SourceLocation LParenLoc
,
2987 SourceLocation RParenLoc
) {
2988 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_dynamic_cast
,
2990 SourceRange(LAngleLoc
, RAngleLoc
),
2991 SourceRange(LParenLoc
, RParenLoc
));
2994 /// Build a new C++ reinterpret_cast expression.
2996 /// By default, performs semantic analysis to build the new expression.
2997 /// Subclasses may override this routine to provide different behavior.
2998 ExprResult
RebuildCXXReinterpretCastExpr(SourceLocation OpLoc
,
2999 SourceLocation LAngleLoc
,
3000 TypeSourceInfo
*TInfo
,
3001 SourceLocation RAngleLoc
,
3002 SourceLocation LParenLoc
,
3004 SourceLocation RParenLoc
) {
3005 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_reinterpret_cast
,
3007 SourceRange(LAngleLoc
, RAngleLoc
),
3008 SourceRange(LParenLoc
, RParenLoc
));
3011 /// Build a new C++ const_cast expression.
3013 /// By default, performs semantic analysis to build the new expression.
3014 /// Subclasses may override this routine to provide different behavior.
3015 ExprResult
RebuildCXXConstCastExpr(SourceLocation OpLoc
,
3016 SourceLocation LAngleLoc
,
3017 TypeSourceInfo
*TInfo
,
3018 SourceLocation RAngleLoc
,
3019 SourceLocation LParenLoc
,
3021 SourceLocation RParenLoc
) {
3022 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_const_cast
,
3024 SourceRange(LAngleLoc
, RAngleLoc
),
3025 SourceRange(LParenLoc
, RParenLoc
));
3029 RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc
, SourceLocation LAngleLoc
,
3030 TypeSourceInfo
*TInfo
, SourceLocation RAngleLoc
,
3031 SourceLocation LParenLoc
, Expr
*SubExpr
,
3032 SourceLocation RParenLoc
) {
3033 return getSema().BuildCXXNamedCast(
3034 OpLoc
, tok::kw_addrspace_cast
, TInfo
, SubExpr
,
3035 SourceRange(LAngleLoc
, RAngleLoc
), SourceRange(LParenLoc
, RParenLoc
));
3038 /// Build a new C++ functional-style cast expression.
3040 /// By default, performs semantic analysis to build the new expression.
3041 /// Subclasses may override this routine to provide different behavior.
3042 ExprResult
RebuildCXXFunctionalCastExpr(TypeSourceInfo
*TInfo
,
3043 SourceLocation LParenLoc
,
3045 SourceLocation RParenLoc
,
3046 bool ListInitialization
) {
3047 return getSema().BuildCXXTypeConstructExpr(TInfo
, LParenLoc
,
3048 MultiExprArg(&Sub
, 1), RParenLoc
,
3049 ListInitialization
);
3052 /// Build a new C++ __builtin_bit_cast expression.
3054 /// By default, performs semantic analysis to build the new expression.
3055 /// Subclasses may override this routine to provide different behavior.
3056 ExprResult
RebuildBuiltinBitCastExpr(SourceLocation KWLoc
,
3057 TypeSourceInfo
*TSI
, Expr
*Sub
,
3058 SourceLocation RParenLoc
) {
3059 return getSema().BuildBuiltinBitCastExpr(KWLoc
, TSI
, Sub
, RParenLoc
);
3062 /// Build a new C++ typeid(type) expression.
3064 /// By default, performs semantic analysis to build the new expression.
3065 /// Subclasses may override this routine to provide different behavior.
3066 ExprResult
RebuildCXXTypeidExpr(QualType TypeInfoType
,
3067 SourceLocation TypeidLoc
,
3068 TypeSourceInfo
*Operand
,
3069 SourceLocation RParenLoc
) {
3070 return getSema().BuildCXXTypeId(TypeInfoType
, TypeidLoc
, Operand
,
3075 /// Build a new C++ typeid(expr) expression.
3077 /// By default, performs semantic analysis to build the new expression.
3078 /// Subclasses may override this routine to provide different behavior.
3079 ExprResult
RebuildCXXTypeidExpr(QualType TypeInfoType
,
3080 SourceLocation TypeidLoc
,
3082 SourceLocation RParenLoc
) {
3083 return getSema().BuildCXXTypeId(TypeInfoType
, TypeidLoc
, Operand
,
3087 /// Build a new C++ __uuidof(type) expression.
3089 /// By default, performs semantic analysis to build the new expression.
3090 /// Subclasses may override this routine to provide different behavior.
3091 ExprResult
RebuildCXXUuidofExpr(QualType Type
, SourceLocation TypeidLoc
,
3092 TypeSourceInfo
*Operand
,
3093 SourceLocation RParenLoc
) {
3094 return getSema().BuildCXXUuidof(Type
, TypeidLoc
, Operand
, RParenLoc
);
3097 /// Build a new C++ __uuidof(expr) expression.
3099 /// By default, performs semantic analysis to build the new expression.
3100 /// Subclasses may override this routine to provide different behavior.
3101 ExprResult
RebuildCXXUuidofExpr(QualType Type
, SourceLocation TypeidLoc
,
3102 Expr
*Operand
, SourceLocation RParenLoc
) {
3103 return getSema().BuildCXXUuidof(Type
, TypeidLoc
, Operand
, RParenLoc
);
3106 /// Build a new C++ "this" expression.
3108 /// By default, builds a new "this" expression without performing any
3109 /// semantic analysis. Subclasses may override this routine to provide
3110 /// different behavior.
3111 ExprResult
RebuildCXXThisExpr(SourceLocation ThisLoc
,
3114 return getSema().BuildCXXThisExpr(ThisLoc
, ThisType
, isImplicit
);
3117 /// Build a new C++ throw expression.
3119 /// By default, performs semantic analysis to build the new expression.
3120 /// Subclasses may override this routine to provide different behavior.
3121 ExprResult
RebuildCXXThrowExpr(SourceLocation ThrowLoc
, Expr
*Sub
,
3122 bool IsThrownVariableInScope
) {
3123 return getSema().BuildCXXThrow(ThrowLoc
, Sub
, IsThrownVariableInScope
);
3126 /// Build a new C++ default-argument expression.
3128 /// By default, builds a new default-argument expression, which does not
3129 /// require any semantic analysis. Subclasses may override this routine to
3130 /// provide different behavior.
3131 ExprResult
RebuildCXXDefaultArgExpr(SourceLocation Loc
, ParmVarDecl
*Param
) {
3132 return CXXDefaultArgExpr::Create(getSema().Context
, Loc
, Param
,
3133 getSema().CurContext
);
3136 /// Build a new C++11 default-initialization expression.
3138 /// By default, builds a new default field initialization expression, which
3139 /// does not require any semantic analysis. Subclasses may override this
3140 /// routine to provide different behavior.
3141 ExprResult
RebuildCXXDefaultInitExpr(SourceLocation Loc
,
3143 return CXXDefaultInitExpr::Create(getSema().Context
, Loc
, Field
,
3144 getSema().CurContext
);
3147 /// Build a new C++ zero-initialization expression.
3149 /// By default, performs semantic analysis to build the new expression.
3150 /// Subclasses may override this routine to provide different behavior.
3151 ExprResult
RebuildCXXScalarValueInitExpr(TypeSourceInfo
*TSInfo
,
3152 SourceLocation LParenLoc
,
3153 SourceLocation RParenLoc
) {
3154 return getSema().BuildCXXTypeConstructExpr(
3155 TSInfo
, LParenLoc
, None
, RParenLoc
, /*ListInitialization=*/false);
3158 /// Build a new C++ "new" expression.
3160 /// By default, performs semantic analysis to build the new expression.
3161 /// Subclasses may override this routine to provide different behavior.
3162 ExprResult
RebuildCXXNewExpr(SourceLocation StartLoc
,
3164 SourceLocation PlacementLParen
,
3165 MultiExprArg PlacementArgs
,
3166 SourceLocation PlacementRParen
,
3167 SourceRange TypeIdParens
,
3168 QualType AllocatedType
,
3169 TypeSourceInfo
*AllocatedTypeInfo
,
3170 Optional
<Expr
*> ArraySize
,
3171 SourceRange DirectInitRange
,
3172 Expr
*Initializer
) {
3173 return getSema().BuildCXXNew(StartLoc
, UseGlobal
,
3185 /// Build a new C++ "delete" expression.
3187 /// By default, performs semantic analysis to build the new expression.
3188 /// Subclasses may override this routine to provide different behavior.
3189 ExprResult
RebuildCXXDeleteExpr(SourceLocation StartLoc
,
3190 bool IsGlobalDelete
,
3193 return getSema().ActOnCXXDelete(StartLoc
, IsGlobalDelete
, IsArrayForm
,
3197 /// Build a new type trait expression.
3199 /// By default, performs semantic analysis to build the new expression.
3200 /// Subclasses may override this routine to provide different behavior.
3201 ExprResult
RebuildTypeTrait(TypeTrait Trait
,
3202 SourceLocation StartLoc
,
3203 ArrayRef
<TypeSourceInfo
*> Args
,
3204 SourceLocation RParenLoc
) {
3205 return getSema().BuildTypeTrait(Trait
, StartLoc
, Args
, RParenLoc
);
3208 /// Build a new array type trait expression.
3210 /// By default, performs semantic analysis to build the new expression.
3211 /// Subclasses may override this routine to provide different behavior.
3212 ExprResult
RebuildArrayTypeTrait(ArrayTypeTrait Trait
,
3213 SourceLocation StartLoc
,
3214 TypeSourceInfo
*TSInfo
,
3216 SourceLocation RParenLoc
) {
3217 return getSema().BuildArrayTypeTrait(Trait
, StartLoc
, TSInfo
, DimExpr
, RParenLoc
);
3220 /// Build a new expression trait expression.
3222 /// By default, performs semantic analysis to build the new expression.
3223 /// Subclasses may override this routine to provide different behavior.
3224 ExprResult
RebuildExpressionTrait(ExpressionTrait Trait
,
3225 SourceLocation StartLoc
,
3227 SourceLocation RParenLoc
) {
3228 return getSema().BuildExpressionTrait(Trait
, StartLoc
, Queried
, RParenLoc
);
3231 /// Build a new (previously unresolved) declaration reference
3234 /// By default, performs semantic analysis to build the new expression.
3235 /// Subclasses may override this routine to provide different behavior.
3236 ExprResult
RebuildDependentScopeDeclRefExpr(
3237 NestedNameSpecifierLoc QualifierLoc
,
3238 SourceLocation TemplateKWLoc
,
3239 const DeclarationNameInfo
&NameInfo
,
3240 const TemplateArgumentListInfo
*TemplateArgs
,
3241 bool IsAddressOfOperand
,
3242 TypeSourceInfo
**RecoveryTSI
) {
3244 SS
.Adopt(QualifierLoc
);
3246 if (TemplateArgs
|| TemplateKWLoc
.isValid())
3247 return getSema().BuildQualifiedTemplateIdExpr(SS
, TemplateKWLoc
, NameInfo
,
3250 return getSema().BuildQualifiedDeclarationNameExpr(
3251 SS
, NameInfo
, IsAddressOfOperand
, /*S*/nullptr, RecoveryTSI
);
3254 /// Build a new template-id expression.
3256 /// By default, performs semantic analysis to build the new expression.
3257 /// Subclasses may override this routine to provide different behavior.
3258 ExprResult
RebuildTemplateIdExpr(const CXXScopeSpec
&SS
,
3259 SourceLocation TemplateKWLoc
,
3262 const TemplateArgumentListInfo
*TemplateArgs
) {
3263 return getSema().BuildTemplateIdExpr(SS
, TemplateKWLoc
, R
, RequiresADL
,
3267 /// Build a new object-construction expression.
3269 /// By default, performs semantic analysis to build the new expression.
3270 /// Subclasses may override this routine to provide different behavior.
3271 ExprResult
RebuildCXXConstructExpr(QualType T
,
3273 CXXConstructorDecl
*Constructor
,
3276 bool HadMultipleCandidates
,
3277 bool ListInitialization
,
3278 bool StdInitListInitialization
,
3279 bool RequiresZeroInit
,
3280 CXXConstructExpr::ConstructionKind ConstructKind
,
3281 SourceRange ParenRange
) {
3282 // Reconstruct the constructor we originally found, which might be
3283 // different if this is a call to an inherited constructor.
3284 CXXConstructorDecl
*FoundCtor
= Constructor
;
3285 if (Constructor
->isInheritingConstructor())
3286 FoundCtor
= Constructor
->getInheritedConstructor().getConstructor();
3288 SmallVector
<Expr
*, 8> ConvertedArgs
;
3289 if (getSema().CompleteConstructorCall(FoundCtor
, T
, Args
, Loc
,
3293 return getSema().BuildCXXConstructExpr(Loc
, T
, Constructor
,
3296 HadMultipleCandidates
,
3298 StdInitListInitialization
,
3299 RequiresZeroInit
, ConstructKind
,
3303 /// Build a new implicit construction via inherited constructor
3305 ExprResult
RebuildCXXInheritedCtorInitExpr(QualType T
, SourceLocation Loc
,
3306 CXXConstructorDecl
*Constructor
,
3307 bool ConstructsVBase
,
3308 bool InheritedFromVBase
) {
3309 return new (getSema().Context
) CXXInheritedCtorInitExpr(
3310 Loc
, T
, Constructor
, ConstructsVBase
, InheritedFromVBase
);
3313 /// Build a new object-construction expression.
3315 /// By default, performs semantic analysis to build the new expression.
3316 /// Subclasses may override this routine to provide different behavior.
3317 ExprResult
RebuildCXXTemporaryObjectExpr(TypeSourceInfo
*TSInfo
,
3318 SourceLocation LParenOrBraceLoc
,
3320 SourceLocation RParenOrBraceLoc
,
3321 bool ListInitialization
) {
3322 return getSema().BuildCXXTypeConstructExpr(
3323 TSInfo
, LParenOrBraceLoc
, Args
, RParenOrBraceLoc
, ListInitialization
);
3326 /// Build a new object-construction expression.
3328 /// By default, performs semantic analysis to build the new expression.
3329 /// Subclasses may override this routine to provide different behavior.
3330 ExprResult
RebuildCXXUnresolvedConstructExpr(TypeSourceInfo
*TSInfo
,
3331 SourceLocation LParenLoc
,
3333 SourceLocation RParenLoc
,
3334 bool ListInitialization
) {
3335 return getSema().BuildCXXTypeConstructExpr(TSInfo
, LParenLoc
, Args
,
3336 RParenLoc
, ListInitialization
);
3339 /// Build a new member reference expression.
3341 /// By default, performs semantic analysis to build the new expression.
3342 /// Subclasses may override this routine to provide different behavior.
3343 ExprResult
RebuildCXXDependentScopeMemberExpr(Expr
*BaseE
,
3346 SourceLocation OperatorLoc
,
3347 NestedNameSpecifierLoc QualifierLoc
,
3348 SourceLocation TemplateKWLoc
,
3349 NamedDecl
*FirstQualifierInScope
,
3350 const DeclarationNameInfo
&MemberNameInfo
,
3351 const TemplateArgumentListInfo
*TemplateArgs
) {
3353 SS
.Adopt(QualifierLoc
);
3355 return SemaRef
.BuildMemberReferenceExpr(BaseE
, BaseType
,
3356 OperatorLoc
, IsArrow
,
3358 FirstQualifierInScope
,
3360 TemplateArgs
, /*S*/nullptr);
3363 /// Build a new member reference expression.
3365 /// By default, performs semantic analysis to build the new expression.
3366 /// Subclasses may override this routine to provide different behavior.
3367 ExprResult
RebuildUnresolvedMemberExpr(Expr
*BaseE
, QualType BaseType
,
3368 SourceLocation OperatorLoc
,
3370 NestedNameSpecifierLoc QualifierLoc
,
3371 SourceLocation TemplateKWLoc
,
3372 NamedDecl
*FirstQualifierInScope
,
3374 const TemplateArgumentListInfo
*TemplateArgs
) {
3376 SS
.Adopt(QualifierLoc
);
3378 return SemaRef
.BuildMemberReferenceExpr(BaseE
, BaseType
,
3379 OperatorLoc
, IsArrow
,
3381 FirstQualifierInScope
,
3382 R
, TemplateArgs
, /*S*/nullptr);
3385 /// Build a new noexcept expression.
3387 /// By default, performs semantic analysis to build the new expression.
3388 /// Subclasses may override this routine to provide different behavior.
3389 ExprResult
RebuildCXXNoexceptExpr(SourceRange Range
, Expr
*Arg
) {
3390 return SemaRef
.BuildCXXNoexceptExpr(Range
.getBegin(), Arg
, Range
.getEnd());
3393 /// Build a new expression to compute the length of a parameter pack.
3394 ExprResult
RebuildSizeOfPackExpr(SourceLocation OperatorLoc
,
3396 SourceLocation PackLoc
,
3397 SourceLocation RParenLoc
,
3398 Optional
<unsigned> Length
,
3399 ArrayRef
<TemplateArgument
> PartialArgs
) {
3400 return SizeOfPackExpr::Create(SemaRef
.Context
, OperatorLoc
, Pack
, PackLoc
,
3401 RParenLoc
, Length
, PartialArgs
);
3404 /// Build a new expression representing a call to a source location
3407 /// By default, performs semantic analysis to build the new expression.
3408 /// Subclasses may override this routine to provide different behavior.
3409 ExprResult
RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind
,
3410 QualType ResultTy
, SourceLocation BuiltinLoc
,
3411 SourceLocation RPLoc
,
3412 DeclContext
*ParentContext
) {
3413 return getSema().BuildSourceLocExpr(Kind
, ResultTy
, BuiltinLoc
, RPLoc
,
3417 /// Build a new Objective-C boxed expression.
3419 /// By default, performs semantic analysis to build the new expression.
3420 /// Subclasses may override this routine to provide different behavior.
3421 ExprResult
RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS
,
3422 SourceLocation TemplateKWLoc
, DeclarationNameInfo ConceptNameInfo
,
3423 NamedDecl
*FoundDecl
, ConceptDecl
*NamedConcept
,
3424 TemplateArgumentListInfo
*TALI
) {
3427 ExprResult Result
= getSema().CheckConceptTemplateId(SS
, TemplateKWLoc
,
3430 NamedConcept
, TALI
);
3431 if (Result
.isInvalid())
3436 /// \brief Build a new requires expression.
3438 /// By default, performs semantic analysis to build the new expression.
3439 /// Subclasses may override this routine to provide different behavior.
3440 ExprResult
RebuildRequiresExpr(SourceLocation RequiresKWLoc
,
3441 RequiresExprBodyDecl
*Body
,
3442 ArrayRef
<ParmVarDecl
*> LocalParameters
,
3443 ArrayRef
<concepts::Requirement
*> Requirements
,
3444 SourceLocation ClosingBraceLoc
) {
3445 return RequiresExpr::Create(SemaRef
.Context
, RequiresKWLoc
, Body
,
3446 LocalParameters
, Requirements
, ClosingBraceLoc
);
3449 concepts::TypeRequirement
*
3450 RebuildTypeRequirement(
3451 concepts::Requirement::SubstitutionDiagnostic
*SubstDiag
) {
3452 return SemaRef
.BuildTypeRequirement(SubstDiag
);
3455 concepts::TypeRequirement
*RebuildTypeRequirement(TypeSourceInfo
*T
) {
3456 return SemaRef
.BuildTypeRequirement(T
);
3459 concepts::ExprRequirement
*
3460 RebuildExprRequirement(
3461 concepts::Requirement::SubstitutionDiagnostic
*SubstDiag
, bool IsSimple
,
3462 SourceLocation NoexceptLoc
,
3463 concepts::ExprRequirement::ReturnTypeRequirement Ret
) {
3464 return SemaRef
.BuildExprRequirement(SubstDiag
, IsSimple
, NoexceptLoc
,
3468 concepts::ExprRequirement
*
3469 RebuildExprRequirement(Expr
*E
, bool IsSimple
, SourceLocation NoexceptLoc
,
3470 concepts::ExprRequirement::ReturnTypeRequirement Ret
) {
3471 return SemaRef
.BuildExprRequirement(E
, IsSimple
, NoexceptLoc
,
3475 concepts::NestedRequirement
*
3476 RebuildNestedRequirement(
3477 concepts::Requirement::SubstitutionDiagnostic
*SubstDiag
) {
3478 return SemaRef
.BuildNestedRequirement(SubstDiag
);
3481 concepts::NestedRequirement
*RebuildNestedRequirement(Expr
*Constraint
) {
3482 return SemaRef
.BuildNestedRequirement(Constraint
);
3485 /// \brief Build a new Objective-C boxed expression.
3487 /// By default, performs semantic analysis to build the new expression.
3488 /// Subclasses may override this routine to provide different behavior.
3489 ExprResult
RebuildObjCBoxedExpr(SourceRange SR
, Expr
*ValueExpr
) {
3490 return getSema().BuildObjCBoxedExpr(SR
, ValueExpr
);
3493 /// Build a new Objective-C array literal.
3495 /// By default, performs semantic analysis to build the new expression.
3496 /// Subclasses may override this routine to provide different behavior.
3497 ExprResult
RebuildObjCArrayLiteral(SourceRange Range
,
3498 Expr
**Elements
, unsigned NumElements
) {
3499 return getSema().BuildObjCArrayLiteral(Range
,
3500 MultiExprArg(Elements
, NumElements
));
3503 ExprResult
RebuildObjCSubscriptRefExpr(SourceLocation RB
,
3504 Expr
*Base
, Expr
*Key
,
3505 ObjCMethodDecl
*getterMethod
,
3506 ObjCMethodDecl
*setterMethod
) {
3507 return getSema().BuildObjCSubscriptExpression(RB
, Base
, Key
,
3508 getterMethod
, setterMethod
);
3511 /// Build a new Objective-C dictionary literal.
3513 /// By default, performs semantic analysis to build the new expression.
3514 /// Subclasses may override this routine to provide different behavior.
3515 ExprResult
RebuildObjCDictionaryLiteral(SourceRange Range
,
3516 MutableArrayRef
<ObjCDictionaryElement
> Elements
) {
3517 return getSema().BuildObjCDictionaryLiteral(Range
, Elements
);
3520 /// Build a new Objective-C \@encode expression.
3522 /// By default, performs semantic analysis to build the new expression.
3523 /// Subclasses may override this routine to provide different behavior.
3524 ExprResult
RebuildObjCEncodeExpr(SourceLocation AtLoc
,
3525 TypeSourceInfo
*EncodeTypeInfo
,
3526 SourceLocation RParenLoc
) {
3527 return SemaRef
.BuildObjCEncodeExpression(AtLoc
, EncodeTypeInfo
, RParenLoc
);
3530 /// Build a new Objective-C class message.
3531 ExprResult
RebuildObjCMessageExpr(TypeSourceInfo
*ReceiverTypeInfo
,
3533 ArrayRef
<SourceLocation
> SelectorLocs
,
3534 ObjCMethodDecl
*Method
,
3535 SourceLocation LBracLoc
,
3537 SourceLocation RBracLoc
) {
3538 return SemaRef
.BuildClassMessage(ReceiverTypeInfo
,
3539 ReceiverTypeInfo
->getType(),
3540 /*SuperLoc=*/SourceLocation(),
3541 Sel
, Method
, LBracLoc
, SelectorLocs
,
3545 /// Build a new Objective-C instance message.
3546 ExprResult
RebuildObjCMessageExpr(Expr
*Receiver
,
3548 ArrayRef
<SourceLocation
> SelectorLocs
,
3549 ObjCMethodDecl
*Method
,
3550 SourceLocation LBracLoc
,
3552 SourceLocation RBracLoc
) {
3553 return SemaRef
.BuildInstanceMessage(Receiver
,
3554 Receiver
->getType(),
3555 /*SuperLoc=*/SourceLocation(),
3556 Sel
, Method
, LBracLoc
, SelectorLocs
,
3560 /// Build a new Objective-C instance/class message to 'super'.
3561 ExprResult
RebuildObjCMessageExpr(SourceLocation SuperLoc
,
3563 ArrayRef
<SourceLocation
> SelectorLocs
,
3565 ObjCMethodDecl
*Method
,
3566 SourceLocation LBracLoc
,
3568 SourceLocation RBracLoc
) {
3569 return Method
->isInstanceMethod() ? SemaRef
.BuildInstanceMessage(nullptr,
3572 Sel
, Method
, LBracLoc
, SelectorLocs
,
3574 : SemaRef
.BuildClassMessage(nullptr,
3577 Sel
, Method
, LBracLoc
, SelectorLocs
,
3583 /// Build a new Objective-C ivar reference expression.
3585 /// By default, performs semantic analysis to build the new expression.
3586 /// Subclasses may override this routine to provide different behavior.
3587 ExprResult
RebuildObjCIvarRefExpr(Expr
*BaseArg
, ObjCIvarDecl
*Ivar
,
3588 SourceLocation IvarLoc
,
3589 bool IsArrow
, bool IsFreeIvar
) {
3591 DeclarationNameInfo
NameInfo(Ivar
->getDeclName(), IvarLoc
);
3592 ExprResult Result
= getSema().BuildMemberReferenceExpr(
3593 BaseArg
, BaseArg
->getType(),
3594 /*FIXME:*/ IvarLoc
, IsArrow
, SS
, SourceLocation(),
3595 /*FirstQualifierInScope=*/nullptr, NameInfo
,
3596 /*TemplateArgs=*/nullptr,
3598 if (IsFreeIvar
&& Result
.isUsable())
3599 cast
<ObjCIvarRefExpr
>(Result
.get())->setIsFreeIvar(IsFreeIvar
);
3603 /// Build a new Objective-C property reference expression.
3605 /// By default, performs semantic analysis to build the new expression.
3606 /// Subclasses may override this routine to provide different behavior.
3607 ExprResult
RebuildObjCPropertyRefExpr(Expr
*BaseArg
,
3608 ObjCPropertyDecl
*Property
,
3609 SourceLocation PropertyLoc
) {
3611 DeclarationNameInfo
NameInfo(Property
->getDeclName(), PropertyLoc
);
3612 return getSema().BuildMemberReferenceExpr(BaseArg
, BaseArg
->getType(),
3613 /*FIXME:*/PropertyLoc
,
3615 SS
, SourceLocation(),
3616 /*FirstQualifierInScope=*/nullptr,
3618 /*TemplateArgs=*/nullptr,
3622 /// Build a new Objective-C property reference expression.
3624 /// By default, performs semantic analysis to build the new expression.
3625 /// Subclasses may override this routine to provide different behavior.
3626 ExprResult
RebuildObjCPropertyRefExpr(Expr
*Base
, QualType T
,
3627 ObjCMethodDecl
*Getter
,
3628 ObjCMethodDecl
*Setter
,
3629 SourceLocation PropertyLoc
) {
3630 // Since these expressions can only be value-dependent, we do not
3631 // need to perform semantic analysis again.
3633 new (getSema().Context
) ObjCPropertyRefExpr(Getter
, Setter
, T
,
3634 VK_LValue
, OK_ObjCProperty
,
3635 PropertyLoc
, Base
));
3638 /// Build a new Objective-C "isa" expression.
3640 /// By default, performs semantic analysis to build the new expression.
3641 /// Subclasses may override this routine to provide different behavior.
3642 ExprResult
RebuildObjCIsaExpr(Expr
*BaseArg
, SourceLocation IsaLoc
,
3643 SourceLocation OpLoc
, bool IsArrow
) {
3645 DeclarationNameInfo
NameInfo(&getSema().Context
.Idents
.get("isa"), IsaLoc
);
3646 return getSema().BuildMemberReferenceExpr(BaseArg
, BaseArg
->getType(),
3648 SS
, SourceLocation(),
3649 /*FirstQualifierInScope=*/nullptr,
3651 /*TemplateArgs=*/nullptr,
3655 /// Build a new shuffle vector expression.
3657 /// By default, performs semantic analysis to build the new expression.
3658 /// Subclasses may override this routine to provide different behavior.
3659 ExprResult
RebuildShuffleVectorExpr(SourceLocation BuiltinLoc
,
3660 MultiExprArg SubExprs
,
3661 SourceLocation RParenLoc
) {
3662 // Find the declaration for __builtin_shufflevector
3663 const IdentifierInfo
&Name
3664 = SemaRef
.Context
.Idents
.get("__builtin_shufflevector");
3665 TranslationUnitDecl
*TUDecl
= SemaRef
.Context
.getTranslationUnitDecl();
3666 DeclContext::lookup_result Lookup
= TUDecl
->lookup(DeclarationName(&Name
));
3667 assert(!Lookup
.empty() && "No __builtin_shufflevector?");
3669 // Build a reference to the __builtin_shufflevector builtin
3670 FunctionDecl
*Builtin
= cast
<FunctionDecl
>(Lookup
.front());
3671 Expr
*Callee
= new (SemaRef
.Context
)
3672 DeclRefExpr(SemaRef
.Context
, Builtin
, false,
3673 SemaRef
.Context
.BuiltinFnTy
, VK_PRValue
, BuiltinLoc
);
3674 QualType CalleePtrTy
= SemaRef
.Context
.getPointerType(Builtin
->getType());
3675 Callee
= SemaRef
.ImpCastExprToType(Callee
, CalleePtrTy
,
3676 CK_BuiltinFnToFnPtr
).get();
3678 // Build the CallExpr
3679 ExprResult TheCall
= CallExpr::Create(
3680 SemaRef
.Context
, Callee
, SubExprs
, Builtin
->getCallResultType(),
3681 Expr::getValueKindForType(Builtin
->getReturnType()), RParenLoc
,
3682 FPOptionsOverride());
3684 // Type-check the __builtin_shufflevector expression.
3685 return SemaRef
.SemaBuiltinShuffleVector(cast
<CallExpr
>(TheCall
.get()));
3688 /// Build a new convert vector expression.
3689 ExprResult
RebuildConvertVectorExpr(SourceLocation BuiltinLoc
,
3690 Expr
*SrcExpr
, TypeSourceInfo
*DstTInfo
,
3691 SourceLocation RParenLoc
) {
3692 return SemaRef
.SemaConvertVectorExpr(SrcExpr
, DstTInfo
,
3693 BuiltinLoc
, RParenLoc
);
3696 /// Build a new template argument pack expansion.
3698 /// By default, performs semantic analysis to build a new pack expansion
3699 /// for a template argument. Subclasses may override this routine to provide
3700 /// different behavior.
3701 TemplateArgumentLoc
RebuildPackExpansion(TemplateArgumentLoc Pattern
,
3702 SourceLocation EllipsisLoc
,
3703 Optional
<unsigned> NumExpansions
) {
3704 switch (Pattern
.getArgument().getKind()) {
3705 case TemplateArgument::Expression
: {
3707 = getSema().CheckPackExpansion(Pattern
.getSourceExpression(),
3708 EllipsisLoc
, NumExpansions
);
3709 if (Result
.isInvalid())
3710 return TemplateArgumentLoc();
3712 return TemplateArgumentLoc(Result
.get(), Result
.get());
3715 case TemplateArgument::Template
:
3716 return TemplateArgumentLoc(
3718 TemplateArgument(Pattern
.getArgument().getAsTemplate(),
3720 Pattern
.getTemplateQualifierLoc(), Pattern
.getTemplateNameLoc(),
3723 case TemplateArgument::Null
:
3724 case TemplateArgument::Integral
:
3725 case TemplateArgument::Declaration
:
3726 case TemplateArgument::Pack
:
3727 case TemplateArgument::TemplateExpansion
:
3728 case TemplateArgument::NullPtr
:
3729 llvm_unreachable("Pack expansion pattern has no parameter packs");
3731 case TemplateArgument::Type
:
3732 if (TypeSourceInfo
*Expansion
3733 = getSema().CheckPackExpansion(Pattern
.getTypeSourceInfo(),
3736 return TemplateArgumentLoc(TemplateArgument(Expansion
->getType()),
3741 return TemplateArgumentLoc();
3744 /// Build a new expression pack expansion.
3746 /// By default, performs semantic analysis to build a new pack expansion
3747 /// for an expression. Subclasses may override this routine to provide
3748 /// different behavior.
3749 ExprResult
RebuildPackExpansion(Expr
*Pattern
, SourceLocation EllipsisLoc
,
3750 Optional
<unsigned> NumExpansions
) {
3751 return getSema().CheckPackExpansion(Pattern
, EllipsisLoc
, NumExpansions
);
3754 /// Build a new C++1z fold-expression.
3756 /// By default, performs semantic analysis in order to build a new fold
3758 ExprResult
RebuildCXXFoldExpr(UnresolvedLookupExpr
*ULE
,
3759 SourceLocation LParenLoc
, Expr
*LHS
,
3760 BinaryOperatorKind Operator
,
3761 SourceLocation EllipsisLoc
, Expr
*RHS
,
3762 SourceLocation RParenLoc
,
3763 Optional
<unsigned> NumExpansions
) {
3764 return getSema().BuildCXXFoldExpr(ULE
, LParenLoc
, LHS
, Operator
,
3765 EllipsisLoc
, RHS
, RParenLoc
,
3769 /// Build an empty C++1z fold-expression with the given operator.
3771 /// By default, produces the fallback value for the fold-expression, or
3772 /// produce an error if there is no fallback value.
3773 ExprResult
RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc
,
3774 BinaryOperatorKind Operator
) {
3775 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc
, Operator
);
3778 /// Build a new atomic operation expression.
3780 /// By default, performs semantic analysis to build the new expression.
3781 /// Subclasses may override this routine to provide different behavior.
3782 ExprResult
RebuildAtomicExpr(SourceLocation BuiltinLoc
, MultiExprArg SubExprs
,
3783 AtomicExpr::AtomicOp Op
,
3784 SourceLocation RParenLoc
) {
3785 // Use this for all of the locations, since we don't know the difference
3786 // between the call and the expr at this point.
3787 SourceRange Range
{BuiltinLoc
, RParenLoc
};
3788 return getSema().BuildAtomicExpr(Range
, Range
, RParenLoc
, SubExprs
, Op
,
3789 Sema::AtomicArgumentOrder::AST
);
3792 ExprResult
RebuildRecoveryExpr(SourceLocation BeginLoc
, SourceLocation EndLoc
,
3793 ArrayRef
<Expr
*> SubExprs
, QualType Type
) {
3794 return getSema().CreateRecoveryExpr(BeginLoc
, EndLoc
, SubExprs
, Type
);
3798 TypeLoc
TransformTypeInObjectScope(TypeLoc TL
,
3799 QualType ObjectType
,
3800 NamedDecl
*FirstQualifierInScope
,
3803 TypeSourceInfo
*TransformTypeInObjectScope(TypeSourceInfo
*TSInfo
,
3804 QualType ObjectType
,
3805 NamedDecl
*FirstQualifierInScope
,
3808 TypeSourceInfo
*TransformTSIInObjectScope(TypeLoc TL
, QualType ObjectType
,
3809 NamedDecl
*FirstQualifierInScope
,
3812 QualType
TransformDependentNameType(TypeLocBuilder
&TLB
,
3813 DependentNameTypeLoc TL
,
3814 bool DeducibleTSTContext
);
3817 template <typename Derived
>
3818 StmtResult TreeTransform
<Derived
>::TransformStmt(Stmt
*S
, StmtDiscardKind SDK
) {
3822 switch (S
->getStmtClass()) {
3823 case Stmt::NoStmtClass
: break;
3825 // Transform individual statement nodes
3826 // Pass SDK into statements that can produce a value
3827 #define STMT(Node, Parent) \
3828 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3829 #define VALUESTMT(Node, Parent) \
3830 case Stmt::Node##Class: \
3831 return getDerived().Transform##Node(cast<Node>(S), SDK);
3832 #define ABSTRACT_STMT(Node)
3833 #define EXPR(Node, Parent)
3834 #include "clang/AST/StmtNodes.inc"
3836 // Transform expressions by calling TransformExpr.
3837 #define STMT(Node, Parent)
3838 #define ABSTRACT_STMT(Stmt)
3839 #define EXPR(Node, Parent) case Stmt::Node##Class:
3840 #include "clang/AST/StmtNodes.inc"
3842 ExprResult E
= getDerived().TransformExpr(cast
<Expr
>(S
));
3844 if (SDK
== SDK_StmtExprResult
)
3845 E
= getSema().ActOnStmtExprResult(E
);
3846 return getSema().ActOnExprStmt(E
, SDK
== SDK_Discarded
);
3853 template<typename Derived
>
3854 OMPClause
*TreeTransform
<Derived
>::TransformOMPClause(OMPClause
*S
) {
3858 switch (S
->getClauseKind()) {
3860 // Transform individual clause nodes
3861 #define GEN_CLANG_CLAUSE_CLASS
3862 #define CLAUSE_CLASS(Enum, Str, Class) \
3864 return getDerived().Transform##Class(cast<Class>(S));
3865 #include "llvm/Frontend/OpenMP/OMP.inc"
3872 template<typename Derived
>
3873 ExprResult TreeTransform
<Derived
>::TransformExpr(Expr
*E
) {
3877 switch (E
->getStmtClass()) {
3878 case Stmt::NoStmtClass
: break;
3879 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3880 #define ABSTRACT_STMT(Stmt)
3881 #define EXPR(Node, Parent) \
3882 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3883 #include "clang/AST/StmtNodes.inc"
3889 template<typename Derived
>
3890 ExprResult TreeTransform
<Derived
>::TransformInitializer(Expr
*Init
,
3892 // Initializers are instantiated like expressions, except that various outer
3893 // layers are stripped.
3897 if (auto *FE
= dyn_cast
<FullExpr
>(Init
))
3898 Init
= FE
->getSubExpr();
3900 if (auto *AIL
= dyn_cast
<ArrayInitLoopExpr
>(Init
)) {
3901 OpaqueValueExpr
*OVE
= AIL
->getCommonExpr();
3902 Init
= OVE
->getSourceExpr();
3905 if (MaterializeTemporaryExpr
*MTE
= dyn_cast
<MaterializeTemporaryExpr
>(Init
))
3906 Init
= MTE
->getSubExpr();
3908 while (CXXBindTemporaryExpr
*Binder
= dyn_cast
<CXXBindTemporaryExpr
>(Init
))
3909 Init
= Binder
->getSubExpr();
3911 if (ImplicitCastExpr
*ICE
= dyn_cast
<ImplicitCastExpr
>(Init
))
3912 Init
= ICE
->getSubExprAsWritten();
3914 if (CXXStdInitializerListExpr
*ILE
=
3915 dyn_cast
<CXXStdInitializerListExpr
>(Init
))
3916 return TransformInitializer(ILE
->getSubExpr(), NotCopyInit
);
3918 // If this is copy-initialization, we only need to reconstruct
3919 // InitListExprs. Other forms of copy-initialization will be a no-op if
3920 // the initializer is already the right type.
3921 CXXConstructExpr
*Construct
= dyn_cast
<CXXConstructExpr
>(Init
);
3922 if (!NotCopyInit
&& !(Construct
&& Construct
->isListInitialization()))
3923 return getDerived().TransformExpr(Init
);
3925 // Revert value-initialization back to empty parens.
3926 if (CXXScalarValueInitExpr
*VIE
= dyn_cast
<CXXScalarValueInitExpr
>(Init
)) {
3927 SourceRange Parens
= VIE
->getSourceRange();
3928 return getDerived().RebuildParenListExpr(Parens
.getBegin(), None
,
3932 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3933 if (isa
<ImplicitValueInitExpr
>(Init
))
3934 return getDerived().RebuildParenListExpr(SourceLocation(), None
,
3937 // Revert initialization by constructor back to a parenthesized or braced list
3938 // of expressions. Any other form of initializer can just be reused directly.
3939 if (!Construct
|| isa
<CXXTemporaryObjectExpr
>(Construct
))
3940 return getDerived().TransformExpr(Init
);
3942 // If the initialization implicitly converted an initializer list to a
3943 // std::initializer_list object, unwrap the std::initializer_list too.
3944 if (Construct
&& Construct
->isStdInitListInitialization())
3945 return TransformInitializer(Construct
->getArg(0), NotCopyInit
);
3947 // Enter a list-init context if this was list initialization.
3948 EnterExpressionEvaluationContext
Context(
3949 getSema(), EnterExpressionEvaluationContext::InitList
,
3950 Construct
->isListInitialization());
3952 SmallVector
<Expr
*, 8> NewArgs
;
3953 bool ArgChanged
= false;
3954 if (getDerived().TransformExprs(Construct
->getArgs(), Construct
->getNumArgs(),
3955 /*IsCall*/true, NewArgs
, &ArgChanged
))
3958 // If this was list initialization, revert to syntactic list form.
3959 if (Construct
->isListInitialization())
3960 return getDerived().RebuildInitList(Construct
->getBeginLoc(), NewArgs
,
3961 Construct
->getEndLoc());
3963 // Build a ParenListExpr to represent anything else.
3964 SourceRange Parens
= Construct
->getParenOrBraceRange();
3965 if (Parens
.isInvalid()) {
3966 // This was a variable declaration's initialization for which no initializer
3968 assert(NewArgs
.empty() &&
3969 "no parens or braces but have direct init with arguments?");
3972 return getDerived().RebuildParenListExpr(Parens
.getBegin(), NewArgs
,
3976 template<typename Derived
>
3977 bool TreeTransform
<Derived
>::TransformExprs(Expr
*const *Inputs
,
3980 SmallVectorImpl
<Expr
*> &Outputs
,
3982 for (unsigned I
= 0; I
!= NumInputs
; ++I
) {
3983 // If requested, drop call arguments that need to be dropped.
3984 if (IsCall
&& getDerived().DropCallArgument(Inputs
[I
])) {
3991 if (PackExpansionExpr
*Expansion
= dyn_cast
<PackExpansionExpr
>(Inputs
[I
])) {
3992 Expr
*Pattern
= Expansion
->getPattern();
3994 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
3995 getSema().collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
3996 assert(!Unexpanded
.empty() && "Pack expansion without parameter packs?");
3998 // Determine whether the set of unexpanded parameter packs can and should
4001 bool RetainExpansion
= false;
4002 Optional
<unsigned> OrigNumExpansions
= Expansion
->getNumExpansions();
4003 Optional
<unsigned> NumExpansions
= OrigNumExpansions
;
4004 if (getDerived().TryExpandParameterPacks(Expansion
->getEllipsisLoc(),
4005 Pattern
->getSourceRange(),
4007 Expand
, RetainExpansion
,
4012 // The transform has determined that we should perform a simple
4013 // transformation on the pack expansion, producing another pack
4015 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
4016 ExprResult OutPattern
= getDerived().TransformExpr(Pattern
);
4017 if (OutPattern
.isInvalid())
4020 ExprResult Out
= getDerived().RebuildPackExpansion(OutPattern
.get(),
4021 Expansion
->getEllipsisLoc(),
4023 if (Out
.isInvalid())
4028 Outputs
.push_back(Out
.get());
4032 // Record right away that the argument was changed. This needs
4033 // to happen even if the array expands to nothing.
4034 if (ArgChanged
) *ArgChanged
= true;
4036 // The transform has determined that we should perform an elementwise
4037 // expansion of the pattern. Do so.
4038 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
4039 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
4040 ExprResult Out
= getDerived().TransformExpr(Pattern
);
4041 if (Out
.isInvalid())
4044 if (Out
.get()->containsUnexpandedParameterPack()) {
4045 Out
= getDerived().RebuildPackExpansion(
4046 Out
.get(), Expansion
->getEllipsisLoc(), OrigNumExpansions
);
4047 if (Out
.isInvalid())
4051 Outputs
.push_back(Out
.get());
4054 // If we're supposed to retain a pack expansion, do so by temporarily
4055 // forgetting the partially-substituted parameter pack.
4056 if (RetainExpansion
) {
4057 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
4059 ExprResult Out
= getDerived().TransformExpr(Pattern
);
4060 if (Out
.isInvalid())
4063 Out
= getDerived().RebuildPackExpansion(
4064 Out
.get(), Expansion
->getEllipsisLoc(), OrigNumExpansions
);
4065 if (Out
.isInvalid())
4068 Outputs
.push_back(Out
.get());
4075 IsCall
? getDerived().TransformInitializer(Inputs
[I
], /*DirectInit*/false)
4076 : getDerived().TransformExpr(Inputs
[I
]);
4077 if (Result
.isInvalid())
4080 if (Result
.get() != Inputs
[I
] && ArgChanged
)
4083 Outputs
.push_back(Result
.get());
4089 template <typename Derived
>
4090 Sema::ConditionResult TreeTransform
<Derived
>::TransformCondition(
4091 SourceLocation Loc
, VarDecl
*Var
, Expr
*Expr
, Sema::ConditionKind Kind
) {
4093 VarDecl
*ConditionVar
= cast_or_null
<VarDecl
>(
4094 getDerived().TransformDefinition(Var
->getLocation(), Var
));
4097 return Sema::ConditionError();
4099 return getSema().ActOnConditionVariable(ConditionVar
, Loc
, Kind
);
4103 ExprResult CondExpr
= getDerived().TransformExpr(Expr
);
4105 if (CondExpr
.isInvalid())
4106 return Sema::ConditionError();
4108 return getSema().ActOnCondition(nullptr, Loc
, CondExpr
.get(), Kind
,
4109 /*MissingOK=*/true);
4112 return Sema::ConditionResult();
4115 template <typename Derived
>
4116 NestedNameSpecifierLoc TreeTransform
<Derived
>::TransformNestedNameSpecifierLoc(
4117 NestedNameSpecifierLoc NNS
, QualType ObjectType
,
4118 NamedDecl
*FirstQualifierInScope
) {
4119 SmallVector
<NestedNameSpecifierLoc
, 4> Qualifiers
;
4120 for (NestedNameSpecifierLoc Qualifier
= NNS
; Qualifier
;
4121 Qualifier
= Qualifier
.getPrefix())
4122 Qualifiers
.push_back(Qualifier
);
4125 while (!Qualifiers
.empty()) {
4126 NestedNameSpecifierLoc Q
= Qualifiers
.pop_back_val();
4127 NestedNameSpecifier
*QNNS
= Q
.getNestedNameSpecifier();
4129 switch (QNNS
->getKind()) {
4130 case NestedNameSpecifier::Identifier
: {
4131 Sema::NestedNameSpecInfo
IdInfo(QNNS
->getAsIdentifier(),
4132 Q
.getLocalBeginLoc(), Q
.getLocalEndLoc(),
4134 if (SemaRef
.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo
, false,
4135 SS
, FirstQualifierInScope
, false))
4136 return NestedNameSpecifierLoc();
4140 case NestedNameSpecifier::Namespace
: {
4142 cast_or_null
<NamespaceDecl
>(getDerived().TransformDecl(
4143 Q
.getLocalBeginLoc(), QNNS
->getAsNamespace()));
4144 SS
.Extend(SemaRef
.Context
, NS
, Q
.getLocalBeginLoc(), Q
.getLocalEndLoc());
4148 case NestedNameSpecifier::NamespaceAlias
: {
4149 NamespaceAliasDecl
*Alias
=
4150 cast_or_null
<NamespaceAliasDecl
>(getDerived().TransformDecl(
4151 Q
.getLocalBeginLoc(), QNNS
->getAsNamespaceAlias()));
4152 SS
.Extend(SemaRef
.Context
, Alias
, Q
.getLocalBeginLoc(),
4153 Q
.getLocalEndLoc());
4157 case NestedNameSpecifier::Global
:
4158 // There is no meaningful transformation that one could perform on the
4160 SS
.MakeGlobal(SemaRef
.Context
, Q
.getBeginLoc());
4163 case NestedNameSpecifier::Super
: {
4165 cast_or_null
<CXXRecordDecl
>(getDerived().TransformDecl(
4166 SourceLocation(), QNNS
->getAsRecordDecl()));
4167 SS
.MakeSuper(SemaRef
.Context
, RD
, Q
.getBeginLoc(), Q
.getEndLoc());
4171 case NestedNameSpecifier::TypeSpecWithTemplate
:
4172 case NestedNameSpecifier::TypeSpec
: {
4173 TypeLoc TL
= TransformTypeInObjectScope(Q
.getTypeLoc(), ObjectType
,
4174 FirstQualifierInScope
, SS
);
4177 return NestedNameSpecifierLoc();
4179 if (TL
.getType()->isDependentType() || TL
.getType()->isRecordType() ||
4180 (SemaRef
.getLangOpts().CPlusPlus11
&&
4181 TL
.getType()->isEnumeralType())) {
4182 assert(!TL
.getType().hasLocalQualifiers() &&
4183 "Can't get cv-qualifiers here");
4184 if (TL
.getType()->isEnumeralType())
4185 SemaRef
.Diag(TL
.getBeginLoc(),
4186 diag::warn_cxx98_compat_enum_nested_name_spec
);
4187 SS
.Extend(SemaRef
.Context
, /*FIXME:*/ SourceLocation(), TL
,
4188 Q
.getLocalEndLoc());
4191 // If the nested-name-specifier is an invalid type def, don't emit an
4192 // error because a previous error should have already been emitted.
4193 TypedefTypeLoc TTL
= TL
.getAsAdjusted
<TypedefTypeLoc
>();
4194 if (!TTL
|| !TTL
.getTypedefNameDecl()->isInvalidDecl()) {
4195 SemaRef
.Diag(TL
.getBeginLoc(), diag::err_nested_name_spec_non_tag
)
4196 << TL
.getType() << SS
.getRange();
4198 return NestedNameSpecifierLoc();
4202 // The qualifier-in-scope and object type only apply to the leftmost entity.
4203 FirstQualifierInScope
= nullptr;
4204 ObjectType
= QualType();
4207 // Don't rebuild the nested-name-specifier if we don't have to.
4208 if (SS
.getScopeRep() == NNS
.getNestedNameSpecifier() &&
4209 !getDerived().AlwaysRebuild())
4212 // If we can re-use the source-location data from the original
4213 // nested-name-specifier, do so.
4214 if (SS
.location_size() == NNS
.getDataLength() &&
4215 memcmp(SS
.location_data(), NNS
.getOpaqueData(), SS
.location_size()) == 0)
4216 return NestedNameSpecifierLoc(SS
.getScopeRep(), NNS
.getOpaqueData());
4218 // Allocate new nested-name-specifier location information.
4219 return SS
.getWithLocInContext(SemaRef
.Context
);
4222 template<typename Derived
>
4224 TreeTransform
<Derived
>
4225 ::TransformDeclarationNameInfo(const DeclarationNameInfo
&NameInfo
) {
4226 DeclarationName Name
= NameInfo
.getName();
4228 return DeclarationNameInfo();
4230 switch (Name
.getNameKind()) {
4231 case DeclarationName::Identifier
:
4232 case DeclarationName::ObjCZeroArgSelector
:
4233 case DeclarationName::ObjCOneArgSelector
:
4234 case DeclarationName::ObjCMultiArgSelector
:
4235 case DeclarationName::CXXOperatorName
:
4236 case DeclarationName::CXXLiteralOperatorName
:
4237 case DeclarationName::CXXUsingDirective
:
4240 case DeclarationName::CXXDeductionGuideName
: {
4241 TemplateDecl
*OldTemplate
= Name
.getCXXDeductionGuideTemplate();
4242 TemplateDecl
*NewTemplate
= cast_or_null
<TemplateDecl
>(
4243 getDerived().TransformDecl(NameInfo
.getLoc(), OldTemplate
));
4245 return DeclarationNameInfo();
4247 DeclarationNameInfo
NewNameInfo(NameInfo
);
4248 NewNameInfo
.setName(
4249 SemaRef
.Context
.DeclarationNames
.getCXXDeductionGuideName(NewTemplate
));
4253 case DeclarationName::CXXConstructorName
:
4254 case DeclarationName::CXXDestructorName
:
4255 case DeclarationName::CXXConversionFunctionName
: {
4256 TypeSourceInfo
*NewTInfo
;
4257 CanQualType NewCanTy
;
4258 if (TypeSourceInfo
*OldTInfo
= NameInfo
.getNamedTypeInfo()) {
4259 NewTInfo
= getDerived().TransformType(OldTInfo
);
4261 return DeclarationNameInfo();
4262 NewCanTy
= SemaRef
.Context
.getCanonicalType(NewTInfo
->getType());
4266 TemporaryBase
Rebase(*this, NameInfo
.getLoc(), Name
);
4267 QualType NewT
= getDerived().TransformType(Name
.getCXXNameType());
4269 return DeclarationNameInfo();
4270 NewCanTy
= SemaRef
.Context
.getCanonicalType(NewT
);
4273 DeclarationName NewName
4274 = SemaRef
.Context
.DeclarationNames
.getCXXSpecialName(Name
.getNameKind(),
4276 DeclarationNameInfo
NewNameInfo(NameInfo
);
4277 NewNameInfo
.setName(NewName
);
4278 NewNameInfo
.setNamedTypeInfo(NewTInfo
);
4283 llvm_unreachable("Unknown name kind.");
4286 template<typename Derived
>
4288 TreeTransform
<Derived
>::TransformTemplateName(CXXScopeSpec
&SS
,
4290 SourceLocation NameLoc
,
4291 QualType ObjectType
,
4292 NamedDecl
*FirstQualifierInScope
,
4293 bool AllowInjectedClassName
) {
4294 if (QualifiedTemplateName
*QTN
= Name
.getAsQualifiedTemplateName()) {
4295 TemplateDecl
*Template
= QTN
->getUnderlyingTemplate().getAsTemplateDecl();
4296 assert(Template
&& "qualified template name must refer to a template");
4298 TemplateDecl
*TransTemplate
4299 = cast_or_null
<TemplateDecl
>(getDerived().TransformDecl(NameLoc
,
4302 return TemplateName();
4304 if (!getDerived().AlwaysRebuild() &&
4305 SS
.getScopeRep() == QTN
->getQualifier() &&
4306 TransTemplate
== Template
)
4309 return getDerived().RebuildTemplateName(SS
, QTN
->hasTemplateKeyword(),
4313 if (DependentTemplateName
*DTN
= Name
.getAsDependentTemplateName()) {
4314 if (SS
.getScopeRep()) {
4315 // These apply to the scope specifier, not the template.
4316 ObjectType
= QualType();
4317 FirstQualifierInScope
= nullptr;
4320 if (!getDerived().AlwaysRebuild() &&
4321 SS
.getScopeRep() == DTN
->getQualifier() &&
4322 ObjectType
.isNull())
4325 // FIXME: Preserve the location of the "template" keyword.
4326 SourceLocation TemplateKWLoc
= NameLoc
;
4328 if (DTN
->isIdentifier()) {
4329 return getDerived().RebuildTemplateName(SS
,
4331 *DTN
->getIdentifier(),
4334 FirstQualifierInScope
,
4335 AllowInjectedClassName
);
4338 return getDerived().RebuildTemplateName(SS
, TemplateKWLoc
,
4339 DTN
->getOperator(), NameLoc
,
4340 ObjectType
, AllowInjectedClassName
);
4343 if (TemplateDecl
*Template
= Name
.getAsTemplateDecl()) {
4344 TemplateDecl
*TransTemplate
4345 = cast_or_null
<TemplateDecl
>(getDerived().TransformDecl(NameLoc
,
4348 return TemplateName();
4350 if (!getDerived().AlwaysRebuild() &&
4351 TransTemplate
== Template
)
4354 return TemplateName(TransTemplate
);
4357 if (SubstTemplateTemplateParmPackStorage
*SubstPack
4358 = Name
.getAsSubstTemplateTemplateParmPack()) {
4359 TemplateTemplateParmDecl
*TransParam
4360 = cast_or_null
<TemplateTemplateParmDecl
>(
4361 getDerived().TransformDecl(NameLoc
, SubstPack
->getParameterPack()));
4363 return TemplateName();
4365 if (!getDerived().AlwaysRebuild() &&
4366 TransParam
== SubstPack
->getParameterPack())
4369 return getDerived().RebuildTemplateName(TransParam
,
4370 SubstPack
->getArgumentPack());
4373 // These should be getting filtered out before they reach the AST.
4374 llvm_unreachable("overloaded function decl survived to here");
4377 template<typename Derived
>
4378 void TreeTransform
<Derived
>::InventTemplateArgumentLoc(
4379 const TemplateArgument
&Arg
,
4380 TemplateArgumentLoc
&Output
) {
4381 Output
= getSema().getTrivialTemplateArgumentLoc(
4382 Arg
, QualType(), getDerived().getBaseLocation());
4385 template <typename Derived
>
4386 bool TreeTransform
<Derived
>::TransformTemplateArgument(
4387 const TemplateArgumentLoc
&Input
, TemplateArgumentLoc
&Output
,
4389 const TemplateArgument
&Arg
= Input
.getArgument();
4390 switch (Arg
.getKind()) {
4391 case TemplateArgument::Null
:
4392 case TemplateArgument::Pack
:
4393 llvm_unreachable("Unexpected TemplateArgument");
4395 case TemplateArgument::Integral
:
4396 case TemplateArgument::NullPtr
:
4397 case TemplateArgument::Declaration
: {
4398 // Transform a resolved template argument straight to a resolved template
4399 // argument. We get here when substituting into an already-substituted
4400 // template type argument during concept satisfaction checking.
4401 QualType T
= Arg
.getNonTypeTemplateArgumentType();
4402 QualType NewT
= getDerived().TransformType(T
);
4406 ValueDecl
*D
= Arg
.getKind() == TemplateArgument::Declaration
4409 ValueDecl
*NewD
= D
? cast_or_null
<ValueDecl
>(getDerived().TransformDecl(
4410 getDerived().getBaseLocation(), D
))
4415 if (NewT
== T
&& D
== NewD
)
4417 else if (Arg
.getKind() == TemplateArgument::Integral
)
4418 Output
= TemplateArgumentLoc(
4419 TemplateArgument(getSema().Context
, Arg
.getAsIntegral(), NewT
),
4420 TemplateArgumentLocInfo());
4421 else if (Arg
.getKind() == TemplateArgument::NullPtr
)
4422 Output
= TemplateArgumentLoc(TemplateArgument(NewT
, /*IsNullPtr=*/true),
4423 TemplateArgumentLocInfo());
4425 Output
= TemplateArgumentLoc(TemplateArgument(NewD
, NewT
),
4426 TemplateArgumentLocInfo());
4431 case TemplateArgument::Type
: {
4432 TypeSourceInfo
*DI
= Input
.getTypeSourceInfo();
4434 DI
= InventTypeSourceInfo(Input
.getArgument().getAsType());
4436 DI
= getDerived().TransformType(DI
);
4440 Output
= TemplateArgumentLoc(TemplateArgument(DI
->getType()), DI
);
4444 case TemplateArgument::Template
: {
4445 NestedNameSpecifierLoc QualifierLoc
= Input
.getTemplateQualifierLoc();
4447 QualifierLoc
= getDerived().TransformNestedNameSpecifierLoc(QualifierLoc
);
4453 SS
.Adopt(QualifierLoc
);
4454 TemplateName Template
= getDerived().TransformTemplateName(
4455 SS
, Arg
.getAsTemplate(), Input
.getTemplateNameLoc());
4456 if (Template
.isNull())
4459 Output
= TemplateArgumentLoc(SemaRef
.Context
, TemplateArgument(Template
),
4460 QualifierLoc
, Input
.getTemplateNameLoc());
4464 case TemplateArgument::TemplateExpansion
:
4465 llvm_unreachable("Caller should expand pack expansions");
4467 case TemplateArgument::Expression
: {
4468 // Template argument expressions are constant expressions.
4469 EnterExpressionEvaluationContext
Unevaluated(
4471 Uneval
? Sema::ExpressionEvaluationContext::Unevaluated
4472 : Sema::ExpressionEvaluationContext::ConstantEvaluated
,
4473 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
4474 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument
);
4476 Expr
*InputExpr
= Input
.getSourceExpression();
4478 InputExpr
= Input
.getArgument().getAsExpr();
4480 ExprResult E
= getDerived().TransformExpr(InputExpr
);
4481 E
= SemaRef
.ActOnConstantExpression(E
);
4484 Output
= TemplateArgumentLoc(TemplateArgument(E
.get()), E
.get());
4489 // Work around bogus GCC warning
4493 /// Iterator adaptor that invents template argument location information
4494 /// for each of the template arguments in its underlying iterator.
4495 template<typename Derived
, typename InputIterator
>
4496 class TemplateArgumentLocInventIterator
{
4497 TreeTransform
<Derived
> &Self
;
4501 typedef TemplateArgumentLoc value_type
;
4502 typedef TemplateArgumentLoc reference
;
4503 typedef typename
std::iterator_traits
<InputIterator
>::difference_type
4505 typedef std::input_iterator_tag iterator_category
;
4508 TemplateArgumentLoc Arg
;
4511 explicit pointer(TemplateArgumentLoc Arg
) : Arg(Arg
) { }
4513 const TemplateArgumentLoc
*operator->() const { return &Arg
; }
4516 TemplateArgumentLocInventIterator() { }
4518 explicit TemplateArgumentLocInventIterator(TreeTransform
<Derived
> &Self
,
4520 : Self(Self
), Iter(Iter
) { }
4522 TemplateArgumentLocInventIterator
&operator++() {
4527 TemplateArgumentLocInventIterator
operator++(int) {
4528 TemplateArgumentLocInventIterator
Old(*this);
4533 reference
operator*() const {
4534 TemplateArgumentLoc Result
;
4535 Self
.InventTemplateArgumentLoc(*Iter
, Result
);
4539 pointer
operator->() const { return pointer(**this); }
4541 friend bool operator==(const TemplateArgumentLocInventIterator
&X
,
4542 const TemplateArgumentLocInventIterator
&Y
) {
4543 return X
.Iter
== Y
.Iter
;
4546 friend bool operator!=(const TemplateArgumentLocInventIterator
&X
,
4547 const TemplateArgumentLocInventIterator
&Y
) {
4548 return X
.Iter
!= Y
.Iter
;
4552 template<typename Derived
>
4553 template<typename InputIterator
>
4554 bool TreeTransform
<Derived
>::TransformTemplateArguments(
4555 InputIterator First
, InputIterator Last
, TemplateArgumentListInfo
&Outputs
,
4557 for (; First
!= Last
; ++First
) {
4558 TemplateArgumentLoc Out
;
4559 TemplateArgumentLoc In
= *First
;
4561 if (In
.getArgument().getKind() == TemplateArgument::Pack
) {
4562 // Unpack argument packs, which we translate them into separate
4564 // FIXME: We could do much better if we could guarantee that the
4565 // TemplateArgumentLocInfo for the pack expansion would be usable for
4566 // all of the template arguments in the argument pack.
4567 typedef TemplateArgumentLocInventIterator
<Derived
,
4568 TemplateArgument::pack_iterator
>
4570 if (TransformTemplateArguments(PackLocIterator(*this,
4571 In
.getArgument().pack_begin()),
4572 PackLocIterator(*this,
4573 In
.getArgument().pack_end()),
4580 if (In
.getArgument().isPackExpansion()) {
4581 // We have a pack expansion, for which we will be substituting into
4583 SourceLocation Ellipsis
;
4584 Optional
<unsigned> OrigNumExpansions
;
4585 TemplateArgumentLoc Pattern
4586 = getSema().getTemplateArgumentPackExpansionPattern(
4587 In
, Ellipsis
, OrigNumExpansions
);
4589 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
4590 getSema().collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
4591 assert(!Unexpanded
.empty() && "Pack expansion without parameter packs?");
4593 // Determine whether the set of unexpanded parameter packs can and should
4596 bool RetainExpansion
= false;
4597 Optional
<unsigned> NumExpansions
= OrigNumExpansions
;
4598 if (getDerived().TryExpandParameterPacks(Ellipsis
,
4599 Pattern
.getSourceRange(),
4607 // The transform has determined that we should perform a simple
4608 // transformation on the pack expansion, producing another pack
4610 TemplateArgumentLoc OutPattern
;
4611 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
4612 if (getDerived().TransformTemplateArgument(Pattern
, OutPattern
, Uneval
))
4615 Out
= getDerived().RebuildPackExpansion(OutPattern
, Ellipsis
,
4617 if (Out
.getArgument().isNull())
4620 Outputs
.addArgument(Out
);
4624 // The transform has determined that we should perform an elementwise
4625 // expansion of the pattern. Do so.
4626 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
4627 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
4629 if (getDerived().TransformTemplateArgument(Pattern
, Out
, Uneval
))
4632 if (Out
.getArgument().containsUnexpandedParameterPack()) {
4633 Out
= getDerived().RebuildPackExpansion(Out
, Ellipsis
,
4635 if (Out
.getArgument().isNull())
4639 Outputs
.addArgument(Out
);
4642 // If we're supposed to retain a pack expansion, do so by temporarily
4643 // forgetting the partially-substituted parameter pack.
4644 if (RetainExpansion
) {
4645 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
4647 if (getDerived().TransformTemplateArgument(Pattern
, Out
, Uneval
))
4650 Out
= getDerived().RebuildPackExpansion(Out
, Ellipsis
,
4652 if (Out
.getArgument().isNull())
4655 Outputs
.addArgument(Out
);
4662 if (getDerived().TransformTemplateArgument(In
, Out
, Uneval
))
4665 Outputs
.addArgument(Out
);
4672 //===----------------------------------------------------------------------===//
4673 // Type transformation
4674 //===----------------------------------------------------------------------===//
4676 template<typename Derived
>
4677 QualType TreeTransform
<Derived
>::TransformType(QualType T
) {
4678 if (getDerived().AlreadyTransformed(T
))
4681 // Temporary workaround. All of these transformations should
4682 // eventually turn into transformations on TypeLocs.
4683 TypeSourceInfo
*DI
= getSema().Context
.getTrivialTypeSourceInfo(T
,
4684 getDerived().getBaseLocation());
4686 TypeSourceInfo
*NewDI
= getDerived().TransformType(DI
);
4691 return NewDI
->getType();
4694 template<typename Derived
>
4695 TypeSourceInfo
*TreeTransform
<Derived
>::TransformType(TypeSourceInfo
*DI
) {
4696 // Refine the base location to the type's location.
4697 TemporaryBase
Rebase(*this, DI
->getTypeLoc().getBeginLoc(),
4698 getDerived().getBaseEntity());
4699 if (getDerived().AlreadyTransformed(DI
->getType()))
4704 TypeLoc TL
= DI
->getTypeLoc();
4705 TLB
.reserve(TL
.getFullDataSize());
4707 QualType Result
= getDerived().TransformType(TLB
, TL
);
4708 if (Result
.isNull())
4711 return TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
4714 template<typename Derived
>
4716 TreeTransform
<Derived
>::TransformType(TypeLocBuilder
&TLB
, TypeLoc T
) {
4717 switch (T
.getTypeLocClass()) {
4718 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4719 #define TYPELOC(CLASS, PARENT) \
4720 case TypeLoc::CLASS: \
4721 return getDerived().Transform##CLASS##Type(TLB, \
4722 T.castAs<CLASS##TypeLoc>());
4723 #include "clang/AST/TypeLocNodes.def"
4726 llvm_unreachable("unhandled type loc!");
4729 template<typename Derived
>
4730 QualType TreeTransform
<Derived
>::TransformTypeWithDeducedTST(QualType T
) {
4731 if (!isa
<DependentNameType
>(T
))
4732 return TransformType(T
);
4734 if (getDerived().AlreadyTransformed(T
))
4736 TypeSourceInfo
*DI
= getSema().Context
.getTrivialTypeSourceInfo(T
,
4737 getDerived().getBaseLocation());
4738 TypeSourceInfo
*NewDI
= getDerived().TransformTypeWithDeducedTST(DI
);
4739 return NewDI
? NewDI
->getType() : QualType();
4742 template<typename Derived
>
4744 TreeTransform
<Derived
>::TransformTypeWithDeducedTST(TypeSourceInfo
*DI
) {
4745 if (!isa
<DependentNameType
>(DI
->getType()))
4746 return TransformType(DI
);
4748 // Refine the base location to the type's location.
4749 TemporaryBase
Rebase(*this, DI
->getTypeLoc().getBeginLoc(),
4750 getDerived().getBaseEntity());
4751 if (getDerived().AlreadyTransformed(DI
->getType()))
4756 TypeLoc TL
= DI
->getTypeLoc();
4757 TLB
.reserve(TL
.getFullDataSize());
4759 auto QTL
= TL
.getAs
<QualifiedTypeLoc
>();
4761 TL
= QTL
.getUnqualifiedLoc();
4763 auto DNTL
= TL
.castAs
<DependentNameTypeLoc
>();
4765 QualType Result
= getDerived().TransformDependentNameType(
4766 TLB
, DNTL
, /*DeducedTSTContext*/true);
4767 if (Result
.isNull())
4771 Result
= getDerived().RebuildQualifiedType(Result
, QTL
);
4772 if (Result
.isNull())
4774 TLB
.TypeWasModifiedSafely(Result
);
4777 return TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
4780 template<typename Derived
>
4782 TreeTransform
<Derived
>::TransformQualifiedType(TypeLocBuilder
&TLB
,
4783 QualifiedTypeLoc T
) {
4784 QualType Result
= getDerived().TransformType(TLB
, T
.getUnqualifiedLoc());
4785 if (Result
.isNull())
4788 Result
= getDerived().RebuildQualifiedType(Result
, T
);
4790 if (Result
.isNull())
4793 // RebuildQualifiedType might have updated the type, but not in a way
4794 // that invalidates the TypeLoc. (There's no location information for
4796 TLB
.TypeWasModifiedSafely(Result
);
4801 template <typename Derived
>
4802 QualType TreeTransform
<Derived
>::RebuildQualifiedType(QualType T
,
4803 QualifiedTypeLoc TL
) {
4805 SourceLocation Loc
= TL
.getBeginLoc();
4806 Qualifiers Quals
= TL
.getType().getLocalQualifiers();
4808 if ((T
.getAddressSpace() != LangAS::Default
&&
4809 Quals
.getAddressSpace() != LangAS::Default
) &&
4810 T
.getAddressSpace() != Quals
.getAddressSpace()) {
4811 SemaRef
.Diag(Loc
, diag::err_address_space_mismatch_templ_inst
)
4812 << TL
.getType() << T
;
4817 // [When] adding cv-qualifications on top of the function type [...] the
4818 // cv-qualifiers are ignored.
4819 if (T
->isFunctionType()) {
4820 T
= SemaRef
.getASTContext().getAddrSpaceQualType(T
,
4821 Quals
.getAddressSpace());
4826 // when the cv-qualifiers are introduced through the use of a typedef-name
4827 // or decltype-specifier [...] the cv-qualifiers are ignored.
4828 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4829 // applied to a reference type.
4830 if (T
->isReferenceType()) {
4831 // The only qualifier that applies to a reference type is restrict.
4832 if (!Quals
.hasRestrict())
4834 Quals
= Qualifiers::fromCVRMask(Qualifiers::Restrict
);
4837 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4839 if (Quals
.hasObjCLifetime()) {
4840 if (!T
->isObjCLifetimeType() && !T
->isDependentType())
4841 Quals
.removeObjCLifetime();
4842 else if (T
.getObjCLifetime()) {
4844 // A lifetime qualifier applied to a substituted template parameter
4845 // overrides the lifetime qualifier from the template argument.
4846 const AutoType
*AutoTy
;
4847 if (const SubstTemplateTypeParmType
*SubstTypeParam
4848 = dyn_cast
<SubstTemplateTypeParmType
>(T
)) {
4849 QualType Replacement
= SubstTypeParam
->getReplacementType();
4850 Qualifiers Qs
= Replacement
.getQualifiers();
4851 Qs
.removeObjCLifetime();
4852 Replacement
= SemaRef
.Context
.getQualifiedType(
4853 Replacement
.getUnqualifiedType(), Qs
);
4854 T
= SemaRef
.Context
.getSubstTemplateTypeParmType(
4855 SubstTypeParam
->getReplacedParameter(), Replacement
,
4856 SubstTypeParam
->getPackIndex());
4857 } else if ((AutoTy
= dyn_cast
<AutoType
>(T
)) && AutoTy
->isDeduced()) {
4858 // 'auto' types behave the same way as template parameters.
4859 QualType Deduced
= AutoTy
->getDeducedType();
4860 Qualifiers Qs
= Deduced
.getQualifiers();
4861 Qs
.removeObjCLifetime();
4863 SemaRef
.Context
.getQualifiedType(Deduced
.getUnqualifiedType(), Qs
);
4864 T
= SemaRef
.Context
.getAutoType(Deduced
, AutoTy
->getKeyword(),
4865 AutoTy
->isDependentType(),
4867 AutoTy
->getTypeConstraintConcept(),
4868 AutoTy
->getTypeConstraintArguments());
4870 // Otherwise, complain about the addition of a qualifier to an
4871 // already-qualified type.
4872 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4873 SemaRef
.Diag(Loc
, diag::err_attr_objc_ownership_redundant
) << T
;
4874 Quals
.removeObjCLifetime();
4879 return SemaRef
.BuildQualifiedType(T
, Loc
, Quals
);
4882 template<typename Derived
>
4884 TreeTransform
<Derived
>::TransformTypeInObjectScope(TypeLoc TL
,
4885 QualType ObjectType
,
4886 NamedDecl
*UnqualLookup
,
4888 if (getDerived().AlreadyTransformed(TL
.getType()))
4891 TypeSourceInfo
*TSI
=
4892 TransformTSIInObjectScope(TL
, ObjectType
, UnqualLookup
, SS
);
4894 return TSI
->getTypeLoc();
4898 template<typename Derived
>
4900 TreeTransform
<Derived
>::TransformTypeInObjectScope(TypeSourceInfo
*TSInfo
,
4901 QualType ObjectType
,
4902 NamedDecl
*UnqualLookup
,
4904 if (getDerived().AlreadyTransformed(TSInfo
->getType()))
4907 return TransformTSIInObjectScope(TSInfo
->getTypeLoc(), ObjectType
,
4911 template <typename Derived
>
4912 TypeSourceInfo
*TreeTransform
<Derived
>::TransformTSIInObjectScope(
4913 TypeLoc TL
, QualType ObjectType
, NamedDecl
*UnqualLookup
,
4915 QualType T
= TL
.getType();
4916 assert(!getDerived().AlreadyTransformed(T
));
4921 if (isa
<TemplateSpecializationType
>(T
)) {
4922 TemplateSpecializationTypeLoc SpecTL
=
4923 TL
.castAs
<TemplateSpecializationTypeLoc
>();
4925 TemplateName Template
= getDerived().TransformTemplateName(
4926 SS
, SpecTL
.getTypePtr()->getTemplateName(), SpecTL
.getTemplateNameLoc(),
4927 ObjectType
, UnqualLookup
, /*AllowInjectedClassName*/true);
4928 if (Template
.isNull())
4931 Result
= getDerived().TransformTemplateSpecializationType(TLB
, SpecTL
,
4933 } else if (isa
<DependentTemplateSpecializationType
>(T
)) {
4934 DependentTemplateSpecializationTypeLoc SpecTL
=
4935 TL
.castAs
<DependentTemplateSpecializationTypeLoc
>();
4937 TemplateName Template
4938 = getDerived().RebuildTemplateName(SS
,
4939 SpecTL
.getTemplateKeywordLoc(),
4940 *SpecTL
.getTypePtr()->getIdentifier(),
4941 SpecTL
.getTemplateNameLoc(),
4942 ObjectType
, UnqualLookup
,
4943 /*AllowInjectedClassName*/true);
4944 if (Template
.isNull())
4947 Result
= getDerived().TransformDependentTemplateSpecializationType(TLB
,
4952 // Nothing special needs to be done for these.
4953 Result
= getDerived().TransformType(TLB
, TL
);
4956 if (Result
.isNull())
4959 return TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
4962 template <class TyLoc
> static inline
4963 QualType
TransformTypeSpecType(TypeLocBuilder
&TLB
, TyLoc T
) {
4964 TyLoc NewT
= TLB
.push
<TyLoc
>(T
.getType());
4965 NewT
.setNameLoc(T
.getNameLoc());
4969 template<typename Derived
>
4970 QualType TreeTransform
<Derived
>::TransformBuiltinType(TypeLocBuilder
&TLB
,
4972 BuiltinTypeLoc NewT
= TLB
.push
<BuiltinTypeLoc
>(T
.getType());
4973 NewT
.setBuiltinLoc(T
.getBuiltinLoc());
4974 if (T
.needsExtraLocalData())
4975 NewT
.getWrittenBuiltinSpecs() = T
.getWrittenBuiltinSpecs();
4979 template<typename Derived
>
4980 QualType TreeTransform
<Derived
>::TransformComplexType(TypeLocBuilder
&TLB
,
4983 return TransformTypeSpecType(TLB
, T
);
4986 template <typename Derived
>
4987 QualType TreeTransform
<Derived
>::TransformAdjustedType(TypeLocBuilder
&TLB
,
4988 AdjustedTypeLoc TL
) {
4989 // Adjustments applied during transformation are handled elsewhere.
4990 return getDerived().TransformType(TLB
, TL
.getOriginalLoc());
4993 template<typename Derived
>
4994 QualType TreeTransform
<Derived
>::TransformDecayedType(TypeLocBuilder
&TLB
,
4995 DecayedTypeLoc TL
) {
4996 QualType OriginalType
= getDerived().TransformType(TLB
, TL
.getOriginalLoc());
4997 if (OriginalType
.isNull())
5000 QualType Result
= TL
.getType();
5001 if (getDerived().AlwaysRebuild() ||
5002 OriginalType
!= TL
.getOriginalLoc().getType())
5003 Result
= SemaRef
.Context
.getDecayedType(OriginalType
);
5004 TLB
.push
<DecayedTypeLoc
>(Result
);
5005 // Nothing to set for DecayedTypeLoc.
5009 template<typename Derived
>
5010 QualType TreeTransform
<Derived
>::TransformPointerType(TypeLocBuilder
&TLB
,
5011 PointerTypeLoc TL
) {
5012 QualType PointeeType
5013 = getDerived().TransformType(TLB
, TL
.getPointeeLoc());
5014 if (PointeeType
.isNull())
5017 QualType Result
= TL
.getType();
5018 if (PointeeType
->getAs
<ObjCObjectType
>()) {
5019 // A dependent pointer type 'T *' has is being transformed such
5020 // that an Objective-C class type is being replaced for 'T'. The
5021 // resulting pointer type is an ObjCObjectPointerType, not a
5023 Result
= SemaRef
.Context
.getObjCObjectPointerType(PointeeType
);
5025 ObjCObjectPointerTypeLoc NewT
= TLB
.push
<ObjCObjectPointerTypeLoc
>(Result
);
5026 NewT
.setStarLoc(TL
.getStarLoc());
5030 if (getDerived().AlwaysRebuild() ||
5031 PointeeType
!= TL
.getPointeeLoc().getType()) {
5032 Result
= getDerived().RebuildPointerType(PointeeType
, TL
.getSigilLoc());
5033 if (Result
.isNull())
5037 // Objective-C ARC can add lifetime qualifiers to the type that we're
5039 TLB
.TypeWasModifiedSafely(Result
->getPointeeType());
5041 PointerTypeLoc NewT
= TLB
.push
<PointerTypeLoc
>(Result
);
5042 NewT
.setSigilLoc(TL
.getSigilLoc());
5046 template<typename Derived
>
5048 TreeTransform
<Derived
>::TransformBlockPointerType(TypeLocBuilder
&TLB
,
5049 BlockPointerTypeLoc TL
) {
5050 QualType PointeeType
5051 = getDerived().TransformType(TLB
, TL
.getPointeeLoc());
5052 if (PointeeType
.isNull())
5055 QualType Result
= TL
.getType();
5056 if (getDerived().AlwaysRebuild() ||
5057 PointeeType
!= TL
.getPointeeLoc().getType()) {
5058 Result
= getDerived().RebuildBlockPointerType(PointeeType
,
5060 if (Result
.isNull())
5064 BlockPointerTypeLoc NewT
= TLB
.push
<BlockPointerTypeLoc
>(Result
);
5065 NewT
.setSigilLoc(TL
.getSigilLoc());
5069 /// Transforms a reference type. Note that somewhat paradoxically we
5070 /// don't care whether the type itself is an l-value type or an r-value
5071 /// type; we only care if the type was *written* as an l-value type
5072 /// or an r-value type.
5073 template<typename Derived
>
5075 TreeTransform
<Derived
>::TransformReferenceType(TypeLocBuilder
&TLB
,
5076 ReferenceTypeLoc TL
) {
5077 const ReferenceType
*T
= TL
.getTypePtr();
5079 // Note that this works with the pointee-as-written.
5080 QualType PointeeType
= getDerived().TransformType(TLB
, TL
.getPointeeLoc());
5081 if (PointeeType
.isNull())
5084 QualType Result
= TL
.getType();
5085 if (getDerived().AlwaysRebuild() ||
5086 PointeeType
!= T
->getPointeeTypeAsWritten()) {
5087 Result
= getDerived().RebuildReferenceType(PointeeType
,
5088 T
->isSpelledAsLValue(),
5090 if (Result
.isNull())
5094 // Objective-C ARC can add lifetime qualifiers to the type that we're
5096 TLB
.TypeWasModifiedSafely(
5097 Result
->castAs
<ReferenceType
>()->getPointeeTypeAsWritten());
5099 // r-value references can be rebuilt as l-value references.
5100 ReferenceTypeLoc NewTL
;
5101 if (isa
<LValueReferenceType
>(Result
))
5102 NewTL
= TLB
.push
<LValueReferenceTypeLoc
>(Result
);
5104 NewTL
= TLB
.push
<RValueReferenceTypeLoc
>(Result
);
5105 NewTL
.setSigilLoc(TL
.getSigilLoc());
5110 template<typename Derived
>
5112 TreeTransform
<Derived
>::TransformLValueReferenceType(TypeLocBuilder
&TLB
,
5113 LValueReferenceTypeLoc TL
) {
5114 return TransformReferenceType(TLB
, TL
);
5117 template<typename Derived
>
5119 TreeTransform
<Derived
>::TransformRValueReferenceType(TypeLocBuilder
&TLB
,
5120 RValueReferenceTypeLoc TL
) {
5121 return TransformReferenceType(TLB
, TL
);
5124 template<typename Derived
>
5126 TreeTransform
<Derived
>::TransformMemberPointerType(TypeLocBuilder
&TLB
,
5127 MemberPointerTypeLoc TL
) {
5128 QualType PointeeType
= getDerived().TransformType(TLB
, TL
.getPointeeLoc());
5129 if (PointeeType
.isNull())
5132 TypeSourceInfo
* OldClsTInfo
= TL
.getClassTInfo();
5133 TypeSourceInfo
*NewClsTInfo
= nullptr;
5135 NewClsTInfo
= getDerived().TransformType(OldClsTInfo
);
5140 const MemberPointerType
*T
= TL
.getTypePtr();
5141 QualType OldClsType
= QualType(T
->getClass(), 0);
5142 QualType NewClsType
;
5144 NewClsType
= NewClsTInfo
->getType();
5146 NewClsType
= getDerived().TransformType(OldClsType
);
5147 if (NewClsType
.isNull())
5151 QualType Result
= TL
.getType();
5152 if (getDerived().AlwaysRebuild() ||
5153 PointeeType
!= T
->getPointeeType() ||
5154 NewClsType
!= OldClsType
) {
5155 Result
= getDerived().RebuildMemberPointerType(PointeeType
, NewClsType
,
5157 if (Result
.isNull())
5161 // If we had to adjust the pointee type when building a member pointer, make
5162 // sure to push TypeLoc info for it.
5163 const MemberPointerType
*MPT
= Result
->getAs
<MemberPointerType
>();
5164 if (MPT
&& PointeeType
!= MPT
->getPointeeType()) {
5165 assert(isa
<AdjustedType
>(MPT
->getPointeeType()));
5166 TLB
.push
<AdjustedTypeLoc
>(MPT
->getPointeeType());
5169 MemberPointerTypeLoc NewTL
= TLB
.push
<MemberPointerTypeLoc
>(Result
);
5170 NewTL
.setSigilLoc(TL
.getSigilLoc());
5171 NewTL
.setClassTInfo(NewClsTInfo
);
5176 template<typename Derived
>
5178 TreeTransform
<Derived
>::TransformConstantArrayType(TypeLocBuilder
&TLB
,
5179 ConstantArrayTypeLoc TL
) {
5180 const ConstantArrayType
*T
= TL
.getTypePtr();
5181 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
5182 if (ElementType
.isNull())
5185 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5186 Expr
*OldSize
= TL
.getSizeExpr();
5188 OldSize
= const_cast<Expr
*>(T
->getSizeExpr());
5189 Expr
*NewSize
= nullptr;
5191 EnterExpressionEvaluationContext
Unevaluated(
5192 SemaRef
, Sema::ExpressionEvaluationContext::ConstantEvaluated
);
5193 NewSize
= getDerived().TransformExpr(OldSize
).template getAs
<Expr
>();
5194 NewSize
= SemaRef
.ActOnConstantExpression(NewSize
).get();
5197 QualType Result
= TL
.getType();
5198 if (getDerived().AlwaysRebuild() ||
5199 ElementType
!= T
->getElementType() ||
5200 (T
->getSizeExpr() && NewSize
!= OldSize
)) {
5201 Result
= getDerived().RebuildConstantArrayType(ElementType
,
5202 T
->getSizeModifier(),
5203 T
->getSize(), NewSize
,
5204 T
->getIndexTypeCVRQualifiers(),
5205 TL
.getBracketsRange());
5206 if (Result
.isNull())
5210 // We might have either a ConstantArrayType or a VariableArrayType now:
5211 // a ConstantArrayType is allowed to have an element type which is a
5212 // VariableArrayType if the type is dependent. Fortunately, all array
5213 // types have the same location layout.
5214 ArrayTypeLoc NewTL
= TLB
.push
<ArrayTypeLoc
>(Result
);
5215 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
5216 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
5217 NewTL
.setSizeExpr(NewSize
);
5222 template<typename Derived
>
5223 QualType TreeTransform
<Derived
>::TransformIncompleteArrayType(
5224 TypeLocBuilder
&TLB
,
5225 IncompleteArrayTypeLoc TL
) {
5226 const IncompleteArrayType
*T
= TL
.getTypePtr();
5227 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
5228 if (ElementType
.isNull())
5231 QualType Result
= TL
.getType();
5232 if (getDerived().AlwaysRebuild() ||
5233 ElementType
!= T
->getElementType()) {
5234 Result
= getDerived().RebuildIncompleteArrayType(ElementType
,
5235 T
->getSizeModifier(),
5236 T
->getIndexTypeCVRQualifiers(),
5237 TL
.getBracketsRange());
5238 if (Result
.isNull())
5242 IncompleteArrayTypeLoc NewTL
= TLB
.push
<IncompleteArrayTypeLoc
>(Result
);
5243 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
5244 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
5245 NewTL
.setSizeExpr(nullptr);
5250 template<typename Derived
>
5252 TreeTransform
<Derived
>::TransformVariableArrayType(TypeLocBuilder
&TLB
,
5253 VariableArrayTypeLoc TL
) {
5254 const VariableArrayType
*T
= TL
.getTypePtr();
5255 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
5256 if (ElementType
.isNull())
5259 ExprResult SizeResult
;
5261 EnterExpressionEvaluationContext
Context(
5262 SemaRef
, Sema::ExpressionEvaluationContext::PotentiallyEvaluated
);
5263 SizeResult
= getDerived().TransformExpr(T
->getSizeExpr());
5265 if (SizeResult
.isInvalid())
5268 SemaRef
.ActOnFinishFullExpr(SizeResult
.get(), /*DiscardedValue*/ false);
5269 if (SizeResult
.isInvalid())
5272 Expr
*Size
= SizeResult
.get();
5274 QualType Result
= TL
.getType();
5275 if (getDerived().AlwaysRebuild() ||
5276 ElementType
!= T
->getElementType() ||
5277 Size
!= T
->getSizeExpr()) {
5278 Result
= getDerived().RebuildVariableArrayType(ElementType
,
5279 T
->getSizeModifier(),
5281 T
->getIndexTypeCVRQualifiers(),
5282 TL
.getBracketsRange());
5283 if (Result
.isNull())
5287 // We might have constant size array now, but fortunately it has the same
5289 ArrayTypeLoc NewTL
= TLB
.push
<ArrayTypeLoc
>(Result
);
5290 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
5291 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
5292 NewTL
.setSizeExpr(Size
);
5297 template<typename Derived
>
5299 TreeTransform
<Derived
>::TransformDependentSizedArrayType(TypeLocBuilder
&TLB
,
5300 DependentSizedArrayTypeLoc TL
) {
5301 const DependentSizedArrayType
*T
= TL
.getTypePtr();
5302 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
5303 if (ElementType
.isNull())
5306 // Array bounds are constant expressions.
5307 EnterExpressionEvaluationContext
Unevaluated(
5308 SemaRef
, Sema::ExpressionEvaluationContext::ConstantEvaluated
);
5310 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5311 Expr
*origSize
= TL
.getSizeExpr();
5312 if (!origSize
) origSize
= T
->getSizeExpr();
5314 ExprResult sizeResult
5315 = getDerived().TransformExpr(origSize
);
5316 sizeResult
= SemaRef
.ActOnConstantExpression(sizeResult
);
5317 if (sizeResult
.isInvalid())
5320 Expr
*size
= sizeResult
.get();
5322 QualType Result
= TL
.getType();
5323 if (getDerived().AlwaysRebuild() ||
5324 ElementType
!= T
->getElementType() ||
5326 Result
= getDerived().RebuildDependentSizedArrayType(ElementType
,
5327 T
->getSizeModifier(),
5329 T
->getIndexTypeCVRQualifiers(),
5330 TL
.getBracketsRange());
5331 if (Result
.isNull())
5335 // We might have any sort of array type now, but fortunately they
5336 // all have the same location layout.
5337 ArrayTypeLoc NewTL
= TLB
.push
<ArrayTypeLoc
>(Result
);
5338 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
5339 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
5340 NewTL
.setSizeExpr(size
);
5345 template <typename Derived
>
5346 QualType TreeTransform
<Derived
>::TransformDependentVectorType(
5347 TypeLocBuilder
&TLB
, DependentVectorTypeLoc TL
) {
5348 const DependentVectorType
*T
= TL
.getTypePtr();
5349 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
5350 if (ElementType
.isNull())
5353 EnterExpressionEvaluationContext
Unevaluated(
5354 SemaRef
, Sema::ExpressionEvaluationContext::ConstantEvaluated
);
5356 ExprResult Size
= getDerived().TransformExpr(T
->getSizeExpr());
5357 Size
= SemaRef
.ActOnConstantExpression(Size
);
5358 if (Size
.isInvalid())
5361 QualType Result
= TL
.getType();
5362 if (getDerived().AlwaysRebuild() || ElementType
!= T
->getElementType() ||
5363 Size
.get() != T
->getSizeExpr()) {
5364 Result
= getDerived().RebuildDependentVectorType(
5365 ElementType
, Size
.get(), T
->getAttributeLoc(), T
->getVectorKind());
5366 if (Result
.isNull())
5370 // Result might be dependent or not.
5371 if (isa
<DependentVectorType
>(Result
)) {
5372 DependentVectorTypeLoc NewTL
=
5373 TLB
.push
<DependentVectorTypeLoc
>(Result
);
5374 NewTL
.setNameLoc(TL
.getNameLoc());
5376 VectorTypeLoc NewTL
= TLB
.push
<VectorTypeLoc
>(Result
);
5377 NewTL
.setNameLoc(TL
.getNameLoc());
5383 template<typename Derived
>
5384 QualType TreeTransform
<Derived
>::TransformDependentSizedExtVectorType(
5385 TypeLocBuilder
&TLB
,
5386 DependentSizedExtVectorTypeLoc TL
) {
5387 const DependentSizedExtVectorType
*T
= TL
.getTypePtr();
5389 // FIXME: ext vector locs should be nested
5390 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
5391 if (ElementType
.isNull())
5394 // Vector sizes are constant expressions.
5395 EnterExpressionEvaluationContext
Unevaluated(
5396 SemaRef
, Sema::ExpressionEvaluationContext::ConstantEvaluated
);
5398 ExprResult Size
= getDerived().TransformExpr(T
->getSizeExpr());
5399 Size
= SemaRef
.ActOnConstantExpression(Size
);
5400 if (Size
.isInvalid())
5403 QualType Result
= TL
.getType();
5404 if (getDerived().AlwaysRebuild() ||
5405 ElementType
!= T
->getElementType() ||
5406 Size
.get() != T
->getSizeExpr()) {
5407 Result
= getDerived().RebuildDependentSizedExtVectorType(ElementType
,
5409 T
->getAttributeLoc());
5410 if (Result
.isNull())
5414 // Result might be dependent or not.
5415 if (isa
<DependentSizedExtVectorType
>(Result
)) {
5416 DependentSizedExtVectorTypeLoc NewTL
5417 = TLB
.push
<DependentSizedExtVectorTypeLoc
>(Result
);
5418 NewTL
.setNameLoc(TL
.getNameLoc());
5420 ExtVectorTypeLoc NewTL
= TLB
.push
<ExtVectorTypeLoc
>(Result
);
5421 NewTL
.setNameLoc(TL
.getNameLoc());
5427 template <typename Derived
>
5429 TreeTransform
<Derived
>::TransformConstantMatrixType(TypeLocBuilder
&TLB
,
5430 ConstantMatrixTypeLoc TL
) {
5431 const ConstantMatrixType
*T
= TL
.getTypePtr();
5432 QualType ElementType
= getDerived().TransformType(T
->getElementType());
5433 if (ElementType
.isNull())
5436 QualType Result
= TL
.getType();
5437 if (getDerived().AlwaysRebuild() || ElementType
!= T
->getElementType()) {
5438 Result
= getDerived().RebuildConstantMatrixType(
5439 ElementType
, T
->getNumRows(), T
->getNumColumns());
5440 if (Result
.isNull())
5444 ConstantMatrixTypeLoc NewTL
= TLB
.push
<ConstantMatrixTypeLoc
>(Result
);
5445 NewTL
.setAttrNameLoc(TL
.getAttrNameLoc());
5446 NewTL
.setAttrOperandParensRange(TL
.getAttrOperandParensRange());
5447 NewTL
.setAttrRowOperand(TL
.getAttrRowOperand());
5448 NewTL
.setAttrColumnOperand(TL
.getAttrColumnOperand());
5453 template <typename Derived
>
5454 QualType TreeTransform
<Derived
>::TransformDependentSizedMatrixType(
5455 TypeLocBuilder
&TLB
, DependentSizedMatrixTypeLoc TL
) {
5456 const DependentSizedMatrixType
*T
= TL
.getTypePtr();
5458 QualType ElementType
= getDerived().TransformType(T
->getElementType());
5459 if (ElementType
.isNull()) {
5463 // Matrix dimensions are constant expressions.
5464 EnterExpressionEvaluationContext
Unevaluated(
5465 SemaRef
, Sema::ExpressionEvaluationContext::ConstantEvaluated
);
5467 Expr
*origRows
= TL
.getAttrRowOperand();
5469 origRows
= T
->getRowExpr();
5470 Expr
*origColumns
= TL
.getAttrColumnOperand();
5472 origColumns
= T
->getColumnExpr();
5474 ExprResult rowResult
= getDerived().TransformExpr(origRows
);
5475 rowResult
= SemaRef
.ActOnConstantExpression(rowResult
);
5476 if (rowResult
.isInvalid())
5479 ExprResult columnResult
= getDerived().TransformExpr(origColumns
);
5480 columnResult
= SemaRef
.ActOnConstantExpression(columnResult
);
5481 if (columnResult
.isInvalid())
5484 Expr
*rows
= rowResult
.get();
5485 Expr
*columns
= columnResult
.get();
5487 QualType Result
= TL
.getType();
5488 if (getDerived().AlwaysRebuild() || ElementType
!= T
->getElementType() ||
5489 rows
!= origRows
|| columns
!= origColumns
) {
5490 Result
= getDerived().RebuildDependentSizedMatrixType(
5491 ElementType
, rows
, columns
, T
->getAttributeLoc());
5493 if (Result
.isNull())
5497 // We might have any sort of matrix type now, but fortunately they
5498 // all have the same location layout.
5499 MatrixTypeLoc NewTL
= TLB
.push
<MatrixTypeLoc
>(Result
);
5500 NewTL
.setAttrNameLoc(TL
.getAttrNameLoc());
5501 NewTL
.setAttrOperandParensRange(TL
.getAttrOperandParensRange());
5502 NewTL
.setAttrRowOperand(rows
);
5503 NewTL
.setAttrColumnOperand(columns
);
5507 template <typename Derived
>
5508 QualType TreeTransform
<Derived
>::TransformDependentAddressSpaceType(
5509 TypeLocBuilder
&TLB
, DependentAddressSpaceTypeLoc TL
) {
5510 const DependentAddressSpaceType
*T
= TL
.getTypePtr();
5512 QualType pointeeType
= getDerived().TransformType(T
->getPointeeType());
5514 if (pointeeType
.isNull())
5517 // Address spaces are constant expressions.
5518 EnterExpressionEvaluationContext
Unevaluated(
5519 SemaRef
, Sema::ExpressionEvaluationContext::ConstantEvaluated
);
5521 ExprResult AddrSpace
= getDerived().TransformExpr(T
->getAddrSpaceExpr());
5522 AddrSpace
= SemaRef
.ActOnConstantExpression(AddrSpace
);
5523 if (AddrSpace
.isInvalid())
5526 QualType Result
= TL
.getType();
5527 if (getDerived().AlwaysRebuild() || pointeeType
!= T
->getPointeeType() ||
5528 AddrSpace
.get() != T
->getAddrSpaceExpr()) {
5529 Result
= getDerived().RebuildDependentAddressSpaceType(
5530 pointeeType
, AddrSpace
.get(), T
->getAttributeLoc());
5531 if (Result
.isNull())
5535 // Result might be dependent or not.
5536 if (isa
<DependentAddressSpaceType
>(Result
)) {
5537 DependentAddressSpaceTypeLoc NewTL
=
5538 TLB
.push
<DependentAddressSpaceTypeLoc
>(Result
);
5540 NewTL
.setAttrOperandParensRange(TL
.getAttrOperandParensRange());
5541 NewTL
.setAttrExprOperand(TL
.getAttrExprOperand());
5542 NewTL
.setAttrNameLoc(TL
.getAttrNameLoc());
5545 TypeSourceInfo
*DI
= getSema().Context
.getTrivialTypeSourceInfo(
5546 Result
, getDerived().getBaseLocation());
5547 TransformType(TLB
, DI
->getTypeLoc());
5553 template <typename Derived
>
5554 QualType TreeTransform
<Derived
>::TransformVectorType(TypeLocBuilder
&TLB
,
5556 const VectorType
*T
= TL
.getTypePtr();
5557 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
5558 if (ElementType
.isNull())
5561 QualType Result
= TL
.getType();
5562 if (getDerived().AlwaysRebuild() ||
5563 ElementType
!= T
->getElementType()) {
5564 Result
= getDerived().RebuildVectorType(ElementType
, T
->getNumElements(),
5565 T
->getVectorKind());
5566 if (Result
.isNull())
5570 VectorTypeLoc NewTL
= TLB
.push
<VectorTypeLoc
>(Result
);
5571 NewTL
.setNameLoc(TL
.getNameLoc());
5576 template<typename Derived
>
5577 QualType TreeTransform
<Derived
>::TransformExtVectorType(TypeLocBuilder
&TLB
,
5578 ExtVectorTypeLoc TL
) {
5579 const VectorType
*T
= TL
.getTypePtr();
5580 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
5581 if (ElementType
.isNull())
5584 QualType Result
= TL
.getType();
5585 if (getDerived().AlwaysRebuild() ||
5586 ElementType
!= T
->getElementType()) {
5587 Result
= getDerived().RebuildExtVectorType(ElementType
,
5588 T
->getNumElements(),
5589 /*FIXME*/ SourceLocation());
5590 if (Result
.isNull())
5594 ExtVectorTypeLoc NewTL
= TLB
.push
<ExtVectorTypeLoc
>(Result
);
5595 NewTL
.setNameLoc(TL
.getNameLoc());
5600 template <typename Derived
>
5601 ParmVarDecl
*TreeTransform
<Derived
>::TransformFunctionTypeParam(
5602 ParmVarDecl
*OldParm
, int indexAdjustment
, Optional
<unsigned> NumExpansions
,
5603 bool ExpectParameterPack
) {
5604 TypeSourceInfo
*OldDI
= OldParm
->getTypeSourceInfo();
5605 TypeSourceInfo
*NewDI
= nullptr;
5607 if (NumExpansions
&& isa
<PackExpansionType
>(OldDI
->getType())) {
5608 // If we're substituting into a pack expansion type and we know the
5609 // length we want to expand to, just substitute for the pattern.
5610 TypeLoc OldTL
= OldDI
->getTypeLoc();
5611 PackExpansionTypeLoc OldExpansionTL
= OldTL
.castAs
<PackExpansionTypeLoc
>();
5614 TypeLoc NewTL
= OldDI
->getTypeLoc();
5615 TLB
.reserve(NewTL
.getFullDataSize());
5617 QualType Result
= getDerived().TransformType(TLB
,
5618 OldExpansionTL
.getPatternLoc());
5619 if (Result
.isNull())
5622 Result
= RebuildPackExpansionType(Result
,
5623 OldExpansionTL
.getPatternLoc().getSourceRange(),
5624 OldExpansionTL
.getEllipsisLoc(),
5626 if (Result
.isNull())
5629 PackExpansionTypeLoc NewExpansionTL
5630 = TLB
.push
<PackExpansionTypeLoc
>(Result
);
5631 NewExpansionTL
.setEllipsisLoc(OldExpansionTL
.getEllipsisLoc());
5632 NewDI
= TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
5634 NewDI
= getDerived().TransformType(OldDI
);
5638 if (NewDI
== OldDI
&& indexAdjustment
== 0)
5641 ParmVarDecl
*newParm
= ParmVarDecl::Create(SemaRef
.Context
,
5642 OldParm
->getDeclContext(),
5643 OldParm
->getInnerLocStart(),
5644 OldParm
->getLocation(),
5645 OldParm
->getIdentifier(),
5648 OldParm
->getStorageClass(),
5649 /* DefArg */ nullptr);
5650 newParm
->setScopeInfo(OldParm
->getFunctionScopeDepth(),
5651 OldParm
->getFunctionScopeIndex() + indexAdjustment
);
5652 transformedLocalDecl(OldParm
, {newParm
});
5656 template <typename Derived
>
5657 bool TreeTransform
<Derived
>::TransformFunctionTypeParams(
5658 SourceLocation Loc
, ArrayRef
<ParmVarDecl
*> Params
,
5659 const QualType
*ParamTypes
,
5660 const FunctionProtoType::ExtParameterInfo
*ParamInfos
,
5661 SmallVectorImpl
<QualType
> &OutParamTypes
,
5662 SmallVectorImpl
<ParmVarDecl
*> *PVars
,
5663 Sema::ExtParameterInfoBuilder
&PInfos
) {
5664 int indexAdjustment
= 0;
5666 unsigned NumParams
= Params
.size();
5667 for (unsigned i
= 0; i
!= NumParams
; ++i
) {
5668 if (ParmVarDecl
*OldParm
= Params
[i
]) {
5669 assert(OldParm
->getFunctionScopeIndex() == i
);
5671 Optional
<unsigned> NumExpansions
;
5672 ParmVarDecl
*NewParm
= nullptr;
5673 if (OldParm
->isParameterPack()) {
5674 // We have a function parameter pack that may need to be expanded.
5675 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
5677 // Find the parameter packs that could be expanded.
5678 TypeLoc TL
= OldParm
->getTypeSourceInfo()->getTypeLoc();
5679 PackExpansionTypeLoc ExpansionTL
= TL
.castAs
<PackExpansionTypeLoc
>();
5680 TypeLoc Pattern
= ExpansionTL
.getPatternLoc();
5681 SemaRef
.collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
5683 // Determine whether we should expand the parameter packs.
5684 bool ShouldExpand
= false;
5685 bool RetainExpansion
= false;
5686 Optional
<unsigned> OrigNumExpansions
;
5687 if (Unexpanded
.size() > 0) {
5688 OrigNumExpansions
= ExpansionTL
.getTypePtr()->getNumExpansions();
5689 NumExpansions
= OrigNumExpansions
;
5690 if (getDerived().TryExpandParameterPacks(ExpansionTL
.getEllipsisLoc(),
5691 Pattern
.getSourceRange(),
5700 const AutoType
*AT
=
5701 Pattern
.getType().getTypePtr()->getContainedAutoType();
5702 assert((AT
&& (!AT
->isDeduced() || AT
->getDeducedType().isNull())) &&
5703 "Could not find parameter packs or undeduced auto type!");
5708 // Expand the function parameter pack into multiple, separate
5710 getDerived().ExpandingFunctionParameterPack(OldParm
);
5711 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
5712 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
5713 ParmVarDecl
*NewParm
5714 = getDerived().TransformFunctionTypeParam(OldParm
,
5717 /*ExpectParameterPack=*/false);
5722 PInfos
.set(OutParamTypes
.size(), ParamInfos
[i
]);
5723 OutParamTypes
.push_back(NewParm
->getType());
5725 PVars
->push_back(NewParm
);
5728 // If we're supposed to retain a pack expansion, do so by temporarily
5729 // forgetting the partially-substituted parameter pack.
5730 if (RetainExpansion
) {
5731 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
5732 ParmVarDecl
*NewParm
5733 = getDerived().TransformFunctionTypeParam(OldParm
,
5736 /*ExpectParameterPack=*/false);
5741 PInfos
.set(OutParamTypes
.size(), ParamInfos
[i
]);
5742 OutParamTypes
.push_back(NewParm
->getType());
5744 PVars
->push_back(NewParm
);
5747 // The next parameter should have the same adjustment as the
5748 // last thing we pushed, but we post-incremented indexAdjustment
5749 // on every push. Also, if we push nothing, the adjustment should
5753 // We're done with the pack expansion.
5757 // We'll substitute the parameter now without expanding the pack
5759 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
5760 NewParm
= getDerived().TransformFunctionTypeParam(OldParm
,
5763 /*ExpectParameterPack=*/true);
5764 assert(NewParm
->isParameterPack() &&
5765 "Parameter pack no longer a parameter pack after "
5768 NewParm
= getDerived().TransformFunctionTypeParam(
5769 OldParm
, indexAdjustment
, None
, /*ExpectParameterPack=*/ false);
5776 PInfos
.set(OutParamTypes
.size(), ParamInfos
[i
]);
5777 OutParamTypes
.push_back(NewParm
->getType());
5779 PVars
->push_back(NewParm
);
5783 // Deal with the possibility that we don't have a parameter
5784 // declaration for this parameter.
5785 QualType OldType
= ParamTypes
[i
];
5786 bool IsPackExpansion
= false;
5787 Optional
<unsigned> NumExpansions
;
5789 if (const PackExpansionType
*Expansion
5790 = dyn_cast
<PackExpansionType
>(OldType
)) {
5791 // We have a function parameter pack that may need to be expanded.
5792 QualType Pattern
= Expansion
->getPattern();
5793 NumExpansions
= Expansion
->getNumExpansions();
5794 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
5795 getSema().collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
5797 // Determine whether we should expand the parameter packs.
5798 bool ShouldExpand
= false;
5799 bool RetainExpansion
= false;
5800 if (getDerived().TryExpandParameterPacks(Loc
, SourceRange(),
5809 // Expand the function parameter pack into multiple, separate
5811 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
5812 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
5813 QualType NewType
= getDerived().TransformType(Pattern
);
5814 if (NewType
.isNull())
5817 if (NewType
->containsUnexpandedParameterPack()) {
5819 getSema().getASTContext().getPackExpansionType(NewType
, None
);
5821 if (NewType
.isNull())
5826 PInfos
.set(OutParamTypes
.size(), ParamInfos
[i
]);
5827 OutParamTypes
.push_back(NewType
);
5829 PVars
->push_back(nullptr);
5832 // We're done with the pack expansion.
5836 // If we're supposed to retain a pack expansion, do so by temporarily
5837 // forgetting the partially-substituted parameter pack.
5838 if (RetainExpansion
) {
5839 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
5840 QualType NewType
= getDerived().TransformType(Pattern
);
5841 if (NewType
.isNull())
5845 PInfos
.set(OutParamTypes
.size(), ParamInfos
[i
]);
5846 OutParamTypes
.push_back(NewType
);
5848 PVars
->push_back(nullptr);
5851 // We'll substitute the parameter now without expanding the pack
5853 OldType
= Expansion
->getPattern();
5854 IsPackExpansion
= true;
5855 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
5856 NewType
= getDerived().TransformType(OldType
);
5858 NewType
= getDerived().TransformType(OldType
);
5861 if (NewType
.isNull())
5864 if (IsPackExpansion
)
5865 NewType
= getSema().Context
.getPackExpansionType(NewType
,
5869 PInfos
.set(OutParamTypes
.size(), ParamInfos
[i
]);
5870 OutParamTypes
.push_back(NewType
);
5872 PVars
->push_back(nullptr);
5877 for (unsigned i
= 0, e
= PVars
->size(); i
!= e
; ++i
)
5878 if (ParmVarDecl
*parm
= (*PVars
)[i
])
5879 assert(parm
->getFunctionScopeIndex() == i
);
5886 template<typename Derived
>
5888 TreeTransform
<Derived
>::TransformFunctionProtoType(TypeLocBuilder
&TLB
,
5889 FunctionProtoTypeLoc TL
) {
5890 SmallVector
<QualType
, 4> ExceptionStorage
;
5891 TreeTransform
*This
= this; // Work around gcc.gnu.org/PR56135.
5892 return getDerived().TransformFunctionProtoType(
5893 TLB
, TL
, nullptr, Qualifiers(),
5894 [&](FunctionProtoType::ExceptionSpecInfo
&ESI
, bool &Changed
) {
5895 return This
->getDerived().TransformExceptionSpec(
5896 TL
.getBeginLoc(), ESI
, ExceptionStorage
, Changed
);
5900 template<typename Derived
> template<typename Fn
>
5901 QualType TreeTransform
<Derived
>::TransformFunctionProtoType(
5902 TypeLocBuilder
&TLB
, FunctionProtoTypeLoc TL
, CXXRecordDecl
*ThisContext
,
5903 Qualifiers ThisTypeQuals
, Fn TransformExceptionSpec
) {
5905 // Transform the parameters and return type.
5907 // We are required to instantiate the params and return type in source order.
5908 // When the function has a trailing return type, we instantiate the
5909 // parameters before the return type, since the return type can then refer
5910 // to the parameters themselves (via decltype, sizeof, etc.).
5912 SmallVector
<QualType
, 4> ParamTypes
;
5913 SmallVector
<ParmVarDecl
*, 4> ParamDecls
;
5914 Sema::ExtParameterInfoBuilder ExtParamInfos
;
5915 const FunctionProtoType
*T
= TL
.getTypePtr();
5917 QualType ResultType
;
5919 if (T
->hasTrailingReturn()) {
5920 if (getDerived().TransformFunctionTypeParams(
5921 TL
.getBeginLoc(), TL
.getParams(),
5922 TL
.getTypePtr()->param_type_begin(),
5923 T
->getExtParameterInfosOrNull(),
5924 ParamTypes
, &ParamDecls
, ExtParamInfos
))
5928 // C++11 [expr.prim.general]p3:
5929 // If a declaration declares a member function or member function
5930 // template of a class X, the expression this is a prvalue of type
5931 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
5932 // and the end of the function-definition, member-declarator, or
5934 Sema::CXXThisScopeRAII
ThisScope(SemaRef
, ThisContext
, ThisTypeQuals
);
5936 ResultType
= getDerived().TransformType(TLB
, TL
.getReturnLoc());
5937 if (ResultType
.isNull())
5942 ResultType
= getDerived().TransformType(TLB
, TL
.getReturnLoc());
5943 if (ResultType
.isNull())
5946 if (getDerived().TransformFunctionTypeParams(
5947 TL
.getBeginLoc(), TL
.getParams(),
5948 TL
.getTypePtr()->param_type_begin(),
5949 T
->getExtParameterInfosOrNull(),
5950 ParamTypes
, &ParamDecls
, ExtParamInfos
))
5954 FunctionProtoType::ExtProtoInfo EPI
= T
->getExtProtoInfo();
5956 bool EPIChanged
= false;
5957 if (TransformExceptionSpec(EPI
.ExceptionSpec
, EPIChanged
))
5960 // Handle extended parameter information.
5961 if (auto NewExtParamInfos
=
5962 ExtParamInfos
.getPointerOrNull(ParamTypes
.size())) {
5963 if (!EPI
.ExtParameterInfos
||
5964 llvm::makeArrayRef(EPI
.ExtParameterInfos
, TL
.getNumParams())
5965 != llvm::makeArrayRef(NewExtParamInfos
, ParamTypes
.size())) {
5968 EPI
.ExtParameterInfos
= NewExtParamInfos
;
5969 } else if (EPI
.ExtParameterInfos
) {
5971 EPI
.ExtParameterInfos
= nullptr;
5974 QualType Result
= TL
.getType();
5975 if (getDerived().AlwaysRebuild() || ResultType
!= T
->getReturnType() ||
5976 T
->getParamTypes() != llvm::makeArrayRef(ParamTypes
) || EPIChanged
) {
5977 Result
= getDerived().RebuildFunctionProtoType(ResultType
, ParamTypes
, EPI
);
5978 if (Result
.isNull())
5982 FunctionProtoTypeLoc NewTL
= TLB
.push
<FunctionProtoTypeLoc
>(Result
);
5983 NewTL
.setLocalRangeBegin(TL
.getLocalRangeBegin());
5984 NewTL
.setLParenLoc(TL
.getLParenLoc());
5985 NewTL
.setRParenLoc(TL
.getRParenLoc());
5986 NewTL
.setExceptionSpecRange(TL
.getExceptionSpecRange());
5987 NewTL
.setLocalRangeEnd(TL
.getLocalRangeEnd());
5988 for (unsigned i
= 0, e
= NewTL
.getNumParams(); i
!= e
; ++i
)
5989 NewTL
.setParam(i
, ParamDecls
[i
]);
5994 template<typename Derived
>
5995 bool TreeTransform
<Derived
>::TransformExceptionSpec(
5996 SourceLocation Loc
, FunctionProtoType::ExceptionSpecInfo
&ESI
,
5997 SmallVectorImpl
<QualType
> &Exceptions
, bool &Changed
) {
5998 assert(ESI
.Type
!= EST_Uninstantiated
&& ESI
.Type
!= EST_Unevaluated
);
6000 // Instantiate a dynamic noexcept expression, if any.
6001 if (isComputedNoexcept(ESI
.Type
)) {
6002 EnterExpressionEvaluationContext
Unevaluated(
6003 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated
);
6004 ExprResult NoexceptExpr
= getDerived().TransformExpr(ESI
.NoexceptExpr
);
6005 if (NoexceptExpr
.isInvalid())
6008 ExceptionSpecificationType EST
= ESI
.Type
;
6010 getSema().ActOnNoexceptSpec(NoexceptExpr
.get(), EST
);
6011 if (NoexceptExpr
.isInvalid())
6014 if (ESI
.NoexceptExpr
!= NoexceptExpr
.get() || EST
!= ESI
.Type
)
6016 ESI
.NoexceptExpr
= NoexceptExpr
.get();
6020 if (ESI
.Type
!= EST_Dynamic
)
6023 // Instantiate a dynamic exception specification's type.
6024 for (QualType T
: ESI
.Exceptions
) {
6025 if (const PackExpansionType
*PackExpansion
=
6026 T
->getAs
<PackExpansionType
>()) {
6029 // We have a pack expansion. Instantiate it.
6030 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
6031 SemaRef
.collectUnexpandedParameterPacks(PackExpansion
->getPattern(),
6033 assert(!Unexpanded
.empty() && "Pack expansion without parameter packs?");
6035 // Determine whether the set of unexpanded parameter packs can and
6038 bool Expand
= false;
6039 bool RetainExpansion
= false;
6040 Optional
<unsigned> NumExpansions
= PackExpansion
->getNumExpansions();
6041 // FIXME: Track the location of the ellipsis (and track source location
6042 // information for the types in the exception specification in general).
6043 if (getDerived().TryExpandParameterPacks(
6044 Loc
, SourceRange(), Unexpanded
, Expand
,
6045 RetainExpansion
, NumExpansions
))
6049 // We can't expand this pack expansion into separate arguments yet;
6050 // just substitute into the pattern and create a new pack expansion
6052 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
6053 QualType U
= getDerived().TransformType(PackExpansion
->getPattern());
6057 U
= SemaRef
.Context
.getPackExpansionType(U
, NumExpansions
);
6058 Exceptions
.push_back(U
);
6062 // Substitute into the pack expansion pattern for each slice of the
6064 for (unsigned ArgIdx
= 0; ArgIdx
!= *NumExpansions
; ++ArgIdx
) {
6065 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), ArgIdx
);
6067 QualType U
= getDerived().TransformType(PackExpansion
->getPattern());
6068 if (U
.isNull() || SemaRef
.CheckSpecifiedExceptionType(U
, Loc
))
6071 Exceptions
.push_back(U
);
6074 QualType U
= getDerived().TransformType(T
);
6075 if (U
.isNull() || SemaRef
.CheckSpecifiedExceptionType(U
, Loc
))
6080 Exceptions
.push_back(U
);
6084 ESI
.Exceptions
= Exceptions
;
6085 if (ESI
.Exceptions
.empty())
6086 ESI
.Type
= EST_DynamicNone
;
6090 template<typename Derived
>
6091 QualType TreeTransform
<Derived
>::TransformFunctionNoProtoType(
6092 TypeLocBuilder
&TLB
,
6093 FunctionNoProtoTypeLoc TL
) {
6094 const FunctionNoProtoType
*T
= TL
.getTypePtr();
6095 QualType ResultType
= getDerived().TransformType(TLB
, TL
.getReturnLoc());
6096 if (ResultType
.isNull())
6099 QualType Result
= TL
.getType();
6100 if (getDerived().AlwaysRebuild() || ResultType
!= T
->getReturnType())
6101 Result
= getDerived().RebuildFunctionNoProtoType(ResultType
);
6103 FunctionNoProtoTypeLoc NewTL
= TLB
.push
<FunctionNoProtoTypeLoc
>(Result
);
6104 NewTL
.setLocalRangeBegin(TL
.getLocalRangeBegin());
6105 NewTL
.setLParenLoc(TL
.getLParenLoc());
6106 NewTL
.setRParenLoc(TL
.getRParenLoc());
6107 NewTL
.setLocalRangeEnd(TL
.getLocalRangeEnd());
6112 template <typename Derived
>
6113 QualType TreeTransform
<Derived
>::TransformUnresolvedUsingType(
6114 TypeLocBuilder
&TLB
, UnresolvedUsingTypeLoc TL
) {
6115 const UnresolvedUsingType
*T
= TL
.getTypePtr();
6116 Decl
*D
= getDerived().TransformDecl(TL
.getNameLoc(), T
->getDecl());
6120 QualType Result
= TL
.getType();
6121 if (getDerived().AlwaysRebuild() || D
!= T
->getDecl()) {
6122 Result
= getDerived().RebuildUnresolvedUsingType(TL
.getNameLoc(), D
);
6123 if (Result
.isNull())
6127 // We might get an arbitrary type spec type back. We should at
6128 // least always get a type spec type, though.
6129 TypeSpecTypeLoc NewTL
= TLB
.pushTypeSpec(Result
);
6130 NewTL
.setNameLoc(TL
.getNameLoc());
6135 template <typename Derived
>
6136 QualType TreeTransform
<Derived
>::TransformUsingType(TypeLocBuilder
&TLB
,
6138 const UsingType
*T
= TL
.getTypePtr();
6140 auto *Found
= cast_or_null
<UsingShadowDecl
>(getDerived().TransformDecl(
6141 TL
.getLocalSourceRange().getBegin(), T
->getFoundDecl()));
6145 QualType Underlying
= getDerived().TransformType(T
->desugar());
6146 if (Underlying
.isNull())
6149 QualType Result
= TL
.getType();
6150 if (getDerived().AlwaysRebuild() || Found
!= T
->getFoundDecl() ||
6151 Underlying
!= T
->getUnderlyingType()) {
6152 Result
= getDerived().RebuildUsingType(Found
, Underlying
);
6153 if (Result
.isNull())
6157 TLB
.pushTypeSpec(Result
).setNameLoc(TL
.getNameLoc());
6161 template<typename Derived
>
6162 QualType TreeTransform
<Derived
>::TransformTypedefType(TypeLocBuilder
&TLB
,
6163 TypedefTypeLoc TL
) {
6164 const TypedefType
*T
= TL
.getTypePtr();
6165 TypedefNameDecl
*Typedef
6166 = cast_or_null
<TypedefNameDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
6171 QualType Result
= TL
.getType();
6172 if (getDerived().AlwaysRebuild() ||
6173 Typedef
!= T
->getDecl()) {
6174 Result
= getDerived().RebuildTypedefType(Typedef
);
6175 if (Result
.isNull())
6179 TypedefTypeLoc NewTL
= TLB
.push
<TypedefTypeLoc
>(Result
);
6180 NewTL
.setNameLoc(TL
.getNameLoc());
6185 template<typename Derived
>
6186 QualType TreeTransform
<Derived
>::TransformTypeOfExprType(TypeLocBuilder
&TLB
,
6187 TypeOfExprTypeLoc TL
) {
6188 // typeof expressions are not potentially evaluated contexts
6189 EnterExpressionEvaluationContext
Unevaluated(
6190 SemaRef
, Sema::ExpressionEvaluationContext::Unevaluated
,
6191 Sema::ReuseLambdaContextDecl
);
6193 ExprResult E
= getDerived().TransformExpr(TL
.getUnderlyingExpr());
6197 E
= SemaRef
.HandleExprEvaluationContextForTypeof(E
.get());
6201 QualType Result
= TL
.getType();
6202 if (getDerived().AlwaysRebuild() ||
6203 E
.get() != TL
.getUnderlyingExpr()) {
6204 Result
= getDerived().RebuildTypeOfExprType(E
.get(), TL
.getTypeofLoc());
6205 if (Result
.isNull())
6210 TypeOfExprTypeLoc NewTL
= TLB
.push
<TypeOfExprTypeLoc
>(Result
);
6211 NewTL
.setTypeofLoc(TL
.getTypeofLoc());
6212 NewTL
.setLParenLoc(TL
.getLParenLoc());
6213 NewTL
.setRParenLoc(TL
.getRParenLoc());
6218 template<typename Derived
>
6219 QualType TreeTransform
<Derived
>::TransformTypeOfType(TypeLocBuilder
&TLB
,
6221 TypeSourceInfo
* Old_Under_TI
= TL
.getUnderlyingTInfo();
6222 TypeSourceInfo
* New_Under_TI
= getDerived().TransformType(Old_Under_TI
);
6226 QualType Result
= TL
.getType();
6227 if (getDerived().AlwaysRebuild() || New_Under_TI
!= Old_Under_TI
) {
6228 Result
= getDerived().RebuildTypeOfType(New_Under_TI
->getType());
6229 if (Result
.isNull())
6233 TypeOfTypeLoc NewTL
= TLB
.push
<TypeOfTypeLoc
>(Result
);
6234 NewTL
.setTypeofLoc(TL
.getTypeofLoc());
6235 NewTL
.setLParenLoc(TL
.getLParenLoc());
6236 NewTL
.setRParenLoc(TL
.getRParenLoc());
6237 NewTL
.setUnderlyingTInfo(New_Under_TI
);
6242 template<typename Derived
>
6243 QualType TreeTransform
<Derived
>::TransformDecltypeType(TypeLocBuilder
&TLB
,
6244 DecltypeTypeLoc TL
) {
6245 const DecltypeType
*T
= TL
.getTypePtr();
6247 // decltype expressions are not potentially evaluated contexts
6248 EnterExpressionEvaluationContext
Unevaluated(
6249 SemaRef
, Sema::ExpressionEvaluationContext::Unevaluated
, nullptr,
6250 Sema::ExpressionEvaluationContextRecord::EK_Decltype
);
6252 ExprResult E
= getDerived().TransformExpr(T
->getUnderlyingExpr());
6256 E
= getSema().ActOnDecltypeExpression(E
.get());
6260 QualType Result
= TL
.getType();
6261 if (getDerived().AlwaysRebuild() ||
6262 E
.get() != T
->getUnderlyingExpr()) {
6263 Result
= getDerived().RebuildDecltypeType(E
.get(), TL
.getDecltypeLoc());
6264 if (Result
.isNull())
6269 DecltypeTypeLoc NewTL
= TLB
.push
<DecltypeTypeLoc
>(Result
);
6270 NewTL
.setDecltypeLoc(TL
.getDecltypeLoc());
6271 NewTL
.setRParenLoc(TL
.getRParenLoc());
6275 template<typename Derived
>
6276 QualType TreeTransform
<Derived
>::TransformUnaryTransformType(
6277 TypeLocBuilder
&TLB
,
6278 UnaryTransformTypeLoc TL
) {
6279 QualType Result
= TL
.getType();
6280 if (Result
->isDependentType()) {
6281 const UnaryTransformType
*T
= TL
.getTypePtr();
6283 getDerived().TransformType(TL
.getUnderlyingTInfo())->getType();
6284 Result
= getDerived().RebuildUnaryTransformType(NewBase
,
6287 if (Result
.isNull())
6291 UnaryTransformTypeLoc NewTL
= TLB
.push
<UnaryTransformTypeLoc
>(Result
);
6292 NewTL
.setKWLoc(TL
.getKWLoc());
6293 NewTL
.setParensRange(TL
.getParensRange());
6294 NewTL
.setUnderlyingTInfo(TL
.getUnderlyingTInfo());
6298 template<typename Derived
>
6299 QualType TreeTransform
<Derived
>::TransformDeducedTemplateSpecializationType(
6300 TypeLocBuilder
&TLB
, DeducedTemplateSpecializationTypeLoc TL
) {
6301 const DeducedTemplateSpecializationType
*T
= TL
.getTypePtr();
6304 TemplateName TemplateName
= getDerived().TransformTemplateName(
6305 SS
, T
->getTemplateName(), TL
.getTemplateNameLoc());
6306 if (TemplateName
.isNull())
6309 QualType OldDeduced
= T
->getDeducedType();
6310 QualType NewDeduced
;
6311 if (!OldDeduced
.isNull()) {
6312 NewDeduced
= getDerived().TransformType(OldDeduced
);
6313 if (NewDeduced
.isNull())
6317 QualType Result
= getDerived().RebuildDeducedTemplateSpecializationType(
6318 TemplateName
, NewDeduced
);
6319 if (Result
.isNull())
6322 DeducedTemplateSpecializationTypeLoc NewTL
=
6323 TLB
.push
<DeducedTemplateSpecializationTypeLoc
>(Result
);
6324 NewTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
6329 template<typename Derived
>
6330 QualType TreeTransform
<Derived
>::TransformRecordType(TypeLocBuilder
&TLB
,
6332 const RecordType
*T
= TL
.getTypePtr();
6334 = cast_or_null
<RecordDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
6339 QualType Result
= TL
.getType();
6340 if (getDerived().AlwaysRebuild() ||
6341 Record
!= T
->getDecl()) {
6342 Result
= getDerived().RebuildRecordType(Record
);
6343 if (Result
.isNull())
6347 RecordTypeLoc NewTL
= TLB
.push
<RecordTypeLoc
>(Result
);
6348 NewTL
.setNameLoc(TL
.getNameLoc());
6353 template<typename Derived
>
6354 QualType TreeTransform
<Derived
>::TransformEnumType(TypeLocBuilder
&TLB
,
6356 const EnumType
*T
= TL
.getTypePtr();
6358 = cast_or_null
<EnumDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
6363 QualType Result
= TL
.getType();
6364 if (getDerived().AlwaysRebuild() ||
6365 Enum
!= T
->getDecl()) {
6366 Result
= getDerived().RebuildEnumType(Enum
);
6367 if (Result
.isNull())
6371 EnumTypeLoc NewTL
= TLB
.push
<EnumTypeLoc
>(Result
);
6372 NewTL
.setNameLoc(TL
.getNameLoc());
6377 template<typename Derived
>
6378 QualType TreeTransform
<Derived
>::TransformInjectedClassNameType(
6379 TypeLocBuilder
&TLB
,
6380 InjectedClassNameTypeLoc TL
) {
6381 Decl
*D
= getDerived().TransformDecl(TL
.getNameLoc(),
6382 TL
.getTypePtr()->getDecl());
6383 if (!D
) return QualType();
6385 QualType T
= SemaRef
.Context
.getTypeDeclType(cast
<TypeDecl
>(D
));
6386 TLB
.pushTypeSpec(T
).setNameLoc(TL
.getNameLoc());
6390 template<typename Derived
>
6391 QualType TreeTransform
<Derived
>::TransformTemplateTypeParmType(
6392 TypeLocBuilder
&TLB
,
6393 TemplateTypeParmTypeLoc TL
) {
6394 return TransformTypeSpecType(TLB
, TL
);
6397 template<typename Derived
>
6398 QualType TreeTransform
<Derived
>::TransformSubstTemplateTypeParmType(
6399 TypeLocBuilder
&TLB
,
6400 SubstTemplateTypeParmTypeLoc TL
) {
6401 const SubstTemplateTypeParmType
*T
= TL
.getTypePtr();
6403 // Substitute into the replacement type, which itself might involve something
6404 // that needs to be transformed. This only tends to occur with default
6405 // template arguments of template template parameters.
6406 TemporaryBase
Rebase(*this, TL
.getNameLoc(), DeclarationName());
6407 QualType Replacement
= getDerived().TransformType(T
->getReplacementType());
6408 if (Replacement
.isNull())
6411 // Always canonicalize the replacement type.
6412 Replacement
= SemaRef
.Context
.getCanonicalType(Replacement
);
6413 QualType Result
= SemaRef
.Context
.getSubstTemplateTypeParmType(
6414 T
->getReplacedParameter(), Replacement
, T
->getPackIndex());
6416 // Propagate type-source information.
6417 SubstTemplateTypeParmTypeLoc NewTL
6418 = TLB
.push
<SubstTemplateTypeParmTypeLoc
>(Result
);
6419 NewTL
.setNameLoc(TL
.getNameLoc());
6424 template<typename Derived
>
6425 QualType TreeTransform
<Derived
>::TransformSubstTemplateTypeParmPackType(
6426 TypeLocBuilder
&TLB
,
6427 SubstTemplateTypeParmPackTypeLoc TL
) {
6428 return TransformTypeSpecType(TLB
, TL
);
6431 template<typename Derived
>
6432 QualType TreeTransform
<Derived
>::TransformTemplateSpecializationType(
6433 TypeLocBuilder
&TLB
,
6434 TemplateSpecializationTypeLoc TL
) {
6435 const TemplateSpecializationType
*T
= TL
.getTypePtr();
6437 // The nested-name-specifier never matters in a TemplateSpecializationType,
6438 // because we can't have a dependent nested-name-specifier anyway.
6440 TemplateName Template
6441 = getDerived().TransformTemplateName(SS
, T
->getTemplateName(),
6442 TL
.getTemplateNameLoc());
6443 if (Template
.isNull())
6446 return getDerived().TransformTemplateSpecializationType(TLB
, TL
, Template
);
6449 template<typename Derived
>
6450 QualType TreeTransform
<Derived
>::TransformAtomicType(TypeLocBuilder
&TLB
,
6452 QualType ValueType
= getDerived().TransformType(TLB
, TL
.getValueLoc());
6453 if (ValueType
.isNull())
6456 QualType Result
= TL
.getType();
6457 if (getDerived().AlwaysRebuild() ||
6458 ValueType
!= TL
.getValueLoc().getType()) {
6459 Result
= getDerived().RebuildAtomicType(ValueType
, TL
.getKWLoc());
6460 if (Result
.isNull())
6464 AtomicTypeLoc NewTL
= TLB
.push
<AtomicTypeLoc
>(Result
);
6465 NewTL
.setKWLoc(TL
.getKWLoc());
6466 NewTL
.setLParenLoc(TL
.getLParenLoc());
6467 NewTL
.setRParenLoc(TL
.getRParenLoc());
6472 template <typename Derived
>
6473 QualType TreeTransform
<Derived
>::TransformPipeType(TypeLocBuilder
&TLB
,
6475 QualType ValueType
= getDerived().TransformType(TLB
, TL
.getValueLoc());
6476 if (ValueType
.isNull())
6479 QualType Result
= TL
.getType();
6480 if (getDerived().AlwaysRebuild() || ValueType
!= TL
.getValueLoc().getType()) {
6481 const PipeType
*PT
= Result
->castAs
<PipeType
>();
6482 bool isReadPipe
= PT
->isReadOnly();
6483 Result
= getDerived().RebuildPipeType(ValueType
, TL
.getKWLoc(), isReadPipe
);
6484 if (Result
.isNull())
6488 PipeTypeLoc NewTL
= TLB
.push
<PipeTypeLoc
>(Result
);
6489 NewTL
.setKWLoc(TL
.getKWLoc());
6494 template <typename Derived
>
6495 QualType TreeTransform
<Derived
>::TransformBitIntType(TypeLocBuilder
&TLB
,
6497 const BitIntType
*EIT
= TL
.getTypePtr();
6498 QualType Result
= TL
.getType();
6500 if (getDerived().AlwaysRebuild()) {
6501 Result
= getDerived().RebuildBitIntType(EIT
->isUnsigned(),
6502 EIT
->getNumBits(), TL
.getNameLoc());
6503 if (Result
.isNull())
6507 BitIntTypeLoc NewTL
= TLB
.push
<BitIntTypeLoc
>(Result
);
6508 NewTL
.setNameLoc(TL
.getNameLoc());
6512 template <typename Derived
>
6513 QualType TreeTransform
<Derived
>::TransformDependentBitIntType(
6514 TypeLocBuilder
&TLB
, DependentBitIntTypeLoc TL
) {
6515 const DependentBitIntType
*EIT
= TL
.getTypePtr();
6517 EnterExpressionEvaluationContext
Unevaluated(
6518 SemaRef
, Sema::ExpressionEvaluationContext::ConstantEvaluated
);
6519 ExprResult BitsExpr
= getDerived().TransformExpr(EIT
->getNumBitsExpr());
6520 BitsExpr
= SemaRef
.ActOnConstantExpression(BitsExpr
);
6522 if (BitsExpr
.isInvalid())
6525 QualType Result
= TL
.getType();
6527 if (getDerived().AlwaysRebuild() || BitsExpr
.get() != EIT
->getNumBitsExpr()) {
6528 Result
= getDerived().RebuildDependentBitIntType(
6529 EIT
->isUnsigned(), BitsExpr
.get(), TL
.getNameLoc());
6531 if (Result
.isNull())
6535 if (isa
<DependentBitIntType
>(Result
)) {
6536 DependentBitIntTypeLoc NewTL
= TLB
.push
<DependentBitIntTypeLoc
>(Result
);
6537 NewTL
.setNameLoc(TL
.getNameLoc());
6539 BitIntTypeLoc NewTL
= TLB
.push
<BitIntTypeLoc
>(Result
);
6540 NewTL
.setNameLoc(TL
.getNameLoc());
6545 /// Simple iterator that traverses the template arguments in a
6546 /// container that provides a \c getArgLoc() member function.
6548 /// This iterator is intended to be used with the iterator form of
6549 /// \c TreeTransform<Derived>::TransformTemplateArguments().
6550 template<typename ArgLocContainer
>
6551 class TemplateArgumentLocContainerIterator
{
6552 ArgLocContainer
*Container
;
6556 typedef TemplateArgumentLoc value_type
;
6557 typedef TemplateArgumentLoc reference
;
6558 typedef int difference_type
;
6559 typedef std::input_iterator_tag iterator_category
;
6562 TemplateArgumentLoc Arg
;
6565 explicit pointer(TemplateArgumentLoc Arg
) : Arg(Arg
) { }
6567 const TemplateArgumentLoc
*operator->() const {
6573 TemplateArgumentLocContainerIterator() {}
6575 TemplateArgumentLocContainerIterator(ArgLocContainer
&Container
,
6577 : Container(&Container
), Index(Index
) { }
6579 TemplateArgumentLocContainerIterator
&operator++() {
6584 TemplateArgumentLocContainerIterator
operator++(int) {
6585 TemplateArgumentLocContainerIterator
Old(*this);
6590 TemplateArgumentLoc
operator*() const {
6591 return Container
->getArgLoc(Index
);
6594 pointer
operator->() const {
6595 return pointer(Container
->getArgLoc(Index
));
6598 friend bool operator==(const TemplateArgumentLocContainerIterator
&X
,
6599 const TemplateArgumentLocContainerIterator
&Y
) {
6600 return X
.Container
== Y
.Container
&& X
.Index
== Y
.Index
;
6603 friend bool operator!=(const TemplateArgumentLocContainerIterator
&X
,
6604 const TemplateArgumentLocContainerIterator
&Y
) {
6609 template<typename Derived
>
6610 QualType TreeTransform
<Derived
>::TransformAutoType(TypeLocBuilder
&TLB
,
6612 const AutoType
*T
= TL
.getTypePtr();
6613 QualType OldDeduced
= T
->getDeducedType();
6614 QualType NewDeduced
;
6615 if (!OldDeduced
.isNull()) {
6616 NewDeduced
= getDerived().TransformType(OldDeduced
);
6617 if (NewDeduced
.isNull())
6621 ConceptDecl
*NewCD
= nullptr;
6622 TemplateArgumentListInfo NewTemplateArgs
;
6623 NestedNameSpecifierLoc NewNestedNameSpec
;
6624 if (T
->isConstrained()) {
6625 NewCD
= cast_or_null
<ConceptDecl
>(getDerived().TransformDecl(
6626 TL
.getConceptNameLoc(), T
->getTypeConstraintConcept()));
6628 NewTemplateArgs
.setLAngleLoc(TL
.getLAngleLoc());
6629 NewTemplateArgs
.setRAngleLoc(TL
.getRAngleLoc());
6630 typedef TemplateArgumentLocContainerIterator
<AutoTypeLoc
> ArgIterator
;
6631 if (getDerived().TransformTemplateArguments(ArgIterator(TL
, 0),
6637 if (TL
.getNestedNameSpecifierLoc()) {
6639 = getDerived().TransformNestedNameSpecifierLoc(
6640 TL
.getNestedNameSpecifierLoc());
6641 if (!NewNestedNameSpec
)
6646 QualType Result
= TL
.getType();
6647 if (getDerived().AlwaysRebuild() || NewDeduced
!= OldDeduced
||
6648 T
->isDependentType() || T
->isConstrained()) {
6649 // FIXME: Maybe don't rebuild if all template arguments are the same.
6650 llvm::SmallVector
<TemplateArgument
, 4> NewArgList
;
6651 NewArgList
.reserve(NewTemplateArgs
.size());
6652 for (const auto &ArgLoc
: NewTemplateArgs
.arguments())
6653 NewArgList
.push_back(ArgLoc
.getArgument());
6654 Result
= getDerived().RebuildAutoType(NewDeduced
, T
->getKeyword(), NewCD
,
6656 if (Result
.isNull())
6660 AutoTypeLoc NewTL
= TLB
.push
<AutoTypeLoc
>(Result
);
6661 NewTL
.setNameLoc(TL
.getNameLoc());
6662 NewTL
.setNestedNameSpecifierLoc(NewNestedNameSpec
);
6663 NewTL
.setTemplateKWLoc(TL
.getTemplateKWLoc());
6664 NewTL
.setConceptNameLoc(TL
.getConceptNameLoc());
6665 NewTL
.setFoundDecl(TL
.getFoundDecl());
6666 NewTL
.setLAngleLoc(TL
.getLAngleLoc());
6667 NewTL
.setRAngleLoc(TL
.getRAngleLoc());
6668 NewTL
.setRParenLoc(TL
.getRParenLoc());
6669 for (unsigned I
= 0; I
< NewTL
.getNumArgs(); ++I
)
6670 NewTL
.setArgLocInfo(I
, NewTemplateArgs
.arguments()[I
].getLocInfo());
6675 template <typename Derived
>
6676 QualType TreeTransform
<Derived
>::TransformTemplateSpecializationType(
6677 TypeLocBuilder
&TLB
,
6678 TemplateSpecializationTypeLoc TL
,
6679 TemplateName Template
) {
6680 TemplateArgumentListInfo NewTemplateArgs
;
6681 NewTemplateArgs
.setLAngleLoc(TL
.getLAngleLoc());
6682 NewTemplateArgs
.setRAngleLoc(TL
.getRAngleLoc());
6683 typedef TemplateArgumentLocContainerIterator
<TemplateSpecializationTypeLoc
>
6685 if (getDerived().TransformTemplateArguments(ArgIterator(TL
, 0),
6686 ArgIterator(TL
, TL
.getNumArgs()),
6690 // FIXME: maybe don't rebuild if all the template arguments are the same.
6693 getDerived().RebuildTemplateSpecializationType(Template
,
6694 TL
.getTemplateNameLoc(),
6697 if (!Result
.isNull()) {
6698 // Specializations of template template parameters are represented as
6699 // TemplateSpecializationTypes, and substitution of type alias templates
6700 // within a dependent context can transform them into
6701 // DependentTemplateSpecializationTypes.
6702 if (isa
<DependentTemplateSpecializationType
>(Result
)) {
6703 DependentTemplateSpecializationTypeLoc NewTL
6704 = TLB
.push
<DependentTemplateSpecializationTypeLoc
>(Result
);
6705 NewTL
.setElaboratedKeywordLoc(SourceLocation());
6706 NewTL
.setQualifierLoc(NestedNameSpecifierLoc());
6707 NewTL
.setTemplateKeywordLoc(TL
.getTemplateKeywordLoc());
6708 NewTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
6709 NewTL
.setLAngleLoc(TL
.getLAngleLoc());
6710 NewTL
.setRAngleLoc(TL
.getRAngleLoc());
6711 for (unsigned i
= 0, e
= NewTemplateArgs
.size(); i
!= e
; ++i
)
6712 NewTL
.setArgLocInfo(i
, NewTemplateArgs
[i
].getLocInfo());
6716 TemplateSpecializationTypeLoc NewTL
6717 = TLB
.push
<TemplateSpecializationTypeLoc
>(Result
);
6718 NewTL
.setTemplateKeywordLoc(TL
.getTemplateKeywordLoc());
6719 NewTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
6720 NewTL
.setLAngleLoc(TL
.getLAngleLoc());
6721 NewTL
.setRAngleLoc(TL
.getRAngleLoc());
6722 for (unsigned i
= 0, e
= NewTemplateArgs
.size(); i
!= e
; ++i
)
6723 NewTL
.setArgLocInfo(i
, NewTemplateArgs
[i
].getLocInfo());
6729 template <typename Derived
>
6730 QualType TreeTransform
<Derived
>::TransformDependentTemplateSpecializationType(
6731 TypeLocBuilder
&TLB
,
6732 DependentTemplateSpecializationTypeLoc TL
,
6733 TemplateName Template
,
6735 TemplateArgumentListInfo NewTemplateArgs
;
6736 NewTemplateArgs
.setLAngleLoc(TL
.getLAngleLoc());
6737 NewTemplateArgs
.setRAngleLoc(TL
.getRAngleLoc());
6738 typedef TemplateArgumentLocContainerIterator
<
6739 DependentTemplateSpecializationTypeLoc
> ArgIterator
;
6740 if (getDerived().TransformTemplateArguments(ArgIterator(TL
, 0),
6741 ArgIterator(TL
, TL
.getNumArgs()),
6745 // FIXME: maybe don't rebuild if all the template arguments are the same.
6747 if (DependentTemplateName
*DTN
= Template
.getAsDependentTemplateName()) {
6749 = getSema().Context
.getDependentTemplateSpecializationType(
6750 TL
.getTypePtr()->getKeyword(),
6751 DTN
->getQualifier(),
6752 DTN
->getIdentifier(),
6755 DependentTemplateSpecializationTypeLoc NewTL
6756 = TLB
.push
<DependentTemplateSpecializationTypeLoc
>(Result
);
6757 NewTL
.setElaboratedKeywordLoc(TL
.getElaboratedKeywordLoc());
6758 NewTL
.setQualifierLoc(SS
.getWithLocInContext(SemaRef
.Context
));
6759 NewTL
.setTemplateKeywordLoc(TL
.getTemplateKeywordLoc());
6760 NewTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
6761 NewTL
.setLAngleLoc(TL
.getLAngleLoc());
6762 NewTL
.setRAngleLoc(TL
.getRAngleLoc());
6763 for (unsigned i
= 0, e
= NewTemplateArgs
.size(); i
!= e
; ++i
)
6764 NewTL
.setArgLocInfo(i
, NewTemplateArgs
[i
].getLocInfo());
6769 = getDerived().RebuildTemplateSpecializationType(Template
,
6770 TL
.getTemplateNameLoc(),
6773 if (!Result
.isNull()) {
6774 /// FIXME: Wrap this in an elaborated-type-specifier?
6775 TemplateSpecializationTypeLoc NewTL
6776 = TLB
.push
<TemplateSpecializationTypeLoc
>(Result
);
6777 NewTL
.setTemplateKeywordLoc(TL
.getTemplateKeywordLoc());
6778 NewTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
6779 NewTL
.setLAngleLoc(TL
.getLAngleLoc());
6780 NewTL
.setRAngleLoc(TL
.getRAngleLoc());
6781 for (unsigned i
= 0, e
= NewTemplateArgs
.size(); i
!= e
; ++i
)
6782 NewTL
.setArgLocInfo(i
, NewTemplateArgs
[i
].getLocInfo());
6788 template<typename Derived
>
6790 TreeTransform
<Derived
>::TransformElaboratedType(TypeLocBuilder
&TLB
,
6791 ElaboratedTypeLoc TL
) {
6792 const ElaboratedType
*T
= TL
.getTypePtr();
6794 NestedNameSpecifierLoc QualifierLoc
;
6795 // NOTE: the qualifier in an ElaboratedType is optional.
6796 if (TL
.getQualifierLoc()) {
6798 = getDerived().TransformNestedNameSpecifierLoc(TL
.getQualifierLoc());
6803 QualType NamedT
= getDerived().TransformType(TLB
, TL
.getNamedTypeLoc());
6804 if (NamedT
.isNull())
6807 // C++0x [dcl.type.elab]p2:
6808 // If the identifier resolves to a typedef-name or the simple-template-id
6809 // resolves to an alias template specialization, the
6810 // elaborated-type-specifier is ill-formed.
6811 if (T
->getKeyword() != ETK_None
&& T
->getKeyword() != ETK_Typename
) {
6812 if (const TemplateSpecializationType
*TST
=
6813 NamedT
->getAs
<TemplateSpecializationType
>()) {
6814 TemplateName Template
= TST
->getTemplateName();
6815 if (TypeAliasTemplateDecl
*TAT
= dyn_cast_or_null
<TypeAliasTemplateDecl
>(
6816 Template
.getAsTemplateDecl())) {
6817 SemaRef
.Diag(TL
.getNamedTypeLoc().getBeginLoc(),
6818 diag::err_tag_reference_non_tag
)
6819 << TAT
<< Sema::NTK_TypeAliasTemplate
6820 << ElaboratedType::getTagTypeKindForKeyword(T
->getKeyword());
6821 SemaRef
.Diag(TAT
->getLocation(), diag::note_declared_at
);
6826 QualType Result
= TL
.getType();
6827 if (getDerived().AlwaysRebuild() ||
6828 QualifierLoc
!= TL
.getQualifierLoc() ||
6829 NamedT
!= T
->getNamedType()) {
6830 Result
= getDerived().RebuildElaboratedType(TL
.getElaboratedKeywordLoc(),
6832 QualifierLoc
, NamedT
);
6833 if (Result
.isNull())
6837 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
6838 NewTL
.setElaboratedKeywordLoc(TL
.getElaboratedKeywordLoc());
6839 NewTL
.setQualifierLoc(QualifierLoc
);
6843 template<typename Derived
>
6844 QualType TreeTransform
<Derived
>::TransformAttributedType(
6845 TypeLocBuilder
&TLB
,
6846 AttributedTypeLoc TL
) {
6847 const AttributedType
*oldType
= TL
.getTypePtr();
6848 QualType modifiedType
= getDerived().TransformType(TLB
, TL
.getModifiedLoc());
6849 if (modifiedType
.isNull())
6852 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6853 const Attr
*oldAttr
= TL
.getAttr();
6854 const Attr
*newAttr
= oldAttr
? getDerived().TransformAttr(oldAttr
) : nullptr;
6855 if (oldAttr
&& !newAttr
)
6858 QualType result
= TL
.getType();
6860 // FIXME: dependent operand expressions?
6861 if (getDerived().AlwaysRebuild() ||
6862 modifiedType
!= oldType
->getModifiedType()) {
6863 // TODO: this is really lame; we should really be rebuilding the
6864 // equivalent type from first principles.
6865 QualType equivalentType
6866 = getDerived().TransformType(oldType
->getEquivalentType());
6867 if (equivalentType
.isNull())
6870 // Check whether we can add nullability; it is only represented as
6871 // type sugar, and therefore cannot be diagnosed in any other way.
6872 if (auto nullability
= oldType
->getImmediateNullability()) {
6873 if (!modifiedType
->canHaveNullability()) {
6874 SemaRef
.Diag(TL
.getAttr()->getLocation(),
6875 diag::err_nullability_nonpointer
)
6876 << DiagNullabilityKind(*nullability
, false) << modifiedType
;
6881 result
= SemaRef
.Context
.getAttributedType(TL
.getAttrKind(),
6886 AttributedTypeLoc newTL
= TLB
.push
<AttributedTypeLoc
>(result
);
6887 newTL
.setAttr(newAttr
);
6891 template <typename Derived
>
6892 QualType TreeTransform
<Derived
>::TransformBTFTagAttributedType(
6893 TypeLocBuilder
&TLB
, BTFTagAttributedTypeLoc TL
) {
6894 // The BTFTagAttributedType is available for C only.
6895 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
6898 template<typename Derived
>
6900 TreeTransform
<Derived
>::TransformParenType(TypeLocBuilder
&TLB
,
6902 QualType Inner
= getDerived().TransformType(TLB
, TL
.getInnerLoc());
6906 QualType Result
= TL
.getType();
6907 if (getDerived().AlwaysRebuild() ||
6908 Inner
!= TL
.getInnerLoc().getType()) {
6909 Result
= getDerived().RebuildParenType(Inner
);
6910 if (Result
.isNull())
6914 ParenTypeLoc NewTL
= TLB
.push
<ParenTypeLoc
>(Result
);
6915 NewTL
.setLParenLoc(TL
.getLParenLoc());
6916 NewTL
.setRParenLoc(TL
.getRParenLoc());
6920 template <typename Derived
>
6922 TreeTransform
<Derived
>::TransformMacroQualifiedType(TypeLocBuilder
&TLB
,
6923 MacroQualifiedTypeLoc TL
) {
6924 QualType Inner
= getDerived().TransformType(TLB
, TL
.getInnerLoc());
6928 QualType Result
= TL
.getType();
6929 if (getDerived().AlwaysRebuild() || Inner
!= TL
.getInnerLoc().getType()) {
6931 getDerived().RebuildMacroQualifiedType(Inner
, TL
.getMacroIdentifier());
6932 if (Result
.isNull())
6936 MacroQualifiedTypeLoc NewTL
= TLB
.push
<MacroQualifiedTypeLoc
>(Result
);
6937 NewTL
.setExpansionLoc(TL
.getExpansionLoc());
6941 template<typename Derived
>
6942 QualType TreeTransform
<Derived
>::TransformDependentNameType(
6943 TypeLocBuilder
&TLB
, DependentNameTypeLoc TL
) {
6944 return TransformDependentNameType(TLB
, TL
, false);
6947 template<typename Derived
>
6948 QualType TreeTransform
<Derived
>::TransformDependentNameType(
6949 TypeLocBuilder
&TLB
, DependentNameTypeLoc TL
, bool DeducedTSTContext
) {
6950 const DependentNameType
*T
= TL
.getTypePtr();
6952 NestedNameSpecifierLoc QualifierLoc
6953 = getDerived().TransformNestedNameSpecifierLoc(TL
.getQualifierLoc());
6958 = getDerived().RebuildDependentNameType(T
->getKeyword(),
6959 TL
.getElaboratedKeywordLoc(),
6964 if (Result
.isNull())
6967 if (const ElaboratedType
* ElabT
= Result
->getAs
<ElaboratedType
>()) {
6968 QualType NamedT
= ElabT
->getNamedType();
6969 TLB
.pushTypeSpec(NamedT
).setNameLoc(TL
.getNameLoc());
6971 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
6972 NewTL
.setElaboratedKeywordLoc(TL
.getElaboratedKeywordLoc());
6973 NewTL
.setQualifierLoc(QualifierLoc
);
6975 DependentNameTypeLoc NewTL
= TLB
.push
<DependentNameTypeLoc
>(Result
);
6976 NewTL
.setElaboratedKeywordLoc(TL
.getElaboratedKeywordLoc());
6977 NewTL
.setQualifierLoc(QualifierLoc
);
6978 NewTL
.setNameLoc(TL
.getNameLoc());
6983 template<typename Derived
>
6984 QualType TreeTransform
<Derived
>::
6985 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
6986 DependentTemplateSpecializationTypeLoc TL
) {
6987 NestedNameSpecifierLoc QualifierLoc
;
6988 if (TL
.getQualifierLoc()) {
6990 = getDerived().TransformNestedNameSpecifierLoc(TL
.getQualifierLoc());
6996 .TransformDependentTemplateSpecializationType(TLB
, TL
, QualifierLoc
);
6999 template<typename Derived
>
7000 QualType TreeTransform
<Derived
>::
7001 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
7002 DependentTemplateSpecializationTypeLoc TL
,
7003 NestedNameSpecifierLoc QualifierLoc
) {
7004 const DependentTemplateSpecializationType
*T
= TL
.getTypePtr();
7006 TemplateArgumentListInfo NewTemplateArgs
;
7007 NewTemplateArgs
.setLAngleLoc(TL
.getLAngleLoc());
7008 NewTemplateArgs
.setRAngleLoc(TL
.getRAngleLoc());
7010 typedef TemplateArgumentLocContainerIterator
<
7011 DependentTemplateSpecializationTypeLoc
> ArgIterator
;
7012 if (getDerived().TransformTemplateArguments(ArgIterator(TL
, 0),
7013 ArgIterator(TL
, TL
.getNumArgs()),
7017 QualType Result
= getDerived().RebuildDependentTemplateSpecializationType(
7018 T
->getKeyword(), QualifierLoc
, TL
.getTemplateKeywordLoc(),
7019 T
->getIdentifier(), TL
.getTemplateNameLoc(), NewTemplateArgs
,
7020 /*AllowInjectedClassName*/ false);
7021 if (Result
.isNull())
7024 if (const ElaboratedType
*ElabT
= dyn_cast
<ElaboratedType
>(Result
)) {
7025 QualType NamedT
= ElabT
->getNamedType();
7027 // Copy information relevant to the template specialization.
7028 TemplateSpecializationTypeLoc NamedTL
7029 = TLB
.push
<TemplateSpecializationTypeLoc
>(NamedT
);
7030 NamedTL
.setTemplateKeywordLoc(TL
.getTemplateKeywordLoc());
7031 NamedTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
7032 NamedTL
.setLAngleLoc(TL
.getLAngleLoc());
7033 NamedTL
.setRAngleLoc(TL
.getRAngleLoc());
7034 for (unsigned I
= 0, E
= NewTemplateArgs
.size(); I
!= E
; ++I
)
7035 NamedTL
.setArgLocInfo(I
, NewTemplateArgs
[I
].getLocInfo());
7037 // Copy information relevant to the elaborated type.
7038 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
7039 NewTL
.setElaboratedKeywordLoc(TL
.getElaboratedKeywordLoc());
7040 NewTL
.setQualifierLoc(QualifierLoc
);
7041 } else if (isa
<DependentTemplateSpecializationType
>(Result
)) {
7042 DependentTemplateSpecializationTypeLoc SpecTL
7043 = TLB
.push
<DependentTemplateSpecializationTypeLoc
>(Result
);
7044 SpecTL
.setElaboratedKeywordLoc(TL
.getElaboratedKeywordLoc());
7045 SpecTL
.setQualifierLoc(QualifierLoc
);
7046 SpecTL
.setTemplateKeywordLoc(TL
.getTemplateKeywordLoc());
7047 SpecTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
7048 SpecTL
.setLAngleLoc(TL
.getLAngleLoc());
7049 SpecTL
.setRAngleLoc(TL
.getRAngleLoc());
7050 for (unsigned I
= 0, E
= NewTemplateArgs
.size(); I
!= E
; ++I
)
7051 SpecTL
.setArgLocInfo(I
, NewTemplateArgs
[I
].getLocInfo());
7053 TemplateSpecializationTypeLoc SpecTL
7054 = TLB
.push
<TemplateSpecializationTypeLoc
>(Result
);
7055 SpecTL
.setTemplateKeywordLoc(TL
.getTemplateKeywordLoc());
7056 SpecTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
7057 SpecTL
.setLAngleLoc(TL
.getLAngleLoc());
7058 SpecTL
.setRAngleLoc(TL
.getRAngleLoc());
7059 for (unsigned I
= 0, E
= NewTemplateArgs
.size(); I
!= E
; ++I
)
7060 SpecTL
.setArgLocInfo(I
, NewTemplateArgs
[I
].getLocInfo());
7065 template<typename Derived
>
7066 QualType TreeTransform
<Derived
>::TransformPackExpansionType(TypeLocBuilder
&TLB
,
7067 PackExpansionTypeLoc TL
) {
7069 = getDerived().TransformType(TLB
, TL
.getPatternLoc());
7070 if (Pattern
.isNull())
7073 QualType Result
= TL
.getType();
7074 if (getDerived().AlwaysRebuild() ||
7075 Pattern
!= TL
.getPatternLoc().getType()) {
7076 Result
= getDerived().RebuildPackExpansionType(Pattern
,
7077 TL
.getPatternLoc().getSourceRange(),
7078 TL
.getEllipsisLoc(),
7079 TL
.getTypePtr()->getNumExpansions());
7080 if (Result
.isNull())
7084 PackExpansionTypeLoc NewT
= TLB
.push
<PackExpansionTypeLoc
>(Result
);
7085 NewT
.setEllipsisLoc(TL
.getEllipsisLoc());
7089 template<typename Derived
>
7091 TreeTransform
<Derived
>::TransformObjCInterfaceType(TypeLocBuilder
&TLB
,
7092 ObjCInterfaceTypeLoc TL
) {
7093 // ObjCInterfaceType is never dependent.
7094 TLB
.pushFullCopy(TL
);
7095 return TL
.getType();
7098 template<typename Derived
>
7100 TreeTransform
<Derived
>::TransformObjCTypeParamType(TypeLocBuilder
&TLB
,
7101 ObjCTypeParamTypeLoc TL
) {
7102 const ObjCTypeParamType
*T
= TL
.getTypePtr();
7103 ObjCTypeParamDecl
*OTP
= cast_or_null
<ObjCTypeParamDecl
>(
7104 getDerived().TransformDecl(T
->getDecl()->getLocation(), T
->getDecl()));
7108 QualType Result
= TL
.getType();
7109 if (getDerived().AlwaysRebuild() ||
7110 OTP
!= T
->getDecl()) {
7111 Result
= getDerived().RebuildObjCTypeParamType(OTP
,
7112 TL
.getProtocolLAngleLoc(),
7113 llvm::makeArrayRef(TL
.getTypePtr()->qual_begin(),
7114 TL
.getNumProtocols()),
7115 TL
.getProtocolLocs(),
7116 TL
.getProtocolRAngleLoc());
7117 if (Result
.isNull())
7121 ObjCTypeParamTypeLoc NewTL
= TLB
.push
<ObjCTypeParamTypeLoc
>(Result
);
7122 if (TL
.getNumProtocols()) {
7123 NewTL
.setProtocolLAngleLoc(TL
.getProtocolLAngleLoc());
7124 for (unsigned i
= 0, n
= TL
.getNumProtocols(); i
!= n
; ++i
)
7125 NewTL
.setProtocolLoc(i
, TL
.getProtocolLoc(i
));
7126 NewTL
.setProtocolRAngleLoc(TL
.getProtocolRAngleLoc());
7131 template<typename Derived
>
7133 TreeTransform
<Derived
>::TransformObjCObjectType(TypeLocBuilder
&TLB
,
7134 ObjCObjectTypeLoc TL
) {
7135 // Transform base type.
7136 QualType BaseType
= getDerived().TransformType(TLB
, TL
.getBaseLoc());
7137 if (BaseType
.isNull())
7140 bool AnyChanged
= BaseType
!= TL
.getBaseLoc().getType();
7142 // Transform type arguments.
7143 SmallVector
<TypeSourceInfo
*, 4> NewTypeArgInfos
;
7144 for (unsigned i
= 0, n
= TL
.getNumTypeArgs(); i
!= n
; ++i
) {
7145 TypeSourceInfo
*TypeArgInfo
= TL
.getTypeArgTInfo(i
);
7146 TypeLoc TypeArgLoc
= TypeArgInfo
->getTypeLoc();
7147 QualType TypeArg
= TypeArgInfo
->getType();
7148 if (auto PackExpansionLoc
= TypeArgLoc
.getAs
<PackExpansionTypeLoc
>()) {
7151 // We have a pack expansion. Instantiate it.
7152 const auto *PackExpansion
= PackExpansionLoc
.getType()
7153 ->castAs
<PackExpansionType
>();
7154 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
7155 SemaRef
.collectUnexpandedParameterPacks(PackExpansion
->getPattern(),
7157 assert(!Unexpanded
.empty() && "Pack expansion without parameter packs?");
7159 // Determine whether the set of unexpanded parameter packs can
7160 // and should be expanded.
7161 TypeLoc PatternLoc
= PackExpansionLoc
.getPatternLoc();
7162 bool Expand
= false;
7163 bool RetainExpansion
= false;
7164 Optional
<unsigned> NumExpansions
= PackExpansion
->getNumExpansions();
7165 if (getDerived().TryExpandParameterPacks(
7166 PackExpansionLoc
.getEllipsisLoc(), PatternLoc
.getSourceRange(),
7167 Unexpanded
, Expand
, RetainExpansion
, NumExpansions
))
7171 // We can't expand this pack expansion into separate arguments yet;
7172 // just substitute into the pattern and create a new pack expansion
7174 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
7176 TypeLocBuilder TypeArgBuilder
;
7177 TypeArgBuilder
.reserve(PatternLoc
.getFullDataSize());
7178 QualType NewPatternType
= getDerived().TransformType(TypeArgBuilder
,
7180 if (NewPatternType
.isNull())
7183 QualType NewExpansionType
= SemaRef
.Context
.getPackExpansionType(
7184 NewPatternType
, NumExpansions
);
7185 auto NewExpansionLoc
= TLB
.push
<PackExpansionTypeLoc
>(NewExpansionType
);
7186 NewExpansionLoc
.setEllipsisLoc(PackExpansionLoc
.getEllipsisLoc());
7187 NewTypeArgInfos
.push_back(
7188 TypeArgBuilder
.getTypeSourceInfo(SemaRef
.Context
, NewExpansionType
));
7192 // Substitute into the pack expansion pattern for each slice of the
7194 for (unsigned ArgIdx
= 0; ArgIdx
!= *NumExpansions
; ++ArgIdx
) {
7195 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), ArgIdx
);
7197 TypeLocBuilder TypeArgBuilder
;
7198 TypeArgBuilder
.reserve(PatternLoc
.getFullDataSize());
7200 QualType NewTypeArg
= getDerived().TransformType(TypeArgBuilder
,
7202 if (NewTypeArg
.isNull())
7205 NewTypeArgInfos
.push_back(
7206 TypeArgBuilder
.getTypeSourceInfo(SemaRef
.Context
, NewTypeArg
));
7212 TypeLocBuilder TypeArgBuilder
;
7213 TypeArgBuilder
.reserve(TypeArgLoc
.getFullDataSize());
7214 QualType NewTypeArg
= getDerived().TransformType(TypeArgBuilder
, TypeArgLoc
);
7215 if (NewTypeArg
.isNull())
7218 // If nothing changed, just keep the old TypeSourceInfo.
7219 if (NewTypeArg
== TypeArg
) {
7220 NewTypeArgInfos
.push_back(TypeArgInfo
);
7224 NewTypeArgInfos
.push_back(
7225 TypeArgBuilder
.getTypeSourceInfo(SemaRef
.Context
, NewTypeArg
));
7229 QualType Result
= TL
.getType();
7230 if (getDerived().AlwaysRebuild() || AnyChanged
) {
7231 // Rebuild the type.
7232 Result
= getDerived().RebuildObjCObjectType(
7233 BaseType
, TL
.getBeginLoc(), TL
.getTypeArgsLAngleLoc(), NewTypeArgInfos
,
7234 TL
.getTypeArgsRAngleLoc(), TL
.getProtocolLAngleLoc(),
7235 llvm::makeArrayRef(TL
.getTypePtr()->qual_begin(), TL
.getNumProtocols()),
7236 TL
.getProtocolLocs(), TL
.getProtocolRAngleLoc());
7238 if (Result
.isNull())
7242 ObjCObjectTypeLoc NewT
= TLB
.push
<ObjCObjectTypeLoc
>(Result
);
7243 NewT
.setHasBaseTypeAsWritten(true);
7244 NewT
.setTypeArgsLAngleLoc(TL
.getTypeArgsLAngleLoc());
7245 for (unsigned i
= 0, n
= TL
.getNumTypeArgs(); i
!= n
; ++i
)
7246 NewT
.setTypeArgTInfo(i
, NewTypeArgInfos
[i
]);
7247 NewT
.setTypeArgsRAngleLoc(TL
.getTypeArgsRAngleLoc());
7248 NewT
.setProtocolLAngleLoc(TL
.getProtocolLAngleLoc());
7249 for (unsigned i
= 0, n
= TL
.getNumProtocols(); i
!= n
; ++i
)
7250 NewT
.setProtocolLoc(i
, TL
.getProtocolLoc(i
));
7251 NewT
.setProtocolRAngleLoc(TL
.getProtocolRAngleLoc());
7255 template<typename Derived
>
7257 TreeTransform
<Derived
>::TransformObjCObjectPointerType(TypeLocBuilder
&TLB
,
7258 ObjCObjectPointerTypeLoc TL
) {
7259 QualType PointeeType
= getDerived().TransformType(TLB
, TL
.getPointeeLoc());
7260 if (PointeeType
.isNull())
7263 QualType Result
= TL
.getType();
7264 if (getDerived().AlwaysRebuild() ||
7265 PointeeType
!= TL
.getPointeeLoc().getType()) {
7266 Result
= getDerived().RebuildObjCObjectPointerType(PointeeType
,
7268 if (Result
.isNull())
7272 ObjCObjectPointerTypeLoc NewT
= TLB
.push
<ObjCObjectPointerTypeLoc
>(Result
);
7273 NewT
.setStarLoc(TL
.getStarLoc());
7277 //===----------------------------------------------------------------------===//
7278 // Statement transformation
7279 //===----------------------------------------------------------------------===//
7280 template<typename Derived
>
7282 TreeTransform
<Derived
>::TransformNullStmt(NullStmt
*S
) {
7286 template<typename Derived
>
7288 TreeTransform
<Derived
>::TransformCompoundStmt(CompoundStmt
*S
) {
7289 return getDerived().TransformCompoundStmt(S
, false);
7292 template<typename Derived
>
7294 TreeTransform
<Derived
>::TransformCompoundStmt(CompoundStmt
*S
,
7296 Sema::CompoundScopeRAII
CompoundScope(getSema());
7298 const Stmt
*ExprResult
= S
->getStmtExprResult();
7299 bool SubStmtInvalid
= false;
7300 bool SubStmtChanged
= false;
7301 SmallVector
<Stmt
*, 8> Statements
;
7302 for (auto *B
: S
->body()) {
7303 StmtResult Result
= getDerived().TransformStmt(
7304 B
, IsStmtExpr
&& B
== ExprResult
? SDK_StmtExprResult
: SDK_Discarded
);
7306 if (Result
.isInvalid()) {
7307 // Immediately fail if this was a DeclStmt, since it's very
7308 // likely that this will cause problems for future statements.
7309 if (isa
<DeclStmt
>(B
))
7312 // Otherwise, just keep processing substatements and fail later.
7313 SubStmtInvalid
= true;
7317 SubStmtChanged
= SubStmtChanged
|| Result
.get() != B
;
7318 Statements
.push_back(Result
.getAs
<Stmt
>());
7324 if (!getDerived().AlwaysRebuild() &&
7328 return getDerived().RebuildCompoundStmt(S
->getLBracLoc(),
7334 template<typename Derived
>
7336 TreeTransform
<Derived
>::TransformCaseStmt(CaseStmt
*S
) {
7337 ExprResult LHS
, RHS
;
7339 EnterExpressionEvaluationContext
Unevaluated(
7340 SemaRef
, Sema::ExpressionEvaluationContext::ConstantEvaluated
);
7342 // Transform the left-hand case value.
7343 LHS
= getDerived().TransformExpr(S
->getLHS());
7344 LHS
= SemaRef
.ActOnCaseExpr(S
->getCaseLoc(), LHS
);
7345 if (LHS
.isInvalid())
7348 // Transform the right-hand case value (for the GNU case-range extension).
7349 RHS
= getDerived().TransformExpr(S
->getRHS());
7350 RHS
= SemaRef
.ActOnCaseExpr(S
->getCaseLoc(), RHS
);
7351 if (RHS
.isInvalid())
7355 // Build the case statement.
7356 // Case statements are always rebuilt so that they will attached to their
7357 // transformed switch statement.
7358 StmtResult Case
= getDerived().RebuildCaseStmt(S
->getCaseLoc(),
7360 S
->getEllipsisLoc(),
7363 if (Case
.isInvalid())
7366 // Transform the statement following the case
7367 StmtResult SubStmt
=
7368 getDerived().TransformStmt(S
->getSubStmt());
7369 if (SubStmt
.isInvalid())
7372 // Attach the body to the case statement
7373 return getDerived().RebuildCaseStmtBody(Case
.get(), SubStmt
.get());
7376 template <typename Derived
>
7377 StmtResult TreeTransform
<Derived
>::TransformDefaultStmt(DefaultStmt
*S
) {
7378 // Transform the statement following the default case
7379 StmtResult SubStmt
=
7380 getDerived().TransformStmt(S
->getSubStmt());
7381 if (SubStmt
.isInvalid())
7384 // Default statements are always rebuilt
7385 return getDerived().RebuildDefaultStmt(S
->getDefaultLoc(), S
->getColonLoc(),
7389 template<typename Derived
>
7391 TreeTransform
<Derived
>::TransformLabelStmt(LabelStmt
*S
, StmtDiscardKind SDK
) {
7392 StmtResult SubStmt
= getDerived().TransformStmt(S
->getSubStmt(), SDK
);
7393 if (SubStmt
.isInvalid())
7396 Decl
*LD
= getDerived().TransformDecl(S
->getDecl()->getLocation(),
7401 // If we're transforming "in-place" (we're not creating new local
7402 // declarations), assume we're replacing the old label statement
7403 // and clear out the reference to it.
7404 if (LD
== S
->getDecl())
7405 S
->getDecl()->setStmt(nullptr);
7407 // FIXME: Pass the real colon location in.
7408 return getDerived().RebuildLabelStmt(S
->getIdentLoc(),
7409 cast
<LabelDecl
>(LD
), SourceLocation(),
7413 template <typename Derived
>
7414 const Attr
*TreeTransform
<Derived
>::TransformAttr(const Attr
*R
) {
7418 switch (R
->getKind()) {
7419 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
7421 #define PRAGMA_SPELLING_ATTR(X) \
7423 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
7424 #include "clang/Basic/AttrList.inc"
7430 template <typename Derived
>
7432 TreeTransform
<Derived
>::TransformAttributedStmt(AttributedStmt
*S
,
7433 StmtDiscardKind SDK
) {
7434 bool AttrsChanged
= false;
7435 SmallVector
<const Attr
*, 1> Attrs
;
7437 // Visit attributes and keep track if any are transformed.
7438 for (const auto *I
: S
->getAttrs()) {
7439 const Attr
*R
= getDerived().TransformAttr(I
);
7440 AttrsChanged
|= (I
!= R
);
7445 StmtResult SubStmt
= getDerived().TransformStmt(S
->getSubStmt(), SDK
);
7446 if (SubStmt
.isInvalid())
7449 if (SubStmt
.get() == S
->getSubStmt() && !AttrsChanged
)
7452 // If transforming the attributes failed for all of the attributes in the
7453 // statement, don't make an AttributedStmt without attributes.
7457 return getDerived().RebuildAttributedStmt(S
->getAttrLoc(), Attrs
,
7461 template<typename Derived
>
7463 TreeTransform
<Derived
>::TransformIfStmt(IfStmt
*S
) {
7464 // Transform the initialization statement
7465 StmtResult Init
= getDerived().TransformStmt(S
->getInit());
7466 if (Init
.isInvalid())
7469 Sema::ConditionResult Cond
;
7470 if (!S
->isConsteval()) {
7471 // Transform the condition
7472 Cond
= getDerived().TransformCondition(
7473 S
->getIfLoc(), S
->getConditionVariable(), S
->getCond(),
7474 S
->isConstexpr() ? Sema::ConditionKind::ConstexprIf
7475 : Sema::ConditionKind::Boolean
);
7476 if (Cond
.isInvalid())
7480 // If this is a constexpr if, determine which arm we should instantiate.
7481 llvm::Optional
<bool> ConstexprConditionValue
;
7482 if (S
->isConstexpr())
7483 ConstexprConditionValue
= Cond
.getKnownValue();
7485 // Transform the "then" branch.
7487 if (!ConstexprConditionValue
|| *ConstexprConditionValue
) {
7488 Then
= getDerived().TransformStmt(S
->getThen());
7489 if (Then
.isInvalid())
7492 Then
= new (getSema().Context
) NullStmt(S
->getThen()->getBeginLoc());
7495 // Transform the "else" branch.
7497 if (!ConstexprConditionValue
|| !*ConstexprConditionValue
) {
7498 Else
= getDerived().TransformStmt(S
->getElse());
7499 if (Else
.isInvalid())
7503 if (!getDerived().AlwaysRebuild() &&
7504 Init
.get() == S
->getInit() &&
7505 Cond
.get() == std::make_pair(S
->getConditionVariable(), S
->getCond()) &&
7506 Then
.get() == S
->getThen() &&
7507 Else
.get() == S
->getElse())
7510 return getDerived().RebuildIfStmt(
7511 S
->getIfLoc(), S
->getStatementKind(), S
->getLParenLoc(), Cond
,
7512 S
->getRParenLoc(), Init
.get(), Then
.get(), S
->getElseLoc(), Else
.get());
7515 template<typename Derived
>
7517 TreeTransform
<Derived
>::TransformSwitchStmt(SwitchStmt
*S
) {
7518 // Transform the initialization statement
7519 StmtResult Init
= getDerived().TransformStmt(S
->getInit());
7520 if (Init
.isInvalid())
7523 // Transform the condition.
7524 Sema::ConditionResult Cond
= getDerived().TransformCondition(
7525 S
->getSwitchLoc(), S
->getConditionVariable(), S
->getCond(),
7526 Sema::ConditionKind::Switch
);
7527 if (Cond
.isInvalid())
7530 // Rebuild the switch statement.
7532 getDerived().RebuildSwitchStmtStart(S
->getSwitchLoc(), S
->getLParenLoc(),
7533 Init
.get(), Cond
, S
->getRParenLoc());
7534 if (Switch
.isInvalid())
7537 // Transform the body of the switch statement.
7538 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
7539 if (Body
.isInvalid())
7542 // Complete the switch statement.
7543 return getDerived().RebuildSwitchStmtBody(S
->getSwitchLoc(), Switch
.get(),
7547 template<typename Derived
>
7549 TreeTransform
<Derived
>::TransformWhileStmt(WhileStmt
*S
) {
7550 // Transform the condition
7551 Sema::ConditionResult Cond
= getDerived().TransformCondition(
7552 S
->getWhileLoc(), S
->getConditionVariable(), S
->getCond(),
7553 Sema::ConditionKind::Boolean
);
7554 if (Cond
.isInvalid())
7557 // Transform the body
7558 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
7559 if (Body
.isInvalid())
7562 if (!getDerived().AlwaysRebuild() &&
7563 Cond
.get() == std::make_pair(S
->getConditionVariable(), S
->getCond()) &&
7564 Body
.get() == S
->getBody())
7567 return getDerived().RebuildWhileStmt(S
->getWhileLoc(), S
->getLParenLoc(),
7568 Cond
, S
->getRParenLoc(), Body
.get());
7571 template<typename Derived
>
7573 TreeTransform
<Derived
>::TransformDoStmt(DoStmt
*S
) {
7574 // Transform the body
7575 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
7576 if (Body
.isInvalid())
7579 // Transform the condition
7580 ExprResult Cond
= getDerived().TransformExpr(S
->getCond());
7581 if (Cond
.isInvalid())
7584 if (!getDerived().AlwaysRebuild() &&
7585 Cond
.get() == S
->getCond() &&
7586 Body
.get() == S
->getBody())
7589 return getDerived().RebuildDoStmt(S
->getDoLoc(), Body
.get(), S
->getWhileLoc(),
7590 /*FIXME:*/S
->getWhileLoc(), Cond
.get(),
7594 template<typename Derived
>
7596 TreeTransform
<Derived
>::TransformForStmt(ForStmt
*S
) {
7597 if (getSema().getLangOpts().OpenMP
)
7598 getSema().startOpenMPLoop();
7600 // Transform the initialization statement
7601 StmtResult Init
= getDerived().TransformStmt(S
->getInit());
7602 if (Init
.isInvalid())
7605 // In OpenMP loop region loop control variable must be captured and be
7606 // private. Perform analysis of first part (if any).
7607 if (getSema().getLangOpts().OpenMP
&& Init
.isUsable())
7608 getSema().ActOnOpenMPLoopInitialization(S
->getForLoc(), Init
.get());
7610 // Transform the condition
7611 Sema::ConditionResult Cond
= getDerived().TransformCondition(
7612 S
->getForLoc(), S
->getConditionVariable(), S
->getCond(),
7613 Sema::ConditionKind::Boolean
);
7614 if (Cond
.isInvalid())
7617 // Transform the increment
7618 ExprResult Inc
= getDerived().TransformExpr(S
->getInc());
7619 if (Inc
.isInvalid())
7622 Sema::FullExprArg
FullInc(getSema().MakeFullDiscardedValueExpr(Inc
.get()));
7623 if (S
->getInc() && !FullInc
.get())
7626 // Transform the body
7627 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
7628 if (Body
.isInvalid())
7631 if (!getDerived().AlwaysRebuild() &&
7632 Init
.get() == S
->getInit() &&
7633 Cond
.get() == std::make_pair(S
->getConditionVariable(), S
->getCond()) &&
7634 Inc
.get() == S
->getInc() &&
7635 Body
.get() == S
->getBody())
7638 return getDerived().RebuildForStmt(S
->getForLoc(), S
->getLParenLoc(),
7639 Init
.get(), Cond
, FullInc
,
7640 S
->getRParenLoc(), Body
.get());
7643 template<typename Derived
>
7645 TreeTransform
<Derived
>::TransformGotoStmt(GotoStmt
*S
) {
7646 Decl
*LD
= getDerived().TransformDecl(S
->getLabel()->getLocation(),
7651 // Goto statements must always be rebuilt, to resolve the label.
7652 return getDerived().RebuildGotoStmt(S
->getGotoLoc(), S
->getLabelLoc(),
7653 cast
<LabelDecl
>(LD
));
7656 template<typename Derived
>
7658 TreeTransform
<Derived
>::TransformIndirectGotoStmt(IndirectGotoStmt
*S
) {
7659 ExprResult Target
= getDerived().TransformExpr(S
->getTarget());
7660 if (Target
.isInvalid())
7662 Target
= SemaRef
.MaybeCreateExprWithCleanups(Target
.get());
7664 if (!getDerived().AlwaysRebuild() &&
7665 Target
.get() == S
->getTarget())
7668 return getDerived().RebuildIndirectGotoStmt(S
->getGotoLoc(), S
->getStarLoc(),
7672 template<typename Derived
>
7674 TreeTransform
<Derived
>::TransformContinueStmt(ContinueStmt
*S
) {
7678 template<typename Derived
>
7680 TreeTransform
<Derived
>::TransformBreakStmt(BreakStmt
*S
) {
7684 template<typename Derived
>
7686 TreeTransform
<Derived
>::TransformReturnStmt(ReturnStmt
*S
) {
7687 ExprResult Result
= getDerived().TransformInitializer(S
->getRetValue(),
7688 /*NotCopyInit*/false);
7689 if (Result
.isInvalid())
7692 // FIXME: We always rebuild the return statement because there is no way
7693 // to tell whether the return type of the function has changed.
7694 return getDerived().RebuildReturnStmt(S
->getReturnLoc(), Result
.get());
7697 template<typename Derived
>
7699 TreeTransform
<Derived
>::TransformDeclStmt(DeclStmt
*S
) {
7700 bool DeclChanged
= false;
7701 SmallVector
<Decl
*, 4> Decls
;
7702 for (auto *D
: S
->decls()) {
7703 Decl
*Transformed
= getDerived().TransformDefinition(D
->getLocation(), D
);
7707 if (Transformed
!= D
)
7710 Decls
.push_back(Transformed
);
7713 if (!getDerived().AlwaysRebuild() && !DeclChanged
)
7716 return getDerived().RebuildDeclStmt(Decls
, S
->getBeginLoc(), S
->getEndLoc());
7719 template<typename Derived
>
7721 TreeTransform
<Derived
>::TransformGCCAsmStmt(GCCAsmStmt
*S
) {
7723 SmallVector
<Expr
*, 8> Constraints
;
7724 SmallVector
<Expr
*, 8> Exprs
;
7725 SmallVector
<IdentifierInfo
*, 4> Names
;
7727 ExprResult AsmString
;
7728 SmallVector
<Expr
*, 8> Clobbers
;
7730 bool ExprsChanged
= false;
7732 // Go through the outputs.
7733 for (unsigned I
= 0, E
= S
->getNumOutputs(); I
!= E
; ++I
) {
7734 Names
.push_back(S
->getOutputIdentifier(I
));
7736 // No need to transform the constraint literal.
7737 Constraints
.push_back(S
->getOutputConstraintLiteral(I
));
7739 // Transform the output expr.
7740 Expr
*OutputExpr
= S
->getOutputExpr(I
);
7741 ExprResult Result
= getDerived().TransformExpr(OutputExpr
);
7742 if (Result
.isInvalid())
7745 ExprsChanged
|= Result
.get() != OutputExpr
;
7747 Exprs
.push_back(Result
.get());
7750 // Go through the inputs.
7751 for (unsigned I
= 0, E
= S
->getNumInputs(); I
!= E
; ++I
) {
7752 Names
.push_back(S
->getInputIdentifier(I
));
7754 // No need to transform the constraint literal.
7755 Constraints
.push_back(S
->getInputConstraintLiteral(I
));
7757 // Transform the input expr.
7758 Expr
*InputExpr
= S
->getInputExpr(I
);
7759 ExprResult Result
= getDerived().TransformExpr(InputExpr
);
7760 if (Result
.isInvalid())
7763 ExprsChanged
|= Result
.get() != InputExpr
;
7765 Exprs
.push_back(Result
.get());
7768 // Go through the Labels.
7769 for (unsigned I
= 0, E
= S
->getNumLabels(); I
!= E
; ++I
) {
7770 Names
.push_back(S
->getLabelIdentifier(I
));
7772 ExprResult Result
= getDerived().TransformExpr(S
->getLabelExpr(I
));
7773 if (Result
.isInvalid())
7775 ExprsChanged
|= Result
.get() != S
->getLabelExpr(I
);
7776 Exprs
.push_back(Result
.get());
7778 if (!getDerived().AlwaysRebuild() && !ExprsChanged
)
7781 // Go through the clobbers.
7782 for (unsigned I
= 0, E
= S
->getNumClobbers(); I
!= E
; ++I
)
7783 Clobbers
.push_back(S
->getClobberStringLiteral(I
));
7785 // No need to transform the asm string literal.
7786 AsmString
= S
->getAsmString();
7787 return getDerived().RebuildGCCAsmStmt(S
->getAsmLoc(), S
->isSimple(),
7788 S
->isVolatile(), S
->getNumOutputs(),
7789 S
->getNumInputs(), Names
.data(),
7790 Constraints
, Exprs
, AsmString
.get(),
7791 Clobbers
, S
->getNumLabels(),
7795 template<typename Derived
>
7797 TreeTransform
<Derived
>::TransformMSAsmStmt(MSAsmStmt
*S
) {
7798 ArrayRef
<Token
> AsmToks
=
7799 llvm::makeArrayRef(S
->getAsmToks(), S
->getNumAsmToks());
7801 bool HadError
= false, HadChange
= false;
7803 ArrayRef
<Expr
*> SrcExprs
= S
->getAllExprs();
7804 SmallVector
<Expr
*, 8> TransformedExprs
;
7805 TransformedExprs
.reserve(SrcExprs
.size());
7806 for (unsigned i
= 0, e
= SrcExprs
.size(); i
!= e
; ++i
) {
7807 ExprResult Result
= getDerived().TransformExpr(SrcExprs
[i
]);
7808 if (!Result
.isUsable()) {
7811 HadChange
|= (Result
.get() != SrcExprs
[i
]);
7812 TransformedExprs
.push_back(Result
.get());
7816 if (HadError
) return StmtError();
7817 if (!HadChange
&& !getDerived().AlwaysRebuild())
7820 return getDerived().RebuildMSAsmStmt(S
->getAsmLoc(), S
->getLBraceLoc(),
7821 AsmToks
, S
->getAsmString(),
7822 S
->getNumOutputs(), S
->getNumInputs(),
7823 S
->getAllConstraints(), S
->getClobbers(),
7824 TransformedExprs
, S
->getEndLoc());
7827 // C++ Coroutines TS
7829 template<typename Derived
>
7831 TreeTransform
<Derived
>::TransformCoroutineBodyStmt(CoroutineBodyStmt
*S
) {
7832 auto *ScopeInfo
= SemaRef
.getCurFunction();
7833 auto *FD
= cast
<FunctionDecl
>(SemaRef
.CurContext
);
7834 assert(FD
&& ScopeInfo
&& !ScopeInfo
->CoroutinePromise
&&
7835 ScopeInfo
->NeedsCoroutineSuspends
&&
7836 ScopeInfo
->CoroutineSuspends
.first
== nullptr &&
7837 ScopeInfo
->CoroutineSuspends
.second
== nullptr &&
7838 "expected clean scope info");
7840 // Set that we have (possibly-invalid) suspend points before we do anything
7842 ScopeInfo
->setNeedsCoroutineSuspends(false);
7844 // We re-build the coroutine promise object (and the coroutine parameters its
7845 // type and constructor depend on) based on the types used in our current
7846 // function. We must do so, and set it on the current FunctionScopeInfo,
7847 // before attempting to transform the other parts of the coroutine body
7848 // statement, such as the implicit suspend statements (because those
7849 // statements reference the FunctionScopeInfo::CoroutinePromise).
7850 if (!SemaRef
.buildCoroutineParameterMoves(FD
->getLocation()))
7852 auto *Promise
= SemaRef
.buildCoroutinePromise(FD
->getLocation());
7855 getDerived().transformedLocalDecl(S
->getPromiseDecl(), {Promise
});
7856 ScopeInfo
->CoroutinePromise
= Promise
;
7858 // Transform the implicit coroutine statements constructed using dependent
7859 // types during the previous parse: initial and final suspensions, the return
7860 // object, and others. We also transform the coroutine function's body.
7861 StmtResult InitSuspend
= getDerived().TransformStmt(S
->getInitSuspendStmt());
7862 if (InitSuspend
.isInvalid())
7864 StmtResult FinalSuspend
=
7865 getDerived().TransformStmt(S
->getFinalSuspendStmt());
7866 if (FinalSuspend
.isInvalid() ||
7867 !SemaRef
.checkFinalSuspendNoThrow(FinalSuspend
.get()))
7869 ScopeInfo
->setCoroutineSuspends(InitSuspend
.get(), FinalSuspend
.get());
7870 assert(isa
<Expr
>(InitSuspend
.get()) && isa
<Expr
>(FinalSuspend
.get()));
7872 StmtResult BodyRes
= getDerived().TransformStmt(S
->getBody());
7873 if (BodyRes
.isInvalid())
7876 CoroutineStmtBuilder
Builder(SemaRef
, *FD
, *ScopeInfo
, BodyRes
.get());
7877 if (Builder
.isInvalid())
7880 Expr
*ReturnObject
= S
->getReturnValueInit();
7881 assert(ReturnObject
&& "the return object is expected to be valid");
7882 ExprResult Res
= getDerived().TransformInitializer(ReturnObject
,
7883 /*NoCopyInit*/ false);
7884 if (Res
.isInvalid())
7886 Builder
.ReturnValue
= Res
.get();
7888 // If during the previous parse the coroutine still had a dependent promise
7889 // statement, we may need to build some implicit coroutine statements
7890 // (such as exception and fallthrough handlers) for the first time.
7891 if (S
->hasDependentPromiseType()) {
7892 // We can only build these statements, however, if the current promise type
7893 // is not dependent.
7894 if (!Promise
->getType()->isDependentType()) {
7895 assert(!S
->getFallthroughHandler() && !S
->getExceptionHandler() &&
7896 !S
->getReturnStmtOnAllocFailure() && !S
->getDeallocate() &&
7897 "these nodes should not have been built yet");
7898 if (!Builder
.buildDependentStatements())
7902 if (auto *OnFallthrough
= S
->getFallthroughHandler()) {
7903 StmtResult Res
= getDerived().TransformStmt(OnFallthrough
);
7904 if (Res
.isInvalid())
7906 Builder
.OnFallthrough
= Res
.get();
7909 if (auto *OnException
= S
->getExceptionHandler()) {
7910 StmtResult Res
= getDerived().TransformStmt(OnException
);
7911 if (Res
.isInvalid())
7913 Builder
.OnException
= Res
.get();
7916 if (auto *OnAllocFailure
= S
->getReturnStmtOnAllocFailure()) {
7917 StmtResult Res
= getDerived().TransformStmt(OnAllocFailure
);
7918 if (Res
.isInvalid())
7920 Builder
.ReturnStmtOnAllocFailure
= Res
.get();
7923 // Transform any additional statements we may have already built
7924 assert(S
->getAllocate() && S
->getDeallocate() &&
7925 "allocation and deallocation calls must already be built");
7926 ExprResult AllocRes
= getDerived().TransformExpr(S
->getAllocate());
7927 if (AllocRes
.isInvalid())
7929 Builder
.Allocate
= AllocRes
.get();
7931 ExprResult DeallocRes
= getDerived().TransformExpr(S
->getDeallocate());
7932 if (DeallocRes
.isInvalid())
7934 Builder
.Deallocate
= DeallocRes
.get();
7936 if (auto *ReturnStmt
= S
->getReturnStmt()) {
7937 StmtResult Res
= getDerived().TransformStmt(ReturnStmt
);
7938 if (Res
.isInvalid())
7940 Builder
.ReturnStmt
= Res
.get();
7944 return getDerived().RebuildCoroutineBodyStmt(Builder
);
7947 template<typename Derived
>
7949 TreeTransform
<Derived
>::TransformCoreturnStmt(CoreturnStmt
*S
) {
7950 ExprResult Result
= getDerived().TransformInitializer(S
->getOperand(),
7951 /*NotCopyInit*/false);
7952 if (Result
.isInvalid())
7955 // Always rebuild; we don't know if this needs to be injected into a new
7956 // context or if the promise type has changed.
7957 return getDerived().RebuildCoreturnStmt(S
->getKeywordLoc(), Result
.get(),
7961 template <typename Derived
>
7962 ExprResult TreeTransform
<Derived
>::TransformCoawaitExpr(CoawaitExpr
*E
) {
7963 ExprResult Operand
= getDerived().TransformInitializer(E
->getOperand(),
7964 /*NotCopyInit*/ false);
7965 if (Operand
.isInvalid())
7968 // Rebuild the common-expr from the operand rather than transforming it
7971 // FIXME: getCurScope() should not be used during template instantiation.
7972 // We should pick up the set of unqualified lookup results for operator
7973 // co_await during the initial parse.
7974 ExprResult Lookup
= getSema().BuildOperatorCoawaitLookupExpr(
7975 getSema().getCurScope(), E
->getKeywordLoc());
7977 // Always rebuild; we don't know if this needs to be injected into a new
7978 // context or if the promise type has changed.
7979 return getDerived().RebuildCoawaitExpr(
7980 E
->getKeywordLoc(), Operand
.get(),
7981 cast
<UnresolvedLookupExpr
>(Lookup
.get()), E
->isImplicit());
7984 template <typename Derived
>
7986 TreeTransform
<Derived
>::TransformDependentCoawaitExpr(DependentCoawaitExpr
*E
) {
7987 ExprResult OperandResult
= getDerived().TransformInitializer(E
->getOperand(),
7988 /*NotCopyInit*/ false);
7989 if (OperandResult
.isInvalid())
7992 ExprResult LookupResult
= getDerived().TransformUnresolvedLookupExpr(
7993 E
->getOperatorCoawaitLookup());
7995 if (LookupResult
.isInvalid())
7998 // Always rebuild; we don't know if this needs to be injected into a new
7999 // context or if the promise type has changed.
8000 return getDerived().RebuildDependentCoawaitExpr(
8001 E
->getKeywordLoc(), OperandResult
.get(),
8002 cast
<UnresolvedLookupExpr
>(LookupResult
.get()));
8005 template<typename Derived
>
8007 TreeTransform
<Derived
>::TransformCoyieldExpr(CoyieldExpr
*E
) {
8008 ExprResult Result
= getDerived().TransformInitializer(E
->getOperand(),
8009 /*NotCopyInit*/false);
8010 if (Result
.isInvalid())
8013 // Always rebuild; we don't know if this needs to be injected into a new
8014 // context or if the promise type has changed.
8015 return getDerived().RebuildCoyieldExpr(E
->getKeywordLoc(), Result
.get());
8018 // Objective-C Statements.
8020 template<typename Derived
>
8022 TreeTransform
<Derived
>::TransformObjCAtTryStmt(ObjCAtTryStmt
*S
) {
8023 // Transform the body of the @try.
8024 StmtResult TryBody
= getDerived().TransformStmt(S
->getTryBody());
8025 if (TryBody
.isInvalid())
8028 // Transform the @catch statements (if present).
8029 bool AnyCatchChanged
= false;
8030 SmallVector
<Stmt
*, 8> CatchStmts
;
8031 for (unsigned I
= 0, N
= S
->getNumCatchStmts(); I
!= N
; ++I
) {
8032 StmtResult Catch
= getDerived().TransformStmt(S
->getCatchStmt(I
));
8033 if (Catch
.isInvalid())
8035 if (Catch
.get() != S
->getCatchStmt(I
))
8036 AnyCatchChanged
= true;
8037 CatchStmts
.push_back(Catch
.get());
8040 // Transform the @finally statement (if present).
8042 if (S
->getFinallyStmt()) {
8043 Finally
= getDerived().TransformStmt(S
->getFinallyStmt());
8044 if (Finally
.isInvalid())
8048 // If nothing changed, just retain this statement.
8049 if (!getDerived().AlwaysRebuild() &&
8050 TryBody
.get() == S
->getTryBody() &&
8052 Finally
.get() == S
->getFinallyStmt())
8055 // Build a new statement.
8056 return getDerived().RebuildObjCAtTryStmt(S
->getAtTryLoc(), TryBody
.get(),
8057 CatchStmts
, Finally
.get());
8060 template<typename Derived
>
8062 TreeTransform
<Derived
>::TransformObjCAtCatchStmt(ObjCAtCatchStmt
*S
) {
8063 // Transform the @catch parameter, if there is one.
8064 VarDecl
*Var
= nullptr;
8065 if (VarDecl
*FromVar
= S
->getCatchParamDecl()) {
8066 TypeSourceInfo
*TSInfo
= nullptr;
8067 if (FromVar
->getTypeSourceInfo()) {
8068 TSInfo
= getDerived().TransformType(FromVar
->getTypeSourceInfo());
8075 T
= TSInfo
->getType();
8077 T
= getDerived().TransformType(FromVar
->getType());
8082 Var
= getDerived().RebuildObjCExceptionDecl(FromVar
, TSInfo
, T
);
8087 StmtResult Body
= getDerived().TransformStmt(S
->getCatchBody());
8088 if (Body
.isInvalid())
8091 return getDerived().RebuildObjCAtCatchStmt(S
->getAtCatchLoc(),
8096 template<typename Derived
>
8098 TreeTransform
<Derived
>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt
*S
) {
8099 // Transform the body.
8100 StmtResult Body
= getDerived().TransformStmt(S
->getFinallyBody());
8101 if (Body
.isInvalid())
8104 // If nothing changed, just retain this statement.
8105 if (!getDerived().AlwaysRebuild() &&
8106 Body
.get() == S
->getFinallyBody())
8109 // Build a new statement.
8110 return getDerived().RebuildObjCAtFinallyStmt(S
->getAtFinallyLoc(),
8114 template<typename Derived
>
8116 TreeTransform
<Derived
>::TransformObjCAtThrowStmt(ObjCAtThrowStmt
*S
) {
8118 if (S
->getThrowExpr()) {
8119 Operand
= getDerived().TransformExpr(S
->getThrowExpr());
8120 if (Operand
.isInvalid())
8124 if (!getDerived().AlwaysRebuild() &&
8125 Operand
.get() == S
->getThrowExpr())
8128 return getDerived().RebuildObjCAtThrowStmt(S
->getThrowLoc(), Operand
.get());
8131 template<typename Derived
>
8133 TreeTransform
<Derived
>::TransformObjCAtSynchronizedStmt(
8134 ObjCAtSynchronizedStmt
*S
) {
8135 // Transform the object we are locking.
8136 ExprResult Object
= getDerived().TransformExpr(S
->getSynchExpr());
8137 if (Object
.isInvalid())
8140 getDerived().RebuildObjCAtSynchronizedOperand(S
->getAtSynchronizedLoc(),
8142 if (Object
.isInvalid())
8145 // Transform the body.
8146 StmtResult Body
= getDerived().TransformStmt(S
->getSynchBody());
8147 if (Body
.isInvalid())
8150 // If nothing change, just retain the current statement.
8151 if (!getDerived().AlwaysRebuild() &&
8152 Object
.get() == S
->getSynchExpr() &&
8153 Body
.get() == S
->getSynchBody())
8156 // Build a new statement.
8157 return getDerived().RebuildObjCAtSynchronizedStmt(S
->getAtSynchronizedLoc(),
8158 Object
.get(), Body
.get());
8161 template<typename Derived
>
8163 TreeTransform
<Derived
>::TransformObjCAutoreleasePoolStmt(
8164 ObjCAutoreleasePoolStmt
*S
) {
8165 // Transform the body.
8166 StmtResult Body
= getDerived().TransformStmt(S
->getSubStmt());
8167 if (Body
.isInvalid())
8170 // If nothing changed, just retain this statement.
8171 if (!getDerived().AlwaysRebuild() &&
8172 Body
.get() == S
->getSubStmt())
8175 // Build a new statement.
8176 return getDerived().RebuildObjCAutoreleasePoolStmt(
8177 S
->getAtLoc(), Body
.get());
8180 template<typename Derived
>
8182 TreeTransform
<Derived
>::TransformObjCForCollectionStmt(
8183 ObjCForCollectionStmt
*S
) {
8184 // Transform the element statement.
8185 StmtResult Element
=
8186 getDerived().TransformStmt(S
->getElement(), SDK_NotDiscarded
);
8187 if (Element
.isInvalid())
8190 // Transform the collection expression.
8191 ExprResult Collection
= getDerived().TransformExpr(S
->getCollection());
8192 if (Collection
.isInvalid())
8195 // Transform the body.
8196 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
8197 if (Body
.isInvalid())
8200 // If nothing changed, just retain this statement.
8201 if (!getDerived().AlwaysRebuild() &&
8202 Element
.get() == S
->getElement() &&
8203 Collection
.get() == S
->getCollection() &&
8204 Body
.get() == S
->getBody())
8207 // Build a new statement.
8208 return getDerived().RebuildObjCForCollectionStmt(S
->getForLoc(),
8215 template <typename Derived
>
8216 StmtResult TreeTransform
<Derived
>::TransformCXXCatchStmt(CXXCatchStmt
*S
) {
8217 // Transform the exception declaration, if any.
8218 VarDecl
*Var
= nullptr;
8219 if (VarDecl
*ExceptionDecl
= S
->getExceptionDecl()) {
8221 getDerived().TransformType(ExceptionDecl
->getTypeSourceInfo());
8225 Var
= getDerived().RebuildExceptionDecl(
8226 ExceptionDecl
, T
, ExceptionDecl
->getInnerLocStart(),
8227 ExceptionDecl
->getLocation(), ExceptionDecl
->getIdentifier());
8228 if (!Var
|| Var
->isInvalidDecl())
8232 // Transform the actual exception handler.
8233 StmtResult Handler
= getDerived().TransformStmt(S
->getHandlerBlock());
8234 if (Handler
.isInvalid())
8237 if (!getDerived().AlwaysRebuild() && !Var
&&
8238 Handler
.get() == S
->getHandlerBlock())
8241 return getDerived().RebuildCXXCatchStmt(S
->getCatchLoc(), Var
, Handler
.get());
8244 template <typename Derived
>
8245 StmtResult TreeTransform
<Derived
>::TransformCXXTryStmt(CXXTryStmt
*S
) {
8246 // Transform the try block itself.
8247 StmtResult TryBlock
= getDerived().TransformCompoundStmt(S
->getTryBlock());
8248 if (TryBlock
.isInvalid())
8251 // Transform the handlers.
8252 bool HandlerChanged
= false;
8253 SmallVector
<Stmt
*, 8> Handlers
;
8254 for (unsigned I
= 0, N
= S
->getNumHandlers(); I
!= N
; ++I
) {
8255 StmtResult Handler
= getDerived().TransformCXXCatchStmt(S
->getHandler(I
));
8256 if (Handler
.isInvalid())
8259 HandlerChanged
= HandlerChanged
|| Handler
.get() != S
->getHandler(I
);
8260 Handlers
.push_back(Handler
.getAs
<Stmt
>());
8263 if (!getDerived().AlwaysRebuild() && TryBlock
.get() == S
->getTryBlock() &&
8267 return getDerived().RebuildCXXTryStmt(S
->getTryLoc(), TryBlock
.get(),
8271 template<typename Derived
>
8273 TreeTransform
<Derived
>::TransformCXXForRangeStmt(CXXForRangeStmt
*S
) {
8275 S
->getInit() ? getDerived().TransformStmt(S
->getInit()) : StmtResult();
8276 if (Init
.isInvalid())
8279 StmtResult Range
= getDerived().TransformStmt(S
->getRangeStmt());
8280 if (Range
.isInvalid())
8283 StmtResult Begin
= getDerived().TransformStmt(S
->getBeginStmt());
8284 if (Begin
.isInvalid())
8286 StmtResult End
= getDerived().TransformStmt(S
->getEndStmt());
8287 if (End
.isInvalid())
8290 ExprResult Cond
= getDerived().TransformExpr(S
->getCond());
8291 if (Cond
.isInvalid())
8294 Cond
= SemaRef
.CheckBooleanCondition(S
->getColonLoc(), Cond
.get());
8295 if (Cond
.isInvalid())
8298 Cond
= SemaRef
.MaybeCreateExprWithCleanups(Cond
.get());
8300 ExprResult Inc
= getDerived().TransformExpr(S
->getInc());
8301 if (Inc
.isInvalid())
8304 Inc
= SemaRef
.MaybeCreateExprWithCleanups(Inc
.get());
8306 StmtResult LoopVar
= getDerived().TransformStmt(S
->getLoopVarStmt());
8307 if (LoopVar
.isInvalid())
8310 StmtResult NewStmt
= S
;
8311 if (getDerived().AlwaysRebuild() ||
8312 Init
.get() != S
->getInit() ||
8313 Range
.get() != S
->getRangeStmt() ||
8314 Begin
.get() != S
->getBeginStmt() ||
8315 End
.get() != S
->getEndStmt() ||
8316 Cond
.get() != S
->getCond() ||
8317 Inc
.get() != S
->getInc() ||
8318 LoopVar
.get() != S
->getLoopVarStmt()) {
8319 NewStmt
= getDerived().RebuildCXXForRangeStmt(S
->getForLoc(),
8320 S
->getCoawaitLoc(), Init
.get(),
8321 S
->getColonLoc(), Range
.get(),
8322 Begin
.get(), End
.get(),
8324 Inc
.get(), LoopVar
.get(),
8326 if (NewStmt
.isInvalid() && LoopVar
.get() != S
->getLoopVarStmt()) {
8327 // Might not have attached any initializer to the loop variable.
8328 getSema().ActOnInitializerError(
8329 cast
<DeclStmt
>(LoopVar
.get())->getSingleDecl());
8334 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
8335 if (Body
.isInvalid())
8338 // Body has changed but we didn't rebuild the for-range statement. Rebuild
8339 // it now so we have a new statement to attach the body to.
8340 if (Body
.get() != S
->getBody() && NewStmt
.get() == S
) {
8341 NewStmt
= getDerived().RebuildCXXForRangeStmt(S
->getForLoc(),
8342 S
->getCoawaitLoc(), Init
.get(),
8343 S
->getColonLoc(), Range
.get(),
8344 Begin
.get(), End
.get(),
8346 Inc
.get(), LoopVar
.get(),
8348 if (NewStmt
.isInvalid())
8352 if (NewStmt
.get() == S
)
8355 return FinishCXXForRangeStmt(NewStmt
.get(), Body
.get());
8358 template<typename Derived
>
8360 TreeTransform
<Derived
>::TransformMSDependentExistsStmt(
8361 MSDependentExistsStmt
*S
) {
8362 // Transform the nested-name-specifier, if any.
8363 NestedNameSpecifierLoc QualifierLoc
;
8364 if (S
->getQualifierLoc()) {
8366 = getDerived().TransformNestedNameSpecifierLoc(S
->getQualifierLoc());
8371 // Transform the declaration name.
8372 DeclarationNameInfo NameInfo
= S
->getNameInfo();
8373 if (NameInfo
.getName()) {
8374 NameInfo
= getDerived().TransformDeclarationNameInfo(NameInfo
);
8375 if (!NameInfo
.getName())
8379 // Check whether anything changed.
8380 if (!getDerived().AlwaysRebuild() &&
8381 QualifierLoc
== S
->getQualifierLoc() &&
8382 NameInfo
.getName() == S
->getNameInfo().getName())
8385 // Determine whether this name exists, if we can.
8387 SS
.Adopt(QualifierLoc
);
8388 bool Dependent
= false;
8389 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS
, NameInfo
)) {
8390 case Sema::IER_Exists
:
8391 if (S
->isIfExists())
8394 return new (getSema().Context
) NullStmt(S
->getKeywordLoc());
8396 case Sema::IER_DoesNotExist
:
8397 if (S
->isIfNotExists())
8400 return new (getSema().Context
) NullStmt(S
->getKeywordLoc());
8402 case Sema::IER_Dependent
:
8406 case Sema::IER_Error
:
8410 // We need to continue with the instantiation, so do so now.
8411 StmtResult SubStmt
= getDerived().TransformCompoundStmt(S
->getSubStmt());
8412 if (SubStmt
.isInvalid())
8415 // If we have resolved the name, just transform to the substatement.
8419 // The name is still dependent, so build a dependent expression again.
8420 return getDerived().RebuildMSDependentExistsStmt(S
->getKeywordLoc(),
8427 template<typename Derived
>
8429 TreeTransform
<Derived
>::TransformMSPropertyRefExpr(MSPropertyRefExpr
*E
) {
8430 NestedNameSpecifierLoc QualifierLoc
;
8431 if (E
->getQualifierLoc()) {
8433 = getDerived().TransformNestedNameSpecifierLoc(E
->getQualifierLoc());
8438 MSPropertyDecl
*PD
= cast_or_null
<MSPropertyDecl
>(
8439 getDerived().TransformDecl(E
->getMemberLoc(), E
->getPropertyDecl()));
8443 ExprResult Base
= getDerived().TransformExpr(E
->getBaseExpr());
8444 if (Base
.isInvalid())
8447 return new (SemaRef
.getASTContext())
8448 MSPropertyRefExpr(Base
.get(), PD
, E
->isArrow(),
8449 SemaRef
.getASTContext().PseudoObjectTy
, VK_LValue
,
8450 QualifierLoc
, E
->getMemberLoc());
8453 template <typename Derived
>
8454 ExprResult TreeTransform
<Derived
>::TransformMSPropertySubscriptExpr(
8455 MSPropertySubscriptExpr
*E
) {
8456 auto BaseRes
= getDerived().TransformExpr(E
->getBase());
8457 if (BaseRes
.isInvalid())
8459 auto IdxRes
= getDerived().TransformExpr(E
->getIdx());
8460 if (IdxRes
.isInvalid())
8463 if (!getDerived().AlwaysRebuild() &&
8464 BaseRes
.get() == E
->getBase() &&
8465 IdxRes
.get() == E
->getIdx())
8468 return getDerived().RebuildArraySubscriptExpr(
8469 BaseRes
.get(), SourceLocation(), IdxRes
.get(), E
->getRBracketLoc());
8472 template <typename Derived
>
8473 StmtResult TreeTransform
<Derived
>::TransformSEHTryStmt(SEHTryStmt
*S
) {
8474 StmtResult TryBlock
= getDerived().TransformCompoundStmt(S
->getTryBlock());
8475 if (TryBlock
.isInvalid())
8478 StmtResult Handler
= getDerived().TransformSEHHandler(S
->getHandler());
8479 if (Handler
.isInvalid())
8482 if (!getDerived().AlwaysRebuild() && TryBlock
.get() == S
->getTryBlock() &&
8483 Handler
.get() == S
->getHandler())
8486 return getDerived().RebuildSEHTryStmt(S
->getIsCXXTry(), S
->getTryLoc(),
8487 TryBlock
.get(), Handler
.get());
8490 template <typename Derived
>
8491 StmtResult TreeTransform
<Derived
>::TransformSEHFinallyStmt(SEHFinallyStmt
*S
) {
8492 StmtResult Block
= getDerived().TransformCompoundStmt(S
->getBlock());
8493 if (Block
.isInvalid())
8496 return getDerived().RebuildSEHFinallyStmt(S
->getFinallyLoc(), Block
.get());
8499 template <typename Derived
>
8500 StmtResult TreeTransform
<Derived
>::TransformSEHExceptStmt(SEHExceptStmt
*S
) {
8501 ExprResult FilterExpr
= getDerived().TransformExpr(S
->getFilterExpr());
8502 if (FilterExpr
.isInvalid())
8505 StmtResult Block
= getDerived().TransformCompoundStmt(S
->getBlock());
8506 if (Block
.isInvalid())
8509 return getDerived().RebuildSEHExceptStmt(S
->getExceptLoc(), FilterExpr
.get(),
8513 template <typename Derived
>
8514 StmtResult TreeTransform
<Derived
>::TransformSEHHandler(Stmt
*Handler
) {
8515 if (isa
<SEHFinallyStmt
>(Handler
))
8516 return getDerived().TransformSEHFinallyStmt(cast
<SEHFinallyStmt
>(Handler
));
8518 return getDerived().TransformSEHExceptStmt(cast
<SEHExceptStmt
>(Handler
));
8521 template<typename Derived
>
8523 TreeTransform
<Derived
>::TransformSEHLeaveStmt(SEHLeaveStmt
*S
) {
8527 //===----------------------------------------------------------------------===//
8528 // OpenMP directive transformation
8529 //===----------------------------------------------------------------------===//
8531 template <typename Derived
>
8533 TreeTransform
<Derived
>::TransformOMPCanonicalLoop(OMPCanonicalLoop
*L
) {
8534 // OMPCanonicalLoops are eliminated during transformation, since they will be
8535 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
8536 // after transformation.
8537 return getDerived().TransformStmt(L
->getLoopStmt());
8540 template <typename Derived
>
8541 StmtResult TreeTransform
<Derived
>::TransformOMPExecutableDirective(
8542 OMPExecutableDirective
*D
) {
8544 // Transform the clauses
8545 llvm::SmallVector
<OMPClause
*, 16> TClauses
;
8546 ArrayRef
<OMPClause
*> Clauses
= D
->clauses();
8547 TClauses
.reserve(Clauses
.size());
8548 for (ArrayRef
<OMPClause
*>::iterator I
= Clauses
.begin(), E
= Clauses
.end();
8551 getDerived().getSema().StartOpenMPClause((*I
)->getClauseKind());
8552 OMPClause
*Clause
= getDerived().TransformOMPClause(*I
);
8553 getDerived().getSema().EndOpenMPClause();
8555 TClauses
.push_back(Clause
);
8557 TClauses
.push_back(nullptr);
8560 StmtResult AssociatedStmt
;
8561 if (D
->hasAssociatedStmt() && D
->getAssociatedStmt()) {
8562 getDerived().getSema().ActOnOpenMPRegionStart(D
->getDirectiveKind(),
8563 /*CurScope=*/nullptr);
8566 Sema::CompoundScopeRAII
CompoundScope(getSema());
8568 if (D
->getDirectiveKind() == OMPD_atomic
||
8569 D
->getDirectiveKind() == OMPD_critical
||
8570 D
->getDirectiveKind() == OMPD_section
||
8571 D
->getDirectiveKind() == OMPD_master
)
8572 CS
= D
->getAssociatedStmt();
8574 CS
= D
->getRawStmt();
8575 Body
= getDerived().TransformStmt(CS
);
8576 if (Body
.isUsable() && isOpenMPLoopDirective(D
->getDirectiveKind()) &&
8577 getSema().getLangOpts().OpenMPIRBuilder
)
8578 Body
= getDerived().RebuildOMPCanonicalLoop(Body
.get());
8581 getDerived().getSema().ActOnOpenMPRegionEnd(Body
, TClauses
);
8582 if (AssociatedStmt
.isInvalid()) {
8586 if (TClauses
.size() != Clauses
.size()) {
8590 // Transform directive name for 'omp critical' directive.
8591 DeclarationNameInfo DirName
;
8592 if (D
->getDirectiveKind() == OMPD_critical
) {
8593 DirName
= cast
<OMPCriticalDirective
>(D
)->getDirectiveName();
8594 DirName
= getDerived().TransformDeclarationNameInfo(DirName
);
8596 OpenMPDirectiveKind CancelRegion
= OMPD_unknown
;
8597 if (D
->getDirectiveKind() == OMPD_cancellation_point
) {
8598 CancelRegion
= cast
<OMPCancellationPointDirective
>(D
)->getCancelRegion();
8599 } else if (D
->getDirectiveKind() == OMPD_cancel
) {
8600 CancelRegion
= cast
<OMPCancelDirective
>(D
)->getCancelRegion();
8603 return getDerived().RebuildOMPExecutableDirective(
8604 D
->getDirectiveKind(), DirName
, CancelRegion
, TClauses
,
8605 AssociatedStmt
.get(), D
->getBeginLoc(), D
->getEndLoc());
8608 template <typename Derived
>
8610 TreeTransform
<Derived
>::TransformOMPMetaDirective(OMPMetaDirective
*D
) {
8612 SemaRef
.Diag(D
->getBeginLoc(), diag::err_omp_instantiation_not_supported
)
8613 << getOpenMPDirectiveName(D
->getDirectiveKind());
8617 template <typename Derived
>
8619 TreeTransform
<Derived
>::TransformOMPParallelDirective(OMPParallelDirective
*D
) {
8620 DeclarationNameInfo DirName
;
8621 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel
, DirName
, nullptr,
8623 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8624 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8628 template <typename Derived
>
8630 TreeTransform
<Derived
>::TransformOMPSimdDirective(OMPSimdDirective
*D
) {
8631 DeclarationNameInfo DirName
;
8632 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd
, DirName
, nullptr,
8634 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8635 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8639 template <typename Derived
>
8641 TreeTransform
<Derived
>::TransformOMPTileDirective(OMPTileDirective
*D
) {
8642 DeclarationNameInfo DirName
;
8643 getDerived().getSema().StartOpenMPDSABlock(D
->getDirectiveKind(), DirName
,
8644 nullptr, D
->getBeginLoc());
8645 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8646 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8650 template <typename Derived
>
8652 TreeTransform
<Derived
>::TransformOMPUnrollDirective(OMPUnrollDirective
*D
) {
8653 DeclarationNameInfo DirName
;
8654 getDerived().getSema().StartOpenMPDSABlock(D
->getDirectiveKind(), DirName
,
8655 nullptr, D
->getBeginLoc());
8656 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8657 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8661 template <typename Derived
>
8663 TreeTransform
<Derived
>::TransformOMPForDirective(OMPForDirective
*D
) {
8664 DeclarationNameInfo DirName
;
8665 getDerived().getSema().StartOpenMPDSABlock(OMPD_for
, DirName
, nullptr,
8667 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8668 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8672 template <typename Derived
>
8674 TreeTransform
<Derived
>::TransformOMPForSimdDirective(OMPForSimdDirective
*D
) {
8675 DeclarationNameInfo DirName
;
8676 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd
, DirName
, nullptr,
8678 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8679 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8683 template <typename Derived
>
8685 TreeTransform
<Derived
>::TransformOMPSectionsDirective(OMPSectionsDirective
*D
) {
8686 DeclarationNameInfo DirName
;
8687 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections
, DirName
, nullptr,
8689 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8690 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8694 template <typename Derived
>
8696 TreeTransform
<Derived
>::TransformOMPSectionDirective(OMPSectionDirective
*D
) {
8697 DeclarationNameInfo DirName
;
8698 getDerived().getSema().StartOpenMPDSABlock(OMPD_section
, DirName
, nullptr,
8700 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8701 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8705 template <typename Derived
>
8707 TreeTransform
<Derived
>::TransformOMPSingleDirective(OMPSingleDirective
*D
) {
8708 DeclarationNameInfo DirName
;
8709 getDerived().getSema().StartOpenMPDSABlock(OMPD_single
, DirName
, nullptr,
8711 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8712 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8716 template <typename Derived
>
8718 TreeTransform
<Derived
>::TransformOMPMasterDirective(OMPMasterDirective
*D
) {
8719 DeclarationNameInfo DirName
;
8720 getDerived().getSema().StartOpenMPDSABlock(OMPD_master
, DirName
, nullptr,
8722 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8723 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8727 template <typename Derived
>
8729 TreeTransform
<Derived
>::TransformOMPCriticalDirective(OMPCriticalDirective
*D
) {
8730 getDerived().getSema().StartOpenMPDSABlock(
8731 OMPD_critical
, D
->getDirectiveName(), nullptr, D
->getBeginLoc());
8732 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8733 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8737 template <typename Derived
>
8738 StmtResult TreeTransform
<Derived
>::TransformOMPParallelForDirective(
8739 OMPParallelForDirective
*D
) {
8740 DeclarationNameInfo DirName
;
8741 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for
, DirName
,
8742 nullptr, D
->getBeginLoc());
8743 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8744 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8748 template <typename Derived
>
8749 StmtResult TreeTransform
<Derived
>::TransformOMPParallelForSimdDirective(
8750 OMPParallelForSimdDirective
*D
) {
8751 DeclarationNameInfo DirName
;
8752 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd
, DirName
,
8753 nullptr, D
->getBeginLoc());
8754 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8755 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8759 template <typename Derived
>
8760 StmtResult TreeTransform
<Derived
>::TransformOMPParallelMasterDirective(
8761 OMPParallelMasterDirective
*D
) {
8762 DeclarationNameInfo DirName
;
8763 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master
, DirName
,
8764 nullptr, D
->getBeginLoc());
8765 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8766 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8770 template <typename Derived
>
8771 StmtResult TreeTransform
<Derived
>::TransformOMPParallelMaskedDirective(
8772 OMPParallelMaskedDirective
*D
) {
8773 DeclarationNameInfo DirName
;
8774 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_masked
, DirName
,
8775 nullptr, D
->getBeginLoc());
8776 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8777 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8781 template <typename Derived
>
8782 StmtResult TreeTransform
<Derived
>::TransformOMPParallelSectionsDirective(
8783 OMPParallelSectionsDirective
*D
) {
8784 DeclarationNameInfo DirName
;
8785 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections
, DirName
,
8786 nullptr, D
->getBeginLoc());
8787 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8788 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8792 template <typename Derived
>
8794 TreeTransform
<Derived
>::TransformOMPTaskDirective(OMPTaskDirective
*D
) {
8795 DeclarationNameInfo DirName
;
8796 getDerived().getSema().StartOpenMPDSABlock(OMPD_task
, DirName
, nullptr,
8798 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8799 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8803 template <typename Derived
>
8804 StmtResult TreeTransform
<Derived
>::TransformOMPTaskyieldDirective(
8805 OMPTaskyieldDirective
*D
) {
8806 DeclarationNameInfo DirName
;
8807 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield
, DirName
, nullptr,
8809 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8810 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8814 template <typename Derived
>
8816 TreeTransform
<Derived
>::TransformOMPBarrierDirective(OMPBarrierDirective
*D
) {
8817 DeclarationNameInfo DirName
;
8818 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier
, DirName
, nullptr,
8820 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8821 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8825 template <typename Derived
>
8827 TreeTransform
<Derived
>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective
*D
) {
8828 DeclarationNameInfo DirName
;
8829 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait
, DirName
, nullptr,
8831 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8832 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8836 template <typename Derived
>
8837 StmtResult TreeTransform
<Derived
>::TransformOMPTaskgroupDirective(
8838 OMPTaskgroupDirective
*D
) {
8839 DeclarationNameInfo DirName
;
8840 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup
, DirName
, nullptr,
8842 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8843 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8847 template <typename Derived
>
8849 TreeTransform
<Derived
>::TransformOMPFlushDirective(OMPFlushDirective
*D
) {
8850 DeclarationNameInfo DirName
;
8851 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush
, DirName
, nullptr,
8853 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8854 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8858 template <typename Derived
>
8860 TreeTransform
<Derived
>::TransformOMPDepobjDirective(OMPDepobjDirective
*D
) {
8861 DeclarationNameInfo DirName
;
8862 getDerived().getSema().StartOpenMPDSABlock(OMPD_depobj
, DirName
, nullptr,
8864 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8865 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8869 template <typename Derived
>
8871 TreeTransform
<Derived
>::TransformOMPScanDirective(OMPScanDirective
*D
) {
8872 DeclarationNameInfo DirName
;
8873 getDerived().getSema().StartOpenMPDSABlock(OMPD_scan
, DirName
, nullptr,
8875 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8876 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8880 template <typename Derived
>
8882 TreeTransform
<Derived
>::TransformOMPOrderedDirective(OMPOrderedDirective
*D
) {
8883 DeclarationNameInfo DirName
;
8884 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered
, DirName
, nullptr,
8886 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8887 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8891 template <typename Derived
>
8893 TreeTransform
<Derived
>::TransformOMPAtomicDirective(OMPAtomicDirective
*D
) {
8894 DeclarationNameInfo DirName
;
8895 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic
, DirName
, nullptr,
8897 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8898 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8902 template <typename Derived
>
8904 TreeTransform
<Derived
>::TransformOMPTargetDirective(OMPTargetDirective
*D
) {
8905 DeclarationNameInfo DirName
;
8906 getDerived().getSema().StartOpenMPDSABlock(OMPD_target
, DirName
, nullptr,
8908 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8909 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8913 template <typename Derived
>
8914 StmtResult TreeTransform
<Derived
>::TransformOMPTargetDataDirective(
8915 OMPTargetDataDirective
*D
) {
8916 DeclarationNameInfo DirName
;
8917 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data
, DirName
, nullptr,
8919 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8920 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8924 template <typename Derived
>
8925 StmtResult TreeTransform
<Derived
>::TransformOMPTargetEnterDataDirective(
8926 OMPTargetEnterDataDirective
*D
) {
8927 DeclarationNameInfo DirName
;
8928 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data
, DirName
,
8929 nullptr, D
->getBeginLoc());
8930 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8931 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8935 template <typename Derived
>
8936 StmtResult TreeTransform
<Derived
>::TransformOMPTargetExitDataDirective(
8937 OMPTargetExitDataDirective
*D
) {
8938 DeclarationNameInfo DirName
;
8939 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data
, DirName
,
8940 nullptr, D
->getBeginLoc());
8941 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8942 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8946 template <typename Derived
>
8947 StmtResult TreeTransform
<Derived
>::TransformOMPTargetParallelDirective(
8948 OMPTargetParallelDirective
*D
) {
8949 DeclarationNameInfo DirName
;
8950 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel
, DirName
,
8951 nullptr, D
->getBeginLoc());
8952 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8953 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8957 template <typename Derived
>
8958 StmtResult TreeTransform
<Derived
>::TransformOMPTargetParallelForDirective(
8959 OMPTargetParallelForDirective
*D
) {
8960 DeclarationNameInfo DirName
;
8961 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for
, DirName
,
8962 nullptr, D
->getBeginLoc());
8963 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8964 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8968 template <typename Derived
>
8969 StmtResult TreeTransform
<Derived
>::TransformOMPTargetUpdateDirective(
8970 OMPTargetUpdateDirective
*D
) {
8971 DeclarationNameInfo DirName
;
8972 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update
, DirName
,
8973 nullptr, D
->getBeginLoc());
8974 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8975 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8979 template <typename Derived
>
8981 TreeTransform
<Derived
>::TransformOMPTeamsDirective(OMPTeamsDirective
*D
) {
8982 DeclarationNameInfo DirName
;
8983 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams
, DirName
, nullptr,
8985 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8986 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
8990 template <typename Derived
>
8991 StmtResult TreeTransform
<Derived
>::TransformOMPCancellationPointDirective(
8992 OMPCancellationPointDirective
*D
) {
8993 DeclarationNameInfo DirName
;
8994 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point
, DirName
,
8995 nullptr, D
->getBeginLoc());
8996 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
8997 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9001 template <typename Derived
>
9003 TreeTransform
<Derived
>::TransformOMPCancelDirective(OMPCancelDirective
*D
) {
9004 DeclarationNameInfo DirName
;
9005 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel
, DirName
, nullptr,
9007 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9008 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9012 template <typename Derived
>
9014 TreeTransform
<Derived
>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective
*D
) {
9015 DeclarationNameInfo DirName
;
9016 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop
, DirName
, nullptr,
9018 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9019 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9023 template <typename Derived
>
9024 StmtResult TreeTransform
<Derived
>::TransformOMPTaskLoopSimdDirective(
9025 OMPTaskLoopSimdDirective
*D
) {
9026 DeclarationNameInfo DirName
;
9027 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd
, DirName
,
9028 nullptr, D
->getBeginLoc());
9029 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9030 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9034 template <typename Derived
>
9035 StmtResult TreeTransform
<Derived
>::TransformOMPMasterTaskLoopDirective(
9036 OMPMasterTaskLoopDirective
*D
) {
9037 DeclarationNameInfo DirName
;
9038 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop
, DirName
,
9039 nullptr, D
->getBeginLoc());
9040 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9041 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9045 template <typename Derived
>
9046 StmtResult TreeTransform
<Derived
>::TransformOMPMaskedTaskLoopDirective(
9047 OMPMaskedTaskLoopDirective
*D
) {
9048 DeclarationNameInfo DirName
;
9049 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked_taskloop
, DirName
,
9050 nullptr, D
->getBeginLoc());
9051 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9052 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9056 template <typename Derived
>
9057 StmtResult TreeTransform
<Derived
>::TransformOMPMasterTaskLoopSimdDirective(
9058 OMPMasterTaskLoopSimdDirective
*D
) {
9059 DeclarationNameInfo DirName
;
9060 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop_simd
, DirName
,
9061 nullptr, D
->getBeginLoc());
9062 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9063 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9067 template <typename Derived
>
9068 StmtResult TreeTransform
<Derived
>::TransformOMPMaskedTaskLoopSimdDirective(
9069 OMPMaskedTaskLoopSimdDirective
*D
) {
9070 DeclarationNameInfo DirName
;
9071 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked_taskloop_simd
, DirName
,
9072 nullptr, D
->getBeginLoc());
9073 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9074 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9078 template <typename Derived
>
9079 StmtResult TreeTransform
<Derived
>::TransformOMPParallelMasterTaskLoopDirective(
9080 OMPParallelMasterTaskLoopDirective
*D
) {
9081 DeclarationNameInfo DirName
;
9082 getDerived().getSema().StartOpenMPDSABlock(
9083 OMPD_parallel_master_taskloop
, DirName
, nullptr, D
->getBeginLoc());
9084 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9085 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9089 template <typename Derived
>
9090 StmtResult TreeTransform
<Derived
>::TransformOMPParallelMaskedTaskLoopDirective(
9091 OMPParallelMaskedTaskLoopDirective
*D
) {
9092 DeclarationNameInfo DirName
;
9093 getDerived().getSema().StartOpenMPDSABlock(
9094 OMPD_parallel_masked_taskloop
, DirName
, nullptr, D
->getBeginLoc());
9095 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9096 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9100 template <typename Derived
>
9102 TreeTransform
<Derived
>::TransformOMPParallelMasterTaskLoopSimdDirective(
9103 OMPParallelMasterTaskLoopSimdDirective
*D
) {
9104 DeclarationNameInfo DirName
;
9105 getDerived().getSema().StartOpenMPDSABlock(
9106 OMPD_parallel_master_taskloop_simd
, DirName
, nullptr, D
->getBeginLoc());
9107 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9108 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9112 template <typename Derived
>
9114 TreeTransform
<Derived
>::TransformOMPParallelMaskedTaskLoopSimdDirective(
9115 OMPParallelMaskedTaskLoopSimdDirective
*D
) {
9116 DeclarationNameInfo DirName
;
9117 getDerived().getSema().StartOpenMPDSABlock(
9118 OMPD_parallel_masked_taskloop_simd
, DirName
, nullptr, D
->getBeginLoc());
9119 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9120 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9124 template <typename Derived
>
9125 StmtResult TreeTransform
<Derived
>::TransformOMPDistributeDirective(
9126 OMPDistributeDirective
*D
) {
9127 DeclarationNameInfo DirName
;
9128 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute
, DirName
, nullptr,
9130 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9131 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9135 template <typename Derived
>
9136 StmtResult TreeTransform
<Derived
>::TransformOMPDistributeParallelForDirective(
9137 OMPDistributeParallelForDirective
*D
) {
9138 DeclarationNameInfo DirName
;
9139 getDerived().getSema().StartOpenMPDSABlock(
9140 OMPD_distribute_parallel_for
, DirName
, nullptr, D
->getBeginLoc());
9141 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9142 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9146 template <typename Derived
>
9148 TreeTransform
<Derived
>::TransformOMPDistributeParallelForSimdDirective(
9149 OMPDistributeParallelForSimdDirective
*D
) {
9150 DeclarationNameInfo DirName
;
9151 getDerived().getSema().StartOpenMPDSABlock(
9152 OMPD_distribute_parallel_for_simd
, DirName
, nullptr, D
->getBeginLoc());
9153 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9154 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9158 template <typename Derived
>
9159 StmtResult TreeTransform
<Derived
>::TransformOMPDistributeSimdDirective(
9160 OMPDistributeSimdDirective
*D
) {
9161 DeclarationNameInfo DirName
;
9162 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd
, DirName
,
9163 nullptr, D
->getBeginLoc());
9164 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9165 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9169 template <typename Derived
>
9170 StmtResult TreeTransform
<Derived
>::TransformOMPTargetParallelForSimdDirective(
9171 OMPTargetParallelForSimdDirective
*D
) {
9172 DeclarationNameInfo DirName
;
9173 getDerived().getSema().StartOpenMPDSABlock(
9174 OMPD_target_parallel_for_simd
, DirName
, nullptr, D
->getBeginLoc());
9175 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9176 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9180 template <typename Derived
>
9181 StmtResult TreeTransform
<Derived
>::TransformOMPTargetSimdDirective(
9182 OMPTargetSimdDirective
*D
) {
9183 DeclarationNameInfo DirName
;
9184 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd
, DirName
, nullptr,
9186 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9187 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9191 template <typename Derived
>
9192 StmtResult TreeTransform
<Derived
>::TransformOMPTeamsDistributeDirective(
9193 OMPTeamsDistributeDirective
*D
) {
9194 DeclarationNameInfo DirName
;
9195 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute
, DirName
,
9196 nullptr, D
->getBeginLoc());
9197 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9198 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9202 template <typename Derived
>
9203 StmtResult TreeTransform
<Derived
>::TransformOMPTeamsDistributeSimdDirective(
9204 OMPTeamsDistributeSimdDirective
*D
) {
9205 DeclarationNameInfo DirName
;
9206 getDerived().getSema().StartOpenMPDSABlock(
9207 OMPD_teams_distribute_simd
, DirName
, nullptr, D
->getBeginLoc());
9208 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9209 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9213 template <typename Derived
>
9214 StmtResult TreeTransform
<Derived
>::TransformOMPTeamsDistributeParallelForSimdDirective(
9215 OMPTeamsDistributeParallelForSimdDirective
*D
) {
9216 DeclarationNameInfo DirName
;
9217 getDerived().getSema().StartOpenMPDSABlock(
9218 OMPD_teams_distribute_parallel_for_simd
, DirName
, nullptr,
9220 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9221 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9225 template <typename Derived
>
9226 StmtResult TreeTransform
<Derived
>::TransformOMPTeamsDistributeParallelForDirective(
9227 OMPTeamsDistributeParallelForDirective
*D
) {
9228 DeclarationNameInfo DirName
;
9229 getDerived().getSema().StartOpenMPDSABlock(
9230 OMPD_teams_distribute_parallel_for
, DirName
, nullptr, D
->getBeginLoc());
9231 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9232 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9236 template <typename Derived
>
9237 StmtResult TreeTransform
<Derived
>::TransformOMPTargetTeamsDirective(
9238 OMPTargetTeamsDirective
*D
) {
9239 DeclarationNameInfo DirName
;
9240 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams
, DirName
,
9241 nullptr, D
->getBeginLoc());
9242 auto Res
= getDerived().TransformOMPExecutableDirective(D
);
9243 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9247 template <typename Derived
>
9248 StmtResult TreeTransform
<Derived
>::TransformOMPTargetTeamsDistributeDirective(
9249 OMPTargetTeamsDistributeDirective
*D
) {
9250 DeclarationNameInfo DirName
;
9251 getDerived().getSema().StartOpenMPDSABlock(
9252 OMPD_target_teams_distribute
, DirName
, nullptr, D
->getBeginLoc());
9253 auto Res
= getDerived().TransformOMPExecutableDirective(D
);
9254 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9258 template <typename Derived
>
9260 TreeTransform
<Derived
>::TransformOMPTargetTeamsDistributeParallelForDirective(
9261 OMPTargetTeamsDistributeParallelForDirective
*D
) {
9262 DeclarationNameInfo DirName
;
9263 getDerived().getSema().StartOpenMPDSABlock(
9264 OMPD_target_teams_distribute_parallel_for
, DirName
, nullptr,
9266 auto Res
= getDerived().TransformOMPExecutableDirective(D
);
9267 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9271 template <typename Derived
>
9272 StmtResult TreeTransform
<Derived
>::
9273 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
9274 OMPTargetTeamsDistributeParallelForSimdDirective
*D
) {
9275 DeclarationNameInfo DirName
;
9276 getDerived().getSema().StartOpenMPDSABlock(
9277 OMPD_target_teams_distribute_parallel_for_simd
, DirName
, nullptr,
9279 auto Res
= getDerived().TransformOMPExecutableDirective(D
);
9280 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9284 template <typename Derived
>
9286 TreeTransform
<Derived
>::TransformOMPTargetTeamsDistributeSimdDirective(
9287 OMPTargetTeamsDistributeSimdDirective
*D
) {
9288 DeclarationNameInfo DirName
;
9289 getDerived().getSema().StartOpenMPDSABlock(
9290 OMPD_target_teams_distribute_simd
, DirName
, nullptr, D
->getBeginLoc());
9291 auto Res
= getDerived().TransformOMPExecutableDirective(D
);
9292 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9296 template <typename Derived
>
9298 TreeTransform
<Derived
>::TransformOMPInteropDirective(OMPInteropDirective
*D
) {
9299 DeclarationNameInfo DirName
;
9300 getDerived().getSema().StartOpenMPDSABlock(OMPD_interop
, DirName
, nullptr,
9302 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9303 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9307 template <typename Derived
>
9309 TreeTransform
<Derived
>::TransformOMPDispatchDirective(OMPDispatchDirective
*D
) {
9310 DeclarationNameInfo DirName
;
9311 getDerived().getSema().StartOpenMPDSABlock(OMPD_dispatch
, DirName
, nullptr,
9313 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9314 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9318 template <typename Derived
>
9320 TreeTransform
<Derived
>::TransformOMPMaskedDirective(OMPMaskedDirective
*D
) {
9321 DeclarationNameInfo DirName
;
9322 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked
, DirName
, nullptr,
9324 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9325 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9329 template <typename Derived
>
9330 StmtResult TreeTransform
<Derived
>::TransformOMPGenericLoopDirective(
9331 OMPGenericLoopDirective
*D
) {
9332 DeclarationNameInfo DirName
;
9333 getDerived().getSema().StartOpenMPDSABlock(OMPD_loop
, DirName
, nullptr,
9335 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9336 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9340 template <typename Derived
>
9341 StmtResult TreeTransform
<Derived
>::TransformOMPTeamsGenericLoopDirective(
9342 OMPTeamsGenericLoopDirective
*D
) {
9343 DeclarationNameInfo DirName
;
9344 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_loop
, DirName
, nullptr,
9346 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9347 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9351 template <typename Derived
>
9352 StmtResult TreeTransform
<Derived
>::TransformOMPTargetTeamsGenericLoopDirective(
9353 OMPTargetTeamsGenericLoopDirective
*D
) {
9354 DeclarationNameInfo DirName
;
9355 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_loop
, DirName
,
9356 nullptr, D
->getBeginLoc());
9357 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9358 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9362 template <typename Derived
>
9363 StmtResult TreeTransform
<Derived
>::TransformOMPParallelGenericLoopDirective(
9364 OMPParallelGenericLoopDirective
*D
) {
9365 DeclarationNameInfo DirName
;
9366 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_loop
, DirName
,
9367 nullptr, D
->getBeginLoc());
9368 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9369 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9373 template <typename Derived
>
9375 TreeTransform
<Derived
>::TransformOMPTargetParallelGenericLoopDirective(
9376 OMPTargetParallelGenericLoopDirective
*D
) {
9377 DeclarationNameInfo DirName
;
9378 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_loop
, DirName
,
9379 nullptr, D
->getBeginLoc());
9380 StmtResult Res
= getDerived().TransformOMPExecutableDirective(D
);
9381 getDerived().getSema().EndOpenMPDSABlock(Res
.get());
9385 //===----------------------------------------------------------------------===//
9386 // OpenMP clause transformation
9387 //===----------------------------------------------------------------------===//
9388 template <typename Derived
>
9389 OMPClause
*TreeTransform
<Derived
>::TransformOMPIfClause(OMPIfClause
*C
) {
9390 ExprResult Cond
= getDerived().TransformExpr(C
->getCondition());
9391 if (Cond
.isInvalid())
9393 return getDerived().RebuildOMPIfClause(
9394 C
->getNameModifier(), Cond
.get(), C
->getBeginLoc(), C
->getLParenLoc(),
9395 C
->getNameModifierLoc(), C
->getColonLoc(), C
->getEndLoc());
9398 template <typename Derived
>
9399 OMPClause
*TreeTransform
<Derived
>::TransformOMPFinalClause(OMPFinalClause
*C
) {
9400 ExprResult Cond
= getDerived().TransformExpr(C
->getCondition());
9401 if (Cond
.isInvalid())
9403 return getDerived().RebuildOMPFinalClause(Cond
.get(), C
->getBeginLoc(),
9404 C
->getLParenLoc(), C
->getEndLoc());
9407 template <typename Derived
>
9409 TreeTransform
<Derived
>::TransformOMPNumThreadsClause(OMPNumThreadsClause
*C
) {
9410 ExprResult NumThreads
= getDerived().TransformExpr(C
->getNumThreads());
9411 if (NumThreads
.isInvalid())
9413 return getDerived().RebuildOMPNumThreadsClause(
9414 NumThreads
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9417 template <typename Derived
>
9419 TreeTransform
<Derived
>::TransformOMPSafelenClause(OMPSafelenClause
*C
) {
9420 ExprResult E
= getDerived().TransformExpr(C
->getSafelen());
9423 return getDerived().RebuildOMPSafelenClause(
9424 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9427 template <typename Derived
>
9429 TreeTransform
<Derived
>::TransformOMPAllocatorClause(OMPAllocatorClause
*C
) {
9430 ExprResult E
= getDerived().TransformExpr(C
->getAllocator());
9433 return getDerived().RebuildOMPAllocatorClause(
9434 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9437 template <typename Derived
>
9439 TreeTransform
<Derived
>::TransformOMPSimdlenClause(OMPSimdlenClause
*C
) {
9440 ExprResult E
= getDerived().TransformExpr(C
->getSimdlen());
9443 return getDerived().RebuildOMPSimdlenClause(
9444 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9447 template <typename Derived
>
9448 OMPClause
*TreeTransform
<Derived
>::TransformOMPSizesClause(OMPSizesClause
*C
) {
9449 SmallVector
<Expr
*, 4> TransformedSizes
;
9450 TransformedSizes
.reserve(C
->getNumSizes());
9451 bool Changed
= false;
9452 for (Expr
*E
: C
->getSizesRefs()) {
9454 TransformedSizes
.push_back(nullptr);
9458 ExprResult T
= getDerived().TransformExpr(E
);
9463 TransformedSizes
.push_back(T
.get());
9466 if (!Changed
&& !getDerived().AlwaysRebuild())
9468 return RebuildOMPSizesClause(TransformedSizes
, C
->getBeginLoc(),
9469 C
->getLParenLoc(), C
->getEndLoc());
9472 template <typename Derived
>
9473 OMPClause
*TreeTransform
<Derived
>::TransformOMPFullClause(OMPFullClause
*C
) {
9474 if (!getDerived().AlwaysRebuild())
9476 return RebuildOMPFullClause(C
->getBeginLoc(), C
->getEndLoc());
9479 template <typename Derived
>
9481 TreeTransform
<Derived
>::TransformOMPPartialClause(OMPPartialClause
*C
) {
9482 ExprResult T
= getDerived().TransformExpr(C
->getFactor());
9485 Expr
*Factor
= T
.get();
9486 bool Changed
= Factor
!= C
->getFactor();
9488 if (!Changed
&& !getDerived().AlwaysRebuild())
9490 return RebuildOMPPartialClause(Factor
, C
->getBeginLoc(), C
->getLParenLoc(),
9494 template <typename Derived
>
9496 TreeTransform
<Derived
>::TransformOMPCollapseClause(OMPCollapseClause
*C
) {
9497 ExprResult E
= getDerived().TransformExpr(C
->getNumForLoops());
9500 return getDerived().RebuildOMPCollapseClause(
9501 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9504 template <typename Derived
>
9506 TreeTransform
<Derived
>::TransformOMPDefaultClause(OMPDefaultClause
*C
) {
9507 return getDerived().RebuildOMPDefaultClause(
9508 C
->getDefaultKind(), C
->getDefaultKindKwLoc(), C
->getBeginLoc(),
9509 C
->getLParenLoc(), C
->getEndLoc());
9512 template <typename Derived
>
9514 TreeTransform
<Derived
>::TransformOMPProcBindClause(OMPProcBindClause
*C
) {
9515 return getDerived().RebuildOMPProcBindClause(
9516 C
->getProcBindKind(), C
->getProcBindKindKwLoc(), C
->getBeginLoc(),
9517 C
->getLParenLoc(), C
->getEndLoc());
9520 template <typename Derived
>
9522 TreeTransform
<Derived
>::TransformOMPScheduleClause(OMPScheduleClause
*C
) {
9523 ExprResult E
= getDerived().TransformExpr(C
->getChunkSize());
9526 return getDerived().RebuildOMPScheduleClause(
9527 C
->getFirstScheduleModifier(), C
->getSecondScheduleModifier(),
9528 C
->getScheduleKind(), E
.get(), C
->getBeginLoc(), C
->getLParenLoc(),
9529 C
->getFirstScheduleModifierLoc(), C
->getSecondScheduleModifierLoc(),
9530 C
->getScheduleKindLoc(), C
->getCommaLoc(), C
->getEndLoc());
9533 template <typename Derived
>
9535 TreeTransform
<Derived
>::TransformOMPOrderedClause(OMPOrderedClause
*C
) {
9537 if (auto *Num
= C
->getNumForLoops()) {
9538 E
= getDerived().TransformExpr(Num
);
9542 return getDerived().RebuildOMPOrderedClause(C
->getBeginLoc(), C
->getEndLoc(),
9543 C
->getLParenLoc(), E
.get());
9546 template <typename Derived
>
9548 TreeTransform
<Derived
>::TransformOMPDetachClause(OMPDetachClause
*C
) {
9550 if (Expr
*Evt
= C
->getEventHandler()) {
9551 E
= getDerived().TransformExpr(Evt
);
9555 return getDerived().RebuildOMPDetachClause(E
.get(), C
->getBeginLoc(),
9556 C
->getLParenLoc(), C
->getEndLoc());
9559 template <typename Derived
>
9561 TreeTransform
<Derived
>::TransformOMPNowaitClause(OMPNowaitClause
*C
) {
9562 // No need to rebuild this clause, no template-dependent parameters.
9566 template <typename Derived
>
9568 TreeTransform
<Derived
>::TransformOMPUntiedClause(OMPUntiedClause
*C
) {
9569 // No need to rebuild this clause, no template-dependent parameters.
9573 template <typename Derived
>
9575 TreeTransform
<Derived
>::TransformOMPMergeableClause(OMPMergeableClause
*C
) {
9576 // No need to rebuild this clause, no template-dependent parameters.
9580 template <typename Derived
>
9581 OMPClause
*TreeTransform
<Derived
>::TransformOMPReadClause(OMPReadClause
*C
) {
9582 // No need to rebuild this clause, no template-dependent parameters.
9586 template <typename Derived
>
9587 OMPClause
*TreeTransform
<Derived
>::TransformOMPWriteClause(OMPWriteClause
*C
) {
9588 // No need to rebuild this clause, no template-dependent parameters.
9592 template <typename Derived
>
9594 TreeTransform
<Derived
>::TransformOMPUpdateClause(OMPUpdateClause
*C
) {
9595 // No need to rebuild this clause, no template-dependent parameters.
9599 template <typename Derived
>
9601 TreeTransform
<Derived
>::TransformOMPCaptureClause(OMPCaptureClause
*C
) {
9602 // No need to rebuild this clause, no template-dependent parameters.
9606 template <typename Derived
>
9608 TreeTransform
<Derived
>::TransformOMPCompareClause(OMPCompareClause
*C
) {
9609 // No need to rebuild this clause, no template-dependent parameters.
9613 template <typename Derived
>
9615 TreeTransform
<Derived
>::TransformOMPSeqCstClause(OMPSeqCstClause
*C
) {
9616 // No need to rebuild this clause, no template-dependent parameters.
9620 template <typename Derived
>
9622 TreeTransform
<Derived
>::TransformOMPAcqRelClause(OMPAcqRelClause
*C
) {
9623 // No need to rebuild this clause, no template-dependent parameters.
9627 template <typename Derived
>
9629 TreeTransform
<Derived
>::TransformOMPAcquireClause(OMPAcquireClause
*C
) {
9630 // No need to rebuild this clause, no template-dependent parameters.
9634 template <typename Derived
>
9636 TreeTransform
<Derived
>::TransformOMPReleaseClause(OMPReleaseClause
*C
) {
9637 // No need to rebuild this clause, no template-dependent parameters.
9641 template <typename Derived
>
9643 TreeTransform
<Derived
>::TransformOMPRelaxedClause(OMPRelaxedClause
*C
) {
9644 // No need to rebuild this clause, no template-dependent parameters.
9648 template <typename Derived
>
9650 TreeTransform
<Derived
>::TransformOMPThreadsClause(OMPThreadsClause
*C
) {
9651 // No need to rebuild this clause, no template-dependent parameters.
9655 template <typename Derived
>
9656 OMPClause
*TreeTransform
<Derived
>::TransformOMPSIMDClause(OMPSIMDClause
*C
) {
9657 // No need to rebuild this clause, no template-dependent parameters.
9661 template <typename Derived
>
9663 TreeTransform
<Derived
>::TransformOMPNogroupClause(OMPNogroupClause
*C
) {
9664 // No need to rebuild this clause, no template-dependent parameters.
9668 template <typename Derived
>
9669 OMPClause
*TreeTransform
<Derived
>::TransformOMPInitClause(OMPInitClause
*C
) {
9670 ExprResult IVR
= getDerived().TransformExpr(C
->getInteropVar());
9671 if (IVR
.isInvalid())
9674 OMPInteropInfo
InteropInfo(C
->getIsTarget(), C
->getIsTargetSync());
9675 InteropInfo
.PreferTypes
.reserve(C
->varlist_size() - 1);
9676 for (Expr
*E
: llvm::drop_begin(C
->varlists())) {
9677 ExprResult ER
= getDerived().TransformExpr(cast
<Expr
>(E
));
9680 InteropInfo
.PreferTypes
.push_back(ER
.get());
9682 return getDerived().RebuildOMPInitClause(IVR
.get(), InteropInfo
,
9683 C
->getBeginLoc(), C
->getLParenLoc(),
9684 C
->getVarLoc(), C
->getEndLoc());
9687 template <typename Derived
>
9688 OMPClause
*TreeTransform
<Derived
>::TransformOMPUseClause(OMPUseClause
*C
) {
9689 ExprResult ER
= getDerived().TransformExpr(C
->getInteropVar());
9692 return getDerived().RebuildOMPUseClause(ER
.get(), C
->getBeginLoc(),
9693 C
->getLParenLoc(), C
->getVarLoc(),
9697 template <typename Derived
>
9699 TreeTransform
<Derived
>::TransformOMPDestroyClause(OMPDestroyClause
*C
) {
9701 if (Expr
*IV
= C
->getInteropVar()) {
9702 ER
= getDerived().TransformExpr(IV
);
9706 return getDerived().RebuildOMPDestroyClause(ER
.get(), C
->getBeginLoc(),
9707 C
->getLParenLoc(), C
->getVarLoc(),
9711 template <typename Derived
>
9713 TreeTransform
<Derived
>::TransformOMPNovariantsClause(OMPNovariantsClause
*C
) {
9714 ExprResult Cond
= getDerived().TransformExpr(C
->getCondition());
9715 if (Cond
.isInvalid())
9717 return getDerived().RebuildOMPNovariantsClause(
9718 Cond
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9721 template <typename Derived
>
9723 TreeTransform
<Derived
>::TransformOMPNocontextClause(OMPNocontextClause
*C
) {
9724 ExprResult Cond
= getDerived().TransformExpr(C
->getCondition());
9725 if (Cond
.isInvalid())
9727 return getDerived().RebuildOMPNocontextClause(
9728 Cond
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9731 template <typename Derived
>
9733 TreeTransform
<Derived
>::TransformOMPFilterClause(OMPFilterClause
*C
) {
9734 ExprResult ThreadID
= getDerived().TransformExpr(C
->getThreadID());
9735 if (ThreadID
.isInvalid())
9737 return getDerived().RebuildOMPFilterClause(ThreadID
.get(), C
->getBeginLoc(),
9738 C
->getLParenLoc(), C
->getEndLoc());
9741 template <typename Derived
>
9742 OMPClause
*TreeTransform
<Derived
>::TransformOMPAlignClause(OMPAlignClause
*C
) {
9743 ExprResult E
= getDerived().TransformExpr(C
->getAlignment());
9746 return getDerived().RebuildOMPAlignClause(E
.get(), C
->getBeginLoc(),
9747 C
->getLParenLoc(), C
->getEndLoc());
9750 template <typename Derived
>
9751 OMPClause
*TreeTransform
<Derived
>::TransformOMPUnifiedAddressClause(
9752 OMPUnifiedAddressClause
*C
) {
9753 llvm_unreachable("unified_address clause cannot appear in dependent context");
9756 template <typename Derived
>
9757 OMPClause
*TreeTransform
<Derived
>::TransformOMPUnifiedSharedMemoryClause(
9758 OMPUnifiedSharedMemoryClause
*C
) {
9760 "unified_shared_memory clause cannot appear in dependent context");
9763 template <typename Derived
>
9764 OMPClause
*TreeTransform
<Derived
>::TransformOMPReverseOffloadClause(
9765 OMPReverseOffloadClause
*C
) {
9766 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
9769 template <typename Derived
>
9770 OMPClause
*TreeTransform
<Derived
>::TransformOMPDynamicAllocatorsClause(
9771 OMPDynamicAllocatorsClause
*C
) {
9773 "dynamic_allocators clause cannot appear in dependent context");
9776 template <typename Derived
>
9777 OMPClause
*TreeTransform
<Derived
>::TransformOMPAtomicDefaultMemOrderClause(
9778 OMPAtomicDefaultMemOrderClause
*C
) {
9780 "atomic_default_mem_order clause cannot appear in dependent context");
9783 template <typename Derived
>
9785 TreeTransform
<Derived
>::TransformOMPPrivateClause(OMPPrivateClause
*C
) {
9786 llvm::SmallVector
<Expr
*, 16> Vars
;
9787 Vars
.reserve(C
->varlist_size());
9788 for (auto *VE
: C
->varlists()) {
9789 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
9790 if (EVar
.isInvalid())
9792 Vars
.push_back(EVar
.get());
9794 return getDerived().RebuildOMPPrivateClause(
9795 Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9798 template <typename Derived
>
9799 OMPClause
*TreeTransform
<Derived
>::TransformOMPFirstprivateClause(
9800 OMPFirstprivateClause
*C
) {
9801 llvm::SmallVector
<Expr
*, 16> Vars
;
9802 Vars
.reserve(C
->varlist_size());
9803 for (auto *VE
: C
->varlists()) {
9804 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
9805 if (EVar
.isInvalid())
9807 Vars
.push_back(EVar
.get());
9809 return getDerived().RebuildOMPFirstprivateClause(
9810 Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
9813 template <typename Derived
>
9815 TreeTransform
<Derived
>::TransformOMPLastprivateClause(OMPLastprivateClause
*C
) {
9816 llvm::SmallVector
<Expr
*, 16> Vars
;
9817 Vars
.reserve(C
->varlist_size());
9818 for (auto *VE
: C
->varlists()) {
9819 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
9820 if (EVar
.isInvalid())
9822 Vars
.push_back(EVar
.get());
9824 return getDerived().RebuildOMPLastprivateClause(
9825 Vars
, C
->getKind(), C
->getKindLoc(), C
->getColonLoc(), C
->getBeginLoc(),
9826 C
->getLParenLoc(), C
->getEndLoc());
9829 template <typename Derived
>
9831 TreeTransform
<Derived
>::TransformOMPSharedClause(OMPSharedClause
*C
) {
9832 llvm::SmallVector
<Expr
*, 16> Vars
;
9833 Vars
.reserve(C
->varlist_size());
9834 for (auto *VE
: C
->varlists()) {
9835 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
9836 if (EVar
.isInvalid())
9838 Vars
.push_back(EVar
.get());
9840 return getDerived().RebuildOMPSharedClause(Vars
, C
->getBeginLoc(),
9841 C
->getLParenLoc(), C
->getEndLoc());
9844 template <typename Derived
>
9846 TreeTransform
<Derived
>::TransformOMPReductionClause(OMPReductionClause
*C
) {
9847 llvm::SmallVector
<Expr
*, 16> Vars
;
9848 Vars
.reserve(C
->varlist_size());
9849 for (auto *VE
: C
->varlists()) {
9850 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
9851 if (EVar
.isInvalid())
9853 Vars
.push_back(EVar
.get());
9855 CXXScopeSpec ReductionIdScopeSpec
;
9856 ReductionIdScopeSpec
.Adopt(C
->getQualifierLoc());
9858 DeclarationNameInfo NameInfo
= C
->getNameInfo();
9859 if (NameInfo
.getName()) {
9860 NameInfo
= getDerived().TransformDeclarationNameInfo(NameInfo
);
9861 if (!NameInfo
.getName())
9864 // Build a list of all UDR decls with the same names ranged by the Scopes.
9865 // The Scope boundary is a duplication of the previous decl.
9866 llvm::SmallVector
<Expr
*, 16> UnresolvedReductions
;
9867 for (auto *E
: C
->reduction_ops()) {
9868 // Transform all the decls.
9870 auto *ULE
= cast
<UnresolvedLookupExpr
>(E
);
9871 UnresolvedSet
<8> Decls
;
9872 for (auto *D
: ULE
->decls()) {
9874 cast
<NamedDecl
>(getDerived().TransformDecl(E
->getExprLoc(), D
));
9875 Decls
.addDecl(InstD
, InstD
->getAccess());
9877 UnresolvedReductions
.push_back(
9878 UnresolvedLookupExpr::Create(
9879 SemaRef
.Context
, /*NamingClass=*/nullptr,
9880 ReductionIdScopeSpec
.getWithLocInContext(SemaRef
.Context
),
9881 NameInfo
, /*ADL=*/true, ULE
->isOverloaded(),
9882 Decls
.begin(), Decls
.end()));
9884 UnresolvedReductions
.push_back(nullptr);
9886 return getDerived().RebuildOMPReductionClause(
9887 Vars
, C
->getModifier(), C
->getBeginLoc(), C
->getLParenLoc(),
9888 C
->getModifierLoc(), C
->getColonLoc(), C
->getEndLoc(),
9889 ReductionIdScopeSpec
, NameInfo
, UnresolvedReductions
);
9892 template <typename Derived
>
9893 OMPClause
*TreeTransform
<Derived
>::TransformOMPTaskReductionClause(
9894 OMPTaskReductionClause
*C
) {
9895 llvm::SmallVector
<Expr
*, 16> Vars
;
9896 Vars
.reserve(C
->varlist_size());
9897 for (auto *VE
: C
->varlists()) {
9898 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
9899 if (EVar
.isInvalid())
9901 Vars
.push_back(EVar
.get());
9903 CXXScopeSpec ReductionIdScopeSpec
;
9904 ReductionIdScopeSpec
.Adopt(C
->getQualifierLoc());
9906 DeclarationNameInfo NameInfo
= C
->getNameInfo();
9907 if (NameInfo
.getName()) {
9908 NameInfo
= getDerived().TransformDeclarationNameInfo(NameInfo
);
9909 if (!NameInfo
.getName())
9912 // Build a list of all UDR decls with the same names ranged by the Scopes.
9913 // The Scope boundary is a duplication of the previous decl.
9914 llvm::SmallVector
<Expr
*, 16> UnresolvedReductions
;
9915 for (auto *E
: C
->reduction_ops()) {
9916 // Transform all the decls.
9918 auto *ULE
= cast
<UnresolvedLookupExpr
>(E
);
9919 UnresolvedSet
<8> Decls
;
9920 for (auto *D
: ULE
->decls()) {
9922 cast
<NamedDecl
>(getDerived().TransformDecl(E
->getExprLoc(), D
));
9923 Decls
.addDecl(InstD
, InstD
->getAccess());
9925 UnresolvedReductions
.push_back(UnresolvedLookupExpr::Create(
9926 SemaRef
.Context
, /*NamingClass=*/nullptr,
9927 ReductionIdScopeSpec
.getWithLocInContext(SemaRef
.Context
), NameInfo
,
9928 /*ADL=*/true, ULE
->isOverloaded(), Decls
.begin(), Decls
.end()));
9930 UnresolvedReductions
.push_back(nullptr);
9932 return getDerived().RebuildOMPTaskReductionClause(
9933 Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getColonLoc(),
9934 C
->getEndLoc(), ReductionIdScopeSpec
, NameInfo
, UnresolvedReductions
);
9937 template <typename Derived
>
9939 TreeTransform
<Derived
>::TransformOMPInReductionClause(OMPInReductionClause
*C
) {
9940 llvm::SmallVector
<Expr
*, 16> Vars
;
9941 Vars
.reserve(C
->varlist_size());
9942 for (auto *VE
: C
->varlists()) {
9943 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
9944 if (EVar
.isInvalid())
9946 Vars
.push_back(EVar
.get());
9948 CXXScopeSpec ReductionIdScopeSpec
;
9949 ReductionIdScopeSpec
.Adopt(C
->getQualifierLoc());
9951 DeclarationNameInfo NameInfo
= C
->getNameInfo();
9952 if (NameInfo
.getName()) {
9953 NameInfo
= getDerived().TransformDeclarationNameInfo(NameInfo
);
9954 if (!NameInfo
.getName())
9957 // Build a list of all UDR decls with the same names ranged by the Scopes.
9958 // The Scope boundary is a duplication of the previous decl.
9959 llvm::SmallVector
<Expr
*, 16> UnresolvedReductions
;
9960 for (auto *E
: C
->reduction_ops()) {
9961 // Transform all the decls.
9963 auto *ULE
= cast
<UnresolvedLookupExpr
>(E
);
9964 UnresolvedSet
<8> Decls
;
9965 for (auto *D
: ULE
->decls()) {
9967 cast
<NamedDecl
>(getDerived().TransformDecl(E
->getExprLoc(), D
));
9968 Decls
.addDecl(InstD
, InstD
->getAccess());
9970 UnresolvedReductions
.push_back(UnresolvedLookupExpr::Create(
9971 SemaRef
.Context
, /*NamingClass=*/nullptr,
9972 ReductionIdScopeSpec
.getWithLocInContext(SemaRef
.Context
), NameInfo
,
9973 /*ADL=*/true, ULE
->isOverloaded(), Decls
.begin(), Decls
.end()));
9975 UnresolvedReductions
.push_back(nullptr);
9977 return getDerived().RebuildOMPInReductionClause(
9978 Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getColonLoc(),
9979 C
->getEndLoc(), ReductionIdScopeSpec
, NameInfo
, UnresolvedReductions
);
9982 template <typename Derived
>
9984 TreeTransform
<Derived
>::TransformOMPLinearClause(OMPLinearClause
*C
) {
9985 llvm::SmallVector
<Expr
*, 16> Vars
;
9986 Vars
.reserve(C
->varlist_size());
9987 for (auto *VE
: C
->varlists()) {
9988 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
9989 if (EVar
.isInvalid())
9991 Vars
.push_back(EVar
.get());
9993 ExprResult Step
= getDerived().TransformExpr(C
->getStep());
9994 if (Step
.isInvalid())
9996 return getDerived().RebuildOMPLinearClause(
9997 Vars
, Step
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getModifier(),
9998 C
->getModifierLoc(), C
->getColonLoc(), C
->getEndLoc());
10001 template <typename Derived
>
10003 TreeTransform
<Derived
>::TransformOMPAlignedClause(OMPAlignedClause
*C
) {
10004 llvm::SmallVector
<Expr
*, 16> Vars
;
10005 Vars
.reserve(C
->varlist_size());
10006 for (auto *VE
: C
->varlists()) {
10007 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10008 if (EVar
.isInvalid())
10010 Vars
.push_back(EVar
.get());
10012 ExprResult Alignment
= getDerived().TransformExpr(C
->getAlignment());
10013 if (Alignment
.isInvalid())
10015 return getDerived().RebuildOMPAlignedClause(
10016 Vars
, Alignment
.get(), C
->getBeginLoc(), C
->getLParenLoc(),
10017 C
->getColonLoc(), C
->getEndLoc());
10020 template <typename Derived
>
10022 TreeTransform
<Derived
>::TransformOMPCopyinClause(OMPCopyinClause
*C
) {
10023 llvm::SmallVector
<Expr
*, 16> Vars
;
10024 Vars
.reserve(C
->varlist_size());
10025 for (auto *VE
: C
->varlists()) {
10026 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10027 if (EVar
.isInvalid())
10029 Vars
.push_back(EVar
.get());
10031 return getDerived().RebuildOMPCopyinClause(Vars
, C
->getBeginLoc(),
10032 C
->getLParenLoc(), C
->getEndLoc());
10035 template <typename Derived
>
10037 TreeTransform
<Derived
>::TransformOMPCopyprivateClause(OMPCopyprivateClause
*C
) {
10038 llvm::SmallVector
<Expr
*, 16> Vars
;
10039 Vars
.reserve(C
->varlist_size());
10040 for (auto *VE
: C
->varlists()) {
10041 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10042 if (EVar
.isInvalid())
10044 Vars
.push_back(EVar
.get());
10046 return getDerived().RebuildOMPCopyprivateClause(
10047 Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10050 template <typename Derived
>
10051 OMPClause
*TreeTransform
<Derived
>::TransformOMPFlushClause(OMPFlushClause
*C
) {
10052 llvm::SmallVector
<Expr
*, 16> Vars
;
10053 Vars
.reserve(C
->varlist_size());
10054 for (auto *VE
: C
->varlists()) {
10055 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10056 if (EVar
.isInvalid())
10058 Vars
.push_back(EVar
.get());
10060 return getDerived().RebuildOMPFlushClause(Vars
, C
->getBeginLoc(),
10061 C
->getLParenLoc(), C
->getEndLoc());
10064 template <typename Derived
>
10066 TreeTransform
<Derived
>::TransformOMPDepobjClause(OMPDepobjClause
*C
) {
10067 ExprResult E
= getDerived().TransformExpr(C
->getDepobj());
10070 return getDerived().RebuildOMPDepobjClause(E
.get(), C
->getBeginLoc(),
10071 C
->getLParenLoc(), C
->getEndLoc());
10074 template <typename Derived
>
10076 TreeTransform
<Derived
>::TransformOMPDependClause(OMPDependClause
*C
) {
10077 llvm::SmallVector
<Expr
*, 16> Vars
;
10078 Expr
*DepModifier
= C
->getModifier();
10080 ExprResult DepModRes
= getDerived().TransformExpr(DepModifier
);
10081 if (DepModRes
.isInvalid())
10083 DepModifier
= DepModRes
.get();
10085 Vars
.reserve(C
->varlist_size());
10086 for (auto *VE
: C
->varlists()) {
10087 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10088 if (EVar
.isInvalid())
10090 Vars
.push_back(EVar
.get());
10092 return getDerived().RebuildOMPDependClause(
10093 {C
->getDependencyKind(), C
->getDependencyLoc(), C
->getColonLoc(),
10094 C
->getOmpAllMemoryLoc()},
10095 DepModifier
, Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10098 template <typename Derived
>
10100 TreeTransform
<Derived
>::TransformOMPDeviceClause(OMPDeviceClause
*C
) {
10101 ExprResult E
= getDerived().TransformExpr(C
->getDevice());
10104 return getDerived().RebuildOMPDeviceClause(
10105 C
->getModifier(), E
.get(), C
->getBeginLoc(), C
->getLParenLoc(),
10106 C
->getModifierLoc(), C
->getEndLoc());
10109 template <typename Derived
, class T
>
10110 bool transformOMPMappableExprListClause(
10111 TreeTransform
<Derived
> &TT
, OMPMappableExprListClause
<T
> *C
,
10112 llvm::SmallVectorImpl
<Expr
*> &Vars
, CXXScopeSpec
&MapperIdScopeSpec
,
10113 DeclarationNameInfo
&MapperIdInfo
,
10114 llvm::SmallVectorImpl
<Expr
*> &UnresolvedMappers
) {
10115 // Transform expressions in the list.
10116 Vars
.reserve(C
->varlist_size());
10117 for (auto *VE
: C
->varlists()) {
10118 ExprResult EVar
= TT
.getDerived().TransformExpr(cast
<Expr
>(VE
));
10119 if (EVar
.isInvalid())
10121 Vars
.push_back(EVar
.get());
10123 // Transform mapper scope specifier and identifier.
10124 NestedNameSpecifierLoc QualifierLoc
;
10125 if (C
->getMapperQualifierLoc()) {
10126 QualifierLoc
= TT
.getDerived().TransformNestedNameSpecifierLoc(
10127 C
->getMapperQualifierLoc());
10131 MapperIdScopeSpec
.Adopt(QualifierLoc
);
10132 MapperIdInfo
= C
->getMapperIdInfo();
10133 if (MapperIdInfo
.getName()) {
10134 MapperIdInfo
= TT
.getDerived().TransformDeclarationNameInfo(MapperIdInfo
);
10135 if (!MapperIdInfo
.getName())
10138 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
10139 // the previous user-defined mapper lookup in dependent environment.
10140 for (auto *E
: C
->mapperlists()) {
10141 // Transform all the decls.
10143 auto *ULE
= cast
<UnresolvedLookupExpr
>(E
);
10144 UnresolvedSet
<8> Decls
;
10145 for (auto *D
: ULE
->decls()) {
10147 cast
<NamedDecl
>(TT
.getDerived().TransformDecl(E
->getExprLoc(), D
));
10148 Decls
.addDecl(InstD
, InstD
->getAccess());
10150 UnresolvedMappers
.push_back(UnresolvedLookupExpr::Create(
10151 TT
.getSema().Context
, /*NamingClass=*/nullptr,
10152 MapperIdScopeSpec
.getWithLocInContext(TT
.getSema().Context
),
10153 MapperIdInfo
, /*ADL=*/true, ULE
->isOverloaded(), Decls
.begin(),
10156 UnresolvedMappers
.push_back(nullptr);
10162 template <typename Derived
>
10163 OMPClause
*TreeTransform
<Derived
>::TransformOMPMapClause(OMPMapClause
*C
) {
10164 OMPVarListLocTy
Locs(C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10165 llvm::SmallVector
<Expr
*, 16> Vars
;
10166 CXXScopeSpec MapperIdScopeSpec
;
10167 DeclarationNameInfo MapperIdInfo
;
10168 llvm::SmallVector
<Expr
*, 16> UnresolvedMappers
;
10169 if (transformOMPMappableExprListClause
<Derived
, OMPMapClause
>(
10170 *this, C
, Vars
, MapperIdScopeSpec
, MapperIdInfo
, UnresolvedMappers
))
10172 return getDerived().RebuildOMPMapClause(
10173 C
->getMapTypeModifiers(), C
->getMapTypeModifiersLoc(), MapperIdScopeSpec
,
10174 MapperIdInfo
, C
->getMapType(), C
->isImplicitMapType(), C
->getMapLoc(),
10175 C
->getColonLoc(), Vars
, Locs
, UnresolvedMappers
);
10178 template <typename Derived
>
10180 TreeTransform
<Derived
>::TransformOMPAllocateClause(OMPAllocateClause
*C
) {
10181 Expr
*Allocator
= C
->getAllocator();
10183 ExprResult AllocatorRes
= getDerived().TransformExpr(Allocator
);
10184 if (AllocatorRes
.isInvalid())
10186 Allocator
= AllocatorRes
.get();
10188 llvm::SmallVector
<Expr
*, 16> Vars
;
10189 Vars
.reserve(C
->varlist_size());
10190 for (auto *VE
: C
->varlists()) {
10191 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10192 if (EVar
.isInvalid())
10194 Vars
.push_back(EVar
.get());
10196 return getDerived().RebuildOMPAllocateClause(
10197 Allocator
, Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getColonLoc(),
10201 template <typename Derived
>
10203 TreeTransform
<Derived
>::TransformOMPNumTeamsClause(OMPNumTeamsClause
*C
) {
10204 ExprResult E
= getDerived().TransformExpr(C
->getNumTeams());
10207 return getDerived().RebuildOMPNumTeamsClause(
10208 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10211 template <typename Derived
>
10213 TreeTransform
<Derived
>::TransformOMPThreadLimitClause(OMPThreadLimitClause
*C
) {
10214 ExprResult E
= getDerived().TransformExpr(C
->getThreadLimit());
10217 return getDerived().RebuildOMPThreadLimitClause(
10218 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10221 template <typename Derived
>
10223 TreeTransform
<Derived
>::TransformOMPPriorityClause(OMPPriorityClause
*C
) {
10224 ExprResult E
= getDerived().TransformExpr(C
->getPriority());
10227 return getDerived().RebuildOMPPriorityClause(
10228 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10231 template <typename Derived
>
10233 TreeTransform
<Derived
>::TransformOMPGrainsizeClause(OMPGrainsizeClause
*C
) {
10234 ExprResult E
= getDerived().TransformExpr(C
->getGrainsize());
10237 return getDerived().RebuildOMPGrainsizeClause(
10238 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10241 template <typename Derived
>
10243 TreeTransform
<Derived
>::TransformOMPNumTasksClause(OMPNumTasksClause
*C
) {
10244 ExprResult E
= getDerived().TransformExpr(C
->getNumTasks());
10247 return getDerived().RebuildOMPNumTasksClause(
10248 E
.get(), C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10251 template <typename Derived
>
10252 OMPClause
*TreeTransform
<Derived
>::TransformOMPHintClause(OMPHintClause
*C
) {
10253 ExprResult E
= getDerived().TransformExpr(C
->getHint());
10256 return getDerived().RebuildOMPHintClause(E
.get(), C
->getBeginLoc(),
10257 C
->getLParenLoc(), C
->getEndLoc());
10260 template <typename Derived
>
10261 OMPClause
*TreeTransform
<Derived
>::TransformOMPDistScheduleClause(
10262 OMPDistScheduleClause
*C
) {
10263 ExprResult E
= getDerived().TransformExpr(C
->getChunkSize());
10266 return getDerived().RebuildOMPDistScheduleClause(
10267 C
->getDistScheduleKind(), E
.get(), C
->getBeginLoc(), C
->getLParenLoc(),
10268 C
->getDistScheduleKindLoc(), C
->getCommaLoc(), C
->getEndLoc());
10271 template <typename Derived
>
10273 TreeTransform
<Derived
>::TransformOMPDefaultmapClause(OMPDefaultmapClause
*C
) {
10274 // Rebuild Defaultmap Clause since we need to invoke the checking of
10275 // defaultmap(none:variable-category) after template initialization.
10276 return getDerived().RebuildOMPDefaultmapClause(C
->getDefaultmapModifier(),
10277 C
->getDefaultmapKind(),
10280 C
->getDefaultmapModifierLoc(),
10281 C
->getDefaultmapKindLoc(),
10285 template <typename Derived
>
10286 OMPClause
*TreeTransform
<Derived
>::TransformOMPToClause(OMPToClause
*C
) {
10287 OMPVarListLocTy
Locs(C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10288 llvm::SmallVector
<Expr
*, 16> Vars
;
10289 CXXScopeSpec MapperIdScopeSpec
;
10290 DeclarationNameInfo MapperIdInfo
;
10291 llvm::SmallVector
<Expr
*, 16> UnresolvedMappers
;
10292 if (transformOMPMappableExprListClause
<Derived
, OMPToClause
>(
10293 *this, C
, Vars
, MapperIdScopeSpec
, MapperIdInfo
, UnresolvedMappers
))
10295 return getDerived().RebuildOMPToClause(
10296 C
->getMotionModifiers(), C
->getMotionModifiersLoc(), MapperIdScopeSpec
,
10297 MapperIdInfo
, C
->getColonLoc(), Vars
, Locs
, UnresolvedMappers
);
10300 template <typename Derived
>
10301 OMPClause
*TreeTransform
<Derived
>::TransformOMPFromClause(OMPFromClause
*C
) {
10302 OMPVarListLocTy
Locs(C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10303 llvm::SmallVector
<Expr
*, 16> Vars
;
10304 CXXScopeSpec MapperIdScopeSpec
;
10305 DeclarationNameInfo MapperIdInfo
;
10306 llvm::SmallVector
<Expr
*, 16> UnresolvedMappers
;
10307 if (transformOMPMappableExprListClause
<Derived
, OMPFromClause
>(
10308 *this, C
, Vars
, MapperIdScopeSpec
, MapperIdInfo
, UnresolvedMappers
))
10310 return getDerived().RebuildOMPFromClause(
10311 C
->getMotionModifiers(), C
->getMotionModifiersLoc(), MapperIdScopeSpec
,
10312 MapperIdInfo
, C
->getColonLoc(), Vars
, Locs
, UnresolvedMappers
);
10315 template <typename Derived
>
10316 OMPClause
*TreeTransform
<Derived
>::TransformOMPUseDevicePtrClause(
10317 OMPUseDevicePtrClause
*C
) {
10318 llvm::SmallVector
<Expr
*, 16> Vars
;
10319 Vars
.reserve(C
->varlist_size());
10320 for (auto *VE
: C
->varlists()) {
10321 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10322 if (EVar
.isInvalid())
10324 Vars
.push_back(EVar
.get());
10326 OMPVarListLocTy
Locs(C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10327 return getDerived().RebuildOMPUseDevicePtrClause(Vars
, Locs
);
10330 template <typename Derived
>
10331 OMPClause
*TreeTransform
<Derived
>::TransformOMPUseDeviceAddrClause(
10332 OMPUseDeviceAddrClause
*C
) {
10333 llvm::SmallVector
<Expr
*, 16> Vars
;
10334 Vars
.reserve(C
->varlist_size());
10335 for (auto *VE
: C
->varlists()) {
10336 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10337 if (EVar
.isInvalid())
10339 Vars
.push_back(EVar
.get());
10341 OMPVarListLocTy
Locs(C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10342 return getDerived().RebuildOMPUseDeviceAddrClause(Vars
, Locs
);
10345 template <typename Derived
>
10347 TreeTransform
<Derived
>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause
*C
) {
10348 llvm::SmallVector
<Expr
*, 16> Vars
;
10349 Vars
.reserve(C
->varlist_size());
10350 for (auto *VE
: C
->varlists()) {
10351 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10352 if (EVar
.isInvalid())
10354 Vars
.push_back(EVar
.get());
10356 OMPVarListLocTy
Locs(C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10357 return getDerived().RebuildOMPIsDevicePtrClause(Vars
, Locs
);
10360 template <typename Derived
>
10361 OMPClause
*TreeTransform
<Derived
>::TransformOMPHasDeviceAddrClause(
10362 OMPHasDeviceAddrClause
*C
) {
10363 llvm::SmallVector
<Expr
*, 16> Vars
;
10364 Vars
.reserve(C
->varlist_size());
10365 for (auto *VE
: C
->varlists()) {
10366 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10367 if (EVar
.isInvalid())
10369 Vars
.push_back(EVar
.get());
10371 OMPVarListLocTy
Locs(C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10372 return getDerived().RebuildOMPHasDeviceAddrClause(Vars
, Locs
);
10375 template <typename Derived
>
10377 TreeTransform
<Derived
>::TransformOMPNontemporalClause(OMPNontemporalClause
*C
) {
10378 llvm::SmallVector
<Expr
*, 16> Vars
;
10379 Vars
.reserve(C
->varlist_size());
10380 for (auto *VE
: C
->varlists()) {
10381 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10382 if (EVar
.isInvalid())
10384 Vars
.push_back(EVar
.get());
10386 return getDerived().RebuildOMPNontemporalClause(
10387 Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10390 template <typename Derived
>
10392 TreeTransform
<Derived
>::TransformOMPInclusiveClause(OMPInclusiveClause
*C
) {
10393 llvm::SmallVector
<Expr
*, 16> Vars
;
10394 Vars
.reserve(C
->varlist_size());
10395 for (auto *VE
: C
->varlists()) {
10396 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10397 if (EVar
.isInvalid())
10399 Vars
.push_back(EVar
.get());
10401 return getDerived().RebuildOMPInclusiveClause(
10402 Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10405 template <typename Derived
>
10407 TreeTransform
<Derived
>::TransformOMPExclusiveClause(OMPExclusiveClause
*C
) {
10408 llvm::SmallVector
<Expr
*, 16> Vars
;
10409 Vars
.reserve(C
->varlist_size());
10410 for (auto *VE
: C
->varlists()) {
10411 ExprResult EVar
= getDerived().TransformExpr(cast
<Expr
>(VE
));
10412 if (EVar
.isInvalid())
10414 Vars
.push_back(EVar
.get());
10416 return getDerived().RebuildOMPExclusiveClause(
10417 Vars
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10420 template <typename Derived
>
10421 OMPClause
*TreeTransform
<Derived
>::TransformOMPUsesAllocatorsClause(
10422 OMPUsesAllocatorsClause
*C
) {
10423 SmallVector
<Sema::UsesAllocatorsData
, 16> Data
;
10424 Data
.reserve(C
->getNumberOfAllocators());
10425 for (unsigned I
= 0, E
= C
->getNumberOfAllocators(); I
< E
; ++I
) {
10426 OMPUsesAllocatorsClause::Data D
= C
->getAllocatorData(I
);
10427 ExprResult Allocator
= getDerived().TransformExpr(D
.Allocator
);
10428 if (Allocator
.isInvalid())
10430 ExprResult AllocatorTraits
;
10431 if (Expr
*AT
= D
.AllocatorTraits
) {
10432 AllocatorTraits
= getDerived().TransformExpr(AT
);
10433 if (AllocatorTraits
.isInvalid())
10436 Sema::UsesAllocatorsData
&NewD
= Data
.emplace_back();
10437 NewD
.Allocator
= Allocator
.get();
10438 NewD
.AllocatorTraits
= AllocatorTraits
.get();
10439 NewD
.LParenLoc
= D
.LParenLoc
;
10440 NewD
.RParenLoc
= D
.RParenLoc
;
10442 return getDerived().RebuildOMPUsesAllocatorsClause(
10443 Data
, C
->getBeginLoc(), C
->getLParenLoc(), C
->getEndLoc());
10446 template <typename Derived
>
10448 TreeTransform
<Derived
>::TransformOMPAffinityClause(OMPAffinityClause
*C
) {
10449 SmallVector
<Expr
*, 4> Locators
;
10450 Locators
.reserve(C
->varlist_size());
10451 ExprResult ModifierRes
;
10452 if (Expr
*Modifier
= C
->getModifier()) {
10453 ModifierRes
= getDerived().TransformExpr(Modifier
);
10454 if (ModifierRes
.isInvalid())
10457 for (Expr
*E
: C
->varlists()) {
10458 ExprResult Locator
= getDerived().TransformExpr(E
);
10459 if (Locator
.isInvalid())
10461 Locators
.push_back(Locator
.get());
10463 return getDerived().RebuildOMPAffinityClause(
10464 C
->getBeginLoc(), C
->getLParenLoc(), C
->getColonLoc(), C
->getEndLoc(),
10465 ModifierRes
.get(), Locators
);
10468 template <typename Derived
>
10469 OMPClause
*TreeTransform
<Derived
>::TransformOMPOrderClause(OMPOrderClause
*C
) {
10470 return getDerived().RebuildOMPOrderClause(C
->getKind(), C
->getKindKwLoc(),
10471 C
->getBeginLoc(), C
->getLParenLoc(),
10475 template <typename Derived
>
10476 OMPClause
*TreeTransform
<Derived
>::TransformOMPBindClause(OMPBindClause
*C
) {
10477 return getDerived().RebuildOMPBindClause(
10478 C
->getBindKind(), C
->getBindKindLoc(), C
->getBeginLoc(),
10479 C
->getLParenLoc(), C
->getEndLoc());
10482 //===----------------------------------------------------------------------===//
10483 // Expression transformation
10484 //===----------------------------------------------------------------------===//
10485 template<typename Derived
>
10487 TreeTransform
<Derived
>::TransformConstantExpr(ConstantExpr
*E
) {
10488 return TransformExpr(E
->getSubExpr());
10491 template <typename Derived
>
10492 ExprResult TreeTransform
<Derived
>::TransformSYCLUniqueStableNameExpr(
10493 SYCLUniqueStableNameExpr
*E
) {
10494 if (!E
->isTypeDependent())
10497 TypeSourceInfo
*NewT
= getDerived().TransformType(E
->getTypeSourceInfo());
10500 return ExprError();
10502 if (!getDerived().AlwaysRebuild() && E
->getTypeSourceInfo() == NewT
)
10505 return getDerived().RebuildSYCLUniqueStableNameExpr(
10506 E
->getLocation(), E
->getLParenLocation(), E
->getRParenLocation(), NewT
);
10509 template<typename Derived
>
10511 TreeTransform
<Derived
>::TransformPredefinedExpr(PredefinedExpr
*E
) {
10512 if (!E
->isTypeDependent())
10515 return getDerived().RebuildPredefinedExpr(E
->getLocation(),
10516 E
->getIdentKind());
10519 template<typename Derived
>
10521 TreeTransform
<Derived
>::TransformDeclRefExpr(DeclRefExpr
*E
) {
10522 NestedNameSpecifierLoc QualifierLoc
;
10523 if (E
->getQualifierLoc()) {
10525 = getDerived().TransformNestedNameSpecifierLoc(E
->getQualifierLoc());
10527 return ExprError();
10531 = cast_or_null
<ValueDecl
>(getDerived().TransformDecl(E
->getLocation(),
10534 return ExprError();
10536 NamedDecl
*Found
= ND
;
10537 if (E
->getFoundDecl() != E
->getDecl()) {
10538 Found
= cast_or_null
<NamedDecl
>(
10539 getDerived().TransformDecl(E
->getLocation(), E
->getFoundDecl()));
10541 return ExprError();
10544 DeclarationNameInfo NameInfo
= E
->getNameInfo();
10545 if (NameInfo
.getName()) {
10546 NameInfo
= getDerived().TransformDeclarationNameInfo(NameInfo
);
10547 if (!NameInfo
.getName())
10548 return ExprError();
10551 if (!getDerived().AlwaysRebuild() &&
10552 QualifierLoc
== E
->getQualifierLoc() &&
10553 ND
== E
->getDecl() &&
10554 Found
== E
->getFoundDecl() &&
10555 NameInfo
.getName() == E
->getDecl()->getDeclName() &&
10556 !E
->hasExplicitTemplateArgs()) {
10558 // Mark it referenced in the new context regardless.
10559 // FIXME: this is a bit instantiation-specific.
10560 SemaRef
.MarkDeclRefReferenced(E
);
10565 TemplateArgumentListInfo TransArgs
, *TemplateArgs
= nullptr;
10566 if (E
->hasExplicitTemplateArgs()) {
10567 TemplateArgs
= &TransArgs
;
10568 TransArgs
.setLAngleLoc(E
->getLAngleLoc());
10569 TransArgs
.setRAngleLoc(E
->getRAngleLoc());
10570 if (getDerived().TransformTemplateArguments(E
->getTemplateArgs(),
10571 E
->getNumTemplateArgs(),
10573 return ExprError();
10576 return getDerived().RebuildDeclRefExpr(QualifierLoc
, ND
, NameInfo
,
10577 Found
, TemplateArgs
);
10580 template<typename Derived
>
10582 TreeTransform
<Derived
>::TransformIntegerLiteral(IntegerLiteral
*E
) {
10586 template <typename Derived
>
10587 ExprResult TreeTransform
<Derived
>::TransformFixedPointLiteral(
10588 FixedPointLiteral
*E
) {
10592 template<typename Derived
>
10594 TreeTransform
<Derived
>::TransformFloatingLiteral(FloatingLiteral
*E
) {
10598 template<typename Derived
>
10600 TreeTransform
<Derived
>::TransformImaginaryLiteral(ImaginaryLiteral
*E
) {
10604 template<typename Derived
>
10606 TreeTransform
<Derived
>::TransformStringLiteral(StringLiteral
*E
) {
10610 template<typename Derived
>
10612 TreeTransform
<Derived
>::TransformCharacterLiteral(CharacterLiteral
*E
) {
10616 template<typename Derived
>
10618 TreeTransform
<Derived
>::TransformUserDefinedLiteral(UserDefinedLiteral
*E
) {
10619 return getDerived().TransformCallExpr(E
);
10622 template<typename Derived
>
10624 TreeTransform
<Derived
>::TransformGenericSelectionExpr(GenericSelectionExpr
*E
) {
10625 ExprResult ControllingExpr
=
10626 getDerived().TransformExpr(E
->getControllingExpr());
10627 if (ControllingExpr
.isInvalid())
10628 return ExprError();
10630 SmallVector
<Expr
*, 4> AssocExprs
;
10631 SmallVector
<TypeSourceInfo
*, 4> AssocTypes
;
10632 for (const GenericSelectionExpr::Association Assoc
: E
->associations()) {
10633 TypeSourceInfo
*TSI
= Assoc
.getTypeSourceInfo();
10635 TypeSourceInfo
*AssocType
= getDerived().TransformType(TSI
);
10637 return ExprError();
10638 AssocTypes
.push_back(AssocType
);
10640 AssocTypes
.push_back(nullptr);
10643 ExprResult AssocExpr
=
10644 getDerived().TransformExpr(Assoc
.getAssociationExpr());
10645 if (AssocExpr
.isInvalid())
10646 return ExprError();
10647 AssocExprs
.push_back(AssocExpr
.get());
10650 return getDerived().RebuildGenericSelectionExpr(E
->getGenericLoc(),
10651 E
->getDefaultLoc(),
10653 ControllingExpr
.get(),
10658 template<typename Derived
>
10660 TreeTransform
<Derived
>::TransformParenExpr(ParenExpr
*E
) {
10661 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
10662 if (SubExpr
.isInvalid())
10663 return ExprError();
10665 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getSubExpr())
10668 return getDerived().RebuildParenExpr(SubExpr
.get(), E
->getLParen(),
10672 /// The operand of a unary address-of operator has special rules: it's
10673 /// allowed to refer to a non-static member of a class even if there's no 'this'
10674 /// object available.
10675 template<typename Derived
>
10677 TreeTransform
<Derived
>::TransformAddressOfOperand(Expr
*E
) {
10678 if (DependentScopeDeclRefExpr
*DRE
= dyn_cast
<DependentScopeDeclRefExpr
>(E
))
10679 return getDerived().TransformDependentScopeDeclRefExpr(DRE
, true, nullptr);
10681 return getDerived().TransformExpr(E
);
10684 template<typename Derived
>
10686 TreeTransform
<Derived
>::TransformUnaryOperator(UnaryOperator
*E
) {
10687 ExprResult SubExpr
;
10688 if (E
->getOpcode() == UO_AddrOf
)
10689 SubExpr
= TransformAddressOfOperand(E
->getSubExpr());
10691 SubExpr
= TransformExpr(E
->getSubExpr());
10692 if (SubExpr
.isInvalid())
10693 return ExprError();
10695 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getSubExpr())
10698 return getDerived().RebuildUnaryOperator(E
->getOperatorLoc(),
10703 template<typename Derived
>
10705 TreeTransform
<Derived
>::TransformOffsetOfExpr(OffsetOfExpr
*E
) {
10706 // Transform the type.
10707 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeSourceInfo());
10709 return ExprError();
10711 // Transform all of the components into components similar to what the
10713 // FIXME: It would be slightly more efficient in the non-dependent case to
10714 // just map FieldDecls, rather than requiring the rebuilder to look for
10715 // the fields again. However, __builtin_offsetof is rare enough in
10716 // template code that we don't care.
10717 bool ExprChanged
= false;
10718 typedef Sema::OffsetOfComponent Component
;
10719 SmallVector
<Component
, 4> Components
;
10720 for (unsigned I
= 0, N
= E
->getNumComponents(); I
!= N
; ++I
) {
10721 const OffsetOfNode
&ON
= E
->getComponent(I
);
10723 Comp
.isBrackets
= true;
10724 Comp
.LocStart
= ON
.getSourceRange().getBegin();
10725 Comp
.LocEnd
= ON
.getSourceRange().getEnd();
10726 switch (ON
.getKind()) {
10727 case OffsetOfNode::Array
: {
10728 Expr
*FromIndex
= E
->getIndexExpr(ON
.getArrayExprIndex());
10729 ExprResult Index
= getDerived().TransformExpr(FromIndex
);
10730 if (Index
.isInvalid())
10731 return ExprError();
10733 ExprChanged
= ExprChanged
|| Index
.get() != FromIndex
;
10734 Comp
.isBrackets
= true;
10735 Comp
.U
.E
= Index
.get();
10739 case OffsetOfNode::Field
:
10740 case OffsetOfNode::Identifier
:
10741 Comp
.isBrackets
= false;
10742 Comp
.U
.IdentInfo
= ON
.getFieldName();
10743 if (!Comp
.U
.IdentInfo
)
10748 case OffsetOfNode::Base
:
10749 // Will be recomputed during the rebuild.
10753 Components
.push_back(Comp
);
10756 // If nothing changed, retain the existing expression.
10757 if (!getDerived().AlwaysRebuild() &&
10758 Type
== E
->getTypeSourceInfo() &&
10762 // Build a new offsetof expression.
10763 return getDerived().RebuildOffsetOfExpr(E
->getOperatorLoc(), Type
,
10764 Components
, E
->getRParenLoc());
10767 template<typename Derived
>
10769 TreeTransform
<Derived
>::TransformOpaqueValueExpr(OpaqueValueExpr
*E
) {
10770 assert((!E
->getSourceExpr() || getDerived().AlreadyTransformed(E
->getType())) &&
10771 "opaque value expression requires transformation");
10775 template<typename Derived
>
10777 TreeTransform
<Derived
>::TransformTypoExpr(TypoExpr
*E
) {
10781 template <typename Derived
>
10782 ExprResult TreeTransform
<Derived
>::TransformRecoveryExpr(RecoveryExpr
*E
) {
10783 llvm::SmallVector
<Expr
*, 8> Children
;
10784 bool Changed
= false;
10785 for (Expr
*C
: E
->subExpressions()) {
10786 ExprResult NewC
= getDerived().TransformExpr(C
);
10787 if (NewC
.isInvalid())
10788 return ExprError();
10789 Children
.push_back(NewC
.get());
10791 Changed
|= NewC
.get() != C
;
10793 if (!getDerived().AlwaysRebuild() && !Changed
)
10795 return getDerived().RebuildRecoveryExpr(E
->getBeginLoc(), E
->getEndLoc(),
10796 Children
, E
->getType());
10799 template<typename Derived
>
10801 TreeTransform
<Derived
>::TransformPseudoObjectExpr(PseudoObjectExpr
*E
) {
10802 // Rebuild the syntactic form. The original syntactic form has
10803 // opaque-value expressions in it, so strip those away and rebuild
10804 // the result. This is a really awful way of doing this, but the
10805 // better solution (rebuilding the semantic expressions and
10806 // rebinding OVEs as necessary) doesn't work; we'd need
10807 // TreeTransform to not strip away implicit conversions.
10808 Expr
*newSyntacticForm
= SemaRef
.recreateSyntacticForm(E
);
10809 ExprResult result
= getDerived().TransformExpr(newSyntacticForm
);
10810 if (result
.isInvalid()) return ExprError();
10812 // If that gives us a pseudo-object result back, the pseudo-object
10813 // expression must have been an lvalue-to-rvalue conversion which we
10815 if (result
.get()->hasPlaceholderType(BuiltinType::PseudoObject
))
10816 result
= SemaRef
.checkPseudoObjectRValue(result
.get());
10821 template<typename Derived
>
10823 TreeTransform
<Derived
>::TransformUnaryExprOrTypeTraitExpr(
10824 UnaryExprOrTypeTraitExpr
*E
) {
10825 if (E
->isArgumentType()) {
10826 TypeSourceInfo
*OldT
= E
->getArgumentTypeInfo();
10828 TypeSourceInfo
*NewT
= getDerived().TransformType(OldT
);
10830 return ExprError();
10832 if (!getDerived().AlwaysRebuild() && OldT
== NewT
)
10835 return getDerived().RebuildUnaryExprOrTypeTrait(NewT
, E
->getOperatorLoc(),
10837 E
->getSourceRange());
10840 // C++0x [expr.sizeof]p1:
10841 // The operand is either an expression, which is an unevaluated operand
10843 EnterExpressionEvaluationContext
Unevaluated(
10844 SemaRef
, Sema::ExpressionEvaluationContext::Unevaluated
,
10845 Sema::ReuseLambdaContextDecl
);
10847 // Try to recover if we have something like sizeof(T::X) where X is a type.
10848 // Notably, there must be *exactly* one set of parens if X is a type.
10849 TypeSourceInfo
*RecoveryTSI
= nullptr;
10850 ExprResult SubExpr
;
10851 auto *PE
= dyn_cast
<ParenExpr
>(E
->getArgumentExpr());
10853 PE
? dyn_cast
<DependentScopeDeclRefExpr
>(PE
->getSubExpr()) : nullptr)
10854 SubExpr
= getDerived().TransformParenDependentScopeDeclRefExpr(
10855 PE
, DRE
, false, &RecoveryTSI
);
10857 SubExpr
= getDerived().TransformExpr(E
->getArgumentExpr());
10860 return getDerived().RebuildUnaryExprOrTypeTrait(
10861 RecoveryTSI
, E
->getOperatorLoc(), E
->getKind(), E
->getSourceRange());
10862 } else if (SubExpr
.isInvalid())
10863 return ExprError();
10865 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getArgumentExpr())
10868 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr
.get(),
10869 E
->getOperatorLoc(),
10871 E
->getSourceRange());
10874 template<typename Derived
>
10876 TreeTransform
<Derived
>::TransformArraySubscriptExpr(ArraySubscriptExpr
*E
) {
10877 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
10878 if (LHS
.isInvalid())
10879 return ExprError();
10881 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
10882 if (RHS
.isInvalid())
10883 return ExprError();
10886 if (!getDerived().AlwaysRebuild() &&
10887 LHS
.get() == E
->getLHS() &&
10888 RHS
.get() == E
->getRHS())
10891 return getDerived().RebuildArraySubscriptExpr(
10893 /*FIXME:*/ E
->getLHS()->getBeginLoc(), RHS
.get(), E
->getRBracketLoc());
10896 template <typename Derived
>
10898 TreeTransform
<Derived
>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr
*E
) {
10899 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
10900 if (Base
.isInvalid())
10901 return ExprError();
10903 ExprResult RowIdx
= getDerived().TransformExpr(E
->getRowIdx());
10904 if (RowIdx
.isInvalid())
10905 return ExprError();
10907 ExprResult ColumnIdx
= getDerived().TransformExpr(E
->getColumnIdx());
10908 if (ColumnIdx
.isInvalid())
10909 return ExprError();
10911 if (!getDerived().AlwaysRebuild() && Base
.get() == E
->getBase() &&
10912 RowIdx
.get() == E
->getRowIdx() && ColumnIdx
.get() == E
->getColumnIdx())
10915 return getDerived().RebuildMatrixSubscriptExpr(
10916 Base
.get(), RowIdx
.get(), ColumnIdx
.get(), E
->getRBracketLoc());
10919 template <typename Derived
>
10921 TreeTransform
<Derived
>::TransformOMPArraySectionExpr(OMPArraySectionExpr
*E
) {
10922 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
10923 if (Base
.isInvalid())
10924 return ExprError();
10926 ExprResult LowerBound
;
10927 if (E
->getLowerBound()) {
10928 LowerBound
= getDerived().TransformExpr(E
->getLowerBound());
10929 if (LowerBound
.isInvalid())
10930 return ExprError();
10934 if (E
->getLength()) {
10935 Length
= getDerived().TransformExpr(E
->getLength());
10936 if (Length
.isInvalid())
10937 return ExprError();
10941 if (Expr
*Str
= E
->getStride()) {
10942 Stride
= getDerived().TransformExpr(Str
);
10943 if (Stride
.isInvalid())
10944 return ExprError();
10947 if (!getDerived().AlwaysRebuild() && Base
.get() == E
->getBase() &&
10948 LowerBound
.get() == E
->getLowerBound() && Length
.get() == E
->getLength())
10951 return getDerived().RebuildOMPArraySectionExpr(
10952 Base
.get(), E
->getBase()->getEndLoc(), LowerBound
.get(),
10953 E
->getColonLocFirst(), E
->getColonLocSecond(), Length
.get(), Stride
.get(),
10954 E
->getRBracketLoc());
10957 template <typename Derived
>
10959 TreeTransform
<Derived
>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr
*E
) {
10960 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
10961 if (Base
.isInvalid())
10962 return ExprError();
10964 SmallVector
<Expr
*, 4> Dims
;
10965 bool ErrorFound
= false;
10966 for (Expr
*Dim
: E
->getDimensions()) {
10967 ExprResult DimRes
= getDerived().TransformExpr(Dim
);
10968 if (DimRes
.isInvalid()) {
10972 Dims
.push_back(DimRes
.get());
10976 return ExprError();
10977 return getDerived().RebuildOMPArrayShapingExpr(Base
.get(), E
->getLParenLoc(),
10978 E
->getRParenLoc(), Dims
,
10979 E
->getBracketsRanges());
10982 template <typename Derived
>
10984 TreeTransform
<Derived
>::TransformOMPIteratorExpr(OMPIteratorExpr
*E
) {
10985 unsigned NumIterators
= E
->numOfIterators();
10986 SmallVector
<Sema::OMPIteratorData
, 4> Data(NumIterators
);
10988 bool ErrorFound
= false;
10989 bool NeedToRebuild
= getDerived().AlwaysRebuild();
10990 for (unsigned I
= 0; I
< NumIterators
; ++I
) {
10991 auto *D
= cast
<VarDecl
>(E
->getIteratorDecl(I
));
10992 Data
[I
].DeclIdent
= D
->getIdentifier();
10993 Data
[I
].DeclIdentLoc
= D
->getLocation();
10994 if (D
->getLocation() == D
->getBeginLoc()) {
10995 assert(SemaRef
.Context
.hasSameType(D
->getType(), SemaRef
.Context
.IntTy
) &&
10996 "Implicit type must be int.");
10998 TypeSourceInfo
*TSI
= getDerived().TransformType(D
->getTypeSourceInfo());
10999 QualType DeclTy
= getDerived().TransformType(D
->getType());
11000 Data
[I
].Type
= SemaRef
.CreateParsedType(DeclTy
, TSI
);
11002 OMPIteratorExpr::IteratorRange Range
= E
->getIteratorRange(I
);
11003 ExprResult Begin
= getDerived().TransformExpr(Range
.Begin
);
11004 ExprResult End
= getDerived().TransformExpr(Range
.End
);
11005 ExprResult Step
= getDerived().TransformExpr(Range
.Step
);
11006 ErrorFound
= ErrorFound
||
11007 !(!D
->getTypeSourceInfo() || (Data
[I
].Type
.getAsOpaquePtr() &&
11008 !Data
[I
].Type
.get().isNull())) ||
11009 Begin
.isInvalid() || End
.isInvalid() || Step
.isInvalid();
11012 Data
[I
].Range
.Begin
= Begin
.get();
11013 Data
[I
].Range
.End
= End
.get();
11014 Data
[I
].Range
.Step
= Step
.get();
11015 Data
[I
].AssignLoc
= E
->getAssignLoc(I
);
11016 Data
[I
].ColonLoc
= E
->getColonLoc(I
);
11017 Data
[I
].SecColonLoc
= E
->getSecondColonLoc(I
);
11020 (D
->getTypeSourceInfo() && Data
[I
].Type
.get().getTypePtrOrNull() !=
11021 D
->getType().getTypePtrOrNull()) ||
11022 Range
.Begin
!= Data
[I
].Range
.Begin
|| Range
.End
!= Data
[I
].Range
.End
||
11023 Range
.Step
!= Data
[I
].Range
.Step
;
11026 return ExprError();
11027 if (!NeedToRebuild
)
11030 ExprResult Res
= getDerived().RebuildOMPIteratorExpr(
11031 E
->getIteratorKwLoc(), E
->getLParenLoc(), E
->getRParenLoc(), Data
);
11032 if (!Res
.isUsable())
11034 auto *IE
= cast
<OMPIteratorExpr
>(Res
.get());
11035 for (unsigned I
= 0; I
< NumIterators
; ++I
)
11036 getDerived().transformedLocalDecl(E
->getIteratorDecl(I
),
11037 IE
->getIteratorDecl(I
));
11041 template<typename Derived
>
11043 TreeTransform
<Derived
>::TransformCallExpr(CallExpr
*E
) {
11044 // Transform the callee.
11045 ExprResult Callee
= getDerived().TransformExpr(E
->getCallee());
11046 if (Callee
.isInvalid())
11047 return ExprError();
11049 // Transform arguments.
11050 bool ArgChanged
= false;
11051 SmallVector
<Expr
*, 8> Args
;
11052 if (getDerived().TransformExprs(E
->getArgs(), E
->getNumArgs(), true, Args
,
11054 return ExprError();
11056 if (!getDerived().AlwaysRebuild() &&
11057 Callee
.get() == E
->getCallee() &&
11059 return SemaRef
.MaybeBindToTemporary(E
);
11061 // FIXME: Wrong source location information for the '('.
11062 SourceLocation FakeLParenLoc
11063 = ((Expr
*)Callee
.get())->getSourceRange().getBegin();
11065 Sema::FPFeaturesStateRAII
FPFeaturesState(getSema());
11066 if (E
->hasStoredFPFeatures()) {
11067 FPOptionsOverride NewOverrides
= E
->getFPFeatures();
11068 getSema().CurFPFeatures
=
11069 NewOverrides
.applyOverrides(getSema().getLangOpts());
11070 getSema().FpPragmaStack
.CurrentValue
= NewOverrides
;
11073 return getDerived().RebuildCallExpr(Callee
.get(), FakeLParenLoc
,
11075 E
->getRParenLoc());
11078 template<typename Derived
>
11080 TreeTransform
<Derived
>::TransformMemberExpr(MemberExpr
*E
) {
11081 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
11082 if (Base
.isInvalid())
11083 return ExprError();
11085 NestedNameSpecifierLoc QualifierLoc
;
11086 if (E
->hasQualifier()) {
11088 = getDerived().TransformNestedNameSpecifierLoc(E
->getQualifierLoc());
11091 return ExprError();
11093 SourceLocation TemplateKWLoc
= E
->getTemplateKeywordLoc();
11096 = cast_or_null
<ValueDecl
>(getDerived().TransformDecl(E
->getMemberLoc(),
11097 E
->getMemberDecl()));
11099 return ExprError();
11101 NamedDecl
*FoundDecl
= E
->getFoundDecl();
11102 if (FoundDecl
== E
->getMemberDecl()) {
11103 FoundDecl
= Member
;
11105 FoundDecl
= cast_or_null
<NamedDecl
>(
11106 getDerived().TransformDecl(E
->getMemberLoc(), FoundDecl
));
11108 return ExprError();
11111 if (!getDerived().AlwaysRebuild() &&
11112 Base
.get() == E
->getBase() &&
11113 QualifierLoc
== E
->getQualifierLoc() &&
11114 Member
== E
->getMemberDecl() &&
11115 FoundDecl
== E
->getFoundDecl() &&
11116 !E
->hasExplicitTemplateArgs()) {
11118 // Skip for member expression of (this->f), rebuilt thisi->f is needed
11119 // for Openmp where the field need to be privatizized in the case.
11120 if (!(isa
<CXXThisExpr
>(E
->getBase()) &&
11121 getSema().isOpenMPRebuildMemberExpr(cast
<ValueDecl
>(Member
)))) {
11122 // Mark it referenced in the new context regardless.
11123 // FIXME: this is a bit instantiation-specific.
11124 SemaRef
.MarkMemberReferenced(E
);
11129 TemplateArgumentListInfo TransArgs
;
11130 if (E
->hasExplicitTemplateArgs()) {
11131 TransArgs
.setLAngleLoc(E
->getLAngleLoc());
11132 TransArgs
.setRAngleLoc(E
->getRAngleLoc());
11133 if (getDerived().TransformTemplateArguments(E
->getTemplateArgs(),
11134 E
->getNumTemplateArgs(),
11136 return ExprError();
11139 // FIXME: Bogus source location for the operator
11140 SourceLocation FakeOperatorLoc
=
11141 SemaRef
.getLocForEndOfToken(E
->getBase()->getSourceRange().getEnd());
11143 // FIXME: to do this check properly, we will need to preserve the
11144 // first-qualifier-in-scope here, just in case we had a dependent
11145 // base (and therefore couldn't do the check) and a
11146 // nested-name-qualifier (and therefore could do the lookup).
11147 NamedDecl
*FirstQualifierInScope
= nullptr;
11148 DeclarationNameInfo MemberNameInfo
= E
->getMemberNameInfo();
11149 if (MemberNameInfo
.getName()) {
11150 MemberNameInfo
= getDerived().TransformDeclarationNameInfo(MemberNameInfo
);
11151 if (!MemberNameInfo
.getName())
11152 return ExprError();
11155 return getDerived().RebuildMemberExpr(Base
.get(), FakeOperatorLoc
,
11162 (E
->hasExplicitTemplateArgs()
11163 ? &TransArgs
: nullptr),
11164 FirstQualifierInScope
);
11167 template<typename Derived
>
11169 TreeTransform
<Derived
>::TransformBinaryOperator(BinaryOperator
*E
) {
11170 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
11171 if (LHS
.isInvalid())
11172 return ExprError();
11174 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
11175 if (RHS
.isInvalid())
11176 return ExprError();
11178 if (!getDerived().AlwaysRebuild() &&
11179 LHS
.get() == E
->getLHS() &&
11180 RHS
.get() == E
->getRHS())
11183 if (E
->isCompoundAssignmentOp())
11184 // FPFeatures has already been established from trailing storage
11185 return getDerived().RebuildBinaryOperator(
11186 E
->getOperatorLoc(), E
->getOpcode(), LHS
.get(), RHS
.get());
11187 Sema::FPFeaturesStateRAII
FPFeaturesState(getSema());
11188 FPOptionsOverride
NewOverrides(E
->getFPFeatures());
11189 getSema().CurFPFeatures
=
11190 NewOverrides
.applyOverrides(getSema().getLangOpts());
11191 getSema().FpPragmaStack
.CurrentValue
= NewOverrides
;
11192 return getDerived().RebuildBinaryOperator(E
->getOperatorLoc(), E
->getOpcode(),
11193 LHS
.get(), RHS
.get());
11196 template <typename Derived
>
11197 ExprResult TreeTransform
<Derived
>::TransformCXXRewrittenBinaryOperator(
11198 CXXRewrittenBinaryOperator
*E
) {
11199 CXXRewrittenBinaryOperator::DecomposedForm Decomp
= E
->getDecomposedForm();
11201 ExprResult LHS
= getDerived().TransformExpr(const_cast<Expr
*>(Decomp
.LHS
));
11202 if (LHS
.isInvalid())
11203 return ExprError();
11205 ExprResult RHS
= getDerived().TransformExpr(const_cast<Expr
*>(Decomp
.RHS
));
11206 if (RHS
.isInvalid())
11207 return ExprError();
11209 // Extract the already-resolved callee declarations so that we can restrict
11210 // ourselves to using them as the unqualified lookup results when rebuilding.
11211 UnresolvedSet
<2> UnqualLookups
;
11212 bool ChangedAnyLookups
= false;
11213 Expr
*PossibleBinOps
[] = {E
->getSemanticForm(),
11214 const_cast<Expr
*>(Decomp
.InnerBinOp
)};
11215 for (Expr
*PossibleBinOp
: PossibleBinOps
) {
11216 auto *Op
= dyn_cast
<CXXOperatorCallExpr
>(PossibleBinOp
->IgnoreImplicit());
11219 auto *Callee
= dyn_cast
<DeclRefExpr
>(Op
->getCallee()->IgnoreImplicit());
11220 if (!Callee
|| isa
<CXXMethodDecl
>(Callee
->getDecl()))
11223 // Transform the callee in case we built a call to a local extern
11225 NamedDecl
*Found
= cast_or_null
<NamedDecl
>(getDerived().TransformDecl(
11226 E
->getOperatorLoc(), Callee
->getFoundDecl()));
11228 return ExprError();
11229 if (Found
!= Callee
->getFoundDecl())
11230 ChangedAnyLookups
= true;
11231 UnqualLookups
.addDecl(Found
);
11234 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups
&&
11235 LHS
.get() == Decomp
.LHS
&& RHS
.get() == Decomp
.RHS
) {
11236 // Mark all functions used in the rewrite as referenced. Note that when
11237 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
11238 // function calls, and/or there might be a user-defined conversion sequence
11239 // applied to the operands of the <.
11240 // FIXME: this is a bit instantiation-specific.
11241 const Expr
*StopAt
[] = {Decomp
.LHS
, Decomp
.RHS
};
11242 SemaRef
.MarkDeclarationsReferencedInExpr(E
, false, StopAt
);
11246 return getDerived().RebuildCXXRewrittenBinaryOperator(
11247 E
->getOperatorLoc(), Decomp
.Opcode
, UnqualLookups
, LHS
.get(), RHS
.get());
11250 template<typename Derived
>
11252 TreeTransform
<Derived
>::TransformCompoundAssignOperator(
11253 CompoundAssignOperator
*E
) {
11254 Sema::FPFeaturesStateRAII
FPFeaturesState(getSema());
11255 FPOptionsOverride
NewOverrides(E
->getFPFeatures());
11256 getSema().CurFPFeatures
=
11257 NewOverrides
.applyOverrides(getSema().getLangOpts());
11258 getSema().FpPragmaStack
.CurrentValue
= NewOverrides
;
11259 return getDerived().TransformBinaryOperator(E
);
11262 template<typename Derived
>
11263 ExprResult TreeTransform
<Derived
>::
11264 TransformBinaryConditionalOperator(BinaryConditionalOperator
*e
) {
11265 // Just rebuild the common and RHS expressions and see whether we
11266 // get any changes.
11268 ExprResult commonExpr
= getDerived().TransformExpr(e
->getCommon());
11269 if (commonExpr
.isInvalid())
11270 return ExprError();
11272 ExprResult rhs
= getDerived().TransformExpr(e
->getFalseExpr());
11273 if (rhs
.isInvalid())
11274 return ExprError();
11276 if (!getDerived().AlwaysRebuild() &&
11277 commonExpr
.get() == e
->getCommon() &&
11278 rhs
.get() == e
->getFalseExpr())
11281 return getDerived().RebuildConditionalOperator(commonExpr
.get(),
11282 e
->getQuestionLoc(),
11288 template<typename Derived
>
11290 TreeTransform
<Derived
>::TransformConditionalOperator(ConditionalOperator
*E
) {
11291 ExprResult Cond
= getDerived().TransformExpr(E
->getCond());
11292 if (Cond
.isInvalid())
11293 return ExprError();
11295 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
11296 if (LHS
.isInvalid())
11297 return ExprError();
11299 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
11300 if (RHS
.isInvalid())
11301 return ExprError();
11303 if (!getDerived().AlwaysRebuild() &&
11304 Cond
.get() == E
->getCond() &&
11305 LHS
.get() == E
->getLHS() &&
11306 RHS
.get() == E
->getRHS())
11309 return getDerived().RebuildConditionalOperator(Cond
.get(),
11310 E
->getQuestionLoc(),
11316 template<typename Derived
>
11318 TreeTransform
<Derived
>::TransformImplicitCastExpr(ImplicitCastExpr
*E
) {
11319 // Implicit casts are eliminated during transformation, since they
11320 // will be recomputed by semantic analysis after transformation.
11321 return getDerived().TransformExpr(E
->getSubExprAsWritten());
11324 template<typename Derived
>
11326 TreeTransform
<Derived
>::TransformCStyleCastExpr(CStyleCastExpr
*E
) {
11327 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeInfoAsWritten());
11329 return ExprError();
11332 = getDerived().TransformExpr(E
->getSubExprAsWritten());
11333 if (SubExpr
.isInvalid())
11334 return ExprError();
11336 if (!getDerived().AlwaysRebuild() &&
11337 Type
== E
->getTypeInfoAsWritten() &&
11338 SubExpr
.get() == E
->getSubExpr())
11341 return getDerived().RebuildCStyleCastExpr(E
->getLParenLoc(),
11347 template<typename Derived
>
11349 TreeTransform
<Derived
>::TransformCompoundLiteralExpr(CompoundLiteralExpr
*E
) {
11350 TypeSourceInfo
*OldT
= E
->getTypeSourceInfo();
11351 TypeSourceInfo
*NewT
= getDerived().TransformType(OldT
);
11353 return ExprError();
11355 ExprResult Init
= getDerived().TransformExpr(E
->getInitializer());
11356 if (Init
.isInvalid())
11357 return ExprError();
11359 if (!getDerived().AlwaysRebuild() &&
11361 Init
.get() == E
->getInitializer())
11362 return SemaRef
.MaybeBindToTemporary(E
);
11364 // Note: the expression type doesn't necessarily match the
11365 // type-as-written, but that's okay, because it should always be
11366 // derivable from the initializer.
11368 return getDerived().RebuildCompoundLiteralExpr(
11369 E
->getLParenLoc(), NewT
,
11370 /*FIXME:*/ E
->getInitializer()->getEndLoc(), Init
.get());
11373 template<typename Derived
>
11375 TreeTransform
<Derived
>::TransformExtVectorElementExpr(ExtVectorElementExpr
*E
) {
11376 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
11377 if (Base
.isInvalid())
11378 return ExprError();
11380 if (!getDerived().AlwaysRebuild() &&
11381 Base
.get() == E
->getBase())
11384 // FIXME: Bad source location
11385 SourceLocation FakeOperatorLoc
=
11386 SemaRef
.getLocForEndOfToken(E
->getBase()->getEndLoc());
11387 return getDerived().RebuildExtVectorElementExpr(Base
.get(), FakeOperatorLoc
,
11388 E
->getAccessorLoc(),
11392 template<typename Derived
>
11394 TreeTransform
<Derived
>::TransformInitListExpr(InitListExpr
*E
) {
11395 if (InitListExpr
*Syntactic
= E
->getSyntacticForm())
11398 bool InitChanged
= false;
11400 EnterExpressionEvaluationContext
Context(
11401 getSema(), EnterExpressionEvaluationContext::InitList
);
11403 SmallVector
<Expr
*, 4> Inits
;
11404 if (getDerived().TransformExprs(E
->getInits(), E
->getNumInits(), false,
11405 Inits
, &InitChanged
))
11406 return ExprError();
11408 if (!getDerived().AlwaysRebuild() && !InitChanged
) {
11409 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
11410 // in some cases. We can't reuse it in general, because the syntactic and
11411 // semantic forms are linked, and we can't know that semantic form will
11412 // match even if the syntactic form does.
11415 return getDerived().RebuildInitList(E
->getLBraceLoc(), Inits
,
11416 E
->getRBraceLoc());
11419 template<typename Derived
>
11421 TreeTransform
<Derived
>::TransformDesignatedInitExpr(DesignatedInitExpr
*E
) {
11424 // transform the initializer value
11425 ExprResult Init
= getDerived().TransformExpr(E
->getInit());
11426 if (Init
.isInvalid())
11427 return ExprError();
11429 // transform the designators.
11430 SmallVector
<Expr
*, 4> ArrayExprs
;
11431 bool ExprChanged
= false;
11432 for (const DesignatedInitExpr::Designator
&D
: E
->designators()) {
11433 if (D
.isFieldDesignator()) {
11434 Desig
.AddDesignator(Designator::getField(D
.getFieldName(),
11437 if (D
.getField()) {
11438 FieldDecl
*Field
= cast_or_null
<FieldDecl
>(
11439 getDerived().TransformDecl(D
.getFieldLoc(), D
.getField()));
11440 if (Field
!= D
.getField())
11441 // Rebuild the expression when the transformed FieldDecl is
11442 // different to the already assigned FieldDecl.
11443 ExprChanged
= true;
11445 // Ensure that the designator expression is rebuilt when there isn't
11446 // a resolved FieldDecl in the designator as we don't want to assign
11447 // a FieldDecl to a pattern designator that will be instantiated again.
11448 ExprChanged
= true;
11453 if (D
.isArrayDesignator()) {
11454 ExprResult Index
= getDerived().TransformExpr(E
->getArrayIndex(D
));
11455 if (Index
.isInvalid())
11456 return ExprError();
11458 Desig
.AddDesignator(
11459 Designator::getArray(Index
.get(), D
.getLBracketLoc()));
11461 ExprChanged
= ExprChanged
|| Init
.get() != E
->getArrayIndex(D
);
11462 ArrayExprs
.push_back(Index
.get());
11466 assert(D
.isArrayRangeDesignator() && "New kind of designator?");
11468 = getDerived().TransformExpr(E
->getArrayRangeStart(D
));
11469 if (Start
.isInvalid())
11470 return ExprError();
11472 ExprResult End
= getDerived().TransformExpr(E
->getArrayRangeEnd(D
));
11473 if (End
.isInvalid())
11474 return ExprError();
11476 Desig
.AddDesignator(Designator::getArrayRange(Start
.get(),
11478 D
.getLBracketLoc(),
11479 D
.getEllipsisLoc()));
11481 ExprChanged
= ExprChanged
|| Start
.get() != E
->getArrayRangeStart(D
) ||
11482 End
.get() != E
->getArrayRangeEnd(D
);
11484 ArrayExprs
.push_back(Start
.get());
11485 ArrayExprs
.push_back(End
.get());
11488 if (!getDerived().AlwaysRebuild() &&
11489 Init
.get() == E
->getInit() &&
11493 return getDerived().RebuildDesignatedInitExpr(Desig
, ArrayExprs
,
11494 E
->getEqualOrColonLoc(),
11495 E
->usesGNUSyntax(), Init
.get());
11498 // Seems that if TransformInitListExpr() only works on the syntactic form of an
11499 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
11500 template<typename Derived
>
11502 TreeTransform
<Derived
>::TransformDesignatedInitUpdateExpr(
11503 DesignatedInitUpdateExpr
*E
) {
11504 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
11506 return ExprError();
11509 template<typename Derived
>
11511 TreeTransform
<Derived
>::TransformNoInitExpr(
11513 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
11514 return ExprError();
11517 template<typename Derived
>
11519 TreeTransform
<Derived
>::TransformArrayInitLoopExpr(ArrayInitLoopExpr
*E
) {
11520 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
11521 return ExprError();
11524 template<typename Derived
>
11526 TreeTransform
<Derived
>::TransformArrayInitIndexExpr(ArrayInitIndexExpr
*E
) {
11527 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
11528 return ExprError();
11531 template<typename Derived
>
11533 TreeTransform
<Derived
>::TransformImplicitValueInitExpr(
11534 ImplicitValueInitExpr
*E
) {
11535 TemporaryBase
Rebase(*this, E
->getBeginLoc(), DeclarationName());
11537 // FIXME: Will we ever have proper type location here? Will we actually
11538 // need to transform the type?
11539 QualType T
= getDerived().TransformType(E
->getType());
11541 return ExprError();
11543 if (!getDerived().AlwaysRebuild() &&
11547 return getDerived().RebuildImplicitValueInitExpr(T
);
11550 template<typename Derived
>
11552 TreeTransform
<Derived
>::TransformVAArgExpr(VAArgExpr
*E
) {
11553 TypeSourceInfo
*TInfo
= getDerived().TransformType(E
->getWrittenTypeInfo());
11555 return ExprError();
11557 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
11558 if (SubExpr
.isInvalid())
11559 return ExprError();
11561 if (!getDerived().AlwaysRebuild() &&
11562 TInfo
== E
->getWrittenTypeInfo() &&
11563 SubExpr
.get() == E
->getSubExpr())
11566 return getDerived().RebuildVAArgExpr(E
->getBuiltinLoc(), SubExpr
.get(),
11567 TInfo
, E
->getRParenLoc());
11570 template<typename Derived
>
11572 TreeTransform
<Derived
>::TransformParenListExpr(ParenListExpr
*E
) {
11573 bool ArgumentChanged
= false;
11574 SmallVector
<Expr
*, 4> Inits
;
11575 if (TransformExprs(E
->getExprs(), E
->getNumExprs(), true, Inits
,
11577 return ExprError();
11579 return getDerived().RebuildParenListExpr(E
->getLParenLoc(),
11581 E
->getRParenLoc());
11584 /// Transform an address-of-label expression.
11586 /// By default, the transformation of an address-of-label expression always
11587 /// rebuilds the expression, so that the label identifier can be resolved to
11588 /// the corresponding label statement by semantic analysis.
11589 template<typename Derived
>
11591 TreeTransform
<Derived
>::TransformAddrLabelExpr(AddrLabelExpr
*E
) {
11592 Decl
*LD
= getDerived().TransformDecl(E
->getLabel()->getLocation(),
11595 return ExprError();
11597 return getDerived().RebuildAddrLabelExpr(E
->getAmpAmpLoc(), E
->getLabelLoc(),
11598 cast
<LabelDecl
>(LD
));
11601 template<typename Derived
>
11603 TreeTransform
<Derived
>::TransformStmtExpr(StmtExpr
*E
) {
11604 SemaRef
.ActOnStartStmtExpr();
11606 = getDerived().TransformCompoundStmt(E
->getSubStmt(), true);
11607 if (SubStmt
.isInvalid()) {
11608 SemaRef
.ActOnStmtExprError();
11609 return ExprError();
11612 unsigned OldDepth
= E
->getTemplateDepth();
11613 unsigned NewDepth
= getDerived().TransformTemplateDepth(OldDepth
);
11615 if (!getDerived().AlwaysRebuild() && OldDepth
== NewDepth
&&
11616 SubStmt
.get() == E
->getSubStmt()) {
11617 // Calling this an 'error' is unintuitive, but it does the right thing.
11618 SemaRef
.ActOnStmtExprError();
11619 return SemaRef
.MaybeBindToTemporary(E
);
11622 return getDerived().RebuildStmtExpr(E
->getLParenLoc(), SubStmt
.get(),
11623 E
->getRParenLoc(), NewDepth
);
11626 template<typename Derived
>
11628 TreeTransform
<Derived
>::TransformChooseExpr(ChooseExpr
*E
) {
11629 ExprResult Cond
= getDerived().TransformExpr(E
->getCond());
11630 if (Cond
.isInvalid())
11631 return ExprError();
11633 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
11634 if (LHS
.isInvalid())
11635 return ExprError();
11637 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
11638 if (RHS
.isInvalid())
11639 return ExprError();
11641 if (!getDerived().AlwaysRebuild() &&
11642 Cond
.get() == E
->getCond() &&
11643 LHS
.get() == E
->getLHS() &&
11644 RHS
.get() == E
->getRHS())
11647 return getDerived().RebuildChooseExpr(E
->getBuiltinLoc(),
11648 Cond
.get(), LHS
.get(), RHS
.get(),
11649 E
->getRParenLoc());
11652 template<typename Derived
>
11654 TreeTransform
<Derived
>::TransformGNUNullExpr(GNUNullExpr
*E
) {
11658 template<typename Derived
>
11660 TreeTransform
<Derived
>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr
*E
) {
11661 switch (E
->getOperator()) {
11665 case OO_Array_Delete
:
11666 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
11670 // This is a call to an object's operator().
11671 assert(E
->getNumArgs() >= 1 && "Object call is missing arguments");
11673 // Transform the object itself.
11674 ExprResult Object
= getDerived().TransformExpr(E
->getArg(0));
11675 if (Object
.isInvalid())
11676 return ExprError();
11678 // FIXME: Poor location information
11679 SourceLocation FakeLParenLoc
= SemaRef
.getLocForEndOfToken(
11680 static_cast<Expr
*>(Object
.get())->getEndLoc());
11682 // Transform the call arguments.
11683 SmallVector
<Expr
*, 8> Args
;
11684 if (getDerived().TransformExprs(E
->getArgs() + 1, E
->getNumArgs() - 1, true,
11686 return ExprError();
11688 if (E
->getOperator() == OO_Subscript
)
11689 return getDerived().RebuildCxxSubscriptExpr(Object
.get(), FakeLParenLoc
,
11690 Args
, E
->getEndLoc());
11692 return getDerived().RebuildCallExpr(Object
.get(), FakeLParenLoc
, Args
,
11696 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
11700 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
11701 #include "clang/Basic/OperatorKinds.def"
11703 case OO_Conditional
:
11704 llvm_unreachable("conditional operator is not actually overloadable");
11707 case NUM_OVERLOADED_OPERATORS
:
11708 llvm_unreachable("not an overloaded operator?");
11711 ExprResult Callee
= getDerived().TransformExpr(E
->getCallee());
11712 if (Callee
.isInvalid())
11713 return ExprError();
11716 if (E
->getOperator() == OO_Amp
)
11717 First
= getDerived().TransformAddressOfOperand(E
->getArg(0));
11719 First
= getDerived().TransformExpr(E
->getArg(0));
11720 if (First
.isInvalid())
11721 return ExprError();
11724 if (E
->getNumArgs() == 2) {
11725 Second
= getDerived().TransformExpr(E
->getArg(1));
11726 if (Second
.isInvalid())
11727 return ExprError();
11730 if (!getDerived().AlwaysRebuild() &&
11731 Callee
.get() == E
->getCallee() &&
11732 First
.get() == E
->getArg(0) &&
11733 (E
->getNumArgs() != 2 || Second
.get() == E
->getArg(1)))
11734 return SemaRef
.MaybeBindToTemporary(E
);
11736 Sema::FPFeaturesStateRAII
FPFeaturesState(getSema());
11737 FPOptionsOverride
NewOverrides(E
->getFPFeatures());
11738 getSema().CurFPFeatures
=
11739 NewOverrides
.applyOverrides(getSema().getLangOpts());
11740 getSema().FpPragmaStack
.CurrentValue
= NewOverrides
;
11742 return getDerived().RebuildCXXOperatorCallExpr(E
->getOperator(),
11743 E
->getOperatorLoc(),
11749 template<typename Derived
>
11751 TreeTransform
<Derived
>::TransformCXXMemberCallExpr(CXXMemberCallExpr
*E
) {
11752 return getDerived().TransformCallExpr(E
);
11755 template <typename Derived
>
11756 ExprResult TreeTransform
<Derived
>::TransformSourceLocExpr(SourceLocExpr
*E
) {
11757 bool NeedRebuildFunc
= E
->getIdentKind() == SourceLocExpr::Function
&&
11758 getSema().CurContext
!= E
->getParentContext();
11760 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc
)
11763 return getDerived().RebuildSourceLocExpr(E
->getIdentKind(), E
->getType(),
11764 E
->getBeginLoc(), E
->getEndLoc(),
11765 getSema().CurContext
);
11768 template<typename Derived
>
11770 TreeTransform
<Derived
>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr
*E
) {
11771 // Transform the callee.
11772 ExprResult Callee
= getDerived().TransformExpr(E
->getCallee());
11773 if (Callee
.isInvalid())
11774 return ExprError();
11776 // Transform exec config.
11777 ExprResult EC
= getDerived().TransformCallExpr(E
->getConfig());
11778 if (EC
.isInvalid())
11779 return ExprError();
11781 // Transform arguments.
11782 bool ArgChanged
= false;
11783 SmallVector
<Expr
*, 8> Args
;
11784 if (getDerived().TransformExprs(E
->getArgs(), E
->getNumArgs(), true, Args
,
11786 return ExprError();
11788 if (!getDerived().AlwaysRebuild() &&
11789 Callee
.get() == E
->getCallee() &&
11791 return SemaRef
.MaybeBindToTemporary(E
);
11793 // FIXME: Wrong source location information for the '('.
11794 SourceLocation FakeLParenLoc
11795 = ((Expr
*)Callee
.get())->getSourceRange().getBegin();
11796 return getDerived().RebuildCallExpr(Callee
.get(), FakeLParenLoc
,
11798 E
->getRParenLoc(), EC
.get());
11801 template<typename Derived
>
11803 TreeTransform
<Derived
>::TransformCXXNamedCastExpr(CXXNamedCastExpr
*E
) {
11804 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeInfoAsWritten());
11806 return ExprError();
11809 = getDerived().TransformExpr(E
->getSubExprAsWritten());
11810 if (SubExpr
.isInvalid())
11811 return ExprError();
11813 if (!getDerived().AlwaysRebuild() &&
11814 Type
== E
->getTypeInfoAsWritten() &&
11815 SubExpr
.get() == E
->getSubExpr())
11817 return getDerived().RebuildCXXNamedCastExpr(
11818 E
->getOperatorLoc(), E
->getStmtClass(), E
->getAngleBrackets().getBegin(),
11819 Type
, E
->getAngleBrackets().getEnd(),
11820 // FIXME. this should be '(' location
11821 E
->getAngleBrackets().getEnd(), SubExpr
.get(), E
->getRParenLoc());
11824 template<typename Derived
>
11826 TreeTransform
<Derived
>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr
*BCE
) {
11827 TypeSourceInfo
*TSI
=
11828 getDerived().TransformType(BCE
->getTypeInfoAsWritten());
11830 return ExprError();
11832 ExprResult Sub
= getDerived().TransformExpr(BCE
->getSubExpr());
11833 if (Sub
.isInvalid())
11834 return ExprError();
11836 return getDerived().RebuildBuiltinBitCastExpr(BCE
->getBeginLoc(), TSI
,
11837 Sub
.get(), BCE
->getEndLoc());
11840 template<typename Derived
>
11842 TreeTransform
<Derived
>::TransformCXXStaticCastExpr(CXXStaticCastExpr
*E
) {
11843 return getDerived().TransformCXXNamedCastExpr(E
);
11846 template<typename Derived
>
11848 TreeTransform
<Derived
>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr
*E
) {
11849 return getDerived().TransformCXXNamedCastExpr(E
);
11852 template<typename Derived
>
11854 TreeTransform
<Derived
>::TransformCXXReinterpretCastExpr(
11855 CXXReinterpretCastExpr
*E
) {
11856 return getDerived().TransformCXXNamedCastExpr(E
);
11859 template<typename Derived
>
11861 TreeTransform
<Derived
>::TransformCXXConstCastExpr(CXXConstCastExpr
*E
) {
11862 return getDerived().TransformCXXNamedCastExpr(E
);
11865 template<typename Derived
>
11867 TreeTransform
<Derived
>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr
*E
) {
11868 return getDerived().TransformCXXNamedCastExpr(E
);
11871 template<typename Derived
>
11873 TreeTransform
<Derived
>::TransformCXXFunctionalCastExpr(
11874 CXXFunctionalCastExpr
*E
) {
11875 TypeSourceInfo
*Type
=
11876 getDerived().TransformTypeWithDeducedTST(E
->getTypeInfoAsWritten());
11878 return ExprError();
11881 = getDerived().TransformExpr(E
->getSubExprAsWritten());
11882 if (SubExpr
.isInvalid())
11883 return ExprError();
11885 if (!getDerived().AlwaysRebuild() &&
11886 Type
== E
->getTypeInfoAsWritten() &&
11887 SubExpr
.get() == E
->getSubExpr())
11890 return getDerived().RebuildCXXFunctionalCastExpr(Type
,
11894 E
->isListInitialization());
11897 template<typename Derived
>
11899 TreeTransform
<Derived
>::TransformCXXTypeidExpr(CXXTypeidExpr
*E
) {
11900 if (E
->isTypeOperand()) {
11901 TypeSourceInfo
*TInfo
11902 = getDerived().TransformType(E
->getTypeOperandSourceInfo());
11904 return ExprError();
11906 if (!getDerived().AlwaysRebuild() &&
11907 TInfo
== E
->getTypeOperandSourceInfo())
11910 return getDerived().RebuildCXXTypeidExpr(E
->getType(), E
->getBeginLoc(),
11911 TInfo
, E
->getEndLoc());
11914 // Typeid's operand is an unevaluated context, unless it's a polymorphic
11915 // type. We must not unilaterally enter unevaluated context here, as then
11916 // semantic processing can re-transform an already transformed operand.
11917 Expr
*Op
= E
->getExprOperand();
11918 auto EvalCtx
= Sema::ExpressionEvaluationContext::Unevaluated
;
11919 if (E
->isGLValue())
11920 if (auto *RecordT
= Op
->getType()->getAs
<RecordType
>())
11921 if (cast
<CXXRecordDecl
>(RecordT
->getDecl())->isPolymorphic())
11922 EvalCtx
= SemaRef
.ExprEvalContexts
.back().Context
;
11924 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, EvalCtx
,
11925 Sema::ReuseLambdaContextDecl
);
11927 ExprResult SubExpr
= getDerived().TransformExpr(Op
);
11928 if (SubExpr
.isInvalid())
11929 return ExprError();
11931 if (!getDerived().AlwaysRebuild() &&
11932 SubExpr
.get() == E
->getExprOperand())
11935 return getDerived().RebuildCXXTypeidExpr(E
->getType(), E
->getBeginLoc(),
11936 SubExpr
.get(), E
->getEndLoc());
11939 template<typename Derived
>
11941 TreeTransform
<Derived
>::TransformCXXUuidofExpr(CXXUuidofExpr
*E
) {
11942 if (E
->isTypeOperand()) {
11943 TypeSourceInfo
*TInfo
11944 = getDerived().TransformType(E
->getTypeOperandSourceInfo());
11946 return ExprError();
11948 if (!getDerived().AlwaysRebuild() &&
11949 TInfo
== E
->getTypeOperandSourceInfo())
11952 return getDerived().RebuildCXXUuidofExpr(E
->getType(), E
->getBeginLoc(),
11953 TInfo
, E
->getEndLoc());
11956 EnterExpressionEvaluationContext
Unevaluated(
11957 SemaRef
, Sema::ExpressionEvaluationContext::Unevaluated
);
11959 ExprResult SubExpr
= getDerived().TransformExpr(E
->getExprOperand());
11960 if (SubExpr
.isInvalid())
11961 return ExprError();
11963 if (!getDerived().AlwaysRebuild() &&
11964 SubExpr
.get() == E
->getExprOperand())
11967 return getDerived().RebuildCXXUuidofExpr(E
->getType(), E
->getBeginLoc(),
11968 SubExpr
.get(), E
->getEndLoc());
11971 template<typename Derived
>
11973 TreeTransform
<Derived
>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr
*E
) {
11977 template<typename Derived
>
11979 TreeTransform
<Derived
>::TransformCXXNullPtrLiteralExpr(
11980 CXXNullPtrLiteralExpr
*E
) {
11984 template<typename Derived
>
11986 TreeTransform
<Derived
>::TransformCXXThisExpr(CXXThisExpr
*E
) {
11987 QualType T
= getSema().getCurrentThisType();
11989 if (!getDerived().AlwaysRebuild() && T
== E
->getType()) {
11990 // Mark it referenced in the new context regardless.
11991 // FIXME: this is a bit instantiation-specific.
11992 getSema().MarkThisReferenced(E
);
11996 return getDerived().RebuildCXXThisExpr(E
->getBeginLoc(), T
, E
->isImplicit());
11999 template<typename Derived
>
12001 TreeTransform
<Derived
>::TransformCXXThrowExpr(CXXThrowExpr
*E
) {
12002 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
12003 if (SubExpr
.isInvalid())
12004 return ExprError();
12006 if (!getDerived().AlwaysRebuild() &&
12007 SubExpr
.get() == E
->getSubExpr())
12010 return getDerived().RebuildCXXThrowExpr(E
->getThrowLoc(), SubExpr
.get(),
12011 E
->isThrownVariableInScope());
12014 template<typename Derived
>
12016 TreeTransform
<Derived
>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr
*E
) {
12017 ParmVarDecl
*Param
= cast_or_null
<ParmVarDecl
>(
12018 getDerived().TransformDecl(E
->getBeginLoc(), E
->getParam()));
12020 return ExprError();
12022 if (!getDerived().AlwaysRebuild() && Param
== E
->getParam() &&
12023 E
->getUsedContext() == SemaRef
.CurContext
)
12026 return getDerived().RebuildCXXDefaultArgExpr(E
->getUsedLocation(), Param
);
12029 template<typename Derived
>
12031 TreeTransform
<Derived
>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr
*E
) {
12032 FieldDecl
*Field
= cast_or_null
<FieldDecl
>(
12033 getDerived().TransformDecl(E
->getBeginLoc(), E
->getField()));
12035 return ExprError();
12037 if (!getDerived().AlwaysRebuild() && Field
== E
->getField() &&
12038 E
->getUsedContext() == SemaRef
.CurContext
)
12041 return getDerived().RebuildCXXDefaultInitExpr(E
->getExprLoc(), Field
);
12044 template<typename Derived
>
12046 TreeTransform
<Derived
>::TransformCXXScalarValueInitExpr(
12047 CXXScalarValueInitExpr
*E
) {
12048 TypeSourceInfo
*T
= getDerived().TransformType(E
->getTypeSourceInfo());
12050 return ExprError();
12052 if (!getDerived().AlwaysRebuild() &&
12053 T
== E
->getTypeSourceInfo())
12056 return getDerived().RebuildCXXScalarValueInitExpr(T
,
12057 /*FIXME:*/T
->getTypeLoc().getEndLoc(),
12058 E
->getRParenLoc());
12061 template<typename Derived
>
12063 TreeTransform
<Derived
>::TransformCXXNewExpr(CXXNewExpr
*E
) {
12064 // Transform the type that we're allocating
12065 TypeSourceInfo
*AllocTypeInfo
=
12066 getDerived().TransformTypeWithDeducedTST(E
->getAllocatedTypeSourceInfo());
12067 if (!AllocTypeInfo
)
12068 return ExprError();
12070 // Transform the size of the array we're allocating (if any).
12071 Optional
<Expr
*> ArraySize
;
12072 if (E
->isArray()) {
12073 ExprResult NewArraySize
;
12074 if (Optional
<Expr
*> OldArraySize
= E
->getArraySize()) {
12075 NewArraySize
= getDerived().TransformExpr(*OldArraySize
);
12076 if (NewArraySize
.isInvalid())
12077 return ExprError();
12079 ArraySize
= NewArraySize
.get();
12082 // Transform the placement arguments (if any).
12083 bool ArgumentChanged
= false;
12084 SmallVector
<Expr
*, 8> PlacementArgs
;
12085 if (getDerived().TransformExprs(E
->getPlacementArgs(),
12086 E
->getNumPlacementArgs(), true,
12087 PlacementArgs
, &ArgumentChanged
))
12088 return ExprError();
12090 // Transform the initializer (if any).
12091 Expr
*OldInit
= E
->getInitializer();
12092 ExprResult NewInit
;
12094 NewInit
= getDerived().TransformInitializer(OldInit
, true);
12095 if (NewInit
.isInvalid())
12096 return ExprError();
12098 // Transform new operator and delete operator.
12099 FunctionDecl
*OperatorNew
= nullptr;
12100 if (E
->getOperatorNew()) {
12101 OperatorNew
= cast_or_null
<FunctionDecl
>(
12102 getDerived().TransformDecl(E
->getBeginLoc(), E
->getOperatorNew()));
12104 return ExprError();
12107 FunctionDecl
*OperatorDelete
= nullptr;
12108 if (E
->getOperatorDelete()) {
12109 OperatorDelete
= cast_or_null
<FunctionDecl
>(
12110 getDerived().TransformDecl(E
->getBeginLoc(), E
->getOperatorDelete()));
12111 if (!OperatorDelete
)
12112 return ExprError();
12115 if (!getDerived().AlwaysRebuild() &&
12116 AllocTypeInfo
== E
->getAllocatedTypeSourceInfo() &&
12117 ArraySize
== E
->getArraySize() &&
12118 NewInit
.get() == OldInit
&&
12119 OperatorNew
== E
->getOperatorNew() &&
12120 OperatorDelete
== E
->getOperatorDelete() &&
12121 !ArgumentChanged
) {
12122 // Mark any declarations we need as referenced.
12123 // FIXME: instantiation-specific.
12125 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(), OperatorNew
);
12126 if (OperatorDelete
)
12127 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(), OperatorDelete
);
12129 if (E
->isArray() && !E
->getAllocatedType()->isDependentType()) {
12130 QualType ElementType
12131 = SemaRef
.Context
.getBaseElementType(E
->getAllocatedType());
12132 if (const RecordType
*RecordT
= ElementType
->getAs
<RecordType
>()) {
12133 CXXRecordDecl
*Record
= cast
<CXXRecordDecl
>(RecordT
->getDecl());
12134 if (CXXDestructorDecl
*Destructor
= SemaRef
.LookupDestructor(Record
)) {
12135 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(), Destructor
);
12143 QualType AllocType
= AllocTypeInfo
->getType();
12145 // If no array size was specified, but the new expression was
12146 // instantiated with an array type (e.g., "new T" where T is
12147 // instantiated with "int[4]"), extract the outer bound from the
12148 // array type as our array size. We do this with constant and
12149 // dependently-sized array types.
12150 const ArrayType
*ArrayT
= SemaRef
.Context
.getAsArrayType(AllocType
);
12153 } else if (const ConstantArrayType
*ConsArrayT
12154 = dyn_cast
<ConstantArrayType
>(ArrayT
)) {
12155 ArraySize
= IntegerLiteral::Create(SemaRef
.Context
, ConsArrayT
->getSize(),
12156 SemaRef
.Context
.getSizeType(),
12157 /*FIXME:*/ E
->getBeginLoc());
12158 AllocType
= ConsArrayT
->getElementType();
12159 } else if (const DependentSizedArrayType
*DepArrayT
12160 = dyn_cast
<DependentSizedArrayType
>(ArrayT
)) {
12161 if (DepArrayT
->getSizeExpr()) {
12162 ArraySize
= DepArrayT
->getSizeExpr();
12163 AllocType
= DepArrayT
->getElementType();
12168 return getDerived().RebuildCXXNewExpr(
12169 E
->getBeginLoc(), E
->isGlobalNew(),
12170 /*FIXME:*/ E
->getBeginLoc(), PlacementArgs
,
12171 /*FIXME:*/ E
->getBeginLoc(), E
->getTypeIdParens(), AllocType
,
12172 AllocTypeInfo
, ArraySize
, E
->getDirectInitRange(), NewInit
.get());
12175 template<typename Derived
>
12177 TreeTransform
<Derived
>::TransformCXXDeleteExpr(CXXDeleteExpr
*E
) {
12178 ExprResult Operand
= getDerived().TransformExpr(E
->getArgument());
12179 if (Operand
.isInvalid())
12180 return ExprError();
12182 // Transform the delete operator, if known.
12183 FunctionDecl
*OperatorDelete
= nullptr;
12184 if (E
->getOperatorDelete()) {
12185 OperatorDelete
= cast_or_null
<FunctionDecl
>(
12186 getDerived().TransformDecl(E
->getBeginLoc(), E
->getOperatorDelete()));
12187 if (!OperatorDelete
)
12188 return ExprError();
12191 if (!getDerived().AlwaysRebuild() &&
12192 Operand
.get() == E
->getArgument() &&
12193 OperatorDelete
== E
->getOperatorDelete()) {
12194 // Mark any declarations we need as referenced.
12195 // FIXME: instantiation-specific.
12196 if (OperatorDelete
)
12197 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(), OperatorDelete
);
12199 if (!E
->getArgument()->isTypeDependent()) {
12200 QualType Destroyed
= SemaRef
.Context
.getBaseElementType(
12201 E
->getDestroyedType());
12202 if (const RecordType
*DestroyedRec
= Destroyed
->getAs
<RecordType
>()) {
12203 CXXRecordDecl
*Record
= cast
<CXXRecordDecl
>(DestroyedRec
->getDecl());
12204 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(),
12205 SemaRef
.LookupDestructor(Record
));
12212 return getDerived().RebuildCXXDeleteExpr(
12213 E
->getBeginLoc(), E
->isGlobalDelete(), E
->isArrayForm(), Operand
.get());
12216 template<typename Derived
>
12218 TreeTransform
<Derived
>::TransformCXXPseudoDestructorExpr(
12219 CXXPseudoDestructorExpr
*E
) {
12220 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
12221 if (Base
.isInvalid())
12222 return ExprError();
12224 ParsedType ObjectTypePtr
;
12225 bool MayBePseudoDestructor
= false;
12226 Base
= SemaRef
.ActOnStartCXXMemberReference(nullptr, Base
.get(),
12227 E
->getOperatorLoc(),
12228 E
->isArrow()? tok::arrow
: tok::period
,
12230 MayBePseudoDestructor
);
12231 if (Base
.isInvalid())
12232 return ExprError();
12234 QualType ObjectType
= ObjectTypePtr
.get();
12235 NestedNameSpecifierLoc QualifierLoc
= E
->getQualifierLoc();
12236 if (QualifierLoc
) {
12238 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc
, ObjectType
);
12240 return ExprError();
12243 SS
.Adopt(QualifierLoc
);
12245 PseudoDestructorTypeStorage Destroyed
;
12246 if (E
->getDestroyedTypeInfo()) {
12247 TypeSourceInfo
*DestroyedTypeInfo
12248 = getDerived().TransformTypeInObjectScope(E
->getDestroyedTypeInfo(),
12249 ObjectType
, nullptr, SS
);
12250 if (!DestroyedTypeInfo
)
12251 return ExprError();
12252 Destroyed
= DestroyedTypeInfo
;
12253 } else if (!ObjectType
.isNull() && ObjectType
->isDependentType()) {
12254 // We aren't likely to be able to resolve the identifier down to a type
12255 // now anyway, so just retain the identifier.
12256 Destroyed
= PseudoDestructorTypeStorage(E
->getDestroyedTypeIdentifier(),
12257 E
->getDestroyedTypeLoc());
12259 // Look for a destructor known with the given name.
12260 ParsedType T
= SemaRef
.getDestructorName(E
->getTildeLoc(),
12261 *E
->getDestroyedTypeIdentifier(),
12262 E
->getDestroyedTypeLoc(),
12267 return ExprError();
12270 = SemaRef
.Context
.getTrivialTypeSourceInfo(SemaRef
.GetTypeFromParser(T
),
12271 E
->getDestroyedTypeLoc());
12274 TypeSourceInfo
*ScopeTypeInfo
= nullptr;
12275 if (E
->getScopeTypeInfo()) {
12276 CXXScopeSpec EmptySS
;
12277 ScopeTypeInfo
= getDerived().TransformTypeInObjectScope(
12278 E
->getScopeTypeInfo(), ObjectType
, nullptr, EmptySS
);
12279 if (!ScopeTypeInfo
)
12280 return ExprError();
12283 return getDerived().RebuildCXXPseudoDestructorExpr(Base
.get(),
12284 E
->getOperatorLoc(),
12288 E
->getColonColonLoc(),
12293 template <typename Derived
>
12294 bool TreeTransform
<Derived
>::TransformOverloadExprDecls(OverloadExpr
*Old
,
12297 // Transform all the decls.
12298 bool AllEmptyPacks
= true;
12299 for (auto *OldD
: Old
->decls()) {
12300 Decl
*InstD
= getDerived().TransformDecl(Old
->getNameLoc(), OldD
);
12302 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
12303 // This can happen because of dependent hiding.
12304 if (isa
<UsingShadowDecl
>(OldD
))
12312 // Expand using pack declarations.
12313 NamedDecl
*SingleDecl
= cast
<NamedDecl
>(InstD
);
12314 ArrayRef
<NamedDecl
*> Decls
= SingleDecl
;
12315 if (auto *UPD
= dyn_cast
<UsingPackDecl
>(InstD
))
12316 Decls
= UPD
->expansions();
12318 // Expand using declarations.
12319 for (auto *D
: Decls
) {
12320 if (auto *UD
= dyn_cast
<UsingDecl
>(D
)) {
12321 for (auto *SD
: UD
->shadows())
12328 AllEmptyPacks
&= Decls
.empty();
12331 // C++ [temp.res]/8.4.2:
12332 // The program is ill-formed, no diagnostic required, if [...] lookup for
12333 // a name in the template definition found a using-declaration, but the
12334 // lookup in the corresponding scope in the instantiation odoes not find
12335 // any declarations because the using-declaration was a pack expansion and
12336 // the corresponding pack is empty
12337 if (AllEmptyPacks
&& !RequiresADL
) {
12338 getSema().Diag(Old
->getNameLoc(), diag::err_using_pack_expansion_empty
)
12339 << isa
<UnresolvedMemberExpr
>(Old
) << Old
->getName();
12343 // Resolve a kind, but don't do any further analysis. If it's
12344 // ambiguous, the callee needs to deal with it.
12349 template<typename Derived
>
12351 TreeTransform
<Derived
>::TransformUnresolvedLookupExpr(
12352 UnresolvedLookupExpr
*Old
) {
12353 LookupResult
R(SemaRef
, Old
->getName(), Old
->getNameLoc(),
12354 Sema::LookupOrdinaryName
);
12356 // Transform the declaration set.
12357 if (TransformOverloadExprDecls(Old
, Old
->requiresADL(), R
))
12358 return ExprError();
12360 // Rebuild the nested-name qualifier, if present.
12362 if (Old
->getQualifierLoc()) {
12363 NestedNameSpecifierLoc QualifierLoc
12364 = getDerived().TransformNestedNameSpecifierLoc(Old
->getQualifierLoc());
12366 return ExprError();
12368 SS
.Adopt(QualifierLoc
);
12371 if (Old
->getNamingClass()) {
12372 CXXRecordDecl
*NamingClass
12373 = cast_or_null
<CXXRecordDecl
>(getDerived().TransformDecl(
12375 Old
->getNamingClass()));
12376 if (!NamingClass
) {
12378 return ExprError();
12381 R
.setNamingClass(NamingClass
);
12384 SourceLocation TemplateKWLoc
= Old
->getTemplateKeywordLoc();
12386 // If we have neither explicit template arguments, nor the template keyword,
12387 // it's a normal declaration name or member reference.
12388 if (!Old
->hasExplicitTemplateArgs() && !TemplateKWLoc
.isValid()) {
12389 NamedDecl
*D
= R
.getAsSingle
<NamedDecl
>();
12390 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
12391 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
12392 // give a good diagnostic.
12393 if (D
&& D
->isCXXInstanceMember()) {
12394 return SemaRef
.BuildPossibleImplicitMemberExpr(SS
, TemplateKWLoc
, R
,
12395 /*TemplateArgs=*/nullptr,
12396 /*Scope=*/nullptr);
12399 return getDerived().RebuildDeclarationNameExpr(SS
, R
, Old
->requiresADL());
12402 // If we have template arguments, rebuild them, then rebuild the
12403 // templateid expression.
12404 TemplateArgumentListInfo
TransArgs(Old
->getLAngleLoc(), Old
->getRAngleLoc());
12405 if (Old
->hasExplicitTemplateArgs() &&
12406 getDerived().TransformTemplateArguments(Old
->getTemplateArgs(),
12407 Old
->getNumTemplateArgs(),
12410 return ExprError();
12413 return getDerived().RebuildTemplateIdExpr(SS
, TemplateKWLoc
, R
,
12414 Old
->requiresADL(), &TransArgs
);
12417 template<typename Derived
>
12419 TreeTransform
<Derived
>::TransformTypeTraitExpr(TypeTraitExpr
*E
) {
12420 bool ArgChanged
= false;
12421 SmallVector
<TypeSourceInfo
*, 4> Args
;
12422 for (unsigned I
= 0, N
= E
->getNumArgs(); I
!= N
; ++I
) {
12423 TypeSourceInfo
*From
= E
->getArg(I
);
12424 TypeLoc FromTL
= From
->getTypeLoc();
12425 if (!FromTL
.getAs
<PackExpansionTypeLoc
>()) {
12426 TypeLocBuilder TLB
;
12427 TLB
.reserve(FromTL
.getFullDataSize());
12428 QualType To
= getDerived().TransformType(TLB
, FromTL
);
12430 return ExprError();
12432 if (To
== From
->getType())
12433 Args
.push_back(From
);
12435 Args
.push_back(TLB
.getTypeSourceInfo(SemaRef
.Context
, To
));
12443 // We have a pack expansion. Instantiate it.
12444 PackExpansionTypeLoc ExpansionTL
= FromTL
.castAs
<PackExpansionTypeLoc
>();
12445 TypeLoc PatternTL
= ExpansionTL
.getPatternLoc();
12446 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
12447 SemaRef
.collectUnexpandedParameterPacks(PatternTL
, Unexpanded
);
12449 // Determine whether the set of unexpanded parameter packs can and should
12451 bool Expand
= true;
12452 bool RetainExpansion
= false;
12453 Optional
<unsigned> OrigNumExpansions
=
12454 ExpansionTL
.getTypePtr()->getNumExpansions();
12455 Optional
<unsigned> NumExpansions
= OrigNumExpansions
;
12456 if (getDerived().TryExpandParameterPacks(ExpansionTL
.getEllipsisLoc(),
12457 PatternTL
.getSourceRange(),
12459 Expand
, RetainExpansion
,
12461 return ExprError();
12464 // The transform has determined that we should perform a simple
12465 // transformation on the pack expansion, producing another pack
12467 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
12469 TypeLocBuilder TLB
;
12470 TLB
.reserve(From
->getTypeLoc().getFullDataSize());
12472 QualType To
= getDerived().TransformType(TLB
, PatternTL
);
12474 return ExprError();
12476 To
= getDerived().RebuildPackExpansionType(To
,
12477 PatternTL
.getSourceRange(),
12478 ExpansionTL
.getEllipsisLoc(),
12481 return ExprError();
12483 PackExpansionTypeLoc ToExpansionTL
12484 = TLB
.push
<PackExpansionTypeLoc
>(To
);
12485 ToExpansionTL
.setEllipsisLoc(ExpansionTL
.getEllipsisLoc());
12486 Args
.push_back(TLB
.getTypeSourceInfo(SemaRef
.Context
, To
));
12490 // Expand the pack expansion by substituting for each argument in the
12492 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
12493 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(SemaRef
, I
);
12494 TypeLocBuilder TLB
;
12495 TLB
.reserve(PatternTL
.getFullDataSize());
12496 QualType To
= getDerived().TransformType(TLB
, PatternTL
);
12498 return ExprError();
12500 if (To
->containsUnexpandedParameterPack()) {
12501 To
= getDerived().RebuildPackExpansionType(To
,
12502 PatternTL
.getSourceRange(),
12503 ExpansionTL
.getEllipsisLoc(),
12506 return ExprError();
12508 PackExpansionTypeLoc ToExpansionTL
12509 = TLB
.push
<PackExpansionTypeLoc
>(To
);
12510 ToExpansionTL
.setEllipsisLoc(ExpansionTL
.getEllipsisLoc());
12513 Args
.push_back(TLB
.getTypeSourceInfo(SemaRef
.Context
, To
));
12516 if (!RetainExpansion
)
12519 // If we're supposed to retain a pack expansion, do so by temporarily
12520 // forgetting the partially-substituted parameter pack.
12521 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
12523 TypeLocBuilder TLB
;
12524 TLB
.reserve(From
->getTypeLoc().getFullDataSize());
12526 QualType To
= getDerived().TransformType(TLB
, PatternTL
);
12528 return ExprError();
12530 To
= getDerived().RebuildPackExpansionType(To
,
12531 PatternTL
.getSourceRange(),
12532 ExpansionTL
.getEllipsisLoc(),
12535 return ExprError();
12537 PackExpansionTypeLoc ToExpansionTL
12538 = TLB
.push
<PackExpansionTypeLoc
>(To
);
12539 ToExpansionTL
.setEllipsisLoc(ExpansionTL
.getEllipsisLoc());
12540 Args
.push_back(TLB
.getTypeSourceInfo(SemaRef
.Context
, To
));
12543 if (!getDerived().AlwaysRebuild() && !ArgChanged
)
12546 return getDerived().RebuildTypeTrait(E
->getTrait(), E
->getBeginLoc(), Args
,
12550 template<typename Derived
>
12552 TreeTransform
<Derived
>::TransformConceptSpecializationExpr(
12553 ConceptSpecializationExpr
*E
) {
12554 const ASTTemplateArgumentListInfo
*Old
= E
->getTemplateArgsAsWritten();
12555 TemplateArgumentListInfo
TransArgs(Old
->LAngleLoc
, Old
->RAngleLoc
);
12556 if (getDerived().TransformTemplateArguments(Old
->getTemplateArgs(),
12557 Old
->NumTemplateArgs
, TransArgs
))
12558 return ExprError();
12560 return getDerived().RebuildConceptSpecializationExpr(
12561 E
->getNestedNameSpecifierLoc(), E
->getTemplateKWLoc(),
12562 E
->getConceptNameInfo(), E
->getFoundDecl(), E
->getNamedConcept(),
12566 template<typename Derived
>
12568 TreeTransform
<Derived
>::TransformRequiresExpr(RequiresExpr
*E
) {
12569 SmallVector
<ParmVarDecl
*, 4> TransParams
;
12570 SmallVector
<QualType
, 4> TransParamTypes
;
12571 Sema::ExtParameterInfoBuilder ExtParamInfos
;
12573 // C++2a [expr.prim.req]p2
12574 // Expressions appearing within a requirement-body are unevaluated operands.
12575 EnterExpressionEvaluationContext
Ctx(
12576 SemaRef
, Sema::ExpressionEvaluationContext::Unevaluated
);
12578 RequiresExprBodyDecl
*Body
= RequiresExprBodyDecl::Create(
12579 getSema().Context
, getSema().CurContext
,
12580 E
->getBody()->getBeginLoc());
12582 Sema::ContextRAII
SavedContext(getSema(), Body
, /*NewThisContext*/false);
12584 if (getDerived().TransformFunctionTypeParams(E
->getRequiresKWLoc(),
12585 E
->getLocalParameters(),
12586 /*ParamTypes=*/nullptr,
12587 /*ParamInfos=*/nullptr,
12588 TransParamTypes
, &TransParams
,
12590 return ExprError();
12592 for (ParmVarDecl
*Param
: TransParams
)
12593 Param
->setDeclContext(Body
);
12595 SmallVector
<concepts::Requirement
*, 4> TransReqs
;
12596 if (getDerived().TransformRequiresExprRequirements(E
->getRequirements(),
12598 return ExprError();
12600 for (concepts::Requirement
*Req
: TransReqs
) {
12601 if (auto *ER
= dyn_cast
<concepts::ExprRequirement
>(Req
)) {
12602 if (ER
->getReturnTypeRequirement().isTypeConstraint()) {
12603 ER
->getReturnTypeRequirement()
12604 .getTypeConstraintTemplateParameterList()->getParam(0)
12605 ->setDeclContext(Body
);
12610 return getDerived().RebuildRequiresExpr(E
->getRequiresKWLoc(), Body
,
12611 TransParams
, TransReqs
,
12612 E
->getRBraceLoc());
12615 template<typename Derived
>
12616 bool TreeTransform
<Derived
>::TransformRequiresExprRequirements(
12617 ArrayRef
<concepts::Requirement
*> Reqs
,
12618 SmallVectorImpl
<concepts::Requirement
*> &Transformed
) {
12619 for (concepts::Requirement
*Req
: Reqs
) {
12620 concepts::Requirement
*TransReq
= nullptr;
12621 if (auto *TypeReq
= dyn_cast
<concepts::TypeRequirement
>(Req
))
12622 TransReq
= getDerived().TransformTypeRequirement(TypeReq
);
12623 else if (auto *ExprReq
= dyn_cast
<concepts::ExprRequirement
>(Req
))
12624 TransReq
= getDerived().TransformExprRequirement(ExprReq
);
12626 TransReq
= getDerived().TransformNestedRequirement(
12627 cast
<concepts::NestedRequirement
>(Req
));
12630 Transformed
.push_back(TransReq
);
12635 template<typename Derived
>
12636 concepts::TypeRequirement
*
12637 TreeTransform
<Derived
>::TransformTypeRequirement(
12638 concepts::TypeRequirement
*Req
) {
12639 if (Req
->isSubstitutionFailure()) {
12640 if (getDerived().AlwaysRebuild())
12641 return getDerived().RebuildTypeRequirement(
12642 Req
->getSubstitutionDiagnostic());
12645 TypeSourceInfo
*TransType
= getDerived().TransformType(Req
->getType());
12648 return getDerived().RebuildTypeRequirement(TransType
);
12651 template<typename Derived
>
12652 concepts::ExprRequirement
*
12653 TreeTransform
<Derived
>::TransformExprRequirement(concepts::ExprRequirement
*Req
) {
12654 llvm::PointerUnion
<Expr
*, concepts::Requirement::SubstitutionDiagnostic
*> TransExpr
;
12655 if (Req
->isExprSubstitutionFailure())
12656 TransExpr
= Req
->getExprSubstitutionDiagnostic();
12658 ExprResult TransExprRes
= getDerived().TransformExpr(Req
->getExpr());
12659 if (TransExprRes
.isUsable() && TransExprRes
.get()->hasPlaceholderType())
12660 TransExprRes
= SemaRef
.CheckPlaceholderExpr(TransExprRes
.get());
12661 if (TransExprRes
.isInvalid())
12663 TransExpr
= TransExprRes
.get();
12666 llvm::Optional
<concepts::ExprRequirement::ReturnTypeRequirement
> TransRetReq
;
12667 const auto &RetReq
= Req
->getReturnTypeRequirement();
12668 if (RetReq
.isEmpty())
12669 TransRetReq
.emplace();
12670 else if (RetReq
.isSubstitutionFailure())
12671 TransRetReq
.emplace(RetReq
.getSubstitutionDiagnostic());
12672 else if (RetReq
.isTypeConstraint()) {
12673 TemplateParameterList
*OrigTPL
=
12674 RetReq
.getTypeConstraintTemplateParameterList();
12675 TemplateParameterList
*TPL
=
12676 getDerived().TransformTemplateParameterList(OrigTPL
);
12679 TransRetReq
.emplace(TPL
);
12681 assert(TransRetReq
&& "All code paths leading here must set TransRetReq");
12682 if (Expr
*E
= TransExpr
.dyn_cast
<Expr
*>())
12683 return getDerived().RebuildExprRequirement(E
, Req
->isSimple(),
12684 Req
->getNoexceptLoc(),
12685 std::move(*TransRetReq
));
12686 return getDerived().RebuildExprRequirement(
12687 TransExpr
.get
<concepts::Requirement::SubstitutionDiagnostic
*>(),
12688 Req
->isSimple(), Req
->getNoexceptLoc(), std::move(*TransRetReq
));
12691 template<typename Derived
>
12692 concepts::NestedRequirement
*
12693 TreeTransform
<Derived
>::TransformNestedRequirement(
12694 concepts::NestedRequirement
*Req
) {
12695 if (Req
->isSubstitutionFailure()) {
12696 if (getDerived().AlwaysRebuild())
12697 return getDerived().RebuildNestedRequirement(
12698 Req
->getSubstitutionDiagnostic());
12701 ExprResult TransConstraint
=
12702 getDerived().TransformExpr(Req
->getConstraintExpr());
12703 if (TransConstraint
.isInvalid())
12705 return getDerived().RebuildNestedRequirement(TransConstraint
.get());
12708 template<typename Derived
>
12710 TreeTransform
<Derived
>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr
*E
) {
12711 TypeSourceInfo
*T
= getDerived().TransformType(E
->getQueriedTypeSourceInfo());
12713 return ExprError();
12715 if (!getDerived().AlwaysRebuild() &&
12716 T
== E
->getQueriedTypeSourceInfo())
12719 ExprResult SubExpr
;
12721 EnterExpressionEvaluationContext
Unevaluated(
12722 SemaRef
, Sema::ExpressionEvaluationContext::Unevaluated
);
12723 SubExpr
= getDerived().TransformExpr(E
->getDimensionExpression());
12724 if (SubExpr
.isInvalid())
12725 return ExprError();
12727 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getDimensionExpression())
12731 return getDerived().RebuildArrayTypeTrait(E
->getTrait(), E
->getBeginLoc(), T
,
12732 SubExpr
.get(), E
->getEndLoc());
12735 template<typename Derived
>
12737 TreeTransform
<Derived
>::TransformExpressionTraitExpr(ExpressionTraitExpr
*E
) {
12738 ExprResult SubExpr
;
12740 EnterExpressionEvaluationContext
Unevaluated(
12741 SemaRef
, Sema::ExpressionEvaluationContext::Unevaluated
);
12742 SubExpr
= getDerived().TransformExpr(E
->getQueriedExpression());
12743 if (SubExpr
.isInvalid())
12744 return ExprError();
12746 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getQueriedExpression())
12750 return getDerived().RebuildExpressionTrait(E
->getTrait(), E
->getBeginLoc(),
12751 SubExpr
.get(), E
->getEndLoc());
12754 template <typename Derived
>
12755 ExprResult TreeTransform
<Derived
>::TransformParenDependentScopeDeclRefExpr(
12756 ParenExpr
*PE
, DependentScopeDeclRefExpr
*DRE
, bool AddrTaken
,
12757 TypeSourceInfo
**RecoveryTSI
) {
12758 ExprResult NewDRE
= getDerived().TransformDependentScopeDeclRefExpr(
12759 DRE
, AddrTaken
, RecoveryTSI
);
12761 // Propagate both errors and recovered types, which return ExprEmpty.
12762 if (!NewDRE
.isUsable())
12765 // We got an expr, wrap it up in parens.
12766 if (!getDerived().AlwaysRebuild() && NewDRE
.get() == DRE
)
12768 return getDerived().RebuildParenExpr(NewDRE
.get(), PE
->getLParen(),
12772 template <typename Derived
>
12773 ExprResult TreeTransform
<Derived
>::TransformDependentScopeDeclRefExpr(
12774 DependentScopeDeclRefExpr
*E
) {
12775 return TransformDependentScopeDeclRefExpr(E
, /*IsAddressOfOperand=*/false,
12779 template <typename Derived
>
12780 ExprResult TreeTransform
<Derived
>::TransformDependentScopeDeclRefExpr(
12781 DependentScopeDeclRefExpr
*E
, bool IsAddressOfOperand
,
12782 TypeSourceInfo
**RecoveryTSI
) {
12783 assert(E
->getQualifierLoc());
12784 NestedNameSpecifierLoc QualifierLoc
=
12785 getDerived().TransformNestedNameSpecifierLoc(E
->getQualifierLoc());
12787 return ExprError();
12788 SourceLocation TemplateKWLoc
= E
->getTemplateKeywordLoc();
12790 // TODO: If this is a conversion-function-id, verify that the
12791 // destination type name (if present) resolves the same way after
12792 // instantiation as it did in the local scope.
12794 DeclarationNameInfo NameInfo
=
12795 getDerived().TransformDeclarationNameInfo(E
->getNameInfo());
12796 if (!NameInfo
.getName())
12797 return ExprError();
12799 if (!E
->hasExplicitTemplateArgs()) {
12800 if (!getDerived().AlwaysRebuild() && QualifierLoc
== E
->getQualifierLoc() &&
12801 // Note: it is sufficient to compare the Name component of NameInfo:
12802 // if name has not changed, DNLoc has not changed either.
12803 NameInfo
.getName() == E
->getDeclName())
12806 return getDerived().RebuildDependentScopeDeclRefExpr(
12807 QualifierLoc
, TemplateKWLoc
, NameInfo
, /*TemplateArgs=*/nullptr,
12808 IsAddressOfOperand
, RecoveryTSI
);
12811 TemplateArgumentListInfo
TransArgs(E
->getLAngleLoc(), E
->getRAngleLoc());
12812 if (getDerived().TransformTemplateArguments(
12813 E
->getTemplateArgs(), E
->getNumTemplateArgs(), TransArgs
))
12814 return ExprError();
12816 return getDerived().RebuildDependentScopeDeclRefExpr(
12817 QualifierLoc
, TemplateKWLoc
, NameInfo
, &TransArgs
, IsAddressOfOperand
,
12821 template<typename Derived
>
12823 TreeTransform
<Derived
>::TransformCXXConstructExpr(CXXConstructExpr
*E
) {
12824 // CXXConstructExprs other than for list-initialization and
12825 // CXXTemporaryObjectExpr are always implicit, so when we have
12826 // a 1-argument construction we just transform that argument.
12827 if (getDerived().AllowSkippingCXXConstructExpr() &&
12828 ((E
->getNumArgs() == 1 ||
12829 (E
->getNumArgs() > 1 && getDerived().DropCallArgument(E
->getArg(1)))) &&
12830 (!getDerived().DropCallArgument(E
->getArg(0))) &&
12831 !E
->isListInitialization()))
12832 return getDerived().TransformInitializer(E
->getArg(0),
12833 /*DirectInit*/ false);
12835 TemporaryBase
Rebase(*this, /*FIXME*/ E
->getBeginLoc(), DeclarationName());
12837 QualType T
= getDerived().TransformType(E
->getType());
12839 return ExprError();
12841 CXXConstructorDecl
*Constructor
= cast_or_null
<CXXConstructorDecl
>(
12842 getDerived().TransformDecl(E
->getBeginLoc(), E
->getConstructor()));
12844 return ExprError();
12846 bool ArgumentChanged
= false;
12847 SmallVector
<Expr
*, 8> Args
;
12849 EnterExpressionEvaluationContext
Context(
12850 getSema(), EnterExpressionEvaluationContext::InitList
,
12851 E
->isListInitialization());
12852 if (getDerived().TransformExprs(E
->getArgs(), E
->getNumArgs(), true, Args
,
12854 return ExprError();
12857 if (!getDerived().AlwaysRebuild() &&
12858 T
== E
->getType() &&
12859 Constructor
== E
->getConstructor() &&
12860 !ArgumentChanged
) {
12861 // Mark the constructor as referenced.
12862 // FIXME: Instantiation-specific
12863 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(), Constructor
);
12867 return getDerived().RebuildCXXConstructExpr(
12868 T
, /*FIXME:*/ E
->getBeginLoc(), Constructor
, E
->isElidable(), Args
,
12869 E
->hadMultipleCandidates(), E
->isListInitialization(),
12870 E
->isStdInitListInitialization(), E
->requiresZeroInitialization(),
12871 E
->getConstructionKind(), E
->getParenOrBraceRange());
12874 template<typename Derived
>
12875 ExprResult TreeTransform
<Derived
>::TransformCXXInheritedCtorInitExpr(
12876 CXXInheritedCtorInitExpr
*E
) {
12877 QualType T
= getDerived().TransformType(E
->getType());
12879 return ExprError();
12881 CXXConstructorDecl
*Constructor
= cast_or_null
<CXXConstructorDecl
>(
12882 getDerived().TransformDecl(E
->getBeginLoc(), E
->getConstructor()));
12884 return ExprError();
12886 if (!getDerived().AlwaysRebuild() &&
12887 T
== E
->getType() &&
12888 Constructor
== E
->getConstructor()) {
12889 // Mark the constructor as referenced.
12890 // FIXME: Instantiation-specific
12891 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(), Constructor
);
12895 return getDerived().RebuildCXXInheritedCtorInitExpr(
12896 T
, E
->getLocation(), Constructor
,
12897 E
->constructsVBase(), E
->inheritedFromVBase());
12900 /// Transform a C++ temporary-binding expression.
12902 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
12903 /// transform the subexpression and return that.
12904 template<typename Derived
>
12906 TreeTransform
<Derived
>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr
*E
) {
12907 if (auto *Dtor
= E
->getTemporary()->getDestructor())
12908 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(),
12909 const_cast<CXXDestructorDecl
*>(Dtor
));
12910 return getDerived().TransformExpr(E
->getSubExpr());
12913 /// Transform a C++ expression that contains cleanups that should
12914 /// be run after the expression is evaluated.
12916 /// Since ExprWithCleanups nodes are implicitly generated, we
12917 /// just transform the subexpression and return that.
12918 template<typename Derived
>
12920 TreeTransform
<Derived
>::TransformExprWithCleanups(ExprWithCleanups
*E
) {
12921 return getDerived().TransformExpr(E
->getSubExpr());
12924 template<typename Derived
>
12926 TreeTransform
<Derived
>::TransformCXXTemporaryObjectExpr(
12927 CXXTemporaryObjectExpr
*E
) {
12928 TypeSourceInfo
*T
=
12929 getDerived().TransformTypeWithDeducedTST(E
->getTypeSourceInfo());
12931 return ExprError();
12933 CXXConstructorDecl
*Constructor
= cast_or_null
<CXXConstructorDecl
>(
12934 getDerived().TransformDecl(E
->getBeginLoc(), E
->getConstructor()));
12936 return ExprError();
12938 bool ArgumentChanged
= false;
12939 SmallVector
<Expr
*, 8> Args
;
12940 Args
.reserve(E
->getNumArgs());
12942 EnterExpressionEvaluationContext
Context(
12943 getSema(), EnterExpressionEvaluationContext::InitList
,
12944 E
->isListInitialization());
12945 if (TransformExprs(E
->getArgs(), E
->getNumArgs(), true, Args
,
12947 return ExprError();
12950 if (!getDerived().AlwaysRebuild() &&
12951 T
== E
->getTypeSourceInfo() &&
12952 Constructor
== E
->getConstructor() &&
12953 !ArgumentChanged
) {
12954 // FIXME: Instantiation-specific
12955 SemaRef
.MarkFunctionReferenced(E
->getBeginLoc(), Constructor
);
12956 return SemaRef
.MaybeBindToTemporary(E
);
12959 // FIXME: We should just pass E->isListInitialization(), but we're not
12960 // prepared to handle list-initialization without a child InitListExpr.
12961 SourceLocation LParenLoc
= T
->getTypeLoc().getEndLoc();
12962 return getDerived().RebuildCXXTemporaryObjectExpr(
12963 T
, LParenLoc
, Args
, E
->getEndLoc(),
12964 /*ListInitialization=*/LParenLoc
.isInvalid());
12967 template<typename Derived
>
12969 TreeTransform
<Derived
>::TransformLambdaExpr(LambdaExpr
*E
) {
12970 // Transform any init-capture expressions before entering the scope of the
12971 // lambda body, because they are not semantically within that scope.
12972 typedef std::pair
<ExprResult
, QualType
> InitCaptureInfoTy
;
12973 struct TransformedInitCapture
{
12974 // The location of the ... if the result is retaining a pack expansion.
12975 SourceLocation EllipsisLoc
;
12976 // Zero or more expansions of the init-capture.
12977 SmallVector
<InitCaptureInfoTy
, 4> Expansions
;
12979 SmallVector
<TransformedInitCapture
, 4> InitCaptures
;
12980 InitCaptures
.resize(E
->explicit_capture_end() - E
->explicit_capture_begin());
12981 for (LambdaExpr::capture_iterator C
= E
->capture_begin(),
12982 CEnd
= E
->capture_end();
12984 if (!E
->isInitCapture(C
))
12987 TransformedInitCapture
&Result
= InitCaptures
[C
- E
->capture_begin()];
12988 auto *OldVD
= cast
<VarDecl
>(C
->getCapturedVar());
12990 auto SubstInitCapture
= [&](SourceLocation EllipsisLoc
,
12991 Optional
<unsigned> NumExpansions
) {
12992 ExprResult NewExprInitResult
= getDerived().TransformInitializer(
12993 OldVD
->getInit(), OldVD
->getInitStyle() == VarDecl::CallInit
);
12995 if (NewExprInitResult
.isInvalid()) {
12996 Result
.Expansions
.push_back(InitCaptureInfoTy(ExprError(), QualType()));
12999 Expr
*NewExprInit
= NewExprInitResult
.get();
13001 QualType NewInitCaptureType
=
13002 getSema().buildLambdaInitCaptureInitialization(
13003 C
->getLocation(), OldVD
->getType()->isReferenceType(),
13004 EllipsisLoc
, NumExpansions
, OldVD
->getIdentifier(),
13005 cast
<VarDecl
>(C
->getCapturedVar())->getInitStyle() !=
13008 Result
.Expansions
.push_back(
13009 InitCaptureInfoTy(NewExprInit
, NewInitCaptureType
));
13012 // If this is an init-capture pack, consider expanding the pack now.
13013 if (OldVD
->isParameterPack()) {
13014 PackExpansionTypeLoc ExpansionTL
= OldVD
->getTypeSourceInfo()
13016 .castAs
<PackExpansionTypeLoc
>();
13017 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
13018 SemaRef
.collectUnexpandedParameterPacks(OldVD
->getInit(), Unexpanded
);
13020 // Determine whether the set of unexpanded parameter packs can and should
13022 bool Expand
= true;
13023 bool RetainExpansion
= false;
13024 Optional
<unsigned> OrigNumExpansions
=
13025 ExpansionTL
.getTypePtr()->getNumExpansions();
13026 Optional
<unsigned> NumExpansions
= OrigNumExpansions
;
13027 if (getDerived().TryExpandParameterPacks(
13028 ExpansionTL
.getEllipsisLoc(),
13029 OldVD
->getInit()->getSourceRange(), Unexpanded
, Expand
,
13030 RetainExpansion
, NumExpansions
))
13031 return ExprError();
13033 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
13034 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
13035 SubstInitCapture(SourceLocation(), None
);
13038 if (!Expand
|| RetainExpansion
) {
13039 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
13040 SubstInitCapture(ExpansionTL
.getEllipsisLoc(), NumExpansions
);
13041 Result
.EllipsisLoc
= ExpansionTL
.getEllipsisLoc();
13044 SubstInitCapture(SourceLocation(), None
);
13048 LambdaScopeInfo
*LSI
= getSema().PushLambdaScope();
13049 Sema::FunctionScopeRAII
FuncScopeCleanup(getSema());
13051 // Transform the template parameters, and add them to the current
13052 // instantiation scope. The null case is handled correctly.
13053 auto TPL
= getDerived().TransformTemplateParameterList(
13054 E
->getTemplateParameterList());
13055 LSI
->GLTemplateParameterList
= TPL
;
13057 // Transform the type of the original lambda's call operator.
13058 // The transformation MUST be done in the CurrentInstantiationScope since
13059 // it introduces a mapping of the original to the newly created
13060 // transformed parameters.
13061 TypeSourceInfo
*NewCallOpTSI
= nullptr;
13063 TypeSourceInfo
*OldCallOpTSI
= E
->getCallOperator()->getTypeSourceInfo();
13064 FunctionProtoTypeLoc OldCallOpFPTL
=
13065 OldCallOpTSI
->getTypeLoc().getAs
<FunctionProtoTypeLoc
>();
13067 TypeLocBuilder NewCallOpTLBuilder
;
13068 SmallVector
<QualType
, 4> ExceptionStorage
;
13069 TreeTransform
*This
= this; // Work around gcc.gnu.org/PR56135.
13070 QualType NewCallOpType
= TransformFunctionProtoType(
13071 NewCallOpTLBuilder
, OldCallOpFPTL
, nullptr, Qualifiers(),
13072 [&](FunctionProtoType::ExceptionSpecInfo
&ESI
, bool &Changed
) {
13073 return This
->TransformExceptionSpec(OldCallOpFPTL
.getBeginLoc(), ESI
,
13074 ExceptionStorage
, Changed
);
13076 if (NewCallOpType
.isNull())
13077 return ExprError();
13078 NewCallOpTSI
= NewCallOpTLBuilder
.getTypeSourceInfo(getSema().Context
,
13082 // Transform the trailing requires clause
13083 ExprResult NewTrailingRequiresClause
;
13084 if (Expr
*TRC
= E
->getCallOperator()->getTrailingRequiresClause())
13085 // FIXME: Concepts: Substitution into requires clause should only happen
13086 // when checking satisfaction.
13087 NewTrailingRequiresClause
= getDerived().TransformExpr(TRC
);
13089 // Create the local class that will describe the lambda.
13091 // FIXME: DependencyKind below is wrong when substituting inside a templated
13092 // context that isn't a DeclContext (such as a variable template), or when
13093 // substituting an unevaluated lambda inside of a function's parameter's type
13094 // - as parameter types are not instantiated from within a function's DC. We
13095 // use isUnevaluatedContext() to distinguish the function parameter case.
13096 CXXRecordDecl::LambdaDependencyKind DependencyKind
=
13097 CXXRecordDecl::LDK_Unknown
;
13098 if (getSema().isUnevaluatedContext() &&
13099 (getSema().CurContext
->isFileContext() ||
13100 !getSema().CurContext
->getParent()->isDependentContext()))
13101 DependencyKind
= CXXRecordDecl::LDK_NeverDependent
;
13103 CXXRecordDecl
*OldClass
= E
->getLambdaClass();
13104 CXXRecordDecl
*Class
=
13105 getSema().createLambdaClosureType(E
->getIntroducerRange(), NewCallOpTSI
,
13106 DependencyKind
, E
->getCaptureDefault());
13108 getDerived().transformedLocalDecl(OldClass
, {Class
});
13110 Optional
<std::tuple
<bool, unsigned, unsigned, Decl
*>> Mangling
;
13111 if (getDerived().ReplacingOriginal())
13112 Mangling
= std::make_tuple(OldClass
->hasKnownLambdaInternalLinkage(),
13113 OldClass
->getLambdaManglingNumber(),
13114 OldClass
->getDeviceLambdaManglingNumber(),
13115 OldClass
->getLambdaContextDecl());
13117 // Build the call operator.
13118 CXXMethodDecl
*NewCallOperator
= getSema().startLambdaDefinition(
13119 Class
, E
->getIntroducerRange(), NewCallOpTSI
,
13120 E
->getCallOperator()->getEndLoc(),
13121 NewCallOpTSI
->getTypeLoc().castAs
<FunctionProtoTypeLoc
>().getParams(),
13122 E
->getCallOperator()->getConstexprKind(),
13123 NewTrailingRequiresClause
.get());
13125 LSI
->CallOperator
= NewCallOperator
;
13127 getDerived().transformAttrs(E
->getCallOperator(), NewCallOperator
);
13128 getDerived().transformedLocalDecl(E
->getCallOperator(), {NewCallOperator
});
13130 // Number the lambda for linkage purposes if necessary.
13131 getSema().handleLambdaNumbering(Class
, NewCallOperator
, Mangling
);
13133 // Introduce the context of the call operator.
13134 Sema::ContextRAII
SavedContext(getSema(), NewCallOperator
,
13135 /*NewThisContext*/false);
13137 // Enter the scope of the lambda.
13138 getSema().buildLambdaScope(LSI
, NewCallOperator
,
13139 E
->getIntroducerRange(),
13140 E
->getCaptureDefault(),
13141 E
->getCaptureDefaultLoc(),
13142 E
->hasExplicitParameters(),
13143 E
->hasExplicitResultType(),
13146 bool Invalid
= false;
13148 // Transform captures.
13149 for (LambdaExpr::capture_iterator C
= E
->capture_begin(),
13150 CEnd
= E
->capture_end();
13152 // When we hit the first implicit capture, tell Sema that we've finished
13153 // the list of explicit captures.
13154 if (C
->isImplicit())
13157 // Capturing 'this' is trivial.
13158 if (C
->capturesThis()) {
13159 getSema().CheckCXXThisCapture(C
->getLocation(), C
->isExplicit(),
13160 /*BuildAndDiagnose*/ true, nullptr,
13161 C
->getCaptureKind() == LCK_StarThis
);
13164 // Captured expression will be recaptured during captured variables
13166 if (C
->capturesVLAType())
13169 // Rebuild init-captures, including the implied field declaration.
13170 if (E
->isInitCapture(C
)) {
13171 TransformedInitCapture
&NewC
= InitCaptures
[C
- E
->capture_begin()];
13173 auto *OldVD
= cast
<VarDecl
>(C
->getCapturedVar());
13174 llvm::SmallVector
<Decl
*, 4> NewVDs
;
13176 for (InitCaptureInfoTy
&Info
: NewC
.Expansions
) {
13177 ExprResult Init
= Info
.first
;
13178 QualType InitQualType
= Info
.second
;
13179 if (Init
.isInvalid() || InitQualType
.isNull()) {
13183 VarDecl
*NewVD
= getSema().createLambdaInitCaptureVarDecl(
13184 OldVD
->getLocation(), InitQualType
, NewC
.EllipsisLoc
,
13185 OldVD
->getIdentifier(), OldVD
->getInitStyle(), Init
.get());
13190 NewVDs
.push_back(NewVD
);
13191 getSema().addInitCapture(LSI
, NewVD
);
13197 getDerived().transformedLocalDecl(OldVD
, NewVDs
);
13201 assert(C
->capturesVariable() && "unexpected kind of lambda capture");
13203 // Determine the capture kind for Sema.
13204 Sema::TryCaptureKind Kind
13205 = C
->isImplicit()? Sema::TryCapture_Implicit
13206 : C
->getCaptureKind() == LCK_ByCopy
13207 ? Sema::TryCapture_ExplicitByVal
13208 : Sema::TryCapture_ExplicitByRef
;
13209 SourceLocation EllipsisLoc
;
13210 if (C
->isPackExpansion()) {
13211 UnexpandedParameterPack
Unexpanded(C
->getCapturedVar(), C
->getLocation());
13212 bool ShouldExpand
= false;
13213 bool RetainExpansion
= false;
13214 Optional
<unsigned> NumExpansions
;
13215 if (getDerived().TryExpandParameterPacks(C
->getEllipsisLoc(),
13218 ShouldExpand
, RetainExpansion
,
13224 if (ShouldExpand
) {
13225 // The transform has determined that we should perform an expansion;
13226 // transform and capture each of the arguments.
13227 // expansion of the pattern. Do so.
13228 auto *Pack
= cast
<VarDecl
>(C
->getCapturedVar());
13229 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
13230 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
13231 VarDecl
*CapturedVar
13232 = cast_or_null
<VarDecl
>(getDerived().TransformDecl(C
->getLocation(),
13234 if (!CapturedVar
) {
13239 // Capture the transformed variable.
13240 getSema().tryCaptureVariable(CapturedVar
, C
->getLocation(), Kind
);
13243 // FIXME: Retain a pack expansion if RetainExpansion is true.
13248 EllipsisLoc
= C
->getEllipsisLoc();
13251 // Transform the captured variable.
13252 VarDecl
*CapturedVar
13253 = cast_or_null
<VarDecl
>(getDerived().TransformDecl(C
->getLocation(),
13254 C
->getCapturedVar()));
13255 if (!CapturedVar
|| CapturedVar
->isInvalidDecl()) {
13260 // Capture the transformed variable.
13261 getSema().tryCaptureVariable(CapturedVar
, C
->getLocation(), Kind
,
13264 getSema().finishLambdaExplicitCaptures(LSI
);
13266 // FIXME: Sema's lambda-building mechanism expects us to push an expression
13267 // evaluation context even if we're not transforming the function body.
13268 getSema().PushExpressionEvaluationContext(
13269 Sema::ExpressionEvaluationContext::PotentiallyEvaluated
);
13271 // Instantiate the body of the lambda expression.
13273 Invalid
? StmtError() : getDerived().TransformLambdaBody(E
, E
->getBody());
13275 // ActOnLambda* will pop the function scope for us.
13276 FuncScopeCleanup
.disable();
13278 if (Body
.isInvalid()) {
13279 SavedContext
.pop();
13280 getSema().ActOnLambdaError(E
->getBeginLoc(), /*CurScope=*/nullptr,
13281 /*IsInstantiation=*/true);
13282 return ExprError();
13285 // Copy the LSI before ActOnFinishFunctionBody removes it.
13286 // FIXME: This is dumb. Store the lambda information somewhere that outlives
13287 // the call operator.
13288 auto LSICopy
= *LSI
;
13289 getSema().ActOnFinishFunctionBody(NewCallOperator
, Body
.get(),
13290 /*IsInstantiation*/ true);
13291 SavedContext
.pop();
13293 return getSema().BuildLambdaExpr(E
->getBeginLoc(), Body
.get()->getEndLoc(),
13297 template<typename Derived
>
13299 TreeTransform
<Derived
>::TransformLambdaBody(LambdaExpr
*E
, Stmt
*S
) {
13300 return TransformStmt(S
);
13303 template<typename Derived
>
13305 TreeTransform
<Derived
>::SkipLambdaBody(LambdaExpr
*E
, Stmt
*S
) {
13306 // Transform captures.
13307 for (LambdaExpr::capture_iterator C
= E
->capture_begin(),
13308 CEnd
= E
->capture_end();
13310 // When we hit the first implicit capture, tell Sema that we've finished
13311 // the list of explicit captures.
13312 if (!C
->isImplicit())
13315 // Capturing 'this' is trivial.
13316 if (C
->capturesThis()) {
13317 getSema().CheckCXXThisCapture(C
->getLocation(), C
->isExplicit(),
13318 /*BuildAndDiagnose*/ true, nullptr,
13319 C
->getCaptureKind() == LCK_StarThis
);
13322 // Captured expression will be recaptured during captured variables
13324 if (C
->capturesVLAType())
13327 assert(C
->capturesVariable() && "unexpected kind of lambda capture");
13328 assert(!E
->isInitCapture(C
) && "implicit init-capture?");
13330 // Transform the captured variable.
13331 VarDecl
*CapturedVar
= cast_or_null
<VarDecl
>(
13332 getDerived().TransformDecl(C
->getLocation(), C
->getCapturedVar()));
13333 if (!CapturedVar
|| CapturedVar
->isInvalidDecl())
13334 return StmtError();
13336 // Capture the transformed variable.
13337 getSema().tryCaptureVariable(CapturedVar
, C
->getLocation());
13343 template<typename Derived
>
13345 TreeTransform
<Derived
>::TransformCXXUnresolvedConstructExpr(
13346 CXXUnresolvedConstructExpr
*E
) {
13347 TypeSourceInfo
*T
=
13348 getDerived().TransformTypeWithDeducedTST(E
->getTypeSourceInfo());
13350 return ExprError();
13352 bool ArgumentChanged
= false;
13353 SmallVector
<Expr
*, 8> Args
;
13354 Args
.reserve(E
->getNumArgs());
13356 EnterExpressionEvaluationContext
Context(
13357 getSema(), EnterExpressionEvaluationContext::InitList
,
13358 E
->isListInitialization());
13359 if (getDerived().TransformExprs(E
->arg_begin(), E
->getNumArgs(), true, Args
,
13361 return ExprError();
13364 if (!getDerived().AlwaysRebuild() &&
13365 T
== E
->getTypeSourceInfo() &&
13369 // FIXME: we're faking the locations of the commas
13370 return getDerived().RebuildCXXUnresolvedConstructExpr(
13371 T
, E
->getLParenLoc(), Args
, E
->getRParenLoc(), E
->isListInitialization());
13374 template<typename Derived
>
13376 TreeTransform
<Derived
>::TransformCXXDependentScopeMemberExpr(
13377 CXXDependentScopeMemberExpr
*E
) {
13378 // Transform the base of the expression.
13379 ExprResult
Base((Expr
*) nullptr);
13382 QualType ObjectType
;
13383 if (!E
->isImplicitAccess()) {
13384 OldBase
= E
->getBase();
13385 Base
= getDerived().TransformExpr(OldBase
);
13386 if (Base
.isInvalid())
13387 return ExprError();
13389 // Start the member reference and compute the object's type.
13390 ParsedType ObjectTy
;
13391 bool MayBePseudoDestructor
= false;
13392 Base
= SemaRef
.ActOnStartCXXMemberReference(nullptr, Base
.get(),
13393 E
->getOperatorLoc(),
13394 E
->isArrow()? tok::arrow
: tok::period
,
13396 MayBePseudoDestructor
);
13397 if (Base
.isInvalid())
13398 return ExprError();
13400 ObjectType
= ObjectTy
.get();
13401 BaseType
= ((Expr
*) Base
.get())->getType();
13404 BaseType
= getDerived().TransformType(E
->getBaseType());
13405 ObjectType
= BaseType
->castAs
<PointerType
>()->getPointeeType();
13408 // Transform the first part of the nested-name-specifier that qualifies
13409 // the member name.
13410 NamedDecl
*FirstQualifierInScope
13411 = getDerived().TransformFirstQualifierInScope(
13412 E
->getFirstQualifierFoundInScope(),
13413 E
->getQualifierLoc().getBeginLoc());
13415 NestedNameSpecifierLoc QualifierLoc
;
13416 if (E
->getQualifier()) {
13418 = getDerived().TransformNestedNameSpecifierLoc(E
->getQualifierLoc(),
13420 FirstQualifierInScope
);
13422 return ExprError();
13425 SourceLocation TemplateKWLoc
= E
->getTemplateKeywordLoc();
13427 // TODO: If this is a conversion-function-id, verify that the
13428 // destination type name (if present) resolves the same way after
13429 // instantiation as it did in the local scope.
13431 DeclarationNameInfo NameInfo
13432 = getDerived().TransformDeclarationNameInfo(E
->getMemberNameInfo());
13433 if (!NameInfo
.getName())
13434 return ExprError();
13436 if (!E
->hasExplicitTemplateArgs()) {
13437 // This is a reference to a member without an explicitly-specified
13438 // template argument list. Optimize for this common case.
13439 if (!getDerived().AlwaysRebuild() &&
13440 Base
.get() == OldBase
&&
13441 BaseType
== E
->getBaseType() &&
13442 QualifierLoc
== E
->getQualifierLoc() &&
13443 NameInfo
.getName() == E
->getMember() &&
13444 FirstQualifierInScope
== E
->getFirstQualifierFoundInScope())
13447 return getDerived().RebuildCXXDependentScopeMemberExpr(Base
.get(),
13450 E
->getOperatorLoc(),
13453 FirstQualifierInScope
,
13455 /*TemplateArgs*/nullptr);
13458 TemplateArgumentListInfo
TransArgs(E
->getLAngleLoc(), E
->getRAngleLoc());
13459 if (getDerived().TransformTemplateArguments(E
->getTemplateArgs(),
13460 E
->getNumTemplateArgs(),
13462 return ExprError();
13464 return getDerived().RebuildCXXDependentScopeMemberExpr(Base
.get(),
13467 E
->getOperatorLoc(),
13470 FirstQualifierInScope
,
13475 template <typename Derived
>
13476 ExprResult TreeTransform
<Derived
>::TransformUnresolvedMemberExpr(
13477 UnresolvedMemberExpr
*Old
) {
13478 // Transform the base of the expression.
13479 ExprResult
Base((Expr
*)nullptr);
13481 if (!Old
->isImplicitAccess()) {
13482 Base
= getDerived().TransformExpr(Old
->getBase());
13483 if (Base
.isInvalid())
13484 return ExprError();
13486 getSema().PerformMemberExprBaseConversion(Base
.get(), Old
->isArrow());
13487 if (Base
.isInvalid())
13488 return ExprError();
13489 BaseType
= Base
.get()->getType();
13491 BaseType
= getDerived().TransformType(Old
->getBaseType());
13494 NestedNameSpecifierLoc QualifierLoc
;
13495 if (Old
->getQualifierLoc()) {
13497 getDerived().TransformNestedNameSpecifierLoc(Old
->getQualifierLoc());
13499 return ExprError();
13502 SourceLocation TemplateKWLoc
= Old
->getTemplateKeywordLoc();
13504 LookupResult
R(SemaRef
, Old
->getMemberNameInfo(), Sema::LookupOrdinaryName
);
13506 // Transform the declaration set.
13507 if (TransformOverloadExprDecls(Old
, /*RequiresADL*/ false, R
))
13508 return ExprError();
13510 // Determine the naming class.
13511 if (Old
->getNamingClass()) {
13512 CXXRecordDecl
*NamingClass
= cast_or_null
<CXXRecordDecl
>(
13513 getDerived().TransformDecl(Old
->getMemberLoc(), Old
->getNamingClass()));
13515 return ExprError();
13517 R
.setNamingClass(NamingClass
);
13520 TemplateArgumentListInfo TransArgs
;
13521 if (Old
->hasExplicitTemplateArgs()) {
13522 TransArgs
.setLAngleLoc(Old
->getLAngleLoc());
13523 TransArgs
.setRAngleLoc(Old
->getRAngleLoc());
13524 if (getDerived().TransformTemplateArguments(
13525 Old
->getTemplateArgs(), Old
->getNumTemplateArgs(), TransArgs
))
13526 return ExprError();
13529 // FIXME: to do this check properly, we will need to preserve the
13530 // first-qualifier-in-scope here, just in case we had a dependent
13531 // base (and therefore couldn't do the check) and a
13532 // nested-name-qualifier (and therefore could do the lookup).
13533 NamedDecl
*FirstQualifierInScope
= nullptr;
13535 return getDerived().RebuildUnresolvedMemberExpr(
13536 Base
.get(), BaseType
, Old
->getOperatorLoc(), Old
->isArrow(), QualifierLoc
,
13537 TemplateKWLoc
, FirstQualifierInScope
, R
,
13538 (Old
->hasExplicitTemplateArgs() ? &TransArgs
: nullptr));
13541 template<typename Derived
>
13543 TreeTransform
<Derived
>::TransformCXXNoexceptExpr(CXXNoexceptExpr
*E
) {
13544 EnterExpressionEvaluationContext
Unevaluated(
13545 SemaRef
, Sema::ExpressionEvaluationContext::Unevaluated
);
13546 ExprResult SubExpr
= getDerived().TransformExpr(E
->getOperand());
13547 if (SubExpr
.isInvalid())
13548 return ExprError();
13550 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getOperand())
13553 return getDerived().RebuildCXXNoexceptExpr(E
->getSourceRange(),SubExpr
.get());
13556 template<typename Derived
>
13558 TreeTransform
<Derived
>::TransformPackExpansionExpr(PackExpansionExpr
*E
) {
13559 ExprResult Pattern
= getDerived().TransformExpr(E
->getPattern());
13560 if (Pattern
.isInvalid())
13561 return ExprError();
13563 if (!getDerived().AlwaysRebuild() && Pattern
.get() == E
->getPattern())
13566 return getDerived().RebuildPackExpansion(Pattern
.get(), E
->getEllipsisLoc(),
13567 E
->getNumExpansions());
13570 template<typename Derived
>
13572 TreeTransform
<Derived
>::TransformSizeOfPackExpr(SizeOfPackExpr
*E
) {
13573 // If E is not value-dependent, then nothing will change when we transform it.
13574 // Note: This is an instantiation-centric view.
13575 if (!E
->isValueDependent())
13578 EnterExpressionEvaluationContext
Unevaluated(
13579 getSema(), Sema::ExpressionEvaluationContext::Unevaluated
);
13581 ArrayRef
<TemplateArgument
> PackArgs
;
13582 TemplateArgument ArgStorage
;
13584 // Find the argument list to transform.
13585 if (E
->isPartiallySubstituted()) {
13586 PackArgs
= E
->getPartialArguments();
13587 } else if (E
->isValueDependent()) {
13588 UnexpandedParameterPack
Unexpanded(E
->getPack(), E
->getPackLoc());
13589 bool ShouldExpand
= false;
13590 bool RetainExpansion
= false;
13591 Optional
<unsigned> NumExpansions
;
13592 if (getDerived().TryExpandParameterPacks(E
->getOperatorLoc(), E
->getPackLoc(),
13594 ShouldExpand
, RetainExpansion
,
13596 return ExprError();
13598 // If we need to expand the pack, build a template argument from it and
13600 if (ShouldExpand
) {
13601 auto *Pack
= E
->getPack();
13602 if (auto *TTPD
= dyn_cast
<TemplateTypeParmDecl
>(Pack
)) {
13603 ArgStorage
= getSema().Context
.getPackExpansionType(
13604 getSema().Context
.getTypeDeclType(TTPD
), None
);
13605 } else if (auto *TTPD
= dyn_cast
<TemplateTemplateParmDecl
>(Pack
)) {
13606 ArgStorage
= TemplateArgument(TemplateName(TTPD
), None
);
13608 auto *VD
= cast
<ValueDecl
>(Pack
);
13609 ExprResult DRE
= getSema().BuildDeclRefExpr(
13610 VD
, VD
->getType().getNonLValueExprType(getSema().Context
),
13611 VD
->getType()->isReferenceType() ? VK_LValue
: VK_PRValue
,
13613 if (DRE
.isInvalid())
13614 return ExprError();
13615 ArgStorage
= new (getSema().Context
) PackExpansionExpr(
13616 getSema().Context
.DependentTy
, DRE
.get(), E
->getPackLoc(), None
);
13618 PackArgs
= ArgStorage
;
13622 // If we're not expanding the pack, just transform the decl.
13623 if (!PackArgs
.size()) {
13624 auto *Pack
= cast_or_null
<NamedDecl
>(
13625 getDerived().TransformDecl(E
->getPackLoc(), E
->getPack()));
13627 return ExprError();
13628 return getDerived().RebuildSizeOfPackExpr(E
->getOperatorLoc(), Pack
,
13630 E
->getRParenLoc(), None
, None
);
13633 // Try to compute the result without performing a partial substitution.
13634 Optional
<unsigned> Result
= 0;
13635 for (const TemplateArgument
&Arg
: PackArgs
) {
13636 if (!Arg
.isPackExpansion()) {
13637 Result
= *Result
+ 1;
13641 TemplateArgumentLoc ArgLoc
;
13642 InventTemplateArgumentLoc(Arg
, ArgLoc
);
13644 // Find the pattern of the pack expansion.
13645 SourceLocation Ellipsis
;
13646 Optional
<unsigned> OrigNumExpansions
;
13647 TemplateArgumentLoc Pattern
=
13648 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc
, Ellipsis
,
13649 OrigNumExpansions
);
13651 // Substitute under the pack expansion. Do not expand the pack (yet).
13652 TemplateArgumentLoc OutPattern
;
13653 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
13654 if (getDerived().TransformTemplateArgument(Pattern
, OutPattern
,
13658 // See if we can determine the number of arguments from the result.
13659 Optional
<unsigned> NumExpansions
=
13660 getSema().getFullyPackExpandedSize(OutPattern
.getArgument());
13661 if (!NumExpansions
) {
13662 // No: we must be in an alias template expansion, and we're going to need
13663 // to actually expand the packs.
13668 Result
= *Result
+ *NumExpansions
;
13671 // Common case: we could determine the number of expansions without
13674 return getDerived().RebuildSizeOfPackExpr(E
->getOperatorLoc(), E
->getPack(),
13676 E
->getRParenLoc(), *Result
, None
);
13678 TemplateArgumentListInfo
TransformedPackArgs(E
->getPackLoc(),
13681 TemporaryBase
Rebase(*this, E
->getPackLoc(), getBaseEntity());
13682 typedef TemplateArgumentLocInventIterator
<
13683 Derived
, const TemplateArgument
*> PackLocIterator
;
13684 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs
.begin()),
13685 PackLocIterator(*this, PackArgs
.end()),
13686 TransformedPackArgs
, /*Uneval*/true))
13687 return ExprError();
13690 // Check whether we managed to fully-expand the pack.
13691 // FIXME: Is it possible for us to do so and not hit the early exit path?
13692 SmallVector
<TemplateArgument
, 8> Args
;
13693 bool PartialSubstitution
= false;
13694 for (auto &Loc
: TransformedPackArgs
.arguments()) {
13695 Args
.push_back(Loc
.getArgument());
13696 if (Loc
.getArgument().isPackExpansion())
13697 PartialSubstitution
= true;
13700 if (PartialSubstitution
)
13701 return getDerived().RebuildSizeOfPackExpr(E
->getOperatorLoc(), E
->getPack(),
13703 E
->getRParenLoc(), None
, Args
);
13705 return getDerived().RebuildSizeOfPackExpr(E
->getOperatorLoc(), E
->getPack(),
13706 E
->getPackLoc(), E
->getRParenLoc(),
13707 Args
.size(), None
);
13710 template<typename Derived
>
13712 TreeTransform
<Derived
>::TransformSubstNonTypeTemplateParmPackExpr(
13713 SubstNonTypeTemplateParmPackExpr
*E
) {
13714 // Default behavior is to do nothing with this transformation.
13718 template<typename Derived
>
13720 TreeTransform
<Derived
>::TransformSubstNonTypeTemplateParmExpr(
13721 SubstNonTypeTemplateParmExpr
*E
) {
13722 // Default behavior is to do nothing with this transformation.
13726 template<typename Derived
>
13728 TreeTransform
<Derived
>::TransformFunctionParmPackExpr(FunctionParmPackExpr
*E
) {
13729 // Default behavior is to do nothing with this transformation.
13733 template<typename Derived
>
13735 TreeTransform
<Derived
>::TransformMaterializeTemporaryExpr(
13736 MaterializeTemporaryExpr
*E
) {
13737 return getDerived().TransformExpr(E
->getSubExpr());
13740 template<typename Derived
>
13742 TreeTransform
<Derived
>::TransformCXXFoldExpr(CXXFoldExpr
*E
) {
13743 UnresolvedLookupExpr
*Callee
= nullptr;
13744 if (Expr
*OldCallee
= E
->getCallee()) {
13745 ExprResult CalleeResult
= getDerived().TransformExpr(OldCallee
);
13746 if (CalleeResult
.isInvalid())
13747 return ExprError();
13748 Callee
= cast
<UnresolvedLookupExpr
>(CalleeResult
.get());
13751 Expr
*Pattern
= E
->getPattern();
13753 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
13754 getSema().collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
13755 assert(!Unexpanded
.empty() && "Pack expansion without parameter packs?");
13757 // Determine whether the set of unexpanded parameter packs can and should
13759 bool Expand
= true;
13760 bool RetainExpansion
= false;
13761 Optional
<unsigned> OrigNumExpansions
= E
->getNumExpansions(),
13762 NumExpansions
= OrigNumExpansions
;
13763 if (getDerived().TryExpandParameterPacks(E
->getEllipsisLoc(),
13764 Pattern
->getSourceRange(),
13766 Expand
, RetainExpansion
,
13771 // Do not expand any packs here, just transform and rebuild a fold
13773 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
13776 E
->getLHS() ? getDerived().TransformExpr(E
->getLHS()) : ExprResult();
13777 if (LHS
.isInvalid())
13781 E
->getRHS() ? getDerived().TransformExpr(E
->getRHS()) : ExprResult();
13782 if (RHS
.isInvalid())
13785 if (!getDerived().AlwaysRebuild() &&
13786 LHS
.get() == E
->getLHS() && RHS
.get() == E
->getRHS())
13789 return getDerived().RebuildCXXFoldExpr(
13790 Callee
, E
->getBeginLoc(), LHS
.get(), E
->getOperator(),
13791 E
->getEllipsisLoc(), RHS
.get(), E
->getEndLoc(), NumExpansions
);
13794 // Formally a fold expression expands to nested parenthesized expressions.
13795 // Enforce this limit to avoid creating trees so deep we can't safely traverse
13797 if (NumExpansions
&& SemaRef
.getLangOpts().BracketDepth
< NumExpansions
) {
13798 SemaRef
.Diag(E
->getEllipsisLoc(),
13799 clang::diag::err_fold_expression_limit_exceeded
)
13800 << *NumExpansions
<< SemaRef
.getLangOpts().BracketDepth
13801 << E
->getSourceRange();
13802 SemaRef
.Diag(E
->getEllipsisLoc(), diag::note_bracket_depth
);
13803 return ExprError();
13806 // The transform has determined that we should perform an elementwise
13807 // expansion of the pattern. Do so.
13808 ExprResult Result
= getDerived().TransformExpr(E
->getInit());
13809 if (Result
.isInvalid())
13811 bool LeftFold
= E
->isLeftFold();
13813 // If we're retaining an expansion for a right fold, it is the innermost
13814 // component and takes the init (if any).
13815 if (!LeftFold
&& RetainExpansion
) {
13816 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
13818 ExprResult Out
= getDerived().TransformExpr(Pattern
);
13819 if (Out
.isInvalid())
13822 Result
= getDerived().RebuildCXXFoldExpr(
13823 Callee
, E
->getBeginLoc(), Out
.get(), E
->getOperator(),
13824 E
->getEllipsisLoc(), Result
.get(), E
->getEndLoc(), OrigNumExpansions
);
13825 if (Result
.isInvalid())
13829 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
13830 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(
13831 getSema(), LeftFold
? I
: *NumExpansions
- I
- 1);
13832 ExprResult Out
= getDerived().TransformExpr(Pattern
);
13833 if (Out
.isInvalid())
13836 if (Out
.get()->containsUnexpandedParameterPack()) {
13837 // We still have a pack; retain a pack expansion for this slice.
13838 Result
= getDerived().RebuildCXXFoldExpr(
13839 Callee
, E
->getBeginLoc(), LeftFold
? Result
.get() : Out
.get(),
13840 E
->getOperator(), E
->getEllipsisLoc(),
13841 LeftFold
? Out
.get() : Result
.get(), E
->getEndLoc(),
13842 OrigNumExpansions
);
13843 } else if (Result
.isUsable()) {
13844 // We've got down to a single element; build a binary operator.
13845 Expr
*LHS
= LeftFold
? Result
.get() : Out
.get();
13846 Expr
*RHS
= LeftFold
? Out
.get() : Result
.get();
13848 Result
= getDerived().RebuildCXXOperatorCallExpr(
13849 BinaryOperator::getOverloadedOperator(E
->getOperator()),
13850 E
->getEllipsisLoc(), Callee
, LHS
, RHS
);
13852 Result
= getDerived().RebuildBinaryOperator(E
->getEllipsisLoc(),
13853 E
->getOperator(), LHS
, RHS
);
13857 if (Result
.isInvalid())
13861 // If we're retaining an expansion for a left fold, it is the outermost
13862 // component and takes the complete expansion so far as its init (if any).
13863 if (LeftFold
&& RetainExpansion
) {
13864 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
13866 ExprResult Out
= getDerived().TransformExpr(Pattern
);
13867 if (Out
.isInvalid())
13870 Result
= getDerived().RebuildCXXFoldExpr(
13871 Callee
, E
->getBeginLoc(), Result
.get(), E
->getOperator(),
13872 E
->getEllipsisLoc(), Out
.get(), E
->getEndLoc(), OrigNumExpansions
);
13873 if (Result
.isInvalid())
13877 // If we had no init and an empty pack, and we're not retaining an expansion,
13878 // then produce a fallback value or error.
13879 if (Result
.isUnset())
13880 return getDerived().RebuildEmptyCXXFoldExpr(E
->getEllipsisLoc(),
13886 template<typename Derived
>
13888 TreeTransform
<Derived
>::TransformCXXStdInitializerListExpr(
13889 CXXStdInitializerListExpr
*E
) {
13890 return getDerived().TransformExpr(E
->getSubExpr());
13893 template<typename Derived
>
13895 TreeTransform
<Derived
>::TransformObjCStringLiteral(ObjCStringLiteral
*E
) {
13896 return SemaRef
.MaybeBindToTemporary(E
);
13899 template<typename Derived
>
13901 TreeTransform
<Derived
>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr
*E
) {
13905 template<typename Derived
>
13907 TreeTransform
<Derived
>::TransformObjCBoxedExpr(ObjCBoxedExpr
*E
) {
13908 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
13909 if (SubExpr
.isInvalid())
13910 return ExprError();
13912 if (!getDerived().AlwaysRebuild() &&
13913 SubExpr
.get() == E
->getSubExpr())
13916 return getDerived().RebuildObjCBoxedExpr(E
->getSourceRange(), SubExpr
.get());
13919 template<typename Derived
>
13921 TreeTransform
<Derived
>::TransformObjCArrayLiteral(ObjCArrayLiteral
*E
) {
13922 // Transform each of the elements.
13923 SmallVector
<Expr
*, 8> Elements
;
13924 bool ArgChanged
= false;
13925 if (getDerived().TransformExprs(E
->getElements(), E
->getNumElements(),
13926 /*IsCall=*/false, Elements
, &ArgChanged
))
13927 return ExprError();
13929 if (!getDerived().AlwaysRebuild() && !ArgChanged
)
13930 return SemaRef
.MaybeBindToTemporary(E
);
13932 return getDerived().RebuildObjCArrayLiteral(E
->getSourceRange(),
13937 template<typename Derived
>
13939 TreeTransform
<Derived
>::TransformObjCDictionaryLiteral(
13940 ObjCDictionaryLiteral
*E
) {
13941 // Transform each of the elements.
13942 SmallVector
<ObjCDictionaryElement
, 8> Elements
;
13943 bool ArgChanged
= false;
13944 for (unsigned I
= 0, N
= E
->getNumElements(); I
!= N
; ++I
) {
13945 ObjCDictionaryElement OrigElement
= E
->getKeyValueElement(I
);
13947 if (OrigElement
.isPackExpansion()) {
13948 // This key/value element is a pack expansion.
13949 SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
13950 getSema().collectUnexpandedParameterPacks(OrigElement
.Key
, Unexpanded
);
13951 getSema().collectUnexpandedParameterPacks(OrigElement
.Value
, Unexpanded
);
13952 assert(!Unexpanded
.empty() && "Pack expansion without parameter packs?");
13954 // Determine whether the set of unexpanded parameter packs can
13955 // and should be expanded.
13956 bool Expand
= true;
13957 bool RetainExpansion
= false;
13958 Optional
<unsigned> OrigNumExpansions
= OrigElement
.NumExpansions
;
13959 Optional
<unsigned> NumExpansions
= OrigNumExpansions
;
13960 SourceRange
PatternRange(OrigElement
.Key
->getBeginLoc(),
13961 OrigElement
.Value
->getEndLoc());
13962 if (getDerived().TryExpandParameterPacks(OrigElement
.EllipsisLoc
,
13963 PatternRange
, Unexpanded
, Expand
,
13964 RetainExpansion
, NumExpansions
))
13965 return ExprError();
13968 // The transform has determined that we should perform a simple
13969 // transformation on the pack expansion, producing another pack
13971 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
13972 ExprResult Key
= getDerived().TransformExpr(OrigElement
.Key
);
13973 if (Key
.isInvalid())
13974 return ExprError();
13976 if (Key
.get() != OrigElement
.Key
)
13979 ExprResult Value
= getDerived().TransformExpr(OrigElement
.Value
);
13980 if (Value
.isInvalid())
13981 return ExprError();
13983 if (Value
.get() != OrigElement
.Value
)
13986 ObjCDictionaryElement Expansion
= {
13987 Key
.get(), Value
.get(), OrigElement
.EllipsisLoc
, NumExpansions
13989 Elements
.push_back(Expansion
);
13993 // Record right away that the argument was changed. This needs
13994 // to happen even if the array expands to nothing.
13997 // The transform has determined that we should perform an elementwise
13998 // expansion of the pattern. Do so.
13999 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
14000 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
14001 ExprResult Key
= getDerived().TransformExpr(OrigElement
.Key
);
14002 if (Key
.isInvalid())
14003 return ExprError();
14005 ExprResult Value
= getDerived().TransformExpr(OrigElement
.Value
);
14006 if (Value
.isInvalid())
14007 return ExprError();
14009 ObjCDictionaryElement Element
= {
14010 Key
.get(), Value
.get(), SourceLocation(), NumExpansions
14013 // If any unexpanded parameter packs remain, we still have a
14015 // FIXME: Can this really happen?
14016 if (Key
.get()->containsUnexpandedParameterPack() ||
14017 Value
.get()->containsUnexpandedParameterPack())
14018 Element
.EllipsisLoc
= OrigElement
.EllipsisLoc
;
14020 Elements
.push_back(Element
);
14023 // FIXME: Retain a pack expansion if RetainExpansion is true.
14025 // We've finished with this pack expansion.
14029 // Transform and check key.
14030 ExprResult Key
= getDerived().TransformExpr(OrigElement
.Key
);
14031 if (Key
.isInvalid())
14032 return ExprError();
14034 if (Key
.get() != OrigElement
.Key
)
14037 // Transform and check value.
14039 = getDerived().TransformExpr(OrigElement
.Value
);
14040 if (Value
.isInvalid())
14041 return ExprError();
14043 if (Value
.get() != OrigElement
.Value
)
14046 ObjCDictionaryElement Element
= {
14047 Key
.get(), Value
.get(), SourceLocation(), None
14049 Elements
.push_back(Element
);
14052 if (!getDerived().AlwaysRebuild() && !ArgChanged
)
14053 return SemaRef
.MaybeBindToTemporary(E
);
14055 return getDerived().RebuildObjCDictionaryLiteral(E
->getSourceRange(),
14059 template<typename Derived
>
14061 TreeTransform
<Derived
>::TransformObjCEncodeExpr(ObjCEncodeExpr
*E
) {
14062 TypeSourceInfo
*EncodedTypeInfo
14063 = getDerived().TransformType(E
->getEncodedTypeSourceInfo());
14064 if (!EncodedTypeInfo
)
14065 return ExprError();
14067 if (!getDerived().AlwaysRebuild() &&
14068 EncodedTypeInfo
== E
->getEncodedTypeSourceInfo())
14071 return getDerived().RebuildObjCEncodeExpr(E
->getAtLoc(),
14073 E
->getRParenLoc());
14076 template<typename Derived
>
14077 ExprResult TreeTransform
<Derived
>::
14078 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr
*E
) {
14079 // This is a kind of implicit conversion, and it needs to get dropped
14080 // and recomputed for the same general reasons that ImplicitCastExprs
14081 // do, as well a more specific one: this expression is only valid when
14082 // it appears *immediately* as an argument expression.
14083 return getDerived().TransformExpr(E
->getSubExpr());
14086 template<typename Derived
>
14087 ExprResult TreeTransform
<Derived
>::
14088 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr
*E
) {
14089 TypeSourceInfo
*TSInfo
14090 = getDerived().TransformType(E
->getTypeInfoAsWritten());
14092 return ExprError();
14094 ExprResult Result
= getDerived().TransformExpr(E
->getSubExpr());
14095 if (Result
.isInvalid())
14096 return ExprError();
14098 if (!getDerived().AlwaysRebuild() &&
14099 TSInfo
== E
->getTypeInfoAsWritten() &&
14100 Result
.get() == E
->getSubExpr())
14103 return SemaRef
.BuildObjCBridgedCast(E
->getLParenLoc(), E
->getBridgeKind(),
14104 E
->getBridgeKeywordLoc(), TSInfo
,
14108 template <typename Derived
>
14109 ExprResult TreeTransform
<Derived
>::TransformObjCAvailabilityCheckExpr(
14110 ObjCAvailabilityCheckExpr
*E
) {
14114 template<typename Derived
>
14116 TreeTransform
<Derived
>::TransformObjCMessageExpr(ObjCMessageExpr
*E
) {
14117 // Transform arguments.
14118 bool ArgChanged
= false;
14119 SmallVector
<Expr
*, 8> Args
;
14120 Args
.reserve(E
->getNumArgs());
14121 if (getDerived().TransformExprs(E
->getArgs(), E
->getNumArgs(), false, Args
,
14123 return ExprError();
14125 if (E
->getReceiverKind() == ObjCMessageExpr::Class
) {
14126 // Class message: transform the receiver type.
14127 TypeSourceInfo
*ReceiverTypeInfo
14128 = getDerived().TransformType(E
->getClassReceiverTypeInfo());
14129 if (!ReceiverTypeInfo
)
14130 return ExprError();
14132 // If nothing changed, just retain the existing message send.
14133 if (!getDerived().AlwaysRebuild() &&
14134 ReceiverTypeInfo
== E
->getClassReceiverTypeInfo() && !ArgChanged
)
14135 return SemaRef
.MaybeBindToTemporary(E
);
14137 // Build a new class message send.
14138 SmallVector
<SourceLocation
, 16> SelLocs
;
14139 E
->getSelectorLocs(SelLocs
);
14140 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo
,
14143 E
->getMethodDecl(),
14148 else if (E
->getReceiverKind() == ObjCMessageExpr::SuperClass
||
14149 E
->getReceiverKind() == ObjCMessageExpr::SuperInstance
) {
14150 if (!E
->getMethodDecl())
14151 return ExprError();
14153 // Build a new class message send to 'super'.
14154 SmallVector
<SourceLocation
, 16> SelLocs
;
14155 E
->getSelectorLocs(SelLocs
);
14156 return getDerived().RebuildObjCMessageExpr(E
->getSuperLoc(),
14159 E
->getReceiverType(),
14160 E
->getMethodDecl(),
14166 // Instance message: transform the receiver
14167 assert(E
->getReceiverKind() == ObjCMessageExpr::Instance
&&
14168 "Only class and instance messages may be instantiated");
14169 ExprResult Receiver
14170 = getDerived().TransformExpr(E
->getInstanceReceiver());
14171 if (Receiver
.isInvalid())
14172 return ExprError();
14174 // If nothing changed, just retain the existing message send.
14175 if (!getDerived().AlwaysRebuild() &&
14176 Receiver
.get() == E
->getInstanceReceiver() && !ArgChanged
)
14177 return SemaRef
.MaybeBindToTemporary(E
);
14179 // Build a new instance message send.
14180 SmallVector
<SourceLocation
, 16> SelLocs
;
14181 E
->getSelectorLocs(SelLocs
);
14182 return getDerived().RebuildObjCMessageExpr(Receiver
.get(),
14185 E
->getMethodDecl(),
14191 template<typename Derived
>
14193 TreeTransform
<Derived
>::TransformObjCSelectorExpr(ObjCSelectorExpr
*E
) {
14197 template<typename Derived
>
14199 TreeTransform
<Derived
>::TransformObjCProtocolExpr(ObjCProtocolExpr
*E
) {
14203 template<typename Derived
>
14205 TreeTransform
<Derived
>::TransformObjCIvarRefExpr(ObjCIvarRefExpr
*E
) {
14206 // Transform the base expression.
14207 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
14208 if (Base
.isInvalid())
14209 return ExprError();
14211 // We don't need to transform the ivar; it will never change.
14213 // If nothing changed, just retain the existing expression.
14214 if (!getDerived().AlwaysRebuild() &&
14215 Base
.get() == E
->getBase())
14218 return getDerived().RebuildObjCIvarRefExpr(Base
.get(), E
->getDecl(),
14220 E
->isArrow(), E
->isFreeIvar());
14223 template<typename Derived
>
14225 TreeTransform
<Derived
>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr
*E
) {
14226 // 'super' and types never change. Property never changes. Just
14227 // retain the existing expression.
14228 if (!E
->isObjectReceiver())
14231 // Transform the base expression.
14232 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
14233 if (Base
.isInvalid())
14234 return ExprError();
14236 // We don't need to transform the property; it will never change.
14238 // If nothing changed, just retain the existing expression.
14239 if (!getDerived().AlwaysRebuild() &&
14240 Base
.get() == E
->getBase())
14243 if (E
->isExplicitProperty())
14244 return getDerived().RebuildObjCPropertyRefExpr(Base
.get(),
14245 E
->getExplicitProperty(),
14248 return getDerived().RebuildObjCPropertyRefExpr(Base
.get(),
14249 SemaRef
.Context
.PseudoObjectTy
,
14250 E
->getImplicitPropertyGetter(),
14251 E
->getImplicitPropertySetter(),
14255 template<typename Derived
>
14257 TreeTransform
<Derived
>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr
*E
) {
14258 // Transform the base expression.
14259 ExprResult Base
= getDerived().TransformExpr(E
->getBaseExpr());
14260 if (Base
.isInvalid())
14261 return ExprError();
14263 // Transform the key expression.
14264 ExprResult Key
= getDerived().TransformExpr(E
->getKeyExpr());
14265 if (Key
.isInvalid())
14266 return ExprError();
14268 // If nothing changed, just retain the existing expression.
14269 if (!getDerived().AlwaysRebuild() &&
14270 Key
.get() == E
->getKeyExpr() && Base
.get() == E
->getBaseExpr())
14273 return getDerived().RebuildObjCSubscriptRefExpr(E
->getRBracket(),
14274 Base
.get(), Key
.get(),
14275 E
->getAtIndexMethodDecl(),
14276 E
->setAtIndexMethodDecl());
14279 template<typename Derived
>
14281 TreeTransform
<Derived
>::TransformObjCIsaExpr(ObjCIsaExpr
*E
) {
14282 // Transform the base expression.
14283 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
14284 if (Base
.isInvalid())
14285 return ExprError();
14287 // If nothing changed, just retain the existing expression.
14288 if (!getDerived().AlwaysRebuild() &&
14289 Base
.get() == E
->getBase())
14292 return getDerived().RebuildObjCIsaExpr(Base
.get(), E
->getIsaMemberLoc(),
14297 template<typename Derived
>
14299 TreeTransform
<Derived
>::TransformShuffleVectorExpr(ShuffleVectorExpr
*E
) {
14300 bool ArgumentChanged
= false;
14301 SmallVector
<Expr
*, 8> SubExprs
;
14302 SubExprs
.reserve(E
->getNumSubExprs());
14303 if (getDerived().TransformExprs(E
->getSubExprs(), E
->getNumSubExprs(), false,
14304 SubExprs
, &ArgumentChanged
))
14305 return ExprError();
14307 if (!getDerived().AlwaysRebuild() &&
14311 return getDerived().RebuildShuffleVectorExpr(E
->getBuiltinLoc(),
14313 E
->getRParenLoc());
14316 template<typename Derived
>
14318 TreeTransform
<Derived
>::TransformConvertVectorExpr(ConvertVectorExpr
*E
) {
14319 ExprResult SrcExpr
= getDerived().TransformExpr(E
->getSrcExpr());
14320 if (SrcExpr
.isInvalid())
14321 return ExprError();
14323 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeSourceInfo());
14325 return ExprError();
14327 if (!getDerived().AlwaysRebuild() &&
14328 Type
== E
->getTypeSourceInfo() &&
14329 SrcExpr
.get() == E
->getSrcExpr())
14332 return getDerived().RebuildConvertVectorExpr(E
->getBuiltinLoc(),
14333 SrcExpr
.get(), Type
,
14334 E
->getRParenLoc());
14337 template<typename Derived
>
14339 TreeTransform
<Derived
>::TransformBlockExpr(BlockExpr
*E
) {
14340 BlockDecl
*oldBlock
= E
->getBlockDecl();
14342 SemaRef
.ActOnBlockStart(E
->getCaretLocation(), /*Scope=*/nullptr);
14343 BlockScopeInfo
*blockScope
= SemaRef
.getCurBlock();
14345 blockScope
->TheDecl
->setIsVariadic(oldBlock
->isVariadic());
14346 blockScope
->TheDecl
->setBlockMissingReturnType(
14347 oldBlock
->blockMissingReturnType());
14349 SmallVector
<ParmVarDecl
*, 4> params
;
14350 SmallVector
<QualType
, 4> paramTypes
;
14352 const FunctionProtoType
*exprFunctionType
= E
->getFunctionType();
14354 // Parameter substitution.
14355 Sema::ExtParameterInfoBuilder extParamInfos
;
14356 if (getDerived().TransformFunctionTypeParams(
14357 E
->getCaretLocation(), oldBlock
->parameters(), nullptr,
14358 exprFunctionType
->getExtParameterInfosOrNull(), paramTypes
, ¶ms
,
14360 getSema().ActOnBlockError(E
->getCaretLocation(), /*Scope=*/nullptr);
14361 return ExprError();
14364 QualType exprResultType
=
14365 getDerived().TransformType(exprFunctionType
->getReturnType());
14367 auto epi
= exprFunctionType
->getExtProtoInfo();
14368 epi
.ExtParameterInfos
= extParamInfos
.getPointerOrNull(paramTypes
.size());
14370 QualType functionType
=
14371 getDerived().RebuildFunctionProtoType(exprResultType
, paramTypes
, epi
);
14372 blockScope
->FunctionType
= functionType
;
14374 // Set the parameters on the block decl.
14375 if (!params
.empty())
14376 blockScope
->TheDecl
->setParams(params
);
14378 if (!oldBlock
->blockMissingReturnType()) {
14379 blockScope
->HasImplicitReturnType
= false;
14380 blockScope
->ReturnType
= exprResultType
;
14383 // Transform the body
14384 StmtResult body
= getDerived().TransformStmt(E
->getBody());
14385 if (body
.isInvalid()) {
14386 getSema().ActOnBlockError(E
->getCaretLocation(), /*Scope=*/nullptr);
14387 return ExprError();
14391 // In builds with assertions, make sure that we captured everything we
14392 // captured before.
14393 if (!SemaRef
.getDiagnostics().hasErrorOccurred()) {
14394 for (const auto &I
: oldBlock
->captures()) {
14395 VarDecl
*oldCapture
= I
.getVariable();
14397 // Ignore parameter packs.
14398 if (oldCapture
->isParameterPack())
14401 VarDecl
*newCapture
=
14402 cast
<VarDecl
>(getDerived().TransformDecl(E
->getCaretLocation(),
14404 assert(blockScope
->CaptureMap
.count(newCapture
));
14406 assert(oldBlock
->capturesCXXThis() == blockScope
->isCXXThisCaptured());
14410 return SemaRef
.ActOnBlockStmtExpr(E
->getCaretLocation(), body
.get(),
14411 /*Scope=*/nullptr);
14414 template<typename Derived
>
14416 TreeTransform
<Derived
>::TransformAsTypeExpr(AsTypeExpr
*E
) {
14417 ExprResult SrcExpr
= getDerived().TransformExpr(E
->getSrcExpr());
14418 if (SrcExpr
.isInvalid())
14419 return ExprError();
14421 QualType Type
= getDerived().TransformType(E
->getType());
14423 return SemaRef
.BuildAsTypeExpr(SrcExpr
.get(), Type
, E
->getBuiltinLoc(),
14424 E
->getRParenLoc());
14427 template<typename Derived
>
14429 TreeTransform
<Derived
>::TransformAtomicExpr(AtomicExpr
*E
) {
14430 bool ArgumentChanged
= false;
14431 SmallVector
<Expr
*, 8> SubExprs
;
14432 SubExprs
.reserve(E
->getNumSubExprs());
14433 if (getDerived().TransformExprs(E
->getSubExprs(), E
->getNumSubExprs(), false,
14434 SubExprs
, &ArgumentChanged
))
14435 return ExprError();
14437 if (!getDerived().AlwaysRebuild() &&
14441 return getDerived().RebuildAtomicExpr(E
->getBuiltinLoc(), SubExprs
,
14442 E
->getOp(), E
->getRParenLoc());
14445 //===----------------------------------------------------------------------===//
14446 // Type reconstruction
14447 //===----------------------------------------------------------------------===//
14449 template<typename Derived
>
14450 QualType TreeTransform
<Derived
>::RebuildPointerType(QualType PointeeType
,
14451 SourceLocation Star
) {
14452 return SemaRef
.BuildPointerType(PointeeType
, Star
,
14453 getDerived().getBaseEntity());
14456 template<typename Derived
>
14457 QualType TreeTransform
<Derived
>::RebuildBlockPointerType(QualType PointeeType
,
14458 SourceLocation Star
) {
14459 return SemaRef
.BuildBlockPointerType(PointeeType
, Star
,
14460 getDerived().getBaseEntity());
14463 template<typename Derived
>
14465 TreeTransform
<Derived
>::RebuildReferenceType(QualType ReferentType
,
14466 bool WrittenAsLValue
,
14467 SourceLocation Sigil
) {
14468 return SemaRef
.BuildReferenceType(ReferentType
, WrittenAsLValue
,
14469 Sigil
, getDerived().getBaseEntity());
14472 template<typename Derived
>
14474 TreeTransform
<Derived
>::RebuildMemberPointerType(QualType PointeeType
,
14475 QualType ClassType
,
14476 SourceLocation Sigil
) {
14477 return SemaRef
.BuildMemberPointerType(PointeeType
, ClassType
, Sigil
,
14478 getDerived().getBaseEntity());
14481 template<typename Derived
>
14482 QualType TreeTransform
<Derived
>::RebuildObjCTypeParamType(
14483 const ObjCTypeParamDecl
*Decl
,
14484 SourceLocation ProtocolLAngleLoc
,
14485 ArrayRef
<ObjCProtocolDecl
*> Protocols
,
14486 ArrayRef
<SourceLocation
> ProtocolLocs
,
14487 SourceLocation ProtocolRAngleLoc
) {
14488 return SemaRef
.BuildObjCTypeParamType(Decl
,
14489 ProtocolLAngleLoc
, Protocols
,
14490 ProtocolLocs
, ProtocolRAngleLoc
,
14491 /*FailOnError=*/true);
14494 template<typename Derived
>
14495 QualType TreeTransform
<Derived
>::RebuildObjCObjectType(
14497 SourceLocation Loc
,
14498 SourceLocation TypeArgsLAngleLoc
,
14499 ArrayRef
<TypeSourceInfo
*> TypeArgs
,
14500 SourceLocation TypeArgsRAngleLoc
,
14501 SourceLocation ProtocolLAngleLoc
,
14502 ArrayRef
<ObjCProtocolDecl
*> Protocols
,
14503 ArrayRef
<SourceLocation
> ProtocolLocs
,
14504 SourceLocation ProtocolRAngleLoc
) {
14505 return SemaRef
.BuildObjCObjectType(BaseType
, Loc
, TypeArgsLAngleLoc
,
14506 TypeArgs
, TypeArgsRAngleLoc
,
14507 ProtocolLAngleLoc
, Protocols
, ProtocolLocs
,
14509 /*FailOnError=*/true);
14512 template<typename Derived
>
14513 QualType TreeTransform
<Derived
>::RebuildObjCObjectPointerType(
14514 QualType PointeeType
,
14515 SourceLocation Star
) {
14516 return SemaRef
.Context
.getObjCObjectPointerType(PointeeType
);
14519 template<typename Derived
>
14521 TreeTransform
<Derived
>::RebuildArrayType(QualType ElementType
,
14522 ArrayType::ArraySizeModifier SizeMod
,
14523 const llvm::APInt
*Size
,
14525 unsigned IndexTypeQuals
,
14526 SourceRange BracketsRange
) {
14527 if (SizeExpr
|| !Size
)
14528 return SemaRef
.BuildArrayType(ElementType
, SizeMod
, SizeExpr
,
14529 IndexTypeQuals
, BracketsRange
,
14530 getDerived().getBaseEntity());
14532 QualType Types
[] = {
14533 SemaRef
.Context
.UnsignedCharTy
, SemaRef
.Context
.UnsignedShortTy
,
14534 SemaRef
.Context
.UnsignedIntTy
, SemaRef
.Context
.UnsignedLongTy
,
14535 SemaRef
.Context
.UnsignedLongLongTy
, SemaRef
.Context
.UnsignedInt128Ty
14538 for (const auto &T
: Types
)
14539 if (Size
->getBitWidth() == SemaRef
.Context
.getIntWidth(T
)) {
14544 // Note that we can return a VariableArrayType here in the case where
14545 // the element type was a dependent VariableArrayType.
14546 IntegerLiteral
*ArraySize
14547 = IntegerLiteral::Create(SemaRef
.Context
, *Size
, SizeType
,
14548 /*FIXME*/BracketsRange
.getBegin());
14549 return SemaRef
.BuildArrayType(ElementType
, SizeMod
, ArraySize
,
14550 IndexTypeQuals
, BracketsRange
,
14551 getDerived().getBaseEntity());
14554 template<typename Derived
>
14556 TreeTransform
<Derived
>::RebuildConstantArrayType(QualType ElementType
,
14557 ArrayType::ArraySizeModifier SizeMod
,
14558 const llvm::APInt
&Size
,
14560 unsigned IndexTypeQuals
,
14561 SourceRange BracketsRange
) {
14562 return getDerived().RebuildArrayType(ElementType
, SizeMod
, &Size
, SizeExpr
,
14563 IndexTypeQuals
, BracketsRange
);
14566 template<typename Derived
>
14568 TreeTransform
<Derived
>::RebuildIncompleteArrayType(QualType ElementType
,
14569 ArrayType::ArraySizeModifier SizeMod
,
14570 unsigned IndexTypeQuals
,
14571 SourceRange BracketsRange
) {
14572 return getDerived().RebuildArrayType(ElementType
, SizeMod
, nullptr, nullptr,
14573 IndexTypeQuals
, BracketsRange
);
14576 template<typename Derived
>
14578 TreeTransform
<Derived
>::RebuildVariableArrayType(QualType ElementType
,
14579 ArrayType::ArraySizeModifier SizeMod
,
14581 unsigned IndexTypeQuals
,
14582 SourceRange BracketsRange
) {
14583 return getDerived().RebuildArrayType(ElementType
, SizeMod
, nullptr,
14585 IndexTypeQuals
, BracketsRange
);
14588 template<typename Derived
>
14590 TreeTransform
<Derived
>::RebuildDependentSizedArrayType(QualType ElementType
,
14591 ArrayType::ArraySizeModifier SizeMod
,
14593 unsigned IndexTypeQuals
,
14594 SourceRange BracketsRange
) {
14595 return getDerived().RebuildArrayType(ElementType
, SizeMod
, nullptr,
14597 IndexTypeQuals
, BracketsRange
);
14600 template <typename Derived
>
14601 QualType TreeTransform
<Derived
>::RebuildDependentAddressSpaceType(
14602 QualType PointeeType
, Expr
*AddrSpaceExpr
, SourceLocation AttributeLoc
) {
14603 return SemaRef
.BuildAddressSpaceAttr(PointeeType
, AddrSpaceExpr
,
14607 template <typename Derived
>
14609 TreeTransform
<Derived
>::RebuildVectorType(QualType ElementType
,
14610 unsigned NumElements
,
14611 VectorType::VectorKind VecKind
) {
14612 // FIXME: semantic checking!
14613 return SemaRef
.Context
.getVectorType(ElementType
, NumElements
, VecKind
);
14616 template <typename Derived
>
14617 QualType TreeTransform
<Derived
>::RebuildDependentVectorType(
14618 QualType ElementType
, Expr
*SizeExpr
, SourceLocation AttributeLoc
,
14619 VectorType::VectorKind VecKind
) {
14620 return SemaRef
.BuildVectorType(ElementType
, SizeExpr
, AttributeLoc
);
14623 template<typename Derived
>
14624 QualType TreeTransform
<Derived
>::RebuildExtVectorType(QualType ElementType
,
14625 unsigned NumElements
,
14626 SourceLocation AttributeLoc
) {
14627 llvm::APInt
numElements(SemaRef
.Context
.getIntWidth(SemaRef
.Context
.IntTy
),
14628 NumElements
, true);
14629 IntegerLiteral
*VectorSize
14630 = IntegerLiteral::Create(SemaRef
.Context
, numElements
, SemaRef
.Context
.IntTy
,
14632 return SemaRef
.BuildExtVectorType(ElementType
, VectorSize
, AttributeLoc
);
14635 template<typename Derived
>
14637 TreeTransform
<Derived
>::RebuildDependentSizedExtVectorType(QualType ElementType
,
14639 SourceLocation AttributeLoc
) {
14640 return SemaRef
.BuildExtVectorType(ElementType
, SizeExpr
, AttributeLoc
);
14643 template <typename Derived
>
14644 QualType TreeTransform
<Derived
>::RebuildConstantMatrixType(
14645 QualType ElementType
, unsigned NumRows
, unsigned NumColumns
) {
14646 return SemaRef
.Context
.getConstantMatrixType(ElementType
, NumRows
,
14650 template <typename Derived
>
14651 QualType TreeTransform
<Derived
>::RebuildDependentSizedMatrixType(
14652 QualType ElementType
, Expr
*RowExpr
, Expr
*ColumnExpr
,
14653 SourceLocation AttributeLoc
) {
14654 return SemaRef
.BuildMatrixType(ElementType
, RowExpr
, ColumnExpr
,
14658 template<typename Derived
>
14659 QualType TreeTransform
<Derived
>::RebuildFunctionProtoType(
14661 MutableArrayRef
<QualType
> ParamTypes
,
14662 const FunctionProtoType::ExtProtoInfo
&EPI
) {
14663 return SemaRef
.BuildFunctionType(T
, ParamTypes
,
14664 getDerived().getBaseLocation(),
14665 getDerived().getBaseEntity(),
14669 template<typename Derived
>
14670 QualType TreeTransform
<Derived
>::RebuildFunctionNoProtoType(QualType T
) {
14671 return SemaRef
.Context
.getFunctionNoProtoType(T
);
14674 template<typename Derived
>
14675 QualType TreeTransform
<Derived
>::RebuildUnresolvedUsingType(SourceLocation Loc
,
14677 assert(D
&& "no decl found");
14678 if (D
->isInvalidDecl()) return QualType();
14680 // FIXME: Doesn't account for ObjCInterfaceDecl!
14681 if (auto *UPD
= dyn_cast
<UsingPackDecl
>(D
)) {
14682 // A valid resolved using typename pack expansion decl can have multiple
14683 // UsingDecls, but they must each have exactly one type, and it must be
14684 // the same type in every case. But we must have at least one expansion!
14685 if (UPD
->expansions().empty()) {
14686 getSema().Diag(Loc
, diag::err_using_pack_expansion_empty
)
14687 << UPD
->isCXXClassMember() << UPD
;
14691 // We might still have some unresolved types. Try to pick a resolved type
14692 // if we can. The final instantiation will check that the remaining
14693 // unresolved types instantiate to the type we pick.
14694 QualType FallbackT
;
14696 for (auto *E
: UPD
->expansions()) {
14697 QualType ThisT
= RebuildUnresolvedUsingType(Loc
, E
);
14698 if (ThisT
.isNull())
14700 else if (ThisT
->getAs
<UnresolvedUsingType
>())
14702 else if (T
.isNull())
14705 assert(getSema().Context
.hasSameType(ThisT
, T
) &&
14706 "mismatched resolved types in using pack expansion");
14708 return T
.isNull() ? FallbackT
: T
;
14709 } else if (auto *Using
= dyn_cast
<UsingDecl
>(D
)) {
14710 assert(Using
->hasTypename() &&
14711 "UnresolvedUsingTypenameDecl transformed to non-typename using");
14713 // A valid resolved using typename decl points to exactly one type decl.
14714 assert(++Using
->shadow_begin() == Using
->shadow_end());
14716 UsingShadowDecl
*Shadow
= *Using
->shadow_begin();
14717 if (SemaRef
.DiagnoseUseOfDecl(Shadow
->getTargetDecl(), Loc
))
14719 return SemaRef
.Context
.getUsingType(
14720 Shadow
, SemaRef
.Context
.getTypeDeclType(
14721 cast
<TypeDecl
>(Shadow
->getTargetDecl())));
14723 assert(isa
<UnresolvedUsingTypenameDecl
>(D
) &&
14724 "UnresolvedUsingTypenameDecl transformed to non-using decl");
14725 return SemaRef
.Context
.getTypeDeclType(
14726 cast
<UnresolvedUsingTypenameDecl
>(D
));
14730 template <typename Derived
>
14731 QualType TreeTransform
<Derived
>::RebuildTypeOfExprType(Expr
*E
,
14733 return SemaRef
.BuildTypeofExprType(E
);
14736 template<typename Derived
>
14737 QualType TreeTransform
<Derived
>::RebuildTypeOfType(QualType Underlying
) {
14738 return SemaRef
.Context
.getTypeOfType(Underlying
);
14741 template <typename Derived
>
14742 QualType TreeTransform
<Derived
>::RebuildDecltypeType(Expr
*E
, SourceLocation
) {
14743 return SemaRef
.BuildDecltypeType(E
);
14746 template<typename Derived
>
14747 QualType TreeTransform
<Derived
>::RebuildUnaryTransformType(QualType BaseType
,
14748 UnaryTransformType::UTTKind UKind
,
14749 SourceLocation Loc
) {
14750 return SemaRef
.BuildUnaryTransformType(BaseType
, UKind
, Loc
);
14753 template<typename Derived
>
14754 QualType TreeTransform
<Derived
>::RebuildTemplateSpecializationType(
14755 TemplateName Template
,
14756 SourceLocation TemplateNameLoc
,
14757 TemplateArgumentListInfo
&TemplateArgs
) {
14758 return SemaRef
.CheckTemplateIdType(Template
, TemplateNameLoc
, TemplateArgs
);
14761 template<typename Derived
>
14762 QualType TreeTransform
<Derived
>::RebuildAtomicType(QualType ValueType
,
14763 SourceLocation KWLoc
) {
14764 return SemaRef
.BuildAtomicType(ValueType
, KWLoc
);
14767 template<typename Derived
>
14768 QualType TreeTransform
<Derived
>::RebuildPipeType(QualType ValueType
,
14769 SourceLocation KWLoc
,
14771 return isReadPipe
? SemaRef
.BuildReadPipeType(ValueType
, KWLoc
)
14772 : SemaRef
.BuildWritePipeType(ValueType
, KWLoc
);
14775 template <typename Derived
>
14776 QualType TreeTransform
<Derived
>::RebuildBitIntType(bool IsUnsigned
,
14778 SourceLocation Loc
) {
14779 llvm::APInt
NumBitsAP(SemaRef
.Context
.getIntWidth(SemaRef
.Context
.IntTy
),
14781 IntegerLiteral
*Bits
= IntegerLiteral::Create(SemaRef
.Context
, NumBitsAP
,
14782 SemaRef
.Context
.IntTy
, Loc
);
14783 return SemaRef
.BuildBitIntType(IsUnsigned
, Bits
, Loc
);
14786 template <typename Derived
>
14787 QualType TreeTransform
<Derived
>::RebuildDependentBitIntType(
14788 bool IsUnsigned
, Expr
*NumBitsExpr
, SourceLocation Loc
) {
14789 return SemaRef
.BuildBitIntType(IsUnsigned
, NumBitsExpr
, Loc
);
14792 template<typename Derived
>
14794 TreeTransform
<Derived
>::RebuildTemplateName(CXXScopeSpec
&SS
,
14796 TemplateDecl
*Template
) {
14797 return SemaRef
.Context
.getQualifiedTemplateName(SS
.getScopeRep(), TemplateKW
,
14798 TemplateName(Template
));
14801 template<typename Derived
>
14803 TreeTransform
<Derived
>::RebuildTemplateName(CXXScopeSpec
&SS
,
14804 SourceLocation TemplateKWLoc
,
14805 const IdentifierInfo
&Name
,
14806 SourceLocation NameLoc
,
14807 QualType ObjectType
,
14808 NamedDecl
*FirstQualifierInScope
,
14809 bool AllowInjectedClassName
) {
14810 UnqualifiedId TemplateName
;
14811 TemplateName
.setIdentifier(&Name
, NameLoc
);
14812 Sema::TemplateTy Template
;
14813 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS
, TemplateKWLoc
,
14814 TemplateName
, ParsedType::make(ObjectType
),
14815 /*EnteringContext=*/false, Template
,
14816 AllowInjectedClassName
);
14817 return Template
.get();
14820 template<typename Derived
>
14822 TreeTransform
<Derived
>::RebuildTemplateName(CXXScopeSpec
&SS
,
14823 SourceLocation TemplateKWLoc
,
14824 OverloadedOperatorKind Operator
,
14825 SourceLocation NameLoc
,
14826 QualType ObjectType
,
14827 bool AllowInjectedClassName
) {
14828 UnqualifiedId Name
;
14829 // FIXME: Bogus location information.
14830 SourceLocation SymbolLocations
[3] = { NameLoc
, NameLoc
, NameLoc
};
14831 Name
.setOperatorFunctionId(NameLoc
, Operator
, SymbolLocations
);
14832 Sema::TemplateTy Template
;
14833 getSema().ActOnTemplateName(
14834 /*Scope=*/nullptr, SS
, TemplateKWLoc
, Name
, ParsedType::make(ObjectType
),
14835 /*EnteringContext=*/false, Template
, AllowInjectedClassName
);
14836 return Template
.get();
14839 template<typename Derived
>
14841 TreeTransform
<Derived
>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op
,
14842 SourceLocation OpLoc
,
14846 Expr
*Callee
= OrigCallee
->IgnoreParenCasts();
14847 bool isPostIncDec
= Second
&& (Op
== OO_PlusPlus
|| Op
== OO_MinusMinus
);
14849 if (First
->getObjectKind() == OK_ObjCProperty
) {
14850 BinaryOperatorKind Opc
= BinaryOperator::getOverloadedOpcode(Op
);
14851 if (BinaryOperator::isAssignmentOp(Opc
))
14852 return SemaRef
.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc
, Opc
,
14854 ExprResult Result
= SemaRef
.CheckPlaceholderExpr(First
);
14855 if (Result
.isInvalid())
14856 return ExprError();
14857 First
= Result
.get();
14860 if (Second
&& Second
->getObjectKind() == OK_ObjCProperty
) {
14861 ExprResult Result
= SemaRef
.CheckPlaceholderExpr(Second
);
14862 if (Result
.isInvalid())
14863 return ExprError();
14864 Second
= Result
.get();
14867 // Determine whether this should be a builtin operation.
14868 if (Op
== OO_Subscript
) {
14869 if (!First
->getType()->isOverloadableType() &&
14870 !Second
->getType()->isOverloadableType())
14871 return getSema().CreateBuiltinArraySubscriptExpr(
14872 First
, Callee
->getBeginLoc(), Second
, OpLoc
);
14873 } else if (Op
== OO_Arrow
) {
14874 // It is possible that the type refers to a RecoveryExpr created earlier
14875 // in the tree transformation.
14876 if (First
->getType()->isDependentType())
14877 return ExprError();
14878 // -> is never a builtin operation.
14879 return SemaRef
.BuildOverloadedArrowExpr(nullptr, First
, OpLoc
);
14880 } else if (Second
== nullptr || isPostIncDec
) {
14881 if (!First
->getType()->isOverloadableType() ||
14882 (Op
== OO_Amp
&& getSema().isQualifiedMemberAccess(First
))) {
14883 // The argument is not of overloadable type, or this is an expression
14884 // of the form &Class::member, so try to create a built-in unary
14886 UnaryOperatorKind Opc
14887 = UnaryOperator::getOverloadedOpcode(Op
, isPostIncDec
);
14889 return getSema().CreateBuiltinUnaryOp(OpLoc
, Opc
, First
);
14892 if (!First
->getType()->isOverloadableType() &&
14893 !Second
->getType()->isOverloadableType()) {
14894 // Neither of the arguments is an overloadable type, so try to
14895 // create a built-in binary operation.
14896 BinaryOperatorKind Opc
= BinaryOperator::getOverloadedOpcode(Op
);
14898 = SemaRef
.CreateBuiltinBinOp(OpLoc
, Opc
, First
, Second
);
14899 if (Result
.isInvalid())
14900 return ExprError();
14906 // Compute the transformed set of functions (and function templates) to be
14907 // used during overload resolution.
14908 UnresolvedSet
<16> Functions
;
14911 if (UnresolvedLookupExpr
*ULE
= dyn_cast
<UnresolvedLookupExpr
>(Callee
)) {
14912 Functions
.append(ULE
->decls_begin(), ULE
->decls_end());
14913 // If the overload could not be resolved in the template definition
14914 // (because we had a dependent argument), ADL is performed as part of
14915 // template instantiation.
14916 RequiresADL
= ULE
->requiresADL();
14918 // If we've resolved this to a particular non-member function, just call
14919 // that function. If we resolved it to a member function,
14920 // CreateOverloaded* will find that function for us.
14921 NamedDecl
*ND
= cast
<DeclRefExpr
>(Callee
)->getDecl();
14922 if (!isa
<CXXMethodDecl
>(ND
))
14923 Functions
.addDecl(ND
);
14924 RequiresADL
= false;
14927 // Add any functions found via argument-dependent lookup.
14928 Expr
*Args
[2] = { First
, Second
};
14929 unsigned NumArgs
= 1 + (Second
!= nullptr);
14931 // Create the overloaded operator invocation for unary operators.
14932 if (NumArgs
== 1 || isPostIncDec
) {
14933 UnaryOperatorKind Opc
14934 = UnaryOperator::getOverloadedOpcode(Op
, isPostIncDec
);
14935 return SemaRef
.CreateOverloadedUnaryOp(OpLoc
, Opc
, Functions
, First
,
14939 if (Op
== OO_Subscript
) {
14940 SourceLocation LBrace
;
14941 SourceLocation RBrace
;
14943 if (DeclRefExpr
*DRE
= dyn_cast
<DeclRefExpr
>(Callee
)) {
14944 DeclarationNameLoc NameLoc
= DRE
->getNameInfo().getInfo();
14945 LBrace
= NameLoc
.getCXXOperatorNameBeginLoc();
14946 RBrace
= NameLoc
.getCXXOperatorNameEndLoc();
14948 LBrace
= Callee
->getBeginLoc();
14952 return SemaRef
.CreateOverloadedArraySubscriptExpr(LBrace
, RBrace
,
14956 // Create the overloaded operator invocation for binary operators.
14957 BinaryOperatorKind Opc
= BinaryOperator::getOverloadedOpcode(Op
);
14958 ExprResult Result
= SemaRef
.CreateOverloadedBinOp(
14959 OpLoc
, Opc
, Functions
, Args
[0], Args
[1], RequiresADL
);
14960 if (Result
.isInvalid())
14961 return ExprError();
14966 template<typename Derived
>
14968 TreeTransform
<Derived
>::RebuildCXXPseudoDestructorExpr(Expr
*Base
,
14969 SourceLocation OperatorLoc
,
14972 TypeSourceInfo
*ScopeType
,
14973 SourceLocation CCLoc
,
14974 SourceLocation TildeLoc
,
14975 PseudoDestructorTypeStorage Destroyed
) {
14976 QualType BaseType
= Base
->getType();
14977 if (Base
->isTypeDependent() || Destroyed
.getIdentifier() ||
14978 (!isArrow
&& !BaseType
->getAs
<RecordType
>()) ||
14979 (isArrow
&& BaseType
->getAs
<PointerType
>() &&
14980 !BaseType
->castAs
<PointerType
>()->getPointeeType()
14981 ->template getAs
<RecordType
>())){
14982 // This pseudo-destructor expression is still a pseudo-destructor.
14983 return SemaRef
.BuildPseudoDestructorExpr(
14984 Base
, OperatorLoc
, isArrow
? tok::arrow
: tok::period
, SS
, ScopeType
,
14985 CCLoc
, TildeLoc
, Destroyed
);
14988 TypeSourceInfo
*DestroyedType
= Destroyed
.getTypeSourceInfo();
14989 DeclarationName
Name(SemaRef
.Context
.DeclarationNames
.getCXXDestructorName(
14990 SemaRef
.Context
.getCanonicalType(DestroyedType
->getType())));
14991 DeclarationNameInfo
NameInfo(Name
, Destroyed
.getLocation());
14992 NameInfo
.setNamedTypeInfo(DestroyedType
);
14994 // The scope type is now known to be a valid nested name specifier
14995 // component. Tack it on to the end of the nested name specifier.
14997 if (!ScopeType
->getType()->getAs
<TagType
>()) {
14998 getSema().Diag(ScopeType
->getTypeLoc().getBeginLoc(),
14999 diag::err_expected_class_or_namespace
)
15000 << ScopeType
->getType() << getSema().getLangOpts().CPlusPlus
;
15001 return ExprError();
15003 SS
.Extend(SemaRef
.Context
, SourceLocation(), ScopeType
->getTypeLoc(),
15007 SourceLocation TemplateKWLoc
; // FIXME: retrieve it from caller.
15008 return getSema().BuildMemberReferenceExpr(Base
, BaseType
,
15009 OperatorLoc
, isArrow
,
15011 /*FIXME: FirstQualifier*/ nullptr,
15013 /*TemplateArgs*/ nullptr,
15017 template<typename Derived
>
15019 TreeTransform
<Derived
>::TransformCapturedStmt(CapturedStmt
*S
) {
15020 SourceLocation Loc
= S
->getBeginLoc();
15021 CapturedDecl
*CD
= S
->getCapturedDecl();
15022 unsigned NumParams
= CD
->getNumParams();
15023 unsigned ContextParamPos
= CD
->getContextParamPosition();
15024 SmallVector
<Sema::CapturedParamNameType
, 4> Params
;
15025 for (unsigned I
= 0; I
< NumParams
; ++I
) {
15026 if (I
!= ContextParamPos
) {
15029 CD
->getParam(I
)->getName(),
15030 getDerived().TransformType(CD
->getParam(I
)->getType())));
15032 Params
.push_back(std::make_pair(StringRef(), QualType()));
15035 getSema().ActOnCapturedRegionStart(Loc
, /*CurScope*/nullptr,
15036 S
->getCapturedRegionKind(), Params
);
15039 Sema::CompoundScopeRAII
CompoundScope(getSema());
15040 Body
= getDerived().TransformStmt(S
->getCapturedStmt());
15043 if (Body
.isInvalid()) {
15044 getSema().ActOnCapturedRegionError();
15045 return StmtError();
15048 return getSema().ActOnCapturedRegionEnd(Body
.get());
15051 } // end namespace clang
15053 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H