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/Expr.h"
25 #include "clang/AST/ExprCXX.h"
26 #include "clang/AST/ExprObjC.h"
27 #include "clang/AST/Stmt.h"
28 #include "clang/AST/StmtCXX.h"
29 #include "clang/AST/StmtObjC.h"
30 #include "clang/Sema/Ownership.h"
31 #include "clang/Sema/Designator.h"
32 #include "clang/Lex/Preprocessor.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "TypeLocBuilder.h"
40 /// \brief A semantic tree transformation that allows one to transform one
41 /// abstract syntax tree into another.
43 /// A new tree transformation is defined by creating a new subclass \c X of
44 /// \c TreeTransform<X> and then overriding certain operations to provide
45 /// behavior specific to that transformation. For example, template
46 /// instantiation is implemented as a tree transformation where the
47 /// transformation of TemplateTypeParmType nodes involves substituting the
48 /// template arguments for their corresponding template parameters; a similar
49 /// transformation is performed for non-type template parameters and
50 /// template template parameters.
52 /// This tree-transformation template uses static polymorphism to allow
53 /// subclasses to customize any of its operations. Thus, a subclass can
54 /// override any of the transformation or rebuild operators by providing an
55 /// operation with the same signature as the default implementation. The
56 /// overridding function should not be virtual.
58 /// Semantic tree transformations are split into two stages, either of which
59 /// can be replaced by a subclass. The "transform" step transforms an AST node
60 /// or the parts of an AST node using the various transformation functions,
61 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
62 /// node of the appropriate kind from the pieces. The default transformation
63 /// routines recursively transform the operands to composite AST nodes (e.g.,
64 /// the pointee type of a PointerType node) and, if any of those operand nodes
65 /// were changed by the transformation, invokes the rebuild operation to create
68 /// Subclasses can customize the transformation at various levels. The
69 /// most coarse-grained transformations involve replacing TransformType(),
70 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
72 /// new implementations.
74 /// For more fine-grained transformations, subclasses can replace any of the
75 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
76 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
77 /// replacing TransformTemplateTypeParmType() allows template instantiation
78 /// to substitute template arguments for their corresponding template
79 /// parameters. Additionally, subclasses can override the \c RebuildXXX
80 /// functions to control how AST nodes are rebuilt when their operands change.
81 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
82 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
83 /// be able to use more efficient rebuild steps.
85 /// There are a handful of other functions that can be overridden, allowing one
86 /// to avoid traversing nodes that don't need any transformation
87 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88 /// operands have not changed (\c AlwaysRebuild()), and customize the
89 /// default locations and entity names used for type-checking
90 /// (\c getBaseLocation(), \c getBaseEntity()).
91 template<typename Derived
>
93 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
96 class ForgetPartiallySubstitutedPackRAII
{
101 ForgetPartiallySubstitutedPackRAII(Derived
&Self
) : Self(Self
) {
102 Old
= Self
.ForgetPartiallySubstitutedPack();
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self
.RememberPartiallySubstitutedPack(Old
);
114 /// \brief Initializes a new tree transformer.
115 TreeTransform(Sema
&SemaRef
) : SemaRef(SemaRef
) { }
117 /// \brief Retrieves a reference to the derived class.
118 Derived
&getDerived() { return static_cast<Derived
&>(*this); }
120 /// \brief Retrieves a reference to the derived class.
121 const Derived
&getDerived() const {
122 return static_cast<const Derived
&>(*this);
125 static inline ExprResult
Owned(Expr
*E
) { return E
; }
126 static inline StmtResult
Owned(Stmt
*S
) { return S
; }
128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema
&getSema() const { return SemaRef
; }
132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
142 /// By default, returns no source-location information. Subclasses can
143 /// provide an alternative implementation that provides better location
145 SourceLocation
getBaseLocation() { return SourceLocation(); }
147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName
getBaseEntity() { return DeclarationName(); }
154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc
, DeclarationName Entity
) { }
161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase
{
165 SourceLocation OldLocation
;
166 DeclarationName OldEntity
;
169 TemporaryBase(TreeTransform
&Self
, SourceLocation Location
,
170 DeclarationName Entity
) : Self(Self
) {
171 OldLocation
= Self
.getDerived().getBaseLocation();
172 OldEntity
= Self
.getDerived().getBaseEntity();
174 if (Location
.isValid())
175 Self
.getDerived().setBase(Location
, Entity
);
179 Self
.getDerived().setBase(OldLocation
, OldEntity
);
183 /// \brief Determine whether the given type \p T has already been
186 /// Subclasses can provide an alternative implementation of this routine
187 /// to short-circuit evaluation when it is known that a given type will
188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T
) {
194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr
*E
) {
201 return E
->isDefaultArgument();
204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
208 /// By default, the transformer never tries to expand pack expansions.
209 /// Subclasses can override this routine to provide different behavior.
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
217 /// \param Unexpanded The set of unexpanded parameter packs within the
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
232 /// \param NumExpansions The number of separate arguments that will be in
233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc
,
245 SourceRange PatternRange
,
246 const UnexpandedParameterPack
*Unexpanded
,
247 unsigned NumUnexpanded
,
249 bool &RetainExpansion
,
250 llvm::Optional
<unsigned> &NumExpansions
) {
251 ShouldExpand
= false;
255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument
ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg
) { }
271 /// \brief Note to the derived class when a function parameter pack is
273 void ExpandingFunctionParameterPack(ParmVarDecl
*Pack
) { }
275 /// \brief Transforms the given type into another type.
277 /// By default, this routine transforms a type by creating a
278 /// TypeSourceInfo for it and delegating to the appropriate
279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
281 /// switched to storing TypeSourceInfos.
283 /// \returns the transformed type.
284 QualType
TransformType(QualType T
);
286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
294 TypeSourceInfo
*TransformType(TypeSourceInfo
*DI
);
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
300 QualType
TransformType(TypeLocBuilder
&TLB
, TypeLoc TL
);
302 /// \brief Transform the given statement.
304 /// By default, this routine transforms a statement by delegating to the
305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
310 /// \returns the transformed statement.
311 StmtResult
TransformStmt(Stmt
*S
);
313 /// \brief Transform the given expression.
315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
320 /// \returns the transformed expression.
321 ExprResult
TransformExpr(Expr
*E
);
323 /// \brief Transform the given list of expressions.
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
331 /// \param Inputs The set of expressions to be transformed.
333 /// \param NumInputs The number of expressions in \c Inputs.
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
339 /// \param Outputs The transformed input expressions will be added to this
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr
**Inputs
, unsigned NumInputs
, bool IsCall
,
347 llvm::SmallVectorImpl
<Expr
*> &Outputs
,
348 bool *ArgChanged
= 0);
350 /// \brief Transform the given declaration, which is referenced from a type
353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
355 Decl
*TransformDecl(SourceLocation Loc
, Decl
*D
) { return D
; }
357 /// \brief Transform the definition of the given declaration.
359 /// By default, invokes TransformDecl() to transform the declaration.
360 /// Subclasses may override this function to provide alternate behavior.
361 Decl
*TransformDefinition(SourceLocation Loc
, Decl
*D
) {
362 return getDerived().TransformDecl(Loc
, D
);
365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
368 /// This specific declaration transformation only applies to the first
369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
374 NamedDecl
*TransformFirstQualifierInScope(NamedDecl
*D
, SourceLocation Loc
) {
375 return cast_or_null
<NamedDecl
>(getDerived().TransformDecl(Loc
, D
));
378 /// \brief Transform the given nested-name-specifier.
380 /// By default, transforms all of the types and declarations within the
381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
383 NestedNameSpecifier
*TransformNestedNameSpecifier(NestedNameSpecifier
*NNS
,
385 QualType ObjectType
= QualType(),
386 NamedDecl
*FirstQualifierInScope
= 0);
388 /// \brief Transform the given declaration name.
390 /// By default, transforms the types of conversion function, constructor,
391 /// and destructor names and then (if needed) rebuilds the declaration name.
392 /// Identifiers and selectors are returned unmodified. Sublcasses may
393 /// override this function to provide alternate behavior.
395 TransformDeclarationNameInfo(const DeclarationNameInfo
&NameInfo
);
397 /// \brief Transform the given template name.
399 /// By default, transforms the template name by transforming the declarations
400 /// and nested-name-specifiers that occur within the template name.
401 /// Subclasses may override this function to provide alternate behavior.
402 TemplateName
TransformTemplateName(TemplateName Name
,
403 QualType ObjectType
= QualType(),
404 NamedDecl
*FirstQualifierInScope
= 0);
406 /// \brief Transform the given template argument.
408 /// By default, this operation transforms the type, expression, or
409 /// declaration stored within the template argument and constructs a
410 /// new template argument from the transformed result. Subclasses may
411 /// override this function to provide alternate behavior.
413 /// Returns true if there was an error.
414 bool TransformTemplateArgument(const TemplateArgumentLoc
&Input
,
415 TemplateArgumentLoc
&Output
);
417 /// \brief Transform the given set of template arguments.
419 /// By default, this operation transforms all of the template arguments
420 /// in the input set using \c TransformTemplateArgument(), and appends
421 /// the transformed arguments to the output list.
423 /// Note that this overload of \c TransformTemplateArguments() is merely
424 /// a convenience function. Subclasses that wish to override this behavior
425 /// should override the iterator-based member template version.
427 /// \param Inputs The set of template arguments to be transformed.
429 /// \param NumInputs The number of template arguments in \p Inputs.
431 /// \param Outputs The set of transformed template arguments output by this
434 /// Returns true if an error occurred.
435 bool TransformTemplateArguments(const TemplateArgumentLoc
*Inputs
,
437 TemplateArgumentListInfo
&Outputs
) {
438 return TransformTemplateArguments(Inputs
, Inputs
+ NumInputs
, Outputs
);
441 /// \brief Transform the given set of template arguments.
443 /// By default, this operation transforms all of the template arguments
444 /// in the input set using \c TransformTemplateArgument(), and appends
445 /// the transformed arguments to the output list.
447 /// \param First An iterator to the first template argument.
449 /// \param Last An iterator one step past the last template argument.
451 /// \param Outputs The set of transformed template arguments output by this
454 /// Returns true if an error occurred.
455 template<typename InputIterator
>
456 bool TransformTemplateArguments(InputIterator First
,
458 TemplateArgumentListInfo
&Outputs
);
460 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
461 void InventTemplateArgumentLoc(const TemplateArgument
&Arg
,
462 TemplateArgumentLoc
&ArgLoc
);
464 /// \brief Fakes up a TypeSourceInfo for a type.
465 TypeSourceInfo
*InventTypeSourceInfo(QualType T
) {
466 return SemaRef
.Context
.getTrivialTypeSourceInfo(T
,
467 getDerived().getBaseLocation());
470 #define ABSTRACT_TYPELOC(CLASS, PARENT)
471 #define TYPELOC(CLASS, PARENT) \
472 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
473 #include "clang/AST/TypeLocNodes.def"
476 TransformTemplateSpecializationType(TypeLocBuilder
&TLB
,
477 TemplateSpecializationTypeLoc TL
,
478 TemplateName Template
);
481 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
482 DependentTemplateSpecializationTypeLoc TL
,
483 NestedNameSpecifier
*Prefix
);
485 /// \brief Transforms the parameters of a function type into the
488 /// The result vectors should be kept in sync; null entries in the
489 /// variables vector are acceptable.
491 /// Return true on error.
492 bool TransformFunctionTypeParams(SourceLocation Loc
,
493 ParmVarDecl
**Params
, unsigned NumParams
,
494 const QualType
*ParamTypes
,
495 llvm::SmallVectorImpl
<QualType
> &PTypes
,
496 llvm::SmallVectorImpl
<ParmVarDecl
*> *PVars
);
498 /// \brief Transforms a single function-type parameter. Return null
500 ParmVarDecl
*TransformFunctionTypeParam(ParmVarDecl
*OldParm
,
501 llvm::Optional
<unsigned> NumExpansions
);
503 QualType
TransformReferenceType(TypeLocBuilder
&TLB
, ReferenceTypeLoc TL
);
505 StmtResult
TransformCompoundStmt(CompoundStmt
*S
, bool IsStmtExpr
);
506 ExprResult
TransformCXXNamedCastExpr(CXXNamedCastExpr
*E
);
508 #define STMT(Node, Parent) \
509 StmtResult Transform##Node(Node *S);
510 #define EXPR(Node, Parent) \
511 ExprResult Transform##Node(Node *E);
512 #define ABSTRACT_STMT(Stmt)
513 #include "clang/AST/StmtNodes.inc"
515 /// \brief Build a new pointer type given its pointee type.
517 /// By default, performs semantic analysis when building the pointer type.
518 /// Subclasses may override this routine to provide different behavior.
519 QualType
RebuildPointerType(QualType PointeeType
, SourceLocation Sigil
);
521 /// \brief Build a new block pointer type given its pointee type.
523 /// By default, performs semantic analysis when building the block pointer
524 /// type. Subclasses may override this routine to provide different behavior.
525 QualType
RebuildBlockPointerType(QualType PointeeType
, SourceLocation Sigil
);
527 /// \brief Build a new reference type given the type it references.
529 /// By default, performs semantic analysis when building the
530 /// reference type. Subclasses may override this routine to provide
531 /// different behavior.
533 /// \param LValue whether the type was written with an lvalue sigil
534 /// or an rvalue sigil.
535 QualType
RebuildReferenceType(QualType ReferentType
,
537 SourceLocation Sigil
);
539 /// \brief Build a new member pointer type given the pointee type and the
540 /// class type it refers into.
542 /// By default, performs semantic analysis when building the member pointer
543 /// type. Subclasses may override this routine to provide different behavior.
544 QualType
RebuildMemberPointerType(QualType PointeeType
, QualType ClassType
,
545 SourceLocation Sigil
);
547 /// \brief Build a new array type given the element type, size
548 /// modifier, size of the array (if known), size expression, and index type
551 /// By default, performs semantic analysis when building the array type.
552 /// Subclasses may override this routine to provide different behavior.
553 /// Also by default, all of the other Rebuild*Array
554 QualType
RebuildArrayType(QualType ElementType
,
555 ArrayType::ArraySizeModifier SizeMod
,
556 const llvm::APInt
*Size
,
558 unsigned IndexTypeQuals
,
559 SourceRange BracketsRange
);
561 /// \brief Build a new constant array type given the element type, size
562 /// modifier, (known) size of the array, and index type qualifiers.
564 /// By default, performs semantic analysis when building the array type.
565 /// Subclasses may override this routine to provide different behavior.
566 QualType
RebuildConstantArrayType(QualType ElementType
,
567 ArrayType::ArraySizeModifier SizeMod
,
568 const llvm::APInt
&Size
,
569 unsigned IndexTypeQuals
,
570 SourceRange BracketsRange
);
572 /// \brief Build a new incomplete array type given the element type, size
573 /// modifier, and index type qualifiers.
575 /// By default, performs semantic analysis when building the array type.
576 /// Subclasses may override this routine to provide different behavior.
577 QualType
RebuildIncompleteArrayType(QualType ElementType
,
578 ArrayType::ArraySizeModifier SizeMod
,
579 unsigned IndexTypeQuals
,
580 SourceRange BracketsRange
);
582 /// \brief Build a new variable-length array type given the element type,
583 /// size modifier, size expression, and index type qualifiers.
585 /// By default, performs semantic analysis when building the array type.
586 /// Subclasses may override this routine to provide different behavior.
587 QualType
RebuildVariableArrayType(QualType ElementType
,
588 ArrayType::ArraySizeModifier SizeMod
,
590 unsigned IndexTypeQuals
,
591 SourceRange BracketsRange
);
593 /// \brief Build a new dependent-sized array type given the element type,
594 /// size modifier, size expression, and index type qualifiers.
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
598 QualType
RebuildDependentSizedArrayType(QualType ElementType
,
599 ArrayType::ArraySizeModifier SizeMod
,
601 unsigned IndexTypeQuals
,
602 SourceRange BracketsRange
);
604 /// \brief Build a new vector type given the element type and
605 /// number of elements.
607 /// By default, performs semantic analysis when building the vector type.
608 /// Subclasses may override this routine to provide different behavior.
609 QualType
RebuildVectorType(QualType ElementType
, unsigned NumElements
,
610 VectorType::VectorKind VecKind
);
612 /// \brief Build a new extended vector type given the element type and
613 /// number of elements.
615 /// By default, performs semantic analysis when building the vector type.
616 /// Subclasses may override this routine to provide different behavior.
617 QualType
RebuildExtVectorType(QualType ElementType
, unsigned NumElements
,
618 SourceLocation AttributeLoc
);
620 /// \brief Build a new potentially dependently-sized extended vector type
621 /// given the element type and number of elements.
623 /// By default, performs semantic analysis when building the vector type.
624 /// Subclasses may override this routine to provide different behavior.
625 QualType
RebuildDependentSizedExtVectorType(QualType ElementType
,
627 SourceLocation AttributeLoc
);
629 /// \brief Build a new function type.
631 /// By default, performs semantic analysis when building the function type.
632 /// Subclasses may override this routine to provide different behavior.
633 QualType
RebuildFunctionProtoType(QualType T
,
634 QualType
*ParamTypes
,
635 unsigned NumParamTypes
,
636 bool Variadic
, unsigned Quals
,
637 RefQualifierKind RefQualifier
,
638 const FunctionType::ExtInfo
&Info
);
640 /// \brief Build a new unprototyped function type.
641 QualType
RebuildFunctionNoProtoType(QualType ResultType
);
643 /// \brief Rebuild an unresolved typename type, given the decl that
644 /// the UnresolvedUsingTypenameDecl was transformed to.
645 QualType
RebuildUnresolvedUsingType(Decl
*D
);
647 /// \brief Build a new typedef type.
648 QualType
RebuildTypedefType(TypedefDecl
*Typedef
) {
649 return SemaRef
.Context
.getTypeDeclType(Typedef
);
652 /// \brief Build a new class/struct/union type.
653 QualType
RebuildRecordType(RecordDecl
*Record
) {
654 return SemaRef
.Context
.getTypeDeclType(Record
);
657 /// \brief Build a new Enum type.
658 QualType
RebuildEnumType(EnumDecl
*Enum
) {
659 return SemaRef
.Context
.getTypeDeclType(Enum
);
662 /// \brief Build a new typeof(expr) type.
664 /// By default, performs semantic analysis when building the typeof type.
665 /// Subclasses may override this routine to provide different behavior.
666 QualType
RebuildTypeOfExprType(Expr
*Underlying
, SourceLocation Loc
);
668 /// \brief Build a new typeof(type) type.
670 /// By default, builds a new TypeOfType with the given underlying type.
671 QualType
RebuildTypeOfType(QualType Underlying
);
673 /// \brief Build a new C++0x decltype type.
675 /// By default, performs semantic analysis when building the decltype type.
676 /// Subclasses may override this routine to provide different behavior.
677 QualType
RebuildDecltypeType(Expr
*Underlying
, SourceLocation Loc
);
679 /// \brief Build a new template specialization type.
681 /// By default, performs semantic analysis when building the template
682 /// specialization type. Subclasses may override this routine to provide
683 /// different behavior.
684 QualType
RebuildTemplateSpecializationType(TemplateName Template
,
685 SourceLocation TemplateLoc
,
686 const TemplateArgumentListInfo
&Args
);
688 /// \brief Build a new parenthesized type.
690 /// By default, builds a new ParenType type from the inner type.
691 /// Subclasses may override this routine to provide different behavior.
692 QualType
RebuildParenType(QualType InnerType
) {
693 return SemaRef
.Context
.getParenType(InnerType
);
696 /// \brief Build a new qualified name type.
698 /// By default, builds a new ElaboratedType type from the keyword,
699 /// the nested-name-specifier and the named type.
700 /// Subclasses may override this routine to provide different behavior.
701 QualType
RebuildElaboratedType(SourceLocation KeywordLoc
,
702 ElaboratedTypeKeyword Keyword
,
703 NestedNameSpecifier
*NNS
, QualType Named
) {
704 return SemaRef
.Context
.getElaboratedType(Keyword
, NNS
, Named
);
707 /// \brief Build a new typename type that refers to a template-id.
709 /// By default, builds a new DependentNameType type from the
710 /// nested-name-specifier and the given type. Subclasses may override
711 /// this routine to provide different behavior.
712 QualType
RebuildDependentTemplateSpecializationType(
713 ElaboratedTypeKeyword Keyword
,
714 NestedNameSpecifier
*Qualifier
,
715 SourceRange QualifierRange
,
716 const IdentifierInfo
*Name
,
717 SourceLocation NameLoc
,
718 const TemplateArgumentListInfo
&Args
) {
719 // Rebuild the template name.
720 // TODO: avoid TemplateName abstraction
721 TemplateName InstName
=
722 getDerived().RebuildTemplateName(Qualifier
, QualifierRange
, *Name
,
725 if (InstName
.isNull())
728 // If it's still dependent, make a dependent specialization.
729 if (InstName
.getAsDependentTemplateName())
730 return SemaRef
.Context
.getDependentTemplateSpecializationType(
731 Keyword
, Qualifier
, Name
, Args
);
733 // Otherwise, make an elaborated type wrapping a non-dependent
736 getDerived().RebuildTemplateSpecializationType(InstName
, NameLoc
, Args
);
737 if (T
.isNull()) return QualType();
739 // NOTE: NNS is already recorded in template specialization type T.
740 return SemaRef
.Context
.getElaboratedType(Keyword
, /*NNS=*/0, T
);
743 /// \brief Build a new typename type that refers to an identifier.
745 /// By default, performs semantic analysis when building the typename type
746 /// (or elaborated type). Subclasses may override this routine to provide
747 /// different behavior.
748 QualType
RebuildDependentNameType(ElaboratedTypeKeyword Keyword
,
749 NestedNameSpecifier
*NNS
,
750 const IdentifierInfo
*Id
,
751 SourceLocation KeywordLoc
,
752 SourceRange NNSRange
,
753 SourceLocation IdLoc
) {
756 SS
.setRange(NNSRange
);
758 if (NNS
->isDependent()) {
759 // If the name is still dependent, just build a new dependent name type.
760 if (!SemaRef
.computeDeclContext(SS
))
761 return SemaRef
.Context
.getDependentNameType(Keyword
, NNS
, Id
);
764 if (Keyword
== ETK_None
|| Keyword
== ETK_Typename
)
765 return SemaRef
.CheckTypenameType(Keyword
, NNS
, *Id
,
766 KeywordLoc
, NNSRange
, IdLoc
);
768 TagTypeKind Kind
= TypeWithKeyword::getTagTypeKindForKeyword(Keyword
);
770 // We had a dependent elaborated-type-specifier that has been transformed
771 // into a non-dependent elaborated-type-specifier. Find the tag we're
773 LookupResult
Result(SemaRef
, Id
, IdLoc
, Sema::LookupTagName
);
774 DeclContext
*DC
= SemaRef
.computeDeclContext(SS
, false);
778 if (SemaRef
.RequireCompleteDeclContext(SS
, DC
))
782 SemaRef
.LookupQualifiedName(Result
, DC
);
783 switch (Result
.getResultKind()) {
784 case LookupResult::NotFound
:
785 case LookupResult::NotFoundInCurrentInstantiation
:
788 case LookupResult::Found
:
789 Tag
= Result
.getAsSingle
<TagDecl
>();
792 case LookupResult::FoundOverloaded
:
793 case LookupResult::FoundUnresolvedValue
:
794 llvm_unreachable("Tag lookup cannot find non-tags");
797 case LookupResult::Ambiguous
:
798 // Let the LookupResult structure handle ambiguities.
803 // Check where the name exists but isn't a tag type and use that to emit
804 // better diagnostics.
805 LookupResult
Result(SemaRef
, Id
, IdLoc
, Sema::LookupTagName
);
806 SemaRef
.LookupQualifiedName(Result
, DC
);
807 switch (Result
.getResultKind()) {
808 case LookupResult::Found
:
809 case LookupResult::FoundOverloaded
:
810 case LookupResult::FoundUnresolvedValue
: {
811 NamedDecl
*SomeDecl
= Result
.getRepresentativeDecl();
813 if (isa
<TypedefDecl
>(SomeDecl
)) Kind
= 1;
814 else if (isa
<ClassTemplateDecl
>(SomeDecl
)) Kind
= 2;
815 SemaRef
.Diag(IdLoc
, diag::err_tag_reference_non_tag
) << Kind
;
816 SemaRef
.Diag(SomeDecl
->getLocation(), diag::note_declared_at
);
820 // FIXME: Would be nice to highlight just the source range.
821 SemaRef
.Diag(IdLoc
, diag::err_not_tag_in_scope
)
828 if (!SemaRef
.isAcceptableTagRedeclaration(Tag
, Kind
, IdLoc
, *Id
)) {
829 SemaRef
.Diag(KeywordLoc
, diag::err_use_with_wrong_tag
) << Id
;
830 SemaRef
.Diag(Tag
->getLocation(), diag::note_previous_use
);
834 // Build the elaborated-type-specifier type.
835 QualType T
= SemaRef
.Context
.getTypeDeclType(Tag
);
836 return SemaRef
.Context
.getElaboratedType(Keyword
, NNS
, T
);
839 /// \brief Build a new pack expansion type.
841 /// By default, builds a new PackExpansionType type from the given pattern.
842 /// Subclasses may override this routine to provide different behavior.
843 QualType
RebuildPackExpansionType(QualType Pattern
,
844 SourceRange PatternRange
,
845 SourceLocation EllipsisLoc
,
846 llvm::Optional
<unsigned> NumExpansions
) {
847 return getSema().CheckPackExpansion(Pattern
, PatternRange
, EllipsisLoc
,
851 /// \brief Build a new nested-name-specifier given the prefix and an
852 /// identifier that names the next step in the nested-name-specifier.
854 /// By default, performs semantic analysis when building the new
855 /// nested-name-specifier. Subclasses may override this routine to provide
856 /// different behavior.
857 NestedNameSpecifier
*RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
861 NamedDecl
*FirstQualifierInScope
);
863 /// \brief Build a new nested-name-specifier given the prefix and the
864 /// namespace named in the next step in the nested-name-specifier.
866 /// By default, performs semantic analysis when building the new
867 /// nested-name-specifier. Subclasses may override this routine to provide
868 /// different behavior.
869 NestedNameSpecifier
*RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
873 /// \brief Build a new nested-name-specifier given the prefix and the
874 /// type named in the next step in the nested-name-specifier.
876 /// By default, performs semantic analysis when building the new
877 /// nested-name-specifier. Subclasses may override this routine to provide
878 /// different behavior.
879 NestedNameSpecifier
*RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
884 /// \brief Build a new template name given a nested name specifier, a flag
885 /// indicating whether the "template" keyword was provided, and the template
886 /// that the template name refers to.
888 /// By default, builds the new template name directly. Subclasses may override
889 /// this routine to provide different behavior.
890 TemplateName
RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
892 TemplateDecl
*Template
);
894 /// \brief Build a new template name given a nested name specifier and the
895 /// name that is referred to as a template.
897 /// By default, performs semantic analysis to determine whether the name can
898 /// be resolved to a specific template, then builds the appropriate kind of
899 /// template name. Subclasses may override this routine to provide different
901 TemplateName
RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
902 SourceRange QualifierRange
,
903 const IdentifierInfo
&II
,
905 NamedDecl
*FirstQualifierInScope
);
907 /// \brief Build a new template name given a nested name specifier and the
908 /// overloaded operator name that is referred to as a template.
910 /// By default, performs semantic analysis to determine whether the name can
911 /// be resolved to a specific template, then builds the appropriate kind of
912 /// template name. Subclasses may override this routine to provide different
914 TemplateName
RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
915 OverloadedOperatorKind Operator
,
916 QualType ObjectType
);
918 /// \brief Build a new template name given a template template parameter pack
921 /// By default, performs semantic analysis to determine whether the name can
922 /// be resolved to a specific template, then builds the appropriate kind of
923 /// template name. Subclasses may override this routine to provide different
925 TemplateName
RebuildTemplateName(TemplateTemplateParmDecl
*Param
,
926 const TemplateArgument
&ArgPack
) {
927 return getSema().Context
.getSubstTemplateTemplateParmPack(Param
, ArgPack
);
930 /// \brief Build a new compound statement.
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
934 StmtResult
RebuildCompoundStmt(SourceLocation LBraceLoc
,
935 MultiStmtArg Statements
,
936 SourceLocation RBraceLoc
,
938 return getSema().ActOnCompoundStmt(LBraceLoc
, RBraceLoc
, Statements
,
942 /// \brief Build a new case statement.
944 /// By default, performs semantic analysis to build the new statement.
945 /// Subclasses may override this routine to provide different behavior.
946 StmtResult
RebuildCaseStmt(SourceLocation CaseLoc
,
948 SourceLocation EllipsisLoc
,
950 SourceLocation ColonLoc
) {
951 return getSema().ActOnCaseStmt(CaseLoc
, LHS
, EllipsisLoc
, RHS
,
955 /// \brief Attach the body to a new case statement.
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
959 StmtResult
RebuildCaseStmtBody(Stmt
*S
, Stmt
*Body
) {
960 getSema().ActOnCaseStmtBody(S
, Body
);
964 /// \brief Build a new default statement.
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
968 StmtResult
RebuildDefaultStmt(SourceLocation DefaultLoc
,
969 SourceLocation ColonLoc
,
971 return getSema().ActOnDefaultStmt(DefaultLoc
, ColonLoc
, SubStmt
,
975 /// \brief Build a new label statement.
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
979 StmtResult
RebuildLabelStmt(SourceLocation IdentLoc
, LabelDecl
*L
,
980 SourceLocation ColonLoc
, Stmt
*SubStmt
) {
981 return SemaRef
.ActOnLabelStmt(IdentLoc
, L
, ColonLoc
, SubStmt
);
984 /// \brief Build a new "if" statement.
986 /// By default, performs semantic analysis to build the new statement.
987 /// Subclasses may override this routine to provide different behavior.
988 StmtResult
RebuildIfStmt(SourceLocation IfLoc
, Sema::FullExprArg Cond
,
989 VarDecl
*CondVar
, Stmt
*Then
,
990 SourceLocation ElseLoc
, Stmt
*Else
) {
991 return getSema().ActOnIfStmt(IfLoc
, Cond
, CondVar
, Then
, ElseLoc
, Else
);
994 /// \brief Start building a new switch statement.
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
998 StmtResult
RebuildSwitchStmtStart(SourceLocation SwitchLoc
,
999 Expr
*Cond
, VarDecl
*CondVar
) {
1000 return getSema().ActOnStartOfSwitchStmt(SwitchLoc
, Cond
,
1004 /// \brief Attach the body to the switch statement.
1006 /// By default, performs semantic analysis to build the new statement.
1007 /// Subclasses may override this routine to provide different behavior.
1008 StmtResult
RebuildSwitchStmtBody(SourceLocation SwitchLoc
,
1009 Stmt
*Switch
, Stmt
*Body
) {
1010 return getSema().ActOnFinishSwitchStmt(SwitchLoc
, Switch
, Body
);
1013 /// \brief Build a new while statement.
1015 /// By default, performs semantic analysis to build the new statement.
1016 /// Subclasses may override this routine to provide different behavior.
1017 StmtResult
RebuildWhileStmt(SourceLocation WhileLoc
, Sema::FullExprArg Cond
,
1018 VarDecl
*CondVar
, Stmt
*Body
) {
1019 return getSema().ActOnWhileStmt(WhileLoc
, Cond
, CondVar
, Body
);
1022 /// \brief Build a new do-while statement.
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
1026 StmtResult
RebuildDoStmt(SourceLocation DoLoc
, Stmt
*Body
,
1027 SourceLocation WhileLoc
, SourceLocation LParenLoc
,
1028 Expr
*Cond
, SourceLocation RParenLoc
) {
1029 return getSema().ActOnDoStmt(DoLoc
, Body
, WhileLoc
, LParenLoc
,
1033 /// \brief Build a new for statement.
1035 /// By default, performs semantic analysis to build the new statement.
1036 /// Subclasses may override this routine to provide different behavior.
1037 StmtResult
RebuildForStmt(SourceLocation ForLoc
, SourceLocation LParenLoc
,
1038 Stmt
*Init
, Sema::FullExprArg Cond
,
1039 VarDecl
*CondVar
, Sema::FullExprArg Inc
,
1040 SourceLocation RParenLoc
, Stmt
*Body
) {
1041 return getSema().ActOnForStmt(ForLoc
, LParenLoc
, Init
, Cond
,
1042 CondVar
, Inc
, RParenLoc
, Body
);
1045 /// \brief Build a new goto statement.
1047 /// By default, performs semantic analysis to build the new statement.
1048 /// Subclasses may override this routine to provide different behavior.
1049 StmtResult
RebuildGotoStmt(SourceLocation GotoLoc
, SourceLocation LabelLoc
,
1051 return getSema().ActOnGotoStmt(GotoLoc
, LabelLoc
, Label
);
1054 /// \brief Build a new indirect goto statement.
1056 /// By default, performs semantic analysis to build the new statement.
1057 /// Subclasses may override this routine to provide different behavior.
1058 StmtResult
RebuildIndirectGotoStmt(SourceLocation GotoLoc
,
1059 SourceLocation StarLoc
,
1061 return getSema().ActOnIndirectGotoStmt(GotoLoc
, StarLoc
, Target
);
1064 /// \brief Build a new return statement.
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
1068 StmtResult
RebuildReturnStmt(SourceLocation ReturnLoc
, Expr
*Result
) {
1069 return getSema().ActOnReturnStmt(ReturnLoc
, Result
);
1072 /// \brief Build a new declaration statement.
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
1076 StmtResult
RebuildDeclStmt(Decl
**Decls
, unsigned NumDecls
,
1077 SourceLocation StartLoc
,
1078 SourceLocation EndLoc
) {
1079 return getSema().Owned(
1080 new (getSema().Context
) DeclStmt(
1081 DeclGroupRef::Create(getSema().Context
,
1086 /// \brief Build a new inline asm statement.
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
1090 StmtResult
RebuildAsmStmt(SourceLocation AsmLoc
,
1093 unsigned NumOutputs
,
1095 IdentifierInfo
**Names
,
1096 MultiExprArg Constraints
,
1099 MultiExprArg Clobbers
,
1100 SourceLocation RParenLoc
,
1102 return getSema().ActOnAsmStmt(AsmLoc
, IsSimple
, IsVolatile
, NumOutputs
,
1103 NumInputs
, Names
, move(Constraints
),
1104 Exprs
, AsmString
, Clobbers
,
1108 /// \brief Build a new Objective-C @try statement.
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
1112 StmtResult
RebuildObjCAtTryStmt(SourceLocation AtLoc
,
1114 MultiStmtArg CatchStmts
,
1116 return getSema().ActOnObjCAtTryStmt(AtLoc
, TryBody
, move(CatchStmts
),
1120 /// \brief Rebuild an Objective-C exception declaration.
1122 /// By default, performs semantic analysis to build the new declaration.
1123 /// Subclasses may override this routine to provide different behavior.
1124 VarDecl
*RebuildObjCExceptionDecl(VarDecl
*ExceptionDecl
,
1125 TypeSourceInfo
*TInfo
, QualType T
) {
1126 return getSema().BuildObjCExceptionDecl(TInfo
, T
,
1127 ExceptionDecl
->getIdentifier(),
1128 ExceptionDecl
->getLocation());
1131 /// \brief Build a new Objective-C @catch statement.
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
1135 StmtResult
RebuildObjCAtCatchStmt(SourceLocation AtLoc
,
1136 SourceLocation RParenLoc
,
1139 return getSema().ActOnObjCAtCatchStmt(AtLoc
, RParenLoc
,
1143 /// \brief Build a new Objective-C @finally statement.
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
1147 StmtResult
RebuildObjCAtFinallyStmt(SourceLocation AtLoc
,
1149 return getSema().ActOnObjCAtFinallyStmt(AtLoc
, Body
);
1152 /// \brief Build a new Objective-C @throw statement.
1154 /// By default, performs semantic analysis to build the new statement.
1155 /// Subclasses may override this routine to provide different behavior.
1156 StmtResult
RebuildObjCAtThrowStmt(SourceLocation AtLoc
,
1158 return getSema().BuildObjCAtThrowStmt(AtLoc
, Operand
);
1161 /// \brief Build a new Objective-C @synchronized statement.
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
1165 StmtResult
RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc
,
1168 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc
, Object
,
1172 /// \brief Build a new Objective-C fast enumeration statement.
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
1176 StmtResult
RebuildObjCForCollectionStmt(SourceLocation ForLoc
,
1177 SourceLocation LParenLoc
,
1180 SourceLocation RParenLoc
,
1182 return getSema().ActOnObjCForCollectionStmt(ForLoc
, LParenLoc
,
1189 /// \brief Build a new C++ exception declaration.
1191 /// By default, performs semantic analysis to build the new decaration.
1192 /// Subclasses may override this routine to provide different behavior.
1193 VarDecl
*RebuildExceptionDecl(VarDecl
*ExceptionDecl
,
1194 TypeSourceInfo
*Declarator
,
1195 IdentifierInfo
*Name
,
1196 SourceLocation Loc
) {
1197 return getSema().BuildExceptionDeclaration(0, Declarator
, Name
, Loc
);
1200 /// \brief Build a new C++ catch statement.
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
1204 StmtResult
RebuildCXXCatchStmt(SourceLocation CatchLoc
,
1205 VarDecl
*ExceptionDecl
,
1207 return Owned(new (getSema().Context
) CXXCatchStmt(CatchLoc
, ExceptionDecl
,
1211 /// \brief Build a new C++ try statement.
1213 /// By default, performs semantic analysis to build the new statement.
1214 /// Subclasses may override this routine to provide different behavior.
1215 StmtResult
RebuildCXXTryStmt(SourceLocation TryLoc
,
1217 MultiStmtArg Handlers
) {
1218 return getSema().ActOnCXXTryBlock(TryLoc
, TryBlock
, move(Handlers
));
1221 /// \brief Build a new expression that references a declaration.
1223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
1225 ExprResult
RebuildDeclarationNameExpr(const CXXScopeSpec
&SS
,
1228 return getSema().BuildDeclarationNameExpr(SS
, R
, RequiresADL
);
1232 /// \brief Build a new expression that references a declaration.
1234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
1236 ExprResult
RebuildDeclRefExpr(NestedNameSpecifier
*Qualifier
,
1237 SourceRange QualifierRange
,
1239 const DeclarationNameInfo
&NameInfo
,
1240 TemplateArgumentListInfo
*TemplateArgs
) {
1242 SS
.setScopeRep(Qualifier
);
1243 SS
.setRange(QualifierRange
);
1245 // FIXME: loses template args.
1247 return getSema().BuildDeclarationNameExpr(SS
, NameInfo
, VD
);
1250 /// \brief Build a new expression in parentheses.
1252 /// By default, performs semantic analysis to build the new expression.
1253 /// Subclasses may override this routine to provide different behavior.
1254 ExprResult
RebuildParenExpr(Expr
*SubExpr
, SourceLocation LParen
,
1255 SourceLocation RParen
) {
1256 return getSema().ActOnParenExpr(LParen
, RParen
, SubExpr
);
1259 /// \brief Build a new pseudo-destructor expression.
1261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
1263 ExprResult
RebuildCXXPseudoDestructorExpr(Expr
*Base
,
1264 SourceLocation OperatorLoc
,
1266 NestedNameSpecifier
*Qualifier
,
1267 SourceRange QualifierRange
,
1268 TypeSourceInfo
*ScopeType
,
1269 SourceLocation CCLoc
,
1270 SourceLocation TildeLoc
,
1271 PseudoDestructorTypeStorage Destroyed
);
1273 /// \brief Build a new unary operator expression.
1275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
1277 ExprResult
RebuildUnaryOperator(SourceLocation OpLoc
,
1278 UnaryOperatorKind Opc
,
1280 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc
, Opc
, SubExpr
);
1283 /// \brief Build a new builtin offsetof expression.
1285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
1287 ExprResult
RebuildOffsetOfExpr(SourceLocation OperatorLoc
,
1288 TypeSourceInfo
*Type
,
1289 Sema::OffsetOfComponent
*Components
,
1290 unsigned NumComponents
,
1291 SourceLocation RParenLoc
) {
1292 return getSema().BuildBuiltinOffsetOf(OperatorLoc
, Type
, Components
,
1293 NumComponents
, RParenLoc
);
1296 /// \brief Build a new sizeof or alignof expression with a type argument.
1298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
1300 ExprResult
RebuildSizeOfAlignOf(TypeSourceInfo
*TInfo
,
1301 SourceLocation OpLoc
,
1302 bool isSizeOf
, SourceRange R
) {
1303 return getSema().CreateSizeOfAlignOfExpr(TInfo
, OpLoc
, isSizeOf
, R
);
1306 /// \brief Build a new sizeof or alignof expression with an expression
1309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
1311 ExprResult
RebuildSizeOfAlignOf(Expr
*SubExpr
, SourceLocation OpLoc
,
1312 bool isSizeOf
, SourceRange R
) {
1314 = getSema().CreateSizeOfAlignOfExpr(SubExpr
, OpLoc
, isSizeOf
, R
);
1315 if (Result
.isInvalid())
1318 return move(Result
);
1321 /// \brief Build a new array subscript expression.
1323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
1325 ExprResult
RebuildArraySubscriptExpr(Expr
*LHS
,
1326 SourceLocation LBracketLoc
,
1328 SourceLocation RBracketLoc
) {
1329 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS
,
1334 /// \brief Build a new call expression.
1336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
1338 ExprResult
RebuildCallExpr(Expr
*Callee
, SourceLocation LParenLoc
,
1340 SourceLocation RParenLoc
,
1341 Expr
*ExecConfig
= 0) {
1342 return getSema().ActOnCallExpr(/*Scope=*/0, Callee
, LParenLoc
,
1343 move(Args
), RParenLoc
, ExecConfig
);
1346 /// \brief Build a new member access expression.
1348 /// By default, performs semantic analysis to build the new expression.
1349 /// Subclasses may override this routine to provide different behavior.
1350 ExprResult
RebuildMemberExpr(Expr
*Base
, SourceLocation OpLoc
,
1352 NestedNameSpecifier
*Qualifier
,
1353 SourceRange QualifierRange
,
1354 const DeclarationNameInfo
&MemberNameInfo
,
1356 NamedDecl
*FoundDecl
,
1357 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
1358 NamedDecl
*FirstQualifierInScope
) {
1359 if (!Member
->getDeclName()) {
1360 // We have a reference to an unnamed field. This is always the
1361 // base of an anonymous struct/union member access, i.e. the
1362 // field is always of record type.
1363 assert(!Qualifier
&& "Can't have an unnamed field with a qualifier!");
1364 assert(Member
->getType()->isRecordType() &&
1365 "unnamed member not of record type?");
1367 if (getSema().PerformObjectMemberConversion(Base
, Qualifier
,
1371 ExprValueKind VK
= isArrow
? VK_LValue
: Base
->getValueKind();
1373 new (getSema().Context
) MemberExpr(Base
, isArrow
,
1374 Member
, MemberNameInfo
,
1375 cast
<FieldDecl
>(Member
)->getType(),
1377 return getSema().Owned(ME
);
1382 SS
.setRange(QualifierRange
);
1383 SS
.setScopeRep(Qualifier
);
1386 getSema().DefaultFunctionArrayConversion(Base
);
1387 QualType BaseType
= Base
->getType();
1389 // FIXME: this involves duplicating earlier analysis in a lot of
1390 // cases; we should avoid this when possible.
1391 LookupResult
R(getSema(), MemberNameInfo
, Sema::LookupMemberName
);
1392 R
.addDecl(FoundDecl
);
1395 return getSema().BuildMemberReferenceExpr(Base
, BaseType
, OpLoc
, isArrow
,
1396 SS
, FirstQualifierInScope
,
1397 R
, ExplicitTemplateArgs
);
1400 /// \brief Build a new binary operator expression.
1402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
1404 ExprResult
RebuildBinaryOperator(SourceLocation OpLoc
,
1405 BinaryOperatorKind Opc
,
1406 Expr
*LHS
, Expr
*RHS
) {
1407 return getSema().BuildBinOp(/*Scope=*/0, OpLoc
, Opc
, LHS
, RHS
);
1410 /// \brief Build a new conditional operator expression.
1412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
1414 ExprResult
RebuildConditionalOperator(Expr
*Cond
,
1415 SourceLocation QuestionLoc
,
1417 SourceLocation ColonLoc
,
1419 return getSema().ActOnConditionalOp(QuestionLoc
, ColonLoc
, Cond
,
1423 /// \brief Build a new C-style cast expression.
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
1427 ExprResult
RebuildCStyleCastExpr(SourceLocation LParenLoc
,
1428 TypeSourceInfo
*TInfo
,
1429 SourceLocation RParenLoc
,
1431 return getSema().BuildCStyleCastExpr(LParenLoc
, TInfo
, RParenLoc
,
1435 /// \brief Build a new compound literal expression.
1437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
1439 ExprResult
RebuildCompoundLiteralExpr(SourceLocation LParenLoc
,
1440 TypeSourceInfo
*TInfo
,
1441 SourceLocation RParenLoc
,
1443 return getSema().BuildCompoundLiteralExpr(LParenLoc
, TInfo
, RParenLoc
,
1447 /// \brief Build a new extended vector element access expression.
1449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
1451 ExprResult
RebuildExtVectorElementExpr(Expr
*Base
,
1452 SourceLocation OpLoc
,
1453 SourceLocation AccessorLoc
,
1454 IdentifierInfo
&Accessor
) {
1457 DeclarationNameInfo
NameInfo(&Accessor
, AccessorLoc
);
1458 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
1459 OpLoc
, /*IsArrow*/ false,
1460 SS
, /*FirstQualifierInScope*/ 0,
1462 /* TemplateArgs */ 0);
1465 /// \brief Build a new initializer list expression.
1467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
1469 ExprResult
RebuildInitList(SourceLocation LBraceLoc
,
1471 SourceLocation RBraceLoc
,
1472 QualType ResultTy
) {
1474 = SemaRef
.ActOnInitList(LBraceLoc
, move(Inits
), RBraceLoc
);
1475 if (Result
.isInvalid() || ResultTy
->isDependentType())
1476 return move(Result
);
1478 // Patch in the result type we were given, which may have been computed
1479 // when the initial InitListExpr was built.
1480 InitListExpr
*ILE
= cast
<InitListExpr
>((Expr
*)Result
.get());
1481 ILE
->setType(ResultTy
);
1482 return move(Result
);
1485 /// \brief Build a new designated initializer expression.
1487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
1489 ExprResult
RebuildDesignatedInitExpr(Designation
&Desig
,
1490 MultiExprArg ArrayExprs
,
1491 SourceLocation EqualOrColonLoc
,
1495 = SemaRef
.ActOnDesignatedInitializer(Desig
, EqualOrColonLoc
, GNUSyntax
,
1497 if (Result
.isInvalid())
1500 ArrayExprs
.release();
1501 return move(Result
);
1504 /// \brief Build a new value-initialized expression.
1506 /// By default, builds the implicit value initialization without performing
1507 /// any semantic analysis. Subclasses may override this routine to provide
1508 /// different behavior.
1509 ExprResult
RebuildImplicitValueInitExpr(QualType T
) {
1510 return SemaRef
.Owned(new (SemaRef
.Context
) ImplicitValueInitExpr(T
));
1513 /// \brief Build a new \c va_arg expression.
1515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
1517 ExprResult
RebuildVAArgExpr(SourceLocation BuiltinLoc
,
1518 Expr
*SubExpr
, TypeSourceInfo
*TInfo
,
1519 SourceLocation RParenLoc
) {
1520 return getSema().BuildVAArgExpr(BuiltinLoc
,
1525 /// \brief Build a new expression list in parentheses.
1527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
1529 ExprResult
RebuildParenListExpr(SourceLocation LParenLoc
,
1530 MultiExprArg SubExprs
,
1531 SourceLocation RParenLoc
) {
1532 return getSema().ActOnParenOrParenListExpr(LParenLoc
, RParenLoc
,
1536 /// \brief Build a new address-of-label expression.
1538 /// By default, performs semantic analysis, using the name of the label
1539 /// rather than attempting to map the label statement itself.
1540 /// Subclasses may override this routine to provide different behavior.
1541 ExprResult
RebuildAddrLabelExpr(SourceLocation AmpAmpLoc
,
1542 SourceLocation LabelLoc
, LabelDecl
*Label
) {
1543 return getSema().ActOnAddrLabel(AmpAmpLoc
, LabelLoc
, Label
);
1546 /// \brief Build a new GNU statement expression.
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
1550 ExprResult
RebuildStmtExpr(SourceLocation LParenLoc
,
1552 SourceLocation RParenLoc
) {
1553 return getSema().ActOnStmtExpr(LParenLoc
, SubStmt
, RParenLoc
);
1556 /// \brief Build a new __builtin_choose_expr expression.
1558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
1560 ExprResult
RebuildChooseExpr(SourceLocation BuiltinLoc
,
1561 Expr
*Cond
, Expr
*LHS
, Expr
*RHS
,
1562 SourceLocation RParenLoc
) {
1563 return SemaRef
.ActOnChooseExpr(BuiltinLoc
,
1568 /// \brief Build a new overloaded operator call expression.
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// The semantic analysis provides the behavior of template instantiation,
1572 /// copying with transformations that turn what looks like an overloaded
1573 /// operator call into a use of a builtin operator, performing
1574 /// argument-dependent lookup, etc. Subclasses may override this routine to
1575 /// provide different behavior.
1576 ExprResult
RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op
,
1577 SourceLocation OpLoc
,
1582 /// \brief Build a new C++ "named" cast expression, such as static_cast or
1583 /// reinterpret_cast.
1585 /// By default, this routine dispatches to one of the more-specific routines
1586 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1587 /// Subclasses may override this routine to provide different behavior.
1588 ExprResult
RebuildCXXNamedCastExpr(SourceLocation OpLoc
,
1589 Stmt::StmtClass Class
,
1590 SourceLocation LAngleLoc
,
1591 TypeSourceInfo
*TInfo
,
1592 SourceLocation RAngleLoc
,
1593 SourceLocation LParenLoc
,
1595 SourceLocation RParenLoc
) {
1597 case Stmt::CXXStaticCastExprClass
:
1598 return getDerived().RebuildCXXStaticCastExpr(OpLoc
, LAngleLoc
, TInfo
,
1599 RAngleLoc
, LParenLoc
,
1600 SubExpr
, RParenLoc
);
1602 case Stmt::CXXDynamicCastExprClass
:
1603 return getDerived().RebuildCXXDynamicCastExpr(OpLoc
, LAngleLoc
, TInfo
,
1604 RAngleLoc
, LParenLoc
,
1605 SubExpr
, RParenLoc
);
1607 case Stmt::CXXReinterpretCastExprClass
:
1608 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc
, LAngleLoc
, TInfo
,
1609 RAngleLoc
, LParenLoc
,
1613 case Stmt::CXXConstCastExprClass
:
1614 return getDerived().RebuildCXXConstCastExpr(OpLoc
, LAngleLoc
, TInfo
,
1615 RAngleLoc
, LParenLoc
,
1616 SubExpr
, RParenLoc
);
1619 assert(false && "Invalid C++ named cast");
1626 /// \brief Build a new C++ static_cast expression.
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
1630 ExprResult
RebuildCXXStaticCastExpr(SourceLocation OpLoc
,
1631 SourceLocation LAngleLoc
,
1632 TypeSourceInfo
*TInfo
,
1633 SourceLocation RAngleLoc
,
1634 SourceLocation LParenLoc
,
1636 SourceLocation RParenLoc
) {
1637 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_static_cast
,
1639 SourceRange(LAngleLoc
, RAngleLoc
),
1640 SourceRange(LParenLoc
, RParenLoc
));
1643 /// \brief Build a new C++ dynamic_cast expression.
1645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
1647 ExprResult
RebuildCXXDynamicCastExpr(SourceLocation OpLoc
,
1648 SourceLocation LAngleLoc
,
1649 TypeSourceInfo
*TInfo
,
1650 SourceLocation RAngleLoc
,
1651 SourceLocation LParenLoc
,
1653 SourceLocation RParenLoc
) {
1654 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_dynamic_cast
,
1656 SourceRange(LAngleLoc
, RAngleLoc
),
1657 SourceRange(LParenLoc
, RParenLoc
));
1660 /// \brief Build a new C++ reinterpret_cast expression.
1662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
1664 ExprResult
RebuildCXXReinterpretCastExpr(SourceLocation OpLoc
,
1665 SourceLocation LAngleLoc
,
1666 TypeSourceInfo
*TInfo
,
1667 SourceLocation RAngleLoc
,
1668 SourceLocation LParenLoc
,
1670 SourceLocation RParenLoc
) {
1671 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_reinterpret_cast
,
1673 SourceRange(LAngleLoc
, RAngleLoc
),
1674 SourceRange(LParenLoc
, RParenLoc
));
1677 /// \brief Build a new C++ const_cast expression.
1679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
1681 ExprResult
RebuildCXXConstCastExpr(SourceLocation OpLoc
,
1682 SourceLocation LAngleLoc
,
1683 TypeSourceInfo
*TInfo
,
1684 SourceLocation RAngleLoc
,
1685 SourceLocation LParenLoc
,
1687 SourceLocation RParenLoc
) {
1688 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_const_cast
,
1690 SourceRange(LAngleLoc
, RAngleLoc
),
1691 SourceRange(LParenLoc
, RParenLoc
));
1694 /// \brief Build a new C++ functional-style cast expression.
1696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
1698 ExprResult
RebuildCXXFunctionalCastExpr(TypeSourceInfo
*TInfo
,
1699 SourceLocation LParenLoc
,
1701 SourceLocation RParenLoc
) {
1702 return getSema().BuildCXXTypeConstructExpr(TInfo
, LParenLoc
,
1703 MultiExprArg(&Sub
, 1),
1707 /// \brief Build a new C++ typeid(type) expression.
1709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
1711 ExprResult
RebuildCXXTypeidExpr(QualType TypeInfoType
,
1712 SourceLocation TypeidLoc
,
1713 TypeSourceInfo
*Operand
,
1714 SourceLocation RParenLoc
) {
1715 return getSema().BuildCXXTypeId(TypeInfoType
, TypeidLoc
, Operand
,
1720 /// \brief Build a new C++ typeid(expr) expression.
1722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
1724 ExprResult
RebuildCXXTypeidExpr(QualType TypeInfoType
,
1725 SourceLocation TypeidLoc
,
1727 SourceLocation RParenLoc
) {
1728 return getSema().BuildCXXTypeId(TypeInfoType
, TypeidLoc
, Operand
,
1732 /// \brief Build a new C++ __uuidof(type) expression.
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
1736 ExprResult
RebuildCXXUuidofExpr(QualType TypeInfoType
,
1737 SourceLocation TypeidLoc
,
1738 TypeSourceInfo
*Operand
,
1739 SourceLocation RParenLoc
) {
1740 return getSema().BuildCXXUuidof(TypeInfoType
, TypeidLoc
, Operand
,
1744 /// \brief Build a new C++ __uuidof(expr) expression.
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
1748 ExprResult
RebuildCXXUuidofExpr(QualType TypeInfoType
,
1749 SourceLocation TypeidLoc
,
1751 SourceLocation RParenLoc
) {
1752 return getSema().BuildCXXUuidof(TypeInfoType
, TypeidLoc
, Operand
,
1756 /// \brief Build a new C++ "this" expression.
1758 /// By default, builds a new "this" expression without performing any
1759 /// semantic analysis. Subclasses may override this routine to provide
1760 /// different behavior.
1761 ExprResult
RebuildCXXThisExpr(SourceLocation ThisLoc
,
1764 return getSema().Owned(
1765 new (getSema().Context
) CXXThisExpr(ThisLoc
, ThisType
,
1769 /// \brief Build a new C++ throw expression.
1771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
1773 ExprResult
RebuildCXXThrowExpr(SourceLocation ThrowLoc
, Expr
*Sub
) {
1774 return getSema().ActOnCXXThrow(ThrowLoc
, Sub
);
1777 /// \brief Build a new C++ default-argument expression.
1779 /// By default, builds a new default-argument expression, which does not
1780 /// require any semantic analysis. Subclasses may override this routine to
1781 /// provide different behavior.
1782 ExprResult
RebuildCXXDefaultArgExpr(SourceLocation Loc
,
1783 ParmVarDecl
*Param
) {
1784 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context
, Loc
,
1788 /// \brief Build a new C++ zero-initialization expression.
1790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
1792 ExprResult
RebuildCXXScalarValueInitExpr(TypeSourceInfo
*TSInfo
,
1793 SourceLocation LParenLoc
,
1794 SourceLocation RParenLoc
) {
1795 return getSema().BuildCXXTypeConstructExpr(TSInfo
, LParenLoc
,
1796 MultiExprArg(getSema(), 0, 0),
1800 /// \brief Build a new C++ "new" expression.
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
1804 ExprResult
RebuildCXXNewExpr(SourceLocation StartLoc
,
1806 SourceLocation PlacementLParen
,
1807 MultiExprArg PlacementArgs
,
1808 SourceLocation PlacementRParen
,
1809 SourceRange TypeIdParens
,
1810 QualType AllocatedType
,
1811 TypeSourceInfo
*AllocatedTypeInfo
,
1813 SourceLocation ConstructorLParen
,
1814 MultiExprArg ConstructorArgs
,
1815 SourceLocation ConstructorRParen
) {
1816 return getSema().BuildCXXNew(StartLoc
, UseGlobal
,
1818 move(PlacementArgs
),
1825 move(ConstructorArgs
),
1829 /// \brief Build a new C++ "delete" expression.
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
1833 ExprResult
RebuildCXXDeleteExpr(SourceLocation StartLoc
,
1834 bool IsGlobalDelete
,
1837 return getSema().ActOnCXXDelete(StartLoc
, IsGlobalDelete
, IsArrayForm
,
1841 /// \brief Build a new unary type trait expression.
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
1845 ExprResult
RebuildUnaryTypeTrait(UnaryTypeTrait Trait
,
1846 SourceLocation StartLoc
,
1848 SourceLocation RParenLoc
) {
1849 return getSema().BuildUnaryTypeTrait(Trait
, StartLoc
, T
, RParenLoc
);
1852 /// \brief Build a new binary type trait expression.
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
1856 ExprResult
RebuildBinaryTypeTrait(BinaryTypeTrait Trait
,
1857 SourceLocation StartLoc
,
1858 TypeSourceInfo
*LhsT
,
1859 TypeSourceInfo
*RhsT
,
1860 SourceLocation RParenLoc
) {
1861 return getSema().BuildBinaryTypeTrait(Trait
, StartLoc
, LhsT
, RhsT
, RParenLoc
);
1864 /// \brief Build a new (previously unresolved) declaration reference
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
1869 ExprResult
RebuildDependentScopeDeclRefExpr(NestedNameSpecifier
*NNS
,
1870 SourceRange QualifierRange
,
1871 const DeclarationNameInfo
&NameInfo
,
1872 const TemplateArgumentListInfo
*TemplateArgs
) {
1874 SS
.setRange(QualifierRange
);
1875 SS
.setScopeRep(NNS
);
1878 return getSema().BuildQualifiedTemplateIdExpr(SS
, NameInfo
,
1881 return getSema().BuildQualifiedDeclarationNameExpr(SS
, NameInfo
);
1884 /// \brief Build a new template-id expression.
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
1888 ExprResult
RebuildTemplateIdExpr(const CXXScopeSpec
&SS
,
1891 const TemplateArgumentListInfo
&TemplateArgs
) {
1892 return getSema().BuildTemplateIdExpr(SS
, R
, RequiresADL
, TemplateArgs
);
1895 /// \brief Build a new object-construction expression.
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
1899 ExprResult
RebuildCXXConstructExpr(QualType T
,
1901 CXXConstructorDecl
*Constructor
,
1904 bool RequiresZeroInit
,
1905 CXXConstructExpr::ConstructionKind ConstructKind
,
1906 SourceRange ParenRange
) {
1907 ASTOwningVector
<Expr
*> ConvertedArgs(SemaRef
);
1908 if (getSema().CompleteConstructorCall(Constructor
, move(Args
), Loc
,
1912 return getSema().BuildCXXConstructExpr(Loc
, T
, Constructor
, IsElidable
,
1913 move_arg(ConvertedArgs
),
1914 RequiresZeroInit
, ConstructKind
,
1918 /// \brief Build a new object-construction expression.
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
1922 ExprResult
RebuildCXXTemporaryObjectExpr(TypeSourceInfo
*TSInfo
,
1923 SourceLocation LParenLoc
,
1925 SourceLocation RParenLoc
) {
1926 return getSema().BuildCXXTypeConstructExpr(TSInfo
,
1932 /// \brief Build a new object-construction expression.
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
1936 ExprResult
RebuildCXXUnresolvedConstructExpr(TypeSourceInfo
*TSInfo
,
1937 SourceLocation LParenLoc
,
1939 SourceLocation RParenLoc
) {
1940 return getSema().BuildCXXTypeConstructExpr(TSInfo
,
1946 /// \brief Build a new member reference expression.
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
1950 ExprResult
RebuildCXXDependentScopeMemberExpr(Expr
*BaseE
,
1953 SourceLocation OperatorLoc
,
1954 NestedNameSpecifier
*Qualifier
,
1955 SourceRange QualifierRange
,
1956 NamedDecl
*FirstQualifierInScope
,
1957 const DeclarationNameInfo
&MemberNameInfo
,
1958 const TemplateArgumentListInfo
*TemplateArgs
) {
1960 SS
.setRange(QualifierRange
);
1961 SS
.setScopeRep(Qualifier
);
1963 return SemaRef
.BuildMemberReferenceExpr(BaseE
, BaseType
,
1964 OperatorLoc
, IsArrow
,
1965 SS
, FirstQualifierInScope
,
1970 /// \brief Build a new member reference expression.
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
1974 ExprResult
RebuildUnresolvedMemberExpr(Expr
*BaseE
,
1976 SourceLocation OperatorLoc
,
1978 NestedNameSpecifier
*Qualifier
,
1979 SourceRange QualifierRange
,
1980 NamedDecl
*FirstQualifierInScope
,
1982 const TemplateArgumentListInfo
*TemplateArgs
) {
1984 SS
.setRange(QualifierRange
);
1985 SS
.setScopeRep(Qualifier
);
1987 return SemaRef
.BuildMemberReferenceExpr(BaseE
, BaseType
,
1988 OperatorLoc
, IsArrow
,
1989 SS
, FirstQualifierInScope
,
1993 /// \brief Build a new noexcept expression.
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
1997 ExprResult
RebuildCXXNoexceptExpr(SourceRange Range
, Expr
*Arg
) {
1998 return SemaRef
.BuildCXXNoexceptExpr(Range
.getBegin(), Arg
, Range
.getEnd());
2001 /// \brief Build a new expression to compute the length of a parameter pack.
2002 ExprResult
RebuildSizeOfPackExpr(SourceLocation OperatorLoc
, NamedDecl
*Pack
,
2003 SourceLocation PackLoc
,
2004 SourceLocation RParenLoc
,
2006 return new (SemaRef
.Context
) SizeOfPackExpr(SemaRef
.Context
.getSizeType(),
2007 OperatorLoc
, Pack
, PackLoc
,
2011 /// \brief Build a new Objective-C @encode expression.
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
2015 ExprResult
RebuildObjCEncodeExpr(SourceLocation AtLoc
,
2016 TypeSourceInfo
*EncodeTypeInfo
,
2017 SourceLocation RParenLoc
) {
2018 return SemaRef
.Owned(SemaRef
.BuildObjCEncodeExpression(AtLoc
, EncodeTypeInfo
,
2022 /// \brief Build a new Objective-C class message.
2023 ExprResult
RebuildObjCMessageExpr(TypeSourceInfo
*ReceiverTypeInfo
,
2025 SourceLocation SelectorLoc
,
2026 ObjCMethodDecl
*Method
,
2027 SourceLocation LBracLoc
,
2029 SourceLocation RBracLoc
) {
2030 return SemaRef
.BuildClassMessage(ReceiverTypeInfo
,
2031 ReceiverTypeInfo
->getType(),
2032 /*SuperLoc=*/SourceLocation(),
2033 Sel
, Method
, LBracLoc
, SelectorLoc
,
2034 RBracLoc
, move(Args
));
2037 /// \brief Build a new Objective-C instance message.
2038 ExprResult
RebuildObjCMessageExpr(Expr
*Receiver
,
2040 SourceLocation SelectorLoc
,
2041 ObjCMethodDecl
*Method
,
2042 SourceLocation LBracLoc
,
2044 SourceLocation RBracLoc
) {
2045 return SemaRef
.BuildInstanceMessage(Receiver
,
2046 Receiver
->getType(),
2047 /*SuperLoc=*/SourceLocation(),
2048 Sel
, Method
, LBracLoc
, SelectorLoc
,
2049 RBracLoc
, move(Args
));
2052 /// \brief Build a new Objective-C ivar reference expression.
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
2056 ExprResult
RebuildObjCIvarRefExpr(Expr
*BaseArg
, ObjCIvarDecl
*Ivar
,
2057 SourceLocation IvarLoc
,
2058 bool IsArrow
, bool IsFreeIvar
) {
2059 // FIXME: We lose track of the IsFreeIvar bit.
2061 Expr
*Base
= BaseArg
;
2062 LookupResult
R(getSema(), Ivar
->getDeclName(), IvarLoc
,
2063 Sema::LookupMemberName
);
2064 ExprResult Result
= getSema().LookupMemberExpr(R
, Base
, IsArrow
,
2068 if (Result
.isInvalid())
2072 return move(Result
);
2074 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
2075 /*FIXME:*/IvarLoc
, IsArrow
, SS
,
2076 /*FirstQualifierInScope=*/0,
2078 /*TemplateArgs=*/0);
2081 /// \brief Build a new Objective-C property reference expression.
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
2085 ExprResult
RebuildObjCPropertyRefExpr(Expr
*BaseArg
,
2086 ObjCPropertyDecl
*Property
,
2087 SourceLocation PropertyLoc
) {
2089 Expr
*Base
= BaseArg
;
2090 LookupResult
R(getSema(), Property
->getDeclName(), PropertyLoc
,
2091 Sema::LookupMemberName
);
2092 bool IsArrow
= false;
2093 ExprResult Result
= getSema().LookupMemberExpr(R
, Base
, IsArrow
,
2094 /*FIME:*/PropertyLoc
,
2096 if (Result
.isInvalid())
2100 return move(Result
);
2102 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
2103 /*FIXME:*/PropertyLoc
, IsArrow
,
2105 /*FirstQualifierInScope=*/0,
2107 /*TemplateArgs=*/0);
2110 /// \brief Build a new Objective-C property reference expression.
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
2114 ExprResult
RebuildObjCPropertyRefExpr(Expr
*Base
, QualType T
,
2115 ObjCMethodDecl
*Getter
,
2116 ObjCMethodDecl
*Setter
,
2117 SourceLocation PropertyLoc
) {
2118 // Since these expressions can only be value-dependent, we do not
2119 // need to perform semantic analysis again.
2121 new (getSema().Context
) ObjCPropertyRefExpr(Getter
, Setter
, T
,
2122 VK_LValue
, OK_ObjCProperty
,
2123 PropertyLoc
, Base
));
2126 /// \brief Build a new Objective-C "isa" expression.
2128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
2130 ExprResult
RebuildObjCIsaExpr(Expr
*BaseArg
, SourceLocation IsaLoc
,
2133 Expr
*Base
= BaseArg
;
2134 LookupResult
R(getSema(), &getSema().Context
.Idents
.get("isa"), IsaLoc
,
2135 Sema::LookupMemberName
);
2136 ExprResult Result
= getSema().LookupMemberExpr(R
, Base
, IsArrow
,
2139 if (Result
.isInvalid())
2143 return move(Result
);
2145 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
2146 /*FIXME:*/IsaLoc
, IsArrow
, SS
,
2147 /*FirstQualifierInScope=*/0,
2149 /*TemplateArgs=*/0);
2152 /// \brief Build a new shuffle vector expression.
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
2156 ExprResult
RebuildShuffleVectorExpr(SourceLocation BuiltinLoc
,
2157 MultiExprArg SubExprs
,
2158 SourceLocation RParenLoc
) {
2159 // Find the declaration for __builtin_shufflevector
2160 const IdentifierInfo
&Name
2161 = SemaRef
.Context
.Idents
.get("__builtin_shufflevector");
2162 TranslationUnitDecl
*TUDecl
= SemaRef
.Context
.getTranslationUnitDecl();
2163 DeclContext::lookup_result Lookup
= TUDecl
->lookup(DeclarationName(&Name
));
2164 assert(Lookup
.first
!= Lookup
.second
&& "No __builtin_shufflevector?");
2166 // Build a reference to the __builtin_shufflevector builtin
2167 FunctionDecl
*Builtin
= cast
<FunctionDecl
>(*Lookup
.first
);
2169 = new (SemaRef
.Context
) DeclRefExpr(Builtin
, Builtin
->getType(),
2170 VK_LValue
, BuiltinLoc
);
2171 SemaRef
.UsualUnaryConversions(Callee
);
2173 // Build the CallExpr
2174 unsigned NumSubExprs
= SubExprs
.size();
2175 Expr
**Subs
= (Expr
**)SubExprs
.release();
2176 CallExpr
*TheCall
= new (SemaRef
.Context
) CallExpr(SemaRef
.Context
, Callee
,
2178 Builtin
->getCallResultType(),
2179 Expr::getValueKindForType(Builtin
->getResultType()),
2181 ExprResult
OwnedCall(SemaRef
.Owned(TheCall
));
2183 // Type-check the __builtin_shufflevector expression.
2184 ExprResult Result
= SemaRef
.SemaBuiltinShuffleVector(TheCall
);
2185 if (Result
.isInvalid())
2188 OwnedCall
.release();
2189 return move(Result
);
2192 /// \brief Build a new template argument pack expansion.
2194 /// By default, performs semantic analysis to build a new pack expansion
2195 /// for a template argument. Subclasses may override this routine to provide
2196 /// different behavior.
2197 TemplateArgumentLoc
RebuildPackExpansion(TemplateArgumentLoc Pattern
,
2198 SourceLocation EllipsisLoc
,
2199 llvm::Optional
<unsigned> NumExpansions
) {
2200 switch (Pattern
.getArgument().getKind()) {
2201 case TemplateArgument::Expression
: {
2203 = getSema().CheckPackExpansion(Pattern
.getSourceExpression(),
2204 EllipsisLoc
, NumExpansions
);
2205 if (Result
.isInvalid())
2206 return TemplateArgumentLoc();
2208 return TemplateArgumentLoc(Result
.get(), Result
.get());
2211 case TemplateArgument::Template
:
2212 return TemplateArgumentLoc(TemplateArgument(
2213 Pattern
.getArgument().getAsTemplate(),
2215 Pattern
.getTemplateQualifierRange(),
2216 Pattern
.getTemplateNameLoc(),
2219 case TemplateArgument::Null
:
2220 case TemplateArgument::Integral
:
2221 case TemplateArgument::Declaration
:
2222 case TemplateArgument::Pack
:
2223 case TemplateArgument::TemplateExpansion
:
2224 llvm_unreachable("Pack expansion pattern has no parameter packs");
2226 case TemplateArgument::Type
:
2227 if (TypeSourceInfo
*Expansion
2228 = getSema().CheckPackExpansion(Pattern
.getTypeSourceInfo(),
2231 return TemplateArgumentLoc(TemplateArgument(Expansion
->getType()),
2236 return TemplateArgumentLoc();
2239 /// \brief Build a new expression pack expansion.
2241 /// By default, performs semantic analysis to build a new pack expansion
2242 /// for an expression. Subclasses may override this routine to provide
2243 /// different behavior.
2244 ExprResult
RebuildPackExpansion(Expr
*Pattern
, SourceLocation EllipsisLoc
,
2245 llvm::Optional
<unsigned> NumExpansions
) {
2246 return getSema().CheckPackExpansion(Pattern
, EllipsisLoc
, NumExpansions
);
2250 QualType
TransformTypeInObjectScope(QualType T
,
2251 QualType ObjectType
,
2252 NamedDecl
*FirstQualifierInScope
,
2253 NestedNameSpecifier
*Prefix
);
2255 TypeSourceInfo
*TransformTypeInObjectScope(TypeSourceInfo
*T
,
2256 QualType ObjectType
,
2257 NamedDecl
*FirstQualifierInScope
,
2258 NestedNameSpecifier
*Prefix
);
2261 template<typename Derived
>
2262 StmtResult TreeTransform
<Derived
>::TransformStmt(Stmt
*S
) {
2264 return SemaRef
.Owned(S
);
2266 switch (S
->getStmtClass()) {
2267 case Stmt::NoStmtClass
: break;
2269 // Transform individual statement nodes
2270 #define STMT(Node, Parent) \
2271 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2272 #define ABSTRACT_STMT(Node)
2273 #define EXPR(Node, Parent)
2274 #include "clang/AST/StmtNodes.inc"
2276 // Transform expressions by calling TransformExpr.
2277 #define STMT(Node, Parent)
2278 #define ABSTRACT_STMT(Stmt)
2279 #define EXPR(Node, Parent) case Stmt::Node##Class:
2280 #include "clang/AST/StmtNodes.inc"
2282 ExprResult E
= getDerived().TransformExpr(cast
<Expr
>(S
));
2286 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E
.take()));
2290 return SemaRef
.Owned(S
);
2294 template<typename Derived
>
2295 ExprResult TreeTransform
<Derived
>::TransformExpr(Expr
*E
) {
2297 return SemaRef
.Owned(E
);
2299 switch (E
->getStmtClass()) {
2300 case Stmt::NoStmtClass
: break;
2301 #define STMT(Node, Parent) case Stmt::Node##Class: break;
2302 #define ABSTRACT_STMT(Stmt)
2303 #define EXPR(Node, Parent) \
2304 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
2305 #include "clang/AST/StmtNodes.inc"
2308 return SemaRef
.Owned(E
);
2311 template<typename Derived
>
2312 bool TreeTransform
<Derived
>::TransformExprs(Expr
**Inputs
,
2315 llvm::SmallVectorImpl
<Expr
*> &Outputs
,
2317 for (unsigned I
= 0; I
!= NumInputs
; ++I
) {
2318 // If requested, drop call arguments that need to be dropped.
2319 if (IsCall
&& getDerived().DropCallArgument(Inputs
[I
])) {
2326 if (PackExpansionExpr
*Expansion
= dyn_cast
<PackExpansionExpr
>(Inputs
[I
])) {
2327 Expr
*Pattern
= Expansion
->getPattern();
2329 llvm::SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
2330 getSema().collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
2331 assert(!Unexpanded
.empty() && "Pack expansion without parameter packs?");
2333 // Determine whether the set of unexpanded parameter packs can and should
2336 bool RetainExpansion
= false;
2337 llvm::Optional
<unsigned> OrigNumExpansions
2338 = Expansion
->getNumExpansions();
2339 llvm::Optional
<unsigned> NumExpansions
= OrigNumExpansions
;
2340 if (getDerived().TryExpandParameterPacks(Expansion
->getEllipsisLoc(),
2341 Pattern
->getSourceRange(),
2344 Expand
, RetainExpansion
,
2349 // The transform has determined that we should perform a simple
2350 // transformation on the pack expansion, producing another pack
2352 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
2353 ExprResult OutPattern
= getDerived().TransformExpr(Pattern
);
2354 if (OutPattern
.isInvalid())
2357 ExprResult Out
= getDerived().RebuildPackExpansion(OutPattern
.get(),
2358 Expansion
->getEllipsisLoc(),
2360 if (Out
.isInvalid())
2365 Outputs
.push_back(Out
.get());
2369 // The transform has determined that we should perform an elementwise
2370 // expansion of the pattern. Do so.
2371 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
2372 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
2373 ExprResult Out
= getDerived().TransformExpr(Pattern
);
2374 if (Out
.isInvalid())
2377 if (Out
.get()->containsUnexpandedParameterPack()) {
2378 Out
= RebuildPackExpansion(Out
.get(), Expansion
->getEllipsisLoc(),
2380 if (Out
.isInvalid())
2386 Outputs
.push_back(Out
.get());
2392 ExprResult Result
= getDerived().TransformExpr(Inputs
[I
]);
2393 if (Result
.isInvalid())
2396 if (Result
.get() != Inputs
[I
] && ArgChanged
)
2399 Outputs
.push_back(Result
.get());
2405 template<typename Derived
>
2406 NestedNameSpecifier
*
2407 TreeTransform
<Derived
>::TransformNestedNameSpecifier(NestedNameSpecifier
*NNS
,
2409 QualType ObjectType
,
2410 NamedDecl
*FirstQualifierInScope
) {
2411 NestedNameSpecifier
*Prefix
= NNS
->getPrefix();
2413 // Transform the prefix of this nested name specifier.
2415 Prefix
= getDerived().TransformNestedNameSpecifier(Prefix
, Range
,
2417 FirstQualifierInScope
);
2422 switch (NNS
->getKind()) {
2423 case NestedNameSpecifier::Identifier
:
2425 // The object type and qualifier-in-scope really apply to the
2427 ObjectType
= QualType();
2428 FirstQualifierInScope
= 0;
2431 assert((Prefix
|| !ObjectType
.isNull()) &&
2432 "Identifier nested-name-specifier with no prefix or object type");
2433 if (!getDerived().AlwaysRebuild() && Prefix
== NNS
->getPrefix() &&
2434 ObjectType
.isNull())
2437 return getDerived().RebuildNestedNameSpecifier(Prefix
, Range
,
2438 *NNS
->getAsIdentifier(),
2440 FirstQualifierInScope
);
2442 case NestedNameSpecifier::Namespace
: {
2444 = cast_or_null
<NamespaceDecl
>(
2445 getDerived().TransformDecl(Range
.getBegin(),
2446 NNS
->getAsNamespace()));
2447 if (!getDerived().AlwaysRebuild() &&
2448 Prefix
== NNS
->getPrefix() &&
2449 NS
== NNS
->getAsNamespace())
2452 return getDerived().RebuildNestedNameSpecifier(Prefix
, Range
, NS
);
2455 case NestedNameSpecifier::Global
:
2456 // There is no meaningful transformation that one could perform on the
2460 case NestedNameSpecifier::TypeSpecWithTemplate
:
2461 case NestedNameSpecifier::TypeSpec
: {
2462 TemporaryBase
Rebase(*this, Range
.getBegin(), DeclarationName());
2463 QualType T
= TransformTypeInObjectScope(QualType(NNS
->getAsType(), 0),
2465 FirstQualifierInScope
,
2470 if (!getDerived().AlwaysRebuild() &&
2471 Prefix
== NNS
->getPrefix() &&
2472 T
== QualType(NNS
->getAsType(), 0))
2475 return getDerived().RebuildNestedNameSpecifier(Prefix
, Range
,
2476 NNS
->getKind() == NestedNameSpecifier::TypeSpecWithTemplate
,
2481 // Required to silence a GCC warning
2485 template<typename Derived
>
2487 TreeTransform
<Derived
>
2488 ::TransformDeclarationNameInfo(const DeclarationNameInfo
&NameInfo
) {
2489 DeclarationName Name
= NameInfo
.getName();
2491 return DeclarationNameInfo();
2493 switch (Name
.getNameKind()) {
2494 case DeclarationName::Identifier
:
2495 case DeclarationName::ObjCZeroArgSelector
:
2496 case DeclarationName::ObjCOneArgSelector
:
2497 case DeclarationName::ObjCMultiArgSelector
:
2498 case DeclarationName::CXXOperatorName
:
2499 case DeclarationName::CXXLiteralOperatorName
:
2500 case DeclarationName::CXXUsingDirective
:
2503 case DeclarationName::CXXConstructorName
:
2504 case DeclarationName::CXXDestructorName
:
2505 case DeclarationName::CXXConversionFunctionName
: {
2506 TypeSourceInfo
*NewTInfo
;
2507 CanQualType NewCanTy
;
2508 if (TypeSourceInfo
*OldTInfo
= NameInfo
.getNamedTypeInfo()) {
2509 NewTInfo
= getDerived().TransformType(OldTInfo
);
2511 return DeclarationNameInfo();
2512 NewCanTy
= SemaRef
.Context
.getCanonicalType(NewTInfo
->getType());
2516 TemporaryBase
Rebase(*this, NameInfo
.getLoc(), Name
);
2517 QualType NewT
= getDerived().TransformType(Name
.getCXXNameType());
2519 return DeclarationNameInfo();
2520 NewCanTy
= SemaRef
.Context
.getCanonicalType(NewT
);
2523 DeclarationName NewName
2524 = SemaRef
.Context
.DeclarationNames
.getCXXSpecialName(Name
.getNameKind(),
2526 DeclarationNameInfo
NewNameInfo(NameInfo
);
2527 NewNameInfo
.setName(NewName
);
2528 NewNameInfo
.setNamedTypeInfo(NewTInfo
);
2533 assert(0 && "Unknown name kind.");
2534 return DeclarationNameInfo();
2537 template<typename Derived
>
2539 TreeTransform
<Derived
>::TransformTemplateName(TemplateName Name
,
2540 QualType ObjectType
,
2541 NamedDecl
*FirstQualifierInScope
) {
2542 SourceLocation Loc
= getDerived().getBaseLocation();
2544 if (QualifiedTemplateName
*QTN
= Name
.getAsQualifiedTemplateName()) {
2545 NestedNameSpecifier
*NNS
2546 = getDerived().TransformNestedNameSpecifier(QTN
->getQualifier(),
2547 /*FIXME*/ SourceRange(Loc
),
2549 FirstQualifierInScope
);
2551 return TemplateName();
2553 if (TemplateDecl
*Template
= QTN
->getTemplateDecl()) {
2554 TemplateDecl
*TransTemplate
2555 = cast_or_null
<TemplateDecl
>(getDerived().TransformDecl(Loc
, Template
));
2557 return TemplateName();
2559 if (!getDerived().AlwaysRebuild() &&
2560 NNS
== QTN
->getQualifier() &&
2561 TransTemplate
== Template
)
2564 return getDerived().RebuildTemplateName(NNS
, QTN
->hasTemplateKeyword(),
2568 // These should be getting filtered out before they make it into the AST.
2569 llvm_unreachable("overloaded template name survived to here");
2572 if (DependentTemplateName
*DTN
= Name
.getAsDependentTemplateName()) {
2573 NestedNameSpecifier
*NNS
= DTN
->getQualifier();
2575 NNS
= getDerived().TransformNestedNameSpecifier(NNS
,
2576 /*FIXME:*/SourceRange(Loc
),
2578 FirstQualifierInScope
);
2579 if (!NNS
) return TemplateName();
2581 // These apply to the scope specifier, not the template.
2582 ObjectType
= QualType();
2583 FirstQualifierInScope
= 0;
2586 if (!getDerived().AlwaysRebuild() &&
2587 NNS
== DTN
->getQualifier() &&
2588 ObjectType
.isNull())
2591 if (DTN
->isIdentifier()) {
2593 SourceRange
QualifierRange(getDerived().getBaseLocation());
2594 return getDerived().RebuildTemplateName(NNS
, QualifierRange
,
2595 *DTN
->getIdentifier(),
2597 FirstQualifierInScope
);
2600 return getDerived().RebuildTemplateName(NNS
, DTN
->getOperator(),
2604 if (TemplateDecl
*Template
= Name
.getAsTemplateDecl()) {
2605 TemplateDecl
*TransTemplate
2606 = cast_or_null
<TemplateDecl
>(getDerived().TransformDecl(Loc
, Template
));
2608 return TemplateName();
2610 if (!getDerived().AlwaysRebuild() &&
2611 TransTemplate
== Template
)
2614 return TemplateName(TransTemplate
);
2617 if (SubstTemplateTemplateParmPackStorage
*SubstPack
2618 = Name
.getAsSubstTemplateTemplateParmPack()) {
2619 TemplateTemplateParmDecl
*TransParam
2620 = cast_or_null
<TemplateTemplateParmDecl
>(
2621 getDerived().TransformDecl(Loc
, SubstPack
->getParameterPack()));
2623 return TemplateName();
2625 if (!getDerived().AlwaysRebuild() &&
2626 TransParam
== SubstPack
->getParameterPack())
2629 return getDerived().RebuildTemplateName(TransParam
,
2630 SubstPack
->getArgumentPack());
2633 // These should be getting filtered out before they reach the AST.
2634 llvm_unreachable("overloaded function decl survived to here");
2635 return TemplateName();
2638 template<typename Derived
>
2639 void TreeTransform
<Derived
>::InventTemplateArgumentLoc(
2640 const TemplateArgument
&Arg
,
2641 TemplateArgumentLoc
&Output
) {
2642 SourceLocation Loc
= getDerived().getBaseLocation();
2643 switch (Arg
.getKind()) {
2644 case TemplateArgument::Null
:
2645 llvm_unreachable("null template argument in TreeTransform");
2648 case TemplateArgument::Type
:
2649 Output
= TemplateArgumentLoc(Arg
,
2650 SemaRef
.Context
.getTrivialTypeSourceInfo(Arg
.getAsType(), Loc
));
2654 case TemplateArgument::Template
:
2655 Output
= TemplateArgumentLoc(Arg
, SourceRange(), Loc
);
2658 case TemplateArgument::TemplateExpansion
:
2659 Output
= TemplateArgumentLoc(Arg
, SourceRange(), Loc
, Loc
);
2662 case TemplateArgument::Expression
:
2663 Output
= TemplateArgumentLoc(Arg
, Arg
.getAsExpr());
2666 case TemplateArgument::Declaration
:
2667 case TemplateArgument::Integral
:
2668 case TemplateArgument::Pack
:
2669 Output
= TemplateArgumentLoc(Arg
, TemplateArgumentLocInfo());
2674 template<typename Derived
>
2675 bool TreeTransform
<Derived
>::TransformTemplateArgument(
2676 const TemplateArgumentLoc
&Input
,
2677 TemplateArgumentLoc
&Output
) {
2678 const TemplateArgument
&Arg
= Input
.getArgument();
2679 switch (Arg
.getKind()) {
2680 case TemplateArgument::Null
:
2681 case TemplateArgument::Integral
:
2685 case TemplateArgument::Type
: {
2686 TypeSourceInfo
*DI
= Input
.getTypeSourceInfo();
2688 DI
= InventTypeSourceInfo(Input
.getArgument().getAsType());
2690 DI
= getDerived().TransformType(DI
);
2691 if (!DI
) return true;
2693 Output
= TemplateArgumentLoc(TemplateArgument(DI
->getType()), DI
);
2697 case TemplateArgument::Declaration
: {
2698 // FIXME: we should never have to transform one of these.
2699 DeclarationName Name
;
2700 if (NamedDecl
*ND
= dyn_cast
<NamedDecl
>(Arg
.getAsDecl()))
2701 Name
= ND
->getDeclName();
2702 TemporaryBase
Rebase(*this, Input
.getLocation(), Name
);
2703 Decl
*D
= getDerived().TransformDecl(Input
.getLocation(), Arg
.getAsDecl());
2704 if (!D
) return true;
2706 Expr
*SourceExpr
= Input
.getSourceDeclExpression();
2708 EnterExpressionEvaluationContext
Unevaluated(getSema(),
2710 ExprResult E
= getDerived().TransformExpr(SourceExpr
);
2711 SourceExpr
= (E
.isInvalid() ? 0 : E
.take());
2714 Output
= TemplateArgumentLoc(TemplateArgument(D
), SourceExpr
);
2718 case TemplateArgument::Template
: {
2719 TemporaryBase
Rebase(*this, Input
.getLocation(), DeclarationName());
2720 TemplateName Template
2721 = getDerived().TransformTemplateName(Arg
.getAsTemplate());
2722 if (Template
.isNull())
2725 Output
= TemplateArgumentLoc(TemplateArgument(Template
),
2726 Input
.getTemplateQualifierRange(),
2727 Input
.getTemplateNameLoc());
2731 case TemplateArgument::TemplateExpansion
:
2732 llvm_unreachable("Caller should expand pack expansions");
2734 case TemplateArgument::Expression
: {
2735 // Template argument expressions are not potentially evaluated.
2736 EnterExpressionEvaluationContext
Unevaluated(getSema(),
2739 Expr
*InputExpr
= Input
.getSourceExpression();
2740 if (!InputExpr
) InputExpr
= Input
.getArgument().getAsExpr();
2743 = getDerived().TransformExpr(InputExpr
);
2744 if (E
.isInvalid()) return true;
2745 Output
= TemplateArgumentLoc(TemplateArgument(E
.take()), E
.take());
2749 case TemplateArgument::Pack
: {
2750 llvm::SmallVector
<TemplateArgument
, 4> TransformedArgs
;
2751 TransformedArgs
.reserve(Arg
.pack_size());
2752 for (TemplateArgument::pack_iterator A
= Arg
.pack_begin(),
2753 AEnd
= Arg
.pack_end();
2756 // FIXME: preserve source information here when we start
2757 // caring about parameter packs.
2759 TemplateArgumentLoc InputArg
;
2760 TemplateArgumentLoc OutputArg
;
2761 getDerived().InventTemplateArgumentLoc(*A
, InputArg
);
2762 if (getDerived().TransformTemplateArgument(InputArg
, OutputArg
))
2765 TransformedArgs
.push_back(OutputArg
.getArgument());
2768 TemplateArgument
*TransformedArgsPtr
2769 = new (getSema().Context
) TemplateArgument
[TransformedArgs
.size()];
2770 std::copy(TransformedArgs
.begin(), TransformedArgs
.end(),
2771 TransformedArgsPtr
);
2772 Output
= TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr
,
2773 TransformedArgs
.size()),
2774 Input
.getLocInfo());
2779 // Work around bogus GCC warning
2783 /// \brief Iterator adaptor that invents template argument location information
2784 /// for each of the template arguments in its underlying iterator.
2785 template<typename Derived
, typename InputIterator
>
2786 class TemplateArgumentLocInventIterator
{
2787 TreeTransform
<Derived
> &Self
;
2791 typedef TemplateArgumentLoc value_type
;
2792 typedef TemplateArgumentLoc reference
;
2793 typedef typename
std::iterator_traits
<InputIterator
>::difference_type
2795 typedef std::input_iterator_tag iterator_category
;
2798 TemplateArgumentLoc Arg
;
2801 explicit pointer(TemplateArgumentLoc Arg
) : Arg(Arg
) { }
2803 const TemplateArgumentLoc
*operator->() const { return &Arg
; }
2806 TemplateArgumentLocInventIterator() { }
2808 explicit TemplateArgumentLocInventIterator(TreeTransform
<Derived
> &Self
,
2810 : Self(Self
), Iter(Iter
) { }
2812 TemplateArgumentLocInventIterator
&operator++() {
2817 TemplateArgumentLocInventIterator
operator++(int) {
2818 TemplateArgumentLocInventIterator
Old(*this);
2823 reference
operator*() const {
2824 TemplateArgumentLoc Result
;
2825 Self
.InventTemplateArgumentLoc(*Iter
, Result
);
2829 pointer
operator->() const { return pointer(**this); }
2831 friend bool operator==(const TemplateArgumentLocInventIterator
&X
,
2832 const TemplateArgumentLocInventIterator
&Y
) {
2833 return X
.Iter
== Y
.Iter
;
2836 friend bool operator!=(const TemplateArgumentLocInventIterator
&X
,
2837 const TemplateArgumentLocInventIterator
&Y
) {
2838 return X
.Iter
!= Y
.Iter
;
2842 template<typename Derived
>
2843 template<typename InputIterator
>
2844 bool TreeTransform
<Derived
>::TransformTemplateArguments(InputIterator First
,
2846 TemplateArgumentListInfo
&Outputs
) {
2847 for (; First
!= Last
; ++First
) {
2848 TemplateArgumentLoc Out
;
2849 TemplateArgumentLoc In
= *First
;
2851 if (In
.getArgument().getKind() == TemplateArgument::Pack
) {
2852 // Unpack argument packs, which we translate them into separate
2854 // FIXME: We could do much better if we could guarantee that the
2855 // TemplateArgumentLocInfo for the pack expansion would be usable for
2856 // all of the template arguments in the argument pack.
2857 typedef TemplateArgumentLocInventIterator
<Derived
,
2858 TemplateArgument::pack_iterator
>
2860 if (TransformTemplateArguments(PackLocIterator(*this,
2861 In
.getArgument().pack_begin()),
2862 PackLocIterator(*this,
2863 In
.getArgument().pack_end()),
2870 if (In
.getArgument().isPackExpansion()) {
2871 // We have a pack expansion, for which we will be substituting into
2873 SourceLocation Ellipsis
;
2874 llvm::Optional
<unsigned> OrigNumExpansions
;
2875 TemplateArgumentLoc Pattern
2876 = In
.getPackExpansionPattern(Ellipsis
, OrigNumExpansions
,
2879 llvm::SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
2880 getSema().collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
2881 assert(!Unexpanded
.empty() && "Pack expansion without parameter packs?");
2883 // Determine whether the set of unexpanded parameter packs can and should
2886 bool RetainExpansion
= false;
2887 llvm::Optional
<unsigned> NumExpansions
= OrigNumExpansions
;
2888 if (getDerived().TryExpandParameterPacks(Ellipsis
,
2889 Pattern
.getSourceRange(),
2898 // The transform has determined that we should perform a simple
2899 // transformation on the pack expansion, producing another pack
2901 TemplateArgumentLoc OutPattern
;
2902 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
2903 if (getDerived().TransformTemplateArgument(Pattern
, OutPattern
))
2906 Out
= getDerived().RebuildPackExpansion(OutPattern
, Ellipsis
,
2908 if (Out
.getArgument().isNull())
2911 Outputs
.addArgument(Out
);
2915 // The transform has determined that we should perform an elementwise
2916 // expansion of the pattern. Do so.
2917 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
2918 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
2920 if (getDerived().TransformTemplateArgument(Pattern
, Out
))
2923 if (Out
.getArgument().containsUnexpandedParameterPack()) {
2924 Out
= getDerived().RebuildPackExpansion(Out
, Ellipsis
,
2926 if (Out
.getArgument().isNull())
2930 Outputs
.addArgument(Out
);
2933 // If we're supposed to retain a pack expansion, do so by temporarily
2934 // forgetting the partially-substituted parameter pack.
2935 if (RetainExpansion
) {
2936 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
2938 if (getDerived().TransformTemplateArgument(Pattern
, Out
))
2941 Out
= getDerived().RebuildPackExpansion(Out
, Ellipsis
,
2943 if (Out
.getArgument().isNull())
2946 Outputs
.addArgument(Out
);
2953 if (getDerived().TransformTemplateArgument(In
, Out
))
2956 Outputs
.addArgument(Out
);
2963 //===----------------------------------------------------------------------===//
2964 // Type transformation
2965 //===----------------------------------------------------------------------===//
2967 template<typename Derived
>
2968 QualType TreeTransform
<Derived
>::TransformType(QualType T
) {
2969 if (getDerived().AlreadyTransformed(T
))
2972 // Temporary workaround. All of these transformations should
2973 // eventually turn into transformations on TypeLocs.
2974 TypeSourceInfo
*DI
= getSema().Context
.getTrivialTypeSourceInfo(T
,
2975 getDerived().getBaseLocation());
2977 TypeSourceInfo
*NewDI
= getDerived().TransformType(DI
);
2982 return NewDI
->getType();
2985 template<typename Derived
>
2986 TypeSourceInfo
*TreeTransform
<Derived
>::TransformType(TypeSourceInfo
*DI
) {
2987 if (getDerived().AlreadyTransformed(DI
->getType()))
2992 TypeLoc TL
= DI
->getTypeLoc();
2993 TLB
.reserve(TL
.getFullDataSize());
2995 QualType Result
= getDerived().TransformType(TLB
, TL
);
2996 if (Result
.isNull())
2999 return TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
3002 template<typename Derived
>
3004 TreeTransform
<Derived
>::TransformType(TypeLocBuilder
&TLB
, TypeLoc T
) {
3005 switch (T
.getTypeLocClass()) {
3006 #define ABSTRACT_TYPELOC(CLASS, PARENT)
3007 #define TYPELOC(CLASS, PARENT) \
3008 case TypeLoc::CLASS: \
3009 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3010 #include "clang/AST/TypeLocNodes.def"
3013 llvm_unreachable("unhandled type loc!");
3017 /// FIXME: By default, this routine adds type qualifiers only to types
3018 /// that can have qualifiers, and silently suppresses those qualifiers
3019 /// that are not permitted (e.g., qualifiers on reference or function
3020 /// types). This is the right thing for template instantiation, but
3021 /// probably not for other clients.
3022 template<typename Derived
>
3024 TreeTransform
<Derived
>::TransformQualifiedType(TypeLocBuilder
&TLB
,
3025 QualifiedTypeLoc T
) {
3026 Qualifiers Quals
= T
.getType().getLocalQualifiers();
3028 QualType Result
= getDerived().TransformType(TLB
, T
.getUnqualifiedLoc());
3029 if (Result
.isNull())
3032 // Silently suppress qualifiers if the result type can't be qualified.
3033 // FIXME: this is the right thing for template instantiation, but
3034 // probably not for other clients.
3035 if (Result
->isFunctionType() || Result
->isReferenceType())
3038 if (!Quals
.empty()) {
3039 Result
= SemaRef
.BuildQualifiedType(Result
, T
.getBeginLoc(), Quals
);
3040 TLB
.push
<QualifiedTypeLoc
>(Result
);
3041 // No location information to preserve.
3047 /// \brief Transforms a type that was written in a scope specifier,
3048 /// given an object type, the results of unqualified lookup, and
3049 /// an already-instantiated prefix.
3051 /// The object type is provided iff the scope specifier qualifies the
3052 /// member of a dependent member-access expression. The prefix is
3053 /// provided iff the the scope specifier in which this appears has a
3056 /// This is private to TreeTransform.
3057 template<typename Derived
>
3059 TreeTransform
<Derived
>::TransformTypeInObjectScope(QualType T
,
3060 QualType ObjectType
,
3061 NamedDecl
*UnqualLookup
,
3062 NestedNameSpecifier
*Prefix
) {
3063 if (getDerived().AlreadyTransformed(T
))
3066 TypeSourceInfo
*TSI
=
3067 SemaRef
.Context
.getTrivialTypeSourceInfo(T
, getDerived().getBaseLocation());
3069 TSI
= getDerived().TransformTypeInObjectScope(TSI
, ObjectType
,
3070 UnqualLookup
, Prefix
);
3071 if (!TSI
) return QualType();
3072 return TSI
->getType();
3075 template<typename Derived
>
3077 TreeTransform
<Derived
>::TransformTypeInObjectScope(TypeSourceInfo
*TSI
,
3078 QualType ObjectType
,
3079 NamedDecl
*UnqualLookup
,
3080 NestedNameSpecifier
*Prefix
) {
3081 // TODO: in some cases, we might be some verification to do here.
3082 if (ObjectType
.isNull())
3083 return getDerived().TransformType(TSI
);
3085 QualType T
= TSI
->getType();
3086 if (getDerived().AlreadyTransformed(T
))
3092 if (isa
<TemplateSpecializationType
>(T
)) {
3093 TemplateSpecializationTypeLoc TL
3094 = cast
<TemplateSpecializationTypeLoc
>(TSI
->getTypeLoc());
3096 TemplateName Template
=
3097 getDerived().TransformTemplateName(TL
.getTypePtr()->getTemplateName(),
3098 ObjectType
, UnqualLookup
);
3099 if (Template
.isNull()) return 0;
3101 Result
= getDerived()
3102 .TransformTemplateSpecializationType(TLB
, TL
, Template
);
3103 } else if (isa
<DependentTemplateSpecializationType
>(T
)) {
3104 DependentTemplateSpecializationTypeLoc TL
3105 = cast
<DependentTemplateSpecializationTypeLoc
>(TSI
->getTypeLoc());
3107 Result
= getDerived()
3108 .TransformDependentTemplateSpecializationType(TLB
, TL
, Prefix
);
3110 // Nothing special needs to be done for these.
3111 Result
= getDerived().TransformType(TLB
, TSI
->getTypeLoc());
3114 if (Result
.isNull()) return 0;
3115 return TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
3118 template <class TyLoc
> static inline
3119 QualType
TransformTypeSpecType(TypeLocBuilder
&TLB
, TyLoc T
) {
3120 TyLoc NewT
= TLB
.push
<TyLoc
>(T
.getType());
3121 NewT
.setNameLoc(T
.getNameLoc());
3125 template<typename Derived
>
3126 QualType TreeTransform
<Derived
>::TransformBuiltinType(TypeLocBuilder
&TLB
,
3128 BuiltinTypeLoc NewT
= TLB
.push
<BuiltinTypeLoc
>(T
.getType());
3129 NewT
.setBuiltinLoc(T
.getBuiltinLoc());
3130 if (T
.needsExtraLocalData())
3131 NewT
.getWrittenBuiltinSpecs() = T
.getWrittenBuiltinSpecs();
3135 template<typename Derived
>
3136 QualType TreeTransform
<Derived
>::TransformComplexType(TypeLocBuilder
&TLB
,
3139 return TransformTypeSpecType(TLB
, T
);
3142 template<typename Derived
>
3143 QualType TreeTransform
<Derived
>::TransformPointerType(TypeLocBuilder
&TLB
,
3144 PointerTypeLoc TL
) {
3145 QualType PointeeType
3146 = getDerived().TransformType(TLB
, TL
.getPointeeLoc());
3147 if (PointeeType
.isNull())
3150 QualType Result
= TL
.getType();
3151 if (PointeeType
->getAs
<ObjCObjectType
>()) {
3152 // A dependent pointer type 'T *' has is being transformed such
3153 // that an Objective-C class type is being replaced for 'T'. The
3154 // resulting pointer type is an ObjCObjectPointerType, not a
3156 Result
= SemaRef
.Context
.getObjCObjectPointerType(PointeeType
);
3158 ObjCObjectPointerTypeLoc NewT
= TLB
.push
<ObjCObjectPointerTypeLoc
>(Result
);
3159 NewT
.setStarLoc(TL
.getStarLoc());
3163 if (getDerived().AlwaysRebuild() ||
3164 PointeeType
!= TL
.getPointeeLoc().getType()) {
3165 Result
= getDerived().RebuildPointerType(PointeeType
, TL
.getSigilLoc());
3166 if (Result
.isNull())
3170 PointerTypeLoc NewT
= TLB
.push
<PointerTypeLoc
>(Result
);
3171 NewT
.setSigilLoc(TL
.getSigilLoc());
3175 template<typename Derived
>
3177 TreeTransform
<Derived
>::TransformBlockPointerType(TypeLocBuilder
&TLB
,
3178 BlockPointerTypeLoc TL
) {
3179 QualType PointeeType
3180 = getDerived().TransformType(TLB
, TL
.getPointeeLoc());
3181 if (PointeeType
.isNull())
3184 QualType Result
= TL
.getType();
3185 if (getDerived().AlwaysRebuild() ||
3186 PointeeType
!= TL
.getPointeeLoc().getType()) {
3187 Result
= getDerived().RebuildBlockPointerType(PointeeType
,
3189 if (Result
.isNull())
3193 BlockPointerTypeLoc NewT
= TLB
.push
<BlockPointerTypeLoc
>(Result
);
3194 NewT
.setSigilLoc(TL
.getSigilLoc());
3198 /// Transforms a reference type. Note that somewhat paradoxically we
3199 /// don't care whether the type itself is an l-value type or an r-value
3200 /// type; we only care if the type was *written* as an l-value type
3201 /// or an r-value type.
3202 template<typename Derived
>
3204 TreeTransform
<Derived
>::TransformReferenceType(TypeLocBuilder
&TLB
,
3205 ReferenceTypeLoc TL
) {
3206 const ReferenceType
*T
= TL
.getTypePtr();
3208 // Note that this works with the pointee-as-written.
3209 QualType PointeeType
= getDerived().TransformType(TLB
, TL
.getPointeeLoc());
3210 if (PointeeType
.isNull())
3213 QualType Result
= TL
.getType();
3214 if (getDerived().AlwaysRebuild() ||
3215 PointeeType
!= T
->getPointeeTypeAsWritten()) {
3216 Result
= getDerived().RebuildReferenceType(PointeeType
,
3217 T
->isSpelledAsLValue(),
3219 if (Result
.isNull())
3223 // r-value references can be rebuilt as l-value references.
3224 ReferenceTypeLoc NewTL
;
3225 if (isa
<LValueReferenceType
>(Result
))
3226 NewTL
= TLB
.push
<LValueReferenceTypeLoc
>(Result
);
3228 NewTL
= TLB
.push
<RValueReferenceTypeLoc
>(Result
);
3229 NewTL
.setSigilLoc(TL
.getSigilLoc());
3234 template<typename Derived
>
3236 TreeTransform
<Derived
>::TransformLValueReferenceType(TypeLocBuilder
&TLB
,
3237 LValueReferenceTypeLoc TL
) {
3238 return TransformReferenceType(TLB
, TL
);
3241 template<typename Derived
>
3243 TreeTransform
<Derived
>::TransformRValueReferenceType(TypeLocBuilder
&TLB
,
3244 RValueReferenceTypeLoc TL
) {
3245 return TransformReferenceType(TLB
, TL
);
3248 template<typename Derived
>
3250 TreeTransform
<Derived
>::TransformMemberPointerType(TypeLocBuilder
&TLB
,
3251 MemberPointerTypeLoc TL
) {
3252 const MemberPointerType
*T
= TL
.getTypePtr();
3254 QualType PointeeType
= getDerived().TransformType(TLB
, TL
.getPointeeLoc());
3255 if (PointeeType
.isNull())
3258 // TODO: preserve source information for this.
3260 = getDerived().TransformType(QualType(T
->getClass(), 0));
3261 if (ClassType
.isNull())
3264 QualType Result
= TL
.getType();
3265 if (getDerived().AlwaysRebuild() ||
3266 PointeeType
!= T
->getPointeeType() ||
3267 ClassType
!= QualType(T
->getClass(), 0)) {
3268 Result
= getDerived().RebuildMemberPointerType(PointeeType
, ClassType
,
3270 if (Result
.isNull())
3274 MemberPointerTypeLoc NewTL
= TLB
.push
<MemberPointerTypeLoc
>(Result
);
3275 NewTL
.setSigilLoc(TL
.getSigilLoc());
3280 template<typename Derived
>
3282 TreeTransform
<Derived
>::TransformConstantArrayType(TypeLocBuilder
&TLB
,
3283 ConstantArrayTypeLoc TL
) {
3284 const ConstantArrayType
*T
= TL
.getTypePtr();
3285 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
3286 if (ElementType
.isNull())
3289 QualType Result
= TL
.getType();
3290 if (getDerived().AlwaysRebuild() ||
3291 ElementType
!= T
->getElementType()) {
3292 Result
= getDerived().RebuildConstantArrayType(ElementType
,
3293 T
->getSizeModifier(),
3295 T
->getIndexTypeCVRQualifiers(),
3296 TL
.getBracketsRange());
3297 if (Result
.isNull())
3301 ConstantArrayTypeLoc NewTL
= TLB
.push
<ConstantArrayTypeLoc
>(Result
);
3302 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
3303 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
3305 Expr
*Size
= TL
.getSizeExpr();
3307 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3308 Size
= getDerived().TransformExpr(Size
).template takeAs
<Expr
>();
3310 NewTL
.setSizeExpr(Size
);
3315 template<typename Derived
>
3316 QualType TreeTransform
<Derived
>::TransformIncompleteArrayType(
3317 TypeLocBuilder
&TLB
,
3318 IncompleteArrayTypeLoc TL
) {
3319 const IncompleteArrayType
*T
= TL
.getTypePtr();
3320 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
3321 if (ElementType
.isNull())
3324 QualType Result
= TL
.getType();
3325 if (getDerived().AlwaysRebuild() ||
3326 ElementType
!= T
->getElementType()) {
3327 Result
= getDerived().RebuildIncompleteArrayType(ElementType
,
3328 T
->getSizeModifier(),
3329 T
->getIndexTypeCVRQualifiers(),
3330 TL
.getBracketsRange());
3331 if (Result
.isNull())
3335 IncompleteArrayTypeLoc NewTL
= TLB
.push
<IncompleteArrayTypeLoc
>(Result
);
3336 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
3337 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
3338 NewTL
.setSizeExpr(0);
3343 template<typename Derived
>
3345 TreeTransform
<Derived
>::TransformVariableArrayType(TypeLocBuilder
&TLB
,
3346 VariableArrayTypeLoc TL
) {
3347 const VariableArrayType
*T
= TL
.getTypePtr();
3348 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
3349 if (ElementType
.isNull())
3352 // Array bounds are not potentially evaluated contexts
3353 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3355 ExprResult SizeResult
3356 = getDerived().TransformExpr(T
->getSizeExpr());
3357 if (SizeResult
.isInvalid())
3360 Expr
*Size
= SizeResult
.take();
3362 QualType Result
= TL
.getType();
3363 if (getDerived().AlwaysRebuild() ||
3364 ElementType
!= T
->getElementType() ||
3365 Size
!= T
->getSizeExpr()) {
3366 Result
= getDerived().RebuildVariableArrayType(ElementType
,
3367 T
->getSizeModifier(),
3369 T
->getIndexTypeCVRQualifiers(),
3370 TL
.getBracketsRange());
3371 if (Result
.isNull())
3375 VariableArrayTypeLoc NewTL
= TLB
.push
<VariableArrayTypeLoc
>(Result
);
3376 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
3377 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
3378 NewTL
.setSizeExpr(Size
);
3383 template<typename Derived
>
3385 TreeTransform
<Derived
>::TransformDependentSizedArrayType(TypeLocBuilder
&TLB
,
3386 DependentSizedArrayTypeLoc TL
) {
3387 const DependentSizedArrayType
*T
= TL
.getTypePtr();
3388 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
3389 if (ElementType
.isNull())
3392 // Array bounds are not potentially evaluated contexts
3393 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3395 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3396 Expr
*origSize
= TL
.getSizeExpr();
3397 if (!origSize
) origSize
= T
->getSizeExpr();
3399 ExprResult sizeResult
3400 = getDerived().TransformExpr(origSize
);
3401 if (sizeResult
.isInvalid())
3404 Expr
*size
= sizeResult
.get();
3406 QualType Result
= TL
.getType();
3407 if (getDerived().AlwaysRebuild() ||
3408 ElementType
!= T
->getElementType() ||
3410 Result
= getDerived().RebuildDependentSizedArrayType(ElementType
,
3411 T
->getSizeModifier(),
3413 T
->getIndexTypeCVRQualifiers(),
3414 TL
.getBracketsRange());
3415 if (Result
.isNull())
3419 // We might have any sort of array type now, but fortunately they
3420 // all have the same location layout.
3421 ArrayTypeLoc NewTL
= TLB
.push
<ArrayTypeLoc
>(Result
);
3422 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
3423 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
3424 NewTL
.setSizeExpr(size
);
3429 template<typename Derived
>
3430 QualType TreeTransform
<Derived
>::TransformDependentSizedExtVectorType(
3431 TypeLocBuilder
&TLB
,
3432 DependentSizedExtVectorTypeLoc TL
) {
3433 const DependentSizedExtVectorType
*T
= TL
.getTypePtr();
3435 // FIXME: ext vector locs should be nested
3436 QualType ElementType
= getDerived().TransformType(T
->getElementType());
3437 if (ElementType
.isNull())
3440 // Vector sizes are not potentially evaluated contexts
3441 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3443 ExprResult Size
= getDerived().TransformExpr(T
->getSizeExpr());
3444 if (Size
.isInvalid())
3447 QualType Result
= TL
.getType();
3448 if (getDerived().AlwaysRebuild() ||
3449 ElementType
!= T
->getElementType() ||
3450 Size
.get() != T
->getSizeExpr()) {
3451 Result
= getDerived().RebuildDependentSizedExtVectorType(ElementType
,
3453 T
->getAttributeLoc());
3454 if (Result
.isNull())
3458 // Result might be dependent or not.
3459 if (isa
<DependentSizedExtVectorType
>(Result
)) {
3460 DependentSizedExtVectorTypeLoc NewTL
3461 = TLB
.push
<DependentSizedExtVectorTypeLoc
>(Result
);
3462 NewTL
.setNameLoc(TL
.getNameLoc());
3464 ExtVectorTypeLoc NewTL
= TLB
.push
<ExtVectorTypeLoc
>(Result
);
3465 NewTL
.setNameLoc(TL
.getNameLoc());
3471 template<typename Derived
>
3472 QualType TreeTransform
<Derived
>::TransformVectorType(TypeLocBuilder
&TLB
,
3474 const VectorType
*T
= TL
.getTypePtr();
3475 QualType ElementType
= getDerived().TransformType(T
->getElementType());
3476 if (ElementType
.isNull())
3479 QualType Result
= TL
.getType();
3480 if (getDerived().AlwaysRebuild() ||
3481 ElementType
!= T
->getElementType()) {
3482 Result
= getDerived().RebuildVectorType(ElementType
, T
->getNumElements(),
3483 T
->getVectorKind());
3484 if (Result
.isNull())
3488 VectorTypeLoc NewTL
= TLB
.push
<VectorTypeLoc
>(Result
);
3489 NewTL
.setNameLoc(TL
.getNameLoc());
3494 template<typename Derived
>
3495 QualType TreeTransform
<Derived
>::TransformExtVectorType(TypeLocBuilder
&TLB
,
3496 ExtVectorTypeLoc TL
) {
3497 const VectorType
*T
= TL
.getTypePtr();
3498 QualType ElementType
= getDerived().TransformType(T
->getElementType());
3499 if (ElementType
.isNull())
3502 QualType Result
= TL
.getType();
3503 if (getDerived().AlwaysRebuild() ||
3504 ElementType
!= T
->getElementType()) {
3505 Result
= getDerived().RebuildExtVectorType(ElementType
,
3506 T
->getNumElements(),
3507 /*FIXME*/ SourceLocation());
3508 if (Result
.isNull())
3512 ExtVectorTypeLoc NewTL
= TLB
.push
<ExtVectorTypeLoc
>(Result
);
3513 NewTL
.setNameLoc(TL
.getNameLoc());
3518 template<typename Derived
>
3520 TreeTransform
<Derived
>::TransformFunctionTypeParam(ParmVarDecl
*OldParm
,
3521 llvm::Optional
<unsigned> NumExpansions
) {
3522 TypeSourceInfo
*OldDI
= OldParm
->getTypeSourceInfo();
3523 TypeSourceInfo
*NewDI
= 0;
3525 if (NumExpansions
&& isa
<PackExpansionType
>(OldDI
->getType())) {
3526 // If we're substituting into a pack expansion type and we know the
3527 TypeLoc OldTL
= OldDI
->getTypeLoc();
3528 PackExpansionTypeLoc OldExpansionTL
= cast
<PackExpansionTypeLoc
>(OldTL
);
3531 TypeLoc NewTL
= OldDI
->getTypeLoc();
3532 TLB
.reserve(NewTL
.getFullDataSize());
3534 QualType Result
= getDerived().TransformType(TLB
,
3535 OldExpansionTL
.getPatternLoc());
3536 if (Result
.isNull())
3539 Result
= RebuildPackExpansionType(Result
,
3540 OldExpansionTL
.getPatternLoc().getSourceRange(),
3541 OldExpansionTL
.getEllipsisLoc(),
3543 if (Result
.isNull())
3546 PackExpansionTypeLoc NewExpansionTL
3547 = TLB
.push
<PackExpansionTypeLoc
>(Result
);
3548 NewExpansionTL
.setEllipsisLoc(OldExpansionTL
.getEllipsisLoc());
3549 NewDI
= TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
3551 NewDI
= getDerived().TransformType(OldDI
);
3558 return ParmVarDecl::Create(SemaRef
.Context
,
3559 OldParm
->getDeclContext(),
3560 OldParm
->getLocation(),
3561 OldParm
->getIdentifier(),
3564 OldParm
->getStorageClass(),
3565 OldParm
->getStorageClassAsWritten(),
3569 template<typename Derived
>
3570 bool TreeTransform
<Derived
>::
3571 TransformFunctionTypeParams(SourceLocation Loc
,
3572 ParmVarDecl
**Params
, unsigned NumParams
,
3573 const QualType
*ParamTypes
,
3574 llvm::SmallVectorImpl
<QualType
> &OutParamTypes
,
3575 llvm::SmallVectorImpl
<ParmVarDecl
*> *PVars
) {
3576 for (unsigned i
= 0; i
!= NumParams
; ++i
) {
3577 if (ParmVarDecl
*OldParm
= Params
[i
]) {
3578 llvm::Optional
<unsigned> NumExpansions
;
3579 if (OldParm
->isParameterPack()) {
3580 // We have a function parameter pack that may need to be expanded.
3581 llvm::SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
3583 // Find the parameter packs that could be expanded.
3584 TypeLoc TL
= OldParm
->getTypeSourceInfo()->getTypeLoc();
3585 PackExpansionTypeLoc ExpansionTL
= cast
<PackExpansionTypeLoc
>(TL
);
3586 TypeLoc Pattern
= ExpansionTL
.getPatternLoc();
3587 SemaRef
.collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
3589 // Determine whether we should expand the parameter packs.
3590 bool ShouldExpand
= false;
3591 bool RetainExpansion
= false;
3592 llvm::Optional
<unsigned> OrigNumExpansions
3593 = ExpansionTL
.getTypePtr()->getNumExpansions();
3594 NumExpansions
= OrigNumExpansions
;
3595 if (getDerived().TryExpandParameterPacks(ExpansionTL
.getEllipsisLoc(),
3596 Pattern
.getSourceRange(),
3606 // Expand the function parameter pack into multiple, separate
3608 getDerived().ExpandingFunctionParameterPack(OldParm
);
3609 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
3610 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
3611 ParmVarDecl
*NewParm
3612 = getDerived().TransformFunctionTypeParam(OldParm
,
3617 OutParamTypes
.push_back(NewParm
->getType());
3619 PVars
->push_back(NewParm
);
3622 // If we're supposed to retain a pack expansion, do so by temporarily
3623 // forgetting the partially-substituted parameter pack.
3624 if (RetainExpansion
) {
3625 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
3626 ParmVarDecl
*NewParm
3627 = getDerived().TransformFunctionTypeParam(OldParm
,
3632 OutParamTypes
.push_back(NewParm
->getType());
3634 PVars
->push_back(NewParm
);
3637 // We're done with the pack expansion.
3641 // We'll substitute the parameter now without expanding the pack
3645 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
3646 ParmVarDecl
*NewParm
= getDerived().TransformFunctionTypeParam(OldParm
,
3651 OutParamTypes
.push_back(NewParm
->getType());
3653 PVars
->push_back(NewParm
);
3657 // Deal with the possibility that we don't have a parameter
3658 // declaration for this parameter.
3659 QualType OldType
= ParamTypes
[i
];
3660 bool IsPackExpansion
= false;
3661 llvm::Optional
<unsigned> NumExpansions
;
3662 if (const PackExpansionType
*Expansion
3663 = dyn_cast
<PackExpansionType
>(OldType
)) {
3664 // We have a function parameter pack that may need to be expanded.
3665 QualType Pattern
= Expansion
->getPattern();
3666 llvm::SmallVector
<UnexpandedParameterPack
, 2> Unexpanded
;
3667 getSema().collectUnexpandedParameterPacks(Pattern
, Unexpanded
);
3669 // Determine whether we should expand the parameter packs.
3670 bool ShouldExpand
= false;
3671 bool RetainExpansion
= false;
3672 if (getDerived().TryExpandParameterPacks(Loc
, SourceRange(),
3682 // Expand the function parameter pack into multiple, separate
3684 for (unsigned I
= 0; I
!= *NumExpansions
; ++I
) {
3685 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), I
);
3686 QualType NewType
= getDerived().TransformType(Pattern
);
3687 if (NewType
.isNull())
3690 OutParamTypes
.push_back(NewType
);
3692 PVars
->push_back(0);
3695 // We're done with the pack expansion.
3699 // If we're supposed to retain a pack expansion, do so by temporarily
3700 // forgetting the partially-substituted parameter pack.
3701 if (RetainExpansion
) {
3702 ForgetPartiallySubstitutedPackRAII
Forget(getDerived());
3703 QualType NewType
= getDerived().TransformType(Pattern
);
3704 if (NewType
.isNull())
3707 OutParamTypes
.push_back(NewType
);
3709 PVars
->push_back(0);
3712 // We'll substitute the parameter now without expanding the pack
3714 OldType
= Expansion
->getPattern();
3715 IsPackExpansion
= true;
3718 Sema::ArgumentPackSubstitutionIndexRAII
SubstIndex(getSema(), -1);
3719 QualType NewType
= getDerived().TransformType(OldType
);
3720 if (NewType
.isNull())
3723 if (IsPackExpansion
)
3724 NewType
= getSema().Context
.getPackExpansionType(NewType
,
3727 OutParamTypes
.push_back(NewType
);
3729 PVars
->push_back(0);
3735 template<typename Derived
>
3737 TreeTransform
<Derived
>::TransformFunctionProtoType(TypeLocBuilder
&TLB
,
3738 FunctionProtoTypeLoc TL
) {
3739 // Transform the parameters and return type.
3741 // We instantiate in source order, with the return type first followed by
3742 // the parameters, because users tend to expect this (even if they shouldn't
3745 // When the function has a trailing return type, we instantiate the
3746 // parameters before the return type, since the return type can then refer
3747 // to the parameters themselves (via decltype, sizeof, etc.).
3749 llvm::SmallVector
<QualType
, 4> ParamTypes
;
3750 llvm::SmallVector
<ParmVarDecl
*, 4> ParamDecls
;
3751 const FunctionProtoType
*T
= TL
.getTypePtr();
3753 QualType ResultType
;
3755 if (TL
.getTrailingReturn()) {
3756 if (getDerived().TransformFunctionTypeParams(TL
.getBeginLoc(),
3759 TL
.getTypePtr()->arg_type_begin(),
3760 ParamTypes
, &ParamDecls
))
3763 ResultType
= getDerived().TransformType(TLB
, TL
.getResultLoc());
3764 if (ResultType
.isNull())
3768 ResultType
= getDerived().TransformType(TLB
, TL
.getResultLoc());
3769 if (ResultType
.isNull())
3772 if (getDerived().TransformFunctionTypeParams(TL
.getBeginLoc(),
3775 TL
.getTypePtr()->arg_type_begin(),
3776 ParamTypes
, &ParamDecls
))
3780 QualType Result
= TL
.getType();
3781 if (getDerived().AlwaysRebuild() ||
3782 ResultType
!= T
->getResultType() ||
3783 T
->getNumArgs() != ParamTypes
.size() ||
3784 !std::equal(T
->arg_type_begin(), T
->arg_type_end(), ParamTypes
.begin())) {
3785 Result
= getDerived().RebuildFunctionProtoType(ResultType
,
3790 T
->getRefQualifier(),
3792 if (Result
.isNull())
3796 FunctionProtoTypeLoc NewTL
= TLB
.push
<FunctionProtoTypeLoc
>(Result
);
3797 NewTL
.setLParenLoc(TL
.getLParenLoc());
3798 NewTL
.setRParenLoc(TL
.getRParenLoc());
3799 NewTL
.setTrailingReturn(TL
.getTrailingReturn());
3800 for (unsigned i
= 0, e
= NewTL
.getNumArgs(); i
!= e
; ++i
)
3801 NewTL
.setArg(i
, ParamDecls
[i
]);
3806 template<typename Derived
>
3807 QualType TreeTransform
<Derived
>::TransformFunctionNoProtoType(
3808 TypeLocBuilder
&TLB
,
3809 FunctionNoProtoTypeLoc TL
) {
3810 const FunctionNoProtoType
*T
= TL
.getTypePtr();
3811 QualType ResultType
= getDerived().TransformType(TLB
, TL
.getResultLoc());
3812 if (ResultType
.isNull())
3815 QualType Result
= TL
.getType();
3816 if (getDerived().AlwaysRebuild() ||
3817 ResultType
!= T
->getResultType())
3818 Result
= getDerived().RebuildFunctionNoProtoType(ResultType
);
3820 FunctionNoProtoTypeLoc NewTL
= TLB
.push
<FunctionNoProtoTypeLoc
>(Result
);
3821 NewTL
.setLParenLoc(TL
.getLParenLoc());
3822 NewTL
.setRParenLoc(TL
.getRParenLoc());
3823 NewTL
.setTrailingReturn(false);
3828 template<typename Derived
> QualType
3829 TreeTransform
<Derived
>::TransformUnresolvedUsingType(TypeLocBuilder
&TLB
,
3830 UnresolvedUsingTypeLoc TL
) {
3831 const UnresolvedUsingType
*T
= TL
.getTypePtr();
3832 Decl
*D
= getDerived().TransformDecl(TL
.getNameLoc(), T
->getDecl());
3836 QualType Result
= TL
.getType();
3837 if (getDerived().AlwaysRebuild() || D
!= T
->getDecl()) {
3838 Result
= getDerived().RebuildUnresolvedUsingType(D
);
3839 if (Result
.isNull())
3843 // We might get an arbitrary type spec type back. We should at
3844 // least always get a type spec type, though.
3845 TypeSpecTypeLoc NewTL
= TLB
.pushTypeSpec(Result
);
3846 NewTL
.setNameLoc(TL
.getNameLoc());
3851 template<typename Derived
>
3852 QualType TreeTransform
<Derived
>::TransformTypedefType(TypeLocBuilder
&TLB
,
3853 TypedefTypeLoc TL
) {
3854 const TypedefType
*T
= TL
.getTypePtr();
3855 TypedefDecl
*Typedef
3856 = cast_or_null
<TypedefDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
3861 QualType Result
= TL
.getType();
3862 if (getDerived().AlwaysRebuild() ||
3863 Typedef
!= T
->getDecl()) {
3864 Result
= getDerived().RebuildTypedefType(Typedef
);
3865 if (Result
.isNull())
3869 TypedefTypeLoc NewTL
= TLB
.push
<TypedefTypeLoc
>(Result
);
3870 NewTL
.setNameLoc(TL
.getNameLoc());
3875 template<typename Derived
>
3876 QualType TreeTransform
<Derived
>::TransformTypeOfExprType(TypeLocBuilder
&TLB
,
3877 TypeOfExprTypeLoc TL
) {
3878 // typeof expressions are not potentially evaluated contexts
3879 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3881 ExprResult E
= getDerived().TransformExpr(TL
.getUnderlyingExpr());
3885 QualType Result
= TL
.getType();
3886 if (getDerived().AlwaysRebuild() ||
3887 E
.get() != TL
.getUnderlyingExpr()) {
3888 Result
= getDerived().RebuildTypeOfExprType(E
.get(), TL
.getTypeofLoc());
3889 if (Result
.isNull())
3894 TypeOfExprTypeLoc NewTL
= TLB
.push
<TypeOfExprTypeLoc
>(Result
);
3895 NewTL
.setTypeofLoc(TL
.getTypeofLoc());
3896 NewTL
.setLParenLoc(TL
.getLParenLoc());
3897 NewTL
.setRParenLoc(TL
.getRParenLoc());
3902 template<typename Derived
>
3903 QualType TreeTransform
<Derived
>::TransformTypeOfType(TypeLocBuilder
&TLB
,
3905 TypeSourceInfo
* Old_Under_TI
= TL
.getUnderlyingTInfo();
3906 TypeSourceInfo
* New_Under_TI
= getDerived().TransformType(Old_Under_TI
);
3910 QualType Result
= TL
.getType();
3911 if (getDerived().AlwaysRebuild() || New_Under_TI
!= Old_Under_TI
) {
3912 Result
= getDerived().RebuildTypeOfType(New_Under_TI
->getType());
3913 if (Result
.isNull())
3917 TypeOfTypeLoc NewTL
= TLB
.push
<TypeOfTypeLoc
>(Result
);
3918 NewTL
.setTypeofLoc(TL
.getTypeofLoc());
3919 NewTL
.setLParenLoc(TL
.getLParenLoc());
3920 NewTL
.setRParenLoc(TL
.getRParenLoc());
3921 NewTL
.setUnderlyingTInfo(New_Under_TI
);
3926 template<typename Derived
>
3927 QualType TreeTransform
<Derived
>::TransformDecltypeType(TypeLocBuilder
&TLB
,
3928 DecltypeTypeLoc TL
) {
3929 const DecltypeType
*T
= TL
.getTypePtr();
3931 // decltype expressions are not potentially evaluated contexts
3932 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3934 ExprResult E
= getDerived().TransformExpr(T
->getUnderlyingExpr());
3938 QualType Result
= TL
.getType();
3939 if (getDerived().AlwaysRebuild() ||
3940 E
.get() != T
->getUnderlyingExpr()) {
3941 Result
= getDerived().RebuildDecltypeType(E
.get(), TL
.getNameLoc());
3942 if (Result
.isNull())
3947 DecltypeTypeLoc NewTL
= TLB
.push
<DecltypeTypeLoc
>(Result
);
3948 NewTL
.setNameLoc(TL
.getNameLoc());
3953 template<typename Derived
>
3954 QualType TreeTransform
<Derived
>::TransformRecordType(TypeLocBuilder
&TLB
,
3956 const RecordType
*T
= TL
.getTypePtr();
3958 = cast_or_null
<RecordDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
3963 QualType Result
= TL
.getType();
3964 if (getDerived().AlwaysRebuild() ||
3965 Record
!= T
->getDecl()) {
3966 Result
= getDerived().RebuildRecordType(Record
);
3967 if (Result
.isNull())
3971 RecordTypeLoc NewTL
= TLB
.push
<RecordTypeLoc
>(Result
);
3972 NewTL
.setNameLoc(TL
.getNameLoc());
3977 template<typename Derived
>
3978 QualType TreeTransform
<Derived
>::TransformEnumType(TypeLocBuilder
&TLB
,
3980 const EnumType
*T
= TL
.getTypePtr();
3982 = cast_or_null
<EnumDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
3987 QualType Result
= TL
.getType();
3988 if (getDerived().AlwaysRebuild() ||
3989 Enum
!= T
->getDecl()) {
3990 Result
= getDerived().RebuildEnumType(Enum
);
3991 if (Result
.isNull())
3995 EnumTypeLoc NewTL
= TLB
.push
<EnumTypeLoc
>(Result
);
3996 NewTL
.setNameLoc(TL
.getNameLoc());
4001 template<typename Derived
>
4002 QualType TreeTransform
<Derived
>::TransformInjectedClassNameType(
4003 TypeLocBuilder
&TLB
,
4004 InjectedClassNameTypeLoc TL
) {
4005 Decl
*D
= getDerived().TransformDecl(TL
.getNameLoc(),
4006 TL
.getTypePtr()->getDecl());
4007 if (!D
) return QualType();
4009 QualType T
= SemaRef
.Context
.getTypeDeclType(cast
<TypeDecl
>(D
));
4010 TLB
.pushTypeSpec(T
).setNameLoc(TL
.getNameLoc());
4014 template<typename Derived
>
4015 QualType TreeTransform
<Derived
>::TransformTemplateTypeParmType(
4016 TypeLocBuilder
&TLB
,
4017 TemplateTypeParmTypeLoc TL
) {
4018 return TransformTypeSpecType(TLB
, TL
);
4021 template<typename Derived
>
4022 QualType TreeTransform
<Derived
>::TransformSubstTemplateTypeParmType(
4023 TypeLocBuilder
&TLB
,
4024 SubstTemplateTypeParmTypeLoc TL
) {
4025 return TransformTypeSpecType(TLB
, TL
);
4028 template<typename Derived
>
4029 QualType TreeTransform
<Derived
>::TransformSubstTemplateTypeParmPackType(
4030 TypeLocBuilder
&TLB
,
4031 SubstTemplateTypeParmPackTypeLoc TL
) {
4032 return TransformTypeSpecType(TLB
, TL
);
4035 template<typename Derived
>
4036 QualType TreeTransform
<Derived
>::TransformTemplateSpecializationType(
4037 TypeLocBuilder
&TLB
,
4038 TemplateSpecializationTypeLoc TL
) {
4039 const TemplateSpecializationType
*T
= TL
.getTypePtr();
4041 TemplateName Template
4042 = getDerived().TransformTemplateName(T
->getTemplateName());
4043 if (Template
.isNull())
4046 return getDerived().TransformTemplateSpecializationType(TLB
, TL
, Template
);
4050 /// \brief Simple iterator that traverses the template arguments in a
4051 /// container that provides a \c getArgLoc() member function.
4053 /// This iterator is intended to be used with the iterator form of
4054 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4055 template<typename ArgLocContainer
>
4056 class TemplateArgumentLocContainerIterator
{
4057 ArgLocContainer
*Container
;
4061 typedef TemplateArgumentLoc value_type
;
4062 typedef TemplateArgumentLoc reference
;
4063 typedef int difference_type
;
4064 typedef std::input_iterator_tag iterator_category
;
4067 TemplateArgumentLoc Arg
;
4070 explicit pointer(TemplateArgumentLoc Arg
) : Arg(Arg
) { }
4072 const TemplateArgumentLoc
*operator->() const {
4078 TemplateArgumentLocContainerIterator() {}
4080 TemplateArgumentLocContainerIterator(ArgLocContainer
&Container
,
4082 : Container(&Container
), Index(Index
) { }
4084 TemplateArgumentLocContainerIterator
&operator++() {
4089 TemplateArgumentLocContainerIterator
operator++(int) {
4090 TemplateArgumentLocContainerIterator
Old(*this);
4095 TemplateArgumentLoc
operator*() const {
4096 return Container
->getArgLoc(Index
);
4099 pointer
operator->() const {
4100 return pointer(Container
->getArgLoc(Index
));
4103 friend bool operator==(const TemplateArgumentLocContainerIterator
&X
,
4104 const TemplateArgumentLocContainerIterator
&Y
) {
4105 return X
.Container
== Y
.Container
&& X
.Index
== Y
.Index
;
4108 friend bool operator!=(const TemplateArgumentLocContainerIterator
&X
,
4109 const TemplateArgumentLocContainerIterator
&Y
) {
4116 template <typename Derived
>
4117 QualType TreeTransform
<Derived
>::TransformTemplateSpecializationType(
4118 TypeLocBuilder
&TLB
,
4119 TemplateSpecializationTypeLoc TL
,
4120 TemplateName Template
) {
4121 TemplateArgumentListInfo NewTemplateArgs
;
4122 NewTemplateArgs
.setLAngleLoc(TL
.getLAngleLoc());
4123 NewTemplateArgs
.setRAngleLoc(TL
.getRAngleLoc());
4124 typedef TemplateArgumentLocContainerIterator
<TemplateSpecializationTypeLoc
>
4126 if (getDerived().TransformTemplateArguments(ArgIterator(TL
, 0),
4127 ArgIterator(TL
, TL
.getNumArgs()),
4131 // FIXME: maybe don't rebuild if all the template arguments are the same.
4134 getDerived().RebuildTemplateSpecializationType(Template
,
4135 TL
.getTemplateNameLoc(),
4138 if (!Result
.isNull()) {
4139 TemplateSpecializationTypeLoc NewTL
4140 = TLB
.push
<TemplateSpecializationTypeLoc
>(Result
);
4141 NewTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
4142 NewTL
.setLAngleLoc(TL
.getLAngleLoc());
4143 NewTL
.setRAngleLoc(TL
.getRAngleLoc());
4144 for (unsigned i
= 0, e
= NewTemplateArgs
.size(); i
!= e
; ++i
)
4145 NewTL
.setArgLocInfo(i
, NewTemplateArgs
[i
].getLocInfo());
4151 template<typename Derived
>
4153 TreeTransform
<Derived
>::TransformElaboratedType(TypeLocBuilder
&TLB
,
4154 ElaboratedTypeLoc TL
) {
4155 const ElaboratedType
*T
= TL
.getTypePtr();
4157 NestedNameSpecifier
*NNS
= 0;
4158 // NOTE: the qualifier in an ElaboratedType is optional.
4159 if (T
->getQualifier() != 0) {
4160 NNS
= getDerived().TransformNestedNameSpecifier(T
->getQualifier(),
4161 TL
.getQualifierRange());
4166 QualType NamedT
= getDerived().TransformType(TLB
, TL
.getNamedTypeLoc());
4167 if (NamedT
.isNull())
4170 QualType Result
= TL
.getType();
4171 if (getDerived().AlwaysRebuild() ||
4172 NNS
!= T
->getQualifier() ||
4173 NamedT
!= T
->getNamedType()) {
4174 Result
= getDerived().RebuildElaboratedType(TL
.getKeywordLoc(),
4175 T
->getKeyword(), NNS
, NamedT
);
4176 if (Result
.isNull())
4180 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
4181 NewTL
.setKeywordLoc(TL
.getKeywordLoc());
4182 NewTL
.setQualifierRange(TL
.getQualifierRange());
4187 template<typename Derived
>
4188 QualType TreeTransform
<Derived
>::TransformAttributedType(
4189 TypeLocBuilder
&TLB
,
4190 AttributedTypeLoc TL
) {
4191 const AttributedType
*oldType
= TL
.getTypePtr();
4192 QualType modifiedType
= getDerived().TransformType(TLB
, TL
.getModifiedLoc());
4193 if (modifiedType
.isNull())
4196 QualType result
= TL
.getType();
4198 // FIXME: dependent operand expressions?
4199 if (getDerived().AlwaysRebuild() ||
4200 modifiedType
!= oldType
->getModifiedType()) {
4201 // TODO: this is really lame; we should really be rebuilding the
4202 // equivalent type from first principles.
4203 QualType equivalentType
4204 = getDerived().TransformType(oldType
->getEquivalentType());
4205 if (equivalentType
.isNull())
4207 result
= SemaRef
.Context
.getAttributedType(oldType
->getAttrKind(),
4212 AttributedTypeLoc newTL
= TLB
.push
<AttributedTypeLoc
>(result
);
4213 newTL
.setAttrNameLoc(TL
.getAttrNameLoc());
4214 if (TL
.hasAttrOperand())
4215 newTL
.setAttrOperandParensRange(TL
.getAttrOperandParensRange());
4216 if (TL
.hasAttrExprOperand())
4217 newTL
.setAttrExprOperand(TL
.getAttrExprOperand());
4218 else if (TL
.hasAttrEnumOperand())
4219 newTL
.setAttrEnumOperandLoc(TL
.getAttrEnumOperandLoc());
4224 template<typename Derived
>
4226 TreeTransform
<Derived
>::TransformParenType(TypeLocBuilder
&TLB
,
4228 QualType Inner
= getDerived().TransformType(TLB
, TL
.getInnerLoc());
4232 QualType Result
= TL
.getType();
4233 if (getDerived().AlwaysRebuild() ||
4234 Inner
!= TL
.getInnerLoc().getType()) {
4235 Result
= getDerived().RebuildParenType(Inner
);
4236 if (Result
.isNull())
4240 ParenTypeLoc NewTL
= TLB
.push
<ParenTypeLoc
>(Result
);
4241 NewTL
.setLParenLoc(TL
.getLParenLoc());
4242 NewTL
.setRParenLoc(TL
.getRParenLoc());
4246 template<typename Derived
>
4247 QualType TreeTransform
<Derived
>::TransformDependentNameType(TypeLocBuilder
&TLB
,
4248 DependentNameTypeLoc TL
) {
4249 const DependentNameType
*T
= TL
.getTypePtr();
4251 NestedNameSpecifier
*NNS
4252 = getDerived().TransformNestedNameSpecifier(T
->getQualifier(),
4253 TL
.getQualifierRange());
4258 = getDerived().RebuildDependentNameType(T
->getKeyword(), NNS
,
4261 TL
.getQualifierRange(),
4263 if (Result
.isNull())
4266 if (const ElaboratedType
* ElabT
= Result
->getAs
<ElaboratedType
>()) {
4267 QualType NamedT
= ElabT
->getNamedType();
4268 TLB
.pushTypeSpec(NamedT
).setNameLoc(TL
.getNameLoc());
4270 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
4271 NewTL
.setKeywordLoc(TL
.getKeywordLoc());
4272 NewTL
.setQualifierRange(TL
.getQualifierRange());
4274 DependentNameTypeLoc NewTL
= TLB
.push
<DependentNameTypeLoc
>(Result
);
4275 NewTL
.setKeywordLoc(TL
.getKeywordLoc());
4276 NewTL
.setQualifierRange(TL
.getQualifierRange());
4277 NewTL
.setNameLoc(TL
.getNameLoc());
4282 template<typename Derived
>
4283 QualType TreeTransform
<Derived
>::
4284 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
4285 DependentTemplateSpecializationTypeLoc TL
) {
4286 const DependentTemplateSpecializationType
*T
= TL
.getTypePtr();
4288 NestedNameSpecifier
*NNS
4289 = getDerived().TransformNestedNameSpecifier(T
->getQualifier(),
4290 TL
.getQualifierRange());
4295 .TransformDependentTemplateSpecializationType(TLB
, TL
, NNS
);
4298 template<typename Derived
>
4299 QualType TreeTransform
<Derived
>::
4300 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
4301 DependentTemplateSpecializationTypeLoc TL
,
4302 NestedNameSpecifier
*NNS
) {
4303 const DependentTemplateSpecializationType
*T
= TL
.getTypePtr();
4305 TemplateArgumentListInfo NewTemplateArgs
;
4306 NewTemplateArgs
.setLAngleLoc(TL
.getLAngleLoc());
4307 NewTemplateArgs
.setRAngleLoc(TL
.getRAngleLoc());
4309 typedef TemplateArgumentLocContainerIterator
<
4310 DependentTemplateSpecializationTypeLoc
> ArgIterator
;
4311 if (getDerived().TransformTemplateArguments(ArgIterator(TL
, 0),
4312 ArgIterator(TL
, TL
.getNumArgs()),
4317 = getDerived().RebuildDependentTemplateSpecializationType(T
->getKeyword(),
4319 TL
.getQualifierRange(),
4323 if (Result
.isNull())
4326 if (const ElaboratedType
*ElabT
= dyn_cast
<ElaboratedType
>(Result
)) {
4327 QualType NamedT
= ElabT
->getNamedType();
4329 // Copy information relevant to the template specialization.
4330 TemplateSpecializationTypeLoc NamedTL
4331 = TLB
.push
<TemplateSpecializationTypeLoc
>(NamedT
);
4332 NamedTL
.setLAngleLoc(TL
.getLAngleLoc());
4333 NamedTL
.setRAngleLoc(TL
.getRAngleLoc());
4334 for (unsigned I
= 0, E
= TL
.getNumArgs(); I
!= E
; ++I
)
4335 NamedTL
.setArgLocInfo(I
, TL
.getArgLocInfo(I
));
4337 // Copy information relevant to the elaborated type.
4338 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
4339 NewTL
.setKeywordLoc(TL
.getKeywordLoc());
4340 NewTL
.setQualifierRange(TL
.getQualifierRange());
4342 TypeLoc
NewTL(Result
, TL
.getOpaqueData());
4343 TLB
.pushFullCopy(NewTL
);
4348 template<typename Derived
>
4349 QualType TreeTransform
<Derived
>::TransformPackExpansionType(TypeLocBuilder
&TLB
,
4350 PackExpansionTypeLoc TL
) {
4352 = getDerived().TransformType(TLB
, TL
.getPatternLoc());
4353 if (Pattern
.isNull())
4356 QualType Result
= TL
.getType();
4357 if (getDerived().AlwaysRebuild() ||
4358 Pattern
!= TL
.getPatternLoc().getType()) {
4359 Result
= getDerived().RebuildPackExpansionType(Pattern
,
4360 TL
.getPatternLoc().getSourceRange(),
4361 TL
.getEllipsisLoc(),
4362 TL
.getTypePtr()->getNumExpansions());
4363 if (Result
.isNull())
4367 PackExpansionTypeLoc NewT
= TLB
.push
<PackExpansionTypeLoc
>(Result
);
4368 NewT
.setEllipsisLoc(TL
.getEllipsisLoc());
4372 template<typename Derived
>
4374 TreeTransform
<Derived
>::TransformObjCInterfaceType(TypeLocBuilder
&TLB
,
4375 ObjCInterfaceTypeLoc TL
) {
4376 // ObjCInterfaceType is never dependent.
4377 TLB
.pushFullCopy(TL
);
4378 return TL
.getType();
4381 template<typename Derived
>
4383 TreeTransform
<Derived
>::TransformObjCObjectType(TypeLocBuilder
&TLB
,
4384 ObjCObjectTypeLoc TL
) {
4385 // ObjCObjectType is never dependent.
4386 TLB
.pushFullCopy(TL
);
4387 return TL
.getType();
4390 template<typename Derived
>
4392 TreeTransform
<Derived
>::TransformObjCObjectPointerType(TypeLocBuilder
&TLB
,
4393 ObjCObjectPointerTypeLoc TL
) {
4394 // ObjCObjectPointerType is never dependent.
4395 TLB
.pushFullCopy(TL
);
4396 return TL
.getType();
4399 //===----------------------------------------------------------------------===//
4400 // Statement transformation
4401 //===----------------------------------------------------------------------===//
4402 template<typename Derived
>
4404 TreeTransform
<Derived
>::TransformNullStmt(NullStmt
*S
) {
4405 return SemaRef
.Owned(S
);
4408 template<typename Derived
>
4410 TreeTransform
<Derived
>::TransformCompoundStmt(CompoundStmt
*S
) {
4411 return getDerived().TransformCompoundStmt(S
, false);
4414 template<typename Derived
>
4416 TreeTransform
<Derived
>::TransformCompoundStmt(CompoundStmt
*S
,
4418 bool SubStmtInvalid
= false;
4419 bool SubStmtChanged
= false;
4420 ASTOwningVector
<Stmt
*> Statements(getSema());
4421 for (CompoundStmt::body_iterator B
= S
->body_begin(), BEnd
= S
->body_end();
4423 StmtResult Result
= getDerived().TransformStmt(*B
);
4424 if (Result
.isInvalid()) {
4425 // Immediately fail if this was a DeclStmt, since it's very
4426 // likely that this will cause problems for future statements.
4427 if (isa
<DeclStmt
>(*B
))
4430 // Otherwise, just keep processing substatements and fail later.
4431 SubStmtInvalid
= true;
4435 SubStmtChanged
= SubStmtChanged
|| Result
.get() != *B
;
4436 Statements
.push_back(Result
.takeAs
<Stmt
>());
4442 if (!getDerived().AlwaysRebuild() &&
4444 return SemaRef
.Owned(S
);
4446 return getDerived().RebuildCompoundStmt(S
->getLBracLoc(),
4447 move_arg(Statements
),
4452 template<typename Derived
>
4454 TreeTransform
<Derived
>::TransformCaseStmt(CaseStmt
*S
) {
4455 ExprResult LHS
, RHS
;
4457 // The case value expressions are not potentially evaluated.
4458 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
4460 // Transform the left-hand case value.
4461 LHS
= getDerived().TransformExpr(S
->getLHS());
4462 if (LHS
.isInvalid())
4465 // Transform the right-hand case value (for the GNU case-range extension).
4466 RHS
= getDerived().TransformExpr(S
->getRHS());
4467 if (RHS
.isInvalid())
4471 // Build the case statement.
4472 // Case statements are always rebuilt so that they will attached to their
4473 // transformed switch statement.
4474 StmtResult Case
= getDerived().RebuildCaseStmt(S
->getCaseLoc(),
4476 S
->getEllipsisLoc(),
4479 if (Case
.isInvalid())
4482 // Transform the statement following the case
4483 StmtResult SubStmt
= getDerived().TransformStmt(S
->getSubStmt());
4484 if (SubStmt
.isInvalid())
4487 // Attach the body to the case statement
4488 return getDerived().RebuildCaseStmtBody(Case
.get(), SubStmt
.get());
4491 template<typename Derived
>
4493 TreeTransform
<Derived
>::TransformDefaultStmt(DefaultStmt
*S
) {
4494 // Transform the statement following the default case
4495 StmtResult SubStmt
= getDerived().TransformStmt(S
->getSubStmt());
4496 if (SubStmt
.isInvalid())
4499 // Default statements are always rebuilt
4500 return getDerived().RebuildDefaultStmt(S
->getDefaultLoc(), S
->getColonLoc(),
4504 template<typename Derived
>
4506 TreeTransform
<Derived
>::TransformLabelStmt(LabelStmt
*S
) {
4507 StmtResult SubStmt
= getDerived().TransformStmt(S
->getSubStmt());
4508 if (SubStmt
.isInvalid())
4511 Decl
*LD
= getDerived().TransformDecl(S
->getDecl()->getLocation(),
4517 // FIXME: Pass the real colon location in.
4518 return getDerived().RebuildLabelStmt(S
->getIdentLoc(),
4519 cast
<LabelDecl
>(LD
), SourceLocation(),
4523 template<typename Derived
>
4525 TreeTransform
<Derived
>::TransformIfStmt(IfStmt
*S
) {
4526 // Transform the condition
4528 VarDecl
*ConditionVar
= 0;
4529 if (S
->getConditionVariable()) {
4531 = cast_or_null
<VarDecl
>(
4532 getDerived().TransformDefinition(
4533 S
->getConditionVariable()->getLocation(),
4534 S
->getConditionVariable()));
4538 Cond
= getDerived().TransformExpr(S
->getCond());
4540 if (Cond
.isInvalid())
4543 // Convert the condition to a boolean value.
4545 ExprResult CondE
= getSema().ActOnBooleanCondition(0, S
->getIfLoc(),
4547 if (CondE
.isInvalid())
4554 Sema::FullExprArg
FullCond(getSema().MakeFullExpr(Cond
.take()));
4555 if (!S
->getConditionVariable() && S
->getCond() && !FullCond
.get())
4558 // Transform the "then" branch.
4559 StmtResult Then
= getDerived().TransformStmt(S
->getThen());
4560 if (Then
.isInvalid())
4563 // Transform the "else" branch.
4564 StmtResult Else
= getDerived().TransformStmt(S
->getElse());
4565 if (Else
.isInvalid())
4568 if (!getDerived().AlwaysRebuild() &&
4569 FullCond
.get() == S
->getCond() &&
4570 ConditionVar
== S
->getConditionVariable() &&
4571 Then
.get() == S
->getThen() &&
4572 Else
.get() == S
->getElse())
4573 return SemaRef
.Owned(S
);
4575 return getDerived().RebuildIfStmt(S
->getIfLoc(), FullCond
, ConditionVar
,
4577 S
->getElseLoc(), Else
.get());
4580 template<typename Derived
>
4582 TreeTransform
<Derived
>::TransformSwitchStmt(SwitchStmt
*S
) {
4583 // Transform the condition.
4585 VarDecl
*ConditionVar
= 0;
4586 if (S
->getConditionVariable()) {
4588 = cast_or_null
<VarDecl
>(
4589 getDerived().TransformDefinition(
4590 S
->getConditionVariable()->getLocation(),
4591 S
->getConditionVariable()));
4595 Cond
= getDerived().TransformExpr(S
->getCond());
4597 if (Cond
.isInvalid())
4601 // Rebuild the switch statement.
4603 = getDerived().RebuildSwitchStmtStart(S
->getSwitchLoc(), Cond
.get(),
4605 if (Switch
.isInvalid())
4608 // Transform the body of the switch statement.
4609 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
4610 if (Body
.isInvalid())
4613 // Complete the switch statement.
4614 return getDerived().RebuildSwitchStmtBody(S
->getSwitchLoc(), Switch
.get(),
4618 template<typename Derived
>
4620 TreeTransform
<Derived
>::TransformWhileStmt(WhileStmt
*S
) {
4621 // Transform the condition
4623 VarDecl
*ConditionVar
= 0;
4624 if (S
->getConditionVariable()) {
4626 = cast_or_null
<VarDecl
>(
4627 getDerived().TransformDefinition(
4628 S
->getConditionVariable()->getLocation(),
4629 S
->getConditionVariable()));
4633 Cond
= getDerived().TransformExpr(S
->getCond());
4635 if (Cond
.isInvalid())
4639 // Convert the condition to a boolean value.
4640 ExprResult CondE
= getSema().ActOnBooleanCondition(0, S
->getWhileLoc(),
4642 if (CondE
.isInvalid())
4648 Sema::FullExprArg
FullCond(getSema().MakeFullExpr(Cond
.take()));
4649 if (!S
->getConditionVariable() && S
->getCond() && !FullCond
.get())
4652 // Transform the body
4653 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
4654 if (Body
.isInvalid())
4657 if (!getDerived().AlwaysRebuild() &&
4658 FullCond
.get() == S
->getCond() &&
4659 ConditionVar
== S
->getConditionVariable() &&
4660 Body
.get() == S
->getBody())
4663 return getDerived().RebuildWhileStmt(S
->getWhileLoc(), FullCond
,
4664 ConditionVar
, Body
.get());
4667 template<typename Derived
>
4669 TreeTransform
<Derived
>::TransformDoStmt(DoStmt
*S
) {
4670 // Transform the body
4671 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
4672 if (Body
.isInvalid())
4675 // Transform the condition
4676 ExprResult Cond
= getDerived().TransformExpr(S
->getCond());
4677 if (Cond
.isInvalid())
4680 if (!getDerived().AlwaysRebuild() &&
4681 Cond
.get() == S
->getCond() &&
4682 Body
.get() == S
->getBody())
4683 return SemaRef
.Owned(S
);
4685 return getDerived().RebuildDoStmt(S
->getDoLoc(), Body
.get(), S
->getWhileLoc(),
4686 /*FIXME:*/S
->getWhileLoc(), Cond
.get(),
4690 template<typename Derived
>
4692 TreeTransform
<Derived
>::TransformForStmt(ForStmt
*S
) {
4693 // Transform the initialization statement
4694 StmtResult Init
= getDerived().TransformStmt(S
->getInit());
4695 if (Init
.isInvalid())
4698 // Transform the condition
4700 VarDecl
*ConditionVar
= 0;
4701 if (S
->getConditionVariable()) {
4703 = cast_or_null
<VarDecl
>(
4704 getDerived().TransformDefinition(
4705 S
->getConditionVariable()->getLocation(),
4706 S
->getConditionVariable()));
4710 Cond
= getDerived().TransformExpr(S
->getCond());
4712 if (Cond
.isInvalid())
4716 // Convert the condition to a boolean value.
4717 ExprResult CondE
= getSema().ActOnBooleanCondition(0, S
->getForLoc(),
4719 if (CondE
.isInvalid())
4726 Sema::FullExprArg
FullCond(getSema().MakeFullExpr(Cond
.take()));
4727 if (!S
->getConditionVariable() && S
->getCond() && !FullCond
.get())
4730 // Transform the increment
4731 ExprResult Inc
= getDerived().TransformExpr(S
->getInc());
4732 if (Inc
.isInvalid())
4735 Sema::FullExprArg
FullInc(getSema().MakeFullExpr(Inc
.get()));
4736 if (S
->getInc() && !FullInc
.get())
4739 // Transform the body
4740 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
4741 if (Body
.isInvalid())
4744 if (!getDerived().AlwaysRebuild() &&
4745 Init
.get() == S
->getInit() &&
4746 FullCond
.get() == S
->getCond() &&
4747 Inc
.get() == S
->getInc() &&
4748 Body
.get() == S
->getBody())
4749 return SemaRef
.Owned(S
);
4751 return getDerived().RebuildForStmt(S
->getForLoc(), S
->getLParenLoc(),
4752 Init
.get(), FullCond
, ConditionVar
,
4753 FullInc
, S
->getRParenLoc(), Body
.get());
4756 template<typename Derived
>
4758 TreeTransform
<Derived
>::TransformGotoStmt(GotoStmt
*S
) {
4759 Decl
*LD
= getDerived().TransformDecl(S
->getLabel()->getLocation(),
4764 // Goto statements must always be rebuilt, to resolve the label.
4765 return getDerived().RebuildGotoStmt(S
->getGotoLoc(), S
->getLabelLoc(),
4766 cast
<LabelDecl
>(LD
));
4769 template<typename Derived
>
4771 TreeTransform
<Derived
>::TransformIndirectGotoStmt(IndirectGotoStmt
*S
) {
4772 ExprResult Target
= getDerived().TransformExpr(S
->getTarget());
4773 if (Target
.isInvalid())
4776 if (!getDerived().AlwaysRebuild() &&
4777 Target
.get() == S
->getTarget())
4778 return SemaRef
.Owned(S
);
4780 return getDerived().RebuildIndirectGotoStmt(S
->getGotoLoc(), S
->getStarLoc(),
4784 template<typename Derived
>
4786 TreeTransform
<Derived
>::TransformContinueStmt(ContinueStmt
*S
) {
4787 return SemaRef
.Owned(S
);
4790 template<typename Derived
>
4792 TreeTransform
<Derived
>::TransformBreakStmt(BreakStmt
*S
) {
4793 return SemaRef
.Owned(S
);
4796 template<typename Derived
>
4798 TreeTransform
<Derived
>::TransformReturnStmt(ReturnStmt
*S
) {
4799 ExprResult Result
= getDerived().TransformExpr(S
->getRetValue());
4800 if (Result
.isInvalid())
4803 // FIXME: We always rebuild the return statement because there is no way
4804 // to tell whether the return type of the function has changed.
4805 return getDerived().RebuildReturnStmt(S
->getReturnLoc(), Result
.get());
4808 template<typename Derived
>
4810 TreeTransform
<Derived
>::TransformDeclStmt(DeclStmt
*S
) {
4811 bool DeclChanged
= false;
4812 llvm::SmallVector
<Decl
*, 4> Decls
;
4813 for (DeclStmt::decl_iterator D
= S
->decl_begin(), DEnd
= S
->decl_end();
4815 Decl
*Transformed
= getDerived().TransformDefinition((*D
)->getLocation(),
4820 if (Transformed
!= *D
)
4823 Decls
.push_back(Transformed
);
4826 if (!getDerived().AlwaysRebuild() && !DeclChanged
)
4827 return SemaRef
.Owned(S
);
4829 return getDerived().RebuildDeclStmt(Decls
.data(), Decls
.size(),
4830 S
->getStartLoc(), S
->getEndLoc());
4833 template<typename Derived
>
4835 TreeTransform
<Derived
>::TransformAsmStmt(AsmStmt
*S
) {
4837 ASTOwningVector
<Expr
*> Constraints(getSema());
4838 ASTOwningVector
<Expr
*> Exprs(getSema());
4839 llvm::SmallVector
<IdentifierInfo
*, 4> Names
;
4841 ExprResult AsmString
;
4842 ASTOwningVector
<Expr
*> Clobbers(getSema());
4844 bool ExprsChanged
= false;
4846 // Go through the outputs.
4847 for (unsigned I
= 0, E
= S
->getNumOutputs(); I
!= E
; ++I
) {
4848 Names
.push_back(S
->getOutputIdentifier(I
));
4850 // No need to transform the constraint literal.
4851 Constraints
.push_back(S
->getOutputConstraintLiteral(I
));
4853 // Transform the output expr.
4854 Expr
*OutputExpr
= S
->getOutputExpr(I
);
4855 ExprResult Result
= getDerived().TransformExpr(OutputExpr
);
4856 if (Result
.isInvalid())
4859 ExprsChanged
|= Result
.get() != OutputExpr
;
4861 Exprs
.push_back(Result
.get());
4864 // Go through the inputs.
4865 for (unsigned I
= 0, E
= S
->getNumInputs(); I
!= E
; ++I
) {
4866 Names
.push_back(S
->getInputIdentifier(I
));
4868 // No need to transform the constraint literal.
4869 Constraints
.push_back(S
->getInputConstraintLiteral(I
));
4871 // Transform the input expr.
4872 Expr
*InputExpr
= S
->getInputExpr(I
);
4873 ExprResult Result
= getDerived().TransformExpr(InputExpr
);
4874 if (Result
.isInvalid())
4877 ExprsChanged
|= Result
.get() != InputExpr
;
4879 Exprs
.push_back(Result
.get());
4882 if (!getDerived().AlwaysRebuild() && !ExprsChanged
)
4883 return SemaRef
.Owned(S
);
4885 // Go through the clobbers.
4886 for (unsigned I
= 0, E
= S
->getNumClobbers(); I
!= E
; ++I
)
4887 Clobbers
.push_back(S
->getClobber(I
));
4889 // No need to transform the asm string literal.
4890 AsmString
= SemaRef
.Owned(S
->getAsmString());
4892 return getDerived().RebuildAsmStmt(S
->getAsmLoc(),
4898 move_arg(Constraints
),
4907 template<typename Derived
>
4909 TreeTransform
<Derived
>::TransformObjCAtTryStmt(ObjCAtTryStmt
*S
) {
4910 // Transform the body of the @try.
4911 StmtResult TryBody
= getDerived().TransformStmt(S
->getTryBody());
4912 if (TryBody
.isInvalid())
4915 // Transform the @catch statements (if present).
4916 bool AnyCatchChanged
= false;
4917 ASTOwningVector
<Stmt
*> CatchStmts(SemaRef
);
4918 for (unsigned I
= 0, N
= S
->getNumCatchStmts(); I
!= N
; ++I
) {
4919 StmtResult Catch
= getDerived().TransformStmt(S
->getCatchStmt(I
));
4920 if (Catch
.isInvalid())
4922 if (Catch
.get() != S
->getCatchStmt(I
))
4923 AnyCatchChanged
= true;
4924 CatchStmts
.push_back(Catch
.release());
4927 // Transform the @finally statement (if present).
4929 if (S
->getFinallyStmt()) {
4930 Finally
= getDerived().TransformStmt(S
->getFinallyStmt());
4931 if (Finally
.isInvalid())
4935 // If nothing changed, just retain this statement.
4936 if (!getDerived().AlwaysRebuild() &&
4937 TryBody
.get() == S
->getTryBody() &&
4939 Finally
.get() == S
->getFinallyStmt())
4940 return SemaRef
.Owned(S
);
4942 // Build a new statement.
4943 return getDerived().RebuildObjCAtTryStmt(S
->getAtTryLoc(), TryBody
.get(),
4944 move_arg(CatchStmts
), Finally
.get());
4947 template<typename Derived
>
4949 TreeTransform
<Derived
>::TransformObjCAtCatchStmt(ObjCAtCatchStmt
*S
) {
4950 // Transform the @catch parameter, if there is one.
4952 if (VarDecl
*FromVar
= S
->getCatchParamDecl()) {
4953 TypeSourceInfo
*TSInfo
= 0;
4954 if (FromVar
->getTypeSourceInfo()) {
4955 TSInfo
= getDerived().TransformType(FromVar
->getTypeSourceInfo());
4962 T
= TSInfo
->getType();
4964 T
= getDerived().TransformType(FromVar
->getType());
4969 Var
= getDerived().RebuildObjCExceptionDecl(FromVar
, TSInfo
, T
);
4974 StmtResult Body
= getDerived().TransformStmt(S
->getCatchBody());
4975 if (Body
.isInvalid())
4978 return getDerived().RebuildObjCAtCatchStmt(S
->getAtCatchLoc(),
4983 template<typename Derived
>
4985 TreeTransform
<Derived
>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt
*S
) {
4986 // Transform the body.
4987 StmtResult Body
= getDerived().TransformStmt(S
->getFinallyBody());
4988 if (Body
.isInvalid())
4991 // If nothing changed, just retain this statement.
4992 if (!getDerived().AlwaysRebuild() &&
4993 Body
.get() == S
->getFinallyBody())
4994 return SemaRef
.Owned(S
);
4996 // Build a new statement.
4997 return getDerived().RebuildObjCAtFinallyStmt(S
->getAtFinallyLoc(),
5001 template<typename Derived
>
5003 TreeTransform
<Derived
>::TransformObjCAtThrowStmt(ObjCAtThrowStmt
*S
) {
5005 if (S
->getThrowExpr()) {
5006 Operand
= getDerived().TransformExpr(S
->getThrowExpr());
5007 if (Operand
.isInvalid())
5011 if (!getDerived().AlwaysRebuild() &&
5012 Operand
.get() == S
->getThrowExpr())
5013 return getSema().Owned(S
);
5015 return getDerived().RebuildObjCAtThrowStmt(S
->getThrowLoc(), Operand
.get());
5018 template<typename Derived
>
5020 TreeTransform
<Derived
>::TransformObjCAtSynchronizedStmt(
5021 ObjCAtSynchronizedStmt
*S
) {
5022 // Transform the object we are locking.
5023 ExprResult Object
= getDerived().TransformExpr(S
->getSynchExpr());
5024 if (Object
.isInvalid())
5027 // Transform the body.
5028 StmtResult Body
= getDerived().TransformStmt(S
->getSynchBody());
5029 if (Body
.isInvalid())
5032 // If nothing change, just retain the current statement.
5033 if (!getDerived().AlwaysRebuild() &&
5034 Object
.get() == S
->getSynchExpr() &&
5035 Body
.get() == S
->getSynchBody())
5036 return SemaRef
.Owned(S
);
5038 // Build a new statement.
5039 return getDerived().RebuildObjCAtSynchronizedStmt(S
->getAtSynchronizedLoc(),
5040 Object
.get(), Body
.get());
5043 template<typename Derived
>
5045 TreeTransform
<Derived
>::TransformObjCForCollectionStmt(
5046 ObjCForCollectionStmt
*S
) {
5047 // Transform the element statement.
5048 StmtResult Element
= getDerived().TransformStmt(S
->getElement());
5049 if (Element
.isInvalid())
5052 // Transform the collection expression.
5053 ExprResult Collection
= getDerived().TransformExpr(S
->getCollection());
5054 if (Collection
.isInvalid())
5057 // Transform the body.
5058 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
5059 if (Body
.isInvalid())
5062 // If nothing changed, just retain this statement.
5063 if (!getDerived().AlwaysRebuild() &&
5064 Element
.get() == S
->getElement() &&
5065 Collection
.get() == S
->getCollection() &&
5066 Body
.get() == S
->getBody())
5067 return SemaRef
.Owned(S
);
5069 // Build a new statement.
5070 return getDerived().RebuildObjCForCollectionStmt(S
->getForLoc(),
5071 /*FIXME:*/S
->getForLoc(),
5079 template<typename Derived
>
5081 TreeTransform
<Derived
>::TransformCXXCatchStmt(CXXCatchStmt
*S
) {
5082 // Transform the exception declaration, if any.
5084 if (S
->getExceptionDecl()) {
5085 VarDecl
*ExceptionDecl
= S
->getExceptionDecl();
5086 TypeSourceInfo
*T
= getDerived().TransformType(
5087 ExceptionDecl
->getTypeSourceInfo());
5091 Var
= getDerived().RebuildExceptionDecl(ExceptionDecl
, T
,
5092 ExceptionDecl
->getIdentifier(),
5093 ExceptionDecl
->getLocation());
5094 if (!Var
|| Var
->isInvalidDecl())
5098 // Transform the actual exception handler.
5099 StmtResult Handler
= getDerived().TransformStmt(S
->getHandlerBlock());
5100 if (Handler
.isInvalid())
5103 if (!getDerived().AlwaysRebuild() &&
5105 Handler
.get() == S
->getHandlerBlock())
5106 return SemaRef
.Owned(S
);
5108 return getDerived().RebuildCXXCatchStmt(S
->getCatchLoc(),
5113 template<typename Derived
>
5115 TreeTransform
<Derived
>::TransformCXXTryStmt(CXXTryStmt
*S
) {
5116 // Transform the try block itself.
5118 = getDerived().TransformCompoundStmt(S
->getTryBlock());
5119 if (TryBlock
.isInvalid())
5122 // Transform the handlers.
5123 bool HandlerChanged
= false;
5124 ASTOwningVector
<Stmt
*> Handlers(SemaRef
);
5125 for (unsigned I
= 0, N
= S
->getNumHandlers(); I
!= N
; ++I
) {
5127 = getDerived().TransformCXXCatchStmt(S
->getHandler(I
));
5128 if (Handler
.isInvalid())
5131 HandlerChanged
= HandlerChanged
|| Handler
.get() != S
->getHandler(I
);
5132 Handlers
.push_back(Handler
.takeAs
<Stmt
>());
5135 if (!getDerived().AlwaysRebuild() &&
5136 TryBlock
.get() == S
->getTryBlock() &&
5138 return SemaRef
.Owned(S
);
5140 return getDerived().RebuildCXXTryStmt(S
->getTryLoc(), TryBlock
.get(),
5141 move_arg(Handlers
));
5144 //===----------------------------------------------------------------------===//
5145 // Expression transformation
5146 //===----------------------------------------------------------------------===//
5147 template<typename Derived
>
5149 TreeTransform
<Derived
>::TransformPredefinedExpr(PredefinedExpr
*E
) {
5150 return SemaRef
.Owned(E
);
5153 template<typename Derived
>
5155 TreeTransform
<Derived
>::TransformDeclRefExpr(DeclRefExpr
*E
) {
5156 NestedNameSpecifier
*Qualifier
= 0;
5157 if (E
->getQualifier()) {
5158 Qualifier
= getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
5159 E
->getQualifierRange());
5165 = cast_or_null
<ValueDecl
>(getDerived().TransformDecl(E
->getLocation(),
5170 DeclarationNameInfo NameInfo
= E
->getNameInfo();
5171 if (NameInfo
.getName()) {
5172 NameInfo
= getDerived().TransformDeclarationNameInfo(NameInfo
);
5173 if (!NameInfo
.getName())
5177 if (!getDerived().AlwaysRebuild() &&
5178 Qualifier
== E
->getQualifier() &&
5179 ND
== E
->getDecl() &&
5180 NameInfo
.getName() == E
->getDecl()->getDeclName() &&
5181 !E
->hasExplicitTemplateArgs()) {
5183 // Mark it referenced in the new context regardless.
5184 // FIXME: this is a bit instantiation-specific.
5185 SemaRef
.MarkDeclarationReferenced(E
->getLocation(), ND
);
5187 return SemaRef
.Owned(E
);
5190 TemplateArgumentListInfo TransArgs
, *TemplateArgs
= 0;
5191 if (E
->hasExplicitTemplateArgs()) {
5192 TemplateArgs
= &TransArgs
;
5193 TransArgs
.setLAngleLoc(E
->getLAngleLoc());
5194 TransArgs
.setRAngleLoc(E
->getRAngleLoc());
5195 if (getDerived().TransformTemplateArguments(E
->getTemplateArgs(),
5196 E
->getNumTemplateArgs(),
5201 return getDerived().RebuildDeclRefExpr(Qualifier
, E
->getQualifierRange(),
5202 ND
, NameInfo
, TemplateArgs
);
5205 template<typename Derived
>
5207 TreeTransform
<Derived
>::TransformIntegerLiteral(IntegerLiteral
*E
) {
5208 return SemaRef
.Owned(E
);
5211 template<typename Derived
>
5213 TreeTransform
<Derived
>::TransformFloatingLiteral(FloatingLiteral
*E
) {
5214 return SemaRef
.Owned(E
);
5217 template<typename Derived
>
5219 TreeTransform
<Derived
>::TransformImaginaryLiteral(ImaginaryLiteral
*E
) {
5220 return SemaRef
.Owned(E
);
5223 template<typename Derived
>
5225 TreeTransform
<Derived
>::TransformStringLiteral(StringLiteral
*E
) {
5226 return SemaRef
.Owned(E
);
5229 template<typename Derived
>
5231 TreeTransform
<Derived
>::TransformCharacterLiteral(CharacterLiteral
*E
) {
5232 return SemaRef
.Owned(E
);
5235 template<typename Derived
>
5237 TreeTransform
<Derived
>::TransformParenExpr(ParenExpr
*E
) {
5238 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
5239 if (SubExpr
.isInvalid())
5242 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getSubExpr())
5243 return SemaRef
.Owned(E
);
5245 return getDerived().RebuildParenExpr(SubExpr
.get(), E
->getLParen(),
5249 template<typename Derived
>
5251 TreeTransform
<Derived
>::TransformUnaryOperator(UnaryOperator
*E
) {
5252 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
5253 if (SubExpr
.isInvalid())
5256 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getSubExpr())
5257 return SemaRef
.Owned(E
);
5259 return getDerived().RebuildUnaryOperator(E
->getOperatorLoc(),
5264 template<typename Derived
>
5266 TreeTransform
<Derived
>::TransformOffsetOfExpr(OffsetOfExpr
*E
) {
5267 // Transform the type.
5268 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeSourceInfo());
5272 // Transform all of the components into components similar to what the
5274 // FIXME: It would be slightly more efficient in the non-dependent case to
5275 // just map FieldDecls, rather than requiring the rebuilder to look for
5276 // the fields again. However, __builtin_offsetof is rare enough in
5277 // template code that we don't care.
5278 bool ExprChanged
= false;
5279 typedef Sema::OffsetOfComponent Component
;
5280 typedef OffsetOfExpr::OffsetOfNode Node
;
5281 llvm::SmallVector
<Component
, 4> Components
;
5282 for (unsigned I
= 0, N
= E
->getNumComponents(); I
!= N
; ++I
) {
5283 const Node
&ON
= E
->getComponent(I
);
5285 Comp
.isBrackets
= true;
5286 Comp
.LocStart
= ON
.getRange().getBegin();
5287 Comp
.LocEnd
= ON
.getRange().getEnd();
5288 switch (ON
.getKind()) {
5290 Expr
*FromIndex
= E
->getIndexExpr(ON
.getArrayExprIndex());
5291 ExprResult Index
= getDerived().TransformExpr(FromIndex
);
5292 if (Index
.isInvalid())
5295 ExprChanged
= ExprChanged
|| Index
.get() != FromIndex
;
5296 Comp
.isBrackets
= true;
5297 Comp
.U
.E
= Index
.get();
5302 case Node::Identifier
:
5303 Comp
.isBrackets
= false;
5304 Comp
.U
.IdentInfo
= ON
.getFieldName();
5305 if (!Comp
.U
.IdentInfo
)
5311 // Will be recomputed during the rebuild.
5315 Components
.push_back(Comp
);
5318 // If nothing changed, retain the existing expression.
5319 if (!getDerived().AlwaysRebuild() &&
5320 Type
== E
->getTypeSourceInfo() &&
5322 return SemaRef
.Owned(E
);
5324 // Build a new offsetof expression.
5325 return getDerived().RebuildOffsetOfExpr(E
->getOperatorLoc(), Type
,
5326 Components
.data(), Components
.size(),
5330 template<typename Derived
>
5332 TreeTransform
<Derived
>::TransformOpaqueValueExpr(OpaqueValueExpr
*E
) {
5333 assert(getDerived().AlreadyTransformed(E
->getType()) &&
5334 "opaque value expression requires transformation");
5335 return SemaRef
.Owned(E
);
5338 template<typename Derived
>
5340 TreeTransform
<Derived
>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr
*E
) {
5341 if (E
->isArgumentType()) {
5342 TypeSourceInfo
*OldT
= E
->getArgumentTypeInfo();
5344 TypeSourceInfo
*NewT
= getDerived().TransformType(OldT
);
5348 if (!getDerived().AlwaysRebuild() && OldT
== NewT
)
5349 return SemaRef
.Owned(E
);
5351 return getDerived().RebuildSizeOfAlignOf(NewT
, E
->getOperatorLoc(),
5353 E
->getSourceRange());
5358 // C++0x [expr.sizeof]p1:
5359 // The operand is either an expression, which is an unevaluated operand
5361 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
5363 SubExpr
= getDerived().TransformExpr(E
->getArgumentExpr());
5364 if (SubExpr
.isInvalid())
5367 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getArgumentExpr())
5368 return SemaRef
.Owned(E
);
5371 return getDerived().RebuildSizeOfAlignOf(SubExpr
.get(), E
->getOperatorLoc(),
5373 E
->getSourceRange());
5376 template<typename Derived
>
5378 TreeTransform
<Derived
>::TransformArraySubscriptExpr(ArraySubscriptExpr
*E
) {
5379 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
5380 if (LHS
.isInvalid())
5383 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
5384 if (RHS
.isInvalid())
5388 if (!getDerived().AlwaysRebuild() &&
5389 LHS
.get() == E
->getLHS() &&
5390 RHS
.get() == E
->getRHS())
5391 return SemaRef
.Owned(E
);
5393 return getDerived().RebuildArraySubscriptExpr(LHS
.get(),
5394 /*FIXME:*/E
->getLHS()->getLocStart(),
5396 E
->getRBracketLoc());
5399 template<typename Derived
>
5401 TreeTransform
<Derived
>::TransformCallExpr(CallExpr
*E
) {
5402 // Transform the callee.
5403 ExprResult Callee
= getDerived().TransformExpr(E
->getCallee());
5404 if (Callee
.isInvalid())
5407 // Transform arguments.
5408 bool ArgChanged
= false;
5409 ASTOwningVector
<Expr
*> Args(SemaRef
);
5410 if (getDerived().TransformExprs(E
->getArgs(), E
->getNumArgs(), true, Args
,
5414 if (!getDerived().AlwaysRebuild() &&
5415 Callee
.get() == E
->getCallee() &&
5417 return SemaRef
.Owned(E
);
5419 // FIXME: Wrong source location information for the '('.
5420 SourceLocation FakeLParenLoc
5421 = ((Expr
*)Callee
.get())->getSourceRange().getBegin();
5422 return getDerived().RebuildCallExpr(Callee
.get(), FakeLParenLoc
,
5427 template<typename Derived
>
5429 TreeTransform
<Derived
>::TransformMemberExpr(MemberExpr
*E
) {
5430 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
5431 if (Base
.isInvalid())
5434 NestedNameSpecifier
*Qualifier
= 0;
5435 if (E
->hasQualifier()) {
5437 = getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
5438 E
->getQualifierRange());
5444 = cast_or_null
<ValueDecl
>(getDerived().TransformDecl(E
->getMemberLoc(),
5445 E
->getMemberDecl()));
5449 NamedDecl
*FoundDecl
= E
->getFoundDecl();
5450 if (FoundDecl
== E
->getMemberDecl()) {
5453 FoundDecl
= cast_or_null
<NamedDecl
>(
5454 getDerived().TransformDecl(E
->getMemberLoc(), FoundDecl
));
5459 if (!getDerived().AlwaysRebuild() &&
5460 Base
.get() == E
->getBase() &&
5461 Qualifier
== E
->getQualifier() &&
5462 Member
== E
->getMemberDecl() &&
5463 FoundDecl
== E
->getFoundDecl() &&
5464 !E
->hasExplicitTemplateArgs()) {
5466 // Mark it referenced in the new context regardless.
5467 // FIXME: this is a bit instantiation-specific.
5468 SemaRef
.MarkDeclarationReferenced(E
->getMemberLoc(), Member
);
5469 return SemaRef
.Owned(E
);
5472 TemplateArgumentListInfo TransArgs
;
5473 if (E
->hasExplicitTemplateArgs()) {
5474 TransArgs
.setLAngleLoc(E
->getLAngleLoc());
5475 TransArgs
.setRAngleLoc(E
->getRAngleLoc());
5476 if (getDerived().TransformTemplateArguments(E
->getTemplateArgs(),
5477 E
->getNumTemplateArgs(),
5482 // FIXME: Bogus source location for the operator
5483 SourceLocation FakeOperatorLoc
5484 = SemaRef
.PP
.getLocForEndOfToken(E
->getBase()->getSourceRange().getEnd());
5486 // FIXME: to do this check properly, we will need to preserve the
5487 // first-qualifier-in-scope here, just in case we had a dependent
5488 // base (and therefore couldn't do the check) and a
5489 // nested-name-qualifier (and therefore could do the lookup).
5490 NamedDecl
*FirstQualifierInScope
= 0;
5492 return getDerived().RebuildMemberExpr(Base
.get(), FakeOperatorLoc
,
5495 E
->getQualifierRange(),
5496 E
->getMemberNameInfo(),
5499 (E
->hasExplicitTemplateArgs()
5501 FirstQualifierInScope
);
5504 template<typename Derived
>
5506 TreeTransform
<Derived
>::TransformBinaryOperator(BinaryOperator
*E
) {
5507 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
5508 if (LHS
.isInvalid())
5511 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
5512 if (RHS
.isInvalid())
5515 if (!getDerived().AlwaysRebuild() &&
5516 LHS
.get() == E
->getLHS() &&
5517 RHS
.get() == E
->getRHS())
5518 return SemaRef
.Owned(E
);
5520 return getDerived().RebuildBinaryOperator(E
->getOperatorLoc(), E
->getOpcode(),
5521 LHS
.get(), RHS
.get());
5524 template<typename Derived
>
5526 TreeTransform
<Derived
>::TransformCompoundAssignOperator(
5527 CompoundAssignOperator
*E
) {
5528 return getDerived().TransformBinaryOperator(E
);
5531 template<typename Derived
>
5532 ExprResult TreeTransform
<Derived
>::
5533 TransformBinaryConditionalOperator(BinaryConditionalOperator
*e
) {
5534 // Just rebuild the common and RHS expressions and see whether we
5537 ExprResult commonExpr
= getDerived().TransformExpr(e
->getCommon());
5538 if (commonExpr
.isInvalid())
5541 ExprResult rhs
= getDerived().TransformExpr(e
->getFalseExpr());
5542 if (rhs
.isInvalid())
5545 if (!getDerived().AlwaysRebuild() &&
5546 commonExpr
.get() == e
->getCommon() &&
5547 rhs
.get() == e
->getFalseExpr())
5548 return SemaRef
.Owned(e
);
5550 return getDerived().RebuildConditionalOperator(commonExpr
.take(),
5551 e
->getQuestionLoc(),
5557 template<typename Derived
>
5559 TreeTransform
<Derived
>::TransformConditionalOperator(ConditionalOperator
*E
) {
5560 ExprResult Cond
= getDerived().TransformExpr(E
->getCond());
5561 if (Cond
.isInvalid())
5564 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
5565 if (LHS
.isInvalid())
5568 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
5569 if (RHS
.isInvalid())
5572 if (!getDerived().AlwaysRebuild() &&
5573 Cond
.get() == E
->getCond() &&
5574 LHS
.get() == E
->getLHS() &&
5575 RHS
.get() == E
->getRHS())
5576 return SemaRef
.Owned(E
);
5578 return getDerived().RebuildConditionalOperator(Cond
.get(),
5579 E
->getQuestionLoc(),
5585 template<typename Derived
>
5587 TreeTransform
<Derived
>::TransformImplicitCastExpr(ImplicitCastExpr
*E
) {
5588 // Implicit casts are eliminated during transformation, since they
5589 // will be recomputed by semantic analysis after transformation.
5590 return getDerived().TransformExpr(E
->getSubExprAsWritten());
5593 template<typename Derived
>
5595 TreeTransform
<Derived
>::TransformCStyleCastExpr(CStyleCastExpr
*E
) {
5596 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeInfoAsWritten());
5601 = getDerived().TransformExpr(E
->getSubExprAsWritten());
5602 if (SubExpr
.isInvalid())
5605 if (!getDerived().AlwaysRebuild() &&
5606 Type
== E
->getTypeInfoAsWritten() &&
5607 SubExpr
.get() == E
->getSubExpr())
5608 return SemaRef
.Owned(E
);
5610 return getDerived().RebuildCStyleCastExpr(E
->getLParenLoc(),
5616 template<typename Derived
>
5618 TreeTransform
<Derived
>::TransformCompoundLiteralExpr(CompoundLiteralExpr
*E
) {
5619 TypeSourceInfo
*OldT
= E
->getTypeSourceInfo();
5620 TypeSourceInfo
*NewT
= getDerived().TransformType(OldT
);
5624 ExprResult Init
= getDerived().TransformExpr(E
->getInitializer());
5625 if (Init
.isInvalid())
5628 if (!getDerived().AlwaysRebuild() &&
5630 Init
.get() == E
->getInitializer())
5631 return SemaRef
.Owned(E
);
5633 // Note: the expression type doesn't necessarily match the
5634 // type-as-written, but that's okay, because it should always be
5635 // derivable from the initializer.
5637 return getDerived().RebuildCompoundLiteralExpr(E
->getLParenLoc(), NewT
,
5638 /*FIXME:*/E
->getInitializer()->getLocEnd(),
5642 template<typename Derived
>
5644 TreeTransform
<Derived
>::TransformExtVectorElementExpr(ExtVectorElementExpr
*E
) {
5645 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
5646 if (Base
.isInvalid())
5649 if (!getDerived().AlwaysRebuild() &&
5650 Base
.get() == E
->getBase())
5651 return SemaRef
.Owned(E
);
5653 // FIXME: Bad source location
5654 SourceLocation FakeOperatorLoc
5655 = SemaRef
.PP
.getLocForEndOfToken(E
->getBase()->getLocEnd());
5656 return getDerived().RebuildExtVectorElementExpr(Base
.get(), FakeOperatorLoc
,
5657 E
->getAccessorLoc(),
5661 template<typename Derived
>
5663 TreeTransform
<Derived
>::TransformInitListExpr(InitListExpr
*E
) {
5664 bool InitChanged
= false;
5666 ASTOwningVector
<Expr
*, 4> Inits(SemaRef
);
5667 if (getDerived().TransformExprs(E
->getInits(), E
->getNumInits(), false,
5668 Inits
, &InitChanged
))
5671 if (!getDerived().AlwaysRebuild() && !InitChanged
)
5672 return SemaRef
.Owned(E
);
5674 return getDerived().RebuildInitList(E
->getLBraceLoc(), move_arg(Inits
),
5675 E
->getRBraceLoc(), E
->getType());
5678 template<typename Derived
>
5680 TreeTransform
<Derived
>::TransformDesignatedInitExpr(DesignatedInitExpr
*E
) {
5683 // transform the initializer value
5684 ExprResult Init
= getDerived().TransformExpr(E
->getInit());
5685 if (Init
.isInvalid())
5688 // transform the designators.
5689 ASTOwningVector
<Expr
*, 4> ArrayExprs(SemaRef
);
5690 bool ExprChanged
= false;
5691 for (DesignatedInitExpr::designators_iterator D
= E
->designators_begin(),
5692 DEnd
= E
->designators_end();
5694 if (D
->isFieldDesignator()) {
5695 Desig
.AddDesignator(Designator::getField(D
->getFieldName(),
5701 if (D
->isArrayDesignator()) {
5702 ExprResult Index
= getDerived().TransformExpr(E
->getArrayIndex(*D
));
5703 if (Index
.isInvalid())
5706 Desig
.AddDesignator(Designator::getArray(Index
.get(),
5707 D
->getLBracketLoc()));
5709 ExprChanged
= ExprChanged
|| Init
.get() != E
->getArrayIndex(*D
);
5710 ArrayExprs
.push_back(Index
.release());
5714 assert(D
->isArrayRangeDesignator() && "New kind of designator?");
5716 = getDerived().TransformExpr(E
->getArrayRangeStart(*D
));
5717 if (Start
.isInvalid())
5720 ExprResult End
= getDerived().TransformExpr(E
->getArrayRangeEnd(*D
));
5721 if (End
.isInvalid())
5724 Desig
.AddDesignator(Designator::getArrayRange(Start
.get(),
5726 D
->getLBracketLoc(),
5727 D
->getEllipsisLoc()));
5729 ExprChanged
= ExprChanged
|| Start
.get() != E
->getArrayRangeStart(*D
) ||
5730 End
.get() != E
->getArrayRangeEnd(*D
);
5732 ArrayExprs
.push_back(Start
.release());
5733 ArrayExprs
.push_back(End
.release());
5736 if (!getDerived().AlwaysRebuild() &&
5737 Init
.get() == E
->getInit() &&
5739 return SemaRef
.Owned(E
);
5741 return getDerived().RebuildDesignatedInitExpr(Desig
, move_arg(ArrayExprs
),
5742 E
->getEqualOrColonLoc(),
5743 E
->usesGNUSyntax(), Init
.get());
5746 template<typename Derived
>
5748 TreeTransform
<Derived
>::TransformImplicitValueInitExpr(
5749 ImplicitValueInitExpr
*E
) {
5750 TemporaryBase
Rebase(*this, E
->getLocStart(), DeclarationName());
5752 // FIXME: Will we ever have proper type location here? Will we actually
5753 // need to transform the type?
5754 QualType T
= getDerived().TransformType(E
->getType());
5758 if (!getDerived().AlwaysRebuild() &&
5760 return SemaRef
.Owned(E
);
5762 return getDerived().RebuildImplicitValueInitExpr(T
);
5765 template<typename Derived
>
5767 TreeTransform
<Derived
>::TransformVAArgExpr(VAArgExpr
*E
) {
5768 TypeSourceInfo
*TInfo
= getDerived().TransformType(E
->getWrittenTypeInfo());
5772 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
5773 if (SubExpr
.isInvalid())
5776 if (!getDerived().AlwaysRebuild() &&
5777 TInfo
== E
->getWrittenTypeInfo() &&
5778 SubExpr
.get() == E
->getSubExpr())
5779 return SemaRef
.Owned(E
);
5781 return getDerived().RebuildVAArgExpr(E
->getBuiltinLoc(), SubExpr
.get(),
5782 TInfo
, E
->getRParenLoc());
5785 template<typename Derived
>
5787 TreeTransform
<Derived
>::TransformParenListExpr(ParenListExpr
*E
) {
5788 bool ArgumentChanged
= false;
5789 ASTOwningVector
<Expr
*, 4> Inits(SemaRef
);
5790 if (TransformExprs(E
->getExprs(), E
->getNumExprs(), true, Inits
,
5794 return getDerived().RebuildParenListExpr(E
->getLParenLoc(),
5799 /// \brief Transform an address-of-label expression.
5801 /// By default, the transformation of an address-of-label expression always
5802 /// rebuilds the expression, so that the label identifier can be resolved to
5803 /// the corresponding label statement by semantic analysis.
5804 template<typename Derived
>
5806 TreeTransform
<Derived
>::TransformAddrLabelExpr(AddrLabelExpr
*E
) {
5807 Decl
*LD
= getDerived().TransformDecl(E
->getLabel()->getLocation(),
5812 return getDerived().RebuildAddrLabelExpr(E
->getAmpAmpLoc(), E
->getLabelLoc(),
5813 cast
<LabelDecl
>(LD
));
5816 template<typename Derived
>
5818 TreeTransform
<Derived
>::TransformStmtExpr(StmtExpr
*E
) {
5820 = getDerived().TransformCompoundStmt(E
->getSubStmt(), true);
5821 if (SubStmt
.isInvalid())
5824 if (!getDerived().AlwaysRebuild() &&
5825 SubStmt
.get() == E
->getSubStmt())
5826 return SemaRef
.Owned(E
);
5828 return getDerived().RebuildStmtExpr(E
->getLParenLoc(),
5833 template<typename Derived
>
5835 TreeTransform
<Derived
>::TransformChooseExpr(ChooseExpr
*E
) {
5836 ExprResult Cond
= getDerived().TransformExpr(E
->getCond());
5837 if (Cond
.isInvalid())
5840 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
5841 if (LHS
.isInvalid())
5844 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
5845 if (RHS
.isInvalid())
5848 if (!getDerived().AlwaysRebuild() &&
5849 Cond
.get() == E
->getCond() &&
5850 LHS
.get() == E
->getLHS() &&
5851 RHS
.get() == E
->getRHS())
5852 return SemaRef
.Owned(E
);
5854 return getDerived().RebuildChooseExpr(E
->getBuiltinLoc(),
5855 Cond
.get(), LHS
.get(), RHS
.get(),
5859 template<typename Derived
>
5861 TreeTransform
<Derived
>::TransformGNUNullExpr(GNUNullExpr
*E
) {
5862 return SemaRef
.Owned(E
);
5865 template<typename Derived
>
5867 TreeTransform
<Derived
>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr
*E
) {
5868 switch (E
->getOperator()) {
5872 case OO_Array_Delete
:
5873 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
5877 // This is a call to an object's operator().
5878 assert(E
->getNumArgs() >= 1 && "Object call is missing arguments");
5880 // Transform the object itself.
5881 ExprResult Object
= getDerived().TransformExpr(E
->getArg(0));
5882 if (Object
.isInvalid())
5885 // FIXME: Poor location information
5886 SourceLocation FakeLParenLoc
5887 = SemaRef
.PP
.getLocForEndOfToken(
5888 static_cast<Expr
*>(Object
.get())->getLocEnd());
5890 // Transform the call arguments.
5891 ASTOwningVector
<Expr
*> Args(SemaRef
);
5892 if (getDerived().TransformExprs(E
->getArgs() + 1, E
->getNumArgs() - 1, true,
5896 return getDerived().RebuildCallExpr(Object
.get(), FakeLParenLoc
,
5901 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5903 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5904 #include "clang/Basic/OperatorKinds.def"
5909 case OO_Conditional
:
5910 llvm_unreachable("conditional operator is not actually overloadable");
5914 case NUM_OVERLOADED_OPERATORS
:
5915 llvm_unreachable("not an overloaded operator?");
5919 ExprResult Callee
= getDerived().TransformExpr(E
->getCallee());
5920 if (Callee
.isInvalid())
5923 ExprResult First
= getDerived().TransformExpr(E
->getArg(0));
5924 if (First
.isInvalid())
5928 if (E
->getNumArgs() == 2) {
5929 Second
= getDerived().TransformExpr(E
->getArg(1));
5930 if (Second
.isInvalid())
5934 if (!getDerived().AlwaysRebuild() &&
5935 Callee
.get() == E
->getCallee() &&
5936 First
.get() == E
->getArg(0) &&
5937 (E
->getNumArgs() != 2 || Second
.get() == E
->getArg(1)))
5938 return SemaRef
.Owned(E
);
5940 return getDerived().RebuildCXXOperatorCallExpr(E
->getOperator(),
5941 E
->getOperatorLoc(),
5947 template<typename Derived
>
5949 TreeTransform
<Derived
>::TransformCXXMemberCallExpr(CXXMemberCallExpr
*E
) {
5950 return getDerived().TransformCallExpr(E
);
5953 template<typename Derived
>
5955 TreeTransform
<Derived
>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr
*E
) {
5956 // Transform the callee.
5957 ExprResult Callee
= getDerived().TransformExpr(E
->getCallee());
5958 if (Callee
.isInvalid())
5961 // Transform exec config.
5962 ExprResult EC
= getDerived().TransformCallExpr(E
->getConfig());
5966 // Transform arguments.
5967 bool ArgChanged
= false;
5968 ASTOwningVector
<Expr
*> Args(SemaRef
);
5969 if (getDerived().TransformExprs(E
->getArgs(), E
->getNumArgs(), true, Args
,
5973 if (!getDerived().AlwaysRebuild() &&
5974 Callee
.get() == E
->getCallee() &&
5976 return SemaRef
.Owned(E
);
5978 // FIXME: Wrong source location information for the '('.
5979 SourceLocation FakeLParenLoc
5980 = ((Expr
*)Callee
.get())->getSourceRange().getBegin();
5981 return getDerived().RebuildCallExpr(Callee
.get(), FakeLParenLoc
,
5983 E
->getRParenLoc(), EC
.get());
5986 template<typename Derived
>
5988 TreeTransform
<Derived
>::TransformCXXNamedCastExpr(CXXNamedCastExpr
*E
) {
5989 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeInfoAsWritten());
5994 = getDerived().TransformExpr(E
->getSubExprAsWritten());
5995 if (SubExpr
.isInvalid())
5998 if (!getDerived().AlwaysRebuild() &&
5999 Type
== E
->getTypeInfoAsWritten() &&
6000 SubExpr
.get() == E
->getSubExpr())
6001 return SemaRef
.Owned(E
);
6003 // FIXME: Poor source location information here.
6004 SourceLocation FakeLAngleLoc
6005 = SemaRef
.PP
.getLocForEndOfToken(E
->getOperatorLoc());
6006 SourceLocation FakeRAngleLoc
= E
->getSubExpr()->getSourceRange().getBegin();
6007 SourceLocation FakeRParenLoc
6008 = SemaRef
.PP
.getLocForEndOfToken(
6009 E
->getSubExpr()->getSourceRange().getEnd());
6010 return getDerived().RebuildCXXNamedCastExpr(E
->getOperatorLoc(),
6020 template<typename Derived
>
6022 TreeTransform
<Derived
>::TransformCXXStaticCastExpr(CXXStaticCastExpr
*E
) {
6023 return getDerived().TransformCXXNamedCastExpr(E
);
6026 template<typename Derived
>
6028 TreeTransform
<Derived
>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr
*E
) {
6029 return getDerived().TransformCXXNamedCastExpr(E
);
6032 template<typename Derived
>
6034 TreeTransform
<Derived
>::TransformCXXReinterpretCastExpr(
6035 CXXReinterpretCastExpr
*E
) {
6036 return getDerived().TransformCXXNamedCastExpr(E
);
6039 template<typename Derived
>
6041 TreeTransform
<Derived
>::TransformCXXConstCastExpr(CXXConstCastExpr
*E
) {
6042 return getDerived().TransformCXXNamedCastExpr(E
);
6045 template<typename Derived
>
6047 TreeTransform
<Derived
>::TransformCXXFunctionalCastExpr(
6048 CXXFunctionalCastExpr
*E
) {
6049 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeInfoAsWritten());
6054 = getDerived().TransformExpr(E
->getSubExprAsWritten());
6055 if (SubExpr
.isInvalid())
6058 if (!getDerived().AlwaysRebuild() &&
6059 Type
== E
->getTypeInfoAsWritten() &&
6060 SubExpr
.get() == E
->getSubExpr())
6061 return SemaRef
.Owned(E
);
6063 return getDerived().RebuildCXXFunctionalCastExpr(Type
,
6064 /*FIXME:*/E
->getSubExpr()->getLocStart(),
6069 template<typename Derived
>
6071 TreeTransform
<Derived
>::TransformCXXTypeidExpr(CXXTypeidExpr
*E
) {
6072 if (E
->isTypeOperand()) {
6073 TypeSourceInfo
*TInfo
6074 = getDerived().TransformType(E
->getTypeOperandSourceInfo());
6078 if (!getDerived().AlwaysRebuild() &&
6079 TInfo
== E
->getTypeOperandSourceInfo())
6080 return SemaRef
.Owned(E
);
6082 return getDerived().RebuildCXXTypeidExpr(E
->getType(),
6088 // We don't know whether the expression is potentially evaluated until
6089 // after we perform semantic analysis, so the expression is potentially
6090 // potentially evaluated.
6091 EnterExpressionEvaluationContext
Unevaluated(SemaRef
,
6092 Sema::PotentiallyPotentiallyEvaluated
);
6094 ExprResult SubExpr
= getDerived().TransformExpr(E
->getExprOperand());
6095 if (SubExpr
.isInvalid())
6098 if (!getDerived().AlwaysRebuild() &&
6099 SubExpr
.get() == E
->getExprOperand())
6100 return SemaRef
.Owned(E
);
6102 return getDerived().RebuildCXXTypeidExpr(E
->getType(),
6108 template<typename Derived
>
6110 TreeTransform
<Derived
>::TransformCXXUuidofExpr(CXXUuidofExpr
*E
) {
6111 if (E
->isTypeOperand()) {
6112 TypeSourceInfo
*TInfo
6113 = getDerived().TransformType(E
->getTypeOperandSourceInfo());
6117 if (!getDerived().AlwaysRebuild() &&
6118 TInfo
== E
->getTypeOperandSourceInfo())
6119 return SemaRef
.Owned(E
);
6121 return getDerived().RebuildCXXTypeidExpr(E
->getType(),
6127 // We don't know whether the expression is potentially evaluated until
6128 // after we perform semantic analysis, so the expression is potentially
6129 // potentially evaluated.
6130 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
6132 ExprResult SubExpr
= getDerived().TransformExpr(E
->getExprOperand());
6133 if (SubExpr
.isInvalid())
6136 if (!getDerived().AlwaysRebuild() &&
6137 SubExpr
.get() == E
->getExprOperand())
6138 return SemaRef
.Owned(E
);
6140 return getDerived().RebuildCXXUuidofExpr(E
->getType(),
6146 template<typename Derived
>
6148 TreeTransform
<Derived
>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr
*E
) {
6149 return SemaRef
.Owned(E
);
6152 template<typename Derived
>
6154 TreeTransform
<Derived
>::TransformCXXNullPtrLiteralExpr(
6155 CXXNullPtrLiteralExpr
*E
) {
6156 return SemaRef
.Owned(E
);
6159 template<typename Derived
>
6161 TreeTransform
<Derived
>::TransformCXXThisExpr(CXXThisExpr
*E
) {
6162 DeclContext
*DC
= getSema().getFunctionLevelDeclContext();
6163 CXXMethodDecl
*MD
= dyn_cast
<CXXMethodDecl
>(DC
);
6164 QualType T
= MD
->getThisType(getSema().Context
);
6166 if (!getDerived().AlwaysRebuild() && T
== E
->getType())
6167 return SemaRef
.Owned(E
);
6169 return getDerived().RebuildCXXThisExpr(E
->getLocStart(), T
, E
->isImplicit());
6172 template<typename Derived
>
6174 TreeTransform
<Derived
>::TransformCXXThrowExpr(CXXThrowExpr
*E
) {
6175 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
6176 if (SubExpr
.isInvalid())
6179 if (!getDerived().AlwaysRebuild() &&
6180 SubExpr
.get() == E
->getSubExpr())
6181 return SemaRef
.Owned(E
);
6183 return getDerived().RebuildCXXThrowExpr(E
->getThrowLoc(), SubExpr
.get());
6186 template<typename Derived
>
6188 TreeTransform
<Derived
>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr
*E
) {
6190 = cast_or_null
<ParmVarDecl
>(getDerived().TransformDecl(E
->getLocStart(),
6195 if (!getDerived().AlwaysRebuild() &&
6196 Param
== E
->getParam())
6197 return SemaRef
.Owned(E
);
6199 return getDerived().RebuildCXXDefaultArgExpr(E
->getUsedLocation(), Param
);
6202 template<typename Derived
>
6204 TreeTransform
<Derived
>::TransformCXXScalarValueInitExpr(
6205 CXXScalarValueInitExpr
*E
) {
6206 TypeSourceInfo
*T
= getDerived().TransformType(E
->getTypeSourceInfo());
6210 if (!getDerived().AlwaysRebuild() &&
6211 T
== E
->getTypeSourceInfo())
6212 return SemaRef
.Owned(E
);
6214 return getDerived().RebuildCXXScalarValueInitExpr(T
,
6215 /*FIXME:*/T
->getTypeLoc().getEndLoc(),
6219 template<typename Derived
>
6221 TreeTransform
<Derived
>::TransformCXXNewExpr(CXXNewExpr
*E
) {
6222 // Transform the type that we're allocating
6223 TypeSourceInfo
*AllocTypeInfo
6224 = getDerived().TransformType(E
->getAllocatedTypeSourceInfo());
6228 // Transform the size of the array we're allocating (if any).
6229 ExprResult ArraySize
= getDerived().TransformExpr(E
->getArraySize());
6230 if (ArraySize
.isInvalid())
6233 // Transform the placement arguments (if any).
6234 bool ArgumentChanged
= false;
6235 ASTOwningVector
<Expr
*> PlacementArgs(SemaRef
);
6236 if (getDerived().TransformExprs(E
->getPlacementArgs(),
6237 E
->getNumPlacementArgs(), true,
6238 PlacementArgs
, &ArgumentChanged
))
6241 // transform the constructor arguments (if any).
6242 ASTOwningVector
<Expr
*> ConstructorArgs(SemaRef
);
6243 if (TransformExprs(E
->getConstructorArgs(), E
->getNumConstructorArgs(), true,
6244 ConstructorArgs
, &ArgumentChanged
))
6247 // Transform constructor, new operator, and delete operator.
6248 CXXConstructorDecl
*Constructor
= 0;
6249 if (E
->getConstructor()) {
6250 Constructor
= cast_or_null
<CXXConstructorDecl
>(
6251 getDerived().TransformDecl(E
->getLocStart(),
6252 E
->getConstructor()));
6257 FunctionDecl
*OperatorNew
= 0;
6258 if (E
->getOperatorNew()) {
6259 OperatorNew
= cast_or_null
<FunctionDecl
>(
6260 getDerived().TransformDecl(E
->getLocStart(),
6261 E
->getOperatorNew()));
6266 FunctionDecl
*OperatorDelete
= 0;
6267 if (E
->getOperatorDelete()) {
6268 OperatorDelete
= cast_or_null
<FunctionDecl
>(
6269 getDerived().TransformDecl(E
->getLocStart(),
6270 E
->getOperatorDelete()));
6271 if (!OperatorDelete
)
6275 if (!getDerived().AlwaysRebuild() &&
6276 AllocTypeInfo
== E
->getAllocatedTypeSourceInfo() &&
6277 ArraySize
.get() == E
->getArraySize() &&
6278 Constructor
== E
->getConstructor() &&
6279 OperatorNew
== E
->getOperatorNew() &&
6280 OperatorDelete
== E
->getOperatorDelete() &&
6282 // Mark any declarations we need as referenced.
6283 // FIXME: instantiation-specific.
6285 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), Constructor
);
6287 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), OperatorNew
);
6289 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), OperatorDelete
);
6290 return SemaRef
.Owned(E
);
6293 QualType AllocType
= AllocTypeInfo
->getType();
6294 if (!ArraySize
.get()) {
6295 // If no array size was specified, but the new expression was
6296 // instantiated with an array type (e.g., "new T" where T is
6297 // instantiated with "int[4]"), extract the outer bound from the
6298 // array type as our array size. We do this with constant and
6299 // dependently-sized array types.
6300 const ArrayType
*ArrayT
= SemaRef
.Context
.getAsArrayType(AllocType
);
6303 } else if (const ConstantArrayType
*ConsArrayT
6304 = dyn_cast
<ConstantArrayType
>(ArrayT
)) {
6306 = SemaRef
.Owned(IntegerLiteral::Create(SemaRef
.Context
,
6307 ConsArrayT
->getSize(),
6308 SemaRef
.Context
.getSizeType(),
6309 /*FIXME:*/E
->getLocStart()));
6310 AllocType
= ConsArrayT
->getElementType();
6311 } else if (const DependentSizedArrayType
*DepArrayT
6312 = dyn_cast
<DependentSizedArrayType
>(ArrayT
)) {
6313 if (DepArrayT
->getSizeExpr()) {
6314 ArraySize
= SemaRef
.Owned(DepArrayT
->getSizeExpr());
6315 AllocType
= DepArrayT
->getElementType();
6320 return getDerived().RebuildCXXNewExpr(E
->getLocStart(),
6322 /*FIXME:*/E
->getLocStart(),
6323 move_arg(PlacementArgs
),
6324 /*FIXME:*/E
->getLocStart(),
6325 E
->getTypeIdParens(),
6329 /*FIXME:*/E
->getLocStart(),
6330 move_arg(ConstructorArgs
),
6334 template<typename Derived
>
6336 TreeTransform
<Derived
>::TransformCXXDeleteExpr(CXXDeleteExpr
*E
) {
6337 ExprResult Operand
= getDerived().TransformExpr(E
->getArgument());
6338 if (Operand
.isInvalid())
6341 // Transform the delete operator, if known.
6342 FunctionDecl
*OperatorDelete
= 0;
6343 if (E
->getOperatorDelete()) {
6344 OperatorDelete
= cast_or_null
<FunctionDecl
>(
6345 getDerived().TransformDecl(E
->getLocStart(),
6346 E
->getOperatorDelete()));
6347 if (!OperatorDelete
)
6351 if (!getDerived().AlwaysRebuild() &&
6352 Operand
.get() == E
->getArgument() &&
6353 OperatorDelete
== E
->getOperatorDelete()) {
6354 // Mark any declarations we need as referenced.
6355 // FIXME: instantiation-specific.
6357 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), OperatorDelete
);
6359 if (!E
->getArgument()->isTypeDependent()) {
6360 QualType Destroyed
= SemaRef
.Context
.getBaseElementType(
6361 E
->getDestroyedType());
6362 if (const RecordType
*DestroyedRec
= Destroyed
->getAs
<RecordType
>()) {
6363 CXXRecordDecl
*Record
= cast
<CXXRecordDecl
>(DestroyedRec
->getDecl());
6364 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(),
6365 SemaRef
.LookupDestructor(Record
));
6369 return SemaRef
.Owned(E
);
6372 return getDerived().RebuildCXXDeleteExpr(E
->getLocStart(),
6373 E
->isGlobalDelete(),
6378 template<typename Derived
>
6380 TreeTransform
<Derived
>::TransformCXXPseudoDestructorExpr(
6381 CXXPseudoDestructorExpr
*E
) {
6382 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
6383 if (Base
.isInvalid())
6386 ParsedType ObjectTypePtr
;
6387 bool MayBePseudoDestructor
= false;
6388 Base
= SemaRef
.ActOnStartCXXMemberReference(0, Base
.get(),
6389 E
->getOperatorLoc(),
6390 E
->isArrow()? tok::arrow
: tok::period
,
6392 MayBePseudoDestructor
);
6393 if (Base
.isInvalid())
6396 QualType ObjectType
= ObjectTypePtr
.get();
6397 NestedNameSpecifier
*Qualifier
= E
->getQualifier();
6400 = getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
6401 E
->getQualifierRange(),
6407 PseudoDestructorTypeStorage Destroyed
;
6408 if (E
->getDestroyedTypeInfo()) {
6409 TypeSourceInfo
*DestroyedTypeInfo
6410 = getDerived().TransformTypeInObjectScope(E
->getDestroyedTypeInfo(),
6411 ObjectType
, 0, Qualifier
);
6412 if (!DestroyedTypeInfo
)
6414 Destroyed
= DestroyedTypeInfo
;
6415 } else if (ObjectType
->isDependentType()) {
6416 // We aren't likely to be able to resolve the identifier down to a type
6417 // now anyway, so just retain the identifier.
6418 Destroyed
= PseudoDestructorTypeStorage(E
->getDestroyedTypeIdentifier(),
6419 E
->getDestroyedTypeLoc());
6421 // Look for a destructor known with the given name.
6424 SS
.setScopeRep(Qualifier
);
6425 SS
.setRange(E
->getQualifierRange());
6428 ParsedType T
= SemaRef
.getDestructorName(E
->getTildeLoc(),
6429 *E
->getDestroyedTypeIdentifier(),
6430 E
->getDestroyedTypeLoc(),
6438 = SemaRef
.Context
.getTrivialTypeSourceInfo(SemaRef
.GetTypeFromParser(T
),
6439 E
->getDestroyedTypeLoc());
6442 TypeSourceInfo
*ScopeTypeInfo
= 0;
6443 if (E
->getScopeTypeInfo()) {
6444 ScopeTypeInfo
= getDerived().TransformType(E
->getScopeTypeInfo());
6449 return getDerived().RebuildCXXPseudoDestructorExpr(Base
.get(),
6450 E
->getOperatorLoc(),
6453 E
->getQualifierRange(),
6455 E
->getColonColonLoc(),
6460 template<typename Derived
>
6462 TreeTransform
<Derived
>::TransformUnresolvedLookupExpr(
6463 UnresolvedLookupExpr
*Old
) {
6464 TemporaryBase
Rebase(*this, Old
->getNameLoc(), DeclarationName());
6466 LookupResult
R(SemaRef
, Old
->getName(), Old
->getNameLoc(),
6467 Sema::LookupOrdinaryName
);
6469 // Transform all the decls.
6470 for (UnresolvedLookupExpr::decls_iterator I
= Old
->decls_begin(),
6471 E
= Old
->decls_end(); I
!= E
; ++I
) {
6472 NamedDecl
*InstD
= static_cast<NamedDecl
*>(
6473 getDerived().TransformDecl(Old
->getNameLoc(),
6476 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6477 // This can happen because of dependent hiding.
6478 if (isa
<UsingShadowDecl
>(*I
))
6484 // Expand using declarations.
6485 if (isa
<UsingDecl
>(InstD
)) {
6486 UsingDecl
*UD
= cast
<UsingDecl
>(InstD
);
6487 for (UsingDecl::shadow_iterator I
= UD
->shadow_begin(),
6488 E
= UD
->shadow_end(); I
!= E
; ++I
)
6496 // Resolve a kind, but don't do any further analysis. If it's
6497 // ambiguous, the callee needs to deal with it.
6500 // Rebuild the nested-name qualifier, if present.
6502 NestedNameSpecifier
*Qualifier
= 0;
6503 if (Old
->getQualifier()) {
6504 Qualifier
= getDerived().TransformNestedNameSpecifier(Old
->getQualifier(),
6505 Old
->getQualifierRange());
6509 SS
.setScopeRep(Qualifier
);
6510 SS
.setRange(Old
->getQualifierRange());
6513 if (Old
->getNamingClass()) {
6514 CXXRecordDecl
*NamingClass
6515 = cast_or_null
<CXXRecordDecl
>(getDerived().TransformDecl(
6517 Old
->getNamingClass()));
6521 R
.setNamingClass(NamingClass
);
6524 // If we have no template arguments, it's a normal declaration name.
6525 if (!Old
->hasExplicitTemplateArgs())
6526 return getDerived().RebuildDeclarationNameExpr(SS
, R
, Old
->requiresADL());
6528 // If we have template arguments, rebuild them, then rebuild the
6529 // templateid expression.
6530 TemplateArgumentListInfo
TransArgs(Old
->getLAngleLoc(), Old
->getRAngleLoc());
6531 if (getDerived().TransformTemplateArguments(Old
->getTemplateArgs(),
6532 Old
->getNumTemplateArgs(),
6536 return getDerived().RebuildTemplateIdExpr(SS
, R
, Old
->requiresADL(),
6540 template<typename Derived
>
6542 TreeTransform
<Derived
>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr
*E
) {
6543 TypeSourceInfo
*T
= getDerived().TransformType(E
->getQueriedTypeSourceInfo());
6547 if (!getDerived().AlwaysRebuild() &&
6548 T
== E
->getQueriedTypeSourceInfo())
6549 return SemaRef
.Owned(E
);
6551 return getDerived().RebuildUnaryTypeTrait(E
->getTrait(),
6557 template<typename Derived
>
6559 TreeTransform
<Derived
>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr
*E
) {
6560 TypeSourceInfo
*LhsT
= getDerived().TransformType(E
->getLhsTypeSourceInfo());
6564 TypeSourceInfo
*RhsT
= getDerived().TransformType(E
->getRhsTypeSourceInfo());
6568 if (!getDerived().AlwaysRebuild() &&
6569 LhsT
== E
->getLhsTypeSourceInfo() && RhsT
== E
->getRhsTypeSourceInfo())
6570 return SemaRef
.Owned(E
);
6572 return getDerived().RebuildBinaryTypeTrait(E
->getTrait(),
6578 template<typename Derived
>
6580 TreeTransform
<Derived
>::TransformDependentScopeDeclRefExpr(
6581 DependentScopeDeclRefExpr
*E
) {
6582 NestedNameSpecifier
*NNS
6583 = getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
6584 E
->getQualifierRange());
6588 // TODO: If this is a conversion-function-id, verify that the
6589 // destination type name (if present) resolves the same way after
6590 // instantiation as it did in the local scope.
6592 DeclarationNameInfo NameInfo
6593 = getDerived().TransformDeclarationNameInfo(E
->getNameInfo());
6594 if (!NameInfo
.getName())
6597 if (!E
->hasExplicitTemplateArgs()) {
6598 if (!getDerived().AlwaysRebuild() &&
6599 NNS
== E
->getQualifier() &&
6600 // Note: it is sufficient to compare the Name component of NameInfo:
6601 // if name has not changed, DNLoc has not changed either.
6602 NameInfo
.getName() == E
->getDeclName())
6603 return SemaRef
.Owned(E
);
6605 return getDerived().RebuildDependentScopeDeclRefExpr(NNS
,
6606 E
->getQualifierRange(),
6608 /*TemplateArgs*/ 0);
6611 TemplateArgumentListInfo
TransArgs(E
->getLAngleLoc(), E
->getRAngleLoc());
6612 if (getDerived().TransformTemplateArguments(E
->getTemplateArgs(),
6613 E
->getNumTemplateArgs(),
6617 return getDerived().RebuildDependentScopeDeclRefExpr(NNS
,
6618 E
->getQualifierRange(),
6623 template<typename Derived
>
6625 TreeTransform
<Derived
>::TransformCXXConstructExpr(CXXConstructExpr
*E
) {
6626 // CXXConstructExprs are always implicit, so when we have a
6627 // 1-argument construction we just transform that argument.
6628 if (E
->getNumArgs() == 1 ||
6629 (E
->getNumArgs() > 1 && getDerived().DropCallArgument(E
->getArg(1))))
6630 return getDerived().TransformExpr(E
->getArg(0));
6632 TemporaryBase
Rebase(*this, /*FIXME*/E
->getLocStart(), DeclarationName());
6634 QualType T
= getDerived().TransformType(E
->getType());
6638 CXXConstructorDecl
*Constructor
6639 = cast_or_null
<CXXConstructorDecl
>(
6640 getDerived().TransformDecl(E
->getLocStart(),
6641 E
->getConstructor()));
6645 bool ArgumentChanged
= false;
6646 ASTOwningVector
<Expr
*> Args(SemaRef
);
6647 if (getDerived().TransformExprs(E
->getArgs(), E
->getNumArgs(), true, Args
,
6651 if (!getDerived().AlwaysRebuild() &&
6652 T
== E
->getType() &&
6653 Constructor
== E
->getConstructor() &&
6655 // Mark the constructor as referenced.
6656 // FIXME: Instantiation-specific
6657 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), Constructor
);
6658 return SemaRef
.Owned(E
);
6661 return getDerived().RebuildCXXConstructExpr(T
, /*FIXME:*/E
->getLocStart(),
6662 Constructor
, E
->isElidable(),
6664 E
->requiresZeroInitialization(),
6665 E
->getConstructionKind(),
6666 E
->getParenRange());
6669 /// \brief Transform a C++ temporary-binding expression.
6671 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6672 /// transform the subexpression and return that.
6673 template<typename Derived
>
6675 TreeTransform
<Derived
>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr
*E
) {
6676 return getDerived().TransformExpr(E
->getSubExpr());
6679 /// \brief Transform a C++ expression that contains cleanups that should
6680 /// be run after the expression is evaluated.
6682 /// Since ExprWithCleanups nodes are implicitly generated, we
6683 /// just transform the subexpression and return that.
6684 template<typename Derived
>
6686 TreeTransform
<Derived
>::TransformExprWithCleanups(ExprWithCleanups
*E
) {
6687 return getDerived().TransformExpr(E
->getSubExpr());
6690 template<typename Derived
>
6692 TreeTransform
<Derived
>::TransformCXXTemporaryObjectExpr(
6693 CXXTemporaryObjectExpr
*E
) {
6694 TypeSourceInfo
*T
= getDerived().TransformType(E
->getTypeSourceInfo());
6698 CXXConstructorDecl
*Constructor
6699 = cast_or_null
<CXXConstructorDecl
>(
6700 getDerived().TransformDecl(E
->getLocStart(),
6701 E
->getConstructor()));
6705 bool ArgumentChanged
= false;
6706 ASTOwningVector
<Expr
*> Args(SemaRef
);
6707 Args
.reserve(E
->getNumArgs());
6708 if (TransformExprs(E
->getArgs(), E
->getNumArgs(), true, Args
,
6712 if (!getDerived().AlwaysRebuild() &&
6713 T
== E
->getTypeSourceInfo() &&
6714 Constructor
== E
->getConstructor() &&
6716 // FIXME: Instantiation-specific
6717 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), Constructor
);
6718 return SemaRef
.MaybeBindToTemporary(E
);
6721 return getDerived().RebuildCXXTemporaryObjectExpr(T
,
6722 /*FIXME:*/T
->getTypeLoc().getEndLoc(),
6727 template<typename Derived
>
6729 TreeTransform
<Derived
>::TransformCXXUnresolvedConstructExpr(
6730 CXXUnresolvedConstructExpr
*E
) {
6731 TypeSourceInfo
*T
= getDerived().TransformType(E
->getTypeSourceInfo());
6735 bool ArgumentChanged
= false;
6736 ASTOwningVector
<Expr
*> Args(SemaRef
);
6737 Args
.reserve(E
->arg_size());
6738 if (getDerived().TransformExprs(E
->arg_begin(), E
->arg_size(), true, Args
,
6742 if (!getDerived().AlwaysRebuild() &&
6743 T
== E
->getTypeSourceInfo() &&
6745 return SemaRef
.Owned(E
);
6747 // FIXME: we're faking the locations of the commas
6748 return getDerived().RebuildCXXUnresolvedConstructExpr(T
,
6754 template<typename Derived
>
6756 TreeTransform
<Derived
>::TransformCXXDependentScopeMemberExpr(
6757 CXXDependentScopeMemberExpr
*E
) {
6758 // Transform the base of the expression.
6759 ExprResult
Base((Expr
*) 0);
6762 QualType ObjectType
;
6763 if (!E
->isImplicitAccess()) {
6764 OldBase
= E
->getBase();
6765 Base
= getDerived().TransformExpr(OldBase
);
6766 if (Base
.isInvalid())
6769 // Start the member reference and compute the object's type.
6770 ParsedType ObjectTy
;
6771 bool MayBePseudoDestructor
= false;
6772 Base
= SemaRef
.ActOnStartCXXMemberReference(0, Base
.get(),
6773 E
->getOperatorLoc(),
6774 E
->isArrow()? tok::arrow
: tok::period
,
6776 MayBePseudoDestructor
);
6777 if (Base
.isInvalid())
6780 ObjectType
= ObjectTy
.get();
6781 BaseType
= ((Expr
*) Base
.get())->getType();
6784 BaseType
= getDerived().TransformType(E
->getBaseType());
6785 ObjectType
= BaseType
->getAs
<PointerType
>()->getPointeeType();
6788 // Transform the first part of the nested-name-specifier that qualifies
6790 NamedDecl
*FirstQualifierInScope
6791 = getDerived().TransformFirstQualifierInScope(
6792 E
->getFirstQualifierFoundInScope(),
6793 E
->getQualifierRange().getBegin());
6795 NestedNameSpecifier
*Qualifier
= 0;
6796 if (E
->getQualifier()) {
6797 Qualifier
= getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
6798 E
->getQualifierRange(),
6800 FirstQualifierInScope
);
6805 // TODO: If this is a conversion-function-id, verify that the
6806 // destination type name (if present) resolves the same way after
6807 // instantiation as it did in the local scope.
6809 DeclarationNameInfo NameInfo
6810 = getDerived().TransformDeclarationNameInfo(E
->getMemberNameInfo());
6811 if (!NameInfo
.getName())
6814 if (!E
->hasExplicitTemplateArgs()) {
6815 // This is a reference to a member without an explicitly-specified
6816 // template argument list. Optimize for this common case.
6817 if (!getDerived().AlwaysRebuild() &&
6818 Base
.get() == OldBase
&&
6819 BaseType
== E
->getBaseType() &&
6820 Qualifier
== E
->getQualifier() &&
6821 NameInfo
.getName() == E
->getMember() &&
6822 FirstQualifierInScope
== E
->getFirstQualifierFoundInScope())
6823 return SemaRef
.Owned(E
);
6825 return getDerived().RebuildCXXDependentScopeMemberExpr(Base
.get(),
6828 E
->getOperatorLoc(),
6830 E
->getQualifierRange(),
6831 FirstQualifierInScope
,
6833 /*TemplateArgs*/ 0);
6836 TemplateArgumentListInfo
TransArgs(E
->getLAngleLoc(), E
->getRAngleLoc());
6837 if (getDerived().TransformTemplateArguments(E
->getTemplateArgs(),
6838 E
->getNumTemplateArgs(),
6842 return getDerived().RebuildCXXDependentScopeMemberExpr(Base
.get(),
6845 E
->getOperatorLoc(),
6847 E
->getQualifierRange(),
6848 FirstQualifierInScope
,
6853 template<typename Derived
>
6855 TreeTransform
<Derived
>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr
*Old
) {
6856 // Transform the base of the expression.
6857 ExprResult
Base((Expr
*) 0);
6859 if (!Old
->isImplicitAccess()) {
6860 Base
= getDerived().TransformExpr(Old
->getBase());
6861 if (Base
.isInvalid())
6863 BaseType
= ((Expr
*) Base
.get())->getType();
6865 BaseType
= getDerived().TransformType(Old
->getBaseType());
6868 NestedNameSpecifier
*Qualifier
= 0;
6869 if (Old
->getQualifier()) {
6871 = getDerived().TransformNestedNameSpecifier(Old
->getQualifier(),
6872 Old
->getQualifierRange());
6877 LookupResult
R(SemaRef
, Old
->getMemberNameInfo(),
6878 Sema::LookupOrdinaryName
);
6880 // Transform all the decls.
6881 for (UnresolvedMemberExpr::decls_iterator I
= Old
->decls_begin(),
6882 E
= Old
->decls_end(); I
!= E
; ++I
) {
6883 NamedDecl
*InstD
= static_cast<NamedDecl
*>(
6884 getDerived().TransformDecl(Old
->getMemberLoc(),
6887 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6888 // This can happen because of dependent hiding.
6889 if (isa
<UsingShadowDecl
>(*I
))
6895 // Expand using declarations.
6896 if (isa
<UsingDecl
>(InstD
)) {
6897 UsingDecl
*UD
= cast
<UsingDecl
>(InstD
);
6898 for (UsingDecl::shadow_iterator I
= UD
->shadow_begin(),
6899 E
= UD
->shadow_end(); I
!= E
; ++I
)
6909 // Determine the naming class.
6910 if (Old
->getNamingClass()) {
6911 CXXRecordDecl
*NamingClass
6912 = cast_or_null
<CXXRecordDecl
>(getDerived().TransformDecl(
6913 Old
->getMemberLoc(),
6914 Old
->getNamingClass()));
6918 R
.setNamingClass(NamingClass
);
6921 TemplateArgumentListInfo TransArgs
;
6922 if (Old
->hasExplicitTemplateArgs()) {
6923 TransArgs
.setLAngleLoc(Old
->getLAngleLoc());
6924 TransArgs
.setRAngleLoc(Old
->getRAngleLoc());
6925 if (getDerived().TransformTemplateArguments(Old
->getTemplateArgs(),
6926 Old
->getNumTemplateArgs(),
6931 // FIXME: to do this check properly, we will need to preserve the
6932 // first-qualifier-in-scope here, just in case we had a dependent
6933 // base (and therefore couldn't do the check) and a
6934 // nested-name-qualifier (and therefore could do the lookup).
6935 NamedDecl
*FirstQualifierInScope
= 0;
6937 return getDerived().RebuildUnresolvedMemberExpr(Base
.get(),
6939 Old
->getOperatorLoc(),
6942 Old
->getQualifierRange(),
6943 FirstQualifierInScope
,
6945 (Old
->hasExplicitTemplateArgs()
6949 template<typename Derived
>
6951 TreeTransform
<Derived
>::TransformCXXNoexceptExpr(CXXNoexceptExpr
*E
) {
6952 ExprResult SubExpr
= getDerived().TransformExpr(E
->getOperand());
6953 if (SubExpr
.isInvalid())
6956 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getOperand())
6957 return SemaRef
.Owned(E
);
6959 return getDerived().RebuildCXXNoexceptExpr(E
->getSourceRange(),SubExpr
.get());
6962 template<typename Derived
>
6964 TreeTransform
<Derived
>::TransformPackExpansionExpr(PackExpansionExpr
*E
) {
6965 ExprResult Pattern
= getDerived().TransformExpr(E
->getPattern());
6966 if (Pattern
.isInvalid())
6969 if (!getDerived().AlwaysRebuild() && Pattern
.get() == E
->getPattern())
6970 return SemaRef
.Owned(E
);
6972 return getDerived().RebuildPackExpansion(Pattern
.get(), E
->getEllipsisLoc(),
6973 E
->getNumExpansions());
6976 template<typename Derived
>
6978 TreeTransform
<Derived
>::TransformSizeOfPackExpr(SizeOfPackExpr
*E
) {
6979 // If E is not value-dependent, then nothing will change when we transform it.
6980 // Note: This is an instantiation-centric view.
6981 if (!E
->isValueDependent())
6982 return SemaRef
.Owned(E
);
6984 // Note: None of the implementations of TryExpandParameterPacks can ever
6985 // produce a diagnostic when given only a single unexpanded parameter pack,
6987 UnexpandedParameterPack
Unexpanded(E
->getPack(), E
->getPackLoc());
6988 bool ShouldExpand
= false;
6989 bool RetainExpansion
= false;
6990 llvm::Optional
<unsigned> NumExpansions
;
6991 if (getDerived().TryExpandParameterPacks(E
->getOperatorLoc(), E
->getPackLoc(),
6993 ShouldExpand
, RetainExpansion
,
6997 if (!ShouldExpand
|| RetainExpansion
)
6998 return SemaRef
.Owned(E
);
7000 // We now know the length of the parameter pack, so build a new expression
7001 // that stores that length.
7002 return getDerived().RebuildSizeOfPackExpr(E
->getOperatorLoc(), E
->getPack(),
7003 E
->getPackLoc(), E
->getRParenLoc(),
7007 template<typename Derived
>
7009 TreeTransform
<Derived
>::TransformSubstNonTypeTemplateParmPackExpr(
7010 SubstNonTypeTemplateParmPackExpr
*E
) {
7011 // Default behavior is to do nothing with this transformation.
7012 return SemaRef
.Owned(E
);
7015 template<typename Derived
>
7017 TreeTransform
<Derived
>::TransformObjCStringLiteral(ObjCStringLiteral
*E
) {
7018 return SemaRef
.Owned(E
);
7021 template<typename Derived
>
7023 TreeTransform
<Derived
>::TransformObjCEncodeExpr(ObjCEncodeExpr
*E
) {
7024 TypeSourceInfo
*EncodedTypeInfo
7025 = getDerived().TransformType(E
->getEncodedTypeSourceInfo());
7026 if (!EncodedTypeInfo
)
7029 if (!getDerived().AlwaysRebuild() &&
7030 EncodedTypeInfo
== E
->getEncodedTypeSourceInfo())
7031 return SemaRef
.Owned(E
);
7033 return getDerived().RebuildObjCEncodeExpr(E
->getAtLoc(),
7038 template<typename Derived
>
7040 TreeTransform
<Derived
>::TransformObjCMessageExpr(ObjCMessageExpr
*E
) {
7041 // Transform arguments.
7042 bool ArgChanged
= false;
7043 ASTOwningVector
<Expr
*> Args(SemaRef
);
7044 Args
.reserve(E
->getNumArgs());
7045 if (getDerived().TransformExprs(E
->getArgs(), E
->getNumArgs(), false, Args
,
7049 if (E
->getReceiverKind() == ObjCMessageExpr::Class
) {
7050 // Class message: transform the receiver type.
7051 TypeSourceInfo
*ReceiverTypeInfo
7052 = getDerived().TransformType(E
->getClassReceiverTypeInfo());
7053 if (!ReceiverTypeInfo
)
7056 // If nothing changed, just retain the existing message send.
7057 if (!getDerived().AlwaysRebuild() &&
7058 ReceiverTypeInfo
== E
->getClassReceiverTypeInfo() && !ArgChanged
)
7059 return SemaRef
.Owned(E
);
7061 // Build a new class message send.
7062 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo
,
7064 E
->getSelectorLoc(),
7071 // Instance message: transform the receiver
7072 assert(E
->getReceiverKind() == ObjCMessageExpr::Instance
&&
7073 "Only class and instance messages may be instantiated");
7075 = getDerived().TransformExpr(E
->getInstanceReceiver());
7076 if (Receiver
.isInvalid())
7079 // If nothing changed, just retain the existing message send.
7080 if (!getDerived().AlwaysRebuild() &&
7081 Receiver
.get() == E
->getInstanceReceiver() && !ArgChanged
)
7082 return SemaRef
.Owned(E
);
7084 // Build a new instance message send.
7085 return getDerived().RebuildObjCMessageExpr(Receiver
.get(),
7087 E
->getSelectorLoc(),
7094 template<typename Derived
>
7096 TreeTransform
<Derived
>::TransformObjCSelectorExpr(ObjCSelectorExpr
*E
) {
7097 return SemaRef
.Owned(E
);
7100 template<typename Derived
>
7102 TreeTransform
<Derived
>::TransformObjCProtocolExpr(ObjCProtocolExpr
*E
) {
7103 return SemaRef
.Owned(E
);
7106 template<typename Derived
>
7108 TreeTransform
<Derived
>::TransformObjCIvarRefExpr(ObjCIvarRefExpr
*E
) {
7109 // Transform the base expression.
7110 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
7111 if (Base
.isInvalid())
7114 // We don't need to transform the ivar; it will never change.
7116 // If nothing changed, just retain the existing expression.
7117 if (!getDerived().AlwaysRebuild() &&
7118 Base
.get() == E
->getBase())
7119 return SemaRef
.Owned(E
);
7121 return getDerived().RebuildObjCIvarRefExpr(Base
.get(), E
->getDecl(),
7123 E
->isArrow(), E
->isFreeIvar());
7126 template<typename Derived
>
7128 TreeTransform
<Derived
>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr
*E
) {
7129 // 'super' and types never change. Property never changes. Just
7130 // retain the existing expression.
7131 if (!E
->isObjectReceiver())
7132 return SemaRef
.Owned(E
);
7134 // Transform the base expression.
7135 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
7136 if (Base
.isInvalid())
7139 // We don't need to transform the property; it will never change.
7141 // If nothing changed, just retain the existing expression.
7142 if (!getDerived().AlwaysRebuild() &&
7143 Base
.get() == E
->getBase())
7144 return SemaRef
.Owned(E
);
7146 if (E
->isExplicitProperty())
7147 return getDerived().RebuildObjCPropertyRefExpr(Base
.get(),
7148 E
->getExplicitProperty(),
7151 return getDerived().RebuildObjCPropertyRefExpr(Base
.get(),
7153 E
->getImplicitPropertyGetter(),
7154 E
->getImplicitPropertySetter(),
7158 template<typename Derived
>
7160 TreeTransform
<Derived
>::TransformObjCIsaExpr(ObjCIsaExpr
*E
) {
7161 // Transform the base expression.
7162 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
7163 if (Base
.isInvalid())
7166 // If nothing changed, just retain the existing expression.
7167 if (!getDerived().AlwaysRebuild() &&
7168 Base
.get() == E
->getBase())
7169 return SemaRef
.Owned(E
);
7171 return getDerived().RebuildObjCIsaExpr(Base
.get(), E
->getIsaMemberLoc(),
7175 template<typename Derived
>
7177 TreeTransform
<Derived
>::TransformShuffleVectorExpr(ShuffleVectorExpr
*E
) {
7178 bool ArgumentChanged
= false;
7179 ASTOwningVector
<Expr
*> SubExprs(SemaRef
);
7180 SubExprs
.reserve(E
->getNumSubExprs());
7181 if (getDerived().TransformExprs(E
->getSubExprs(), E
->getNumSubExprs(), false,
7182 SubExprs
, &ArgumentChanged
))
7185 if (!getDerived().AlwaysRebuild() &&
7187 return SemaRef
.Owned(E
);
7189 return getDerived().RebuildShuffleVectorExpr(E
->getBuiltinLoc(),
7194 template<typename Derived
>
7196 TreeTransform
<Derived
>::TransformBlockExpr(BlockExpr
*E
) {
7197 BlockDecl
*oldBlock
= E
->getBlockDecl();
7199 SemaRef
.ActOnBlockStart(E
->getCaretLocation(), /*Scope=*/0);
7200 BlockScopeInfo
*blockScope
= SemaRef
.getCurBlock();
7202 blockScope
->TheDecl
->setIsVariadic(oldBlock
->isVariadic());
7203 llvm::SmallVector
<ParmVarDecl
*, 4> params
;
7204 llvm::SmallVector
<QualType
, 4> paramTypes
;
7206 // Parameter substitution.
7207 if (getDerived().TransformFunctionTypeParams(E
->getCaretLocation(),
7208 oldBlock
->param_begin(),
7209 oldBlock
->param_size(),
7210 0, paramTypes
, ¶ms
))
7213 const FunctionType
*exprFunctionType
= E
->getFunctionType();
7214 QualType exprResultType
= exprFunctionType
->getResultType();
7215 if (!exprResultType
.isNull()) {
7216 if (!exprResultType
->isDependentType())
7217 blockScope
->ReturnType
= exprResultType
;
7218 else if (exprResultType
!= getSema().Context
.DependentTy
)
7219 blockScope
->ReturnType
= getDerived().TransformType(exprResultType
);
7222 // If the return type has not been determined yet, leave it as a dependent
7223 // type; it'll get set when we process the body.
7224 if (blockScope
->ReturnType
.isNull())
7225 blockScope
->ReturnType
= getSema().Context
.DependentTy
;
7227 // Don't allow returning a objc interface by value.
7228 if (blockScope
->ReturnType
->isObjCObjectType()) {
7229 getSema().Diag(E
->getCaretLocation(),
7230 diag::err_object_cannot_be_passed_returned_by_value
)
7231 << 0 << blockScope
->ReturnType
;
7235 QualType functionType
= getDerived().RebuildFunctionProtoType(
7236 blockScope
->ReturnType
,
7239 oldBlock
->isVariadic(),
7241 exprFunctionType
->getExtInfo());
7242 blockScope
->FunctionType
= functionType
;
7244 // Set the parameters on the block decl.
7245 if (!params
.empty())
7246 blockScope
->TheDecl
->setParams(params
.data(), params
.size());
7248 // If the return type wasn't explicitly set, it will have been marked as a
7249 // dependent type (DependentTy); clear out the return type setting so
7250 // we will deduce the return type when type-checking the block's body.
7251 if (blockScope
->ReturnType
== getSema().Context
.DependentTy
)
7252 blockScope
->ReturnType
= QualType();
7254 // Transform the body
7255 StmtResult body
= getDerived().TransformStmt(E
->getBody());
7256 if (body
.isInvalid())
7260 // In builds with assertions, make sure that we captured everything we
7263 if (oldBlock
->capturesCXXThis()) assert(blockScope
->CapturesCXXThis
);
7265 for (BlockDecl::capture_iterator i
= oldBlock
->capture_begin(),
7266 e
= oldBlock
->capture_end(); i
!= e
; ++i
) {
7267 VarDecl
*oldCapture
= i
->getVariable();
7269 // Ignore parameter packs.
7270 if (isa
<ParmVarDecl
>(oldCapture
) &&
7271 cast
<ParmVarDecl
>(oldCapture
)->isParameterPack())
7274 VarDecl
*newCapture
=
7275 cast
<VarDecl
>(getDerived().TransformDecl(E
->getCaretLocation(),
7277 assert(blockScope
->CaptureMap
.count(newCapture
));
7281 return SemaRef
.ActOnBlockStmtExpr(E
->getCaretLocation(), body
.get(),
7285 template<typename Derived
>
7287 TreeTransform
<Derived
>::TransformBlockDeclRefExpr(BlockDeclRefExpr
*E
) {
7288 NestedNameSpecifier
*Qualifier
= 0;
7291 = cast_or_null
<ValueDecl
>(getDerived().TransformDecl(E
->getLocation(),
7296 if (!getDerived().AlwaysRebuild() &&
7297 ND
== E
->getDecl()) {
7298 // Mark it referenced in the new context regardless.
7299 // FIXME: this is a bit instantiation-specific.
7300 SemaRef
.MarkDeclarationReferenced(E
->getLocation(), ND
);
7302 return SemaRef
.Owned(E
);
7305 DeclarationNameInfo
NameInfo(E
->getDecl()->getDeclName(), E
->getLocation());
7306 return getDerived().RebuildDeclRefExpr(Qualifier
, SourceLocation(),
7310 //===----------------------------------------------------------------------===//
7311 // Type reconstruction
7312 //===----------------------------------------------------------------------===//
7314 template<typename Derived
>
7315 QualType TreeTransform
<Derived
>::RebuildPointerType(QualType PointeeType
,
7316 SourceLocation Star
) {
7317 return SemaRef
.BuildPointerType(PointeeType
, Star
,
7318 getDerived().getBaseEntity());
7321 template<typename Derived
>
7322 QualType TreeTransform
<Derived
>::RebuildBlockPointerType(QualType PointeeType
,
7323 SourceLocation Star
) {
7324 return SemaRef
.BuildBlockPointerType(PointeeType
, Star
,
7325 getDerived().getBaseEntity());
7328 template<typename Derived
>
7330 TreeTransform
<Derived
>::RebuildReferenceType(QualType ReferentType
,
7331 bool WrittenAsLValue
,
7332 SourceLocation Sigil
) {
7333 return SemaRef
.BuildReferenceType(ReferentType
, WrittenAsLValue
,
7334 Sigil
, getDerived().getBaseEntity());
7337 template<typename Derived
>
7339 TreeTransform
<Derived
>::RebuildMemberPointerType(QualType PointeeType
,
7341 SourceLocation Sigil
) {
7342 return SemaRef
.BuildMemberPointerType(PointeeType
, ClassType
,
7343 Sigil
, getDerived().getBaseEntity());
7346 template<typename Derived
>
7348 TreeTransform
<Derived
>::RebuildArrayType(QualType ElementType
,
7349 ArrayType::ArraySizeModifier SizeMod
,
7350 const llvm::APInt
*Size
,
7352 unsigned IndexTypeQuals
,
7353 SourceRange BracketsRange
) {
7354 if (SizeExpr
|| !Size
)
7355 return SemaRef
.BuildArrayType(ElementType
, SizeMod
, SizeExpr
,
7356 IndexTypeQuals
, BracketsRange
,
7357 getDerived().getBaseEntity());
7359 QualType Types
[] = {
7360 SemaRef
.Context
.UnsignedCharTy
, SemaRef
.Context
.UnsignedShortTy
,
7361 SemaRef
.Context
.UnsignedIntTy
, SemaRef
.Context
.UnsignedLongTy
,
7362 SemaRef
.Context
.UnsignedLongLongTy
, SemaRef
.Context
.UnsignedInt128Ty
7364 const unsigned NumTypes
= sizeof(Types
) / sizeof(QualType
);
7366 for (unsigned I
= 0; I
!= NumTypes
; ++I
)
7367 if (Size
->getBitWidth() == SemaRef
.Context
.getIntWidth(Types
[I
])) {
7368 SizeType
= Types
[I
];
7372 IntegerLiteral
ArraySize(SemaRef
.Context
, *Size
, SizeType
,
7373 /*FIXME*/BracketsRange
.getBegin());
7374 return SemaRef
.BuildArrayType(ElementType
, SizeMod
, &ArraySize
,
7375 IndexTypeQuals
, BracketsRange
,
7376 getDerived().getBaseEntity());
7379 template<typename Derived
>
7381 TreeTransform
<Derived
>::RebuildConstantArrayType(QualType ElementType
,
7382 ArrayType::ArraySizeModifier SizeMod
,
7383 const llvm::APInt
&Size
,
7384 unsigned IndexTypeQuals
,
7385 SourceRange BracketsRange
) {
7386 return getDerived().RebuildArrayType(ElementType
, SizeMod
, &Size
, 0,
7387 IndexTypeQuals
, BracketsRange
);
7390 template<typename Derived
>
7392 TreeTransform
<Derived
>::RebuildIncompleteArrayType(QualType ElementType
,
7393 ArrayType::ArraySizeModifier SizeMod
,
7394 unsigned IndexTypeQuals
,
7395 SourceRange BracketsRange
) {
7396 return getDerived().RebuildArrayType(ElementType
, SizeMod
, 0, 0,
7397 IndexTypeQuals
, BracketsRange
);
7400 template<typename Derived
>
7402 TreeTransform
<Derived
>::RebuildVariableArrayType(QualType ElementType
,
7403 ArrayType::ArraySizeModifier SizeMod
,
7405 unsigned IndexTypeQuals
,
7406 SourceRange BracketsRange
) {
7407 return getDerived().RebuildArrayType(ElementType
, SizeMod
, 0,
7409 IndexTypeQuals
, BracketsRange
);
7412 template<typename Derived
>
7414 TreeTransform
<Derived
>::RebuildDependentSizedArrayType(QualType ElementType
,
7415 ArrayType::ArraySizeModifier SizeMod
,
7417 unsigned IndexTypeQuals
,
7418 SourceRange BracketsRange
) {
7419 return getDerived().RebuildArrayType(ElementType
, SizeMod
, 0,
7421 IndexTypeQuals
, BracketsRange
);
7424 template<typename Derived
>
7425 QualType TreeTransform
<Derived
>::RebuildVectorType(QualType ElementType
,
7426 unsigned NumElements
,
7427 VectorType::VectorKind VecKind
) {
7428 // FIXME: semantic checking!
7429 return SemaRef
.Context
.getVectorType(ElementType
, NumElements
, VecKind
);
7432 template<typename Derived
>
7433 QualType TreeTransform
<Derived
>::RebuildExtVectorType(QualType ElementType
,
7434 unsigned NumElements
,
7435 SourceLocation AttributeLoc
) {
7436 llvm::APInt
numElements(SemaRef
.Context
.getIntWidth(SemaRef
.Context
.IntTy
),
7438 IntegerLiteral
*VectorSize
7439 = IntegerLiteral::Create(SemaRef
.Context
, numElements
, SemaRef
.Context
.IntTy
,
7441 return SemaRef
.BuildExtVectorType(ElementType
, VectorSize
, AttributeLoc
);
7444 template<typename Derived
>
7446 TreeTransform
<Derived
>::RebuildDependentSizedExtVectorType(QualType ElementType
,
7448 SourceLocation AttributeLoc
) {
7449 return SemaRef
.BuildExtVectorType(ElementType
, SizeExpr
, AttributeLoc
);
7452 template<typename Derived
>
7453 QualType TreeTransform
<Derived
>::RebuildFunctionProtoType(QualType T
,
7454 QualType
*ParamTypes
,
7455 unsigned NumParamTypes
,
7458 RefQualifierKind RefQualifier
,
7459 const FunctionType::ExtInfo
&Info
) {
7460 return SemaRef
.BuildFunctionType(T
, ParamTypes
, NumParamTypes
, Variadic
,
7461 Quals
, RefQualifier
,
7462 getDerived().getBaseLocation(),
7463 getDerived().getBaseEntity(),
7467 template<typename Derived
>
7468 QualType TreeTransform
<Derived
>::RebuildFunctionNoProtoType(QualType T
) {
7469 return SemaRef
.Context
.getFunctionNoProtoType(T
);
7472 template<typename Derived
>
7473 QualType TreeTransform
<Derived
>::RebuildUnresolvedUsingType(Decl
*D
) {
7474 assert(D
&& "no decl found");
7475 if (D
->isInvalidDecl()) return QualType();
7477 // FIXME: Doesn't account for ObjCInterfaceDecl!
7479 if (isa
<UsingDecl
>(D
)) {
7480 UsingDecl
*Using
= cast
<UsingDecl
>(D
);
7481 assert(Using
->isTypeName() &&
7482 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7484 // A valid resolved using typename decl points to exactly one type decl.
7485 assert(++Using
->shadow_begin() == Using
->shadow_end());
7486 Ty
= cast
<TypeDecl
>((*Using
->shadow_begin())->getTargetDecl());
7489 assert(isa
<UnresolvedUsingTypenameDecl
>(D
) &&
7490 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7491 Ty
= cast
<UnresolvedUsingTypenameDecl
>(D
);
7494 return SemaRef
.Context
.getTypeDeclType(Ty
);
7497 template<typename Derived
>
7498 QualType TreeTransform
<Derived
>::RebuildTypeOfExprType(Expr
*E
,
7499 SourceLocation Loc
) {
7500 return SemaRef
.BuildTypeofExprType(E
, Loc
);
7503 template<typename Derived
>
7504 QualType TreeTransform
<Derived
>::RebuildTypeOfType(QualType Underlying
) {
7505 return SemaRef
.Context
.getTypeOfType(Underlying
);
7508 template<typename Derived
>
7509 QualType TreeTransform
<Derived
>::RebuildDecltypeType(Expr
*E
,
7510 SourceLocation Loc
) {
7511 return SemaRef
.BuildDecltypeType(E
, Loc
);
7514 template<typename Derived
>
7515 QualType TreeTransform
<Derived
>::RebuildTemplateSpecializationType(
7516 TemplateName Template
,
7517 SourceLocation TemplateNameLoc
,
7518 const TemplateArgumentListInfo
&TemplateArgs
) {
7519 return SemaRef
.CheckTemplateIdType(Template
, TemplateNameLoc
, TemplateArgs
);
7522 template<typename Derived
>
7523 NestedNameSpecifier
*
7524 TreeTransform
<Derived
>::RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
7527 QualType ObjectType
,
7528 NamedDecl
*FirstQualifierInScope
) {
7530 // FIXME: The source location information is all wrong.
7532 SS
.setScopeRep(Prefix
);
7533 return static_cast<NestedNameSpecifier
*>(
7534 SemaRef
.BuildCXXNestedNameSpecifier(0, SS
, Range
.getEnd(),
7537 FirstQualifierInScope
,
7541 template<typename Derived
>
7542 NestedNameSpecifier
*
7543 TreeTransform
<Derived
>::RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
7545 NamespaceDecl
*NS
) {
7546 return NestedNameSpecifier::Create(SemaRef
.Context
, Prefix
, NS
);
7549 template<typename Derived
>
7550 NestedNameSpecifier
*
7551 TreeTransform
<Derived
>::RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
7555 if (T
->isDependentType() || T
->isRecordType() ||
7556 (SemaRef
.getLangOptions().CPlusPlus0x
&& T
->isEnumeralType())) {
7557 assert(!T
.hasLocalQualifiers() && "Can't get cv-qualifiers here");
7558 return NestedNameSpecifier::Create(SemaRef
.Context
, Prefix
, TemplateKW
,
7562 SemaRef
.Diag(Range
.getBegin(), diag::err_nested_name_spec_non_tag
) << T
;
7566 template<typename Derived
>
7568 TreeTransform
<Derived
>::RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
7570 TemplateDecl
*Template
) {
7571 return SemaRef
.Context
.getQualifiedTemplateName(Qualifier
, TemplateKW
,
7575 template<typename Derived
>
7577 TreeTransform
<Derived
>::RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
7578 SourceRange QualifierRange
,
7579 const IdentifierInfo
&II
,
7580 QualType ObjectType
,
7581 NamedDecl
*FirstQualifierInScope
) {
7583 SS
.setRange(QualifierRange
);
7584 SS
.setScopeRep(Qualifier
);
7586 Name
.setIdentifier(&II
, /*FIXME:*/getDerived().getBaseLocation());
7587 Sema::TemplateTy Template
;
7588 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7589 /*FIXME:*/getDerived().getBaseLocation(),
7592 ParsedType::make(ObjectType
),
7593 /*EnteringContext=*/false,
7595 return Template
.get();
7598 template<typename Derived
>
7600 TreeTransform
<Derived
>::RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
7601 OverloadedOperatorKind Operator
,
7602 QualType ObjectType
) {
7604 SS
.setRange(SourceRange(getDerived().getBaseLocation()));
7605 SS
.setScopeRep(Qualifier
);
7607 SourceLocation SymbolLocations
[3]; // FIXME: Bogus location information.
7608 Name
.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7609 Operator
, SymbolLocations
);
7610 Sema::TemplateTy Template
;
7611 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7612 /*FIXME:*/getDerived().getBaseLocation(),
7615 ParsedType::make(ObjectType
),
7616 /*EnteringContext=*/false,
7618 return Template
.template getAsVal
<TemplateName
>();
7621 template<typename Derived
>
7623 TreeTransform
<Derived
>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op
,
7624 SourceLocation OpLoc
,
7628 Expr
*Callee
= OrigCallee
->IgnoreParenCasts();
7629 bool isPostIncDec
= Second
&& (Op
== OO_PlusPlus
|| Op
== OO_MinusMinus
);
7631 // Determine whether this should be a builtin operation.
7632 if (Op
== OO_Subscript
) {
7633 if (!First
->getType()->isOverloadableType() &&
7634 !Second
->getType()->isOverloadableType())
7635 return getSema().CreateBuiltinArraySubscriptExpr(First
,
7636 Callee
->getLocStart(),
7638 } else if (Op
== OO_Arrow
) {
7639 // -> is never a builtin operation.
7640 return SemaRef
.BuildOverloadedArrowExpr(0, First
, OpLoc
);
7641 } else if (Second
== 0 || isPostIncDec
) {
7642 if (!First
->getType()->isOverloadableType()) {
7643 // The argument is not of overloadable type, so try to create a
7644 // built-in unary operation.
7645 UnaryOperatorKind Opc
7646 = UnaryOperator::getOverloadedOpcode(Op
, isPostIncDec
);
7648 return getSema().CreateBuiltinUnaryOp(OpLoc
, Opc
, First
);
7651 if (!First
->getType()->isOverloadableType() &&
7652 !Second
->getType()->isOverloadableType()) {
7653 // Neither of the arguments is an overloadable type, so try to
7654 // create a built-in binary operation.
7655 BinaryOperatorKind Opc
= BinaryOperator::getOverloadedOpcode(Op
);
7657 = SemaRef
.CreateBuiltinBinOp(OpLoc
, Opc
, First
, Second
);
7658 if (Result
.isInvalid())
7661 return move(Result
);
7665 // Compute the transformed set of functions (and function templates) to be
7666 // used during overload resolution.
7667 UnresolvedSet
<16> Functions
;
7669 if (UnresolvedLookupExpr
*ULE
= dyn_cast
<UnresolvedLookupExpr
>(Callee
)) {
7670 assert(ULE
->requiresADL());
7672 // FIXME: Do we have to check
7673 // IsAcceptableNonMemberOperatorCandidate for each of these?
7674 Functions
.append(ULE
->decls_begin(), ULE
->decls_end());
7676 Functions
.addDecl(cast
<DeclRefExpr
>(Callee
)->getDecl());
7679 // Add any functions found via argument-dependent lookup.
7680 Expr
*Args
[2] = { First
, Second
};
7681 unsigned NumArgs
= 1 + (Second
!= 0);
7683 // Create the overloaded operator invocation for unary operators.
7684 if (NumArgs
== 1 || isPostIncDec
) {
7685 UnaryOperatorKind Opc
7686 = UnaryOperator::getOverloadedOpcode(Op
, isPostIncDec
);
7687 return SemaRef
.CreateOverloadedUnaryOp(OpLoc
, Opc
, Functions
, First
);
7690 if (Op
== OO_Subscript
)
7691 return SemaRef
.CreateOverloadedArraySubscriptExpr(Callee
->getLocStart(),
7696 // Create the overloaded operator invocation for binary operators.
7697 BinaryOperatorKind Opc
= BinaryOperator::getOverloadedOpcode(Op
);
7699 = SemaRef
.CreateOverloadedBinOp(OpLoc
, Opc
, Functions
, Args
[0], Args
[1]);
7700 if (Result
.isInvalid())
7703 return move(Result
);
7706 template<typename Derived
>
7708 TreeTransform
<Derived
>::RebuildCXXPseudoDestructorExpr(Expr
*Base
,
7709 SourceLocation OperatorLoc
,
7711 NestedNameSpecifier
*Qualifier
,
7712 SourceRange QualifierRange
,
7713 TypeSourceInfo
*ScopeType
,
7714 SourceLocation CCLoc
,
7715 SourceLocation TildeLoc
,
7716 PseudoDestructorTypeStorage Destroyed
) {
7719 SS
.setRange(QualifierRange
);
7720 SS
.setScopeRep(Qualifier
);
7723 QualType BaseType
= Base
->getType();
7724 if (Base
->isTypeDependent() || Destroyed
.getIdentifier() ||
7725 (!isArrow
&& !BaseType
->getAs
<RecordType
>()) ||
7726 (isArrow
&& BaseType
->getAs
<PointerType
>() &&
7727 !BaseType
->getAs
<PointerType
>()->getPointeeType()
7728 ->template getAs
<RecordType
>())){
7729 // This pseudo-destructor expression is still a pseudo-destructor.
7730 return SemaRef
.BuildPseudoDestructorExpr(Base
, OperatorLoc
,
7731 isArrow
? tok::arrow
: tok::period
,
7732 SS
, ScopeType
, CCLoc
, TildeLoc
,
7737 TypeSourceInfo
*DestroyedType
= Destroyed
.getTypeSourceInfo();
7738 DeclarationName
Name(SemaRef
.Context
.DeclarationNames
.getCXXDestructorName(
7739 SemaRef
.Context
.getCanonicalType(DestroyedType
->getType())));
7740 DeclarationNameInfo
NameInfo(Name
, Destroyed
.getLocation());
7741 NameInfo
.setNamedTypeInfo(DestroyedType
);
7743 // FIXME: the ScopeType should be tacked onto SS.
7745 return getSema().BuildMemberReferenceExpr(Base
, BaseType
,
7746 OperatorLoc
, isArrow
,
7747 SS
, /*FIXME: FirstQualifier*/ 0,
7749 /*TemplateArgs*/ 0);
7752 } // end namespace clang
7754 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H