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 "clang/Sema/SemaInternal.h"
18 #include "clang/Sema/Lookup.h"
19 #include "clang/Sema/ParsedTemplate.h"
20 #include "clang/Sema/SemaDiagnostic.h"
21 #include "clang/Sema/ScopeInfo.h"
22 #include "clang/AST/Decl.h"
23 #include "clang/AST/DeclObjC.h"
24 #include "clang/AST/DeclTemplate.h"
25 #include "clang/AST/Expr.h"
26 #include "clang/AST/ExprCXX.h"
27 #include "clang/AST/ExprObjC.h"
28 #include "clang/AST/Stmt.h"
29 #include "clang/AST/StmtCXX.h"
30 #include "clang/AST/StmtObjC.h"
31 #include "clang/Sema/Ownership.h"
32 #include "clang/Sema/Designator.h"
33 #include "clang/Lex/Preprocessor.h"
34 #include "llvm/ADT/ArrayRef.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "TypeLocBuilder.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.
144 bool AlwaysRebuild() { return false; }
146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
149 /// By default, returns no source-location information. Subclasses can
150 /// provide an alternative implementation that provides better location
152 SourceLocation getBaseLocation() { return SourceLocation(); }
154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
177 DeclarationName Entity) : Self(Self) {
178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
186 Self.getDerived().setBase(OldLocation, OldEntity);
190 /// \brief Determine whether the given type \p T has already been
193 /// Subclasses can provide an alternative implementation of this routine
194 /// to short-circuit evaluation when it is known that a given type will
195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
215 /// By default, the transformer never tries to expand pack expansions.
216 /// Subclasses can override this routine to provide different behavior.
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
224 /// \param Unexpanded The set of unexpanded parameter packs within the
227 /// \param NumUnexpanded The number of unexpanded parameter packs in
230 /// \param ShouldExpand Will be set to \c true if the transformer should
231 /// expand the corresponding pack expansions into separate arguments. When
232 /// set, \c NumExpansions must also be set.
234 /// \param RetainExpansion Whether the caller should add an unexpanded
235 /// pack expansion after all of the expanded arguments. This is used
236 /// when extending explicitly-specified template argument packs per
237 /// C++0x [temp.arg.explicit]p9.
239 /// \param NumExpansions The number of separate arguments that will be in
240 /// the expanded form of the corresponding pack expansion. This is both an
241 /// input and an output parameter, which can be set by the caller if the
242 /// number of expansions is known a priori (e.g., due to a prior substitution)
243 /// and will be set by the callee when the number of expansions is known.
244 /// The callee must set this value when \c ShouldExpand is \c true; it may
245 /// set this value in other cases.
247 /// \returns true if an error occurred (e.g., because the parameter packs
248 /// are to be instantiated with arguments of different lengths), false
249 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
251 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
252 SourceRange PatternRange,
253 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
255 bool &RetainExpansion,
256 llvm::Optional<unsigned> &NumExpansions) {
257 ShouldExpand = false;
261 /// \brief "Forget" about the partially-substituted pack template argument,
262 /// when performing an instantiation that must preserve the parameter pack
265 /// This routine is meant to be overridden by the template instantiator.
266 TemplateArgument ForgetPartiallySubstitutedPack() {
267 return TemplateArgument();
270 /// \brief "Remember" the partially-substituted pack template argument
271 /// after performing an instantiation that must preserve the parameter pack
274 /// This routine is meant to be overridden by the template instantiator.
275 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
277 /// \brief Note to the derived class when a function parameter pack is
279 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
281 /// \brief Transforms the given type into another type.
283 /// By default, this routine transforms a type by creating a
284 /// TypeSourceInfo for it and delegating to the appropriate
285 /// function. This is expensive, but we don't mind, because
286 /// this method is deprecated anyway; all users should be
287 /// switched to storing TypeSourceInfos.
289 /// \returns the transformed type.
290 QualType TransformType(QualType T);
292 /// \brief Transforms the given type-with-location into a new
293 /// type-with-location.
295 /// By default, this routine transforms a type by delegating to the
296 /// appropriate TransformXXXType to build a new type. Subclasses
297 /// may override this function (to take over all type
298 /// transformations) or some set of the TransformXXXType functions
299 /// to alter the transformation.
300 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
302 /// \brief Transform the given type-with-location into a new
303 /// type, collecting location information in the given builder
306 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
308 /// \brief Transform the given statement.
310 /// By default, this routine transforms a statement by delegating to the
311 /// appropriate TransformXXXStmt function to transform a specific kind of
312 /// statement or the TransformExpr() function to transform an expression.
313 /// Subclasses may override this function to transform statements using some
316 /// \returns the transformed statement.
317 StmtResult TransformStmt(Stmt *S);
319 /// \brief Transform the given expression.
321 /// By default, this routine transforms an expression by delegating to the
322 /// appropriate TransformXXXExpr function to build a new expression.
323 /// Subclasses may override this function to transform expressions using some
326 /// \returns the transformed expression.
327 ExprResult TransformExpr(Expr *E);
329 /// \brief Transform the given list of expressions.
331 /// This routine transforms a list of expressions by invoking
332 /// \c TransformExpr() for each subexpression. However, it also provides
333 /// support for variadic templates by expanding any pack expansions (if the
334 /// derived class permits such expansion) along the way. When pack expansions
335 /// are present, the number of outputs may not equal the number of inputs.
337 /// \param Inputs The set of expressions to be transformed.
339 /// \param NumInputs The number of expressions in \c Inputs.
341 /// \param IsCall If \c true, then this transform is being performed on
342 /// function-call arguments, and any arguments that should be dropped, will
345 /// \param Outputs The transformed input expressions will be added to this
348 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
349 /// due to transformation.
351 /// \returns true if an error occurred, false otherwise.
352 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
353 SmallVectorImpl<Expr *> &Outputs,
354 bool *ArgChanged = 0);
356 /// \brief Transform the given declaration, which is referenced from a type
359 /// By default, acts as the identity function on declarations, unless the
360 /// transformer has had to transform the declaration itself. Subclasses
361 /// may override this function to provide alternate behavior.
362 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
363 llvm::DenseMap<Decl *, Decl *>::iterator Known
364 = TransformedLocalDecls.find(D);
365 if (Known != TransformedLocalDecls.end())
366 return Known->second;
371 /// \brief Transform the attributes associated with the given declaration and
372 /// place them on the new declaration.
374 /// By default, this operation does nothing. Subclasses may override this
375 /// behavior to transform attributes.
376 void transformAttrs(Decl *Old, Decl *New) { }
378 /// \brief Note that a local declaration has been transformed by this
381 /// Local declarations are typically transformed via a call to
382 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
383 /// the transformer itself has to transform the declarations. This routine
384 /// can be overridden by a subclass that keeps track of such mappings.
385 void transformedLocalDecl(Decl *Old, Decl *New) {
386 TransformedLocalDecls[Old] = New;
389 /// \brief Transform the definition of the given declaration.
391 /// By default, invokes TransformDecl() to transform the declaration.
392 /// Subclasses may override this function to provide alternate behavior.
393 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
394 return getDerived().TransformDecl(Loc, D);
397 /// \brief Transform the given declaration, which was the first part of a
398 /// nested-name-specifier in a member access expression.
400 /// This specific declaration transformation only applies to the first
401 /// identifier in a nested-name-specifier of a member access expression, e.g.,
402 /// the \c T in \c x->T::member
404 /// By default, invokes TransformDecl() to transform the declaration.
405 /// Subclasses may override this function to provide alternate behavior.
406 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
407 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
410 /// \brief Transform the given nested-name-specifier with source-location
413 /// By default, transforms all of the types and declarations within the
414 /// nested-name-specifier. Subclasses may override this function to provide
415 /// alternate behavior.
416 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
417 NestedNameSpecifierLoc NNS,
418 QualType ObjectType = QualType(),
419 NamedDecl *FirstQualifierInScope = 0);
421 /// \brief Transform the given declaration name.
423 /// By default, transforms the types of conversion function, constructor,
424 /// and destructor names and then (if needed) rebuilds the declaration name.
425 /// Identifiers and selectors are returned unmodified. Sublcasses may
426 /// override this function to provide alternate behavior.
428 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
430 /// \brief Transform the given template name.
432 /// \param SS The nested-name-specifier that qualifies the template
433 /// name. This nested-name-specifier must already have been transformed.
435 /// \param Name The template name to transform.
437 /// \param NameLoc The source location of the template name.
439 /// \param ObjectType If we're translating a template name within a member
440 /// access expression, this is the type of the object whose member template
441 /// is being referenced.
443 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
444 /// also refers to a name within the current (lexical) scope, this is the
445 /// declaration it refers to.
447 /// By default, transforms the template name by transforming the declarations
448 /// and nested-name-specifiers that occur within the template name.
449 /// Subclasses may override this function to provide alternate behavior.
450 TemplateName TransformTemplateName(CXXScopeSpec &SS,
452 SourceLocation NameLoc,
453 QualType ObjectType = QualType(),
454 NamedDecl *FirstQualifierInScope = 0);
456 /// \brief Transform the given template argument.
458 /// By default, this operation transforms the type, expression, or
459 /// declaration stored within the template argument and constructs a
460 /// new template argument from the transformed result. Subclasses may
461 /// override this function to provide alternate behavior.
463 /// Returns true if there was an error.
464 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
465 TemplateArgumentLoc &Output);
467 /// \brief Transform the given set of template arguments.
469 /// By default, this operation transforms all of the template arguments
470 /// in the input set using \c TransformTemplateArgument(), and appends
471 /// the transformed arguments to the output list.
473 /// Note that this overload of \c TransformTemplateArguments() is merely
474 /// a convenience function. Subclasses that wish to override this behavior
475 /// should override the iterator-based member template version.
477 /// \param Inputs The set of template arguments to be transformed.
479 /// \param NumInputs The number of template arguments in \p Inputs.
481 /// \param Outputs The set of transformed template arguments output by this
484 /// Returns true if an error occurred.
485 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
487 TemplateArgumentListInfo &Outputs) {
488 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
491 /// \brief Transform the given set of template arguments.
493 /// By default, this operation transforms all of the template arguments
494 /// in the input set using \c TransformTemplateArgument(), and appends
495 /// the transformed arguments to the output list.
497 /// \param First An iterator to the first template argument.
499 /// \param Last An iterator one step past the last template argument.
501 /// \param Outputs The set of transformed template arguments output by this
504 /// Returns true if an error occurred.
505 template<typename InputIterator>
506 bool TransformTemplateArguments(InputIterator First,
508 TemplateArgumentListInfo &Outputs);
510 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
511 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
512 TemplateArgumentLoc &ArgLoc);
514 /// \brief Fakes up a TypeSourceInfo for a type.
515 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
516 return SemaRef.Context.getTrivialTypeSourceInfo(T,
517 getDerived().getBaseLocation());
520 #define ABSTRACT_TYPELOC(CLASS, PARENT)
521 #define TYPELOC(CLASS, PARENT) \
522 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
523 #include "clang/AST/TypeLocNodes.def"
526 TransformSEHHandler(Stmt *Handler);
529 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
530 TemplateSpecializationTypeLoc TL,
531 TemplateName Template);
534 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
535 DependentTemplateSpecializationTypeLoc TL,
536 TemplateName Template,
540 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
541 DependentTemplateSpecializationTypeLoc TL,
542 NestedNameSpecifierLoc QualifierLoc);
544 /// \brief Transforms the parameters of a function type into the
547 /// The result vectors should be kept in sync; null entries in the
548 /// variables vector are acceptable.
550 /// Return true on error.
551 bool TransformFunctionTypeParams(SourceLocation Loc,
552 ParmVarDecl **Params, unsigned NumParams,
553 const QualType *ParamTypes,
554 SmallVectorImpl<QualType> &PTypes,
555 SmallVectorImpl<ParmVarDecl*> *PVars);
557 /// \brief Transforms a single function-type parameter. Return null
560 /// \param indexAdjustment - A number to add to the parameter's
561 /// scope index; can be negative
562 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
564 llvm::Optional<unsigned> NumExpansions,
565 bool ExpectParameterPack);
567 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
569 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
570 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
572 #define STMT(Node, Parent) \
573 StmtResult Transform##Node(Node *S);
574 #define EXPR(Node, Parent) \
575 ExprResult Transform##Node(Node *E);
576 #define ABSTRACT_STMT(Stmt)
577 #include "clang/AST/StmtNodes.inc"
579 /// \brief Build a new pointer type given its pointee type.
581 /// By default, performs semantic analysis when building the pointer type.
582 /// Subclasses may override this routine to provide different behavior.
583 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
585 /// \brief Build a new block pointer type given its pointee type.
587 /// By default, performs semantic analysis when building the block pointer
588 /// type. Subclasses may override this routine to provide different behavior.
589 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
591 /// \brief Build a new reference type given the type it references.
593 /// By default, performs semantic analysis when building the
594 /// reference type. Subclasses may override this routine to provide
595 /// different behavior.
597 /// \param LValue whether the type was written with an lvalue sigil
598 /// or an rvalue sigil.
599 QualType RebuildReferenceType(QualType ReferentType,
601 SourceLocation Sigil);
603 /// \brief Build a new member pointer type given the pointee type and the
604 /// class type it refers into.
606 /// By default, performs semantic analysis when building the member pointer
607 /// type. Subclasses may override this routine to provide different behavior.
608 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
609 SourceLocation Sigil);
611 /// \brief Build a new array type given the element type, size
612 /// modifier, size of the array (if known), size expression, and index type
615 /// By default, performs semantic analysis when building the array type.
616 /// Subclasses may override this routine to provide different behavior.
617 /// Also by default, all of the other Rebuild*Array
618 QualType RebuildArrayType(QualType ElementType,
619 ArrayType::ArraySizeModifier SizeMod,
620 const llvm::APInt *Size,
622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
625 /// \brief Build a new constant array type given the element type, size
626 /// modifier, (known) size of the array, and index type qualifiers.
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
630 QualType RebuildConstantArrayType(QualType ElementType,
631 ArrayType::ArraySizeModifier SizeMod,
632 const llvm::APInt &Size,
633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
636 /// \brief Build a new incomplete array type given the element type, size
637 /// modifier, and index type qualifiers.
639 /// By default, performs semantic analysis when building the array type.
640 /// Subclasses may override this routine to provide different behavior.
641 QualType RebuildIncompleteArrayType(QualType ElementType,
642 ArrayType::ArraySizeModifier SizeMod,
643 unsigned IndexTypeQuals,
644 SourceRange BracketsRange);
646 /// \brief Build a new variable-length array type given the element type,
647 /// size modifier, size expression, and index type qualifiers.
649 /// By default, performs semantic analysis when building the array type.
650 /// Subclasses may override this routine to provide different behavior.
651 QualType RebuildVariableArrayType(QualType ElementType,
652 ArrayType::ArraySizeModifier SizeMod,
654 unsigned IndexTypeQuals,
655 SourceRange BracketsRange);
657 /// \brief Build a new dependent-sized array type given the element type,
658 /// size modifier, size expression, and index type qualifiers.
660 /// By default, performs semantic analysis when building the array type.
661 /// Subclasses may override this routine to provide different behavior.
662 QualType RebuildDependentSizedArrayType(QualType ElementType,
663 ArrayType::ArraySizeModifier SizeMod,
665 unsigned IndexTypeQuals,
666 SourceRange BracketsRange);
668 /// \brief Build a new vector type given the element type and
669 /// number of elements.
671 /// By default, performs semantic analysis when building the vector type.
672 /// Subclasses may override this routine to provide different behavior.
673 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
674 VectorType::VectorKind VecKind);
676 /// \brief Build a new extended vector type given the element type and
677 /// number of elements.
679 /// By default, performs semantic analysis when building the vector type.
680 /// Subclasses may override this routine to provide different behavior.
681 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
682 SourceLocation AttributeLoc);
684 /// \brief Build a new potentially dependently-sized extended vector type
685 /// given the element type and number of elements.
687 /// By default, performs semantic analysis when building the vector type.
688 /// Subclasses may override this routine to provide different behavior.
689 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
691 SourceLocation AttributeLoc);
693 /// \brief Build a new function type.
695 /// By default, performs semantic analysis when building the function type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildFunctionProtoType(QualType T,
698 QualType *ParamTypes,
699 unsigned NumParamTypes,
700 bool Variadic, bool HasTrailingReturn,
702 RefQualifierKind RefQualifier,
703 const FunctionType::ExtInfo &Info);
705 /// \brief Build a new unprototyped function type.
706 QualType RebuildFunctionNoProtoType(QualType ResultType);
708 /// \brief Rebuild an unresolved typename type, given the decl that
709 /// the UnresolvedUsingTypenameDecl was transformed to.
710 QualType RebuildUnresolvedUsingType(Decl *D);
712 /// \brief Build a new typedef type.
713 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
714 return SemaRef.Context.getTypeDeclType(Typedef);
717 /// \brief Build a new class/struct/union type.
718 QualType RebuildRecordType(RecordDecl *Record) {
719 return SemaRef.Context.getTypeDeclType(Record);
722 /// \brief Build a new Enum type.
723 QualType RebuildEnumType(EnumDecl *Enum) {
724 return SemaRef.Context.getTypeDeclType(Enum);
727 /// \brief Build a new typeof(expr) type.
729 /// By default, performs semantic analysis when building the typeof type.
730 /// Subclasses may override this routine to provide different behavior.
731 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
733 /// \brief Build a new typeof(type) type.
735 /// By default, builds a new TypeOfType with the given underlying type.
736 QualType RebuildTypeOfType(QualType Underlying);
738 /// \brief Build a new unary transform type.
739 QualType RebuildUnaryTransformType(QualType BaseType,
740 UnaryTransformType::UTTKind UKind,
743 /// \brief Build a new C++0x decltype type.
745 /// By default, performs semantic analysis when building the decltype type.
746 /// Subclasses may override this routine to provide different behavior.
747 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
749 /// \brief Build a new C++0x auto type.
751 /// By default, builds a new AutoType with the given deduced type.
752 QualType RebuildAutoType(QualType Deduced) {
753 return SemaRef.Context.getAutoType(Deduced);
756 /// \brief Build a new template specialization type.
758 /// By default, performs semantic analysis when building the template
759 /// specialization type. Subclasses may override this routine to provide
760 /// different behavior.
761 QualType RebuildTemplateSpecializationType(TemplateName Template,
762 SourceLocation TemplateLoc,
763 TemplateArgumentListInfo &Args);
765 /// \brief Build a new parenthesized type.
767 /// By default, builds a new ParenType type from the inner type.
768 /// Subclasses may override this routine to provide different behavior.
769 QualType RebuildParenType(QualType InnerType) {
770 return SemaRef.Context.getParenType(InnerType);
773 /// \brief Build a new qualified name type.
775 /// By default, builds a new ElaboratedType type from the keyword,
776 /// the nested-name-specifier and the named type.
777 /// Subclasses may override this routine to provide different behavior.
778 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
779 ElaboratedTypeKeyword Keyword,
780 NestedNameSpecifierLoc QualifierLoc,
782 return SemaRef.Context.getElaboratedType(Keyword,
783 QualifierLoc.getNestedNameSpecifier(),
787 /// \brief Build a new typename type that refers to a template-id.
789 /// By default, builds a new DependentNameType type from the
790 /// nested-name-specifier and the given type. Subclasses may override
791 /// this routine to provide different behavior.
792 QualType RebuildDependentTemplateSpecializationType(
793 ElaboratedTypeKeyword Keyword,
794 NestedNameSpecifierLoc QualifierLoc,
795 const IdentifierInfo *Name,
796 SourceLocation NameLoc,
797 TemplateArgumentListInfo &Args) {
798 // Rebuild the template name.
799 // TODO: avoid TemplateName abstraction
801 SS.Adopt(QualifierLoc);
802 TemplateName InstName
803 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
805 if (InstName.isNull())
808 // If it's still dependent, make a dependent specialization.
809 if (InstName.getAsDependentTemplateName())
810 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
811 QualifierLoc.getNestedNameSpecifier(),
815 // Otherwise, make an elaborated type wrapping a non-dependent
818 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
819 if (T.isNull()) return QualType();
821 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
824 return SemaRef.Context.getElaboratedType(Keyword,
825 QualifierLoc.getNestedNameSpecifier(),
829 /// \brief Build a new typename type that refers to an identifier.
831 /// By default, performs semantic analysis when building the typename type
832 /// (or elaborated type). Subclasses may override this routine to provide
833 /// different behavior.
834 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
835 SourceLocation KeywordLoc,
836 NestedNameSpecifierLoc QualifierLoc,
837 const IdentifierInfo *Id,
838 SourceLocation IdLoc) {
840 SS.Adopt(QualifierLoc);
842 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
843 // If the name is still dependent, just build a new dependent name type.
844 if (!SemaRef.computeDeclContext(SS))
845 return SemaRef.Context.getDependentNameType(Keyword,
846 QualifierLoc.getNestedNameSpecifier(),
850 if (Keyword == ETK_None || Keyword == ETK_Typename)
851 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
854 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
856 // We had a dependent elaborated-type-specifier that has been transformed
857 // into a non-dependent elaborated-type-specifier. Find the tag we're
859 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
860 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
864 if (SemaRef.RequireCompleteDeclContext(SS, DC))
868 SemaRef.LookupQualifiedName(Result, DC);
869 switch (Result.getResultKind()) {
870 case LookupResult::NotFound:
871 case LookupResult::NotFoundInCurrentInstantiation:
874 case LookupResult::Found:
875 Tag = Result.getAsSingle<TagDecl>();
878 case LookupResult::FoundOverloaded:
879 case LookupResult::FoundUnresolvedValue:
880 llvm_unreachable("Tag lookup cannot find non-tags");
882 case LookupResult::Ambiguous:
883 // Let the LookupResult structure handle ambiguities.
888 // Check where the name exists but isn't a tag type and use that to emit
889 // better diagnostics.
890 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
891 SemaRef.LookupQualifiedName(Result, DC);
892 switch (Result.getResultKind()) {
893 case LookupResult::Found:
894 case LookupResult::FoundOverloaded:
895 case LookupResult::FoundUnresolvedValue: {
896 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
898 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
899 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
900 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
901 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
902 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
906 // FIXME: Would be nice to highlight just the source range.
907 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
914 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
916 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
917 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
921 // Build the elaborated-type-specifier type.
922 QualType T = SemaRef.Context.getTypeDeclType(Tag);
923 return SemaRef.Context.getElaboratedType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
928 /// \brief Build a new pack expansion type.
930 /// By default, builds a new PackExpansionType type from the given pattern.
931 /// Subclasses may override this routine to provide different behavior.
932 QualType RebuildPackExpansionType(QualType Pattern,
933 SourceRange PatternRange,
934 SourceLocation EllipsisLoc,
935 llvm::Optional<unsigned> NumExpansions) {
936 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
940 /// \brief Build a new atomic type given its value type.
942 /// By default, performs semantic analysis when building the atomic type.
943 /// Subclasses may override this routine to provide different behavior.
944 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
946 /// \brief Build a new template name given a nested name specifier, a flag
947 /// indicating whether the "template" keyword was provided, and the template
948 /// that the template name refers to.
950 /// By default, builds the new template name directly. Subclasses may override
951 /// this routine to provide different behavior.
952 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
954 TemplateDecl *Template);
956 /// \brief Build a new template name given a nested name specifier and the
957 /// name that is referred to as a template.
959 /// By default, performs semantic analysis to determine whether the name can
960 /// be resolved to a specific template, then builds the appropriate kind of
961 /// template name. Subclasses may override this routine to provide different
963 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
964 const IdentifierInfo &Name,
965 SourceLocation NameLoc,
967 NamedDecl *FirstQualifierInScope);
969 /// \brief Build a new template name given a nested name specifier and the
970 /// overloaded operator name that is referred to as a template.
972 /// By default, performs semantic analysis to determine whether the name can
973 /// be resolved to a specific template, then builds the appropriate kind of
974 /// template name. Subclasses may override this routine to provide different
976 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
977 OverloadedOperatorKind Operator,
978 SourceLocation NameLoc,
979 QualType ObjectType);
981 /// \brief Build a new template name given a template template parameter pack
984 /// By default, performs semantic analysis to determine whether the name can
985 /// be resolved to a specific template, then builds the appropriate kind of
986 /// template name. Subclasses may override this routine to provide different
988 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
989 const TemplateArgument &ArgPack) {
990 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
993 /// \brief Build a new compound statement.
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
997 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
998 MultiStmtArg Statements,
999 SourceLocation RBraceLoc,
1001 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1005 /// \brief Build a new case statement.
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
1009 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1011 SourceLocation EllipsisLoc,
1013 SourceLocation ColonLoc) {
1014 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1018 /// \brief Attach the body to a new case statement.
1020 /// By default, performs semantic analysis to build the new statement.
1021 /// Subclasses may override this routine to provide different behavior.
1022 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1023 getSema().ActOnCaseStmtBody(S, Body);
1027 /// \brief Build a new default statement.
1029 /// By default, performs semantic analysis to build the new statement.
1030 /// Subclasses may override this routine to provide different behavior.
1031 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1032 SourceLocation ColonLoc,
1034 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1038 /// \brief Build a new label statement.
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
1042 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1043 SourceLocation ColonLoc, Stmt *SubStmt) {
1044 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1047 /// \brief Build a new "if" statement.
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
1051 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
1052 VarDecl *CondVar, Stmt *Then,
1053 SourceLocation ElseLoc, Stmt *Else) {
1054 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
1057 /// \brief Start building a new switch statement.
1059 /// By default, performs semantic analysis to build the new statement.
1060 /// Subclasses may override this routine to provide different behavior.
1061 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
1062 Expr *Cond, VarDecl *CondVar) {
1063 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1067 /// \brief Attach the body to the switch statement.
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
1071 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1072 Stmt *Switch, Stmt *Body) {
1073 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1076 /// \brief Build a new while statement.
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
1080 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1081 VarDecl *CondVar, Stmt *Body) {
1082 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
1085 /// \brief Build a new do-while statement.
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
1089 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1090 SourceLocation WhileLoc, SourceLocation LParenLoc,
1091 Expr *Cond, SourceLocation RParenLoc) {
1092 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1096 /// \brief Build a new for statement.
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
1100 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1101 Stmt *Init, Sema::FullExprArg Cond,
1102 VarDecl *CondVar, Sema::FullExprArg Inc,
1103 SourceLocation RParenLoc, Stmt *Body) {
1104 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1105 CondVar, Inc, RParenLoc, Body);
1108 /// \brief Build a new goto statement.
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
1112 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1114 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1117 /// \brief Build a new indirect goto statement.
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
1121 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1122 SourceLocation StarLoc,
1124 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1127 /// \brief Build a new return statement.
1129 /// By default, performs semantic analysis to build the new statement.
1130 /// Subclasses may override this routine to provide different behavior.
1131 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1132 return getSema().ActOnReturnStmt(ReturnLoc, Result);
1135 /// \brief Build a new declaration statement.
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
1139 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
1140 SourceLocation StartLoc,
1141 SourceLocation EndLoc) {
1142 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1143 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1146 /// \brief Build a new inline asm statement.
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
1150 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
1153 unsigned NumOutputs,
1155 IdentifierInfo **Names,
1156 MultiExprArg Constraints,
1159 MultiExprArg Clobbers,
1160 SourceLocation RParenLoc,
1162 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1163 NumInputs, Names, move(Constraints),
1164 Exprs, AsmString, Clobbers,
1168 /// \brief Build a new Objective-C @try statement.
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
1172 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1174 MultiStmtArg CatchStmts,
1176 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1180 /// \brief Rebuild an Objective-C exception declaration.
1182 /// By default, performs semantic analysis to build the new declaration.
1183 /// Subclasses may override this routine to provide different behavior.
1184 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1185 TypeSourceInfo *TInfo, QualType T) {
1186 return getSema().BuildObjCExceptionDecl(TInfo, T,
1187 ExceptionDecl->getInnerLocStart(),
1188 ExceptionDecl->getLocation(),
1189 ExceptionDecl->getIdentifier());
1192 /// \brief Build a new Objective-C @catch statement.
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
1196 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1197 SourceLocation RParenLoc,
1200 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1204 /// \brief Build a new Objective-C @finally statement.
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
1208 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1210 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1213 /// \brief Build a new Objective-C @throw statement.
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
1217 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1219 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1222 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
1226 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1228 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1231 /// \brief Build a new Objective-C @synchronized statement.
1233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
1235 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1236 Expr *Object, Stmt *Body) {
1237 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1240 /// \brief Build a new Objective-C @autoreleasepool statement.
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
1244 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1246 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1249 /// \brief Build the collection operand to a new Objective-C fast
1250 /// enumeration statement.
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
1254 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1256 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1259 /// \brief Build a new Objective-C fast enumeration statement.
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1264 SourceLocation LParenLoc,
1267 SourceLocation RParenLoc,
1269 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
1276 /// \brief Build a new C++ exception declaration.
1278 /// By default, performs semantic analysis to build the new decaration.
1279 /// Subclasses may override this routine to provide different behavior.
1280 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1281 TypeSourceInfo *Declarator,
1282 SourceLocation StartLoc,
1283 SourceLocation IdLoc,
1284 IdentifierInfo *Id) {
1285 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1286 StartLoc, IdLoc, Id);
1288 getSema().CurContext->addDecl(Var);
1292 /// \brief Build a new C++ catch statement.
1294 /// By default, performs semantic analysis to build the new statement.
1295 /// Subclasses may override this routine to provide different behavior.
1296 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1297 VarDecl *ExceptionDecl,
1299 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1303 /// \brief Build a new C++ try statement.
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1309 MultiStmtArg Handlers) {
1310 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
1313 /// \brief Build a new C++0x range-based for statement.
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
1317 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1318 SourceLocation ColonLoc,
1319 Stmt *Range, Stmt *BeginEnd,
1320 Expr *Cond, Expr *Inc,
1322 SourceLocation RParenLoc) {
1323 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1324 Cond, Inc, LoopVar, RParenLoc);
1327 /// \brief Build a new C++0x range-based for statement.
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
1331 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1333 NestedNameSpecifierLoc QualifierLoc,
1334 DeclarationNameInfo NameInfo,
1336 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1337 QualifierLoc, NameInfo, Nested);
1340 /// \brief Attach body to a C++0x range-based for statement.
1342 /// By default, performs semantic analysis to finish the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
1344 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1345 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1348 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1349 SourceLocation TryLoc,
1352 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1355 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1358 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1361 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1363 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1366 /// \brief Build a new expression that references a declaration.
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// Subclasses may override this routine to provide different behavior.
1370 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1373 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1377 /// \brief Build a new expression that references a declaration.
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
1381 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1383 const DeclarationNameInfo &NameInfo,
1384 TemplateArgumentListInfo *TemplateArgs) {
1386 SS.Adopt(QualifierLoc);
1388 // FIXME: loses template args.
1390 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1393 /// \brief Build a new expression in parentheses.
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
1397 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1398 SourceLocation RParen) {
1399 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1402 /// \brief Build a new pseudo-destructor expression.
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
1406 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1407 SourceLocation OperatorLoc,
1410 TypeSourceInfo *ScopeType,
1411 SourceLocation CCLoc,
1412 SourceLocation TildeLoc,
1413 PseudoDestructorTypeStorage Destroyed);
1415 /// \brief Build a new unary operator expression.
1417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
1419 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1420 UnaryOperatorKind Opc,
1422 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1425 /// \brief Build a new builtin offsetof expression.
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
1429 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1430 TypeSourceInfo *Type,
1431 Sema::OffsetOfComponent *Components,
1432 unsigned NumComponents,
1433 SourceLocation RParenLoc) {
1434 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1435 NumComponents, RParenLoc);
1438 /// \brief Build a new sizeof, alignof or vec_step expression with a
1441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
1443 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1444 SourceLocation OpLoc,
1445 UnaryExprOrTypeTrait ExprKind,
1447 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1450 /// \brief Build a new sizeof, alignof or vec step expression with an
1451 /// expression argument.
1453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
1455 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1456 UnaryExprOrTypeTrait ExprKind,
1459 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1460 if (Result.isInvalid())
1463 return move(Result);
1466 /// \brief Build a new array subscript expression.
1468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
1470 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1471 SourceLocation LBracketLoc,
1473 SourceLocation RBracketLoc) {
1474 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1479 /// \brief Build a new call expression.
1481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
1483 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1485 SourceLocation RParenLoc,
1486 Expr *ExecConfig = 0) {
1487 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1488 move(Args), RParenLoc, ExecConfig);
1491 /// \brief Build a new member access expression.
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
1495 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1497 NestedNameSpecifierLoc QualifierLoc,
1498 SourceLocation TemplateKWLoc,
1499 const DeclarationNameInfo &MemberNameInfo,
1501 NamedDecl *FoundDecl,
1502 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1503 NamedDecl *FirstQualifierInScope) {
1504 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1506 if (!Member->getDeclName()) {
1507 // We have a reference to an unnamed field. This is always the
1508 // base of an anonymous struct/union member access, i.e. the
1509 // field is always of record type.
1510 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1511 assert(Member->getType()->isRecordType() &&
1512 "unnamed member not of record type?");
1515 getSema().PerformObjectMemberConversion(BaseResult.take(),
1516 QualifierLoc.getNestedNameSpecifier(),
1518 if (BaseResult.isInvalid())
1520 Base = BaseResult.take();
1521 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
1523 new (getSema().Context) MemberExpr(Base, isArrow,
1524 Member, MemberNameInfo,
1525 cast<FieldDecl>(Member)->getType(),
1527 return getSema().Owned(ME);
1531 SS.Adopt(QualifierLoc);
1533 Base = BaseResult.take();
1534 QualType BaseType = Base->getType();
1536 // FIXME: this involves duplicating earlier analysis in a lot of
1537 // cases; we should avoid this when possible.
1538 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
1539 R.addDecl(FoundDecl);
1542 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1544 FirstQualifierInScope,
1545 R, ExplicitTemplateArgs);
1548 /// \brief Build a new binary operator expression.
1550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
1552 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1553 BinaryOperatorKind Opc,
1554 Expr *LHS, Expr *RHS) {
1555 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1558 /// \brief Build a new conditional operator expression.
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
1562 ExprResult RebuildConditionalOperator(Expr *Cond,
1563 SourceLocation QuestionLoc,
1565 SourceLocation ColonLoc,
1567 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1571 /// \brief Build a new C-style cast expression.
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
1575 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1576 TypeSourceInfo *TInfo,
1577 SourceLocation RParenLoc,
1579 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1583 /// \brief Build a new compound literal expression.
1585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
1587 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1588 TypeSourceInfo *TInfo,
1589 SourceLocation RParenLoc,
1591 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1595 /// \brief Build a new extended vector element access expression.
1597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
1599 ExprResult RebuildExtVectorElementExpr(Expr *Base,
1600 SourceLocation OpLoc,
1601 SourceLocation AccessorLoc,
1602 IdentifierInfo &Accessor) {
1605 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
1606 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1607 OpLoc, /*IsArrow*/ false,
1608 SS, SourceLocation(),
1609 /*FirstQualifierInScope*/ 0,
1611 /* TemplateArgs */ 0);
1614 /// \brief Build a new initializer list expression.
1616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
1618 ExprResult RebuildInitList(SourceLocation LBraceLoc,
1620 SourceLocation RBraceLoc,
1621 QualType ResultTy) {
1623 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1624 if (Result.isInvalid() || ResultTy->isDependentType())
1625 return move(Result);
1627 // Patch in the result type we were given, which may have been computed
1628 // when the initial InitListExpr was built.
1629 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1630 ILE->setType(ResultTy);
1631 return move(Result);
1634 /// \brief Build a new designated initializer expression.
1636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
1638 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1639 MultiExprArg ArrayExprs,
1640 SourceLocation EqualOrColonLoc,
1644 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1646 if (Result.isInvalid())
1649 ArrayExprs.release();
1650 return move(Result);
1653 /// \brief Build a new value-initialized expression.
1655 /// By default, builds the implicit value initialization without performing
1656 /// any semantic analysis. Subclasses may override this routine to provide
1657 /// different behavior.
1658 ExprResult RebuildImplicitValueInitExpr(QualType T) {
1659 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1662 /// \brief Build a new \c va_arg expression.
1664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
1666 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1667 Expr *SubExpr, TypeSourceInfo *TInfo,
1668 SourceLocation RParenLoc) {
1669 return getSema().BuildVAArgExpr(BuiltinLoc,
1674 /// \brief Build a new expression list in parentheses.
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
1678 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1679 MultiExprArg SubExprs,
1680 SourceLocation RParenLoc) {
1681 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
1684 /// \brief Build a new address-of-label expression.
1686 /// By default, performs semantic analysis, using the name of the label
1687 /// rather than attempting to map the label statement itself.
1688 /// Subclasses may override this routine to provide different behavior.
1689 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1690 SourceLocation LabelLoc, LabelDecl *Label) {
1691 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
1694 /// \brief Build a new GNU statement expression.
1696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
1698 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1700 SourceLocation RParenLoc) {
1701 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1704 /// \brief Build a new __builtin_choose_expr expression.
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
1708 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1709 Expr *Cond, Expr *LHS, Expr *RHS,
1710 SourceLocation RParenLoc) {
1711 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1716 /// \brief Build a new generic selection expression.
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
1720 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1721 SourceLocation DefaultLoc,
1722 SourceLocation RParenLoc,
1723 Expr *ControllingExpr,
1724 TypeSourceInfo **Types,
1726 unsigned NumAssocs) {
1727 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1728 ControllingExpr, Types, Exprs,
1732 /// \brief Build a new overloaded operator call expression.
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// The semantic analysis provides the behavior of template instantiation,
1736 /// copying with transformations that turn what looks like an overloaded
1737 /// operator call into a use of a builtin operator, performing
1738 /// argument-dependent lookup, etc. Subclasses may override this routine to
1739 /// provide different behavior.
1740 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1741 SourceLocation OpLoc,
1746 /// \brief Build a new C++ "named" cast expression, such as static_cast or
1747 /// reinterpret_cast.
1749 /// By default, this routine dispatches to one of the more-specific routines
1750 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1751 /// Subclasses may override this routine to provide different behavior.
1752 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1753 Stmt::StmtClass Class,
1754 SourceLocation LAngleLoc,
1755 TypeSourceInfo *TInfo,
1756 SourceLocation RAngleLoc,
1757 SourceLocation LParenLoc,
1759 SourceLocation RParenLoc) {
1761 case Stmt::CXXStaticCastExprClass:
1762 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
1763 RAngleLoc, LParenLoc,
1764 SubExpr, RParenLoc);
1766 case Stmt::CXXDynamicCastExprClass:
1767 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
1768 RAngleLoc, LParenLoc,
1769 SubExpr, RParenLoc);
1771 case Stmt::CXXReinterpretCastExprClass:
1772 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
1773 RAngleLoc, LParenLoc,
1777 case Stmt::CXXConstCastExprClass:
1778 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
1779 RAngleLoc, LParenLoc,
1780 SubExpr, RParenLoc);
1783 llvm_unreachable("Invalid C++ named cast");
1787 /// \brief Build a new C++ static_cast expression.
1789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
1791 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1792 SourceLocation LAngleLoc,
1793 TypeSourceInfo *TInfo,
1794 SourceLocation RAngleLoc,
1795 SourceLocation LParenLoc,
1797 SourceLocation RParenLoc) {
1798 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1800 SourceRange(LAngleLoc, RAngleLoc),
1801 SourceRange(LParenLoc, RParenLoc));
1804 /// \brief Build a new C++ dynamic_cast expression.
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
1808 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1809 SourceLocation LAngleLoc,
1810 TypeSourceInfo *TInfo,
1811 SourceLocation RAngleLoc,
1812 SourceLocation LParenLoc,
1814 SourceLocation RParenLoc) {
1815 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1817 SourceRange(LAngleLoc, RAngleLoc),
1818 SourceRange(LParenLoc, RParenLoc));
1821 /// \brief Build a new C++ reinterpret_cast expression.
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
1825 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1826 SourceLocation LAngleLoc,
1827 TypeSourceInfo *TInfo,
1828 SourceLocation RAngleLoc,
1829 SourceLocation LParenLoc,
1831 SourceLocation RParenLoc) {
1832 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1834 SourceRange(LAngleLoc, RAngleLoc),
1835 SourceRange(LParenLoc, RParenLoc));
1838 /// \brief Build a new C++ const_cast expression.
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
1842 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1843 SourceLocation LAngleLoc,
1844 TypeSourceInfo *TInfo,
1845 SourceLocation RAngleLoc,
1846 SourceLocation LParenLoc,
1848 SourceLocation RParenLoc) {
1849 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1851 SourceRange(LAngleLoc, RAngleLoc),
1852 SourceRange(LParenLoc, RParenLoc));
1855 /// \brief Build a new C++ functional-style cast expression.
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
1859 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1860 SourceLocation LParenLoc,
1862 SourceLocation RParenLoc) {
1863 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1864 MultiExprArg(&Sub, 1),
1868 /// \brief Build a new C++ typeid(type) expression.
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
1872 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1873 SourceLocation TypeidLoc,
1874 TypeSourceInfo *Operand,
1875 SourceLocation RParenLoc) {
1876 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1881 /// \brief Build a new C++ typeid(expr) expression.
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
1885 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1886 SourceLocation TypeidLoc,
1888 SourceLocation RParenLoc) {
1889 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1893 /// \brief Build a new C++ __uuidof(type) expression.
1895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
1897 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1898 SourceLocation TypeidLoc,
1899 TypeSourceInfo *Operand,
1900 SourceLocation RParenLoc) {
1901 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1905 /// \brief Build a new C++ __uuidof(expr) expression.
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1910 SourceLocation TypeidLoc,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1917 /// \brief Build a new C++ "this" expression.
1919 /// By default, builds a new "this" expression without performing any
1920 /// semantic analysis. Subclasses may override this routine to provide
1921 /// different behavior.
1922 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1925 getSema().CheckCXXThisCapture(ThisLoc);
1926 return getSema().Owned(
1927 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1931 /// \brief Build a new C++ throw expression.
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
1935 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1936 bool IsThrownVariableInScope) {
1937 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
1940 /// \brief Build a new C++ default-argument expression.
1942 /// By default, builds a new default-argument expression, which does not
1943 /// require any semantic analysis. Subclasses may override this routine to
1944 /// provide different behavior.
1945 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1946 ParmVarDecl *Param) {
1947 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1951 /// \brief Build a new C++ zero-initialization expression.
1953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
1955 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1956 SourceLocation LParenLoc,
1957 SourceLocation RParenLoc) {
1958 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
1959 MultiExprArg(getSema(), 0, 0),
1963 /// \brief Build a new C++ "new" expression.
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
1967 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
1969 SourceLocation PlacementLParen,
1970 MultiExprArg PlacementArgs,
1971 SourceLocation PlacementRParen,
1972 SourceRange TypeIdParens,
1973 QualType AllocatedType,
1974 TypeSourceInfo *AllocatedTypeInfo,
1976 SourceRange DirectInitRange,
1977 Expr *Initializer) {
1978 return getSema().BuildCXXNew(StartLoc, UseGlobal,
1980 move(PlacementArgs),
1990 /// \brief Build a new C++ "delete" expression.
1992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
1994 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1995 bool IsGlobalDelete,
1998 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2002 /// \brief Build a new unary type trait expression.
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
2006 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
2007 SourceLocation StartLoc,
2009 SourceLocation RParenLoc) {
2010 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
2013 /// \brief Build a new binary type trait expression.
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
2017 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2018 SourceLocation StartLoc,
2019 TypeSourceInfo *LhsT,
2020 TypeSourceInfo *RhsT,
2021 SourceLocation RParenLoc) {
2022 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2025 /// \brief Build a new type trait expression.
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
2029 ExprResult RebuildTypeTrait(TypeTrait Trait,
2030 SourceLocation StartLoc,
2031 ArrayRef<TypeSourceInfo *> Args,
2032 SourceLocation RParenLoc) {
2033 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2036 /// \brief Build a new array type trait expression.
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
2040 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2041 SourceLocation StartLoc,
2042 TypeSourceInfo *TSInfo,
2044 SourceLocation RParenLoc) {
2045 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2048 /// \brief Build a new expression trait expression.
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
2052 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2053 SourceLocation StartLoc,
2055 SourceLocation RParenLoc) {
2056 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2059 /// \brief Build a new (previously unresolved) declaration reference
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
2064 ExprResult RebuildDependentScopeDeclRefExpr(
2065 NestedNameSpecifierLoc QualifierLoc,
2066 SourceLocation TemplateKWLoc,
2067 const DeclarationNameInfo &NameInfo,
2068 const TemplateArgumentListInfo *TemplateArgs) {
2070 SS.Adopt(QualifierLoc);
2072 if (TemplateArgs || TemplateKWLoc.isValid())
2073 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
2074 NameInfo, TemplateArgs);
2076 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
2079 /// \brief Build a new template-id expression.
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
2083 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2084 SourceLocation TemplateKWLoc,
2087 const TemplateArgumentListInfo *TemplateArgs) {
2088 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2092 /// \brief Build a new object-construction expression.
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
2096 ExprResult RebuildCXXConstructExpr(QualType T,
2098 CXXConstructorDecl *Constructor,
2101 bool HadMultipleCandidates,
2102 bool RequiresZeroInit,
2103 CXXConstructExpr::ConstructionKind ConstructKind,
2104 SourceRange ParenRange) {
2105 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
2106 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
2110 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
2111 move_arg(ConvertedArgs),
2112 HadMultipleCandidates,
2113 RequiresZeroInit, ConstructKind,
2117 /// \brief Build a new object-construction expression.
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
2121 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2122 SourceLocation LParenLoc,
2124 SourceLocation RParenLoc) {
2125 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2131 /// \brief Build a new object-construction expression.
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2136 SourceLocation LParenLoc,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2145 /// \brief Build a new member reference expression.
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
2149 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2152 SourceLocation OperatorLoc,
2153 NestedNameSpecifierLoc QualifierLoc,
2154 SourceLocation TemplateKWLoc,
2155 NamedDecl *FirstQualifierInScope,
2156 const DeclarationNameInfo &MemberNameInfo,
2157 const TemplateArgumentListInfo *TemplateArgs) {
2159 SS.Adopt(QualifierLoc);
2161 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2162 OperatorLoc, IsArrow,
2164 FirstQualifierInScope,
2169 /// \brief Build a new member reference expression.
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
2173 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2174 SourceLocation OperatorLoc,
2176 NestedNameSpecifierLoc QualifierLoc,
2177 SourceLocation TemplateKWLoc,
2178 NamedDecl *FirstQualifierInScope,
2180 const TemplateArgumentListInfo *TemplateArgs) {
2182 SS.Adopt(QualifierLoc);
2184 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2185 OperatorLoc, IsArrow,
2187 FirstQualifierInScope,
2191 /// \brief Build a new noexcept expression.
2193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
2195 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2196 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2199 /// \brief Build a new expression to compute the length of a parameter pack.
2200 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2201 SourceLocation PackLoc,
2202 SourceLocation RParenLoc,
2203 llvm::Optional<unsigned> Length) {
2205 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2206 OperatorLoc, Pack, PackLoc,
2207 RParenLoc, *Length);
2209 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2210 OperatorLoc, Pack, PackLoc,
2214 /// \brief Build a new Objective-C array literal.
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
2218 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2219 Expr **Elements, unsigned NumElements) {
2220 return getSema().BuildObjCArrayLiteral(Range,
2221 MultiExprArg(Elements, NumElements));
2224 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2225 Expr *Base, Expr *Key,
2226 ObjCMethodDecl *getterMethod,
2227 ObjCMethodDecl *setterMethod) {
2228 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2229 getterMethod, setterMethod);
2232 /// \brief Build a new Objective-C dictionary literal.
2234 /// By default, performs semantic analysis to build the new expression.
2235 /// Subclasses may override this routine to provide different behavior.
2236 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2237 ObjCDictionaryElement *Elements,
2238 unsigned NumElements) {
2239 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2242 /// \brief Build a new Objective-C @encode expression.
2244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
2246 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2247 TypeSourceInfo *EncodeTypeInfo,
2248 SourceLocation RParenLoc) {
2249 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2253 /// \brief Build a new Objective-C class message.
2254 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2256 ArrayRef<SourceLocation> SelectorLocs,
2257 ObjCMethodDecl *Method,
2258 SourceLocation LBracLoc,
2260 SourceLocation RBracLoc) {
2261 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2262 ReceiverTypeInfo->getType(),
2263 /*SuperLoc=*/SourceLocation(),
2264 Sel, Method, LBracLoc, SelectorLocs,
2265 RBracLoc, move(Args));
2268 /// \brief Build a new Objective-C instance message.
2269 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2271 ArrayRef<SourceLocation> SelectorLocs,
2272 ObjCMethodDecl *Method,
2273 SourceLocation LBracLoc,
2275 SourceLocation RBracLoc) {
2276 return SemaRef.BuildInstanceMessage(Receiver,
2277 Receiver->getType(),
2278 /*SuperLoc=*/SourceLocation(),
2279 Sel, Method, LBracLoc, SelectorLocs,
2280 RBracLoc, move(Args));
2283 /// \brief Build a new Objective-C ivar reference expression.
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
2287 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2288 SourceLocation IvarLoc,
2289 bool IsArrow, bool IsFreeIvar) {
2290 // FIXME: We lose track of the IsFreeIvar bit.
2292 ExprResult Base = getSema().Owned(BaseArg);
2293 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2294 Sema::LookupMemberName);
2295 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2299 if (Result.isInvalid() || Base.isInvalid())
2303 return move(Result);
2305 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2306 /*FIXME:*/IvarLoc, IsArrow,
2307 SS, SourceLocation(),
2308 /*FirstQualifierInScope=*/0,
2310 /*TemplateArgs=*/0);
2313 /// \brief Build a new Objective-C property reference expression.
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
2317 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2318 ObjCPropertyDecl *Property,
2319 SourceLocation PropertyLoc) {
2321 ExprResult Base = getSema().Owned(BaseArg);
2322 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2323 Sema::LookupMemberName);
2324 bool IsArrow = false;
2325 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2326 /*FIME:*/PropertyLoc,
2328 if (Result.isInvalid() || Base.isInvalid())
2332 return move(Result);
2334 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2335 /*FIXME:*/PropertyLoc, IsArrow,
2336 SS, SourceLocation(),
2337 /*FirstQualifierInScope=*/0,
2339 /*TemplateArgs=*/0);
2342 /// \brief Build a new Objective-C property reference expression.
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
2346 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2347 ObjCMethodDecl *Getter,
2348 ObjCMethodDecl *Setter,
2349 SourceLocation PropertyLoc) {
2350 // Since these expressions can only be value-dependent, we do not
2351 // need to perform semantic analysis again.
2353 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2354 VK_LValue, OK_ObjCProperty,
2355 PropertyLoc, Base));
2358 /// \brief Build a new Objective-C "isa" expression.
2360 /// By default, performs semantic analysis to build the new expression.
2361 /// Subclasses may override this routine to provide different behavior.
2362 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2365 ExprResult Base = getSema().Owned(BaseArg);
2366 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2367 Sema::LookupMemberName);
2368 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2371 if (Result.isInvalid() || Base.isInvalid())
2375 return move(Result);
2377 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2378 /*FIXME:*/IsaLoc, IsArrow,
2379 SS, SourceLocation(),
2380 /*FirstQualifierInScope=*/0,
2382 /*TemplateArgs=*/0);
2385 /// \brief Build a new shuffle vector expression.
2387 /// By default, performs semantic analysis to build the new expression.
2388 /// Subclasses may override this routine to provide different behavior.
2389 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2390 MultiExprArg SubExprs,
2391 SourceLocation RParenLoc) {
2392 // Find the declaration for __builtin_shufflevector
2393 const IdentifierInfo &Name
2394 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2395 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2396 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2397 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
2399 // Build a reference to the __builtin_shufflevector builtin
2400 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
2402 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2404 VK_LValue, BuiltinLoc));
2405 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2406 if (Callee.isInvalid())
2409 // Build the CallExpr
2410 unsigned NumSubExprs = SubExprs.size();
2411 Expr **Subs = (Expr **)SubExprs.release();
2412 ExprResult TheCall = SemaRef.Owned(
2413 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
2415 Builtin->getCallResultType(),
2416 Expr::getValueKindForType(Builtin->getResultType()),
2419 // Type-check the __builtin_shufflevector expression.
2420 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
2423 /// \brief Build a new template argument pack expansion.
2425 /// By default, performs semantic analysis to build a new pack expansion
2426 /// for a template argument. Subclasses may override this routine to provide
2427 /// different behavior.
2428 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2429 SourceLocation EllipsisLoc,
2430 llvm::Optional<unsigned> NumExpansions) {
2431 switch (Pattern.getArgument().getKind()) {
2432 case TemplateArgument::Expression: {
2434 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2435 EllipsisLoc, NumExpansions);
2436 if (Result.isInvalid())
2437 return TemplateArgumentLoc();
2439 return TemplateArgumentLoc(Result.get(), Result.get());
2442 case TemplateArgument::Template:
2443 return TemplateArgumentLoc(TemplateArgument(
2444 Pattern.getArgument().getAsTemplate(),
2446 Pattern.getTemplateQualifierLoc(),
2447 Pattern.getTemplateNameLoc(),
2450 case TemplateArgument::Null:
2451 case TemplateArgument::Integral:
2452 case TemplateArgument::Declaration:
2453 case TemplateArgument::Pack:
2454 case TemplateArgument::TemplateExpansion:
2455 llvm_unreachable("Pack expansion pattern has no parameter packs");
2457 case TemplateArgument::Type:
2458 if (TypeSourceInfo *Expansion
2459 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2462 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2467 return TemplateArgumentLoc();
2470 /// \brief Build a new expression pack expansion.
2472 /// By default, performs semantic analysis to build a new pack expansion
2473 /// for an expression. Subclasses may override this routine to provide
2474 /// different behavior.
2475 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2476 llvm::Optional<unsigned> NumExpansions) {
2477 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2480 /// \brief Build a new atomic operation expression.
2482 /// By default, performs semantic analysis to build the new expression.
2483 /// Subclasses may override this routine to provide different behavior.
2484 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2485 MultiExprArg SubExprs,
2487 AtomicExpr::AtomicOp Op,
2488 SourceLocation RParenLoc) {
2489 // Just create the expression; there is not any interesting semantic
2490 // analysis here because we can't actually build an AtomicExpr until
2491 // we are sure it is semantically sound.
2492 unsigned NumSubExprs = SubExprs.size();
2493 Expr **Subs = (Expr **)SubExprs.release();
2494 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2495 NumSubExprs, RetTy, Op,
2500 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2501 QualType ObjectType,
2502 NamedDecl *FirstQualifierInScope,
2505 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2506 QualType ObjectType,
2507 NamedDecl *FirstQualifierInScope,
2511 template<typename Derived>
2512 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
2514 return SemaRef.Owned(S);
2516 switch (S->getStmtClass()) {
2517 case Stmt::NoStmtClass: break;
2519 // Transform individual statement nodes
2520 #define STMT(Node, Parent) \
2521 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2522 #define ABSTRACT_STMT(Node)
2523 #define EXPR(Node, Parent)
2524 #include "clang/AST/StmtNodes.inc"
2526 // Transform expressions by calling TransformExpr.
2527 #define STMT(Node, Parent)
2528 #define ABSTRACT_STMT(Stmt)
2529 #define EXPR(Node, Parent) case Stmt::Node##Class:
2530 #include "clang/AST/StmtNodes.inc"
2532 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
2536 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
2540 return SemaRef.Owned(S);
2544 template<typename Derived>
2545 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2547 return SemaRef.Owned(E);
2549 switch (E->getStmtClass()) {
2550 case Stmt::NoStmtClass: break;
2551 #define STMT(Node, Parent) case Stmt::Node##Class: break;
2552 #define ABSTRACT_STMT(Stmt)
2553 #define EXPR(Node, Parent) \
2554 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
2555 #include "clang/AST/StmtNodes.inc"
2558 return SemaRef.Owned(E);
2561 template<typename Derived>
2562 bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2565 SmallVectorImpl<Expr *> &Outputs,
2567 for (unsigned I = 0; I != NumInputs; ++I) {
2568 // If requested, drop call arguments that need to be dropped.
2569 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2576 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2577 Expr *Pattern = Expansion->getPattern();
2579 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2580 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2581 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2583 // Determine whether the set of unexpanded parameter packs can and should
2586 bool RetainExpansion = false;
2587 llvm::Optional<unsigned> OrigNumExpansions
2588 = Expansion->getNumExpansions();
2589 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
2590 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2591 Pattern->getSourceRange(),
2593 Expand, RetainExpansion,
2598 // The transform has determined that we should perform a simple
2599 // transformation on the pack expansion, producing another pack
2601 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2602 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2603 if (OutPattern.isInvalid())
2606 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2607 Expansion->getEllipsisLoc(),
2609 if (Out.isInvalid())
2614 Outputs.push_back(Out.get());
2618 // Record right away that the argument was changed. This needs
2619 // to happen even if the array expands to nothing.
2620 if (ArgChanged) *ArgChanged = true;
2622 // The transform has determined that we should perform an elementwise
2623 // expansion of the pattern. Do so.
2624 for (unsigned I = 0; I != *NumExpansions; ++I) {
2625 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2626 ExprResult Out = getDerived().TransformExpr(Pattern);
2627 if (Out.isInvalid())
2630 if (Out.get()->containsUnexpandedParameterPack()) {
2631 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2633 if (Out.isInvalid())
2637 Outputs.push_back(Out.get());
2643 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2644 if (Result.isInvalid())
2647 if (Result.get() != Inputs[I] && ArgChanged)
2650 Outputs.push_back(Result.get());
2656 template<typename Derived>
2657 NestedNameSpecifierLoc
2658 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2659 NestedNameSpecifierLoc NNS,
2660 QualType ObjectType,
2661 NamedDecl *FirstQualifierInScope) {
2662 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2663 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2664 Qualifier = Qualifier.getPrefix())
2665 Qualifiers.push_back(Qualifier);
2668 while (!Qualifiers.empty()) {
2669 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2670 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2672 switch (QNNS->getKind()) {
2673 case NestedNameSpecifier::Identifier:
2674 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2675 *QNNS->getAsIdentifier(),
2676 Q.getLocalBeginLoc(),
2678 ObjectType, false, SS,
2679 FirstQualifierInScope, false))
2680 return NestedNameSpecifierLoc();
2684 case NestedNameSpecifier::Namespace: {
2686 = cast_or_null<NamespaceDecl>(
2687 getDerived().TransformDecl(
2688 Q.getLocalBeginLoc(),
2689 QNNS->getAsNamespace()));
2690 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2694 case NestedNameSpecifier::NamespaceAlias: {
2695 NamespaceAliasDecl *Alias
2696 = cast_or_null<NamespaceAliasDecl>(
2697 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2698 QNNS->getAsNamespaceAlias()));
2699 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2700 Q.getLocalEndLoc());
2704 case NestedNameSpecifier::Global:
2705 // There is no meaningful transformation that one could perform on the
2707 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2710 case NestedNameSpecifier::TypeSpecWithTemplate:
2711 case NestedNameSpecifier::TypeSpec: {
2712 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2713 FirstQualifierInScope, SS);
2716 return NestedNameSpecifierLoc();
2718 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2719 (SemaRef.getLangOpts().CPlusPlus0x &&
2720 TL.getType()->isEnumeralType())) {
2721 assert(!TL.getType().hasLocalQualifiers() &&
2722 "Can't get cv-qualifiers here");
2723 if (TL.getType()->isEnumeralType())
2724 SemaRef.Diag(TL.getBeginLoc(),
2725 diag::warn_cxx98_compat_enum_nested_name_spec);
2726 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2727 Q.getLocalEndLoc());
2730 // If the nested-name-specifier is an invalid type def, don't emit an
2731 // error because a previous error should have already been emitted.
2732 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2733 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2734 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2735 << TL.getType() << SS.getRange();
2737 return NestedNameSpecifierLoc();
2741 // The qualifier-in-scope and object type only apply to the leftmost entity.
2742 FirstQualifierInScope = 0;
2743 ObjectType = QualType();
2746 // Don't rebuild the nested-name-specifier if we don't have to.
2747 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2748 !getDerived().AlwaysRebuild())
2751 // If we can re-use the source-location data from the original
2752 // nested-name-specifier, do so.
2753 if (SS.location_size() == NNS.getDataLength() &&
2754 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2755 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2757 // Allocate new nested-name-specifier location information.
2758 return SS.getWithLocInContext(SemaRef.Context);
2761 template<typename Derived>
2763 TreeTransform<Derived>
2764 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
2765 DeclarationName Name = NameInfo.getName();
2767 return DeclarationNameInfo();
2769 switch (Name.getNameKind()) {
2770 case DeclarationName::Identifier:
2771 case DeclarationName::ObjCZeroArgSelector:
2772 case DeclarationName::ObjCOneArgSelector:
2773 case DeclarationName::ObjCMultiArgSelector:
2774 case DeclarationName::CXXOperatorName:
2775 case DeclarationName::CXXLiteralOperatorName:
2776 case DeclarationName::CXXUsingDirective:
2779 case DeclarationName::CXXConstructorName:
2780 case DeclarationName::CXXDestructorName:
2781 case DeclarationName::CXXConversionFunctionName: {
2782 TypeSourceInfo *NewTInfo;
2783 CanQualType NewCanTy;
2784 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2785 NewTInfo = getDerived().TransformType(OldTInfo);
2787 return DeclarationNameInfo();
2788 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2792 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2793 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
2795 return DeclarationNameInfo();
2796 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2799 DeclarationName NewName
2800 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2802 DeclarationNameInfo NewNameInfo(NameInfo);
2803 NewNameInfo.setName(NewName);
2804 NewNameInfo.setNamedTypeInfo(NewTInfo);
2809 llvm_unreachable("Unknown name kind.");
2812 template<typename Derived>
2814 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2816 SourceLocation NameLoc,
2817 QualType ObjectType,
2818 NamedDecl *FirstQualifierInScope) {
2819 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2820 TemplateDecl *Template = QTN->getTemplateDecl();
2821 assert(Template && "qualified template name must refer to a template");
2823 TemplateDecl *TransTemplate
2824 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2827 return TemplateName();
2829 if (!getDerived().AlwaysRebuild() &&
2830 SS.getScopeRep() == QTN->getQualifier() &&
2831 TransTemplate == Template)
2834 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2838 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2839 if (SS.getScopeRep()) {
2840 // These apply to the scope specifier, not the template.
2841 ObjectType = QualType();
2842 FirstQualifierInScope = 0;
2845 if (!getDerived().AlwaysRebuild() &&
2846 SS.getScopeRep() == DTN->getQualifier() &&
2847 ObjectType.isNull())
2850 if (DTN->isIdentifier()) {
2851 return getDerived().RebuildTemplateName(SS,
2852 *DTN->getIdentifier(),
2855 FirstQualifierInScope);
2858 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2862 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2863 TemplateDecl *TransTemplate
2864 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2867 return TemplateName();
2869 if (!getDerived().AlwaysRebuild() &&
2870 TransTemplate == Template)
2873 return TemplateName(TransTemplate);
2876 if (SubstTemplateTemplateParmPackStorage *SubstPack
2877 = Name.getAsSubstTemplateTemplateParmPack()) {
2878 TemplateTemplateParmDecl *TransParam
2879 = cast_or_null<TemplateTemplateParmDecl>(
2880 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2882 return TemplateName();
2884 if (!getDerived().AlwaysRebuild() &&
2885 TransParam == SubstPack->getParameterPack())
2888 return getDerived().RebuildTemplateName(TransParam,
2889 SubstPack->getArgumentPack());
2892 // These should be getting filtered out before they reach the AST.
2893 llvm_unreachable("overloaded function decl survived to here");
2896 template<typename Derived>
2897 void TreeTransform<Derived>::InventTemplateArgumentLoc(
2898 const TemplateArgument &Arg,
2899 TemplateArgumentLoc &Output) {
2900 SourceLocation Loc = getDerived().getBaseLocation();
2901 switch (Arg.getKind()) {
2902 case TemplateArgument::Null:
2903 llvm_unreachable("null template argument in TreeTransform");
2906 case TemplateArgument::Type:
2907 Output = TemplateArgumentLoc(Arg,
2908 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2912 case TemplateArgument::Template:
2913 case TemplateArgument::TemplateExpansion: {
2914 NestedNameSpecifierLocBuilder Builder;
2915 TemplateName Template = Arg.getAsTemplate();
2916 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2917 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2918 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2919 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2921 if (Arg.getKind() == TemplateArgument::Template)
2922 Output = TemplateArgumentLoc(Arg,
2923 Builder.getWithLocInContext(SemaRef.Context),
2926 Output = TemplateArgumentLoc(Arg,
2927 Builder.getWithLocInContext(SemaRef.Context),
2933 case TemplateArgument::Expression:
2934 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2937 case TemplateArgument::Declaration:
2938 case TemplateArgument::Integral:
2939 case TemplateArgument::Pack:
2940 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2945 template<typename Derived>
2946 bool TreeTransform<Derived>::TransformTemplateArgument(
2947 const TemplateArgumentLoc &Input,
2948 TemplateArgumentLoc &Output) {
2949 const TemplateArgument &Arg = Input.getArgument();
2950 switch (Arg.getKind()) {
2951 case TemplateArgument::Null:
2952 case TemplateArgument::Integral:
2956 case TemplateArgument::Type: {
2957 TypeSourceInfo *DI = Input.getTypeSourceInfo();
2959 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2961 DI = getDerived().TransformType(DI);
2962 if (!DI) return true;
2964 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2968 case TemplateArgument::Declaration: {
2969 // FIXME: we should never have to transform one of these.
2970 DeclarationName Name;
2971 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2972 Name = ND->getDeclName();
2973 TemporaryBase Rebase(*this, Input.getLocation(), Name);
2974 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2975 if (!D) return true;
2977 Expr *SourceExpr = Input.getSourceDeclExpression();
2979 EnterExpressionEvaluationContext Unevaluated(getSema(),
2980 Sema::ConstantEvaluated);
2981 ExprResult E = getDerived().TransformExpr(SourceExpr);
2982 E = SemaRef.ActOnConstantExpression(E);
2983 SourceExpr = (E.isInvalid() ? 0 : E.take());
2986 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2990 case TemplateArgument::Template: {
2991 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2993 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2999 SS.Adopt(QualifierLoc);
3000 TemplateName Template
3001 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3002 Input.getTemplateNameLoc());
3003 if (Template.isNull())
3006 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3007 Input.getTemplateNameLoc());
3011 case TemplateArgument::TemplateExpansion:
3012 llvm_unreachable("Caller should expand pack expansions");
3014 case TemplateArgument::Expression: {
3015 // Template argument expressions are constant expressions.
3016 EnterExpressionEvaluationContext Unevaluated(getSema(),
3017 Sema::ConstantEvaluated);
3019 Expr *InputExpr = Input.getSourceExpression();
3020 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3022 ExprResult E = getDerived().TransformExpr(InputExpr);
3023 E = SemaRef.ActOnConstantExpression(E);
3024 if (E.isInvalid()) return true;
3025 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
3029 case TemplateArgument::Pack: {
3030 SmallVector<TemplateArgument, 4> TransformedArgs;
3031 TransformedArgs.reserve(Arg.pack_size());
3032 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
3033 AEnd = Arg.pack_end();
3036 // FIXME: preserve source information here when we start
3037 // caring about parameter packs.
3039 TemplateArgumentLoc InputArg;
3040 TemplateArgumentLoc OutputArg;
3041 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3042 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
3045 TransformedArgs.push_back(OutputArg.getArgument());
3048 TemplateArgument *TransformedArgsPtr
3049 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3050 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3051 TransformedArgsPtr);
3052 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3053 TransformedArgs.size()),
3054 Input.getLocInfo());
3059 // Work around bogus GCC warning
3063 /// \brief Iterator adaptor that invents template argument location information
3064 /// for each of the template arguments in its underlying iterator.
3065 template<typename Derived, typename InputIterator>
3066 class TemplateArgumentLocInventIterator {
3067 TreeTransform<Derived> &Self;
3071 typedef TemplateArgumentLoc value_type;
3072 typedef TemplateArgumentLoc reference;
3073 typedef typename std::iterator_traits<InputIterator>::difference_type
3075 typedef std::input_iterator_tag iterator_category;
3078 TemplateArgumentLoc Arg;
3081 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3083 const TemplateArgumentLoc *operator->() const { return &Arg; }
3086 TemplateArgumentLocInventIterator() { }
3088 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3090 : Self(Self), Iter(Iter) { }
3092 TemplateArgumentLocInventIterator &operator++() {
3097 TemplateArgumentLocInventIterator operator++(int) {
3098 TemplateArgumentLocInventIterator Old(*this);
3103 reference operator*() const {
3104 TemplateArgumentLoc Result;
3105 Self.InventTemplateArgumentLoc(*Iter, Result);
3109 pointer operator->() const { return pointer(**this); }
3111 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3112 const TemplateArgumentLocInventIterator &Y) {
3113 return X.Iter == Y.Iter;
3116 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3117 const TemplateArgumentLocInventIterator &Y) {
3118 return X.Iter != Y.Iter;
3122 template<typename Derived>
3123 template<typename InputIterator>
3124 bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3126 TemplateArgumentListInfo &Outputs) {
3127 for (; First != Last; ++First) {
3128 TemplateArgumentLoc Out;
3129 TemplateArgumentLoc In = *First;
3131 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3132 // Unpack argument packs, which we translate them into separate
3134 // FIXME: We could do much better if we could guarantee that the
3135 // TemplateArgumentLocInfo for the pack expansion would be usable for
3136 // all of the template arguments in the argument pack.
3137 typedef TemplateArgumentLocInventIterator<Derived,
3138 TemplateArgument::pack_iterator>
3140 if (TransformTemplateArguments(PackLocIterator(*this,
3141 In.getArgument().pack_begin()),
3142 PackLocIterator(*this,
3143 In.getArgument().pack_end()),
3150 if (In.getArgument().isPackExpansion()) {
3151 // We have a pack expansion, for which we will be substituting into
3153 SourceLocation Ellipsis;
3154 llvm::Optional<unsigned> OrigNumExpansions;
3155 TemplateArgumentLoc Pattern
3156 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3159 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3160 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3161 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3163 // Determine whether the set of unexpanded parameter packs can and should
3166 bool RetainExpansion = false;
3167 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
3168 if (getDerived().TryExpandParameterPacks(Ellipsis,
3169 Pattern.getSourceRange(),
3177 // The transform has determined that we should perform a simple
3178 // transformation on the pack expansion, producing another pack
3180 TemplateArgumentLoc OutPattern;
3181 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3182 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3185 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3187 if (Out.getArgument().isNull())
3190 Outputs.addArgument(Out);
3194 // The transform has determined that we should perform an elementwise
3195 // expansion of the pattern. Do so.
3196 for (unsigned I = 0; I != *NumExpansions; ++I) {
3197 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3199 if (getDerived().TransformTemplateArgument(Pattern, Out))
3202 if (Out.getArgument().containsUnexpandedParameterPack()) {
3203 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3205 if (Out.getArgument().isNull())
3209 Outputs.addArgument(Out);
3212 // If we're supposed to retain a pack expansion, do so by temporarily
3213 // forgetting the partially-substituted parameter pack.
3214 if (RetainExpansion) {
3215 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3217 if (getDerived().TransformTemplateArgument(Pattern, Out))
3220 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3222 if (Out.getArgument().isNull())
3225 Outputs.addArgument(Out);
3232 if (getDerived().TransformTemplateArgument(In, Out))
3235 Outputs.addArgument(Out);
3242 //===----------------------------------------------------------------------===//
3243 // Type transformation
3244 //===----------------------------------------------------------------------===//
3246 template<typename Derived>
3247 QualType TreeTransform<Derived>::TransformType(QualType T) {
3248 if (getDerived().AlreadyTransformed(T))
3251 // Temporary workaround. All of these transformations should
3252 // eventually turn into transformations on TypeLocs.
3253 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3254 getDerived().getBaseLocation());
3256 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3261 return NewDI->getType();
3264 template<typename Derived>
3265 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3266 // Refine the base location to the type's location.
3267 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3268 getDerived().getBaseEntity());
3269 if (getDerived().AlreadyTransformed(DI->getType()))
3274 TypeLoc TL = DI->getTypeLoc();
3275 TLB.reserve(TL.getFullDataSize());
3277 QualType Result = getDerived().TransformType(TLB, TL);
3278 if (Result.isNull())
3281 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3284 template<typename Derived>
3286 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3287 switch (T.getTypeLocClass()) {
3288 #define ABSTRACT_TYPELOC(CLASS, PARENT)
3289 #define TYPELOC(CLASS, PARENT) \
3290 case TypeLoc::CLASS: \
3291 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3292 #include "clang/AST/TypeLocNodes.def"
3295 llvm_unreachable("unhandled type loc!");
3298 /// FIXME: By default, this routine adds type qualifiers only to types
3299 /// that can have qualifiers, and silently suppresses those qualifiers
3300 /// that are not permitted (e.g., qualifiers on reference or function
3301 /// types). This is the right thing for template instantiation, but
3302 /// probably not for other clients.
3303 template<typename Derived>
3305 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
3306 QualifiedTypeLoc T) {
3307 Qualifiers Quals = T.getType().getLocalQualifiers();
3309 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3310 if (Result.isNull())
3313 // Silently suppress qualifiers if the result type can't be qualified.
3314 // FIXME: this is the right thing for template instantiation, but
3315 // probably not for other clients.
3316 if (Result->isFunctionType() || Result->isReferenceType())
3319 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3321 if (Quals.hasObjCLifetime()) {
3322 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3323 Quals.removeObjCLifetime();
3324 else if (Result.getObjCLifetime()) {
3326 // A lifetime qualifier applied to a substituted template parameter
3327 // overrides the lifetime qualifier from the template argument.
3328 if (const SubstTemplateTypeParmType *SubstTypeParam
3329 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3330 QualType Replacement = SubstTypeParam->getReplacementType();
3331 Qualifiers Qs = Replacement.getQualifiers();
3332 Qs.removeObjCLifetime();
3334 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3336 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3337 SubstTypeParam->getReplacedParameter(),
3339 TLB.TypeWasModifiedSafely(Result);
3341 // Otherwise, complain about the addition of a qualifier to an
3342 // already-qualified type.
3343 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
3344 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
3347 Quals.removeObjCLifetime();
3351 if (!Quals.empty()) {
3352 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3353 TLB.push<QualifiedTypeLoc>(Result);
3354 // No location information to preserve.
3360 template<typename Derived>
3362 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3363 QualType ObjectType,
3364 NamedDecl *UnqualLookup,
3366 QualType T = TL.getType();
3367 if (getDerived().AlreadyTransformed(T))
3373 if (isa<TemplateSpecializationType>(T)) {
3374 TemplateSpecializationTypeLoc SpecTL
3375 = cast<TemplateSpecializationTypeLoc>(TL);
3377 TemplateName Template =
3378 getDerived().TransformTemplateName(SS,
3379 SpecTL.getTypePtr()->getTemplateName(),
3380 SpecTL.getTemplateNameLoc(),
3381 ObjectType, UnqualLookup);
3382 if (Template.isNull())
3385 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3387 } else if (isa<DependentTemplateSpecializationType>(T)) {
3388 DependentTemplateSpecializationTypeLoc SpecTL
3389 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3391 TemplateName Template
3392 = getDerived().RebuildTemplateName(SS,
3393 *SpecTL.getTypePtr()->getIdentifier(),
3394 SpecTL.getTemplateNameLoc(),
3395 ObjectType, UnqualLookup);
3396 if (Template.isNull())
3399 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3404 // Nothing special needs to be done for these.
3405 Result = getDerived().TransformType(TLB, TL);
3408 if (Result.isNull())
3411 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3414 template<typename Derived>
3416 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3417 QualType ObjectType,
3418 NamedDecl *UnqualLookup,
3420 // FIXME: Painfully copy-paste from the above!
3422 QualType T = TSInfo->getType();
3423 if (getDerived().AlreadyTransformed(T))
3429 TypeLoc TL = TSInfo->getTypeLoc();
3430 if (isa<TemplateSpecializationType>(T)) {
3431 TemplateSpecializationTypeLoc SpecTL
3432 = cast<TemplateSpecializationTypeLoc>(TL);
3434 TemplateName Template
3435 = getDerived().TransformTemplateName(SS,
3436 SpecTL.getTypePtr()->getTemplateName(),
3437 SpecTL.getTemplateNameLoc(),
3438 ObjectType, UnqualLookup);
3439 if (Template.isNull())
3442 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3444 } else if (isa<DependentTemplateSpecializationType>(T)) {
3445 DependentTemplateSpecializationTypeLoc SpecTL
3446 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3448 TemplateName Template
3449 = getDerived().RebuildTemplateName(SS,
3450 *SpecTL.getTypePtr()->getIdentifier(),
3451 SpecTL.getTemplateNameLoc(),
3452 ObjectType, UnqualLookup);
3453 if (Template.isNull())
3456 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3461 // Nothing special needs to be done for these.
3462 Result = getDerived().TransformType(TLB, TL);
3465 if (Result.isNull())
3468 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3471 template <class TyLoc> static inline
3472 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3473 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3474 NewT.setNameLoc(T.getNameLoc());
3478 template<typename Derived>
3479 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
3481 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3482 NewT.setBuiltinLoc(T.getBuiltinLoc());
3483 if (T.needsExtraLocalData())
3484 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3488 template<typename Derived>
3489 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
3492 return TransformTypeSpecType(TLB, T);
3495 template<typename Derived>
3496 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
3497 PointerTypeLoc TL) {
3498 QualType PointeeType
3499 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3500 if (PointeeType.isNull())
3503 QualType Result = TL.getType();
3504 if (PointeeType->getAs<ObjCObjectType>()) {
3505 // A dependent pointer type 'T *' has is being transformed such
3506 // that an Objective-C class type is being replaced for 'T'. The
3507 // resulting pointer type is an ObjCObjectPointerType, not a
3509 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3511 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3512 NewT.setStarLoc(TL.getStarLoc());
3516 if (getDerived().AlwaysRebuild() ||
3517 PointeeType != TL.getPointeeLoc().getType()) {
3518 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3519 if (Result.isNull())
3523 // Objective-C ARC can add lifetime qualifiers to the type that we're
3525 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3527 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3528 NewT.setSigilLoc(TL.getSigilLoc());
3532 template<typename Derived>
3534 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
3535 BlockPointerTypeLoc TL) {
3536 QualType PointeeType
3537 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3538 if (PointeeType.isNull())
3541 QualType Result = TL.getType();
3542 if (getDerived().AlwaysRebuild() ||
3543 PointeeType != TL.getPointeeLoc().getType()) {
3544 Result = getDerived().RebuildBlockPointerType(PointeeType,
3546 if (Result.isNull())
3550 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3551 NewT.setSigilLoc(TL.getSigilLoc());
3555 /// Transforms a reference type. Note that somewhat paradoxically we
3556 /// don't care whether the type itself is an l-value type or an r-value
3557 /// type; we only care if the type was *written* as an l-value type
3558 /// or an r-value type.
3559 template<typename Derived>
3561 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
3562 ReferenceTypeLoc TL) {
3563 const ReferenceType *T = TL.getTypePtr();
3565 // Note that this works with the pointee-as-written.
3566 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3567 if (PointeeType.isNull())
3570 QualType Result = TL.getType();
3571 if (getDerived().AlwaysRebuild() ||
3572 PointeeType != T->getPointeeTypeAsWritten()) {
3573 Result = getDerived().RebuildReferenceType(PointeeType,
3574 T->isSpelledAsLValue(),
3576 if (Result.isNull())
3580 // Objective-C ARC can add lifetime qualifiers to the type that we're
3582 TLB.TypeWasModifiedSafely(
3583 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3585 // r-value references can be rebuilt as l-value references.
3586 ReferenceTypeLoc NewTL;
3587 if (isa<LValueReferenceType>(Result))
3588 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3590 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3591 NewTL.setSigilLoc(TL.getSigilLoc());
3596 template<typename Derived>
3598 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
3599 LValueReferenceTypeLoc TL) {
3600 return TransformReferenceType(TLB, TL);
3603 template<typename Derived>
3605 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
3606 RValueReferenceTypeLoc TL) {
3607 return TransformReferenceType(TLB, TL);
3610 template<typename Derived>
3612 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
3613 MemberPointerTypeLoc TL) {
3614 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3615 if (PointeeType.isNull())
3618 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3619 TypeSourceInfo* NewClsTInfo = 0;
3621 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3626 const MemberPointerType *T = TL.getTypePtr();
3627 QualType OldClsType = QualType(T->getClass(), 0);
3628 QualType NewClsType;
3630 NewClsType = NewClsTInfo->getType();
3632 NewClsType = getDerived().TransformType(OldClsType);
3633 if (NewClsType.isNull())
3637 QualType Result = TL.getType();
3638 if (getDerived().AlwaysRebuild() ||
3639 PointeeType != T->getPointeeType() ||
3640 NewClsType != OldClsType) {
3641 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
3643 if (Result.isNull())
3647 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3648 NewTL.setSigilLoc(TL.getSigilLoc());
3649 NewTL.setClassTInfo(NewClsTInfo);
3654 template<typename Derived>
3656 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
3657 ConstantArrayTypeLoc TL) {
3658 const ConstantArrayType *T = TL.getTypePtr();
3659 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3660 if (ElementType.isNull())
3663 QualType Result = TL.getType();
3664 if (getDerived().AlwaysRebuild() ||
3665 ElementType != T->getElementType()) {
3666 Result = getDerived().RebuildConstantArrayType(ElementType,
3667 T->getSizeModifier(),
3669 T->getIndexTypeCVRQualifiers(),
3670 TL.getBracketsRange());
3671 if (Result.isNull())
3675 // We might have either a ConstantArrayType or a VariableArrayType now:
3676 // a ConstantArrayType is allowed to have an element type which is a
3677 // VariableArrayType if the type is dependent. Fortunately, all array
3678 // types have the same location layout.
3679 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3680 NewTL.setLBracketLoc(TL.getLBracketLoc());
3681 NewTL.setRBracketLoc(TL.getRBracketLoc());
3683 Expr *Size = TL.getSizeExpr();
3685 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3686 Sema::ConstantEvaluated);
3687 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3688 Size = SemaRef.ActOnConstantExpression(Size).take();
3690 NewTL.setSizeExpr(Size);
3695 template<typename Derived>
3696 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
3697 TypeLocBuilder &TLB,
3698 IncompleteArrayTypeLoc TL) {
3699 const IncompleteArrayType *T = TL.getTypePtr();
3700 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3701 if (ElementType.isNull())
3704 QualType Result = TL.getType();
3705 if (getDerived().AlwaysRebuild() ||
3706 ElementType != T->getElementType()) {
3707 Result = getDerived().RebuildIncompleteArrayType(ElementType,
3708 T->getSizeModifier(),
3709 T->getIndexTypeCVRQualifiers(),
3710 TL.getBracketsRange());
3711 if (Result.isNull())
3715 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3716 NewTL.setLBracketLoc(TL.getLBracketLoc());
3717 NewTL.setRBracketLoc(TL.getRBracketLoc());
3718 NewTL.setSizeExpr(0);
3723 template<typename Derived>
3725 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
3726 VariableArrayTypeLoc TL) {
3727 const VariableArrayType *T = TL.getTypePtr();
3728 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3729 if (ElementType.isNull())
3732 ExprResult SizeResult
3733 = getDerived().TransformExpr(T->getSizeExpr());
3734 if (SizeResult.isInvalid())
3737 Expr *Size = SizeResult.take();
3739 QualType Result = TL.getType();
3740 if (getDerived().AlwaysRebuild() ||
3741 ElementType != T->getElementType() ||
3742 Size != T->getSizeExpr()) {
3743 Result = getDerived().RebuildVariableArrayType(ElementType,
3744 T->getSizeModifier(),
3746 T->getIndexTypeCVRQualifiers(),
3747 TL.getBracketsRange());
3748 if (Result.isNull())
3752 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3753 NewTL.setLBracketLoc(TL.getLBracketLoc());
3754 NewTL.setRBracketLoc(TL.getRBracketLoc());
3755 NewTL.setSizeExpr(Size);
3760 template<typename Derived>
3762 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
3763 DependentSizedArrayTypeLoc TL) {
3764 const DependentSizedArrayType *T = TL.getTypePtr();
3765 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3766 if (ElementType.isNull())
3769 // Array bounds are constant expressions.
3770 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3771 Sema::ConstantEvaluated);
3773 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3774 Expr *origSize = TL.getSizeExpr();
3775 if (!origSize) origSize = T->getSizeExpr();
3777 ExprResult sizeResult
3778 = getDerived().TransformExpr(origSize);
3779 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
3780 if (sizeResult.isInvalid())
3783 Expr *size = sizeResult.get();
3785 QualType Result = TL.getType();
3786 if (getDerived().AlwaysRebuild() ||
3787 ElementType != T->getElementType() ||
3789 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3790 T->getSizeModifier(),
3792 T->getIndexTypeCVRQualifiers(),
3793 TL.getBracketsRange());
3794 if (Result.isNull())
3798 // We might have any sort of array type now, but fortunately they
3799 // all have the same location layout.
3800 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3801 NewTL.setLBracketLoc(TL.getLBracketLoc());
3802 NewTL.setRBracketLoc(TL.getRBracketLoc());
3803 NewTL.setSizeExpr(size);
3808 template<typename Derived>
3809 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3810 TypeLocBuilder &TLB,
3811 DependentSizedExtVectorTypeLoc TL) {
3812 const DependentSizedExtVectorType *T = TL.getTypePtr();
3814 // FIXME: ext vector locs should be nested
3815 QualType ElementType = getDerived().TransformType(T->getElementType());
3816 if (ElementType.isNull())
3819 // Vector sizes are constant expressions.
3820 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3821 Sema::ConstantEvaluated);
3823 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3824 Size = SemaRef.ActOnConstantExpression(Size);
3825 if (Size.isInvalid())
3828 QualType Result = TL.getType();
3829 if (getDerived().AlwaysRebuild() ||
3830 ElementType != T->getElementType() ||
3831 Size.get() != T->getSizeExpr()) {
3832 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
3834 T->getAttributeLoc());
3835 if (Result.isNull())
3839 // Result might be dependent or not.
3840 if (isa<DependentSizedExtVectorType>(Result)) {
3841 DependentSizedExtVectorTypeLoc NewTL
3842 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3843 NewTL.setNameLoc(TL.getNameLoc());
3845 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3846 NewTL.setNameLoc(TL.getNameLoc());
3852 template<typename Derived>
3853 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
3855 const VectorType *T = TL.getTypePtr();
3856 QualType ElementType = getDerived().TransformType(T->getElementType());
3857 if (ElementType.isNull())
3860 QualType Result = TL.getType();
3861 if (getDerived().AlwaysRebuild() ||
3862 ElementType != T->getElementType()) {
3863 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3864 T->getVectorKind());
3865 if (Result.isNull())
3869 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3870 NewTL.setNameLoc(TL.getNameLoc());
3875 template<typename Derived>
3876 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
3877 ExtVectorTypeLoc TL) {
3878 const VectorType *T = TL.getTypePtr();
3879 QualType ElementType = getDerived().TransformType(T->getElementType());
3880 if (ElementType.isNull())
3883 QualType Result = TL.getType();
3884 if (getDerived().AlwaysRebuild() ||
3885 ElementType != T->getElementType()) {
3886 Result = getDerived().RebuildExtVectorType(ElementType,
3887 T->getNumElements(),
3888 /*FIXME*/ SourceLocation());
3889 if (Result.isNull())
3893 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3894 NewTL.setNameLoc(TL.getNameLoc());
3899 template<typename Derived>
3901 TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3902 int indexAdjustment,
3903 llvm::Optional<unsigned> NumExpansions,
3904 bool ExpectParameterPack) {
3905 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3906 TypeSourceInfo *NewDI = 0;
3908 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3909 // If we're substituting into a pack expansion type and we know the
3910 // length we want to expand to, just substitute for the pattern.
3911 TypeLoc OldTL = OldDI->getTypeLoc();
3912 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3915 TypeLoc NewTL = OldDI->getTypeLoc();
3916 TLB.reserve(NewTL.getFullDataSize());
3918 QualType Result = getDerived().TransformType(TLB,
3919 OldExpansionTL.getPatternLoc());
3920 if (Result.isNull())
3923 Result = RebuildPackExpansionType(Result,
3924 OldExpansionTL.getPatternLoc().getSourceRange(),
3925 OldExpansionTL.getEllipsisLoc(),
3927 if (Result.isNull())
3930 PackExpansionTypeLoc NewExpansionTL
3931 = TLB.push<PackExpansionTypeLoc>(Result);
3932 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3933 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3935 NewDI = getDerived().TransformType(OldDI);
3939 if (NewDI == OldDI && indexAdjustment == 0)
3942 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3943 OldParm->getDeclContext(),
3944 OldParm->getInnerLocStart(),
3945 OldParm->getLocation(),
3946 OldParm->getIdentifier(),
3949 OldParm->getStorageClass(),
3950 OldParm->getStorageClassAsWritten(),
3952 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3953 OldParm->getFunctionScopeIndex() + indexAdjustment);
3957 template<typename Derived>
3958 bool TreeTransform<Derived>::
3959 TransformFunctionTypeParams(SourceLocation Loc,
3960 ParmVarDecl **Params, unsigned NumParams,
3961 const QualType *ParamTypes,
3962 SmallVectorImpl<QualType> &OutParamTypes,
3963 SmallVectorImpl<ParmVarDecl*> *PVars) {
3964 int indexAdjustment = 0;
3966 for (unsigned i = 0; i != NumParams; ++i) {
3967 if (ParmVarDecl *OldParm = Params[i]) {
3968 assert(OldParm->getFunctionScopeIndex() == i);
3970 llvm::Optional<unsigned> NumExpansions;
3971 ParmVarDecl *NewParm = 0;
3972 if (OldParm->isParameterPack()) {
3973 // We have a function parameter pack that may need to be expanded.
3974 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3976 // Find the parameter packs that could be expanded.
3977 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3978 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3979 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3980 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3981 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3983 // Determine whether we should expand the parameter packs.
3984 bool ShouldExpand = false;
3985 bool RetainExpansion = false;
3986 llvm::Optional<unsigned> OrigNumExpansions
3987 = ExpansionTL.getTypePtr()->getNumExpansions();
3988 NumExpansions = OrigNumExpansions;
3989 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3990 Pattern.getSourceRange(),
3999 // Expand the function parameter pack into multiple, separate
4001 getDerived().ExpandingFunctionParameterPack(OldParm);
4002 for (unsigned I = 0; I != *NumExpansions; ++I) {
4003 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4004 ParmVarDecl *NewParm
4005 = getDerived().TransformFunctionTypeParam(OldParm,
4008 /*ExpectParameterPack=*/false);
4012 OutParamTypes.push_back(NewParm->getType());
4014 PVars->push_back(NewParm);
4017 // If we're supposed to retain a pack expansion, do so by temporarily
4018 // forgetting the partially-substituted parameter pack.
4019 if (RetainExpansion) {
4020 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4021 ParmVarDecl *NewParm
4022 = getDerived().TransformFunctionTypeParam(OldParm,
4025 /*ExpectParameterPack=*/false);
4029 OutParamTypes.push_back(NewParm->getType());
4031 PVars->push_back(NewParm);
4034 // The next parameter should have the same adjustment as the
4035 // last thing we pushed, but we post-incremented indexAdjustment
4036 // on every push. Also, if we push nothing, the adjustment should
4040 // We're done with the pack expansion.
4044 // We'll substitute the parameter now without expanding the pack
4046 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4047 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4050 /*ExpectParameterPack=*/true);
4052 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4054 llvm::Optional<unsigned>(),
4055 /*ExpectParameterPack=*/false);
4061 OutParamTypes.push_back(NewParm->getType());
4063 PVars->push_back(NewParm);
4067 // Deal with the possibility that we don't have a parameter
4068 // declaration for this parameter.
4069 QualType OldType = ParamTypes[i];
4070 bool IsPackExpansion = false;
4071 llvm::Optional<unsigned> NumExpansions;
4073 if (const PackExpansionType *Expansion
4074 = dyn_cast<PackExpansionType>(OldType)) {
4075 // We have a function parameter pack that may need to be expanded.
4076 QualType Pattern = Expansion->getPattern();
4077 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4078 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4080 // Determine whether we should expand the parameter packs.
4081 bool ShouldExpand = false;
4082 bool RetainExpansion = false;
4083 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4092 // Expand the function parameter pack into multiple, separate
4094 for (unsigned I = 0; I != *NumExpansions; ++I) {
4095 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4096 QualType NewType = getDerived().TransformType(Pattern);
4097 if (NewType.isNull())
4100 OutParamTypes.push_back(NewType);
4102 PVars->push_back(0);
4105 // We're done with the pack expansion.
4109 // If we're supposed to retain a pack expansion, do so by temporarily
4110 // forgetting the partially-substituted parameter pack.
4111 if (RetainExpansion) {
4112 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4113 QualType NewType = getDerived().TransformType(Pattern);
4114 if (NewType.isNull())
4117 OutParamTypes.push_back(NewType);
4119 PVars->push_back(0);
4122 // We'll substitute the parameter now without expanding the pack
4124 OldType = Expansion->getPattern();
4125 IsPackExpansion = true;
4126 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4127 NewType = getDerived().TransformType(OldType);
4129 NewType = getDerived().TransformType(OldType);
4132 if (NewType.isNull())
4135 if (IsPackExpansion)
4136 NewType = getSema().Context.getPackExpansionType(NewType,
4139 OutParamTypes.push_back(NewType);
4141 PVars->push_back(0);
4146 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4147 if (ParmVarDecl *parm = (*PVars)[i])
4148 assert(parm->getFunctionScopeIndex() == i);
4155 template<typename Derived>
4157 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4158 FunctionProtoTypeLoc TL) {
4159 // Transform the parameters and return type.
4161 // We instantiate in source order, with the return type first followed by
4162 // the parameters, because users tend to expect this (even if they shouldn't
4165 // When the function has a trailing return type, we instantiate the
4166 // parameters before the return type, since the return type can then refer
4167 // to the parameters themselves (via decltype, sizeof, etc.).
4169 SmallVector<QualType, 4> ParamTypes;
4170 SmallVector<ParmVarDecl*, 4> ParamDecls;
4171 const FunctionProtoType *T = TL.getTypePtr();
4173 QualType ResultType;
4175 if (TL.getTrailingReturn()) {
4176 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4179 TL.getTypePtr()->arg_type_begin(),
4180 ParamTypes, &ParamDecls))
4183 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4184 if (ResultType.isNull())
4188 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4189 if (ResultType.isNull())
4192 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4195 TL.getTypePtr()->arg_type_begin(),
4196 ParamTypes, &ParamDecls))
4200 QualType Result = TL.getType();
4201 if (getDerived().AlwaysRebuild() ||
4202 ResultType != T->getResultType() ||
4203 T->getNumArgs() != ParamTypes.size() ||
4204 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4205 Result = getDerived().RebuildFunctionProtoType(ResultType,
4209 T->hasTrailingReturn(),
4211 T->getRefQualifier(),
4213 if (Result.isNull())
4217 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4218 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4219 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4220 NewTL.setTrailingReturn(TL.getTrailingReturn());
4221 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4222 NewTL.setArg(i, ParamDecls[i]);
4227 template<typename Derived>
4228 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4229 TypeLocBuilder &TLB,
4230 FunctionNoProtoTypeLoc TL) {
4231 const FunctionNoProtoType *T = TL.getTypePtr();
4232 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4233 if (ResultType.isNull())
4236 QualType Result = TL.getType();
4237 if (getDerived().AlwaysRebuild() ||
4238 ResultType != T->getResultType())
4239 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4241 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4242 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4243 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4244 NewTL.setTrailingReturn(false);
4249 template<typename Derived> QualType
4250 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
4251 UnresolvedUsingTypeLoc TL) {
4252 const UnresolvedUsingType *T = TL.getTypePtr();
4253 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4257 QualType Result = TL.getType();
4258 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4259 Result = getDerived().RebuildUnresolvedUsingType(D);
4260 if (Result.isNull())
4264 // We might get an arbitrary type spec type back. We should at
4265 // least always get a type spec type, though.
4266 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4267 NewTL.setNameLoc(TL.getNameLoc());
4272 template<typename Derived>
4273 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
4274 TypedefTypeLoc TL) {
4275 const TypedefType *T = TL.getTypePtr();
4276 TypedefNameDecl *Typedef
4277 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4282 QualType Result = TL.getType();
4283 if (getDerived().AlwaysRebuild() ||
4284 Typedef != T->getDecl()) {
4285 Result = getDerived().RebuildTypedefType(Typedef);
4286 if (Result.isNull())
4290 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4291 NewTL.setNameLoc(TL.getNameLoc());
4296 template<typename Derived>
4297 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
4298 TypeOfExprTypeLoc TL) {
4299 // typeof expressions are not potentially evaluated contexts
4300 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
4302 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4306 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4310 QualType Result = TL.getType();
4311 if (getDerived().AlwaysRebuild() ||
4312 E.get() != TL.getUnderlyingExpr()) {
4313 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4314 if (Result.isNull())
4319 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4320 NewTL.setTypeofLoc(TL.getTypeofLoc());
4321 NewTL.setLParenLoc(TL.getLParenLoc());
4322 NewTL.setRParenLoc(TL.getRParenLoc());
4327 template<typename Derived>
4328 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
4330 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4331 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4335 QualType Result = TL.getType();
4336 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4337 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4338 if (Result.isNull())
4342 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4343 NewTL.setTypeofLoc(TL.getTypeofLoc());
4344 NewTL.setLParenLoc(TL.getLParenLoc());
4345 NewTL.setRParenLoc(TL.getRParenLoc());
4346 NewTL.setUnderlyingTInfo(New_Under_TI);
4351 template<typename Derived>
4352 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
4353 DecltypeTypeLoc TL) {
4354 const DecltypeType *T = TL.getTypePtr();
4356 // decltype expressions are not potentially evaluated contexts
4357 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4358 /*IsDecltype=*/ true);
4360 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4364 E = getSema().ActOnDecltypeExpression(E.take());
4368 QualType Result = TL.getType();
4369 if (getDerived().AlwaysRebuild() ||
4370 E.get() != T->getUnderlyingExpr()) {
4371 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4372 if (Result.isNull())
4377 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4378 NewTL.setNameLoc(TL.getNameLoc());
4383 template<typename Derived>
4384 QualType TreeTransform<Derived>::TransformUnaryTransformType(
4385 TypeLocBuilder &TLB,
4386 UnaryTransformTypeLoc TL) {
4387 QualType Result = TL.getType();
4388 if (Result->isDependentType()) {
4389 const UnaryTransformType *T = TL.getTypePtr();
4391 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4392 Result = getDerived().RebuildUnaryTransformType(NewBase,
4395 if (Result.isNull())
4399 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4400 NewTL.setKWLoc(TL.getKWLoc());
4401 NewTL.setParensRange(TL.getParensRange());
4402 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4406 template<typename Derived>
4407 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4409 const AutoType *T = TL.getTypePtr();
4410 QualType OldDeduced = T->getDeducedType();
4411 QualType NewDeduced;
4412 if (!OldDeduced.isNull()) {
4413 NewDeduced = getDerived().TransformType(OldDeduced);
4414 if (NewDeduced.isNull())
4418 QualType Result = TL.getType();
4419 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4420 Result = getDerived().RebuildAutoType(NewDeduced);
4421 if (Result.isNull())
4425 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4426 NewTL.setNameLoc(TL.getNameLoc());
4431 template<typename Derived>
4432 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
4434 const RecordType *T = TL.getTypePtr();
4436 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4441 QualType Result = TL.getType();
4442 if (getDerived().AlwaysRebuild() ||
4443 Record != T->getDecl()) {
4444 Result = getDerived().RebuildRecordType(Record);
4445 if (Result.isNull())
4449 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4450 NewTL.setNameLoc(TL.getNameLoc());
4455 template<typename Derived>
4456 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
4458 const EnumType *T = TL.getTypePtr();
4460 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4465 QualType Result = TL.getType();
4466 if (getDerived().AlwaysRebuild() ||
4467 Enum != T->getDecl()) {
4468 Result = getDerived().RebuildEnumType(Enum);
4469 if (Result.isNull())
4473 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4474 NewTL.setNameLoc(TL.getNameLoc());
4479 template<typename Derived>
4480 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4481 TypeLocBuilder &TLB,
4482 InjectedClassNameTypeLoc TL) {
4483 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4484 TL.getTypePtr()->getDecl());
4485 if (!D) return QualType();
4487 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4488 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4492 template<typename Derived>
4493 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4494 TypeLocBuilder &TLB,
4495 TemplateTypeParmTypeLoc TL) {
4496 return TransformTypeSpecType(TLB, TL);
4499 template<typename Derived>
4500 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4501 TypeLocBuilder &TLB,
4502 SubstTemplateTypeParmTypeLoc TL) {
4503 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4505 // Substitute into the replacement type, which itself might involve something
4506 // that needs to be transformed. This only tends to occur with default
4507 // template arguments of template template parameters.
4508 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4509 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4510 if (Replacement.isNull())
4513 // Always canonicalize the replacement type.
4514 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4516 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4519 // Propagate type-source information.
4520 SubstTemplateTypeParmTypeLoc NewTL
4521 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4522 NewTL.setNameLoc(TL.getNameLoc());
4527 template<typename Derived>
4528 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4529 TypeLocBuilder &TLB,
4530 SubstTemplateTypeParmPackTypeLoc TL) {
4531 return TransformTypeSpecType(TLB, TL);
4534 template<typename Derived>
4535 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4536 TypeLocBuilder &TLB,
4537 TemplateSpecializationTypeLoc TL) {
4538 const TemplateSpecializationType *T = TL.getTypePtr();
4540 // The nested-name-specifier never matters in a TemplateSpecializationType,
4541 // because we can't have a dependent nested-name-specifier anyway.
4543 TemplateName Template
4544 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4545 TL.getTemplateNameLoc());
4546 if (Template.isNull())
4549 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4552 template<typename Derived>
4553 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4555 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4556 if (ValueType.isNull())
4559 QualType Result = TL.getType();
4560 if (getDerived().AlwaysRebuild() ||
4561 ValueType != TL.getValueLoc().getType()) {
4562 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4563 if (Result.isNull())
4567 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4568 NewTL.setKWLoc(TL.getKWLoc());
4569 NewTL.setLParenLoc(TL.getLParenLoc());
4570 NewTL.setRParenLoc(TL.getRParenLoc());
4576 /// \brief Simple iterator that traverses the template arguments in a
4577 /// container that provides a \c getArgLoc() member function.
4579 /// This iterator is intended to be used with the iterator form of
4580 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4581 template<typename ArgLocContainer>
4582 class TemplateArgumentLocContainerIterator {
4583 ArgLocContainer *Container;
4587 typedef TemplateArgumentLoc value_type;
4588 typedef TemplateArgumentLoc reference;
4589 typedef int difference_type;
4590 typedef std::input_iterator_tag iterator_category;
4593 TemplateArgumentLoc Arg;
4596 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4598 const TemplateArgumentLoc *operator->() const {
4604 TemplateArgumentLocContainerIterator() {}
4606 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4608 : Container(&Container), Index(Index) { }
4610 TemplateArgumentLocContainerIterator &operator++() {
4615 TemplateArgumentLocContainerIterator operator++(int) {
4616 TemplateArgumentLocContainerIterator Old(*this);
4621 TemplateArgumentLoc operator*() const {
4622 return Container->getArgLoc(Index);
4625 pointer operator->() const {
4626 return pointer(Container->getArgLoc(Index));
4629 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4630 const TemplateArgumentLocContainerIterator &Y) {
4631 return X.Container == Y.Container && X.Index == Y.Index;
4634 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4635 const TemplateArgumentLocContainerIterator &Y) {
4642 template <typename Derived>
4643 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4644 TypeLocBuilder &TLB,
4645 TemplateSpecializationTypeLoc TL,
4646 TemplateName Template) {
4647 TemplateArgumentListInfo NewTemplateArgs;
4648 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4649 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4650 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4652 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4653 ArgIterator(TL, TL.getNumArgs()),
4657 // FIXME: maybe don't rebuild if all the template arguments are the same.
4660 getDerived().RebuildTemplateSpecializationType(Template,
4661 TL.getTemplateNameLoc(),
4664 if (!Result.isNull()) {
4665 // Specializations of template template parameters are represented as
4666 // TemplateSpecializationTypes, and substitution of type alias templates
4667 // within a dependent context can transform them into
4668 // DependentTemplateSpecializationTypes.
4669 if (isa<DependentTemplateSpecializationType>(Result)) {
4670 DependentTemplateSpecializationTypeLoc NewTL
4671 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4672 NewTL.setElaboratedKeywordLoc(SourceLocation());
4673 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4674 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4675 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4676 NewTL.setLAngleLoc(TL.getLAngleLoc());
4677 NewTL.setRAngleLoc(TL.getRAngleLoc());
4678 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4679 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4683 TemplateSpecializationTypeLoc NewTL
4684 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4685 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4686 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4687 NewTL.setLAngleLoc(TL.getLAngleLoc());
4688 NewTL.setRAngleLoc(TL.getRAngleLoc());
4689 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4690 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4696 template <typename Derived>
4697 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4698 TypeLocBuilder &TLB,
4699 DependentTemplateSpecializationTypeLoc TL,
4700 TemplateName Template,
4702 TemplateArgumentListInfo NewTemplateArgs;
4703 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4704 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4705 typedef TemplateArgumentLocContainerIterator<
4706 DependentTemplateSpecializationTypeLoc> ArgIterator;
4707 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4708 ArgIterator(TL, TL.getNumArgs()),
4712 // FIXME: maybe don't rebuild if all the template arguments are the same.
4714 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4716 = getSema().Context.getDependentTemplateSpecializationType(
4717 TL.getTypePtr()->getKeyword(),
4718 DTN->getQualifier(),
4719 DTN->getIdentifier(),
4722 DependentTemplateSpecializationTypeLoc NewTL
4723 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4724 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4725 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
4726 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4727 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4728 NewTL.setLAngleLoc(TL.getLAngleLoc());
4729 NewTL.setRAngleLoc(TL.getRAngleLoc());
4730 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4731 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4736 = getDerived().RebuildTemplateSpecializationType(Template,
4737 TL.getTemplateNameLoc(),
4740 if (!Result.isNull()) {
4741 /// FIXME: Wrap this in an elaborated-type-specifier?
4742 TemplateSpecializationTypeLoc NewTL
4743 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4744 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4745 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4746 NewTL.setLAngleLoc(TL.getLAngleLoc());
4747 NewTL.setRAngleLoc(TL.getRAngleLoc());
4748 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4749 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4755 template<typename Derived>
4757 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
4758 ElaboratedTypeLoc TL) {
4759 const ElaboratedType *T = TL.getTypePtr();
4761 NestedNameSpecifierLoc QualifierLoc;
4762 // NOTE: the qualifier in an ElaboratedType is optional.
4763 if (TL.getQualifierLoc()) {
4765 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4770 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4771 if (NamedT.isNull())
4774 // C++0x [dcl.type.elab]p2:
4775 // If the identifier resolves to a typedef-name or the simple-template-id
4776 // resolves to an alias template specialization, the
4777 // elaborated-type-specifier is ill-formed.
4778 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4779 if (const TemplateSpecializationType *TST =
4780 NamedT->getAs<TemplateSpecializationType>()) {
4781 TemplateName Template = TST->getTemplateName();
4782 if (TypeAliasTemplateDecl *TAT =
4783 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4784 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4785 diag::err_tag_reference_non_tag) << 4;
4786 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4791 QualType Result = TL.getType();
4792 if (getDerived().AlwaysRebuild() ||
4793 QualifierLoc != TL.getQualifierLoc() ||
4794 NamedT != T->getNamedType()) {
4795 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
4797 QualifierLoc, NamedT);
4798 if (Result.isNull())
4802 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4803 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4804 NewTL.setQualifierLoc(QualifierLoc);
4808 template<typename Derived>
4809 QualType TreeTransform<Derived>::TransformAttributedType(
4810 TypeLocBuilder &TLB,
4811 AttributedTypeLoc TL) {
4812 const AttributedType *oldType = TL.getTypePtr();
4813 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4814 if (modifiedType.isNull())
4817 QualType result = TL.getType();
4819 // FIXME: dependent operand expressions?
4820 if (getDerived().AlwaysRebuild() ||
4821 modifiedType != oldType->getModifiedType()) {
4822 // TODO: this is really lame; we should really be rebuilding the
4823 // equivalent type from first principles.
4824 QualType equivalentType
4825 = getDerived().TransformType(oldType->getEquivalentType());
4826 if (equivalentType.isNull())
4828 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4833 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4834 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4835 if (TL.hasAttrOperand())
4836 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4837 if (TL.hasAttrExprOperand())
4838 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4839 else if (TL.hasAttrEnumOperand())
4840 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4845 template<typename Derived>
4847 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4849 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4853 QualType Result = TL.getType();
4854 if (getDerived().AlwaysRebuild() ||
4855 Inner != TL.getInnerLoc().getType()) {
4856 Result = getDerived().RebuildParenType(Inner);
4857 if (Result.isNull())
4861 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4862 NewTL.setLParenLoc(TL.getLParenLoc());
4863 NewTL.setRParenLoc(TL.getRParenLoc());
4867 template<typename Derived>
4868 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
4869 DependentNameTypeLoc TL) {
4870 const DependentNameType *T = TL.getTypePtr();
4872 NestedNameSpecifierLoc QualifierLoc
4873 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4878 = getDerived().RebuildDependentNameType(T->getKeyword(),
4879 TL.getElaboratedKeywordLoc(),
4883 if (Result.isNull())
4886 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4887 QualType NamedT = ElabT->getNamedType();
4888 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4890 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4891 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4892 NewTL.setQualifierLoc(QualifierLoc);
4894 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4895 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4896 NewTL.setQualifierLoc(QualifierLoc);
4897 NewTL.setNameLoc(TL.getNameLoc());
4902 template<typename Derived>
4903 QualType TreeTransform<Derived>::
4904 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4905 DependentTemplateSpecializationTypeLoc TL) {
4906 NestedNameSpecifierLoc QualifierLoc;
4907 if (TL.getQualifierLoc()) {
4909 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4915 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
4918 template<typename Derived>
4919 QualType TreeTransform<Derived>::
4920 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4921 DependentTemplateSpecializationTypeLoc TL,
4922 NestedNameSpecifierLoc QualifierLoc) {
4923 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4925 TemplateArgumentListInfo NewTemplateArgs;
4926 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4927 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4929 typedef TemplateArgumentLocContainerIterator<
4930 DependentTemplateSpecializationTypeLoc> ArgIterator;
4931 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4932 ArgIterator(TL, TL.getNumArgs()),
4937 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4940 TL.getTemplateNameLoc(),
4942 if (Result.isNull())
4945 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4946 QualType NamedT = ElabT->getNamedType();
4948 // Copy information relevant to the template specialization.
4949 TemplateSpecializationTypeLoc NamedTL
4950 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4951 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4952 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4953 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4954 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4955 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
4956 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
4958 // Copy information relevant to the elaborated type.
4959 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4960 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4961 NewTL.setQualifierLoc(QualifierLoc);
4962 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4963 DependentTemplateSpecializationTypeLoc SpecTL
4964 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4965 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4966 SpecTL.setQualifierLoc(QualifierLoc);
4967 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4968 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4969 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4970 SpecTL.setRAngleLoc(TL.getRAngleLoc());
4971 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
4972 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
4974 TemplateSpecializationTypeLoc SpecTL
4975 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4976 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4977 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4978 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4979 SpecTL.setRAngleLoc(TL.getRAngleLoc());
4980 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
4981 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
4986 template<typename Derived>
4987 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4988 PackExpansionTypeLoc TL) {
4990 = getDerived().TransformType(TLB, TL.getPatternLoc());
4991 if (Pattern.isNull())
4994 QualType Result = TL.getType();
4995 if (getDerived().AlwaysRebuild() ||
4996 Pattern != TL.getPatternLoc().getType()) {
4997 Result = getDerived().RebuildPackExpansionType(Pattern,
4998 TL.getPatternLoc().getSourceRange(),
4999 TL.getEllipsisLoc(),
5000 TL.getTypePtr()->getNumExpansions());
5001 if (Result.isNull())
5005 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5006 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5010 template<typename Derived>
5012 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5013 ObjCInterfaceTypeLoc TL) {
5014 // ObjCInterfaceType is never dependent.
5015 TLB.pushFullCopy(TL);
5016 return TL.getType();
5019 template<typename Derived>
5021 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5022 ObjCObjectTypeLoc TL) {
5023 // ObjCObjectType is never dependent.
5024 TLB.pushFullCopy(TL);
5025 return TL.getType();
5028 template<typename Derived>
5030 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
5031 ObjCObjectPointerTypeLoc TL) {
5032 // ObjCObjectPointerType is never dependent.
5033 TLB.pushFullCopy(TL);
5034 return TL.getType();
5037 //===----------------------------------------------------------------------===//
5038 // Statement transformation
5039 //===----------------------------------------------------------------------===//
5040 template<typename Derived>
5042 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
5043 return SemaRef.Owned(S);
5046 template<typename Derived>
5048 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5049 return getDerived().TransformCompoundStmt(S, false);
5052 template<typename Derived>
5054 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
5056 Sema::CompoundScopeRAII CompoundScope(getSema());
5058 bool SubStmtInvalid = false;
5059 bool SubStmtChanged = false;
5060 ASTOwningVector<Stmt*> Statements(getSema());
5061 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5063 StmtResult Result = getDerived().TransformStmt(*B);
5064 if (Result.isInvalid()) {
5065 // Immediately fail if this was a DeclStmt, since it's very
5066 // likely that this will cause problems for future statements.
5067 if (isa<DeclStmt>(*B))
5070 // Otherwise, just keep processing substatements and fail later.
5071 SubStmtInvalid = true;
5075 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5076 Statements.push_back(Result.takeAs<Stmt>());
5082 if (!getDerived().AlwaysRebuild() &&
5084 return SemaRef.Owned(S);
5086 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5087 move_arg(Statements),
5092 template<typename Derived>
5094 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
5095 ExprResult LHS, RHS;
5097 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5098 Sema::ConstantEvaluated);
5100 // Transform the left-hand case value.
5101 LHS = getDerived().TransformExpr(S->getLHS());
5102 LHS = SemaRef.ActOnConstantExpression(LHS);
5103 if (LHS.isInvalid())
5106 // Transform the right-hand case value (for the GNU case-range extension).
5107 RHS = getDerived().TransformExpr(S->getRHS());
5108 RHS = SemaRef.ActOnConstantExpression(RHS);
5109 if (RHS.isInvalid())
5113 // Build the case statement.
5114 // Case statements are always rebuilt so that they will attached to their
5115 // transformed switch statement.
5116 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
5118 S->getEllipsisLoc(),
5121 if (Case.isInvalid())
5124 // Transform the statement following the case
5125 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5126 if (SubStmt.isInvalid())
5129 // Attach the body to the case statement
5130 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
5133 template<typename Derived>
5135 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
5136 // Transform the statement following the default case
5137 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5138 if (SubStmt.isInvalid())
5141 // Default statements are always rebuilt
5142 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
5146 template<typename Derived>
5148 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
5149 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5150 if (SubStmt.isInvalid())
5153 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5159 // FIXME: Pass the real colon location in.
5160 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
5161 cast<LabelDecl>(LD), SourceLocation(),
5165 template<typename Derived>
5167 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
5168 // Transform the condition
5170 VarDecl *ConditionVar = 0;
5171 if (S->getConditionVariable()) {
5173 = cast_or_null<VarDecl>(
5174 getDerived().TransformDefinition(
5175 S->getConditionVariable()->getLocation(),
5176 S->getConditionVariable()));
5180 Cond = getDerived().TransformExpr(S->getCond());
5182 if (Cond.isInvalid())
5185 // Convert the condition to a boolean value.
5187 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5189 if (CondE.isInvalid())
5196 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5197 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5200 // Transform the "then" branch.
5201 StmtResult Then = getDerived().TransformStmt(S->getThen());
5202 if (Then.isInvalid())
5205 // Transform the "else" branch.
5206 StmtResult Else = getDerived().TransformStmt(S->getElse());
5207 if (Else.isInvalid())
5210 if (!getDerived().AlwaysRebuild() &&
5211 FullCond.get() == S->getCond() &&
5212 ConditionVar == S->getConditionVariable() &&
5213 Then.get() == S->getThen() &&
5214 Else.get() == S->getElse())
5215 return SemaRef.Owned(S);
5217 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
5219 S->getElseLoc(), Else.get());
5222 template<typename Derived>
5224 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
5225 // Transform the condition.
5227 VarDecl *ConditionVar = 0;
5228 if (S->getConditionVariable()) {
5230 = cast_or_null<VarDecl>(
5231 getDerived().TransformDefinition(
5232 S->getConditionVariable()->getLocation(),
5233 S->getConditionVariable()));
5237 Cond = getDerived().TransformExpr(S->getCond());
5239 if (Cond.isInvalid())
5243 // Rebuild the switch statement.
5245 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5247 if (Switch.isInvalid())
5250 // Transform the body of the switch statement.
5251 StmtResult Body = getDerived().TransformStmt(S->getBody());
5252 if (Body.isInvalid())
5255 // Complete the switch statement.
5256 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5260 template<typename Derived>
5262 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
5263 // Transform the condition
5265 VarDecl *ConditionVar = 0;
5266 if (S->getConditionVariable()) {
5268 = cast_or_null<VarDecl>(
5269 getDerived().TransformDefinition(
5270 S->getConditionVariable()->getLocation(),
5271 S->getConditionVariable()));
5275 Cond = getDerived().TransformExpr(S->getCond());
5277 if (Cond.isInvalid())
5281 // Convert the condition to a boolean value.
5282 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5284 if (CondE.isInvalid())
5290 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5291 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5294 // Transform the body
5295 StmtResult Body = getDerived().TransformStmt(S->getBody());
5296 if (Body.isInvalid())
5299 if (!getDerived().AlwaysRebuild() &&
5300 FullCond.get() == S->getCond() &&
5301 ConditionVar == S->getConditionVariable() &&
5302 Body.get() == S->getBody())
5305 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
5306 ConditionVar, Body.get());
5309 template<typename Derived>
5311 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
5312 // Transform the body
5313 StmtResult Body = getDerived().TransformStmt(S->getBody());
5314 if (Body.isInvalid())
5317 // Transform the condition
5318 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5319 if (Cond.isInvalid())
5322 if (!getDerived().AlwaysRebuild() &&
5323 Cond.get() == S->getCond() &&
5324 Body.get() == S->getBody())
5325 return SemaRef.Owned(S);
5327 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5328 /*FIXME:*/S->getWhileLoc(), Cond.get(),
5332 template<typename Derived>
5334 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
5335 // Transform the initialization statement
5336 StmtResult Init = getDerived().TransformStmt(S->getInit());
5337 if (Init.isInvalid())
5340 // Transform the condition
5342 VarDecl *ConditionVar = 0;
5343 if (S->getConditionVariable()) {
5345 = cast_or_null<VarDecl>(
5346 getDerived().TransformDefinition(
5347 S->getConditionVariable()->getLocation(),
5348 S->getConditionVariable()));
5352 Cond = getDerived().TransformExpr(S->getCond());
5354 if (Cond.isInvalid())
5358 // Convert the condition to a boolean value.
5359 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5361 if (CondE.isInvalid())
5368 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5369 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5372 // Transform the increment
5373 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5374 if (Inc.isInvalid())
5377 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5378 if (S->getInc() && !FullInc.get())
5381 // Transform the body
5382 StmtResult Body = getDerived().TransformStmt(S->getBody());
5383 if (Body.isInvalid())
5386 if (!getDerived().AlwaysRebuild() &&
5387 Init.get() == S->getInit() &&
5388 FullCond.get() == S->getCond() &&
5389 Inc.get() == S->getInc() &&
5390 Body.get() == S->getBody())
5391 return SemaRef.Owned(S);
5393 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
5394 Init.get(), FullCond, ConditionVar,
5395 FullInc, S->getRParenLoc(), Body.get());
5398 template<typename Derived>
5400 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
5401 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5406 // Goto statements must always be rebuilt, to resolve the label.
5407 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
5408 cast<LabelDecl>(LD));
5411 template<typename Derived>
5413 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
5414 ExprResult Target = getDerived().TransformExpr(S->getTarget());
5415 if (Target.isInvalid())
5417 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
5419 if (!getDerived().AlwaysRebuild() &&
5420 Target.get() == S->getTarget())
5421 return SemaRef.Owned(S);
5423 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
5427 template<typename Derived>
5429 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
5430 return SemaRef.Owned(S);
5433 template<typename Derived>
5435 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
5436 return SemaRef.Owned(S);
5439 template<typename Derived>
5441 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
5442 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
5443 if (Result.isInvalid())
5446 // FIXME: We always rebuild the return statement because there is no way
5447 // to tell whether the return type of the function has changed.
5448 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
5451 template<typename Derived>
5453 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
5454 bool DeclChanged = false;
5455 SmallVector<Decl *, 4> Decls;
5456 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5458 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5463 if (Transformed != *D)
5466 Decls.push_back(Transformed);
5469 if (!getDerived().AlwaysRebuild() && !DeclChanged)
5470 return SemaRef.Owned(S);
5472 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
5473 S->getStartLoc(), S->getEndLoc());
5476 template<typename Derived>
5478 TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
5480 ASTOwningVector<Expr*> Constraints(getSema());
5481 ASTOwningVector<Expr*> Exprs(getSema());
5482 SmallVector<IdentifierInfo *, 4> Names;
5484 ExprResult AsmString;
5485 ASTOwningVector<Expr*> Clobbers(getSema());
5487 bool ExprsChanged = false;
5489 // Go through the outputs.
5490 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5491 Names.push_back(S->getOutputIdentifier(I));
5493 // No need to transform the constraint literal.
5494 Constraints.push_back(S->getOutputConstraintLiteral(I));
5496 // Transform the output expr.
5497 Expr *OutputExpr = S->getOutputExpr(I);
5498 ExprResult Result = getDerived().TransformExpr(OutputExpr);
5499 if (Result.isInvalid())
5502 ExprsChanged |= Result.get() != OutputExpr;
5504 Exprs.push_back(Result.get());
5507 // Go through the inputs.
5508 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5509 Names.push_back(S->getInputIdentifier(I));
5511 // No need to transform the constraint literal.
5512 Constraints.push_back(S->getInputConstraintLiteral(I));
5514 // Transform the input expr.
5515 Expr *InputExpr = S->getInputExpr(I);
5516 ExprResult Result = getDerived().TransformExpr(InputExpr);
5517 if (Result.isInvalid())
5520 ExprsChanged |= Result.get() != InputExpr;
5522 Exprs.push_back(Result.get());
5525 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
5526 return SemaRef.Owned(S);
5528 // Go through the clobbers.
5529 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
5530 Clobbers.push_back(S->getClobber(I));
5532 // No need to transform the asm string literal.
5533 AsmString = SemaRef.Owned(S->getAsmString());
5535 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5541 move_arg(Constraints),
5550 template<typename Derived>
5552 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
5553 // Transform the body of the @try.
5554 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
5555 if (TryBody.isInvalid())
5558 // Transform the @catch statements (if present).
5559 bool AnyCatchChanged = false;
5560 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
5561 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
5562 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
5563 if (Catch.isInvalid())
5565 if (Catch.get() != S->getCatchStmt(I))
5566 AnyCatchChanged = true;
5567 CatchStmts.push_back(Catch.release());
5570 // Transform the @finally statement (if present).
5572 if (S->getFinallyStmt()) {
5573 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5574 if (Finally.isInvalid())
5578 // If nothing changed, just retain this statement.
5579 if (!getDerived().AlwaysRebuild() &&
5580 TryBody.get() == S->getTryBody() &&
5582 Finally.get() == S->getFinallyStmt())
5583 return SemaRef.Owned(S);
5585 // Build a new statement.
5586 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5587 move_arg(CatchStmts), Finally.get());
5590 template<typename Derived>
5592 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5593 // Transform the @catch parameter, if there is one.
5595 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5596 TypeSourceInfo *TSInfo = 0;
5597 if (FromVar->getTypeSourceInfo()) {
5598 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5605 T = TSInfo->getType();
5607 T = getDerived().TransformType(FromVar->getType());
5612 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5617 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5618 if (Body.isInvalid())
5621 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5626 template<typename Derived>
5628 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
5629 // Transform the body.
5630 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
5631 if (Body.isInvalid())
5634 // If nothing changed, just retain this statement.
5635 if (!getDerived().AlwaysRebuild() &&
5636 Body.get() == S->getFinallyBody())
5637 return SemaRef.Owned(S);
5639 // Build a new statement.
5640 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
5644 template<typename Derived>
5646 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
5648 if (S->getThrowExpr()) {
5649 Operand = getDerived().TransformExpr(S->getThrowExpr());
5650 if (Operand.isInvalid())
5654 if (!getDerived().AlwaysRebuild() &&
5655 Operand.get() == S->getThrowExpr())
5656 return getSema().Owned(S);
5658 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
5661 template<typename Derived>
5663 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
5664 ObjCAtSynchronizedStmt *S) {
5665 // Transform the object we are locking.
5666 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
5667 if (Object.isInvalid())
5670 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5672 if (Object.isInvalid())
5675 // Transform the body.
5676 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
5677 if (Body.isInvalid())
5680 // If nothing change, just retain the current statement.
5681 if (!getDerived().AlwaysRebuild() &&
5682 Object.get() == S->getSynchExpr() &&
5683 Body.get() == S->getSynchBody())
5684 return SemaRef.Owned(S);
5686 // Build a new statement.
5687 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
5688 Object.get(), Body.get());
5691 template<typename Derived>
5693 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5694 ObjCAutoreleasePoolStmt *S) {
5695 // Transform the body.
5696 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5697 if (Body.isInvalid())
5700 // If nothing changed, just retain this statement.
5701 if (!getDerived().AlwaysRebuild() &&
5702 Body.get() == S->getSubStmt())
5703 return SemaRef.Owned(S);
5705 // Build a new statement.
5706 return getDerived().RebuildObjCAutoreleasePoolStmt(
5707 S->getAtLoc(), Body.get());
5710 template<typename Derived>
5712 TreeTransform<Derived>::TransformObjCForCollectionStmt(
5713 ObjCForCollectionStmt *S) {
5714 // Transform the element statement.
5715 StmtResult Element = getDerived().TransformStmt(S->getElement());
5716 if (Element.isInvalid())
5719 // Transform the collection expression.
5720 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5721 if (Collection.isInvalid())
5723 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5725 if (Collection.isInvalid())
5728 // Transform the body.
5729 StmtResult Body = getDerived().TransformStmt(S->getBody());
5730 if (Body.isInvalid())
5733 // If nothing changed, just retain this statement.
5734 if (!getDerived().AlwaysRebuild() &&
5735 Element.get() == S->getElement() &&
5736 Collection.get() == S->getCollection() &&
5737 Body.get() == S->getBody())
5738 return SemaRef.Owned(S);
5740 // Build a new statement.
5741 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5742 /*FIXME:*/S->getForLoc(),
5750 template<typename Derived>
5752 TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5753 // Transform the exception declaration, if any.
5755 if (S->getExceptionDecl()) {
5756 VarDecl *ExceptionDecl = S->getExceptionDecl();
5757 TypeSourceInfo *T = getDerived().TransformType(
5758 ExceptionDecl->getTypeSourceInfo());
5762 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
5763 ExceptionDecl->getInnerLocStart(),
5764 ExceptionDecl->getLocation(),
5765 ExceptionDecl->getIdentifier());
5766 if (!Var || Var->isInvalidDecl())
5770 // Transform the actual exception handler.
5771 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5772 if (Handler.isInvalid())
5775 if (!getDerived().AlwaysRebuild() &&
5777 Handler.get() == S->getHandlerBlock())
5778 return SemaRef.Owned(S);
5780 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5785 template<typename Derived>
5787 TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5788 // Transform the try block itself.
5790 = getDerived().TransformCompoundStmt(S->getTryBlock());
5791 if (TryBlock.isInvalid())
5794 // Transform the handlers.
5795 bool HandlerChanged = false;
5796 ASTOwningVector<Stmt*> Handlers(SemaRef);
5797 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
5799 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5800 if (Handler.isInvalid())
5803 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5804 Handlers.push_back(Handler.takeAs<Stmt>());
5807 if (!getDerived().AlwaysRebuild() &&
5808 TryBlock.get() == S->getTryBlock() &&
5810 return SemaRef.Owned(S);
5812 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
5813 move_arg(Handlers));
5816 template<typename Derived>
5818 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5819 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5820 if (Range.isInvalid())
5823 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5824 if (BeginEnd.isInvalid())
5827 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5828 if (Cond.isInvalid())
5831 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5832 if (Cond.isInvalid())
5835 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
5837 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5838 if (Inc.isInvalid())
5841 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
5843 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5844 if (LoopVar.isInvalid())
5847 StmtResult NewStmt = S;
5848 if (getDerived().AlwaysRebuild() ||
5849 Range.get() != S->getRangeStmt() ||
5850 BeginEnd.get() != S->getBeginEndStmt() ||
5851 Cond.get() != S->getCond() ||
5852 Inc.get() != S->getInc() ||
5853 LoopVar.get() != S->getLoopVarStmt())
5854 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5855 S->getColonLoc(), Range.get(),
5856 BeginEnd.get(), Cond.get(),
5857 Inc.get(), LoopVar.get(),
5860 StmtResult Body = getDerived().TransformStmt(S->getBody());
5861 if (Body.isInvalid())
5864 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5865 // it now so we have a new statement to attach the body to.
5866 if (Body.get() != S->getBody() && NewStmt.get() == S)
5867 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5868 S->getColonLoc(), Range.get(),
5869 BeginEnd.get(), Cond.get(),
5870 Inc.get(), LoopVar.get(),
5873 if (NewStmt.get() == S)
5874 return SemaRef.Owned(S);
5876 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5879 template<typename Derived>
5881 TreeTransform<Derived>::TransformMSDependentExistsStmt(
5882 MSDependentExistsStmt *S) {
5883 // Transform the nested-name-specifier, if any.
5884 NestedNameSpecifierLoc QualifierLoc;
5885 if (S->getQualifierLoc()) {
5887 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5892 // Transform the declaration name.
5893 DeclarationNameInfo NameInfo = S->getNameInfo();
5894 if (NameInfo.getName()) {
5895 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5896 if (!NameInfo.getName())
5900 // Check whether anything changed.
5901 if (!getDerived().AlwaysRebuild() &&
5902 QualifierLoc == S->getQualifierLoc() &&
5903 NameInfo.getName() == S->getNameInfo().getName())
5906 // Determine whether this name exists, if we can.
5908 SS.Adopt(QualifierLoc);
5909 bool Dependent = false;
5910 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5911 case Sema::IER_Exists:
5912 if (S->isIfExists())
5915 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5917 case Sema::IER_DoesNotExist:
5918 if (S->isIfNotExists())
5921 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5923 case Sema::IER_Dependent:
5927 case Sema::IER_Error:
5931 // We need to continue with the instantiation, so do so now.
5932 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5933 if (SubStmt.isInvalid())
5936 // If we have resolved the name, just transform to the substatement.
5940 // The name is still dependent, so build a dependent expression again.
5941 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5948 template<typename Derived>
5950 TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5951 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5952 if(TryBlock.isInvalid()) return StmtError();
5954 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5955 if(!getDerived().AlwaysRebuild() &&
5956 TryBlock.get() == S->getTryBlock() &&
5957 Handler.get() == S->getHandler())
5958 return SemaRef.Owned(S);
5960 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5966 template<typename Derived>
5968 TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5969 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5970 if(Block.isInvalid()) return StmtError();
5972 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5976 template<typename Derived>
5978 TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5979 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5980 if(FilterExpr.isInvalid()) return StmtError();
5982 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5983 if(Block.isInvalid()) return StmtError();
5985 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5990 template<typename Derived>
5992 TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5993 if(isa<SEHFinallyStmt>(Handler))
5994 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5996 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5999 //===----------------------------------------------------------------------===//
6000 // Expression transformation
6001 //===----------------------------------------------------------------------===//
6002 template<typename Derived>
6004 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
6005 return SemaRef.Owned(E);
6008 template<typename Derived>
6010 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
6011 NestedNameSpecifierLoc QualifierLoc;
6012 if (E->getQualifierLoc()) {
6014 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6020 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6025 DeclarationNameInfo NameInfo = E->getNameInfo();
6026 if (NameInfo.getName()) {
6027 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6028 if (!NameInfo.getName())
6032 if (!getDerived().AlwaysRebuild() &&
6033 QualifierLoc == E->getQualifierLoc() &&
6034 ND == E->getDecl() &&
6035 NameInfo.getName() == E->getDecl()->getDeclName() &&
6036 !E->hasExplicitTemplateArgs()) {
6038 // Mark it referenced in the new context regardless.
6039 // FIXME: this is a bit instantiation-specific.
6040 SemaRef.MarkDeclRefReferenced(E);
6042 return SemaRef.Owned(E);
6045 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
6046 if (E->hasExplicitTemplateArgs()) {
6047 TemplateArgs = &TransArgs;
6048 TransArgs.setLAngleLoc(E->getLAngleLoc());
6049 TransArgs.setRAngleLoc(E->getRAngleLoc());
6050 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6051 E->getNumTemplateArgs(),
6056 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6060 template<typename Derived>
6062 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
6063 return SemaRef.Owned(E);
6066 template<typename Derived>
6068 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
6069 return SemaRef.Owned(E);
6072 template<typename Derived>
6074 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
6075 return SemaRef.Owned(E);
6078 template<typename Derived>
6080 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
6081 return SemaRef.Owned(E);
6084 template<typename Derived>
6086 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
6087 return SemaRef.Owned(E);
6090 template<typename Derived>
6092 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6093 return SemaRef.MaybeBindToTemporary(E);
6096 template<typename Derived>
6098 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6099 ExprResult ControllingExpr =
6100 getDerived().TransformExpr(E->getControllingExpr());
6101 if (ControllingExpr.isInvalid())
6104 SmallVector<Expr *, 4> AssocExprs;
6105 SmallVector<TypeSourceInfo *, 4> AssocTypes;
6106 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6107 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6109 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6112 AssocTypes.push_back(AssocType);
6114 AssocTypes.push_back(0);
6117 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6118 if (AssocExpr.isInvalid())
6120 AssocExprs.push_back(AssocExpr.release());
6123 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6126 ControllingExpr.release(),
6132 template<typename Derived>
6134 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
6135 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6136 if (SubExpr.isInvalid())
6139 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
6140 return SemaRef.Owned(E);
6142 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
6146 template<typename Derived>
6148 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
6149 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6150 if (SubExpr.isInvalid())
6153 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
6154 return SemaRef.Owned(E);
6156 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6161 template<typename Derived>
6163 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6164 // Transform the type.
6165 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6169 // Transform all of the components into components similar to what the
6171 // FIXME: It would be slightly more efficient in the non-dependent case to
6172 // just map FieldDecls, rather than requiring the rebuilder to look for
6173 // the fields again. However, __builtin_offsetof is rare enough in
6174 // template code that we don't care.
6175 bool ExprChanged = false;
6176 typedef Sema::OffsetOfComponent Component;
6177 typedef OffsetOfExpr::OffsetOfNode Node;
6178 SmallVector<Component, 4> Components;
6179 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6180 const Node &ON = E->getComponent(I);
6182 Comp.isBrackets = true;
6183 Comp.LocStart = ON.getSourceRange().getBegin();
6184 Comp.LocEnd = ON.getSourceRange().getEnd();
6185 switch (ON.getKind()) {
6187 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
6188 ExprResult Index = getDerived().TransformExpr(FromIndex);
6189 if (Index.isInvalid())
6192 ExprChanged = ExprChanged || Index.get() != FromIndex;
6193 Comp.isBrackets = true;
6194 Comp.U.E = Index.get();
6199 case Node::Identifier:
6200 Comp.isBrackets = false;
6201 Comp.U.IdentInfo = ON.getFieldName();
6202 if (!Comp.U.IdentInfo)
6208 // Will be recomputed during the rebuild.
6212 Components.push_back(Comp);
6215 // If nothing changed, retain the existing expression.
6216 if (!getDerived().AlwaysRebuild() &&
6217 Type == E->getTypeSourceInfo() &&
6219 return SemaRef.Owned(E);
6221 // Build a new offsetof expression.
6222 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6223 Components.data(), Components.size(),
6227 template<typename Derived>
6229 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6230 assert(getDerived().AlreadyTransformed(E->getType()) &&
6231 "opaque value expression requires transformation");
6232 return SemaRef.Owned(E);
6235 template<typename Derived>
6237 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
6238 // Rebuild the syntactic form. The original syntactic form has
6239 // opaque-value expressions in it, so strip those away and rebuild
6240 // the result. This is a really awful way of doing this, but the
6241 // better solution (rebuilding the semantic expressions and
6242 // rebinding OVEs as necessary) doesn't work; we'd need
6243 // TreeTransform to not strip away implicit conversions.
6244 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6245 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
6246 if (result.isInvalid()) return ExprError();
6248 // If that gives us a pseudo-object result back, the pseudo-object
6249 // expression must have been an lvalue-to-rvalue conversion which we
6251 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6252 result = SemaRef.checkPseudoObjectRValue(result.take());
6257 template<typename Derived>
6259 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6260 UnaryExprOrTypeTraitExpr *E) {
6261 if (E->isArgumentType()) {
6262 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
6264 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6268 if (!getDerived().AlwaysRebuild() && OldT == NewT)
6269 return SemaRef.Owned(E);
6271 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6273 E->getSourceRange());
6276 // C++0x [expr.sizeof]p1:
6277 // The operand is either an expression, which is an unevaluated operand
6279 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6281 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6282 if (SubExpr.isInvalid())
6285 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6286 return SemaRef.Owned(E);
6288 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6289 E->getOperatorLoc(),
6291 E->getSourceRange());
6294 template<typename Derived>
6296 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
6297 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6298 if (LHS.isInvalid())
6301 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6302 if (RHS.isInvalid())
6306 if (!getDerived().AlwaysRebuild() &&
6307 LHS.get() == E->getLHS() &&
6308 RHS.get() == E->getRHS())
6309 return SemaRef.Owned(E);
6311 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
6312 /*FIXME:*/E->getLHS()->getLocStart(),
6314 E->getRBracketLoc());
6317 template<typename Derived>
6319 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6320 // Transform the callee.
6321 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6322 if (Callee.isInvalid())
6325 // Transform arguments.
6326 bool ArgChanged = false;
6327 ASTOwningVector<Expr*> Args(SemaRef);
6328 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6332 if (!getDerived().AlwaysRebuild() &&
6333 Callee.get() == E->getCallee() &&
6335 return SemaRef.MaybeBindToTemporary(E);;
6337 // FIXME: Wrong source location information for the '('.
6338 SourceLocation FakeLParenLoc
6339 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6340 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6345 template<typename Derived>
6347 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
6348 ExprResult Base = getDerived().TransformExpr(E->getBase());
6349 if (Base.isInvalid())
6352 NestedNameSpecifierLoc QualifierLoc;
6353 if (E->hasQualifier()) {
6355 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6360 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
6363 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6364 E->getMemberDecl()));
6368 NamedDecl *FoundDecl = E->getFoundDecl();
6369 if (FoundDecl == E->getMemberDecl()) {
6372 FoundDecl = cast_or_null<NamedDecl>(
6373 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6378 if (!getDerived().AlwaysRebuild() &&
6379 Base.get() == E->getBase() &&
6380 QualifierLoc == E->getQualifierLoc() &&
6381 Member == E->getMemberDecl() &&
6382 FoundDecl == E->getFoundDecl() &&
6383 !E->hasExplicitTemplateArgs()) {
6385 // Mark it referenced in the new context regardless.
6386 // FIXME: this is a bit instantiation-specific.
6387 SemaRef.MarkMemberReferenced(E);
6389 return SemaRef.Owned(E);
6392 TemplateArgumentListInfo TransArgs;
6393 if (E->hasExplicitTemplateArgs()) {
6394 TransArgs.setLAngleLoc(E->getLAngleLoc());
6395 TransArgs.setRAngleLoc(E->getRAngleLoc());
6396 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6397 E->getNumTemplateArgs(),
6402 // FIXME: Bogus source location for the operator
6403 SourceLocation FakeOperatorLoc
6404 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6406 // FIXME: to do this check properly, we will need to preserve the
6407 // first-qualifier-in-scope here, just in case we had a dependent
6408 // base (and therefore couldn't do the check) and a
6409 // nested-name-qualifier (and therefore could do the lookup).
6410 NamedDecl *FirstQualifierInScope = 0;
6412 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6416 E->getMemberNameInfo(),
6419 (E->hasExplicitTemplateArgs()
6421 FirstQualifierInScope);
6424 template<typename Derived>
6426 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
6427 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6428 if (LHS.isInvalid())
6431 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6432 if (RHS.isInvalid())
6435 if (!getDerived().AlwaysRebuild() &&
6436 LHS.get() == E->getLHS() &&
6437 RHS.get() == E->getRHS())
6438 return SemaRef.Owned(E);
6440 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
6441 LHS.get(), RHS.get());
6444 template<typename Derived>
6446 TreeTransform<Derived>::TransformCompoundAssignOperator(
6447 CompoundAssignOperator *E) {
6448 return getDerived().TransformBinaryOperator(E);
6451 template<typename Derived>
6452 ExprResult TreeTransform<Derived>::
6453 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6454 // Just rebuild the common and RHS expressions and see whether we
6457 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6458 if (commonExpr.isInvalid())
6461 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6462 if (rhs.isInvalid())
6465 if (!getDerived().AlwaysRebuild() &&
6466 commonExpr.get() == e->getCommon() &&
6467 rhs.get() == e->getFalseExpr())
6468 return SemaRef.Owned(e);
6470 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6471 e->getQuestionLoc(),
6477 template<typename Derived>
6479 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
6480 ExprResult Cond = getDerived().TransformExpr(E->getCond());
6481 if (Cond.isInvalid())
6484 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6485 if (LHS.isInvalid())
6488 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6489 if (RHS.isInvalid())
6492 if (!getDerived().AlwaysRebuild() &&
6493 Cond.get() == E->getCond() &&
6494 LHS.get() == E->getLHS() &&
6495 RHS.get() == E->getRHS())
6496 return SemaRef.Owned(E);
6498 return getDerived().RebuildConditionalOperator(Cond.get(),
6499 E->getQuestionLoc(),
6505 template<typename Derived>
6507 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6508 // Implicit casts are eliminated during transformation, since they
6509 // will be recomputed by semantic analysis after transformation.
6510 return getDerived().TransformExpr(E->getSubExprAsWritten());
6513 template<typename Derived>
6515 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6516 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6521 = getDerived().TransformExpr(E->getSubExprAsWritten());
6522 if (SubExpr.isInvalid())
6525 if (!getDerived().AlwaysRebuild() &&
6526 Type == E->getTypeInfoAsWritten() &&
6527 SubExpr.get() == E->getSubExpr())
6528 return SemaRef.Owned(E);
6530 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6536 template<typename Derived>
6538 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
6539 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6540 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6544 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6545 if (Init.isInvalid())
6548 if (!getDerived().AlwaysRebuild() &&
6550 Init.get() == E->getInitializer())
6551 return SemaRef.MaybeBindToTemporary(E);
6553 // Note: the expression type doesn't necessarily match the
6554 // type-as-written, but that's okay, because it should always be
6555 // derivable from the initializer.
6557 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6558 /*FIXME:*/E->getInitializer()->getLocEnd(),
6562 template<typename Derived>
6564 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
6565 ExprResult Base = getDerived().TransformExpr(E->getBase());
6566 if (Base.isInvalid())
6569 if (!getDerived().AlwaysRebuild() &&
6570 Base.get() == E->getBase())
6571 return SemaRef.Owned(E);
6573 // FIXME: Bad source location
6574 SourceLocation FakeOperatorLoc
6575 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
6576 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6577 E->getAccessorLoc(),
6581 template<typename Derived>
6583 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6584 bool InitChanged = false;
6586 ASTOwningVector<Expr*, 4> Inits(SemaRef);
6587 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6588 Inits, &InitChanged))
6591 if (!getDerived().AlwaysRebuild() && !InitChanged)
6592 return SemaRef.Owned(E);
6594 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
6595 E->getRBraceLoc(), E->getType());
6598 template<typename Derived>
6600 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
6603 // transform the initializer value
6604 ExprResult Init = getDerived().TransformExpr(E->getInit());
6605 if (Init.isInvalid())
6608 // transform the designators.
6609 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
6610 bool ExprChanged = false;
6611 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6612 DEnd = E->designators_end();
6614 if (D->isFieldDesignator()) {
6615 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6621 if (D->isArrayDesignator()) {
6622 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
6623 if (Index.isInvalid())
6626 Desig.AddDesignator(Designator::getArray(Index.get(),
6627 D->getLBracketLoc()));
6629 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6630 ArrayExprs.push_back(Index.release());
6634 assert(D->isArrayRangeDesignator() && "New kind of designator?");
6636 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6637 if (Start.isInvalid())
6640 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
6641 if (End.isInvalid())
6644 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
6646 D->getLBracketLoc(),
6647 D->getEllipsisLoc()));
6649 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6650 End.get() != E->getArrayRangeEnd(*D);
6652 ArrayExprs.push_back(Start.release());
6653 ArrayExprs.push_back(End.release());
6656 if (!getDerived().AlwaysRebuild() &&
6657 Init.get() == E->getInit() &&
6659 return SemaRef.Owned(E);
6661 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6662 E->getEqualOrColonLoc(),
6663 E->usesGNUSyntax(), Init.get());
6666 template<typename Derived>
6668 TreeTransform<Derived>::TransformImplicitValueInitExpr(
6669 ImplicitValueInitExpr *E) {
6670 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
6672 // FIXME: Will we ever have proper type location here? Will we actually
6673 // need to transform the type?
6674 QualType T = getDerived().TransformType(E->getType());
6678 if (!getDerived().AlwaysRebuild() &&
6680 return SemaRef.Owned(E);
6682 return getDerived().RebuildImplicitValueInitExpr(T);
6685 template<typename Derived>
6687 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
6688 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6692 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6693 if (SubExpr.isInvalid())
6696 if (!getDerived().AlwaysRebuild() &&
6697 TInfo == E->getWrittenTypeInfo() &&
6698 SubExpr.get() == E->getSubExpr())
6699 return SemaRef.Owned(E);
6701 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
6702 TInfo, E->getRParenLoc());
6705 template<typename Derived>
6707 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
6708 bool ArgumentChanged = false;
6709 ASTOwningVector<Expr*, 4> Inits(SemaRef);
6710 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6714 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6719 /// \brief Transform an address-of-label expression.
6721 /// By default, the transformation of an address-of-label expression always
6722 /// rebuilds the expression, so that the label identifier can be resolved to
6723 /// the corresponding label statement by semantic analysis.
6724 template<typename Derived>
6726 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
6727 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6732 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
6733 cast<LabelDecl>(LD));
6736 template<typename Derived>
6738 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
6739 SemaRef.ActOnStartStmtExpr();
6741 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6742 if (SubStmt.isInvalid()) {
6743 SemaRef.ActOnStmtExprError();
6747 if (!getDerived().AlwaysRebuild() &&
6748 SubStmt.get() == E->getSubStmt()) {
6749 // Calling this an 'error' is unintuitive, but it does the right thing.
6750 SemaRef.ActOnStmtExprError();
6751 return SemaRef.MaybeBindToTemporary(E);
6754 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
6759 template<typename Derived>
6761 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
6762 ExprResult Cond = getDerived().TransformExpr(E->getCond());
6763 if (Cond.isInvalid())
6766 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6767 if (LHS.isInvalid())
6770 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6771 if (RHS.isInvalid())
6774 if (!getDerived().AlwaysRebuild() &&
6775 Cond.get() == E->getCond() &&
6776 LHS.get() == E->getLHS() &&
6777 RHS.get() == E->getRHS())
6778 return SemaRef.Owned(E);
6780 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
6781 Cond.get(), LHS.get(), RHS.get(),
6785 template<typename Derived>
6787 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
6788 return SemaRef.Owned(E);
6791 template<typename Derived>
6793 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
6794 switch (E->getOperator()) {
6798 case OO_Array_Delete:
6799 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
6802 // This is a call to an object's operator().
6803 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6805 // Transform the object itself.
6806 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
6807 if (Object.isInvalid())
6810 // FIXME: Poor location information
6811 SourceLocation FakeLParenLoc
6812 = SemaRef.PP.getLocForEndOfToken(
6813 static_cast<Expr *>(Object.get())->getLocEnd());
6815 // Transform the call arguments.
6816 ASTOwningVector<Expr*> Args(SemaRef);
6817 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6821 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
6826 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6828 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6829 #include "clang/Basic/OperatorKinds.def"
6834 case OO_Conditional:
6835 llvm_unreachable("conditional operator is not actually overloadable");
6838 case NUM_OVERLOADED_OPERATORS:
6839 llvm_unreachable("not an overloaded operator?");
6842 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6843 if (Callee.isInvalid())
6846 ExprResult First = getDerived().TransformExpr(E->getArg(0));
6847 if (First.isInvalid())
6851 if (E->getNumArgs() == 2) {
6852 Second = getDerived().TransformExpr(E->getArg(1));
6853 if (Second.isInvalid())
6857 if (!getDerived().AlwaysRebuild() &&
6858 Callee.get() == E->getCallee() &&
6859 First.get() == E->getArg(0) &&
6860 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
6861 return SemaRef.MaybeBindToTemporary(E);
6863 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6864 E->getOperatorLoc(),
6870 template<typename Derived>
6872 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6873 return getDerived().TransformCallExpr(E);
6876 template<typename Derived>
6878 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6879 // Transform the callee.
6880 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6881 if (Callee.isInvalid())
6884 // Transform exec config.
6885 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6889 // Transform arguments.
6890 bool ArgChanged = false;
6891 ASTOwningVector<Expr*> Args(SemaRef);
6892 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6896 if (!getDerived().AlwaysRebuild() &&
6897 Callee.get() == E->getCallee() &&
6899 return SemaRef.MaybeBindToTemporary(E);
6901 // FIXME: Wrong source location information for the '('.
6902 SourceLocation FakeLParenLoc
6903 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6904 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6906 E->getRParenLoc(), EC.get());
6909 template<typename Derived>
6911 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
6912 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6917 = getDerived().TransformExpr(E->getSubExprAsWritten());
6918 if (SubExpr.isInvalid())
6921 if (!getDerived().AlwaysRebuild() &&
6922 Type == E->getTypeInfoAsWritten() &&
6923 SubExpr.get() == E->getSubExpr())
6924 return SemaRef.Owned(E);
6926 // FIXME: Poor source location information here.
6927 SourceLocation FakeLAngleLoc
6928 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6929 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6930 SourceLocation FakeRParenLoc
6931 = SemaRef.PP.getLocForEndOfToken(
6932 E->getSubExpr()->getSourceRange().getEnd());
6933 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
6943 template<typename Derived>
6945 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6946 return getDerived().TransformCXXNamedCastExpr(E);
6949 template<typename Derived>
6951 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6952 return getDerived().TransformCXXNamedCastExpr(E);
6955 template<typename Derived>
6957 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
6958 CXXReinterpretCastExpr *E) {
6959 return getDerived().TransformCXXNamedCastExpr(E);
6962 template<typename Derived>
6964 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6965 return getDerived().TransformCXXNamedCastExpr(E);
6968 template<typename Derived>
6970 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
6971 CXXFunctionalCastExpr *E) {
6972 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6977 = getDerived().TransformExpr(E->getSubExprAsWritten());
6978 if (SubExpr.isInvalid())
6981 if (!getDerived().AlwaysRebuild() &&
6982 Type == E->getTypeInfoAsWritten() &&
6983 SubExpr.get() == E->getSubExpr())
6984 return SemaRef.Owned(E);
6986 return getDerived().RebuildCXXFunctionalCastExpr(Type,
6987 /*FIXME:*/E->getSubExpr()->getLocStart(),
6992 template<typename Derived>
6994 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
6995 if (E->isTypeOperand()) {
6996 TypeSourceInfo *TInfo
6997 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7001 if (!getDerived().AlwaysRebuild() &&
7002 TInfo == E->getTypeOperandSourceInfo())
7003 return SemaRef.Owned(E);
7005 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7011 // We don't know whether the subexpression is potentially evaluated until
7012 // after we perform semantic analysis. We speculatively assume it is
7013 // unevaluated; it will get fixed later if the subexpression is in fact
7014 // potentially evaluated.
7015 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7017 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7018 if (SubExpr.isInvalid())
7021 if (!getDerived().AlwaysRebuild() &&
7022 SubExpr.get() == E->getExprOperand())
7023 return SemaRef.Owned(E);
7025 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7031 template<typename Derived>
7033 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7034 if (E->isTypeOperand()) {
7035 TypeSourceInfo *TInfo
7036 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7040 if (!getDerived().AlwaysRebuild() &&
7041 TInfo == E->getTypeOperandSourceInfo())
7042 return SemaRef.Owned(E);
7044 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7050 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7052 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7053 if (SubExpr.isInvalid())
7056 if (!getDerived().AlwaysRebuild() &&
7057 SubExpr.get() == E->getExprOperand())
7058 return SemaRef.Owned(E);
7060 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7066 template<typename Derived>
7068 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
7069 return SemaRef.Owned(E);
7072 template<typename Derived>
7074 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
7075 CXXNullPtrLiteralExpr *E) {
7076 return SemaRef.Owned(E);
7079 template<typename Derived>
7081 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
7082 DeclContext *DC = getSema().getFunctionLevelDeclContext();
7084 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7085 T = MD->getThisType(getSema().Context);
7087 T = getSema().Context.getPointerType(
7088 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
7090 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7091 // Make sure that we capture 'this'.
7092 getSema().CheckCXXThisCapture(E->getLocStart());
7093 return SemaRef.Owned(E);
7096 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
7099 template<typename Derived>
7101 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
7102 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7103 if (SubExpr.isInvalid())
7106 if (!getDerived().AlwaysRebuild() &&
7107 SubExpr.get() == E->getSubExpr())
7108 return SemaRef.Owned(E);
7110 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7111 E->isThrownVariableInScope());
7114 template<typename Derived>
7116 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
7118 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7123 if (!getDerived().AlwaysRebuild() &&
7124 Param == E->getParam())
7125 return SemaRef.Owned(E);
7127 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
7130 template<typename Derived>
7132 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7133 CXXScalarValueInitExpr *E) {
7134 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7138 if (!getDerived().AlwaysRebuild() &&
7139 T == E->getTypeSourceInfo())
7140 return SemaRef.Owned(E);
7142 return getDerived().RebuildCXXScalarValueInitExpr(T,
7143 /*FIXME:*/T->getTypeLoc().getEndLoc(),
7147 template<typename Derived>
7149 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
7150 // Transform the type that we're allocating
7151 TypeSourceInfo *AllocTypeInfo
7152 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7156 // Transform the size of the array we're allocating (if any).
7157 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
7158 if (ArraySize.isInvalid())
7161 // Transform the placement arguments (if any).
7162 bool ArgumentChanged = false;
7163 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
7164 if (getDerived().TransformExprs(E->getPlacementArgs(),
7165 E->getNumPlacementArgs(), true,
7166 PlacementArgs, &ArgumentChanged))
7169 // Transform the initializer (if any).
7170 Expr *OldInit = E->getInitializer();
7173 NewInit = getDerived().TransformExpr(OldInit);
7174 if (NewInit.isInvalid())
7177 // Transform new operator and delete operator.
7178 FunctionDecl *OperatorNew = 0;
7179 if (E->getOperatorNew()) {
7180 OperatorNew = cast_or_null<FunctionDecl>(
7181 getDerived().TransformDecl(E->getLocStart(),
7182 E->getOperatorNew()));
7187 FunctionDecl *OperatorDelete = 0;
7188 if (E->getOperatorDelete()) {
7189 OperatorDelete = cast_or_null<FunctionDecl>(
7190 getDerived().TransformDecl(E->getLocStart(),
7191 E->getOperatorDelete()));
7192 if (!OperatorDelete)
7196 if (!getDerived().AlwaysRebuild() &&
7197 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
7198 ArraySize.get() == E->getArraySize() &&
7199 NewInit.get() == OldInit &&
7200 OperatorNew == E->getOperatorNew() &&
7201 OperatorDelete == E->getOperatorDelete() &&
7203 // Mark any declarations we need as referenced.
7204 // FIXME: instantiation-specific.
7206 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
7208 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
7210 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
7211 QualType ElementType
7212 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7213 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7214 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7215 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7216 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
7221 return SemaRef.Owned(E);
7224 QualType AllocType = AllocTypeInfo->getType();
7225 if (!ArraySize.get()) {
7226 // If no array size was specified, but the new expression was
7227 // instantiated with an array type (e.g., "new T" where T is
7228 // instantiated with "int[4]"), extract the outer bound from the
7229 // array type as our array size. We do this with constant and
7230 // dependently-sized array types.
7231 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7234 } else if (const ConstantArrayType *ConsArrayT
7235 = dyn_cast<ConstantArrayType>(ArrayT)) {
7237 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7238 ConsArrayT->getSize(),
7239 SemaRef.Context.getSizeType(),
7240 /*FIXME:*/E->getLocStart()));
7241 AllocType = ConsArrayT->getElementType();
7242 } else if (const DependentSizedArrayType *DepArrayT
7243 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7244 if (DepArrayT->getSizeExpr()) {
7245 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
7246 AllocType = DepArrayT->getElementType();
7251 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7253 /*FIXME:*/E->getLocStart(),
7254 move_arg(PlacementArgs),
7255 /*FIXME:*/E->getLocStart(),
7256 E->getTypeIdParens(),
7260 E->getDirectInitRange(),
7264 template<typename Derived>
7266 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
7267 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
7268 if (Operand.isInvalid())
7271 // Transform the delete operator, if known.
7272 FunctionDecl *OperatorDelete = 0;
7273 if (E->getOperatorDelete()) {
7274 OperatorDelete = cast_or_null<FunctionDecl>(
7275 getDerived().TransformDecl(E->getLocStart(),
7276 E->getOperatorDelete()));
7277 if (!OperatorDelete)
7281 if (!getDerived().AlwaysRebuild() &&
7282 Operand.get() == E->getArgument() &&
7283 OperatorDelete == E->getOperatorDelete()) {
7284 // Mark any declarations we need as referenced.
7285 // FIXME: instantiation-specific.
7287 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
7289 if (!E->getArgument()->isTypeDependent()) {
7290 QualType Destroyed = SemaRef.Context.getBaseElementType(
7291 E->getDestroyedType());
7292 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7293 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7294 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7295 SemaRef.LookupDestructor(Record));
7299 return SemaRef.Owned(E);
7302 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7303 E->isGlobalDelete(),
7308 template<typename Derived>
7310 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
7311 CXXPseudoDestructorExpr *E) {
7312 ExprResult Base = getDerived().TransformExpr(E->getBase());
7313 if (Base.isInvalid())
7316 ParsedType ObjectTypePtr;
7317 bool MayBePseudoDestructor = false;
7318 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7319 E->getOperatorLoc(),
7320 E->isArrow()? tok::arrow : tok::period,
7322 MayBePseudoDestructor);
7323 if (Base.isInvalid())
7326 QualType ObjectType = ObjectTypePtr.get();
7327 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7330 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7335 SS.Adopt(QualifierLoc);
7337 PseudoDestructorTypeStorage Destroyed;
7338 if (E->getDestroyedTypeInfo()) {
7339 TypeSourceInfo *DestroyedTypeInfo
7340 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7342 if (!DestroyedTypeInfo)
7344 Destroyed = DestroyedTypeInfo;
7345 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
7346 // We aren't likely to be able to resolve the identifier down to a type
7347 // now anyway, so just retain the identifier.
7348 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7349 E->getDestroyedTypeLoc());
7351 // Look for a destructor known with the given name.
7352 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7353 *E->getDestroyedTypeIdentifier(),
7354 E->getDestroyedTypeLoc(),
7362 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7363 E->getDestroyedTypeLoc());
7366 TypeSourceInfo *ScopeTypeInfo = 0;
7367 if (E->getScopeTypeInfo()) {
7368 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
7373 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7374 E->getOperatorLoc(),
7378 E->getColonColonLoc(),
7383 template<typename Derived>
7385 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
7386 UnresolvedLookupExpr *Old) {
7387 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7388 Sema::LookupOrdinaryName);
7390 // Transform all the decls.
7391 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7392 E = Old->decls_end(); I != E; ++I) {
7393 NamedDecl *InstD = static_cast<NamedDecl*>(
7394 getDerived().TransformDecl(Old->getNameLoc(),
7397 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7398 // This can happen because of dependent hiding.
7399 if (isa<UsingShadowDecl>(*I))
7405 // Expand using declarations.
7406 if (isa<UsingDecl>(InstD)) {
7407 UsingDecl *UD = cast<UsingDecl>(InstD);
7408 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7409 E = UD->shadow_end(); I != E; ++I)
7417 // Resolve a kind, but don't do any further analysis. If it's
7418 // ambiguous, the callee needs to deal with it.
7421 // Rebuild the nested-name qualifier, if present.
7423 if (Old->getQualifierLoc()) {
7424 NestedNameSpecifierLoc QualifierLoc
7425 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7429 SS.Adopt(QualifierLoc);
7432 if (Old->getNamingClass()) {
7433 CXXRecordDecl *NamingClass
7434 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7436 Old->getNamingClass()));
7440 R.setNamingClass(NamingClass);
7443 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7445 // If we have neither explicit template arguments, nor the template keyword,
7446 // it's a normal declaration name.
7447 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
7448 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7450 // If we have template arguments, rebuild them, then rebuild the
7451 // templateid expression.
7452 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
7453 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7454 Old->getNumTemplateArgs(),
7458 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
7459 Old->requiresADL(), &TransArgs);
7462 template<typename Derived>
7464 TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
7465 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7469 if (!getDerived().AlwaysRebuild() &&
7470 T == E->getQueriedTypeSourceInfo())
7471 return SemaRef.Owned(E);
7473 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7479 template<typename Derived>
7481 TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7482 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7486 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7490 if (!getDerived().AlwaysRebuild() &&
7491 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7492 return SemaRef.Owned(E);
7494 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7500 template<typename Derived>
7502 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7503 bool ArgChanged = false;
7504 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7505 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7506 TypeSourceInfo *From = E->getArg(I);
7507 TypeLoc FromTL = From->getTypeLoc();
7508 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7510 TLB.reserve(FromTL.getFullDataSize());
7511 QualType To = getDerived().TransformType(TLB, FromTL);
7515 if (To == From->getType())
7516 Args.push_back(From);
7518 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7526 // We have a pack expansion. Instantiate it.
7527 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7528 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7529 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7530 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7532 // Determine whether the set of unexpanded parameter packs can and should
7535 bool RetainExpansion = false;
7536 llvm::Optional<unsigned> OrigNumExpansions
7537 = ExpansionTL.getTypePtr()->getNumExpansions();
7538 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7539 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7540 PatternTL.getSourceRange(),
7542 Expand, RetainExpansion,
7547 // The transform has determined that we should perform a simple
7548 // transformation on the pack expansion, producing another pack
7550 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7553 TLB.reserve(From->getTypeLoc().getFullDataSize());
7555 QualType To = getDerived().TransformType(TLB, PatternTL);
7559 To = getDerived().RebuildPackExpansionType(To,
7560 PatternTL.getSourceRange(),
7561 ExpansionTL.getEllipsisLoc(),
7566 PackExpansionTypeLoc ToExpansionTL
7567 = TLB.push<PackExpansionTypeLoc>(To);
7568 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7569 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7573 // Expand the pack expansion by substituting for each argument in the
7575 for (unsigned I = 0; I != *NumExpansions; ++I) {
7576 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7578 TLB.reserve(PatternTL.getFullDataSize());
7579 QualType To = getDerived().TransformType(TLB, PatternTL);
7583 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7586 if (!RetainExpansion)
7589 // If we're supposed to retain a pack expansion, do so by temporarily
7590 // forgetting the partially-substituted parameter pack.
7591 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7594 TLB.reserve(From->getTypeLoc().getFullDataSize());
7596 QualType To = getDerived().TransformType(TLB, PatternTL);
7600 To = getDerived().RebuildPackExpansionType(To,
7601 PatternTL.getSourceRange(),
7602 ExpansionTL.getEllipsisLoc(),
7607 PackExpansionTypeLoc ToExpansionTL
7608 = TLB.push<PackExpansionTypeLoc>(To);
7609 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7610 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7613 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7614 return SemaRef.Owned(E);
7616 return getDerived().RebuildTypeTrait(E->getTrait(),
7622 template<typename Derived>
7624 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7625 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7629 if (!getDerived().AlwaysRebuild() &&
7630 T == E->getQueriedTypeSourceInfo())
7631 return SemaRef.Owned(E);
7635 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7636 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7637 if (SubExpr.isInvalid())
7640 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7641 return SemaRef.Owned(E);
7644 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7651 template<typename Derived>
7653 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7656 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7657 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7658 if (SubExpr.isInvalid())
7661 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7662 return SemaRef.Owned(E);
7665 return getDerived().RebuildExpressionTrait(
7666 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7669 template<typename Derived>
7671 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7672 DependentScopeDeclRefExpr *E) {
7673 NestedNameSpecifierLoc QualifierLoc
7674 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7677 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
7679 // TODO: If this is a conversion-function-id, verify that the
7680 // destination type name (if present) resolves the same way after
7681 // instantiation as it did in the local scope.
7683 DeclarationNameInfo NameInfo
7684 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7685 if (!NameInfo.getName())
7688 if (!E->hasExplicitTemplateArgs()) {
7689 if (!getDerived().AlwaysRebuild() &&
7690 QualifierLoc == E->getQualifierLoc() &&
7691 // Note: it is sufficient to compare the Name component of NameInfo:
7692 // if name has not changed, DNLoc has not changed either.
7693 NameInfo.getName() == E->getDeclName())
7694 return SemaRef.Owned(E);
7696 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
7699 /*TemplateArgs*/ 0);
7702 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7703 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7704 E->getNumTemplateArgs(),
7708 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
7714 template<typename Derived>
7716 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
7717 // CXXConstructExprs are always implicit, so when we have a
7718 // 1-argument construction we just transform that argument.
7719 if (E->getNumArgs() == 1 ||
7720 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7721 return getDerived().TransformExpr(E->getArg(0));
7723 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7725 QualType T = getDerived().TransformType(E->getType());
7729 CXXConstructorDecl *Constructor
7730 = cast_or_null<CXXConstructorDecl>(
7731 getDerived().TransformDecl(E->getLocStart(),
7732 E->getConstructor()));
7736 bool ArgumentChanged = false;
7737 ASTOwningVector<Expr*> Args(SemaRef);
7738 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7742 if (!getDerived().AlwaysRebuild() &&
7743 T == E->getType() &&
7744 Constructor == E->getConstructor() &&
7746 // Mark the constructor as referenced.
7747 // FIXME: Instantiation-specific
7748 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
7749 return SemaRef.Owned(E);
7752 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7753 Constructor, E->isElidable(),
7755 E->hadMultipleCandidates(),
7756 E->requiresZeroInitialization(),
7757 E->getConstructionKind(),
7758 E->getParenRange());
7761 /// \brief Transform a C++ temporary-binding expression.
7763 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7764 /// transform the subexpression and return that.
7765 template<typename Derived>
7767 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
7768 return getDerived().TransformExpr(E->getSubExpr());
7771 /// \brief Transform a C++ expression that contains cleanups that should
7772 /// be run after the expression is evaluated.
7774 /// Since ExprWithCleanups nodes are implicitly generated, we
7775 /// just transform the subexpression and return that.
7776 template<typename Derived>
7778 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
7779 return getDerived().TransformExpr(E->getSubExpr());
7782 template<typename Derived>
7784 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
7785 CXXTemporaryObjectExpr *E) {
7786 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7790 CXXConstructorDecl *Constructor
7791 = cast_or_null<CXXConstructorDecl>(
7792 getDerived().TransformDecl(E->getLocStart(),
7793 E->getConstructor()));
7797 bool ArgumentChanged = false;
7798 ASTOwningVector<Expr*> Args(SemaRef);
7799 Args.reserve(E->getNumArgs());
7800 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7804 if (!getDerived().AlwaysRebuild() &&
7805 T == E->getTypeSourceInfo() &&
7806 Constructor == E->getConstructor() &&
7808 // FIXME: Instantiation-specific
7809 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
7810 return SemaRef.MaybeBindToTemporary(E);
7813 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7814 /*FIXME:*/T->getTypeLoc().getEndLoc(),
7819 template<typename Derived>
7821 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
7822 // Create the local class that will describe the lambda.
7823 CXXRecordDecl *Class
7824 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7825 /*KnownDependent=*/false);
7826 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7828 // Transform the type of the lambda parameters and start the definition of
7829 // the lambda itself.
7830 TypeSourceInfo *MethodTy
7831 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7835 // Transform lambda parameters.
7836 bool Invalid = false;
7837 llvm::SmallVector<QualType, 4> ParamTypes;
7838 llvm::SmallVector<ParmVarDecl *, 4> Params;
7839 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7840 E->getCallOperator()->param_begin(),
7841 E->getCallOperator()->param_size(),
7842 0, ParamTypes, &Params))
7845 // Build the call operator.
7846 // Note: Once a lambda mangling number and context declaration have been
7847 // assigned, they never change.
7848 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7849 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
7850 CXXMethodDecl *CallOperator
7851 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7853 E->getCallOperator()->getLocEnd(),
7854 Params, ManglingNumber, ContextDecl);
7855 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7857 // FIXME: Instantiation-specific.
7858 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7859 TSK_ImplicitInstantiation);
7861 // Introduce the context of the call operator.
7862 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7864 // Enter the scope of the lambda.
7865 sema::LambdaScopeInfo *LSI
7866 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7867 E->getCaptureDefault(),
7868 E->hasExplicitParameters(),
7869 E->hasExplicitResultType(),
7872 // Transform captures.
7873 bool FinishedExplicitCaptures = false;
7874 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7875 CEnd = E->capture_end();
7877 // When we hit the first implicit capture, tell Sema that we've finished
7878 // the list of explicit captures.
7879 if (!FinishedExplicitCaptures && C->isImplicit()) {
7880 getSema().finishLambdaExplicitCaptures(LSI);
7881 FinishedExplicitCaptures = true;
7884 // Capturing 'this' is trivial.
7885 if (C->capturesThis()) {
7886 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7890 // Determine the capture kind for Sema.
7891 Sema::TryCaptureKind Kind
7892 = C->isImplicit()? Sema::TryCapture_Implicit
7893 : C->getCaptureKind() == LCK_ByCopy
7894 ? Sema::TryCapture_ExplicitByVal
7895 : Sema::TryCapture_ExplicitByRef;
7896 SourceLocation EllipsisLoc;
7897 if (C->isPackExpansion()) {
7898 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7899 bool ShouldExpand = false;
7900 bool RetainExpansion = false;
7901 llvm::Optional<unsigned> NumExpansions;
7902 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7905 ShouldExpand, RetainExpansion,
7910 // The transform has determined that we should perform an expansion;
7911 // transform and capture each of the arguments.
7912 // expansion of the pattern. Do so.
7913 VarDecl *Pack = C->getCapturedVar();
7914 for (unsigned I = 0; I != *NumExpansions; ++I) {
7915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7916 VarDecl *CapturedVar
7917 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7924 // Capture the transformed variable.
7925 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7930 EllipsisLoc = C->getEllipsisLoc();
7933 // Transform the captured variable.
7934 VarDecl *CapturedVar
7935 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7936 C->getCapturedVar()));
7942 // Capture the transformed variable.
7943 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7945 if (!FinishedExplicitCaptures)
7946 getSema().finishLambdaExplicitCaptures(LSI);
7949 // Enter a new evaluation context to insulate the lambda from any
7950 // cleanups from the enclosing full-expression.
7951 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7954 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7955 /*IsInstantiation=*/true);
7959 // Instantiate the body of the lambda expression.
7960 StmtResult Body = getDerived().TransformStmt(E->getBody());
7961 if (Body.isInvalid()) {
7962 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7963 /*IsInstantiation=*/true);
7967 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
7968 /*CurScope=*/0, /*IsInstantiation=*/true);
7971 template<typename Derived>
7973 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
7974 CXXUnresolvedConstructExpr *E) {
7975 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7979 bool ArgumentChanged = false;
7980 ASTOwningVector<Expr*> Args(SemaRef);
7981 Args.reserve(E->arg_size());
7982 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7986 if (!getDerived().AlwaysRebuild() &&
7987 T == E->getTypeSourceInfo() &&
7989 return SemaRef.Owned(E);
7991 // FIXME: we're faking the locations of the commas
7992 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
7998 template<typename Derived>
8000 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
8001 CXXDependentScopeMemberExpr *E) {
8002 // Transform the base of the expression.
8003 ExprResult Base((Expr*) 0);
8006 QualType ObjectType;
8007 if (!E->isImplicitAccess()) {
8008 OldBase = E->getBase();
8009 Base = getDerived().TransformExpr(OldBase);
8010 if (Base.isInvalid())
8013 // Start the member reference and compute the object's type.
8014 ParsedType ObjectTy;
8015 bool MayBePseudoDestructor = false;
8016 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
8017 E->getOperatorLoc(),
8018 E->isArrow()? tok::arrow : tok::period,
8020 MayBePseudoDestructor);
8021 if (Base.isInvalid())
8024 ObjectType = ObjectTy.get();
8025 BaseType = ((Expr*) Base.get())->getType();
8028 BaseType = getDerived().TransformType(E->getBaseType());
8029 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8032 // Transform the first part of the nested-name-specifier that qualifies
8034 NamedDecl *FirstQualifierInScope
8035 = getDerived().TransformFirstQualifierInScope(
8036 E->getFirstQualifierFoundInScope(),
8037 E->getQualifierLoc().getBeginLoc());
8039 NestedNameSpecifierLoc QualifierLoc;
8040 if (E->getQualifier()) {
8042 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8044 FirstQualifierInScope);
8049 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8051 // TODO: If this is a conversion-function-id, verify that the
8052 // destination type name (if present) resolves the same way after
8053 // instantiation as it did in the local scope.
8055 DeclarationNameInfo NameInfo
8056 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
8057 if (!NameInfo.getName())
8060 if (!E->hasExplicitTemplateArgs()) {
8061 // This is a reference to a member without an explicitly-specified
8062 // template argument list. Optimize for this common case.
8063 if (!getDerived().AlwaysRebuild() &&
8064 Base.get() == OldBase &&
8065 BaseType == E->getBaseType() &&
8066 QualifierLoc == E->getQualifierLoc() &&
8067 NameInfo.getName() == E->getMember() &&
8068 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
8069 return SemaRef.Owned(E);
8071 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8074 E->getOperatorLoc(),
8077 FirstQualifierInScope,
8079 /*TemplateArgs*/ 0);
8082 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8083 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8084 E->getNumTemplateArgs(),
8088 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8091 E->getOperatorLoc(),
8094 FirstQualifierInScope,
8099 template<typename Derived>
8101 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
8102 // Transform the base of the expression.
8103 ExprResult Base((Expr*) 0);
8105 if (!Old->isImplicitAccess()) {
8106 Base = getDerived().TransformExpr(Old->getBase());
8107 if (Base.isInvalid())
8109 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8111 if (Base.isInvalid())
8113 BaseType = Base.get()->getType();
8115 BaseType = getDerived().TransformType(Old->getBaseType());
8118 NestedNameSpecifierLoc QualifierLoc;
8119 if (Old->getQualifierLoc()) {
8121 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8126 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8128 LookupResult R(SemaRef, Old->getMemberNameInfo(),
8129 Sema::LookupOrdinaryName);
8131 // Transform all the decls.
8132 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8133 E = Old->decls_end(); I != E; ++I) {
8134 NamedDecl *InstD = static_cast<NamedDecl*>(
8135 getDerived().TransformDecl(Old->getMemberLoc(),
8138 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8139 // This can happen because of dependent hiding.
8140 if (isa<UsingShadowDecl>(*I))
8148 // Expand using declarations.
8149 if (isa<UsingDecl>(InstD)) {
8150 UsingDecl *UD = cast<UsingDecl>(InstD);
8151 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8152 E = UD->shadow_end(); I != E; ++I)
8162 // Determine the naming class.
8163 if (Old->getNamingClass()) {
8164 CXXRecordDecl *NamingClass
8165 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8166 Old->getMemberLoc(),
8167 Old->getNamingClass()));
8171 R.setNamingClass(NamingClass);
8174 TemplateArgumentListInfo TransArgs;
8175 if (Old->hasExplicitTemplateArgs()) {
8176 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8177 TransArgs.setRAngleLoc(Old->getRAngleLoc());
8178 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8179 Old->getNumTemplateArgs(),
8184 // FIXME: to do this check properly, we will need to preserve the
8185 // first-qualifier-in-scope here, just in case we had a dependent
8186 // base (and therefore couldn't do the check) and a
8187 // nested-name-qualifier (and therefore could do the lookup).
8188 NamedDecl *FirstQualifierInScope = 0;
8190 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
8192 Old->getOperatorLoc(),
8196 FirstQualifierInScope,
8198 (Old->hasExplicitTemplateArgs()
8202 template<typename Derived>
8204 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
8205 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8206 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8207 if (SubExpr.isInvalid())
8210 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
8211 return SemaRef.Owned(E);
8213 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8216 template<typename Derived>
8218 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
8219 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8220 if (Pattern.isInvalid())
8223 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8224 return SemaRef.Owned(E);
8226 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8227 E->getNumExpansions());
8230 template<typename Derived>
8232 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8233 // If E is not value-dependent, then nothing will change when we transform it.
8234 // Note: This is an instantiation-centric view.
8235 if (!E->isValueDependent())
8236 return SemaRef.Owned(E);
8238 // Note: None of the implementations of TryExpandParameterPacks can ever
8239 // produce a diagnostic when given only a single unexpanded parameter pack,
8241 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8242 bool ShouldExpand = false;
8243 bool RetainExpansion = false;
8244 llvm::Optional<unsigned> NumExpansions;
8245 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
8247 ShouldExpand, RetainExpansion,
8251 if (RetainExpansion)
8252 return SemaRef.Owned(E);
8254 NamedDecl *Pack = E->getPack();
8255 if (!ShouldExpand) {
8256 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8263 // We now know the length of the parameter pack, so build a new expression
8264 // that stores that length.
8265 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8266 E->getPackLoc(), E->getRParenLoc(),
8270 template<typename Derived>
8272 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8273 SubstNonTypeTemplateParmPackExpr *E) {
8274 // Default behavior is to do nothing with this transformation.
8275 return SemaRef.Owned(E);
8278 template<typename Derived>
8280 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8281 SubstNonTypeTemplateParmExpr *E) {
8282 // Default behavior is to do nothing with this transformation.
8283 return SemaRef.Owned(E);
8286 template<typename Derived>
8288 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8289 MaterializeTemporaryExpr *E) {
8290 return getDerived().TransformExpr(E->GetTemporaryExpr());
8293 template<typename Derived>
8295 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
8296 return SemaRef.MaybeBindToTemporary(E);
8299 template<typename Derived>
8301 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
8302 return SemaRef.Owned(E);
8305 template<typename Derived>
8307 TreeTransform<Derived>::TransformObjCNumericLiteral(ObjCNumericLiteral *E) {
8308 return SemaRef.MaybeBindToTemporary(E);
8311 template<typename Derived>
8313 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8314 // Transform each of the elements.
8315 llvm::SmallVector<Expr *, 8> Elements;
8316 bool ArgChanged = false;
8317 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8318 /*IsCall=*/false, Elements, &ArgChanged))
8321 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8322 return SemaRef.MaybeBindToTemporary(E);
8324 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8329 template<typename Derived>
8331 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8332 ObjCDictionaryLiteral *E) {
8333 // Transform each of the elements.
8334 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8335 bool ArgChanged = false;
8336 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8337 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8339 if (OrigElement.isPackExpansion()) {
8340 // This key/value element is a pack expansion.
8341 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8342 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8343 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8344 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8346 // Determine whether the set of unexpanded parameter packs can
8347 // and should be expanded.
8349 bool RetainExpansion = false;
8350 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8351 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8352 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8353 OrigElement.Value->getLocEnd());
8354 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8357 Expand, RetainExpansion,
8362 // The transform has determined that we should perform a simple
8363 // transformation on the pack expansion, producing another pack
8365 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8366 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8367 if (Key.isInvalid())
8370 if (Key.get() != OrigElement.Key)
8373 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8374 if (Value.isInvalid())
8377 if (Value.get() != OrigElement.Value)
8380 ObjCDictionaryElement Expansion = {
8381 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8383 Elements.push_back(Expansion);
8387 // Record right away that the argument was changed. This needs
8388 // to happen even if the array expands to nothing.
8391 // The transform has determined that we should perform an elementwise
8392 // expansion of the pattern. Do so.
8393 for (unsigned I = 0; I != *NumExpansions; ++I) {
8394 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8395 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8396 if (Key.isInvalid())
8399 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8400 if (Value.isInvalid())
8403 ObjCDictionaryElement Element = {
8404 Key.get(), Value.get(), SourceLocation(), NumExpansions
8407 // If any unexpanded parameter packs remain, we still have a
8409 if (Key.get()->containsUnexpandedParameterPack() ||
8410 Value.get()->containsUnexpandedParameterPack())
8411 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8413 Elements.push_back(Element);
8416 // We've finished with this pack expansion.
8420 // Transform and check key.
8421 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8422 if (Key.isInvalid())
8425 if (Key.get() != OrigElement.Key)
8428 // Transform and check value.
8430 = getDerived().TransformExpr(OrigElement.Value);
8431 if (Value.isInvalid())
8434 if (Value.get() != OrigElement.Value)
8437 ObjCDictionaryElement Element = {
8438 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8440 Elements.push_back(Element);
8443 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8444 return SemaRef.MaybeBindToTemporary(E);
8446 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8451 template<typename Derived>
8453 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
8454 TypeSourceInfo *EncodedTypeInfo
8455 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8456 if (!EncodedTypeInfo)
8459 if (!getDerived().AlwaysRebuild() &&
8460 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
8461 return SemaRef.Owned(E);
8463 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
8468 template<typename Derived>
8469 ExprResult TreeTransform<Derived>::
8470 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8471 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8472 if (result.isInvalid()) return ExprError();
8473 Expr *subExpr = result.take();
8475 if (!getDerived().AlwaysRebuild() &&
8476 subExpr == E->getSubExpr())
8477 return SemaRef.Owned(E);
8479 return SemaRef.Owned(new(SemaRef.Context)
8480 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8483 template<typename Derived>
8484 ExprResult TreeTransform<Derived>::
8485 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8486 TypeSourceInfo *TSInfo
8487 = getDerived().TransformType(E->getTypeInfoAsWritten());
8491 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8492 if (Result.isInvalid())
8495 if (!getDerived().AlwaysRebuild() &&
8496 TSInfo == E->getTypeInfoAsWritten() &&
8497 Result.get() == E->getSubExpr())
8498 return SemaRef.Owned(E);
8500 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8501 E->getBridgeKeywordLoc(), TSInfo,
8505 template<typename Derived>
8507 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
8508 // Transform arguments.
8509 bool ArgChanged = false;
8510 ASTOwningVector<Expr*> Args(SemaRef);
8511 Args.reserve(E->getNumArgs());
8512 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8516 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8517 // Class message: transform the receiver type.
8518 TypeSourceInfo *ReceiverTypeInfo
8519 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8520 if (!ReceiverTypeInfo)
8523 // If nothing changed, just retain the existing message send.
8524 if (!getDerived().AlwaysRebuild() &&
8525 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
8526 return SemaRef.MaybeBindToTemporary(E);
8528 // Build a new class message send.
8529 SmallVector<SourceLocation, 16> SelLocs;
8530 E->getSelectorLocs(SelLocs);
8531 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8540 // Instance message: transform the receiver
8541 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8542 "Only class and instance messages may be instantiated");
8544 = getDerived().TransformExpr(E->getInstanceReceiver());
8545 if (Receiver.isInvalid())
8548 // If nothing changed, just retain the existing message send.
8549 if (!getDerived().AlwaysRebuild() &&
8550 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
8551 return SemaRef.MaybeBindToTemporary(E);
8553 // Build a new instance message send.
8554 SmallVector<SourceLocation, 16> SelLocs;
8555 E->getSelectorLocs(SelLocs);
8556 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
8565 template<typename Derived>
8567 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
8568 return SemaRef.Owned(E);
8571 template<typename Derived>
8573 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
8574 return SemaRef.Owned(E);
8577 template<typename Derived>
8579 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
8580 // Transform the base expression.
8581 ExprResult Base = getDerived().TransformExpr(E->getBase());
8582 if (Base.isInvalid())
8585 // We don't need to transform the ivar; it will never change.
8587 // If nothing changed, just retain the existing expression.
8588 if (!getDerived().AlwaysRebuild() &&
8589 Base.get() == E->getBase())
8590 return SemaRef.Owned(E);
8592 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
8594 E->isArrow(), E->isFreeIvar());
8597 template<typename Derived>
8599 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
8600 // 'super' and types never change. Property never changes. Just
8601 // retain the existing expression.
8602 if (!E->isObjectReceiver())
8603 return SemaRef.Owned(E);
8605 // Transform the base expression.
8606 ExprResult Base = getDerived().TransformExpr(E->getBase());
8607 if (Base.isInvalid())
8610 // We don't need to transform the property; it will never change.
8612 // If nothing changed, just retain the existing expression.
8613 if (!getDerived().AlwaysRebuild() &&
8614 Base.get() == E->getBase())
8615 return SemaRef.Owned(E);
8617 if (E->isExplicitProperty())
8618 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8619 E->getExplicitProperty(),
8622 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8623 SemaRef.Context.PseudoObjectTy,
8624 E->getImplicitPropertyGetter(),
8625 E->getImplicitPropertySetter(),
8629 template<typename Derived>
8631 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8632 // Transform the base expression.
8633 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8634 if (Base.isInvalid())
8637 // Transform the key expression.
8638 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8639 if (Key.isInvalid())
8642 // If nothing changed, just retain the existing expression.
8643 if (!getDerived().AlwaysRebuild() &&
8644 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8645 return SemaRef.Owned(E);
8647 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8648 Base.get(), Key.get(),
8649 E->getAtIndexMethodDecl(),
8650 E->setAtIndexMethodDecl());
8653 template<typename Derived>
8655 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
8656 // Transform the base expression.
8657 ExprResult Base = getDerived().TransformExpr(E->getBase());
8658 if (Base.isInvalid())
8661 // If nothing changed, just retain the existing expression.
8662 if (!getDerived().AlwaysRebuild() &&
8663 Base.get() == E->getBase())
8664 return SemaRef.Owned(E);
8666 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
8670 template<typename Derived>
8672 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
8673 bool ArgumentChanged = false;
8674 ASTOwningVector<Expr*> SubExprs(SemaRef);
8675 SubExprs.reserve(E->getNumSubExprs());
8676 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8677 SubExprs, &ArgumentChanged))
8680 if (!getDerived().AlwaysRebuild() &&
8682 return SemaRef.Owned(E);
8684 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8689 template<typename Derived>
8691 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
8692 BlockDecl *oldBlock = E->getBlockDecl();
8694 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8695 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8697 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
8698 blockScope->TheDecl->setBlockMissingReturnType(
8699 oldBlock->blockMissingReturnType());
8701 SmallVector<ParmVarDecl*, 4> params;
8702 SmallVector<QualType, 4> paramTypes;
8704 // Parameter substitution.
8705 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8706 oldBlock->param_begin(),
8707 oldBlock->param_size(),
8708 0, paramTypes, ¶ms)) {
8709 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
8713 const FunctionType *exprFunctionType = E->getFunctionType();
8714 QualType exprResultType =
8715 getDerived().TransformType(exprFunctionType->getResultType());
8717 // Don't allow returning a objc interface by value.
8718 if (exprResultType->isObjCObjectType()) {
8719 getSema().Diag(E->getCaretLocation(),
8720 diag::err_object_cannot_be_passed_returned_by_value)
8721 << 0 << exprResultType;
8722 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
8726 QualType functionType = getDerived().RebuildFunctionProtoType(
8730 oldBlock->isVariadic(),
8732 exprFunctionType->getExtInfo());
8733 blockScope->FunctionType = functionType;
8735 // Set the parameters on the block decl.
8736 if (!params.empty())
8737 blockScope->TheDecl->setParams(params);
8739 if (!oldBlock->blockMissingReturnType()) {
8740 blockScope->HasImplicitReturnType = false;
8741 blockScope->ReturnType = exprResultType;
8744 // Transform the body
8745 StmtResult body = getDerived().TransformStmt(E->getBody());
8746 if (body.isInvalid()) {
8747 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
8752 // In builds with assertions, make sure that we captured everything we
8754 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8755 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8756 e = oldBlock->capture_end(); i != e; ++i) {
8757 VarDecl *oldCapture = i->getVariable();
8759 // Ignore parameter packs.
8760 if (isa<ParmVarDecl>(oldCapture) &&
8761 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8764 VarDecl *newCapture =
8765 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8767 assert(blockScope->CaptureMap.count(newCapture));
8769 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
8773 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8777 template<typename Derived>
8779 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8780 llvm_unreachable("Cannot transform asType expressions yet");
8783 template<typename Derived>
8785 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
8786 QualType RetTy = getDerived().TransformType(E->getType());
8787 bool ArgumentChanged = false;
8788 ASTOwningVector<Expr*> SubExprs(SemaRef);
8789 SubExprs.reserve(E->getNumSubExprs());
8790 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8791 SubExprs, &ArgumentChanged))
8794 if (!getDerived().AlwaysRebuild() &&
8796 return SemaRef.Owned(E);
8798 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8799 RetTy, E->getOp(), E->getRParenLoc());
8802 //===----------------------------------------------------------------------===//
8803 // Type reconstruction
8804 //===----------------------------------------------------------------------===//
8806 template<typename Derived>
8807 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8808 SourceLocation Star) {
8809 return SemaRef.BuildPointerType(PointeeType, Star,
8810 getDerived().getBaseEntity());
8813 template<typename Derived>
8814 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8815 SourceLocation Star) {
8816 return SemaRef.BuildBlockPointerType(PointeeType, Star,
8817 getDerived().getBaseEntity());
8820 template<typename Derived>
8822 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8823 bool WrittenAsLValue,
8824 SourceLocation Sigil) {
8825 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
8826 Sigil, getDerived().getBaseEntity());
8829 template<typename Derived>
8831 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8833 SourceLocation Sigil) {
8834 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
8835 Sigil, getDerived().getBaseEntity());
8838 template<typename Derived>
8840 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8841 ArrayType::ArraySizeModifier SizeMod,
8842 const llvm::APInt *Size,
8844 unsigned IndexTypeQuals,
8845 SourceRange BracketsRange) {
8846 if (SizeExpr || !Size)
8847 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8848 IndexTypeQuals, BracketsRange,
8849 getDerived().getBaseEntity());
8851 QualType Types[] = {
8852 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8853 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8854 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
8856 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8858 for (unsigned I = 0; I != NumTypes; ++I)
8859 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8860 SizeType = Types[I];
8864 // Note that we can return a VariableArrayType here in the case where
8865 // the element type was a dependent VariableArrayType.
8866 IntegerLiteral *ArraySize
8867 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8868 /*FIXME*/BracketsRange.getBegin());
8869 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
8870 IndexTypeQuals, BracketsRange,
8871 getDerived().getBaseEntity());
8874 template<typename Derived>
8876 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
8877 ArrayType::ArraySizeModifier SizeMod,
8878 const llvm::APInt &Size,
8879 unsigned IndexTypeQuals,
8880 SourceRange BracketsRange) {
8881 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
8882 IndexTypeQuals, BracketsRange);
8885 template<typename Derived>
8887 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
8888 ArrayType::ArraySizeModifier SizeMod,
8889 unsigned IndexTypeQuals,
8890 SourceRange BracketsRange) {
8891 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
8892 IndexTypeQuals, BracketsRange);
8895 template<typename Derived>
8897 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
8898 ArrayType::ArraySizeModifier SizeMod,
8900 unsigned IndexTypeQuals,
8901 SourceRange BracketsRange) {
8902 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
8904 IndexTypeQuals, BracketsRange);
8907 template<typename Derived>
8909 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
8910 ArrayType::ArraySizeModifier SizeMod,
8912 unsigned IndexTypeQuals,
8913 SourceRange BracketsRange) {
8914 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
8916 IndexTypeQuals, BracketsRange);
8919 template<typename Derived>
8920 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
8921 unsigned NumElements,
8922 VectorType::VectorKind VecKind) {
8923 // FIXME: semantic checking!
8924 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
8927 template<typename Derived>
8928 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8929 unsigned NumElements,
8930 SourceLocation AttributeLoc) {
8931 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8933 IntegerLiteral *VectorSize
8934 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8936 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
8939 template<typename Derived>
8941 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
8943 SourceLocation AttributeLoc) {
8944 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
8947 template<typename Derived>
8948 QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
8949 QualType *ParamTypes,
8950 unsigned NumParamTypes,
8952 bool HasTrailingReturn,
8954 RefQualifierKind RefQualifier,
8955 const FunctionType::ExtInfo &Info) {
8956 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
8957 HasTrailingReturn, Quals, RefQualifier,
8958 getDerived().getBaseLocation(),
8959 getDerived().getBaseEntity(),
8963 template<typename Derived>
8964 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8965 return SemaRef.Context.getFunctionNoProtoType(T);
8968 template<typename Derived>
8969 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8970 assert(D && "no decl found");
8971 if (D->isInvalidDecl()) return QualType();
8973 // FIXME: Doesn't account for ObjCInterfaceDecl!
8975 if (isa<UsingDecl>(D)) {
8976 UsingDecl *Using = cast<UsingDecl>(D);
8977 assert(Using->isTypeName() &&
8978 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8980 // A valid resolved using typename decl points to exactly one type decl.
8981 assert(++Using->shadow_begin() == Using->shadow_end());
8982 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
8985 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8986 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8987 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8990 return SemaRef.Context.getTypeDeclType(Ty);
8993 template<typename Derived>
8994 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8995 SourceLocation Loc) {
8996 return SemaRef.BuildTypeofExprType(E, Loc);
8999 template<typename Derived>
9000 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9001 return SemaRef.Context.getTypeOfType(Underlying);
9004 template<typename Derived>
9005 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9006 SourceLocation Loc) {
9007 return SemaRef.BuildDecltypeType(E, Loc);
9010 template<typename Derived>
9011 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9012 UnaryTransformType::UTTKind UKind,
9013 SourceLocation Loc) {
9014 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9017 template<typename Derived>
9018 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
9019 TemplateName Template,
9020 SourceLocation TemplateNameLoc,
9021 TemplateArgumentListInfo &TemplateArgs) {
9022 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
9025 template<typename Derived>
9026 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9027 SourceLocation KWLoc) {
9028 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9031 template<typename Derived>
9033 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9035 TemplateDecl *Template) {
9036 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
9040 template<typename Derived>
9042 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9043 const IdentifierInfo &Name,
9044 SourceLocation NameLoc,
9045 QualType ObjectType,
9046 NamedDecl *FirstQualifierInScope) {
9047 UnqualifiedId TemplateName;
9048 TemplateName.setIdentifier(&Name, NameLoc);
9049 Sema::TemplateTy Template;
9050 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9051 getSema().ActOnDependentTemplateName(/*Scope=*/0,
9052 SS, TemplateKWLoc, TemplateName,
9053 ParsedType::make(ObjectType),
9054 /*EnteringContext=*/false,
9056 return Template.get();
9059 template<typename Derived>
9061 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9062 OverloadedOperatorKind Operator,
9063 SourceLocation NameLoc,
9064 QualType ObjectType) {
9066 // FIXME: Bogus location information.
9067 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
9068 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
9069 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9070 Sema::TemplateTy Template;
9071 getSema().ActOnDependentTemplateName(/*Scope=*/0,
9072 SS, TemplateKWLoc, Name,
9073 ParsedType::make(ObjectType),
9074 /*EnteringContext=*/false,
9076 return Template.template getAsVal<TemplateName>();
9079 template<typename Derived>
9081 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9082 SourceLocation OpLoc,
9086 Expr *Callee = OrigCallee->IgnoreParenCasts();
9087 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
9089 // Determine whether this should be a builtin operation.
9090 if (Op == OO_Subscript) {
9091 if (!First->getType()->isOverloadableType() &&
9092 !Second->getType()->isOverloadableType())
9093 return getSema().CreateBuiltinArraySubscriptExpr(First,
9094 Callee->getLocStart(),
9096 } else if (Op == OO_Arrow) {
9097 // -> is never a builtin operation.
9098 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9099 } else if (Second == 0 || isPostIncDec) {
9100 if (!First->getType()->isOverloadableType()) {
9101 // The argument is not of overloadable type, so try to create a
9102 // built-in unary operation.
9103 UnaryOperatorKind Opc
9104 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
9106 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
9109 if (!First->getType()->isOverloadableType() &&
9110 !Second->getType()->isOverloadableType()) {
9111 // Neither of the arguments is an overloadable type, so try to
9112 // create a built-in binary operation.
9113 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9115 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
9116 if (Result.isInvalid())
9119 return move(Result);
9123 // Compute the transformed set of functions (and function templates) to be
9124 // used during overload resolution.
9125 UnresolvedSet<16> Functions;
9127 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
9128 assert(ULE->requiresADL());
9130 // FIXME: Do we have to check
9131 // IsAcceptableNonMemberOperatorCandidate for each of these?
9132 Functions.append(ULE->decls_begin(), ULE->decls_end());
9134 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
9137 // Add any functions found via argument-dependent lookup.
9138 Expr *Args[2] = { First, Second };
9139 unsigned NumArgs = 1 + (Second != 0);
9141 // Create the overloaded operator invocation for unary operators.
9142 if (NumArgs == 1 || isPostIncDec) {
9143 UnaryOperatorKind Opc
9144 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
9145 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
9148 if (Op == OO_Subscript) {
9149 SourceLocation LBrace;
9150 SourceLocation RBrace;
9152 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9153 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9154 LBrace = SourceLocation::getFromRawEncoding(
9155 NameLoc.CXXOperatorName.BeginOpNameLoc);
9156 RBrace = SourceLocation::getFromRawEncoding(
9157 NameLoc.CXXOperatorName.EndOpNameLoc);
9159 LBrace = Callee->getLocStart();
9163 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9167 // Create the overloaded operator invocation for binary operators.
9168 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9170 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9171 if (Result.isInvalid())
9174 return move(Result);
9177 template<typename Derived>
9179 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
9180 SourceLocation OperatorLoc,
9183 TypeSourceInfo *ScopeType,
9184 SourceLocation CCLoc,
9185 SourceLocation TildeLoc,
9186 PseudoDestructorTypeStorage Destroyed) {
9187 QualType BaseType = Base->getType();
9188 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
9189 (!isArrow && !BaseType->getAs<RecordType>()) ||
9190 (isArrow && BaseType->getAs<PointerType>() &&
9191 !BaseType->getAs<PointerType>()->getPointeeType()
9192 ->template getAs<RecordType>())){
9193 // This pseudo-destructor expression is still a pseudo-destructor.
9194 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
9195 isArrow? tok::arrow : tok::period,
9196 SS, ScopeType, CCLoc, TildeLoc,
9201 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
9202 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9203 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9204 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9205 NameInfo.setNamedTypeInfo(DestroyedType);
9207 // FIXME: the ScopeType should be tacked onto SS.
9209 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9210 return getSema().BuildMemberReferenceExpr(Base, BaseType,
9211 OperatorLoc, isArrow,
9213 /*FIXME: FirstQualifier*/ 0,
9215 /*TemplateArgs*/ 0);
9218 } // end namespace clang
9220 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H