1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===//
9 // This file implements a semantic tree transformation that takes a given
10 // AST and rebuilds it, possibly transforming some nodes in the process.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15 #define LLVM_CLANG_SEMA_TREETRANSFORM_H
17 #include "TypeLocBuilder.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/ExprCXX.h"
23 #include "clang/AST/ExprObjC.h"
24 #include "clang/AST/Stmt.h"
25 #include "clang/AST/StmtCXX.h"
26 #include "clang/AST/StmtObjC.h"
27 #include "clang/AST/StmtOpenMP.h"
28 #include "clang/Sema/Designator.h"
29 #include "clang/Sema/Lookup.h"
30 #include "clang/Sema/Ownership.h"
31 #include "clang/Sema/ParsedTemplate.h"
32 #include "clang/Sema/ScopeInfo.h"
33 #include "clang/Sema/SemaDiagnostic.h"
34 #include "clang/Sema/SemaInternal.h"
35 #include "llvm/ADT/ArrayRef.h"
36 #include "llvm/Support/ErrorHandling.h"
42 /// \brief A semantic tree transformation that allows one to transform one
43 /// abstract syntax tree into another.
45 /// A new tree transformation is defined by creating a new subclass \c X of
46 /// \c TreeTransform<X> and then overriding certain operations to provide
47 /// behavior specific to that transformation. For example, template
48 /// instantiation is implemented as a tree transformation where the
49 /// transformation of TemplateTypeParmType nodes involves substituting the
50 /// template arguments for their corresponding template parameters; a similar
51 /// transformation is performed for non-type template parameters and
52 /// template template parameters.
54 /// This tree-transformation template uses static polymorphism to allow
55 /// subclasses to customize any of its operations. Thus, a subclass can
56 /// override any of the transformation or rebuild operators by providing an
57 /// operation with the same signature as the default implementation. The
58 /// overridding function should not be virtual.
60 /// Semantic tree transformations are split into two stages, either of which
61 /// can be replaced by a subclass. The "transform" step transforms an AST node
62 /// or the parts of an AST node using the various transformation functions,
63 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
64 /// node of the appropriate kind from the pieces. The default transformation
65 /// routines recursively transform the operands to composite AST nodes (e.g.,
66 /// the pointee type of a PointerType node) and, if any of those operand nodes
67 /// were changed by the transformation, invokes the rebuild operation to create
70 /// Subclasses can customize the transformation at various levels. The
71 /// most coarse-grained transformations involve replacing TransformType(),
72 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
73 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
74 /// new implementations.
76 /// For more fine-grained transformations, subclasses can replace any of the
77 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
78 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
79 /// replacing TransformTemplateTypeParmType() allows template instantiation
80 /// to substitute template arguments for their corresponding template
81 /// parameters. Additionally, subclasses can override the \c RebuildXXX
82 /// functions to control how AST nodes are rebuilt when their operands change.
83 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
84 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
85 /// be able to use more efficient rebuild steps.
87 /// There are a handful of other functions that can be overridden, allowing one
88 /// to avoid traversing nodes that don't need any transformation
89 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90 /// operands have not changed (\c AlwaysRebuild()), and customize the
91 /// default locations and entity names used for type-checking
92 /// (\c getBaseLocation(), \c getBaseEntity()).
93 template<typename Derived>
95 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
98 class ForgetPartiallySubstitutedPackRAII {
100 TemplateArgument Old;
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
121 /// \brief Initializes a new tree transformer.
122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
127 /// \brief Retrieves a reference to the derived class.
128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
153 /// By default, returns no source-location information. Subclasses can
154 /// provide an alternative implementation that provides better location
156 SourceLocation getBaseLocation() { return SourceLocation(); }
158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
181 DeclarationName Entity) : Self(Self) {
182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
190 Self.getDerived().setBase(OldLocation, OldEntity);
194 /// \brief Determine whether the given type \p T has already been
197 /// Subclasses can provide an alternative implementation of this routine
198 /// to short-circuit evaluation when it is known that a given type will
199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
219 /// By default, the transformer never tries to expand pack expansions.
220 /// Subclasses can override this routine to provide different behavior.
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
228 /// \param Unexpanded The set of unexpanded parameter packs within the
231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
240 /// \param NumExpansions The number of separate arguments that will be in
241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
254 ArrayRef<UnexpandedParameterPack> Unexpanded,
256 bool &RetainExpansion,
257 Optional<unsigned> &NumExpansions) {
258 ShouldExpand = false;
262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
278 /// \brief Note to the derived class when a function parameter pack is
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
282 /// \brief Transforms the given type into another type.
284 /// By default, this routine transforms a type by creating a
285 /// TypeSourceInfo for it and delegating to the appropriate
286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
288 /// switched to storing TypeSourceInfos.
290 /// \returns the transformed type.
291 QualType TransformType(QualType T);
293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
309 /// \brief Transform the given statement.
311 /// By default, this routine transforms a statement by delegating to the
312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
317 /// \returns the transformed statement.
318 StmtResult TransformStmt(Stmt *S);
320 /// \brief Transform the given statement.
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
330 /// \brief Transform the given expression.
332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
337 /// \returns the transformed expression.
338 ExprResult TransformExpr(Expr *E);
340 /// \brief Transform the given initializer.
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
349 /// \brief Transform the given list of expressions.
351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
357 /// \param Inputs The set of expressions to be transformed.
359 /// \param NumInputs The number of expressions in \c Inputs.
361 /// \param IsCall If \c true, then this transform is being performed on
362 /// function-call arguments, and any arguments that should be dropped, will
365 /// \param Outputs The transformed input expressions will be added to this
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
373 SmallVectorImpl<Expr *> &Outputs,
374 bool *ArgChanged = nullptr);
376 /// \brief Transform the given declaration, which is referenced from a type
379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
381 /// may override this function to provide alternate behavior.
382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
391 /// \brief Transform the attributes associated with the given declaration and
392 /// place them on the new declaration.
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
398 /// \brief Note that a local declaration has been transformed by this
401 /// Local declarations are typically transformed via a call to
402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
409 /// \brief Transform the definition of the given declaration.
411 /// By default, invokes TransformDecl() to transform the declaration.
412 /// Subclasses may override this function to provide alternate behavior.
413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
420 /// This specific declaration transformation only applies to the first
421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
430 /// \brief Transform the given nested-name-specifier with source-location
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
441 /// \brief Transform the given declaration name.
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
450 /// \brief Transform the given template name.
452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
455 /// \param Name The template name to transform.
457 /// \param NameLoc The source location of the template name.
459 /// \param ObjectType If we're translating a template name within a member
460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
476 /// \brief Transform the given template argument.
478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
487 /// \brief Transform the given set of template arguments.
489 /// By default, this operation transforms all of the template arguments
490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
497 /// \param Inputs The set of template arguments to be transformed.
499 /// \param NumInputs The number of template arguments in \p Inputs.
501 /// \param Outputs The set of transformed template arguments output by this
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
511 /// \brief Transform the given set of template arguments.
513 /// By default, this operation transforms all of the template arguments
514 /// in the input set using \c TransformTemplateArgument(), and appends
515 /// the transformed arguments to the output list.
517 /// \param First An iterator to the first template argument.
519 /// \param Last An iterator one step past the last template argument.
521 /// \param Outputs The set of transformed template arguments output by this
524 /// Returns true if an error occurred.
525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
528 TemplateArgumentListInfo &Outputs);
530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
537 getDerived().getBaseLocation());
540 #define ABSTRACT_TYPELOC(CLASS, PARENT)
541 #define TYPELOC(CLASS, PARENT) \
542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
543 #include "clang/AST/TypeLocNodes.def"
545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
550 StmtResult TransformSEHHandler(Stmt *Handler);
553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
560 TemplateName Template,
564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
568 /// \brief Transforms the parameters of a function type into the
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
574 /// Return true on error.
575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
581 /// \brief Transforms a single function-type parameter. Return null
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
588 Optional<unsigned> NumExpansions,
589 bool ExpectParameterPack);
591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
597 /// \brief Transform the captures and body of a lambda expression.
598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
606 ExprResult TransformAddressOfOperand(Expr *E);
608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
609 bool IsAddressOfOperand,
610 TypeSourceInfo **RecoveryTSI);
612 ExprResult TransformParenDependentScopeDeclRefExpr(
613 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
614 TypeSourceInfo **RecoveryTSI);
616 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
618 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
619 // amount of stack usage with clang.
620 #define STMT(Node, Parent) \
621 LLVM_ATTRIBUTE_NOINLINE \
622 StmtResult Transform##Node(Node *S);
623 #define EXPR(Node, Parent) \
624 LLVM_ATTRIBUTE_NOINLINE \
625 ExprResult Transform##Node(Node *E);
626 #define ABSTRACT_STMT(Stmt)
627 #include "clang/AST/StmtNodes.inc"
629 #define OPENMP_CLAUSE(Name, Class) \
630 LLVM_ATTRIBUTE_NOINLINE \
631 OMPClause *Transform ## Class(Class *S);
632 #include "clang/Basic/OpenMPKinds.def"
634 /// \brief Build a new pointer type given its pointee type.
636 /// By default, performs semantic analysis when building the pointer type.
637 /// Subclasses may override this routine to provide different behavior.
638 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
640 /// \brief Build a new block pointer type given its pointee type.
642 /// By default, performs semantic analysis when building the block pointer
643 /// type. Subclasses may override this routine to provide different behavior.
644 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
646 /// \brief Build a new reference type given the type it references.
648 /// By default, performs semantic analysis when building the
649 /// reference type. Subclasses may override this routine to provide
650 /// different behavior.
652 /// \param LValue whether the type was written with an lvalue sigil
653 /// or an rvalue sigil.
654 QualType RebuildReferenceType(QualType ReferentType,
656 SourceLocation Sigil);
658 /// \brief Build a new member pointer type given the pointee type and the
659 /// class type it refers into.
661 /// By default, performs semantic analysis when building the member pointer
662 /// type. Subclasses may override this routine to provide different behavior.
663 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
664 SourceLocation Sigil);
666 /// \brief Build a new array type given the element type, size
667 /// modifier, size of the array (if known), size expression, and index type
670 /// By default, performs semantic analysis when building the array type.
671 /// Subclasses may override this routine to provide different behavior.
672 /// Also by default, all of the other Rebuild*Array
673 QualType RebuildArrayType(QualType ElementType,
674 ArrayType::ArraySizeModifier SizeMod,
675 const llvm::APInt *Size,
677 unsigned IndexTypeQuals,
678 SourceRange BracketsRange);
680 /// \brief Build a new constant array type given the element type, size
681 /// modifier, (known) size of the array, and index type qualifiers.
683 /// By default, performs semantic analysis when building the array type.
684 /// Subclasses may override this routine to provide different behavior.
685 QualType RebuildConstantArrayType(QualType ElementType,
686 ArrayType::ArraySizeModifier SizeMod,
687 const llvm::APInt &Size,
688 unsigned IndexTypeQuals,
689 SourceRange BracketsRange);
691 /// \brief Build a new incomplete array type given the element type, size
692 /// modifier, and index type qualifiers.
694 /// By default, performs semantic analysis when building the array type.
695 /// Subclasses may override this routine to provide different behavior.
696 QualType RebuildIncompleteArrayType(QualType ElementType,
697 ArrayType::ArraySizeModifier SizeMod,
698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
701 /// \brief Build a new variable-length array type given the element type,
702 /// size modifier, size expression, and index type qualifiers.
704 /// By default, performs semantic analysis when building the array type.
705 /// Subclasses may override this routine to provide different behavior.
706 QualType RebuildVariableArrayType(QualType ElementType,
707 ArrayType::ArraySizeModifier SizeMod,
709 unsigned IndexTypeQuals,
710 SourceRange BracketsRange);
712 /// \brief Build a new dependent-sized array type given the element type,
713 /// size modifier, size expression, and index type qualifiers.
715 /// By default, performs semantic analysis when building the array type.
716 /// Subclasses may override this routine to provide different behavior.
717 QualType RebuildDependentSizedArrayType(QualType ElementType,
718 ArrayType::ArraySizeModifier SizeMod,
720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
723 /// \brief Build a new vector type given the element type and
724 /// number of elements.
726 /// By default, performs semantic analysis when building the vector type.
727 /// Subclasses may override this routine to provide different behavior.
728 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
729 VectorType::VectorKind VecKind);
731 /// \brief Build a new extended vector type given the element type and
732 /// number of elements.
734 /// By default, performs semantic analysis when building the vector type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
737 SourceLocation AttributeLoc);
739 /// \brief Build a new potentially dependently-sized extended vector type
740 /// given the element type and number of elements.
742 /// By default, performs semantic analysis when building the vector type.
743 /// Subclasses may override this routine to provide different behavior.
744 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
746 SourceLocation AttributeLoc);
748 /// \brief Build a new function type.
750 /// By default, performs semantic analysis when building the function type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType RebuildFunctionProtoType(QualType T,
753 MutableArrayRef<QualType> ParamTypes,
754 const FunctionProtoType::ExtProtoInfo &EPI);
756 /// \brief Build a new unprototyped function type.
757 QualType RebuildFunctionNoProtoType(QualType ResultType);
759 /// \brief Rebuild an unresolved typename type, given the decl that
760 /// the UnresolvedUsingTypenameDecl was transformed to.
761 QualType RebuildUnresolvedUsingType(Decl *D);
763 /// \brief Build a new typedef type.
764 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
765 return SemaRef.Context.getTypeDeclType(Typedef);
768 /// \brief Build a new class/struct/union type.
769 QualType RebuildRecordType(RecordDecl *Record) {
770 return SemaRef.Context.getTypeDeclType(Record);
773 /// \brief Build a new Enum type.
774 QualType RebuildEnumType(EnumDecl *Enum) {
775 return SemaRef.Context.getTypeDeclType(Enum);
778 /// \brief Build a new typeof(expr) type.
780 /// By default, performs semantic analysis when building the typeof type.
781 /// Subclasses may override this routine to provide different behavior.
782 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
784 /// \brief Build a new typeof(type) type.
786 /// By default, builds a new TypeOfType with the given underlying type.
787 QualType RebuildTypeOfType(QualType Underlying);
789 /// \brief Build a new unary transform type.
790 QualType RebuildUnaryTransformType(QualType BaseType,
791 UnaryTransformType::UTTKind UKind,
794 /// \brief Build a new C++11 decltype type.
796 /// By default, performs semantic analysis when building the decltype type.
797 /// Subclasses may override this routine to provide different behavior.
798 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
800 /// \brief Build a new C++11 auto type.
802 /// By default, builds a new AutoType with the given deduced type.
803 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
804 // Note, IsDependent is always false here: we implicitly convert an 'auto'
805 // which has been deduced to a dependent type into an undeduced 'auto', so
806 // that we'll retry deduction after the transformation.
807 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
808 /*IsDependent*/ false);
811 /// \brief Build a new template specialization type.
813 /// By default, performs semantic analysis when building the template
814 /// specialization type. Subclasses may override this routine to provide
815 /// different behavior.
816 QualType RebuildTemplateSpecializationType(TemplateName Template,
817 SourceLocation TemplateLoc,
818 TemplateArgumentListInfo &Args);
820 /// \brief Build a new parenthesized type.
822 /// By default, builds a new ParenType type from the inner type.
823 /// Subclasses may override this routine to provide different behavior.
824 QualType RebuildParenType(QualType InnerType) {
825 return SemaRef.Context.getParenType(InnerType);
828 /// \brief Build a new qualified name type.
830 /// By default, builds a new ElaboratedType type from the keyword,
831 /// the nested-name-specifier and the named type.
832 /// Subclasses may override this routine to provide different behavior.
833 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
834 ElaboratedTypeKeyword Keyword,
835 NestedNameSpecifierLoc QualifierLoc,
837 return SemaRef.Context.getElaboratedType(Keyword,
838 QualifierLoc.getNestedNameSpecifier(),
842 /// \brief Build a new typename type that refers to a template-id.
844 /// By default, builds a new DependentNameType type from the
845 /// nested-name-specifier and the given type. Subclasses may override
846 /// this routine to provide different behavior.
847 QualType RebuildDependentTemplateSpecializationType(
848 ElaboratedTypeKeyword Keyword,
849 NestedNameSpecifierLoc QualifierLoc,
850 const IdentifierInfo *Name,
851 SourceLocation NameLoc,
852 TemplateArgumentListInfo &Args) {
853 // Rebuild the template name.
854 // TODO: avoid TemplateName abstraction
856 SS.Adopt(QualifierLoc);
857 TemplateName InstName
858 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
861 if (InstName.isNull())
864 // If it's still dependent, make a dependent specialization.
865 if (InstName.getAsDependentTemplateName())
866 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
867 QualifierLoc.getNestedNameSpecifier(),
871 // Otherwise, make an elaborated type wrapping a non-dependent
874 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
875 if (T.isNull()) return QualType();
877 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
880 return SemaRef.Context.getElaboratedType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
885 /// \brief Build a new typename type that refers to an identifier.
887 /// By default, performs semantic analysis when building the typename type
888 /// (or elaborated type). Subclasses may override this routine to provide
889 /// different behavior.
890 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
891 SourceLocation KeywordLoc,
892 NestedNameSpecifierLoc QualifierLoc,
893 const IdentifierInfo *Id,
894 SourceLocation IdLoc) {
896 SS.Adopt(QualifierLoc);
898 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
899 // If the name is still dependent, just build a new dependent name type.
900 if (!SemaRef.computeDeclContext(SS))
901 return SemaRef.Context.getDependentNameType(Keyword,
902 QualifierLoc.getNestedNameSpecifier(),
906 if (Keyword == ETK_None || Keyword == ETK_Typename)
907 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
910 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
912 // We had a dependent elaborated-type-specifier that has been transformed
913 // into a non-dependent elaborated-type-specifier. Find the tag we're
915 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
916 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
920 if (SemaRef.RequireCompleteDeclContext(SS, DC))
923 TagDecl *Tag = nullptr;
924 SemaRef.LookupQualifiedName(Result, DC);
925 switch (Result.getResultKind()) {
926 case LookupResult::NotFound:
927 case LookupResult::NotFoundInCurrentInstantiation:
930 case LookupResult::Found:
931 Tag = Result.getAsSingle<TagDecl>();
934 case LookupResult::FoundOverloaded:
935 case LookupResult::FoundUnresolvedValue:
936 llvm_unreachable("Tag lookup cannot find non-tags");
938 case LookupResult::Ambiguous:
939 // Let the LookupResult structure handle ambiguities.
944 // Check where the name exists but isn't a tag type and use that to emit
945 // better diagnostics.
946 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
947 SemaRef.LookupQualifiedName(Result, DC);
948 switch (Result.getResultKind()) {
949 case LookupResult::Found:
950 case LookupResult::FoundOverloaded:
951 case LookupResult::FoundUnresolvedValue: {
952 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
954 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
955 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
956 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
957 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
958 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
962 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
963 << Kind << Id << DC << QualifierLoc.getSourceRange();
969 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
971 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
972 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
976 // Build the elaborated-type-specifier type.
977 QualType T = SemaRef.Context.getTypeDeclType(Tag);
978 return SemaRef.Context.getElaboratedType(Keyword,
979 QualifierLoc.getNestedNameSpecifier(),
983 /// \brief Build a new pack expansion type.
985 /// By default, builds a new PackExpansionType type from the given pattern.
986 /// Subclasses may override this routine to provide different behavior.
987 QualType RebuildPackExpansionType(QualType Pattern,
988 SourceRange PatternRange,
989 SourceLocation EllipsisLoc,
990 Optional<unsigned> NumExpansions) {
991 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
995 /// \brief Build a new atomic type given its value type.
997 /// By default, performs semantic analysis when building the atomic type.
998 /// Subclasses may override this routine to provide different behavior.
999 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1001 /// \brief Build a new template name given a nested name specifier, a flag
1002 /// indicating whether the "template" keyword was provided, and the template
1003 /// that the template name refers to.
1005 /// By default, builds the new template name directly. Subclasses may override
1006 /// this routine to provide different behavior.
1007 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1009 TemplateDecl *Template);
1011 /// \brief Build a new template name given a nested name specifier and the
1012 /// name that is referred to as a template.
1014 /// By default, performs semantic analysis to determine whether the name can
1015 /// be resolved to a specific template, then builds the appropriate kind of
1016 /// template name. Subclasses may override this routine to provide different
1018 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1019 const IdentifierInfo &Name,
1020 SourceLocation NameLoc,
1021 QualType ObjectType,
1022 NamedDecl *FirstQualifierInScope);
1024 /// \brief Build a new template name given a nested name specifier and the
1025 /// overloaded operator name that is referred to as a template.
1027 /// By default, performs semantic analysis to determine whether the name can
1028 /// be resolved to a specific template, then builds the appropriate kind of
1029 /// template name. Subclasses may override this routine to provide different
1031 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1032 OverloadedOperatorKind Operator,
1033 SourceLocation NameLoc,
1034 QualType ObjectType);
1036 /// \brief Build a new template name given a template template parameter pack
1039 /// By default, performs semantic analysis to determine whether the name can
1040 /// be resolved to a specific template, then builds the appropriate kind of
1041 /// template name. Subclasses may override this routine to provide different
1043 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1044 const TemplateArgument &ArgPack) {
1045 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1048 /// \brief Build a new compound statement.
1050 /// By default, performs semantic analysis to build the new statement.
1051 /// Subclasses may override this routine to provide different behavior.
1052 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1053 MultiStmtArg Statements,
1054 SourceLocation RBraceLoc,
1056 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1060 /// \brief Build a new case statement.
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
1064 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1066 SourceLocation EllipsisLoc,
1068 SourceLocation ColonLoc) {
1069 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1073 /// \brief Attach the body to a new case statement.
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
1077 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1078 getSema().ActOnCaseStmtBody(S, Body);
1082 /// \brief Build a new default statement.
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
1086 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1087 SourceLocation ColonLoc,
1089 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1090 /*CurScope=*/nullptr);
1093 /// \brief Build a new label statement.
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
1097 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1098 SourceLocation ColonLoc, Stmt *SubStmt) {
1099 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1102 /// \brief Build a new label statement.
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
1106 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1107 ArrayRef<const Attr*> Attrs,
1109 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1112 /// \brief Build a new "if" statement.
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
1116 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
1117 VarDecl *CondVar, Stmt *Then,
1118 SourceLocation ElseLoc, Stmt *Else) {
1119 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
1122 /// \brief Start building a new switch statement.
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
1126 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
1127 Expr *Cond, VarDecl *CondVar) {
1128 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1132 /// \brief Attach the body to the switch statement.
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
1136 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1137 Stmt *Switch, Stmt *Body) {
1138 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1141 /// \brief Build a new while statement.
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
1145 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1146 VarDecl *CondVar, Stmt *Body) {
1147 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
1150 /// \brief Build a new do-while statement.
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
1154 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1155 SourceLocation WhileLoc, SourceLocation LParenLoc,
1156 Expr *Cond, SourceLocation RParenLoc) {
1157 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1161 /// \brief Build a new for statement.
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
1165 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1166 Stmt *Init, Sema::FullExprArg Cond,
1167 VarDecl *CondVar, Sema::FullExprArg Inc,
1168 SourceLocation RParenLoc, Stmt *Body) {
1169 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1170 CondVar, Inc, RParenLoc, Body);
1173 /// \brief Build a new goto statement.
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
1177 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1179 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1182 /// \brief Build a new indirect goto statement.
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
1186 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1187 SourceLocation StarLoc,
1189 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1192 /// \brief Build a new return statement.
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
1196 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1197 return getSema().BuildReturnStmt(ReturnLoc, Result);
1200 /// \brief Build a new declaration statement.
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
1204 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
1205 SourceLocation StartLoc, SourceLocation EndLoc) {
1206 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1207 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1210 /// \brief Build a new inline asm statement.
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
1214 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1215 bool IsVolatile, unsigned NumOutputs,
1216 unsigned NumInputs, IdentifierInfo **Names,
1217 MultiExprArg Constraints, MultiExprArg Exprs,
1218 Expr *AsmString, MultiExprArg Clobbers,
1219 SourceLocation RParenLoc) {
1220 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1221 NumInputs, Names, Constraints, Exprs,
1222 AsmString, Clobbers, RParenLoc);
1225 /// \brief Build a new MS style inline asm statement.
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
1229 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1230 ArrayRef<Token> AsmToks,
1231 StringRef AsmString,
1232 unsigned NumOutputs, unsigned NumInputs,
1233 ArrayRef<StringRef> Constraints,
1234 ArrayRef<StringRef> Clobbers,
1235 ArrayRef<Expr*> Exprs,
1236 SourceLocation EndLoc) {
1237 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1238 NumOutputs, NumInputs,
1239 Constraints, Clobbers, Exprs, EndLoc);
1242 /// \brief Build a new Objective-C \@try statement.
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
1246 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1248 MultiStmtArg CatchStmts,
1250 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1254 /// \brief Rebuild an Objective-C exception declaration.
1256 /// By default, performs semantic analysis to build the new declaration.
1257 /// Subclasses may override this routine to provide different behavior.
1258 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1259 TypeSourceInfo *TInfo, QualType T) {
1260 return getSema().BuildObjCExceptionDecl(TInfo, T,
1261 ExceptionDecl->getInnerLocStart(),
1262 ExceptionDecl->getLocation(),
1263 ExceptionDecl->getIdentifier());
1266 /// \brief Build a new Objective-C \@catch statement.
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
1270 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1271 SourceLocation RParenLoc,
1274 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1278 /// \brief Build a new Objective-C \@finally statement.
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
1282 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1284 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1287 /// \brief Build a new Objective-C \@throw statement.
1289 /// By default, performs semantic analysis to build the new statement.
1290 /// Subclasses may override this routine to provide different behavior.
1291 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1293 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1296 /// \brief Build a new OpenMP executable directive.
1298 /// By default, performs semantic analysis to build the new statement.
1299 /// Subclasses may override this routine to provide different behavior.
1300 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1301 DeclarationNameInfo DirName,
1302 ArrayRef<OMPClause *> Clauses,
1303 Stmt *AStmt, SourceLocation StartLoc,
1304 SourceLocation EndLoc) {
1305 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1306 AStmt, StartLoc, EndLoc);
1309 /// \brief Build a new OpenMP 'if' clause.
1311 /// By default, performs semantic analysis to build the new OpenMP clause.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OMPClause *RebuildOMPIfClause(Expr *Condition,
1314 SourceLocation StartLoc,
1315 SourceLocation LParenLoc,
1316 SourceLocation EndLoc) {
1317 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1321 /// \brief Build a new OpenMP 'final' clause.
1323 /// By default, performs semantic analysis to build the new OpenMP clause.
1324 /// Subclasses may override this routine to provide different behavior.
1325 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1326 SourceLocation LParenLoc,
1327 SourceLocation EndLoc) {
1328 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1332 /// \brief Build a new OpenMP 'num_threads' clause.
1334 /// By default, performs semantic analysis to build the new OpenMP clause.
1335 /// Subclasses may override this routine to provide different behavior.
1336 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1337 SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1344 /// \brief Build a new OpenMP 'safelen' clause.
1346 /// By default, performs semantic analysis to build the new OpenMP clause.
1347 /// Subclasses may override this routine to provide different behavior.
1348 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1349 SourceLocation LParenLoc,
1350 SourceLocation EndLoc) {
1351 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1354 /// \brief Build a new OpenMP 'collapse' clause.
1356 /// By default, performs semantic analysis to build the new OpenMP clause.
1357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1359 SourceLocation LParenLoc,
1360 SourceLocation EndLoc) {
1361 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1365 /// \brief Build a new OpenMP 'default' clause.
1367 /// By default, performs semantic analysis to build the new OpenMP clause.
1368 /// Subclasses may override this routine to provide different behavior.
1369 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1370 SourceLocation KindKwLoc,
1371 SourceLocation StartLoc,
1372 SourceLocation LParenLoc,
1373 SourceLocation EndLoc) {
1374 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1375 StartLoc, LParenLoc, EndLoc);
1378 /// \brief Build a new OpenMP 'proc_bind' clause.
1380 /// By default, performs semantic analysis to build the new OpenMP clause.
1381 /// Subclasses may override this routine to provide different behavior.
1382 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1383 SourceLocation KindKwLoc,
1384 SourceLocation StartLoc,
1385 SourceLocation LParenLoc,
1386 SourceLocation EndLoc) {
1387 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1388 StartLoc, LParenLoc, EndLoc);
1391 /// \brief Build a new OpenMP 'schedule' clause.
1393 /// By default, performs semantic analysis to build the new OpenMP clause.
1394 /// Subclasses may override this routine to provide different behavior.
1395 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1397 SourceLocation StartLoc,
1398 SourceLocation LParenLoc,
1399 SourceLocation KindLoc,
1400 SourceLocation CommaLoc,
1401 SourceLocation EndLoc) {
1402 return getSema().ActOnOpenMPScheduleClause(
1403 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1406 /// \brief Build a new OpenMP 'private' clause.
1408 /// By default, performs semantic analysis to build the new OpenMP clause.
1409 /// Subclasses may override this routine to provide different behavior.
1410 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1411 SourceLocation StartLoc,
1412 SourceLocation LParenLoc,
1413 SourceLocation EndLoc) {
1414 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1418 /// \brief Build a new OpenMP 'firstprivate' clause.
1420 /// By default, performs semantic analysis to build the new OpenMP clause.
1421 /// Subclasses may override this routine to provide different behavior.
1422 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1423 SourceLocation StartLoc,
1424 SourceLocation LParenLoc,
1425 SourceLocation EndLoc) {
1426 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1430 /// \brief Build a new OpenMP 'lastprivate' clause.
1432 /// By default, performs semantic analysis to build the new OpenMP clause.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1435 SourceLocation StartLoc,
1436 SourceLocation LParenLoc,
1437 SourceLocation EndLoc) {
1438 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1442 /// \brief Build a new OpenMP 'shared' clause.
1444 /// By default, performs semantic analysis to build the new OpenMP clause.
1445 /// Subclasses may override this routine to provide different behavior.
1446 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1447 SourceLocation StartLoc,
1448 SourceLocation LParenLoc,
1449 SourceLocation EndLoc) {
1450 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1454 /// \brief Build a new OpenMP 'reduction' clause.
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
1458 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1459 SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation ColonLoc,
1462 SourceLocation EndLoc,
1463 CXXScopeSpec &ReductionIdScopeSpec,
1464 const DeclarationNameInfo &ReductionId) {
1465 return getSema().ActOnOpenMPReductionClause(
1466 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1470 /// \brief Build a new OpenMP 'linear' clause.
1472 /// By default, performs semantic analysis to build the new OpenMP clause.
1473 /// Subclasses may override this routine to provide different behavior.
1474 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1475 SourceLocation StartLoc,
1476 SourceLocation LParenLoc,
1477 SourceLocation ColonLoc,
1478 SourceLocation EndLoc) {
1479 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1483 /// \brief Build a new OpenMP 'aligned' clause.
1485 /// By default, performs semantic analysis to build the new OpenMP clause.
1486 /// Subclasses may override this routine to provide different behavior.
1487 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1488 SourceLocation StartLoc,
1489 SourceLocation LParenLoc,
1490 SourceLocation ColonLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1493 LParenLoc, ColonLoc, EndLoc);
1496 /// \brief Build a new OpenMP 'copyin' clause.
1498 /// By default, performs semantic analysis to build the new OpenMP clause.
1499 /// Subclasses may override this routine to provide different behavior.
1500 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1508 /// \brief Build a new OpenMP 'copyprivate' clause.
1510 /// By default, performs semantic analysis to build the new OpenMP clause.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation EndLoc) {
1516 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1520 /// \brief Build a new OpenMP 'flush' pseudo clause.
1522 /// By default, performs semantic analysis to build the new OpenMP clause.
1523 /// Subclasses may override this routine to provide different behavior.
1524 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1525 SourceLocation StartLoc,
1526 SourceLocation LParenLoc,
1527 SourceLocation EndLoc) {
1528 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1532 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1534 /// By default, performs semantic analysis to build the new statement.
1535 /// Subclasses may override this routine to provide different behavior.
1536 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1538 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1541 /// \brief Build a new Objective-C \@synchronized statement.
1543 /// By default, performs semantic analysis to build the new statement.
1544 /// Subclasses may override this routine to provide different behavior.
1545 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1546 Expr *Object, Stmt *Body) {
1547 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1550 /// \brief Build a new Objective-C \@autoreleasepool statement.
1552 /// By default, performs semantic analysis to build the new statement.
1553 /// Subclasses may override this routine to provide different behavior.
1554 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1556 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1559 /// \brief Build a new Objective-C fast enumeration statement.
1561 /// By default, performs semantic analysis to build the new statement.
1562 /// Subclasses may override this routine to provide different behavior.
1563 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1566 SourceLocation RParenLoc,
1568 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1572 if (ForEachStmt.isInvalid())
1575 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1578 /// \brief Build a new C++ exception declaration.
1580 /// By default, performs semantic analysis to build the new decaration.
1581 /// Subclasses may override this routine to provide different behavior.
1582 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1583 TypeSourceInfo *Declarator,
1584 SourceLocation StartLoc,
1585 SourceLocation IdLoc,
1586 IdentifierInfo *Id) {
1587 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1588 StartLoc, IdLoc, Id);
1590 getSema().CurContext->addDecl(Var);
1594 /// \brief Build a new C++ catch statement.
1596 /// By default, performs semantic analysis to build the new statement.
1597 /// Subclasses may override this routine to provide different behavior.
1598 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1599 VarDecl *ExceptionDecl,
1601 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1605 /// \brief Build a new C++ try statement.
1607 /// By default, performs semantic analysis to build the new statement.
1608 /// Subclasses may override this routine to provide different behavior.
1609 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1610 ArrayRef<Stmt *> Handlers) {
1611 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1614 /// \brief Build a new C++0x range-based for statement.
1616 /// By default, performs semantic analysis to build the new statement.
1617 /// Subclasses may override this routine to provide different behavior.
1618 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1619 SourceLocation ColonLoc,
1620 Stmt *Range, Stmt *BeginEnd,
1621 Expr *Cond, Expr *Inc,
1623 SourceLocation RParenLoc) {
1624 // If we've just learned that the range is actually an Objective-C
1625 // collection, treat this as an Objective-C fast enumeration loop.
1626 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1627 if (RangeStmt->isSingleDecl()) {
1628 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1629 if (RangeVar->isInvalidDecl())
1632 Expr *RangeExpr = RangeVar->getInit();
1633 if (!RangeExpr->isTypeDependent() &&
1634 RangeExpr->getType()->isObjCObjectPointerType())
1635 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1641 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1642 Cond, Inc, LoopVar, RParenLoc,
1643 Sema::BFRK_Rebuild);
1646 /// \brief Build a new C++0x range-based for statement.
1648 /// By default, performs semantic analysis to build the new statement.
1649 /// Subclasses may override this routine to provide different behavior.
1650 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1652 NestedNameSpecifierLoc QualifierLoc,
1653 DeclarationNameInfo NameInfo,
1655 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1656 QualifierLoc, NameInfo, Nested);
1659 /// \brief Attach body to a C++0x range-based for statement.
1661 /// By default, performs semantic analysis to finish the new statement.
1662 /// Subclasses may override this routine to provide different behavior.
1663 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1664 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1667 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1668 Stmt *TryBlock, Stmt *Handler, int HandlerIndex,
1669 int HandlerParentIndex) {
1670 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler,
1671 HandlerIndex, HandlerParentIndex);
1674 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
1676 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
1679 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1680 return getSema().ActOnSEHFinallyBlock(Loc, Block);
1683 /// \brief Build a new expression that references a declaration.
1685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
1687 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1690 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1694 /// \brief Build a new expression that references a declaration.
1696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
1698 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1700 const DeclarationNameInfo &NameInfo,
1701 TemplateArgumentListInfo *TemplateArgs) {
1703 SS.Adopt(QualifierLoc);
1705 // FIXME: loses template args.
1707 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1710 /// \brief Build a new expression in parentheses.
1712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
1714 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1715 SourceLocation RParen) {
1716 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1719 /// \brief Build a new pseudo-destructor expression.
1721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
1723 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1724 SourceLocation OperatorLoc,
1727 TypeSourceInfo *ScopeType,
1728 SourceLocation CCLoc,
1729 SourceLocation TildeLoc,
1730 PseudoDestructorTypeStorage Destroyed);
1732 /// \brief Build a new unary operator expression.
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
1736 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1737 UnaryOperatorKind Opc,
1739 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
1742 /// \brief Build a new builtin offsetof expression.
1744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
1746 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1747 TypeSourceInfo *Type,
1748 Sema::OffsetOfComponent *Components,
1749 unsigned NumComponents,
1750 SourceLocation RParenLoc) {
1751 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1752 NumComponents, RParenLoc);
1755 /// \brief Build a new sizeof, alignof or vec_step expression with a
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
1760 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1761 SourceLocation OpLoc,
1762 UnaryExprOrTypeTrait ExprKind,
1764 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1767 /// \brief Build a new sizeof, alignof or vec step expression with an
1768 /// expression argument.
1770 /// By default, performs semantic analysis to build the new expression.
1771 /// Subclasses may override this routine to provide different behavior.
1772 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1773 UnaryExprOrTypeTrait ExprKind,
1776 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1777 if (Result.isInvalid())
1783 /// \brief Build a new array subscript expression.
1785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
1787 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1788 SourceLocation LBracketLoc,
1790 SourceLocation RBracketLoc) {
1791 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
1796 /// \brief Build a new call expression.
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
1800 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1802 SourceLocation RParenLoc,
1803 Expr *ExecConfig = nullptr) {
1804 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
1805 Args, RParenLoc, ExecConfig);
1808 /// \brief Build a new member access expression.
1810 /// By default, performs semantic analysis to build the new expression.
1811 /// Subclasses may override this routine to provide different behavior.
1812 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1814 NestedNameSpecifierLoc QualifierLoc,
1815 SourceLocation TemplateKWLoc,
1816 const DeclarationNameInfo &MemberNameInfo,
1818 NamedDecl *FoundDecl,
1819 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1820 NamedDecl *FirstQualifierInScope) {
1821 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1823 if (!Member->getDeclName()) {
1824 // We have a reference to an unnamed field. This is always the
1825 // base of an anonymous struct/union member access, i.e. the
1826 // field is always of record type.
1827 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1828 assert(Member->getType()->isRecordType() &&
1829 "unnamed member not of record type?");
1832 getSema().PerformObjectMemberConversion(BaseResult.get(),
1833 QualifierLoc.getNestedNameSpecifier(),
1835 if (BaseResult.isInvalid())
1837 Base = BaseResult.get();
1838 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
1840 new (getSema().Context) MemberExpr(Base, isArrow,
1841 Member, MemberNameInfo,
1842 cast<FieldDecl>(Member)->getType(),
1848 SS.Adopt(QualifierLoc);
1850 Base = BaseResult.get();
1851 QualType BaseType = Base->getType();
1853 // FIXME: this involves duplicating earlier analysis in a lot of
1854 // cases; we should avoid this when possible.
1855 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
1856 R.addDecl(FoundDecl);
1859 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1861 FirstQualifierInScope,
1862 R, ExplicitTemplateArgs);
1865 /// \brief Build a new binary operator expression.
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
1869 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1870 BinaryOperatorKind Opc,
1871 Expr *LHS, Expr *RHS) {
1872 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
1875 /// \brief Build a new conditional operator expression.
1877 /// By default, performs semantic analysis to build the new expression.
1878 /// Subclasses may override this routine to provide different behavior.
1879 ExprResult RebuildConditionalOperator(Expr *Cond,
1880 SourceLocation QuestionLoc,
1882 SourceLocation ColonLoc,
1884 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1888 /// \brief Build a new C-style cast expression.
1890 /// By default, performs semantic analysis to build the new expression.
1891 /// Subclasses may override this routine to provide different behavior.
1892 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1893 TypeSourceInfo *TInfo,
1894 SourceLocation RParenLoc,
1896 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1900 /// \brief Build a new compound literal expression.
1902 /// By default, performs semantic analysis to build the new expression.
1903 /// Subclasses may override this routine to provide different behavior.
1904 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1905 TypeSourceInfo *TInfo,
1906 SourceLocation RParenLoc,
1908 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1912 /// \brief Build a new extended vector element access expression.
1914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
1916 ExprResult RebuildExtVectorElementExpr(Expr *Base,
1917 SourceLocation OpLoc,
1918 SourceLocation AccessorLoc,
1919 IdentifierInfo &Accessor) {
1922 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
1923 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1924 OpLoc, /*IsArrow*/ false,
1925 SS, SourceLocation(),
1926 /*FirstQualifierInScope*/ nullptr,
1928 /* TemplateArgs */ nullptr);
1931 /// \brief Build a new initializer list expression.
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
1935 ExprResult RebuildInitList(SourceLocation LBraceLoc,
1937 SourceLocation RBraceLoc,
1938 QualType ResultTy) {
1940 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
1941 if (Result.isInvalid() || ResultTy->isDependentType())
1944 // Patch in the result type we were given, which may have been computed
1945 // when the initial InitListExpr was built.
1946 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1947 ILE->setType(ResultTy);
1951 /// \brief Build a new designated initializer expression.
1953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
1955 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1956 MultiExprArg ArrayExprs,
1957 SourceLocation EqualOrColonLoc,
1961 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1963 if (Result.isInvalid())
1969 /// \brief Build a new value-initialized expression.
1971 /// By default, builds the implicit value initialization without performing
1972 /// any semantic analysis. Subclasses may override this routine to provide
1973 /// different behavior.
1974 ExprResult RebuildImplicitValueInitExpr(QualType T) {
1975 return new (SemaRef.Context) ImplicitValueInitExpr(T);
1978 /// \brief Build a new \c va_arg expression.
1980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
1982 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1983 Expr *SubExpr, TypeSourceInfo *TInfo,
1984 SourceLocation RParenLoc) {
1985 return getSema().BuildVAArgExpr(BuiltinLoc,
1990 /// \brief Build a new expression list in parentheses.
1992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
1994 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1995 MultiExprArg SubExprs,
1996 SourceLocation RParenLoc) {
1997 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2000 /// \brief Build a new address-of-label expression.
2002 /// By default, performs semantic analysis, using the name of the label
2003 /// rather than attempting to map the label statement itself.
2004 /// Subclasses may override this routine to provide different behavior.
2005 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
2006 SourceLocation LabelLoc, LabelDecl *Label) {
2007 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2010 /// \brief Build a new GNU statement expression.
2012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
2014 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
2016 SourceLocation RParenLoc) {
2017 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2020 /// \brief Build a new __builtin_choose_expr expression.
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
2024 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
2025 Expr *Cond, Expr *LHS, Expr *RHS,
2026 SourceLocation RParenLoc) {
2027 return SemaRef.ActOnChooseExpr(BuiltinLoc,
2032 /// \brief Build a new generic selection expression.
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
2036 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2037 SourceLocation DefaultLoc,
2038 SourceLocation RParenLoc,
2039 Expr *ControllingExpr,
2040 ArrayRef<TypeSourceInfo *> Types,
2041 ArrayRef<Expr *> Exprs) {
2042 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2043 ControllingExpr, Types, Exprs);
2046 /// \brief Build a new overloaded operator call expression.
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// The semantic analysis provides the behavior of template instantiation,
2050 /// copying with transformations that turn what looks like an overloaded
2051 /// operator call into a use of a builtin operator, performing
2052 /// argument-dependent lookup, etc. Subclasses may override this routine to
2053 /// provide different behavior.
2054 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2055 SourceLocation OpLoc,
2060 /// \brief Build a new C++ "named" cast expression, such as static_cast or
2061 /// reinterpret_cast.
2063 /// By default, this routine dispatches to one of the more-specific routines
2064 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2065 /// Subclasses may override this routine to provide different behavior.
2066 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
2067 Stmt::StmtClass Class,
2068 SourceLocation LAngleLoc,
2069 TypeSourceInfo *TInfo,
2070 SourceLocation RAngleLoc,
2071 SourceLocation LParenLoc,
2073 SourceLocation RParenLoc) {
2075 case Stmt::CXXStaticCastExprClass:
2076 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2077 RAngleLoc, LParenLoc,
2078 SubExpr, RParenLoc);
2080 case Stmt::CXXDynamicCastExprClass:
2081 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2082 RAngleLoc, LParenLoc,
2083 SubExpr, RParenLoc);
2085 case Stmt::CXXReinterpretCastExprClass:
2086 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2087 RAngleLoc, LParenLoc,
2091 case Stmt::CXXConstCastExprClass:
2092 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2093 RAngleLoc, LParenLoc,
2094 SubExpr, RParenLoc);
2097 llvm_unreachable("Invalid C++ named cast");
2101 /// \brief Build a new C++ static_cast expression.
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
2105 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
2106 SourceLocation LAngleLoc,
2107 TypeSourceInfo *TInfo,
2108 SourceLocation RAngleLoc,
2109 SourceLocation LParenLoc,
2111 SourceLocation RParenLoc) {
2112 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2114 SourceRange(LAngleLoc, RAngleLoc),
2115 SourceRange(LParenLoc, RParenLoc));
2118 /// \brief Build a new C++ dynamic_cast expression.
2120 /// By default, performs semantic analysis to build the new expression.
2121 /// Subclasses may override this routine to provide different behavior.
2122 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
2123 SourceLocation LAngleLoc,
2124 TypeSourceInfo *TInfo,
2125 SourceLocation RAngleLoc,
2126 SourceLocation LParenLoc,
2128 SourceLocation RParenLoc) {
2129 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2131 SourceRange(LAngleLoc, RAngleLoc),
2132 SourceRange(LParenLoc, RParenLoc));
2135 /// \brief Build a new C++ reinterpret_cast expression.
2137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
2139 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
2140 SourceLocation LAngleLoc,
2141 TypeSourceInfo *TInfo,
2142 SourceLocation RAngleLoc,
2143 SourceLocation LParenLoc,
2145 SourceLocation RParenLoc) {
2146 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2148 SourceRange(LAngleLoc, RAngleLoc),
2149 SourceRange(LParenLoc, RParenLoc));
2152 /// \brief Build a new C++ const_cast expression.
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
2156 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
2157 SourceLocation LAngleLoc,
2158 TypeSourceInfo *TInfo,
2159 SourceLocation RAngleLoc,
2160 SourceLocation LParenLoc,
2162 SourceLocation RParenLoc) {
2163 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2165 SourceRange(LAngleLoc, RAngleLoc),
2166 SourceRange(LParenLoc, RParenLoc));
2169 /// \brief Build a new C++ functional-style cast expression.
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
2173 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2174 SourceLocation LParenLoc,
2176 SourceLocation RParenLoc) {
2177 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2178 MultiExprArg(&Sub, 1),
2182 /// \brief Build a new C++ typeid(type) expression.
2184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
2186 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2187 SourceLocation TypeidLoc,
2188 TypeSourceInfo *Operand,
2189 SourceLocation RParenLoc) {
2190 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2195 /// \brief Build a new C++ typeid(expr) expression.
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
2199 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2200 SourceLocation TypeidLoc,
2202 SourceLocation RParenLoc) {
2203 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2207 /// \brief Build a new C++ __uuidof(type) expression.
2209 /// By default, performs semantic analysis to build the new expression.
2210 /// Subclasses may override this routine to provide different behavior.
2211 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2212 SourceLocation TypeidLoc,
2213 TypeSourceInfo *Operand,
2214 SourceLocation RParenLoc) {
2215 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2219 /// \brief Build a new C++ __uuidof(expr) expression.
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
2223 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2224 SourceLocation TypeidLoc,
2226 SourceLocation RParenLoc) {
2227 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2231 /// \brief Build a new C++ "this" expression.
2233 /// By default, builds a new "this" expression without performing any
2234 /// semantic analysis. Subclasses may override this routine to provide
2235 /// different behavior.
2236 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
2239 getSema().CheckCXXThisCapture(ThisLoc);
2240 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2243 /// \brief Build a new C++ throw expression.
2245 /// By default, performs semantic analysis to build the new expression.
2246 /// Subclasses may override this routine to provide different behavior.
2247 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2248 bool IsThrownVariableInScope) {
2249 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2252 /// \brief Build a new C++ default-argument expression.
2254 /// By default, builds a new default-argument expression, which does not
2255 /// require any semantic analysis. Subclasses may override this routine to
2256 /// provide different behavior.
2257 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
2258 ParmVarDecl *Param) {
2259 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2262 /// \brief Build a new C++11 default-initialization expression.
2264 /// By default, builds a new default field initialization expression, which
2265 /// does not require any semantic analysis. Subclasses may override this
2266 /// routine to provide different behavior.
2267 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2269 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2272 /// \brief Build a new C++ zero-initialization expression.
2274 /// By default, performs semantic analysis to build the new expression.
2275 /// Subclasses may override this routine to provide different behavior.
2276 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2277 SourceLocation LParenLoc,
2278 SourceLocation RParenLoc) {
2279 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2283 /// \brief Build a new C++ "new" expression.
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
2287 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
2289 SourceLocation PlacementLParen,
2290 MultiExprArg PlacementArgs,
2291 SourceLocation PlacementRParen,
2292 SourceRange TypeIdParens,
2293 QualType AllocatedType,
2294 TypeSourceInfo *AllocatedTypeInfo,
2296 SourceRange DirectInitRange,
2297 Expr *Initializer) {
2298 return getSema().BuildCXXNew(StartLoc, UseGlobal,
2310 /// \brief Build a new C++ "delete" expression.
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
2314 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2315 bool IsGlobalDelete,
2318 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2322 /// \brief Build a new type trait expression.
2324 /// By default, performs semantic analysis to build the new expression.
2325 /// Subclasses may override this routine to provide different behavior.
2326 ExprResult RebuildTypeTrait(TypeTrait Trait,
2327 SourceLocation StartLoc,
2328 ArrayRef<TypeSourceInfo *> Args,
2329 SourceLocation RParenLoc) {
2330 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2333 /// \brief Build a new array type trait expression.
2335 /// By default, performs semantic analysis to build the new expression.
2336 /// Subclasses may override this routine to provide different behavior.
2337 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2338 SourceLocation StartLoc,
2339 TypeSourceInfo *TSInfo,
2341 SourceLocation RParenLoc) {
2342 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2345 /// \brief Build a new expression trait expression.
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
2349 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2350 SourceLocation StartLoc,
2352 SourceLocation RParenLoc) {
2353 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2356 /// \brief Build a new (previously unresolved) declaration reference
2359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
2361 ExprResult RebuildDependentScopeDeclRefExpr(
2362 NestedNameSpecifierLoc QualifierLoc,
2363 SourceLocation TemplateKWLoc,
2364 const DeclarationNameInfo &NameInfo,
2365 const TemplateArgumentListInfo *TemplateArgs,
2366 bool IsAddressOfOperand,
2367 TypeSourceInfo **RecoveryTSI) {
2369 SS.Adopt(QualifierLoc);
2371 if (TemplateArgs || TemplateKWLoc.isValid())
2372 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2375 return getSema().BuildQualifiedDeclarationNameExpr(
2376 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
2379 /// \brief Build a new template-id expression.
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
2383 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2384 SourceLocation TemplateKWLoc,
2387 const TemplateArgumentListInfo *TemplateArgs) {
2388 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2392 /// \brief Build a new object-construction expression.
2394 /// By default, performs semantic analysis to build the new expression.
2395 /// Subclasses may override this routine to provide different behavior.
2396 ExprResult RebuildCXXConstructExpr(QualType T,
2398 CXXConstructorDecl *Constructor,
2401 bool HadMultipleCandidates,
2402 bool ListInitialization,
2403 bool StdInitListInitialization,
2404 bool RequiresZeroInit,
2405 CXXConstructExpr::ConstructionKind ConstructKind,
2406 SourceRange ParenRange) {
2407 SmallVector<Expr*, 8> ConvertedArgs;
2408 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2412 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
2414 HadMultipleCandidates,
2416 StdInitListInitialization,
2417 RequiresZeroInit, ConstructKind,
2421 /// \brief Build a new object-construction expression.
2423 /// By default, performs semantic analysis to build the new expression.
2424 /// Subclasses may override this routine to provide different behavior.
2425 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2426 SourceLocation LParenLoc,
2428 SourceLocation RParenLoc) {
2429 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2435 /// \brief Build a new object-construction expression.
2437 /// By default, performs semantic analysis to build the new expression.
2438 /// Subclasses may override this routine to provide different behavior.
2439 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2440 SourceLocation LParenLoc,
2442 SourceLocation RParenLoc) {
2443 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2449 /// \brief Build a new member reference expression.
2451 /// By default, performs semantic analysis to build the new expression.
2452 /// Subclasses may override this routine to provide different behavior.
2453 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2456 SourceLocation OperatorLoc,
2457 NestedNameSpecifierLoc QualifierLoc,
2458 SourceLocation TemplateKWLoc,
2459 NamedDecl *FirstQualifierInScope,
2460 const DeclarationNameInfo &MemberNameInfo,
2461 const TemplateArgumentListInfo *TemplateArgs) {
2463 SS.Adopt(QualifierLoc);
2465 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2466 OperatorLoc, IsArrow,
2468 FirstQualifierInScope,
2473 /// \brief Build a new member reference expression.
2475 /// By default, performs semantic analysis to build the new expression.
2476 /// Subclasses may override this routine to provide different behavior.
2477 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2478 SourceLocation OperatorLoc,
2480 NestedNameSpecifierLoc QualifierLoc,
2481 SourceLocation TemplateKWLoc,
2482 NamedDecl *FirstQualifierInScope,
2484 const TemplateArgumentListInfo *TemplateArgs) {
2486 SS.Adopt(QualifierLoc);
2488 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2489 OperatorLoc, IsArrow,
2491 FirstQualifierInScope,
2495 /// \brief Build a new noexcept expression.
2497 /// By default, performs semantic analysis to build the new expression.
2498 /// Subclasses may override this routine to provide different behavior.
2499 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2500 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2503 /// \brief Build a new expression to compute the length of a parameter pack.
2504 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2505 SourceLocation PackLoc,
2506 SourceLocation RParenLoc,
2507 Optional<unsigned> Length) {
2509 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2510 OperatorLoc, Pack, PackLoc,
2511 RParenLoc, *Length);
2513 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2514 OperatorLoc, Pack, PackLoc,
2518 /// \brief Build a new Objective-C boxed expression.
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// Subclasses may override this routine to provide different behavior.
2522 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2523 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2526 /// \brief Build a new Objective-C array literal.
2528 /// By default, performs semantic analysis to build the new expression.
2529 /// Subclasses may override this routine to provide different behavior.
2530 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2531 Expr **Elements, unsigned NumElements) {
2532 return getSema().BuildObjCArrayLiteral(Range,
2533 MultiExprArg(Elements, NumElements));
2536 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2537 Expr *Base, Expr *Key,
2538 ObjCMethodDecl *getterMethod,
2539 ObjCMethodDecl *setterMethod) {
2540 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2541 getterMethod, setterMethod);
2544 /// \brief Build a new Objective-C dictionary literal.
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
2548 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2549 ObjCDictionaryElement *Elements,
2550 unsigned NumElements) {
2551 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2554 /// \brief Build a new Objective-C \@encode expression.
2556 /// By default, performs semantic analysis to build the new expression.
2557 /// Subclasses may override this routine to provide different behavior.
2558 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2559 TypeSourceInfo *EncodeTypeInfo,
2560 SourceLocation RParenLoc) {
2561 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2564 /// \brief Build a new Objective-C class message.
2565 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2567 ArrayRef<SourceLocation> SelectorLocs,
2568 ObjCMethodDecl *Method,
2569 SourceLocation LBracLoc,
2571 SourceLocation RBracLoc) {
2572 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2573 ReceiverTypeInfo->getType(),
2574 /*SuperLoc=*/SourceLocation(),
2575 Sel, Method, LBracLoc, SelectorLocs,
2579 /// \brief Build a new Objective-C instance message.
2580 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2582 ArrayRef<SourceLocation> SelectorLocs,
2583 ObjCMethodDecl *Method,
2584 SourceLocation LBracLoc,
2586 SourceLocation RBracLoc) {
2587 return SemaRef.BuildInstanceMessage(Receiver,
2588 Receiver->getType(),
2589 /*SuperLoc=*/SourceLocation(),
2590 Sel, Method, LBracLoc, SelectorLocs,
2594 /// \brief Build a new Objective-C ivar reference expression.
2596 /// By default, performs semantic analysis to build the new expression.
2597 /// Subclasses may override this routine to provide different behavior.
2598 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2599 SourceLocation IvarLoc,
2600 bool IsArrow, bool IsFreeIvar) {
2601 // FIXME: We lose track of the IsFreeIvar bit.
2603 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2604 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2605 /*FIXME:*/IvarLoc, IsArrow,
2606 SS, SourceLocation(),
2607 /*FirstQualifierInScope=*/nullptr,
2609 /*TemplateArgs=*/nullptr);
2612 /// \brief Build a new Objective-C property reference expression.
2614 /// By default, performs semantic analysis to build the new expression.
2615 /// Subclasses may override this routine to provide different behavior.
2616 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2617 ObjCPropertyDecl *Property,
2618 SourceLocation PropertyLoc) {
2620 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2621 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2622 /*FIXME:*/PropertyLoc,
2624 SS, SourceLocation(),
2625 /*FirstQualifierInScope=*/nullptr,
2627 /*TemplateArgs=*/nullptr);
2630 /// \brief Build a new Objective-C property reference expression.
2632 /// By default, performs semantic analysis to build the new expression.
2633 /// Subclasses may override this routine to provide different behavior.
2634 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2635 ObjCMethodDecl *Getter,
2636 ObjCMethodDecl *Setter,
2637 SourceLocation PropertyLoc) {
2638 // Since these expressions can only be value-dependent, we do not
2639 // need to perform semantic analysis again.
2641 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2642 VK_LValue, OK_ObjCProperty,
2643 PropertyLoc, Base));
2646 /// \brief Build a new Objective-C "isa" expression.
2648 /// By default, performs semantic analysis to build the new expression.
2649 /// Subclasses may override this routine to provide different behavior.
2650 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2651 SourceLocation OpLoc, bool IsArrow) {
2653 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2654 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2656 SS, SourceLocation(),
2657 /*FirstQualifierInScope=*/nullptr,
2659 /*TemplateArgs=*/nullptr);
2662 /// \brief Build a new shuffle vector expression.
2664 /// By default, performs semantic analysis to build the new expression.
2665 /// Subclasses may override this routine to provide different behavior.
2666 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2667 MultiExprArg SubExprs,
2668 SourceLocation RParenLoc) {
2669 // Find the declaration for __builtin_shufflevector
2670 const IdentifierInfo &Name
2671 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2672 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2673 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2674 assert(!Lookup.empty() && "No __builtin_shufflevector?");
2676 // Build a reference to the __builtin_shufflevector builtin
2677 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
2678 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2679 SemaRef.Context.BuiltinFnTy,
2680 VK_RValue, BuiltinLoc);
2681 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2682 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2683 CK_BuiltinFnToFnPtr).get();
2685 // Build the CallExpr
2686 ExprResult TheCall = new (SemaRef.Context) CallExpr(
2687 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2688 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
2690 // Type-check the __builtin_shufflevector expression.
2691 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
2694 /// \brief Build a new convert vector expression.
2695 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2696 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2697 SourceLocation RParenLoc) {
2698 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2699 BuiltinLoc, RParenLoc);
2702 /// \brief Build a new template argument pack expansion.
2704 /// By default, performs semantic analysis to build a new pack expansion
2705 /// for a template argument. Subclasses may override this routine to provide
2706 /// different behavior.
2707 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2708 SourceLocation EllipsisLoc,
2709 Optional<unsigned> NumExpansions) {
2710 switch (Pattern.getArgument().getKind()) {
2711 case TemplateArgument::Expression: {
2713 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2714 EllipsisLoc, NumExpansions);
2715 if (Result.isInvalid())
2716 return TemplateArgumentLoc();
2718 return TemplateArgumentLoc(Result.get(), Result.get());
2721 case TemplateArgument::Template:
2722 return TemplateArgumentLoc(TemplateArgument(
2723 Pattern.getArgument().getAsTemplate(),
2725 Pattern.getTemplateQualifierLoc(),
2726 Pattern.getTemplateNameLoc(),
2729 case TemplateArgument::Null:
2730 case TemplateArgument::Integral:
2731 case TemplateArgument::Declaration:
2732 case TemplateArgument::Pack:
2733 case TemplateArgument::TemplateExpansion:
2734 case TemplateArgument::NullPtr:
2735 llvm_unreachable("Pack expansion pattern has no parameter packs");
2737 case TemplateArgument::Type:
2738 if (TypeSourceInfo *Expansion
2739 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2742 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2747 return TemplateArgumentLoc();
2750 /// \brief Build a new expression pack expansion.
2752 /// By default, performs semantic analysis to build a new pack expansion
2753 /// for an expression. Subclasses may override this routine to provide
2754 /// different behavior.
2755 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2756 Optional<unsigned> NumExpansions) {
2757 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2760 /// \brief Build a new atomic operation expression.
2762 /// By default, performs semantic analysis to build the new expression.
2763 /// Subclasses may override this routine to provide different behavior.
2764 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2765 MultiExprArg SubExprs,
2767 AtomicExpr::AtomicOp Op,
2768 SourceLocation RParenLoc) {
2769 // Just create the expression; there is not any interesting semantic
2770 // analysis here because we can't actually build an AtomicExpr until
2771 // we are sure it is semantically sound.
2772 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
2777 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2778 QualType ObjectType,
2779 NamedDecl *FirstQualifierInScope,
2782 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2783 QualType ObjectType,
2784 NamedDecl *FirstQualifierInScope,
2787 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2788 NamedDecl *FirstQualifierInScope,
2792 template<typename Derived>
2793 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
2797 switch (S->getStmtClass()) {
2798 case Stmt::NoStmtClass: break;
2800 // Transform individual statement nodes
2801 #define STMT(Node, Parent) \
2802 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2803 #define ABSTRACT_STMT(Node)
2804 #define EXPR(Node, Parent)
2805 #include "clang/AST/StmtNodes.inc"
2807 // Transform expressions by calling TransformExpr.
2808 #define STMT(Node, Parent)
2809 #define ABSTRACT_STMT(Stmt)
2810 #define EXPR(Node, Parent) case Stmt::Node##Class:
2811 #include "clang/AST/StmtNodes.inc"
2813 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
2817 return getSema().ActOnExprStmt(E);
2824 template<typename Derived>
2825 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2829 switch (S->getClauseKind()) {
2831 // Transform individual clause nodes
2832 #define OPENMP_CLAUSE(Name, Class) \
2833 case OMPC_ ## Name : \
2834 return getDerived().Transform ## Class(cast<Class>(S));
2835 #include "clang/Basic/OpenMPKinds.def"
2842 template<typename Derived>
2843 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2847 switch (E->getStmtClass()) {
2848 case Stmt::NoStmtClass: break;
2849 #define STMT(Node, Parent) case Stmt::Node##Class: break;
2850 #define ABSTRACT_STMT(Stmt)
2851 #define EXPR(Node, Parent) \
2852 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
2853 #include "clang/AST/StmtNodes.inc"
2859 template<typename Derived>
2860 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2862 // Initializers are instantiated like expressions, except that various outer
2863 // layers are stripped.
2867 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2868 Init = ExprTemp->getSubExpr();
2870 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2871 Init = MTE->GetTemporaryExpr();
2873 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2874 Init = Binder->getSubExpr();
2876 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2877 Init = ICE->getSubExprAsWritten();
2879 if (CXXStdInitializerListExpr *ILE =
2880 dyn_cast<CXXStdInitializerListExpr>(Init))
2881 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
2883 // If this is copy-initialization, we only need to reconstruct
2884 // InitListExprs. Other forms of copy-initialization will be a no-op if
2885 // the initializer is already the right type.
2886 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2887 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
2888 return getDerived().TransformExpr(Init);
2890 // Revert value-initialization back to empty parens.
2891 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2892 SourceRange Parens = VIE->getSourceRange();
2893 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
2897 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2898 if (isa<ImplicitValueInitExpr>(Init))
2899 return getDerived().RebuildParenListExpr(SourceLocation(), None,
2902 // Revert initialization by constructor back to a parenthesized or braced list
2903 // of expressions. Any other form of initializer can just be reused directly.
2904 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
2905 return getDerived().TransformExpr(Init);
2907 // If the initialization implicitly converted an initializer list to a
2908 // std::initializer_list object, unwrap the std::initializer_list too.
2909 if (Construct && Construct->isStdInitListInitialization())
2910 return TransformInitializer(Construct->getArg(0), NotCopyInit);
2912 SmallVector<Expr*, 8> NewArgs;
2913 bool ArgChanged = false;
2914 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2915 /*IsCall*/true, NewArgs, &ArgChanged))
2918 // If this was list initialization, revert to list form.
2919 if (Construct->isListInitialization())
2920 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2921 Construct->getLocEnd(),
2922 Construct->getType());
2924 // Build a ParenListExpr to represent anything else.
2925 SourceRange Parens = Construct->getParenOrBraceRange();
2926 if (Parens.isInvalid()) {
2927 // This was a variable declaration's initialization for which no initializer
2929 assert(NewArgs.empty() &&
2930 "no parens or braces but have direct init with arguments?");
2933 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2937 template<typename Derived>
2938 bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2941 SmallVectorImpl<Expr *> &Outputs,
2943 for (unsigned I = 0; I != NumInputs; ++I) {
2944 // If requested, drop call arguments that need to be dropped.
2945 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2952 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2953 Expr *Pattern = Expansion->getPattern();
2955 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2956 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2957 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2959 // Determine whether the set of unexpanded parameter packs can and should
2962 bool RetainExpansion = false;
2963 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2964 Optional<unsigned> NumExpansions = OrigNumExpansions;
2965 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2966 Pattern->getSourceRange(),
2968 Expand, RetainExpansion,
2973 // The transform has determined that we should perform a simple
2974 // transformation on the pack expansion, producing another pack
2976 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2977 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2978 if (OutPattern.isInvalid())
2981 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2982 Expansion->getEllipsisLoc(),
2984 if (Out.isInvalid())
2989 Outputs.push_back(Out.get());
2993 // Record right away that the argument was changed. This needs
2994 // to happen even if the array expands to nothing.
2995 if (ArgChanged) *ArgChanged = true;
2997 // The transform has determined that we should perform an elementwise
2998 // expansion of the pattern. Do so.
2999 for (unsigned I = 0; I != *NumExpansions; ++I) {
3000 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3001 ExprResult Out = getDerived().TransformExpr(Pattern);
3002 if (Out.isInvalid())
3005 // FIXME: Can this happen? We should not try to expand the pack
3007 if (Out.get()->containsUnexpandedParameterPack()) {
3008 Out = getDerived().RebuildPackExpansion(
3009 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3010 if (Out.isInvalid())
3014 Outputs.push_back(Out.get());
3017 // If we're supposed to retain a pack expansion, do so by temporarily
3018 // forgetting the partially-substituted parameter pack.
3019 if (RetainExpansion) {
3020 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3022 ExprResult Out = getDerived().TransformExpr(Pattern);
3023 if (Out.isInvalid())
3026 Out = getDerived().RebuildPackExpansion(
3027 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3028 if (Out.isInvalid())
3031 Outputs.push_back(Out.get());
3038 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3039 : getDerived().TransformExpr(Inputs[I]);
3040 if (Result.isInvalid())
3043 if (Result.get() != Inputs[I] && ArgChanged)
3046 Outputs.push_back(Result.get());
3052 template<typename Derived>
3053 NestedNameSpecifierLoc
3054 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3055 NestedNameSpecifierLoc NNS,
3056 QualType ObjectType,
3057 NamedDecl *FirstQualifierInScope) {
3058 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
3059 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3060 Qualifier = Qualifier.getPrefix())
3061 Qualifiers.push_back(Qualifier);
3064 while (!Qualifiers.empty()) {
3065 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3066 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
3068 switch (QNNS->getKind()) {
3069 case NestedNameSpecifier::Identifier:
3070 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
3071 *QNNS->getAsIdentifier(),
3072 Q.getLocalBeginLoc(),
3074 ObjectType, false, SS,
3075 FirstQualifierInScope, false))
3076 return NestedNameSpecifierLoc();
3080 case NestedNameSpecifier::Namespace: {
3082 = cast_or_null<NamespaceDecl>(
3083 getDerived().TransformDecl(
3084 Q.getLocalBeginLoc(),
3085 QNNS->getAsNamespace()));
3086 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3090 case NestedNameSpecifier::NamespaceAlias: {
3091 NamespaceAliasDecl *Alias
3092 = cast_or_null<NamespaceAliasDecl>(
3093 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3094 QNNS->getAsNamespaceAlias()));
3095 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3096 Q.getLocalEndLoc());
3100 case NestedNameSpecifier::Global:
3101 // There is no meaningful transformation that one could perform on the
3103 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3106 case NestedNameSpecifier::TypeSpecWithTemplate:
3107 case NestedNameSpecifier::TypeSpec: {
3108 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3109 FirstQualifierInScope, SS);
3112 return NestedNameSpecifierLoc();
3114 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3115 (SemaRef.getLangOpts().CPlusPlus11 &&
3116 TL.getType()->isEnumeralType())) {
3117 assert(!TL.getType().hasLocalQualifiers() &&
3118 "Can't get cv-qualifiers here");
3119 if (TL.getType()->isEnumeralType())
3120 SemaRef.Diag(TL.getBeginLoc(),
3121 diag::warn_cxx98_compat_enum_nested_name_spec);
3122 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3123 Q.getLocalEndLoc());
3126 // If the nested-name-specifier is an invalid type def, don't emit an
3127 // error because a previous error should have already been emitted.
3128 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3129 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3130 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3131 << TL.getType() << SS.getRange();
3133 return NestedNameSpecifierLoc();
3137 // The qualifier-in-scope and object type only apply to the leftmost entity.
3138 FirstQualifierInScope = nullptr;
3139 ObjectType = QualType();
3142 // Don't rebuild the nested-name-specifier if we don't have to.
3143 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3144 !getDerived().AlwaysRebuild())
3147 // If we can re-use the source-location data from the original
3148 // nested-name-specifier, do so.
3149 if (SS.location_size() == NNS.getDataLength() &&
3150 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3151 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3153 // Allocate new nested-name-specifier location information.
3154 return SS.getWithLocInContext(SemaRef.Context);
3157 template<typename Derived>
3159 TreeTransform<Derived>
3160 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
3161 DeclarationName Name = NameInfo.getName();
3163 return DeclarationNameInfo();
3165 switch (Name.getNameKind()) {
3166 case DeclarationName::Identifier:
3167 case DeclarationName::ObjCZeroArgSelector:
3168 case DeclarationName::ObjCOneArgSelector:
3169 case DeclarationName::ObjCMultiArgSelector:
3170 case DeclarationName::CXXOperatorName:
3171 case DeclarationName::CXXLiteralOperatorName:
3172 case DeclarationName::CXXUsingDirective:
3175 case DeclarationName::CXXConstructorName:
3176 case DeclarationName::CXXDestructorName:
3177 case DeclarationName::CXXConversionFunctionName: {
3178 TypeSourceInfo *NewTInfo;
3179 CanQualType NewCanTy;
3180 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3181 NewTInfo = getDerived().TransformType(OldTInfo);
3183 return DeclarationNameInfo();
3184 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3188 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3189 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3191 return DeclarationNameInfo();
3192 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3195 DeclarationName NewName
3196 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3198 DeclarationNameInfo NewNameInfo(NameInfo);
3199 NewNameInfo.setName(NewName);
3200 NewNameInfo.setNamedTypeInfo(NewTInfo);
3205 llvm_unreachable("Unknown name kind.");
3208 template<typename Derived>
3210 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3212 SourceLocation NameLoc,
3213 QualType ObjectType,
3214 NamedDecl *FirstQualifierInScope) {
3215 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3216 TemplateDecl *Template = QTN->getTemplateDecl();
3217 assert(Template && "qualified template name must refer to a template");
3219 TemplateDecl *TransTemplate
3220 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3223 return TemplateName();
3225 if (!getDerived().AlwaysRebuild() &&
3226 SS.getScopeRep() == QTN->getQualifier() &&
3227 TransTemplate == Template)
3230 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3234 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3235 if (SS.getScopeRep()) {
3236 // These apply to the scope specifier, not the template.
3237 ObjectType = QualType();
3238 FirstQualifierInScope = nullptr;
3241 if (!getDerived().AlwaysRebuild() &&
3242 SS.getScopeRep() == DTN->getQualifier() &&
3243 ObjectType.isNull())
3246 if (DTN->isIdentifier()) {
3247 return getDerived().RebuildTemplateName(SS,
3248 *DTN->getIdentifier(),
3251 FirstQualifierInScope);
3254 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3258 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3259 TemplateDecl *TransTemplate
3260 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3263 return TemplateName();
3265 if (!getDerived().AlwaysRebuild() &&
3266 TransTemplate == Template)
3269 return TemplateName(TransTemplate);
3272 if (SubstTemplateTemplateParmPackStorage *SubstPack
3273 = Name.getAsSubstTemplateTemplateParmPack()) {
3274 TemplateTemplateParmDecl *TransParam
3275 = cast_or_null<TemplateTemplateParmDecl>(
3276 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3278 return TemplateName();
3280 if (!getDerived().AlwaysRebuild() &&
3281 TransParam == SubstPack->getParameterPack())
3284 return getDerived().RebuildTemplateName(TransParam,
3285 SubstPack->getArgumentPack());
3288 // These should be getting filtered out before they reach the AST.
3289 llvm_unreachable("overloaded function decl survived to here");
3292 template<typename Derived>
3293 void TreeTransform<Derived>::InventTemplateArgumentLoc(
3294 const TemplateArgument &Arg,
3295 TemplateArgumentLoc &Output) {
3296 SourceLocation Loc = getDerived().getBaseLocation();
3297 switch (Arg.getKind()) {
3298 case TemplateArgument::Null:
3299 llvm_unreachable("null template argument in TreeTransform");
3302 case TemplateArgument::Type:
3303 Output = TemplateArgumentLoc(Arg,
3304 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3308 case TemplateArgument::Template:
3309 case TemplateArgument::TemplateExpansion: {
3310 NestedNameSpecifierLocBuilder Builder;
3311 TemplateName Template = Arg.getAsTemplate();
3312 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3313 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3314 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3315 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3317 if (Arg.getKind() == TemplateArgument::Template)
3318 Output = TemplateArgumentLoc(Arg,
3319 Builder.getWithLocInContext(SemaRef.Context),
3322 Output = TemplateArgumentLoc(Arg,
3323 Builder.getWithLocInContext(SemaRef.Context),
3329 case TemplateArgument::Expression:
3330 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3333 case TemplateArgument::Declaration:
3334 case TemplateArgument::Integral:
3335 case TemplateArgument::Pack:
3336 case TemplateArgument::NullPtr:
3337 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
3342 template<typename Derived>
3343 bool TreeTransform<Derived>::TransformTemplateArgument(
3344 const TemplateArgumentLoc &Input,
3345 TemplateArgumentLoc &Output) {
3346 const TemplateArgument &Arg = Input.getArgument();
3347 switch (Arg.getKind()) {
3348 case TemplateArgument::Null:
3349 case TemplateArgument::Integral:
3350 case TemplateArgument::Pack:
3351 case TemplateArgument::Declaration:
3352 case TemplateArgument::NullPtr:
3353 llvm_unreachable("Unexpected TemplateArgument");
3355 case TemplateArgument::Type: {
3356 TypeSourceInfo *DI = Input.getTypeSourceInfo();
3358 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3360 DI = getDerived().TransformType(DI);
3361 if (!DI) return true;
3363 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3367 case TemplateArgument::Template: {
3368 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3370 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3376 SS.Adopt(QualifierLoc);
3377 TemplateName Template
3378 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3379 Input.getTemplateNameLoc());
3380 if (Template.isNull())
3383 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3384 Input.getTemplateNameLoc());
3388 case TemplateArgument::TemplateExpansion:
3389 llvm_unreachable("Caller should expand pack expansions");
3391 case TemplateArgument::Expression: {
3392 // Template argument expressions are constant expressions.
3393 EnterExpressionEvaluationContext Unevaluated(getSema(),
3394 Sema::ConstantEvaluated);
3396 Expr *InputExpr = Input.getSourceExpression();
3397 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3399 ExprResult E = getDerived().TransformExpr(InputExpr);
3400 E = SemaRef.ActOnConstantExpression(E);
3401 if (E.isInvalid()) return true;
3402 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3407 // Work around bogus GCC warning
3411 /// \brief Iterator adaptor that invents template argument location information
3412 /// for each of the template arguments in its underlying iterator.
3413 template<typename Derived, typename InputIterator>
3414 class TemplateArgumentLocInventIterator {
3415 TreeTransform<Derived> &Self;
3419 typedef TemplateArgumentLoc value_type;
3420 typedef TemplateArgumentLoc reference;
3421 typedef typename std::iterator_traits<InputIterator>::difference_type
3423 typedef std::input_iterator_tag iterator_category;
3426 TemplateArgumentLoc Arg;
3429 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3431 const TemplateArgumentLoc *operator->() const { return &Arg; }
3434 TemplateArgumentLocInventIterator() { }
3436 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3438 : Self(Self), Iter(Iter) { }
3440 TemplateArgumentLocInventIterator &operator++() {
3445 TemplateArgumentLocInventIterator operator++(int) {
3446 TemplateArgumentLocInventIterator Old(*this);
3451 reference operator*() const {
3452 TemplateArgumentLoc Result;
3453 Self.InventTemplateArgumentLoc(*Iter, Result);
3457 pointer operator->() const { return pointer(**this); }
3459 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3460 const TemplateArgumentLocInventIterator &Y) {
3461 return X.Iter == Y.Iter;
3464 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3465 const TemplateArgumentLocInventIterator &Y) {
3466 return X.Iter != Y.Iter;
3470 template<typename Derived>
3471 template<typename InputIterator>
3472 bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3474 TemplateArgumentListInfo &Outputs) {
3475 for (; First != Last; ++First) {
3476 TemplateArgumentLoc Out;
3477 TemplateArgumentLoc In = *First;
3479 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3480 // Unpack argument packs, which we translate them into separate
3482 // FIXME: We could do much better if we could guarantee that the
3483 // TemplateArgumentLocInfo for the pack expansion would be usable for
3484 // all of the template arguments in the argument pack.
3485 typedef TemplateArgumentLocInventIterator<Derived,
3486 TemplateArgument::pack_iterator>
3488 if (TransformTemplateArguments(PackLocIterator(*this,
3489 In.getArgument().pack_begin()),
3490 PackLocIterator(*this,
3491 In.getArgument().pack_end()),
3498 if (In.getArgument().isPackExpansion()) {
3499 // We have a pack expansion, for which we will be substituting into
3501 SourceLocation Ellipsis;
3502 Optional<unsigned> OrigNumExpansions;
3503 TemplateArgumentLoc Pattern
3504 = getSema().getTemplateArgumentPackExpansionPattern(
3505 In, Ellipsis, OrigNumExpansions);
3507 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3508 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3509 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3511 // Determine whether the set of unexpanded parameter packs can and should
3514 bool RetainExpansion = false;
3515 Optional<unsigned> NumExpansions = OrigNumExpansions;
3516 if (getDerived().TryExpandParameterPacks(Ellipsis,
3517 Pattern.getSourceRange(),
3525 // The transform has determined that we should perform a simple
3526 // transformation on the pack expansion, producing another pack
3528 TemplateArgumentLoc OutPattern;
3529 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3530 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3533 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3535 if (Out.getArgument().isNull())
3538 Outputs.addArgument(Out);
3542 // The transform has determined that we should perform an elementwise
3543 // expansion of the pattern. Do so.
3544 for (unsigned I = 0; I != *NumExpansions; ++I) {
3545 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3547 if (getDerived().TransformTemplateArgument(Pattern, Out))
3550 if (Out.getArgument().containsUnexpandedParameterPack()) {
3551 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3553 if (Out.getArgument().isNull())
3557 Outputs.addArgument(Out);
3560 // If we're supposed to retain a pack expansion, do so by temporarily
3561 // forgetting the partially-substituted parameter pack.
3562 if (RetainExpansion) {
3563 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3565 if (getDerived().TransformTemplateArgument(Pattern, Out))
3568 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3570 if (Out.getArgument().isNull())
3573 Outputs.addArgument(Out);
3580 if (getDerived().TransformTemplateArgument(In, Out))
3583 Outputs.addArgument(Out);
3590 //===----------------------------------------------------------------------===//
3591 // Type transformation
3592 //===----------------------------------------------------------------------===//
3594 template<typename Derived>
3595 QualType TreeTransform<Derived>::TransformType(QualType T) {
3596 if (getDerived().AlreadyTransformed(T))
3599 // Temporary workaround. All of these transformations should
3600 // eventually turn into transformations on TypeLocs.
3601 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3602 getDerived().getBaseLocation());
3604 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3609 return NewDI->getType();
3612 template<typename Derived>
3613 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3614 // Refine the base location to the type's location.
3615 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3616 getDerived().getBaseEntity());
3617 if (getDerived().AlreadyTransformed(DI->getType()))
3622 TypeLoc TL = DI->getTypeLoc();
3623 TLB.reserve(TL.getFullDataSize());
3625 QualType Result = getDerived().TransformType(TLB, TL);
3626 if (Result.isNull())
3629 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3632 template<typename Derived>
3634 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3635 switch (T.getTypeLocClass()) {
3636 #define ABSTRACT_TYPELOC(CLASS, PARENT)
3637 #define TYPELOC(CLASS, PARENT) \
3638 case TypeLoc::CLASS: \
3639 return getDerived().Transform##CLASS##Type(TLB, \
3640 T.castAs<CLASS##TypeLoc>());
3641 #include "clang/AST/TypeLocNodes.def"
3644 llvm_unreachable("unhandled type loc!");
3647 /// FIXME: By default, this routine adds type qualifiers only to types
3648 /// that can have qualifiers, and silently suppresses those qualifiers
3649 /// that are not permitted (e.g., qualifiers on reference or function
3650 /// types). This is the right thing for template instantiation, but
3651 /// probably not for other clients.
3652 template<typename Derived>
3654 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
3655 QualifiedTypeLoc T) {
3656 Qualifiers Quals = T.getType().getLocalQualifiers();
3658 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3659 if (Result.isNull())
3662 // Silently suppress qualifiers if the result type can't be qualified.
3663 // FIXME: this is the right thing for template instantiation, but
3664 // probably not for other clients.
3665 if (Result->isFunctionType() || Result->isReferenceType())
3668 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3670 if (Quals.hasObjCLifetime()) {
3671 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3672 Quals.removeObjCLifetime();
3673 else if (Result.getObjCLifetime()) {
3675 // A lifetime qualifier applied to a substituted template parameter
3676 // overrides the lifetime qualifier from the template argument.
3677 const AutoType *AutoTy;
3678 if (const SubstTemplateTypeParmType *SubstTypeParam
3679 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3680 QualType Replacement = SubstTypeParam->getReplacementType();
3681 Qualifiers Qs = Replacement.getQualifiers();
3682 Qs.removeObjCLifetime();
3684 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3686 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3687 SubstTypeParam->getReplacedParameter(),
3689 TLB.TypeWasModifiedSafely(Result);
3690 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3691 // 'auto' types behave the same way as template parameters.
3692 QualType Deduced = AutoTy->getDeducedType();
3693 Qualifiers Qs = Deduced.getQualifiers();
3694 Qs.removeObjCLifetime();
3695 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3697 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3698 AutoTy->isDependentType());
3699 TLB.TypeWasModifiedSafely(Result);
3701 // Otherwise, complain about the addition of a qualifier to an
3702 // already-qualified type.
3703 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
3704 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
3707 Quals.removeObjCLifetime();
3711 if (!Quals.empty()) {
3712 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3713 // BuildQualifiedType might not add qualifiers if they are invalid.
3714 if (Result.hasLocalQualifiers())
3715 TLB.push<QualifiedTypeLoc>(Result);
3716 // No location information to preserve.
3722 template<typename Derived>
3724 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3725 QualType ObjectType,
3726 NamedDecl *UnqualLookup,
3728 if (getDerived().AlreadyTransformed(TL.getType()))
3731 TypeSourceInfo *TSI =
3732 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3734 return TSI->getTypeLoc();
3738 template<typename Derived>
3740 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3741 QualType ObjectType,
3742 NamedDecl *UnqualLookup,
3744 if (getDerived().AlreadyTransformed(TSInfo->getType()))
3747 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3751 template <typename Derived>
3752 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3753 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3755 QualType T = TL.getType();
3756 assert(!getDerived().AlreadyTransformed(T));
3761 if (isa<TemplateSpecializationType>(T)) {
3762 TemplateSpecializationTypeLoc SpecTL =
3763 TL.castAs<TemplateSpecializationTypeLoc>();
3765 TemplateName Template
3766 = getDerived().TransformTemplateName(SS,
3767 SpecTL.getTypePtr()->getTemplateName(),
3768 SpecTL.getTemplateNameLoc(),
3769 ObjectType, UnqualLookup);
3770 if (Template.isNull())
3773 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3775 } else if (isa<DependentTemplateSpecializationType>(T)) {
3776 DependentTemplateSpecializationTypeLoc SpecTL =
3777 TL.castAs<DependentTemplateSpecializationTypeLoc>();
3779 TemplateName Template
3780 = getDerived().RebuildTemplateName(SS,
3781 *SpecTL.getTypePtr()->getIdentifier(),
3782 SpecTL.getTemplateNameLoc(),
3783 ObjectType, UnqualLookup);
3784 if (Template.isNull())
3787 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3792 // Nothing special needs to be done for these.
3793 Result = getDerived().TransformType(TLB, TL);
3796 if (Result.isNull())
3799 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3802 template <class TyLoc> static inline
3803 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3804 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3805 NewT.setNameLoc(T.getNameLoc());
3809 template<typename Derived>
3810 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
3812 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3813 NewT.setBuiltinLoc(T.getBuiltinLoc());
3814 if (T.needsExtraLocalData())
3815 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3819 template<typename Derived>
3820 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
3823 return TransformTypeSpecType(TLB, T);
3826 template <typename Derived>
3827 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3828 AdjustedTypeLoc TL) {
3829 // Adjustments applied during transformation are handled elsewhere.
3830 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3833 template<typename Derived>
3834 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3835 DecayedTypeLoc TL) {
3836 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3837 if (OriginalType.isNull())
3840 QualType Result = TL.getType();
3841 if (getDerived().AlwaysRebuild() ||
3842 OriginalType != TL.getOriginalLoc().getType())
3843 Result = SemaRef.Context.getDecayedType(OriginalType);
3844 TLB.push<DecayedTypeLoc>(Result);
3845 // Nothing to set for DecayedTypeLoc.
3849 template<typename Derived>
3850 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
3851 PointerTypeLoc TL) {
3852 QualType PointeeType
3853 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3854 if (PointeeType.isNull())
3857 QualType Result = TL.getType();
3858 if (PointeeType->getAs<ObjCObjectType>()) {
3859 // A dependent pointer type 'T *' has is being transformed such
3860 // that an Objective-C class type is being replaced for 'T'. The
3861 // resulting pointer type is an ObjCObjectPointerType, not a
3863 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3865 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3866 NewT.setStarLoc(TL.getStarLoc());
3870 if (getDerived().AlwaysRebuild() ||
3871 PointeeType != TL.getPointeeLoc().getType()) {
3872 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3873 if (Result.isNull())
3877 // Objective-C ARC can add lifetime qualifiers to the type that we're
3879 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3881 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3882 NewT.setSigilLoc(TL.getSigilLoc());
3886 template<typename Derived>
3888 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
3889 BlockPointerTypeLoc TL) {
3890 QualType PointeeType
3891 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3892 if (PointeeType.isNull())
3895 QualType Result = TL.getType();
3896 if (getDerived().AlwaysRebuild() ||
3897 PointeeType != TL.getPointeeLoc().getType()) {
3898 Result = getDerived().RebuildBlockPointerType(PointeeType,
3900 if (Result.isNull())
3904 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3905 NewT.setSigilLoc(TL.getSigilLoc());
3909 /// Transforms a reference type. Note that somewhat paradoxically we
3910 /// don't care whether the type itself is an l-value type or an r-value
3911 /// type; we only care if the type was *written* as an l-value type
3912 /// or an r-value type.
3913 template<typename Derived>
3915 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
3916 ReferenceTypeLoc TL) {
3917 const ReferenceType *T = TL.getTypePtr();
3919 // Note that this works with the pointee-as-written.
3920 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3921 if (PointeeType.isNull())
3924 QualType Result = TL.getType();
3925 if (getDerived().AlwaysRebuild() ||
3926 PointeeType != T->getPointeeTypeAsWritten()) {
3927 Result = getDerived().RebuildReferenceType(PointeeType,
3928 T->isSpelledAsLValue(),
3930 if (Result.isNull())
3934 // Objective-C ARC can add lifetime qualifiers to the type that we're
3936 TLB.TypeWasModifiedSafely(
3937 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3939 // r-value references can be rebuilt as l-value references.
3940 ReferenceTypeLoc NewTL;
3941 if (isa<LValueReferenceType>(Result))
3942 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3944 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3945 NewTL.setSigilLoc(TL.getSigilLoc());
3950 template<typename Derived>
3952 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
3953 LValueReferenceTypeLoc TL) {
3954 return TransformReferenceType(TLB, TL);
3957 template<typename Derived>
3959 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
3960 RValueReferenceTypeLoc TL) {
3961 return TransformReferenceType(TLB, TL);
3964 template<typename Derived>
3966 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
3967 MemberPointerTypeLoc TL) {
3968 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3969 if (PointeeType.isNull())
3972 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3973 TypeSourceInfo *NewClsTInfo = nullptr;
3975 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3980 const MemberPointerType *T = TL.getTypePtr();
3981 QualType OldClsType = QualType(T->getClass(), 0);
3982 QualType NewClsType;
3984 NewClsType = NewClsTInfo->getType();
3986 NewClsType = getDerived().TransformType(OldClsType);
3987 if (NewClsType.isNull())
3991 QualType Result = TL.getType();
3992 if (getDerived().AlwaysRebuild() ||
3993 PointeeType != T->getPointeeType() ||
3994 NewClsType != OldClsType) {
3995 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
3997 if (Result.isNull())
4001 // If we had to adjust the pointee type when building a member pointer, make
4002 // sure to push TypeLoc info for it.
4003 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4004 if (MPT && PointeeType != MPT->getPointeeType()) {
4005 assert(isa<AdjustedType>(MPT->getPointeeType()));
4006 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4009 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4010 NewTL.setSigilLoc(TL.getSigilLoc());
4011 NewTL.setClassTInfo(NewClsTInfo);
4016 template<typename Derived>
4018 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4019 ConstantArrayTypeLoc TL) {
4020 const ConstantArrayType *T = TL.getTypePtr();
4021 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4022 if (ElementType.isNull())
4025 QualType Result = TL.getType();
4026 if (getDerived().AlwaysRebuild() ||
4027 ElementType != T->getElementType()) {
4028 Result = getDerived().RebuildConstantArrayType(ElementType,
4029 T->getSizeModifier(),
4031 T->getIndexTypeCVRQualifiers(),
4032 TL.getBracketsRange());
4033 if (Result.isNull())
4037 // We might have either a ConstantArrayType or a VariableArrayType now:
4038 // a ConstantArrayType is allowed to have an element type which is a
4039 // VariableArrayType if the type is dependent. Fortunately, all array
4040 // types have the same location layout.
4041 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4042 NewTL.setLBracketLoc(TL.getLBracketLoc());
4043 NewTL.setRBracketLoc(TL.getRBracketLoc());
4045 Expr *Size = TL.getSizeExpr();
4047 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4048 Sema::ConstantEvaluated);
4049 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4050 Size = SemaRef.ActOnConstantExpression(Size).get();
4052 NewTL.setSizeExpr(Size);
4057 template<typename Derived>
4058 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4059 TypeLocBuilder &TLB,
4060 IncompleteArrayTypeLoc TL) {
4061 const IncompleteArrayType *T = TL.getTypePtr();
4062 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4063 if (ElementType.isNull())
4066 QualType Result = TL.getType();
4067 if (getDerived().AlwaysRebuild() ||
4068 ElementType != T->getElementType()) {
4069 Result = getDerived().RebuildIncompleteArrayType(ElementType,
4070 T->getSizeModifier(),
4071 T->getIndexTypeCVRQualifiers(),
4072 TL.getBracketsRange());
4073 if (Result.isNull())
4077 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4078 NewTL.setLBracketLoc(TL.getLBracketLoc());
4079 NewTL.setRBracketLoc(TL.getRBracketLoc());
4080 NewTL.setSizeExpr(nullptr);
4085 template<typename Derived>
4087 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4088 VariableArrayTypeLoc TL) {
4089 const VariableArrayType *T = TL.getTypePtr();
4090 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4091 if (ElementType.isNull())
4094 ExprResult SizeResult
4095 = getDerived().TransformExpr(T->getSizeExpr());
4096 if (SizeResult.isInvalid())
4099 Expr *Size = SizeResult.get();
4101 QualType Result = TL.getType();
4102 if (getDerived().AlwaysRebuild() ||
4103 ElementType != T->getElementType() ||
4104 Size != T->getSizeExpr()) {
4105 Result = getDerived().RebuildVariableArrayType(ElementType,
4106 T->getSizeModifier(),
4108 T->getIndexTypeCVRQualifiers(),
4109 TL.getBracketsRange());
4110 if (Result.isNull())
4114 // We might have constant size array now, but fortunately it has the same
4116 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4117 NewTL.setLBracketLoc(TL.getLBracketLoc());
4118 NewTL.setRBracketLoc(TL.getRBracketLoc());
4119 NewTL.setSizeExpr(Size);
4124 template<typename Derived>
4126 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4127 DependentSizedArrayTypeLoc TL) {
4128 const DependentSizedArrayType *T = TL.getTypePtr();
4129 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4130 if (ElementType.isNull())
4133 // Array bounds are constant expressions.
4134 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4135 Sema::ConstantEvaluated);
4137 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4138 Expr *origSize = TL.getSizeExpr();
4139 if (!origSize) origSize = T->getSizeExpr();
4141 ExprResult sizeResult
4142 = getDerived().TransformExpr(origSize);
4143 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4144 if (sizeResult.isInvalid())
4147 Expr *size = sizeResult.get();
4149 QualType Result = TL.getType();
4150 if (getDerived().AlwaysRebuild() ||
4151 ElementType != T->getElementType() ||
4153 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4154 T->getSizeModifier(),
4156 T->getIndexTypeCVRQualifiers(),
4157 TL.getBracketsRange());
4158 if (Result.isNull())
4162 // We might have any sort of array type now, but fortunately they
4163 // all have the same location layout.
4164 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4165 NewTL.setLBracketLoc(TL.getLBracketLoc());
4166 NewTL.setRBracketLoc(TL.getRBracketLoc());
4167 NewTL.setSizeExpr(size);
4172 template<typename Derived>
4173 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4174 TypeLocBuilder &TLB,
4175 DependentSizedExtVectorTypeLoc TL) {
4176 const DependentSizedExtVectorType *T = TL.getTypePtr();
4178 // FIXME: ext vector locs should be nested
4179 QualType ElementType = getDerived().TransformType(T->getElementType());
4180 if (ElementType.isNull())
4183 // Vector sizes are constant expressions.
4184 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4185 Sema::ConstantEvaluated);
4187 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4188 Size = SemaRef.ActOnConstantExpression(Size);
4189 if (Size.isInvalid())
4192 QualType Result = TL.getType();
4193 if (getDerived().AlwaysRebuild() ||
4194 ElementType != T->getElementType() ||
4195 Size.get() != T->getSizeExpr()) {
4196 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4198 T->getAttributeLoc());
4199 if (Result.isNull())
4203 // Result might be dependent or not.
4204 if (isa<DependentSizedExtVectorType>(Result)) {
4205 DependentSizedExtVectorTypeLoc NewTL
4206 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4207 NewTL.setNameLoc(TL.getNameLoc());
4209 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4210 NewTL.setNameLoc(TL.getNameLoc());
4216 template<typename Derived>
4217 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4219 const VectorType *T = TL.getTypePtr();
4220 QualType ElementType = getDerived().TransformType(T->getElementType());
4221 if (ElementType.isNull())
4224 QualType Result = TL.getType();
4225 if (getDerived().AlwaysRebuild() ||
4226 ElementType != T->getElementType()) {
4227 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4228 T->getVectorKind());
4229 if (Result.isNull())
4233 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4234 NewTL.setNameLoc(TL.getNameLoc());
4239 template<typename Derived>
4240 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4241 ExtVectorTypeLoc TL) {
4242 const VectorType *T = TL.getTypePtr();
4243 QualType ElementType = getDerived().TransformType(T->getElementType());
4244 if (ElementType.isNull())
4247 QualType Result = TL.getType();
4248 if (getDerived().AlwaysRebuild() ||
4249 ElementType != T->getElementType()) {
4250 Result = getDerived().RebuildExtVectorType(ElementType,
4251 T->getNumElements(),
4252 /*FIXME*/ SourceLocation());
4253 if (Result.isNull())
4257 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4258 NewTL.setNameLoc(TL.getNameLoc());
4263 template <typename Derived>
4264 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4265 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4266 bool ExpectParameterPack) {
4267 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4268 TypeSourceInfo *NewDI = nullptr;
4270 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4271 // If we're substituting into a pack expansion type and we know the
4272 // length we want to expand to, just substitute for the pattern.
4273 TypeLoc OldTL = OldDI->getTypeLoc();
4274 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4277 TypeLoc NewTL = OldDI->getTypeLoc();
4278 TLB.reserve(NewTL.getFullDataSize());
4280 QualType Result = getDerived().TransformType(TLB,
4281 OldExpansionTL.getPatternLoc());
4282 if (Result.isNull())
4285 Result = RebuildPackExpansionType(Result,
4286 OldExpansionTL.getPatternLoc().getSourceRange(),
4287 OldExpansionTL.getEllipsisLoc(),
4289 if (Result.isNull())
4292 PackExpansionTypeLoc NewExpansionTL
4293 = TLB.push<PackExpansionTypeLoc>(Result);
4294 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4295 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4297 NewDI = getDerived().TransformType(OldDI);
4301 if (NewDI == OldDI && indexAdjustment == 0)
4304 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4305 OldParm->getDeclContext(),
4306 OldParm->getInnerLocStart(),
4307 OldParm->getLocation(),
4308 OldParm->getIdentifier(),
4311 OldParm->getStorageClass(),
4312 /* DefArg */ nullptr);
4313 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4314 OldParm->getFunctionScopeIndex() + indexAdjustment);
4318 template<typename Derived>
4319 bool TreeTransform<Derived>::
4320 TransformFunctionTypeParams(SourceLocation Loc,
4321 ParmVarDecl **Params, unsigned NumParams,
4322 const QualType *ParamTypes,
4323 SmallVectorImpl<QualType> &OutParamTypes,
4324 SmallVectorImpl<ParmVarDecl*> *PVars) {
4325 int indexAdjustment = 0;
4327 for (unsigned i = 0; i != NumParams; ++i) {
4328 if (ParmVarDecl *OldParm = Params[i]) {
4329 assert(OldParm->getFunctionScopeIndex() == i);
4331 Optional<unsigned> NumExpansions;
4332 ParmVarDecl *NewParm = nullptr;
4333 if (OldParm->isParameterPack()) {
4334 // We have a function parameter pack that may need to be expanded.
4335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4337 // Find the parameter packs that could be expanded.
4338 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4339 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4340 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4341 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4342 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4344 // Determine whether we should expand the parameter packs.
4345 bool ShouldExpand = false;
4346 bool RetainExpansion = false;
4347 Optional<unsigned> OrigNumExpansions =
4348 ExpansionTL.getTypePtr()->getNumExpansions();
4349 NumExpansions = OrigNumExpansions;
4350 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4351 Pattern.getSourceRange(),
4360 // Expand the function parameter pack into multiple, separate
4362 getDerived().ExpandingFunctionParameterPack(OldParm);
4363 for (unsigned I = 0; I != *NumExpansions; ++I) {
4364 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4365 ParmVarDecl *NewParm
4366 = getDerived().TransformFunctionTypeParam(OldParm,
4369 /*ExpectParameterPack=*/false);
4373 OutParamTypes.push_back(NewParm->getType());
4375 PVars->push_back(NewParm);
4378 // If we're supposed to retain a pack expansion, do so by temporarily
4379 // forgetting the partially-substituted parameter pack.
4380 if (RetainExpansion) {
4381 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4382 ParmVarDecl *NewParm
4383 = getDerived().TransformFunctionTypeParam(OldParm,
4386 /*ExpectParameterPack=*/false);
4390 OutParamTypes.push_back(NewParm->getType());
4392 PVars->push_back(NewParm);
4395 // The next parameter should have the same adjustment as the
4396 // last thing we pushed, but we post-incremented indexAdjustment
4397 // on every push. Also, if we push nothing, the adjustment should
4401 // We're done with the pack expansion.
4405 // We'll substitute the parameter now without expanding the pack
4407 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4408 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4411 /*ExpectParameterPack=*/true);
4413 NewParm = getDerived().TransformFunctionTypeParam(
4414 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4420 OutParamTypes.push_back(NewParm->getType());
4422 PVars->push_back(NewParm);
4426 // Deal with the possibility that we don't have a parameter
4427 // declaration for this parameter.
4428 QualType OldType = ParamTypes[i];
4429 bool IsPackExpansion = false;
4430 Optional<unsigned> NumExpansions;
4432 if (const PackExpansionType *Expansion
4433 = dyn_cast<PackExpansionType>(OldType)) {
4434 // We have a function parameter pack that may need to be expanded.
4435 QualType Pattern = Expansion->getPattern();
4436 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4437 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4439 // Determine whether we should expand the parameter packs.
4440 bool ShouldExpand = false;
4441 bool RetainExpansion = false;
4442 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4451 // Expand the function parameter pack into multiple, separate
4453 for (unsigned I = 0; I != *NumExpansions; ++I) {
4454 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4455 QualType NewType = getDerived().TransformType(Pattern);
4456 if (NewType.isNull())
4459 OutParamTypes.push_back(NewType);
4461 PVars->push_back(nullptr);
4464 // We're done with the pack expansion.
4468 // If we're supposed to retain a pack expansion, do so by temporarily
4469 // forgetting the partially-substituted parameter pack.
4470 if (RetainExpansion) {
4471 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4472 QualType NewType = getDerived().TransformType(Pattern);
4473 if (NewType.isNull())
4476 OutParamTypes.push_back(NewType);
4478 PVars->push_back(nullptr);
4481 // We'll substitute the parameter now without expanding the pack
4483 OldType = Expansion->getPattern();
4484 IsPackExpansion = true;
4485 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4486 NewType = getDerived().TransformType(OldType);
4488 NewType = getDerived().TransformType(OldType);
4491 if (NewType.isNull())
4494 if (IsPackExpansion)
4495 NewType = getSema().Context.getPackExpansionType(NewType,
4498 OutParamTypes.push_back(NewType);
4500 PVars->push_back(nullptr);
4505 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4506 if (ParmVarDecl *parm = (*PVars)[i])
4507 assert(parm->getFunctionScopeIndex() == i);
4514 template<typename Derived>
4516 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4517 FunctionProtoTypeLoc TL) {
4518 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
4521 template<typename Derived>
4523 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4524 FunctionProtoTypeLoc TL,
4525 CXXRecordDecl *ThisContext,
4526 unsigned ThisTypeQuals) {
4527 // Transform the parameters and return type.
4529 // We are required to instantiate the params and return type in source order.
4530 // When the function has a trailing return type, we instantiate the
4531 // parameters before the return type, since the return type can then refer
4532 // to the parameters themselves (via decltype, sizeof, etc.).
4534 SmallVector<QualType, 4> ParamTypes;
4535 SmallVector<ParmVarDecl*, 4> ParamDecls;
4536 const FunctionProtoType *T = TL.getTypePtr();
4538 QualType ResultType;
4540 if (T->hasTrailingReturn()) {
4541 if (getDerived().TransformFunctionTypeParams(
4542 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
4543 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
4547 // C++11 [expr.prim.general]p3:
4548 // If a declaration declares a member function or member function
4549 // template of a class X, the expression this is a prvalue of type
4550 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4551 // and the end of the function-definition, member-declarator, or
4553 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4555 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4556 if (ResultType.isNull())
4561 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4562 if (ResultType.isNull())
4565 if (getDerived().TransformFunctionTypeParams(
4566 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
4567 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
4571 // FIXME: Need to transform the exception-specification too.
4573 QualType Result = TL.getType();
4574 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
4575 T->getNumParams() != ParamTypes.size() ||
4576 !std::equal(T->param_type_begin(), T->param_type_end(),
4577 ParamTypes.begin())) {
4578 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4579 T->getExtProtoInfo());
4580 if (Result.isNull())
4584 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4585 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4586 NewTL.setLParenLoc(TL.getLParenLoc());
4587 NewTL.setRParenLoc(TL.getRParenLoc());
4588 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4589 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4590 NewTL.setParam(i, ParamDecls[i]);
4595 template<typename Derived>
4596 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4597 TypeLocBuilder &TLB,
4598 FunctionNoProtoTypeLoc TL) {
4599 const FunctionNoProtoType *T = TL.getTypePtr();
4600 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4601 if (ResultType.isNull())
4604 QualType Result = TL.getType();
4605 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
4606 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4608 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4609 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4610 NewTL.setLParenLoc(TL.getLParenLoc());
4611 NewTL.setRParenLoc(TL.getRParenLoc());
4612 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4617 template<typename Derived> QualType
4618 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
4619 UnresolvedUsingTypeLoc TL) {
4620 const UnresolvedUsingType *T = TL.getTypePtr();
4621 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4625 QualType Result = TL.getType();
4626 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4627 Result = getDerived().RebuildUnresolvedUsingType(D);
4628 if (Result.isNull())
4632 // We might get an arbitrary type spec type back. We should at
4633 // least always get a type spec type, though.
4634 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4635 NewTL.setNameLoc(TL.getNameLoc());
4640 template<typename Derived>
4641 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
4642 TypedefTypeLoc TL) {
4643 const TypedefType *T = TL.getTypePtr();
4644 TypedefNameDecl *Typedef
4645 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4650 QualType Result = TL.getType();
4651 if (getDerived().AlwaysRebuild() ||
4652 Typedef != T->getDecl()) {
4653 Result = getDerived().RebuildTypedefType(Typedef);
4654 if (Result.isNull())
4658 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4659 NewTL.setNameLoc(TL.getNameLoc());
4664 template<typename Derived>
4665 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
4666 TypeOfExprTypeLoc TL) {
4667 // typeof expressions are not potentially evaluated contexts
4668 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4669 Sema::ReuseLambdaContextDecl);
4671 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4675 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4679 QualType Result = TL.getType();
4680 if (getDerived().AlwaysRebuild() ||
4681 E.get() != TL.getUnderlyingExpr()) {
4682 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4683 if (Result.isNull())
4688 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4689 NewTL.setTypeofLoc(TL.getTypeofLoc());
4690 NewTL.setLParenLoc(TL.getLParenLoc());
4691 NewTL.setRParenLoc(TL.getRParenLoc());
4696 template<typename Derived>
4697 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
4699 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4700 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4704 QualType Result = TL.getType();
4705 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4706 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4707 if (Result.isNull())
4711 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4712 NewTL.setTypeofLoc(TL.getTypeofLoc());
4713 NewTL.setLParenLoc(TL.getLParenLoc());
4714 NewTL.setRParenLoc(TL.getRParenLoc());
4715 NewTL.setUnderlyingTInfo(New_Under_TI);
4720 template<typename Derived>
4721 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
4722 DecltypeTypeLoc TL) {
4723 const DecltypeType *T = TL.getTypePtr();
4725 // decltype expressions are not potentially evaluated contexts
4726 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4727 nullptr, /*IsDecltype=*/ true);
4729 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4733 E = getSema().ActOnDecltypeExpression(E.get());
4737 QualType Result = TL.getType();
4738 if (getDerived().AlwaysRebuild() ||
4739 E.get() != T->getUnderlyingExpr()) {
4740 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4741 if (Result.isNull())
4746 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4747 NewTL.setNameLoc(TL.getNameLoc());
4752 template<typename Derived>
4753 QualType TreeTransform<Derived>::TransformUnaryTransformType(
4754 TypeLocBuilder &TLB,
4755 UnaryTransformTypeLoc TL) {
4756 QualType Result = TL.getType();
4757 if (Result->isDependentType()) {
4758 const UnaryTransformType *T = TL.getTypePtr();
4760 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4761 Result = getDerived().RebuildUnaryTransformType(NewBase,
4764 if (Result.isNull())
4768 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4769 NewTL.setKWLoc(TL.getKWLoc());
4770 NewTL.setParensRange(TL.getParensRange());
4771 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4775 template<typename Derived>
4776 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4778 const AutoType *T = TL.getTypePtr();
4779 QualType OldDeduced = T->getDeducedType();
4780 QualType NewDeduced;
4781 if (!OldDeduced.isNull()) {
4782 NewDeduced = getDerived().TransformType(OldDeduced);
4783 if (NewDeduced.isNull())
4787 QualType Result = TL.getType();
4788 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4789 T->isDependentType()) {
4790 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
4791 if (Result.isNull())
4795 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4796 NewTL.setNameLoc(TL.getNameLoc());
4801 template<typename Derived>
4802 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
4804 const RecordType *T = TL.getTypePtr();
4806 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4811 QualType Result = TL.getType();
4812 if (getDerived().AlwaysRebuild() ||
4813 Record != T->getDecl()) {
4814 Result = getDerived().RebuildRecordType(Record);
4815 if (Result.isNull())
4819 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4820 NewTL.setNameLoc(TL.getNameLoc());
4825 template<typename Derived>
4826 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
4828 const EnumType *T = TL.getTypePtr();
4830 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4835 QualType Result = TL.getType();
4836 if (getDerived().AlwaysRebuild() ||
4837 Enum != T->getDecl()) {
4838 Result = getDerived().RebuildEnumType(Enum);
4839 if (Result.isNull())
4843 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4844 NewTL.setNameLoc(TL.getNameLoc());
4849 template<typename Derived>
4850 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4851 TypeLocBuilder &TLB,
4852 InjectedClassNameTypeLoc TL) {
4853 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4854 TL.getTypePtr()->getDecl());
4855 if (!D) return QualType();
4857 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4858 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4862 template<typename Derived>
4863 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4864 TypeLocBuilder &TLB,
4865 TemplateTypeParmTypeLoc TL) {
4866 return TransformTypeSpecType(TLB, TL);
4869 template<typename Derived>
4870 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4871 TypeLocBuilder &TLB,
4872 SubstTemplateTypeParmTypeLoc TL) {
4873 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4875 // Substitute into the replacement type, which itself might involve something
4876 // that needs to be transformed. This only tends to occur with default
4877 // template arguments of template template parameters.
4878 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4879 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4880 if (Replacement.isNull())
4883 // Always canonicalize the replacement type.
4884 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4886 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4889 // Propagate type-source information.
4890 SubstTemplateTypeParmTypeLoc NewTL
4891 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4892 NewTL.setNameLoc(TL.getNameLoc());
4897 template<typename Derived>
4898 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4899 TypeLocBuilder &TLB,
4900 SubstTemplateTypeParmPackTypeLoc TL) {
4901 return TransformTypeSpecType(TLB, TL);
4904 template<typename Derived>
4905 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4906 TypeLocBuilder &TLB,
4907 TemplateSpecializationTypeLoc TL) {
4908 const TemplateSpecializationType *T = TL.getTypePtr();
4910 // The nested-name-specifier never matters in a TemplateSpecializationType,
4911 // because we can't have a dependent nested-name-specifier anyway.
4913 TemplateName Template
4914 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4915 TL.getTemplateNameLoc());
4916 if (Template.isNull())
4919 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4922 template<typename Derived>
4923 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4925 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4926 if (ValueType.isNull())
4929 QualType Result = TL.getType();
4930 if (getDerived().AlwaysRebuild() ||
4931 ValueType != TL.getValueLoc().getType()) {
4932 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4933 if (Result.isNull())
4937 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4938 NewTL.setKWLoc(TL.getKWLoc());
4939 NewTL.setLParenLoc(TL.getLParenLoc());
4940 NewTL.setRParenLoc(TL.getRParenLoc());
4945 /// \brief Simple iterator that traverses the template arguments in a
4946 /// container that provides a \c getArgLoc() member function.
4948 /// This iterator is intended to be used with the iterator form of
4949 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4950 template<typename ArgLocContainer>
4951 class TemplateArgumentLocContainerIterator {
4952 ArgLocContainer *Container;
4956 typedef TemplateArgumentLoc value_type;
4957 typedef TemplateArgumentLoc reference;
4958 typedef int difference_type;
4959 typedef std::input_iterator_tag iterator_category;
4962 TemplateArgumentLoc Arg;
4965 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4967 const TemplateArgumentLoc *operator->() const {
4973 TemplateArgumentLocContainerIterator() {}
4975 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4977 : Container(&Container), Index(Index) { }
4979 TemplateArgumentLocContainerIterator &operator++() {
4984 TemplateArgumentLocContainerIterator operator++(int) {
4985 TemplateArgumentLocContainerIterator Old(*this);
4990 TemplateArgumentLoc operator*() const {
4991 return Container->getArgLoc(Index);
4994 pointer operator->() const {
4995 return pointer(Container->getArgLoc(Index));
4998 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4999 const TemplateArgumentLocContainerIterator &Y) {
5000 return X.Container == Y.Container && X.Index == Y.Index;
5003 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
5004 const TemplateArgumentLocContainerIterator &Y) {
5010 template <typename Derived>
5011 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5012 TypeLocBuilder &TLB,
5013 TemplateSpecializationTypeLoc TL,
5014 TemplateName Template) {
5015 TemplateArgumentListInfo NewTemplateArgs;
5016 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5017 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5018 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5020 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5021 ArgIterator(TL, TL.getNumArgs()),
5025 // FIXME: maybe don't rebuild if all the template arguments are the same.
5028 getDerived().RebuildTemplateSpecializationType(Template,
5029 TL.getTemplateNameLoc(),
5032 if (!Result.isNull()) {
5033 // Specializations of template template parameters are represented as
5034 // TemplateSpecializationTypes, and substitution of type alias templates
5035 // within a dependent context can transform them into
5036 // DependentTemplateSpecializationTypes.
5037 if (isa<DependentTemplateSpecializationType>(Result)) {
5038 DependentTemplateSpecializationTypeLoc NewTL
5039 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5040 NewTL.setElaboratedKeywordLoc(SourceLocation());
5041 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5042 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5043 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5044 NewTL.setLAngleLoc(TL.getLAngleLoc());
5045 NewTL.setRAngleLoc(TL.getRAngleLoc());
5046 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5047 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5051 TemplateSpecializationTypeLoc NewTL
5052 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5053 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5054 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5055 NewTL.setLAngleLoc(TL.getLAngleLoc());
5056 NewTL.setRAngleLoc(TL.getRAngleLoc());
5057 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5058 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5064 template <typename Derived>
5065 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5066 TypeLocBuilder &TLB,
5067 DependentTemplateSpecializationTypeLoc TL,
5068 TemplateName Template,
5070 TemplateArgumentListInfo NewTemplateArgs;
5071 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5072 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5073 typedef TemplateArgumentLocContainerIterator<
5074 DependentTemplateSpecializationTypeLoc> ArgIterator;
5075 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5076 ArgIterator(TL, TL.getNumArgs()),
5080 // FIXME: maybe don't rebuild if all the template arguments are the same.
5082 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5084 = getSema().Context.getDependentTemplateSpecializationType(
5085 TL.getTypePtr()->getKeyword(),
5086 DTN->getQualifier(),
5087 DTN->getIdentifier(),
5090 DependentTemplateSpecializationTypeLoc NewTL
5091 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5092 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5093 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5094 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5095 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5096 NewTL.setLAngleLoc(TL.getLAngleLoc());
5097 NewTL.setRAngleLoc(TL.getRAngleLoc());
5098 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5099 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5104 = getDerived().RebuildTemplateSpecializationType(Template,
5105 TL.getTemplateNameLoc(),
5108 if (!Result.isNull()) {
5109 /// FIXME: Wrap this in an elaborated-type-specifier?
5110 TemplateSpecializationTypeLoc NewTL
5111 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5112 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5113 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5114 NewTL.setLAngleLoc(TL.getLAngleLoc());
5115 NewTL.setRAngleLoc(TL.getRAngleLoc());
5116 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5117 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5123 template<typename Derived>
5125 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
5126 ElaboratedTypeLoc TL) {
5127 const ElaboratedType *T = TL.getTypePtr();
5129 NestedNameSpecifierLoc QualifierLoc;
5130 // NOTE: the qualifier in an ElaboratedType is optional.
5131 if (TL.getQualifierLoc()) {
5133 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5138 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5139 if (NamedT.isNull())
5142 // C++0x [dcl.type.elab]p2:
5143 // If the identifier resolves to a typedef-name or the simple-template-id
5144 // resolves to an alias template specialization, the
5145 // elaborated-type-specifier is ill-formed.
5146 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5147 if (const TemplateSpecializationType *TST =
5148 NamedT->getAs<TemplateSpecializationType>()) {
5149 TemplateName Template = TST->getTemplateName();
5150 if (TypeAliasTemplateDecl *TAT =
5151 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5152 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5153 diag::err_tag_reference_non_tag) << 4;
5154 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5159 QualType Result = TL.getType();
5160 if (getDerived().AlwaysRebuild() ||
5161 QualifierLoc != TL.getQualifierLoc() ||
5162 NamedT != T->getNamedType()) {
5163 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5165 QualifierLoc, NamedT);
5166 if (Result.isNull())
5170 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5171 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5172 NewTL.setQualifierLoc(QualifierLoc);
5176 template<typename Derived>
5177 QualType TreeTransform<Derived>::TransformAttributedType(
5178 TypeLocBuilder &TLB,
5179 AttributedTypeLoc TL) {
5180 const AttributedType *oldType = TL.getTypePtr();
5181 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5182 if (modifiedType.isNull())
5185 QualType result = TL.getType();
5187 // FIXME: dependent operand expressions?
5188 if (getDerived().AlwaysRebuild() ||
5189 modifiedType != oldType->getModifiedType()) {
5190 // TODO: this is really lame; we should really be rebuilding the
5191 // equivalent type from first principles.
5192 QualType equivalentType
5193 = getDerived().TransformType(oldType->getEquivalentType());
5194 if (equivalentType.isNull())
5196 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5201 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5202 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5203 if (TL.hasAttrOperand())
5204 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5205 if (TL.hasAttrExprOperand())
5206 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5207 else if (TL.hasAttrEnumOperand())
5208 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5213 template<typename Derived>
5215 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5217 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5221 QualType Result = TL.getType();
5222 if (getDerived().AlwaysRebuild() ||
5223 Inner != TL.getInnerLoc().getType()) {
5224 Result = getDerived().RebuildParenType(Inner);
5225 if (Result.isNull())
5229 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5230 NewTL.setLParenLoc(TL.getLParenLoc());
5231 NewTL.setRParenLoc(TL.getRParenLoc());
5235 template<typename Derived>
5236 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5237 DependentNameTypeLoc TL) {
5238 const DependentNameType *T = TL.getTypePtr();
5240 NestedNameSpecifierLoc QualifierLoc
5241 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5246 = getDerived().RebuildDependentNameType(T->getKeyword(),
5247 TL.getElaboratedKeywordLoc(),
5251 if (Result.isNull())
5254 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5255 QualType NamedT = ElabT->getNamedType();
5256 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5258 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5259 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5260 NewTL.setQualifierLoc(QualifierLoc);
5262 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5263 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5264 NewTL.setQualifierLoc(QualifierLoc);
5265 NewTL.setNameLoc(TL.getNameLoc());
5270 template<typename Derived>
5271 QualType TreeTransform<Derived>::
5272 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5273 DependentTemplateSpecializationTypeLoc TL) {
5274 NestedNameSpecifierLoc QualifierLoc;
5275 if (TL.getQualifierLoc()) {
5277 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5283 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5286 template<typename Derived>
5287 QualType TreeTransform<Derived>::
5288 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5289 DependentTemplateSpecializationTypeLoc TL,
5290 NestedNameSpecifierLoc QualifierLoc) {
5291 const DependentTemplateSpecializationType *T = TL.getTypePtr();
5293 TemplateArgumentListInfo NewTemplateArgs;
5294 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5295 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5297 typedef TemplateArgumentLocContainerIterator<
5298 DependentTemplateSpecializationTypeLoc> ArgIterator;
5299 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5300 ArgIterator(TL, TL.getNumArgs()),
5305 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5308 TL.getTemplateNameLoc(),
5310 if (Result.isNull())
5313 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5314 QualType NamedT = ElabT->getNamedType();
5316 // Copy information relevant to the template specialization.
5317 TemplateSpecializationTypeLoc NamedTL
5318 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5319 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5320 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5321 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5322 NamedTL.setRAngleLoc(TL.getRAngleLoc());
5323 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5324 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5326 // Copy information relevant to the elaborated type.
5327 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5328 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5329 NewTL.setQualifierLoc(QualifierLoc);
5330 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5331 DependentTemplateSpecializationTypeLoc SpecTL
5332 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5333 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5334 SpecTL.setQualifierLoc(QualifierLoc);
5335 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5336 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5337 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5338 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5339 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5340 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5342 TemplateSpecializationTypeLoc SpecTL
5343 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5344 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5345 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5346 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5347 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5348 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5349 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5354 template<typename Derived>
5355 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5356 PackExpansionTypeLoc TL) {
5358 = getDerived().TransformType(TLB, TL.getPatternLoc());
5359 if (Pattern.isNull())
5362 QualType Result = TL.getType();
5363 if (getDerived().AlwaysRebuild() ||
5364 Pattern != TL.getPatternLoc().getType()) {
5365 Result = getDerived().RebuildPackExpansionType(Pattern,
5366 TL.getPatternLoc().getSourceRange(),
5367 TL.getEllipsisLoc(),
5368 TL.getTypePtr()->getNumExpansions());
5369 if (Result.isNull())
5373 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5374 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5378 template<typename Derived>
5380 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5381 ObjCInterfaceTypeLoc TL) {
5382 // ObjCInterfaceType is never dependent.
5383 TLB.pushFullCopy(TL);
5384 return TL.getType();
5387 template<typename Derived>
5389 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5390 ObjCObjectTypeLoc TL) {
5391 // ObjCObjectType is never dependent.
5392 TLB.pushFullCopy(TL);
5393 return TL.getType();
5396 template<typename Derived>
5398 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
5399 ObjCObjectPointerTypeLoc TL) {
5400 // ObjCObjectPointerType is never dependent.
5401 TLB.pushFullCopy(TL);
5402 return TL.getType();
5405 //===----------------------------------------------------------------------===//
5406 // Statement transformation
5407 //===----------------------------------------------------------------------===//
5408 template<typename Derived>
5410 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
5414 template<typename Derived>
5416 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5417 return getDerived().TransformCompoundStmt(S, false);
5420 template<typename Derived>
5422 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
5424 Sema::CompoundScopeRAII CompoundScope(getSema());
5426 bool SubStmtInvalid = false;
5427 bool SubStmtChanged = false;
5428 SmallVector<Stmt*, 8> Statements;
5429 for (auto *B : S->body()) {
5430 StmtResult Result = getDerived().TransformStmt(B);
5431 if (Result.isInvalid()) {
5432 // Immediately fail if this was a DeclStmt, since it's very
5433 // likely that this will cause problems for future statements.
5434 if (isa<DeclStmt>(B))
5437 // Otherwise, just keep processing substatements and fail later.
5438 SubStmtInvalid = true;
5442 SubStmtChanged = SubStmtChanged || Result.get() != B;
5443 Statements.push_back(Result.getAs<Stmt>());
5449 if (!getDerived().AlwaysRebuild() &&
5453 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5459 template<typename Derived>
5461 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
5462 ExprResult LHS, RHS;
5464 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5465 Sema::ConstantEvaluated);
5467 // Transform the left-hand case value.
5468 LHS = getDerived().TransformExpr(S->getLHS());
5469 LHS = SemaRef.ActOnConstantExpression(LHS);
5470 if (LHS.isInvalid())
5473 // Transform the right-hand case value (for the GNU case-range extension).
5474 RHS = getDerived().TransformExpr(S->getRHS());
5475 RHS = SemaRef.ActOnConstantExpression(RHS);
5476 if (RHS.isInvalid())
5480 // Build the case statement.
5481 // Case statements are always rebuilt so that they will attached to their
5482 // transformed switch statement.
5483 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
5485 S->getEllipsisLoc(),
5488 if (Case.isInvalid())
5491 // Transform the statement following the case
5492 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5493 if (SubStmt.isInvalid())
5496 // Attach the body to the case statement
5497 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
5500 template<typename Derived>
5502 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
5503 // Transform the statement following the default case
5504 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5505 if (SubStmt.isInvalid())
5508 // Default statements are always rebuilt
5509 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
5513 template<typename Derived>
5515 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
5516 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5517 if (SubStmt.isInvalid())
5520 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5526 // FIXME: Pass the real colon location in.
5527 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
5528 cast<LabelDecl>(LD), SourceLocation(),
5532 template<typename Derived>
5534 TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5535 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5536 if (SubStmt.isInvalid())
5539 // TODO: transform attributes
5540 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5543 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5548 template<typename Derived>
5550 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
5551 // Transform the condition
5553 VarDecl *ConditionVar = nullptr;
5554 if (S->getConditionVariable()) {
5556 = cast_or_null<VarDecl>(
5557 getDerived().TransformDefinition(
5558 S->getConditionVariable()->getLocation(),
5559 S->getConditionVariable()));
5563 Cond = getDerived().TransformExpr(S->getCond());
5565 if (Cond.isInvalid())
5568 // Convert the condition to a boolean value.
5570 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
5572 if (CondE.isInvalid())
5579 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
5580 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5583 // Transform the "then" branch.
5584 StmtResult Then = getDerived().TransformStmt(S->getThen());
5585 if (Then.isInvalid())
5588 // Transform the "else" branch.
5589 StmtResult Else = getDerived().TransformStmt(S->getElse());
5590 if (Else.isInvalid())
5593 if (!getDerived().AlwaysRebuild() &&
5594 FullCond.get() == S->getCond() &&
5595 ConditionVar == S->getConditionVariable() &&
5596 Then.get() == S->getThen() &&
5597 Else.get() == S->getElse())
5600 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
5602 S->getElseLoc(), Else.get());
5605 template<typename Derived>
5607 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
5608 // Transform the condition.
5610 VarDecl *ConditionVar = nullptr;
5611 if (S->getConditionVariable()) {
5613 = cast_or_null<VarDecl>(
5614 getDerived().TransformDefinition(
5615 S->getConditionVariable()->getLocation(),
5616 S->getConditionVariable()));
5620 Cond = getDerived().TransformExpr(S->getCond());
5622 if (Cond.isInvalid())
5626 // Rebuild the switch statement.
5628 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5630 if (Switch.isInvalid())
5633 // Transform the body of the switch statement.
5634 StmtResult Body = getDerived().TransformStmt(S->getBody());
5635 if (Body.isInvalid())
5638 // Complete the switch statement.
5639 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5643 template<typename Derived>
5645 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
5646 // Transform the condition
5648 VarDecl *ConditionVar = nullptr;
5649 if (S->getConditionVariable()) {
5651 = cast_or_null<VarDecl>(
5652 getDerived().TransformDefinition(
5653 S->getConditionVariable()->getLocation(),
5654 S->getConditionVariable()));
5658 Cond = getDerived().TransformExpr(S->getCond());
5660 if (Cond.isInvalid())
5664 // Convert the condition to a boolean value.
5665 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5668 if (CondE.isInvalid())
5674 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
5675 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5678 // Transform the body
5679 StmtResult Body = getDerived().TransformStmt(S->getBody());
5680 if (Body.isInvalid())
5683 if (!getDerived().AlwaysRebuild() &&
5684 FullCond.get() == S->getCond() &&
5685 ConditionVar == S->getConditionVariable() &&
5686 Body.get() == S->getBody())
5689 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
5690 ConditionVar, Body.get());
5693 template<typename Derived>
5695 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
5696 // Transform the body
5697 StmtResult Body = getDerived().TransformStmt(S->getBody());
5698 if (Body.isInvalid())
5701 // Transform the condition
5702 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5703 if (Cond.isInvalid())
5706 if (!getDerived().AlwaysRebuild() &&
5707 Cond.get() == S->getCond() &&
5708 Body.get() == S->getBody())
5711 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5712 /*FIXME:*/S->getWhileLoc(), Cond.get(),
5716 template<typename Derived>
5718 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
5719 // Transform the initialization statement
5720 StmtResult Init = getDerived().TransformStmt(S->getInit());
5721 if (Init.isInvalid())
5724 // Transform the condition
5726 VarDecl *ConditionVar = nullptr;
5727 if (S->getConditionVariable()) {
5729 = cast_or_null<VarDecl>(
5730 getDerived().TransformDefinition(
5731 S->getConditionVariable()->getLocation(),
5732 S->getConditionVariable()));
5736 Cond = getDerived().TransformExpr(S->getCond());
5738 if (Cond.isInvalid())
5742 // Convert the condition to a boolean value.
5743 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5746 if (CondE.isInvalid())
5753 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
5754 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5757 // Transform the increment
5758 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5759 if (Inc.isInvalid())
5762 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
5763 if (S->getInc() && !FullInc.get())
5766 // Transform the body
5767 StmtResult Body = getDerived().TransformStmt(S->getBody());
5768 if (Body.isInvalid())
5771 if (!getDerived().AlwaysRebuild() &&
5772 Init.get() == S->getInit() &&
5773 FullCond.get() == S->getCond() &&
5774 Inc.get() == S->getInc() &&
5775 Body.get() == S->getBody())
5778 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
5779 Init.get(), FullCond, ConditionVar,
5780 FullInc, S->getRParenLoc(), Body.get());
5783 template<typename Derived>
5785 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
5786 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5791 // Goto statements must always be rebuilt, to resolve the label.
5792 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
5793 cast<LabelDecl>(LD));
5796 template<typename Derived>
5798 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
5799 ExprResult Target = getDerived().TransformExpr(S->getTarget());
5800 if (Target.isInvalid())
5802 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
5804 if (!getDerived().AlwaysRebuild() &&
5805 Target.get() == S->getTarget())
5808 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
5812 template<typename Derived>
5814 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
5818 template<typename Derived>
5820 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
5824 template<typename Derived>
5826 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
5827 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
5828 if (Result.isInvalid())
5831 // FIXME: We always rebuild the return statement because there is no way
5832 // to tell whether the return type of the function has changed.
5833 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
5836 template<typename Derived>
5838 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
5839 bool DeclChanged = false;
5840 SmallVector<Decl *, 4> Decls;
5841 for (auto *D : S->decls()) {
5842 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
5846 if (Transformed != D)
5849 Decls.push_back(Transformed);
5852 if (!getDerived().AlwaysRebuild() && !DeclChanged)
5855 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
5858 template<typename Derived>
5860 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
5862 SmallVector<Expr*, 8> Constraints;
5863 SmallVector<Expr*, 8> Exprs;
5864 SmallVector<IdentifierInfo *, 4> Names;
5866 ExprResult AsmString;
5867 SmallVector<Expr*, 8> Clobbers;
5869 bool ExprsChanged = false;
5871 // Go through the outputs.
5872 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5873 Names.push_back(S->getOutputIdentifier(I));
5875 // No need to transform the constraint literal.
5876 Constraints.push_back(S->getOutputConstraintLiteral(I));
5878 // Transform the output expr.
5879 Expr *OutputExpr = S->getOutputExpr(I);
5880 ExprResult Result = getDerived().TransformExpr(OutputExpr);
5881 if (Result.isInvalid())
5884 ExprsChanged |= Result.get() != OutputExpr;
5886 Exprs.push_back(Result.get());
5889 // Go through the inputs.
5890 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5891 Names.push_back(S->getInputIdentifier(I));
5893 // No need to transform the constraint literal.
5894 Constraints.push_back(S->getInputConstraintLiteral(I));
5896 // Transform the input expr.
5897 Expr *InputExpr = S->getInputExpr(I);
5898 ExprResult Result = getDerived().TransformExpr(InputExpr);
5899 if (Result.isInvalid())
5902 ExprsChanged |= Result.get() != InputExpr;
5904 Exprs.push_back(Result.get());
5907 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
5910 // Go through the clobbers.
5911 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
5912 Clobbers.push_back(S->getClobberStringLiteral(I));
5914 // No need to transform the asm string literal.
5915 AsmString = S->getAsmString();
5916 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5917 S->isVolatile(), S->getNumOutputs(),
5918 S->getNumInputs(), Names.data(),
5919 Constraints, Exprs, AsmString.get(),
5920 Clobbers, S->getRParenLoc());
5923 template<typename Derived>
5925 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
5926 ArrayRef<Token> AsmToks =
5927 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
5929 bool HadError = false, HadChange = false;
5931 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5932 SmallVector<Expr*, 8> TransformedExprs;
5933 TransformedExprs.reserve(SrcExprs.size());
5934 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5935 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5936 if (!Result.isUsable()) {
5939 HadChange |= (Result.get() != SrcExprs[i]);
5940 TransformedExprs.push_back(Result.get());
5944 if (HadError) return StmtError();
5945 if (!HadChange && !getDerived().AlwaysRebuild())
5948 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5949 AsmToks, S->getAsmString(),
5950 S->getNumOutputs(), S->getNumInputs(),
5951 S->getAllConstraints(), S->getClobbers(),
5952 TransformedExprs, S->getEndLoc());
5955 template<typename Derived>
5957 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
5958 // Transform the body of the @try.
5959 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
5960 if (TryBody.isInvalid())
5963 // Transform the @catch statements (if present).
5964 bool AnyCatchChanged = false;
5965 SmallVector<Stmt*, 8> CatchStmts;
5966 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
5967 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
5968 if (Catch.isInvalid())
5970 if (Catch.get() != S->getCatchStmt(I))
5971 AnyCatchChanged = true;
5972 CatchStmts.push_back(Catch.get());
5975 // Transform the @finally statement (if present).
5977 if (S->getFinallyStmt()) {
5978 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5979 if (Finally.isInvalid())
5983 // If nothing changed, just retain this statement.
5984 if (!getDerived().AlwaysRebuild() &&
5985 TryBody.get() == S->getTryBody() &&
5987 Finally.get() == S->getFinallyStmt())
5990 // Build a new statement.
5991 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5992 CatchStmts, Finally.get());
5995 template<typename Derived>
5997 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5998 // Transform the @catch parameter, if there is one.
5999 VarDecl *Var = nullptr;
6000 if (VarDecl *FromVar = S->getCatchParamDecl()) {
6001 TypeSourceInfo *TSInfo = nullptr;
6002 if (FromVar->getTypeSourceInfo()) {
6003 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6010 T = TSInfo->getType();
6012 T = getDerived().TransformType(FromVar->getType());
6017 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6022 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
6023 if (Body.isInvalid())
6026 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
6031 template<typename Derived>
6033 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
6034 // Transform the body.
6035 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
6036 if (Body.isInvalid())
6039 // If nothing changed, just retain this statement.
6040 if (!getDerived().AlwaysRebuild() &&
6041 Body.get() == S->getFinallyBody())
6044 // Build a new statement.
6045 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
6049 template<typename Derived>
6051 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
6053 if (S->getThrowExpr()) {
6054 Operand = getDerived().TransformExpr(S->getThrowExpr());
6055 if (Operand.isInvalid())
6059 if (!getDerived().AlwaysRebuild() &&
6060 Operand.get() == S->getThrowExpr())
6063 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
6066 template<typename Derived>
6068 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
6069 ObjCAtSynchronizedStmt *S) {
6070 // Transform the object we are locking.
6071 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
6072 if (Object.isInvalid())
6075 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6077 if (Object.isInvalid())
6080 // Transform the body.
6081 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
6082 if (Body.isInvalid())
6085 // If nothing change, just retain the current statement.
6086 if (!getDerived().AlwaysRebuild() &&
6087 Object.get() == S->getSynchExpr() &&
6088 Body.get() == S->getSynchBody())
6091 // Build a new statement.
6092 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
6093 Object.get(), Body.get());
6096 template<typename Derived>
6098 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6099 ObjCAutoreleasePoolStmt *S) {
6100 // Transform the body.
6101 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6102 if (Body.isInvalid())
6105 // If nothing changed, just retain this statement.
6106 if (!getDerived().AlwaysRebuild() &&
6107 Body.get() == S->getSubStmt())
6110 // Build a new statement.
6111 return getDerived().RebuildObjCAutoreleasePoolStmt(
6112 S->getAtLoc(), Body.get());
6115 template<typename Derived>
6117 TreeTransform<Derived>::TransformObjCForCollectionStmt(
6118 ObjCForCollectionStmt *S) {
6119 // Transform the element statement.
6120 StmtResult Element = getDerived().TransformStmt(S->getElement());
6121 if (Element.isInvalid())
6124 // Transform the collection expression.
6125 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
6126 if (Collection.isInvalid())
6129 // Transform the body.
6130 StmtResult Body = getDerived().TransformStmt(S->getBody());
6131 if (Body.isInvalid())
6134 // If nothing changed, just retain this statement.
6135 if (!getDerived().AlwaysRebuild() &&
6136 Element.get() == S->getElement() &&
6137 Collection.get() == S->getCollection() &&
6138 Body.get() == S->getBody())
6141 // Build a new statement.
6142 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6149 template <typename Derived>
6150 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6151 // Transform the exception declaration, if any.
6152 VarDecl *Var = nullptr;
6153 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6155 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6159 Var = getDerived().RebuildExceptionDecl(
6160 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6161 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6162 if (!Var || Var->isInvalidDecl())
6166 // Transform the actual exception handler.
6167 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6168 if (Handler.isInvalid())
6171 if (!getDerived().AlwaysRebuild() && !Var &&
6172 Handler.get() == S->getHandlerBlock())
6175 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6178 template <typename Derived>
6179 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6180 // Transform the try block itself.
6181 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6182 if (TryBlock.isInvalid())
6185 // Transform the handlers.
6186 bool HandlerChanged = false;
6187 SmallVector<Stmt *, 8> Handlers;
6188 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6189 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6190 if (Handler.isInvalid())
6193 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6194 Handlers.push_back(Handler.getAs<Stmt>());
6197 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6201 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6205 template<typename Derived>
6207 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6208 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6209 if (Range.isInvalid())
6212 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6213 if (BeginEnd.isInvalid())
6216 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6217 if (Cond.isInvalid())
6220 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
6221 if (Cond.isInvalid())
6224 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
6226 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6227 if (Inc.isInvalid())
6230 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
6232 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6233 if (LoopVar.isInvalid())
6236 StmtResult NewStmt = S;
6237 if (getDerived().AlwaysRebuild() ||
6238 Range.get() != S->getRangeStmt() ||
6239 BeginEnd.get() != S->getBeginEndStmt() ||
6240 Cond.get() != S->getCond() ||
6241 Inc.get() != S->getInc() ||
6242 LoopVar.get() != S->getLoopVarStmt()) {
6243 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6244 S->getColonLoc(), Range.get(),
6245 BeginEnd.get(), Cond.get(),
6246 Inc.get(), LoopVar.get(),
6248 if (NewStmt.isInvalid())
6252 StmtResult Body = getDerived().TransformStmt(S->getBody());
6253 if (Body.isInvalid())
6256 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6257 // it now so we have a new statement to attach the body to.
6258 if (Body.get() != S->getBody() && NewStmt.get() == S) {
6259 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6260 S->getColonLoc(), Range.get(),
6261 BeginEnd.get(), Cond.get(),
6262 Inc.get(), LoopVar.get(),
6264 if (NewStmt.isInvalid())
6268 if (NewStmt.get() == S)
6271 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6274 template<typename Derived>
6276 TreeTransform<Derived>::TransformMSDependentExistsStmt(
6277 MSDependentExistsStmt *S) {
6278 // Transform the nested-name-specifier, if any.
6279 NestedNameSpecifierLoc QualifierLoc;
6280 if (S->getQualifierLoc()) {
6282 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6287 // Transform the declaration name.
6288 DeclarationNameInfo NameInfo = S->getNameInfo();
6289 if (NameInfo.getName()) {
6290 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6291 if (!NameInfo.getName())
6295 // Check whether anything changed.
6296 if (!getDerived().AlwaysRebuild() &&
6297 QualifierLoc == S->getQualifierLoc() &&
6298 NameInfo.getName() == S->getNameInfo().getName())
6301 // Determine whether this name exists, if we can.
6303 SS.Adopt(QualifierLoc);
6304 bool Dependent = false;
6305 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
6306 case Sema::IER_Exists:
6307 if (S->isIfExists())
6310 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6312 case Sema::IER_DoesNotExist:
6313 if (S->isIfNotExists())
6316 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6318 case Sema::IER_Dependent:
6322 case Sema::IER_Error:
6326 // We need to continue with the instantiation, so do so now.
6327 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6328 if (SubStmt.isInvalid())
6331 // If we have resolved the name, just transform to the substatement.
6335 // The name is still dependent, so build a dependent expression again.
6336 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6343 template<typename Derived>
6345 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6346 NestedNameSpecifierLoc QualifierLoc;
6347 if (E->getQualifierLoc()) {
6349 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6354 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6355 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6359 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6360 if (Base.isInvalid())
6363 return new (SemaRef.getASTContext())
6364 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6365 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6366 QualifierLoc, E->getMemberLoc());
6369 template <typename Derived>
6370 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6371 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6372 if (TryBlock.isInvalid())
6375 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6376 if (Handler.isInvalid())
6379 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6380 Handler.get() == S->getHandler())
6383 return getDerived().RebuildSEHTryStmt(
6384 S->getIsCXXTry(), S->getTryLoc(), TryBlock.get(), Handler.get(),
6385 S->getHandlerIndex(), S->getHandlerParentIndex());
6388 template <typename Derived>
6389 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6390 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
6391 if (Block.isInvalid())
6394 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
6397 template <typename Derived>
6398 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6399 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6400 if (FilterExpr.isInvalid())
6403 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
6404 if (Block.isInvalid())
6407 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6411 template <typename Derived>
6412 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6413 if (isa<SEHFinallyStmt>(Handler))
6414 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6416 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6419 template<typename Derived>
6421 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6425 //===----------------------------------------------------------------------===//
6426 // OpenMP directive transformation
6427 //===----------------------------------------------------------------------===//
6428 template <typename Derived>
6429 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6430 OMPExecutableDirective *D) {
6432 // Transform the clauses
6433 llvm::SmallVector<OMPClause *, 16> TClauses;
6434 ArrayRef<OMPClause *> Clauses = D->clauses();
6435 TClauses.reserve(Clauses.size());
6436 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6439 OMPClause *Clause = getDerived().TransformOMPClause(*I);
6441 TClauses.push_back(Clause);
6443 TClauses.push_back(nullptr);
6446 StmtResult AssociatedStmt;
6447 if (D->hasAssociatedStmt()) {
6448 if (!D->getAssociatedStmt()) {
6451 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6452 if (AssociatedStmt.isInvalid()) {
6456 if (TClauses.size() != Clauses.size()) {
6460 // Transform directive name for 'omp critical' directive.
6461 DeclarationNameInfo DirName;
6462 if (D->getDirectiveKind() == OMPD_critical) {
6463 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6464 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6467 return getDerived().RebuildOMPExecutableDirective(
6468 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6469 D->getLocStart(), D->getLocEnd());
6472 template <typename Derived>
6474 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6475 DeclarationNameInfo DirName;
6476 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6478 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6479 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6483 template <typename Derived>
6485 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6486 DeclarationNameInfo DirName;
6487 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6489 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6490 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6494 template <typename Derived>
6496 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6497 DeclarationNameInfo DirName;
6498 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6500 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6501 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6505 template <typename Derived>
6507 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6508 DeclarationNameInfo DirName;
6509 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6511 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6512 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6516 template <typename Derived>
6518 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6519 DeclarationNameInfo DirName;
6520 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6522 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6523 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6527 template <typename Derived>
6529 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6530 DeclarationNameInfo DirName;
6531 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6533 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6534 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6538 template <typename Derived>
6540 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6541 DeclarationNameInfo DirName;
6542 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6544 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6545 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6549 template <typename Derived>
6551 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6552 getDerived().getSema().StartOpenMPDSABlock(
6553 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6554 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6555 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6559 template <typename Derived>
6560 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6561 OMPParallelForDirective *D) {
6562 DeclarationNameInfo DirName;
6563 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6564 nullptr, D->getLocStart());
6565 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6566 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6570 template <typename Derived>
6571 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6572 OMPParallelSectionsDirective *D) {
6573 DeclarationNameInfo DirName;
6574 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6575 nullptr, D->getLocStart());
6576 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6577 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6581 template <typename Derived>
6583 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6584 DeclarationNameInfo DirName;
6585 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6587 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6588 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6592 template <typename Derived>
6593 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6594 OMPTaskyieldDirective *D) {
6595 DeclarationNameInfo DirName;
6596 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6598 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6599 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6603 template <typename Derived>
6605 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6606 DeclarationNameInfo DirName;
6607 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6609 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6610 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6614 template <typename Derived>
6616 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6617 DeclarationNameInfo DirName;
6618 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6620 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6621 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6625 template <typename Derived>
6627 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6628 DeclarationNameInfo DirName;
6629 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6631 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6632 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6636 //===----------------------------------------------------------------------===//
6637 // OpenMP clause transformation
6638 //===----------------------------------------------------------------------===//
6639 template <typename Derived>
6640 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
6641 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6642 if (Cond.isInvalid())
6644 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
6645 C->getLParenLoc(), C->getLocEnd());
6648 template <typename Derived>
6649 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6650 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6651 if (Cond.isInvalid())
6653 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6654 C->getLParenLoc(), C->getLocEnd());
6657 template <typename Derived>
6659 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6660 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6661 if (NumThreads.isInvalid())
6663 return getDerived().RebuildOMPNumThreadsClause(
6664 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6667 template <typename Derived>
6669 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6670 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6673 return getDerived().RebuildOMPSafelenClause(
6674 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6677 template <typename Derived>
6679 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6680 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6683 return getDerived().RebuildOMPCollapseClause(
6684 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6687 template <typename Derived>
6689 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6690 return getDerived().RebuildOMPDefaultClause(
6691 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6692 C->getLParenLoc(), C->getLocEnd());
6695 template <typename Derived>
6697 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
6698 return getDerived().RebuildOMPProcBindClause(
6699 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6700 C->getLParenLoc(), C->getLocEnd());
6703 template <typename Derived>
6705 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6706 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6709 return getDerived().RebuildOMPScheduleClause(
6710 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6711 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6714 template <typename Derived>
6716 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6717 // No need to rebuild this clause, no template-dependent parameters.
6721 template <typename Derived>
6723 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6724 // No need to rebuild this clause, no template-dependent parameters.
6728 template <typename Derived>
6730 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6731 // No need to rebuild this clause, no template-dependent parameters.
6735 template <typename Derived>
6737 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6738 // No need to rebuild this clause, no template-dependent parameters.
6742 template <typename Derived>
6744 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
6745 llvm::SmallVector<Expr *, 16> Vars;
6746 Vars.reserve(C->varlist_size());
6747 for (auto *VE : C->varlists()) {
6748 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6749 if (EVar.isInvalid())
6751 Vars.push_back(EVar.get());
6753 return getDerived().RebuildOMPPrivateClause(
6754 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6757 template <typename Derived>
6758 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6759 OMPFirstprivateClause *C) {
6760 llvm::SmallVector<Expr *, 16> Vars;
6761 Vars.reserve(C->varlist_size());
6762 for (auto *VE : C->varlists()) {
6763 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6764 if (EVar.isInvalid())
6766 Vars.push_back(EVar.get());
6768 return getDerived().RebuildOMPFirstprivateClause(
6769 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6772 template <typename Derived>
6774 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6775 llvm::SmallVector<Expr *, 16> Vars;
6776 Vars.reserve(C->varlist_size());
6777 for (auto *VE : C->varlists()) {
6778 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6779 if (EVar.isInvalid())
6781 Vars.push_back(EVar.get());
6783 return getDerived().RebuildOMPLastprivateClause(
6784 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6787 template <typename Derived>
6789 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6790 llvm::SmallVector<Expr *, 16> Vars;
6791 Vars.reserve(C->varlist_size());
6792 for (auto *VE : C->varlists()) {
6793 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6794 if (EVar.isInvalid())
6796 Vars.push_back(EVar.get());
6798 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6799 C->getLParenLoc(), C->getLocEnd());
6802 template <typename Derived>
6804 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6805 llvm::SmallVector<Expr *, 16> Vars;
6806 Vars.reserve(C->varlist_size());
6807 for (auto *VE : C->varlists()) {
6808 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6809 if (EVar.isInvalid())
6811 Vars.push_back(EVar.get());
6813 CXXScopeSpec ReductionIdScopeSpec;
6814 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6816 DeclarationNameInfo NameInfo = C->getNameInfo();
6817 if (NameInfo.getName()) {
6818 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6819 if (!NameInfo.getName())
6822 return getDerived().RebuildOMPReductionClause(
6823 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6824 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6827 template <typename Derived>
6829 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6830 llvm::SmallVector<Expr *, 16> Vars;
6831 Vars.reserve(C->varlist_size());
6832 for (auto *VE : C->varlists()) {
6833 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6834 if (EVar.isInvalid())
6836 Vars.push_back(EVar.get());
6838 ExprResult Step = getDerived().TransformExpr(C->getStep());
6839 if (Step.isInvalid())
6841 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6843 C->getColonLoc(), C->getLocEnd());
6846 template <typename Derived>
6848 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6849 llvm::SmallVector<Expr *, 16> Vars;
6850 Vars.reserve(C->varlist_size());
6851 for (auto *VE : C->varlists()) {
6852 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6853 if (EVar.isInvalid())
6855 Vars.push_back(EVar.get());
6857 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6858 if (Alignment.isInvalid())
6860 return getDerived().RebuildOMPAlignedClause(
6861 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6862 C->getColonLoc(), C->getLocEnd());
6865 template <typename Derived>
6867 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6868 llvm::SmallVector<Expr *, 16> Vars;
6869 Vars.reserve(C->varlist_size());
6870 for (auto *VE : C->varlists()) {
6871 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6872 if (EVar.isInvalid())
6874 Vars.push_back(EVar.get());
6876 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6877 C->getLParenLoc(), C->getLocEnd());
6880 template <typename Derived>
6882 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6883 llvm::SmallVector<Expr *, 16> Vars;
6884 Vars.reserve(C->varlist_size());
6885 for (auto *VE : C->varlists()) {
6886 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6887 if (EVar.isInvalid())
6889 Vars.push_back(EVar.get());
6891 return getDerived().RebuildOMPCopyprivateClause(
6892 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6895 template <typename Derived>
6896 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
6897 llvm::SmallVector<Expr *, 16> Vars;
6898 Vars.reserve(C->varlist_size());
6899 for (auto *VE : C->varlists()) {
6900 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6901 if (EVar.isInvalid())
6903 Vars.push_back(EVar.get());
6905 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
6906 C->getLParenLoc(), C->getLocEnd());
6909 //===----------------------------------------------------------------------===//
6910 // Expression transformation
6911 //===----------------------------------------------------------------------===//
6912 template<typename Derived>
6914 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
6918 template<typename Derived>
6920 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
6921 NestedNameSpecifierLoc QualifierLoc;
6922 if (E->getQualifierLoc()) {
6924 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6930 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6935 DeclarationNameInfo NameInfo = E->getNameInfo();
6936 if (NameInfo.getName()) {
6937 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6938 if (!NameInfo.getName())
6942 if (!getDerived().AlwaysRebuild() &&
6943 QualifierLoc == E->getQualifierLoc() &&
6944 ND == E->getDecl() &&
6945 NameInfo.getName() == E->getDecl()->getDeclName() &&
6946 !E->hasExplicitTemplateArgs()) {
6948 // Mark it referenced in the new context regardless.
6949 // FIXME: this is a bit instantiation-specific.
6950 SemaRef.MarkDeclRefReferenced(E);
6955 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
6956 if (E->hasExplicitTemplateArgs()) {
6957 TemplateArgs = &TransArgs;
6958 TransArgs.setLAngleLoc(E->getLAngleLoc());
6959 TransArgs.setRAngleLoc(E->getRAngleLoc());
6960 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6961 E->getNumTemplateArgs(),
6966 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6970 template<typename Derived>
6972 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
6976 template<typename Derived>
6978 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
6982 template<typename Derived>
6984 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
6988 template<typename Derived>
6990 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
6994 template<typename Derived>
6996 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
7000 template<typename Derived>
7002 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
7003 if (FunctionDecl *FD = E->getDirectCallee())
7004 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
7005 return SemaRef.MaybeBindToTemporary(E);
7008 template<typename Derived>
7010 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7011 ExprResult ControllingExpr =
7012 getDerived().TransformExpr(E->getControllingExpr());
7013 if (ControllingExpr.isInvalid())
7016 SmallVector<Expr *, 4> AssocExprs;
7017 SmallVector<TypeSourceInfo *, 4> AssocTypes;
7018 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7019 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7021 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7024 AssocTypes.push_back(AssocType);
7026 AssocTypes.push_back(nullptr);
7029 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7030 if (AssocExpr.isInvalid())
7032 AssocExprs.push_back(AssocExpr.get());
7035 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7038 ControllingExpr.get(),
7043 template<typename Derived>
7045 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
7046 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7047 if (SubExpr.isInvalid())
7050 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
7053 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
7057 /// \brief The operand of a unary address-of operator has special rules: it's
7058 /// allowed to refer to a non-static member of a class even if there's no 'this'
7059 /// object available.
7060 template<typename Derived>
7062 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7063 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
7064 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
7066 return getDerived().TransformExpr(E);
7069 template<typename Derived>
7071 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
7073 if (E->getOpcode() == UO_AddrOf)
7074 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7076 SubExpr = TransformExpr(E->getSubExpr());
7077 if (SubExpr.isInvalid())
7080 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
7083 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7088 template<typename Derived>
7090 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7091 // Transform the type.
7092 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7096 // Transform all of the components into components similar to what the
7098 // FIXME: It would be slightly more efficient in the non-dependent case to
7099 // just map FieldDecls, rather than requiring the rebuilder to look for
7100 // the fields again. However, __builtin_offsetof is rare enough in
7101 // template code that we don't care.
7102 bool ExprChanged = false;
7103 typedef Sema::OffsetOfComponent Component;
7104 typedef OffsetOfExpr::OffsetOfNode Node;
7105 SmallVector<Component, 4> Components;
7106 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7107 const Node &ON = E->getComponent(I);
7109 Comp.isBrackets = true;
7110 Comp.LocStart = ON.getSourceRange().getBegin();
7111 Comp.LocEnd = ON.getSourceRange().getEnd();
7112 switch (ON.getKind()) {
7114 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
7115 ExprResult Index = getDerived().TransformExpr(FromIndex);
7116 if (Index.isInvalid())
7119 ExprChanged = ExprChanged || Index.get() != FromIndex;
7120 Comp.isBrackets = true;
7121 Comp.U.E = Index.get();
7126 case Node::Identifier:
7127 Comp.isBrackets = false;
7128 Comp.U.IdentInfo = ON.getFieldName();
7129 if (!Comp.U.IdentInfo)
7135 // Will be recomputed during the rebuild.
7139 Components.push_back(Comp);
7142 // If nothing changed, retain the existing expression.
7143 if (!getDerived().AlwaysRebuild() &&
7144 Type == E->getTypeSourceInfo() &&
7148 // Build a new offsetof expression.
7149 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7150 Components.data(), Components.size(),
7154 template<typename Derived>
7156 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7157 assert(getDerived().AlreadyTransformed(E->getType()) &&
7158 "opaque value expression requires transformation");
7162 template<typename Derived>
7164 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
7165 // Rebuild the syntactic form. The original syntactic form has
7166 // opaque-value expressions in it, so strip those away and rebuild
7167 // the result. This is a really awful way of doing this, but the
7168 // better solution (rebuilding the semantic expressions and
7169 // rebinding OVEs as necessary) doesn't work; we'd need
7170 // TreeTransform to not strip away implicit conversions.
7171 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7172 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
7173 if (result.isInvalid()) return ExprError();
7175 // If that gives us a pseudo-object result back, the pseudo-object
7176 // expression must have been an lvalue-to-rvalue conversion which we
7178 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
7179 result = SemaRef.checkPseudoObjectRValue(result.get());
7184 template<typename Derived>
7186 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7187 UnaryExprOrTypeTraitExpr *E) {
7188 if (E->isArgumentType()) {
7189 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
7191 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7195 if (!getDerived().AlwaysRebuild() && OldT == NewT)
7198 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7200 E->getSourceRange());
7203 // C++0x [expr.sizeof]p1:
7204 // The operand is either an expression, which is an unevaluated operand
7206 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7207 Sema::ReuseLambdaContextDecl);
7209 // Try to recover if we have something like sizeof(T::X) where X is a type.
7210 // Notably, there must be *exactly* one set of parens if X is a type.
7211 TypeSourceInfo *RecoveryTSI = nullptr;
7213 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7215 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7216 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7217 PE, DRE, false, &RecoveryTSI);
7219 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7222 return getDerived().RebuildUnaryExprOrTypeTrait(
7223 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7224 } else if (SubExpr.isInvalid())
7227 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
7230 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7231 E->getOperatorLoc(),
7233 E->getSourceRange());
7236 template<typename Derived>
7238 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
7239 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7240 if (LHS.isInvalid())
7243 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7244 if (RHS.isInvalid())
7248 if (!getDerived().AlwaysRebuild() &&
7249 LHS.get() == E->getLHS() &&
7250 RHS.get() == E->getRHS())
7253 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
7254 /*FIXME:*/E->getLHS()->getLocStart(),
7256 E->getRBracketLoc());
7259 template<typename Derived>
7261 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
7262 // Transform the callee.
7263 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7264 if (Callee.isInvalid())
7267 // Transform arguments.
7268 bool ArgChanged = false;
7269 SmallVector<Expr*, 8> Args;
7270 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7274 if (!getDerived().AlwaysRebuild() &&
7275 Callee.get() == E->getCallee() &&
7277 return SemaRef.MaybeBindToTemporary(E);
7279 // FIXME: Wrong source location information for the '('.
7280 SourceLocation FakeLParenLoc
7281 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7282 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
7287 template<typename Derived>
7289 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
7290 ExprResult Base = getDerived().TransformExpr(E->getBase());
7291 if (Base.isInvalid())
7294 NestedNameSpecifierLoc QualifierLoc;
7295 if (E->hasQualifier()) {
7297 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7302 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
7305 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7306 E->getMemberDecl()));
7310 NamedDecl *FoundDecl = E->getFoundDecl();
7311 if (FoundDecl == E->getMemberDecl()) {
7314 FoundDecl = cast_or_null<NamedDecl>(
7315 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7320 if (!getDerived().AlwaysRebuild() &&
7321 Base.get() == E->getBase() &&
7322 QualifierLoc == E->getQualifierLoc() &&
7323 Member == E->getMemberDecl() &&
7324 FoundDecl == E->getFoundDecl() &&
7325 !E->hasExplicitTemplateArgs()) {
7327 // Mark it referenced in the new context regardless.
7328 // FIXME: this is a bit instantiation-specific.
7329 SemaRef.MarkMemberReferenced(E);
7334 TemplateArgumentListInfo TransArgs;
7335 if (E->hasExplicitTemplateArgs()) {
7336 TransArgs.setLAngleLoc(E->getLAngleLoc());
7337 TransArgs.setRAngleLoc(E->getRAngleLoc());
7338 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7339 E->getNumTemplateArgs(),
7344 // FIXME: Bogus source location for the operator
7345 SourceLocation FakeOperatorLoc =
7346 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
7348 // FIXME: to do this check properly, we will need to preserve the
7349 // first-qualifier-in-scope here, just in case we had a dependent
7350 // base (and therefore couldn't do the check) and a
7351 // nested-name-qualifier (and therefore could do the lookup).
7352 NamedDecl *FirstQualifierInScope = nullptr;
7354 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
7358 E->getMemberNameInfo(),
7361 (E->hasExplicitTemplateArgs()
7362 ? &TransArgs : nullptr),
7363 FirstQualifierInScope);
7366 template<typename Derived>
7368 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
7369 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7370 if (LHS.isInvalid())
7373 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7374 if (RHS.isInvalid())
7377 if (!getDerived().AlwaysRebuild() &&
7378 LHS.get() == E->getLHS() &&
7379 RHS.get() == E->getRHS())
7382 Sema::FPContractStateRAII FPContractState(getSema());
7383 getSema().FPFeatures.fp_contract = E->isFPContractable();
7385 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
7386 LHS.get(), RHS.get());
7389 template<typename Derived>
7391 TreeTransform<Derived>::TransformCompoundAssignOperator(
7392 CompoundAssignOperator *E) {
7393 return getDerived().TransformBinaryOperator(E);
7396 template<typename Derived>
7397 ExprResult TreeTransform<Derived>::
7398 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7399 // Just rebuild the common and RHS expressions and see whether we
7402 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7403 if (commonExpr.isInvalid())
7406 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7407 if (rhs.isInvalid())
7410 if (!getDerived().AlwaysRebuild() &&
7411 commonExpr.get() == e->getCommon() &&
7412 rhs.get() == e->getFalseExpr())
7415 return getDerived().RebuildConditionalOperator(commonExpr.get(),
7416 e->getQuestionLoc(),
7422 template<typename Derived>
7424 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
7425 ExprResult Cond = getDerived().TransformExpr(E->getCond());
7426 if (Cond.isInvalid())
7429 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7430 if (LHS.isInvalid())
7433 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7434 if (RHS.isInvalid())
7437 if (!getDerived().AlwaysRebuild() &&
7438 Cond.get() == E->getCond() &&
7439 LHS.get() == E->getLHS() &&
7440 RHS.get() == E->getRHS())
7443 return getDerived().RebuildConditionalOperator(Cond.get(),
7444 E->getQuestionLoc(),
7450 template<typename Derived>
7452 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
7453 // Implicit casts are eliminated during transformation, since they
7454 // will be recomputed by semantic analysis after transformation.
7455 return getDerived().TransformExpr(E->getSubExprAsWritten());
7458 template<typename Derived>
7460 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
7461 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7466 = getDerived().TransformExpr(E->getSubExprAsWritten());
7467 if (SubExpr.isInvalid())
7470 if (!getDerived().AlwaysRebuild() &&
7471 Type == E->getTypeInfoAsWritten() &&
7472 SubExpr.get() == E->getSubExpr())
7475 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
7481 template<typename Derived>
7483 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
7484 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7485 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7489 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
7490 if (Init.isInvalid())
7493 if (!getDerived().AlwaysRebuild() &&
7495 Init.get() == E->getInitializer())
7496 return SemaRef.MaybeBindToTemporary(E);
7498 // Note: the expression type doesn't necessarily match the
7499 // type-as-written, but that's okay, because it should always be
7500 // derivable from the initializer.
7502 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
7503 /*FIXME:*/E->getInitializer()->getLocEnd(),
7507 template<typename Derived>
7509 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
7510 ExprResult Base = getDerived().TransformExpr(E->getBase());
7511 if (Base.isInvalid())
7514 if (!getDerived().AlwaysRebuild() &&
7515 Base.get() == E->getBase())
7518 // FIXME: Bad source location
7519 SourceLocation FakeOperatorLoc =
7520 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
7521 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
7522 E->getAccessorLoc(),
7526 template<typename Derived>
7528 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
7529 bool InitChanged = false;
7531 SmallVector<Expr*, 4> Inits;
7532 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
7533 Inits, &InitChanged))
7536 if (!getDerived().AlwaysRebuild() && !InitChanged)
7539 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
7540 E->getRBraceLoc(), E->getType());
7543 template<typename Derived>
7545 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
7548 // transform the initializer value
7549 ExprResult Init = getDerived().TransformExpr(E->getInit());
7550 if (Init.isInvalid())
7553 // transform the designators.
7554 SmallVector<Expr*, 4> ArrayExprs;
7555 bool ExprChanged = false;
7556 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7557 DEnd = E->designators_end();
7559 if (D->isFieldDesignator()) {
7560 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7566 if (D->isArrayDesignator()) {
7567 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
7568 if (Index.isInvalid())
7571 Desig.AddDesignator(Designator::getArray(Index.get(),
7572 D->getLBracketLoc()));
7574 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7575 ArrayExprs.push_back(Index.get());
7579 assert(D->isArrayRangeDesignator() && "New kind of designator?");
7581 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7582 if (Start.isInvalid())
7585 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
7586 if (End.isInvalid())
7589 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
7591 D->getLBracketLoc(),
7592 D->getEllipsisLoc()));
7594 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7595 End.get() != E->getArrayRangeEnd(*D);
7597 ArrayExprs.push_back(Start.get());
7598 ArrayExprs.push_back(End.get());
7601 if (!getDerived().AlwaysRebuild() &&
7602 Init.get() == E->getInit() &&
7606 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
7607 E->getEqualOrColonLoc(),
7608 E->usesGNUSyntax(), Init.get());
7611 template<typename Derived>
7613 TreeTransform<Derived>::TransformImplicitValueInitExpr(
7614 ImplicitValueInitExpr *E) {
7615 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
7617 // FIXME: Will we ever have proper type location here? Will we actually
7618 // need to transform the type?
7619 QualType T = getDerived().TransformType(E->getType());
7623 if (!getDerived().AlwaysRebuild() &&
7627 return getDerived().RebuildImplicitValueInitExpr(T);
7630 template<typename Derived>
7632 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
7633 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7637 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7638 if (SubExpr.isInvalid())
7641 if (!getDerived().AlwaysRebuild() &&
7642 TInfo == E->getWrittenTypeInfo() &&
7643 SubExpr.get() == E->getSubExpr())
7646 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
7647 TInfo, E->getRParenLoc());
7650 template<typename Derived>
7652 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
7653 bool ArgumentChanged = false;
7654 SmallVector<Expr*, 4> Inits;
7655 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7659 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
7664 /// \brief Transform an address-of-label expression.
7666 /// By default, the transformation of an address-of-label expression always
7667 /// rebuilds the expression, so that the label identifier can be resolved to
7668 /// the corresponding label statement by semantic analysis.
7669 template<typename Derived>
7671 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
7672 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7677 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
7678 cast<LabelDecl>(LD));
7681 template<typename Derived>
7683 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
7684 SemaRef.ActOnStartStmtExpr();
7686 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
7687 if (SubStmt.isInvalid()) {
7688 SemaRef.ActOnStmtExprError();
7692 if (!getDerived().AlwaysRebuild() &&
7693 SubStmt.get() == E->getSubStmt()) {
7694 // Calling this an 'error' is unintuitive, but it does the right thing.
7695 SemaRef.ActOnStmtExprError();
7696 return SemaRef.MaybeBindToTemporary(E);
7699 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
7704 template<typename Derived>
7706 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
7707 ExprResult Cond = getDerived().TransformExpr(E->getCond());
7708 if (Cond.isInvalid())
7711 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7712 if (LHS.isInvalid())
7715 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7716 if (RHS.isInvalid())
7719 if (!getDerived().AlwaysRebuild() &&
7720 Cond.get() == E->getCond() &&
7721 LHS.get() == E->getLHS() &&
7722 RHS.get() == E->getRHS())
7725 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
7726 Cond.get(), LHS.get(), RHS.get(),
7730 template<typename Derived>
7732 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
7736 template<typename Derived>
7738 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
7739 switch (E->getOperator()) {
7743 case OO_Array_Delete:
7744 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
7747 // This is a call to an object's operator().
7748 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7750 // Transform the object itself.
7751 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
7752 if (Object.isInvalid())
7755 // FIXME: Poor location information
7756 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7757 static_cast<Expr *>(Object.get())->getLocEnd());
7759 // Transform the call arguments.
7760 SmallVector<Expr*, 8> Args;
7761 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
7765 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
7770 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7772 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7773 #include "clang/Basic/OperatorKinds.def"
7778 case OO_Conditional:
7779 llvm_unreachable("conditional operator is not actually overloadable");
7782 case NUM_OVERLOADED_OPERATORS:
7783 llvm_unreachable("not an overloaded operator?");
7786 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7787 if (Callee.isInvalid())
7791 if (E->getOperator() == OO_Amp)
7792 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7794 First = getDerived().TransformExpr(E->getArg(0));
7795 if (First.isInvalid())
7799 if (E->getNumArgs() == 2) {
7800 Second = getDerived().TransformExpr(E->getArg(1));
7801 if (Second.isInvalid())
7805 if (!getDerived().AlwaysRebuild() &&
7806 Callee.get() == E->getCallee() &&
7807 First.get() == E->getArg(0) &&
7808 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
7809 return SemaRef.MaybeBindToTemporary(E);
7811 Sema::FPContractStateRAII FPContractState(getSema());
7812 getSema().FPFeatures.fp_contract = E->isFPContractable();
7814 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7815 E->getOperatorLoc(),
7821 template<typename Derived>
7823 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7824 return getDerived().TransformCallExpr(E);
7827 template<typename Derived>
7829 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7830 // Transform the callee.
7831 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7832 if (Callee.isInvalid())
7835 // Transform exec config.
7836 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7840 // Transform arguments.
7841 bool ArgChanged = false;
7842 SmallVector<Expr*, 8> Args;
7843 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7847 if (!getDerived().AlwaysRebuild() &&
7848 Callee.get() == E->getCallee() &&
7850 return SemaRef.MaybeBindToTemporary(E);
7852 // FIXME: Wrong source location information for the '('.
7853 SourceLocation FakeLParenLoc
7854 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7855 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
7857 E->getRParenLoc(), EC.get());
7860 template<typename Derived>
7862 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
7863 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7868 = getDerived().TransformExpr(E->getSubExprAsWritten());
7869 if (SubExpr.isInvalid())
7872 if (!getDerived().AlwaysRebuild() &&
7873 Type == E->getTypeInfoAsWritten() &&
7874 SubExpr.get() == E->getSubExpr())
7876 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
7878 E->getAngleBrackets().getBegin(),
7880 E->getAngleBrackets().getEnd(),
7881 // FIXME. this should be '(' location
7882 E->getAngleBrackets().getEnd(),
7887 template<typename Derived>
7889 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7890 return getDerived().TransformCXXNamedCastExpr(E);
7893 template<typename Derived>
7895 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7896 return getDerived().TransformCXXNamedCastExpr(E);
7899 template<typename Derived>
7901 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
7902 CXXReinterpretCastExpr *E) {
7903 return getDerived().TransformCXXNamedCastExpr(E);
7906 template<typename Derived>
7908 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7909 return getDerived().TransformCXXNamedCastExpr(E);
7912 template<typename Derived>
7914 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
7915 CXXFunctionalCastExpr *E) {
7916 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7921 = getDerived().TransformExpr(E->getSubExprAsWritten());
7922 if (SubExpr.isInvalid())
7925 if (!getDerived().AlwaysRebuild() &&
7926 Type == E->getTypeInfoAsWritten() &&
7927 SubExpr.get() == E->getSubExpr())
7930 return getDerived().RebuildCXXFunctionalCastExpr(Type,
7936 template<typename Derived>
7938 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
7939 if (E->isTypeOperand()) {
7940 TypeSourceInfo *TInfo
7941 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7945 if (!getDerived().AlwaysRebuild() &&
7946 TInfo == E->getTypeOperandSourceInfo())
7949 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7955 // We don't know whether the subexpression is potentially evaluated until
7956 // after we perform semantic analysis. We speculatively assume it is
7957 // unevaluated; it will get fixed later if the subexpression is in fact
7958 // potentially evaluated.
7959 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7960 Sema::ReuseLambdaContextDecl);
7962 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7963 if (SubExpr.isInvalid())
7966 if (!getDerived().AlwaysRebuild() &&
7967 SubExpr.get() == E->getExprOperand())
7970 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7976 template<typename Derived>
7978 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7979 if (E->isTypeOperand()) {
7980 TypeSourceInfo *TInfo
7981 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7985 if (!getDerived().AlwaysRebuild() &&
7986 TInfo == E->getTypeOperandSourceInfo())
7989 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7995 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7997 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7998 if (SubExpr.isInvalid())
8001 if (!getDerived().AlwaysRebuild() &&
8002 SubExpr.get() == E->getExprOperand())
8005 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8011 template<typename Derived>
8013 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
8017 template<typename Derived>
8019 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
8020 CXXNullPtrLiteralExpr *E) {
8024 template<typename Derived>
8026 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
8027 QualType T = getSema().getCurrentThisType();
8029 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8030 // Make sure that we capture 'this'.
8031 getSema().CheckCXXThisCapture(E->getLocStart());
8035 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
8038 template<typename Derived>
8040 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
8041 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8042 if (SubExpr.isInvalid())
8045 if (!getDerived().AlwaysRebuild() &&
8046 SubExpr.get() == E->getSubExpr())
8049 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8050 E->isThrownVariableInScope());
8053 template<typename Derived>
8055 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
8057 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8062 if (!getDerived().AlwaysRebuild() &&
8063 Param == E->getParam())
8066 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
8069 template<typename Derived>
8071 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8073 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8078 if (!getDerived().AlwaysRebuild() && Field == E->getField())
8081 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8084 template<typename Derived>
8086 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8087 CXXScalarValueInitExpr *E) {
8088 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8092 if (!getDerived().AlwaysRebuild() &&
8093 T == E->getTypeSourceInfo())
8096 return getDerived().RebuildCXXScalarValueInitExpr(T,
8097 /*FIXME:*/T->getTypeLoc().getEndLoc(),
8101 template<typename Derived>
8103 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
8104 // Transform the type that we're allocating
8105 TypeSourceInfo *AllocTypeInfo
8106 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8110 // Transform the size of the array we're allocating (if any).
8111 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
8112 if (ArraySize.isInvalid())
8115 // Transform the placement arguments (if any).
8116 bool ArgumentChanged = false;
8117 SmallVector<Expr*, 8> PlacementArgs;
8118 if (getDerived().TransformExprs(E->getPlacementArgs(),
8119 E->getNumPlacementArgs(), true,
8120 PlacementArgs, &ArgumentChanged))
8123 // Transform the initializer (if any).
8124 Expr *OldInit = E->getInitializer();
8127 NewInit = getDerived().TransformInitializer(OldInit, true);
8128 if (NewInit.isInvalid())
8131 // Transform new operator and delete operator.
8132 FunctionDecl *OperatorNew = nullptr;
8133 if (E->getOperatorNew()) {
8134 OperatorNew = cast_or_null<FunctionDecl>(
8135 getDerived().TransformDecl(E->getLocStart(),
8136 E->getOperatorNew()));
8141 FunctionDecl *OperatorDelete = nullptr;
8142 if (E->getOperatorDelete()) {
8143 OperatorDelete = cast_or_null<FunctionDecl>(
8144 getDerived().TransformDecl(E->getLocStart(),
8145 E->getOperatorDelete()));
8146 if (!OperatorDelete)
8150 if (!getDerived().AlwaysRebuild() &&
8151 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
8152 ArraySize.get() == E->getArraySize() &&
8153 NewInit.get() == OldInit &&
8154 OperatorNew == E->getOperatorNew() &&
8155 OperatorDelete == E->getOperatorDelete() &&
8157 // Mark any declarations we need as referenced.
8158 // FIXME: instantiation-specific.
8160 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
8162 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
8164 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
8165 QualType ElementType
8166 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8167 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8168 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8169 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
8170 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
8178 QualType AllocType = AllocTypeInfo->getType();
8179 if (!ArraySize.get()) {
8180 // If no array size was specified, but the new expression was
8181 // instantiated with an array type (e.g., "new T" where T is
8182 // instantiated with "int[4]"), extract the outer bound from the
8183 // array type as our array size. We do this with constant and
8184 // dependently-sized array types.
8185 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8188 } else if (const ConstantArrayType *ConsArrayT
8189 = dyn_cast<ConstantArrayType>(ArrayT)) {
8190 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8191 SemaRef.Context.getSizeType(),
8192 /*FIXME:*/ E->getLocStart());
8193 AllocType = ConsArrayT->getElementType();
8194 } else if (const DependentSizedArrayType *DepArrayT
8195 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8196 if (DepArrayT->getSizeExpr()) {
8197 ArraySize = DepArrayT->getSizeExpr();
8198 AllocType = DepArrayT->getElementType();
8203 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8205 /*FIXME:*/E->getLocStart(),
8207 /*FIXME:*/E->getLocStart(),
8208 E->getTypeIdParens(),
8212 E->getDirectInitRange(),
8216 template<typename Derived>
8218 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
8219 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
8220 if (Operand.isInvalid())
8223 // Transform the delete operator, if known.
8224 FunctionDecl *OperatorDelete = nullptr;
8225 if (E->getOperatorDelete()) {
8226 OperatorDelete = cast_or_null<FunctionDecl>(
8227 getDerived().TransformDecl(E->getLocStart(),
8228 E->getOperatorDelete()));
8229 if (!OperatorDelete)
8233 if (!getDerived().AlwaysRebuild() &&
8234 Operand.get() == E->getArgument() &&
8235 OperatorDelete == E->getOperatorDelete()) {
8236 // Mark any declarations we need as referenced.
8237 // FIXME: instantiation-specific.
8239 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
8241 if (!E->getArgument()->isTypeDependent()) {
8242 QualType Destroyed = SemaRef.Context.getBaseElementType(
8243 E->getDestroyedType());
8244 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8245 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
8246 SemaRef.MarkFunctionReferenced(E->getLocStart(),
8247 SemaRef.LookupDestructor(Record));
8254 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8255 E->isGlobalDelete(),
8260 template<typename Derived>
8262 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
8263 CXXPseudoDestructorExpr *E) {
8264 ExprResult Base = getDerived().TransformExpr(E->getBase());
8265 if (Base.isInvalid())
8268 ParsedType ObjectTypePtr;
8269 bool MayBePseudoDestructor = false;
8270 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
8271 E->getOperatorLoc(),
8272 E->isArrow()? tok::arrow : tok::period,
8274 MayBePseudoDestructor);
8275 if (Base.isInvalid())
8278 QualType ObjectType = ObjectTypePtr.get();
8279 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8282 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8287 SS.Adopt(QualifierLoc);
8289 PseudoDestructorTypeStorage Destroyed;
8290 if (E->getDestroyedTypeInfo()) {
8291 TypeSourceInfo *DestroyedTypeInfo
8292 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
8293 ObjectType, nullptr, SS);
8294 if (!DestroyedTypeInfo)
8296 Destroyed = DestroyedTypeInfo;
8297 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
8298 // We aren't likely to be able to resolve the identifier down to a type
8299 // now anyway, so just retain the identifier.
8300 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8301 E->getDestroyedTypeLoc());
8303 // Look for a destructor known with the given name.
8304 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
8305 *E->getDestroyedTypeIdentifier(),
8306 E->getDestroyedTypeLoc(),
8314 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8315 E->getDestroyedTypeLoc());
8318 TypeSourceInfo *ScopeTypeInfo = nullptr;
8319 if (E->getScopeTypeInfo()) {
8320 CXXScopeSpec EmptySS;
8321 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
8322 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
8327 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
8328 E->getOperatorLoc(),
8332 E->getColonColonLoc(),
8337 template<typename Derived>
8339 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
8340 UnresolvedLookupExpr *Old) {
8341 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8342 Sema::LookupOrdinaryName);
8344 // Transform all the decls.
8345 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8346 E = Old->decls_end(); I != E; ++I) {
8347 NamedDecl *InstD = static_cast<NamedDecl*>(
8348 getDerived().TransformDecl(Old->getNameLoc(),
8351 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8352 // This can happen because of dependent hiding.
8353 if (isa<UsingShadowDecl>(*I))
8361 // Expand using declarations.
8362 if (isa<UsingDecl>(InstD)) {
8363 UsingDecl *UD = cast<UsingDecl>(InstD);
8364 for (auto *I : UD->shadows())
8372 // Resolve a kind, but don't do any further analysis. If it's
8373 // ambiguous, the callee needs to deal with it.
8376 // Rebuild the nested-name qualifier, if present.
8378 if (Old->getQualifierLoc()) {
8379 NestedNameSpecifierLoc QualifierLoc
8380 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8384 SS.Adopt(QualifierLoc);
8387 if (Old->getNamingClass()) {
8388 CXXRecordDecl *NamingClass
8389 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8391 Old->getNamingClass()));
8397 R.setNamingClass(NamingClass);
8400 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8402 // If we have neither explicit template arguments, nor the template keyword,
8403 // it's a normal declaration name.
8404 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
8405 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8407 // If we have template arguments, rebuild them, then rebuild the
8408 // templateid expression.
8409 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
8410 if (Old->hasExplicitTemplateArgs() &&
8411 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8412 Old->getNumTemplateArgs(),
8418 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
8419 Old->requiresADL(), &TransArgs);
8422 template<typename Derived>
8424 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8425 bool ArgChanged = false;
8426 SmallVector<TypeSourceInfo *, 4> Args;
8427 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8428 TypeSourceInfo *From = E->getArg(I);
8429 TypeLoc FromTL = From->getTypeLoc();
8430 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
8432 TLB.reserve(FromTL.getFullDataSize());
8433 QualType To = getDerived().TransformType(TLB, FromTL);
8437 if (To == From->getType())
8438 Args.push_back(From);
8440 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8448 // We have a pack expansion. Instantiate it.
8449 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
8450 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8451 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8452 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
8454 // Determine whether the set of unexpanded parameter packs can and should
8457 bool RetainExpansion = false;
8458 Optional<unsigned> OrigNumExpansions =
8459 ExpansionTL.getTypePtr()->getNumExpansions();
8460 Optional<unsigned> NumExpansions = OrigNumExpansions;
8461 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8462 PatternTL.getSourceRange(),
8464 Expand, RetainExpansion,
8469 // The transform has determined that we should perform a simple
8470 // transformation on the pack expansion, producing another pack
8472 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8475 TLB.reserve(From->getTypeLoc().getFullDataSize());
8477 QualType To = getDerived().TransformType(TLB, PatternTL);
8481 To = getDerived().RebuildPackExpansionType(To,
8482 PatternTL.getSourceRange(),
8483 ExpansionTL.getEllipsisLoc(),
8488 PackExpansionTypeLoc ToExpansionTL
8489 = TLB.push<PackExpansionTypeLoc>(To);
8490 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8491 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8495 // Expand the pack expansion by substituting for each argument in the
8497 for (unsigned I = 0; I != *NumExpansions; ++I) {
8498 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8500 TLB.reserve(PatternTL.getFullDataSize());
8501 QualType To = getDerived().TransformType(TLB, PatternTL);
8505 if (To->containsUnexpandedParameterPack()) {
8506 To = getDerived().RebuildPackExpansionType(To,
8507 PatternTL.getSourceRange(),
8508 ExpansionTL.getEllipsisLoc(),
8513 PackExpansionTypeLoc ToExpansionTL
8514 = TLB.push<PackExpansionTypeLoc>(To);
8515 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8518 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8521 if (!RetainExpansion)
8524 // If we're supposed to retain a pack expansion, do so by temporarily
8525 // forgetting the partially-substituted parameter pack.
8526 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8529 TLB.reserve(From->getTypeLoc().getFullDataSize());
8531 QualType To = getDerived().TransformType(TLB, PatternTL);
8535 To = getDerived().RebuildPackExpansionType(To,
8536 PatternTL.getSourceRange(),
8537 ExpansionTL.getEllipsisLoc(),
8542 PackExpansionTypeLoc ToExpansionTL
8543 = TLB.push<PackExpansionTypeLoc>(To);
8544 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8545 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8548 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8551 return getDerived().RebuildTypeTrait(E->getTrait(),
8557 template<typename Derived>
8559 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8560 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8564 if (!getDerived().AlwaysRebuild() &&
8565 T == E->getQueriedTypeSourceInfo())
8570 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8571 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8572 if (SubExpr.isInvalid())
8575 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8579 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8586 template<typename Derived>
8588 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8591 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8592 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8593 if (SubExpr.isInvalid())
8596 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8600 return getDerived().RebuildExpressionTrait(
8601 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8604 template <typename Derived>
8605 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8606 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8607 TypeSourceInfo **RecoveryTSI) {
8608 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8609 DRE, AddrTaken, RecoveryTSI);
8611 // Propagate both errors and recovered types, which return ExprEmpty.
8612 if (!NewDRE.isUsable())
8615 // We got an expr, wrap it up in parens.
8616 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8618 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8622 template <typename Derived>
8623 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8624 DependentScopeDeclRefExpr *E) {
8625 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8629 template<typename Derived>
8631 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8632 DependentScopeDeclRefExpr *E,
8633 bool IsAddressOfOperand,
8634 TypeSourceInfo **RecoveryTSI) {
8635 assert(E->getQualifierLoc());
8636 NestedNameSpecifierLoc QualifierLoc
8637 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8640 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8642 // TODO: If this is a conversion-function-id, verify that the
8643 // destination type name (if present) resolves the same way after
8644 // instantiation as it did in the local scope.
8646 DeclarationNameInfo NameInfo
8647 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8648 if (!NameInfo.getName())
8651 if (!E->hasExplicitTemplateArgs()) {
8652 if (!getDerived().AlwaysRebuild() &&
8653 QualifierLoc == E->getQualifierLoc() &&
8654 // Note: it is sufficient to compare the Name component of NameInfo:
8655 // if name has not changed, DNLoc has not changed either.
8656 NameInfo.getName() == E->getDeclName())
8659 return getDerived().RebuildDependentScopeDeclRefExpr(
8660 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8661 IsAddressOfOperand, RecoveryTSI);
8664 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8665 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8666 E->getNumTemplateArgs(),
8670 return getDerived().RebuildDependentScopeDeclRefExpr(
8671 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8675 template<typename Derived>
8677 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
8678 // CXXConstructExprs other than for list-initialization and
8679 // CXXTemporaryObjectExpr are always implicit, so when we have
8680 // a 1-argument construction we just transform that argument.
8681 if ((E->getNumArgs() == 1 ||
8682 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
8683 (!getDerived().DropCallArgument(E->getArg(0))) &&
8684 !E->isListInitialization())
8685 return getDerived().TransformExpr(E->getArg(0));
8687 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8689 QualType T = getDerived().TransformType(E->getType());
8693 CXXConstructorDecl *Constructor
8694 = cast_or_null<CXXConstructorDecl>(
8695 getDerived().TransformDecl(E->getLocStart(),
8696 E->getConstructor()));
8700 bool ArgumentChanged = false;
8701 SmallVector<Expr*, 8> Args;
8702 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8706 if (!getDerived().AlwaysRebuild() &&
8707 T == E->getType() &&
8708 Constructor == E->getConstructor() &&
8710 // Mark the constructor as referenced.
8711 // FIXME: Instantiation-specific
8712 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
8716 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8717 Constructor, E->isElidable(),
8719 E->hadMultipleCandidates(),
8720 E->isListInitialization(),
8721 E->isStdInitListInitialization(),
8722 E->requiresZeroInitialization(),
8723 E->getConstructionKind(),
8724 E->getParenOrBraceRange());
8727 /// \brief Transform a C++ temporary-binding expression.
8729 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8730 /// transform the subexpression and return that.
8731 template<typename Derived>
8733 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
8734 return getDerived().TransformExpr(E->getSubExpr());
8737 /// \brief Transform a C++ expression that contains cleanups that should
8738 /// be run after the expression is evaluated.
8740 /// Since ExprWithCleanups nodes are implicitly generated, we
8741 /// just transform the subexpression and return that.
8742 template<typename Derived>
8744 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
8745 return getDerived().TransformExpr(E->getSubExpr());
8748 template<typename Derived>
8750 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
8751 CXXTemporaryObjectExpr *E) {
8752 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8756 CXXConstructorDecl *Constructor
8757 = cast_or_null<CXXConstructorDecl>(
8758 getDerived().TransformDecl(E->getLocStart(),
8759 E->getConstructor()));
8763 bool ArgumentChanged = false;
8764 SmallVector<Expr*, 8> Args;
8765 Args.reserve(E->getNumArgs());
8766 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8770 if (!getDerived().AlwaysRebuild() &&
8771 T == E->getTypeSourceInfo() &&
8772 Constructor == E->getConstructor() &&
8774 // FIXME: Instantiation-specific
8775 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
8776 return SemaRef.MaybeBindToTemporary(E);
8779 // FIXME: Pass in E->isListInitialization().
8780 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8781 /*FIXME:*/T->getTypeLoc().getEndLoc(),
8786 template<typename Derived>
8788 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
8790 // Transform any init-capture expressions before entering the scope of the
8791 // lambda body, because they are not semantically within that scope.
8792 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8793 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8794 E->explicit_capture_begin());
8796 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8797 CEnd = E->capture_end();
8799 if (!C->isInitCapture())
8801 EnterExpressionEvaluationContext EEEC(getSema(),
8802 Sema::PotentiallyEvaluated);
8803 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8804 C->getCapturedVar()->getInit(),
8805 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8807 if (NewExprInitResult.isInvalid())
8809 Expr *NewExprInit = NewExprInitResult.get();
8811 VarDecl *OldVD = C->getCapturedVar();
8812 QualType NewInitCaptureType =
8813 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8814 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8816 NewExprInitResult = NewExprInit;
8817 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8818 std::make_pair(NewExprInitResult, NewInitCaptureType);
8822 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
8823 // Transform the template parameters, and add them to the current
8824 // instantiation scope. The null case is handled correctly.
8825 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8826 E->getTemplateParameterList());
8828 // Check to see if the TypeSourceInfo of the call operator needs to
8829 // be transformed, and if so do the transformation in the
8830 // CurrentInstantiationScope.
8832 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8833 FunctionProtoTypeLoc OldCallOpFPTL =
8834 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8835 TypeSourceInfo *NewCallOpTSI = nullptr;
8837 const bool CallOpWasAlreadyTransformed =
8838 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8840 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8841 if (CallOpWasAlreadyTransformed)
8842 NewCallOpTSI = OldCallOpTSI;
8844 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8845 // The transformation MUST be done in the CurrentInstantiationScope since
8846 // it introduces a mapping of the original to the newly created
8847 // transformed parameters.
8849 TypeLocBuilder NewCallOpTLBuilder;
8850 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8853 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8856 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8857 // the vector below - this will be used to synthesize the
8858 // NewCallOperator. Additionally, add the parameters of the untransformed
8859 // lambda call operator to the CurrentInstantiationScope.
8860 SmallVector<ParmVarDecl *, 4> Params;
8862 FunctionProtoTypeLoc NewCallOpFPTL =
8863 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8864 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8865 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
8867 for (unsigned I = 0; I < NewNumArgs; ++I) {
8868 // If this call operator's type does not require transformation,
8869 // the parameters do not get added to the current instantiation scope,
8870 // - so ADD them! This allows the following to compile when the enclosing
8871 // template is specialized and the entire lambda expression has to be
8873 // template<class T> void foo(T t) {
8874 // auto L = [](auto a) {
8875 // auto M = [](char b) { <-- note: non-generic lambda
8876 // auto N = [](auto c) {
8877 // int x = sizeof(a);
8878 // x = sizeof(b); <-- specifically this line
8885 if (CallOpWasAlreadyTransformed)
8886 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8887 NewParamDeclArray[I]);
8888 // Add to Params array, so these parameters can be used to create
8889 // the newly transformed call operator.
8890 Params.push_back(NewParamDeclArray[I]);
8897 // Create the local class that will describe the lambda.
8898 CXXRecordDecl *Class
8899 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8901 /*KnownDependent=*/false,
8902 E->getCaptureDefault());
8904 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8906 // Build the call operator.
8907 CXXMethodDecl *NewCallOperator
8908 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
8910 E->getCallOperator()->getLocEnd(),
8912 LSI->CallOperator = NewCallOperator;
8914 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8916 return getDerived().TransformLambdaScope(E, NewCallOperator,
8917 InitCaptureExprsAndTypes);
8920 template<typename Derived>
8922 TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8923 CXXMethodDecl *CallOperator,
8924 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
8925 bool Invalid = false;
8927 // Introduce the context of the call operator.
8928 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8929 /*NewThisContext*/false);
8931 LambdaScopeInfo *const LSI = getSema().getCurLambda();
8932 // Enter the scope of the lambda.
8933 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
8934 E->getCaptureDefault(),
8935 E->getCaptureDefaultLoc(),
8936 E->hasExplicitParameters(),
8937 E->hasExplicitResultType(),
8940 // Transform captures.
8941 bool FinishedExplicitCaptures = false;
8942 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8943 CEnd = E->capture_end();
8945 // When we hit the first implicit capture, tell Sema that we've finished
8946 // the list of explicit captures.
8947 if (!FinishedExplicitCaptures && C->isImplicit()) {
8948 getSema().finishLambdaExplicitCaptures(LSI);
8949 FinishedExplicitCaptures = true;
8952 // Capturing 'this' is trivial.
8953 if (C->capturesThis()) {
8954 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8958 // Rebuild init-captures, including the implied field declaration.
8959 if (C->isInitCapture()) {
8961 InitCaptureInfoTy InitExprTypePair =
8962 InitCaptureExprsAndTypes[C - E->capture_begin()];
8963 ExprResult Init = InitExprTypePair.first;
8964 QualType InitQualType = InitExprTypePair.second;
8965 if (Init.isInvalid() || InitQualType.isNull()) {
8969 VarDecl *OldVD = C->getCapturedVar();
8970 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8971 OldVD->getLocation(), InitExprTypePair.second,
8972 OldVD->getIdentifier(), Init.get());
8976 getDerived().transformedLocalDecl(OldVD, NewVD);
8978 getSema().buildInitCaptureField(LSI, NewVD);
8982 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8984 // Determine the capture kind for Sema.
8985 Sema::TryCaptureKind Kind
8986 = C->isImplicit()? Sema::TryCapture_Implicit
8987 : C->getCaptureKind() == LCK_ByCopy
8988 ? Sema::TryCapture_ExplicitByVal
8989 : Sema::TryCapture_ExplicitByRef;
8990 SourceLocation EllipsisLoc;
8991 if (C->isPackExpansion()) {
8992 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8993 bool ShouldExpand = false;
8994 bool RetainExpansion = false;
8995 Optional<unsigned> NumExpansions;
8996 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8999 ShouldExpand, RetainExpansion,
9006 // The transform has determined that we should perform an expansion;
9007 // transform and capture each of the arguments.
9008 // expansion of the pattern. Do so.
9009 VarDecl *Pack = C->getCapturedVar();
9010 for (unsigned I = 0; I != *NumExpansions; ++I) {
9011 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9012 VarDecl *CapturedVar
9013 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
9020 // Capture the transformed variable.
9021 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9024 // FIXME: Retain a pack expansion if RetainExpansion is true.
9029 EllipsisLoc = C->getEllipsisLoc();
9032 // Transform the captured variable.
9033 VarDecl *CapturedVar
9034 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
9035 C->getCapturedVar()));
9041 // Capture the transformed variable.
9042 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9044 if (!FinishedExplicitCaptures)
9045 getSema().finishLambdaExplicitCaptures(LSI);
9048 // Enter a new evaluation context to insulate the lambda from any
9049 // cleanups from the enclosing full-expression.
9050 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
9053 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
9054 /*IsInstantiation=*/true);
9058 // Instantiate the body of the lambda expression.
9059 StmtResult Body = getDerived().TransformStmt(E->getBody());
9060 if (Body.isInvalid()) {
9061 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
9062 /*IsInstantiation=*/true);
9066 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
9067 /*CurScope=*/nullptr,
9068 /*IsInstantiation=*/true);
9071 template<typename Derived>
9073 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
9074 CXXUnresolvedConstructExpr *E) {
9075 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9079 bool ArgumentChanged = false;
9080 SmallVector<Expr*, 8> Args;
9081 Args.reserve(E->arg_size());
9082 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
9086 if (!getDerived().AlwaysRebuild() &&
9087 T == E->getTypeSourceInfo() &&
9091 // FIXME: we're faking the locations of the commas
9092 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
9098 template<typename Derived>
9100 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
9101 CXXDependentScopeMemberExpr *E) {
9102 // Transform the base of the expression.
9103 ExprResult Base((Expr*) nullptr);
9106 QualType ObjectType;
9107 if (!E->isImplicitAccess()) {
9108 OldBase = E->getBase();
9109 Base = getDerived().TransformExpr(OldBase);
9110 if (Base.isInvalid())
9113 // Start the member reference and compute the object's type.
9114 ParsedType ObjectTy;
9115 bool MayBePseudoDestructor = false;
9116 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
9117 E->getOperatorLoc(),
9118 E->isArrow()? tok::arrow : tok::period,
9120 MayBePseudoDestructor);
9121 if (Base.isInvalid())
9124 ObjectType = ObjectTy.get();
9125 BaseType = ((Expr*) Base.get())->getType();
9128 BaseType = getDerived().TransformType(E->getBaseType());
9129 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9132 // Transform the first part of the nested-name-specifier that qualifies
9134 NamedDecl *FirstQualifierInScope
9135 = getDerived().TransformFirstQualifierInScope(
9136 E->getFirstQualifierFoundInScope(),
9137 E->getQualifierLoc().getBeginLoc());
9139 NestedNameSpecifierLoc QualifierLoc;
9140 if (E->getQualifier()) {
9142 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9144 FirstQualifierInScope);
9149 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9151 // TODO: If this is a conversion-function-id, verify that the
9152 // destination type name (if present) resolves the same way after
9153 // instantiation as it did in the local scope.
9155 DeclarationNameInfo NameInfo
9156 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
9157 if (!NameInfo.getName())
9160 if (!E->hasExplicitTemplateArgs()) {
9161 // This is a reference to a member without an explicitly-specified
9162 // template argument list. Optimize for this common case.
9163 if (!getDerived().AlwaysRebuild() &&
9164 Base.get() == OldBase &&
9165 BaseType == E->getBaseType() &&
9166 QualifierLoc == E->getQualifierLoc() &&
9167 NameInfo.getName() == E->getMember() &&
9168 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
9171 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
9174 E->getOperatorLoc(),
9177 FirstQualifierInScope,
9179 /*TemplateArgs*/nullptr);
9182 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
9183 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9184 E->getNumTemplateArgs(),
9188 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
9191 E->getOperatorLoc(),
9194 FirstQualifierInScope,
9199 template<typename Derived>
9201 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
9202 // Transform the base of the expression.
9203 ExprResult Base((Expr*) nullptr);
9205 if (!Old->isImplicitAccess()) {
9206 Base = getDerived().TransformExpr(Old->getBase());
9207 if (Base.isInvalid())
9209 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
9211 if (Base.isInvalid())
9213 BaseType = Base.get()->getType();
9215 BaseType = getDerived().TransformType(Old->getBaseType());
9218 NestedNameSpecifierLoc QualifierLoc;
9219 if (Old->getQualifierLoc()) {
9221 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9226 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9228 LookupResult R(SemaRef, Old->getMemberNameInfo(),
9229 Sema::LookupOrdinaryName);
9231 // Transform all the decls.
9232 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9233 E = Old->decls_end(); I != E; ++I) {
9234 NamedDecl *InstD = static_cast<NamedDecl*>(
9235 getDerived().TransformDecl(Old->getMemberLoc(),
9238 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9239 // This can happen because of dependent hiding.
9240 if (isa<UsingShadowDecl>(*I))
9248 // Expand using declarations.
9249 if (isa<UsingDecl>(InstD)) {
9250 UsingDecl *UD = cast<UsingDecl>(InstD);
9251 for (auto *I : UD->shadows())
9261 // Determine the naming class.
9262 if (Old->getNamingClass()) {
9263 CXXRecordDecl *NamingClass
9264 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9265 Old->getMemberLoc(),
9266 Old->getNamingClass()));
9270 R.setNamingClass(NamingClass);
9273 TemplateArgumentListInfo TransArgs;
9274 if (Old->hasExplicitTemplateArgs()) {
9275 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9276 TransArgs.setRAngleLoc(Old->getRAngleLoc());
9277 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9278 Old->getNumTemplateArgs(),
9283 // FIXME: to do this check properly, we will need to preserve the
9284 // first-qualifier-in-scope here, just in case we had a dependent
9285 // base (and therefore couldn't do the check) and a
9286 // nested-name-qualifier (and therefore could do the lookup).
9287 NamedDecl *FirstQualifierInScope = nullptr;
9289 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
9291 Old->getOperatorLoc(),
9295 FirstQualifierInScope,
9297 (Old->hasExplicitTemplateArgs()
9298 ? &TransArgs : nullptr));
9301 template<typename Derived>
9303 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
9304 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9305 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9306 if (SubExpr.isInvalid())
9309 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
9312 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9315 template<typename Derived>
9317 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
9318 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9319 if (Pattern.isInvalid())
9322 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
9325 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9326 E->getNumExpansions());
9329 template<typename Derived>
9331 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9332 // If E is not value-dependent, then nothing will change when we transform it.
9333 // Note: This is an instantiation-centric view.
9334 if (!E->isValueDependent())
9337 // Note: None of the implementations of TryExpandParameterPacks can ever
9338 // produce a diagnostic when given only a single unexpanded parameter pack,
9340 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9341 bool ShouldExpand = false;
9342 bool RetainExpansion = false;
9343 Optional<unsigned> NumExpansions;
9344 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
9346 ShouldExpand, RetainExpansion,
9350 if (RetainExpansion)
9353 NamedDecl *Pack = E->getPack();
9354 if (!ShouldExpand) {
9355 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
9362 // We now know the length of the parameter pack, so build a new expression
9363 // that stores that length.
9364 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9365 E->getPackLoc(), E->getRParenLoc(),
9369 template<typename Derived>
9371 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9372 SubstNonTypeTemplateParmPackExpr *E) {
9373 // Default behavior is to do nothing with this transformation.
9377 template<typename Derived>
9379 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9380 SubstNonTypeTemplateParmExpr *E) {
9381 // Default behavior is to do nothing with this transformation.
9385 template<typename Derived>
9387 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9388 // Default behavior is to do nothing with this transformation.
9392 template<typename Derived>
9394 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9395 MaterializeTemporaryExpr *E) {
9396 return getDerived().TransformExpr(E->GetTemporaryExpr());
9399 template<typename Derived>
9401 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9402 CXXStdInitializerListExpr *E) {
9403 return getDerived().TransformExpr(E->getSubExpr());
9406 template<typename Derived>
9408 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
9409 return SemaRef.MaybeBindToTemporary(E);
9412 template<typename Derived>
9414 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
9418 template<typename Derived>
9420 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9421 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9422 if (SubExpr.isInvalid())
9425 if (!getDerived().AlwaysRebuild() &&
9426 SubExpr.get() == E->getSubExpr())
9429 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
9432 template<typename Derived>
9434 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9435 // Transform each of the elements.
9436 SmallVector<Expr *, 8> Elements;
9437 bool ArgChanged = false;
9438 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
9439 /*IsCall=*/false, Elements, &ArgChanged))
9442 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9443 return SemaRef.MaybeBindToTemporary(E);
9445 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9450 template<typename Derived>
9452 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
9453 ObjCDictionaryLiteral *E) {
9454 // Transform each of the elements.
9455 SmallVector<ObjCDictionaryElement, 8> Elements;
9456 bool ArgChanged = false;
9457 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9458 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
9460 if (OrigElement.isPackExpansion()) {
9461 // This key/value element is a pack expansion.
9462 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9463 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9464 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9465 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9467 // Determine whether the set of unexpanded parameter packs can
9468 // and should be expanded.
9470 bool RetainExpansion = false;
9471 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9472 Optional<unsigned> NumExpansions = OrigNumExpansions;
9473 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9474 OrigElement.Value->getLocEnd());
9475 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9478 Expand, RetainExpansion,
9483 // The transform has determined that we should perform a simple
9484 // transformation on the pack expansion, producing another pack
9486 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9487 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9488 if (Key.isInvalid())
9491 if (Key.get() != OrigElement.Key)
9494 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9495 if (Value.isInvalid())
9498 if (Value.get() != OrigElement.Value)
9501 ObjCDictionaryElement Expansion = {
9502 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9504 Elements.push_back(Expansion);
9508 // Record right away that the argument was changed. This needs
9509 // to happen even if the array expands to nothing.
9512 // The transform has determined that we should perform an elementwise
9513 // expansion of the pattern. Do so.
9514 for (unsigned I = 0; I != *NumExpansions; ++I) {
9515 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9516 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9517 if (Key.isInvalid())
9520 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9521 if (Value.isInvalid())
9524 ObjCDictionaryElement Element = {
9525 Key.get(), Value.get(), SourceLocation(), NumExpansions
9528 // If any unexpanded parameter packs remain, we still have a
9530 // FIXME: Can this really happen?
9531 if (Key.get()->containsUnexpandedParameterPack() ||
9532 Value.get()->containsUnexpandedParameterPack())
9533 Element.EllipsisLoc = OrigElement.EllipsisLoc;
9535 Elements.push_back(Element);
9538 // FIXME: Retain a pack expansion if RetainExpansion is true.
9540 // We've finished with this pack expansion.
9544 // Transform and check key.
9545 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9546 if (Key.isInvalid())
9549 if (Key.get() != OrigElement.Key)
9552 // Transform and check value.
9554 = getDerived().TransformExpr(OrigElement.Value);
9555 if (Value.isInvalid())
9558 if (Value.get() != OrigElement.Value)
9561 ObjCDictionaryElement Element = {
9562 Key.get(), Value.get(), SourceLocation(), None
9564 Elements.push_back(Element);
9567 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9568 return SemaRef.MaybeBindToTemporary(E);
9570 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9575 template<typename Derived>
9577 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
9578 TypeSourceInfo *EncodedTypeInfo
9579 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9580 if (!EncodedTypeInfo)
9583 if (!getDerived().AlwaysRebuild() &&
9584 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
9587 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
9592 template<typename Derived>
9593 ExprResult TreeTransform<Derived>::
9594 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
9595 // This is a kind of implicit conversion, and it needs to get dropped
9596 // and recomputed for the same general reasons that ImplicitCastExprs
9597 // do, as well a more specific one: this expression is only valid when
9598 // it appears *immediately* as an argument expression.
9599 return getDerived().TransformExpr(E->getSubExpr());
9602 template<typename Derived>
9603 ExprResult TreeTransform<Derived>::
9604 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
9605 TypeSourceInfo *TSInfo
9606 = getDerived().TransformType(E->getTypeInfoAsWritten());
9610 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
9611 if (Result.isInvalid())
9614 if (!getDerived().AlwaysRebuild() &&
9615 TSInfo == E->getTypeInfoAsWritten() &&
9616 Result.get() == E->getSubExpr())
9619 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
9620 E->getBridgeKeywordLoc(), TSInfo,
9624 template<typename Derived>
9626 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
9627 // Transform arguments.
9628 bool ArgChanged = false;
9629 SmallVector<Expr*, 8> Args;
9630 Args.reserve(E->getNumArgs());
9631 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
9635 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9636 // Class message: transform the receiver type.
9637 TypeSourceInfo *ReceiverTypeInfo
9638 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9639 if (!ReceiverTypeInfo)
9642 // If nothing changed, just retain the existing message send.
9643 if (!getDerived().AlwaysRebuild() &&
9644 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
9645 return SemaRef.MaybeBindToTemporary(E);
9647 // Build a new class message send.
9648 SmallVector<SourceLocation, 16> SelLocs;
9649 E->getSelectorLocs(SelLocs);
9650 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9659 // Instance message: transform the receiver
9660 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9661 "Only class and instance messages may be instantiated");
9663 = getDerived().TransformExpr(E->getInstanceReceiver());
9664 if (Receiver.isInvalid())
9667 // If nothing changed, just retain the existing message send.
9668 if (!getDerived().AlwaysRebuild() &&
9669 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
9670 return SemaRef.MaybeBindToTemporary(E);
9672 // Build a new instance message send.
9673 SmallVector<SourceLocation, 16> SelLocs;
9674 E->getSelectorLocs(SelLocs);
9675 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
9684 template<typename Derived>
9686 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
9690 template<typename Derived>
9692 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
9696 template<typename Derived>
9698 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
9699 // Transform the base expression.
9700 ExprResult Base = getDerived().TransformExpr(E->getBase());
9701 if (Base.isInvalid())
9704 // We don't need to transform the ivar; it will never change.
9706 // If nothing changed, just retain the existing expression.
9707 if (!getDerived().AlwaysRebuild() &&
9708 Base.get() == E->getBase())
9711 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
9713 E->isArrow(), E->isFreeIvar());
9716 template<typename Derived>
9718 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
9719 // 'super' and types never change. Property never changes. Just
9720 // retain the existing expression.
9721 if (!E->isObjectReceiver())
9724 // Transform the base expression.
9725 ExprResult Base = getDerived().TransformExpr(E->getBase());
9726 if (Base.isInvalid())
9729 // We don't need to transform the property; it will never change.
9731 // If nothing changed, just retain the existing expression.
9732 if (!getDerived().AlwaysRebuild() &&
9733 Base.get() == E->getBase())
9736 if (E->isExplicitProperty())
9737 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9738 E->getExplicitProperty(),
9741 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9742 SemaRef.Context.PseudoObjectTy,
9743 E->getImplicitPropertyGetter(),
9744 E->getImplicitPropertySetter(),
9748 template<typename Derived>
9750 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9751 // Transform the base expression.
9752 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9753 if (Base.isInvalid())
9756 // Transform the key expression.
9757 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9758 if (Key.isInvalid())
9761 // If nothing changed, just retain the existing expression.
9762 if (!getDerived().AlwaysRebuild() &&
9763 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9766 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
9767 Base.get(), Key.get(),
9768 E->getAtIndexMethodDecl(),
9769 E->setAtIndexMethodDecl());
9772 template<typename Derived>
9774 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
9775 // Transform the base expression.
9776 ExprResult Base = getDerived().TransformExpr(E->getBase());
9777 if (Base.isInvalid())
9780 // If nothing changed, just retain the existing expression.
9781 if (!getDerived().AlwaysRebuild() &&
9782 Base.get() == E->getBase())
9785 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
9790 template<typename Derived>
9792 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
9793 bool ArgumentChanged = false;
9794 SmallVector<Expr*, 8> SubExprs;
9795 SubExprs.reserve(E->getNumSubExprs());
9796 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9797 SubExprs, &ArgumentChanged))
9800 if (!getDerived().AlwaysRebuild() &&
9804 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
9809 template<typename Derived>
9811 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9812 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9813 if (SrcExpr.isInvalid())
9816 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9820 if (!getDerived().AlwaysRebuild() &&
9821 Type == E->getTypeSourceInfo() &&
9822 SrcExpr.get() == E->getSrcExpr())
9825 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9826 SrcExpr.get(), Type,
9830 template<typename Derived>
9832 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
9833 BlockDecl *oldBlock = E->getBlockDecl();
9835 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
9836 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9838 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
9839 blockScope->TheDecl->setBlockMissingReturnType(
9840 oldBlock->blockMissingReturnType());
9842 SmallVector<ParmVarDecl*, 4> params;
9843 SmallVector<QualType, 4> paramTypes;
9845 // Parameter substitution.
9846 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9847 oldBlock->param_begin(),
9848 oldBlock->param_size(),
9849 nullptr, paramTypes, ¶ms)) {
9850 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
9854 const FunctionProtoType *exprFunctionType = E->getFunctionType();
9855 QualType exprResultType =
9856 getDerived().TransformType(exprFunctionType->getReturnType());
9858 QualType functionType =
9859 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
9860 exprFunctionType->getExtProtoInfo());
9861 blockScope->FunctionType = functionType;
9863 // Set the parameters on the block decl.
9864 if (!params.empty())
9865 blockScope->TheDecl->setParams(params);
9867 if (!oldBlock->blockMissingReturnType()) {
9868 blockScope->HasImplicitReturnType = false;
9869 blockScope->ReturnType = exprResultType;
9872 // Transform the body
9873 StmtResult body = getDerived().TransformStmt(E->getBody());
9874 if (body.isInvalid()) {
9875 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
9880 // In builds with assertions, make sure that we captured everything we
9882 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9883 for (const auto &I : oldBlock->captures()) {
9884 VarDecl *oldCapture = I.getVariable();
9886 // Ignore parameter packs.
9887 if (isa<ParmVarDecl>(oldCapture) &&
9888 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9891 VarDecl *newCapture =
9892 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9894 assert(blockScope->CaptureMap.count(newCapture));
9896 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
9900 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9904 template<typename Derived>
9906 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
9907 llvm_unreachable("Cannot transform asType expressions yet");
9910 template<typename Derived>
9912 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
9913 QualType RetTy = getDerived().TransformType(E->getType());
9914 bool ArgumentChanged = false;
9915 SmallVector<Expr*, 8> SubExprs;
9916 SubExprs.reserve(E->getNumSubExprs());
9917 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9918 SubExprs, &ArgumentChanged))
9921 if (!getDerived().AlwaysRebuild() &&
9925 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
9926 RetTy, E->getOp(), E->getRParenLoc());
9929 //===----------------------------------------------------------------------===//
9930 // Type reconstruction
9931 //===----------------------------------------------------------------------===//
9933 template<typename Derived>
9934 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9935 SourceLocation Star) {
9936 return SemaRef.BuildPointerType(PointeeType, Star,
9937 getDerived().getBaseEntity());
9940 template<typename Derived>
9941 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9942 SourceLocation Star) {
9943 return SemaRef.BuildBlockPointerType(PointeeType, Star,
9944 getDerived().getBaseEntity());
9947 template<typename Derived>
9949 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9950 bool WrittenAsLValue,
9951 SourceLocation Sigil) {
9952 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
9953 Sigil, getDerived().getBaseEntity());
9956 template<typename Derived>
9958 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9960 SourceLocation Sigil) {
9961 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9962 getDerived().getBaseEntity());
9965 template<typename Derived>
9967 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9968 ArrayType::ArraySizeModifier SizeMod,
9969 const llvm::APInt *Size,
9971 unsigned IndexTypeQuals,
9972 SourceRange BracketsRange) {
9973 if (SizeExpr || !Size)
9974 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9975 IndexTypeQuals, BracketsRange,
9976 getDerived().getBaseEntity());
9978 QualType Types[] = {
9979 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9980 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9981 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
9983 const unsigned NumTypes = llvm::array_lengthof(Types);
9985 for (unsigned I = 0; I != NumTypes; ++I)
9986 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9987 SizeType = Types[I];
9991 // Note that we can return a VariableArrayType here in the case where
9992 // the element type was a dependent VariableArrayType.
9993 IntegerLiteral *ArraySize
9994 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9995 /*FIXME*/BracketsRange.getBegin());
9996 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
9997 IndexTypeQuals, BracketsRange,
9998 getDerived().getBaseEntity());
10001 template<typename Derived>
10003 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
10004 ArrayType::ArraySizeModifier SizeMod,
10005 const llvm::APInt &Size,
10006 unsigned IndexTypeQuals,
10007 SourceRange BracketsRange) {
10008 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
10009 IndexTypeQuals, BracketsRange);
10012 template<typename Derived>
10014 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
10015 ArrayType::ArraySizeModifier SizeMod,
10016 unsigned IndexTypeQuals,
10017 SourceRange BracketsRange) {
10018 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
10019 IndexTypeQuals, BracketsRange);
10022 template<typename Derived>
10024 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
10025 ArrayType::ArraySizeModifier SizeMod,
10027 unsigned IndexTypeQuals,
10028 SourceRange BracketsRange) {
10029 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
10031 IndexTypeQuals, BracketsRange);
10034 template<typename Derived>
10036 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
10037 ArrayType::ArraySizeModifier SizeMod,
10039 unsigned IndexTypeQuals,
10040 SourceRange BracketsRange) {
10041 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
10043 IndexTypeQuals, BracketsRange);
10046 template<typename Derived>
10047 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
10048 unsigned NumElements,
10049 VectorType::VectorKind VecKind) {
10050 // FIXME: semantic checking!
10051 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
10054 template<typename Derived>
10055 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10056 unsigned NumElements,
10057 SourceLocation AttributeLoc) {
10058 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10059 NumElements, true);
10060 IntegerLiteral *VectorSize
10061 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10063 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
10066 template<typename Derived>
10068 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
10070 SourceLocation AttributeLoc) {
10071 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
10074 template<typename Derived>
10075 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10077 MutableArrayRef<QualType> ParamTypes,
10078 const FunctionProtoType::ExtProtoInfo &EPI) {
10079 return SemaRef.BuildFunctionType(T, ParamTypes,
10080 getDerived().getBaseLocation(),
10081 getDerived().getBaseEntity(),
10085 template<typename Derived>
10086 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10087 return SemaRef.Context.getFunctionNoProtoType(T);
10090 template<typename Derived>
10091 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10092 assert(D && "no decl found");
10093 if (D->isInvalidDecl()) return QualType();
10095 // FIXME: Doesn't account for ObjCInterfaceDecl!
10097 if (isa<UsingDecl>(D)) {
10098 UsingDecl *Using = cast<UsingDecl>(D);
10099 assert(Using->hasTypename() &&
10100 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10102 // A valid resolved using typename decl points to exactly one type decl.
10103 assert(++Using->shadow_begin() == Using->shadow_end());
10104 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
10107 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10108 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10109 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10112 return SemaRef.Context.getTypeDeclType(Ty);
10115 template<typename Derived>
10116 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10117 SourceLocation Loc) {
10118 return SemaRef.BuildTypeofExprType(E, Loc);
10121 template<typename Derived>
10122 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10123 return SemaRef.Context.getTypeOfType(Underlying);
10126 template<typename Derived>
10127 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10128 SourceLocation Loc) {
10129 return SemaRef.BuildDecltypeType(E, Loc);
10132 template<typename Derived>
10133 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10134 UnaryTransformType::UTTKind UKind,
10135 SourceLocation Loc) {
10136 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10139 template<typename Derived>
10140 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
10141 TemplateName Template,
10142 SourceLocation TemplateNameLoc,
10143 TemplateArgumentListInfo &TemplateArgs) {
10144 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
10147 template<typename Derived>
10148 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10149 SourceLocation KWLoc) {
10150 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10153 template<typename Derived>
10155 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10157 TemplateDecl *Template) {
10158 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
10162 template<typename Derived>
10164 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10165 const IdentifierInfo &Name,
10166 SourceLocation NameLoc,
10167 QualType ObjectType,
10168 NamedDecl *FirstQualifierInScope) {
10169 UnqualifiedId TemplateName;
10170 TemplateName.setIdentifier(&Name, NameLoc);
10171 Sema::TemplateTy Template;
10172 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
10173 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
10174 SS, TemplateKWLoc, TemplateName,
10175 ParsedType::make(ObjectType),
10176 /*EnteringContext=*/false,
10178 return Template.get();
10181 template<typename Derived>
10183 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10184 OverloadedOperatorKind Operator,
10185 SourceLocation NameLoc,
10186 QualType ObjectType) {
10187 UnqualifiedId Name;
10188 // FIXME: Bogus location information.
10189 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
10190 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
10191 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
10192 Sema::TemplateTy Template;
10193 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
10194 SS, TemplateKWLoc, Name,
10195 ParsedType::make(ObjectType),
10196 /*EnteringContext=*/false,
10198 return Template.get();
10201 template<typename Derived>
10203 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10204 SourceLocation OpLoc,
10208 Expr *Callee = OrigCallee->IgnoreParenCasts();
10209 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
10211 if (First->getObjectKind() == OK_ObjCProperty) {
10212 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10213 if (BinaryOperator::isAssignmentOp(Opc))
10214 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10216 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10217 if (Result.isInvalid())
10218 return ExprError();
10219 First = Result.get();
10222 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10223 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10224 if (Result.isInvalid())
10225 return ExprError();
10226 Second = Result.get();
10229 // Determine whether this should be a builtin operation.
10230 if (Op == OO_Subscript) {
10231 if (!First->getType()->isOverloadableType() &&
10232 !Second->getType()->isOverloadableType())
10233 return getSema().CreateBuiltinArraySubscriptExpr(First,
10234 Callee->getLocStart(),
10236 } else if (Op == OO_Arrow) {
10237 // -> is never a builtin operation.
10238 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10239 } else if (Second == nullptr || isPostIncDec) {
10240 if (!First->getType()->isOverloadableType()) {
10241 // The argument is not of overloadable type, so try to create a
10242 // built-in unary operation.
10243 UnaryOperatorKind Opc
10244 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
10246 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
10249 if (!First->getType()->isOverloadableType() &&
10250 !Second->getType()->isOverloadableType()) {
10251 // Neither of the arguments is an overloadable type, so try to
10252 // create a built-in binary operation.
10253 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10255 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
10256 if (Result.isInvalid())
10257 return ExprError();
10263 // Compute the transformed set of functions (and function templates) to be
10264 // used during overload resolution.
10265 UnresolvedSet<16> Functions;
10267 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
10268 assert(ULE->requiresADL());
10269 Functions.append(ULE->decls_begin(), ULE->decls_end());
10271 // If we've resolved this to a particular non-member function, just call
10272 // that function. If we resolved it to a member function,
10273 // CreateOverloaded* will find that function for us.
10274 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10275 if (!isa<CXXMethodDecl>(ND))
10276 Functions.addDecl(ND);
10279 // Add any functions found via argument-dependent lookup.
10280 Expr *Args[2] = { First, Second };
10281 unsigned NumArgs = 1 + (Second != nullptr);
10283 // Create the overloaded operator invocation for unary operators.
10284 if (NumArgs == 1 || isPostIncDec) {
10285 UnaryOperatorKind Opc
10286 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
10287 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
10290 if (Op == OO_Subscript) {
10291 SourceLocation LBrace;
10292 SourceLocation RBrace;
10294 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10295 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10296 LBrace = SourceLocation::getFromRawEncoding(
10297 NameLoc.CXXOperatorName.BeginOpNameLoc);
10298 RBrace = SourceLocation::getFromRawEncoding(
10299 NameLoc.CXXOperatorName.EndOpNameLoc);
10301 LBrace = Callee->getLocStart();
10305 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10309 // Create the overloaded operator invocation for binary operators.
10310 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10312 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10313 if (Result.isInvalid())
10314 return ExprError();
10319 template<typename Derived>
10321 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
10322 SourceLocation OperatorLoc,
10325 TypeSourceInfo *ScopeType,
10326 SourceLocation CCLoc,
10327 SourceLocation TildeLoc,
10328 PseudoDestructorTypeStorage Destroyed) {
10329 QualType BaseType = Base->getType();
10330 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
10331 (!isArrow && !BaseType->getAs<RecordType>()) ||
10332 (isArrow && BaseType->getAs<PointerType>() &&
10333 !BaseType->getAs<PointerType>()->getPointeeType()
10334 ->template getAs<RecordType>())){
10335 // This pseudo-destructor expression is still a pseudo-destructor.
10336 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
10337 isArrow? tok::arrow : tok::period,
10338 SS, ScopeType, CCLoc, TildeLoc,
10343 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
10344 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10345 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10346 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10347 NameInfo.setNamedTypeInfo(DestroyedType);
10349 // The scope type is now known to be a valid nested name specifier
10350 // component. Tack it on to the end of the nested name specifier.
10352 SS.Extend(SemaRef.Context, SourceLocation(),
10353 ScopeType->getTypeLoc(), CCLoc);
10355 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
10356 return getSema().BuildMemberReferenceExpr(Base, BaseType,
10357 OperatorLoc, isArrow,
10359 /*FIXME: FirstQualifier*/ nullptr,
10361 /*TemplateArgs*/ nullptr);
10364 template<typename Derived>
10366 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
10367 SourceLocation Loc = S->getLocStart();
10368 CapturedDecl *CD = S->getCapturedDecl();
10369 unsigned NumParams = CD->getNumParams();
10370 unsigned ContextParamPos = CD->getContextParamPosition();
10371 SmallVector<Sema::CapturedParamNameType, 4> Params;
10372 for (unsigned I = 0; I < NumParams; ++I) {
10373 if (I != ContextParamPos) {
10376 CD->getParam(I)->getName(),
10377 getDerived().TransformType(CD->getParam(I)->getType())));
10379 Params.push_back(std::make_pair(StringRef(), QualType()));
10382 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
10383 S->getCapturedRegionKind(), Params);
10386 Sema::CompoundScopeRAII CompoundScope(getSema());
10387 Body = getDerived().TransformStmt(S->getCapturedStmt());
10390 if (Body.isInvalid()) {
10391 getSema().ActOnCapturedRegionError();
10392 return StmtError();
10395 return getSema().ActOnCapturedRegionEnd(Body.get());
10398 } // end namespace clang
10400 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H