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"
525 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
526 FunctionProtoTypeLoc TL,
527 CXXRecordDecl *ThisContext,
528 unsigned ThisTypeQuals);
531 TransformSEHHandler(Stmt *Handler);
534 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
535 TemplateSpecializationTypeLoc TL,
536 TemplateName Template);
539 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
540 DependentTemplateSpecializationTypeLoc TL,
541 TemplateName Template,
545 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
546 DependentTemplateSpecializationTypeLoc TL,
547 NestedNameSpecifierLoc QualifierLoc);
549 /// \brief Transforms the parameters of a function type into the
552 /// The result vectors should be kept in sync; null entries in the
553 /// variables vector are acceptable.
555 /// Return true on error.
556 bool TransformFunctionTypeParams(SourceLocation Loc,
557 ParmVarDecl **Params, unsigned NumParams,
558 const QualType *ParamTypes,
559 SmallVectorImpl<QualType> &PTypes,
560 SmallVectorImpl<ParmVarDecl*> *PVars);
562 /// \brief Transforms a single function-type parameter. Return null
565 /// \param indexAdjustment - A number to add to the parameter's
566 /// scope index; can be negative
567 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
569 llvm::Optional<unsigned> NumExpansions,
570 bool ExpectParameterPack);
572 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
574 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
575 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
577 #define STMT(Node, Parent) \
578 StmtResult Transform##Node(Node *S);
579 #define EXPR(Node, Parent) \
580 ExprResult Transform##Node(Node *E);
581 #define ABSTRACT_STMT(Stmt)
582 #include "clang/AST/StmtNodes.inc"
584 /// \brief Build a new pointer type given its pointee type.
586 /// By default, performs semantic analysis when building the pointer type.
587 /// Subclasses may override this routine to provide different behavior.
588 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
590 /// \brief Build a new block pointer type given its pointee type.
592 /// By default, performs semantic analysis when building the block pointer
593 /// type. Subclasses may override this routine to provide different behavior.
594 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
596 /// \brief Build a new reference type given the type it references.
598 /// By default, performs semantic analysis when building the
599 /// reference type. Subclasses may override this routine to provide
600 /// different behavior.
602 /// \param LValue whether the type was written with an lvalue sigil
603 /// or an rvalue sigil.
604 QualType RebuildReferenceType(QualType ReferentType,
606 SourceLocation Sigil);
608 /// \brief Build a new member pointer type given the pointee type and the
609 /// class type it refers into.
611 /// By default, performs semantic analysis when building the member pointer
612 /// type. Subclasses may override this routine to provide different behavior.
613 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
614 SourceLocation Sigil);
616 /// \brief Build a new array type given the element type, size
617 /// modifier, size of the array (if known), size expression, and index type
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
622 /// Also by default, all of the other Rebuild*Array
623 QualType RebuildArrayType(QualType ElementType,
624 ArrayType::ArraySizeModifier SizeMod,
625 const llvm::APInt *Size,
627 unsigned IndexTypeQuals,
628 SourceRange BracketsRange);
630 /// \brief Build a new constant array type given the element type, size
631 /// modifier, (known) size of the array, and index type qualifiers.
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
635 QualType RebuildConstantArrayType(QualType ElementType,
636 ArrayType::ArraySizeModifier SizeMod,
637 const llvm::APInt &Size,
638 unsigned IndexTypeQuals,
639 SourceRange BracketsRange);
641 /// \brief Build a new incomplete array type given the element type, size
642 /// modifier, and index type qualifiers.
644 /// By default, performs semantic analysis when building the array type.
645 /// Subclasses may override this routine to provide different behavior.
646 QualType RebuildIncompleteArrayType(QualType ElementType,
647 ArrayType::ArraySizeModifier SizeMod,
648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
651 /// \brief Build a new variable-length array type given the element type,
652 /// size modifier, size expression, and index type qualifiers.
654 /// By default, performs semantic analysis when building the array type.
655 /// Subclasses may override this routine to provide different behavior.
656 QualType RebuildVariableArrayType(QualType ElementType,
657 ArrayType::ArraySizeModifier SizeMod,
659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
662 /// \brief Build a new dependent-sized array type given the element type,
663 /// size modifier, size expression, and index type qualifiers.
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
667 QualType RebuildDependentSizedArrayType(QualType ElementType,
668 ArrayType::ArraySizeModifier SizeMod,
670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
673 /// \brief Build a new vector type given the element type and
674 /// number of elements.
676 /// By default, performs semantic analysis when building the vector type.
677 /// Subclasses may override this routine to provide different behavior.
678 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
679 VectorType::VectorKind VecKind);
681 /// \brief Build a new extended vector type given the element type and
682 /// number of elements.
684 /// By default, performs semantic analysis when building the vector type.
685 /// Subclasses may override this routine to provide different behavior.
686 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687 SourceLocation AttributeLoc);
689 /// \brief Build a new potentially dependently-sized extended vector type
690 /// given the element type and number of elements.
692 /// By default, performs semantic analysis when building the vector type.
693 /// Subclasses may override this routine to provide different behavior.
694 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
696 SourceLocation AttributeLoc);
698 /// \brief Build a new function type.
700 /// By default, performs semantic analysis when building the function type.
701 /// Subclasses may override this routine to provide different behavior.
702 QualType RebuildFunctionProtoType(QualType T,
703 QualType *ParamTypes,
704 unsigned NumParamTypes,
705 bool Variadic, bool HasTrailingReturn,
707 RefQualifierKind RefQualifier,
708 const FunctionType::ExtInfo &Info);
710 /// \brief Build a new unprototyped function type.
711 QualType RebuildFunctionNoProtoType(QualType ResultType);
713 /// \brief Rebuild an unresolved typename type, given the decl that
714 /// the UnresolvedUsingTypenameDecl was transformed to.
715 QualType RebuildUnresolvedUsingType(Decl *D);
717 /// \brief Build a new typedef type.
718 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
719 return SemaRef.Context.getTypeDeclType(Typedef);
722 /// \brief Build a new class/struct/union type.
723 QualType RebuildRecordType(RecordDecl *Record) {
724 return SemaRef.Context.getTypeDeclType(Record);
727 /// \brief Build a new Enum type.
728 QualType RebuildEnumType(EnumDecl *Enum) {
729 return SemaRef.Context.getTypeDeclType(Enum);
732 /// \brief Build a new typeof(expr) type.
734 /// By default, performs semantic analysis when building the typeof type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
738 /// \brief Build a new typeof(type) type.
740 /// By default, builds a new TypeOfType with the given underlying type.
741 QualType RebuildTypeOfType(QualType Underlying);
743 /// \brief Build a new unary transform type.
744 QualType RebuildUnaryTransformType(QualType BaseType,
745 UnaryTransformType::UTTKind UKind,
748 /// \brief Build a new C++0x decltype type.
750 /// By default, performs semantic analysis when building the decltype type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
754 /// \brief Build a new C++0x auto type.
756 /// By default, builds a new AutoType with the given deduced type.
757 QualType RebuildAutoType(QualType Deduced) {
758 return SemaRef.Context.getAutoType(Deduced);
761 /// \brief Build a new template specialization type.
763 /// By default, performs semantic analysis when building the template
764 /// specialization type. Subclasses may override this routine to provide
765 /// different behavior.
766 QualType RebuildTemplateSpecializationType(TemplateName Template,
767 SourceLocation TemplateLoc,
768 TemplateArgumentListInfo &Args);
770 /// \brief Build a new parenthesized type.
772 /// By default, builds a new ParenType type from the inner type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildParenType(QualType InnerType) {
775 return SemaRef.Context.getParenType(InnerType);
778 /// \brief Build a new qualified name type.
780 /// By default, builds a new ElaboratedType type from the keyword,
781 /// the nested-name-specifier and the named type.
782 /// Subclasses may override this routine to provide different behavior.
783 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
784 ElaboratedTypeKeyword Keyword,
785 NestedNameSpecifierLoc QualifierLoc,
787 return SemaRef.Context.getElaboratedType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
792 /// \brief Build a new typename type that refers to a template-id.
794 /// By default, builds a new DependentNameType type from the
795 /// nested-name-specifier and the given type. Subclasses may override
796 /// this routine to provide different behavior.
797 QualType RebuildDependentTemplateSpecializationType(
798 ElaboratedTypeKeyword Keyword,
799 NestedNameSpecifierLoc QualifierLoc,
800 const IdentifierInfo *Name,
801 SourceLocation NameLoc,
802 TemplateArgumentListInfo &Args) {
803 // Rebuild the template name.
804 // TODO: avoid TemplateName abstraction
806 SS.Adopt(QualifierLoc);
807 TemplateName InstName
808 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
810 if (InstName.isNull())
813 // If it's still dependent, make a dependent specialization.
814 if (InstName.getAsDependentTemplateName())
815 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
816 QualifierLoc.getNestedNameSpecifier(),
820 // Otherwise, make an elaborated type wrapping a non-dependent
823 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
824 if (T.isNull()) return QualType();
826 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
829 return SemaRef.Context.getElaboratedType(Keyword,
830 QualifierLoc.getNestedNameSpecifier(),
834 /// \brief Build a new typename type that refers to an identifier.
836 /// By default, performs semantic analysis when building the typename type
837 /// (or elaborated type). Subclasses may override this routine to provide
838 /// different behavior.
839 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
840 SourceLocation KeywordLoc,
841 NestedNameSpecifierLoc QualifierLoc,
842 const IdentifierInfo *Id,
843 SourceLocation IdLoc) {
845 SS.Adopt(QualifierLoc);
847 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
848 // If the name is still dependent, just build a new dependent name type.
849 if (!SemaRef.computeDeclContext(SS))
850 return SemaRef.Context.getDependentNameType(Keyword,
851 QualifierLoc.getNestedNameSpecifier(),
855 if (Keyword == ETK_None || Keyword == ETK_Typename)
856 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
859 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
861 // We had a dependent elaborated-type-specifier that has been transformed
862 // into a non-dependent elaborated-type-specifier. Find the tag we're
864 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
865 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
869 if (SemaRef.RequireCompleteDeclContext(SS, DC))
873 SemaRef.LookupQualifiedName(Result, DC);
874 switch (Result.getResultKind()) {
875 case LookupResult::NotFound:
876 case LookupResult::NotFoundInCurrentInstantiation:
879 case LookupResult::Found:
880 Tag = Result.getAsSingle<TagDecl>();
883 case LookupResult::FoundOverloaded:
884 case LookupResult::FoundUnresolvedValue:
885 llvm_unreachable("Tag lookup cannot find non-tags");
887 case LookupResult::Ambiguous:
888 // Let the LookupResult structure handle ambiguities.
893 // Check where the name exists but isn't a tag type and use that to emit
894 // better diagnostics.
895 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896 SemaRef.LookupQualifiedName(Result, DC);
897 switch (Result.getResultKind()) {
898 case LookupResult::Found:
899 case LookupResult::FoundOverloaded:
900 case LookupResult::FoundUnresolvedValue: {
901 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
903 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
904 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
906 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
911 // FIXME: Would be nice to highlight just the source range.
912 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
919 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
921 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
922 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
926 // Build the elaborated-type-specifier type.
927 QualType T = SemaRef.Context.getTypeDeclType(Tag);
928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
933 /// \brief Build a new pack expansion type.
935 /// By default, builds a new PackExpansionType type from the given pattern.
936 /// Subclasses may override this routine to provide different behavior.
937 QualType RebuildPackExpansionType(QualType Pattern,
938 SourceRange PatternRange,
939 SourceLocation EllipsisLoc,
940 llvm::Optional<unsigned> NumExpansions) {
941 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
945 /// \brief Build a new atomic type given its value type.
947 /// By default, performs semantic analysis when building the atomic type.
948 /// Subclasses may override this routine to provide different behavior.
949 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
951 /// \brief Build a new template name given a nested name specifier, a flag
952 /// indicating whether the "template" keyword was provided, and the template
953 /// that the template name refers to.
955 /// By default, builds the new template name directly. Subclasses may override
956 /// this routine to provide different behavior.
957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
959 TemplateDecl *Template);
961 /// \brief Build a new template name given a nested name specifier and the
962 /// name that is referred to as a template.
964 /// By default, performs semantic analysis to determine whether the name can
965 /// be resolved to a specific template, then builds the appropriate kind of
966 /// template name. Subclasses may override this routine to provide different
968 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969 const IdentifierInfo &Name,
970 SourceLocation NameLoc,
972 NamedDecl *FirstQualifierInScope);
974 /// \brief Build a new template name given a nested name specifier and the
975 /// overloaded operator name that is referred to as a template.
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
982 OverloadedOperatorKind Operator,
983 SourceLocation NameLoc,
984 QualType ObjectType);
986 /// \brief Build a new template name given a template template parameter pack
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
993 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
994 const TemplateArgument &ArgPack) {
995 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
998 /// \brief Build a new compound statement.
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
1002 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1003 MultiStmtArg Statements,
1004 SourceLocation RBraceLoc,
1006 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1010 /// \brief Build a new case statement.
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
1014 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1016 SourceLocation EllipsisLoc,
1018 SourceLocation ColonLoc) {
1019 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1023 /// \brief Attach the body to a new case statement.
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
1027 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1028 getSema().ActOnCaseStmtBody(S, Body);
1032 /// \brief Build a new default statement.
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
1036 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1037 SourceLocation ColonLoc,
1039 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1043 /// \brief Build a new label statement.
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
1047 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1048 SourceLocation ColonLoc, Stmt *SubStmt) {
1049 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1052 /// \brief Build a new label statement.
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
1056 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs,
1058 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1061 /// \brief Build a new "if" statement.
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
1065 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
1066 VarDecl *CondVar, Stmt *Then,
1067 SourceLocation ElseLoc, Stmt *Else) {
1068 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
1071 /// \brief Start building a new switch statement.
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
1075 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
1076 Expr *Cond, VarDecl *CondVar) {
1077 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1081 /// \brief Attach the body to the switch statement.
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
1085 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1086 Stmt *Switch, Stmt *Body) {
1087 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1090 /// \brief Build a new while statement.
1092 /// By default, performs semantic analysis to build the new statement.
1093 /// Subclasses may override this routine to provide different behavior.
1094 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1095 VarDecl *CondVar, Stmt *Body) {
1096 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
1099 /// \brief Build a new do-while statement.
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
1103 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1104 SourceLocation WhileLoc, SourceLocation LParenLoc,
1105 Expr *Cond, SourceLocation RParenLoc) {
1106 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1110 /// \brief Build a new for statement.
1112 /// By default, performs semantic analysis to build the new statement.
1113 /// Subclasses may override this routine to provide different behavior.
1114 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1115 Stmt *Init, Sema::FullExprArg Cond,
1116 VarDecl *CondVar, Sema::FullExprArg Inc,
1117 SourceLocation RParenLoc, Stmt *Body) {
1118 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1119 CondVar, Inc, RParenLoc, Body);
1122 /// \brief Build a new goto statement.
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
1126 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1128 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1131 /// \brief Build a new indirect goto statement.
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
1135 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1136 SourceLocation StarLoc,
1138 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1141 /// \brief Build a new return statement.
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
1145 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1146 return getSema().ActOnReturnStmt(ReturnLoc, Result);
1149 /// \brief Build a new declaration statement.
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
1153 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
1154 SourceLocation StartLoc,
1155 SourceLocation EndLoc) {
1156 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1157 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1160 /// \brief Build a new inline asm statement.
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
1164 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
1167 unsigned NumOutputs,
1169 IdentifierInfo **Names,
1170 MultiExprArg Constraints,
1173 MultiExprArg Clobbers,
1174 SourceLocation RParenLoc,
1176 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1177 NumInputs, Names, move(Constraints),
1178 Exprs, AsmString, Clobbers,
1182 /// \brief Build a new Objective-C @try statement.
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
1186 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1188 MultiStmtArg CatchStmts,
1190 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1194 /// \brief Rebuild an Objective-C exception declaration.
1196 /// By default, performs semantic analysis to build the new declaration.
1197 /// Subclasses may override this routine to provide different behavior.
1198 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1199 TypeSourceInfo *TInfo, QualType T) {
1200 return getSema().BuildObjCExceptionDecl(TInfo, T,
1201 ExceptionDecl->getInnerLocStart(),
1202 ExceptionDecl->getLocation(),
1203 ExceptionDecl->getIdentifier());
1206 /// \brief Build a new Objective-C @catch statement.
1208 /// By default, performs semantic analysis to build the new statement.
1209 /// Subclasses may override this routine to provide different behavior.
1210 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1211 SourceLocation RParenLoc,
1214 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1218 /// \brief Build a new Objective-C @finally statement.
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1224 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1227 /// \brief Build a new Objective-C @throw statement.
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
1231 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1233 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1236 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
1240 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1242 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1245 /// \brief Build a new Objective-C @synchronized statement.
1247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
1249 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1250 Expr *Object, Stmt *Body) {
1251 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1254 /// \brief Build a new Objective-C @autoreleasepool statement.
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
1258 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1260 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1263 /// \brief Build the collection operand to a new Objective-C fast
1264 /// enumeration statement.
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
1268 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1270 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1273 /// \brief Build a new Objective-C fast enumeration statement.
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
1277 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1278 SourceLocation LParenLoc,
1281 SourceLocation RParenLoc,
1283 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
1290 /// \brief Build a new C++ exception declaration.
1292 /// By default, performs semantic analysis to build the new decaration.
1293 /// Subclasses may override this routine to provide different behavior.
1294 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1295 TypeSourceInfo *Declarator,
1296 SourceLocation StartLoc,
1297 SourceLocation IdLoc,
1298 IdentifierInfo *Id) {
1299 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1300 StartLoc, IdLoc, Id);
1302 getSema().CurContext->addDecl(Var);
1306 /// \brief Build a new C++ catch statement.
1308 /// By default, performs semantic analysis to build the new statement.
1309 /// Subclasses may override this routine to provide different behavior.
1310 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1311 VarDecl *ExceptionDecl,
1313 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1317 /// \brief Build a new C++ try statement.
1319 /// By default, performs semantic analysis to build the new statement.
1320 /// Subclasses may override this routine to provide different behavior.
1321 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1323 MultiStmtArg Handlers) {
1324 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
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 RebuildCXXForRangeStmt(SourceLocation ForLoc,
1332 SourceLocation ColonLoc,
1333 Stmt *Range, Stmt *BeginEnd,
1334 Expr *Cond, Expr *Inc,
1336 SourceLocation RParenLoc) {
1337 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1338 Cond, Inc, LoopVar, RParenLoc);
1341 /// \brief Build a new C++0x range-based for statement.
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
1345 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1347 NestedNameSpecifierLoc QualifierLoc,
1348 DeclarationNameInfo NameInfo,
1350 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1351 QualifierLoc, NameInfo, Nested);
1354 /// \brief Attach body to a C++0x range-based for statement.
1356 /// By default, performs semantic analysis to finish the new statement.
1357 /// Subclasses may override this routine to provide different behavior.
1358 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1359 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1362 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1363 SourceLocation TryLoc,
1366 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1369 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1372 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1375 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1377 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1380 /// \brief Build a new expression that references a declaration.
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
1384 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1387 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1391 /// \brief Build a new expression that references a declaration.
1393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
1395 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1397 const DeclarationNameInfo &NameInfo,
1398 TemplateArgumentListInfo *TemplateArgs) {
1400 SS.Adopt(QualifierLoc);
1402 // FIXME: loses template args.
1404 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1407 /// \brief Build a new expression in parentheses.
1409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
1411 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1412 SourceLocation RParen) {
1413 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1416 /// \brief Build a new pseudo-destructor expression.
1418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
1420 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1421 SourceLocation OperatorLoc,
1424 TypeSourceInfo *ScopeType,
1425 SourceLocation CCLoc,
1426 SourceLocation TildeLoc,
1427 PseudoDestructorTypeStorage Destroyed);
1429 /// \brief Build a new unary operator expression.
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1434 UnaryOperatorKind Opc,
1436 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1439 /// \brief Build a new builtin offsetof expression.
1441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
1443 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1444 TypeSourceInfo *Type,
1445 Sema::OffsetOfComponent *Components,
1446 unsigned NumComponents,
1447 SourceLocation RParenLoc) {
1448 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1449 NumComponents, RParenLoc);
1452 /// \brief Build a new sizeof, alignof or vec_step expression with a
1455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
1457 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1458 SourceLocation OpLoc,
1459 UnaryExprOrTypeTrait ExprKind,
1461 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1464 /// \brief Build a new sizeof, alignof or vec step expression with an
1465 /// expression argument.
1467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
1469 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1470 UnaryExprOrTypeTrait ExprKind,
1473 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1474 if (Result.isInvalid())
1477 return move(Result);
1480 /// \brief Build a new array subscript expression.
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
1484 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1485 SourceLocation LBracketLoc,
1487 SourceLocation RBracketLoc) {
1488 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1493 /// \brief Build a new call expression.
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
1497 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1499 SourceLocation RParenLoc,
1500 Expr *ExecConfig = 0) {
1501 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1502 move(Args), RParenLoc, ExecConfig);
1505 /// \brief Build a new member access expression.
1507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
1509 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1511 NestedNameSpecifierLoc QualifierLoc,
1512 SourceLocation TemplateKWLoc,
1513 const DeclarationNameInfo &MemberNameInfo,
1515 NamedDecl *FoundDecl,
1516 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1517 NamedDecl *FirstQualifierInScope) {
1518 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1520 if (!Member->getDeclName()) {
1521 // We have a reference to an unnamed field. This is always the
1522 // base of an anonymous struct/union member access, i.e. the
1523 // field is always of record type.
1524 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1525 assert(Member->getType()->isRecordType() &&
1526 "unnamed member not of record type?");
1529 getSema().PerformObjectMemberConversion(BaseResult.take(),
1530 QualifierLoc.getNestedNameSpecifier(),
1532 if (BaseResult.isInvalid())
1534 Base = BaseResult.take();
1535 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
1537 new (getSema().Context) MemberExpr(Base, isArrow,
1538 Member, MemberNameInfo,
1539 cast<FieldDecl>(Member)->getType(),
1541 return getSema().Owned(ME);
1545 SS.Adopt(QualifierLoc);
1547 Base = BaseResult.take();
1548 QualType BaseType = Base->getType();
1550 // FIXME: this involves duplicating earlier analysis in a lot of
1551 // cases; we should avoid this when possible.
1552 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
1553 R.addDecl(FoundDecl);
1556 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1558 FirstQualifierInScope,
1559 R, ExplicitTemplateArgs);
1562 /// \brief Build a new binary operator expression.
1564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
1566 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1567 BinaryOperatorKind Opc,
1568 Expr *LHS, Expr *RHS) {
1569 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1572 /// \brief Build a new conditional operator expression.
1574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
1576 ExprResult RebuildConditionalOperator(Expr *Cond,
1577 SourceLocation QuestionLoc,
1579 SourceLocation ColonLoc,
1581 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1585 /// \brief Build a new C-style cast expression.
1587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
1589 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1590 TypeSourceInfo *TInfo,
1591 SourceLocation RParenLoc,
1593 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1597 /// \brief Build a new compound literal expression.
1599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
1601 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1602 TypeSourceInfo *TInfo,
1603 SourceLocation RParenLoc,
1605 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1609 /// \brief Build a new extended vector element access expression.
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
1613 ExprResult RebuildExtVectorElementExpr(Expr *Base,
1614 SourceLocation OpLoc,
1615 SourceLocation AccessorLoc,
1616 IdentifierInfo &Accessor) {
1619 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
1620 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1621 OpLoc, /*IsArrow*/ false,
1622 SS, SourceLocation(),
1623 /*FirstQualifierInScope*/ 0,
1625 /* TemplateArgs */ 0);
1628 /// \brief Build a new initializer list expression.
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
1632 ExprResult RebuildInitList(SourceLocation LBraceLoc,
1634 SourceLocation RBraceLoc,
1635 QualType ResultTy) {
1637 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1638 if (Result.isInvalid() || ResultTy->isDependentType())
1639 return move(Result);
1641 // Patch in the result type we were given, which may have been computed
1642 // when the initial InitListExpr was built.
1643 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1644 ILE->setType(ResultTy);
1645 return move(Result);
1648 /// \brief Build a new designated initializer expression.
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
1652 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1653 MultiExprArg ArrayExprs,
1654 SourceLocation EqualOrColonLoc,
1658 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1660 if (Result.isInvalid())
1663 ArrayExprs.release();
1664 return move(Result);
1667 /// \brief Build a new value-initialized expression.
1669 /// By default, builds the implicit value initialization without performing
1670 /// any semantic analysis. Subclasses may override this routine to provide
1671 /// different behavior.
1672 ExprResult RebuildImplicitValueInitExpr(QualType T) {
1673 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1676 /// \brief Build a new \c va_arg expression.
1678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
1680 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1681 Expr *SubExpr, TypeSourceInfo *TInfo,
1682 SourceLocation RParenLoc) {
1683 return getSema().BuildVAArgExpr(BuiltinLoc,
1688 /// \brief Build a new expression list in parentheses.
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
1692 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1693 MultiExprArg SubExprs,
1694 SourceLocation RParenLoc) {
1695 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
1698 /// \brief Build a new address-of-label expression.
1700 /// By default, performs semantic analysis, using the name of the label
1701 /// rather than attempting to map the label statement itself.
1702 /// Subclasses may override this routine to provide different behavior.
1703 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1704 SourceLocation LabelLoc, LabelDecl *Label) {
1705 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
1708 /// \brief Build a new GNU statement expression.
1710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
1712 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1714 SourceLocation RParenLoc) {
1715 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1718 /// \brief Build a new __builtin_choose_expr expression.
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
1722 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1723 Expr *Cond, Expr *LHS, Expr *RHS,
1724 SourceLocation RParenLoc) {
1725 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1730 /// \brief Build a new generic selection expression.
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
1734 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1735 SourceLocation DefaultLoc,
1736 SourceLocation RParenLoc,
1737 Expr *ControllingExpr,
1738 TypeSourceInfo **Types,
1740 unsigned NumAssocs) {
1741 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1742 ControllingExpr, Types, Exprs,
1746 /// \brief Build a new overloaded operator call expression.
1748 /// By default, performs semantic analysis to build the new expression.
1749 /// The semantic analysis provides the behavior of template instantiation,
1750 /// copying with transformations that turn what looks like an overloaded
1751 /// operator call into a use of a builtin operator, performing
1752 /// argument-dependent lookup, etc. Subclasses may override this routine to
1753 /// provide different behavior.
1754 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1755 SourceLocation OpLoc,
1760 /// \brief Build a new C++ "named" cast expression, such as static_cast or
1761 /// reinterpret_cast.
1763 /// By default, this routine dispatches to one of the more-specific routines
1764 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1765 /// Subclasses may override this routine to provide different behavior.
1766 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1767 Stmt::StmtClass Class,
1768 SourceLocation LAngleLoc,
1769 TypeSourceInfo *TInfo,
1770 SourceLocation RAngleLoc,
1771 SourceLocation LParenLoc,
1773 SourceLocation RParenLoc) {
1775 case Stmt::CXXStaticCastExprClass:
1776 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
1777 RAngleLoc, LParenLoc,
1778 SubExpr, RParenLoc);
1780 case Stmt::CXXDynamicCastExprClass:
1781 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
1782 RAngleLoc, LParenLoc,
1783 SubExpr, RParenLoc);
1785 case Stmt::CXXReinterpretCastExprClass:
1786 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
1787 RAngleLoc, LParenLoc,
1791 case Stmt::CXXConstCastExprClass:
1792 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
1793 RAngleLoc, LParenLoc,
1794 SubExpr, RParenLoc);
1797 llvm_unreachable("Invalid C++ named cast");
1801 /// \brief Build a new C++ static_cast expression.
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
1805 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1806 SourceLocation LAngleLoc,
1807 TypeSourceInfo *TInfo,
1808 SourceLocation RAngleLoc,
1809 SourceLocation LParenLoc,
1811 SourceLocation RParenLoc) {
1812 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1814 SourceRange(LAngleLoc, RAngleLoc),
1815 SourceRange(LParenLoc, RParenLoc));
1818 /// \brief Build a new C++ dynamic_cast expression.
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
1822 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1823 SourceLocation LAngleLoc,
1824 TypeSourceInfo *TInfo,
1825 SourceLocation RAngleLoc,
1826 SourceLocation LParenLoc,
1828 SourceLocation RParenLoc) {
1829 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1831 SourceRange(LAngleLoc, RAngleLoc),
1832 SourceRange(LParenLoc, RParenLoc));
1835 /// \brief Build a new C++ reinterpret_cast expression.
1837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
1839 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1840 SourceLocation LAngleLoc,
1841 TypeSourceInfo *TInfo,
1842 SourceLocation RAngleLoc,
1843 SourceLocation LParenLoc,
1845 SourceLocation RParenLoc) {
1846 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1848 SourceRange(LAngleLoc, RAngleLoc),
1849 SourceRange(LParenLoc, RParenLoc));
1852 /// \brief Build a new C++ const_cast expression.
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
1856 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1857 SourceLocation LAngleLoc,
1858 TypeSourceInfo *TInfo,
1859 SourceLocation RAngleLoc,
1860 SourceLocation LParenLoc,
1862 SourceLocation RParenLoc) {
1863 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1865 SourceRange(LAngleLoc, RAngleLoc),
1866 SourceRange(LParenLoc, RParenLoc));
1869 /// \brief Build a new C++ functional-style cast expression.
1871 /// By default, performs semantic analysis to build the new expression.
1872 /// Subclasses may override this routine to provide different behavior.
1873 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1874 SourceLocation LParenLoc,
1876 SourceLocation RParenLoc) {
1877 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1878 MultiExprArg(&Sub, 1),
1882 /// \brief Build a new C++ typeid(type) expression.
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
1886 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1887 SourceLocation TypeidLoc,
1888 TypeSourceInfo *Operand,
1889 SourceLocation RParenLoc) {
1890 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1895 /// \brief Build a new C++ typeid(expr) expression.
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
1899 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1900 SourceLocation TypeidLoc,
1902 SourceLocation RParenLoc) {
1903 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1907 /// \brief Build a new C++ __uuidof(type) expression.
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
1911 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1912 SourceLocation TypeidLoc,
1913 TypeSourceInfo *Operand,
1914 SourceLocation RParenLoc) {
1915 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1919 /// \brief Build a new C++ __uuidof(expr) expression.
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
1923 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1924 SourceLocation TypeidLoc,
1926 SourceLocation RParenLoc) {
1927 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1931 /// \brief Build a new C++ "this" expression.
1933 /// By default, builds a new "this" expression without performing any
1934 /// semantic analysis. Subclasses may override this routine to provide
1935 /// different behavior.
1936 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1939 getSema().CheckCXXThisCapture(ThisLoc);
1940 return getSema().Owned(
1941 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1945 /// \brief Build a new C++ throw expression.
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
1949 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1950 bool IsThrownVariableInScope) {
1951 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
1954 /// \brief Build a new C++ default-argument expression.
1956 /// By default, builds a new default-argument expression, which does not
1957 /// require any semantic analysis. Subclasses may override this routine to
1958 /// provide different behavior.
1959 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1960 ParmVarDecl *Param) {
1961 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1965 /// \brief Build a new C++ zero-initialization expression.
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
1969 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1970 SourceLocation LParenLoc,
1971 SourceLocation RParenLoc) {
1972 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
1973 MultiExprArg(getSema(), 0, 0),
1977 /// \brief Build a new C++ "new" expression.
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
1981 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
1983 SourceLocation PlacementLParen,
1984 MultiExprArg PlacementArgs,
1985 SourceLocation PlacementRParen,
1986 SourceRange TypeIdParens,
1987 QualType AllocatedType,
1988 TypeSourceInfo *AllocatedTypeInfo,
1990 SourceRange DirectInitRange,
1991 Expr *Initializer) {
1992 return getSema().BuildCXXNew(StartLoc, UseGlobal,
1994 move(PlacementArgs),
2004 /// \brief Build a new C++ "delete" expression.
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
2008 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2009 bool IsGlobalDelete,
2012 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2016 /// \brief Build a new unary type trait expression.
2018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
2020 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
2021 SourceLocation StartLoc,
2023 SourceLocation RParenLoc) {
2024 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
2027 /// \brief Build a new binary type trait expression.
2029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
2031 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2032 SourceLocation StartLoc,
2033 TypeSourceInfo *LhsT,
2034 TypeSourceInfo *RhsT,
2035 SourceLocation RParenLoc) {
2036 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2039 /// \brief Build a new type trait expression.
2041 /// By default, performs semantic analysis to build the new expression.
2042 /// Subclasses may override this routine to provide different behavior.
2043 ExprResult RebuildTypeTrait(TypeTrait Trait,
2044 SourceLocation StartLoc,
2045 ArrayRef<TypeSourceInfo *> Args,
2046 SourceLocation RParenLoc) {
2047 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2050 /// \brief Build a new array type trait expression.
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
2054 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2055 SourceLocation StartLoc,
2056 TypeSourceInfo *TSInfo,
2058 SourceLocation RParenLoc) {
2059 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2062 /// \brief Build a new expression trait expression.
2064 /// By default, performs semantic analysis to build the new expression.
2065 /// Subclasses may override this routine to provide different behavior.
2066 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2067 SourceLocation StartLoc,
2069 SourceLocation RParenLoc) {
2070 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2073 /// \brief Build a new (previously unresolved) declaration reference
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
2078 ExprResult RebuildDependentScopeDeclRefExpr(
2079 NestedNameSpecifierLoc QualifierLoc,
2080 SourceLocation TemplateKWLoc,
2081 const DeclarationNameInfo &NameInfo,
2082 const TemplateArgumentListInfo *TemplateArgs) {
2084 SS.Adopt(QualifierLoc);
2086 if (TemplateArgs || TemplateKWLoc.isValid())
2087 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
2088 NameInfo, TemplateArgs);
2090 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
2093 /// \brief Build a new template-id expression.
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
2097 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2098 SourceLocation TemplateKWLoc,
2101 const TemplateArgumentListInfo *TemplateArgs) {
2102 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2106 /// \brief Build a new object-construction expression.
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
2110 ExprResult RebuildCXXConstructExpr(QualType T,
2112 CXXConstructorDecl *Constructor,
2115 bool HadMultipleCandidates,
2116 bool RequiresZeroInit,
2117 CXXConstructExpr::ConstructionKind ConstructKind,
2118 SourceRange ParenRange) {
2119 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
2120 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
2124 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
2125 move_arg(ConvertedArgs),
2126 HadMultipleCandidates,
2127 RequiresZeroInit, ConstructKind,
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 RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2136 SourceLocation LParenLoc,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2145 /// \brief Build a new object-construction expression.
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
2149 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2150 SourceLocation LParenLoc,
2152 SourceLocation RParenLoc) {
2153 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2159 /// \brief Build a new member reference expression.
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
2163 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2166 SourceLocation OperatorLoc,
2167 NestedNameSpecifierLoc QualifierLoc,
2168 SourceLocation TemplateKWLoc,
2169 NamedDecl *FirstQualifierInScope,
2170 const DeclarationNameInfo &MemberNameInfo,
2171 const TemplateArgumentListInfo *TemplateArgs) {
2173 SS.Adopt(QualifierLoc);
2175 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2176 OperatorLoc, IsArrow,
2178 FirstQualifierInScope,
2183 /// \brief Build a new member reference expression.
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
2187 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2188 SourceLocation OperatorLoc,
2190 NestedNameSpecifierLoc QualifierLoc,
2191 SourceLocation TemplateKWLoc,
2192 NamedDecl *FirstQualifierInScope,
2194 const TemplateArgumentListInfo *TemplateArgs) {
2196 SS.Adopt(QualifierLoc);
2198 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2199 OperatorLoc, IsArrow,
2201 FirstQualifierInScope,
2205 /// \brief Build a new noexcept expression.
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
2209 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2210 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2213 /// \brief Build a new expression to compute the length of a parameter pack.
2214 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2215 SourceLocation PackLoc,
2216 SourceLocation RParenLoc,
2217 llvm::Optional<unsigned> Length) {
2219 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2220 OperatorLoc, Pack, PackLoc,
2221 RParenLoc, *Length);
2223 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2224 OperatorLoc, Pack, PackLoc,
2228 /// \brief Build a new Objective-C array literal.
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
2232 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2233 Expr **Elements, unsigned NumElements) {
2234 return getSema().BuildObjCArrayLiteral(Range,
2235 MultiExprArg(Elements, NumElements));
2238 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2239 Expr *Base, Expr *Key,
2240 ObjCMethodDecl *getterMethod,
2241 ObjCMethodDecl *setterMethod) {
2242 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2243 getterMethod, setterMethod);
2246 /// \brief Build a new Objective-C dictionary literal.
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2251 ObjCDictionaryElement *Elements,
2252 unsigned NumElements) {
2253 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2256 /// \brief Build a new Objective-C @encode expression.
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
2260 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2261 TypeSourceInfo *EncodeTypeInfo,
2262 SourceLocation RParenLoc) {
2263 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2267 /// \brief Build a new Objective-C class message.
2268 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2270 ArrayRef<SourceLocation> SelectorLocs,
2271 ObjCMethodDecl *Method,
2272 SourceLocation LBracLoc,
2274 SourceLocation RBracLoc) {
2275 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2276 ReceiverTypeInfo->getType(),
2277 /*SuperLoc=*/SourceLocation(),
2278 Sel, Method, LBracLoc, SelectorLocs,
2279 RBracLoc, move(Args));
2282 /// \brief Build a new Objective-C instance message.
2283 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2285 ArrayRef<SourceLocation> SelectorLocs,
2286 ObjCMethodDecl *Method,
2287 SourceLocation LBracLoc,
2289 SourceLocation RBracLoc) {
2290 return SemaRef.BuildInstanceMessage(Receiver,
2291 Receiver->getType(),
2292 /*SuperLoc=*/SourceLocation(),
2293 Sel, Method, LBracLoc, SelectorLocs,
2294 RBracLoc, move(Args));
2297 /// \brief Build a new Objective-C ivar reference expression.
2299 /// By default, performs semantic analysis to build the new expression.
2300 /// Subclasses may override this routine to provide different behavior.
2301 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2302 SourceLocation IvarLoc,
2303 bool IsArrow, bool IsFreeIvar) {
2304 // FIXME: We lose track of the IsFreeIvar bit.
2306 ExprResult Base = getSema().Owned(BaseArg);
2307 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2308 Sema::LookupMemberName);
2309 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2313 if (Result.isInvalid() || Base.isInvalid())
2317 return move(Result);
2319 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2320 /*FIXME:*/IvarLoc, IsArrow,
2321 SS, SourceLocation(),
2322 /*FirstQualifierInScope=*/0,
2324 /*TemplateArgs=*/0);
2327 /// \brief Build a new Objective-C property reference expression.
2329 /// By default, performs semantic analysis to build the new expression.
2330 /// Subclasses may override this routine to provide different behavior.
2331 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2332 ObjCPropertyDecl *Property,
2333 SourceLocation PropertyLoc) {
2335 ExprResult Base = getSema().Owned(BaseArg);
2336 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2337 Sema::LookupMemberName);
2338 bool IsArrow = false;
2339 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2340 /*FIME:*/PropertyLoc,
2342 if (Result.isInvalid() || Base.isInvalid())
2346 return move(Result);
2348 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2349 /*FIXME:*/PropertyLoc, IsArrow,
2350 SS, SourceLocation(),
2351 /*FirstQualifierInScope=*/0,
2353 /*TemplateArgs=*/0);
2356 /// \brief Build a new Objective-C property reference expression.
2358 /// By default, performs semantic analysis to build the new expression.
2359 /// Subclasses may override this routine to provide different behavior.
2360 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2361 ObjCMethodDecl *Getter,
2362 ObjCMethodDecl *Setter,
2363 SourceLocation PropertyLoc) {
2364 // Since these expressions can only be value-dependent, we do not
2365 // need to perform semantic analysis again.
2367 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2368 VK_LValue, OK_ObjCProperty,
2369 PropertyLoc, Base));
2372 /// \brief Build a new Objective-C "isa" expression.
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
2376 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2379 ExprResult Base = getSema().Owned(BaseArg);
2380 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2381 Sema::LookupMemberName);
2382 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2385 if (Result.isInvalid() || Base.isInvalid())
2389 return move(Result);
2391 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2392 /*FIXME:*/IsaLoc, IsArrow,
2393 SS, SourceLocation(),
2394 /*FirstQualifierInScope=*/0,
2396 /*TemplateArgs=*/0);
2399 /// \brief Build a new shuffle vector expression.
2401 /// By default, performs semantic analysis to build the new expression.
2402 /// Subclasses may override this routine to provide different behavior.
2403 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2404 MultiExprArg SubExprs,
2405 SourceLocation RParenLoc) {
2406 // Find the declaration for __builtin_shufflevector
2407 const IdentifierInfo &Name
2408 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2409 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2410 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2411 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
2413 // Build a reference to the __builtin_shufflevector builtin
2414 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
2416 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2418 VK_LValue, BuiltinLoc));
2419 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2420 if (Callee.isInvalid())
2423 // Build the CallExpr
2424 unsigned NumSubExprs = SubExprs.size();
2425 Expr **Subs = (Expr **)SubExprs.release();
2426 ExprResult TheCall = SemaRef.Owned(
2427 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
2429 Builtin->getCallResultType(),
2430 Expr::getValueKindForType(Builtin->getResultType()),
2433 // Type-check the __builtin_shufflevector expression.
2434 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
2437 /// \brief Build a new template argument pack expansion.
2439 /// By default, performs semantic analysis to build a new pack expansion
2440 /// for a template argument. Subclasses may override this routine to provide
2441 /// different behavior.
2442 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2443 SourceLocation EllipsisLoc,
2444 llvm::Optional<unsigned> NumExpansions) {
2445 switch (Pattern.getArgument().getKind()) {
2446 case TemplateArgument::Expression: {
2448 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2449 EllipsisLoc, NumExpansions);
2450 if (Result.isInvalid())
2451 return TemplateArgumentLoc();
2453 return TemplateArgumentLoc(Result.get(), Result.get());
2456 case TemplateArgument::Template:
2457 return TemplateArgumentLoc(TemplateArgument(
2458 Pattern.getArgument().getAsTemplate(),
2460 Pattern.getTemplateQualifierLoc(),
2461 Pattern.getTemplateNameLoc(),
2464 case TemplateArgument::Null:
2465 case TemplateArgument::Integral:
2466 case TemplateArgument::Declaration:
2467 case TemplateArgument::Pack:
2468 case TemplateArgument::TemplateExpansion:
2469 llvm_unreachable("Pack expansion pattern has no parameter packs");
2471 case TemplateArgument::Type:
2472 if (TypeSourceInfo *Expansion
2473 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2476 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2481 return TemplateArgumentLoc();
2484 /// \brief Build a new expression pack expansion.
2486 /// By default, performs semantic analysis to build a new pack expansion
2487 /// for an expression. Subclasses may override this routine to provide
2488 /// different behavior.
2489 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2490 llvm::Optional<unsigned> NumExpansions) {
2491 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2494 /// \brief Build a new atomic operation expression.
2496 /// By default, performs semantic analysis to build the new expression.
2497 /// Subclasses may override this routine to provide different behavior.
2498 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2499 MultiExprArg SubExprs,
2501 AtomicExpr::AtomicOp Op,
2502 SourceLocation RParenLoc) {
2503 // Just create the expression; there is not any interesting semantic
2504 // analysis here because we can't actually build an AtomicExpr until
2505 // we are sure it is semantically sound.
2506 unsigned NumSubExprs = SubExprs.size();
2507 Expr **Subs = (Expr **)SubExprs.release();
2508 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2509 NumSubExprs, RetTy, Op,
2514 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2515 QualType ObjectType,
2516 NamedDecl *FirstQualifierInScope,
2519 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2520 QualType ObjectType,
2521 NamedDecl *FirstQualifierInScope,
2525 template<typename Derived>
2526 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
2528 return SemaRef.Owned(S);
2530 switch (S->getStmtClass()) {
2531 case Stmt::NoStmtClass: break;
2533 // Transform individual statement nodes
2534 #define STMT(Node, Parent) \
2535 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2536 #define ABSTRACT_STMT(Node)
2537 #define EXPR(Node, Parent)
2538 #include "clang/AST/StmtNodes.inc"
2540 // Transform expressions by calling TransformExpr.
2541 #define STMT(Node, Parent)
2542 #define ABSTRACT_STMT(Stmt)
2543 #define EXPR(Node, Parent) case Stmt::Node##Class:
2544 #include "clang/AST/StmtNodes.inc"
2546 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
2550 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
2554 return SemaRef.Owned(S);
2558 template<typename Derived>
2559 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2561 return SemaRef.Owned(E);
2563 switch (E->getStmtClass()) {
2564 case Stmt::NoStmtClass: break;
2565 #define STMT(Node, Parent) case Stmt::Node##Class: break;
2566 #define ABSTRACT_STMT(Stmt)
2567 #define EXPR(Node, Parent) \
2568 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
2569 #include "clang/AST/StmtNodes.inc"
2572 return SemaRef.Owned(E);
2575 template<typename Derived>
2576 bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2579 SmallVectorImpl<Expr *> &Outputs,
2581 for (unsigned I = 0; I != NumInputs; ++I) {
2582 // If requested, drop call arguments that need to be dropped.
2583 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2590 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2591 Expr *Pattern = Expansion->getPattern();
2593 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2594 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2595 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2597 // Determine whether the set of unexpanded parameter packs can and should
2600 bool RetainExpansion = false;
2601 llvm::Optional<unsigned> OrigNumExpansions
2602 = Expansion->getNumExpansions();
2603 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
2604 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2605 Pattern->getSourceRange(),
2607 Expand, RetainExpansion,
2612 // The transform has determined that we should perform a simple
2613 // transformation on the pack expansion, producing another pack
2615 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2616 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2617 if (OutPattern.isInvalid())
2620 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2621 Expansion->getEllipsisLoc(),
2623 if (Out.isInvalid())
2628 Outputs.push_back(Out.get());
2632 // Record right away that the argument was changed. This needs
2633 // to happen even if the array expands to nothing.
2634 if (ArgChanged) *ArgChanged = true;
2636 // The transform has determined that we should perform an elementwise
2637 // expansion of the pattern. Do so.
2638 for (unsigned I = 0; I != *NumExpansions; ++I) {
2639 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2640 ExprResult Out = getDerived().TransformExpr(Pattern);
2641 if (Out.isInvalid())
2644 if (Out.get()->containsUnexpandedParameterPack()) {
2645 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2647 if (Out.isInvalid())
2651 Outputs.push_back(Out.get());
2657 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2658 if (Result.isInvalid())
2661 if (Result.get() != Inputs[I] && ArgChanged)
2664 Outputs.push_back(Result.get());
2670 template<typename Derived>
2671 NestedNameSpecifierLoc
2672 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2673 NestedNameSpecifierLoc NNS,
2674 QualType ObjectType,
2675 NamedDecl *FirstQualifierInScope) {
2676 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2677 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2678 Qualifier = Qualifier.getPrefix())
2679 Qualifiers.push_back(Qualifier);
2682 while (!Qualifiers.empty()) {
2683 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2684 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2686 switch (QNNS->getKind()) {
2687 case NestedNameSpecifier::Identifier:
2688 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2689 *QNNS->getAsIdentifier(),
2690 Q.getLocalBeginLoc(),
2692 ObjectType, false, SS,
2693 FirstQualifierInScope, false))
2694 return NestedNameSpecifierLoc();
2698 case NestedNameSpecifier::Namespace: {
2700 = cast_or_null<NamespaceDecl>(
2701 getDerived().TransformDecl(
2702 Q.getLocalBeginLoc(),
2703 QNNS->getAsNamespace()));
2704 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2708 case NestedNameSpecifier::NamespaceAlias: {
2709 NamespaceAliasDecl *Alias
2710 = cast_or_null<NamespaceAliasDecl>(
2711 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2712 QNNS->getAsNamespaceAlias()));
2713 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2714 Q.getLocalEndLoc());
2718 case NestedNameSpecifier::Global:
2719 // There is no meaningful transformation that one could perform on the
2721 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2724 case NestedNameSpecifier::TypeSpecWithTemplate:
2725 case NestedNameSpecifier::TypeSpec: {
2726 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2727 FirstQualifierInScope, SS);
2730 return NestedNameSpecifierLoc();
2732 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2733 (SemaRef.getLangOpts().CPlusPlus0x &&
2734 TL.getType()->isEnumeralType())) {
2735 assert(!TL.getType().hasLocalQualifiers() &&
2736 "Can't get cv-qualifiers here");
2737 if (TL.getType()->isEnumeralType())
2738 SemaRef.Diag(TL.getBeginLoc(),
2739 diag::warn_cxx98_compat_enum_nested_name_spec);
2740 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2741 Q.getLocalEndLoc());
2744 // If the nested-name-specifier is an invalid type def, don't emit an
2745 // error because a previous error should have already been emitted.
2746 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2747 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2748 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2749 << TL.getType() << SS.getRange();
2751 return NestedNameSpecifierLoc();
2755 // The qualifier-in-scope and object type only apply to the leftmost entity.
2756 FirstQualifierInScope = 0;
2757 ObjectType = QualType();
2760 // Don't rebuild the nested-name-specifier if we don't have to.
2761 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2762 !getDerived().AlwaysRebuild())
2765 // If we can re-use the source-location data from the original
2766 // nested-name-specifier, do so.
2767 if (SS.location_size() == NNS.getDataLength() &&
2768 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2769 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2771 // Allocate new nested-name-specifier location information.
2772 return SS.getWithLocInContext(SemaRef.Context);
2775 template<typename Derived>
2777 TreeTransform<Derived>
2778 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
2779 DeclarationName Name = NameInfo.getName();
2781 return DeclarationNameInfo();
2783 switch (Name.getNameKind()) {
2784 case DeclarationName::Identifier:
2785 case DeclarationName::ObjCZeroArgSelector:
2786 case DeclarationName::ObjCOneArgSelector:
2787 case DeclarationName::ObjCMultiArgSelector:
2788 case DeclarationName::CXXOperatorName:
2789 case DeclarationName::CXXLiteralOperatorName:
2790 case DeclarationName::CXXUsingDirective:
2793 case DeclarationName::CXXConstructorName:
2794 case DeclarationName::CXXDestructorName:
2795 case DeclarationName::CXXConversionFunctionName: {
2796 TypeSourceInfo *NewTInfo;
2797 CanQualType NewCanTy;
2798 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2799 NewTInfo = getDerived().TransformType(OldTInfo);
2801 return DeclarationNameInfo();
2802 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2806 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2807 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
2809 return DeclarationNameInfo();
2810 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2813 DeclarationName NewName
2814 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2816 DeclarationNameInfo NewNameInfo(NameInfo);
2817 NewNameInfo.setName(NewName);
2818 NewNameInfo.setNamedTypeInfo(NewTInfo);
2823 llvm_unreachable("Unknown name kind.");
2826 template<typename Derived>
2828 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2830 SourceLocation NameLoc,
2831 QualType ObjectType,
2832 NamedDecl *FirstQualifierInScope) {
2833 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2834 TemplateDecl *Template = QTN->getTemplateDecl();
2835 assert(Template && "qualified template name must refer to a template");
2837 TemplateDecl *TransTemplate
2838 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2841 return TemplateName();
2843 if (!getDerived().AlwaysRebuild() &&
2844 SS.getScopeRep() == QTN->getQualifier() &&
2845 TransTemplate == Template)
2848 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2852 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2853 if (SS.getScopeRep()) {
2854 // These apply to the scope specifier, not the template.
2855 ObjectType = QualType();
2856 FirstQualifierInScope = 0;
2859 if (!getDerived().AlwaysRebuild() &&
2860 SS.getScopeRep() == DTN->getQualifier() &&
2861 ObjectType.isNull())
2864 if (DTN->isIdentifier()) {
2865 return getDerived().RebuildTemplateName(SS,
2866 *DTN->getIdentifier(),
2869 FirstQualifierInScope);
2872 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2876 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2877 TemplateDecl *TransTemplate
2878 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2881 return TemplateName();
2883 if (!getDerived().AlwaysRebuild() &&
2884 TransTemplate == Template)
2887 return TemplateName(TransTemplate);
2890 if (SubstTemplateTemplateParmPackStorage *SubstPack
2891 = Name.getAsSubstTemplateTemplateParmPack()) {
2892 TemplateTemplateParmDecl *TransParam
2893 = cast_or_null<TemplateTemplateParmDecl>(
2894 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2896 return TemplateName();
2898 if (!getDerived().AlwaysRebuild() &&
2899 TransParam == SubstPack->getParameterPack())
2902 return getDerived().RebuildTemplateName(TransParam,
2903 SubstPack->getArgumentPack());
2906 // These should be getting filtered out before they reach the AST.
2907 llvm_unreachable("overloaded function decl survived to here");
2910 template<typename Derived>
2911 void TreeTransform<Derived>::InventTemplateArgumentLoc(
2912 const TemplateArgument &Arg,
2913 TemplateArgumentLoc &Output) {
2914 SourceLocation Loc = getDerived().getBaseLocation();
2915 switch (Arg.getKind()) {
2916 case TemplateArgument::Null:
2917 llvm_unreachable("null template argument in TreeTransform");
2920 case TemplateArgument::Type:
2921 Output = TemplateArgumentLoc(Arg,
2922 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2926 case TemplateArgument::Template:
2927 case TemplateArgument::TemplateExpansion: {
2928 NestedNameSpecifierLocBuilder Builder;
2929 TemplateName Template = Arg.getAsTemplate();
2930 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2931 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2932 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2933 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2935 if (Arg.getKind() == TemplateArgument::Template)
2936 Output = TemplateArgumentLoc(Arg,
2937 Builder.getWithLocInContext(SemaRef.Context),
2940 Output = TemplateArgumentLoc(Arg,
2941 Builder.getWithLocInContext(SemaRef.Context),
2947 case TemplateArgument::Expression:
2948 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2951 case TemplateArgument::Declaration:
2952 case TemplateArgument::Integral:
2953 case TemplateArgument::Pack:
2954 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2959 template<typename Derived>
2960 bool TreeTransform<Derived>::TransformTemplateArgument(
2961 const TemplateArgumentLoc &Input,
2962 TemplateArgumentLoc &Output) {
2963 const TemplateArgument &Arg = Input.getArgument();
2964 switch (Arg.getKind()) {
2965 case TemplateArgument::Null:
2966 case TemplateArgument::Integral:
2970 case TemplateArgument::Type: {
2971 TypeSourceInfo *DI = Input.getTypeSourceInfo();
2973 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2975 DI = getDerived().TransformType(DI);
2976 if (!DI) return true;
2978 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2982 case TemplateArgument::Declaration: {
2983 // FIXME: we should never have to transform one of these.
2984 DeclarationName Name;
2985 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2986 Name = ND->getDeclName();
2987 TemporaryBase Rebase(*this, Input.getLocation(), Name);
2988 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2989 if (!D) return true;
2991 Expr *SourceExpr = Input.getSourceDeclExpression();
2993 EnterExpressionEvaluationContext Unevaluated(getSema(),
2994 Sema::ConstantEvaluated);
2995 ExprResult E = getDerived().TransformExpr(SourceExpr);
2996 E = SemaRef.ActOnConstantExpression(E);
2997 SourceExpr = (E.isInvalid() ? 0 : E.take());
3000 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
3004 case TemplateArgument::Template: {
3005 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3007 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3013 SS.Adopt(QualifierLoc);
3014 TemplateName Template
3015 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3016 Input.getTemplateNameLoc());
3017 if (Template.isNull())
3020 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3021 Input.getTemplateNameLoc());
3025 case TemplateArgument::TemplateExpansion:
3026 llvm_unreachable("Caller should expand pack expansions");
3028 case TemplateArgument::Expression: {
3029 // Template argument expressions are constant expressions.
3030 EnterExpressionEvaluationContext Unevaluated(getSema(),
3031 Sema::ConstantEvaluated);
3033 Expr *InputExpr = Input.getSourceExpression();
3034 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3036 ExprResult E = getDerived().TransformExpr(InputExpr);
3037 E = SemaRef.ActOnConstantExpression(E);
3038 if (E.isInvalid()) return true;
3039 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
3043 case TemplateArgument::Pack: {
3044 SmallVector<TemplateArgument, 4> TransformedArgs;
3045 TransformedArgs.reserve(Arg.pack_size());
3046 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
3047 AEnd = Arg.pack_end();
3050 // FIXME: preserve source information here when we start
3051 // caring about parameter packs.
3053 TemplateArgumentLoc InputArg;
3054 TemplateArgumentLoc OutputArg;
3055 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3056 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
3059 TransformedArgs.push_back(OutputArg.getArgument());
3062 TemplateArgument *TransformedArgsPtr
3063 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3064 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3065 TransformedArgsPtr);
3066 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3067 TransformedArgs.size()),
3068 Input.getLocInfo());
3073 // Work around bogus GCC warning
3077 /// \brief Iterator adaptor that invents template argument location information
3078 /// for each of the template arguments in its underlying iterator.
3079 template<typename Derived, typename InputIterator>
3080 class TemplateArgumentLocInventIterator {
3081 TreeTransform<Derived> &Self;
3085 typedef TemplateArgumentLoc value_type;
3086 typedef TemplateArgumentLoc reference;
3087 typedef typename std::iterator_traits<InputIterator>::difference_type
3089 typedef std::input_iterator_tag iterator_category;
3092 TemplateArgumentLoc Arg;
3095 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3097 const TemplateArgumentLoc *operator->() const { return &Arg; }
3100 TemplateArgumentLocInventIterator() { }
3102 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3104 : Self(Self), Iter(Iter) { }
3106 TemplateArgumentLocInventIterator &operator++() {
3111 TemplateArgumentLocInventIterator operator++(int) {
3112 TemplateArgumentLocInventIterator Old(*this);
3117 reference operator*() const {
3118 TemplateArgumentLoc Result;
3119 Self.InventTemplateArgumentLoc(*Iter, Result);
3123 pointer operator->() const { return pointer(**this); }
3125 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3126 const TemplateArgumentLocInventIterator &Y) {
3127 return X.Iter == Y.Iter;
3130 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3131 const TemplateArgumentLocInventIterator &Y) {
3132 return X.Iter != Y.Iter;
3136 template<typename Derived>
3137 template<typename InputIterator>
3138 bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3140 TemplateArgumentListInfo &Outputs) {
3141 for (; First != Last; ++First) {
3142 TemplateArgumentLoc Out;
3143 TemplateArgumentLoc In = *First;
3145 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3146 // Unpack argument packs, which we translate them into separate
3148 // FIXME: We could do much better if we could guarantee that the
3149 // TemplateArgumentLocInfo for the pack expansion would be usable for
3150 // all of the template arguments in the argument pack.
3151 typedef TemplateArgumentLocInventIterator<Derived,
3152 TemplateArgument::pack_iterator>
3154 if (TransformTemplateArguments(PackLocIterator(*this,
3155 In.getArgument().pack_begin()),
3156 PackLocIterator(*this,
3157 In.getArgument().pack_end()),
3164 if (In.getArgument().isPackExpansion()) {
3165 // We have a pack expansion, for which we will be substituting into
3167 SourceLocation Ellipsis;
3168 llvm::Optional<unsigned> OrigNumExpansions;
3169 TemplateArgumentLoc Pattern
3170 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3173 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3174 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3175 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3177 // Determine whether the set of unexpanded parameter packs can and should
3180 bool RetainExpansion = false;
3181 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
3182 if (getDerived().TryExpandParameterPacks(Ellipsis,
3183 Pattern.getSourceRange(),
3191 // The transform has determined that we should perform a simple
3192 // transformation on the pack expansion, producing another pack
3194 TemplateArgumentLoc OutPattern;
3195 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3196 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3199 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3201 if (Out.getArgument().isNull())
3204 Outputs.addArgument(Out);
3208 // The transform has determined that we should perform an elementwise
3209 // expansion of the pattern. Do so.
3210 for (unsigned I = 0; I != *NumExpansions; ++I) {
3211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3213 if (getDerived().TransformTemplateArgument(Pattern, Out))
3216 if (Out.getArgument().containsUnexpandedParameterPack()) {
3217 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3219 if (Out.getArgument().isNull())
3223 Outputs.addArgument(Out);
3226 // If we're supposed to retain a pack expansion, do so by temporarily
3227 // forgetting the partially-substituted parameter pack.
3228 if (RetainExpansion) {
3229 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3231 if (getDerived().TransformTemplateArgument(Pattern, Out))
3234 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3236 if (Out.getArgument().isNull())
3239 Outputs.addArgument(Out);
3246 if (getDerived().TransformTemplateArgument(In, Out))
3249 Outputs.addArgument(Out);
3256 //===----------------------------------------------------------------------===//
3257 // Type transformation
3258 //===----------------------------------------------------------------------===//
3260 template<typename Derived>
3261 QualType TreeTransform<Derived>::TransformType(QualType T) {
3262 if (getDerived().AlreadyTransformed(T))
3265 // Temporary workaround. All of these transformations should
3266 // eventually turn into transformations on TypeLocs.
3267 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3268 getDerived().getBaseLocation());
3270 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3275 return NewDI->getType();
3278 template<typename Derived>
3279 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3280 // Refine the base location to the type's location.
3281 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3282 getDerived().getBaseEntity());
3283 if (getDerived().AlreadyTransformed(DI->getType()))
3288 TypeLoc TL = DI->getTypeLoc();
3289 TLB.reserve(TL.getFullDataSize());
3291 QualType Result = getDerived().TransformType(TLB, TL);
3292 if (Result.isNull())
3295 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3298 template<typename Derived>
3300 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3301 switch (T.getTypeLocClass()) {
3302 #define ABSTRACT_TYPELOC(CLASS, PARENT)
3303 #define TYPELOC(CLASS, PARENT) \
3304 case TypeLoc::CLASS: \
3305 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3306 #include "clang/AST/TypeLocNodes.def"
3309 llvm_unreachable("unhandled type loc!");
3312 /// FIXME: By default, this routine adds type qualifiers only to types
3313 /// that can have qualifiers, and silently suppresses those qualifiers
3314 /// that are not permitted (e.g., qualifiers on reference or function
3315 /// types). This is the right thing for template instantiation, but
3316 /// probably not for other clients.
3317 template<typename Derived>
3319 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
3320 QualifiedTypeLoc T) {
3321 Qualifiers Quals = T.getType().getLocalQualifiers();
3323 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3324 if (Result.isNull())
3327 // Silently suppress qualifiers if the result type can't be qualified.
3328 // FIXME: this is the right thing for template instantiation, but
3329 // probably not for other clients.
3330 if (Result->isFunctionType() || Result->isReferenceType())
3333 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3335 if (Quals.hasObjCLifetime()) {
3336 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3337 Quals.removeObjCLifetime();
3338 else if (Result.getObjCLifetime()) {
3340 // A lifetime qualifier applied to a substituted template parameter
3341 // overrides the lifetime qualifier from the template argument.
3342 if (const SubstTemplateTypeParmType *SubstTypeParam
3343 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3344 QualType Replacement = SubstTypeParam->getReplacementType();
3345 Qualifiers Qs = Replacement.getQualifiers();
3346 Qs.removeObjCLifetime();
3348 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3350 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3351 SubstTypeParam->getReplacedParameter(),
3353 TLB.TypeWasModifiedSafely(Result);
3355 // Otherwise, complain about the addition of a qualifier to an
3356 // already-qualified type.
3357 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
3358 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
3361 Quals.removeObjCLifetime();
3365 if (!Quals.empty()) {
3366 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3367 TLB.push<QualifiedTypeLoc>(Result);
3368 // No location information to preserve.
3374 template<typename Derived>
3376 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3377 QualType ObjectType,
3378 NamedDecl *UnqualLookup,
3380 QualType T = TL.getType();
3381 if (getDerived().AlreadyTransformed(T))
3387 if (isa<TemplateSpecializationType>(T)) {
3388 TemplateSpecializationTypeLoc SpecTL
3389 = cast<TemplateSpecializationTypeLoc>(TL);
3391 TemplateName Template =
3392 getDerived().TransformTemplateName(SS,
3393 SpecTL.getTypePtr()->getTemplateName(),
3394 SpecTL.getTemplateNameLoc(),
3395 ObjectType, UnqualLookup);
3396 if (Template.isNull())
3399 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3401 } else if (isa<DependentTemplateSpecializationType>(T)) {
3402 DependentTemplateSpecializationTypeLoc SpecTL
3403 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3405 TemplateName Template
3406 = getDerived().RebuildTemplateName(SS,
3407 *SpecTL.getTypePtr()->getIdentifier(),
3408 SpecTL.getTemplateNameLoc(),
3409 ObjectType, UnqualLookup);
3410 if (Template.isNull())
3413 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3418 // Nothing special needs to be done for these.
3419 Result = getDerived().TransformType(TLB, TL);
3422 if (Result.isNull())
3425 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3428 template<typename Derived>
3430 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3431 QualType ObjectType,
3432 NamedDecl *UnqualLookup,
3434 // FIXME: Painfully copy-paste from the above!
3436 QualType T = TSInfo->getType();
3437 if (getDerived().AlreadyTransformed(T))
3443 TypeLoc TL = TSInfo->getTypeLoc();
3444 if (isa<TemplateSpecializationType>(T)) {
3445 TemplateSpecializationTypeLoc SpecTL
3446 = cast<TemplateSpecializationTypeLoc>(TL);
3448 TemplateName Template
3449 = getDerived().TransformTemplateName(SS,
3450 SpecTL.getTypePtr()->getTemplateName(),
3451 SpecTL.getTemplateNameLoc(),
3452 ObjectType, UnqualLookup);
3453 if (Template.isNull())
3456 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3458 } else if (isa<DependentTemplateSpecializationType>(T)) {
3459 DependentTemplateSpecializationTypeLoc SpecTL
3460 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3462 TemplateName Template
3463 = getDerived().RebuildTemplateName(SS,
3464 *SpecTL.getTypePtr()->getIdentifier(),
3465 SpecTL.getTemplateNameLoc(),
3466 ObjectType, UnqualLookup);
3467 if (Template.isNull())
3470 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3475 // Nothing special needs to be done for these.
3476 Result = getDerived().TransformType(TLB, TL);
3479 if (Result.isNull())
3482 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3485 template <class TyLoc> static inline
3486 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3487 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3488 NewT.setNameLoc(T.getNameLoc());
3492 template<typename Derived>
3493 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
3495 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3496 NewT.setBuiltinLoc(T.getBuiltinLoc());
3497 if (T.needsExtraLocalData())
3498 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3502 template<typename Derived>
3503 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
3506 return TransformTypeSpecType(TLB, T);
3509 template<typename Derived>
3510 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
3511 PointerTypeLoc TL) {
3512 QualType PointeeType
3513 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3514 if (PointeeType.isNull())
3517 QualType Result = TL.getType();
3518 if (PointeeType->getAs<ObjCObjectType>()) {
3519 // A dependent pointer type 'T *' has is being transformed such
3520 // that an Objective-C class type is being replaced for 'T'. The
3521 // resulting pointer type is an ObjCObjectPointerType, not a
3523 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3525 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3526 NewT.setStarLoc(TL.getStarLoc());
3530 if (getDerived().AlwaysRebuild() ||
3531 PointeeType != TL.getPointeeLoc().getType()) {
3532 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3533 if (Result.isNull())
3537 // Objective-C ARC can add lifetime qualifiers to the type that we're
3539 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3541 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3542 NewT.setSigilLoc(TL.getSigilLoc());
3546 template<typename Derived>
3548 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
3549 BlockPointerTypeLoc TL) {
3550 QualType PointeeType
3551 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3552 if (PointeeType.isNull())
3555 QualType Result = TL.getType();
3556 if (getDerived().AlwaysRebuild() ||
3557 PointeeType != TL.getPointeeLoc().getType()) {
3558 Result = getDerived().RebuildBlockPointerType(PointeeType,
3560 if (Result.isNull())
3564 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3565 NewT.setSigilLoc(TL.getSigilLoc());
3569 /// Transforms a reference type. Note that somewhat paradoxically we
3570 /// don't care whether the type itself is an l-value type or an r-value
3571 /// type; we only care if the type was *written* as an l-value type
3572 /// or an r-value type.
3573 template<typename Derived>
3575 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
3576 ReferenceTypeLoc TL) {
3577 const ReferenceType *T = TL.getTypePtr();
3579 // Note that this works with the pointee-as-written.
3580 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3581 if (PointeeType.isNull())
3584 QualType Result = TL.getType();
3585 if (getDerived().AlwaysRebuild() ||
3586 PointeeType != T->getPointeeTypeAsWritten()) {
3587 Result = getDerived().RebuildReferenceType(PointeeType,
3588 T->isSpelledAsLValue(),
3590 if (Result.isNull())
3594 // Objective-C ARC can add lifetime qualifiers to the type that we're
3596 TLB.TypeWasModifiedSafely(
3597 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3599 // r-value references can be rebuilt as l-value references.
3600 ReferenceTypeLoc NewTL;
3601 if (isa<LValueReferenceType>(Result))
3602 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3604 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3605 NewTL.setSigilLoc(TL.getSigilLoc());
3610 template<typename Derived>
3612 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
3613 LValueReferenceTypeLoc TL) {
3614 return TransformReferenceType(TLB, TL);
3617 template<typename Derived>
3619 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
3620 RValueReferenceTypeLoc TL) {
3621 return TransformReferenceType(TLB, TL);
3624 template<typename Derived>
3626 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
3627 MemberPointerTypeLoc TL) {
3628 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3629 if (PointeeType.isNull())
3632 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3633 TypeSourceInfo* NewClsTInfo = 0;
3635 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3640 const MemberPointerType *T = TL.getTypePtr();
3641 QualType OldClsType = QualType(T->getClass(), 0);
3642 QualType NewClsType;
3644 NewClsType = NewClsTInfo->getType();
3646 NewClsType = getDerived().TransformType(OldClsType);
3647 if (NewClsType.isNull())
3651 QualType Result = TL.getType();
3652 if (getDerived().AlwaysRebuild() ||
3653 PointeeType != T->getPointeeType() ||
3654 NewClsType != OldClsType) {
3655 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
3657 if (Result.isNull())
3661 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3662 NewTL.setSigilLoc(TL.getSigilLoc());
3663 NewTL.setClassTInfo(NewClsTInfo);
3668 template<typename Derived>
3670 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
3671 ConstantArrayTypeLoc TL) {
3672 const ConstantArrayType *T = TL.getTypePtr();
3673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3674 if (ElementType.isNull())
3677 QualType Result = TL.getType();
3678 if (getDerived().AlwaysRebuild() ||
3679 ElementType != T->getElementType()) {
3680 Result = getDerived().RebuildConstantArrayType(ElementType,
3681 T->getSizeModifier(),
3683 T->getIndexTypeCVRQualifiers(),
3684 TL.getBracketsRange());
3685 if (Result.isNull())
3689 // We might have either a ConstantArrayType or a VariableArrayType now:
3690 // a ConstantArrayType is allowed to have an element type which is a
3691 // VariableArrayType if the type is dependent. Fortunately, all array
3692 // types have the same location layout.
3693 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3694 NewTL.setLBracketLoc(TL.getLBracketLoc());
3695 NewTL.setRBracketLoc(TL.getRBracketLoc());
3697 Expr *Size = TL.getSizeExpr();
3699 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3700 Sema::ConstantEvaluated);
3701 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3702 Size = SemaRef.ActOnConstantExpression(Size).take();
3704 NewTL.setSizeExpr(Size);
3709 template<typename Derived>
3710 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
3711 TypeLocBuilder &TLB,
3712 IncompleteArrayTypeLoc TL) {
3713 const IncompleteArrayType *T = TL.getTypePtr();
3714 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3715 if (ElementType.isNull())
3718 QualType Result = TL.getType();
3719 if (getDerived().AlwaysRebuild() ||
3720 ElementType != T->getElementType()) {
3721 Result = getDerived().RebuildIncompleteArrayType(ElementType,
3722 T->getSizeModifier(),
3723 T->getIndexTypeCVRQualifiers(),
3724 TL.getBracketsRange());
3725 if (Result.isNull())
3729 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3730 NewTL.setLBracketLoc(TL.getLBracketLoc());
3731 NewTL.setRBracketLoc(TL.getRBracketLoc());
3732 NewTL.setSizeExpr(0);
3737 template<typename Derived>
3739 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
3740 VariableArrayTypeLoc TL) {
3741 const VariableArrayType *T = TL.getTypePtr();
3742 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3743 if (ElementType.isNull())
3746 ExprResult SizeResult
3747 = getDerived().TransformExpr(T->getSizeExpr());
3748 if (SizeResult.isInvalid())
3751 Expr *Size = SizeResult.take();
3753 QualType Result = TL.getType();
3754 if (getDerived().AlwaysRebuild() ||
3755 ElementType != T->getElementType() ||
3756 Size != T->getSizeExpr()) {
3757 Result = getDerived().RebuildVariableArrayType(ElementType,
3758 T->getSizeModifier(),
3760 T->getIndexTypeCVRQualifiers(),
3761 TL.getBracketsRange());
3762 if (Result.isNull())
3766 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3767 NewTL.setLBracketLoc(TL.getLBracketLoc());
3768 NewTL.setRBracketLoc(TL.getRBracketLoc());
3769 NewTL.setSizeExpr(Size);
3774 template<typename Derived>
3776 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
3777 DependentSizedArrayTypeLoc TL) {
3778 const DependentSizedArrayType *T = TL.getTypePtr();
3779 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3780 if (ElementType.isNull())
3783 // Array bounds are constant expressions.
3784 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3785 Sema::ConstantEvaluated);
3787 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3788 Expr *origSize = TL.getSizeExpr();
3789 if (!origSize) origSize = T->getSizeExpr();
3791 ExprResult sizeResult
3792 = getDerived().TransformExpr(origSize);
3793 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
3794 if (sizeResult.isInvalid())
3797 Expr *size = sizeResult.get();
3799 QualType Result = TL.getType();
3800 if (getDerived().AlwaysRebuild() ||
3801 ElementType != T->getElementType() ||
3803 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3804 T->getSizeModifier(),
3806 T->getIndexTypeCVRQualifiers(),
3807 TL.getBracketsRange());
3808 if (Result.isNull())
3812 // We might have any sort of array type now, but fortunately they
3813 // all have the same location layout.
3814 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3815 NewTL.setLBracketLoc(TL.getLBracketLoc());
3816 NewTL.setRBracketLoc(TL.getRBracketLoc());
3817 NewTL.setSizeExpr(size);
3822 template<typename Derived>
3823 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3824 TypeLocBuilder &TLB,
3825 DependentSizedExtVectorTypeLoc TL) {
3826 const DependentSizedExtVectorType *T = TL.getTypePtr();
3828 // FIXME: ext vector locs should be nested
3829 QualType ElementType = getDerived().TransformType(T->getElementType());
3830 if (ElementType.isNull())
3833 // Vector sizes are constant expressions.
3834 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3835 Sema::ConstantEvaluated);
3837 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3838 Size = SemaRef.ActOnConstantExpression(Size);
3839 if (Size.isInvalid())
3842 QualType Result = TL.getType();
3843 if (getDerived().AlwaysRebuild() ||
3844 ElementType != T->getElementType() ||
3845 Size.get() != T->getSizeExpr()) {
3846 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
3848 T->getAttributeLoc());
3849 if (Result.isNull())
3853 // Result might be dependent or not.
3854 if (isa<DependentSizedExtVectorType>(Result)) {
3855 DependentSizedExtVectorTypeLoc NewTL
3856 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3857 NewTL.setNameLoc(TL.getNameLoc());
3859 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3860 NewTL.setNameLoc(TL.getNameLoc());
3866 template<typename Derived>
3867 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
3869 const VectorType *T = TL.getTypePtr();
3870 QualType ElementType = getDerived().TransformType(T->getElementType());
3871 if (ElementType.isNull())
3874 QualType Result = TL.getType();
3875 if (getDerived().AlwaysRebuild() ||
3876 ElementType != T->getElementType()) {
3877 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3878 T->getVectorKind());
3879 if (Result.isNull())
3883 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3884 NewTL.setNameLoc(TL.getNameLoc());
3889 template<typename Derived>
3890 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
3891 ExtVectorTypeLoc TL) {
3892 const VectorType *T = TL.getTypePtr();
3893 QualType ElementType = getDerived().TransformType(T->getElementType());
3894 if (ElementType.isNull())
3897 QualType Result = TL.getType();
3898 if (getDerived().AlwaysRebuild() ||
3899 ElementType != T->getElementType()) {
3900 Result = getDerived().RebuildExtVectorType(ElementType,
3901 T->getNumElements(),
3902 /*FIXME*/ SourceLocation());
3903 if (Result.isNull())
3907 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3908 NewTL.setNameLoc(TL.getNameLoc());
3913 template<typename Derived>
3915 TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3916 int indexAdjustment,
3917 llvm::Optional<unsigned> NumExpansions,
3918 bool ExpectParameterPack) {
3919 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3920 TypeSourceInfo *NewDI = 0;
3922 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3923 // If we're substituting into a pack expansion type and we know the
3924 // length we want to expand to, just substitute for the pattern.
3925 TypeLoc OldTL = OldDI->getTypeLoc();
3926 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3929 TypeLoc NewTL = OldDI->getTypeLoc();
3930 TLB.reserve(NewTL.getFullDataSize());
3932 QualType Result = getDerived().TransformType(TLB,
3933 OldExpansionTL.getPatternLoc());
3934 if (Result.isNull())
3937 Result = RebuildPackExpansionType(Result,
3938 OldExpansionTL.getPatternLoc().getSourceRange(),
3939 OldExpansionTL.getEllipsisLoc(),
3941 if (Result.isNull())
3944 PackExpansionTypeLoc NewExpansionTL
3945 = TLB.push<PackExpansionTypeLoc>(Result);
3946 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3947 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3949 NewDI = getDerived().TransformType(OldDI);
3953 if (NewDI == OldDI && indexAdjustment == 0)
3956 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3957 OldParm->getDeclContext(),
3958 OldParm->getInnerLocStart(),
3959 OldParm->getLocation(),
3960 OldParm->getIdentifier(),
3963 OldParm->getStorageClass(),
3964 OldParm->getStorageClassAsWritten(),
3966 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3967 OldParm->getFunctionScopeIndex() + indexAdjustment);
3971 template<typename Derived>
3972 bool TreeTransform<Derived>::
3973 TransformFunctionTypeParams(SourceLocation Loc,
3974 ParmVarDecl **Params, unsigned NumParams,
3975 const QualType *ParamTypes,
3976 SmallVectorImpl<QualType> &OutParamTypes,
3977 SmallVectorImpl<ParmVarDecl*> *PVars) {
3978 int indexAdjustment = 0;
3980 for (unsigned i = 0; i != NumParams; ++i) {
3981 if (ParmVarDecl *OldParm = Params[i]) {
3982 assert(OldParm->getFunctionScopeIndex() == i);
3984 llvm::Optional<unsigned> NumExpansions;
3985 ParmVarDecl *NewParm = 0;
3986 if (OldParm->isParameterPack()) {
3987 // We have a function parameter pack that may need to be expanded.
3988 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3990 // Find the parameter packs that could be expanded.
3991 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3992 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3993 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3994 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3995 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3997 // Determine whether we should expand the parameter packs.
3998 bool ShouldExpand = false;
3999 bool RetainExpansion = false;
4000 llvm::Optional<unsigned> OrigNumExpansions
4001 = ExpansionTL.getTypePtr()->getNumExpansions();
4002 NumExpansions = OrigNumExpansions;
4003 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4004 Pattern.getSourceRange(),
4013 // Expand the function parameter pack into multiple, separate
4015 getDerived().ExpandingFunctionParameterPack(OldParm);
4016 for (unsigned I = 0; I != *NumExpansions; ++I) {
4017 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4018 ParmVarDecl *NewParm
4019 = getDerived().TransformFunctionTypeParam(OldParm,
4022 /*ExpectParameterPack=*/false);
4026 OutParamTypes.push_back(NewParm->getType());
4028 PVars->push_back(NewParm);
4031 // If we're supposed to retain a pack expansion, do so by temporarily
4032 // forgetting the partially-substituted parameter pack.
4033 if (RetainExpansion) {
4034 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4035 ParmVarDecl *NewParm
4036 = getDerived().TransformFunctionTypeParam(OldParm,
4039 /*ExpectParameterPack=*/false);
4043 OutParamTypes.push_back(NewParm->getType());
4045 PVars->push_back(NewParm);
4048 // The next parameter should have the same adjustment as the
4049 // last thing we pushed, but we post-incremented indexAdjustment
4050 // on every push. Also, if we push nothing, the adjustment should
4054 // We're done with the pack expansion.
4058 // We'll substitute the parameter now without expanding the pack
4060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4061 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4064 /*ExpectParameterPack=*/true);
4066 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4068 llvm::Optional<unsigned>(),
4069 /*ExpectParameterPack=*/false);
4075 OutParamTypes.push_back(NewParm->getType());
4077 PVars->push_back(NewParm);
4081 // Deal with the possibility that we don't have a parameter
4082 // declaration for this parameter.
4083 QualType OldType = ParamTypes[i];
4084 bool IsPackExpansion = false;
4085 llvm::Optional<unsigned> NumExpansions;
4087 if (const PackExpansionType *Expansion
4088 = dyn_cast<PackExpansionType>(OldType)) {
4089 // We have a function parameter pack that may need to be expanded.
4090 QualType Pattern = Expansion->getPattern();
4091 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4092 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4094 // Determine whether we should expand the parameter packs.
4095 bool ShouldExpand = false;
4096 bool RetainExpansion = false;
4097 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4106 // Expand the function parameter pack into multiple, separate
4108 for (unsigned I = 0; I != *NumExpansions; ++I) {
4109 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4110 QualType NewType = getDerived().TransformType(Pattern);
4111 if (NewType.isNull())
4114 OutParamTypes.push_back(NewType);
4116 PVars->push_back(0);
4119 // We're done with the pack expansion.
4123 // If we're supposed to retain a pack expansion, do so by temporarily
4124 // forgetting the partially-substituted parameter pack.
4125 if (RetainExpansion) {
4126 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4127 QualType NewType = getDerived().TransformType(Pattern);
4128 if (NewType.isNull())
4131 OutParamTypes.push_back(NewType);
4133 PVars->push_back(0);
4136 // We'll substitute the parameter now without expanding the pack
4138 OldType = Expansion->getPattern();
4139 IsPackExpansion = true;
4140 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4141 NewType = getDerived().TransformType(OldType);
4143 NewType = getDerived().TransformType(OldType);
4146 if (NewType.isNull())
4149 if (IsPackExpansion)
4150 NewType = getSema().Context.getPackExpansionType(NewType,
4153 OutParamTypes.push_back(NewType);
4155 PVars->push_back(0);
4160 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4161 if (ParmVarDecl *parm = (*PVars)[i])
4162 assert(parm->getFunctionScopeIndex() == i);
4169 template<typename Derived>
4171 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4172 FunctionProtoTypeLoc TL) {
4173 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4176 template<typename Derived>
4178 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4179 FunctionProtoTypeLoc TL,
4180 CXXRecordDecl *ThisContext,
4181 unsigned ThisTypeQuals) {
4182 // Transform the parameters and return type.
4184 // We are required to instantiate the params and return type in source order.
4185 // When the function has a trailing return type, we instantiate the
4186 // parameters before the return type, since the return type can then refer
4187 // to the parameters themselves (via decltype, sizeof, etc.).
4189 SmallVector<QualType, 4> ParamTypes;
4190 SmallVector<ParmVarDecl*, 4> ParamDecls;
4191 const FunctionProtoType *T = TL.getTypePtr();
4193 QualType ResultType;
4195 if (TL.getTrailingReturn()) {
4196 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4199 TL.getTypePtr()->arg_type_begin(),
4200 ParamTypes, &ParamDecls))
4204 // C++11 [expr.prim.general]p3:
4205 // If a declaration declares a member function or member function
4206 // template of a class X, the expression this is a prvalue of type
4207 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4208 // and the end of the function-definition, member-declarator, or
4210 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4212 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4213 if (ResultType.isNull())
4218 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4219 if (ResultType.isNull())
4222 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4225 TL.getTypePtr()->arg_type_begin(),
4226 ParamTypes, &ParamDecls))
4230 // FIXME: Need to transform the exception-specification too.
4232 QualType Result = TL.getType();
4233 if (getDerived().AlwaysRebuild() ||
4234 ResultType != T->getResultType() ||
4235 T->getNumArgs() != ParamTypes.size() ||
4236 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4237 Result = getDerived().RebuildFunctionProtoType(ResultType,
4241 T->hasTrailingReturn(),
4243 T->getRefQualifier(),
4245 if (Result.isNull())
4249 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4250 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4251 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4252 NewTL.setTrailingReturn(TL.getTrailingReturn());
4253 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4254 NewTL.setArg(i, ParamDecls[i]);
4259 template<typename Derived>
4260 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4261 TypeLocBuilder &TLB,
4262 FunctionNoProtoTypeLoc TL) {
4263 const FunctionNoProtoType *T = TL.getTypePtr();
4264 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4265 if (ResultType.isNull())
4268 QualType Result = TL.getType();
4269 if (getDerived().AlwaysRebuild() ||
4270 ResultType != T->getResultType())
4271 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4273 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4274 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4275 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4276 NewTL.setTrailingReturn(false);
4281 template<typename Derived> QualType
4282 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
4283 UnresolvedUsingTypeLoc TL) {
4284 const UnresolvedUsingType *T = TL.getTypePtr();
4285 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4289 QualType Result = TL.getType();
4290 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4291 Result = getDerived().RebuildUnresolvedUsingType(D);
4292 if (Result.isNull())
4296 // We might get an arbitrary type spec type back. We should at
4297 // least always get a type spec type, though.
4298 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4299 NewTL.setNameLoc(TL.getNameLoc());
4304 template<typename Derived>
4305 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
4306 TypedefTypeLoc TL) {
4307 const TypedefType *T = TL.getTypePtr();
4308 TypedefNameDecl *Typedef
4309 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4314 QualType Result = TL.getType();
4315 if (getDerived().AlwaysRebuild() ||
4316 Typedef != T->getDecl()) {
4317 Result = getDerived().RebuildTypedefType(Typedef);
4318 if (Result.isNull())
4322 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4323 NewTL.setNameLoc(TL.getNameLoc());
4328 template<typename Derived>
4329 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
4330 TypeOfExprTypeLoc TL) {
4331 // typeof expressions are not potentially evaluated contexts
4332 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
4334 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4338 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4342 QualType Result = TL.getType();
4343 if (getDerived().AlwaysRebuild() ||
4344 E.get() != TL.getUnderlyingExpr()) {
4345 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4346 if (Result.isNull())
4351 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4352 NewTL.setTypeofLoc(TL.getTypeofLoc());
4353 NewTL.setLParenLoc(TL.getLParenLoc());
4354 NewTL.setRParenLoc(TL.getRParenLoc());
4359 template<typename Derived>
4360 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
4362 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4363 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4367 QualType Result = TL.getType();
4368 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4369 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4370 if (Result.isNull())
4374 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4375 NewTL.setTypeofLoc(TL.getTypeofLoc());
4376 NewTL.setLParenLoc(TL.getLParenLoc());
4377 NewTL.setRParenLoc(TL.getRParenLoc());
4378 NewTL.setUnderlyingTInfo(New_Under_TI);
4383 template<typename Derived>
4384 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
4385 DecltypeTypeLoc TL) {
4386 const DecltypeType *T = TL.getTypePtr();
4388 // decltype expressions are not potentially evaluated contexts
4389 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4390 /*IsDecltype=*/ true);
4392 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4396 E = getSema().ActOnDecltypeExpression(E.take());
4400 QualType Result = TL.getType();
4401 if (getDerived().AlwaysRebuild() ||
4402 E.get() != T->getUnderlyingExpr()) {
4403 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4404 if (Result.isNull())
4409 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4410 NewTL.setNameLoc(TL.getNameLoc());
4415 template<typename Derived>
4416 QualType TreeTransform<Derived>::TransformUnaryTransformType(
4417 TypeLocBuilder &TLB,
4418 UnaryTransformTypeLoc TL) {
4419 QualType Result = TL.getType();
4420 if (Result->isDependentType()) {
4421 const UnaryTransformType *T = TL.getTypePtr();
4423 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4424 Result = getDerived().RebuildUnaryTransformType(NewBase,
4427 if (Result.isNull())
4431 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4432 NewTL.setKWLoc(TL.getKWLoc());
4433 NewTL.setParensRange(TL.getParensRange());
4434 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4438 template<typename Derived>
4439 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4441 const AutoType *T = TL.getTypePtr();
4442 QualType OldDeduced = T->getDeducedType();
4443 QualType NewDeduced;
4444 if (!OldDeduced.isNull()) {
4445 NewDeduced = getDerived().TransformType(OldDeduced);
4446 if (NewDeduced.isNull())
4450 QualType Result = TL.getType();
4451 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4452 Result = getDerived().RebuildAutoType(NewDeduced);
4453 if (Result.isNull())
4457 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4458 NewTL.setNameLoc(TL.getNameLoc());
4463 template<typename Derived>
4464 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
4466 const RecordType *T = TL.getTypePtr();
4468 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4473 QualType Result = TL.getType();
4474 if (getDerived().AlwaysRebuild() ||
4475 Record != T->getDecl()) {
4476 Result = getDerived().RebuildRecordType(Record);
4477 if (Result.isNull())
4481 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4482 NewTL.setNameLoc(TL.getNameLoc());
4487 template<typename Derived>
4488 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
4490 const EnumType *T = TL.getTypePtr();
4492 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4497 QualType Result = TL.getType();
4498 if (getDerived().AlwaysRebuild() ||
4499 Enum != T->getDecl()) {
4500 Result = getDerived().RebuildEnumType(Enum);
4501 if (Result.isNull())
4505 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4506 NewTL.setNameLoc(TL.getNameLoc());
4511 template<typename Derived>
4512 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4513 TypeLocBuilder &TLB,
4514 InjectedClassNameTypeLoc TL) {
4515 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4516 TL.getTypePtr()->getDecl());
4517 if (!D) return QualType();
4519 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4520 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4524 template<typename Derived>
4525 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4526 TypeLocBuilder &TLB,
4527 TemplateTypeParmTypeLoc TL) {
4528 return TransformTypeSpecType(TLB, TL);
4531 template<typename Derived>
4532 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4533 TypeLocBuilder &TLB,
4534 SubstTemplateTypeParmTypeLoc TL) {
4535 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4537 // Substitute into the replacement type, which itself might involve something
4538 // that needs to be transformed. This only tends to occur with default
4539 // template arguments of template template parameters.
4540 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4541 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4542 if (Replacement.isNull())
4545 // Always canonicalize the replacement type.
4546 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4548 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4551 // Propagate type-source information.
4552 SubstTemplateTypeParmTypeLoc NewTL
4553 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4554 NewTL.setNameLoc(TL.getNameLoc());
4559 template<typename Derived>
4560 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4561 TypeLocBuilder &TLB,
4562 SubstTemplateTypeParmPackTypeLoc TL) {
4563 return TransformTypeSpecType(TLB, TL);
4566 template<typename Derived>
4567 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4568 TypeLocBuilder &TLB,
4569 TemplateSpecializationTypeLoc TL) {
4570 const TemplateSpecializationType *T = TL.getTypePtr();
4572 // The nested-name-specifier never matters in a TemplateSpecializationType,
4573 // because we can't have a dependent nested-name-specifier anyway.
4575 TemplateName Template
4576 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4577 TL.getTemplateNameLoc());
4578 if (Template.isNull())
4581 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4584 template<typename Derived>
4585 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4587 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4588 if (ValueType.isNull())
4591 QualType Result = TL.getType();
4592 if (getDerived().AlwaysRebuild() ||
4593 ValueType != TL.getValueLoc().getType()) {
4594 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4595 if (Result.isNull())
4599 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4600 NewTL.setKWLoc(TL.getKWLoc());
4601 NewTL.setLParenLoc(TL.getLParenLoc());
4602 NewTL.setRParenLoc(TL.getRParenLoc());
4608 /// \brief Simple iterator that traverses the template arguments in a
4609 /// container that provides a \c getArgLoc() member function.
4611 /// This iterator is intended to be used with the iterator form of
4612 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4613 template<typename ArgLocContainer>
4614 class TemplateArgumentLocContainerIterator {
4615 ArgLocContainer *Container;
4619 typedef TemplateArgumentLoc value_type;
4620 typedef TemplateArgumentLoc reference;
4621 typedef int difference_type;
4622 typedef std::input_iterator_tag iterator_category;
4625 TemplateArgumentLoc Arg;
4628 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4630 const TemplateArgumentLoc *operator->() const {
4636 TemplateArgumentLocContainerIterator() {}
4638 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4640 : Container(&Container), Index(Index) { }
4642 TemplateArgumentLocContainerIterator &operator++() {
4647 TemplateArgumentLocContainerIterator operator++(int) {
4648 TemplateArgumentLocContainerIterator Old(*this);
4653 TemplateArgumentLoc operator*() const {
4654 return Container->getArgLoc(Index);
4657 pointer operator->() const {
4658 return pointer(Container->getArgLoc(Index));
4661 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4662 const TemplateArgumentLocContainerIterator &Y) {
4663 return X.Container == Y.Container && X.Index == Y.Index;
4666 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4667 const TemplateArgumentLocContainerIterator &Y) {
4674 template <typename Derived>
4675 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4676 TypeLocBuilder &TLB,
4677 TemplateSpecializationTypeLoc TL,
4678 TemplateName Template) {
4679 TemplateArgumentListInfo NewTemplateArgs;
4680 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4681 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4682 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4684 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4685 ArgIterator(TL, TL.getNumArgs()),
4689 // FIXME: maybe don't rebuild if all the template arguments are the same.
4692 getDerived().RebuildTemplateSpecializationType(Template,
4693 TL.getTemplateNameLoc(),
4696 if (!Result.isNull()) {
4697 // Specializations of template template parameters are represented as
4698 // TemplateSpecializationTypes, and substitution of type alias templates
4699 // within a dependent context can transform them into
4700 // DependentTemplateSpecializationTypes.
4701 if (isa<DependentTemplateSpecializationType>(Result)) {
4702 DependentTemplateSpecializationTypeLoc NewTL
4703 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4704 NewTL.setElaboratedKeywordLoc(SourceLocation());
4705 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4706 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4707 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4708 NewTL.setLAngleLoc(TL.getLAngleLoc());
4709 NewTL.setRAngleLoc(TL.getRAngleLoc());
4710 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4711 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4715 TemplateSpecializationTypeLoc NewTL
4716 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4717 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4718 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4719 NewTL.setLAngleLoc(TL.getLAngleLoc());
4720 NewTL.setRAngleLoc(TL.getRAngleLoc());
4721 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4722 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4728 template <typename Derived>
4729 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4730 TypeLocBuilder &TLB,
4731 DependentTemplateSpecializationTypeLoc TL,
4732 TemplateName Template,
4734 TemplateArgumentListInfo NewTemplateArgs;
4735 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4736 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4737 typedef TemplateArgumentLocContainerIterator<
4738 DependentTemplateSpecializationTypeLoc> ArgIterator;
4739 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4740 ArgIterator(TL, TL.getNumArgs()),
4744 // FIXME: maybe don't rebuild if all the template arguments are the same.
4746 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4748 = getSema().Context.getDependentTemplateSpecializationType(
4749 TL.getTypePtr()->getKeyword(),
4750 DTN->getQualifier(),
4751 DTN->getIdentifier(),
4754 DependentTemplateSpecializationTypeLoc NewTL
4755 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4756 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4757 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
4758 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4759 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4760 NewTL.setLAngleLoc(TL.getLAngleLoc());
4761 NewTL.setRAngleLoc(TL.getRAngleLoc());
4762 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4763 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4768 = getDerived().RebuildTemplateSpecializationType(Template,
4769 TL.getTemplateNameLoc(),
4772 if (!Result.isNull()) {
4773 /// FIXME: Wrap this in an elaborated-type-specifier?
4774 TemplateSpecializationTypeLoc NewTL
4775 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4776 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4777 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4778 NewTL.setLAngleLoc(TL.getLAngleLoc());
4779 NewTL.setRAngleLoc(TL.getRAngleLoc());
4780 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4781 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4787 template<typename Derived>
4789 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
4790 ElaboratedTypeLoc TL) {
4791 const ElaboratedType *T = TL.getTypePtr();
4793 NestedNameSpecifierLoc QualifierLoc;
4794 // NOTE: the qualifier in an ElaboratedType is optional.
4795 if (TL.getQualifierLoc()) {
4797 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4802 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4803 if (NamedT.isNull())
4806 // C++0x [dcl.type.elab]p2:
4807 // If the identifier resolves to a typedef-name or the simple-template-id
4808 // resolves to an alias template specialization, the
4809 // elaborated-type-specifier is ill-formed.
4810 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4811 if (const TemplateSpecializationType *TST =
4812 NamedT->getAs<TemplateSpecializationType>()) {
4813 TemplateName Template = TST->getTemplateName();
4814 if (TypeAliasTemplateDecl *TAT =
4815 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4816 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4817 diag::err_tag_reference_non_tag) << 4;
4818 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4823 QualType Result = TL.getType();
4824 if (getDerived().AlwaysRebuild() ||
4825 QualifierLoc != TL.getQualifierLoc() ||
4826 NamedT != T->getNamedType()) {
4827 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
4829 QualifierLoc, NamedT);
4830 if (Result.isNull())
4834 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4835 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4836 NewTL.setQualifierLoc(QualifierLoc);
4840 template<typename Derived>
4841 QualType TreeTransform<Derived>::TransformAttributedType(
4842 TypeLocBuilder &TLB,
4843 AttributedTypeLoc TL) {
4844 const AttributedType *oldType = TL.getTypePtr();
4845 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4846 if (modifiedType.isNull())
4849 QualType result = TL.getType();
4851 // FIXME: dependent operand expressions?
4852 if (getDerived().AlwaysRebuild() ||
4853 modifiedType != oldType->getModifiedType()) {
4854 // TODO: this is really lame; we should really be rebuilding the
4855 // equivalent type from first principles.
4856 QualType equivalentType
4857 = getDerived().TransformType(oldType->getEquivalentType());
4858 if (equivalentType.isNull())
4860 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4865 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4866 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4867 if (TL.hasAttrOperand())
4868 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4869 if (TL.hasAttrExprOperand())
4870 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4871 else if (TL.hasAttrEnumOperand())
4872 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4877 template<typename Derived>
4879 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4881 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4885 QualType Result = TL.getType();
4886 if (getDerived().AlwaysRebuild() ||
4887 Inner != TL.getInnerLoc().getType()) {
4888 Result = getDerived().RebuildParenType(Inner);
4889 if (Result.isNull())
4893 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4894 NewTL.setLParenLoc(TL.getLParenLoc());
4895 NewTL.setRParenLoc(TL.getRParenLoc());
4899 template<typename Derived>
4900 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
4901 DependentNameTypeLoc TL) {
4902 const DependentNameType *T = TL.getTypePtr();
4904 NestedNameSpecifierLoc QualifierLoc
4905 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4910 = getDerived().RebuildDependentNameType(T->getKeyword(),
4911 TL.getElaboratedKeywordLoc(),
4915 if (Result.isNull())
4918 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4919 QualType NamedT = ElabT->getNamedType();
4920 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4922 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4923 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4924 NewTL.setQualifierLoc(QualifierLoc);
4926 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4927 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4928 NewTL.setQualifierLoc(QualifierLoc);
4929 NewTL.setNameLoc(TL.getNameLoc());
4934 template<typename Derived>
4935 QualType TreeTransform<Derived>::
4936 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4937 DependentTemplateSpecializationTypeLoc TL) {
4938 NestedNameSpecifierLoc QualifierLoc;
4939 if (TL.getQualifierLoc()) {
4941 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4947 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
4950 template<typename Derived>
4951 QualType TreeTransform<Derived>::
4952 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4953 DependentTemplateSpecializationTypeLoc TL,
4954 NestedNameSpecifierLoc QualifierLoc) {
4955 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4957 TemplateArgumentListInfo NewTemplateArgs;
4958 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4959 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4961 typedef TemplateArgumentLocContainerIterator<
4962 DependentTemplateSpecializationTypeLoc> ArgIterator;
4963 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4964 ArgIterator(TL, TL.getNumArgs()),
4969 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4972 TL.getTemplateNameLoc(),
4974 if (Result.isNull())
4977 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4978 QualType NamedT = ElabT->getNamedType();
4980 // Copy information relevant to the template specialization.
4981 TemplateSpecializationTypeLoc NamedTL
4982 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4983 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4984 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4985 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4986 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4987 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
4988 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
4990 // Copy information relevant to the elaborated type.
4991 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4992 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4993 NewTL.setQualifierLoc(QualifierLoc);
4994 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4995 DependentTemplateSpecializationTypeLoc SpecTL
4996 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4997 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4998 SpecTL.setQualifierLoc(QualifierLoc);
4999 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5000 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5001 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5002 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5003 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5004 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5006 TemplateSpecializationTypeLoc SpecTL
5007 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5008 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5009 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5010 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5011 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5012 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5013 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5018 template<typename Derived>
5019 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5020 PackExpansionTypeLoc TL) {
5022 = getDerived().TransformType(TLB, TL.getPatternLoc());
5023 if (Pattern.isNull())
5026 QualType Result = TL.getType();
5027 if (getDerived().AlwaysRebuild() ||
5028 Pattern != TL.getPatternLoc().getType()) {
5029 Result = getDerived().RebuildPackExpansionType(Pattern,
5030 TL.getPatternLoc().getSourceRange(),
5031 TL.getEllipsisLoc(),
5032 TL.getTypePtr()->getNumExpansions());
5033 if (Result.isNull())
5037 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5038 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5042 template<typename Derived>
5044 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5045 ObjCInterfaceTypeLoc TL) {
5046 // ObjCInterfaceType is never dependent.
5047 TLB.pushFullCopy(TL);
5048 return TL.getType();
5051 template<typename Derived>
5053 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5054 ObjCObjectTypeLoc TL) {
5055 // ObjCObjectType is never dependent.
5056 TLB.pushFullCopy(TL);
5057 return TL.getType();
5060 template<typename Derived>
5062 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
5063 ObjCObjectPointerTypeLoc TL) {
5064 // ObjCObjectPointerType is never dependent.
5065 TLB.pushFullCopy(TL);
5066 return TL.getType();
5069 //===----------------------------------------------------------------------===//
5070 // Statement transformation
5071 //===----------------------------------------------------------------------===//
5072 template<typename Derived>
5074 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
5075 return SemaRef.Owned(S);
5078 template<typename Derived>
5080 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5081 return getDerived().TransformCompoundStmt(S, false);
5084 template<typename Derived>
5086 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
5088 Sema::CompoundScopeRAII CompoundScope(getSema());
5090 bool SubStmtInvalid = false;
5091 bool SubStmtChanged = false;
5092 ASTOwningVector<Stmt*> Statements(getSema());
5093 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5095 StmtResult Result = getDerived().TransformStmt(*B);
5096 if (Result.isInvalid()) {
5097 // Immediately fail if this was a DeclStmt, since it's very
5098 // likely that this will cause problems for future statements.
5099 if (isa<DeclStmt>(*B))
5102 // Otherwise, just keep processing substatements and fail later.
5103 SubStmtInvalid = true;
5107 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5108 Statements.push_back(Result.takeAs<Stmt>());
5114 if (!getDerived().AlwaysRebuild() &&
5116 return SemaRef.Owned(S);
5118 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5119 move_arg(Statements),
5124 template<typename Derived>
5126 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
5127 ExprResult LHS, RHS;
5129 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5130 Sema::ConstantEvaluated);
5132 // Transform the left-hand case value.
5133 LHS = getDerived().TransformExpr(S->getLHS());
5134 LHS = SemaRef.ActOnConstantExpression(LHS);
5135 if (LHS.isInvalid())
5138 // Transform the right-hand case value (for the GNU case-range extension).
5139 RHS = getDerived().TransformExpr(S->getRHS());
5140 RHS = SemaRef.ActOnConstantExpression(RHS);
5141 if (RHS.isInvalid())
5145 // Build the case statement.
5146 // Case statements are always rebuilt so that they will attached to their
5147 // transformed switch statement.
5148 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
5150 S->getEllipsisLoc(),
5153 if (Case.isInvalid())
5156 // Transform the statement following the case
5157 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5158 if (SubStmt.isInvalid())
5161 // Attach the body to the case statement
5162 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
5165 template<typename Derived>
5167 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
5168 // Transform the statement following the default case
5169 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5170 if (SubStmt.isInvalid())
5173 // Default statements are always rebuilt
5174 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
5178 template<typename Derived>
5180 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
5181 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5182 if (SubStmt.isInvalid())
5185 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5191 // FIXME: Pass the real colon location in.
5192 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
5193 cast<LabelDecl>(LD), SourceLocation(),
5197 template<typename Derived>
5199 TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5200 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5201 if (SubStmt.isInvalid())
5204 // TODO: transform attributes
5205 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5208 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5213 template<typename Derived>
5215 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
5216 // Transform the condition
5218 VarDecl *ConditionVar = 0;
5219 if (S->getConditionVariable()) {
5221 = cast_or_null<VarDecl>(
5222 getDerived().TransformDefinition(
5223 S->getConditionVariable()->getLocation(),
5224 S->getConditionVariable()));
5228 Cond = getDerived().TransformExpr(S->getCond());
5230 if (Cond.isInvalid())
5233 // Convert the condition to a boolean value.
5235 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5237 if (CondE.isInvalid())
5244 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5245 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5248 // Transform the "then" branch.
5249 StmtResult Then = getDerived().TransformStmt(S->getThen());
5250 if (Then.isInvalid())
5253 // Transform the "else" branch.
5254 StmtResult Else = getDerived().TransformStmt(S->getElse());
5255 if (Else.isInvalid())
5258 if (!getDerived().AlwaysRebuild() &&
5259 FullCond.get() == S->getCond() &&
5260 ConditionVar == S->getConditionVariable() &&
5261 Then.get() == S->getThen() &&
5262 Else.get() == S->getElse())
5263 return SemaRef.Owned(S);
5265 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
5267 S->getElseLoc(), Else.get());
5270 template<typename Derived>
5272 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
5273 // Transform the condition.
5275 VarDecl *ConditionVar = 0;
5276 if (S->getConditionVariable()) {
5278 = cast_or_null<VarDecl>(
5279 getDerived().TransformDefinition(
5280 S->getConditionVariable()->getLocation(),
5281 S->getConditionVariable()));
5285 Cond = getDerived().TransformExpr(S->getCond());
5287 if (Cond.isInvalid())
5291 // Rebuild the switch statement.
5293 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5295 if (Switch.isInvalid())
5298 // Transform the body of the switch statement.
5299 StmtResult Body = getDerived().TransformStmt(S->getBody());
5300 if (Body.isInvalid())
5303 // Complete the switch statement.
5304 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5308 template<typename Derived>
5310 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
5311 // Transform the condition
5313 VarDecl *ConditionVar = 0;
5314 if (S->getConditionVariable()) {
5316 = cast_or_null<VarDecl>(
5317 getDerived().TransformDefinition(
5318 S->getConditionVariable()->getLocation(),
5319 S->getConditionVariable()));
5323 Cond = getDerived().TransformExpr(S->getCond());
5325 if (Cond.isInvalid())
5329 // Convert the condition to a boolean value.
5330 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5332 if (CondE.isInvalid())
5338 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5339 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5342 // Transform the body
5343 StmtResult Body = getDerived().TransformStmt(S->getBody());
5344 if (Body.isInvalid())
5347 if (!getDerived().AlwaysRebuild() &&
5348 FullCond.get() == S->getCond() &&
5349 ConditionVar == S->getConditionVariable() &&
5350 Body.get() == S->getBody())
5353 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
5354 ConditionVar, Body.get());
5357 template<typename Derived>
5359 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
5360 // Transform the body
5361 StmtResult Body = getDerived().TransformStmt(S->getBody());
5362 if (Body.isInvalid())
5365 // Transform the condition
5366 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5367 if (Cond.isInvalid())
5370 if (!getDerived().AlwaysRebuild() &&
5371 Cond.get() == S->getCond() &&
5372 Body.get() == S->getBody())
5373 return SemaRef.Owned(S);
5375 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5376 /*FIXME:*/S->getWhileLoc(), Cond.get(),
5380 template<typename Derived>
5382 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
5383 // Transform the initialization statement
5384 StmtResult Init = getDerived().TransformStmt(S->getInit());
5385 if (Init.isInvalid())
5388 // Transform the condition
5390 VarDecl *ConditionVar = 0;
5391 if (S->getConditionVariable()) {
5393 = cast_or_null<VarDecl>(
5394 getDerived().TransformDefinition(
5395 S->getConditionVariable()->getLocation(),
5396 S->getConditionVariable()));
5400 Cond = getDerived().TransformExpr(S->getCond());
5402 if (Cond.isInvalid())
5406 // Convert the condition to a boolean value.
5407 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5409 if (CondE.isInvalid())
5416 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5417 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5420 // Transform the increment
5421 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5422 if (Inc.isInvalid())
5425 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5426 if (S->getInc() && !FullInc.get())
5429 // Transform the body
5430 StmtResult Body = getDerived().TransformStmt(S->getBody());
5431 if (Body.isInvalid())
5434 if (!getDerived().AlwaysRebuild() &&
5435 Init.get() == S->getInit() &&
5436 FullCond.get() == S->getCond() &&
5437 Inc.get() == S->getInc() &&
5438 Body.get() == S->getBody())
5439 return SemaRef.Owned(S);
5441 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
5442 Init.get(), FullCond, ConditionVar,
5443 FullInc, S->getRParenLoc(), Body.get());
5446 template<typename Derived>
5448 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
5449 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5454 // Goto statements must always be rebuilt, to resolve the label.
5455 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
5456 cast<LabelDecl>(LD));
5459 template<typename Derived>
5461 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
5462 ExprResult Target = getDerived().TransformExpr(S->getTarget());
5463 if (Target.isInvalid())
5465 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
5467 if (!getDerived().AlwaysRebuild() &&
5468 Target.get() == S->getTarget())
5469 return SemaRef.Owned(S);
5471 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
5475 template<typename Derived>
5477 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
5478 return SemaRef.Owned(S);
5481 template<typename Derived>
5483 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
5484 return SemaRef.Owned(S);
5487 template<typename Derived>
5489 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
5490 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
5491 if (Result.isInvalid())
5494 // FIXME: We always rebuild the return statement because there is no way
5495 // to tell whether the return type of the function has changed.
5496 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
5499 template<typename Derived>
5501 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
5502 bool DeclChanged = false;
5503 SmallVector<Decl *, 4> Decls;
5504 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5506 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5511 if (Transformed != *D)
5514 Decls.push_back(Transformed);
5517 if (!getDerived().AlwaysRebuild() && !DeclChanged)
5518 return SemaRef.Owned(S);
5520 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
5521 S->getStartLoc(), S->getEndLoc());
5524 template<typename Derived>
5526 TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
5528 ASTOwningVector<Expr*> Constraints(getSema());
5529 ASTOwningVector<Expr*> Exprs(getSema());
5530 SmallVector<IdentifierInfo *, 4> Names;
5532 ExprResult AsmString;
5533 ASTOwningVector<Expr*> Clobbers(getSema());
5535 bool ExprsChanged = false;
5537 // Go through the outputs.
5538 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5539 Names.push_back(S->getOutputIdentifier(I));
5541 // No need to transform the constraint literal.
5542 Constraints.push_back(S->getOutputConstraintLiteral(I));
5544 // Transform the output expr.
5545 Expr *OutputExpr = S->getOutputExpr(I);
5546 ExprResult Result = getDerived().TransformExpr(OutputExpr);
5547 if (Result.isInvalid())
5550 ExprsChanged |= Result.get() != OutputExpr;
5552 Exprs.push_back(Result.get());
5555 // Go through the inputs.
5556 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5557 Names.push_back(S->getInputIdentifier(I));
5559 // No need to transform the constraint literal.
5560 Constraints.push_back(S->getInputConstraintLiteral(I));
5562 // Transform the input expr.
5563 Expr *InputExpr = S->getInputExpr(I);
5564 ExprResult Result = getDerived().TransformExpr(InputExpr);
5565 if (Result.isInvalid())
5568 ExprsChanged |= Result.get() != InputExpr;
5570 Exprs.push_back(Result.get());
5573 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
5574 return SemaRef.Owned(S);
5576 // Go through the clobbers.
5577 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
5578 Clobbers.push_back(S->getClobber(I));
5580 // No need to transform the asm string literal.
5581 AsmString = SemaRef.Owned(S->getAsmString());
5583 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5589 move_arg(Constraints),
5598 template<typename Derived>
5600 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
5601 // Transform the body of the @try.
5602 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
5603 if (TryBody.isInvalid())
5606 // Transform the @catch statements (if present).
5607 bool AnyCatchChanged = false;
5608 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
5609 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
5610 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
5611 if (Catch.isInvalid())
5613 if (Catch.get() != S->getCatchStmt(I))
5614 AnyCatchChanged = true;
5615 CatchStmts.push_back(Catch.release());
5618 // Transform the @finally statement (if present).
5620 if (S->getFinallyStmt()) {
5621 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5622 if (Finally.isInvalid())
5626 // If nothing changed, just retain this statement.
5627 if (!getDerived().AlwaysRebuild() &&
5628 TryBody.get() == S->getTryBody() &&
5630 Finally.get() == S->getFinallyStmt())
5631 return SemaRef.Owned(S);
5633 // Build a new statement.
5634 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5635 move_arg(CatchStmts), Finally.get());
5638 template<typename Derived>
5640 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5641 // Transform the @catch parameter, if there is one.
5643 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5644 TypeSourceInfo *TSInfo = 0;
5645 if (FromVar->getTypeSourceInfo()) {
5646 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5653 T = TSInfo->getType();
5655 T = getDerived().TransformType(FromVar->getType());
5660 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5665 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5666 if (Body.isInvalid())
5669 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5674 template<typename Derived>
5676 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
5677 // Transform the body.
5678 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
5679 if (Body.isInvalid())
5682 // If nothing changed, just retain this statement.
5683 if (!getDerived().AlwaysRebuild() &&
5684 Body.get() == S->getFinallyBody())
5685 return SemaRef.Owned(S);
5687 // Build a new statement.
5688 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
5692 template<typename Derived>
5694 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
5696 if (S->getThrowExpr()) {
5697 Operand = getDerived().TransformExpr(S->getThrowExpr());
5698 if (Operand.isInvalid())
5702 if (!getDerived().AlwaysRebuild() &&
5703 Operand.get() == S->getThrowExpr())
5704 return getSema().Owned(S);
5706 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
5709 template<typename Derived>
5711 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
5712 ObjCAtSynchronizedStmt *S) {
5713 // Transform the object we are locking.
5714 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
5715 if (Object.isInvalid())
5718 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5720 if (Object.isInvalid())
5723 // Transform the body.
5724 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
5725 if (Body.isInvalid())
5728 // If nothing change, just retain the current statement.
5729 if (!getDerived().AlwaysRebuild() &&
5730 Object.get() == S->getSynchExpr() &&
5731 Body.get() == S->getSynchBody())
5732 return SemaRef.Owned(S);
5734 // Build a new statement.
5735 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
5736 Object.get(), Body.get());
5739 template<typename Derived>
5741 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5742 ObjCAutoreleasePoolStmt *S) {
5743 // Transform the body.
5744 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5745 if (Body.isInvalid())
5748 // If nothing changed, just retain this statement.
5749 if (!getDerived().AlwaysRebuild() &&
5750 Body.get() == S->getSubStmt())
5751 return SemaRef.Owned(S);
5753 // Build a new statement.
5754 return getDerived().RebuildObjCAutoreleasePoolStmt(
5755 S->getAtLoc(), Body.get());
5758 template<typename Derived>
5760 TreeTransform<Derived>::TransformObjCForCollectionStmt(
5761 ObjCForCollectionStmt *S) {
5762 // Transform the element statement.
5763 StmtResult Element = getDerived().TransformStmt(S->getElement());
5764 if (Element.isInvalid())
5767 // Transform the collection expression.
5768 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5769 if (Collection.isInvalid())
5771 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5773 if (Collection.isInvalid())
5776 // Transform the body.
5777 StmtResult Body = getDerived().TransformStmt(S->getBody());
5778 if (Body.isInvalid())
5781 // If nothing changed, just retain this statement.
5782 if (!getDerived().AlwaysRebuild() &&
5783 Element.get() == S->getElement() &&
5784 Collection.get() == S->getCollection() &&
5785 Body.get() == S->getBody())
5786 return SemaRef.Owned(S);
5788 // Build a new statement.
5789 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5790 /*FIXME:*/S->getForLoc(),
5798 template<typename Derived>
5800 TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5801 // Transform the exception declaration, if any.
5803 if (S->getExceptionDecl()) {
5804 VarDecl *ExceptionDecl = S->getExceptionDecl();
5805 TypeSourceInfo *T = getDerived().TransformType(
5806 ExceptionDecl->getTypeSourceInfo());
5810 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
5811 ExceptionDecl->getInnerLocStart(),
5812 ExceptionDecl->getLocation(),
5813 ExceptionDecl->getIdentifier());
5814 if (!Var || Var->isInvalidDecl())
5818 // Transform the actual exception handler.
5819 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5820 if (Handler.isInvalid())
5823 if (!getDerived().AlwaysRebuild() &&
5825 Handler.get() == S->getHandlerBlock())
5826 return SemaRef.Owned(S);
5828 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5833 template<typename Derived>
5835 TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5836 // Transform the try block itself.
5838 = getDerived().TransformCompoundStmt(S->getTryBlock());
5839 if (TryBlock.isInvalid())
5842 // Transform the handlers.
5843 bool HandlerChanged = false;
5844 ASTOwningVector<Stmt*> Handlers(SemaRef);
5845 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
5847 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5848 if (Handler.isInvalid())
5851 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5852 Handlers.push_back(Handler.takeAs<Stmt>());
5855 if (!getDerived().AlwaysRebuild() &&
5856 TryBlock.get() == S->getTryBlock() &&
5858 return SemaRef.Owned(S);
5860 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
5861 move_arg(Handlers));
5864 template<typename Derived>
5866 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5867 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5868 if (Range.isInvalid())
5871 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5872 if (BeginEnd.isInvalid())
5875 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5876 if (Cond.isInvalid())
5879 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5880 if (Cond.isInvalid())
5883 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
5885 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5886 if (Inc.isInvalid())
5889 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
5891 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5892 if (LoopVar.isInvalid())
5895 StmtResult NewStmt = S;
5896 if (getDerived().AlwaysRebuild() ||
5897 Range.get() != S->getRangeStmt() ||
5898 BeginEnd.get() != S->getBeginEndStmt() ||
5899 Cond.get() != S->getCond() ||
5900 Inc.get() != S->getInc() ||
5901 LoopVar.get() != S->getLoopVarStmt())
5902 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5903 S->getColonLoc(), Range.get(),
5904 BeginEnd.get(), Cond.get(),
5905 Inc.get(), LoopVar.get(),
5908 StmtResult Body = getDerived().TransformStmt(S->getBody());
5909 if (Body.isInvalid())
5912 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5913 // it now so we have a new statement to attach the body to.
5914 if (Body.get() != S->getBody() && NewStmt.get() == S)
5915 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5916 S->getColonLoc(), Range.get(),
5917 BeginEnd.get(), Cond.get(),
5918 Inc.get(), LoopVar.get(),
5921 if (NewStmt.get() == S)
5922 return SemaRef.Owned(S);
5924 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5927 template<typename Derived>
5929 TreeTransform<Derived>::TransformMSDependentExistsStmt(
5930 MSDependentExistsStmt *S) {
5931 // Transform the nested-name-specifier, if any.
5932 NestedNameSpecifierLoc QualifierLoc;
5933 if (S->getQualifierLoc()) {
5935 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5940 // Transform the declaration name.
5941 DeclarationNameInfo NameInfo = S->getNameInfo();
5942 if (NameInfo.getName()) {
5943 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5944 if (!NameInfo.getName())
5948 // Check whether anything changed.
5949 if (!getDerived().AlwaysRebuild() &&
5950 QualifierLoc == S->getQualifierLoc() &&
5951 NameInfo.getName() == S->getNameInfo().getName())
5954 // Determine whether this name exists, if we can.
5956 SS.Adopt(QualifierLoc);
5957 bool Dependent = false;
5958 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5959 case Sema::IER_Exists:
5960 if (S->isIfExists())
5963 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5965 case Sema::IER_DoesNotExist:
5966 if (S->isIfNotExists())
5969 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5971 case Sema::IER_Dependent:
5975 case Sema::IER_Error:
5979 // We need to continue with the instantiation, so do so now.
5980 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5981 if (SubStmt.isInvalid())
5984 // If we have resolved the name, just transform to the substatement.
5988 // The name is still dependent, so build a dependent expression again.
5989 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5996 template<typename Derived>
5998 TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5999 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6000 if(TryBlock.isInvalid()) return StmtError();
6002 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6003 if(!getDerived().AlwaysRebuild() &&
6004 TryBlock.get() == S->getTryBlock() &&
6005 Handler.get() == S->getHandler())
6006 return SemaRef.Owned(S);
6008 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6014 template<typename Derived>
6016 TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6017 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6018 if(Block.isInvalid()) return StmtError();
6020 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6024 template<typename Derived>
6026 TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6027 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6028 if(FilterExpr.isInvalid()) return StmtError();
6030 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6031 if(Block.isInvalid()) return StmtError();
6033 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6038 template<typename Derived>
6040 TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6041 if(isa<SEHFinallyStmt>(Handler))
6042 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6044 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6047 //===----------------------------------------------------------------------===//
6048 // Expression transformation
6049 //===----------------------------------------------------------------------===//
6050 template<typename Derived>
6052 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
6053 return SemaRef.Owned(E);
6056 template<typename Derived>
6058 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
6059 NestedNameSpecifierLoc QualifierLoc;
6060 if (E->getQualifierLoc()) {
6062 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6068 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6073 DeclarationNameInfo NameInfo = E->getNameInfo();
6074 if (NameInfo.getName()) {
6075 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6076 if (!NameInfo.getName())
6080 if (!getDerived().AlwaysRebuild() &&
6081 QualifierLoc == E->getQualifierLoc() &&
6082 ND == E->getDecl() &&
6083 NameInfo.getName() == E->getDecl()->getDeclName() &&
6084 !E->hasExplicitTemplateArgs()) {
6086 // Mark it referenced in the new context regardless.
6087 // FIXME: this is a bit instantiation-specific.
6088 SemaRef.MarkDeclRefReferenced(E);
6090 return SemaRef.Owned(E);
6093 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
6094 if (E->hasExplicitTemplateArgs()) {
6095 TemplateArgs = &TransArgs;
6096 TransArgs.setLAngleLoc(E->getLAngleLoc());
6097 TransArgs.setRAngleLoc(E->getRAngleLoc());
6098 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6099 E->getNumTemplateArgs(),
6104 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6108 template<typename Derived>
6110 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
6111 return SemaRef.Owned(E);
6114 template<typename Derived>
6116 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
6117 return SemaRef.Owned(E);
6120 template<typename Derived>
6122 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
6123 return SemaRef.Owned(E);
6126 template<typename Derived>
6128 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
6129 return SemaRef.Owned(E);
6132 template<typename Derived>
6134 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
6135 return SemaRef.Owned(E);
6138 template<typename Derived>
6140 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6141 return SemaRef.MaybeBindToTemporary(E);
6144 template<typename Derived>
6146 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6147 ExprResult ControllingExpr =
6148 getDerived().TransformExpr(E->getControllingExpr());
6149 if (ControllingExpr.isInvalid())
6152 SmallVector<Expr *, 4> AssocExprs;
6153 SmallVector<TypeSourceInfo *, 4> AssocTypes;
6154 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6155 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6157 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6160 AssocTypes.push_back(AssocType);
6162 AssocTypes.push_back(0);
6165 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6166 if (AssocExpr.isInvalid())
6168 AssocExprs.push_back(AssocExpr.release());
6171 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6174 ControllingExpr.release(),
6180 template<typename Derived>
6182 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
6183 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6184 if (SubExpr.isInvalid())
6187 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
6188 return SemaRef.Owned(E);
6190 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
6194 template<typename Derived>
6196 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
6197 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6198 if (SubExpr.isInvalid())
6201 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
6202 return SemaRef.Owned(E);
6204 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6209 template<typename Derived>
6211 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6212 // Transform the type.
6213 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6217 // Transform all of the components into components similar to what the
6219 // FIXME: It would be slightly more efficient in the non-dependent case to
6220 // just map FieldDecls, rather than requiring the rebuilder to look for
6221 // the fields again. However, __builtin_offsetof is rare enough in
6222 // template code that we don't care.
6223 bool ExprChanged = false;
6224 typedef Sema::OffsetOfComponent Component;
6225 typedef OffsetOfExpr::OffsetOfNode Node;
6226 SmallVector<Component, 4> Components;
6227 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6228 const Node &ON = E->getComponent(I);
6230 Comp.isBrackets = true;
6231 Comp.LocStart = ON.getSourceRange().getBegin();
6232 Comp.LocEnd = ON.getSourceRange().getEnd();
6233 switch (ON.getKind()) {
6235 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
6236 ExprResult Index = getDerived().TransformExpr(FromIndex);
6237 if (Index.isInvalid())
6240 ExprChanged = ExprChanged || Index.get() != FromIndex;
6241 Comp.isBrackets = true;
6242 Comp.U.E = Index.get();
6247 case Node::Identifier:
6248 Comp.isBrackets = false;
6249 Comp.U.IdentInfo = ON.getFieldName();
6250 if (!Comp.U.IdentInfo)
6256 // Will be recomputed during the rebuild.
6260 Components.push_back(Comp);
6263 // If nothing changed, retain the existing expression.
6264 if (!getDerived().AlwaysRebuild() &&
6265 Type == E->getTypeSourceInfo() &&
6267 return SemaRef.Owned(E);
6269 // Build a new offsetof expression.
6270 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6271 Components.data(), Components.size(),
6275 template<typename Derived>
6277 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6278 assert(getDerived().AlreadyTransformed(E->getType()) &&
6279 "opaque value expression requires transformation");
6280 return SemaRef.Owned(E);
6283 template<typename Derived>
6285 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
6286 // Rebuild the syntactic form. The original syntactic form has
6287 // opaque-value expressions in it, so strip those away and rebuild
6288 // the result. This is a really awful way of doing this, but the
6289 // better solution (rebuilding the semantic expressions and
6290 // rebinding OVEs as necessary) doesn't work; we'd need
6291 // TreeTransform to not strip away implicit conversions.
6292 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6293 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
6294 if (result.isInvalid()) return ExprError();
6296 // If that gives us a pseudo-object result back, the pseudo-object
6297 // expression must have been an lvalue-to-rvalue conversion which we
6299 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6300 result = SemaRef.checkPseudoObjectRValue(result.take());
6305 template<typename Derived>
6307 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6308 UnaryExprOrTypeTraitExpr *E) {
6309 if (E->isArgumentType()) {
6310 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
6312 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6316 if (!getDerived().AlwaysRebuild() && OldT == NewT)
6317 return SemaRef.Owned(E);
6319 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6321 E->getSourceRange());
6324 // C++0x [expr.sizeof]p1:
6325 // The operand is either an expression, which is an unevaluated operand
6327 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6329 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6330 if (SubExpr.isInvalid())
6333 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6334 return SemaRef.Owned(E);
6336 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6337 E->getOperatorLoc(),
6339 E->getSourceRange());
6342 template<typename Derived>
6344 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
6345 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6346 if (LHS.isInvalid())
6349 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6350 if (RHS.isInvalid())
6354 if (!getDerived().AlwaysRebuild() &&
6355 LHS.get() == E->getLHS() &&
6356 RHS.get() == E->getRHS())
6357 return SemaRef.Owned(E);
6359 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
6360 /*FIXME:*/E->getLHS()->getLocStart(),
6362 E->getRBracketLoc());
6365 template<typename Derived>
6367 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6368 // Transform the callee.
6369 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6370 if (Callee.isInvalid())
6373 // Transform arguments.
6374 bool ArgChanged = false;
6375 ASTOwningVector<Expr*> Args(SemaRef);
6376 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6380 if (!getDerived().AlwaysRebuild() &&
6381 Callee.get() == E->getCallee() &&
6383 return SemaRef.MaybeBindToTemporary(E);;
6385 // FIXME: Wrong source location information for the '('.
6386 SourceLocation FakeLParenLoc
6387 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6388 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6393 template<typename Derived>
6395 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
6396 ExprResult Base = getDerived().TransformExpr(E->getBase());
6397 if (Base.isInvalid())
6400 NestedNameSpecifierLoc QualifierLoc;
6401 if (E->hasQualifier()) {
6403 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6408 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
6411 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6412 E->getMemberDecl()));
6416 NamedDecl *FoundDecl = E->getFoundDecl();
6417 if (FoundDecl == E->getMemberDecl()) {
6420 FoundDecl = cast_or_null<NamedDecl>(
6421 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6426 if (!getDerived().AlwaysRebuild() &&
6427 Base.get() == E->getBase() &&
6428 QualifierLoc == E->getQualifierLoc() &&
6429 Member == E->getMemberDecl() &&
6430 FoundDecl == E->getFoundDecl() &&
6431 !E->hasExplicitTemplateArgs()) {
6433 // Mark it referenced in the new context regardless.
6434 // FIXME: this is a bit instantiation-specific.
6435 SemaRef.MarkMemberReferenced(E);
6437 return SemaRef.Owned(E);
6440 TemplateArgumentListInfo TransArgs;
6441 if (E->hasExplicitTemplateArgs()) {
6442 TransArgs.setLAngleLoc(E->getLAngleLoc());
6443 TransArgs.setRAngleLoc(E->getRAngleLoc());
6444 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6445 E->getNumTemplateArgs(),
6450 // FIXME: Bogus source location for the operator
6451 SourceLocation FakeOperatorLoc
6452 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6454 // FIXME: to do this check properly, we will need to preserve the
6455 // first-qualifier-in-scope here, just in case we had a dependent
6456 // base (and therefore couldn't do the check) and a
6457 // nested-name-qualifier (and therefore could do the lookup).
6458 NamedDecl *FirstQualifierInScope = 0;
6460 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6464 E->getMemberNameInfo(),
6467 (E->hasExplicitTemplateArgs()
6469 FirstQualifierInScope);
6472 template<typename Derived>
6474 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
6475 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6476 if (LHS.isInvalid())
6479 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6480 if (RHS.isInvalid())
6483 if (!getDerived().AlwaysRebuild() &&
6484 LHS.get() == E->getLHS() &&
6485 RHS.get() == E->getRHS())
6486 return SemaRef.Owned(E);
6488 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
6489 LHS.get(), RHS.get());
6492 template<typename Derived>
6494 TreeTransform<Derived>::TransformCompoundAssignOperator(
6495 CompoundAssignOperator *E) {
6496 return getDerived().TransformBinaryOperator(E);
6499 template<typename Derived>
6500 ExprResult TreeTransform<Derived>::
6501 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6502 // Just rebuild the common and RHS expressions and see whether we
6505 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6506 if (commonExpr.isInvalid())
6509 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6510 if (rhs.isInvalid())
6513 if (!getDerived().AlwaysRebuild() &&
6514 commonExpr.get() == e->getCommon() &&
6515 rhs.get() == e->getFalseExpr())
6516 return SemaRef.Owned(e);
6518 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6519 e->getQuestionLoc(),
6525 template<typename Derived>
6527 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
6528 ExprResult Cond = getDerived().TransformExpr(E->getCond());
6529 if (Cond.isInvalid())
6532 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6533 if (LHS.isInvalid())
6536 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6537 if (RHS.isInvalid())
6540 if (!getDerived().AlwaysRebuild() &&
6541 Cond.get() == E->getCond() &&
6542 LHS.get() == E->getLHS() &&
6543 RHS.get() == E->getRHS())
6544 return SemaRef.Owned(E);
6546 return getDerived().RebuildConditionalOperator(Cond.get(),
6547 E->getQuestionLoc(),
6553 template<typename Derived>
6555 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6556 // Implicit casts are eliminated during transformation, since they
6557 // will be recomputed by semantic analysis after transformation.
6558 return getDerived().TransformExpr(E->getSubExprAsWritten());
6561 template<typename Derived>
6563 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6564 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6569 = getDerived().TransformExpr(E->getSubExprAsWritten());
6570 if (SubExpr.isInvalid())
6573 if (!getDerived().AlwaysRebuild() &&
6574 Type == E->getTypeInfoAsWritten() &&
6575 SubExpr.get() == E->getSubExpr())
6576 return SemaRef.Owned(E);
6578 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6584 template<typename Derived>
6586 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
6587 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6588 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6592 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6593 if (Init.isInvalid())
6596 if (!getDerived().AlwaysRebuild() &&
6598 Init.get() == E->getInitializer())
6599 return SemaRef.MaybeBindToTemporary(E);
6601 // Note: the expression type doesn't necessarily match the
6602 // type-as-written, but that's okay, because it should always be
6603 // derivable from the initializer.
6605 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6606 /*FIXME:*/E->getInitializer()->getLocEnd(),
6610 template<typename Derived>
6612 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
6613 ExprResult Base = getDerived().TransformExpr(E->getBase());
6614 if (Base.isInvalid())
6617 if (!getDerived().AlwaysRebuild() &&
6618 Base.get() == E->getBase())
6619 return SemaRef.Owned(E);
6621 // FIXME: Bad source location
6622 SourceLocation FakeOperatorLoc
6623 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
6624 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6625 E->getAccessorLoc(),
6629 template<typename Derived>
6631 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6632 bool InitChanged = false;
6634 ASTOwningVector<Expr*, 4> Inits(SemaRef);
6635 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6636 Inits, &InitChanged))
6639 if (!getDerived().AlwaysRebuild() && !InitChanged)
6640 return SemaRef.Owned(E);
6642 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
6643 E->getRBraceLoc(), E->getType());
6646 template<typename Derived>
6648 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
6651 // transform the initializer value
6652 ExprResult Init = getDerived().TransformExpr(E->getInit());
6653 if (Init.isInvalid())
6656 // transform the designators.
6657 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
6658 bool ExprChanged = false;
6659 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6660 DEnd = E->designators_end();
6662 if (D->isFieldDesignator()) {
6663 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6669 if (D->isArrayDesignator()) {
6670 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
6671 if (Index.isInvalid())
6674 Desig.AddDesignator(Designator::getArray(Index.get(),
6675 D->getLBracketLoc()));
6677 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6678 ArrayExprs.push_back(Index.release());
6682 assert(D->isArrayRangeDesignator() && "New kind of designator?");
6684 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6685 if (Start.isInvalid())
6688 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
6689 if (End.isInvalid())
6692 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
6694 D->getLBracketLoc(),
6695 D->getEllipsisLoc()));
6697 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6698 End.get() != E->getArrayRangeEnd(*D);
6700 ArrayExprs.push_back(Start.release());
6701 ArrayExprs.push_back(End.release());
6704 if (!getDerived().AlwaysRebuild() &&
6705 Init.get() == E->getInit() &&
6707 return SemaRef.Owned(E);
6709 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6710 E->getEqualOrColonLoc(),
6711 E->usesGNUSyntax(), Init.get());
6714 template<typename Derived>
6716 TreeTransform<Derived>::TransformImplicitValueInitExpr(
6717 ImplicitValueInitExpr *E) {
6718 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
6720 // FIXME: Will we ever have proper type location here? Will we actually
6721 // need to transform the type?
6722 QualType T = getDerived().TransformType(E->getType());
6726 if (!getDerived().AlwaysRebuild() &&
6728 return SemaRef.Owned(E);
6730 return getDerived().RebuildImplicitValueInitExpr(T);
6733 template<typename Derived>
6735 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
6736 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6740 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6741 if (SubExpr.isInvalid())
6744 if (!getDerived().AlwaysRebuild() &&
6745 TInfo == E->getWrittenTypeInfo() &&
6746 SubExpr.get() == E->getSubExpr())
6747 return SemaRef.Owned(E);
6749 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
6750 TInfo, E->getRParenLoc());
6753 template<typename Derived>
6755 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
6756 bool ArgumentChanged = false;
6757 ASTOwningVector<Expr*, 4> Inits(SemaRef);
6758 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6762 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6767 /// \brief Transform an address-of-label expression.
6769 /// By default, the transformation of an address-of-label expression always
6770 /// rebuilds the expression, so that the label identifier can be resolved to
6771 /// the corresponding label statement by semantic analysis.
6772 template<typename Derived>
6774 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
6775 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6780 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
6781 cast<LabelDecl>(LD));
6784 template<typename Derived>
6786 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
6787 SemaRef.ActOnStartStmtExpr();
6789 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6790 if (SubStmt.isInvalid()) {
6791 SemaRef.ActOnStmtExprError();
6795 if (!getDerived().AlwaysRebuild() &&
6796 SubStmt.get() == E->getSubStmt()) {
6797 // Calling this an 'error' is unintuitive, but it does the right thing.
6798 SemaRef.ActOnStmtExprError();
6799 return SemaRef.MaybeBindToTemporary(E);
6802 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
6807 template<typename Derived>
6809 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
6810 ExprResult Cond = getDerived().TransformExpr(E->getCond());
6811 if (Cond.isInvalid())
6814 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6815 if (LHS.isInvalid())
6818 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6819 if (RHS.isInvalid())
6822 if (!getDerived().AlwaysRebuild() &&
6823 Cond.get() == E->getCond() &&
6824 LHS.get() == E->getLHS() &&
6825 RHS.get() == E->getRHS())
6826 return SemaRef.Owned(E);
6828 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
6829 Cond.get(), LHS.get(), RHS.get(),
6833 template<typename Derived>
6835 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
6836 return SemaRef.Owned(E);
6839 template<typename Derived>
6841 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
6842 switch (E->getOperator()) {
6846 case OO_Array_Delete:
6847 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
6850 // This is a call to an object's operator().
6851 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6853 // Transform the object itself.
6854 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
6855 if (Object.isInvalid())
6858 // FIXME: Poor location information
6859 SourceLocation FakeLParenLoc
6860 = SemaRef.PP.getLocForEndOfToken(
6861 static_cast<Expr *>(Object.get())->getLocEnd());
6863 // Transform the call arguments.
6864 ASTOwningVector<Expr*> Args(SemaRef);
6865 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6869 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
6874 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6876 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6877 #include "clang/Basic/OperatorKinds.def"
6882 case OO_Conditional:
6883 llvm_unreachable("conditional operator is not actually overloadable");
6886 case NUM_OVERLOADED_OPERATORS:
6887 llvm_unreachable("not an overloaded operator?");
6890 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6891 if (Callee.isInvalid())
6894 ExprResult First = getDerived().TransformExpr(E->getArg(0));
6895 if (First.isInvalid())
6899 if (E->getNumArgs() == 2) {
6900 Second = getDerived().TransformExpr(E->getArg(1));
6901 if (Second.isInvalid())
6905 if (!getDerived().AlwaysRebuild() &&
6906 Callee.get() == E->getCallee() &&
6907 First.get() == E->getArg(0) &&
6908 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
6909 return SemaRef.MaybeBindToTemporary(E);
6911 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6912 E->getOperatorLoc(),
6918 template<typename Derived>
6920 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6921 return getDerived().TransformCallExpr(E);
6924 template<typename Derived>
6926 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6927 // Transform the callee.
6928 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6929 if (Callee.isInvalid())
6932 // Transform exec config.
6933 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6937 // Transform arguments.
6938 bool ArgChanged = false;
6939 ASTOwningVector<Expr*> Args(SemaRef);
6940 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6944 if (!getDerived().AlwaysRebuild() &&
6945 Callee.get() == E->getCallee() &&
6947 return SemaRef.MaybeBindToTemporary(E);
6949 // FIXME: Wrong source location information for the '('.
6950 SourceLocation FakeLParenLoc
6951 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6952 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6954 E->getRParenLoc(), EC.get());
6957 template<typename Derived>
6959 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
6960 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6965 = getDerived().TransformExpr(E->getSubExprAsWritten());
6966 if (SubExpr.isInvalid())
6969 if (!getDerived().AlwaysRebuild() &&
6970 Type == E->getTypeInfoAsWritten() &&
6971 SubExpr.get() == E->getSubExpr())
6972 return SemaRef.Owned(E);
6974 // FIXME: Poor source location information here.
6975 SourceLocation FakeLAngleLoc
6976 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6977 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6978 SourceLocation FakeRParenLoc
6979 = SemaRef.PP.getLocForEndOfToken(
6980 E->getSubExpr()->getSourceRange().getEnd());
6981 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
6991 template<typename Derived>
6993 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6994 return getDerived().TransformCXXNamedCastExpr(E);
6997 template<typename Derived>
6999 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7000 return getDerived().TransformCXXNamedCastExpr(E);
7003 template<typename Derived>
7005 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
7006 CXXReinterpretCastExpr *E) {
7007 return getDerived().TransformCXXNamedCastExpr(E);
7010 template<typename Derived>
7012 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7013 return getDerived().TransformCXXNamedCastExpr(E);
7016 template<typename Derived>
7018 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
7019 CXXFunctionalCastExpr *E) {
7020 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7025 = getDerived().TransformExpr(E->getSubExprAsWritten());
7026 if (SubExpr.isInvalid())
7029 if (!getDerived().AlwaysRebuild() &&
7030 Type == E->getTypeInfoAsWritten() &&
7031 SubExpr.get() == E->getSubExpr())
7032 return SemaRef.Owned(E);
7034 return getDerived().RebuildCXXFunctionalCastExpr(Type,
7035 /*FIXME:*/E->getSubExpr()->getLocStart(),
7040 template<typename Derived>
7042 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
7043 if (E->isTypeOperand()) {
7044 TypeSourceInfo *TInfo
7045 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7049 if (!getDerived().AlwaysRebuild() &&
7050 TInfo == E->getTypeOperandSourceInfo())
7051 return SemaRef.Owned(E);
7053 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7059 // We don't know whether the subexpression is potentially evaluated until
7060 // after we perform semantic analysis. We speculatively assume it is
7061 // unevaluated; it will get fixed later if the subexpression is in fact
7062 // potentially evaluated.
7063 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7065 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7066 if (SubExpr.isInvalid())
7069 if (!getDerived().AlwaysRebuild() &&
7070 SubExpr.get() == E->getExprOperand())
7071 return SemaRef.Owned(E);
7073 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7079 template<typename Derived>
7081 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7082 if (E->isTypeOperand()) {
7083 TypeSourceInfo *TInfo
7084 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7088 if (!getDerived().AlwaysRebuild() &&
7089 TInfo == E->getTypeOperandSourceInfo())
7090 return SemaRef.Owned(E);
7092 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7098 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7100 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7101 if (SubExpr.isInvalid())
7104 if (!getDerived().AlwaysRebuild() &&
7105 SubExpr.get() == E->getExprOperand())
7106 return SemaRef.Owned(E);
7108 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7114 template<typename Derived>
7116 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
7117 return SemaRef.Owned(E);
7120 template<typename Derived>
7122 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
7123 CXXNullPtrLiteralExpr *E) {
7124 return SemaRef.Owned(E);
7127 template<typename Derived>
7129 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
7130 DeclContext *DC = getSema().getFunctionLevelDeclContext();
7132 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7133 T = MD->getThisType(getSema().Context);
7135 T = getSema().Context.getPointerType(
7136 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
7138 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7139 // Make sure that we capture 'this'.
7140 getSema().CheckCXXThisCapture(E->getLocStart());
7141 return SemaRef.Owned(E);
7144 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
7147 template<typename Derived>
7149 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
7150 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7151 if (SubExpr.isInvalid())
7154 if (!getDerived().AlwaysRebuild() &&
7155 SubExpr.get() == E->getSubExpr())
7156 return SemaRef.Owned(E);
7158 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7159 E->isThrownVariableInScope());
7162 template<typename Derived>
7164 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
7166 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7171 if (!getDerived().AlwaysRebuild() &&
7172 Param == E->getParam())
7173 return SemaRef.Owned(E);
7175 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
7178 template<typename Derived>
7180 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7181 CXXScalarValueInitExpr *E) {
7182 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7186 if (!getDerived().AlwaysRebuild() &&
7187 T == E->getTypeSourceInfo())
7188 return SemaRef.Owned(E);
7190 return getDerived().RebuildCXXScalarValueInitExpr(T,
7191 /*FIXME:*/T->getTypeLoc().getEndLoc(),
7195 template<typename Derived>
7197 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
7198 // Transform the type that we're allocating
7199 TypeSourceInfo *AllocTypeInfo
7200 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7204 // Transform the size of the array we're allocating (if any).
7205 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
7206 if (ArraySize.isInvalid())
7209 // Transform the placement arguments (if any).
7210 bool ArgumentChanged = false;
7211 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
7212 if (getDerived().TransformExprs(E->getPlacementArgs(),
7213 E->getNumPlacementArgs(), true,
7214 PlacementArgs, &ArgumentChanged))
7217 // Transform the initializer (if any).
7218 Expr *OldInit = E->getInitializer();
7221 NewInit = getDerived().TransformExpr(OldInit);
7222 if (NewInit.isInvalid())
7225 // Transform new operator and delete operator.
7226 FunctionDecl *OperatorNew = 0;
7227 if (E->getOperatorNew()) {
7228 OperatorNew = cast_or_null<FunctionDecl>(
7229 getDerived().TransformDecl(E->getLocStart(),
7230 E->getOperatorNew()));
7235 FunctionDecl *OperatorDelete = 0;
7236 if (E->getOperatorDelete()) {
7237 OperatorDelete = cast_or_null<FunctionDecl>(
7238 getDerived().TransformDecl(E->getLocStart(),
7239 E->getOperatorDelete()));
7240 if (!OperatorDelete)
7244 if (!getDerived().AlwaysRebuild() &&
7245 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
7246 ArraySize.get() == E->getArraySize() &&
7247 NewInit.get() == OldInit &&
7248 OperatorNew == E->getOperatorNew() &&
7249 OperatorDelete == E->getOperatorDelete() &&
7251 // Mark any declarations we need as referenced.
7252 // FIXME: instantiation-specific.
7254 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
7256 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
7258 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
7259 QualType ElementType
7260 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7261 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7262 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7263 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7264 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
7269 return SemaRef.Owned(E);
7272 QualType AllocType = AllocTypeInfo->getType();
7273 if (!ArraySize.get()) {
7274 // If no array size was specified, but the new expression was
7275 // instantiated with an array type (e.g., "new T" where T is
7276 // instantiated with "int[4]"), extract the outer bound from the
7277 // array type as our array size. We do this with constant and
7278 // dependently-sized array types.
7279 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7282 } else if (const ConstantArrayType *ConsArrayT
7283 = dyn_cast<ConstantArrayType>(ArrayT)) {
7285 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7286 ConsArrayT->getSize(),
7287 SemaRef.Context.getSizeType(),
7288 /*FIXME:*/E->getLocStart()));
7289 AllocType = ConsArrayT->getElementType();
7290 } else if (const DependentSizedArrayType *DepArrayT
7291 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7292 if (DepArrayT->getSizeExpr()) {
7293 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
7294 AllocType = DepArrayT->getElementType();
7299 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7301 /*FIXME:*/E->getLocStart(),
7302 move_arg(PlacementArgs),
7303 /*FIXME:*/E->getLocStart(),
7304 E->getTypeIdParens(),
7308 E->getDirectInitRange(),
7312 template<typename Derived>
7314 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
7315 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
7316 if (Operand.isInvalid())
7319 // Transform the delete operator, if known.
7320 FunctionDecl *OperatorDelete = 0;
7321 if (E->getOperatorDelete()) {
7322 OperatorDelete = cast_or_null<FunctionDecl>(
7323 getDerived().TransformDecl(E->getLocStart(),
7324 E->getOperatorDelete()));
7325 if (!OperatorDelete)
7329 if (!getDerived().AlwaysRebuild() &&
7330 Operand.get() == E->getArgument() &&
7331 OperatorDelete == E->getOperatorDelete()) {
7332 // Mark any declarations we need as referenced.
7333 // FIXME: instantiation-specific.
7335 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
7337 if (!E->getArgument()->isTypeDependent()) {
7338 QualType Destroyed = SemaRef.Context.getBaseElementType(
7339 E->getDestroyedType());
7340 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7341 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7342 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7343 SemaRef.LookupDestructor(Record));
7347 return SemaRef.Owned(E);
7350 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7351 E->isGlobalDelete(),
7356 template<typename Derived>
7358 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
7359 CXXPseudoDestructorExpr *E) {
7360 ExprResult Base = getDerived().TransformExpr(E->getBase());
7361 if (Base.isInvalid())
7364 ParsedType ObjectTypePtr;
7365 bool MayBePseudoDestructor = false;
7366 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7367 E->getOperatorLoc(),
7368 E->isArrow()? tok::arrow : tok::period,
7370 MayBePseudoDestructor);
7371 if (Base.isInvalid())
7374 QualType ObjectType = ObjectTypePtr.get();
7375 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7378 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7383 SS.Adopt(QualifierLoc);
7385 PseudoDestructorTypeStorage Destroyed;
7386 if (E->getDestroyedTypeInfo()) {
7387 TypeSourceInfo *DestroyedTypeInfo
7388 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7390 if (!DestroyedTypeInfo)
7392 Destroyed = DestroyedTypeInfo;
7393 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
7394 // We aren't likely to be able to resolve the identifier down to a type
7395 // now anyway, so just retain the identifier.
7396 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7397 E->getDestroyedTypeLoc());
7399 // Look for a destructor known with the given name.
7400 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7401 *E->getDestroyedTypeIdentifier(),
7402 E->getDestroyedTypeLoc(),
7410 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7411 E->getDestroyedTypeLoc());
7414 TypeSourceInfo *ScopeTypeInfo = 0;
7415 if (E->getScopeTypeInfo()) {
7416 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
7421 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7422 E->getOperatorLoc(),
7426 E->getColonColonLoc(),
7431 template<typename Derived>
7433 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
7434 UnresolvedLookupExpr *Old) {
7435 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7436 Sema::LookupOrdinaryName);
7438 // Transform all the decls.
7439 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7440 E = Old->decls_end(); I != E; ++I) {
7441 NamedDecl *InstD = static_cast<NamedDecl*>(
7442 getDerived().TransformDecl(Old->getNameLoc(),
7445 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7446 // This can happen because of dependent hiding.
7447 if (isa<UsingShadowDecl>(*I))
7453 // Expand using declarations.
7454 if (isa<UsingDecl>(InstD)) {
7455 UsingDecl *UD = cast<UsingDecl>(InstD);
7456 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7457 E = UD->shadow_end(); I != E; ++I)
7465 // Resolve a kind, but don't do any further analysis. If it's
7466 // ambiguous, the callee needs to deal with it.
7469 // Rebuild the nested-name qualifier, if present.
7471 if (Old->getQualifierLoc()) {
7472 NestedNameSpecifierLoc QualifierLoc
7473 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7477 SS.Adopt(QualifierLoc);
7480 if (Old->getNamingClass()) {
7481 CXXRecordDecl *NamingClass
7482 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7484 Old->getNamingClass()));
7488 R.setNamingClass(NamingClass);
7491 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7493 // If we have neither explicit template arguments, nor the template keyword,
7494 // it's a normal declaration name.
7495 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
7496 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7498 // If we have template arguments, rebuild them, then rebuild the
7499 // templateid expression.
7500 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
7501 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7502 Old->getNumTemplateArgs(),
7506 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
7507 Old->requiresADL(), &TransArgs);
7510 template<typename Derived>
7512 TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
7513 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7517 if (!getDerived().AlwaysRebuild() &&
7518 T == E->getQueriedTypeSourceInfo())
7519 return SemaRef.Owned(E);
7521 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7527 template<typename Derived>
7529 TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7530 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7534 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7538 if (!getDerived().AlwaysRebuild() &&
7539 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7540 return SemaRef.Owned(E);
7542 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7548 template<typename Derived>
7550 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7551 bool ArgChanged = false;
7552 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7553 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7554 TypeSourceInfo *From = E->getArg(I);
7555 TypeLoc FromTL = From->getTypeLoc();
7556 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7558 TLB.reserve(FromTL.getFullDataSize());
7559 QualType To = getDerived().TransformType(TLB, FromTL);
7563 if (To == From->getType())
7564 Args.push_back(From);
7566 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7574 // We have a pack expansion. Instantiate it.
7575 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7576 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7577 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7578 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7580 // Determine whether the set of unexpanded parameter packs can and should
7583 bool RetainExpansion = false;
7584 llvm::Optional<unsigned> OrigNumExpansions
7585 = ExpansionTL.getTypePtr()->getNumExpansions();
7586 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7587 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7588 PatternTL.getSourceRange(),
7590 Expand, RetainExpansion,
7595 // The transform has determined that we should perform a simple
7596 // transformation on the pack expansion, producing another pack
7598 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7601 TLB.reserve(From->getTypeLoc().getFullDataSize());
7603 QualType To = getDerived().TransformType(TLB, PatternTL);
7607 To = getDerived().RebuildPackExpansionType(To,
7608 PatternTL.getSourceRange(),
7609 ExpansionTL.getEllipsisLoc(),
7614 PackExpansionTypeLoc ToExpansionTL
7615 = TLB.push<PackExpansionTypeLoc>(To);
7616 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7617 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7621 // Expand the pack expansion by substituting for each argument in the
7623 for (unsigned I = 0; I != *NumExpansions; ++I) {
7624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7626 TLB.reserve(PatternTL.getFullDataSize());
7627 QualType To = getDerived().TransformType(TLB, PatternTL);
7631 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7634 if (!RetainExpansion)
7637 // If we're supposed to retain a pack expansion, do so by temporarily
7638 // forgetting the partially-substituted parameter pack.
7639 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7642 TLB.reserve(From->getTypeLoc().getFullDataSize());
7644 QualType To = getDerived().TransformType(TLB, PatternTL);
7648 To = getDerived().RebuildPackExpansionType(To,
7649 PatternTL.getSourceRange(),
7650 ExpansionTL.getEllipsisLoc(),
7655 PackExpansionTypeLoc ToExpansionTL
7656 = TLB.push<PackExpansionTypeLoc>(To);
7657 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7658 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7661 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7662 return SemaRef.Owned(E);
7664 return getDerived().RebuildTypeTrait(E->getTrait(),
7670 template<typename Derived>
7672 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7673 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7677 if (!getDerived().AlwaysRebuild() &&
7678 T == E->getQueriedTypeSourceInfo())
7679 return SemaRef.Owned(E);
7683 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7684 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7685 if (SubExpr.isInvalid())
7688 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7689 return SemaRef.Owned(E);
7692 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7699 template<typename Derived>
7701 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7704 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7705 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7706 if (SubExpr.isInvalid())
7709 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7710 return SemaRef.Owned(E);
7713 return getDerived().RebuildExpressionTrait(
7714 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7717 template<typename Derived>
7719 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7720 DependentScopeDeclRefExpr *E) {
7721 NestedNameSpecifierLoc QualifierLoc
7722 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7725 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
7727 // TODO: If this is a conversion-function-id, verify that the
7728 // destination type name (if present) resolves the same way after
7729 // instantiation as it did in the local scope.
7731 DeclarationNameInfo NameInfo
7732 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7733 if (!NameInfo.getName())
7736 if (!E->hasExplicitTemplateArgs()) {
7737 if (!getDerived().AlwaysRebuild() &&
7738 QualifierLoc == E->getQualifierLoc() &&
7739 // Note: it is sufficient to compare the Name component of NameInfo:
7740 // if name has not changed, DNLoc has not changed either.
7741 NameInfo.getName() == E->getDeclName())
7742 return SemaRef.Owned(E);
7744 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
7747 /*TemplateArgs*/ 0);
7750 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7751 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7752 E->getNumTemplateArgs(),
7756 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
7762 template<typename Derived>
7764 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
7765 // CXXConstructExprs are always implicit, so when we have a
7766 // 1-argument construction we just transform that argument.
7767 if (E->getNumArgs() == 1 ||
7768 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7769 return getDerived().TransformExpr(E->getArg(0));
7771 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7773 QualType T = getDerived().TransformType(E->getType());
7777 CXXConstructorDecl *Constructor
7778 = cast_or_null<CXXConstructorDecl>(
7779 getDerived().TransformDecl(E->getLocStart(),
7780 E->getConstructor()));
7784 bool ArgumentChanged = false;
7785 ASTOwningVector<Expr*> Args(SemaRef);
7786 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7790 if (!getDerived().AlwaysRebuild() &&
7791 T == E->getType() &&
7792 Constructor == E->getConstructor() &&
7794 // Mark the constructor as referenced.
7795 // FIXME: Instantiation-specific
7796 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
7797 return SemaRef.Owned(E);
7800 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7801 Constructor, E->isElidable(),
7803 E->hadMultipleCandidates(),
7804 E->requiresZeroInitialization(),
7805 E->getConstructionKind(),
7806 E->getParenRange());
7809 /// \brief Transform a C++ temporary-binding expression.
7811 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7812 /// transform the subexpression and return that.
7813 template<typename Derived>
7815 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
7816 return getDerived().TransformExpr(E->getSubExpr());
7819 /// \brief Transform a C++ expression that contains cleanups that should
7820 /// be run after the expression is evaluated.
7822 /// Since ExprWithCleanups nodes are implicitly generated, we
7823 /// just transform the subexpression and return that.
7824 template<typename Derived>
7826 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
7827 return getDerived().TransformExpr(E->getSubExpr());
7830 template<typename Derived>
7832 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
7833 CXXTemporaryObjectExpr *E) {
7834 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7838 CXXConstructorDecl *Constructor
7839 = cast_or_null<CXXConstructorDecl>(
7840 getDerived().TransformDecl(E->getLocStart(),
7841 E->getConstructor()));
7845 bool ArgumentChanged = false;
7846 ASTOwningVector<Expr*> Args(SemaRef);
7847 Args.reserve(E->getNumArgs());
7848 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7852 if (!getDerived().AlwaysRebuild() &&
7853 T == E->getTypeSourceInfo() &&
7854 Constructor == E->getConstructor() &&
7856 // FIXME: Instantiation-specific
7857 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
7858 return SemaRef.MaybeBindToTemporary(E);
7861 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7862 /*FIXME:*/T->getTypeLoc().getEndLoc(),
7867 template<typename Derived>
7869 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
7870 // Create the local class that will describe the lambda.
7871 CXXRecordDecl *Class
7872 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7873 /*KnownDependent=*/false);
7874 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7876 // Transform the type of the lambda parameters and start the definition of
7877 // the lambda itself.
7878 TypeSourceInfo *MethodTy
7879 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7883 // Transform lambda parameters.
7884 bool Invalid = false;
7885 llvm::SmallVector<QualType, 4> ParamTypes;
7886 llvm::SmallVector<ParmVarDecl *, 4> Params;
7887 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7888 E->getCallOperator()->param_begin(),
7889 E->getCallOperator()->param_size(),
7890 0, ParamTypes, &Params))
7893 // Build the call operator.
7894 // Note: Once a lambda mangling number and context declaration have been
7895 // assigned, they never change.
7896 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7897 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
7898 CXXMethodDecl *CallOperator
7899 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7901 E->getCallOperator()->getLocEnd(),
7902 Params, ManglingNumber, ContextDecl);
7903 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7905 // FIXME: Instantiation-specific.
7906 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7907 TSK_ImplicitInstantiation);
7909 // Introduce the context of the call operator.
7910 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7912 // Enter the scope of the lambda.
7913 sema::LambdaScopeInfo *LSI
7914 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7915 E->getCaptureDefault(),
7916 E->hasExplicitParameters(),
7917 E->hasExplicitResultType(),
7920 // Transform captures.
7921 bool FinishedExplicitCaptures = false;
7922 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7923 CEnd = E->capture_end();
7925 // When we hit the first implicit capture, tell Sema that we've finished
7926 // the list of explicit captures.
7927 if (!FinishedExplicitCaptures && C->isImplicit()) {
7928 getSema().finishLambdaExplicitCaptures(LSI);
7929 FinishedExplicitCaptures = true;
7932 // Capturing 'this' is trivial.
7933 if (C->capturesThis()) {
7934 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7938 // Determine the capture kind for Sema.
7939 Sema::TryCaptureKind Kind
7940 = C->isImplicit()? Sema::TryCapture_Implicit
7941 : C->getCaptureKind() == LCK_ByCopy
7942 ? Sema::TryCapture_ExplicitByVal
7943 : Sema::TryCapture_ExplicitByRef;
7944 SourceLocation EllipsisLoc;
7945 if (C->isPackExpansion()) {
7946 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7947 bool ShouldExpand = false;
7948 bool RetainExpansion = false;
7949 llvm::Optional<unsigned> NumExpansions;
7950 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7953 ShouldExpand, RetainExpansion,
7958 // The transform has determined that we should perform an expansion;
7959 // transform and capture each of the arguments.
7960 // expansion of the pattern. Do so.
7961 VarDecl *Pack = C->getCapturedVar();
7962 for (unsigned I = 0; I != *NumExpansions; ++I) {
7963 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7964 VarDecl *CapturedVar
7965 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7972 // Capture the transformed variable.
7973 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7978 EllipsisLoc = C->getEllipsisLoc();
7981 // Transform the captured variable.
7982 VarDecl *CapturedVar
7983 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7984 C->getCapturedVar()));
7990 // Capture the transformed variable.
7991 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7993 if (!FinishedExplicitCaptures)
7994 getSema().finishLambdaExplicitCaptures(LSI);
7997 // Enter a new evaluation context to insulate the lambda from any
7998 // cleanups from the enclosing full-expression.
7999 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8002 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8003 /*IsInstantiation=*/true);
8007 // Instantiate the body of the lambda expression.
8008 StmtResult Body = getDerived().TransformStmt(E->getBody());
8009 if (Body.isInvalid()) {
8010 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8011 /*IsInstantiation=*/true);
8015 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
8016 /*CurScope=*/0, /*IsInstantiation=*/true);
8019 template<typename Derived>
8021 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
8022 CXXUnresolvedConstructExpr *E) {
8023 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8027 bool ArgumentChanged = false;
8028 ASTOwningVector<Expr*> Args(SemaRef);
8029 Args.reserve(E->arg_size());
8030 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8034 if (!getDerived().AlwaysRebuild() &&
8035 T == E->getTypeSourceInfo() &&
8037 return SemaRef.Owned(E);
8039 // FIXME: we're faking the locations of the commas
8040 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
8046 template<typename Derived>
8048 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
8049 CXXDependentScopeMemberExpr *E) {
8050 // Transform the base of the expression.
8051 ExprResult Base((Expr*) 0);
8054 QualType ObjectType;
8055 if (!E->isImplicitAccess()) {
8056 OldBase = E->getBase();
8057 Base = getDerived().TransformExpr(OldBase);
8058 if (Base.isInvalid())
8061 // Start the member reference and compute the object's type.
8062 ParsedType ObjectTy;
8063 bool MayBePseudoDestructor = false;
8064 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
8065 E->getOperatorLoc(),
8066 E->isArrow()? tok::arrow : tok::period,
8068 MayBePseudoDestructor);
8069 if (Base.isInvalid())
8072 ObjectType = ObjectTy.get();
8073 BaseType = ((Expr*) Base.get())->getType();
8076 BaseType = getDerived().TransformType(E->getBaseType());
8077 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8080 // Transform the first part of the nested-name-specifier that qualifies
8082 NamedDecl *FirstQualifierInScope
8083 = getDerived().TransformFirstQualifierInScope(
8084 E->getFirstQualifierFoundInScope(),
8085 E->getQualifierLoc().getBeginLoc());
8087 NestedNameSpecifierLoc QualifierLoc;
8088 if (E->getQualifier()) {
8090 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8092 FirstQualifierInScope);
8097 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8099 // TODO: If this is a conversion-function-id, verify that the
8100 // destination type name (if present) resolves the same way after
8101 // instantiation as it did in the local scope.
8103 DeclarationNameInfo NameInfo
8104 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
8105 if (!NameInfo.getName())
8108 if (!E->hasExplicitTemplateArgs()) {
8109 // This is a reference to a member without an explicitly-specified
8110 // template argument list. Optimize for this common case.
8111 if (!getDerived().AlwaysRebuild() &&
8112 Base.get() == OldBase &&
8113 BaseType == E->getBaseType() &&
8114 QualifierLoc == E->getQualifierLoc() &&
8115 NameInfo.getName() == E->getMember() &&
8116 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
8117 return SemaRef.Owned(E);
8119 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8122 E->getOperatorLoc(),
8125 FirstQualifierInScope,
8127 /*TemplateArgs*/ 0);
8130 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8131 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8132 E->getNumTemplateArgs(),
8136 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8139 E->getOperatorLoc(),
8142 FirstQualifierInScope,
8147 template<typename Derived>
8149 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
8150 // Transform the base of the expression.
8151 ExprResult Base((Expr*) 0);
8153 if (!Old->isImplicitAccess()) {
8154 Base = getDerived().TransformExpr(Old->getBase());
8155 if (Base.isInvalid())
8157 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8159 if (Base.isInvalid())
8161 BaseType = Base.get()->getType();
8163 BaseType = getDerived().TransformType(Old->getBaseType());
8166 NestedNameSpecifierLoc QualifierLoc;
8167 if (Old->getQualifierLoc()) {
8169 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8174 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8176 LookupResult R(SemaRef, Old->getMemberNameInfo(),
8177 Sema::LookupOrdinaryName);
8179 // Transform all the decls.
8180 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8181 E = Old->decls_end(); I != E; ++I) {
8182 NamedDecl *InstD = static_cast<NamedDecl*>(
8183 getDerived().TransformDecl(Old->getMemberLoc(),
8186 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8187 // This can happen because of dependent hiding.
8188 if (isa<UsingShadowDecl>(*I))
8196 // Expand using declarations.
8197 if (isa<UsingDecl>(InstD)) {
8198 UsingDecl *UD = cast<UsingDecl>(InstD);
8199 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8200 E = UD->shadow_end(); I != E; ++I)
8210 // Determine the naming class.
8211 if (Old->getNamingClass()) {
8212 CXXRecordDecl *NamingClass
8213 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8214 Old->getMemberLoc(),
8215 Old->getNamingClass()));
8219 R.setNamingClass(NamingClass);
8222 TemplateArgumentListInfo TransArgs;
8223 if (Old->hasExplicitTemplateArgs()) {
8224 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8225 TransArgs.setRAngleLoc(Old->getRAngleLoc());
8226 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8227 Old->getNumTemplateArgs(),
8232 // FIXME: to do this check properly, we will need to preserve the
8233 // first-qualifier-in-scope here, just in case we had a dependent
8234 // base (and therefore couldn't do the check) and a
8235 // nested-name-qualifier (and therefore could do the lookup).
8236 NamedDecl *FirstQualifierInScope = 0;
8238 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
8240 Old->getOperatorLoc(),
8244 FirstQualifierInScope,
8246 (Old->hasExplicitTemplateArgs()
8250 template<typename Derived>
8252 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
8253 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8254 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8255 if (SubExpr.isInvalid())
8258 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
8259 return SemaRef.Owned(E);
8261 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8264 template<typename Derived>
8266 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
8267 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8268 if (Pattern.isInvalid())
8271 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8272 return SemaRef.Owned(E);
8274 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8275 E->getNumExpansions());
8278 template<typename Derived>
8280 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8281 // If E is not value-dependent, then nothing will change when we transform it.
8282 // Note: This is an instantiation-centric view.
8283 if (!E->isValueDependent())
8284 return SemaRef.Owned(E);
8286 // Note: None of the implementations of TryExpandParameterPacks can ever
8287 // produce a diagnostic when given only a single unexpanded parameter pack,
8289 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8290 bool ShouldExpand = false;
8291 bool RetainExpansion = false;
8292 llvm::Optional<unsigned> NumExpansions;
8293 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
8295 ShouldExpand, RetainExpansion,
8299 if (RetainExpansion)
8300 return SemaRef.Owned(E);
8302 NamedDecl *Pack = E->getPack();
8303 if (!ShouldExpand) {
8304 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8311 // We now know the length of the parameter pack, so build a new expression
8312 // that stores that length.
8313 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8314 E->getPackLoc(), E->getRParenLoc(),
8318 template<typename Derived>
8320 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8321 SubstNonTypeTemplateParmPackExpr *E) {
8322 // Default behavior is to do nothing with this transformation.
8323 return SemaRef.Owned(E);
8326 template<typename Derived>
8328 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8329 SubstNonTypeTemplateParmExpr *E) {
8330 // Default behavior is to do nothing with this transformation.
8331 return SemaRef.Owned(E);
8334 template<typename Derived>
8336 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8337 MaterializeTemporaryExpr *E) {
8338 return getDerived().TransformExpr(E->GetTemporaryExpr());
8341 template<typename Derived>
8343 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
8344 return SemaRef.MaybeBindToTemporary(E);
8347 template<typename Derived>
8349 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
8350 return SemaRef.Owned(E);
8353 template<typename Derived>
8355 TreeTransform<Derived>::TransformObjCNumericLiteral(ObjCNumericLiteral *E) {
8356 return SemaRef.MaybeBindToTemporary(E);
8359 template<typename Derived>
8361 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8362 // Transform each of the elements.
8363 llvm::SmallVector<Expr *, 8> Elements;
8364 bool ArgChanged = false;
8365 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8366 /*IsCall=*/false, Elements, &ArgChanged))
8369 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8370 return SemaRef.MaybeBindToTemporary(E);
8372 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8377 template<typename Derived>
8379 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8380 ObjCDictionaryLiteral *E) {
8381 // Transform each of the elements.
8382 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8383 bool ArgChanged = false;
8384 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8385 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8387 if (OrigElement.isPackExpansion()) {
8388 // This key/value element is a pack expansion.
8389 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8390 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8391 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8392 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8394 // Determine whether the set of unexpanded parameter packs can
8395 // and should be expanded.
8397 bool RetainExpansion = false;
8398 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8399 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8400 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8401 OrigElement.Value->getLocEnd());
8402 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8405 Expand, RetainExpansion,
8410 // The transform has determined that we should perform a simple
8411 // transformation on the pack expansion, producing another pack
8413 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8414 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8415 if (Key.isInvalid())
8418 if (Key.get() != OrigElement.Key)
8421 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8422 if (Value.isInvalid())
8425 if (Value.get() != OrigElement.Value)
8428 ObjCDictionaryElement Expansion = {
8429 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8431 Elements.push_back(Expansion);
8435 // Record right away that the argument was changed. This needs
8436 // to happen even if the array expands to nothing.
8439 // The transform has determined that we should perform an elementwise
8440 // expansion of the pattern. Do so.
8441 for (unsigned I = 0; I != *NumExpansions; ++I) {
8442 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8443 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8444 if (Key.isInvalid())
8447 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8448 if (Value.isInvalid())
8451 ObjCDictionaryElement Element = {
8452 Key.get(), Value.get(), SourceLocation(), NumExpansions
8455 // If any unexpanded parameter packs remain, we still have a
8457 if (Key.get()->containsUnexpandedParameterPack() ||
8458 Value.get()->containsUnexpandedParameterPack())
8459 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8461 Elements.push_back(Element);
8464 // We've finished with this pack expansion.
8468 // Transform and check key.
8469 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8470 if (Key.isInvalid())
8473 if (Key.get() != OrigElement.Key)
8476 // Transform and check value.
8478 = getDerived().TransformExpr(OrigElement.Value);
8479 if (Value.isInvalid())
8482 if (Value.get() != OrigElement.Value)
8485 ObjCDictionaryElement Element = {
8486 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8488 Elements.push_back(Element);
8491 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8492 return SemaRef.MaybeBindToTemporary(E);
8494 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8499 template<typename Derived>
8501 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
8502 TypeSourceInfo *EncodedTypeInfo
8503 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8504 if (!EncodedTypeInfo)
8507 if (!getDerived().AlwaysRebuild() &&
8508 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
8509 return SemaRef.Owned(E);
8511 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
8516 template<typename Derived>
8517 ExprResult TreeTransform<Derived>::
8518 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8519 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8520 if (result.isInvalid()) return ExprError();
8521 Expr *subExpr = result.take();
8523 if (!getDerived().AlwaysRebuild() &&
8524 subExpr == E->getSubExpr())
8525 return SemaRef.Owned(E);
8527 return SemaRef.Owned(new(SemaRef.Context)
8528 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8531 template<typename Derived>
8532 ExprResult TreeTransform<Derived>::
8533 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8534 TypeSourceInfo *TSInfo
8535 = getDerived().TransformType(E->getTypeInfoAsWritten());
8539 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8540 if (Result.isInvalid())
8543 if (!getDerived().AlwaysRebuild() &&
8544 TSInfo == E->getTypeInfoAsWritten() &&
8545 Result.get() == E->getSubExpr())
8546 return SemaRef.Owned(E);
8548 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8549 E->getBridgeKeywordLoc(), TSInfo,
8553 template<typename Derived>
8555 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
8556 // Transform arguments.
8557 bool ArgChanged = false;
8558 ASTOwningVector<Expr*> Args(SemaRef);
8559 Args.reserve(E->getNumArgs());
8560 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8564 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8565 // Class message: transform the receiver type.
8566 TypeSourceInfo *ReceiverTypeInfo
8567 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8568 if (!ReceiverTypeInfo)
8571 // If nothing changed, just retain the existing message send.
8572 if (!getDerived().AlwaysRebuild() &&
8573 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
8574 return SemaRef.MaybeBindToTemporary(E);
8576 // Build a new class message send.
8577 SmallVector<SourceLocation, 16> SelLocs;
8578 E->getSelectorLocs(SelLocs);
8579 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8588 // Instance message: transform the receiver
8589 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8590 "Only class and instance messages may be instantiated");
8592 = getDerived().TransformExpr(E->getInstanceReceiver());
8593 if (Receiver.isInvalid())
8596 // If nothing changed, just retain the existing message send.
8597 if (!getDerived().AlwaysRebuild() &&
8598 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
8599 return SemaRef.MaybeBindToTemporary(E);
8601 // Build a new instance message send.
8602 SmallVector<SourceLocation, 16> SelLocs;
8603 E->getSelectorLocs(SelLocs);
8604 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
8613 template<typename Derived>
8615 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
8616 return SemaRef.Owned(E);
8619 template<typename Derived>
8621 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
8622 return SemaRef.Owned(E);
8625 template<typename Derived>
8627 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
8628 // Transform the base expression.
8629 ExprResult Base = getDerived().TransformExpr(E->getBase());
8630 if (Base.isInvalid())
8633 // We don't need to transform the ivar; it will never change.
8635 // If nothing changed, just retain the existing expression.
8636 if (!getDerived().AlwaysRebuild() &&
8637 Base.get() == E->getBase())
8638 return SemaRef.Owned(E);
8640 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
8642 E->isArrow(), E->isFreeIvar());
8645 template<typename Derived>
8647 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
8648 // 'super' and types never change. Property never changes. Just
8649 // retain the existing expression.
8650 if (!E->isObjectReceiver())
8651 return SemaRef.Owned(E);
8653 // Transform the base expression.
8654 ExprResult Base = getDerived().TransformExpr(E->getBase());
8655 if (Base.isInvalid())
8658 // We don't need to transform the property; it will never change.
8660 // If nothing changed, just retain the existing expression.
8661 if (!getDerived().AlwaysRebuild() &&
8662 Base.get() == E->getBase())
8663 return SemaRef.Owned(E);
8665 if (E->isExplicitProperty())
8666 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8667 E->getExplicitProperty(),
8670 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8671 SemaRef.Context.PseudoObjectTy,
8672 E->getImplicitPropertyGetter(),
8673 E->getImplicitPropertySetter(),
8677 template<typename Derived>
8679 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8680 // Transform the base expression.
8681 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8682 if (Base.isInvalid())
8685 // Transform the key expression.
8686 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8687 if (Key.isInvalid())
8690 // If nothing changed, just retain the existing expression.
8691 if (!getDerived().AlwaysRebuild() &&
8692 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8693 return SemaRef.Owned(E);
8695 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8696 Base.get(), Key.get(),
8697 E->getAtIndexMethodDecl(),
8698 E->setAtIndexMethodDecl());
8701 template<typename Derived>
8703 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
8704 // Transform the base expression.
8705 ExprResult Base = getDerived().TransformExpr(E->getBase());
8706 if (Base.isInvalid())
8709 // If nothing changed, just retain the existing expression.
8710 if (!getDerived().AlwaysRebuild() &&
8711 Base.get() == E->getBase())
8712 return SemaRef.Owned(E);
8714 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
8718 template<typename Derived>
8720 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
8721 bool ArgumentChanged = false;
8722 ASTOwningVector<Expr*> SubExprs(SemaRef);
8723 SubExprs.reserve(E->getNumSubExprs());
8724 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8725 SubExprs, &ArgumentChanged))
8728 if (!getDerived().AlwaysRebuild() &&
8730 return SemaRef.Owned(E);
8732 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8737 template<typename Derived>
8739 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
8740 BlockDecl *oldBlock = E->getBlockDecl();
8742 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8743 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8745 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
8746 blockScope->TheDecl->setBlockMissingReturnType(
8747 oldBlock->blockMissingReturnType());
8749 SmallVector<ParmVarDecl*, 4> params;
8750 SmallVector<QualType, 4> paramTypes;
8752 // Parameter substitution.
8753 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8754 oldBlock->param_begin(),
8755 oldBlock->param_size(),
8756 0, paramTypes, ¶ms)) {
8757 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
8761 const FunctionType *exprFunctionType = E->getFunctionType();
8762 QualType exprResultType =
8763 getDerived().TransformType(exprFunctionType->getResultType());
8765 // Don't allow returning a objc interface by value.
8766 if (exprResultType->isObjCObjectType()) {
8767 getSema().Diag(E->getCaretLocation(),
8768 diag::err_object_cannot_be_passed_returned_by_value)
8769 << 0 << exprResultType;
8770 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
8774 QualType functionType = getDerived().RebuildFunctionProtoType(
8778 oldBlock->isVariadic(),
8780 exprFunctionType->getExtInfo());
8781 blockScope->FunctionType = functionType;
8783 // Set the parameters on the block decl.
8784 if (!params.empty())
8785 blockScope->TheDecl->setParams(params);
8787 if (!oldBlock->blockMissingReturnType()) {
8788 blockScope->HasImplicitReturnType = false;
8789 blockScope->ReturnType = exprResultType;
8792 // Transform the body
8793 StmtResult body = getDerived().TransformStmt(E->getBody());
8794 if (body.isInvalid()) {
8795 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
8800 // In builds with assertions, make sure that we captured everything we
8802 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8803 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8804 e = oldBlock->capture_end(); i != e; ++i) {
8805 VarDecl *oldCapture = i->getVariable();
8807 // Ignore parameter packs.
8808 if (isa<ParmVarDecl>(oldCapture) &&
8809 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8812 VarDecl *newCapture =
8813 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8815 assert(blockScope->CaptureMap.count(newCapture));
8817 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
8821 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8825 template<typename Derived>
8827 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8828 llvm_unreachable("Cannot transform asType expressions yet");
8831 template<typename Derived>
8833 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
8834 QualType RetTy = getDerived().TransformType(E->getType());
8835 bool ArgumentChanged = false;
8836 ASTOwningVector<Expr*> SubExprs(SemaRef);
8837 SubExprs.reserve(E->getNumSubExprs());
8838 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8839 SubExprs, &ArgumentChanged))
8842 if (!getDerived().AlwaysRebuild() &&
8844 return SemaRef.Owned(E);
8846 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8847 RetTy, E->getOp(), E->getRParenLoc());
8850 //===----------------------------------------------------------------------===//
8851 // Type reconstruction
8852 //===----------------------------------------------------------------------===//
8854 template<typename Derived>
8855 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8856 SourceLocation Star) {
8857 return SemaRef.BuildPointerType(PointeeType, Star,
8858 getDerived().getBaseEntity());
8861 template<typename Derived>
8862 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8863 SourceLocation Star) {
8864 return SemaRef.BuildBlockPointerType(PointeeType, Star,
8865 getDerived().getBaseEntity());
8868 template<typename Derived>
8870 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8871 bool WrittenAsLValue,
8872 SourceLocation Sigil) {
8873 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
8874 Sigil, getDerived().getBaseEntity());
8877 template<typename Derived>
8879 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8881 SourceLocation Sigil) {
8882 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
8883 Sigil, getDerived().getBaseEntity());
8886 template<typename Derived>
8888 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8889 ArrayType::ArraySizeModifier SizeMod,
8890 const llvm::APInt *Size,
8892 unsigned IndexTypeQuals,
8893 SourceRange BracketsRange) {
8894 if (SizeExpr || !Size)
8895 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8896 IndexTypeQuals, BracketsRange,
8897 getDerived().getBaseEntity());
8899 QualType Types[] = {
8900 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8901 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8902 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
8904 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8906 for (unsigned I = 0; I != NumTypes; ++I)
8907 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8908 SizeType = Types[I];
8912 // Note that we can return a VariableArrayType here in the case where
8913 // the element type was a dependent VariableArrayType.
8914 IntegerLiteral *ArraySize
8915 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8916 /*FIXME*/BracketsRange.getBegin());
8917 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
8918 IndexTypeQuals, BracketsRange,
8919 getDerived().getBaseEntity());
8922 template<typename Derived>
8924 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
8925 ArrayType::ArraySizeModifier SizeMod,
8926 const llvm::APInt &Size,
8927 unsigned IndexTypeQuals,
8928 SourceRange BracketsRange) {
8929 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
8930 IndexTypeQuals, BracketsRange);
8933 template<typename Derived>
8935 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
8936 ArrayType::ArraySizeModifier SizeMod,
8937 unsigned IndexTypeQuals,
8938 SourceRange BracketsRange) {
8939 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
8940 IndexTypeQuals, BracketsRange);
8943 template<typename Derived>
8945 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
8946 ArrayType::ArraySizeModifier SizeMod,
8948 unsigned IndexTypeQuals,
8949 SourceRange BracketsRange) {
8950 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
8952 IndexTypeQuals, BracketsRange);
8955 template<typename Derived>
8957 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
8958 ArrayType::ArraySizeModifier SizeMod,
8960 unsigned IndexTypeQuals,
8961 SourceRange BracketsRange) {
8962 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
8964 IndexTypeQuals, BracketsRange);
8967 template<typename Derived>
8968 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
8969 unsigned NumElements,
8970 VectorType::VectorKind VecKind) {
8971 // FIXME: semantic checking!
8972 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
8975 template<typename Derived>
8976 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8977 unsigned NumElements,
8978 SourceLocation AttributeLoc) {
8979 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8981 IntegerLiteral *VectorSize
8982 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8984 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
8987 template<typename Derived>
8989 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
8991 SourceLocation AttributeLoc) {
8992 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
8995 template<typename Derived>
8996 QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
8997 QualType *ParamTypes,
8998 unsigned NumParamTypes,
9000 bool HasTrailingReturn,
9002 RefQualifierKind RefQualifier,
9003 const FunctionType::ExtInfo &Info) {
9004 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
9005 HasTrailingReturn, Quals, RefQualifier,
9006 getDerived().getBaseLocation(),
9007 getDerived().getBaseEntity(),
9011 template<typename Derived>
9012 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9013 return SemaRef.Context.getFunctionNoProtoType(T);
9016 template<typename Derived>
9017 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9018 assert(D && "no decl found");
9019 if (D->isInvalidDecl()) return QualType();
9021 // FIXME: Doesn't account for ObjCInterfaceDecl!
9023 if (isa<UsingDecl>(D)) {
9024 UsingDecl *Using = cast<UsingDecl>(D);
9025 assert(Using->isTypeName() &&
9026 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9028 // A valid resolved using typename decl points to exactly one type decl.
9029 assert(++Using->shadow_begin() == Using->shadow_end());
9030 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
9033 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9034 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9035 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9038 return SemaRef.Context.getTypeDeclType(Ty);
9041 template<typename Derived>
9042 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9043 SourceLocation Loc) {
9044 return SemaRef.BuildTypeofExprType(E, Loc);
9047 template<typename Derived>
9048 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9049 return SemaRef.Context.getTypeOfType(Underlying);
9052 template<typename Derived>
9053 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9054 SourceLocation Loc) {
9055 return SemaRef.BuildDecltypeType(E, Loc);
9058 template<typename Derived>
9059 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9060 UnaryTransformType::UTTKind UKind,
9061 SourceLocation Loc) {
9062 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9065 template<typename Derived>
9066 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
9067 TemplateName Template,
9068 SourceLocation TemplateNameLoc,
9069 TemplateArgumentListInfo &TemplateArgs) {
9070 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
9073 template<typename Derived>
9074 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9075 SourceLocation KWLoc) {
9076 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9079 template<typename Derived>
9081 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9083 TemplateDecl *Template) {
9084 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
9088 template<typename Derived>
9090 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9091 const IdentifierInfo &Name,
9092 SourceLocation NameLoc,
9093 QualType ObjectType,
9094 NamedDecl *FirstQualifierInScope) {
9095 UnqualifiedId TemplateName;
9096 TemplateName.setIdentifier(&Name, NameLoc);
9097 Sema::TemplateTy Template;
9098 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9099 getSema().ActOnDependentTemplateName(/*Scope=*/0,
9100 SS, TemplateKWLoc, TemplateName,
9101 ParsedType::make(ObjectType),
9102 /*EnteringContext=*/false,
9104 return Template.get();
9107 template<typename Derived>
9109 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9110 OverloadedOperatorKind Operator,
9111 SourceLocation NameLoc,
9112 QualType ObjectType) {
9114 // FIXME: Bogus location information.
9115 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
9116 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
9117 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9118 Sema::TemplateTy Template;
9119 getSema().ActOnDependentTemplateName(/*Scope=*/0,
9120 SS, TemplateKWLoc, Name,
9121 ParsedType::make(ObjectType),
9122 /*EnteringContext=*/false,
9124 return Template.template getAsVal<TemplateName>();
9127 template<typename Derived>
9129 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9130 SourceLocation OpLoc,
9134 Expr *Callee = OrigCallee->IgnoreParenCasts();
9135 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
9137 // Determine whether this should be a builtin operation.
9138 if (Op == OO_Subscript) {
9139 if (!First->getType()->isOverloadableType() &&
9140 !Second->getType()->isOverloadableType())
9141 return getSema().CreateBuiltinArraySubscriptExpr(First,
9142 Callee->getLocStart(),
9144 } else if (Op == OO_Arrow) {
9145 // -> is never a builtin operation.
9146 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9147 } else if (Second == 0 || isPostIncDec) {
9148 if (!First->getType()->isOverloadableType()) {
9149 // The argument is not of overloadable type, so try to create a
9150 // built-in unary operation.
9151 UnaryOperatorKind Opc
9152 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
9154 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
9157 if (!First->getType()->isOverloadableType() &&
9158 !Second->getType()->isOverloadableType()) {
9159 // Neither of the arguments is an overloadable type, so try to
9160 // create a built-in binary operation.
9161 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9163 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
9164 if (Result.isInvalid())
9167 return move(Result);
9171 // Compute the transformed set of functions (and function templates) to be
9172 // used during overload resolution.
9173 UnresolvedSet<16> Functions;
9175 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
9176 assert(ULE->requiresADL());
9178 // FIXME: Do we have to check
9179 // IsAcceptableNonMemberOperatorCandidate for each of these?
9180 Functions.append(ULE->decls_begin(), ULE->decls_end());
9182 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
9185 // Add any functions found via argument-dependent lookup.
9186 Expr *Args[2] = { First, Second };
9187 unsigned NumArgs = 1 + (Second != 0);
9189 // Create the overloaded operator invocation for unary operators.
9190 if (NumArgs == 1 || isPostIncDec) {
9191 UnaryOperatorKind Opc
9192 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
9193 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
9196 if (Op == OO_Subscript) {
9197 SourceLocation LBrace;
9198 SourceLocation RBrace;
9200 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9201 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9202 LBrace = SourceLocation::getFromRawEncoding(
9203 NameLoc.CXXOperatorName.BeginOpNameLoc);
9204 RBrace = SourceLocation::getFromRawEncoding(
9205 NameLoc.CXXOperatorName.EndOpNameLoc);
9207 LBrace = Callee->getLocStart();
9211 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9215 // Create the overloaded operator invocation for binary operators.
9216 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9218 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9219 if (Result.isInvalid())
9222 return move(Result);
9225 template<typename Derived>
9227 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
9228 SourceLocation OperatorLoc,
9231 TypeSourceInfo *ScopeType,
9232 SourceLocation CCLoc,
9233 SourceLocation TildeLoc,
9234 PseudoDestructorTypeStorage Destroyed) {
9235 QualType BaseType = Base->getType();
9236 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
9237 (!isArrow && !BaseType->getAs<RecordType>()) ||
9238 (isArrow && BaseType->getAs<PointerType>() &&
9239 !BaseType->getAs<PointerType>()->getPointeeType()
9240 ->template getAs<RecordType>())){
9241 // This pseudo-destructor expression is still a pseudo-destructor.
9242 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
9243 isArrow? tok::arrow : tok::period,
9244 SS, ScopeType, CCLoc, TildeLoc,
9249 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
9250 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9251 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9252 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9253 NameInfo.setNamedTypeInfo(DestroyedType);
9255 // FIXME: the ScopeType should be tacked onto SS.
9257 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9258 return getSema().BuildMemberReferenceExpr(Base, BaseType,
9259 OperatorLoc, isArrow,
9261 /*FIXME: FirstQualifier*/ 0,
9263 /*TemplateArgs*/ 0);
9266 } // end namespace clang
9268 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H