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,
563 QualType TransformDependentTemplateSpecializationType(
564 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
565 NestedNameSpecifierLoc QualifierLoc);
567 /// \brief Transforms the parameters of a function type into the
570 /// The result vectors should be kept in sync; null entries in the
571 /// variables vector are acceptable.
573 /// Return true on error.
574 bool TransformFunctionTypeParams(SourceLocation Loc,
575 ParmVarDecl **Params, unsigned NumParams,
576 const QualType *ParamTypes,
577 SmallVectorImpl<QualType> &PTypes,
578 SmallVectorImpl<ParmVarDecl*> *PVars);
580 /// \brief Transforms a single function-type parameter. Return null
583 /// \param indexAdjustment - A number to add to the parameter's
584 /// scope index; can be negative
585 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
587 Optional<unsigned> NumExpansions,
588 bool ExpectParameterPack);
590 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
592 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
593 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
595 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
596 /// \brief Transform the captures and body of a lambda expression.
597 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
598 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
600 TemplateParameterList *TransformTemplateParameterList(
601 TemplateParameterList *TPL) {
605 ExprResult TransformAddressOfOperand(Expr *E);
607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
608 bool IsAddressOfOperand,
609 TypeSourceInfo **RecoveryTSI);
611 ExprResult TransformParenDependentScopeDeclRefExpr(
612 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
613 TypeSourceInfo **RecoveryTSI);
615 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
617 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
618 // amount of stack usage with clang.
619 #define STMT(Node, Parent) \
620 LLVM_ATTRIBUTE_NOINLINE \
621 StmtResult Transform##Node(Node *S);
622 #define EXPR(Node, Parent) \
623 LLVM_ATTRIBUTE_NOINLINE \
624 ExprResult Transform##Node(Node *E);
625 #define ABSTRACT_STMT(Stmt)
626 #include "clang/AST/StmtNodes.inc"
628 #define OPENMP_CLAUSE(Name, Class) \
629 LLVM_ATTRIBUTE_NOINLINE \
630 OMPClause *Transform ## Class(Class *S);
631 #include "clang/Basic/OpenMPKinds.def"
633 /// \brief Build a new pointer type given its pointee type.
635 /// By default, performs semantic analysis when building the pointer type.
636 /// Subclasses may override this routine to provide different behavior.
637 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
639 /// \brief Build a new block pointer type given its pointee type.
641 /// By default, performs semantic analysis when building the block pointer
642 /// type. Subclasses may override this routine to provide different behavior.
643 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
645 /// \brief Build a new reference type given the type it references.
647 /// By default, performs semantic analysis when building the
648 /// reference type. Subclasses may override this routine to provide
649 /// different behavior.
651 /// \param LValue whether the type was written with an lvalue sigil
652 /// or an rvalue sigil.
653 QualType RebuildReferenceType(QualType ReferentType,
655 SourceLocation Sigil);
657 /// \brief Build a new member pointer type given the pointee type and the
658 /// class type it refers into.
660 /// By default, performs semantic analysis when building the member pointer
661 /// type. Subclasses may override this routine to provide different behavior.
662 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
663 SourceLocation Sigil);
665 /// \brief Build a new array type given the element type, size
666 /// modifier, size of the array (if known), size expression, and index type
669 /// By default, performs semantic analysis when building the array type.
670 /// Subclasses may override this routine to provide different behavior.
671 /// Also by default, all of the other Rebuild*Array
672 QualType RebuildArrayType(QualType ElementType,
673 ArrayType::ArraySizeModifier SizeMod,
674 const llvm::APInt *Size,
676 unsigned IndexTypeQuals,
677 SourceRange BracketsRange);
679 /// \brief Build a new constant array type given the element type, size
680 /// modifier, (known) size of the array, and index type qualifiers.
682 /// By default, performs semantic analysis when building the array type.
683 /// Subclasses may override this routine to provide different behavior.
684 QualType RebuildConstantArrayType(QualType ElementType,
685 ArrayType::ArraySizeModifier SizeMod,
686 const llvm::APInt &Size,
687 unsigned IndexTypeQuals,
688 SourceRange BracketsRange);
690 /// \brief Build a new incomplete array type given the element type, size
691 /// modifier, and index type qualifiers.
693 /// By default, performs semantic analysis when building the array type.
694 /// Subclasses may override this routine to provide different behavior.
695 QualType RebuildIncompleteArrayType(QualType ElementType,
696 ArrayType::ArraySizeModifier SizeMod,
697 unsigned IndexTypeQuals,
698 SourceRange BracketsRange);
700 /// \brief Build a new variable-length array type given the element type,
701 /// size modifier, size expression, and index type qualifiers.
703 /// By default, performs semantic analysis when building the array type.
704 /// Subclasses may override this routine to provide different behavior.
705 QualType RebuildVariableArrayType(QualType ElementType,
706 ArrayType::ArraySizeModifier SizeMod,
708 unsigned IndexTypeQuals,
709 SourceRange BracketsRange);
711 /// \brief Build a new dependent-sized array type given the element type,
712 /// size modifier, size expression, and index type qualifiers.
714 /// By default, performs semantic analysis when building the array type.
715 /// Subclasses may override this routine to provide different behavior.
716 QualType RebuildDependentSizedArrayType(QualType ElementType,
717 ArrayType::ArraySizeModifier SizeMod,
719 unsigned IndexTypeQuals,
720 SourceRange BracketsRange);
722 /// \brief Build a new vector type given the element type and
723 /// number of elements.
725 /// By default, performs semantic analysis when building the vector type.
726 /// Subclasses may override this routine to provide different behavior.
727 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
728 VectorType::VectorKind VecKind);
730 /// \brief Build a new extended vector type given the element type and
731 /// number of elements.
733 /// By default, performs semantic analysis when building the vector type.
734 /// Subclasses may override this routine to provide different behavior.
735 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
736 SourceLocation AttributeLoc);
738 /// \brief Build a new potentially dependently-sized extended vector type
739 /// given the element type and number of elements.
741 /// By default, performs semantic analysis when building the vector type.
742 /// Subclasses may override this routine to provide different behavior.
743 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
745 SourceLocation AttributeLoc);
747 /// \brief Build a new function type.
749 /// By default, performs semantic analysis when building the function type.
750 /// Subclasses may override this routine to provide different behavior.
751 QualType RebuildFunctionProtoType(QualType T,
752 MutableArrayRef<QualType> ParamTypes,
753 const FunctionProtoType::ExtProtoInfo &EPI);
755 /// \brief Build a new unprototyped function type.
756 QualType RebuildFunctionNoProtoType(QualType ResultType);
758 /// \brief Rebuild an unresolved typename type, given the decl that
759 /// the UnresolvedUsingTypenameDecl was transformed to.
760 QualType RebuildUnresolvedUsingType(Decl *D);
762 /// \brief Build a new typedef type.
763 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
764 return SemaRef.Context.getTypeDeclType(Typedef);
767 /// \brief Build a new class/struct/union type.
768 QualType RebuildRecordType(RecordDecl *Record) {
769 return SemaRef.Context.getTypeDeclType(Record);
772 /// \brief Build a new Enum type.
773 QualType RebuildEnumType(EnumDecl *Enum) {
774 return SemaRef.Context.getTypeDeclType(Enum);
777 /// \brief Build a new typeof(expr) type.
779 /// By default, performs semantic analysis when building the typeof type.
780 /// Subclasses may override this routine to provide different behavior.
781 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
783 /// \brief Build a new typeof(type) type.
785 /// By default, builds a new TypeOfType with the given underlying type.
786 QualType RebuildTypeOfType(QualType Underlying);
788 /// \brief Build a new unary transform type.
789 QualType RebuildUnaryTransformType(QualType BaseType,
790 UnaryTransformType::UTTKind UKind,
793 /// \brief Build a new C++11 decltype type.
795 /// By default, performs semantic analysis when building the decltype type.
796 /// Subclasses may override this routine to provide different behavior.
797 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
799 /// \brief Build a new C++11 auto type.
801 /// By default, builds a new AutoType with the given deduced type.
802 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
803 // Note, IsDependent is always false here: we implicitly convert an 'auto'
804 // which has been deduced to a dependent type into an undeduced 'auto', so
805 // that we'll retry deduction after the transformation.
806 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
807 /*IsDependent*/ false);
810 /// \brief Build a new template specialization type.
812 /// By default, performs semantic analysis when building the template
813 /// specialization type. Subclasses may override this routine to provide
814 /// different behavior.
815 QualType RebuildTemplateSpecializationType(TemplateName Template,
816 SourceLocation TemplateLoc,
817 TemplateArgumentListInfo &Args);
819 /// \brief Build a new parenthesized type.
821 /// By default, builds a new ParenType type from the inner type.
822 /// Subclasses may override this routine to provide different behavior.
823 QualType RebuildParenType(QualType InnerType) {
824 return SemaRef.Context.getParenType(InnerType);
827 /// \brief Build a new qualified name type.
829 /// By default, builds a new ElaboratedType type from the keyword,
830 /// the nested-name-specifier and the named type.
831 /// Subclasses may override this routine to provide different behavior.
832 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
833 ElaboratedTypeKeyword Keyword,
834 NestedNameSpecifierLoc QualifierLoc,
836 return SemaRef.Context.getElaboratedType(Keyword,
837 QualifierLoc.getNestedNameSpecifier(),
841 /// \brief Build a new typename type that refers to a template-id.
843 /// By default, builds a new DependentNameType type from the
844 /// nested-name-specifier and the given type. Subclasses may override
845 /// this routine to provide different behavior.
846 QualType RebuildDependentTemplateSpecializationType(
847 ElaboratedTypeKeyword Keyword,
848 NestedNameSpecifierLoc QualifierLoc,
849 const IdentifierInfo *Name,
850 SourceLocation NameLoc,
851 TemplateArgumentListInfo &Args) {
852 // Rebuild the template name.
853 // TODO: avoid TemplateName abstraction
855 SS.Adopt(QualifierLoc);
856 TemplateName InstName
857 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
860 if (InstName.isNull())
863 // If it's still dependent, make a dependent specialization.
864 if (InstName.getAsDependentTemplateName())
865 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
866 QualifierLoc.getNestedNameSpecifier(),
870 // Otherwise, make an elaborated type wrapping a non-dependent
873 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
874 if (T.isNull()) return QualType();
876 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
879 return SemaRef.Context.getElaboratedType(Keyword,
880 QualifierLoc.getNestedNameSpecifier(),
884 /// \brief Build a new typename type that refers to an identifier.
886 /// By default, performs semantic analysis when building the typename type
887 /// (or elaborated type). Subclasses may override this routine to provide
888 /// different behavior.
889 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
890 SourceLocation KeywordLoc,
891 NestedNameSpecifierLoc QualifierLoc,
892 const IdentifierInfo *Id,
893 SourceLocation IdLoc) {
895 SS.Adopt(QualifierLoc);
897 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
898 // If the name is still dependent, just build a new dependent name type.
899 if (!SemaRef.computeDeclContext(SS))
900 return SemaRef.Context.getDependentNameType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
905 if (Keyword == ETK_None || Keyword == ETK_Typename)
906 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
909 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
911 // We had a dependent elaborated-type-specifier that has been transformed
912 // into a non-dependent elaborated-type-specifier. Find the tag we're
914 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
915 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
919 if (SemaRef.RequireCompleteDeclContext(SS, DC))
922 TagDecl *Tag = nullptr;
923 SemaRef.LookupQualifiedName(Result, DC);
924 switch (Result.getResultKind()) {
925 case LookupResult::NotFound:
926 case LookupResult::NotFoundInCurrentInstantiation:
929 case LookupResult::Found:
930 Tag = Result.getAsSingle<TagDecl>();
933 case LookupResult::FoundOverloaded:
934 case LookupResult::FoundUnresolvedValue:
935 llvm_unreachable("Tag lookup cannot find non-tags");
937 case LookupResult::Ambiguous:
938 // Let the LookupResult structure handle ambiguities.
943 // Check where the name exists but isn't a tag type and use that to emit
944 // better diagnostics.
945 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
946 SemaRef.LookupQualifiedName(Result, DC);
947 switch (Result.getResultKind()) {
948 case LookupResult::Found:
949 case LookupResult::FoundOverloaded:
950 case LookupResult::FoundUnresolvedValue: {
951 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
953 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
954 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
955 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
956 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
957 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
961 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
962 << Kind << Id << DC << QualifierLoc.getSourceRange();
968 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
970 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
971 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
975 // Build the elaborated-type-specifier type.
976 QualType T = SemaRef.Context.getTypeDeclType(Tag);
977 return SemaRef.Context.getElaboratedType(Keyword,
978 QualifierLoc.getNestedNameSpecifier(),
982 /// \brief Build a new pack expansion type.
984 /// By default, builds a new PackExpansionType type from the given pattern.
985 /// Subclasses may override this routine to provide different behavior.
986 QualType RebuildPackExpansionType(QualType Pattern,
987 SourceRange PatternRange,
988 SourceLocation EllipsisLoc,
989 Optional<unsigned> NumExpansions) {
990 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
994 /// \brief Build a new atomic type given its value type.
996 /// By default, performs semantic analysis when building the atomic type.
997 /// Subclasses may override this routine to provide different behavior.
998 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1000 /// \brief Build a new template name given a nested name specifier, a flag
1001 /// indicating whether the "template" keyword was provided, and the template
1002 /// that the template name refers to.
1004 /// By default, builds the new template name directly. Subclasses may override
1005 /// this routine to provide different behavior.
1006 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1008 TemplateDecl *Template);
1010 /// \brief Build a new template name given a nested name specifier and the
1011 /// name that is referred to as a template.
1013 /// By default, performs semantic analysis to determine whether the name can
1014 /// be resolved to a specific template, then builds the appropriate kind of
1015 /// template name. Subclasses may override this routine to provide different
1017 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1018 const IdentifierInfo &Name,
1019 SourceLocation NameLoc,
1020 QualType ObjectType,
1021 NamedDecl *FirstQualifierInScope);
1023 /// \brief Build a new template name given a nested name specifier and the
1024 /// overloaded operator name that is referred to as a template.
1026 /// By default, performs semantic analysis to determine whether the name can
1027 /// be resolved to a specific template, then builds the appropriate kind of
1028 /// template name. Subclasses may override this routine to provide different
1030 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1031 OverloadedOperatorKind Operator,
1032 SourceLocation NameLoc,
1033 QualType ObjectType);
1035 /// \brief Build a new template name given a template template parameter pack
1038 /// By default, performs semantic analysis to determine whether the name can
1039 /// be resolved to a specific template, then builds the appropriate kind of
1040 /// template name. Subclasses may override this routine to provide different
1042 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1043 const TemplateArgument &ArgPack) {
1044 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1047 /// \brief Build a new compound statement.
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
1051 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1052 MultiStmtArg Statements,
1053 SourceLocation RBraceLoc,
1055 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1059 /// \brief Build a new case statement.
1061 /// By default, performs semantic analysis to build the new statement.
1062 /// Subclasses may override this routine to provide different behavior.
1063 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1065 SourceLocation EllipsisLoc,
1067 SourceLocation ColonLoc) {
1068 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1072 /// \brief Attach the body to a new case statement.
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
1076 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1077 getSema().ActOnCaseStmtBody(S, Body);
1081 /// \brief Build a new default statement.
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
1085 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1086 SourceLocation ColonLoc,
1088 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1089 /*CurScope=*/nullptr);
1092 /// \brief Build a new label statement.
1094 /// By default, performs semantic analysis to build the new statement.
1095 /// Subclasses may override this routine to provide different behavior.
1096 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1097 SourceLocation ColonLoc, Stmt *SubStmt) {
1098 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1101 /// \brief Build a new label statement.
1103 /// By default, performs semantic analysis to build the new statement.
1104 /// Subclasses may override this routine to provide different behavior.
1105 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1106 ArrayRef<const Attr*> Attrs,
1108 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1111 /// \brief Build a new "if" statement.
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
1115 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
1116 VarDecl *CondVar, Stmt *Then,
1117 SourceLocation ElseLoc, Stmt *Else) {
1118 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
1121 /// \brief Start building a new switch statement.
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
1125 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
1126 Expr *Cond, VarDecl *CondVar) {
1127 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1131 /// \brief Attach the body to the switch statement.
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
1135 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1136 Stmt *Switch, Stmt *Body) {
1137 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1140 /// \brief Build a new while statement.
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
1144 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1145 VarDecl *CondVar, Stmt *Body) {
1146 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
1149 /// \brief Build a new do-while statement.
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
1153 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1154 SourceLocation WhileLoc, SourceLocation LParenLoc,
1155 Expr *Cond, SourceLocation RParenLoc) {
1156 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1160 /// \brief Build a new for statement.
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
1164 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1165 Stmt *Init, Sema::FullExprArg Cond,
1166 VarDecl *CondVar, Sema::FullExprArg Inc,
1167 SourceLocation RParenLoc, Stmt *Body) {
1168 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1169 CondVar, Inc, RParenLoc, Body);
1172 /// \brief Build a new goto statement.
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
1176 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1178 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1181 /// \brief Build a new indirect goto statement.
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
1185 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1186 SourceLocation StarLoc,
1188 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1191 /// \brief Build a new return statement.
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
1195 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1196 return getSema().BuildReturnStmt(ReturnLoc, Result);
1199 /// \brief Build a new declaration statement.
1201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
1203 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
1204 SourceLocation StartLoc, SourceLocation EndLoc) {
1205 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1206 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1209 /// \brief Build a new inline asm statement.
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
1213 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1214 bool IsVolatile, unsigned NumOutputs,
1215 unsigned NumInputs, IdentifierInfo **Names,
1216 MultiExprArg Constraints, MultiExprArg Exprs,
1217 Expr *AsmString, MultiExprArg Clobbers,
1218 SourceLocation RParenLoc) {
1219 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1220 NumInputs, Names, Constraints, Exprs,
1221 AsmString, Clobbers, RParenLoc);
1224 /// \brief Build a new MS style inline asm statement.
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
1228 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1229 ArrayRef<Token> AsmToks,
1230 StringRef AsmString,
1231 unsigned NumOutputs, unsigned NumInputs,
1232 ArrayRef<StringRef> Constraints,
1233 ArrayRef<StringRef> Clobbers,
1234 ArrayRef<Expr*> Exprs,
1235 SourceLocation EndLoc) {
1236 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1237 NumOutputs, NumInputs,
1238 Constraints, Clobbers, Exprs, EndLoc);
1241 /// \brief Build a new Objective-C \@try statement.
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
1245 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1247 MultiStmtArg CatchStmts,
1249 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1253 /// \brief Rebuild an Objective-C exception declaration.
1255 /// By default, performs semantic analysis to build the new declaration.
1256 /// Subclasses may override this routine to provide different behavior.
1257 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1258 TypeSourceInfo *TInfo, QualType T) {
1259 return getSema().BuildObjCExceptionDecl(TInfo, T,
1260 ExceptionDecl->getInnerLocStart(),
1261 ExceptionDecl->getLocation(),
1262 ExceptionDecl->getIdentifier());
1265 /// \brief Build a new Objective-C \@catch statement.
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
1269 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1270 SourceLocation RParenLoc,
1273 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1277 /// \brief Build a new Objective-C \@finally statement.
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
1281 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1283 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1286 /// \brief Build a new Objective-C \@throw statement.
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
1290 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1292 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1295 /// \brief Build a new OpenMP executable directive.
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1300 DeclarationNameInfo DirName,
1301 ArrayRef<OMPClause *> Clauses,
1302 Stmt *AStmt, SourceLocation StartLoc,
1303 SourceLocation EndLoc) {
1304 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1305 AStmt, StartLoc, EndLoc);
1308 /// \brief Build a new OpenMP 'if' clause.
1310 /// By default, performs semantic analysis to build the new OpenMP clause.
1311 /// Subclasses may override this routine to provide different behavior.
1312 OMPClause *RebuildOMPIfClause(Expr *Condition,
1313 SourceLocation StartLoc,
1314 SourceLocation LParenLoc,
1315 SourceLocation EndLoc) {
1316 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1320 /// \brief Build a new OpenMP 'final' clause.
1322 /// By default, performs semantic analysis to build the new OpenMP clause.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1325 SourceLocation LParenLoc,
1326 SourceLocation EndLoc) {
1327 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1331 /// \brief Build a new OpenMP 'num_threads' clause.
1333 /// By default, performs semantic analysis to build the new OpenMP clause.
1334 /// Subclasses may override this routine to provide different behavior.
1335 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1336 SourceLocation StartLoc,
1337 SourceLocation LParenLoc,
1338 SourceLocation EndLoc) {
1339 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1343 /// \brief Build a new OpenMP 'safelen' clause.
1345 /// By default, performs semantic analysis to build the new OpenMP clause.
1346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1353 /// \brief Build a new OpenMP 'collapse' clause.
1355 /// By default, performs semantic analysis to build the new OpenMP clause.
1356 /// Subclasses may override this routine to provide different behavior.
1357 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1358 SourceLocation LParenLoc,
1359 SourceLocation EndLoc) {
1360 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1364 /// \brief Build a new OpenMP 'default' clause.
1366 /// By default, performs semantic analysis to build the new OpenMP clause.
1367 /// Subclasses may override this routine to provide different behavior.
1368 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1369 SourceLocation KindKwLoc,
1370 SourceLocation StartLoc,
1371 SourceLocation LParenLoc,
1372 SourceLocation EndLoc) {
1373 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1374 StartLoc, LParenLoc, EndLoc);
1377 /// \brief Build a new OpenMP 'proc_bind' clause.
1379 /// By default, performs semantic analysis to build the new OpenMP clause.
1380 /// Subclasses may override this routine to provide different behavior.
1381 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1382 SourceLocation KindKwLoc,
1383 SourceLocation StartLoc,
1384 SourceLocation LParenLoc,
1385 SourceLocation EndLoc) {
1386 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1387 StartLoc, LParenLoc, EndLoc);
1390 /// \brief Build a new OpenMP 'schedule' clause.
1392 /// By default, performs semantic analysis to build the new OpenMP clause.
1393 /// Subclasses may override this routine to provide different behavior.
1394 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1396 SourceLocation StartLoc,
1397 SourceLocation LParenLoc,
1398 SourceLocation KindLoc,
1399 SourceLocation CommaLoc,
1400 SourceLocation EndLoc) {
1401 return getSema().ActOnOpenMPScheduleClause(
1402 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1405 /// \brief Build a new OpenMP 'private' clause.
1407 /// By default, performs semantic analysis to build the new OpenMP clause.
1408 /// Subclasses may override this routine to provide different behavior.
1409 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1410 SourceLocation StartLoc,
1411 SourceLocation LParenLoc,
1412 SourceLocation EndLoc) {
1413 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1417 /// \brief Build a new OpenMP 'firstprivate' clause.
1419 /// By default, performs semantic analysis to build the new OpenMP clause.
1420 /// Subclasses may override this routine to provide different behavior.
1421 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1422 SourceLocation StartLoc,
1423 SourceLocation LParenLoc,
1424 SourceLocation EndLoc) {
1425 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1429 /// \brief Build a new OpenMP 'lastprivate' clause.
1431 /// By default, performs semantic analysis to build the new OpenMP clause.
1432 /// Subclasses may override this routine to provide different behavior.
1433 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1434 SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1441 /// \brief Build a new OpenMP 'shared' clause.
1443 /// By default, performs semantic analysis to build the new OpenMP clause.
1444 /// Subclasses may override this routine to provide different behavior.
1445 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1453 /// \brief Build a new OpenMP 'reduction' clause.
1455 /// By default, performs semantic analysis to build the new statement.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1458 SourceLocation StartLoc,
1459 SourceLocation LParenLoc,
1460 SourceLocation ColonLoc,
1461 SourceLocation EndLoc,
1462 CXXScopeSpec &ReductionIdScopeSpec,
1463 const DeclarationNameInfo &ReductionId) {
1464 return getSema().ActOnOpenMPReductionClause(
1465 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1469 /// \brief Build a new OpenMP 'linear' clause.
1471 /// By default, performs semantic analysis to build the new OpenMP clause.
1472 /// Subclasses may override this routine to provide different behavior.
1473 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1474 SourceLocation StartLoc,
1475 SourceLocation LParenLoc,
1476 SourceLocation ColonLoc,
1477 SourceLocation EndLoc) {
1478 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1482 /// \brief Build a new OpenMP 'aligned' clause.
1484 /// By default, performs semantic analysis to build the new OpenMP clause.
1485 /// Subclasses may override this routine to provide different behavior.
1486 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1487 SourceLocation StartLoc,
1488 SourceLocation LParenLoc,
1489 SourceLocation ColonLoc,
1490 SourceLocation EndLoc) {
1491 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1492 LParenLoc, ColonLoc, EndLoc);
1495 /// \brief Build a new OpenMP 'copyin' clause.
1497 /// By default, performs semantic analysis to build the new OpenMP clause.
1498 /// Subclasses may override this routine to provide different behavior.
1499 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1500 SourceLocation StartLoc,
1501 SourceLocation LParenLoc,
1502 SourceLocation EndLoc) {
1503 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1507 /// \brief Build a new OpenMP 'copyprivate' clause.
1509 /// By default, performs semantic analysis to build the new OpenMP clause.
1510 /// Subclasses may override this routine to provide different behavior.
1511 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1512 SourceLocation StartLoc,
1513 SourceLocation LParenLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1519 /// \brief Build a new OpenMP 'flush' pseudo clause.
1521 /// By default, performs semantic analysis to build the new OpenMP clause.
1522 /// Subclasses may override this routine to provide different behavior.
1523 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1524 SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1531 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1533 /// By default, performs semantic analysis to build the new statement.
1534 /// Subclasses may override this routine to provide different behavior.
1535 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1537 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1540 /// \brief Build a new Objective-C \@synchronized statement.
1542 /// By default, performs semantic analysis to build the new statement.
1543 /// Subclasses may override this routine to provide different behavior.
1544 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1545 Expr *Object, Stmt *Body) {
1546 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1549 /// \brief Build a new Objective-C \@autoreleasepool statement.
1551 /// By default, performs semantic analysis to build the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1553 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1555 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1558 /// \brief Build a new Objective-C fast enumeration statement.
1560 /// By default, performs semantic analysis to build the new statement.
1561 /// Subclasses may override this routine to provide different behavior.
1562 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1565 SourceLocation RParenLoc,
1567 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1571 if (ForEachStmt.isInvalid())
1574 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1577 /// \brief Build a new C++ exception declaration.
1579 /// By default, performs semantic analysis to build the new decaration.
1580 /// Subclasses may override this routine to provide different behavior.
1581 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1582 TypeSourceInfo *Declarator,
1583 SourceLocation StartLoc,
1584 SourceLocation IdLoc,
1585 IdentifierInfo *Id) {
1586 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1587 StartLoc, IdLoc, Id);
1589 getSema().CurContext->addDecl(Var);
1593 /// \brief Build a new C++ catch statement.
1595 /// By default, performs semantic analysis to build the new statement.
1596 /// Subclasses may override this routine to provide different behavior.
1597 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1598 VarDecl *ExceptionDecl,
1600 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1604 /// \brief Build a new C++ try statement.
1606 /// By default, performs semantic analysis to build the new statement.
1607 /// Subclasses may override this routine to provide different behavior.
1608 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1609 ArrayRef<Stmt *> Handlers) {
1610 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1613 /// \brief Build a new C++0x range-based for statement.
1615 /// By default, performs semantic analysis to build the new statement.
1616 /// Subclasses may override this routine to provide different behavior.
1617 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1618 SourceLocation ColonLoc,
1619 Stmt *Range, Stmt *BeginEnd,
1620 Expr *Cond, Expr *Inc,
1622 SourceLocation RParenLoc) {
1623 // If we've just learned that the range is actually an Objective-C
1624 // collection, treat this as an Objective-C fast enumeration loop.
1625 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1626 if (RangeStmt->isSingleDecl()) {
1627 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1628 if (RangeVar->isInvalidDecl())
1631 Expr *RangeExpr = RangeVar->getInit();
1632 if (!RangeExpr->isTypeDependent() &&
1633 RangeExpr->getType()->isObjCObjectPointerType())
1634 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1640 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1641 Cond, Inc, LoopVar, RParenLoc,
1642 Sema::BFRK_Rebuild);
1645 /// \brief Build a new C++0x range-based for statement.
1647 /// By default, performs semantic analysis to build the new statement.
1648 /// Subclasses may override this routine to provide different behavior.
1649 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1651 NestedNameSpecifierLoc QualifierLoc,
1652 DeclarationNameInfo NameInfo,
1654 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1655 QualifierLoc, NameInfo, Nested);
1658 /// \brief Attach body to a C++0x range-based for statement.
1660 /// By default, performs semantic analysis to finish the new statement.
1661 /// Subclasses may override this routine to provide different behavior.
1662 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1663 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1666 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1667 Stmt *TryBlock, Stmt *Handler) {
1668 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
1671 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
1673 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
1676 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1677 return getSema().ActOnSEHFinallyBlock(Loc, Block);
1680 /// \brief Build a new expression that references a declaration.
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
1684 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1687 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1691 /// \brief Build a new expression that references a declaration.
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
1695 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1697 const DeclarationNameInfo &NameInfo,
1698 TemplateArgumentListInfo *TemplateArgs) {
1700 SS.Adopt(QualifierLoc);
1702 // FIXME: loses template args.
1704 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1707 /// \brief Build a new expression in parentheses.
1709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
1711 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1712 SourceLocation RParen) {
1713 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1716 /// \brief Build a new pseudo-destructor expression.
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
1720 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1721 SourceLocation OperatorLoc,
1724 TypeSourceInfo *ScopeType,
1725 SourceLocation CCLoc,
1726 SourceLocation TildeLoc,
1727 PseudoDestructorTypeStorage Destroyed);
1729 /// \brief Build a new unary operator expression.
1731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
1733 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1734 UnaryOperatorKind Opc,
1736 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
1739 /// \brief Build a new builtin offsetof expression.
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
1743 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1744 TypeSourceInfo *Type,
1745 Sema::OffsetOfComponent *Components,
1746 unsigned NumComponents,
1747 SourceLocation RParenLoc) {
1748 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1749 NumComponents, RParenLoc);
1752 /// \brief Build a new sizeof, alignof or vec_step expression with a
1755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
1757 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1758 SourceLocation OpLoc,
1759 UnaryExprOrTypeTrait ExprKind,
1761 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1764 /// \brief Build a new sizeof, alignof or vec step expression with an
1765 /// expression argument.
1767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
1769 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1770 UnaryExprOrTypeTrait ExprKind,
1773 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1774 if (Result.isInvalid())
1780 /// \brief Build a new array subscript expression.
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
1784 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1785 SourceLocation LBracketLoc,
1787 SourceLocation RBracketLoc) {
1788 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
1793 /// \brief Build a new call expression.
1795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
1797 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1799 SourceLocation RParenLoc,
1800 Expr *ExecConfig = nullptr) {
1801 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
1802 Args, RParenLoc, ExecConfig);
1805 /// \brief Build a new member access expression.
1807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
1809 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1811 NestedNameSpecifierLoc QualifierLoc,
1812 SourceLocation TemplateKWLoc,
1813 const DeclarationNameInfo &MemberNameInfo,
1815 NamedDecl *FoundDecl,
1816 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1817 NamedDecl *FirstQualifierInScope) {
1818 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1820 if (!Member->getDeclName()) {
1821 // We have a reference to an unnamed field. This is always the
1822 // base of an anonymous struct/union member access, i.e. the
1823 // field is always of record type.
1824 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1825 assert(Member->getType()->isRecordType() &&
1826 "unnamed member not of record type?");
1829 getSema().PerformObjectMemberConversion(BaseResult.get(),
1830 QualifierLoc.getNestedNameSpecifier(),
1832 if (BaseResult.isInvalid())
1834 Base = BaseResult.get();
1835 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
1837 new (getSema().Context) MemberExpr(Base, isArrow,
1838 Member, MemberNameInfo,
1839 cast<FieldDecl>(Member)->getType(),
1845 SS.Adopt(QualifierLoc);
1847 Base = BaseResult.get();
1848 QualType BaseType = Base->getType();
1850 // FIXME: this involves duplicating earlier analysis in a lot of
1851 // cases; we should avoid this when possible.
1852 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
1853 R.addDecl(FoundDecl);
1856 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1858 FirstQualifierInScope,
1859 R, ExplicitTemplateArgs);
1862 /// \brief Build a new binary operator expression.
1864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
1866 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1867 BinaryOperatorKind Opc,
1868 Expr *LHS, Expr *RHS) {
1869 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
1872 /// \brief Build a new conditional operator expression.
1874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
1876 ExprResult RebuildConditionalOperator(Expr *Cond,
1877 SourceLocation QuestionLoc,
1879 SourceLocation ColonLoc,
1881 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1885 /// \brief Build a new C-style cast expression.
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
1889 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1890 TypeSourceInfo *TInfo,
1891 SourceLocation RParenLoc,
1893 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1897 /// \brief Build a new compound literal expression.
1899 /// By default, performs semantic analysis to build the new expression.
1900 /// Subclasses may override this routine to provide different behavior.
1901 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1902 TypeSourceInfo *TInfo,
1903 SourceLocation RParenLoc,
1905 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1909 /// \brief Build a new extended vector element access expression.
1911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
1913 ExprResult RebuildExtVectorElementExpr(Expr *Base,
1914 SourceLocation OpLoc,
1915 SourceLocation AccessorLoc,
1916 IdentifierInfo &Accessor) {
1919 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
1920 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1921 OpLoc, /*IsArrow*/ false,
1922 SS, SourceLocation(),
1923 /*FirstQualifierInScope*/ nullptr,
1925 /* TemplateArgs */ nullptr);
1928 /// \brief Build a new initializer list expression.
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
1932 ExprResult RebuildInitList(SourceLocation LBraceLoc,
1934 SourceLocation RBraceLoc,
1935 QualType ResultTy) {
1937 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
1938 if (Result.isInvalid() || ResultTy->isDependentType())
1941 // Patch in the result type we were given, which may have been computed
1942 // when the initial InitListExpr was built.
1943 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1944 ILE->setType(ResultTy);
1948 /// \brief Build a new designated initializer expression.
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
1952 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1953 MultiExprArg ArrayExprs,
1954 SourceLocation EqualOrColonLoc,
1958 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1960 if (Result.isInvalid())
1966 /// \brief Build a new value-initialized expression.
1968 /// By default, builds the implicit value initialization without performing
1969 /// any semantic analysis. Subclasses may override this routine to provide
1970 /// different behavior.
1971 ExprResult RebuildImplicitValueInitExpr(QualType T) {
1972 return new (SemaRef.Context) ImplicitValueInitExpr(T);
1975 /// \brief Build a new \c va_arg expression.
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
1979 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1980 Expr *SubExpr, TypeSourceInfo *TInfo,
1981 SourceLocation RParenLoc) {
1982 return getSema().BuildVAArgExpr(BuiltinLoc,
1987 /// \brief Build a new expression list in parentheses.
1989 /// By default, performs semantic analysis to build the new expression.
1990 /// Subclasses may override this routine to provide different behavior.
1991 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1992 MultiExprArg SubExprs,
1993 SourceLocation RParenLoc) {
1994 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
1997 /// \brief Build a new address-of-label expression.
1999 /// By default, performs semantic analysis, using the name of the label
2000 /// rather than attempting to map the label statement itself.
2001 /// Subclasses may override this routine to provide different behavior.
2002 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
2003 SourceLocation LabelLoc, LabelDecl *Label) {
2004 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2007 /// \brief Build a new GNU statement expression.
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
2011 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
2013 SourceLocation RParenLoc) {
2014 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2017 /// \brief Build a new __builtin_choose_expr expression.
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
2021 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
2022 Expr *Cond, Expr *LHS, Expr *RHS,
2023 SourceLocation RParenLoc) {
2024 return SemaRef.ActOnChooseExpr(BuiltinLoc,
2029 /// \brief Build a new generic selection expression.
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
2033 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2034 SourceLocation DefaultLoc,
2035 SourceLocation RParenLoc,
2036 Expr *ControllingExpr,
2037 ArrayRef<TypeSourceInfo *> Types,
2038 ArrayRef<Expr *> Exprs) {
2039 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2040 ControllingExpr, Types, Exprs);
2043 /// \brief Build a new overloaded operator call expression.
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// The semantic analysis provides the behavior of template instantiation,
2047 /// copying with transformations that turn what looks like an overloaded
2048 /// operator call into a use of a builtin operator, performing
2049 /// argument-dependent lookup, etc. Subclasses may override this routine to
2050 /// provide different behavior.
2051 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2052 SourceLocation OpLoc,
2057 /// \brief Build a new C++ "named" cast expression, such as static_cast or
2058 /// reinterpret_cast.
2060 /// By default, this routine dispatches to one of the more-specific routines
2061 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2062 /// Subclasses may override this routine to provide different behavior.
2063 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
2064 Stmt::StmtClass Class,
2065 SourceLocation LAngleLoc,
2066 TypeSourceInfo *TInfo,
2067 SourceLocation RAngleLoc,
2068 SourceLocation LParenLoc,
2070 SourceLocation RParenLoc) {
2072 case Stmt::CXXStaticCastExprClass:
2073 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2074 RAngleLoc, LParenLoc,
2075 SubExpr, RParenLoc);
2077 case Stmt::CXXDynamicCastExprClass:
2078 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2079 RAngleLoc, LParenLoc,
2080 SubExpr, RParenLoc);
2082 case Stmt::CXXReinterpretCastExprClass:
2083 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2084 RAngleLoc, LParenLoc,
2088 case Stmt::CXXConstCastExprClass:
2089 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2090 RAngleLoc, LParenLoc,
2091 SubExpr, RParenLoc);
2094 llvm_unreachable("Invalid C++ named cast");
2098 /// \brief Build a new C++ static_cast expression.
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
2102 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
2103 SourceLocation LAngleLoc,
2104 TypeSourceInfo *TInfo,
2105 SourceLocation RAngleLoc,
2106 SourceLocation LParenLoc,
2108 SourceLocation RParenLoc) {
2109 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2111 SourceRange(LAngleLoc, RAngleLoc),
2112 SourceRange(LParenLoc, RParenLoc));
2115 /// \brief Build a new C++ dynamic_cast expression.
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
2119 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
2120 SourceLocation LAngleLoc,
2121 TypeSourceInfo *TInfo,
2122 SourceLocation RAngleLoc,
2123 SourceLocation LParenLoc,
2125 SourceLocation RParenLoc) {
2126 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2128 SourceRange(LAngleLoc, RAngleLoc),
2129 SourceRange(LParenLoc, RParenLoc));
2132 /// \brief Build a new C++ reinterpret_cast expression.
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
2136 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
2137 SourceLocation LAngleLoc,
2138 TypeSourceInfo *TInfo,
2139 SourceLocation RAngleLoc,
2140 SourceLocation LParenLoc,
2142 SourceLocation RParenLoc) {
2143 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2145 SourceRange(LAngleLoc, RAngleLoc),
2146 SourceRange(LParenLoc, RParenLoc));
2149 /// \brief Build a new C++ const_cast expression.
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
2153 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
2154 SourceLocation LAngleLoc,
2155 TypeSourceInfo *TInfo,
2156 SourceLocation RAngleLoc,
2157 SourceLocation LParenLoc,
2159 SourceLocation RParenLoc) {
2160 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2162 SourceRange(LAngleLoc, RAngleLoc),
2163 SourceRange(LParenLoc, RParenLoc));
2166 /// \brief Build a new C++ functional-style cast expression.
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
2170 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2171 SourceLocation LParenLoc,
2173 SourceLocation RParenLoc) {
2174 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2175 MultiExprArg(&Sub, 1),
2179 /// \brief Build a new C++ typeid(type) expression.
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
2183 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2184 SourceLocation TypeidLoc,
2185 TypeSourceInfo *Operand,
2186 SourceLocation RParenLoc) {
2187 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2192 /// \brief Build a new C++ typeid(expr) expression.
2194 /// By default, performs semantic analysis to build the new expression.
2195 /// Subclasses may override this routine to provide different behavior.
2196 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2197 SourceLocation TypeidLoc,
2199 SourceLocation RParenLoc) {
2200 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2204 /// \brief Build a new C++ __uuidof(type) expression.
2206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
2208 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2209 SourceLocation TypeidLoc,
2210 TypeSourceInfo *Operand,
2211 SourceLocation RParenLoc) {
2212 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2216 /// \brief Build a new C++ __uuidof(expr) expression.
2218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
2220 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2221 SourceLocation TypeidLoc,
2223 SourceLocation RParenLoc) {
2224 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2228 /// \brief Build a new C++ "this" expression.
2230 /// By default, builds a new "this" expression without performing any
2231 /// semantic analysis. Subclasses may override this routine to provide
2232 /// different behavior.
2233 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
2236 getSema().CheckCXXThisCapture(ThisLoc);
2237 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2240 /// \brief Build a new C++ throw expression.
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
2244 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2245 bool IsThrownVariableInScope) {
2246 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2249 /// \brief Build a new C++ default-argument expression.
2251 /// By default, builds a new default-argument expression, which does not
2252 /// require any semantic analysis. Subclasses may override this routine to
2253 /// provide different behavior.
2254 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
2255 ParmVarDecl *Param) {
2256 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2259 /// \brief Build a new C++11 default-initialization expression.
2261 /// By default, builds a new default field initialization expression, which
2262 /// does not require any semantic analysis. Subclasses may override this
2263 /// routine to provide different behavior.
2264 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2266 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2269 /// \brief Build a new C++ zero-initialization expression.
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
2273 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2274 SourceLocation LParenLoc,
2275 SourceLocation RParenLoc) {
2276 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2280 /// \brief Build a new C++ "new" expression.
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
2284 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
2286 SourceLocation PlacementLParen,
2287 MultiExprArg PlacementArgs,
2288 SourceLocation PlacementRParen,
2289 SourceRange TypeIdParens,
2290 QualType AllocatedType,
2291 TypeSourceInfo *AllocatedTypeInfo,
2293 SourceRange DirectInitRange,
2294 Expr *Initializer) {
2295 return getSema().BuildCXXNew(StartLoc, UseGlobal,
2307 /// \brief Build a new C++ "delete" expression.
2309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
2311 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2312 bool IsGlobalDelete,
2315 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2319 /// \brief Build a new type trait expression.
2321 /// By default, performs semantic analysis to build the new expression.
2322 /// Subclasses may override this routine to provide different behavior.
2323 ExprResult RebuildTypeTrait(TypeTrait Trait,
2324 SourceLocation StartLoc,
2325 ArrayRef<TypeSourceInfo *> Args,
2326 SourceLocation RParenLoc) {
2327 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2330 /// \brief Build a new array type trait expression.
2332 /// By default, performs semantic analysis to build the new expression.
2333 /// Subclasses may override this routine to provide different behavior.
2334 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2335 SourceLocation StartLoc,
2336 TypeSourceInfo *TSInfo,
2338 SourceLocation RParenLoc) {
2339 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2342 /// \brief Build a new expression trait expression.
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
2346 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2347 SourceLocation StartLoc,
2349 SourceLocation RParenLoc) {
2350 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2353 /// \brief Build a new (previously unresolved) declaration reference
2356 /// By default, performs semantic analysis to build the new expression.
2357 /// Subclasses may override this routine to provide different behavior.
2358 ExprResult RebuildDependentScopeDeclRefExpr(
2359 NestedNameSpecifierLoc QualifierLoc,
2360 SourceLocation TemplateKWLoc,
2361 const DeclarationNameInfo &NameInfo,
2362 const TemplateArgumentListInfo *TemplateArgs,
2363 bool IsAddressOfOperand,
2364 TypeSourceInfo **RecoveryTSI) {
2366 SS.Adopt(QualifierLoc);
2368 if (TemplateArgs || TemplateKWLoc.isValid())
2369 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2372 return getSema().BuildQualifiedDeclarationNameExpr(
2373 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
2376 /// \brief Build a new template-id expression.
2378 /// By default, performs semantic analysis to build the new expression.
2379 /// Subclasses may override this routine to provide different behavior.
2380 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2381 SourceLocation TemplateKWLoc,
2384 const TemplateArgumentListInfo *TemplateArgs) {
2385 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2389 /// \brief Build a new object-construction expression.
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
2393 ExprResult RebuildCXXConstructExpr(QualType T,
2395 CXXConstructorDecl *Constructor,
2398 bool HadMultipleCandidates,
2399 bool ListInitialization,
2400 bool StdInitListInitialization,
2401 bool RequiresZeroInit,
2402 CXXConstructExpr::ConstructionKind ConstructKind,
2403 SourceRange ParenRange) {
2404 SmallVector<Expr*, 8> ConvertedArgs;
2405 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2409 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
2411 HadMultipleCandidates,
2413 StdInitListInitialization,
2414 RequiresZeroInit, ConstructKind,
2418 /// \brief Build a new object-construction expression.
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
2422 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2423 SourceLocation LParenLoc,
2425 SourceLocation RParenLoc) {
2426 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2432 /// \brief Build a new object-construction expression.
2434 /// By default, performs semantic analysis to build the new expression.
2435 /// Subclasses may override this routine to provide different behavior.
2436 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2437 SourceLocation LParenLoc,
2439 SourceLocation RParenLoc) {
2440 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2446 /// \brief Build a new member reference expression.
2448 /// By default, performs semantic analysis to build the new expression.
2449 /// Subclasses may override this routine to provide different behavior.
2450 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2453 SourceLocation OperatorLoc,
2454 NestedNameSpecifierLoc QualifierLoc,
2455 SourceLocation TemplateKWLoc,
2456 NamedDecl *FirstQualifierInScope,
2457 const DeclarationNameInfo &MemberNameInfo,
2458 const TemplateArgumentListInfo *TemplateArgs) {
2460 SS.Adopt(QualifierLoc);
2462 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2463 OperatorLoc, IsArrow,
2465 FirstQualifierInScope,
2470 /// \brief Build a new member reference expression.
2472 /// By default, performs semantic analysis to build the new expression.
2473 /// Subclasses may override this routine to provide different behavior.
2474 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2475 SourceLocation OperatorLoc,
2477 NestedNameSpecifierLoc QualifierLoc,
2478 SourceLocation TemplateKWLoc,
2479 NamedDecl *FirstQualifierInScope,
2481 const TemplateArgumentListInfo *TemplateArgs) {
2483 SS.Adopt(QualifierLoc);
2485 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2486 OperatorLoc, IsArrow,
2488 FirstQualifierInScope,
2492 /// \brief Build a new noexcept expression.
2494 /// By default, performs semantic analysis to build the new expression.
2495 /// Subclasses may override this routine to provide different behavior.
2496 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2497 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2500 /// \brief Build a new expression to compute the length of a parameter pack.
2501 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2502 SourceLocation PackLoc,
2503 SourceLocation RParenLoc,
2504 Optional<unsigned> Length) {
2506 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2507 OperatorLoc, Pack, PackLoc,
2508 RParenLoc, *Length);
2510 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2511 OperatorLoc, Pack, PackLoc,
2515 /// \brief Build a new Objective-C boxed expression.
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
2519 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2520 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2523 /// \brief Build a new Objective-C array literal.
2525 /// By default, performs semantic analysis to build the new expression.
2526 /// Subclasses may override this routine to provide different behavior.
2527 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2528 Expr **Elements, unsigned NumElements) {
2529 return getSema().BuildObjCArrayLiteral(Range,
2530 MultiExprArg(Elements, NumElements));
2533 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2534 Expr *Base, Expr *Key,
2535 ObjCMethodDecl *getterMethod,
2536 ObjCMethodDecl *setterMethod) {
2537 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2538 getterMethod, setterMethod);
2541 /// \brief Build a new Objective-C dictionary literal.
2543 /// By default, performs semantic analysis to build the new expression.
2544 /// Subclasses may override this routine to provide different behavior.
2545 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2546 ObjCDictionaryElement *Elements,
2547 unsigned NumElements) {
2548 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2551 /// \brief Build a new Objective-C \@encode expression.
2553 /// By default, performs semantic analysis to build the new expression.
2554 /// Subclasses may override this routine to provide different behavior.
2555 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2556 TypeSourceInfo *EncodeTypeInfo,
2557 SourceLocation RParenLoc) {
2558 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2561 /// \brief Build a new Objective-C class message.
2562 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2564 ArrayRef<SourceLocation> SelectorLocs,
2565 ObjCMethodDecl *Method,
2566 SourceLocation LBracLoc,
2568 SourceLocation RBracLoc) {
2569 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2570 ReceiverTypeInfo->getType(),
2571 /*SuperLoc=*/SourceLocation(),
2572 Sel, Method, LBracLoc, SelectorLocs,
2576 /// \brief Build a new Objective-C instance message.
2577 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2579 ArrayRef<SourceLocation> SelectorLocs,
2580 ObjCMethodDecl *Method,
2581 SourceLocation LBracLoc,
2583 SourceLocation RBracLoc) {
2584 return SemaRef.BuildInstanceMessage(Receiver,
2585 Receiver->getType(),
2586 /*SuperLoc=*/SourceLocation(),
2587 Sel, Method, LBracLoc, SelectorLocs,
2591 /// \brief Build a new Objective-C ivar reference expression.
2593 /// By default, performs semantic analysis to build the new expression.
2594 /// Subclasses may override this routine to provide different behavior.
2595 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2596 SourceLocation IvarLoc,
2597 bool IsArrow, bool IsFreeIvar) {
2598 // FIXME: We lose track of the IsFreeIvar bit.
2600 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2601 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2602 /*FIXME:*/IvarLoc, IsArrow,
2603 SS, SourceLocation(),
2604 /*FirstQualifierInScope=*/nullptr,
2606 /*TemplateArgs=*/nullptr);
2609 /// \brief Build a new Objective-C property reference expression.
2611 /// By default, performs semantic analysis to build the new expression.
2612 /// Subclasses may override this routine to provide different behavior.
2613 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2614 ObjCPropertyDecl *Property,
2615 SourceLocation PropertyLoc) {
2617 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2618 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2619 /*FIXME:*/PropertyLoc,
2621 SS, SourceLocation(),
2622 /*FirstQualifierInScope=*/nullptr,
2624 /*TemplateArgs=*/nullptr);
2627 /// \brief Build a new Objective-C property reference expression.
2629 /// By default, performs semantic analysis to build the new expression.
2630 /// Subclasses may override this routine to provide different behavior.
2631 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2632 ObjCMethodDecl *Getter,
2633 ObjCMethodDecl *Setter,
2634 SourceLocation PropertyLoc) {
2635 // Since these expressions can only be value-dependent, we do not
2636 // need to perform semantic analysis again.
2638 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2639 VK_LValue, OK_ObjCProperty,
2640 PropertyLoc, Base));
2643 /// \brief Build a new Objective-C "isa" expression.
2645 /// By default, performs semantic analysis to build the new expression.
2646 /// Subclasses may override this routine to provide different behavior.
2647 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2648 SourceLocation OpLoc, bool IsArrow) {
2650 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2651 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2653 SS, SourceLocation(),
2654 /*FirstQualifierInScope=*/nullptr,
2656 /*TemplateArgs=*/nullptr);
2659 /// \brief Build a new shuffle vector expression.
2661 /// By default, performs semantic analysis to build the new expression.
2662 /// Subclasses may override this routine to provide different behavior.
2663 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2664 MultiExprArg SubExprs,
2665 SourceLocation RParenLoc) {
2666 // Find the declaration for __builtin_shufflevector
2667 const IdentifierInfo &Name
2668 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2669 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2670 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2671 assert(!Lookup.empty() && "No __builtin_shufflevector?");
2673 // Build a reference to the __builtin_shufflevector builtin
2674 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
2675 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2676 SemaRef.Context.BuiltinFnTy,
2677 VK_RValue, BuiltinLoc);
2678 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2679 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2680 CK_BuiltinFnToFnPtr).get();
2682 // Build the CallExpr
2683 ExprResult TheCall = new (SemaRef.Context) CallExpr(
2684 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2685 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
2687 // Type-check the __builtin_shufflevector expression.
2688 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
2691 /// \brief Build a new convert vector expression.
2692 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2693 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2694 SourceLocation RParenLoc) {
2695 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2696 BuiltinLoc, RParenLoc);
2699 /// \brief Build a new template argument pack expansion.
2701 /// By default, performs semantic analysis to build a new pack expansion
2702 /// for a template argument. Subclasses may override this routine to provide
2703 /// different behavior.
2704 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2705 SourceLocation EllipsisLoc,
2706 Optional<unsigned> NumExpansions) {
2707 switch (Pattern.getArgument().getKind()) {
2708 case TemplateArgument::Expression: {
2710 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2711 EllipsisLoc, NumExpansions);
2712 if (Result.isInvalid())
2713 return TemplateArgumentLoc();
2715 return TemplateArgumentLoc(Result.get(), Result.get());
2718 case TemplateArgument::Template:
2719 return TemplateArgumentLoc(TemplateArgument(
2720 Pattern.getArgument().getAsTemplate(),
2722 Pattern.getTemplateQualifierLoc(),
2723 Pattern.getTemplateNameLoc(),
2726 case TemplateArgument::Null:
2727 case TemplateArgument::Integral:
2728 case TemplateArgument::Declaration:
2729 case TemplateArgument::Pack:
2730 case TemplateArgument::TemplateExpansion:
2731 case TemplateArgument::NullPtr:
2732 llvm_unreachable("Pack expansion pattern has no parameter packs");
2734 case TemplateArgument::Type:
2735 if (TypeSourceInfo *Expansion
2736 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2739 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2744 return TemplateArgumentLoc();
2747 /// \brief Build a new expression pack expansion.
2749 /// By default, performs semantic analysis to build a new pack expansion
2750 /// for an expression. Subclasses may override this routine to provide
2751 /// different behavior.
2752 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2753 Optional<unsigned> NumExpansions) {
2754 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2757 /// \brief Build a new atomic operation expression.
2759 /// By default, performs semantic analysis to build the new expression.
2760 /// Subclasses may override this routine to provide different behavior.
2761 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2762 MultiExprArg SubExprs,
2764 AtomicExpr::AtomicOp Op,
2765 SourceLocation RParenLoc) {
2766 // Just create the expression; there is not any interesting semantic
2767 // analysis here because we can't actually build an AtomicExpr until
2768 // we are sure it is semantically sound.
2769 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
2774 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2775 QualType ObjectType,
2776 NamedDecl *FirstQualifierInScope,
2779 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2780 QualType ObjectType,
2781 NamedDecl *FirstQualifierInScope,
2784 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2785 NamedDecl *FirstQualifierInScope,
2789 template<typename Derived>
2790 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
2794 switch (S->getStmtClass()) {
2795 case Stmt::NoStmtClass: break;
2797 // Transform individual statement nodes
2798 #define STMT(Node, Parent) \
2799 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2800 #define ABSTRACT_STMT(Node)
2801 #define EXPR(Node, Parent)
2802 #include "clang/AST/StmtNodes.inc"
2804 // Transform expressions by calling TransformExpr.
2805 #define STMT(Node, Parent)
2806 #define ABSTRACT_STMT(Stmt)
2807 #define EXPR(Node, Parent) case Stmt::Node##Class:
2808 #include "clang/AST/StmtNodes.inc"
2810 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
2814 return getSema().ActOnExprStmt(E);
2821 template<typename Derived>
2822 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2826 switch (S->getClauseKind()) {
2828 // Transform individual clause nodes
2829 #define OPENMP_CLAUSE(Name, Class) \
2830 case OMPC_ ## Name : \
2831 return getDerived().Transform ## Class(cast<Class>(S));
2832 #include "clang/Basic/OpenMPKinds.def"
2839 template<typename Derived>
2840 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2844 switch (E->getStmtClass()) {
2845 case Stmt::NoStmtClass: break;
2846 #define STMT(Node, Parent) case Stmt::Node##Class: break;
2847 #define ABSTRACT_STMT(Stmt)
2848 #define EXPR(Node, Parent) \
2849 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
2850 #include "clang/AST/StmtNodes.inc"
2856 template<typename Derived>
2857 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2859 // Initializers are instantiated like expressions, except that various outer
2860 // layers are stripped.
2864 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2865 Init = ExprTemp->getSubExpr();
2867 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2868 Init = MTE->GetTemporaryExpr();
2870 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2871 Init = Binder->getSubExpr();
2873 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2874 Init = ICE->getSubExprAsWritten();
2876 if (CXXStdInitializerListExpr *ILE =
2877 dyn_cast<CXXStdInitializerListExpr>(Init))
2878 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
2880 // If this is copy-initialization, we only need to reconstruct
2881 // InitListExprs. Other forms of copy-initialization will be a no-op if
2882 // the initializer is already the right type.
2883 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2884 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
2885 return getDerived().TransformExpr(Init);
2887 // Revert value-initialization back to empty parens.
2888 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2889 SourceRange Parens = VIE->getSourceRange();
2890 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
2894 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2895 if (isa<ImplicitValueInitExpr>(Init))
2896 return getDerived().RebuildParenListExpr(SourceLocation(), None,
2899 // Revert initialization by constructor back to a parenthesized or braced list
2900 // of expressions. Any other form of initializer can just be reused directly.
2901 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
2902 return getDerived().TransformExpr(Init);
2904 // If the initialization implicitly converted an initializer list to a
2905 // std::initializer_list object, unwrap the std::initializer_list too.
2906 if (Construct && Construct->isStdInitListInitialization())
2907 return TransformInitializer(Construct->getArg(0), NotCopyInit);
2909 SmallVector<Expr*, 8> NewArgs;
2910 bool ArgChanged = false;
2911 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2912 /*IsCall*/true, NewArgs, &ArgChanged))
2915 // If this was list initialization, revert to list form.
2916 if (Construct->isListInitialization())
2917 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2918 Construct->getLocEnd(),
2919 Construct->getType());
2921 // Build a ParenListExpr to represent anything else.
2922 SourceRange Parens = Construct->getParenOrBraceRange();
2923 if (Parens.isInvalid()) {
2924 // This was a variable declaration's initialization for which no initializer
2926 assert(NewArgs.empty() &&
2927 "no parens or braces but have direct init with arguments?");
2930 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2934 template<typename Derived>
2935 bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2938 SmallVectorImpl<Expr *> &Outputs,
2940 for (unsigned I = 0; I != NumInputs; ++I) {
2941 // If requested, drop call arguments that need to be dropped.
2942 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2949 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2950 Expr *Pattern = Expansion->getPattern();
2952 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2953 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2954 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2956 // Determine whether the set of unexpanded parameter packs can and should
2959 bool RetainExpansion = false;
2960 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2961 Optional<unsigned> NumExpansions = OrigNumExpansions;
2962 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2963 Pattern->getSourceRange(),
2965 Expand, RetainExpansion,
2970 // The transform has determined that we should perform a simple
2971 // transformation on the pack expansion, producing another pack
2973 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2974 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2975 if (OutPattern.isInvalid())
2978 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2979 Expansion->getEllipsisLoc(),
2981 if (Out.isInvalid())
2986 Outputs.push_back(Out.get());
2990 // Record right away that the argument was changed. This needs
2991 // to happen even if the array expands to nothing.
2992 if (ArgChanged) *ArgChanged = true;
2994 // The transform has determined that we should perform an elementwise
2995 // expansion of the pattern. Do so.
2996 for (unsigned I = 0; I != *NumExpansions; ++I) {
2997 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2998 ExprResult Out = getDerived().TransformExpr(Pattern);
2999 if (Out.isInvalid())
3002 // FIXME: Can this happen? We should not try to expand the pack
3004 if (Out.get()->containsUnexpandedParameterPack()) {
3005 Out = getDerived().RebuildPackExpansion(
3006 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3007 if (Out.isInvalid())
3011 Outputs.push_back(Out.get());
3014 // If we're supposed to retain a pack expansion, do so by temporarily
3015 // forgetting the partially-substituted parameter pack.
3016 if (RetainExpansion) {
3017 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3019 ExprResult Out = getDerived().TransformExpr(Pattern);
3020 if (Out.isInvalid())
3023 Out = getDerived().RebuildPackExpansion(
3024 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3025 if (Out.isInvalid())
3028 Outputs.push_back(Out.get());
3035 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3036 : getDerived().TransformExpr(Inputs[I]);
3037 if (Result.isInvalid())
3040 if (Result.get() != Inputs[I] && ArgChanged)
3043 Outputs.push_back(Result.get());
3049 template<typename Derived>
3050 NestedNameSpecifierLoc
3051 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3052 NestedNameSpecifierLoc NNS,
3053 QualType ObjectType,
3054 NamedDecl *FirstQualifierInScope) {
3055 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
3056 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3057 Qualifier = Qualifier.getPrefix())
3058 Qualifiers.push_back(Qualifier);
3061 while (!Qualifiers.empty()) {
3062 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3063 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
3065 switch (QNNS->getKind()) {
3066 case NestedNameSpecifier::Identifier:
3067 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
3068 *QNNS->getAsIdentifier(),
3069 Q.getLocalBeginLoc(),
3071 ObjectType, false, SS,
3072 FirstQualifierInScope, false))
3073 return NestedNameSpecifierLoc();
3077 case NestedNameSpecifier::Namespace: {
3079 = cast_or_null<NamespaceDecl>(
3080 getDerived().TransformDecl(
3081 Q.getLocalBeginLoc(),
3082 QNNS->getAsNamespace()));
3083 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3087 case NestedNameSpecifier::NamespaceAlias: {
3088 NamespaceAliasDecl *Alias
3089 = cast_or_null<NamespaceAliasDecl>(
3090 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3091 QNNS->getAsNamespaceAlias()));
3092 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3093 Q.getLocalEndLoc());
3097 case NestedNameSpecifier::Global:
3098 // There is no meaningful transformation that one could perform on the
3100 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3103 case NestedNameSpecifier::TypeSpecWithTemplate:
3104 case NestedNameSpecifier::TypeSpec: {
3105 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3106 FirstQualifierInScope, SS);
3109 return NestedNameSpecifierLoc();
3111 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3112 (SemaRef.getLangOpts().CPlusPlus11 &&
3113 TL.getType()->isEnumeralType())) {
3114 assert(!TL.getType().hasLocalQualifiers() &&
3115 "Can't get cv-qualifiers here");
3116 if (TL.getType()->isEnumeralType())
3117 SemaRef.Diag(TL.getBeginLoc(),
3118 diag::warn_cxx98_compat_enum_nested_name_spec);
3119 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3120 Q.getLocalEndLoc());
3123 // If the nested-name-specifier is an invalid type def, don't emit an
3124 // error because a previous error should have already been emitted.
3125 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3126 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3127 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3128 << TL.getType() << SS.getRange();
3130 return NestedNameSpecifierLoc();
3134 // The qualifier-in-scope and object type only apply to the leftmost entity.
3135 FirstQualifierInScope = nullptr;
3136 ObjectType = QualType();
3139 // Don't rebuild the nested-name-specifier if we don't have to.
3140 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3141 !getDerived().AlwaysRebuild())
3144 // If we can re-use the source-location data from the original
3145 // nested-name-specifier, do so.
3146 if (SS.location_size() == NNS.getDataLength() &&
3147 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3148 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3150 // Allocate new nested-name-specifier location information.
3151 return SS.getWithLocInContext(SemaRef.Context);
3154 template<typename Derived>
3156 TreeTransform<Derived>
3157 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
3158 DeclarationName Name = NameInfo.getName();
3160 return DeclarationNameInfo();
3162 switch (Name.getNameKind()) {
3163 case DeclarationName::Identifier:
3164 case DeclarationName::ObjCZeroArgSelector:
3165 case DeclarationName::ObjCOneArgSelector:
3166 case DeclarationName::ObjCMultiArgSelector:
3167 case DeclarationName::CXXOperatorName:
3168 case DeclarationName::CXXLiteralOperatorName:
3169 case DeclarationName::CXXUsingDirective:
3172 case DeclarationName::CXXConstructorName:
3173 case DeclarationName::CXXDestructorName:
3174 case DeclarationName::CXXConversionFunctionName: {
3175 TypeSourceInfo *NewTInfo;
3176 CanQualType NewCanTy;
3177 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3178 NewTInfo = getDerived().TransformType(OldTInfo);
3180 return DeclarationNameInfo();
3181 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3185 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3186 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3188 return DeclarationNameInfo();
3189 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3192 DeclarationName NewName
3193 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3195 DeclarationNameInfo NewNameInfo(NameInfo);
3196 NewNameInfo.setName(NewName);
3197 NewNameInfo.setNamedTypeInfo(NewTInfo);
3202 llvm_unreachable("Unknown name kind.");
3205 template<typename Derived>
3207 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3209 SourceLocation NameLoc,
3210 QualType ObjectType,
3211 NamedDecl *FirstQualifierInScope) {
3212 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3213 TemplateDecl *Template = QTN->getTemplateDecl();
3214 assert(Template && "qualified template name must refer to a template");
3216 TemplateDecl *TransTemplate
3217 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3220 return TemplateName();
3222 if (!getDerived().AlwaysRebuild() &&
3223 SS.getScopeRep() == QTN->getQualifier() &&
3224 TransTemplate == Template)
3227 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3231 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3232 if (SS.getScopeRep()) {
3233 // These apply to the scope specifier, not the template.
3234 ObjectType = QualType();
3235 FirstQualifierInScope = nullptr;
3238 if (!getDerived().AlwaysRebuild() &&
3239 SS.getScopeRep() == DTN->getQualifier() &&
3240 ObjectType.isNull())
3243 if (DTN->isIdentifier()) {
3244 return getDerived().RebuildTemplateName(SS,
3245 *DTN->getIdentifier(),
3248 FirstQualifierInScope);
3251 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3255 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3256 TemplateDecl *TransTemplate
3257 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3260 return TemplateName();
3262 if (!getDerived().AlwaysRebuild() &&
3263 TransTemplate == Template)
3266 return TemplateName(TransTemplate);
3269 if (SubstTemplateTemplateParmPackStorage *SubstPack
3270 = Name.getAsSubstTemplateTemplateParmPack()) {
3271 TemplateTemplateParmDecl *TransParam
3272 = cast_or_null<TemplateTemplateParmDecl>(
3273 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3275 return TemplateName();
3277 if (!getDerived().AlwaysRebuild() &&
3278 TransParam == SubstPack->getParameterPack())
3281 return getDerived().RebuildTemplateName(TransParam,
3282 SubstPack->getArgumentPack());
3285 // These should be getting filtered out before they reach the AST.
3286 llvm_unreachable("overloaded function decl survived to here");
3289 template<typename Derived>
3290 void TreeTransform<Derived>::InventTemplateArgumentLoc(
3291 const TemplateArgument &Arg,
3292 TemplateArgumentLoc &Output) {
3293 SourceLocation Loc = getDerived().getBaseLocation();
3294 switch (Arg.getKind()) {
3295 case TemplateArgument::Null:
3296 llvm_unreachable("null template argument in TreeTransform");
3299 case TemplateArgument::Type:
3300 Output = TemplateArgumentLoc(Arg,
3301 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3305 case TemplateArgument::Template:
3306 case TemplateArgument::TemplateExpansion: {
3307 NestedNameSpecifierLocBuilder Builder;
3308 TemplateName Template = Arg.getAsTemplate();
3309 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3310 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3311 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3312 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3314 if (Arg.getKind() == TemplateArgument::Template)
3315 Output = TemplateArgumentLoc(Arg,
3316 Builder.getWithLocInContext(SemaRef.Context),
3319 Output = TemplateArgumentLoc(Arg,
3320 Builder.getWithLocInContext(SemaRef.Context),
3326 case TemplateArgument::Expression:
3327 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3330 case TemplateArgument::Declaration:
3331 case TemplateArgument::Integral:
3332 case TemplateArgument::Pack:
3333 case TemplateArgument::NullPtr:
3334 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
3339 template<typename Derived>
3340 bool TreeTransform<Derived>::TransformTemplateArgument(
3341 const TemplateArgumentLoc &Input,
3342 TemplateArgumentLoc &Output) {
3343 const TemplateArgument &Arg = Input.getArgument();
3344 switch (Arg.getKind()) {
3345 case TemplateArgument::Null:
3346 case TemplateArgument::Integral:
3347 case TemplateArgument::Pack:
3348 case TemplateArgument::Declaration:
3349 case TemplateArgument::NullPtr:
3350 llvm_unreachable("Unexpected TemplateArgument");
3352 case TemplateArgument::Type: {
3353 TypeSourceInfo *DI = Input.getTypeSourceInfo();
3355 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3357 DI = getDerived().TransformType(DI);
3358 if (!DI) return true;
3360 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3364 case TemplateArgument::Template: {
3365 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3367 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3373 SS.Adopt(QualifierLoc);
3374 TemplateName Template
3375 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3376 Input.getTemplateNameLoc());
3377 if (Template.isNull())
3380 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3381 Input.getTemplateNameLoc());
3385 case TemplateArgument::TemplateExpansion:
3386 llvm_unreachable("Caller should expand pack expansions");
3388 case TemplateArgument::Expression: {
3389 // Template argument expressions are constant expressions.
3390 EnterExpressionEvaluationContext Unevaluated(getSema(),
3391 Sema::ConstantEvaluated);
3393 Expr *InputExpr = Input.getSourceExpression();
3394 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3396 ExprResult E = getDerived().TransformExpr(InputExpr);
3397 E = SemaRef.ActOnConstantExpression(E);
3398 if (E.isInvalid()) return true;
3399 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3404 // Work around bogus GCC warning
3408 /// \brief Iterator adaptor that invents template argument location information
3409 /// for each of the template arguments in its underlying iterator.
3410 template<typename Derived, typename InputIterator>
3411 class TemplateArgumentLocInventIterator {
3412 TreeTransform<Derived> &Self;
3416 typedef TemplateArgumentLoc value_type;
3417 typedef TemplateArgumentLoc reference;
3418 typedef typename std::iterator_traits<InputIterator>::difference_type
3420 typedef std::input_iterator_tag iterator_category;
3423 TemplateArgumentLoc Arg;
3426 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3428 const TemplateArgumentLoc *operator->() const { return &Arg; }
3431 TemplateArgumentLocInventIterator() { }
3433 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3435 : Self(Self), Iter(Iter) { }
3437 TemplateArgumentLocInventIterator &operator++() {
3442 TemplateArgumentLocInventIterator operator++(int) {
3443 TemplateArgumentLocInventIterator Old(*this);
3448 reference operator*() const {
3449 TemplateArgumentLoc Result;
3450 Self.InventTemplateArgumentLoc(*Iter, Result);
3454 pointer operator->() const { return pointer(**this); }
3456 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3457 const TemplateArgumentLocInventIterator &Y) {
3458 return X.Iter == Y.Iter;
3461 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3462 const TemplateArgumentLocInventIterator &Y) {
3463 return X.Iter != Y.Iter;
3467 template<typename Derived>
3468 template<typename InputIterator>
3469 bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3471 TemplateArgumentListInfo &Outputs) {
3472 for (; First != Last; ++First) {
3473 TemplateArgumentLoc Out;
3474 TemplateArgumentLoc In = *First;
3476 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3477 // Unpack argument packs, which we translate them into separate
3479 // FIXME: We could do much better if we could guarantee that the
3480 // TemplateArgumentLocInfo for the pack expansion would be usable for
3481 // all of the template arguments in the argument pack.
3482 typedef TemplateArgumentLocInventIterator<Derived,
3483 TemplateArgument::pack_iterator>
3485 if (TransformTemplateArguments(PackLocIterator(*this,
3486 In.getArgument().pack_begin()),
3487 PackLocIterator(*this,
3488 In.getArgument().pack_end()),
3495 if (In.getArgument().isPackExpansion()) {
3496 // We have a pack expansion, for which we will be substituting into
3498 SourceLocation Ellipsis;
3499 Optional<unsigned> OrigNumExpansions;
3500 TemplateArgumentLoc Pattern
3501 = getSema().getTemplateArgumentPackExpansionPattern(
3502 In, Ellipsis, OrigNumExpansions);
3504 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3505 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3506 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3508 // Determine whether the set of unexpanded parameter packs can and should
3511 bool RetainExpansion = false;
3512 Optional<unsigned> NumExpansions = OrigNumExpansions;
3513 if (getDerived().TryExpandParameterPacks(Ellipsis,
3514 Pattern.getSourceRange(),
3522 // The transform has determined that we should perform a simple
3523 // transformation on the pack expansion, producing another pack
3525 TemplateArgumentLoc OutPattern;
3526 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3527 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3530 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3532 if (Out.getArgument().isNull())
3535 Outputs.addArgument(Out);
3539 // The transform has determined that we should perform an elementwise
3540 // expansion of the pattern. Do so.
3541 for (unsigned I = 0; I != *NumExpansions; ++I) {
3542 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3544 if (getDerived().TransformTemplateArgument(Pattern, Out))
3547 if (Out.getArgument().containsUnexpandedParameterPack()) {
3548 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3550 if (Out.getArgument().isNull())
3554 Outputs.addArgument(Out);
3557 // If we're supposed to retain a pack expansion, do so by temporarily
3558 // forgetting the partially-substituted parameter pack.
3559 if (RetainExpansion) {
3560 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3562 if (getDerived().TransformTemplateArgument(Pattern, Out))
3565 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3567 if (Out.getArgument().isNull())
3570 Outputs.addArgument(Out);
3577 if (getDerived().TransformTemplateArgument(In, Out))
3580 Outputs.addArgument(Out);
3587 //===----------------------------------------------------------------------===//
3588 // Type transformation
3589 //===----------------------------------------------------------------------===//
3591 template<typename Derived>
3592 QualType TreeTransform<Derived>::TransformType(QualType T) {
3593 if (getDerived().AlreadyTransformed(T))
3596 // Temporary workaround. All of these transformations should
3597 // eventually turn into transformations on TypeLocs.
3598 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3599 getDerived().getBaseLocation());
3601 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3606 return NewDI->getType();
3609 template<typename Derived>
3610 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3611 // Refine the base location to the type's location.
3612 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3613 getDerived().getBaseEntity());
3614 if (getDerived().AlreadyTransformed(DI->getType()))
3619 TypeLoc TL = DI->getTypeLoc();
3620 TLB.reserve(TL.getFullDataSize());
3622 QualType Result = getDerived().TransformType(TLB, TL);
3623 if (Result.isNull())
3626 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3629 template<typename Derived>
3631 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3632 switch (T.getTypeLocClass()) {
3633 #define ABSTRACT_TYPELOC(CLASS, PARENT)
3634 #define TYPELOC(CLASS, PARENT) \
3635 case TypeLoc::CLASS: \
3636 return getDerived().Transform##CLASS##Type(TLB, \
3637 T.castAs<CLASS##TypeLoc>());
3638 #include "clang/AST/TypeLocNodes.def"
3641 llvm_unreachable("unhandled type loc!");
3644 /// FIXME: By default, this routine adds type qualifiers only to types
3645 /// that can have qualifiers, and silently suppresses those qualifiers
3646 /// that are not permitted (e.g., qualifiers on reference or function
3647 /// types). This is the right thing for template instantiation, but
3648 /// probably not for other clients.
3649 template<typename Derived>
3651 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
3652 QualifiedTypeLoc T) {
3653 Qualifiers Quals = T.getType().getLocalQualifiers();
3655 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3656 if (Result.isNull())
3659 // Silently suppress qualifiers if the result type can't be qualified.
3660 // FIXME: this is the right thing for template instantiation, but
3661 // probably not for other clients.
3662 if (Result->isFunctionType() || Result->isReferenceType())
3665 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3667 if (Quals.hasObjCLifetime()) {
3668 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3669 Quals.removeObjCLifetime();
3670 else if (Result.getObjCLifetime()) {
3672 // A lifetime qualifier applied to a substituted template parameter
3673 // overrides the lifetime qualifier from the template argument.
3674 const AutoType *AutoTy;
3675 if (const SubstTemplateTypeParmType *SubstTypeParam
3676 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3677 QualType Replacement = SubstTypeParam->getReplacementType();
3678 Qualifiers Qs = Replacement.getQualifiers();
3679 Qs.removeObjCLifetime();
3681 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3683 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3684 SubstTypeParam->getReplacedParameter(),
3686 TLB.TypeWasModifiedSafely(Result);
3687 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3688 // 'auto' types behave the same way as template parameters.
3689 QualType Deduced = AutoTy->getDeducedType();
3690 Qualifiers Qs = Deduced.getQualifiers();
3691 Qs.removeObjCLifetime();
3692 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3694 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3695 AutoTy->isDependentType());
3696 TLB.TypeWasModifiedSafely(Result);
3698 // Otherwise, complain about the addition of a qualifier to an
3699 // already-qualified type.
3700 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
3701 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
3704 Quals.removeObjCLifetime();
3708 if (!Quals.empty()) {
3709 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3710 // BuildQualifiedType might not add qualifiers if they are invalid.
3711 if (Result.hasLocalQualifiers())
3712 TLB.push<QualifiedTypeLoc>(Result);
3713 // No location information to preserve.
3719 template<typename Derived>
3721 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3722 QualType ObjectType,
3723 NamedDecl *UnqualLookup,
3725 if (getDerived().AlreadyTransformed(TL.getType()))
3728 TypeSourceInfo *TSI =
3729 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3731 return TSI->getTypeLoc();
3735 template<typename Derived>
3737 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3738 QualType ObjectType,
3739 NamedDecl *UnqualLookup,
3741 if (getDerived().AlreadyTransformed(TSInfo->getType()))
3744 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3748 template <typename Derived>
3749 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3750 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3752 QualType T = TL.getType();
3753 assert(!getDerived().AlreadyTransformed(T));
3758 if (isa<TemplateSpecializationType>(T)) {
3759 TemplateSpecializationTypeLoc SpecTL =
3760 TL.castAs<TemplateSpecializationTypeLoc>();
3762 TemplateName Template
3763 = getDerived().TransformTemplateName(SS,
3764 SpecTL.getTypePtr()->getTemplateName(),
3765 SpecTL.getTemplateNameLoc(),
3766 ObjectType, UnqualLookup);
3767 if (Template.isNull())
3770 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3772 } else if (isa<DependentTemplateSpecializationType>(T)) {
3773 DependentTemplateSpecializationTypeLoc SpecTL =
3774 TL.castAs<DependentTemplateSpecializationTypeLoc>();
3776 TemplateName Template
3777 = getDerived().RebuildTemplateName(SS,
3778 *SpecTL.getTypePtr()->getIdentifier(),
3779 SpecTL.getTemplateNameLoc(),
3780 ObjectType, UnqualLookup);
3781 if (Template.isNull())
3784 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3789 // Nothing special needs to be done for these.
3790 Result = getDerived().TransformType(TLB, TL);
3793 if (Result.isNull())
3796 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3799 template <class TyLoc> static inline
3800 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3801 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3802 NewT.setNameLoc(T.getNameLoc());
3806 template<typename Derived>
3807 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
3809 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3810 NewT.setBuiltinLoc(T.getBuiltinLoc());
3811 if (T.needsExtraLocalData())
3812 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3816 template<typename Derived>
3817 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
3820 return TransformTypeSpecType(TLB, T);
3823 template <typename Derived>
3824 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3825 AdjustedTypeLoc TL) {
3826 // Adjustments applied during transformation are handled elsewhere.
3827 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3830 template<typename Derived>
3831 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3832 DecayedTypeLoc TL) {
3833 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3834 if (OriginalType.isNull())
3837 QualType Result = TL.getType();
3838 if (getDerived().AlwaysRebuild() ||
3839 OriginalType != TL.getOriginalLoc().getType())
3840 Result = SemaRef.Context.getDecayedType(OriginalType);
3841 TLB.push<DecayedTypeLoc>(Result);
3842 // Nothing to set for DecayedTypeLoc.
3846 template<typename Derived>
3847 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
3848 PointerTypeLoc TL) {
3849 QualType PointeeType
3850 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3851 if (PointeeType.isNull())
3854 QualType Result = TL.getType();
3855 if (PointeeType->getAs<ObjCObjectType>()) {
3856 // A dependent pointer type 'T *' has is being transformed such
3857 // that an Objective-C class type is being replaced for 'T'. The
3858 // resulting pointer type is an ObjCObjectPointerType, not a
3860 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3862 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3863 NewT.setStarLoc(TL.getStarLoc());
3867 if (getDerived().AlwaysRebuild() ||
3868 PointeeType != TL.getPointeeLoc().getType()) {
3869 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3870 if (Result.isNull())
3874 // Objective-C ARC can add lifetime qualifiers to the type that we're
3876 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3878 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3879 NewT.setSigilLoc(TL.getSigilLoc());
3883 template<typename Derived>
3885 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
3886 BlockPointerTypeLoc TL) {
3887 QualType PointeeType
3888 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3889 if (PointeeType.isNull())
3892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
3894 PointeeType != TL.getPointeeLoc().getType()) {
3895 Result = getDerived().RebuildBlockPointerType(PointeeType,
3897 if (Result.isNull())
3901 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3902 NewT.setSigilLoc(TL.getSigilLoc());
3906 /// Transforms a reference type. Note that somewhat paradoxically we
3907 /// don't care whether the type itself is an l-value type or an r-value
3908 /// type; we only care if the type was *written* as an l-value type
3909 /// or an r-value type.
3910 template<typename Derived>
3912 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
3913 ReferenceTypeLoc TL) {
3914 const ReferenceType *T = TL.getTypePtr();
3916 // Note that this works with the pointee-as-written.
3917 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3918 if (PointeeType.isNull())
3921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 PointeeType != T->getPointeeTypeAsWritten()) {
3924 Result = getDerived().RebuildReferenceType(PointeeType,
3925 T->isSpelledAsLValue(),
3927 if (Result.isNull())
3931 // Objective-C ARC can add lifetime qualifiers to the type that we're
3933 TLB.TypeWasModifiedSafely(
3934 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3936 // r-value references can be rebuilt as l-value references.
3937 ReferenceTypeLoc NewTL;
3938 if (isa<LValueReferenceType>(Result))
3939 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3941 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3942 NewTL.setSigilLoc(TL.getSigilLoc());
3947 template<typename Derived>
3949 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
3950 LValueReferenceTypeLoc TL) {
3951 return TransformReferenceType(TLB, TL);
3954 template<typename Derived>
3956 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
3957 RValueReferenceTypeLoc TL) {
3958 return TransformReferenceType(TLB, TL);
3961 template<typename Derived>
3963 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
3964 MemberPointerTypeLoc TL) {
3965 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3966 if (PointeeType.isNull())
3969 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3970 TypeSourceInfo *NewClsTInfo = nullptr;
3972 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3977 const MemberPointerType *T = TL.getTypePtr();
3978 QualType OldClsType = QualType(T->getClass(), 0);
3979 QualType NewClsType;
3981 NewClsType = NewClsTInfo->getType();
3983 NewClsType = getDerived().TransformType(OldClsType);
3984 if (NewClsType.isNull())
3988 QualType Result = TL.getType();
3989 if (getDerived().AlwaysRebuild() ||
3990 PointeeType != T->getPointeeType() ||
3991 NewClsType != OldClsType) {
3992 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
3994 if (Result.isNull())
3998 // If we had to adjust the pointee type when building a member pointer, make
3999 // sure to push TypeLoc info for it.
4000 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4001 if (MPT && PointeeType != MPT->getPointeeType()) {
4002 assert(isa<AdjustedType>(MPT->getPointeeType()));
4003 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4006 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4007 NewTL.setSigilLoc(TL.getSigilLoc());
4008 NewTL.setClassTInfo(NewClsTInfo);
4013 template<typename Derived>
4015 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4016 ConstantArrayTypeLoc TL) {
4017 const ConstantArrayType *T = TL.getTypePtr();
4018 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4019 if (ElementType.isNull())
4022 QualType Result = TL.getType();
4023 if (getDerived().AlwaysRebuild() ||
4024 ElementType != T->getElementType()) {
4025 Result = getDerived().RebuildConstantArrayType(ElementType,
4026 T->getSizeModifier(),
4028 T->getIndexTypeCVRQualifiers(),
4029 TL.getBracketsRange());
4030 if (Result.isNull())
4034 // We might have either a ConstantArrayType or a VariableArrayType now:
4035 // a ConstantArrayType is allowed to have an element type which is a
4036 // VariableArrayType if the type is dependent. Fortunately, all array
4037 // types have the same location layout.
4038 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4039 NewTL.setLBracketLoc(TL.getLBracketLoc());
4040 NewTL.setRBracketLoc(TL.getRBracketLoc());
4042 Expr *Size = TL.getSizeExpr();
4044 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4045 Sema::ConstantEvaluated);
4046 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4047 Size = SemaRef.ActOnConstantExpression(Size).get();
4049 NewTL.setSizeExpr(Size);
4054 template<typename Derived>
4055 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4056 TypeLocBuilder &TLB,
4057 IncompleteArrayTypeLoc TL) {
4058 const IncompleteArrayType *T = TL.getTypePtr();
4059 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4060 if (ElementType.isNull())
4063 QualType Result = TL.getType();
4064 if (getDerived().AlwaysRebuild() ||
4065 ElementType != T->getElementType()) {
4066 Result = getDerived().RebuildIncompleteArrayType(ElementType,
4067 T->getSizeModifier(),
4068 T->getIndexTypeCVRQualifiers(),
4069 TL.getBracketsRange());
4070 if (Result.isNull())
4074 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4075 NewTL.setLBracketLoc(TL.getLBracketLoc());
4076 NewTL.setRBracketLoc(TL.getRBracketLoc());
4077 NewTL.setSizeExpr(nullptr);
4082 template<typename Derived>
4084 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4085 VariableArrayTypeLoc TL) {
4086 const VariableArrayType *T = TL.getTypePtr();
4087 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4088 if (ElementType.isNull())
4091 ExprResult SizeResult
4092 = getDerived().TransformExpr(T->getSizeExpr());
4093 if (SizeResult.isInvalid())
4096 Expr *Size = SizeResult.get();
4098 QualType Result = TL.getType();
4099 if (getDerived().AlwaysRebuild() ||
4100 ElementType != T->getElementType() ||
4101 Size != T->getSizeExpr()) {
4102 Result = getDerived().RebuildVariableArrayType(ElementType,
4103 T->getSizeModifier(),
4105 T->getIndexTypeCVRQualifiers(),
4106 TL.getBracketsRange());
4107 if (Result.isNull())
4111 // We might have constant size array now, but fortunately it has the same
4113 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4114 NewTL.setLBracketLoc(TL.getLBracketLoc());
4115 NewTL.setRBracketLoc(TL.getRBracketLoc());
4116 NewTL.setSizeExpr(Size);
4121 template<typename Derived>
4123 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4124 DependentSizedArrayTypeLoc TL) {
4125 const DependentSizedArrayType *T = TL.getTypePtr();
4126 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4127 if (ElementType.isNull())
4130 // Array bounds are constant expressions.
4131 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4132 Sema::ConstantEvaluated);
4134 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4135 Expr *origSize = TL.getSizeExpr();
4136 if (!origSize) origSize = T->getSizeExpr();
4138 ExprResult sizeResult
4139 = getDerived().TransformExpr(origSize);
4140 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4141 if (sizeResult.isInvalid())
4144 Expr *size = sizeResult.get();
4146 QualType Result = TL.getType();
4147 if (getDerived().AlwaysRebuild() ||
4148 ElementType != T->getElementType() ||
4150 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4151 T->getSizeModifier(),
4153 T->getIndexTypeCVRQualifiers(),
4154 TL.getBracketsRange());
4155 if (Result.isNull())
4159 // We might have any sort of array type now, but fortunately they
4160 // all have the same location layout.
4161 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4162 NewTL.setLBracketLoc(TL.getLBracketLoc());
4163 NewTL.setRBracketLoc(TL.getRBracketLoc());
4164 NewTL.setSizeExpr(size);
4169 template<typename Derived>
4170 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4171 TypeLocBuilder &TLB,
4172 DependentSizedExtVectorTypeLoc TL) {
4173 const DependentSizedExtVectorType *T = TL.getTypePtr();
4175 // FIXME: ext vector locs should be nested
4176 QualType ElementType = getDerived().TransformType(T->getElementType());
4177 if (ElementType.isNull())
4180 // Vector sizes are constant expressions.
4181 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4182 Sema::ConstantEvaluated);
4184 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4185 Size = SemaRef.ActOnConstantExpression(Size);
4186 if (Size.isInvalid())
4189 QualType Result = TL.getType();
4190 if (getDerived().AlwaysRebuild() ||
4191 ElementType != T->getElementType() ||
4192 Size.get() != T->getSizeExpr()) {
4193 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4195 T->getAttributeLoc());
4196 if (Result.isNull())
4200 // Result might be dependent or not.
4201 if (isa<DependentSizedExtVectorType>(Result)) {
4202 DependentSizedExtVectorTypeLoc NewTL
4203 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4204 NewTL.setNameLoc(TL.getNameLoc());
4206 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4207 NewTL.setNameLoc(TL.getNameLoc());
4213 template<typename Derived>
4214 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4216 const VectorType *T = TL.getTypePtr();
4217 QualType ElementType = getDerived().TransformType(T->getElementType());
4218 if (ElementType.isNull())
4221 QualType Result = TL.getType();
4222 if (getDerived().AlwaysRebuild() ||
4223 ElementType != T->getElementType()) {
4224 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4225 T->getVectorKind());
4226 if (Result.isNull())
4230 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4231 NewTL.setNameLoc(TL.getNameLoc());
4236 template<typename Derived>
4237 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4238 ExtVectorTypeLoc TL) {
4239 const VectorType *T = TL.getTypePtr();
4240 QualType ElementType = getDerived().TransformType(T->getElementType());
4241 if (ElementType.isNull())
4244 QualType Result = TL.getType();
4245 if (getDerived().AlwaysRebuild() ||
4246 ElementType != T->getElementType()) {
4247 Result = getDerived().RebuildExtVectorType(ElementType,
4248 T->getNumElements(),
4249 /*FIXME*/ SourceLocation());
4250 if (Result.isNull())
4254 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4255 NewTL.setNameLoc(TL.getNameLoc());
4260 template <typename Derived>
4261 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4262 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4263 bool ExpectParameterPack) {
4264 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4265 TypeSourceInfo *NewDI = nullptr;
4267 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4268 // If we're substituting into a pack expansion type and we know the
4269 // length we want to expand to, just substitute for the pattern.
4270 TypeLoc OldTL = OldDI->getTypeLoc();
4271 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4274 TypeLoc NewTL = OldDI->getTypeLoc();
4275 TLB.reserve(NewTL.getFullDataSize());
4277 QualType Result = getDerived().TransformType(TLB,
4278 OldExpansionTL.getPatternLoc());
4279 if (Result.isNull())
4282 Result = RebuildPackExpansionType(Result,
4283 OldExpansionTL.getPatternLoc().getSourceRange(),
4284 OldExpansionTL.getEllipsisLoc(),
4286 if (Result.isNull())
4289 PackExpansionTypeLoc NewExpansionTL
4290 = TLB.push<PackExpansionTypeLoc>(Result);
4291 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4292 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4294 NewDI = getDerived().TransformType(OldDI);
4298 if (NewDI == OldDI && indexAdjustment == 0)
4301 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4302 OldParm->getDeclContext(),
4303 OldParm->getInnerLocStart(),
4304 OldParm->getLocation(),
4305 OldParm->getIdentifier(),
4308 OldParm->getStorageClass(),
4309 /* DefArg */ nullptr);
4310 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4311 OldParm->getFunctionScopeIndex() + indexAdjustment);
4315 template<typename Derived>
4316 bool TreeTransform<Derived>::
4317 TransformFunctionTypeParams(SourceLocation Loc,
4318 ParmVarDecl **Params, unsigned NumParams,
4319 const QualType *ParamTypes,
4320 SmallVectorImpl<QualType> &OutParamTypes,
4321 SmallVectorImpl<ParmVarDecl*> *PVars) {
4322 int indexAdjustment = 0;
4324 for (unsigned i = 0; i != NumParams; ++i) {
4325 if (ParmVarDecl *OldParm = Params[i]) {
4326 assert(OldParm->getFunctionScopeIndex() == i);
4328 Optional<unsigned> NumExpansions;
4329 ParmVarDecl *NewParm = nullptr;
4330 if (OldParm->isParameterPack()) {
4331 // We have a function parameter pack that may need to be expanded.
4332 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4334 // Find the parameter packs that could be expanded.
4335 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4336 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4337 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4338 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4339 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4341 // Determine whether we should expand the parameter packs.
4342 bool ShouldExpand = false;
4343 bool RetainExpansion = false;
4344 Optional<unsigned> OrigNumExpansions =
4345 ExpansionTL.getTypePtr()->getNumExpansions();
4346 NumExpansions = OrigNumExpansions;
4347 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4348 Pattern.getSourceRange(),
4357 // Expand the function parameter pack into multiple, separate
4359 getDerived().ExpandingFunctionParameterPack(OldParm);
4360 for (unsigned I = 0; I != *NumExpansions; ++I) {
4361 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4362 ParmVarDecl *NewParm
4363 = getDerived().TransformFunctionTypeParam(OldParm,
4366 /*ExpectParameterPack=*/false);
4370 OutParamTypes.push_back(NewParm->getType());
4372 PVars->push_back(NewParm);
4375 // If we're supposed to retain a pack expansion, do so by temporarily
4376 // forgetting the partially-substituted parameter pack.
4377 if (RetainExpansion) {
4378 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4379 ParmVarDecl *NewParm
4380 = getDerived().TransformFunctionTypeParam(OldParm,
4383 /*ExpectParameterPack=*/false);
4387 OutParamTypes.push_back(NewParm->getType());
4389 PVars->push_back(NewParm);
4392 // The next parameter should have the same adjustment as the
4393 // last thing we pushed, but we post-incremented indexAdjustment
4394 // on every push. Also, if we push nothing, the adjustment should
4398 // We're done with the pack expansion.
4402 // We'll substitute the parameter now without expanding the pack
4404 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4405 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4408 /*ExpectParameterPack=*/true);
4410 NewParm = getDerived().TransformFunctionTypeParam(
4411 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4417 OutParamTypes.push_back(NewParm->getType());
4419 PVars->push_back(NewParm);
4423 // Deal with the possibility that we don't have a parameter
4424 // declaration for this parameter.
4425 QualType OldType = ParamTypes[i];
4426 bool IsPackExpansion = false;
4427 Optional<unsigned> NumExpansions;
4429 if (const PackExpansionType *Expansion
4430 = dyn_cast<PackExpansionType>(OldType)) {
4431 // We have a function parameter pack that may need to be expanded.
4432 QualType Pattern = Expansion->getPattern();
4433 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4434 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4436 // Determine whether we should expand the parameter packs.
4437 bool ShouldExpand = false;
4438 bool RetainExpansion = false;
4439 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4448 // Expand the function parameter pack into multiple, separate
4450 for (unsigned I = 0; I != *NumExpansions; ++I) {
4451 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4452 QualType NewType = getDerived().TransformType(Pattern);
4453 if (NewType.isNull())
4456 OutParamTypes.push_back(NewType);
4458 PVars->push_back(nullptr);
4461 // We're done with the pack expansion.
4465 // If we're supposed to retain a pack expansion, do so by temporarily
4466 // forgetting the partially-substituted parameter pack.
4467 if (RetainExpansion) {
4468 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4469 QualType NewType = getDerived().TransformType(Pattern);
4470 if (NewType.isNull())
4473 OutParamTypes.push_back(NewType);
4475 PVars->push_back(nullptr);
4478 // We'll substitute the parameter now without expanding the pack
4480 OldType = Expansion->getPattern();
4481 IsPackExpansion = true;
4482 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4483 NewType = getDerived().TransformType(OldType);
4485 NewType = getDerived().TransformType(OldType);
4488 if (NewType.isNull())
4491 if (IsPackExpansion)
4492 NewType = getSema().Context.getPackExpansionType(NewType,
4495 OutParamTypes.push_back(NewType);
4497 PVars->push_back(nullptr);
4502 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4503 if (ParmVarDecl *parm = (*PVars)[i])
4504 assert(parm->getFunctionScopeIndex() == i);
4511 template<typename Derived>
4513 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4514 FunctionProtoTypeLoc TL) {
4515 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
4518 template<typename Derived>
4520 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4521 FunctionProtoTypeLoc TL,
4522 CXXRecordDecl *ThisContext,
4523 unsigned ThisTypeQuals) {
4524 // Transform the parameters and return type.
4526 // We are required to instantiate the params and return type in source order.
4527 // When the function has a trailing return type, we instantiate the
4528 // parameters before the return type, since the return type can then refer
4529 // to the parameters themselves (via decltype, sizeof, etc.).
4531 SmallVector<QualType, 4> ParamTypes;
4532 SmallVector<ParmVarDecl*, 4> ParamDecls;
4533 const FunctionProtoType *T = TL.getTypePtr();
4535 QualType ResultType;
4537 if (T->hasTrailingReturn()) {
4538 if (getDerived().TransformFunctionTypeParams(
4539 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
4540 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
4544 // C++11 [expr.prim.general]p3:
4545 // If a declaration declares a member function or member function
4546 // template of a class X, the expression this is a prvalue of type
4547 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4548 // and the end of the function-definition, member-declarator, or
4550 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4552 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4553 if (ResultType.isNull())
4558 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4559 if (ResultType.isNull())
4562 if (getDerived().TransformFunctionTypeParams(
4563 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
4564 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
4568 // FIXME: Need to transform the exception-specification too.
4570 QualType Result = TL.getType();
4571 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
4572 T->getNumParams() != ParamTypes.size() ||
4573 !std::equal(T->param_type_begin(), T->param_type_end(),
4574 ParamTypes.begin())) {
4575 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4576 T->getExtProtoInfo());
4577 if (Result.isNull())
4581 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4582 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4583 NewTL.setLParenLoc(TL.getLParenLoc());
4584 NewTL.setRParenLoc(TL.getRParenLoc());
4585 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4586 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4587 NewTL.setParam(i, ParamDecls[i]);
4592 template<typename Derived>
4593 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4594 TypeLocBuilder &TLB,
4595 FunctionNoProtoTypeLoc TL) {
4596 const FunctionNoProtoType *T = TL.getTypePtr();
4597 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4598 if (ResultType.isNull())
4601 QualType Result = TL.getType();
4602 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
4603 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4605 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4606 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4607 NewTL.setLParenLoc(TL.getLParenLoc());
4608 NewTL.setRParenLoc(TL.getRParenLoc());
4609 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4614 template<typename Derived> QualType
4615 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
4616 UnresolvedUsingTypeLoc TL) {
4617 const UnresolvedUsingType *T = TL.getTypePtr();
4618 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4622 QualType Result = TL.getType();
4623 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4624 Result = getDerived().RebuildUnresolvedUsingType(D);
4625 if (Result.isNull())
4629 // We might get an arbitrary type spec type back. We should at
4630 // least always get a type spec type, though.
4631 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4632 NewTL.setNameLoc(TL.getNameLoc());
4637 template<typename Derived>
4638 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
4639 TypedefTypeLoc TL) {
4640 const TypedefType *T = TL.getTypePtr();
4641 TypedefNameDecl *Typedef
4642 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4647 QualType Result = TL.getType();
4648 if (getDerived().AlwaysRebuild() ||
4649 Typedef != T->getDecl()) {
4650 Result = getDerived().RebuildTypedefType(Typedef);
4651 if (Result.isNull())
4655 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4656 NewTL.setNameLoc(TL.getNameLoc());
4661 template<typename Derived>
4662 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
4663 TypeOfExprTypeLoc TL) {
4664 // typeof expressions are not potentially evaluated contexts
4665 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4666 Sema::ReuseLambdaContextDecl);
4668 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4672 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4676 QualType Result = TL.getType();
4677 if (getDerived().AlwaysRebuild() ||
4678 E.get() != TL.getUnderlyingExpr()) {
4679 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4680 if (Result.isNull())
4685 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4686 NewTL.setTypeofLoc(TL.getTypeofLoc());
4687 NewTL.setLParenLoc(TL.getLParenLoc());
4688 NewTL.setRParenLoc(TL.getRParenLoc());
4693 template<typename Derived>
4694 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
4696 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4697 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4701 QualType Result = TL.getType();
4702 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4703 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4704 if (Result.isNull())
4708 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4709 NewTL.setTypeofLoc(TL.getTypeofLoc());
4710 NewTL.setLParenLoc(TL.getLParenLoc());
4711 NewTL.setRParenLoc(TL.getRParenLoc());
4712 NewTL.setUnderlyingTInfo(New_Under_TI);
4717 template<typename Derived>
4718 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
4719 DecltypeTypeLoc TL) {
4720 const DecltypeType *T = TL.getTypePtr();
4722 // decltype expressions are not potentially evaluated contexts
4723 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4724 nullptr, /*IsDecltype=*/ true);
4726 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4730 E = getSema().ActOnDecltypeExpression(E.get());
4734 QualType Result = TL.getType();
4735 if (getDerived().AlwaysRebuild() ||
4736 E.get() != T->getUnderlyingExpr()) {
4737 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4738 if (Result.isNull())
4743 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4744 NewTL.setNameLoc(TL.getNameLoc());
4749 template<typename Derived>
4750 QualType TreeTransform<Derived>::TransformUnaryTransformType(
4751 TypeLocBuilder &TLB,
4752 UnaryTransformTypeLoc TL) {
4753 QualType Result = TL.getType();
4754 if (Result->isDependentType()) {
4755 const UnaryTransformType *T = TL.getTypePtr();
4757 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4758 Result = getDerived().RebuildUnaryTransformType(NewBase,
4761 if (Result.isNull())
4765 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4766 NewTL.setKWLoc(TL.getKWLoc());
4767 NewTL.setParensRange(TL.getParensRange());
4768 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4772 template<typename Derived>
4773 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4775 const AutoType *T = TL.getTypePtr();
4776 QualType OldDeduced = T->getDeducedType();
4777 QualType NewDeduced;
4778 if (!OldDeduced.isNull()) {
4779 NewDeduced = getDerived().TransformType(OldDeduced);
4780 if (NewDeduced.isNull())
4784 QualType Result = TL.getType();
4785 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4786 T->isDependentType()) {
4787 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
4788 if (Result.isNull())
4792 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4793 NewTL.setNameLoc(TL.getNameLoc());
4798 template<typename Derived>
4799 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
4801 const RecordType *T = TL.getTypePtr();
4803 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4808 QualType Result = TL.getType();
4809 if (getDerived().AlwaysRebuild() ||
4810 Record != T->getDecl()) {
4811 Result = getDerived().RebuildRecordType(Record);
4812 if (Result.isNull())
4816 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4817 NewTL.setNameLoc(TL.getNameLoc());
4822 template<typename Derived>
4823 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
4825 const EnumType *T = TL.getTypePtr();
4827 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4832 QualType Result = TL.getType();
4833 if (getDerived().AlwaysRebuild() ||
4834 Enum != T->getDecl()) {
4835 Result = getDerived().RebuildEnumType(Enum);
4836 if (Result.isNull())
4840 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4841 NewTL.setNameLoc(TL.getNameLoc());
4846 template<typename Derived>
4847 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4848 TypeLocBuilder &TLB,
4849 InjectedClassNameTypeLoc TL) {
4850 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4851 TL.getTypePtr()->getDecl());
4852 if (!D) return QualType();
4854 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4855 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4859 template<typename Derived>
4860 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4861 TypeLocBuilder &TLB,
4862 TemplateTypeParmTypeLoc TL) {
4863 return TransformTypeSpecType(TLB, TL);
4866 template<typename Derived>
4867 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4868 TypeLocBuilder &TLB,
4869 SubstTemplateTypeParmTypeLoc TL) {
4870 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4872 // Substitute into the replacement type, which itself might involve something
4873 // that needs to be transformed. This only tends to occur with default
4874 // template arguments of template template parameters.
4875 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4876 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4877 if (Replacement.isNull())
4880 // Always canonicalize the replacement type.
4881 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4883 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4886 // Propagate type-source information.
4887 SubstTemplateTypeParmTypeLoc NewTL
4888 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4889 NewTL.setNameLoc(TL.getNameLoc());
4894 template<typename Derived>
4895 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4896 TypeLocBuilder &TLB,
4897 SubstTemplateTypeParmPackTypeLoc TL) {
4898 return TransformTypeSpecType(TLB, TL);
4901 template<typename Derived>
4902 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4903 TypeLocBuilder &TLB,
4904 TemplateSpecializationTypeLoc TL) {
4905 const TemplateSpecializationType *T = TL.getTypePtr();
4907 // The nested-name-specifier never matters in a TemplateSpecializationType,
4908 // because we can't have a dependent nested-name-specifier anyway.
4910 TemplateName Template
4911 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4912 TL.getTemplateNameLoc());
4913 if (Template.isNull())
4916 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4919 template<typename Derived>
4920 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4922 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4923 if (ValueType.isNull())
4926 QualType Result = TL.getType();
4927 if (getDerived().AlwaysRebuild() ||
4928 ValueType != TL.getValueLoc().getType()) {
4929 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4930 if (Result.isNull())
4934 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4935 NewTL.setKWLoc(TL.getKWLoc());
4936 NewTL.setLParenLoc(TL.getLParenLoc());
4937 NewTL.setRParenLoc(TL.getRParenLoc());
4942 /// \brief Simple iterator that traverses the template arguments in a
4943 /// container that provides a \c getArgLoc() member function.
4945 /// This iterator is intended to be used with the iterator form of
4946 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4947 template<typename ArgLocContainer>
4948 class TemplateArgumentLocContainerIterator {
4949 ArgLocContainer *Container;
4953 typedef TemplateArgumentLoc value_type;
4954 typedef TemplateArgumentLoc reference;
4955 typedef int difference_type;
4956 typedef std::input_iterator_tag iterator_category;
4959 TemplateArgumentLoc Arg;
4962 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4964 const TemplateArgumentLoc *operator->() const {
4970 TemplateArgumentLocContainerIterator() {}
4972 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4974 : Container(&Container), Index(Index) { }
4976 TemplateArgumentLocContainerIterator &operator++() {
4981 TemplateArgumentLocContainerIterator operator++(int) {
4982 TemplateArgumentLocContainerIterator Old(*this);
4987 TemplateArgumentLoc operator*() const {
4988 return Container->getArgLoc(Index);
4991 pointer operator->() const {
4992 return pointer(Container->getArgLoc(Index));
4995 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4996 const TemplateArgumentLocContainerIterator &Y) {
4997 return X.Container == Y.Container && X.Index == Y.Index;
5000 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
5001 const TemplateArgumentLocContainerIterator &Y) {
5007 template <typename Derived>
5008 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5009 TypeLocBuilder &TLB,
5010 TemplateSpecializationTypeLoc TL,
5011 TemplateName Template) {
5012 TemplateArgumentListInfo NewTemplateArgs;
5013 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5014 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5015 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5017 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5018 ArgIterator(TL, TL.getNumArgs()),
5022 // FIXME: maybe don't rebuild if all the template arguments are the same.
5025 getDerived().RebuildTemplateSpecializationType(Template,
5026 TL.getTemplateNameLoc(),
5029 if (!Result.isNull()) {
5030 // Specializations of template template parameters are represented as
5031 // TemplateSpecializationTypes, and substitution of type alias templates
5032 // within a dependent context can transform them into
5033 // DependentTemplateSpecializationTypes.
5034 if (isa<DependentTemplateSpecializationType>(Result)) {
5035 DependentTemplateSpecializationTypeLoc NewTL
5036 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5037 NewTL.setElaboratedKeywordLoc(SourceLocation());
5038 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5039 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5040 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5041 NewTL.setLAngleLoc(TL.getLAngleLoc());
5042 NewTL.setRAngleLoc(TL.getRAngleLoc());
5043 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5044 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5048 TemplateSpecializationTypeLoc NewTL
5049 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5050 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5051 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5052 NewTL.setLAngleLoc(TL.getLAngleLoc());
5053 NewTL.setRAngleLoc(TL.getRAngleLoc());
5054 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5055 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5061 template <typename Derived>
5062 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5063 TypeLocBuilder &TLB,
5064 DependentTemplateSpecializationTypeLoc TL,
5065 TemplateName Template,
5067 TemplateArgumentListInfo NewTemplateArgs;
5068 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5069 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5070 typedef TemplateArgumentLocContainerIterator<
5071 DependentTemplateSpecializationTypeLoc> ArgIterator;
5072 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5073 ArgIterator(TL, TL.getNumArgs()),
5077 // FIXME: maybe don't rebuild if all the template arguments are the same.
5079 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5081 = getSema().Context.getDependentTemplateSpecializationType(
5082 TL.getTypePtr()->getKeyword(),
5083 DTN->getQualifier(),
5084 DTN->getIdentifier(),
5087 DependentTemplateSpecializationTypeLoc NewTL
5088 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5089 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5090 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5091 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5092 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5093 NewTL.setLAngleLoc(TL.getLAngleLoc());
5094 NewTL.setRAngleLoc(TL.getRAngleLoc());
5095 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5096 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5101 = getDerived().RebuildTemplateSpecializationType(Template,
5102 TL.getTemplateNameLoc(),
5105 if (!Result.isNull()) {
5106 /// FIXME: Wrap this in an elaborated-type-specifier?
5107 TemplateSpecializationTypeLoc NewTL
5108 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5109 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5110 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5111 NewTL.setLAngleLoc(TL.getLAngleLoc());
5112 NewTL.setRAngleLoc(TL.getRAngleLoc());
5113 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5114 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5120 template<typename Derived>
5122 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
5123 ElaboratedTypeLoc TL) {
5124 const ElaboratedType *T = TL.getTypePtr();
5126 NestedNameSpecifierLoc QualifierLoc;
5127 // NOTE: the qualifier in an ElaboratedType is optional.
5128 if (TL.getQualifierLoc()) {
5130 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5135 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5136 if (NamedT.isNull())
5139 // C++0x [dcl.type.elab]p2:
5140 // If the identifier resolves to a typedef-name or the simple-template-id
5141 // resolves to an alias template specialization, the
5142 // elaborated-type-specifier is ill-formed.
5143 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5144 if (const TemplateSpecializationType *TST =
5145 NamedT->getAs<TemplateSpecializationType>()) {
5146 TemplateName Template = TST->getTemplateName();
5147 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5148 Template.getAsTemplateDecl())) {
5149 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5150 diag::err_tag_reference_non_tag) << 4;
5151 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5156 QualType Result = TL.getType();
5157 if (getDerived().AlwaysRebuild() ||
5158 QualifierLoc != TL.getQualifierLoc() ||
5159 NamedT != T->getNamedType()) {
5160 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5162 QualifierLoc, NamedT);
5163 if (Result.isNull())
5167 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5168 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5169 NewTL.setQualifierLoc(QualifierLoc);
5173 template<typename Derived>
5174 QualType TreeTransform<Derived>::TransformAttributedType(
5175 TypeLocBuilder &TLB,
5176 AttributedTypeLoc TL) {
5177 const AttributedType *oldType = TL.getTypePtr();
5178 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5179 if (modifiedType.isNull())
5182 QualType result = TL.getType();
5184 // FIXME: dependent operand expressions?
5185 if (getDerived().AlwaysRebuild() ||
5186 modifiedType != oldType->getModifiedType()) {
5187 // TODO: this is really lame; we should really be rebuilding the
5188 // equivalent type from first principles.
5189 QualType equivalentType
5190 = getDerived().TransformType(oldType->getEquivalentType());
5191 if (equivalentType.isNull())
5193 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5198 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5199 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5200 if (TL.hasAttrOperand())
5201 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5202 if (TL.hasAttrExprOperand())
5203 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5204 else if (TL.hasAttrEnumOperand())
5205 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5210 template<typename Derived>
5212 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5214 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5218 QualType Result = TL.getType();
5219 if (getDerived().AlwaysRebuild() ||
5220 Inner != TL.getInnerLoc().getType()) {
5221 Result = getDerived().RebuildParenType(Inner);
5222 if (Result.isNull())
5226 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5227 NewTL.setLParenLoc(TL.getLParenLoc());
5228 NewTL.setRParenLoc(TL.getRParenLoc());
5232 template<typename Derived>
5233 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5234 DependentNameTypeLoc TL) {
5235 const DependentNameType *T = TL.getTypePtr();
5237 NestedNameSpecifierLoc QualifierLoc
5238 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5243 = getDerived().RebuildDependentNameType(T->getKeyword(),
5244 TL.getElaboratedKeywordLoc(),
5248 if (Result.isNull())
5251 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5252 QualType NamedT = ElabT->getNamedType();
5253 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5255 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5256 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5257 NewTL.setQualifierLoc(QualifierLoc);
5259 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5260 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5261 NewTL.setQualifierLoc(QualifierLoc);
5262 NewTL.setNameLoc(TL.getNameLoc());
5267 template<typename Derived>
5268 QualType TreeTransform<Derived>::
5269 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5270 DependentTemplateSpecializationTypeLoc TL) {
5271 NestedNameSpecifierLoc QualifierLoc;
5272 if (TL.getQualifierLoc()) {
5274 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5280 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5283 template<typename Derived>
5284 QualType TreeTransform<Derived>::
5285 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5286 DependentTemplateSpecializationTypeLoc TL,
5287 NestedNameSpecifierLoc QualifierLoc) {
5288 const DependentTemplateSpecializationType *T = TL.getTypePtr();
5290 TemplateArgumentListInfo NewTemplateArgs;
5291 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5292 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5294 typedef TemplateArgumentLocContainerIterator<
5295 DependentTemplateSpecializationTypeLoc> ArgIterator;
5296 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5297 ArgIterator(TL, TL.getNumArgs()),
5302 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5305 TL.getTemplateNameLoc(),
5307 if (Result.isNull())
5310 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5311 QualType NamedT = ElabT->getNamedType();
5313 // Copy information relevant to the template specialization.
5314 TemplateSpecializationTypeLoc NamedTL
5315 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5316 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5317 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5318 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5319 NamedTL.setRAngleLoc(TL.getRAngleLoc());
5320 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5321 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5323 // Copy information relevant to the elaborated type.
5324 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5325 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5326 NewTL.setQualifierLoc(QualifierLoc);
5327 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5328 DependentTemplateSpecializationTypeLoc SpecTL
5329 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5330 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5331 SpecTL.setQualifierLoc(QualifierLoc);
5332 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5333 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5334 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5335 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5336 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5337 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5339 TemplateSpecializationTypeLoc SpecTL
5340 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5341 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5342 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5343 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5344 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5345 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5346 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5351 template<typename Derived>
5352 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5353 PackExpansionTypeLoc TL) {
5355 = getDerived().TransformType(TLB, TL.getPatternLoc());
5356 if (Pattern.isNull())
5359 QualType Result = TL.getType();
5360 if (getDerived().AlwaysRebuild() ||
5361 Pattern != TL.getPatternLoc().getType()) {
5362 Result = getDerived().RebuildPackExpansionType(Pattern,
5363 TL.getPatternLoc().getSourceRange(),
5364 TL.getEllipsisLoc(),
5365 TL.getTypePtr()->getNumExpansions());
5366 if (Result.isNull())
5370 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5371 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5375 template<typename Derived>
5377 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5378 ObjCInterfaceTypeLoc TL) {
5379 // ObjCInterfaceType is never dependent.
5380 TLB.pushFullCopy(TL);
5381 return TL.getType();
5384 template<typename Derived>
5386 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5387 ObjCObjectTypeLoc TL) {
5388 // ObjCObjectType is never dependent.
5389 TLB.pushFullCopy(TL);
5390 return TL.getType();
5393 template<typename Derived>
5395 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
5396 ObjCObjectPointerTypeLoc TL) {
5397 // ObjCObjectPointerType is never dependent.
5398 TLB.pushFullCopy(TL);
5399 return TL.getType();
5402 //===----------------------------------------------------------------------===//
5403 // Statement transformation
5404 //===----------------------------------------------------------------------===//
5405 template<typename Derived>
5407 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
5411 template<typename Derived>
5413 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5414 return getDerived().TransformCompoundStmt(S, false);
5417 template<typename Derived>
5419 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
5421 Sema::CompoundScopeRAII CompoundScope(getSema());
5423 bool SubStmtInvalid = false;
5424 bool SubStmtChanged = false;
5425 SmallVector<Stmt*, 8> Statements;
5426 for (auto *B : S->body()) {
5427 StmtResult Result = getDerived().TransformStmt(B);
5428 if (Result.isInvalid()) {
5429 // Immediately fail if this was a DeclStmt, since it's very
5430 // likely that this will cause problems for future statements.
5431 if (isa<DeclStmt>(B))
5434 // Otherwise, just keep processing substatements and fail later.
5435 SubStmtInvalid = true;
5439 SubStmtChanged = SubStmtChanged || Result.get() != B;
5440 Statements.push_back(Result.getAs<Stmt>());
5446 if (!getDerived().AlwaysRebuild() &&
5450 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5456 template<typename Derived>
5458 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
5459 ExprResult LHS, RHS;
5461 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5462 Sema::ConstantEvaluated);
5464 // Transform the left-hand case value.
5465 LHS = getDerived().TransformExpr(S->getLHS());
5466 LHS = SemaRef.ActOnConstantExpression(LHS);
5467 if (LHS.isInvalid())
5470 // Transform the right-hand case value (for the GNU case-range extension).
5471 RHS = getDerived().TransformExpr(S->getRHS());
5472 RHS = SemaRef.ActOnConstantExpression(RHS);
5473 if (RHS.isInvalid())
5477 // Build the case statement.
5478 // Case statements are always rebuilt so that they will attached to their
5479 // transformed switch statement.
5480 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
5482 S->getEllipsisLoc(),
5485 if (Case.isInvalid())
5488 // Transform the statement following the case
5489 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5490 if (SubStmt.isInvalid())
5493 // Attach the body to the case statement
5494 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
5497 template<typename Derived>
5499 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
5500 // Transform the statement following the default case
5501 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5502 if (SubStmt.isInvalid())
5505 // Default statements are always rebuilt
5506 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
5510 template<typename Derived>
5512 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
5513 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5514 if (SubStmt.isInvalid())
5517 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5523 // FIXME: Pass the real colon location in.
5524 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
5525 cast<LabelDecl>(LD), SourceLocation(),
5529 template<typename Derived>
5531 TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5532 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5533 if (SubStmt.isInvalid())
5536 // TODO: transform attributes
5537 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5540 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5545 template<typename Derived>
5547 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
5548 // Transform the condition
5550 VarDecl *ConditionVar = nullptr;
5551 if (S->getConditionVariable()) {
5553 = cast_or_null<VarDecl>(
5554 getDerived().TransformDefinition(
5555 S->getConditionVariable()->getLocation(),
5556 S->getConditionVariable()));
5560 Cond = getDerived().TransformExpr(S->getCond());
5562 if (Cond.isInvalid())
5565 // Convert the condition to a boolean value.
5567 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
5569 if (CondE.isInvalid())
5576 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
5577 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5580 // Transform the "then" branch.
5581 StmtResult Then = getDerived().TransformStmt(S->getThen());
5582 if (Then.isInvalid())
5585 // Transform the "else" branch.
5586 StmtResult Else = getDerived().TransformStmt(S->getElse());
5587 if (Else.isInvalid())
5590 if (!getDerived().AlwaysRebuild() &&
5591 FullCond.get() == S->getCond() &&
5592 ConditionVar == S->getConditionVariable() &&
5593 Then.get() == S->getThen() &&
5594 Else.get() == S->getElse())
5597 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
5599 S->getElseLoc(), Else.get());
5602 template<typename Derived>
5604 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
5605 // Transform the condition.
5607 VarDecl *ConditionVar = nullptr;
5608 if (S->getConditionVariable()) {
5610 = cast_or_null<VarDecl>(
5611 getDerived().TransformDefinition(
5612 S->getConditionVariable()->getLocation(),
5613 S->getConditionVariable()));
5617 Cond = getDerived().TransformExpr(S->getCond());
5619 if (Cond.isInvalid())
5623 // Rebuild the switch statement.
5625 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5627 if (Switch.isInvalid())
5630 // Transform the body of the switch statement.
5631 StmtResult Body = getDerived().TransformStmt(S->getBody());
5632 if (Body.isInvalid())
5635 // Complete the switch statement.
5636 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5640 template<typename Derived>
5642 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
5643 // Transform the condition
5645 VarDecl *ConditionVar = nullptr;
5646 if (S->getConditionVariable()) {
5648 = cast_or_null<VarDecl>(
5649 getDerived().TransformDefinition(
5650 S->getConditionVariable()->getLocation(),
5651 S->getConditionVariable()));
5655 Cond = getDerived().TransformExpr(S->getCond());
5657 if (Cond.isInvalid())
5661 // Convert the condition to a boolean value.
5662 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5665 if (CondE.isInvalid())
5671 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
5672 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5675 // Transform the body
5676 StmtResult Body = getDerived().TransformStmt(S->getBody());
5677 if (Body.isInvalid())
5680 if (!getDerived().AlwaysRebuild() &&
5681 FullCond.get() == S->getCond() &&
5682 ConditionVar == S->getConditionVariable() &&
5683 Body.get() == S->getBody())
5686 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
5687 ConditionVar, Body.get());
5690 template<typename Derived>
5692 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
5693 // Transform the body
5694 StmtResult Body = getDerived().TransformStmt(S->getBody());
5695 if (Body.isInvalid())
5698 // Transform the condition
5699 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5700 if (Cond.isInvalid())
5703 if (!getDerived().AlwaysRebuild() &&
5704 Cond.get() == S->getCond() &&
5705 Body.get() == S->getBody())
5708 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5709 /*FIXME:*/S->getWhileLoc(), Cond.get(),
5713 template<typename Derived>
5715 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
5716 // Transform the initialization statement
5717 StmtResult Init = getDerived().TransformStmt(S->getInit());
5718 if (Init.isInvalid())
5721 // Transform the condition
5723 VarDecl *ConditionVar = nullptr;
5724 if (S->getConditionVariable()) {
5726 = cast_or_null<VarDecl>(
5727 getDerived().TransformDefinition(
5728 S->getConditionVariable()->getLocation(),
5729 S->getConditionVariable()));
5733 Cond = getDerived().TransformExpr(S->getCond());
5735 if (Cond.isInvalid())
5739 // Convert the condition to a boolean value.
5740 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5743 if (CondE.isInvalid())
5750 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
5751 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5754 // Transform the increment
5755 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5756 if (Inc.isInvalid())
5759 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
5760 if (S->getInc() && !FullInc.get())
5763 // Transform the body
5764 StmtResult Body = getDerived().TransformStmt(S->getBody());
5765 if (Body.isInvalid())
5768 if (!getDerived().AlwaysRebuild() &&
5769 Init.get() == S->getInit() &&
5770 FullCond.get() == S->getCond() &&
5771 Inc.get() == S->getInc() &&
5772 Body.get() == S->getBody())
5775 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
5776 Init.get(), FullCond, ConditionVar,
5777 FullInc, S->getRParenLoc(), Body.get());
5780 template<typename Derived>
5782 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
5783 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5788 // Goto statements must always be rebuilt, to resolve the label.
5789 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
5790 cast<LabelDecl>(LD));
5793 template<typename Derived>
5795 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
5796 ExprResult Target = getDerived().TransformExpr(S->getTarget());
5797 if (Target.isInvalid())
5799 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
5801 if (!getDerived().AlwaysRebuild() &&
5802 Target.get() == S->getTarget())
5805 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
5809 template<typename Derived>
5811 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
5815 template<typename Derived>
5817 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
5821 template<typename Derived>
5823 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
5824 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
5825 if (Result.isInvalid())
5828 // FIXME: We always rebuild the return statement because there is no way
5829 // to tell whether the return type of the function has changed.
5830 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
5833 template<typename Derived>
5835 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
5836 bool DeclChanged = false;
5837 SmallVector<Decl *, 4> Decls;
5838 for (auto *D : S->decls()) {
5839 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
5843 if (Transformed != D)
5846 Decls.push_back(Transformed);
5849 if (!getDerived().AlwaysRebuild() && !DeclChanged)
5852 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
5855 template<typename Derived>
5857 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
5859 SmallVector<Expr*, 8> Constraints;
5860 SmallVector<Expr*, 8> Exprs;
5861 SmallVector<IdentifierInfo *, 4> Names;
5863 ExprResult AsmString;
5864 SmallVector<Expr*, 8> Clobbers;
5866 bool ExprsChanged = false;
5868 // Go through the outputs.
5869 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5870 Names.push_back(S->getOutputIdentifier(I));
5872 // No need to transform the constraint literal.
5873 Constraints.push_back(S->getOutputConstraintLiteral(I));
5875 // Transform the output expr.
5876 Expr *OutputExpr = S->getOutputExpr(I);
5877 ExprResult Result = getDerived().TransformExpr(OutputExpr);
5878 if (Result.isInvalid())
5881 ExprsChanged |= Result.get() != OutputExpr;
5883 Exprs.push_back(Result.get());
5886 // Go through the inputs.
5887 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5888 Names.push_back(S->getInputIdentifier(I));
5890 // No need to transform the constraint literal.
5891 Constraints.push_back(S->getInputConstraintLiteral(I));
5893 // Transform the input expr.
5894 Expr *InputExpr = S->getInputExpr(I);
5895 ExprResult Result = getDerived().TransformExpr(InputExpr);
5896 if (Result.isInvalid())
5899 ExprsChanged |= Result.get() != InputExpr;
5901 Exprs.push_back(Result.get());
5904 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
5907 // Go through the clobbers.
5908 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
5909 Clobbers.push_back(S->getClobberStringLiteral(I));
5911 // No need to transform the asm string literal.
5912 AsmString = S->getAsmString();
5913 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5914 S->isVolatile(), S->getNumOutputs(),
5915 S->getNumInputs(), Names.data(),
5916 Constraints, Exprs, AsmString.get(),
5917 Clobbers, S->getRParenLoc());
5920 template<typename Derived>
5922 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
5923 ArrayRef<Token> AsmToks =
5924 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
5926 bool HadError = false, HadChange = false;
5928 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5929 SmallVector<Expr*, 8> TransformedExprs;
5930 TransformedExprs.reserve(SrcExprs.size());
5931 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5932 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5933 if (!Result.isUsable()) {
5936 HadChange |= (Result.get() != SrcExprs[i]);
5937 TransformedExprs.push_back(Result.get());
5941 if (HadError) return StmtError();
5942 if (!HadChange && !getDerived().AlwaysRebuild())
5945 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5946 AsmToks, S->getAsmString(),
5947 S->getNumOutputs(), S->getNumInputs(),
5948 S->getAllConstraints(), S->getClobbers(),
5949 TransformedExprs, S->getEndLoc());
5952 template<typename Derived>
5954 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
5955 // Transform the body of the @try.
5956 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
5957 if (TryBody.isInvalid())
5960 // Transform the @catch statements (if present).
5961 bool AnyCatchChanged = false;
5962 SmallVector<Stmt*, 8> CatchStmts;
5963 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
5964 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
5965 if (Catch.isInvalid())
5967 if (Catch.get() != S->getCatchStmt(I))
5968 AnyCatchChanged = true;
5969 CatchStmts.push_back(Catch.get());
5972 // Transform the @finally statement (if present).
5974 if (S->getFinallyStmt()) {
5975 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5976 if (Finally.isInvalid())
5980 // If nothing changed, just retain this statement.
5981 if (!getDerived().AlwaysRebuild() &&
5982 TryBody.get() == S->getTryBody() &&
5984 Finally.get() == S->getFinallyStmt())
5987 // Build a new statement.
5988 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5989 CatchStmts, Finally.get());
5992 template<typename Derived>
5994 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5995 // Transform the @catch parameter, if there is one.
5996 VarDecl *Var = nullptr;
5997 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5998 TypeSourceInfo *TSInfo = nullptr;
5999 if (FromVar->getTypeSourceInfo()) {
6000 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6007 T = TSInfo->getType();
6009 T = getDerived().TransformType(FromVar->getType());
6014 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6019 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
6020 if (Body.isInvalid())
6023 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
6028 template<typename Derived>
6030 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
6031 // Transform the body.
6032 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
6033 if (Body.isInvalid())
6036 // If nothing changed, just retain this statement.
6037 if (!getDerived().AlwaysRebuild() &&
6038 Body.get() == S->getFinallyBody())
6041 // Build a new statement.
6042 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
6046 template<typename Derived>
6048 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
6050 if (S->getThrowExpr()) {
6051 Operand = getDerived().TransformExpr(S->getThrowExpr());
6052 if (Operand.isInvalid())
6056 if (!getDerived().AlwaysRebuild() &&
6057 Operand.get() == S->getThrowExpr())
6060 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
6063 template<typename Derived>
6065 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
6066 ObjCAtSynchronizedStmt *S) {
6067 // Transform the object we are locking.
6068 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
6069 if (Object.isInvalid())
6072 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6074 if (Object.isInvalid())
6077 // Transform the body.
6078 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
6079 if (Body.isInvalid())
6082 // If nothing change, just retain the current statement.
6083 if (!getDerived().AlwaysRebuild() &&
6084 Object.get() == S->getSynchExpr() &&
6085 Body.get() == S->getSynchBody())
6088 // Build a new statement.
6089 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
6090 Object.get(), Body.get());
6093 template<typename Derived>
6095 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6096 ObjCAutoreleasePoolStmt *S) {
6097 // Transform the body.
6098 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6099 if (Body.isInvalid())
6102 // If nothing changed, just retain this statement.
6103 if (!getDerived().AlwaysRebuild() &&
6104 Body.get() == S->getSubStmt())
6107 // Build a new statement.
6108 return getDerived().RebuildObjCAutoreleasePoolStmt(
6109 S->getAtLoc(), Body.get());
6112 template<typename Derived>
6114 TreeTransform<Derived>::TransformObjCForCollectionStmt(
6115 ObjCForCollectionStmt *S) {
6116 // Transform the element statement.
6117 StmtResult Element = getDerived().TransformStmt(S->getElement());
6118 if (Element.isInvalid())
6121 // Transform the collection expression.
6122 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
6123 if (Collection.isInvalid())
6126 // Transform the body.
6127 StmtResult Body = getDerived().TransformStmt(S->getBody());
6128 if (Body.isInvalid())
6131 // If nothing changed, just retain this statement.
6132 if (!getDerived().AlwaysRebuild() &&
6133 Element.get() == S->getElement() &&
6134 Collection.get() == S->getCollection() &&
6135 Body.get() == S->getBody())
6138 // Build a new statement.
6139 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6146 template <typename Derived>
6147 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6148 // Transform the exception declaration, if any.
6149 VarDecl *Var = nullptr;
6150 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6152 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6156 Var = getDerived().RebuildExceptionDecl(
6157 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6158 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6159 if (!Var || Var->isInvalidDecl())
6163 // Transform the actual exception handler.
6164 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6165 if (Handler.isInvalid())
6168 if (!getDerived().AlwaysRebuild() && !Var &&
6169 Handler.get() == S->getHandlerBlock())
6172 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6175 template <typename Derived>
6176 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6177 // Transform the try block itself.
6178 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6179 if (TryBlock.isInvalid())
6182 // Transform the handlers.
6183 bool HandlerChanged = false;
6184 SmallVector<Stmt *, 8> Handlers;
6185 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6186 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6187 if (Handler.isInvalid())
6190 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6191 Handlers.push_back(Handler.getAs<Stmt>());
6194 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6198 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6202 template<typename Derived>
6204 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6205 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6206 if (Range.isInvalid())
6209 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6210 if (BeginEnd.isInvalid())
6213 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6214 if (Cond.isInvalid())
6217 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
6218 if (Cond.isInvalid())
6221 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
6223 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6224 if (Inc.isInvalid())
6227 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
6229 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6230 if (LoopVar.isInvalid())
6233 StmtResult NewStmt = S;
6234 if (getDerived().AlwaysRebuild() ||
6235 Range.get() != S->getRangeStmt() ||
6236 BeginEnd.get() != S->getBeginEndStmt() ||
6237 Cond.get() != S->getCond() ||
6238 Inc.get() != S->getInc() ||
6239 LoopVar.get() != S->getLoopVarStmt()) {
6240 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6241 S->getColonLoc(), Range.get(),
6242 BeginEnd.get(), Cond.get(),
6243 Inc.get(), LoopVar.get(),
6245 if (NewStmt.isInvalid())
6249 StmtResult Body = getDerived().TransformStmt(S->getBody());
6250 if (Body.isInvalid())
6253 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6254 // it now so we have a new statement to attach the body to.
6255 if (Body.get() != S->getBody() && NewStmt.get() == S) {
6256 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6257 S->getColonLoc(), Range.get(),
6258 BeginEnd.get(), Cond.get(),
6259 Inc.get(), LoopVar.get(),
6261 if (NewStmt.isInvalid())
6265 if (NewStmt.get() == S)
6268 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6271 template<typename Derived>
6273 TreeTransform<Derived>::TransformMSDependentExistsStmt(
6274 MSDependentExistsStmt *S) {
6275 // Transform the nested-name-specifier, if any.
6276 NestedNameSpecifierLoc QualifierLoc;
6277 if (S->getQualifierLoc()) {
6279 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6284 // Transform the declaration name.
6285 DeclarationNameInfo NameInfo = S->getNameInfo();
6286 if (NameInfo.getName()) {
6287 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6288 if (!NameInfo.getName())
6292 // Check whether anything changed.
6293 if (!getDerived().AlwaysRebuild() &&
6294 QualifierLoc == S->getQualifierLoc() &&
6295 NameInfo.getName() == S->getNameInfo().getName())
6298 // Determine whether this name exists, if we can.
6300 SS.Adopt(QualifierLoc);
6301 bool Dependent = false;
6302 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
6303 case Sema::IER_Exists:
6304 if (S->isIfExists())
6307 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6309 case Sema::IER_DoesNotExist:
6310 if (S->isIfNotExists())
6313 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6315 case Sema::IER_Dependent:
6319 case Sema::IER_Error:
6323 // We need to continue with the instantiation, so do so now.
6324 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6325 if (SubStmt.isInvalid())
6328 // If we have resolved the name, just transform to the substatement.
6332 // The name is still dependent, so build a dependent expression again.
6333 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6340 template<typename Derived>
6342 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6343 NestedNameSpecifierLoc QualifierLoc;
6344 if (E->getQualifierLoc()) {
6346 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6351 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6352 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6356 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6357 if (Base.isInvalid())
6360 return new (SemaRef.getASTContext())
6361 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6362 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6363 QualifierLoc, E->getMemberLoc());
6366 template <typename Derived>
6367 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6368 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6369 if (TryBlock.isInvalid())
6372 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6373 if (Handler.isInvalid())
6376 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6377 Handler.get() == S->getHandler())
6380 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6381 TryBlock.get(), Handler.get());
6384 template <typename Derived>
6385 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6386 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
6387 if (Block.isInvalid())
6390 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
6393 template <typename Derived>
6394 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6395 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6396 if (FilterExpr.isInvalid())
6399 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
6400 if (Block.isInvalid())
6403 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6407 template <typename Derived>
6408 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6409 if (isa<SEHFinallyStmt>(Handler))
6410 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6412 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6415 template<typename Derived>
6417 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6421 //===----------------------------------------------------------------------===//
6422 // OpenMP directive transformation
6423 //===----------------------------------------------------------------------===//
6424 template <typename Derived>
6425 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6426 OMPExecutableDirective *D) {
6428 // Transform the clauses
6429 llvm::SmallVector<OMPClause *, 16> TClauses;
6430 ArrayRef<OMPClause *> Clauses = D->clauses();
6431 TClauses.reserve(Clauses.size());
6432 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6435 OMPClause *Clause = getDerived().TransformOMPClause(*I);
6437 TClauses.push_back(Clause);
6439 TClauses.push_back(nullptr);
6442 StmtResult AssociatedStmt;
6443 if (D->hasAssociatedStmt()) {
6444 if (!D->getAssociatedStmt()) {
6447 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6448 if (AssociatedStmt.isInvalid()) {
6452 if (TClauses.size() != Clauses.size()) {
6456 // Transform directive name for 'omp critical' directive.
6457 DeclarationNameInfo DirName;
6458 if (D->getDirectiveKind() == OMPD_critical) {
6459 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6460 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6463 return getDerived().RebuildOMPExecutableDirective(
6464 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6465 D->getLocStart(), D->getLocEnd());
6468 template <typename Derived>
6470 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6471 DeclarationNameInfo DirName;
6472 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6474 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6475 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6479 template <typename Derived>
6481 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6482 DeclarationNameInfo DirName;
6483 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6485 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6486 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6490 template <typename Derived>
6492 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6493 DeclarationNameInfo DirName;
6494 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6496 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6497 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6501 template <typename Derived>
6503 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6504 DeclarationNameInfo DirName;
6505 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6507 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6508 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6512 template <typename Derived>
6514 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6515 DeclarationNameInfo DirName;
6516 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6518 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6519 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6523 template <typename Derived>
6525 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6526 DeclarationNameInfo DirName;
6527 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6529 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6530 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6534 template <typename Derived>
6536 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6537 DeclarationNameInfo DirName;
6538 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6540 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6541 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6545 template <typename Derived>
6547 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6548 getDerived().getSema().StartOpenMPDSABlock(
6549 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6550 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6551 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6555 template <typename Derived>
6556 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6557 OMPParallelForDirective *D) {
6558 DeclarationNameInfo DirName;
6559 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6560 nullptr, D->getLocStart());
6561 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6562 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6566 template <typename Derived>
6567 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6568 OMPParallelSectionsDirective *D) {
6569 DeclarationNameInfo DirName;
6570 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6571 nullptr, D->getLocStart());
6572 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6573 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6577 template <typename Derived>
6579 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6580 DeclarationNameInfo DirName;
6581 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6583 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6584 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6588 template <typename Derived>
6589 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6590 OMPTaskyieldDirective *D) {
6591 DeclarationNameInfo DirName;
6592 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6594 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6595 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6599 template <typename Derived>
6601 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6602 DeclarationNameInfo DirName;
6603 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6605 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6606 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6610 template <typename Derived>
6612 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6613 DeclarationNameInfo DirName;
6614 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6616 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6617 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6621 template <typename Derived>
6623 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6624 DeclarationNameInfo DirName;
6625 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6627 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6628 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6632 template <typename Derived>
6634 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6635 DeclarationNameInfo DirName;
6636 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6638 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6639 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6643 template <typename Derived>
6645 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6646 DeclarationNameInfo DirName;
6647 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6649 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6650 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6654 //===----------------------------------------------------------------------===//
6655 // OpenMP clause transformation
6656 //===----------------------------------------------------------------------===//
6657 template <typename Derived>
6658 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
6659 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6660 if (Cond.isInvalid())
6662 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
6663 C->getLParenLoc(), C->getLocEnd());
6666 template <typename Derived>
6667 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6668 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6669 if (Cond.isInvalid())
6671 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6672 C->getLParenLoc(), C->getLocEnd());
6675 template <typename Derived>
6677 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6678 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6679 if (NumThreads.isInvalid())
6681 return getDerived().RebuildOMPNumThreadsClause(
6682 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6685 template <typename Derived>
6687 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6688 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6691 return getDerived().RebuildOMPSafelenClause(
6692 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6695 template <typename Derived>
6697 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6698 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6701 return getDerived().RebuildOMPCollapseClause(
6702 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6705 template <typename Derived>
6707 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6708 return getDerived().RebuildOMPDefaultClause(
6709 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6710 C->getLParenLoc(), C->getLocEnd());
6713 template <typename Derived>
6715 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
6716 return getDerived().RebuildOMPProcBindClause(
6717 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6718 C->getLParenLoc(), C->getLocEnd());
6721 template <typename Derived>
6723 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6724 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6727 return getDerived().RebuildOMPScheduleClause(
6728 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6729 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6732 template <typename Derived>
6734 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6735 // No need to rebuild this clause, no template-dependent parameters.
6739 template <typename Derived>
6741 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6742 // No need to rebuild this clause, no template-dependent parameters.
6746 template <typename Derived>
6748 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6749 // No need to rebuild this clause, no template-dependent parameters.
6753 template <typename Derived>
6755 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6756 // No need to rebuild this clause, no template-dependent parameters.
6760 template <typename Derived>
6761 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6762 // No need to rebuild this clause, no template-dependent parameters.
6766 template <typename Derived>
6767 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6768 // No need to rebuild this clause, no template-dependent parameters.
6772 template <typename Derived>
6774 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6775 // No need to rebuild this clause, no template-dependent parameters.
6779 template <typename Derived>
6781 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6782 // No need to rebuild this clause, no template-dependent parameters.
6786 template <typename Derived>
6788 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6789 // No need to rebuild this clause, no template-dependent parameters.
6793 template <typename Derived>
6795 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
6796 llvm::SmallVector<Expr *, 16> Vars;
6797 Vars.reserve(C->varlist_size());
6798 for (auto *VE : C->varlists()) {
6799 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6800 if (EVar.isInvalid())
6802 Vars.push_back(EVar.get());
6804 return getDerived().RebuildOMPPrivateClause(
6805 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6808 template <typename Derived>
6809 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6810 OMPFirstprivateClause *C) {
6811 llvm::SmallVector<Expr *, 16> Vars;
6812 Vars.reserve(C->varlist_size());
6813 for (auto *VE : C->varlists()) {
6814 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6815 if (EVar.isInvalid())
6817 Vars.push_back(EVar.get());
6819 return getDerived().RebuildOMPFirstprivateClause(
6820 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6823 template <typename Derived>
6825 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6826 llvm::SmallVector<Expr *, 16> Vars;
6827 Vars.reserve(C->varlist_size());
6828 for (auto *VE : C->varlists()) {
6829 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6830 if (EVar.isInvalid())
6832 Vars.push_back(EVar.get());
6834 return getDerived().RebuildOMPLastprivateClause(
6835 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6838 template <typename Derived>
6840 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6841 llvm::SmallVector<Expr *, 16> Vars;
6842 Vars.reserve(C->varlist_size());
6843 for (auto *VE : C->varlists()) {
6844 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6845 if (EVar.isInvalid())
6847 Vars.push_back(EVar.get());
6849 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6850 C->getLParenLoc(), C->getLocEnd());
6853 template <typename Derived>
6855 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6856 llvm::SmallVector<Expr *, 16> Vars;
6857 Vars.reserve(C->varlist_size());
6858 for (auto *VE : C->varlists()) {
6859 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6860 if (EVar.isInvalid())
6862 Vars.push_back(EVar.get());
6864 CXXScopeSpec ReductionIdScopeSpec;
6865 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6867 DeclarationNameInfo NameInfo = C->getNameInfo();
6868 if (NameInfo.getName()) {
6869 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6870 if (!NameInfo.getName())
6873 return getDerived().RebuildOMPReductionClause(
6874 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6875 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6878 template <typename Derived>
6880 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6881 llvm::SmallVector<Expr *, 16> Vars;
6882 Vars.reserve(C->varlist_size());
6883 for (auto *VE : C->varlists()) {
6884 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6885 if (EVar.isInvalid())
6887 Vars.push_back(EVar.get());
6889 ExprResult Step = getDerived().TransformExpr(C->getStep());
6890 if (Step.isInvalid())
6892 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6894 C->getColonLoc(), C->getLocEnd());
6897 template <typename Derived>
6899 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6900 llvm::SmallVector<Expr *, 16> Vars;
6901 Vars.reserve(C->varlist_size());
6902 for (auto *VE : C->varlists()) {
6903 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6904 if (EVar.isInvalid())
6906 Vars.push_back(EVar.get());
6908 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6909 if (Alignment.isInvalid())
6911 return getDerived().RebuildOMPAlignedClause(
6912 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6913 C->getColonLoc(), C->getLocEnd());
6916 template <typename Derived>
6918 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6919 llvm::SmallVector<Expr *, 16> Vars;
6920 Vars.reserve(C->varlist_size());
6921 for (auto *VE : C->varlists()) {
6922 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6923 if (EVar.isInvalid())
6925 Vars.push_back(EVar.get());
6927 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6928 C->getLParenLoc(), C->getLocEnd());
6931 template <typename Derived>
6933 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
6934 llvm::SmallVector<Expr *, 16> Vars;
6935 Vars.reserve(C->varlist_size());
6936 for (auto *VE : C->varlists()) {
6937 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6938 if (EVar.isInvalid())
6940 Vars.push_back(EVar.get());
6942 return getDerived().RebuildOMPCopyprivateClause(
6943 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6946 template <typename Derived>
6947 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
6948 llvm::SmallVector<Expr *, 16> Vars;
6949 Vars.reserve(C->varlist_size());
6950 for (auto *VE : C->varlists()) {
6951 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6952 if (EVar.isInvalid())
6954 Vars.push_back(EVar.get());
6956 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
6957 C->getLParenLoc(), C->getLocEnd());
6960 //===----------------------------------------------------------------------===//
6961 // Expression transformation
6962 //===----------------------------------------------------------------------===//
6963 template<typename Derived>
6965 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
6969 template<typename Derived>
6971 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
6972 NestedNameSpecifierLoc QualifierLoc;
6973 if (E->getQualifierLoc()) {
6975 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6981 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6986 DeclarationNameInfo NameInfo = E->getNameInfo();
6987 if (NameInfo.getName()) {
6988 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6989 if (!NameInfo.getName())
6993 if (!getDerived().AlwaysRebuild() &&
6994 QualifierLoc == E->getQualifierLoc() &&
6995 ND == E->getDecl() &&
6996 NameInfo.getName() == E->getDecl()->getDeclName() &&
6997 !E->hasExplicitTemplateArgs()) {
6999 // Mark it referenced in the new context regardless.
7000 // FIXME: this is a bit instantiation-specific.
7001 SemaRef.MarkDeclRefReferenced(E);
7006 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
7007 if (E->hasExplicitTemplateArgs()) {
7008 TemplateArgs = &TransArgs;
7009 TransArgs.setLAngleLoc(E->getLAngleLoc());
7010 TransArgs.setRAngleLoc(E->getRAngleLoc());
7011 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7012 E->getNumTemplateArgs(),
7017 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
7021 template<typename Derived>
7023 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
7027 template<typename Derived>
7029 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
7033 template<typename Derived>
7035 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
7039 template<typename Derived>
7041 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
7045 template<typename Derived>
7047 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
7051 template<typename Derived>
7053 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
7054 if (FunctionDecl *FD = E->getDirectCallee())
7055 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
7056 return SemaRef.MaybeBindToTemporary(E);
7059 template<typename Derived>
7061 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7062 ExprResult ControllingExpr =
7063 getDerived().TransformExpr(E->getControllingExpr());
7064 if (ControllingExpr.isInvalid())
7067 SmallVector<Expr *, 4> AssocExprs;
7068 SmallVector<TypeSourceInfo *, 4> AssocTypes;
7069 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7070 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7072 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7075 AssocTypes.push_back(AssocType);
7077 AssocTypes.push_back(nullptr);
7080 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7081 if (AssocExpr.isInvalid())
7083 AssocExprs.push_back(AssocExpr.get());
7086 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7089 ControllingExpr.get(),
7094 template<typename Derived>
7096 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
7097 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7098 if (SubExpr.isInvalid())
7101 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
7104 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
7108 /// \brief The operand of a unary address-of operator has special rules: it's
7109 /// allowed to refer to a non-static member of a class even if there's no 'this'
7110 /// object available.
7111 template<typename Derived>
7113 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7114 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
7115 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
7117 return getDerived().TransformExpr(E);
7120 template<typename Derived>
7122 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
7124 if (E->getOpcode() == UO_AddrOf)
7125 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7127 SubExpr = TransformExpr(E->getSubExpr());
7128 if (SubExpr.isInvalid())
7131 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
7134 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7139 template<typename Derived>
7141 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7142 // Transform the type.
7143 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7147 // Transform all of the components into components similar to what the
7149 // FIXME: It would be slightly more efficient in the non-dependent case to
7150 // just map FieldDecls, rather than requiring the rebuilder to look for
7151 // the fields again. However, __builtin_offsetof is rare enough in
7152 // template code that we don't care.
7153 bool ExprChanged = false;
7154 typedef Sema::OffsetOfComponent Component;
7155 typedef OffsetOfExpr::OffsetOfNode Node;
7156 SmallVector<Component, 4> Components;
7157 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7158 const Node &ON = E->getComponent(I);
7160 Comp.isBrackets = true;
7161 Comp.LocStart = ON.getSourceRange().getBegin();
7162 Comp.LocEnd = ON.getSourceRange().getEnd();
7163 switch (ON.getKind()) {
7165 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
7166 ExprResult Index = getDerived().TransformExpr(FromIndex);
7167 if (Index.isInvalid())
7170 ExprChanged = ExprChanged || Index.get() != FromIndex;
7171 Comp.isBrackets = true;
7172 Comp.U.E = Index.get();
7177 case Node::Identifier:
7178 Comp.isBrackets = false;
7179 Comp.U.IdentInfo = ON.getFieldName();
7180 if (!Comp.U.IdentInfo)
7186 // Will be recomputed during the rebuild.
7190 Components.push_back(Comp);
7193 // If nothing changed, retain the existing expression.
7194 if (!getDerived().AlwaysRebuild() &&
7195 Type == E->getTypeSourceInfo() &&
7199 // Build a new offsetof expression.
7200 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7201 Components.data(), Components.size(),
7205 template<typename Derived>
7207 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7208 assert(getDerived().AlreadyTransformed(E->getType()) &&
7209 "opaque value expression requires transformation");
7213 template<typename Derived>
7215 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
7216 // Rebuild the syntactic form. The original syntactic form has
7217 // opaque-value expressions in it, so strip those away and rebuild
7218 // the result. This is a really awful way of doing this, but the
7219 // better solution (rebuilding the semantic expressions and
7220 // rebinding OVEs as necessary) doesn't work; we'd need
7221 // TreeTransform to not strip away implicit conversions.
7222 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7223 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
7224 if (result.isInvalid()) return ExprError();
7226 // If that gives us a pseudo-object result back, the pseudo-object
7227 // expression must have been an lvalue-to-rvalue conversion which we
7229 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
7230 result = SemaRef.checkPseudoObjectRValue(result.get());
7235 template<typename Derived>
7237 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7238 UnaryExprOrTypeTraitExpr *E) {
7239 if (E->isArgumentType()) {
7240 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
7242 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7246 if (!getDerived().AlwaysRebuild() && OldT == NewT)
7249 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7251 E->getSourceRange());
7254 // C++0x [expr.sizeof]p1:
7255 // The operand is either an expression, which is an unevaluated operand
7257 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7258 Sema::ReuseLambdaContextDecl);
7260 // Try to recover if we have something like sizeof(T::X) where X is a type.
7261 // Notably, there must be *exactly* one set of parens if X is a type.
7262 TypeSourceInfo *RecoveryTSI = nullptr;
7264 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7266 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7267 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7268 PE, DRE, false, &RecoveryTSI);
7270 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7273 return getDerived().RebuildUnaryExprOrTypeTrait(
7274 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7275 } else if (SubExpr.isInvalid())
7278 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
7281 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7282 E->getOperatorLoc(),
7284 E->getSourceRange());
7287 template<typename Derived>
7289 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
7290 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7291 if (LHS.isInvalid())
7294 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7295 if (RHS.isInvalid())
7299 if (!getDerived().AlwaysRebuild() &&
7300 LHS.get() == E->getLHS() &&
7301 RHS.get() == E->getRHS())
7304 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
7305 /*FIXME:*/E->getLHS()->getLocStart(),
7307 E->getRBracketLoc());
7310 template<typename Derived>
7312 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
7313 // Transform the callee.
7314 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7315 if (Callee.isInvalid())
7318 // Transform arguments.
7319 bool ArgChanged = false;
7320 SmallVector<Expr*, 8> Args;
7321 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7325 if (!getDerived().AlwaysRebuild() &&
7326 Callee.get() == E->getCallee() &&
7328 return SemaRef.MaybeBindToTemporary(E);
7330 // FIXME: Wrong source location information for the '('.
7331 SourceLocation FakeLParenLoc
7332 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7333 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
7338 template<typename Derived>
7340 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
7341 ExprResult Base = getDerived().TransformExpr(E->getBase());
7342 if (Base.isInvalid())
7345 NestedNameSpecifierLoc QualifierLoc;
7346 if (E->hasQualifier()) {
7348 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7353 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
7356 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7357 E->getMemberDecl()));
7361 NamedDecl *FoundDecl = E->getFoundDecl();
7362 if (FoundDecl == E->getMemberDecl()) {
7365 FoundDecl = cast_or_null<NamedDecl>(
7366 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7371 if (!getDerived().AlwaysRebuild() &&
7372 Base.get() == E->getBase() &&
7373 QualifierLoc == E->getQualifierLoc() &&
7374 Member == E->getMemberDecl() &&
7375 FoundDecl == E->getFoundDecl() &&
7376 !E->hasExplicitTemplateArgs()) {
7378 // Mark it referenced in the new context regardless.
7379 // FIXME: this is a bit instantiation-specific.
7380 SemaRef.MarkMemberReferenced(E);
7385 TemplateArgumentListInfo TransArgs;
7386 if (E->hasExplicitTemplateArgs()) {
7387 TransArgs.setLAngleLoc(E->getLAngleLoc());
7388 TransArgs.setRAngleLoc(E->getRAngleLoc());
7389 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7390 E->getNumTemplateArgs(),
7395 // FIXME: Bogus source location for the operator
7396 SourceLocation FakeOperatorLoc =
7397 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
7399 // FIXME: to do this check properly, we will need to preserve the
7400 // first-qualifier-in-scope here, just in case we had a dependent
7401 // base (and therefore couldn't do the check) and a
7402 // nested-name-qualifier (and therefore could do the lookup).
7403 NamedDecl *FirstQualifierInScope = nullptr;
7405 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
7409 E->getMemberNameInfo(),
7412 (E->hasExplicitTemplateArgs()
7413 ? &TransArgs : nullptr),
7414 FirstQualifierInScope);
7417 template<typename Derived>
7419 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
7420 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7421 if (LHS.isInvalid())
7424 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7425 if (RHS.isInvalid())
7428 if (!getDerived().AlwaysRebuild() &&
7429 LHS.get() == E->getLHS() &&
7430 RHS.get() == E->getRHS())
7433 Sema::FPContractStateRAII FPContractState(getSema());
7434 getSema().FPFeatures.fp_contract = E->isFPContractable();
7436 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
7437 LHS.get(), RHS.get());
7440 template<typename Derived>
7442 TreeTransform<Derived>::TransformCompoundAssignOperator(
7443 CompoundAssignOperator *E) {
7444 return getDerived().TransformBinaryOperator(E);
7447 template<typename Derived>
7448 ExprResult TreeTransform<Derived>::
7449 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7450 // Just rebuild the common and RHS expressions and see whether we
7453 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7454 if (commonExpr.isInvalid())
7457 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7458 if (rhs.isInvalid())
7461 if (!getDerived().AlwaysRebuild() &&
7462 commonExpr.get() == e->getCommon() &&
7463 rhs.get() == e->getFalseExpr())
7466 return getDerived().RebuildConditionalOperator(commonExpr.get(),
7467 e->getQuestionLoc(),
7473 template<typename Derived>
7475 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
7476 ExprResult Cond = getDerived().TransformExpr(E->getCond());
7477 if (Cond.isInvalid())
7480 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7481 if (LHS.isInvalid())
7484 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7485 if (RHS.isInvalid())
7488 if (!getDerived().AlwaysRebuild() &&
7489 Cond.get() == E->getCond() &&
7490 LHS.get() == E->getLHS() &&
7491 RHS.get() == E->getRHS())
7494 return getDerived().RebuildConditionalOperator(Cond.get(),
7495 E->getQuestionLoc(),
7501 template<typename Derived>
7503 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
7504 // Implicit casts are eliminated during transformation, since they
7505 // will be recomputed by semantic analysis after transformation.
7506 return getDerived().TransformExpr(E->getSubExprAsWritten());
7509 template<typename Derived>
7511 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
7512 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7517 = getDerived().TransformExpr(E->getSubExprAsWritten());
7518 if (SubExpr.isInvalid())
7521 if (!getDerived().AlwaysRebuild() &&
7522 Type == E->getTypeInfoAsWritten() &&
7523 SubExpr.get() == E->getSubExpr())
7526 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
7532 template<typename Derived>
7534 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
7535 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7536 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7540 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
7541 if (Init.isInvalid())
7544 if (!getDerived().AlwaysRebuild() &&
7546 Init.get() == E->getInitializer())
7547 return SemaRef.MaybeBindToTemporary(E);
7549 // Note: the expression type doesn't necessarily match the
7550 // type-as-written, but that's okay, because it should always be
7551 // derivable from the initializer.
7553 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
7554 /*FIXME:*/E->getInitializer()->getLocEnd(),
7558 template<typename Derived>
7560 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
7561 ExprResult Base = getDerived().TransformExpr(E->getBase());
7562 if (Base.isInvalid())
7565 if (!getDerived().AlwaysRebuild() &&
7566 Base.get() == E->getBase())
7569 // FIXME: Bad source location
7570 SourceLocation FakeOperatorLoc =
7571 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
7572 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
7573 E->getAccessorLoc(),
7577 template<typename Derived>
7579 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
7580 bool InitChanged = false;
7582 SmallVector<Expr*, 4> Inits;
7583 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
7584 Inits, &InitChanged))
7587 if (!getDerived().AlwaysRebuild() && !InitChanged)
7590 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
7591 E->getRBraceLoc(), E->getType());
7594 template<typename Derived>
7596 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
7599 // transform the initializer value
7600 ExprResult Init = getDerived().TransformExpr(E->getInit());
7601 if (Init.isInvalid())
7604 // transform the designators.
7605 SmallVector<Expr*, 4> ArrayExprs;
7606 bool ExprChanged = false;
7607 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7608 DEnd = E->designators_end();
7610 if (D->isFieldDesignator()) {
7611 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7617 if (D->isArrayDesignator()) {
7618 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
7619 if (Index.isInvalid())
7622 Desig.AddDesignator(Designator::getArray(Index.get(),
7623 D->getLBracketLoc()));
7625 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7626 ArrayExprs.push_back(Index.get());
7630 assert(D->isArrayRangeDesignator() && "New kind of designator?");
7632 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7633 if (Start.isInvalid())
7636 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
7637 if (End.isInvalid())
7640 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
7642 D->getLBracketLoc(),
7643 D->getEllipsisLoc()));
7645 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7646 End.get() != E->getArrayRangeEnd(*D);
7648 ArrayExprs.push_back(Start.get());
7649 ArrayExprs.push_back(End.get());
7652 if (!getDerived().AlwaysRebuild() &&
7653 Init.get() == E->getInit() &&
7657 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
7658 E->getEqualOrColonLoc(),
7659 E->usesGNUSyntax(), Init.get());
7662 template<typename Derived>
7664 TreeTransform<Derived>::TransformImplicitValueInitExpr(
7665 ImplicitValueInitExpr *E) {
7666 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
7668 // FIXME: Will we ever have proper type location here? Will we actually
7669 // need to transform the type?
7670 QualType T = getDerived().TransformType(E->getType());
7674 if (!getDerived().AlwaysRebuild() &&
7678 return getDerived().RebuildImplicitValueInitExpr(T);
7681 template<typename Derived>
7683 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
7684 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7688 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7689 if (SubExpr.isInvalid())
7692 if (!getDerived().AlwaysRebuild() &&
7693 TInfo == E->getWrittenTypeInfo() &&
7694 SubExpr.get() == E->getSubExpr())
7697 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
7698 TInfo, E->getRParenLoc());
7701 template<typename Derived>
7703 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
7704 bool ArgumentChanged = false;
7705 SmallVector<Expr*, 4> Inits;
7706 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7710 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
7715 /// \brief Transform an address-of-label expression.
7717 /// By default, the transformation of an address-of-label expression always
7718 /// rebuilds the expression, so that the label identifier can be resolved to
7719 /// the corresponding label statement by semantic analysis.
7720 template<typename Derived>
7722 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
7723 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7728 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
7729 cast<LabelDecl>(LD));
7732 template<typename Derived>
7734 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
7735 SemaRef.ActOnStartStmtExpr();
7737 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
7738 if (SubStmt.isInvalid()) {
7739 SemaRef.ActOnStmtExprError();
7743 if (!getDerived().AlwaysRebuild() &&
7744 SubStmt.get() == E->getSubStmt()) {
7745 // Calling this an 'error' is unintuitive, but it does the right thing.
7746 SemaRef.ActOnStmtExprError();
7747 return SemaRef.MaybeBindToTemporary(E);
7750 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
7755 template<typename Derived>
7757 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
7758 ExprResult Cond = getDerived().TransformExpr(E->getCond());
7759 if (Cond.isInvalid())
7762 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7763 if (LHS.isInvalid())
7766 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7767 if (RHS.isInvalid())
7770 if (!getDerived().AlwaysRebuild() &&
7771 Cond.get() == E->getCond() &&
7772 LHS.get() == E->getLHS() &&
7773 RHS.get() == E->getRHS())
7776 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
7777 Cond.get(), LHS.get(), RHS.get(),
7781 template<typename Derived>
7783 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
7787 template<typename Derived>
7789 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
7790 switch (E->getOperator()) {
7794 case OO_Array_Delete:
7795 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
7798 // This is a call to an object's operator().
7799 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7801 // Transform the object itself.
7802 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
7803 if (Object.isInvalid())
7806 // FIXME: Poor location information
7807 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7808 static_cast<Expr *>(Object.get())->getLocEnd());
7810 // Transform the call arguments.
7811 SmallVector<Expr*, 8> Args;
7812 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
7816 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
7821 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7823 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7824 #include "clang/Basic/OperatorKinds.def"
7829 case OO_Conditional:
7830 llvm_unreachable("conditional operator is not actually overloadable");
7833 case NUM_OVERLOADED_OPERATORS:
7834 llvm_unreachable("not an overloaded operator?");
7837 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7838 if (Callee.isInvalid())
7842 if (E->getOperator() == OO_Amp)
7843 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7845 First = getDerived().TransformExpr(E->getArg(0));
7846 if (First.isInvalid())
7850 if (E->getNumArgs() == 2) {
7851 Second = getDerived().TransformExpr(E->getArg(1));
7852 if (Second.isInvalid())
7856 if (!getDerived().AlwaysRebuild() &&
7857 Callee.get() == E->getCallee() &&
7858 First.get() == E->getArg(0) &&
7859 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
7860 return SemaRef.MaybeBindToTemporary(E);
7862 Sema::FPContractStateRAII FPContractState(getSema());
7863 getSema().FPFeatures.fp_contract = E->isFPContractable();
7865 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7866 E->getOperatorLoc(),
7872 template<typename Derived>
7874 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7875 return getDerived().TransformCallExpr(E);
7878 template<typename Derived>
7880 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7881 // Transform the callee.
7882 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7883 if (Callee.isInvalid())
7886 // Transform exec config.
7887 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7891 // Transform arguments.
7892 bool ArgChanged = false;
7893 SmallVector<Expr*, 8> Args;
7894 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7898 if (!getDerived().AlwaysRebuild() &&
7899 Callee.get() == E->getCallee() &&
7901 return SemaRef.MaybeBindToTemporary(E);
7903 // FIXME: Wrong source location information for the '('.
7904 SourceLocation FakeLParenLoc
7905 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7906 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
7908 E->getRParenLoc(), EC.get());
7911 template<typename Derived>
7913 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
7914 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7919 = getDerived().TransformExpr(E->getSubExprAsWritten());
7920 if (SubExpr.isInvalid())
7923 if (!getDerived().AlwaysRebuild() &&
7924 Type == E->getTypeInfoAsWritten() &&
7925 SubExpr.get() == E->getSubExpr())
7927 return getDerived().RebuildCXXNamedCastExpr(
7928 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
7929 Type, E->getAngleBrackets().getEnd(),
7930 // FIXME. this should be '(' location
7931 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
7934 template<typename Derived>
7936 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7937 return getDerived().TransformCXXNamedCastExpr(E);
7940 template<typename Derived>
7942 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7943 return getDerived().TransformCXXNamedCastExpr(E);
7946 template<typename Derived>
7948 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
7949 CXXReinterpretCastExpr *E) {
7950 return getDerived().TransformCXXNamedCastExpr(E);
7953 template<typename Derived>
7955 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7956 return getDerived().TransformCXXNamedCastExpr(E);
7959 template<typename Derived>
7961 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
7962 CXXFunctionalCastExpr *E) {
7963 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7968 = getDerived().TransformExpr(E->getSubExprAsWritten());
7969 if (SubExpr.isInvalid())
7972 if (!getDerived().AlwaysRebuild() &&
7973 Type == E->getTypeInfoAsWritten() &&
7974 SubExpr.get() == E->getSubExpr())
7977 return getDerived().RebuildCXXFunctionalCastExpr(Type,
7983 template<typename Derived>
7985 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
7986 if (E->isTypeOperand()) {
7987 TypeSourceInfo *TInfo
7988 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7992 if (!getDerived().AlwaysRebuild() &&
7993 TInfo == E->getTypeOperandSourceInfo())
7996 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8002 // We don't know whether the subexpression is potentially evaluated until
8003 // after we perform semantic analysis. We speculatively assume it is
8004 // unevaluated; it will get fixed later if the subexpression is in fact
8005 // potentially evaluated.
8006 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8007 Sema::ReuseLambdaContextDecl);
8009 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8010 if (SubExpr.isInvalid())
8013 if (!getDerived().AlwaysRebuild() &&
8014 SubExpr.get() == E->getExprOperand())
8017 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8023 template<typename Derived>
8025 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8026 if (E->isTypeOperand()) {
8027 TypeSourceInfo *TInfo
8028 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8032 if (!getDerived().AlwaysRebuild() &&
8033 TInfo == E->getTypeOperandSourceInfo())
8036 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8042 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8044 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8045 if (SubExpr.isInvalid())
8048 if (!getDerived().AlwaysRebuild() &&
8049 SubExpr.get() == E->getExprOperand())
8052 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8058 template<typename Derived>
8060 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
8064 template<typename Derived>
8066 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
8067 CXXNullPtrLiteralExpr *E) {
8071 template<typename Derived>
8073 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
8074 QualType T = getSema().getCurrentThisType();
8076 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8077 // Make sure that we capture 'this'.
8078 getSema().CheckCXXThisCapture(E->getLocStart());
8082 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
8085 template<typename Derived>
8087 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
8088 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8089 if (SubExpr.isInvalid())
8092 if (!getDerived().AlwaysRebuild() &&
8093 SubExpr.get() == E->getSubExpr())
8096 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8097 E->isThrownVariableInScope());
8100 template<typename Derived>
8102 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
8104 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8109 if (!getDerived().AlwaysRebuild() &&
8110 Param == E->getParam())
8113 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
8116 template<typename Derived>
8118 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8120 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8125 if (!getDerived().AlwaysRebuild() && Field == E->getField())
8128 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8131 template<typename Derived>
8133 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8134 CXXScalarValueInitExpr *E) {
8135 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8139 if (!getDerived().AlwaysRebuild() &&
8140 T == E->getTypeSourceInfo())
8143 return getDerived().RebuildCXXScalarValueInitExpr(T,
8144 /*FIXME:*/T->getTypeLoc().getEndLoc(),
8148 template<typename Derived>
8150 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
8151 // Transform the type that we're allocating
8152 TypeSourceInfo *AllocTypeInfo
8153 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8157 // Transform the size of the array we're allocating (if any).
8158 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
8159 if (ArraySize.isInvalid())
8162 // Transform the placement arguments (if any).
8163 bool ArgumentChanged = false;
8164 SmallVector<Expr*, 8> PlacementArgs;
8165 if (getDerived().TransformExprs(E->getPlacementArgs(),
8166 E->getNumPlacementArgs(), true,
8167 PlacementArgs, &ArgumentChanged))
8170 // Transform the initializer (if any).
8171 Expr *OldInit = E->getInitializer();
8174 NewInit = getDerived().TransformInitializer(OldInit, true);
8175 if (NewInit.isInvalid())
8178 // Transform new operator and delete operator.
8179 FunctionDecl *OperatorNew = nullptr;
8180 if (E->getOperatorNew()) {
8181 OperatorNew = cast_or_null<FunctionDecl>(
8182 getDerived().TransformDecl(E->getLocStart(),
8183 E->getOperatorNew()));
8188 FunctionDecl *OperatorDelete = nullptr;
8189 if (E->getOperatorDelete()) {
8190 OperatorDelete = cast_or_null<FunctionDecl>(
8191 getDerived().TransformDecl(E->getLocStart(),
8192 E->getOperatorDelete()));
8193 if (!OperatorDelete)
8197 if (!getDerived().AlwaysRebuild() &&
8198 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
8199 ArraySize.get() == E->getArraySize() &&
8200 NewInit.get() == OldInit &&
8201 OperatorNew == E->getOperatorNew() &&
8202 OperatorDelete == E->getOperatorDelete() &&
8204 // Mark any declarations we need as referenced.
8205 // FIXME: instantiation-specific.
8207 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
8209 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
8211 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
8212 QualType ElementType
8213 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8214 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8215 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8216 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
8217 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
8225 QualType AllocType = AllocTypeInfo->getType();
8226 if (!ArraySize.get()) {
8227 // If no array size was specified, but the new expression was
8228 // instantiated with an array type (e.g., "new T" where T is
8229 // instantiated with "int[4]"), extract the outer bound from the
8230 // array type as our array size. We do this with constant and
8231 // dependently-sized array types.
8232 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8235 } else if (const ConstantArrayType *ConsArrayT
8236 = dyn_cast<ConstantArrayType>(ArrayT)) {
8237 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8238 SemaRef.Context.getSizeType(),
8239 /*FIXME:*/ E->getLocStart());
8240 AllocType = ConsArrayT->getElementType();
8241 } else if (const DependentSizedArrayType *DepArrayT
8242 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8243 if (DepArrayT->getSizeExpr()) {
8244 ArraySize = DepArrayT->getSizeExpr();
8245 AllocType = DepArrayT->getElementType();
8250 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8252 /*FIXME:*/E->getLocStart(),
8254 /*FIXME:*/E->getLocStart(),
8255 E->getTypeIdParens(),
8259 E->getDirectInitRange(),
8263 template<typename Derived>
8265 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
8266 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
8267 if (Operand.isInvalid())
8270 // Transform the delete operator, if known.
8271 FunctionDecl *OperatorDelete = nullptr;
8272 if (E->getOperatorDelete()) {
8273 OperatorDelete = cast_or_null<FunctionDecl>(
8274 getDerived().TransformDecl(E->getLocStart(),
8275 E->getOperatorDelete()));
8276 if (!OperatorDelete)
8280 if (!getDerived().AlwaysRebuild() &&
8281 Operand.get() == E->getArgument() &&
8282 OperatorDelete == E->getOperatorDelete()) {
8283 // Mark any declarations we need as referenced.
8284 // FIXME: instantiation-specific.
8286 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
8288 if (!E->getArgument()->isTypeDependent()) {
8289 QualType Destroyed = SemaRef.Context.getBaseElementType(
8290 E->getDestroyedType());
8291 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8292 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
8293 SemaRef.MarkFunctionReferenced(E->getLocStart(),
8294 SemaRef.LookupDestructor(Record));
8301 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8302 E->isGlobalDelete(),
8307 template<typename Derived>
8309 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
8310 CXXPseudoDestructorExpr *E) {
8311 ExprResult Base = getDerived().TransformExpr(E->getBase());
8312 if (Base.isInvalid())
8315 ParsedType ObjectTypePtr;
8316 bool MayBePseudoDestructor = false;
8317 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
8318 E->getOperatorLoc(),
8319 E->isArrow()? tok::arrow : tok::period,
8321 MayBePseudoDestructor);
8322 if (Base.isInvalid())
8325 QualType ObjectType = ObjectTypePtr.get();
8326 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8329 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8334 SS.Adopt(QualifierLoc);
8336 PseudoDestructorTypeStorage Destroyed;
8337 if (E->getDestroyedTypeInfo()) {
8338 TypeSourceInfo *DestroyedTypeInfo
8339 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
8340 ObjectType, nullptr, SS);
8341 if (!DestroyedTypeInfo)
8343 Destroyed = DestroyedTypeInfo;
8344 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
8345 // We aren't likely to be able to resolve the identifier down to a type
8346 // now anyway, so just retain the identifier.
8347 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8348 E->getDestroyedTypeLoc());
8350 // Look for a destructor known with the given name.
8351 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
8352 *E->getDestroyedTypeIdentifier(),
8353 E->getDestroyedTypeLoc(),
8361 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8362 E->getDestroyedTypeLoc());
8365 TypeSourceInfo *ScopeTypeInfo = nullptr;
8366 if (E->getScopeTypeInfo()) {
8367 CXXScopeSpec EmptySS;
8368 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
8369 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
8374 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
8375 E->getOperatorLoc(),
8379 E->getColonColonLoc(),
8384 template<typename Derived>
8386 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
8387 UnresolvedLookupExpr *Old) {
8388 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8389 Sema::LookupOrdinaryName);
8391 // Transform all the decls.
8392 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8393 E = Old->decls_end(); I != E; ++I) {
8394 NamedDecl *InstD = static_cast<NamedDecl*>(
8395 getDerived().TransformDecl(Old->getNameLoc(),
8398 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8399 // This can happen because of dependent hiding.
8400 if (isa<UsingShadowDecl>(*I))
8408 // Expand using declarations.
8409 if (isa<UsingDecl>(InstD)) {
8410 UsingDecl *UD = cast<UsingDecl>(InstD);
8411 for (auto *I : UD->shadows())
8419 // Resolve a kind, but don't do any further analysis. If it's
8420 // ambiguous, the callee needs to deal with it.
8423 // Rebuild the nested-name qualifier, if present.
8425 if (Old->getQualifierLoc()) {
8426 NestedNameSpecifierLoc QualifierLoc
8427 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8431 SS.Adopt(QualifierLoc);
8434 if (Old->getNamingClass()) {
8435 CXXRecordDecl *NamingClass
8436 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8438 Old->getNamingClass()));
8444 R.setNamingClass(NamingClass);
8447 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8449 // If we have neither explicit template arguments, nor the template keyword,
8450 // it's a normal declaration name.
8451 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
8452 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8454 // If we have template arguments, rebuild them, then rebuild the
8455 // templateid expression.
8456 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
8457 if (Old->hasExplicitTemplateArgs() &&
8458 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8459 Old->getNumTemplateArgs(),
8465 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
8466 Old->requiresADL(), &TransArgs);
8469 template<typename Derived>
8471 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8472 bool ArgChanged = false;
8473 SmallVector<TypeSourceInfo *, 4> Args;
8474 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8475 TypeSourceInfo *From = E->getArg(I);
8476 TypeLoc FromTL = From->getTypeLoc();
8477 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
8479 TLB.reserve(FromTL.getFullDataSize());
8480 QualType To = getDerived().TransformType(TLB, FromTL);
8484 if (To == From->getType())
8485 Args.push_back(From);
8487 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8495 // We have a pack expansion. Instantiate it.
8496 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
8497 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8498 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8499 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
8501 // Determine whether the set of unexpanded parameter packs can and should
8504 bool RetainExpansion = false;
8505 Optional<unsigned> OrigNumExpansions =
8506 ExpansionTL.getTypePtr()->getNumExpansions();
8507 Optional<unsigned> NumExpansions = OrigNumExpansions;
8508 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8509 PatternTL.getSourceRange(),
8511 Expand, RetainExpansion,
8516 // The transform has determined that we should perform a simple
8517 // transformation on the pack expansion, producing another pack
8519 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8522 TLB.reserve(From->getTypeLoc().getFullDataSize());
8524 QualType To = getDerived().TransformType(TLB, PatternTL);
8528 To = getDerived().RebuildPackExpansionType(To,
8529 PatternTL.getSourceRange(),
8530 ExpansionTL.getEllipsisLoc(),
8535 PackExpansionTypeLoc ToExpansionTL
8536 = TLB.push<PackExpansionTypeLoc>(To);
8537 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8538 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8542 // Expand the pack expansion by substituting for each argument in the
8544 for (unsigned I = 0; I != *NumExpansions; ++I) {
8545 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8547 TLB.reserve(PatternTL.getFullDataSize());
8548 QualType To = getDerived().TransformType(TLB, PatternTL);
8552 if (To->containsUnexpandedParameterPack()) {
8553 To = getDerived().RebuildPackExpansionType(To,
8554 PatternTL.getSourceRange(),
8555 ExpansionTL.getEllipsisLoc(),
8560 PackExpansionTypeLoc ToExpansionTL
8561 = TLB.push<PackExpansionTypeLoc>(To);
8562 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8565 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8568 if (!RetainExpansion)
8571 // If we're supposed to retain a pack expansion, do so by temporarily
8572 // forgetting the partially-substituted parameter pack.
8573 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8576 TLB.reserve(From->getTypeLoc().getFullDataSize());
8578 QualType To = getDerived().TransformType(TLB, PatternTL);
8582 To = getDerived().RebuildPackExpansionType(To,
8583 PatternTL.getSourceRange(),
8584 ExpansionTL.getEllipsisLoc(),
8589 PackExpansionTypeLoc ToExpansionTL
8590 = TLB.push<PackExpansionTypeLoc>(To);
8591 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8592 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8595 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8598 return getDerived().RebuildTypeTrait(E->getTrait(),
8604 template<typename Derived>
8606 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8607 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8611 if (!getDerived().AlwaysRebuild() &&
8612 T == E->getQueriedTypeSourceInfo())
8617 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8618 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8619 if (SubExpr.isInvalid())
8622 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8626 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8633 template<typename Derived>
8635 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8638 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8639 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8640 if (SubExpr.isInvalid())
8643 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8647 return getDerived().RebuildExpressionTrait(
8648 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8651 template <typename Derived>
8652 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8653 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8654 TypeSourceInfo **RecoveryTSI) {
8655 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8656 DRE, AddrTaken, RecoveryTSI);
8658 // Propagate both errors and recovered types, which return ExprEmpty.
8659 if (!NewDRE.isUsable())
8662 // We got an expr, wrap it up in parens.
8663 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8665 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8669 template <typename Derived>
8670 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8671 DependentScopeDeclRefExpr *E) {
8672 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8676 template<typename Derived>
8678 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8679 DependentScopeDeclRefExpr *E,
8680 bool IsAddressOfOperand,
8681 TypeSourceInfo **RecoveryTSI) {
8682 assert(E->getQualifierLoc());
8683 NestedNameSpecifierLoc QualifierLoc
8684 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8687 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8689 // TODO: If this is a conversion-function-id, verify that the
8690 // destination type name (if present) resolves the same way after
8691 // instantiation as it did in the local scope.
8693 DeclarationNameInfo NameInfo
8694 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8695 if (!NameInfo.getName())
8698 if (!E->hasExplicitTemplateArgs()) {
8699 if (!getDerived().AlwaysRebuild() &&
8700 QualifierLoc == E->getQualifierLoc() &&
8701 // Note: it is sufficient to compare the Name component of NameInfo:
8702 // if name has not changed, DNLoc has not changed either.
8703 NameInfo.getName() == E->getDeclName())
8706 return getDerived().RebuildDependentScopeDeclRefExpr(
8707 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8708 IsAddressOfOperand, RecoveryTSI);
8711 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8712 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8713 E->getNumTemplateArgs(),
8717 return getDerived().RebuildDependentScopeDeclRefExpr(
8718 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8722 template<typename Derived>
8724 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
8725 // CXXConstructExprs other than for list-initialization and
8726 // CXXTemporaryObjectExpr are always implicit, so when we have
8727 // a 1-argument construction we just transform that argument.
8728 if ((E->getNumArgs() == 1 ||
8729 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
8730 (!getDerived().DropCallArgument(E->getArg(0))) &&
8731 !E->isListInitialization())
8732 return getDerived().TransformExpr(E->getArg(0));
8734 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8736 QualType T = getDerived().TransformType(E->getType());
8740 CXXConstructorDecl *Constructor
8741 = cast_or_null<CXXConstructorDecl>(
8742 getDerived().TransformDecl(E->getLocStart(),
8743 E->getConstructor()));
8747 bool ArgumentChanged = false;
8748 SmallVector<Expr*, 8> Args;
8749 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8753 if (!getDerived().AlwaysRebuild() &&
8754 T == E->getType() &&
8755 Constructor == E->getConstructor() &&
8757 // Mark the constructor as referenced.
8758 // FIXME: Instantiation-specific
8759 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
8763 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8764 Constructor, E->isElidable(),
8766 E->hadMultipleCandidates(),
8767 E->isListInitialization(),
8768 E->isStdInitListInitialization(),
8769 E->requiresZeroInitialization(),
8770 E->getConstructionKind(),
8771 E->getParenOrBraceRange());
8774 /// \brief Transform a C++ temporary-binding expression.
8776 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8777 /// transform the subexpression and return that.
8778 template<typename Derived>
8780 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
8781 return getDerived().TransformExpr(E->getSubExpr());
8784 /// \brief Transform a C++ expression that contains cleanups that should
8785 /// be run after the expression is evaluated.
8787 /// Since ExprWithCleanups nodes are implicitly generated, we
8788 /// just transform the subexpression and return that.
8789 template<typename Derived>
8791 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
8792 return getDerived().TransformExpr(E->getSubExpr());
8795 template<typename Derived>
8797 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
8798 CXXTemporaryObjectExpr *E) {
8799 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8803 CXXConstructorDecl *Constructor
8804 = cast_or_null<CXXConstructorDecl>(
8805 getDerived().TransformDecl(E->getLocStart(),
8806 E->getConstructor()));
8810 bool ArgumentChanged = false;
8811 SmallVector<Expr*, 8> Args;
8812 Args.reserve(E->getNumArgs());
8813 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8817 if (!getDerived().AlwaysRebuild() &&
8818 T == E->getTypeSourceInfo() &&
8819 Constructor == E->getConstructor() &&
8821 // FIXME: Instantiation-specific
8822 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
8823 return SemaRef.MaybeBindToTemporary(E);
8826 // FIXME: Pass in E->isListInitialization().
8827 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8828 /*FIXME:*/T->getTypeLoc().getEndLoc(),
8833 template<typename Derived>
8835 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
8837 // Transform any init-capture expressions before entering the scope of the
8838 // lambda body, because they are not semantically within that scope.
8839 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8840 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8841 E->explicit_capture_begin());
8843 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8844 CEnd = E->capture_end();
8846 if (!C->isInitCapture())
8848 EnterExpressionEvaluationContext EEEC(getSema(),
8849 Sema::PotentiallyEvaluated);
8850 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8851 C->getCapturedVar()->getInit(),
8852 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8854 if (NewExprInitResult.isInvalid())
8856 Expr *NewExprInit = NewExprInitResult.get();
8858 VarDecl *OldVD = C->getCapturedVar();
8859 QualType NewInitCaptureType =
8860 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8861 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8863 NewExprInitResult = NewExprInit;
8864 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8865 std::make_pair(NewExprInitResult, NewInitCaptureType);
8869 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
8870 // Transform the template parameters, and add them to the current
8871 // instantiation scope. The null case is handled correctly.
8872 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8873 E->getTemplateParameterList());
8875 // Check to see if the TypeSourceInfo of the call operator needs to
8876 // be transformed, and if so do the transformation in the
8877 // CurrentInstantiationScope.
8879 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8880 FunctionProtoTypeLoc OldCallOpFPTL =
8881 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8882 TypeSourceInfo *NewCallOpTSI = nullptr;
8884 const bool CallOpWasAlreadyTransformed =
8885 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8887 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8888 if (CallOpWasAlreadyTransformed)
8889 NewCallOpTSI = OldCallOpTSI;
8891 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8892 // The transformation MUST be done in the CurrentInstantiationScope since
8893 // it introduces a mapping of the original to the newly created
8894 // transformed parameters.
8896 TypeLocBuilder NewCallOpTLBuilder;
8897 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8900 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8903 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8904 // the vector below - this will be used to synthesize the
8905 // NewCallOperator. Additionally, add the parameters of the untransformed
8906 // lambda call operator to the CurrentInstantiationScope.
8907 SmallVector<ParmVarDecl *, 4> Params;
8909 FunctionProtoTypeLoc NewCallOpFPTL =
8910 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8911 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8912 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
8914 for (unsigned I = 0; I < NewNumArgs; ++I) {
8915 // If this call operator's type does not require transformation,
8916 // the parameters do not get added to the current instantiation scope,
8917 // - so ADD them! This allows the following to compile when the enclosing
8918 // template is specialized and the entire lambda expression has to be
8920 // template<class T> void foo(T t) {
8921 // auto L = [](auto a) {
8922 // auto M = [](char b) { <-- note: non-generic lambda
8923 // auto N = [](auto c) {
8924 // int x = sizeof(a);
8925 // x = sizeof(b); <-- specifically this line
8932 if (CallOpWasAlreadyTransformed)
8933 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8934 NewParamDeclArray[I]);
8935 // Add to Params array, so these parameters can be used to create
8936 // the newly transformed call operator.
8937 Params.push_back(NewParamDeclArray[I]);
8944 // Create the local class that will describe the lambda.
8945 CXXRecordDecl *Class
8946 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8948 /*KnownDependent=*/false,
8949 E->getCaptureDefault());
8951 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8953 // Build the call operator.
8954 CXXMethodDecl *NewCallOperator
8955 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
8957 E->getCallOperator()->getLocEnd(),
8959 LSI->CallOperator = NewCallOperator;
8961 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8963 return getDerived().TransformLambdaScope(E, NewCallOperator,
8964 InitCaptureExprsAndTypes);
8967 template<typename Derived>
8969 TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8970 CXXMethodDecl *CallOperator,
8971 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
8972 bool Invalid = false;
8974 // Introduce the context of the call operator.
8975 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8976 /*NewThisContext*/false);
8978 LambdaScopeInfo *const LSI = getSema().getCurLambda();
8979 // Enter the scope of the lambda.
8980 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
8981 E->getCaptureDefault(),
8982 E->getCaptureDefaultLoc(),
8983 E->hasExplicitParameters(),
8984 E->hasExplicitResultType(),
8987 // Transform captures.
8988 bool FinishedExplicitCaptures = false;
8989 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8990 CEnd = E->capture_end();
8992 // When we hit the first implicit capture, tell Sema that we've finished
8993 // the list of explicit captures.
8994 if (!FinishedExplicitCaptures && C->isImplicit()) {
8995 getSema().finishLambdaExplicitCaptures(LSI);
8996 FinishedExplicitCaptures = true;
8999 // Capturing 'this' is trivial.
9000 if (C->capturesThis()) {
9001 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9005 // Rebuild init-captures, including the implied field declaration.
9006 if (C->isInitCapture()) {
9008 InitCaptureInfoTy InitExprTypePair =
9009 InitCaptureExprsAndTypes[C - E->capture_begin()];
9010 ExprResult Init = InitExprTypePair.first;
9011 QualType InitQualType = InitExprTypePair.second;
9012 if (Init.isInvalid() || InitQualType.isNull()) {
9016 VarDecl *OldVD = C->getCapturedVar();
9017 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9018 OldVD->getLocation(), InitExprTypePair.second,
9019 OldVD->getIdentifier(), Init.get());
9023 getDerived().transformedLocalDecl(OldVD, NewVD);
9025 getSema().buildInitCaptureField(LSI, NewVD);
9029 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9031 // Determine the capture kind for Sema.
9032 Sema::TryCaptureKind Kind
9033 = C->isImplicit()? Sema::TryCapture_Implicit
9034 : C->getCaptureKind() == LCK_ByCopy
9035 ? Sema::TryCapture_ExplicitByVal
9036 : Sema::TryCapture_ExplicitByRef;
9037 SourceLocation EllipsisLoc;
9038 if (C->isPackExpansion()) {
9039 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9040 bool ShouldExpand = false;
9041 bool RetainExpansion = false;
9042 Optional<unsigned> NumExpansions;
9043 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9046 ShouldExpand, RetainExpansion,
9053 // The transform has determined that we should perform an expansion;
9054 // transform and capture each of the arguments.
9055 // expansion of the pattern. Do so.
9056 VarDecl *Pack = C->getCapturedVar();
9057 for (unsigned I = 0; I != *NumExpansions; ++I) {
9058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9059 VarDecl *CapturedVar
9060 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
9067 // Capture the transformed variable.
9068 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9071 // FIXME: Retain a pack expansion if RetainExpansion is true.
9076 EllipsisLoc = C->getEllipsisLoc();
9079 // Transform the captured variable.
9080 VarDecl *CapturedVar
9081 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
9082 C->getCapturedVar()));
9088 // Capture the transformed variable.
9089 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9091 if (!FinishedExplicitCaptures)
9092 getSema().finishLambdaExplicitCaptures(LSI);
9095 // Enter a new evaluation context to insulate the lambda from any
9096 // cleanups from the enclosing full-expression.
9097 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
9100 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
9101 /*IsInstantiation=*/true);
9105 // Instantiate the body of the lambda expression.
9106 StmtResult Body = getDerived().TransformStmt(E->getBody());
9107 if (Body.isInvalid()) {
9108 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
9109 /*IsInstantiation=*/true);
9113 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
9114 /*CurScope=*/nullptr,
9115 /*IsInstantiation=*/true);
9118 template<typename Derived>
9120 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
9121 CXXUnresolvedConstructExpr *E) {
9122 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9126 bool ArgumentChanged = false;
9127 SmallVector<Expr*, 8> Args;
9128 Args.reserve(E->arg_size());
9129 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
9133 if (!getDerived().AlwaysRebuild() &&
9134 T == E->getTypeSourceInfo() &&
9138 // FIXME: we're faking the locations of the commas
9139 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
9145 template<typename Derived>
9147 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
9148 CXXDependentScopeMemberExpr *E) {
9149 // Transform the base of the expression.
9150 ExprResult Base((Expr*) nullptr);
9153 QualType ObjectType;
9154 if (!E->isImplicitAccess()) {
9155 OldBase = E->getBase();
9156 Base = getDerived().TransformExpr(OldBase);
9157 if (Base.isInvalid())
9160 // Start the member reference and compute the object's type.
9161 ParsedType ObjectTy;
9162 bool MayBePseudoDestructor = false;
9163 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
9164 E->getOperatorLoc(),
9165 E->isArrow()? tok::arrow : tok::period,
9167 MayBePseudoDestructor);
9168 if (Base.isInvalid())
9171 ObjectType = ObjectTy.get();
9172 BaseType = ((Expr*) Base.get())->getType();
9175 BaseType = getDerived().TransformType(E->getBaseType());
9176 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9179 // Transform the first part of the nested-name-specifier that qualifies
9181 NamedDecl *FirstQualifierInScope
9182 = getDerived().TransformFirstQualifierInScope(
9183 E->getFirstQualifierFoundInScope(),
9184 E->getQualifierLoc().getBeginLoc());
9186 NestedNameSpecifierLoc QualifierLoc;
9187 if (E->getQualifier()) {
9189 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9191 FirstQualifierInScope);
9196 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9198 // TODO: If this is a conversion-function-id, verify that the
9199 // destination type name (if present) resolves the same way after
9200 // instantiation as it did in the local scope.
9202 DeclarationNameInfo NameInfo
9203 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
9204 if (!NameInfo.getName())
9207 if (!E->hasExplicitTemplateArgs()) {
9208 // This is a reference to a member without an explicitly-specified
9209 // template argument list. Optimize for this common case.
9210 if (!getDerived().AlwaysRebuild() &&
9211 Base.get() == OldBase &&
9212 BaseType == E->getBaseType() &&
9213 QualifierLoc == E->getQualifierLoc() &&
9214 NameInfo.getName() == E->getMember() &&
9215 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
9218 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
9221 E->getOperatorLoc(),
9224 FirstQualifierInScope,
9226 /*TemplateArgs*/nullptr);
9229 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
9230 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9231 E->getNumTemplateArgs(),
9235 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
9238 E->getOperatorLoc(),
9241 FirstQualifierInScope,
9246 template<typename Derived>
9248 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
9249 // Transform the base of the expression.
9250 ExprResult Base((Expr*) nullptr);
9252 if (!Old->isImplicitAccess()) {
9253 Base = getDerived().TransformExpr(Old->getBase());
9254 if (Base.isInvalid())
9256 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
9258 if (Base.isInvalid())
9260 BaseType = Base.get()->getType();
9262 BaseType = getDerived().TransformType(Old->getBaseType());
9265 NestedNameSpecifierLoc QualifierLoc;
9266 if (Old->getQualifierLoc()) {
9268 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9273 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9275 LookupResult R(SemaRef, Old->getMemberNameInfo(),
9276 Sema::LookupOrdinaryName);
9278 // Transform all the decls.
9279 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9280 E = Old->decls_end(); I != E; ++I) {
9281 NamedDecl *InstD = static_cast<NamedDecl*>(
9282 getDerived().TransformDecl(Old->getMemberLoc(),
9285 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9286 // This can happen because of dependent hiding.
9287 if (isa<UsingShadowDecl>(*I))
9295 // Expand using declarations.
9296 if (isa<UsingDecl>(InstD)) {
9297 UsingDecl *UD = cast<UsingDecl>(InstD);
9298 for (auto *I : UD->shadows())
9308 // Determine the naming class.
9309 if (Old->getNamingClass()) {
9310 CXXRecordDecl *NamingClass
9311 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9312 Old->getMemberLoc(),
9313 Old->getNamingClass()));
9317 R.setNamingClass(NamingClass);
9320 TemplateArgumentListInfo TransArgs;
9321 if (Old->hasExplicitTemplateArgs()) {
9322 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9323 TransArgs.setRAngleLoc(Old->getRAngleLoc());
9324 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9325 Old->getNumTemplateArgs(),
9330 // FIXME: to do this check properly, we will need to preserve the
9331 // first-qualifier-in-scope here, just in case we had a dependent
9332 // base (and therefore couldn't do the check) and a
9333 // nested-name-qualifier (and therefore could do the lookup).
9334 NamedDecl *FirstQualifierInScope = nullptr;
9336 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
9338 Old->getOperatorLoc(),
9342 FirstQualifierInScope,
9344 (Old->hasExplicitTemplateArgs()
9345 ? &TransArgs : nullptr));
9348 template<typename Derived>
9350 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
9351 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9352 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9353 if (SubExpr.isInvalid())
9356 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
9359 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9362 template<typename Derived>
9364 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
9365 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9366 if (Pattern.isInvalid())
9369 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
9372 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9373 E->getNumExpansions());
9376 template<typename Derived>
9378 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9379 // If E is not value-dependent, then nothing will change when we transform it.
9380 // Note: This is an instantiation-centric view.
9381 if (!E->isValueDependent())
9384 // Note: None of the implementations of TryExpandParameterPacks can ever
9385 // produce a diagnostic when given only a single unexpanded parameter pack,
9387 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9388 bool ShouldExpand = false;
9389 bool RetainExpansion = false;
9390 Optional<unsigned> NumExpansions;
9391 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
9393 ShouldExpand, RetainExpansion,
9397 if (RetainExpansion)
9400 NamedDecl *Pack = E->getPack();
9401 if (!ShouldExpand) {
9402 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
9409 // We now know the length of the parameter pack, so build a new expression
9410 // that stores that length.
9411 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9412 E->getPackLoc(), E->getRParenLoc(),
9416 template<typename Derived>
9418 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9419 SubstNonTypeTemplateParmPackExpr *E) {
9420 // Default behavior is to do nothing with this transformation.
9424 template<typename Derived>
9426 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9427 SubstNonTypeTemplateParmExpr *E) {
9428 // Default behavior is to do nothing with this transformation.
9432 template<typename Derived>
9434 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9435 // Default behavior is to do nothing with this transformation.
9439 template<typename Derived>
9441 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9442 MaterializeTemporaryExpr *E) {
9443 return getDerived().TransformExpr(E->GetTemporaryExpr());
9446 template<typename Derived>
9448 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9449 CXXStdInitializerListExpr *E) {
9450 return getDerived().TransformExpr(E->getSubExpr());
9453 template<typename Derived>
9455 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
9456 return SemaRef.MaybeBindToTemporary(E);
9459 template<typename Derived>
9461 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
9465 template<typename Derived>
9467 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9468 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9469 if (SubExpr.isInvalid())
9472 if (!getDerived().AlwaysRebuild() &&
9473 SubExpr.get() == E->getSubExpr())
9476 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
9479 template<typename Derived>
9481 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9482 // Transform each of the elements.
9483 SmallVector<Expr *, 8> Elements;
9484 bool ArgChanged = false;
9485 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
9486 /*IsCall=*/false, Elements, &ArgChanged))
9489 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9490 return SemaRef.MaybeBindToTemporary(E);
9492 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9497 template<typename Derived>
9499 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
9500 ObjCDictionaryLiteral *E) {
9501 // Transform each of the elements.
9502 SmallVector<ObjCDictionaryElement, 8> Elements;
9503 bool ArgChanged = false;
9504 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9505 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
9507 if (OrigElement.isPackExpansion()) {
9508 // This key/value element is a pack expansion.
9509 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9510 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9511 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9512 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9514 // Determine whether the set of unexpanded parameter packs can
9515 // and should be expanded.
9517 bool RetainExpansion = false;
9518 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9519 Optional<unsigned> NumExpansions = OrigNumExpansions;
9520 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9521 OrigElement.Value->getLocEnd());
9522 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9525 Expand, RetainExpansion,
9530 // The transform has determined that we should perform a simple
9531 // transformation on the pack expansion, producing another pack
9533 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9534 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9535 if (Key.isInvalid())
9538 if (Key.get() != OrigElement.Key)
9541 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9542 if (Value.isInvalid())
9545 if (Value.get() != OrigElement.Value)
9548 ObjCDictionaryElement Expansion = {
9549 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9551 Elements.push_back(Expansion);
9555 // Record right away that the argument was changed. This needs
9556 // to happen even if the array expands to nothing.
9559 // The transform has determined that we should perform an elementwise
9560 // expansion of the pattern. Do so.
9561 for (unsigned I = 0; I != *NumExpansions; ++I) {
9562 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9563 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9564 if (Key.isInvalid())
9567 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9568 if (Value.isInvalid())
9571 ObjCDictionaryElement Element = {
9572 Key.get(), Value.get(), SourceLocation(), NumExpansions
9575 // If any unexpanded parameter packs remain, we still have a
9577 // FIXME: Can this really happen?
9578 if (Key.get()->containsUnexpandedParameterPack() ||
9579 Value.get()->containsUnexpandedParameterPack())
9580 Element.EllipsisLoc = OrigElement.EllipsisLoc;
9582 Elements.push_back(Element);
9585 // FIXME: Retain a pack expansion if RetainExpansion is true.
9587 // We've finished with this pack expansion.
9591 // Transform and check key.
9592 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9593 if (Key.isInvalid())
9596 if (Key.get() != OrigElement.Key)
9599 // Transform and check value.
9601 = getDerived().TransformExpr(OrigElement.Value);
9602 if (Value.isInvalid())
9605 if (Value.get() != OrigElement.Value)
9608 ObjCDictionaryElement Element = {
9609 Key.get(), Value.get(), SourceLocation(), None
9611 Elements.push_back(Element);
9614 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9615 return SemaRef.MaybeBindToTemporary(E);
9617 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9622 template<typename Derived>
9624 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
9625 TypeSourceInfo *EncodedTypeInfo
9626 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9627 if (!EncodedTypeInfo)
9630 if (!getDerived().AlwaysRebuild() &&
9631 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
9634 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
9639 template<typename Derived>
9640 ExprResult TreeTransform<Derived>::
9641 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
9642 // This is a kind of implicit conversion, and it needs to get dropped
9643 // and recomputed for the same general reasons that ImplicitCastExprs
9644 // do, as well a more specific one: this expression is only valid when
9645 // it appears *immediately* as an argument expression.
9646 return getDerived().TransformExpr(E->getSubExpr());
9649 template<typename Derived>
9650 ExprResult TreeTransform<Derived>::
9651 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
9652 TypeSourceInfo *TSInfo
9653 = getDerived().TransformType(E->getTypeInfoAsWritten());
9657 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
9658 if (Result.isInvalid())
9661 if (!getDerived().AlwaysRebuild() &&
9662 TSInfo == E->getTypeInfoAsWritten() &&
9663 Result.get() == E->getSubExpr())
9666 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
9667 E->getBridgeKeywordLoc(), TSInfo,
9671 template<typename Derived>
9673 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
9674 // Transform arguments.
9675 bool ArgChanged = false;
9676 SmallVector<Expr*, 8> Args;
9677 Args.reserve(E->getNumArgs());
9678 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
9682 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9683 // Class message: transform the receiver type.
9684 TypeSourceInfo *ReceiverTypeInfo
9685 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9686 if (!ReceiverTypeInfo)
9689 // If nothing changed, just retain the existing message send.
9690 if (!getDerived().AlwaysRebuild() &&
9691 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
9692 return SemaRef.MaybeBindToTemporary(E);
9694 // Build a new class message send.
9695 SmallVector<SourceLocation, 16> SelLocs;
9696 E->getSelectorLocs(SelLocs);
9697 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9706 // Instance message: transform the receiver
9707 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9708 "Only class and instance messages may be instantiated");
9710 = getDerived().TransformExpr(E->getInstanceReceiver());
9711 if (Receiver.isInvalid())
9714 // If nothing changed, just retain the existing message send.
9715 if (!getDerived().AlwaysRebuild() &&
9716 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
9717 return SemaRef.MaybeBindToTemporary(E);
9719 // Build a new instance message send.
9720 SmallVector<SourceLocation, 16> SelLocs;
9721 E->getSelectorLocs(SelLocs);
9722 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
9731 template<typename Derived>
9733 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
9737 template<typename Derived>
9739 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
9743 template<typename Derived>
9745 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
9746 // Transform the base expression.
9747 ExprResult Base = getDerived().TransformExpr(E->getBase());
9748 if (Base.isInvalid())
9751 // We don't need to transform the ivar; it will never change.
9753 // If nothing changed, just retain the existing expression.
9754 if (!getDerived().AlwaysRebuild() &&
9755 Base.get() == E->getBase())
9758 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
9760 E->isArrow(), E->isFreeIvar());
9763 template<typename Derived>
9765 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
9766 // 'super' and types never change. Property never changes. Just
9767 // retain the existing expression.
9768 if (!E->isObjectReceiver())
9771 // Transform the base expression.
9772 ExprResult Base = getDerived().TransformExpr(E->getBase());
9773 if (Base.isInvalid())
9776 // We don't need to transform the property; it will never change.
9778 // If nothing changed, just retain the existing expression.
9779 if (!getDerived().AlwaysRebuild() &&
9780 Base.get() == E->getBase())
9783 if (E->isExplicitProperty())
9784 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9785 E->getExplicitProperty(),
9788 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9789 SemaRef.Context.PseudoObjectTy,
9790 E->getImplicitPropertyGetter(),
9791 E->getImplicitPropertySetter(),
9795 template<typename Derived>
9797 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9798 // Transform the base expression.
9799 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9800 if (Base.isInvalid())
9803 // Transform the key expression.
9804 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9805 if (Key.isInvalid())
9808 // If nothing changed, just retain the existing expression.
9809 if (!getDerived().AlwaysRebuild() &&
9810 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9813 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
9814 Base.get(), Key.get(),
9815 E->getAtIndexMethodDecl(),
9816 E->setAtIndexMethodDecl());
9819 template<typename Derived>
9821 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
9822 // Transform the base expression.
9823 ExprResult Base = getDerived().TransformExpr(E->getBase());
9824 if (Base.isInvalid())
9827 // If nothing changed, just retain the existing expression.
9828 if (!getDerived().AlwaysRebuild() &&
9829 Base.get() == E->getBase())
9832 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
9837 template<typename Derived>
9839 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
9840 bool ArgumentChanged = false;
9841 SmallVector<Expr*, 8> SubExprs;
9842 SubExprs.reserve(E->getNumSubExprs());
9843 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9844 SubExprs, &ArgumentChanged))
9847 if (!getDerived().AlwaysRebuild() &&
9851 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
9856 template<typename Derived>
9858 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9859 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9860 if (SrcExpr.isInvalid())
9863 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9867 if (!getDerived().AlwaysRebuild() &&
9868 Type == E->getTypeSourceInfo() &&
9869 SrcExpr.get() == E->getSrcExpr())
9872 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9873 SrcExpr.get(), Type,
9877 template<typename Derived>
9879 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
9880 BlockDecl *oldBlock = E->getBlockDecl();
9882 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
9883 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9885 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
9886 blockScope->TheDecl->setBlockMissingReturnType(
9887 oldBlock->blockMissingReturnType());
9889 SmallVector<ParmVarDecl*, 4> params;
9890 SmallVector<QualType, 4> paramTypes;
9892 // Parameter substitution.
9893 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9894 oldBlock->param_begin(),
9895 oldBlock->param_size(),
9896 nullptr, paramTypes, ¶ms)) {
9897 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
9901 const FunctionProtoType *exprFunctionType = E->getFunctionType();
9902 QualType exprResultType =
9903 getDerived().TransformType(exprFunctionType->getReturnType());
9905 QualType functionType =
9906 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
9907 exprFunctionType->getExtProtoInfo());
9908 blockScope->FunctionType = functionType;
9910 // Set the parameters on the block decl.
9911 if (!params.empty())
9912 blockScope->TheDecl->setParams(params);
9914 if (!oldBlock->blockMissingReturnType()) {
9915 blockScope->HasImplicitReturnType = false;
9916 blockScope->ReturnType = exprResultType;
9919 // Transform the body
9920 StmtResult body = getDerived().TransformStmt(E->getBody());
9921 if (body.isInvalid()) {
9922 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
9927 // In builds with assertions, make sure that we captured everything we
9929 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9930 for (const auto &I : oldBlock->captures()) {
9931 VarDecl *oldCapture = I.getVariable();
9933 // Ignore parameter packs.
9934 if (isa<ParmVarDecl>(oldCapture) &&
9935 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9938 VarDecl *newCapture =
9939 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9941 assert(blockScope->CaptureMap.count(newCapture));
9943 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
9947 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9951 template<typename Derived>
9953 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
9954 llvm_unreachable("Cannot transform asType expressions yet");
9957 template<typename Derived>
9959 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
9960 QualType RetTy = getDerived().TransformType(E->getType());
9961 bool ArgumentChanged = false;
9962 SmallVector<Expr*, 8> SubExprs;
9963 SubExprs.reserve(E->getNumSubExprs());
9964 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9965 SubExprs, &ArgumentChanged))
9968 if (!getDerived().AlwaysRebuild() &&
9972 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
9973 RetTy, E->getOp(), E->getRParenLoc());
9976 //===----------------------------------------------------------------------===//
9977 // Type reconstruction
9978 //===----------------------------------------------------------------------===//
9980 template<typename Derived>
9981 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9982 SourceLocation Star) {
9983 return SemaRef.BuildPointerType(PointeeType, Star,
9984 getDerived().getBaseEntity());
9987 template<typename Derived>
9988 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9989 SourceLocation Star) {
9990 return SemaRef.BuildBlockPointerType(PointeeType, Star,
9991 getDerived().getBaseEntity());
9994 template<typename Derived>
9996 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9997 bool WrittenAsLValue,
9998 SourceLocation Sigil) {
9999 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
10000 Sigil, getDerived().getBaseEntity());
10003 template<typename Derived>
10005 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10006 QualType ClassType,
10007 SourceLocation Sigil) {
10008 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10009 getDerived().getBaseEntity());
10012 template<typename Derived>
10014 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10015 ArrayType::ArraySizeModifier SizeMod,
10016 const llvm::APInt *Size,
10018 unsigned IndexTypeQuals,
10019 SourceRange BracketsRange) {
10020 if (SizeExpr || !Size)
10021 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10022 IndexTypeQuals, BracketsRange,
10023 getDerived().getBaseEntity());
10025 QualType Types[] = {
10026 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10027 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10028 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
10030 const unsigned NumTypes = llvm::array_lengthof(Types);
10032 for (unsigned I = 0; I != NumTypes; ++I)
10033 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10034 SizeType = Types[I];
10038 // Note that we can return a VariableArrayType here in the case where
10039 // the element type was a dependent VariableArrayType.
10040 IntegerLiteral *ArraySize
10041 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10042 /*FIXME*/BracketsRange.getBegin());
10043 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
10044 IndexTypeQuals, BracketsRange,
10045 getDerived().getBaseEntity());
10048 template<typename Derived>
10050 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
10051 ArrayType::ArraySizeModifier SizeMod,
10052 const llvm::APInt &Size,
10053 unsigned IndexTypeQuals,
10054 SourceRange BracketsRange) {
10055 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
10056 IndexTypeQuals, BracketsRange);
10059 template<typename Derived>
10061 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
10062 ArrayType::ArraySizeModifier SizeMod,
10063 unsigned IndexTypeQuals,
10064 SourceRange BracketsRange) {
10065 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
10066 IndexTypeQuals, BracketsRange);
10069 template<typename Derived>
10071 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
10072 ArrayType::ArraySizeModifier SizeMod,
10074 unsigned IndexTypeQuals,
10075 SourceRange BracketsRange) {
10076 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
10078 IndexTypeQuals, BracketsRange);
10081 template<typename Derived>
10083 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
10084 ArrayType::ArraySizeModifier SizeMod,
10086 unsigned IndexTypeQuals,
10087 SourceRange BracketsRange) {
10088 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
10090 IndexTypeQuals, BracketsRange);
10093 template<typename Derived>
10094 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
10095 unsigned NumElements,
10096 VectorType::VectorKind VecKind) {
10097 // FIXME: semantic checking!
10098 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
10101 template<typename Derived>
10102 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10103 unsigned NumElements,
10104 SourceLocation AttributeLoc) {
10105 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10106 NumElements, true);
10107 IntegerLiteral *VectorSize
10108 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10110 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
10113 template<typename Derived>
10115 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
10117 SourceLocation AttributeLoc) {
10118 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
10121 template<typename Derived>
10122 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10124 MutableArrayRef<QualType> ParamTypes,
10125 const FunctionProtoType::ExtProtoInfo &EPI) {
10126 return SemaRef.BuildFunctionType(T, ParamTypes,
10127 getDerived().getBaseLocation(),
10128 getDerived().getBaseEntity(),
10132 template<typename Derived>
10133 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10134 return SemaRef.Context.getFunctionNoProtoType(T);
10137 template<typename Derived>
10138 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10139 assert(D && "no decl found");
10140 if (D->isInvalidDecl()) return QualType();
10142 // FIXME: Doesn't account for ObjCInterfaceDecl!
10144 if (isa<UsingDecl>(D)) {
10145 UsingDecl *Using = cast<UsingDecl>(D);
10146 assert(Using->hasTypename() &&
10147 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10149 // A valid resolved using typename decl points to exactly one type decl.
10150 assert(++Using->shadow_begin() == Using->shadow_end());
10151 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
10154 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10155 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10156 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10159 return SemaRef.Context.getTypeDeclType(Ty);
10162 template<typename Derived>
10163 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10164 SourceLocation Loc) {
10165 return SemaRef.BuildTypeofExprType(E, Loc);
10168 template<typename Derived>
10169 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10170 return SemaRef.Context.getTypeOfType(Underlying);
10173 template<typename Derived>
10174 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10175 SourceLocation Loc) {
10176 return SemaRef.BuildDecltypeType(E, Loc);
10179 template<typename Derived>
10180 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10181 UnaryTransformType::UTTKind UKind,
10182 SourceLocation Loc) {
10183 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10186 template<typename Derived>
10187 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
10188 TemplateName Template,
10189 SourceLocation TemplateNameLoc,
10190 TemplateArgumentListInfo &TemplateArgs) {
10191 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
10194 template<typename Derived>
10195 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10196 SourceLocation KWLoc) {
10197 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10200 template<typename Derived>
10202 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10204 TemplateDecl *Template) {
10205 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
10209 template<typename Derived>
10211 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10212 const IdentifierInfo &Name,
10213 SourceLocation NameLoc,
10214 QualType ObjectType,
10215 NamedDecl *FirstQualifierInScope) {
10216 UnqualifiedId TemplateName;
10217 TemplateName.setIdentifier(&Name, NameLoc);
10218 Sema::TemplateTy Template;
10219 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
10220 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
10221 SS, TemplateKWLoc, TemplateName,
10222 ParsedType::make(ObjectType),
10223 /*EnteringContext=*/false,
10225 return Template.get();
10228 template<typename Derived>
10230 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10231 OverloadedOperatorKind Operator,
10232 SourceLocation NameLoc,
10233 QualType ObjectType) {
10234 UnqualifiedId Name;
10235 // FIXME: Bogus location information.
10236 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
10237 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
10238 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
10239 Sema::TemplateTy Template;
10240 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
10241 SS, TemplateKWLoc, Name,
10242 ParsedType::make(ObjectType),
10243 /*EnteringContext=*/false,
10245 return Template.get();
10248 template<typename Derived>
10250 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10251 SourceLocation OpLoc,
10255 Expr *Callee = OrigCallee->IgnoreParenCasts();
10256 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
10258 if (First->getObjectKind() == OK_ObjCProperty) {
10259 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10260 if (BinaryOperator::isAssignmentOp(Opc))
10261 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10263 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10264 if (Result.isInvalid())
10265 return ExprError();
10266 First = Result.get();
10269 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10270 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10271 if (Result.isInvalid())
10272 return ExprError();
10273 Second = Result.get();
10276 // Determine whether this should be a builtin operation.
10277 if (Op == OO_Subscript) {
10278 if (!First->getType()->isOverloadableType() &&
10279 !Second->getType()->isOverloadableType())
10280 return getSema().CreateBuiltinArraySubscriptExpr(First,
10281 Callee->getLocStart(),
10283 } else if (Op == OO_Arrow) {
10284 // -> is never a builtin operation.
10285 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10286 } else if (Second == nullptr || isPostIncDec) {
10287 if (!First->getType()->isOverloadableType()) {
10288 // The argument is not of overloadable type, so try to create a
10289 // built-in unary operation.
10290 UnaryOperatorKind Opc
10291 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
10293 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
10296 if (!First->getType()->isOverloadableType() &&
10297 !Second->getType()->isOverloadableType()) {
10298 // Neither of the arguments is an overloadable type, so try to
10299 // create a built-in binary operation.
10300 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10302 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
10303 if (Result.isInvalid())
10304 return ExprError();
10310 // Compute the transformed set of functions (and function templates) to be
10311 // used during overload resolution.
10312 UnresolvedSet<16> Functions;
10314 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
10315 assert(ULE->requiresADL());
10316 Functions.append(ULE->decls_begin(), ULE->decls_end());
10318 // If we've resolved this to a particular non-member function, just call
10319 // that function. If we resolved it to a member function,
10320 // CreateOverloaded* will find that function for us.
10321 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10322 if (!isa<CXXMethodDecl>(ND))
10323 Functions.addDecl(ND);
10326 // Add any functions found via argument-dependent lookup.
10327 Expr *Args[2] = { First, Second };
10328 unsigned NumArgs = 1 + (Second != nullptr);
10330 // Create the overloaded operator invocation for unary operators.
10331 if (NumArgs == 1 || isPostIncDec) {
10332 UnaryOperatorKind Opc
10333 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
10334 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
10337 if (Op == OO_Subscript) {
10338 SourceLocation LBrace;
10339 SourceLocation RBrace;
10341 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10342 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10343 LBrace = SourceLocation::getFromRawEncoding(
10344 NameLoc.CXXOperatorName.BeginOpNameLoc);
10345 RBrace = SourceLocation::getFromRawEncoding(
10346 NameLoc.CXXOperatorName.EndOpNameLoc);
10348 LBrace = Callee->getLocStart();
10352 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10356 // Create the overloaded operator invocation for binary operators.
10357 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10359 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10360 if (Result.isInvalid())
10361 return ExprError();
10366 template<typename Derived>
10368 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
10369 SourceLocation OperatorLoc,
10372 TypeSourceInfo *ScopeType,
10373 SourceLocation CCLoc,
10374 SourceLocation TildeLoc,
10375 PseudoDestructorTypeStorage Destroyed) {
10376 QualType BaseType = Base->getType();
10377 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
10378 (!isArrow && !BaseType->getAs<RecordType>()) ||
10379 (isArrow && BaseType->getAs<PointerType>() &&
10380 !BaseType->getAs<PointerType>()->getPointeeType()
10381 ->template getAs<RecordType>())){
10382 // This pseudo-destructor expression is still a pseudo-destructor.
10383 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
10384 isArrow? tok::arrow : tok::period,
10385 SS, ScopeType, CCLoc, TildeLoc,
10390 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
10391 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10392 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10393 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10394 NameInfo.setNamedTypeInfo(DestroyedType);
10396 // The scope type is now known to be a valid nested name specifier
10397 // component. Tack it on to the end of the nested name specifier.
10399 SS.Extend(SemaRef.Context, SourceLocation(),
10400 ScopeType->getTypeLoc(), CCLoc);
10402 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
10403 return getSema().BuildMemberReferenceExpr(Base, BaseType,
10404 OperatorLoc, isArrow,
10406 /*FIXME: FirstQualifier*/ nullptr,
10408 /*TemplateArgs*/ nullptr);
10411 template<typename Derived>
10413 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
10414 SourceLocation Loc = S->getLocStart();
10415 CapturedDecl *CD = S->getCapturedDecl();
10416 unsigned NumParams = CD->getNumParams();
10417 unsigned ContextParamPos = CD->getContextParamPosition();
10418 SmallVector<Sema::CapturedParamNameType, 4> Params;
10419 for (unsigned I = 0; I < NumParams; ++I) {
10420 if (I != ContextParamPos) {
10423 CD->getParam(I)->getName(),
10424 getDerived().TransformType(CD->getParam(I)->getType())));
10426 Params.push_back(std::make_pair(StringRef(), QualType()));
10429 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
10430 S->getCapturedRegionKind(), Params);
10433 Sema::CompoundScopeRAII CompoundScope(getSema());
10434 Body = getDerived().TransformStmt(S->getCapturedStmt());
10437 if (Body.isInvalid()) {
10438 getSema().ActOnCapturedRegionError();
10439 return StmtError();
10442 return getSema().ActOnCapturedRegionEnd(Body.get());
10445 } // end namespace clang
10447 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H