[docs] Fix build-docs.sh
[llvm-project.git] / clang / lib / Sema / TreeTransform.h
blob9fde9ce8582d14d419efd557b6d0bfc8a0a09f7f
1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2 //
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 //===----------------------------------------------------------------------===//
7 //
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"
42 #include <algorithm>
44 using namespace llvm::omp;
46 namespace clang {
47 using namespace sema;
49 /// A semantic tree transformation that allows one to transform one
50 /// abstract syntax tree into another.
51 ///
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.
60 ///
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.
66 ///
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
75 /// a new AST node.
76 ///
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.
82 ///
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.
93 ///
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
104 /// pack.
105 class ForgetPartiallySubstitutedPackRAII {
106 Derived &Self;
107 TemplateArgument Old;
109 public:
110 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
111 Old = Self.ForgetPartiallySubstitutedPack();
114 ~ForgetPartiallySubstitutedPackRAII() {
115 Self.RememberPartiallySubstitutedPack(Old);
119 protected:
120 Sema &SemaRef;
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;
127 public:
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
166 /// started.
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
174 /// information.
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 {
194 TreeTransform &Self;
195 SourceLocation OldLocation;
196 DeclarationName OldEntity;
198 public:
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);
208 ~TemporaryBase() {
209 Self.getDerived().setBase(OldLocation, OldEntity);
213 /// Determine whether the given type \p T has already been
214 /// transformed.
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) {
221 return T.isNull();
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) {
229 return 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
250 /// pack expansion.
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
256 /// pattern.
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)
278 /// must be set.
279 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
280 SourceRange PatternRange,
281 ArrayRef<UnexpandedParameterPack> Unexpanded,
282 bool &ShouldExpand,
283 bool &RetainExpansion,
284 Optional<unsigned> &NumExpansions) {
285 ShouldExpand = false;
286 return false;
289 /// "Forget" about the partially-substituted pack template argument,
290 /// when performing an instantiation that must preserve the parameter pack
291 /// use.
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
300 /// use.
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
306 /// being expanded.
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
332 /// as necessary.
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.
342 /// @{
343 QualType TransformTypeWithDeducedTST(QualType T);
344 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
345 /// @}
347 /// The reason why the value of a statement is not discarded, if any.
348 enum StmtDiscardKind {
349 SDK_Discarded,
350 SDK_NotDiscarded,
351 SDK_StmtExprResult,
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
360 /// other mechanism.
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.
391 #define ATTR(X)
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
401 /// other mechanism.
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
429 /// be.
431 /// \param Outputs The transformed input expressions will be added to this
432 /// vector.
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
443 /// or expression.
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;
454 return D;
457 /// Transform the specified condition.
459 /// By default, this transforms the variable and expression and rebuilds
460 /// the condition.
461 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
462 Expr *Expr,
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
473 /// transformer.
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,
508 LookupResult &R);
510 /// Transform the given nested-name-specifier with source-location
511 /// information.
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.
527 DeclarationNameInfo
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.
559 TemplateName
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
593 /// routine.
595 /// Returns true if an error occurred.
596 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
597 unsigned NumInputs,
598 TemplateArgumentListInfo &Outputs,
599 bool Uneval = false) {
600 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
601 Uneval);
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
615 /// routine.
617 /// Returns true if an error occurred.
618 template<typename InputIterator>
619 bool TransformTemplateArguments(InputIterator First,
620 InputIterator Last,
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,
649 bool &Changed);
651 StmtResult TransformSEHHandler(Stmt *Handler);
653 QualType
654 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
655 TemplateSpecializationTypeLoc TL,
656 TemplateName Template);
658 QualType
659 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
660 DependentTemplateSpecializationTypeLoc TL,
661 TemplateName Template,
662 CXXScopeSpec &SS);
664 QualType TransformDependentTemplateSpecializationType(
665 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
666 NestedNameSpecifierLoc QualifierLoc);
668 /// Transforms the parameters of a function type into the
669 /// given vectors.
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
683 /// on error.
685 /// \param indexAdjustment - A number to add to the parameter's
686 /// scope index; can be negative
687 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
688 int indexAdjustment,
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
695 /// the body.
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) {
705 return 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
745 /// behavior.
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,
769 bool LValue,
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,
791 SourceLocation Loc,
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
803 /// analysis.
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
809 /// qualifiers.
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,
817 Expr *SizeExpr,
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,
829 Expr *SizeExpr,
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,
850 Expr *SizeExpr,
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,
861 Expr *SizeExpr,
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,
896 Expr *SizeExpr,
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
904 /// dimensions.
905 QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr,
906 Expr *ColumnExpr,
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
916 /// behavior.
917 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
918 Expr *AddrSpaceExpr,
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,
976 SourceLocation Loc);
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,
996 TypeConstraintArgs);
999 /// By default, builds a new DeducedTemplateSpecializationType with the given
1000 /// deduced type.
1001 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
1002 QualType Deduced) {
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,
1032 QualType Named) {
1033 return SemaRef.Context.getElaboratedType(Keyword,
1034 QualifierLoc.getNestedNameSpecifier(),
1035 Named);
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
1053 CXXScopeSpec SS;
1054 SS.Adopt(QualifierLoc);
1055 TemplateName InstName = getDerived().RebuildTemplateName(
1056 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1057 AllowInjectedClassName);
1059 if (InstName.isNull())
1060 return QualType();
1062 // If it's still dependent, make a dependent specialization.
1063 if (InstName.getAsDependentTemplateName())
1064 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1065 QualifierLoc.getNestedNameSpecifier(),
1066 Name,
1067 Args);
1069 // Otherwise, make an elaborated type wrapping a non-dependent
1070 // specialization.
1071 QualType T =
1072 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1073 if (T.isNull())
1074 return QualType();
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) {
1090 CXXScopeSpec SS;
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(),
1098 Id);
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
1110 // referring to.
1111 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1112 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1113 if (!DC)
1114 return QualType();
1116 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1117 return QualType();
1119 TagDecl *Tag = nullptr;
1120 SemaRef.LookupQualifiedName(Result, DC);
1121 switch (Result.getResultKind()) {
1122 case LookupResult::NotFound:
1123 case LookupResult::NotFoundInCurrentInstantiation:
1124 break;
1126 case LookupResult::Found:
1127 Tag = Result.getAsSingle<TagDecl>();
1128 break;
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.
1136 return QualType();
1139 if (!Tag) {
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
1151 << NTK << Kind;
1152 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1153 break;
1155 default:
1156 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1157 << Kind << Id << DC << QualifierLoc.getSourceRange();
1158 break;
1160 return QualType();
1163 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1164 IdLoc, Id)) {
1165 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1166 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1167 return QualType();
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,
1186 NumExpansions);
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,
1197 bool isReadPipe);
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,
1214 bool TemplateKW,
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
1223 /// behavior.
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
1237 /// behavior.
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
1245 /// and the
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
1250 /// behavior.
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,
1263 bool IsStmtExpr) {
1264 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1265 IsStmtExpr);
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,
1273 Expr *LHS,
1274 SourceLocation EllipsisLoc,
1275 Expr *RHS,
1276 SourceLocation ColonLoc) {
1277 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1278 ColonLoc);
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);
1287 return S;
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,
1296 Stmt *SubStmt) {
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,
1316 Stmt *SubStmt) {
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,
1341 RParenLoc);
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,
1371 Cond, RParenLoc);
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,
1381 Stmt *Body) {
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,
1391 LabelDecl *Label) {
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,
1401 Expr *Target) {
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,
1432 unsigned NumLabels,
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,
1461 bool IsImplicit) {
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,
1471 bool IsImplicit) {
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().
1480 if (IsImplicit) {
1481 ExprResult Suspend = getSema().BuildOperatorCoawaitCall(
1482 CoawaitLoc, Operand, OpCoawaitLookup);
1483 if (Suspend.isInvalid())
1484 return ExprError();
1485 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1486 Suspend.get(), true);
1489 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1490 OpCoawaitLookup);
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,
1498 Expr *Result,
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,
1520 Stmt *TryBody,
1521 MultiStmtArg CatchStmts,
1522 Stmt *Finally) {
1523 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1524 Finally);
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,
1545 VarDecl *Var,
1546 Stmt *Body) {
1547 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1548 Var, Body);
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,
1556 Stmt *Body) {
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,
1565 Expr *Operand) {
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,
1603 EndLoc);
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,
1614 EndLoc);
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,
1626 LParenLoc, EndLoc);
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,
1667 EndLoc);
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,
1688 EndLoc);
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,
1727 CommaLoc, EndLoc);
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,
1749 EndLoc);
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,
1761 EndLoc);
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,
1788 EndLoc);
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.
1826 OMPClause *
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,
1851 EndLoc);
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,
1876 EndLoc);
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,
1888 EndLoc);
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,
1900 EndLoc);
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,
1911 EndLoc);
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,
1978 EndLoc);
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,
1990 LParenLoc, EndLoc);
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,
2001 EndLoc);
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,
2012 EndLoc);
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,
2023 EndLoc);
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.
2050 OMPClause *
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.
2063 OMPClause *
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.
2079 OMPClause *
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,
2151 EndLoc);
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,
2163 EndLoc);
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,
2175 EndLoc);
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,
2186 Data);
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,
2212 LParenLoc, EndLoc);
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,
2236 VarLoc, EndLoc);
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,
2248 VarLoc, EndLoc);
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,
2260 EndLoc);
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,
2271 EndLoc);
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,
2282 EndLoc);
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,
2295 EndLoc);
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,
2313 Expr *object) {
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,
2331 Stmt *Body) {
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,
2340 Stmt *Element,
2341 Expr *Collection,
2342 SourceLocation RParenLoc,
2343 Stmt *Body) {
2344 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
2345 Element,
2346 Collection,
2347 RParenLoc);
2348 if (ForEachStmt.isInvalid())
2349 return StmtError();
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);
2365 if (Var)
2366 getSema().CurContext->addDecl(Var);
2367 return 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,
2376 Stmt *Handler) {
2377 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2378 Handler));
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())
2406 return StmtError();
2408 Expr *RangeExpr = RangeVar->getInit();
2409 if (!RangeExpr->isTypeDependent() &&
2410 RangeExpr->getType()->isObjCObjectPointerType()) {
2411 // FIXME: Support init-statements in Objective-C++20 ranged for
2412 // statement.
2413 if (Init) {
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,
2435 bool IsIfExists,
2436 NestedNameSpecifierLoc QualifierLoc,
2437 DeclarationNameInfo NameInfo,
2438 Stmt *Nested) {
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,
2457 Stmt *Block) {
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,
2486 LookupResult &R,
2487 bool RequiresADL) {
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,
2497 ValueDecl *VD,
2498 const DeclarationNameInfo &NameInfo,
2499 NamedDecl *Found,
2500 TemplateArgumentListInfo *TemplateArgs) {
2501 CXXScopeSpec SS;
2502 SS.Adopt(QualifierLoc);
2503 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2504 TemplateArgs);
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,
2522 bool isArrow,
2523 CXXScopeSpec &SS,
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,
2535 Expr *SubExpr) {
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,
2548 RParenLoc);
2551 /// Build a new sizeof, alignof or vec_step expression with a
2552 /// type argument.
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,
2559 SourceRange R) {
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,
2570 SourceRange R) {
2571 ExprResult Result
2572 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2573 if (Result.isInvalid())
2574 return ExprError();
2576 return Result;
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,
2585 Expr *RHS,
2586 SourceLocation RBracketLoc) {
2587 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2588 LBracketLoc, RHS,
2589 RBracketLoc);
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,
2597 Expr *ColumnIdx,
2598 SourceLocation RBracketLoc) {
2599 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2600 RBracketLoc);
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,
2608 Expr *LowerBound,
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,
2627 BracketsRanges);
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,
2638 LLoc, RLoc, Data);
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,
2646 MultiExprArg Args,
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,
2654 MultiExprArg Args,
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,
2665 bool isArrow,
2666 NestedNameSpecifierLoc QualifierLoc,
2667 SourceLocation TemplateKWLoc,
2668 const DeclarationNameInfo &MemberNameInfo,
2669 ValueDecl *Member,
2670 NamedDecl *FoundDecl,
2671 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2672 NamedDecl *FirstQualifierInScope) {
2673 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2674 isArrow);
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?");
2682 BaseResult =
2683 getSema().PerformObjectMemberConversion(BaseResult.get(),
2684 QualifierLoc.getNestedNameSpecifier(),
2685 FoundDecl, Member);
2686 if (BaseResult.isInvalid())
2687 return ExprError();
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);
2696 CXXScopeSpec SS;
2697 SS.Adopt(QualifierLoc);
2699 Base = BaseResult.get();
2700 QualType BaseType = Base->getType();
2702 if (isArrow && !BaseType->isPointerType())
2703 return ExprError();
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);
2709 R.resolveKind();
2711 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2712 SS, TemplateKWLoc,
2713 FirstQualifierInScope,
2714 R, ExplicitTemplateArgs,
2715 /*S*/nullptr);
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,
2745 Expr *LHS,
2746 SourceLocation ColonLoc,
2747 Expr *RHS) {
2748 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2749 LHS, RHS);
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,
2759 Expr *SubExpr) {
2760 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2761 SubExpr);
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,
2771 Expr *Init) {
2772 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2773 Init);
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) {
2785 CXXScopeSpec SS;
2786 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2787 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2788 OpLoc, /*IsArrow*/ false,
2789 SS, SourceLocation(),
2790 /*FirstQualifierInScope*/ nullptr,
2791 NameInfo,
2792 /* TemplateArgs */ nullptr,
2793 /*S*/ 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,
2801 MultiExprArg Inits,
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,
2813 bool GNUSyntax,
2814 Expr *Init) {
2815 ExprResult Result
2816 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2817 Init);
2818 if (Result.isInvalid())
2819 return ExprError();
2821 return Result;
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,
2841 SubExpr, TInfo,
2842 RParenLoc);
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,
2872 TemplateDepth);
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,
2883 Cond, LHS, RHS,
2884 RParenLoc);
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,
2911 Expr *Callee,
2912 Expr *First,
2913 Expr *Second);
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,
2927 Expr *SubExpr,
2928 SourceLocation RParenLoc) {
2929 switch (Class) {
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,
2943 SubExpr,
2944 RParenLoc);
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);
2955 default:
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,
2969 Expr *SubExpr,
2970 SourceLocation RParenLoc) {
2971 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2972 TInfo, SubExpr,
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,
2986 Expr *SubExpr,
2987 SourceLocation RParenLoc) {
2988 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2989 TInfo, SubExpr,
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,
3003 Expr *SubExpr,
3004 SourceLocation RParenLoc) {
3005 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3006 TInfo, SubExpr,
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,
3020 Expr *SubExpr,
3021 SourceLocation RParenLoc) {
3022 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3023 TInfo, SubExpr,
3024 SourceRange(LAngleLoc, RAngleLoc),
3025 SourceRange(LParenLoc, RParenLoc));
3028 ExprResult
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,
3044 Expr *Sub,
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,
3071 RParenLoc);
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,
3081 Expr *Operand,
3082 SourceLocation RParenLoc) {
3083 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3084 RParenLoc);
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,
3112 QualType ThisType,
3113 bool isImplicit) {
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,
3142 FieldDecl *Field) {
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,
3163 bool UseGlobal,
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,
3174 PlacementLParen,
3175 PlacementArgs,
3176 PlacementRParen,
3177 TypeIdParens,
3178 AllocatedType,
3179 AllocatedTypeInfo,
3180 ArraySize,
3181 DirectInitRange,
3182 Initializer);
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,
3191 bool IsArrayForm,
3192 Expr *Operand) {
3193 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3194 Operand);
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,
3215 Expr *DimExpr,
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,
3226 Expr *Queried,
3227 SourceLocation RParenLoc) {
3228 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3231 /// Build a new (previously unresolved) declaration reference
3232 /// expression.
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) {
3243 CXXScopeSpec SS;
3244 SS.Adopt(QualifierLoc);
3246 if (TemplateArgs || TemplateKWLoc.isValid())
3247 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
3248 TemplateArgs);
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,
3260 LookupResult &R,
3261 bool RequiresADL,
3262 const TemplateArgumentListInfo *TemplateArgs) {
3263 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3264 TemplateArgs);
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,
3272 SourceLocation Loc,
3273 CXXConstructorDecl *Constructor,
3274 bool IsElidable,
3275 MultiExprArg Args,
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,
3290 ConvertedArgs))
3291 return ExprError();
3293 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3294 IsElidable,
3295 ConvertedArgs,
3296 HadMultipleCandidates,
3297 ListInitialization,
3298 StdInitListInitialization,
3299 RequiresZeroInit, ConstructKind,
3300 ParenRange);
3303 /// Build a new implicit construction via inherited constructor
3304 /// expression.
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,
3319 MultiExprArg Args,
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,
3332 MultiExprArg Args,
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,
3344 QualType BaseType,
3345 bool IsArrow,
3346 SourceLocation OperatorLoc,
3347 NestedNameSpecifierLoc QualifierLoc,
3348 SourceLocation TemplateKWLoc,
3349 NamedDecl *FirstQualifierInScope,
3350 const DeclarationNameInfo &MemberNameInfo,
3351 const TemplateArgumentListInfo *TemplateArgs) {
3352 CXXScopeSpec SS;
3353 SS.Adopt(QualifierLoc);
3355 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3356 OperatorLoc, IsArrow,
3357 SS, TemplateKWLoc,
3358 FirstQualifierInScope,
3359 MemberNameInfo,
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,
3369 bool IsArrow,
3370 NestedNameSpecifierLoc QualifierLoc,
3371 SourceLocation TemplateKWLoc,
3372 NamedDecl *FirstQualifierInScope,
3373 LookupResult &R,
3374 const TemplateArgumentListInfo *TemplateArgs) {
3375 CXXScopeSpec SS;
3376 SS.Adopt(QualifierLoc);
3378 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3379 OperatorLoc, IsArrow,
3380 SS, TemplateKWLoc,
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,
3395 NamedDecl *Pack,
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
3405 /// builtin.
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,
3414 ParentContext);
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) {
3425 CXXScopeSpec SS;
3426 SS.Adopt(NNS);
3427 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3428 ConceptNameInfo,
3429 FoundDecl,
3430 NamedConcept, TALI);
3431 if (Result.isInvalid())
3432 return ExprError();
3433 return Result;
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,
3465 std::move(Ret));
3468 concepts::ExprRequirement *
3469 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3470 concepts::ExprRequirement::ReturnTypeRequirement Ret) {
3471 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3472 std::move(Ret));
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,
3532 Selector Sel,
3533 ArrayRef<SourceLocation> SelectorLocs,
3534 ObjCMethodDecl *Method,
3535 SourceLocation LBracLoc,
3536 MultiExprArg Args,
3537 SourceLocation RBracLoc) {
3538 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3539 ReceiverTypeInfo->getType(),
3540 /*SuperLoc=*/SourceLocation(),
3541 Sel, Method, LBracLoc, SelectorLocs,
3542 RBracLoc, Args);
3545 /// Build a new Objective-C instance message.
3546 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
3547 Selector Sel,
3548 ArrayRef<SourceLocation> SelectorLocs,
3549 ObjCMethodDecl *Method,
3550 SourceLocation LBracLoc,
3551 MultiExprArg Args,
3552 SourceLocation RBracLoc) {
3553 return SemaRef.BuildInstanceMessage(Receiver,
3554 Receiver->getType(),
3555 /*SuperLoc=*/SourceLocation(),
3556 Sel, Method, LBracLoc, SelectorLocs,
3557 RBracLoc, Args);
3560 /// Build a new Objective-C instance/class message to 'super'.
3561 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3562 Selector Sel,
3563 ArrayRef<SourceLocation> SelectorLocs,
3564 QualType SuperType,
3565 ObjCMethodDecl *Method,
3566 SourceLocation LBracLoc,
3567 MultiExprArg Args,
3568 SourceLocation RBracLoc) {
3569 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3570 SuperType,
3571 SuperLoc,
3572 Sel, Method, LBracLoc, SelectorLocs,
3573 RBracLoc, Args)
3574 : SemaRef.BuildClassMessage(nullptr,
3575 SuperType,
3576 SuperLoc,
3577 Sel, Method, LBracLoc, SelectorLocs,
3578 RBracLoc, Args);
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) {
3590 CXXScopeSpec SS;
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,
3597 /*S=*/nullptr);
3598 if (IsFreeIvar && Result.isUsable())
3599 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3600 return Result;
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) {
3610 CXXScopeSpec SS;
3611 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3612 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3613 /*FIXME:*/PropertyLoc,
3614 /*IsArrow=*/false,
3615 SS, SourceLocation(),
3616 /*FirstQualifierInScope=*/nullptr,
3617 NameInfo,
3618 /*TemplateArgs=*/nullptr,
3619 /*S=*/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.
3632 return Owned(
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) {
3644 CXXScopeSpec SS;
3645 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3646 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3647 OpLoc, IsArrow,
3648 SS, SourceLocation(),
3649 /*FirstQualifierInScope=*/nullptr,
3650 NameInfo,
3651 /*TemplateArgs=*/nullptr,
3652 /*S=*/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: {
3706 ExprResult Result
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(
3717 SemaRef.Context,
3718 TemplateArgument(Pattern.getArgument().getAsTemplate(),
3719 NumExpansions),
3720 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3721 EllipsisLoc);
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(),
3734 EllipsisLoc,
3735 NumExpansions))
3736 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3737 Expansion);
3738 break;
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
3757 /// expression.
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,
3766 NumExpansions);
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);
3797 private:
3798 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3799 QualType ObjectType,
3800 NamedDecl *FirstQualifierInScope,
3801 CXXScopeSpec &SS);
3803 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3804 QualType ObjectType,
3805 NamedDecl *FirstQualifierInScope,
3806 CXXScopeSpec &SS);
3808 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3809 NamedDecl *FirstQualifierInScope,
3810 CXXScopeSpec &SS);
3812 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3813 DependentNameTypeLoc TL,
3814 bool DeducibleTSTContext);
3817 template <typename Derived>
3818 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
3819 if (!S)
3820 return S;
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);
3850 return S;
3853 template<typename Derived>
3854 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3855 if (!S)
3856 return S;
3858 switch (S->getClauseKind()) {
3859 default: break;
3860 // Transform individual clause nodes
3861 #define GEN_CLANG_CLAUSE_CLASS
3862 #define CLAUSE_CLASS(Enum, Str, Class) \
3863 case Enum: \
3864 return getDerived().Transform##Class(cast<Class>(S));
3865 #include "llvm/Frontend/OpenMP/OMP.inc"
3868 return S;
3872 template<typename Derived>
3873 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
3874 if (!E)
3875 return 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"
3886 return E;
3889 template<typename Derived>
3890 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
3891 bool NotCopyInit) {
3892 // Initializers are instantiated like expressions, except that various outer
3893 // layers are stripped.
3894 if (!Init)
3895 return Init;
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,
3929 Parens.getEnd());
3932 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3933 if (isa<ImplicitValueInitExpr>(Init))
3934 return getDerived().RebuildParenListExpr(SourceLocation(), None,
3935 SourceLocation());
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))
3956 return ExprError();
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
3967 // was specified.
3968 assert(NewArgs.empty() &&
3969 "no parens or braces but have direct init with arguments?");
3970 return ExprEmpty();
3972 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3973 Parens.getEnd());
3976 template<typename Derived>
3977 bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
3978 unsigned NumInputs,
3979 bool IsCall,
3980 SmallVectorImpl<Expr *> &Outputs,
3981 bool *ArgChanged) {
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])) {
3985 if (ArgChanged)
3986 *ArgChanged = true;
3988 break;
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
3999 // be expanded.
4000 bool Expand = true;
4001 bool RetainExpansion = false;
4002 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4003 Optional<unsigned> NumExpansions = OrigNumExpansions;
4004 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4005 Pattern->getSourceRange(),
4006 Unexpanded,
4007 Expand, RetainExpansion,
4008 NumExpansions))
4009 return true;
4011 if (!Expand) {
4012 // The transform has determined that we should perform a simple
4013 // transformation on the pack expansion, producing another pack
4014 // expansion.
4015 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4016 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4017 if (OutPattern.isInvalid())
4018 return true;
4020 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4021 Expansion->getEllipsisLoc(),
4022 NumExpansions);
4023 if (Out.isInvalid())
4024 return true;
4026 if (ArgChanged)
4027 *ArgChanged = true;
4028 Outputs.push_back(Out.get());
4029 continue;
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())
4042 return true;
4044 if (Out.get()->containsUnexpandedParameterPack()) {
4045 Out = getDerived().RebuildPackExpansion(
4046 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4047 if (Out.isInvalid())
4048 return true;
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())
4061 return true;
4063 Out = getDerived().RebuildPackExpansion(
4064 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4065 if (Out.isInvalid())
4066 return true;
4068 Outputs.push_back(Out.get());
4071 continue;
4074 ExprResult Result =
4075 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4076 : getDerived().TransformExpr(Inputs[I]);
4077 if (Result.isInvalid())
4078 return true;
4080 if (Result.get() != Inputs[I] && ArgChanged)
4081 *ArgChanged = true;
4083 Outputs.push_back(Result.get());
4086 return false;
4089 template <typename Derived>
4090 Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
4091 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
4092 if (Var) {
4093 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4094 getDerived().TransformDefinition(Var->getLocation(), Var));
4096 if (!ConditionVar)
4097 return Sema::ConditionError();
4099 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4102 if (Expr) {
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);
4124 CXXScopeSpec SS;
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(),
4133 ObjectType);
4134 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4135 SS, FirstQualifierInScope, false))
4136 return NestedNameSpecifierLoc();
4137 break;
4140 case NestedNameSpecifier::Namespace: {
4141 NamespaceDecl *NS =
4142 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4143 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4144 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4145 break;
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());
4154 break;
4157 case NestedNameSpecifier::Global:
4158 // There is no meaningful transformation that one could perform on the
4159 // global scope.
4160 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4161 break;
4163 case NestedNameSpecifier::Super: {
4164 CXXRecordDecl *RD =
4165 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4166 SourceLocation(), QNNS->getAsRecordDecl()));
4167 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4168 break;
4171 case NestedNameSpecifier::TypeSpecWithTemplate:
4172 case NestedNameSpecifier::TypeSpec: {
4173 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4174 FirstQualifierInScope, SS);
4176 if (!TL)
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());
4189 break;
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())
4210 return NNS;
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>
4223 DeclarationNameInfo
4224 TreeTransform<Derived>
4225 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
4226 DeclarationName Name = NameInfo.getName();
4227 if (!Name)
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:
4238 return NameInfo;
4240 case DeclarationName::CXXDeductionGuideName: {
4241 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4242 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4243 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4244 if (!NewTemplate)
4245 return DeclarationNameInfo();
4247 DeclarationNameInfo NewNameInfo(NameInfo);
4248 NewNameInfo.setName(
4249 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4250 return NewNameInfo;
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);
4260 if (!NewTInfo)
4261 return DeclarationNameInfo();
4262 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4264 else {
4265 NewTInfo = nullptr;
4266 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4267 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4268 if (NewT.isNull())
4269 return DeclarationNameInfo();
4270 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4273 DeclarationName NewName
4274 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4275 NewCanTy);
4276 DeclarationNameInfo NewNameInfo(NameInfo);
4277 NewNameInfo.setName(NewName);
4278 NewNameInfo.setNamedTypeInfo(NewTInfo);
4279 return NewNameInfo;
4283 llvm_unreachable("Unknown name kind.");
4286 template<typename Derived>
4287 TemplateName
4288 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
4289 TemplateName Name,
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,
4300 Template));
4301 if (!TransTemplate)
4302 return TemplateName();
4304 if (!getDerived().AlwaysRebuild() &&
4305 SS.getScopeRep() == QTN->getQualifier() &&
4306 TransTemplate == Template)
4307 return Name;
4309 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4310 TransTemplate);
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())
4323 return Name;
4325 // FIXME: Preserve the location of the "template" keyword.
4326 SourceLocation TemplateKWLoc = NameLoc;
4328 if (DTN->isIdentifier()) {
4329 return getDerived().RebuildTemplateName(SS,
4330 TemplateKWLoc,
4331 *DTN->getIdentifier(),
4332 NameLoc,
4333 ObjectType,
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,
4346 Template));
4347 if (!TransTemplate)
4348 return TemplateName();
4350 if (!getDerived().AlwaysRebuild() &&
4351 TransTemplate == Template)
4352 return Name;
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()));
4362 if (!TransParam)
4363 return TemplateName();
4365 if (!getDerived().AlwaysRebuild() &&
4366 TransParam == SubstPack->getParameterPack())
4367 return Name;
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,
4388 bool Uneval) {
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);
4403 if (NewT.isNull())
4404 return true;
4406 ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration
4407 ? Arg.getAsDecl()
4408 : nullptr;
4409 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4410 getDerived().getBaseLocation(), D))
4411 : nullptr;
4412 if (D && !NewD)
4413 return true;
4415 if (NewT == T && D == NewD)
4416 Output = Input;
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());
4424 else
4425 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4426 TemplateArgumentLocInfo());
4428 return false;
4431 case TemplateArgument::Type: {
4432 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4433 if (!DI)
4434 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4436 DI = getDerived().TransformType(DI);
4437 if (!DI)
4438 return true;
4440 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4441 return false;
4444 case TemplateArgument::Template: {
4445 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4446 if (QualifierLoc) {
4447 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4448 if (!QualifierLoc)
4449 return true;
4452 CXXScopeSpec SS;
4453 SS.Adopt(QualifierLoc);
4454 TemplateName Template = getDerived().TransformTemplateName(
4455 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4456 if (Template.isNull())
4457 return true;
4459 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4460 QualifierLoc, Input.getTemplateNameLoc());
4461 return false;
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(
4470 getSema(),
4471 Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
4472 : Sema::ExpressionEvaluationContext::ConstantEvaluated,
4473 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
4474 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
4476 Expr *InputExpr = Input.getSourceExpression();
4477 if (!InputExpr)
4478 InputExpr = Input.getArgument().getAsExpr();
4480 ExprResult E = getDerived().TransformExpr(InputExpr);
4481 E = SemaRef.ActOnConstantExpression(E);
4482 if (E.isInvalid())
4483 return true;
4484 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4485 return false;
4489 // Work around bogus GCC warning
4490 return true;
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;
4498 InputIterator Iter;
4500 public:
4501 typedef TemplateArgumentLoc value_type;
4502 typedef TemplateArgumentLoc reference;
4503 typedef typename std::iterator_traits<InputIterator>::difference_type
4504 difference_type;
4505 typedef std::input_iterator_tag iterator_category;
4507 class pointer {
4508 TemplateArgumentLoc Arg;
4510 public:
4511 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4513 const TemplateArgumentLoc *operator->() const { return &Arg; }
4516 TemplateArgumentLocInventIterator() { }
4518 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
4519 InputIterator Iter)
4520 : Self(Self), Iter(Iter) { }
4522 TemplateArgumentLocInventIterator &operator++() {
4523 ++Iter;
4524 return *this;
4527 TemplateArgumentLocInventIterator operator++(int) {
4528 TemplateArgumentLocInventIterator Old(*this);
4529 ++(*this);
4530 return Old;
4533 reference operator*() const {
4534 TemplateArgumentLoc Result;
4535 Self.InventTemplateArgumentLoc(*Iter, Result);
4536 return 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,
4556 bool Uneval) {
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
4563 // arguments.
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>
4569 PackLocIterator;
4570 if (TransformTemplateArguments(PackLocIterator(*this,
4571 In.getArgument().pack_begin()),
4572 PackLocIterator(*this,
4573 In.getArgument().pack_end()),
4574 Outputs, Uneval))
4575 return true;
4577 continue;
4580 if (In.getArgument().isPackExpansion()) {
4581 // We have a pack expansion, for which we will be substituting into
4582 // the pattern.
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
4594 // be expanded.
4595 bool Expand = true;
4596 bool RetainExpansion = false;
4597 Optional<unsigned> NumExpansions = OrigNumExpansions;
4598 if (getDerived().TryExpandParameterPacks(Ellipsis,
4599 Pattern.getSourceRange(),
4600 Unexpanded,
4601 Expand,
4602 RetainExpansion,
4603 NumExpansions))
4604 return true;
4606 if (!Expand) {
4607 // The transform has determined that we should perform a simple
4608 // transformation on the pack expansion, producing another pack
4609 // expansion.
4610 TemplateArgumentLoc OutPattern;
4611 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4612 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4613 return true;
4615 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4616 NumExpansions);
4617 if (Out.getArgument().isNull())
4618 return true;
4620 Outputs.addArgument(Out);
4621 continue;
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))
4630 return true;
4632 if (Out.getArgument().containsUnexpandedParameterPack()) {
4633 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4634 OrigNumExpansions);
4635 if (Out.getArgument().isNull())
4636 return true;
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))
4648 return true;
4650 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4651 OrigNumExpansions);
4652 if (Out.getArgument().isNull())
4653 return true;
4655 Outputs.addArgument(Out);
4658 continue;
4661 // The simple case:
4662 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4663 return true;
4665 Outputs.addArgument(Out);
4668 return false;
4672 //===----------------------------------------------------------------------===//
4673 // Type transformation
4674 //===----------------------------------------------------------------------===//
4676 template<typename Derived>
4677 QualType TreeTransform<Derived>::TransformType(QualType T) {
4678 if (getDerived().AlreadyTransformed(T))
4679 return 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);
4688 if (!NewDI)
4689 return QualType();
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()))
4700 return DI;
4702 TypeLocBuilder TLB;
4704 TypeLoc TL = DI->getTypeLoc();
4705 TLB.reserve(TL.getFullDataSize());
4707 QualType Result = getDerived().TransformType(TLB, TL);
4708 if (Result.isNull())
4709 return nullptr;
4711 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4714 template<typename Derived>
4715 QualType
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))
4735 return 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>
4743 TypeSourceInfo *
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()))
4752 return DI;
4754 TypeLocBuilder TLB;
4756 TypeLoc TL = DI->getTypeLoc();
4757 TLB.reserve(TL.getFullDataSize());
4759 auto QTL = TL.getAs<QualifiedTypeLoc>();
4760 if (QTL)
4761 TL = QTL.getUnqualifiedLoc();
4763 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4765 QualType Result = getDerived().TransformDependentNameType(
4766 TLB, DNTL, /*DeducedTSTContext*/true);
4767 if (Result.isNull())
4768 return nullptr;
4770 if (QTL) {
4771 Result = getDerived().RebuildQualifiedType(Result, QTL);
4772 if (Result.isNull())
4773 return nullptr;
4774 TLB.TypeWasModifiedSafely(Result);
4777 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4780 template<typename Derived>
4781 QualType
4782 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
4783 QualifiedTypeLoc T) {
4784 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4785 if (Result.isNull())
4786 return QualType();
4788 Result = getDerived().RebuildQualifiedType(Result, T);
4790 if (Result.isNull())
4791 return QualType();
4793 // RebuildQualifiedType might have updated the type, but not in a way
4794 // that invalidates the TypeLoc. (There's no location information for
4795 // qualifiers.)
4796 TLB.TypeWasModifiedSafely(Result);
4798 return 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;
4813 return QualType();
4816 // C++ [dcl.fct]p7:
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());
4822 return T;
4825 // C++ [dcl.ref]p1:
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())
4833 return T;
4834 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4837 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4838 // resulting type.
4839 if (Quals.hasObjCLifetime()) {
4840 if (!T->isObjCLifetimeType() && !T->isDependentType())
4841 Quals.removeObjCLifetime();
4842 else if (T.getObjCLifetime()) {
4843 // Objective-C ARC:
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();
4862 Deduced =
4863 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4864 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4865 AutoTy->isDependentType(),
4866 /*isPack=*/false,
4867 AutoTy->getTypeConstraintConcept(),
4868 AutoTy->getTypeConstraintArguments());
4869 } else {
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>
4883 TypeLoc
4884 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4885 QualType ObjectType,
4886 NamedDecl *UnqualLookup,
4887 CXXScopeSpec &SS) {
4888 if (getDerived().AlreadyTransformed(TL.getType()))
4889 return TL;
4891 TypeSourceInfo *TSI =
4892 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4893 if (TSI)
4894 return TSI->getTypeLoc();
4895 return TypeLoc();
4898 template<typename Derived>
4899 TypeSourceInfo *
4900 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4901 QualType ObjectType,
4902 NamedDecl *UnqualLookup,
4903 CXXScopeSpec &SS) {
4904 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4905 return TSInfo;
4907 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4908 UnqualLookup, SS);
4911 template <typename Derived>
4912 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4913 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4914 CXXScopeSpec &SS) {
4915 QualType T = TL.getType();
4916 assert(!getDerived().AlreadyTransformed(T));
4918 TypeLocBuilder TLB;
4919 QualType Result;
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())
4929 return nullptr;
4931 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4932 Template);
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())
4945 return nullptr;
4947 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4948 SpecTL,
4949 Template,
4950 SS);
4951 } else {
4952 // Nothing special needs to be done for these.
4953 Result = getDerived().TransformType(TLB, TL);
4956 if (Result.isNull())
4957 return nullptr;
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());
4966 return T.getType();
4969 template<typename Derived>
4970 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4971 BuiltinTypeLoc T) {
4972 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4973 NewT.setBuiltinLoc(T.getBuiltinLoc());
4974 if (T.needsExtraLocalData())
4975 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4976 return T.getType();
4979 template<typename Derived>
4980 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4981 ComplexTypeLoc T) {
4982 // FIXME: recurse?
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())
4998 return QualType();
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.
5006 return Result;
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())
5015 return QualType();
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
5022 // PointerType.
5023 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5025 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5026 NewT.setStarLoc(TL.getStarLoc());
5027 return Result;
5030 if (getDerived().AlwaysRebuild() ||
5031 PointeeType != TL.getPointeeLoc().getType()) {
5032 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5033 if (Result.isNull())
5034 return QualType();
5037 // Objective-C ARC can add lifetime qualifiers to the type that we're
5038 // pointing to.
5039 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5041 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5042 NewT.setSigilLoc(TL.getSigilLoc());
5043 return Result;
5046 template<typename Derived>
5047 QualType
5048 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5049 BlockPointerTypeLoc TL) {
5050 QualType PointeeType
5051 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5052 if (PointeeType.isNull())
5053 return QualType();
5055 QualType Result = TL.getType();
5056 if (getDerived().AlwaysRebuild() ||
5057 PointeeType != TL.getPointeeLoc().getType()) {
5058 Result = getDerived().RebuildBlockPointerType(PointeeType,
5059 TL.getSigilLoc());
5060 if (Result.isNull())
5061 return QualType();
5064 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5065 NewT.setSigilLoc(TL.getSigilLoc());
5066 return Result;
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>
5074 QualType
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())
5082 return QualType();
5084 QualType Result = TL.getType();
5085 if (getDerived().AlwaysRebuild() ||
5086 PointeeType != T->getPointeeTypeAsWritten()) {
5087 Result = getDerived().RebuildReferenceType(PointeeType,
5088 T->isSpelledAsLValue(),
5089 TL.getSigilLoc());
5090 if (Result.isNull())
5091 return QualType();
5094 // Objective-C ARC can add lifetime qualifiers to the type that we're
5095 // referring to.
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);
5103 else
5104 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5105 NewTL.setSigilLoc(TL.getSigilLoc());
5107 return Result;
5110 template<typename Derived>
5111 QualType
5112 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
5113 LValueReferenceTypeLoc TL) {
5114 return TransformReferenceType(TLB, TL);
5117 template<typename Derived>
5118 QualType
5119 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5120 RValueReferenceTypeLoc TL) {
5121 return TransformReferenceType(TLB, TL);
5124 template<typename Derived>
5125 QualType
5126 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5127 MemberPointerTypeLoc TL) {
5128 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5129 if (PointeeType.isNull())
5130 return QualType();
5132 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5133 TypeSourceInfo *NewClsTInfo = nullptr;
5134 if (OldClsTInfo) {
5135 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5136 if (!NewClsTInfo)
5137 return QualType();
5140 const MemberPointerType *T = TL.getTypePtr();
5141 QualType OldClsType = QualType(T->getClass(), 0);
5142 QualType NewClsType;
5143 if (NewClsTInfo)
5144 NewClsType = NewClsTInfo->getType();
5145 else {
5146 NewClsType = getDerived().TransformType(OldClsType);
5147 if (NewClsType.isNull())
5148 return QualType();
5151 QualType Result = TL.getType();
5152 if (getDerived().AlwaysRebuild() ||
5153 PointeeType != T->getPointeeType() ||
5154 NewClsType != OldClsType) {
5155 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5156 TL.getStarLoc());
5157 if (Result.isNull())
5158 return QualType();
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);
5173 return Result;
5176 template<typename Derived>
5177 QualType
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())
5183 return QualType();
5185 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5186 Expr *OldSize = TL.getSizeExpr();
5187 if (!OldSize)
5188 OldSize = const_cast<Expr*>(T->getSizeExpr());
5189 Expr *NewSize = nullptr;
5190 if (OldSize) {
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())
5207 return QualType();
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);
5219 return Result;
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())
5229 return QualType();
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())
5239 return QualType();
5242 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5243 NewTL.setLBracketLoc(TL.getLBracketLoc());
5244 NewTL.setRBracketLoc(TL.getRBracketLoc());
5245 NewTL.setSizeExpr(nullptr);
5247 return Result;
5250 template<typename Derived>
5251 QualType
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())
5257 return QualType();
5259 ExprResult SizeResult;
5261 EnterExpressionEvaluationContext Context(
5262 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
5263 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5265 if (SizeResult.isInvalid())
5266 return QualType();
5267 SizeResult =
5268 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5269 if (SizeResult.isInvalid())
5270 return QualType();
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(),
5280 Size,
5281 T->getIndexTypeCVRQualifiers(),
5282 TL.getBracketsRange());
5283 if (Result.isNull())
5284 return QualType();
5287 // We might have constant size array now, but fortunately it has the same
5288 // location layout.
5289 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5290 NewTL.setLBracketLoc(TL.getLBracketLoc());
5291 NewTL.setRBracketLoc(TL.getRBracketLoc());
5292 NewTL.setSizeExpr(Size);
5294 return Result;
5297 template<typename Derived>
5298 QualType
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())
5304 return QualType();
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())
5318 return QualType();
5320 Expr *size = sizeResult.get();
5322 QualType Result = TL.getType();
5323 if (getDerived().AlwaysRebuild() ||
5324 ElementType != T->getElementType() ||
5325 size != origSize) {
5326 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5327 T->getSizeModifier(),
5328 size,
5329 T->getIndexTypeCVRQualifiers(),
5330 TL.getBracketsRange());
5331 if (Result.isNull())
5332 return QualType();
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);
5342 return Result;
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())
5351 return QualType();
5353 EnterExpressionEvaluationContext Unevaluated(
5354 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5356 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5357 Size = SemaRef.ActOnConstantExpression(Size);
5358 if (Size.isInvalid())
5359 return QualType();
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())
5367 return QualType();
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());
5375 } else {
5376 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5377 NewTL.setNameLoc(TL.getNameLoc());
5380 return Result;
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())
5392 return QualType();
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())
5401 return QualType();
5403 QualType Result = TL.getType();
5404 if (getDerived().AlwaysRebuild() ||
5405 ElementType != T->getElementType() ||
5406 Size.get() != T->getSizeExpr()) {
5407 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5408 Size.get(),
5409 T->getAttributeLoc());
5410 if (Result.isNull())
5411 return QualType();
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());
5419 } else {
5420 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5421 NewTL.setNameLoc(TL.getNameLoc());
5424 return Result;
5427 template <typename Derived>
5428 QualType
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())
5434 return QualType();
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())
5441 return QualType();
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());
5450 return Result;
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()) {
5460 return QualType();
5463 // Matrix dimensions are constant expressions.
5464 EnterExpressionEvaluationContext Unevaluated(
5465 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5467 Expr *origRows = TL.getAttrRowOperand();
5468 if (!origRows)
5469 origRows = T->getRowExpr();
5470 Expr *origColumns = TL.getAttrColumnOperand();
5471 if (!origColumns)
5472 origColumns = T->getColumnExpr();
5474 ExprResult rowResult = getDerived().TransformExpr(origRows);
5475 rowResult = SemaRef.ActOnConstantExpression(rowResult);
5476 if (rowResult.isInvalid())
5477 return QualType();
5479 ExprResult columnResult = getDerived().TransformExpr(origColumns);
5480 columnResult = SemaRef.ActOnConstantExpression(columnResult);
5481 if (columnResult.isInvalid())
5482 return QualType();
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())
5494 return QualType();
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);
5504 return Result;
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())
5515 return QualType();
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())
5524 return QualType();
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())
5532 return QualType();
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());
5544 } else {
5545 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
5546 Result, getDerived().getBaseLocation());
5547 TransformType(TLB, DI->getTypeLoc());
5550 return Result;
5553 template <typename Derived>
5554 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
5555 VectorTypeLoc TL) {
5556 const VectorType *T = TL.getTypePtr();
5557 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5558 if (ElementType.isNull())
5559 return QualType();
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())
5567 return QualType();
5570 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5571 NewTL.setNameLoc(TL.getNameLoc());
5573 return Result;
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())
5582 return QualType();
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())
5591 return QualType();
5594 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5595 NewTL.setNameLoc(TL.getNameLoc());
5597 return Result;
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>();
5613 TypeLocBuilder TLB;
5614 TypeLoc NewTL = OldDI->getTypeLoc();
5615 TLB.reserve(NewTL.getFullDataSize());
5617 QualType Result = getDerived().TransformType(TLB,
5618 OldExpansionTL.getPatternLoc());
5619 if (Result.isNull())
5620 return nullptr;
5622 Result = RebuildPackExpansionType(Result,
5623 OldExpansionTL.getPatternLoc().getSourceRange(),
5624 OldExpansionTL.getEllipsisLoc(),
5625 NumExpansions);
5626 if (Result.isNull())
5627 return nullptr;
5629 PackExpansionTypeLoc NewExpansionTL
5630 = TLB.push<PackExpansionTypeLoc>(Result);
5631 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5632 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5633 } else
5634 NewDI = getDerived().TransformType(OldDI);
5635 if (!NewDI)
5636 return nullptr;
5638 if (NewDI == OldDI && indexAdjustment == 0)
5639 return OldParm;
5641 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5642 OldParm->getDeclContext(),
5643 OldParm->getInnerLocStart(),
5644 OldParm->getLocation(),
5645 OldParm->getIdentifier(),
5646 NewDI->getType(),
5647 NewDI,
5648 OldParm->getStorageClass(),
5649 /* DefArg */ nullptr);
5650 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5651 OldParm->getFunctionScopeIndex() + indexAdjustment);
5652 transformedLocalDecl(OldParm, {newParm});
5653 return 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(),
5692 Unexpanded,
5693 ShouldExpand,
5694 RetainExpansion,
5695 NumExpansions)) {
5696 return true;
5698 } else {
5699 #ifndef NDEBUG
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!");
5704 #endif
5707 if (ShouldExpand) {
5708 // Expand the function parameter pack into multiple, separate
5709 // parameters.
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,
5715 indexAdjustment++,
5716 OrigNumExpansions,
5717 /*ExpectParameterPack=*/false);
5718 if (!NewParm)
5719 return true;
5721 if (ParamInfos)
5722 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5723 OutParamTypes.push_back(NewParm->getType());
5724 if (PVars)
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,
5734 indexAdjustment++,
5735 OrigNumExpansions,
5736 /*ExpectParameterPack=*/false);
5737 if (!NewParm)
5738 return true;
5740 if (ParamInfos)
5741 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5742 OutParamTypes.push_back(NewParm->getType());
5743 if (PVars)
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
5750 // go down by one.
5751 indexAdjustment--;
5753 // We're done with the pack expansion.
5754 continue;
5757 // We'll substitute the parameter now without expanding the pack
5758 // expansion.
5759 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5760 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
5761 indexAdjustment,
5762 NumExpansions,
5763 /*ExpectParameterPack=*/true);
5764 assert(NewParm->isParameterPack() &&
5765 "Parameter pack no longer a parameter pack after "
5766 "transformation.");
5767 } else {
5768 NewParm = getDerived().TransformFunctionTypeParam(
5769 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
5772 if (!NewParm)
5773 return true;
5775 if (ParamInfos)
5776 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5777 OutParamTypes.push_back(NewParm->getType());
5778 if (PVars)
5779 PVars->push_back(NewParm);
5780 continue;
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;
5788 QualType NewType;
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(),
5801 Unexpanded,
5802 ShouldExpand,
5803 RetainExpansion,
5804 NumExpansions)) {
5805 return true;
5808 if (ShouldExpand) {
5809 // Expand the function parameter pack into multiple, separate
5810 // parameters.
5811 for (unsigned I = 0; I != *NumExpansions; ++I) {
5812 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5813 QualType NewType = getDerived().TransformType(Pattern);
5814 if (NewType.isNull())
5815 return true;
5817 if (NewType->containsUnexpandedParameterPack()) {
5818 NewType =
5819 getSema().getASTContext().getPackExpansionType(NewType, None);
5821 if (NewType.isNull())
5822 return true;
5825 if (ParamInfos)
5826 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5827 OutParamTypes.push_back(NewType);
5828 if (PVars)
5829 PVars->push_back(nullptr);
5832 // We're done with the pack expansion.
5833 continue;
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())
5842 return true;
5844 if (ParamInfos)
5845 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5846 OutParamTypes.push_back(NewType);
5847 if (PVars)
5848 PVars->push_back(nullptr);
5851 // We'll substitute the parameter now without expanding the pack
5852 // expansion.
5853 OldType = Expansion->getPattern();
5854 IsPackExpansion = true;
5855 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5856 NewType = getDerived().TransformType(OldType);
5857 } else {
5858 NewType = getDerived().TransformType(OldType);
5861 if (NewType.isNull())
5862 return true;
5864 if (IsPackExpansion)
5865 NewType = getSema().Context.getPackExpansionType(NewType,
5866 NumExpansions);
5868 if (ParamInfos)
5869 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5870 OutParamTypes.push_back(NewType);
5871 if (PVars)
5872 PVars->push_back(nullptr);
5875 #ifndef NDEBUG
5876 if (PVars) {
5877 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5878 if (ParmVarDecl *parm = (*PVars)[i])
5879 assert(parm->getFunctionScopeIndex() == i);
5881 #endif
5883 return false;
5886 template<typename Derived>
5887 QualType
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))
5925 return QualType();
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
5933 // declarator.
5934 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
5936 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5937 if (ResultType.isNull())
5938 return QualType();
5941 else {
5942 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5943 if (ResultType.isNull())
5944 return QualType();
5946 if (getDerived().TransformFunctionTypeParams(
5947 TL.getBeginLoc(), TL.getParams(),
5948 TL.getTypePtr()->param_type_begin(),
5949 T->getExtParameterInfosOrNull(),
5950 ParamTypes, &ParamDecls, ExtParamInfos))
5951 return QualType();
5954 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5956 bool EPIChanged = false;
5957 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5958 return QualType();
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())) {
5966 EPIChanged = true;
5968 EPI.ExtParameterInfos = NewExtParamInfos;
5969 } else if (EPI.ExtParameterInfos) {
5970 EPIChanged = true;
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())
5979 return QualType();
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]);
5991 return Result;
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())
6006 return true;
6008 ExceptionSpecificationType EST = ESI.Type;
6009 NoexceptExpr =
6010 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6011 if (NoexceptExpr.isInvalid())
6012 return true;
6014 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6015 Changed = true;
6016 ESI.NoexceptExpr = NoexceptExpr.get();
6017 ESI.Type = EST;
6020 if (ESI.Type != EST_Dynamic)
6021 return false;
6023 // Instantiate a dynamic exception specification's type.
6024 for (QualType T : ESI.Exceptions) {
6025 if (const PackExpansionType *PackExpansion =
6026 T->getAs<PackExpansionType>()) {
6027 Changed = true;
6029 // We have a pack expansion. Instantiate it.
6030 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6031 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6032 Unexpanded);
6033 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6035 // Determine whether the set of unexpanded parameter packs can and
6036 // should
6037 // be expanded.
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))
6046 return true;
6048 if (!Expand) {
6049 // We can't expand this pack expansion into separate arguments yet;
6050 // just substitute into the pattern and create a new pack expansion
6051 // type.
6052 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6053 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6054 if (U.isNull())
6055 return true;
6057 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6058 Exceptions.push_back(U);
6059 continue;
6062 // Substitute into the pack expansion pattern for each slice of the
6063 // pack.
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))
6069 return true;
6071 Exceptions.push_back(U);
6073 } else {
6074 QualType U = getDerived().TransformType(T);
6075 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6076 return true;
6077 if (T != U)
6078 Changed = true;
6080 Exceptions.push_back(U);
6084 ESI.Exceptions = Exceptions;
6085 if (ESI.Exceptions.empty())
6086 ESI.Type = EST_DynamicNone;
6087 return false;
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())
6097 return QualType();
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());
6109 return Result;
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());
6117 if (!D)
6118 return QualType();
6120 QualType Result = TL.getType();
6121 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
6122 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
6123 if (Result.isNull())
6124 return QualType();
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());
6132 return Result;
6135 template <typename Derived>
6136 QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
6137 UsingTypeLoc TL) {
6138 const UsingType *T = TL.getTypePtr();
6140 auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
6141 TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
6142 if (!Found)
6143 return QualType();
6145 QualType Underlying = getDerived().TransformType(T->desugar());
6146 if (Underlying.isNull())
6147 return QualType();
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())
6154 return QualType();
6157 TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
6158 return Result;
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(),
6167 T->getDecl()));
6168 if (!Typedef)
6169 return QualType();
6171 QualType Result = TL.getType();
6172 if (getDerived().AlwaysRebuild() ||
6173 Typedef != T->getDecl()) {
6174 Result = getDerived().RebuildTypedefType(Typedef);
6175 if (Result.isNull())
6176 return QualType();
6179 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
6180 NewTL.setNameLoc(TL.getNameLoc());
6182 return Result;
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());
6194 if (E.isInvalid())
6195 return QualType();
6197 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6198 if (E.isInvalid())
6199 return QualType();
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())
6206 return QualType();
6208 else E.get();
6210 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6211 NewTL.setTypeofLoc(TL.getTypeofLoc());
6212 NewTL.setLParenLoc(TL.getLParenLoc());
6213 NewTL.setRParenLoc(TL.getRParenLoc());
6215 return Result;
6218 template<typename Derived>
6219 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
6220 TypeOfTypeLoc TL) {
6221 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
6222 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6223 if (!New_Under_TI)
6224 return QualType();
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())
6230 return QualType();
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);
6239 return Result;
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());
6253 if (E.isInvalid())
6254 return QualType();
6256 E = getSema().ActOnDecltypeExpression(E.get());
6257 if (E.isInvalid())
6258 return QualType();
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())
6265 return QualType();
6267 else E.get();
6269 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6270 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6271 NewTL.setRParenLoc(TL.getRParenLoc());
6272 return Result;
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();
6282 QualType NewBase =
6283 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
6284 Result = getDerived().RebuildUnaryTransformType(NewBase,
6285 T->getUTTKind(),
6286 TL.getKWLoc());
6287 if (Result.isNull())
6288 return QualType();
6291 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
6292 NewTL.setKWLoc(TL.getKWLoc());
6293 NewTL.setParensRange(TL.getParensRange());
6294 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
6295 return Result;
6298 template<typename Derived>
6299 QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
6300 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
6301 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
6303 CXXScopeSpec SS;
6304 TemplateName TemplateName = getDerived().TransformTemplateName(
6305 SS, T->getTemplateName(), TL.getTemplateNameLoc());
6306 if (TemplateName.isNull())
6307 return QualType();
6309 QualType OldDeduced = T->getDeducedType();
6310 QualType NewDeduced;
6311 if (!OldDeduced.isNull()) {
6312 NewDeduced = getDerived().TransformType(OldDeduced);
6313 if (NewDeduced.isNull())
6314 return QualType();
6317 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
6318 TemplateName, NewDeduced);
6319 if (Result.isNull())
6320 return QualType();
6322 DeducedTemplateSpecializationTypeLoc NewTL =
6323 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
6324 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6326 return Result;
6329 template<typename Derived>
6330 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
6331 RecordTypeLoc TL) {
6332 const RecordType *T = TL.getTypePtr();
6333 RecordDecl *Record
6334 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6335 T->getDecl()));
6336 if (!Record)
6337 return QualType();
6339 QualType Result = TL.getType();
6340 if (getDerived().AlwaysRebuild() ||
6341 Record != T->getDecl()) {
6342 Result = getDerived().RebuildRecordType(Record);
6343 if (Result.isNull())
6344 return QualType();
6347 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
6348 NewTL.setNameLoc(TL.getNameLoc());
6350 return Result;
6353 template<typename Derived>
6354 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
6355 EnumTypeLoc TL) {
6356 const EnumType *T = TL.getTypePtr();
6357 EnumDecl *Enum
6358 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6359 T->getDecl()));
6360 if (!Enum)
6361 return QualType();
6363 QualType Result = TL.getType();
6364 if (getDerived().AlwaysRebuild() ||
6365 Enum != T->getDecl()) {
6366 Result = getDerived().RebuildEnumType(Enum);
6367 if (Result.isNull())
6368 return QualType();
6371 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
6372 NewTL.setNameLoc(TL.getNameLoc());
6374 return Result;
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());
6387 return T;
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())
6409 return QualType();
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());
6420 return Result;
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.
6439 CXXScopeSpec SS;
6440 TemplateName Template
6441 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
6442 TL.getTemplateNameLoc());
6443 if (Template.isNull())
6444 return QualType();
6446 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
6449 template<typename Derived>
6450 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
6451 AtomicTypeLoc TL) {
6452 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
6453 if (ValueType.isNull())
6454 return QualType();
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())
6461 return QualType();
6464 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
6465 NewTL.setKWLoc(TL.getKWLoc());
6466 NewTL.setLParenLoc(TL.getLParenLoc());
6467 NewTL.setRParenLoc(TL.getRParenLoc());
6469 return Result;
6472 template <typename Derived>
6473 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
6474 PipeTypeLoc TL) {
6475 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
6476 if (ValueType.isNull())
6477 return QualType();
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())
6485 return QualType();
6488 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
6489 NewTL.setKWLoc(TL.getKWLoc());
6491 return Result;
6494 template <typename Derived>
6495 QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
6496 BitIntTypeLoc TL) {
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())
6504 return QualType();
6507 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
6508 NewTL.setNameLoc(TL.getNameLoc());
6509 return Result;
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())
6523 return QualType();
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())
6532 return QualType();
6535 if (isa<DependentBitIntType>(Result)) {
6536 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
6537 NewTL.setNameLoc(TL.getNameLoc());
6538 } else {
6539 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
6540 NewTL.setNameLoc(TL.getNameLoc());
6542 return Result;
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;
6553 unsigned Index;
6555 public:
6556 typedef TemplateArgumentLoc value_type;
6557 typedef TemplateArgumentLoc reference;
6558 typedef int difference_type;
6559 typedef std::input_iterator_tag iterator_category;
6561 class pointer {
6562 TemplateArgumentLoc Arg;
6564 public:
6565 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
6567 const TemplateArgumentLoc *operator->() const {
6568 return &Arg;
6573 TemplateArgumentLocContainerIterator() {}
6575 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
6576 unsigned Index)
6577 : Container(&Container), Index(Index) { }
6579 TemplateArgumentLocContainerIterator &operator++() {
6580 ++Index;
6581 return *this;
6584 TemplateArgumentLocContainerIterator operator++(int) {
6585 TemplateArgumentLocContainerIterator Old(*this);
6586 ++(*this);
6587 return Old;
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) {
6605 return !(X == Y);
6609 template<typename Derived>
6610 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
6611 AutoTypeLoc TL) {
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())
6618 return QualType();
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),
6632 ArgIterator(TL,
6633 TL.getNumArgs()),
6634 NewTemplateArgs))
6635 return QualType();
6637 if (TL.getNestedNameSpecifierLoc()) {
6638 NewNestedNameSpec
6639 = getDerived().TransformNestedNameSpecifierLoc(
6640 TL.getNestedNameSpecifierLoc());
6641 if (!NewNestedNameSpec)
6642 return QualType();
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,
6655 NewArgList);
6656 if (Result.isNull())
6657 return QualType();
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());
6672 return Result;
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>
6684 ArgIterator;
6685 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6686 ArgIterator(TL, TL.getNumArgs()),
6687 NewTemplateArgs))
6688 return QualType();
6690 // FIXME: maybe don't rebuild if all the template arguments are the same.
6692 QualType Result =
6693 getDerived().RebuildTemplateSpecializationType(Template,
6694 TL.getTemplateNameLoc(),
6695 NewTemplateArgs);
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());
6713 return Result;
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());
6726 return Result;
6729 template <typename Derived>
6730 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
6731 TypeLocBuilder &TLB,
6732 DependentTemplateSpecializationTypeLoc TL,
6733 TemplateName Template,
6734 CXXScopeSpec &SS) {
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()),
6742 NewTemplateArgs))
6743 return QualType();
6745 // FIXME: maybe don't rebuild if all the template arguments are the same.
6747 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
6748 QualType Result
6749 = getSema().Context.getDependentTemplateSpecializationType(
6750 TL.getTypePtr()->getKeyword(),
6751 DTN->getQualifier(),
6752 DTN->getIdentifier(),
6753 NewTemplateArgs);
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());
6765 return Result;
6768 QualType Result
6769 = getDerived().RebuildTemplateSpecializationType(Template,
6770 TL.getTemplateNameLoc(),
6771 NewTemplateArgs);
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());
6785 return Result;
6788 template<typename Derived>
6789 QualType
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()) {
6797 QualifierLoc
6798 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6799 if (!QualifierLoc)
6800 return QualType();
6803 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6804 if (NamedT.isNull())
6805 return QualType();
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(),
6831 T->getKeyword(),
6832 QualifierLoc, NamedT);
6833 if (Result.isNull())
6834 return QualType();
6837 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6838 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6839 NewTL.setQualifierLoc(QualifierLoc);
6840 return Result;
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())
6850 return QualType();
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)
6856 return QualType();
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())
6868 return QualType();
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;
6877 return QualType();
6881 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
6882 modifiedType,
6883 equivalentType);
6886 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
6887 newTL.setAttr(newAttr);
6888 return result;
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>
6899 QualType
6900 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6901 ParenTypeLoc TL) {
6902 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6903 if (Inner.isNull())
6904 return QualType();
6906 QualType Result = TL.getType();
6907 if (getDerived().AlwaysRebuild() ||
6908 Inner != TL.getInnerLoc().getType()) {
6909 Result = getDerived().RebuildParenType(Inner);
6910 if (Result.isNull())
6911 return QualType();
6914 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6915 NewTL.setLParenLoc(TL.getLParenLoc());
6916 NewTL.setRParenLoc(TL.getRParenLoc());
6917 return Result;
6920 template <typename Derived>
6921 QualType
6922 TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
6923 MacroQualifiedTypeLoc TL) {
6924 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6925 if (Inner.isNull())
6926 return QualType();
6928 QualType Result = TL.getType();
6929 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
6930 Result =
6931 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
6932 if (Result.isNull())
6933 return QualType();
6936 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
6937 NewTL.setExpansionLoc(TL.getExpansionLoc());
6938 return Result;
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());
6954 if (!QualifierLoc)
6955 return QualType();
6957 QualType Result
6958 = getDerived().RebuildDependentNameType(T->getKeyword(),
6959 TL.getElaboratedKeywordLoc(),
6960 QualifierLoc,
6961 T->getIdentifier(),
6962 TL.getNameLoc(),
6963 DeducedTSTContext);
6964 if (Result.isNull())
6965 return QualType();
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);
6974 } else {
6975 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
6976 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6977 NewTL.setQualifierLoc(QualifierLoc);
6978 NewTL.setNameLoc(TL.getNameLoc());
6980 return Result;
6983 template<typename Derived>
6984 QualType TreeTransform<Derived>::
6985 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6986 DependentTemplateSpecializationTypeLoc TL) {
6987 NestedNameSpecifierLoc QualifierLoc;
6988 if (TL.getQualifierLoc()) {
6989 QualifierLoc
6990 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6991 if (!QualifierLoc)
6992 return QualType();
6995 return getDerived()
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()),
7014 NewTemplateArgs))
7015 return QualType();
7017 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
7018 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
7019 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
7020 /*AllowInjectedClassName*/ false);
7021 if (Result.isNull())
7022 return QualType();
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());
7052 } else {
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());
7062 return Result;
7065 template<typename Derived>
7066 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
7067 PackExpansionTypeLoc TL) {
7068 QualType Pattern
7069 = getDerived().TransformType(TLB, TL.getPatternLoc());
7070 if (Pattern.isNull())
7071 return QualType();
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())
7081 return QualType();
7084 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
7085 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7086 return Result;
7089 template<typename Derived>
7090 QualType
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>
7099 QualType
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()));
7105 if (!OTP)
7106 return QualType();
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())
7118 return QualType();
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());
7128 return Result;
7131 template<typename Derived>
7132 QualType
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())
7138 return QualType();
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>()) {
7149 AnyChanged = true;
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(),
7156 Unexpanded);
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))
7168 return QualType();
7170 if (!Expand) {
7171 // We can't expand this pack expansion into separate arguments yet;
7172 // just substitute into the pattern and create a new pack expansion
7173 // type.
7174 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7176 TypeLocBuilder TypeArgBuilder;
7177 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7178 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7179 PatternLoc);
7180 if (NewPatternType.isNull())
7181 return QualType();
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));
7189 continue;
7192 // Substitute into the pack expansion pattern for each slice of the
7193 // pack.
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,
7201 PatternLoc);
7202 if (NewTypeArg.isNull())
7203 return QualType();
7205 NewTypeArgInfos.push_back(
7206 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7209 continue;
7212 TypeLocBuilder TypeArgBuilder;
7213 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7214 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7215 if (NewTypeArg.isNull())
7216 return QualType();
7218 // If nothing changed, just keep the old TypeSourceInfo.
7219 if (NewTypeArg == TypeArg) {
7220 NewTypeArgInfos.push_back(TypeArgInfo);
7221 continue;
7224 NewTypeArgInfos.push_back(
7225 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7226 AnyChanged = true;
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())
7239 return QualType();
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());
7252 return Result;
7255 template<typename Derived>
7256 QualType
7257 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
7258 ObjCObjectPointerTypeLoc TL) {
7259 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7260 if (PointeeType.isNull())
7261 return QualType();
7263 QualType Result = TL.getType();
7264 if (getDerived().AlwaysRebuild() ||
7265 PointeeType != TL.getPointeeLoc().getType()) {
7266 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7267 TL.getStarLoc());
7268 if (Result.isNull())
7269 return QualType();
7272 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
7273 NewT.setStarLoc(TL.getStarLoc());
7274 return Result;
7277 //===----------------------------------------------------------------------===//
7278 // Statement transformation
7279 //===----------------------------------------------------------------------===//
7280 template<typename Derived>
7281 StmtResult
7282 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
7283 return S;
7286 template<typename Derived>
7287 StmtResult
7288 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
7289 return getDerived().TransformCompoundStmt(S, false);
7292 template<typename Derived>
7293 StmtResult
7294 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
7295 bool IsStmtExpr) {
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))
7310 return StmtError();
7312 // Otherwise, just keep processing substatements and fail later.
7313 SubStmtInvalid = true;
7314 continue;
7317 SubStmtChanged = SubStmtChanged || Result.get() != B;
7318 Statements.push_back(Result.getAs<Stmt>());
7321 if (SubStmtInvalid)
7322 return StmtError();
7324 if (!getDerived().AlwaysRebuild() &&
7325 !SubStmtChanged)
7326 return S;
7328 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
7329 Statements,
7330 S->getRBracLoc(),
7331 IsStmtExpr);
7334 template<typename Derived>
7335 StmtResult
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())
7346 return StmtError();
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())
7352 return StmtError();
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(),
7359 LHS.get(),
7360 S->getEllipsisLoc(),
7361 RHS.get(),
7362 S->getColonLoc());
7363 if (Case.isInvalid())
7364 return StmtError();
7366 // Transform the statement following the case
7367 StmtResult SubStmt =
7368 getDerived().TransformStmt(S->getSubStmt());
7369 if (SubStmt.isInvalid())
7370 return StmtError();
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())
7382 return StmtError();
7384 // Default statements are always rebuilt
7385 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
7386 SubStmt.get());
7389 template<typename Derived>
7390 StmtResult
7391 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
7392 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
7393 if (SubStmt.isInvalid())
7394 return StmtError();
7396 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
7397 S->getDecl());
7398 if (!LD)
7399 return StmtError();
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(),
7410 SubStmt.get());
7413 template <typename Derived>
7414 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
7415 if (!R)
7416 return R;
7418 switch (R->getKind()) {
7419 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
7420 #define ATTR(X)
7421 #define PRAGMA_SPELLING_ATTR(X) \
7422 case attr::X: \
7423 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
7424 #include "clang/Basic/AttrList.inc"
7425 default:
7426 return R;
7430 template <typename Derived>
7431 StmtResult
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);
7441 if (R)
7442 Attrs.push_back(R);
7445 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
7446 if (SubStmt.isInvalid())
7447 return StmtError();
7449 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
7450 return S;
7452 // If transforming the attributes failed for all of the attributes in the
7453 // statement, don't make an AttributedStmt without attributes.
7454 if (Attrs.empty())
7455 return SubStmt;
7457 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
7458 SubStmt.get());
7461 template<typename Derived>
7462 StmtResult
7463 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
7464 // Transform the initialization statement
7465 StmtResult Init = getDerived().TransformStmt(S->getInit());
7466 if (Init.isInvalid())
7467 return StmtError();
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())
7477 return StmtError();
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.
7486 StmtResult Then;
7487 if (!ConstexprConditionValue || *ConstexprConditionValue) {
7488 Then = getDerived().TransformStmt(S->getThen());
7489 if (Then.isInvalid())
7490 return StmtError();
7491 } else {
7492 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
7495 // Transform the "else" branch.
7496 StmtResult Else;
7497 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
7498 Else = getDerived().TransformStmt(S->getElse());
7499 if (Else.isInvalid())
7500 return StmtError();
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())
7508 return S;
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>
7516 StmtResult
7517 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
7518 // Transform the initialization statement
7519 StmtResult Init = getDerived().TransformStmt(S->getInit());
7520 if (Init.isInvalid())
7521 return StmtError();
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())
7528 return StmtError();
7530 // Rebuild the switch statement.
7531 StmtResult Switch =
7532 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
7533 Init.get(), Cond, S->getRParenLoc());
7534 if (Switch.isInvalid())
7535 return StmtError();
7537 // Transform the body of the switch statement.
7538 StmtResult Body = getDerived().TransformStmt(S->getBody());
7539 if (Body.isInvalid())
7540 return StmtError();
7542 // Complete the switch statement.
7543 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
7544 Body.get());
7547 template<typename Derived>
7548 StmtResult
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())
7555 return StmtError();
7557 // Transform the body
7558 StmtResult Body = getDerived().TransformStmt(S->getBody());
7559 if (Body.isInvalid())
7560 return StmtError();
7562 if (!getDerived().AlwaysRebuild() &&
7563 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
7564 Body.get() == S->getBody())
7565 return Owned(S);
7567 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
7568 Cond, S->getRParenLoc(), Body.get());
7571 template<typename Derived>
7572 StmtResult
7573 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
7574 // Transform the body
7575 StmtResult Body = getDerived().TransformStmt(S->getBody());
7576 if (Body.isInvalid())
7577 return StmtError();
7579 // Transform the condition
7580 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7581 if (Cond.isInvalid())
7582 return StmtError();
7584 if (!getDerived().AlwaysRebuild() &&
7585 Cond.get() == S->getCond() &&
7586 Body.get() == S->getBody())
7587 return S;
7589 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
7590 /*FIXME:*/S->getWhileLoc(), Cond.get(),
7591 S->getRParenLoc());
7594 template<typename Derived>
7595 StmtResult
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())
7603 return StmtError();
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())
7615 return StmtError();
7617 // Transform the increment
7618 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7619 if (Inc.isInvalid())
7620 return StmtError();
7622 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
7623 if (S->getInc() && !FullInc.get())
7624 return StmtError();
7626 // Transform the body
7627 StmtResult Body = getDerived().TransformStmt(S->getBody());
7628 if (Body.isInvalid())
7629 return StmtError();
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())
7636 return S;
7638 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
7639 Init.get(), Cond, FullInc,
7640 S->getRParenLoc(), Body.get());
7643 template<typename Derived>
7644 StmtResult
7645 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
7646 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
7647 S->getLabel());
7648 if (!LD)
7649 return StmtError();
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>
7657 StmtResult
7658 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
7659 ExprResult Target = getDerived().TransformExpr(S->getTarget());
7660 if (Target.isInvalid())
7661 return StmtError();
7662 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
7664 if (!getDerived().AlwaysRebuild() &&
7665 Target.get() == S->getTarget())
7666 return S;
7668 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
7669 Target.get());
7672 template<typename Derived>
7673 StmtResult
7674 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
7675 return S;
7678 template<typename Derived>
7679 StmtResult
7680 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
7681 return S;
7684 template<typename Derived>
7685 StmtResult
7686 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
7687 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
7688 /*NotCopyInit*/false);
7689 if (Result.isInvalid())
7690 return StmtError();
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>
7698 StmtResult
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);
7704 if (!Transformed)
7705 return StmtError();
7707 if (Transformed != D)
7708 DeclChanged = true;
7710 Decls.push_back(Transformed);
7713 if (!getDerived().AlwaysRebuild() && !DeclChanged)
7714 return S;
7716 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
7719 template<typename Derived>
7720 StmtResult
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())
7743 return StmtError();
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())
7761 return StmtError();
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())
7774 return StmtError();
7775 ExprsChanged |= Result.get() != S->getLabelExpr(I);
7776 Exprs.push_back(Result.get());
7778 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
7779 return S;
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(),
7792 S->getRParenLoc());
7795 template<typename Derived>
7796 StmtResult
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()) {
7809 HadError = true;
7810 } else {
7811 HadChange |= (Result.get() != SrcExprs[i]);
7812 TransformedExprs.push_back(Result.get());
7816 if (HadError) return StmtError();
7817 if (!HadChange && !getDerived().AlwaysRebuild())
7818 return Owned(S);
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>
7830 StmtResult
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
7841 // that may fail.
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()))
7851 return StmtError();
7852 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7853 if (!Promise)
7854 return StmtError();
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())
7863 return StmtError();
7864 StmtResult FinalSuspend =
7865 getDerived().TransformStmt(S->getFinalSuspendStmt());
7866 if (FinalSuspend.isInvalid() ||
7867 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
7868 return StmtError();
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())
7874 return StmtError();
7876 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7877 if (Builder.isInvalid())
7878 return StmtError();
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())
7885 return StmtError();
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())
7899 return StmtError();
7901 } else {
7902 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7903 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7904 if (Res.isInvalid())
7905 return StmtError();
7906 Builder.OnFallthrough = Res.get();
7909 if (auto *OnException = S->getExceptionHandler()) {
7910 StmtResult Res = getDerived().TransformStmt(OnException);
7911 if (Res.isInvalid())
7912 return StmtError();
7913 Builder.OnException = Res.get();
7916 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7917 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7918 if (Res.isInvalid())
7919 return StmtError();
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())
7928 return StmtError();
7929 Builder.Allocate = AllocRes.get();
7931 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7932 if (DeallocRes.isInvalid())
7933 return StmtError();
7934 Builder.Deallocate = DeallocRes.get();
7936 if (auto *ReturnStmt = S->getReturnStmt()) {
7937 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7938 if (Res.isInvalid())
7939 return StmtError();
7940 Builder.ReturnStmt = Res.get();
7944 return getDerived().RebuildCoroutineBodyStmt(Builder);
7947 template<typename Derived>
7948 StmtResult
7949 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7950 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7951 /*NotCopyInit*/false);
7952 if (Result.isInvalid())
7953 return StmtError();
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(),
7958 S->isImplicit());
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())
7966 return ExprError();
7968 // Rebuild the common-expr from the operand rather than transforming it
7969 // separately.
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>
7985 ExprResult
7986 TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7987 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7988 /*NotCopyInit*/ false);
7989 if (OperandResult.isInvalid())
7990 return ExprError();
7992 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7993 E->getOperatorCoawaitLookup());
7995 if (LookupResult.isInvalid())
7996 return ExprError();
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>
8006 ExprResult
8007 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
8008 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8009 /*NotCopyInit*/false);
8010 if (Result.isInvalid())
8011 return ExprError();
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>
8021 StmtResult
8022 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
8023 // Transform the body of the @try.
8024 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8025 if (TryBody.isInvalid())
8026 return StmtError();
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())
8034 return StmtError();
8035 if (Catch.get() != S->getCatchStmt(I))
8036 AnyCatchChanged = true;
8037 CatchStmts.push_back(Catch.get());
8040 // Transform the @finally statement (if present).
8041 StmtResult Finally;
8042 if (S->getFinallyStmt()) {
8043 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8044 if (Finally.isInvalid())
8045 return StmtError();
8048 // If nothing changed, just retain this statement.
8049 if (!getDerived().AlwaysRebuild() &&
8050 TryBody.get() == S->getTryBody() &&
8051 !AnyCatchChanged &&
8052 Finally.get() == S->getFinallyStmt())
8053 return S;
8055 // Build a new statement.
8056 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8057 CatchStmts, Finally.get());
8060 template<typename Derived>
8061 StmtResult
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());
8069 if (!TSInfo)
8070 return StmtError();
8073 QualType T;
8074 if (TSInfo)
8075 T = TSInfo->getType();
8076 else {
8077 T = getDerived().TransformType(FromVar->getType());
8078 if (T.isNull())
8079 return StmtError();
8082 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8083 if (!Var)
8084 return StmtError();
8087 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8088 if (Body.isInvalid())
8089 return StmtError();
8091 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8092 S->getRParenLoc(),
8093 Var, Body.get());
8096 template<typename Derived>
8097 StmtResult
8098 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
8099 // Transform the body.
8100 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8101 if (Body.isInvalid())
8102 return StmtError();
8104 // If nothing changed, just retain this statement.
8105 if (!getDerived().AlwaysRebuild() &&
8106 Body.get() == S->getFinallyBody())
8107 return S;
8109 // Build a new statement.
8110 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8111 Body.get());
8114 template<typename Derived>
8115 StmtResult
8116 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
8117 ExprResult Operand;
8118 if (S->getThrowExpr()) {
8119 Operand = getDerived().TransformExpr(S->getThrowExpr());
8120 if (Operand.isInvalid())
8121 return StmtError();
8124 if (!getDerived().AlwaysRebuild() &&
8125 Operand.get() == S->getThrowExpr())
8126 return S;
8128 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8131 template<typename Derived>
8132 StmtResult
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())
8138 return StmtError();
8139 Object =
8140 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8141 Object.get());
8142 if (Object.isInvalid())
8143 return StmtError();
8145 // Transform the body.
8146 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8147 if (Body.isInvalid())
8148 return StmtError();
8150 // If nothing change, just retain the current statement.
8151 if (!getDerived().AlwaysRebuild() &&
8152 Object.get() == S->getSynchExpr() &&
8153 Body.get() == S->getSynchBody())
8154 return S;
8156 // Build a new statement.
8157 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
8158 Object.get(), Body.get());
8161 template<typename Derived>
8162 StmtResult
8163 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
8164 ObjCAutoreleasePoolStmt *S) {
8165 // Transform the body.
8166 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
8167 if (Body.isInvalid())
8168 return StmtError();
8170 // If nothing changed, just retain this statement.
8171 if (!getDerived().AlwaysRebuild() &&
8172 Body.get() == S->getSubStmt())
8173 return S;
8175 // Build a new statement.
8176 return getDerived().RebuildObjCAutoreleasePoolStmt(
8177 S->getAtLoc(), Body.get());
8180 template<typename Derived>
8181 StmtResult
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())
8188 return StmtError();
8190 // Transform the collection expression.
8191 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
8192 if (Collection.isInvalid())
8193 return StmtError();
8195 // Transform the body.
8196 StmtResult Body = getDerived().TransformStmt(S->getBody());
8197 if (Body.isInvalid())
8198 return StmtError();
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())
8205 return S;
8207 // Build a new statement.
8208 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
8209 Element.get(),
8210 Collection.get(),
8211 S->getRParenLoc(),
8212 Body.get());
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()) {
8220 TypeSourceInfo *T =
8221 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
8222 if (!T)
8223 return StmtError();
8225 Var = getDerived().RebuildExceptionDecl(
8226 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
8227 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
8228 if (!Var || Var->isInvalidDecl())
8229 return StmtError();
8232 // Transform the actual exception handler.
8233 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
8234 if (Handler.isInvalid())
8235 return StmtError();
8237 if (!getDerived().AlwaysRebuild() && !Var &&
8238 Handler.get() == S->getHandlerBlock())
8239 return S;
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())
8249 return StmtError();
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())
8257 return StmtError();
8259 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
8260 Handlers.push_back(Handler.getAs<Stmt>());
8263 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
8264 !HandlerChanged)
8265 return S;
8267 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
8268 Handlers);
8271 template<typename Derived>
8272 StmtResult
8273 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
8274 StmtResult Init =
8275 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
8276 if (Init.isInvalid())
8277 return StmtError();
8279 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
8280 if (Range.isInvalid())
8281 return StmtError();
8283 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
8284 if (Begin.isInvalid())
8285 return StmtError();
8286 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
8287 if (End.isInvalid())
8288 return StmtError();
8290 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8291 if (Cond.isInvalid())
8292 return StmtError();
8293 if (Cond.get())
8294 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
8295 if (Cond.isInvalid())
8296 return StmtError();
8297 if (Cond.get())
8298 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
8300 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8301 if (Inc.isInvalid())
8302 return StmtError();
8303 if (Inc.get())
8304 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
8306 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
8307 if (LoopVar.isInvalid())
8308 return StmtError();
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(),
8323 Cond.get(),
8324 Inc.get(), LoopVar.get(),
8325 S->getRParenLoc());
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());
8330 return StmtError();
8334 StmtResult Body = getDerived().TransformStmt(S->getBody());
8335 if (Body.isInvalid())
8336 return StmtError();
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(),
8345 Cond.get(),
8346 Inc.get(), LoopVar.get(),
8347 S->getRParenLoc());
8348 if (NewStmt.isInvalid())
8349 return StmtError();
8352 if (NewStmt.get() == S)
8353 return S;
8355 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
8358 template<typename Derived>
8359 StmtResult
8360 TreeTransform<Derived>::TransformMSDependentExistsStmt(
8361 MSDependentExistsStmt *S) {
8362 // Transform the nested-name-specifier, if any.
8363 NestedNameSpecifierLoc QualifierLoc;
8364 if (S->getQualifierLoc()) {
8365 QualifierLoc
8366 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
8367 if (!QualifierLoc)
8368 return StmtError();
8371 // Transform the declaration name.
8372 DeclarationNameInfo NameInfo = S->getNameInfo();
8373 if (NameInfo.getName()) {
8374 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8375 if (!NameInfo.getName())
8376 return StmtError();
8379 // Check whether anything changed.
8380 if (!getDerived().AlwaysRebuild() &&
8381 QualifierLoc == S->getQualifierLoc() &&
8382 NameInfo.getName() == S->getNameInfo().getName())
8383 return S;
8385 // Determine whether this name exists, if we can.
8386 CXXScopeSpec SS;
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())
8392 break;
8394 return new (getSema().Context) NullStmt(S->getKeywordLoc());
8396 case Sema::IER_DoesNotExist:
8397 if (S->isIfNotExists())
8398 break;
8400 return new (getSema().Context) NullStmt(S->getKeywordLoc());
8402 case Sema::IER_Dependent:
8403 Dependent = true;
8404 break;
8406 case Sema::IER_Error:
8407 return StmtError();
8410 // We need to continue with the instantiation, so do so now.
8411 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
8412 if (SubStmt.isInvalid())
8413 return StmtError();
8415 // If we have resolved the name, just transform to the substatement.
8416 if (!Dependent)
8417 return SubStmt;
8419 // The name is still dependent, so build a dependent expression again.
8420 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
8421 S->isIfExists(),
8422 QualifierLoc,
8423 NameInfo,
8424 SubStmt.get());
8427 template<typename Derived>
8428 ExprResult
8429 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
8430 NestedNameSpecifierLoc QualifierLoc;
8431 if (E->getQualifierLoc()) {
8432 QualifierLoc
8433 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8434 if (!QualifierLoc)
8435 return ExprError();
8438 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
8439 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
8440 if (!PD)
8441 return ExprError();
8443 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8444 if (Base.isInvalid())
8445 return ExprError();
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())
8458 return ExprError();
8459 auto IdxRes = getDerived().TransformExpr(E->getIdx());
8460 if (IdxRes.isInvalid())
8461 return ExprError();
8463 if (!getDerived().AlwaysRebuild() &&
8464 BaseRes.get() == E->getBase() &&
8465 IdxRes.get() == E->getIdx())
8466 return E;
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())
8476 return StmtError();
8478 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
8479 if (Handler.isInvalid())
8480 return StmtError();
8482 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
8483 Handler.get() == S->getHandler())
8484 return S;
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())
8494 return StmtError();
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())
8503 return StmtError();
8505 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
8506 if (Block.isInvalid())
8507 return StmtError();
8509 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
8510 Block.get());
8513 template <typename Derived>
8514 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
8515 if (isa<SEHFinallyStmt>(Handler))
8516 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
8517 else
8518 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
8521 template<typename Derived>
8522 StmtResult
8523 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
8524 return S;
8527 //===----------------------------------------------------------------------===//
8528 // OpenMP directive transformation
8529 //===----------------------------------------------------------------------===//
8531 template <typename Derived>
8532 StmtResult
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();
8549 I != E; ++I) {
8550 if (*I) {
8551 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
8552 OMPClause *Clause = getDerived().TransformOMPClause(*I);
8553 getDerived().getSema().EndOpenMPClause();
8554 if (Clause)
8555 TClauses.push_back(Clause);
8556 } else {
8557 TClauses.push_back(nullptr);
8560 StmtResult AssociatedStmt;
8561 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
8562 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
8563 /*CurScope=*/nullptr);
8564 StmtResult Body;
8566 Sema::CompoundScopeRAII CompoundScope(getSema());
8567 Stmt *CS;
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();
8573 else
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());
8580 AssociatedStmt =
8581 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
8582 if (AssociatedStmt.isInvalid()) {
8583 return StmtError();
8586 if (TClauses.size() != Clauses.size()) {
8587 return StmtError();
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>
8609 StmtResult
8610 TreeTransform<Derived>::TransformOMPMetaDirective(OMPMetaDirective *D) {
8611 // TODO: Fix This
8612 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
8613 << getOpenMPDirectiveName(D->getDirectiveKind());
8614 return StmtError();
8617 template <typename Derived>
8618 StmtResult
8619 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
8620 DeclarationNameInfo DirName;
8621 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
8622 D->getBeginLoc());
8623 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8624 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8625 return Res;
8628 template <typename Derived>
8629 StmtResult
8630 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
8631 DeclarationNameInfo DirName;
8632 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
8633 D->getBeginLoc());
8634 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8635 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8636 return Res;
8639 template <typename Derived>
8640 StmtResult
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());
8647 return Res;
8650 template <typename Derived>
8651 StmtResult
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());
8658 return Res;
8661 template <typename Derived>
8662 StmtResult
8663 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
8664 DeclarationNameInfo DirName;
8665 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
8666 D->getBeginLoc());
8667 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8668 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8669 return Res;
8672 template <typename Derived>
8673 StmtResult
8674 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
8675 DeclarationNameInfo DirName;
8676 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
8677 D->getBeginLoc());
8678 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8679 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8680 return Res;
8683 template <typename Derived>
8684 StmtResult
8685 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
8686 DeclarationNameInfo DirName;
8687 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
8688 D->getBeginLoc());
8689 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8690 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8691 return Res;
8694 template <typename Derived>
8695 StmtResult
8696 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
8697 DeclarationNameInfo DirName;
8698 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
8699 D->getBeginLoc());
8700 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8701 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8702 return Res;
8705 template <typename Derived>
8706 StmtResult
8707 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
8708 DeclarationNameInfo DirName;
8709 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
8710 D->getBeginLoc());
8711 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8712 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8713 return Res;
8716 template <typename Derived>
8717 StmtResult
8718 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
8719 DeclarationNameInfo DirName;
8720 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
8721 D->getBeginLoc());
8722 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8723 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8724 return Res;
8727 template <typename Derived>
8728 StmtResult
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());
8734 return Res;
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());
8745 return Res;
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());
8756 return Res;
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());
8767 return Res;
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());
8778 return Res;
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());
8789 return Res;
8792 template <typename Derived>
8793 StmtResult
8794 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
8795 DeclarationNameInfo DirName;
8796 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
8797 D->getBeginLoc());
8798 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8799 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8800 return Res;
8803 template <typename Derived>
8804 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
8805 OMPTaskyieldDirective *D) {
8806 DeclarationNameInfo DirName;
8807 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
8808 D->getBeginLoc());
8809 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8810 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8811 return Res;
8814 template <typename Derived>
8815 StmtResult
8816 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
8817 DeclarationNameInfo DirName;
8818 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
8819 D->getBeginLoc());
8820 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8821 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8822 return Res;
8825 template <typename Derived>
8826 StmtResult
8827 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
8828 DeclarationNameInfo DirName;
8829 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
8830 D->getBeginLoc());
8831 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8832 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8833 return Res;
8836 template <typename Derived>
8837 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
8838 OMPTaskgroupDirective *D) {
8839 DeclarationNameInfo DirName;
8840 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
8841 D->getBeginLoc());
8842 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8843 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8844 return Res;
8847 template <typename Derived>
8848 StmtResult
8849 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
8850 DeclarationNameInfo DirName;
8851 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
8852 D->getBeginLoc());
8853 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8854 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8855 return Res;
8858 template <typename Derived>
8859 StmtResult
8860 TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
8861 DeclarationNameInfo DirName;
8862 getDerived().getSema().StartOpenMPDSABlock(OMPD_depobj, DirName, nullptr,
8863 D->getBeginLoc());
8864 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8865 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8866 return Res;
8869 template <typename Derived>
8870 StmtResult
8871 TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
8872 DeclarationNameInfo DirName;
8873 getDerived().getSema().StartOpenMPDSABlock(OMPD_scan, DirName, nullptr,
8874 D->getBeginLoc());
8875 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8876 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8877 return Res;
8880 template <typename Derived>
8881 StmtResult
8882 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
8883 DeclarationNameInfo DirName;
8884 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
8885 D->getBeginLoc());
8886 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8887 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8888 return Res;
8891 template <typename Derived>
8892 StmtResult
8893 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
8894 DeclarationNameInfo DirName;
8895 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
8896 D->getBeginLoc());
8897 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8898 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8899 return Res;
8902 template <typename Derived>
8903 StmtResult
8904 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
8905 DeclarationNameInfo DirName;
8906 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
8907 D->getBeginLoc());
8908 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8909 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8910 return Res;
8913 template <typename Derived>
8914 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
8915 OMPTargetDataDirective *D) {
8916 DeclarationNameInfo DirName;
8917 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
8918 D->getBeginLoc());
8919 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8920 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8921 return Res;
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());
8932 return Res;
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());
8943 return Res;
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());
8954 return Res;
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());
8965 return Res;
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());
8976 return Res;
8979 template <typename Derived>
8980 StmtResult
8981 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8982 DeclarationNameInfo DirName;
8983 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
8984 D->getBeginLoc());
8985 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8986 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8987 return Res;
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());
8998 return Res;
9001 template <typename Derived>
9002 StmtResult
9003 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
9004 DeclarationNameInfo DirName;
9005 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
9006 D->getBeginLoc());
9007 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9008 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9009 return Res;
9012 template <typename Derived>
9013 StmtResult
9014 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
9015 DeclarationNameInfo DirName;
9016 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
9017 D->getBeginLoc());
9018 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9019 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9020 return Res;
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());
9031 return Res;
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());
9042 return Res;
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());
9053 return Res;
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());
9064 return Res;
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());
9075 return Res;
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());
9086 return Res;
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());
9097 return Res;
9100 template <typename Derived>
9101 StmtResult
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());
9109 return Res;
9112 template <typename Derived>
9113 StmtResult
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());
9121 return Res;
9124 template <typename Derived>
9125 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
9126 OMPDistributeDirective *D) {
9127 DeclarationNameInfo DirName;
9128 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
9129 D->getBeginLoc());
9130 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9131 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9132 return Res;
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());
9143 return Res;
9146 template <typename Derived>
9147 StmtResult
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());
9155 return Res;
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());
9166 return Res;
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());
9177 return Res;
9180 template <typename Derived>
9181 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
9182 OMPTargetSimdDirective *D) {
9183 DeclarationNameInfo DirName;
9184 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
9185 D->getBeginLoc());
9186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9188 return Res;
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());
9199 return Res;
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());
9210 return Res;
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,
9219 D->getBeginLoc());
9220 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9221 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9222 return Res;
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());
9233 return Res;
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());
9244 return Res;
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());
9255 return Res;
9258 template <typename Derived>
9259 StmtResult
9260 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
9261 OMPTargetTeamsDistributeParallelForDirective *D) {
9262 DeclarationNameInfo DirName;
9263 getDerived().getSema().StartOpenMPDSABlock(
9264 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
9265 D->getBeginLoc());
9266 auto Res = getDerived().TransformOMPExecutableDirective(D);
9267 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9268 return Res;
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,
9278 D->getBeginLoc());
9279 auto Res = getDerived().TransformOMPExecutableDirective(D);
9280 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9281 return Res;
9284 template <typename Derived>
9285 StmtResult
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());
9293 return Res;
9296 template <typename Derived>
9297 StmtResult
9298 TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
9299 DeclarationNameInfo DirName;
9300 getDerived().getSema().StartOpenMPDSABlock(OMPD_interop, DirName, nullptr,
9301 D->getBeginLoc());
9302 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9303 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9304 return Res;
9307 template <typename Derived>
9308 StmtResult
9309 TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
9310 DeclarationNameInfo DirName;
9311 getDerived().getSema().StartOpenMPDSABlock(OMPD_dispatch, DirName, nullptr,
9312 D->getBeginLoc());
9313 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9314 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9315 return Res;
9318 template <typename Derived>
9319 StmtResult
9320 TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
9321 DeclarationNameInfo DirName;
9322 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked, DirName, nullptr,
9323 D->getBeginLoc());
9324 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9325 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9326 return Res;
9329 template <typename Derived>
9330 StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
9331 OMPGenericLoopDirective *D) {
9332 DeclarationNameInfo DirName;
9333 getDerived().getSema().StartOpenMPDSABlock(OMPD_loop, DirName, nullptr,
9334 D->getBeginLoc());
9335 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9336 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9337 return Res;
9340 template <typename Derived>
9341 StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective(
9342 OMPTeamsGenericLoopDirective *D) {
9343 DeclarationNameInfo DirName;
9344 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_loop, DirName, nullptr,
9345 D->getBeginLoc());
9346 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9347 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9348 return Res;
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());
9359 return Res;
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());
9370 return Res;
9373 template <typename Derived>
9374 StmtResult
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());
9382 return Res;
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())
9392 return nullptr;
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())
9402 return nullptr;
9403 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
9404 C->getLParenLoc(), C->getEndLoc());
9407 template <typename Derived>
9408 OMPClause *
9409 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
9410 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
9411 if (NumThreads.isInvalid())
9412 return nullptr;
9413 return getDerived().RebuildOMPNumThreadsClause(
9414 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9417 template <typename Derived>
9418 OMPClause *
9419 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
9420 ExprResult E = getDerived().TransformExpr(C->getSafelen());
9421 if (E.isInvalid())
9422 return nullptr;
9423 return getDerived().RebuildOMPSafelenClause(
9424 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9427 template <typename Derived>
9428 OMPClause *
9429 TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
9430 ExprResult E = getDerived().TransformExpr(C->getAllocator());
9431 if (E.isInvalid())
9432 return nullptr;
9433 return getDerived().RebuildOMPAllocatorClause(
9434 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9437 template <typename Derived>
9438 OMPClause *
9439 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
9440 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
9441 if (E.isInvalid())
9442 return nullptr;
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()) {
9453 if (!E) {
9454 TransformedSizes.push_back(nullptr);
9455 continue;
9458 ExprResult T = getDerived().TransformExpr(E);
9459 if (T.isInvalid())
9460 return nullptr;
9461 if (E != T.get())
9462 Changed = true;
9463 TransformedSizes.push_back(T.get());
9466 if (!Changed && !getDerived().AlwaysRebuild())
9467 return C;
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())
9475 return C;
9476 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
9479 template <typename Derived>
9480 OMPClause *
9481 TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
9482 ExprResult T = getDerived().TransformExpr(C->getFactor());
9483 if (T.isInvalid())
9484 return nullptr;
9485 Expr *Factor = T.get();
9486 bool Changed = Factor != C->getFactor();
9488 if (!Changed && !getDerived().AlwaysRebuild())
9489 return C;
9490 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
9491 C->getEndLoc());
9494 template <typename Derived>
9495 OMPClause *
9496 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
9497 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
9498 if (E.isInvalid())
9499 return nullptr;
9500 return getDerived().RebuildOMPCollapseClause(
9501 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9504 template <typename Derived>
9505 OMPClause *
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>
9513 OMPClause *
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>
9521 OMPClause *
9522 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
9523 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
9524 if (E.isInvalid())
9525 return nullptr;
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>
9534 OMPClause *
9535 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
9536 ExprResult E;
9537 if (auto *Num = C->getNumForLoops()) {
9538 E = getDerived().TransformExpr(Num);
9539 if (E.isInvalid())
9540 return nullptr;
9542 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
9543 C->getLParenLoc(), E.get());
9546 template <typename Derived>
9547 OMPClause *
9548 TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
9549 ExprResult E;
9550 if (Expr *Evt = C->getEventHandler()) {
9551 E = getDerived().TransformExpr(Evt);
9552 if (E.isInvalid())
9553 return nullptr;
9555 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
9556 C->getLParenLoc(), C->getEndLoc());
9559 template <typename Derived>
9560 OMPClause *
9561 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
9562 // No need to rebuild this clause, no template-dependent parameters.
9563 return C;
9566 template <typename Derived>
9567 OMPClause *
9568 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
9569 // No need to rebuild this clause, no template-dependent parameters.
9570 return C;
9573 template <typename Derived>
9574 OMPClause *
9575 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
9576 // No need to rebuild this clause, no template-dependent parameters.
9577 return C;
9580 template <typename Derived>
9581 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
9582 // No need to rebuild this clause, no template-dependent parameters.
9583 return C;
9586 template <typename Derived>
9587 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
9588 // No need to rebuild this clause, no template-dependent parameters.
9589 return C;
9592 template <typename Derived>
9593 OMPClause *
9594 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
9595 // No need to rebuild this clause, no template-dependent parameters.
9596 return C;
9599 template <typename Derived>
9600 OMPClause *
9601 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
9602 // No need to rebuild this clause, no template-dependent parameters.
9603 return C;
9606 template <typename Derived>
9607 OMPClause *
9608 TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
9609 // No need to rebuild this clause, no template-dependent parameters.
9610 return C;
9613 template <typename Derived>
9614 OMPClause *
9615 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
9616 // No need to rebuild this clause, no template-dependent parameters.
9617 return C;
9620 template <typename Derived>
9621 OMPClause *
9622 TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
9623 // No need to rebuild this clause, no template-dependent parameters.
9624 return C;
9627 template <typename Derived>
9628 OMPClause *
9629 TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
9630 // No need to rebuild this clause, no template-dependent parameters.
9631 return C;
9634 template <typename Derived>
9635 OMPClause *
9636 TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
9637 // No need to rebuild this clause, no template-dependent parameters.
9638 return C;
9641 template <typename Derived>
9642 OMPClause *
9643 TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
9644 // No need to rebuild this clause, no template-dependent parameters.
9645 return C;
9648 template <typename Derived>
9649 OMPClause *
9650 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
9651 // No need to rebuild this clause, no template-dependent parameters.
9652 return C;
9655 template <typename Derived>
9656 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
9657 // No need to rebuild this clause, no template-dependent parameters.
9658 return C;
9661 template <typename Derived>
9662 OMPClause *
9663 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
9664 // No need to rebuild this clause, no template-dependent parameters.
9665 return C;
9668 template <typename Derived>
9669 OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
9670 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
9671 if (IVR.isInvalid())
9672 return nullptr;
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));
9678 if (ER.isInvalid())
9679 return nullptr;
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());
9690 if (ER.isInvalid())
9691 return nullptr;
9692 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
9693 C->getLParenLoc(), C->getVarLoc(),
9694 C->getEndLoc());
9697 template <typename Derived>
9698 OMPClause *
9699 TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
9700 ExprResult ER;
9701 if (Expr *IV = C->getInteropVar()) {
9702 ER = getDerived().TransformExpr(IV);
9703 if (ER.isInvalid())
9704 return nullptr;
9706 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
9707 C->getLParenLoc(), C->getVarLoc(),
9708 C->getEndLoc());
9711 template <typename Derived>
9712 OMPClause *
9713 TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
9714 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
9715 if (Cond.isInvalid())
9716 return nullptr;
9717 return getDerived().RebuildOMPNovariantsClause(
9718 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9721 template <typename Derived>
9722 OMPClause *
9723 TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
9724 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
9725 if (Cond.isInvalid())
9726 return nullptr;
9727 return getDerived().RebuildOMPNocontextClause(
9728 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9731 template <typename Derived>
9732 OMPClause *
9733 TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
9734 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
9735 if (ThreadID.isInvalid())
9736 return nullptr;
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());
9744 if (E.isInvalid())
9745 return nullptr;
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) {
9759 llvm_unreachable(
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) {
9772 llvm_unreachable(
9773 "dynamic_allocators clause cannot appear in dependent context");
9776 template <typename Derived>
9777 OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
9778 OMPAtomicDefaultMemOrderClause *C) {
9779 llvm_unreachable(
9780 "atomic_default_mem_order clause cannot appear in dependent context");
9783 template <typename Derived>
9784 OMPClause *
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())
9791 return nullptr;
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())
9806 return nullptr;
9807 Vars.push_back(EVar.get());
9809 return getDerived().RebuildOMPFirstprivateClause(
9810 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9813 template <typename Derived>
9814 OMPClause *
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())
9821 return nullptr;
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>
9830 OMPClause *
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())
9837 return nullptr;
9838 Vars.push_back(EVar.get());
9840 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
9841 C->getLParenLoc(), C->getEndLoc());
9844 template <typename Derived>
9845 OMPClause *
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())
9852 return nullptr;
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())
9862 return nullptr;
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.
9869 if (E) {
9870 auto *ULE = cast<UnresolvedLookupExpr>(E);
9871 UnresolvedSet<8> Decls;
9872 for (auto *D : ULE->decls()) {
9873 NamedDecl *InstD =
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()));
9883 } else
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())
9900 return nullptr;
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())
9910 return nullptr;
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.
9917 if (E) {
9918 auto *ULE = cast<UnresolvedLookupExpr>(E);
9919 UnresolvedSet<8> Decls;
9920 for (auto *D : ULE->decls()) {
9921 NamedDecl *InstD =
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()));
9929 } else
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>
9938 OMPClause *
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())
9945 return nullptr;
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())
9955 return nullptr;
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.
9962 if (E) {
9963 auto *ULE = cast<UnresolvedLookupExpr>(E);
9964 UnresolvedSet<8> Decls;
9965 for (auto *D : ULE->decls()) {
9966 NamedDecl *InstD =
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()));
9974 } else
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>
9983 OMPClause *
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())
9990 return nullptr;
9991 Vars.push_back(EVar.get());
9993 ExprResult Step = getDerived().TransformExpr(C->getStep());
9994 if (Step.isInvalid())
9995 return nullptr;
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>
10002 OMPClause *
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())
10009 return nullptr;
10010 Vars.push_back(EVar.get());
10012 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
10013 if (Alignment.isInvalid())
10014 return nullptr;
10015 return getDerived().RebuildOMPAlignedClause(
10016 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
10017 C->getColonLoc(), C->getEndLoc());
10020 template <typename Derived>
10021 OMPClause *
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())
10028 return nullptr;
10029 Vars.push_back(EVar.get());
10031 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
10032 C->getLParenLoc(), C->getEndLoc());
10035 template <typename Derived>
10036 OMPClause *
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())
10043 return nullptr;
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())
10057 return nullptr;
10058 Vars.push_back(EVar.get());
10060 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
10061 C->getLParenLoc(), C->getEndLoc());
10064 template <typename Derived>
10065 OMPClause *
10066 TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
10067 ExprResult E = getDerived().TransformExpr(C->getDepobj());
10068 if (E.isInvalid())
10069 return nullptr;
10070 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
10071 C->getLParenLoc(), C->getEndLoc());
10074 template <typename Derived>
10075 OMPClause *
10076 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
10077 llvm::SmallVector<Expr *, 16> Vars;
10078 Expr *DepModifier = C->getModifier();
10079 if (DepModifier) {
10080 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
10081 if (DepModRes.isInvalid())
10082 return nullptr;
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())
10089 return nullptr;
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>
10099 OMPClause *
10100 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
10101 ExprResult E = getDerived().TransformExpr(C->getDevice());
10102 if (E.isInvalid())
10103 return nullptr;
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())
10120 return true;
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());
10128 if (!QualifierLoc)
10129 return true;
10131 MapperIdScopeSpec.Adopt(QualifierLoc);
10132 MapperIdInfo = C->getMapperIdInfo();
10133 if (MapperIdInfo.getName()) {
10134 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
10135 if (!MapperIdInfo.getName())
10136 return true;
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.
10142 if (E) {
10143 auto *ULE = cast<UnresolvedLookupExpr>(E);
10144 UnresolvedSet<8> Decls;
10145 for (auto *D : ULE->decls()) {
10146 NamedDecl *InstD =
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(),
10154 Decls.end()));
10155 } else {
10156 UnresolvedMappers.push_back(nullptr);
10159 return false;
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))
10171 return nullptr;
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>
10179 OMPClause *
10180 TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
10181 Expr *Allocator = C->getAllocator();
10182 if (Allocator) {
10183 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
10184 if (AllocatorRes.isInvalid())
10185 return nullptr;
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())
10193 return nullptr;
10194 Vars.push_back(EVar.get());
10196 return getDerived().RebuildOMPAllocateClause(
10197 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10198 C->getEndLoc());
10201 template <typename Derived>
10202 OMPClause *
10203 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
10204 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
10205 if (E.isInvalid())
10206 return nullptr;
10207 return getDerived().RebuildOMPNumTeamsClause(
10208 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10211 template <typename Derived>
10212 OMPClause *
10213 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
10214 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
10215 if (E.isInvalid())
10216 return nullptr;
10217 return getDerived().RebuildOMPThreadLimitClause(
10218 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10221 template <typename Derived>
10222 OMPClause *
10223 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
10224 ExprResult E = getDerived().TransformExpr(C->getPriority());
10225 if (E.isInvalid())
10226 return nullptr;
10227 return getDerived().RebuildOMPPriorityClause(
10228 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10231 template <typename Derived>
10232 OMPClause *
10233 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
10234 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
10235 if (E.isInvalid())
10236 return nullptr;
10237 return getDerived().RebuildOMPGrainsizeClause(
10238 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10241 template <typename Derived>
10242 OMPClause *
10243 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
10244 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
10245 if (E.isInvalid())
10246 return nullptr;
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());
10254 if (E.isInvalid())
10255 return nullptr;
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());
10264 if (E.isInvalid())
10265 return nullptr;
10266 return getDerived().RebuildOMPDistScheduleClause(
10267 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10268 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10271 template <typename Derived>
10272 OMPClause *
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(),
10278 C->getBeginLoc(),
10279 C->getLParenLoc(),
10280 C->getDefaultmapModifierLoc(),
10281 C->getDefaultmapKindLoc(),
10282 C->getEndLoc());
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))
10294 return nullptr;
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))
10309 return nullptr;
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())
10323 return nullptr;
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())
10338 return nullptr;
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>
10346 OMPClause *
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())
10353 return nullptr;
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())
10368 return nullptr;
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>
10376 OMPClause *
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())
10383 return nullptr;
10384 Vars.push_back(EVar.get());
10386 return getDerived().RebuildOMPNontemporalClause(
10387 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10390 template <typename Derived>
10391 OMPClause *
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())
10398 return nullptr;
10399 Vars.push_back(EVar.get());
10401 return getDerived().RebuildOMPInclusiveClause(
10402 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10405 template <typename Derived>
10406 OMPClause *
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())
10413 return nullptr;
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())
10429 continue;
10430 ExprResult AllocatorTraits;
10431 if (Expr *AT = D.AllocatorTraits) {
10432 AllocatorTraits = getDerived().TransformExpr(AT);
10433 if (AllocatorTraits.isInvalid())
10434 continue;
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>
10447 OMPClause *
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())
10455 return nullptr;
10457 for (Expr *E : C->varlists()) {
10458 ExprResult Locator = getDerived().TransformExpr(E);
10459 if (Locator.isInvalid())
10460 continue;
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(),
10472 C->getEndLoc());
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>
10486 ExprResult
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())
10495 return E;
10497 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
10499 if (!NewT)
10500 return ExprError();
10502 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
10503 return E;
10505 return getDerived().RebuildSYCLUniqueStableNameExpr(
10506 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
10509 template<typename Derived>
10510 ExprResult
10511 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
10512 if (!E->isTypeDependent())
10513 return E;
10515 return getDerived().RebuildPredefinedExpr(E->getLocation(),
10516 E->getIdentKind());
10519 template<typename Derived>
10520 ExprResult
10521 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
10522 NestedNameSpecifierLoc QualifierLoc;
10523 if (E->getQualifierLoc()) {
10524 QualifierLoc
10525 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10526 if (!QualifierLoc)
10527 return ExprError();
10530 ValueDecl *ND
10531 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
10532 E->getDecl()));
10533 if (!ND)
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()));
10540 if (!Found)
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);
10562 return 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(),
10572 TransArgs))
10573 return ExprError();
10576 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
10577 Found, TemplateArgs);
10580 template<typename Derived>
10581 ExprResult
10582 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
10583 return E;
10586 template <typename Derived>
10587 ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
10588 FixedPointLiteral *E) {
10589 return E;
10592 template<typename Derived>
10593 ExprResult
10594 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
10595 return E;
10598 template<typename Derived>
10599 ExprResult
10600 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
10601 return E;
10604 template<typename Derived>
10605 ExprResult
10606 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
10607 return E;
10610 template<typename Derived>
10611 ExprResult
10612 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
10613 return E;
10616 template<typename Derived>
10617 ExprResult
10618 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
10619 return getDerived().TransformCallExpr(E);
10622 template<typename Derived>
10623 ExprResult
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();
10634 if (TSI) {
10635 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
10636 if (!AssocType)
10637 return ExprError();
10638 AssocTypes.push_back(AssocType);
10639 } else {
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(),
10652 E->getRParenLoc(),
10653 ControllingExpr.get(),
10654 AssocTypes,
10655 AssocExprs);
10658 template<typename Derived>
10659 ExprResult
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())
10666 return E;
10668 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
10669 E->getRParen());
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>
10676 ExprResult
10677 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
10678 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
10679 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
10680 else
10681 return getDerived().TransformExpr(E);
10684 template<typename Derived>
10685 ExprResult
10686 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
10687 ExprResult SubExpr;
10688 if (E->getOpcode() == UO_AddrOf)
10689 SubExpr = TransformAddressOfOperand(E->getSubExpr());
10690 else
10691 SubExpr = TransformExpr(E->getSubExpr());
10692 if (SubExpr.isInvalid())
10693 return ExprError();
10695 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
10696 return E;
10698 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
10699 E->getOpcode(),
10700 SubExpr.get());
10703 template<typename Derived>
10704 ExprResult
10705 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
10706 // Transform the type.
10707 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10708 if (!Type)
10709 return ExprError();
10711 // Transform all of the components into components similar to what the
10712 // parser uses.
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);
10722 Component Comp;
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();
10736 break;
10739 case OffsetOfNode::Field:
10740 case OffsetOfNode::Identifier:
10741 Comp.isBrackets = false;
10742 Comp.U.IdentInfo = ON.getFieldName();
10743 if (!Comp.U.IdentInfo)
10744 continue;
10746 break;
10748 case OffsetOfNode::Base:
10749 // Will be recomputed during the rebuild.
10750 continue;
10753 Components.push_back(Comp);
10756 // If nothing changed, retain the existing expression.
10757 if (!getDerived().AlwaysRebuild() &&
10758 Type == E->getTypeSourceInfo() &&
10759 !ExprChanged)
10760 return E;
10762 // Build a new offsetof expression.
10763 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
10764 Components, E->getRParenLoc());
10767 template<typename Derived>
10768 ExprResult
10769 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
10770 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
10771 "opaque value expression requires transformation");
10772 return E;
10775 template<typename Derived>
10776 ExprResult
10777 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
10778 return 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)
10794 return E;
10795 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
10796 Children, E->getType());
10799 template<typename Derived>
10800 ExprResult
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
10814 // should reapply.
10815 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
10816 result = SemaRef.checkPseudoObjectRValue(result.get());
10818 return result;
10821 template<typename Derived>
10822 ExprResult
10823 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
10824 UnaryExprOrTypeTraitExpr *E) {
10825 if (E->isArgumentType()) {
10826 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
10828 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
10829 if (!NewT)
10830 return ExprError();
10832 if (!getDerived().AlwaysRebuild() && OldT == NewT)
10833 return E;
10835 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
10836 E->getKind(),
10837 E->getSourceRange());
10840 // C++0x [expr.sizeof]p1:
10841 // The operand is either an expression, which is an unevaluated operand
10842 // [...]
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());
10852 if (auto *DRE =
10853 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
10854 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
10855 PE, DRE, false, &RecoveryTSI);
10856 else
10857 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
10859 if (RecoveryTSI) {
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())
10866 return E;
10868 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
10869 E->getOperatorLoc(),
10870 E->getKind(),
10871 E->getSourceRange());
10874 template<typename Derived>
10875 ExprResult
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())
10889 return E;
10891 return getDerived().RebuildArraySubscriptExpr(
10892 LHS.get(),
10893 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
10896 template <typename Derived>
10897 ExprResult
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())
10913 return E;
10915 return getDerived().RebuildMatrixSubscriptExpr(
10916 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
10919 template <typename Derived>
10920 ExprResult
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();
10933 ExprResult Length;
10934 if (E->getLength()) {
10935 Length = getDerived().TransformExpr(E->getLength());
10936 if (Length.isInvalid())
10937 return ExprError();
10940 ExprResult Stride;
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())
10949 return E;
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>
10958 ExprResult
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()) {
10969 ErrorFound = true;
10970 continue;
10972 Dims.push_back(DimRes.get());
10975 if (ErrorFound)
10976 return ExprError();
10977 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
10978 E->getRParenLoc(), Dims,
10979 E->getBracketsRanges());
10982 template <typename Derived>
10983 ExprResult
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.");
10997 } else {
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();
11010 if (ErrorFound)
11011 continue;
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);
11018 NeedToRebuild =
11019 NeedToRebuild ||
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;
11025 if (ErrorFound)
11026 return ExprError();
11027 if (!NeedToRebuild)
11028 return E;
11030 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
11031 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
11032 if (!Res.isUsable())
11033 return Res;
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));
11038 return Res;
11041 template<typename Derived>
11042 ExprResult
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,
11053 &ArgChanged))
11054 return ExprError();
11056 if (!getDerived().AlwaysRebuild() &&
11057 Callee.get() == E->getCallee() &&
11058 !ArgChanged)
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,
11074 Args,
11075 E->getRParenLoc());
11078 template<typename Derived>
11079 ExprResult
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()) {
11087 QualifierLoc
11088 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11090 if (!QualifierLoc)
11091 return ExprError();
11093 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11095 ValueDecl *Member
11096 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
11097 E->getMemberDecl()));
11098 if (!Member)
11099 return ExprError();
11101 NamedDecl *FoundDecl = E->getFoundDecl();
11102 if (FoundDecl == E->getMemberDecl()) {
11103 FoundDecl = Member;
11104 } else {
11105 FoundDecl = cast_or_null<NamedDecl>(
11106 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
11107 if (!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);
11125 return 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(),
11135 TransArgs))
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,
11156 E->isArrow(),
11157 QualifierLoc,
11158 TemplateKWLoc,
11159 MemberNameInfo,
11160 Member,
11161 FoundDecl,
11162 (E->hasExplicitTemplateArgs()
11163 ? &TransArgs : nullptr),
11164 FirstQualifierInScope);
11167 template<typename Derived>
11168 ExprResult
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())
11181 return E;
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());
11217 if (!Op)
11218 continue;
11219 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
11220 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
11221 continue;
11223 // Transform the callee in case we built a call to a local extern
11224 // declaration.
11225 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
11226 E->getOperatorLoc(), Callee->getFoundDecl()));
11227 if (!Found)
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);
11243 return E;
11246 return getDerived().RebuildCXXRewrittenBinaryOperator(
11247 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
11250 template<typename Derived>
11251 ExprResult
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())
11279 return e;
11281 return getDerived().RebuildConditionalOperator(commonExpr.get(),
11282 e->getQuestionLoc(),
11283 nullptr,
11284 e->getColonLoc(),
11285 rhs.get());
11288 template<typename Derived>
11289 ExprResult
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())
11307 return E;
11309 return getDerived().RebuildConditionalOperator(Cond.get(),
11310 E->getQuestionLoc(),
11311 LHS.get(),
11312 E->getColonLoc(),
11313 RHS.get());
11316 template<typename Derived>
11317 ExprResult
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>
11325 ExprResult
11326 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
11327 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
11328 if (!Type)
11329 return ExprError();
11331 ExprResult SubExpr
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())
11339 return E;
11341 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
11342 Type,
11343 E->getRParenLoc(),
11344 SubExpr.get());
11347 template<typename Derived>
11348 ExprResult
11349 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
11350 TypeSourceInfo *OldT = E->getTypeSourceInfo();
11351 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
11352 if (!NewT)
11353 return ExprError();
11355 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
11356 if (Init.isInvalid())
11357 return ExprError();
11359 if (!getDerived().AlwaysRebuild() &&
11360 OldT == NewT &&
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>
11374 ExprResult
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())
11382 return E;
11384 // FIXME: Bad source location
11385 SourceLocation FakeOperatorLoc =
11386 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
11387 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
11388 E->getAccessorLoc(),
11389 E->getAccessor());
11392 template<typename Derived>
11393 ExprResult
11394 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
11395 if (InitListExpr *Syntactic = E->getSyntacticForm())
11396 E = Syntactic;
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>
11420 ExprResult
11421 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
11422 Designation Desig;
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(),
11435 D.getDotLoc(),
11436 D.getFieldLoc()));
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;
11444 } else {
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;
11450 continue;
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());
11463 continue;
11466 assert(D.isArrayRangeDesignator() && "New kind of designator?");
11467 ExprResult Start
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(),
11477 End.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() &&
11490 !ExprChanged)
11491 return E;
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>
11501 ExprResult
11502 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
11503 DesignatedInitUpdateExpr *E) {
11504 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
11505 "initializer");
11506 return ExprError();
11509 template<typename Derived>
11510 ExprResult
11511 TreeTransform<Derived>::TransformNoInitExpr(
11512 NoInitExpr *E) {
11513 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
11514 return ExprError();
11517 template<typename Derived>
11518 ExprResult
11519 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
11520 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
11521 return ExprError();
11524 template<typename Derived>
11525 ExprResult
11526 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
11527 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
11528 return ExprError();
11531 template<typename Derived>
11532 ExprResult
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());
11540 if (T.isNull())
11541 return ExprError();
11543 if (!getDerived().AlwaysRebuild() &&
11544 T == E->getType())
11545 return E;
11547 return getDerived().RebuildImplicitValueInitExpr(T);
11550 template<typename Derived>
11551 ExprResult
11552 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
11553 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
11554 if (!TInfo)
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())
11564 return E;
11566 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
11567 TInfo, E->getRParenLoc());
11570 template<typename Derived>
11571 ExprResult
11572 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
11573 bool ArgumentChanged = false;
11574 SmallVector<Expr*, 4> Inits;
11575 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
11576 &ArgumentChanged))
11577 return ExprError();
11579 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
11580 Inits,
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>
11590 ExprResult
11591 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
11592 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
11593 E->getLabel());
11594 if (!LD)
11595 return ExprError();
11597 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
11598 cast<LabelDecl>(LD));
11601 template<typename Derived>
11602 ExprResult
11603 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
11604 SemaRef.ActOnStartStmtExpr();
11605 StmtResult SubStmt
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>
11627 ExprResult
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())
11645 return E;
11647 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
11648 Cond.get(), LHS.get(), RHS.get(),
11649 E->getRParenLoc());
11652 template<typename Derived>
11653 ExprResult
11654 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
11655 return E;
11658 template<typename Derived>
11659 ExprResult
11660 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
11661 switch (E->getOperator()) {
11662 case OO_New:
11663 case OO_Delete:
11664 case OO_Array_New:
11665 case OO_Array_Delete:
11666 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
11668 case OO_Subscript:
11669 case OO_Call: {
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,
11685 Args))
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,
11693 E->getEndLoc());
11696 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
11697 case OO_##Name: \
11698 break;
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");
11706 case OO_None:
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();
11715 ExprResult First;
11716 if (E->getOperator() == OO_Amp)
11717 First = getDerived().TransformAddressOfOperand(E->getArg(0));
11718 else
11719 First = getDerived().TransformExpr(E->getArg(0));
11720 if (First.isInvalid())
11721 return ExprError();
11723 ExprResult Second;
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(),
11744 Callee.get(),
11745 First.get(),
11746 Second.get());
11749 template<typename Derived>
11750 ExprResult
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)
11761 return E;
11763 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
11764 E->getBeginLoc(), E->getEndLoc(),
11765 getSema().CurContext);
11768 template<typename Derived>
11769 ExprResult
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,
11785 &ArgChanged))
11786 return ExprError();
11788 if (!getDerived().AlwaysRebuild() &&
11789 Callee.get() == E->getCallee() &&
11790 !ArgChanged)
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,
11797 Args,
11798 E->getRParenLoc(), EC.get());
11801 template<typename Derived>
11802 ExprResult
11803 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
11804 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
11805 if (!Type)
11806 return ExprError();
11808 ExprResult SubExpr
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())
11816 return E;
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>
11825 ExprResult
11826 TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) {
11827 TypeSourceInfo *TSI =
11828 getDerived().TransformType(BCE->getTypeInfoAsWritten());
11829 if (!TSI)
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>
11841 ExprResult
11842 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
11843 return getDerived().TransformCXXNamedCastExpr(E);
11846 template<typename Derived>
11847 ExprResult
11848 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
11849 return getDerived().TransformCXXNamedCastExpr(E);
11852 template<typename Derived>
11853 ExprResult
11854 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
11855 CXXReinterpretCastExpr *E) {
11856 return getDerived().TransformCXXNamedCastExpr(E);
11859 template<typename Derived>
11860 ExprResult
11861 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
11862 return getDerived().TransformCXXNamedCastExpr(E);
11865 template<typename Derived>
11866 ExprResult
11867 TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
11868 return getDerived().TransformCXXNamedCastExpr(E);
11871 template<typename Derived>
11872 ExprResult
11873 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
11874 CXXFunctionalCastExpr *E) {
11875 TypeSourceInfo *Type =
11876 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
11877 if (!Type)
11878 return ExprError();
11880 ExprResult SubExpr
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())
11888 return E;
11890 return getDerived().RebuildCXXFunctionalCastExpr(Type,
11891 E->getLParenLoc(),
11892 SubExpr.get(),
11893 E->getRParenLoc(),
11894 E->isListInitialization());
11897 template<typename Derived>
11898 ExprResult
11899 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
11900 if (E->isTypeOperand()) {
11901 TypeSourceInfo *TInfo
11902 = getDerived().TransformType(E->getTypeOperandSourceInfo());
11903 if (!TInfo)
11904 return ExprError();
11906 if (!getDerived().AlwaysRebuild() &&
11907 TInfo == E->getTypeOperandSourceInfo())
11908 return E;
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())
11933 return E;
11935 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
11936 SubExpr.get(), E->getEndLoc());
11939 template<typename Derived>
11940 ExprResult
11941 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
11942 if (E->isTypeOperand()) {
11943 TypeSourceInfo *TInfo
11944 = getDerived().TransformType(E->getTypeOperandSourceInfo());
11945 if (!TInfo)
11946 return ExprError();
11948 if (!getDerived().AlwaysRebuild() &&
11949 TInfo == E->getTypeOperandSourceInfo())
11950 return E;
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())
11965 return E;
11967 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
11968 SubExpr.get(), E->getEndLoc());
11971 template<typename Derived>
11972 ExprResult
11973 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
11974 return E;
11977 template<typename Derived>
11978 ExprResult
11979 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
11980 CXXNullPtrLiteralExpr *E) {
11981 return E;
11984 template<typename Derived>
11985 ExprResult
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);
11993 return E;
11996 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
11999 template<typename Derived>
12000 ExprResult
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())
12008 return E;
12010 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
12011 E->isThrownVariableInScope());
12014 template<typename Derived>
12015 ExprResult
12016 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
12017 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
12018 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
12019 if (!Param)
12020 return ExprError();
12022 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
12023 E->getUsedContext() == SemaRef.CurContext)
12024 return E;
12026 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
12029 template<typename Derived>
12030 ExprResult
12031 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
12032 FieldDecl *Field = cast_or_null<FieldDecl>(
12033 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
12034 if (!Field)
12035 return ExprError();
12037 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
12038 E->getUsedContext() == SemaRef.CurContext)
12039 return E;
12041 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
12044 template<typename Derived>
12045 ExprResult
12046 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
12047 CXXScalarValueInitExpr *E) {
12048 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
12049 if (!T)
12050 return ExprError();
12052 if (!getDerived().AlwaysRebuild() &&
12053 T == E->getTypeSourceInfo())
12054 return E;
12056 return getDerived().RebuildCXXScalarValueInitExpr(T,
12057 /*FIXME:*/T->getTypeLoc().getEndLoc(),
12058 E->getRParenLoc());
12061 template<typename Derived>
12062 ExprResult
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;
12093 if (OldInit)
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()));
12103 if (!OperatorNew)
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.
12124 if (OperatorNew)
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);
12140 return E;
12143 QualType AllocType = AllocTypeInfo->getType();
12144 if (!ArraySize) {
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);
12151 if (!ArrayT) {
12152 // Do nothing
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>
12176 ExprResult
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));
12209 return E;
12212 return getDerived().RebuildCXXDeleteExpr(
12213 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
12216 template<typename Derived>
12217 ExprResult
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,
12229 ObjectTypePtr,
12230 MayBePseudoDestructor);
12231 if (Base.isInvalid())
12232 return ExprError();
12234 QualType ObjectType = ObjectTypePtr.get();
12235 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
12236 if (QualifierLoc) {
12237 QualifierLoc
12238 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
12239 if (!QualifierLoc)
12240 return ExprError();
12242 CXXScopeSpec SS;
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());
12258 } else {
12259 // Look for a destructor known with the given name.
12260 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
12261 *E->getDestroyedTypeIdentifier(),
12262 E->getDestroyedTypeLoc(),
12263 /*Scope=*/nullptr,
12264 SS, ObjectTypePtr,
12265 false);
12266 if (!T)
12267 return ExprError();
12269 Destroyed
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(),
12285 E->isArrow(),
12287 ScopeTypeInfo,
12288 E->getColonColonLoc(),
12289 E->getTildeLoc(),
12290 Destroyed);
12293 template <typename Derived>
12294 bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
12295 bool RequiresADL,
12296 LookupResult &R) {
12297 // Transform all the decls.
12298 bool AllEmptyPacks = true;
12299 for (auto *OldD : Old->decls()) {
12300 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
12301 if (!InstD) {
12302 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
12303 // This can happen because of dependent hiding.
12304 if (isa<UsingShadowDecl>(OldD))
12305 continue;
12306 else {
12307 R.clear();
12308 return true;
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())
12322 R.addDecl(SD);
12323 } else {
12324 R.addDecl(D);
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();
12340 return true;
12343 // Resolve a kind, but don't do any further analysis. If it's
12344 // ambiguous, the callee needs to deal with it.
12345 R.resolveKind();
12346 return false;
12349 template<typename Derived>
12350 ExprResult
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.
12361 CXXScopeSpec SS;
12362 if (Old->getQualifierLoc()) {
12363 NestedNameSpecifierLoc QualifierLoc
12364 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
12365 if (!QualifierLoc)
12366 return ExprError();
12368 SS.Adopt(QualifierLoc);
12371 if (Old->getNamingClass()) {
12372 CXXRecordDecl *NamingClass
12373 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
12374 Old->getNameLoc(),
12375 Old->getNamingClass()));
12376 if (!NamingClass) {
12377 R.clear();
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(),
12408 TransArgs)) {
12409 R.clear();
12410 return ExprError();
12413 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
12414 Old->requiresADL(), &TransArgs);
12417 template<typename Derived>
12418 ExprResult
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);
12429 if (To.isNull())
12430 return ExprError();
12432 if (To == From->getType())
12433 Args.push_back(From);
12434 else {
12435 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
12436 ArgChanged = true;
12438 continue;
12441 ArgChanged = true;
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
12450 // be expanded.
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(),
12458 Unexpanded,
12459 Expand, RetainExpansion,
12460 NumExpansions))
12461 return ExprError();
12463 if (!Expand) {
12464 // The transform has determined that we should perform a simple
12465 // transformation on the pack expansion, producing another pack
12466 // expansion.
12467 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12469 TypeLocBuilder TLB;
12470 TLB.reserve(From->getTypeLoc().getFullDataSize());
12472 QualType To = getDerived().TransformType(TLB, PatternTL);
12473 if (To.isNull())
12474 return ExprError();
12476 To = getDerived().RebuildPackExpansionType(To,
12477 PatternTL.getSourceRange(),
12478 ExpansionTL.getEllipsisLoc(),
12479 NumExpansions);
12480 if (To.isNull())
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));
12487 continue;
12490 // Expand the pack expansion by substituting for each argument in the
12491 // pack(s).
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);
12497 if (To.isNull())
12498 return ExprError();
12500 if (To->containsUnexpandedParameterPack()) {
12501 To = getDerived().RebuildPackExpansionType(To,
12502 PatternTL.getSourceRange(),
12503 ExpansionTL.getEllipsisLoc(),
12504 NumExpansions);
12505 if (To.isNull())
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)
12517 continue;
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);
12527 if (To.isNull())
12528 return ExprError();
12530 To = getDerived().RebuildPackExpansionType(To,
12531 PatternTL.getSourceRange(),
12532 ExpansionTL.getEllipsisLoc(),
12533 NumExpansions);
12534 if (To.isNull())
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)
12544 return E;
12546 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
12547 E->getEndLoc());
12550 template<typename Derived>
12551 ExprResult
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(),
12563 &TransArgs);
12566 template<typename Derived>
12567 ExprResult
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,
12589 ExtParamInfos))
12590 return ExprError();
12592 for (ParmVarDecl *Param : TransParams)
12593 Param->setDeclContext(Body);
12595 SmallVector<concepts::Requirement *, 4> TransReqs;
12596 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
12597 TransReqs))
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);
12625 else
12626 TransReq = getDerived().TransformNestedRequirement(
12627 cast<concepts::NestedRequirement>(Req));
12628 if (!TransReq)
12629 return true;
12630 Transformed.push_back(TransReq);
12632 return false;
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());
12643 return Req;
12645 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
12646 if (!TransType)
12647 return nullptr;
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();
12657 else {
12658 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
12659 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
12660 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
12661 if (TransExprRes.isInvalid())
12662 return nullptr;
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);
12677 if (!TPL)
12678 return nullptr;
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());
12699 return Req;
12701 ExprResult TransConstraint =
12702 getDerived().TransformExpr(Req->getConstraintExpr());
12703 if (TransConstraint.isInvalid())
12704 return nullptr;
12705 return getDerived().RebuildNestedRequirement(TransConstraint.get());
12708 template<typename Derived>
12709 ExprResult
12710 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
12711 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
12712 if (!T)
12713 return ExprError();
12715 if (!getDerived().AlwaysRebuild() &&
12716 T == E->getQueriedTypeSourceInfo())
12717 return E;
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())
12728 return E;
12731 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
12732 SubExpr.get(), E->getEndLoc());
12735 template<typename Derived>
12736 ExprResult
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())
12747 return E;
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())
12763 return NewDRE;
12765 // We got an expr, wrap it up in parens.
12766 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
12767 return PE;
12768 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
12769 PE->getRParen());
12772 template <typename Derived>
12773 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
12774 DependentScopeDeclRefExpr *E) {
12775 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
12776 nullptr);
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());
12786 if (!QualifierLoc)
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())
12804 return E;
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,
12818 RecoveryTSI);
12821 template<typename Derived>
12822 ExprResult
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());
12838 if (T.isNull())
12839 return ExprError();
12841 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
12842 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
12843 if (!Constructor)
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,
12853 &ArgumentChanged))
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);
12864 return E;
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());
12878 if (T.isNull())
12879 return ExprError();
12881 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
12882 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
12883 if (!Constructor)
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);
12892 return E;
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>
12905 ExprResult
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>
12919 ExprResult
12920 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
12921 return getDerived().TransformExpr(E->getSubExpr());
12924 template<typename Derived>
12925 ExprResult
12926 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
12927 CXXTemporaryObjectExpr *E) {
12928 TypeSourceInfo *T =
12929 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
12930 if (!T)
12931 return ExprError();
12933 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
12934 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
12935 if (!Constructor)
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,
12946 &ArgumentChanged))
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>
12968 ExprResult
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();
12983 C != CEnd; ++C) {
12984 if (!E->isInitCapture(C))
12985 continue;
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()));
12997 return;
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() !=
13006 VarDecl::CInit,
13007 NewExprInit);
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()
13015 ->getTypeLoc()
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
13021 // be expanded.
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();
13032 if (Expand) {
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();
13043 } else {
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,
13079 NewCallOpType);
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(),
13144 E->isMutable());
13146 bool Invalid = false;
13148 // Transform captures.
13149 for (LambdaExpr::capture_iterator C = E->capture_begin(),
13150 CEnd = E->capture_end();
13151 C != CEnd; ++C) {
13152 // When we hit the first implicit capture, tell Sema that we've finished
13153 // the list of explicit captures.
13154 if (C->isImplicit())
13155 break;
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);
13162 continue;
13164 // Captured expression will be recaptured during captured variables
13165 // rebuilding.
13166 if (C->capturesVLAType())
13167 continue;
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()) {
13180 Invalid = true;
13181 break;
13183 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
13184 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
13185 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get());
13186 if (!NewVD) {
13187 Invalid = true;
13188 break;
13190 NewVDs.push_back(NewVD);
13191 getSema().addInitCapture(LSI, NewVD);
13194 if (Invalid)
13195 break;
13197 getDerived().transformedLocalDecl(OldVD, NewVDs);
13198 continue;
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(),
13216 C->getLocation(),
13217 Unexpanded,
13218 ShouldExpand, RetainExpansion,
13219 NumExpansions)) {
13220 Invalid = true;
13221 continue;
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(),
13233 Pack));
13234 if (!CapturedVar) {
13235 Invalid = true;
13236 continue;
13239 // Capture the transformed variable.
13240 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
13243 // FIXME: Retain a pack expansion if RetainExpansion is true.
13245 continue;
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()) {
13256 Invalid = true;
13257 continue;
13260 // Capture the transformed variable.
13261 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
13262 EllipsisLoc);
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.
13272 StmtResult Body =
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(),
13294 &LSICopy);
13297 template<typename Derived>
13298 StmtResult
13299 TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) {
13300 return TransformStmt(S);
13303 template<typename Derived>
13304 StmtResult
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();
13309 C != CEnd; ++C) {
13310 // When we hit the first implicit capture, tell Sema that we've finished
13311 // the list of explicit captures.
13312 if (!C->isImplicit())
13313 continue;
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);
13320 continue;
13322 // Captured expression will be recaptured during captured variables
13323 // rebuilding.
13324 if (C->capturesVLAType())
13325 continue;
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());
13340 return S;
13343 template<typename Derived>
13344 ExprResult
13345 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
13346 CXXUnresolvedConstructExpr *E) {
13347 TypeSourceInfo *T =
13348 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
13349 if (!T)
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,
13360 &ArgumentChanged))
13361 return ExprError();
13364 if (!getDerived().AlwaysRebuild() &&
13365 T == E->getTypeSourceInfo() &&
13366 !ArgumentChanged)
13367 return E;
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>
13375 ExprResult
13376 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
13377 CXXDependentScopeMemberExpr *E) {
13378 // Transform the base of the expression.
13379 ExprResult Base((Expr*) nullptr);
13380 Expr *OldBase;
13381 QualType BaseType;
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,
13395 ObjectTy,
13396 MayBePseudoDestructor);
13397 if (Base.isInvalid())
13398 return ExprError();
13400 ObjectType = ObjectTy.get();
13401 BaseType = ((Expr*) Base.get())->getType();
13402 } else {
13403 OldBase = nullptr;
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()) {
13417 QualifierLoc
13418 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
13419 ObjectType,
13420 FirstQualifierInScope);
13421 if (!QualifierLoc)
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())
13445 return E;
13447 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
13448 BaseType,
13449 E->isArrow(),
13450 E->getOperatorLoc(),
13451 QualifierLoc,
13452 TemplateKWLoc,
13453 FirstQualifierInScope,
13454 NameInfo,
13455 /*TemplateArgs*/nullptr);
13458 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
13459 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13460 E->getNumTemplateArgs(),
13461 TransArgs))
13462 return ExprError();
13464 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
13465 BaseType,
13466 E->isArrow(),
13467 E->getOperatorLoc(),
13468 QualifierLoc,
13469 TemplateKWLoc,
13470 FirstQualifierInScope,
13471 NameInfo,
13472 &TransArgs);
13475 template <typename Derived>
13476 ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
13477 UnresolvedMemberExpr *Old) {
13478 // Transform the base of the expression.
13479 ExprResult Base((Expr *)nullptr);
13480 QualType BaseType;
13481 if (!Old->isImplicitAccess()) {
13482 Base = getDerived().TransformExpr(Old->getBase());
13483 if (Base.isInvalid())
13484 return ExprError();
13485 Base =
13486 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
13487 if (Base.isInvalid())
13488 return ExprError();
13489 BaseType = Base.get()->getType();
13490 } else {
13491 BaseType = getDerived().TransformType(Old->getBaseType());
13494 NestedNameSpecifierLoc QualifierLoc;
13495 if (Old->getQualifierLoc()) {
13496 QualifierLoc =
13497 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
13498 if (!QualifierLoc)
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()));
13514 if (!NamingClass)
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>
13542 ExprResult
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())
13551 return E;
13553 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
13556 template<typename Derived>
13557 ExprResult
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())
13564 return E;
13566 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
13567 E->getNumExpansions());
13570 template<typename Derived>
13571 ExprResult
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())
13576 return E;
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(),
13593 Unexpanded,
13594 ShouldExpand, RetainExpansion,
13595 NumExpansions))
13596 return ExprError();
13598 // If we need to expand the pack, build a template argument from it and
13599 // expand that.
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);
13607 } else {
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,
13612 E->getPackLoc());
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()));
13626 if (!Pack)
13627 return ExprError();
13628 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
13629 E->getPackLoc(),
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;
13638 continue;
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,
13655 /*Uneval*/ true))
13656 return true;
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.
13664 Result = None;
13665 break;
13668 Result = *Result + *NumExpansions;
13671 // Common case: we could determine the number of expansions without
13672 // substituting.
13673 if (Result)
13674 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
13675 E->getPackLoc(),
13676 E->getRParenLoc(), *Result, None);
13678 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
13679 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(),
13702 E->getPackLoc(),
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>
13711 ExprResult
13712 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
13713 SubstNonTypeTemplateParmPackExpr *E) {
13714 // Default behavior is to do nothing with this transformation.
13715 return E;
13718 template<typename Derived>
13719 ExprResult
13720 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
13721 SubstNonTypeTemplateParmExpr *E) {
13722 // Default behavior is to do nothing with this transformation.
13723 return E;
13726 template<typename Derived>
13727 ExprResult
13728 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
13729 // Default behavior is to do nothing with this transformation.
13730 return E;
13733 template<typename Derived>
13734 ExprResult
13735 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
13736 MaterializeTemporaryExpr *E) {
13737 return getDerived().TransformExpr(E->getSubExpr());
13740 template<typename Derived>
13741 ExprResult
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
13758 // be expanded.
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(),
13765 Unexpanded,
13766 Expand, RetainExpansion,
13767 NumExpansions))
13768 return true;
13770 if (!Expand) {
13771 // Do not expand any packs here, just transform and rebuild a fold
13772 // expression.
13773 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
13775 ExprResult LHS =
13776 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
13777 if (LHS.isInvalid())
13778 return true;
13780 ExprResult RHS =
13781 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
13782 if (RHS.isInvalid())
13783 return true;
13785 if (!getDerived().AlwaysRebuild() &&
13786 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
13787 return E;
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
13796 // them.
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())
13810 return true;
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())
13820 return true;
13822 Result = getDerived().RebuildCXXFoldExpr(
13823 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
13824 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
13825 if (Result.isInvalid())
13826 return true;
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())
13834 return true;
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();
13847 if (Callee)
13848 Result = getDerived().RebuildCXXOperatorCallExpr(
13849 BinaryOperator::getOverloadedOperator(E->getOperator()),
13850 E->getEllipsisLoc(), Callee, LHS, RHS);
13851 else
13852 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
13853 E->getOperator(), LHS, RHS);
13854 } else
13855 Result = Out;
13857 if (Result.isInvalid())
13858 return true;
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())
13868 return true;
13870 Result = getDerived().RebuildCXXFoldExpr(
13871 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
13872 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
13873 if (Result.isInvalid())
13874 return true;
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(),
13881 E->getOperator());
13883 return Result;
13886 template<typename Derived>
13887 ExprResult
13888 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
13889 CXXStdInitializerListExpr *E) {
13890 return getDerived().TransformExpr(E->getSubExpr());
13893 template<typename Derived>
13894 ExprResult
13895 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
13896 return SemaRef.MaybeBindToTemporary(E);
13899 template<typename Derived>
13900 ExprResult
13901 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
13902 return E;
13905 template<typename Derived>
13906 ExprResult
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())
13914 return E;
13916 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
13919 template<typename Derived>
13920 ExprResult
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(),
13933 Elements.data(),
13934 Elements.size());
13937 template<typename Derived>
13938 ExprResult
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();
13967 if (!Expand) {
13968 // The transform has determined that we should perform a simple
13969 // transformation on the pack expansion, producing another pack
13970 // expansion.
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)
13977 ArgChanged = true;
13979 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
13980 if (Value.isInvalid())
13981 return ExprError();
13983 if (Value.get() != OrigElement.Value)
13984 ArgChanged = true;
13986 ObjCDictionaryElement Expansion = {
13987 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
13989 Elements.push_back(Expansion);
13990 continue;
13993 // Record right away that the argument was changed. This needs
13994 // to happen even if the array expands to nothing.
13995 ArgChanged = true;
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
14014 // pack expansion.
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.
14026 continue;
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)
14035 ArgChanged = true;
14037 // Transform and check value.
14038 ExprResult Value
14039 = getDerived().TransformExpr(OrigElement.Value);
14040 if (Value.isInvalid())
14041 return ExprError();
14043 if (Value.get() != OrigElement.Value)
14044 ArgChanged = true;
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(),
14056 Elements);
14059 template<typename Derived>
14060 ExprResult
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())
14069 return E;
14071 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
14072 EncodedTypeInfo,
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());
14091 if (!TSInfo)
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())
14101 return E;
14103 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
14104 E->getBridgeKeywordLoc(), TSInfo,
14105 Result.get());
14108 template <typename Derived>
14109 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
14110 ObjCAvailabilityCheckExpr *E) {
14111 return E;
14114 template<typename Derived>
14115 ExprResult
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,
14122 &ArgChanged))
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,
14141 E->getSelector(),
14142 SelLocs,
14143 E->getMethodDecl(),
14144 E->getLeftLoc(),
14145 Args,
14146 E->getRightLoc());
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(),
14157 E->getSelector(),
14158 SelLocs,
14159 E->getReceiverType(),
14160 E->getMethodDecl(),
14161 E->getLeftLoc(),
14162 Args,
14163 E->getRightLoc());
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(),
14183 E->getSelector(),
14184 SelLocs,
14185 E->getMethodDecl(),
14186 E->getLeftLoc(),
14187 Args,
14188 E->getRightLoc());
14191 template<typename Derived>
14192 ExprResult
14193 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
14194 return E;
14197 template<typename Derived>
14198 ExprResult
14199 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
14200 return E;
14203 template<typename Derived>
14204 ExprResult
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())
14216 return E;
14218 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
14219 E->getLocation(),
14220 E->isArrow(), E->isFreeIvar());
14223 template<typename Derived>
14224 ExprResult
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())
14229 return E;
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())
14241 return E;
14243 if (E->isExplicitProperty())
14244 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
14245 E->getExplicitProperty(),
14246 E->getLocation());
14248 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
14249 SemaRef.Context.PseudoObjectTy,
14250 E->getImplicitPropertyGetter(),
14251 E->getImplicitPropertySetter(),
14252 E->getLocation());
14255 template<typename Derived>
14256 ExprResult
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())
14271 return E;
14273 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
14274 Base.get(), Key.get(),
14275 E->getAtIndexMethodDecl(),
14276 E->setAtIndexMethodDecl());
14279 template<typename Derived>
14280 ExprResult
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())
14290 return E;
14292 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
14293 E->getOpLoc(),
14294 E->isArrow());
14297 template<typename Derived>
14298 ExprResult
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() &&
14308 !ArgumentChanged)
14309 return E;
14311 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
14312 SubExprs,
14313 E->getRParenLoc());
14316 template<typename Derived>
14317 ExprResult
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());
14324 if (!Type)
14325 return ExprError();
14327 if (!getDerived().AlwaysRebuild() &&
14328 Type == E->getTypeSourceInfo() &&
14329 SrcExpr.get() == E->getSrcExpr())
14330 return E;
14332 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
14333 SrcExpr.get(), Type,
14334 E->getRParenLoc());
14337 template<typename Derived>
14338 ExprResult
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, &params,
14359 extParamInfos)) {
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();
14390 #ifndef NDEBUG
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())
14399 continue;
14401 VarDecl *newCapture =
14402 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
14403 oldCapture));
14404 assert(blockScope->CaptureMap.count(newCapture));
14406 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
14408 #endif
14410 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
14411 /*Scope=*/nullptr);
14414 template<typename Derived>
14415 ExprResult
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>
14428 ExprResult
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() &&
14438 !ArgumentChanged)
14439 return E;
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>
14464 QualType
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>
14473 QualType
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(
14496 QualType BaseType,
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,
14508 ProtocolRAngleLoc,
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>
14520 QualType
14521 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
14522 ArrayType::ArraySizeModifier SizeMod,
14523 const llvm::APInt *Size,
14524 Expr *SizeExpr,
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
14537 QualType SizeType;
14538 for (const auto &T : Types)
14539 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
14540 SizeType = T;
14541 break;
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>
14555 QualType
14556 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
14557 ArrayType::ArraySizeModifier SizeMod,
14558 const llvm::APInt &Size,
14559 Expr *SizeExpr,
14560 unsigned IndexTypeQuals,
14561 SourceRange BracketsRange) {
14562 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
14563 IndexTypeQuals, BracketsRange);
14566 template<typename Derived>
14567 QualType
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>
14577 QualType
14578 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
14579 ArrayType::ArraySizeModifier SizeMod,
14580 Expr *SizeExpr,
14581 unsigned IndexTypeQuals,
14582 SourceRange BracketsRange) {
14583 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
14584 SizeExpr,
14585 IndexTypeQuals, BracketsRange);
14588 template<typename Derived>
14589 QualType
14590 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
14591 ArrayType::ArraySizeModifier SizeMod,
14592 Expr *SizeExpr,
14593 unsigned IndexTypeQuals,
14594 SourceRange BracketsRange) {
14595 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
14596 SizeExpr,
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,
14604 AttributeLoc);
14607 template <typename Derived>
14608 QualType
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,
14631 AttributeLoc);
14632 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
14635 template<typename Derived>
14636 QualType
14637 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
14638 Expr *SizeExpr,
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,
14647 NumColumns);
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,
14655 AttributeLoc);
14658 template<typename Derived>
14659 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
14660 QualType T,
14661 MutableArrayRef<QualType> ParamTypes,
14662 const FunctionProtoType::ExtProtoInfo &EPI) {
14663 return SemaRef.BuildFunctionType(T, ParamTypes,
14664 getDerived().getBaseLocation(),
14665 getDerived().getBaseEntity(),
14666 EPI);
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,
14676 Decl *D) {
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;
14688 return QualType();
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;
14695 QualType T;
14696 for (auto *E : UPD->expansions()) {
14697 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
14698 if (ThisT.isNull())
14699 continue;
14700 else if (ThisT->getAs<UnresolvedUsingType>())
14701 FallbackT = ThisT;
14702 else if (T.isNull())
14703 T = ThisT;
14704 else
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))
14718 return QualType();
14719 return SemaRef.Context.getUsingType(
14720 Shadow, SemaRef.Context.getTypeDeclType(
14721 cast<TypeDecl>(Shadow->getTargetDecl())));
14722 } else {
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,
14732 SourceLocation) {
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,
14770 bool isReadPipe) {
14771 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
14772 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
14775 template <typename Derived>
14776 QualType TreeTransform<Derived>::RebuildBitIntType(bool IsUnsigned,
14777 unsigned NumBits,
14778 SourceLocation Loc) {
14779 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
14780 NumBits, true);
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>
14793 TemplateName
14794 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
14795 bool TemplateKW,
14796 TemplateDecl *Template) {
14797 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
14798 TemplateName(Template));
14801 template<typename Derived>
14802 TemplateName
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>
14821 TemplateName
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>
14840 ExprResult
14841 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
14842 SourceLocation OpLoc,
14843 Expr *OrigCallee,
14844 Expr *First,
14845 Expr *Second) {
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,
14853 First, Second);
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
14885 // operation.
14886 UnaryOperatorKind Opc
14887 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
14889 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
14891 } else {
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);
14897 ExprResult Result
14898 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
14899 if (Result.isInvalid())
14900 return ExprError();
14902 return Result;
14906 // Compute the transformed set of functions (and function templates) to be
14907 // used during overload resolution.
14908 UnresolvedSet<16> Functions;
14909 bool RequiresADL;
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();
14917 } else {
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,
14936 RequiresADL);
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();
14947 } else {
14948 LBrace = Callee->getBeginLoc();
14949 RBrace = OpLoc;
14952 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
14953 First, Second);
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();
14963 return Result;
14966 template<typename Derived>
14967 ExprResult
14968 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
14969 SourceLocation OperatorLoc,
14970 bool isArrow,
14971 CXXScopeSpec &SS,
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.
14996 if (ScopeType) {
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(),
15004 CCLoc);
15007 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
15008 return getSema().BuildMemberReferenceExpr(Base, BaseType,
15009 OperatorLoc, isArrow,
15010 SS, TemplateKWLoc,
15011 /*FIXME: FirstQualifier*/ nullptr,
15012 NameInfo,
15013 /*TemplateArgs*/ nullptr,
15014 /*S*/nullptr);
15017 template<typename Derived>
15018 StmtResult
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) {
15027 Params.push_back(
15028 std::make_pair(
15029 CD->getParam(I)->getName(),
15030 getDerived().TransformType(CD->getParam(I)->getType())));
15031 } else {
15032 Params.push_back(std::make_pair(StringRef(), QualType()));
15035 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
15036 S->getCapturedRegionKind(), Params);
15037 StmtResult Body;
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