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 //===----------------------------------------------------------------------===/
13 #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14 #define LLVM_CLANG_SEMA_TREETRANSFORM_H
16 #include "clang/Sema/SemaInternal.h"
17 #include "clang/Sema/Lookup.h"
18 #include "clang/Sema/SemaDiagnostic.h"
19 #include "clang/Sema/ScopeInfo.h"
20 #include "clang/AST/Decl.h"
21 #include "clang/AST/DeclObjC.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/ExprCXX.h"
24 #include "clang/AST/ExprObjC.h"
25 #include "clang/AST/Stmt.h"
26 #include "clang/AST/StmtCXX.h"
27 #include "clang/AST/StmtObjC.h"
28 #include "clang/Sema/Ownership.h"
29 #include "clang/Sema/Designator.h"
30 #include "clang/Lex/Preprocessor.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "TypeLocBuilder.h"
38 /// \brief A semantic tree transformation that allows one to transform one
39 /// abstract syntax tree into another.
41 /// A new tree transformation is defined by creating a new subclass \c X of
42 /// \c TreeTransform<X> and then overriding certain operations to provide
43 /// behavior specific to that transformation. For example, template
44 /// instantiation is implemented as a tree transformation where the
45 /// transformation of TemplateTypeParmType nodes involves substituting the
46 /// template arguments for their corresponding template parameters; a similar
47 /// transformation is performed for non-type template parameters and
48 /// template template parameters.
50 /// This tree-transformation template uses static polymorphism to allow
51 /// subclasses to customize any of its operations. Thus, a subclass can
52 /// override any of the transformation or rebuild operators by providing an
53 /// operation with the same signature as the default implementation. The
54 /// overridding function should not be virtual.
56 /// Semantic tree transformations are split into two stages, either of which
57 /// can be replaced by a subclass. The "transform" step transforms an AST node
58 /// or the parts of an AST node using the various transformation functions,
59 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
60 /// node of the appropriate kind from the pieces. The default transformation
61 /// routines recursively transform the operands to composite AST nodes (e.g.,
62 /// the pointee type of a PointerType node) and, if any of those operand nodes
63 /// were changed by the transformation, invokes the rebuild operation to create
66 /// Subclasses can customize the transformation at various levels. The
67 /// most coarse-grained transformations involve replacing TransformType(),
68 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
70 /// new implementations.
72 /// For more fine-grained transformations, subclasses can replace any of the
73 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
74 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
75 /// replacing TransformTemplateTypeParmType() allows template instantiation
76 /// to substitute template arguments for their corresponding template
77 /// parameters. Additionally, subclasses can override the \c RebuildXXX
78 /// functions to control how AST nodes are rebuilt when their operands change.
79 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
80 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
81 /// be able to use more efficient rebuild steps.
83 /// There are a handful of other functions that can be overridden, allowing one
84 /// to avoid traversing nodes that don't need any transformation
85 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86 /// operands have not changed (\c AlwaysRebuild()), and customize the
87 /// default locations and entity names used for type-checking
88 /// (\c getBaseLocation(), \c getBaseEntity()).
89 template<typename Derived
>
95 /// \brief Initializes a new tree transformer.
96 TreeTransform(Sema
&SemaRef
) : SemaRef(SemaRef
) { }
98 /// \brief Retrieves a reference to the derived class.
99 Derived
&getDerived() { return static_cast<Derived
&>(*this); }
101 /// \brief Retrieves a reference to the derived class.
102 const Derived
&getDerived() const {
103 return static_cast<const Derived
&>(*this);
106 static inline ExprResult
Owned(Expr
*E
) { return E
; }
107 static inline StmtResult
Owned(Stmt
*S
) { return S
; }
109 /// \brief Retrieves a reference to the semantic analysis object used for
110 /// this tree transform.
111 Sema
&getSema() const { return SemaRef
; }
113 /// \brief Whether the transformation should always rebuild AST nodes, even
114 /// if none of the children have changed.
116 /// Subclasses may override this function to specify when the transformation
117 /// should rebuild all AST nodes.
118 bool AlwaysRebuild() { return false; }
120 /// \brief Returns the location of the entity being transformed, if that
121 /// information was not available elsewhere in the AST.
123 /// By default, returns no source-location information. Subclasses can
124 /// provide an alternative implementation that provides better location
126 SourceLocation
getBaseLocation() { return SourceLocation(); }
128 /// \brief Returns the name of the entity being transformed, if that
129 /// information was not available elsewhere in the AST.
131 /// By default, returns an empty name. Subclasses can provide an alternative
132 /// implementation with a more precise name.
133 DeclarationName
getBaseEntity() { return DeclarationName(); }
135 /// \brief Sets the "base" location and entity when that
136 /// information is known based on another transformation.
138 /// By default, the source location and entity are ignored. Subclasses can
139 /// override this function to provide a customized implementation.
140 void setBase(SourceLocation Loc
, DeclarationName Entity
) { }
142 /// \brief RAII object that temporarily sets the base location and entity
143 /// used for reporting diagnostics in types.
144 class TemporaryBase
{
146 SourceLocation OldLocation
;
147 DeclarationName OldEntity
;
150 TemporaryBase(TreeTransform
&Self
, SourceLocation Location
,
151 DeclarationName Entity
) : Self(Self
) {
152 OldLocation
= Self
.getDerived().getBaseLocation();
153 OldEntity
= Self
.getDerived().getBaseEntity();
154 Self
.getDerived().setBase(Location
, Entity
);
158 Self
.getDerived().setBase(OldLocation
, OldEntity
);
162 /// \brief Determine whether the given type \p T has already been
165 /// Subclasses can provide an alternative implementation of this routine
166 /// to short-circuit evaluation when it is known that a given type will
167 /// not change. For example, template instantiation need not traverse
168 /// non-dependent types.
169 bool AlreadyTransformed(QualType T
) {
173 /// \brief Determine whether the given call argument should be dropped, e.g.,
174 /// because it is a default argument.
176 /// Subclasses can provide an alternative implementation of this routine to
177 /// determine which kinds of call arguments get dropped. By default,
178 /// CXXDefaultArgument nodes are dropped (prior to transformation).
179 bool DropCallArgument(Expr
*E
) {
180 return E
->isDefaultArgument();
183 /// \brief Transforms the given type into another type.
185 /// By default, this routine transforms a type by creating a
186 /// TypeSourceInfo for it and delegating to the appropriate
187 /// function. This is expensive, but we don't mind, because
188 /// this method is deprecated anyway; all users should be
189 /// switched to storing TypeSourceInfos.
191 /// \returns the transformed type.
192 QualType
TransformType(QualType T
);
194 /// \brief Transforms the given type-with-location into a new
195 /// type-with-location.
197 /// By default, this routine transforms a type by delegating to the
198 /// appropriate TransformXXXType to build a new type. Subclasses
199 /// may override this function (to take over all type
200 /// transformations) or some set of the TransformXXXType functions
201 /// to alter the transformation.
202 TypeSourceInfo
*TransformType(TypeSourceInfo
*DI
);
204 /// \brief Transform the given type-with-location into a new
205 /// type, collecting location information in the given builder
208 QualType
TransformType(TypeLocBuilder
&TLB
, TypeLoc TL
);
210 /// \brief Transform the given statement.
212 /// By default, this routine transforms a statement by delegating to the
213 /// appropriate TransformXXXStmt function to transform a specific kind of
214 /// statement or the TransformExpr() function to transform an expression.
215 /// Subclasses may override this function to transform statements using some
218 /// \returns the transformed statement.
219 StmtResult
TransformStmt(Stmt
*S
);
221 /// \brief Transform the given expression.
223 /// By default, this routine transforms an expression by delegating to the
224 /// appropriate TransformXXXExpr function to build a new expression.
225 /// Subclasses may override this function to transform expressions using some
228 /// \returns the transformed expression.
229 ExprResult
TransformExpr(Expr
*E
);
231 /// \brief Transform the given declaration, which is referenced from a type
234 /// By default, acts as the identity function on declarations. Subclasses
235 /// may override this function to provide alternate behavior.
236 Decl
*TransformDecl(SourceLocation Loc
, Decl
*D
) { return D
; }
238 /// \brief Transform the definition of the given declaration.
240 /// By default, invokes TransformDecl() to transform the declaration.
241 /// Subclasses may override this function to provide alternate behavior.
242 Decl
*TransformDefinition(SourceLocation Loc
, Decl
*D
) {
243 return getDerived().TransformDecl(Loc
, D
);
246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
249 /// This specific declaration transformation only applies to the first
250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
255 NamedDecl
*TransformFirstQualifierInScope(NamedDecl
*D
, SourceLocation Loc
) {
256 return cast_or_null
<NamedDecl
>(getDerived().TransformDecl(Loc
, D
));
259 /// \brief Transform the given nested-name-specifier.
261 /// By default, transforms all of the types and declarations within the
262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
264 NestedNameSpecifier
*TransformNestedNameSpecifier(NestedNameSpecifier
*NNS
,
266 QualType ObjectType
= QualType(),
267 NamedDecl
*FirstQualifierInScope
= 0);
269 /// \brief Transform the given declaration name.
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
276 TransformDeclarationNameInfo(const DeclarationNameInfo
&NameInfo
);
278 /// \brief Transform the given template name.
280 /// By default, transforms the template name by transforming the declarations
281 /// and nested-name-specifiers that occur within the template name.
282 /// Subclasses may override this function to provide alternate behavior.
283 TemplateName
TransformTemplateName(TemplateName Name
,
284 QualType ObjectType
= QualType(),
285 NamedDecl
*FirstQualifierInScope
= 0);
287 /// \brief Transform the given template argument.
289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc
&Input
,
296 TemplateArgumentLoc
&Output
);
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument
&Arg
,
300 TemplateArgumentLoc
&ArgLoc
);
302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo
*InventTypeSourceInfo(QualType T
) {
304 return SemaRef
.Context
.getTrivialTypeSourceInfo(T
,
305 getDerived().getBaseLocation());
308 #define ABSTRACT_TYPELOC(CLASS, PARENT)
309 #define TYPELOC(CLASS, PARENT) \
310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
311 #include "clang/AST/TypeLocNodes.def"
314 TransformTemplateSpecializationType(TypeLocBuilder
&TLB
,
315 TemplateSpecializationTypeLoc TL
,
316 TemplateName Template
);
319 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
320 DependentTemplateSpecializationTypeLoc TL
,
321 NestedNameSpecifier
*Prefix
);
323 /// \brief Transforms the parameters of a function type into the
326 /// The result vectors should be kept in sync; null entries in the
327 /// variables vector are acceptable.
329 /// Return true on error.
330 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL
,
331 llvm::SmallVectorImpl
<QualType
> &PTypes
,
332 llvm::SmallVectorImpl
<ParmVarDecl
*> &PVars
);
334 /// \brief Transforms a single function-type parameter. Return null
336 ParmVarDecl
*TransformFunctionTypeParam(ParmVarDecl
*OldParm
);
338 QualType
TransformReferenceType(TypeLocBuilder
&TLB
, ReferenceTypeLoc TL
);
340 StmtResult
TransformCompoundStmt(CompoundStmt
*S
, bool IsStmtExpr
);
341 ExprResult
TransformCXXNamedCastExpr(CXXNamedCastExpr
*E
);
343 #define STMT(Node, Parent) \
344 StmtResult Transform##Node(Node *S);
345 #define EXPR(Node, Parent) \
346 ExprResult Transform##Node(Node *E);
347 #define ABSTRACT_STMT(Stmt)
348 #include "clang/AST/StmtNodes.inc"
350 /// \brief Build a new pointer type given its pointee type.
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
354 QualType
RebuildPointerType(QualType PointeeType
, SourceLocation Sigil
);
356 /// \brief Build a new block pointer type given its pointee type.
358 /// By default, performs semantic analysis when building the block pointer
359 /// type. Subclasses may override this routine to provide different behavior.
360 QualType
RebuildBlockPointerType(QualType PointeeType
, SourceLocation Sigil
);
362 /// \brief Build a new reference type given the type it references.
364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType
RebuildReferenceType(QualType ReferentType
,
372 SourceLocation Sigil
);
374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
379 QualType
RebuildMemberPointerType(QualType PointeeType
, QualType ClassType
,
380 SourceLocation Sigil
);
382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
388 /// Also by default, all of the other Rebuild*Array
389 QualType
RebuildArrayType(QualType ElementType
,
390 ArrayType::ArraySizeModifier SizeMod
,
391 const llvm::APInt
*Size
,
393 unsigned IndexTypeQuals
,
394 SourceRange BracketsRange
);
396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
401 QualType
RebuildConstantArrayType(QualType ElementType
,
402 ArrayType::ArraySizeModifier SizeMod
,
403 const llvm::APInt
&Size
,
404 unsigned IndexTypeQuals
,
405 SourceRange BracketsRange
);
407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
412 QualType
RebuildIncompleteArrayType(QualType ElementType
,
413 ArrayType::ArraySizeModifier SizeMod
,
414 unsigned IndexTypeQuals
,
415 SourceRange BracketsRange
);
417 /// \brief Build a new variable-length array type given the element type,
418 /// size modifier, size expression, and index type qualifiers.
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
422 QualType
RebuildVariableArrayType(QualType ElementType
,
423 ArrayType::ArraySizeModifier SizeMod
,
425 unsigned IndexTypeQuals
,
426 SourceRange BracketsRange
);
428 /// \brief Build a new dependent-sized array type given the element type,
429 /// size modifier, size expression, and index type qualifiers.
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
433 QualType
RebuildDependentSizedArrayType(QualType ElementType
,
434 ArrayType::ArraySizeModifier SizeMod
,
436 unsigned IndexTypeQuals
,
437 SourceRange BracketsRange
);
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
444 QualType
RebuildVectorType(QualType ElementType
, unsigned NumElements
,
445 VectorType::VectorKind VecKind
);
447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType
RebuildExtVectorType(QualType ElementType
, unsigned NumElements
,
453 SourceLocation AttributeLoc
);
455 /// \brief Build a new potentially dependently-sized extended vector type
456 /// given the element type and number of elements.
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
460 QualType
RebuildDependentSizedExtVectorType(QualType ElementType
,
462 SourceLocation AttributeLoc
);
464 /// \brief Build a new function type.
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType
RebuildFunctionProtoType(QualType T
,
469 QualType
*ParamTypes
,
470 unsigned NumParamTypes
,
471 bool Variadic
, unsigned Quals
,
472 const FunctionType::ExtInfo
&Info
);
474 /// \brief Build a new unprototyped function type.
475 QualType
RebuildFunctionNoProtoType(QualType ResultType
);
477 /// \brief Rebuild an unresolved typename type, given the decl that
478 /// the UnresolvedUsingTypenameDecl was transformed to.
479 QualType
RebuildUnresolvedUsingType(Decl
*D
);
481 /// \brief Build a new typedef type.
482 QualType
RebuildTypedefType(TypedefDecl
*Typedef
) {
483 return SemaRef
.Context
.getTypeDeclType(Typedef
);
486 /// \brief Build a new class/struct/union type.
487 QualType
RebuildRecordType(RecordDecl
*Record
) {
488 return SemaRef
.Context
.getTypeDeclType(Record
);
491 /// \brief Build a new Enum type.
492 QualType
RebuildEnumType(EnumDecl
*Enum
) {
493 return SemaRef
.Context
.getTypeDeclType(Enum
);
496 /// \brief Build a new typeof(expr) type.
498 /// By default, performs semantic analysis when building the typeof type.
499 /// Subclasses may override this routine to provide different behavior.
500 QualType
RebuildTypeOfExprType(Expr
*Underlying
, SourceLocation Loc
);
502 /// \brief Build a new typeof(type) type.
504 /// By default, builds a new TypeOfType with the given underlying type.
505 QualType
RebuildTypeOfType(QualType Underlying
);
507 /// \brief Build a new C++0x decltype type.
509 /// By default, performs semantic analysis when building the decltype type.
510 /// Subclasses may override this routine to provide different behavior.
511 QualType
RebuildDecltypeType(Expr
*Underlying
, SourceLocation Loc
);
513 /// \brief Build a new template specialization type.
515 /// By default, performs semantic analysis when building the template
516 /// specialization type. Subclasses may override this routine to provide
517 /// different behavior.
518 QualType
RebuildTemplateSpecializationType(TemplateName Template
,
519 SourceLocation TemplateLoc
,
520 const TemplateArgumentListInfo
&Args
);
522 /// \brief Build a new parenthesized type.
524 /// By default, builds a new ParenType type from the inner type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType
RebuildParenType(QualType InnerType
) {
527 return SemaRef
.Context
.getParenType(InnerType
);
530 /// \brief Build a new qualified name type.
532 /// By default, builds a new ElaboratedType type from the keyword,
533 /// the nested-name-specifier and the named type.
534 /// Subclasses may override this routine to provide different behavior.
535 QualType
RebuildElaboratedType(SourceLocation KeywordLoc
,
536 ElaboratedTypeKeyword Keyword
,
537 NestedNameSpecifier
*NNS
, QualType Named
) {
538 return SemaRef
.Context
.getElaboratedType(Keyword
, NNS
, Named
);
541 /// \brief Build a new typename type that refers to a template-id.
543 /// By default, builds a new DependentNameType type from the
544 /// nested-name-specifier and the given type. Subclasses may override
545 /// this routine to provide different behavior.
546 QualType
RebuildDependentTemplateSpecializationType(
547 ElaboratedTypeKeyword Keyword
,
548 NestedNameSpecifier
*Qualifier
,
549 SourceRange QualifierRange
,
550 const IdentifierInfo
*Name
,
551 SourceLocation NameLoc
,
552 const TemplateArgumentListInfo
&Args
) {
553 // Rebuild the template name.
554 // TODO: avoid TemplateName abstraction
555 TemplateName InstName
=
556 getDerived().RebuildTemplateName(Qualifier
, QualifierRange
, *Name
,
559 if (InstName
.isNull())
562 // If it's still dependent, make a dependent specialization.
563 if (InstName
.getAsDependentTemplateName())
564 return SemaRef
.Context
.getDependentTemplateSpecializationType(
565 Keyword
, Qualifier
, Name
, Args
);
567 // Otherwise, make an elaborated type wrapping a non-dependent
570 getDerived().RebuildTemplateSpecializationType(InstName
, NameLoc
, Args
);
571 if (T
.isNull()) return QualType();
573 // NOTE: NNS is already recorded in template specialization type T.
574 return SemaRef
.Context
.getElaboratedType(Keyword
, /*NNS=*/0, T
);
577 /// \brief Build a new typename type that refers to an identifier.
579 /// By default, performs semantic analysis when building the typename type
580 /// (or elaborated type). Subclasses may override this routine to provide
581 /// different behavior.
582 QualType
RebuildDependentNameType(ElaboratedTypeKeyword Keyword
,
583 NestedNameSpecifier
*NNS
,
584 const IdentifierInfo
*Id
,
585 SourceLocation KeywordLoc
,
586 SourceRange NNSRange
,
587 SourceLocation IdLoc
) {
590 SS
.setRange(NNSRange
);
592 if (NNS
->isDependent()) {
593 // If the name is still dependent, just build a new dependent name type.
594 if (!SemaRef
.computeDeclContext(SS
))
595 return SemaRef
.Context
.getDependentNameType(Keyword
, NNS
, Id
);
598 if (Keyword
== ETK_None
|| Keyword
== ETK_Typename
)
599 return SemaRef
.CheckTypenameType(Keyword
, NNS
, *Id
,
600 KeywordLoc
, NNSRange
, IdLoc
);
602 TagTypeKind Kind
= TypeWithKeyword::getTagTypeKindForKeyword(Keyword
);
604 // We had a dependent elaborated-type-specifier that has been transformed
605 // into a non-dependent elaborated-type-specifier. Find the tag we're
607 LookupResult
Result(SemaRef
, Id
, IdLoc
, Sema::LookupTagName
);
608 DeclContext
*DC
= SemaRef
.computeDeclContext(SS
, false);
612 if (SemaRef
.RequireCompleteDeclContext(SS
, DC
))
616 SemaRef
.LookupQualifiedName(Result
, DC
);
617 switch (Result
.getResultKind()) {
618 case LookupResult::NotFound
:
619 case LookupResult::NotFoundInCurrentInstantiation
:
622 case LookupResult::Found
:
623 Tag
= Result
.getAsSingle
<TagDecl
>();
626 case LookupResult::FoundOverloaded
:
627 case LookupResult::FoundUnresolvedValue
:
628 llvm_unreachable("Tag lookup cannot find non-tags");
631 case LookupResult::Ambiguous
:
632 // Let the LookupResult structure handle ambiguities.
637 // FIXME: Would be nice to highlight just the source range.
638 SemaRef
.Diag(IdLoc
, diag::err_not_tag_in_scope
)
643 if (!SemaRef
.isAcceptableTagRedeclaration(Tag
, Kind
, IdLoc
, *Id
)) {
644 SemaRef
.Diag(KeywordLoc
, diag::err_use_with_wrong_tag
) << Id
;
645 SemaRef
.Diag(Tag
->getLocation(), diag::note_previous_use
);
649 // Build the elaborated-type-specifier type.
650 QualType T
= SemaRef
.Context
.getTypeDeclType(Tag
);
651 return SemaRef
.Context
.getElaboratedType(Keyword
, NNS
, T
);
654 /// \brief Build a new nested-name-specifier given the prefix and an
655 /// identifier that names the next step in the nested-name-specifier.
657 /// By default, performs semantic analysis when building the new
658 /// nested-name-specifier. Subclasses may override this routine to provide
659 /// different behavior.
660 NestedNameSpecifier
*RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
664 NamedDecl
*FirstQualifierInScope
);
666 /// \brief Build a new nested-name-specifier given the prefix and the
667 /// namespace named in the next step in the nested-name-specifier.
669 /// By default, performs semantic analysis when building the new
670 /// nested-name-specifier. Subclasses may override this routine to provide
671 /// different behavior.
672 NestedNameSpecifier
*RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
676 /// \brief Build a new nested-name-specifier given the prefix and the
677 /// type named in the next step in the nested-name-specifier.
679 /// By default, performs semantic analysis when building the new
680 /// nested-name-specifier. Subclasses may override this routine to provide
681 /// different behavior.
682 NestedNameSpecifier
*RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
687 /// \brief Build a new template name given a nested name specifier, a flag
688 /// indicating whether the "template" keyword was provided, and the template
689 /// that the template name refers to.
691 /// By default, builds the new template name directly. Subclasses may override
692 /// this routine to provide different behavior.
693 TemplateName
RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
695 TemplateDecl
*Template
);
697 /// \brief Build a new template name given a nested name specifier and the
698 /// name that is referred to as a template.
700 /// By default, performs semantic analysis to determine whether the name can
701 /// be resolved to a specific template, then builds the appropriate kind of
702 /// template name. Subclasses may override this routine to provide different
704 TemplateName
RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
705 SourceRange QualifierRange
,
706 const IdentifierInfo
&II
,
708 NamedDecl
*FirstQualifierInScope
);
710 /// \brief Build a new template name given a nested name specifier and the
711 /// overloaded operator name that is referred to as a template.
713 /// By default, performs semantic analysis to determine whether the name can
714 /// be resolved to a specific template, then builds the appropriate kind of
715 /// template name. Subclasses may override this routine to provide different
717 TemplateName
RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
718 OverloadedOperatorKind Operator
,
719 QualType ObjectType
);
721 /// \brief Build a new compound statement.
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
725 StmtResult
RebuildCompoundStmt(SourceLocation LBraceLoc
,
726 MultiStmtArg Statements
,
727 SourceLocation RBraceLoc
,
729 return getSema().ActOnCompoundStmt(LBraceLoc
, RBraceLoc
, Statements
,
733 /// \brief Build a new case statement.
735 /// By default, performs semantic analysis to build the new statement.
736 /// Subclasses may override this routine to provide different behavior.
737 StmtResult
RebuildCaseStmt(SourceLocation CaseLoc
,
739 SourceLocation EllipsisLoc
,
741 SourceLocation ColonLoc
) {
742 return getSema().ActOnCaseStmt(CaseLoc
, LHS
, EllipsisLoc
, RHS
,
746 /// \brief Attach the body to a new case statement.
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
750 StmtResult
RebuildCaseStmtBody(Stmt
*S
, Stmt
*Body
) {
751 getSema().ActOnCaseStmtBody(S
, Body
);
755 /// \brief Build a new default statement.
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
759 StmtResult
RebuildDefaultStmt(SourceLocation DefaultLoc
,
760 SourceLocation ColonLoc
,
762 return getSema().ActOnDefaultStmt(DefaultLoc
, ColonLoc
, SubStmt
,
766 /// \brief Build a new label statement.
768 /// By default, performs semantic analysis to build the new statement.
769 /// Subclasses may override this routine to provide different behavior.
770 StmtResult
RebuildLabelStmt(SourceLocation IdentLoc
,
772 SourceLocation ColonLoc
,
773 Stmt
*SubStmt
, bool HasUnusedAttr
) {
774 return SemaRef
.ActOnLabelStmt(IdentLoc
, Id
, ColonLoc
, SubStmt
,
778 /// \brief Build a new "if" statement.
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
782 StmtResult
RebuildIfStmt(SourceLocation IfLoc
, Sema::FullExprArg Cond
,
783 VarDecl
*CondVar
, Stmt
*Then
,
784 SourceLocation ElseLoc
, Stmt
*Else
) {
785 return getSema().ActOnIfStmt(IfLoc
, Cond
, CondVar
, Then
, ElseLoc
, Else
);
788 /// \brief Start building a new switch statement.
790 /// By default, performs semantic analysis to build the new statement.
791 /// Subclasses may override this routine to provide different behavior.
792 StmtResult
RebuildSwitchStmtStart(SourceLocation SwitchLoc
,
793 Expr
*Cond
, VarDecl
*CondVar
) {
794 return getSema().ActOnStartOfSwitchStmt(SwitchLoc
, Cond
,
798 /// \brief Attach the body to the switch statement.
800 /// By default, performs semantic analysis to build the new statement.
801 /// Subclasses may override this routine to provide different behavior.
802 StmtResult
RebuildSwitchStmtBody(SourceLocation SwitchLoc
,
803 Stmt
*Switch
, Stmt
*Body
) {
804 return getSema().ActOnFinishSwitchStmt(SwitchLoc
, Switch
, Body
);
807 /// \brief Build a new while statement.
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
811 StmtResult
RebuildWhileStmt(SourceLocation WhileLoc
,
812 Sema::FullExprArg Cond
,
815 return getSema().ActOnWhileStmt(WhileLoc
, Cond
, CondVar
, Body
);
818 /// \brief Build a new do-while statement.
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
822 StmtResult
RebuildDoStmt(SourceLocation DoLoc
, Stmt
*Body
,
823 SourceLocation WhileLoc
,
824 SourceLocation LParenLoc
,
826 SourceLocation RParenLoc
) {
827 return getSema().ActOnDoStmt(DoLoc
, Body
, WhileLoc
, LParenLoc
,
831 /// \brief Build a new for statement.
833 /// By default, performs semantic analysis to build the new statement.
834 /// Subclasses may override this routine to provide different behavior.
835 StmtResult
RebuildForStmt(SourceLocation ForLoc
,
836 SourceLocation LParenLoc
,
837 Stmt
*Init
, Sema::FullExprArg Cond
,
838 VarDecl
*CondVar
, Sema::FullExprArg Inc
,
839 SourceLocation RParenLoc
, Stmt
*Body
) {
840 return getSema().ActOnForStmt(ForLoc
, LParenLoc
, Init
, Cond
,
842 Inc
, RParenLoc
, Body
);
845 /// \brief Build a new goto statement.
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
849 StmtResult
RebuildGotoStmt(SourceLocation GotoLoc
,
850 SourceLocation LabelLoc
,
852 return getSema().ActOnGotoStmt(GotoLoc
, LabelLoc
, Label
->getID());
855 /// \brief Build a new indirect goto statement.
857 /// By default, performs semantic analysis to build the new statement.
858 /// Subclasses may override this routine to provide different behavior.
859 StmtResult
RebuildIndirectGotoStmt(SourceLocation GotoLoc
,
860 SourceLocation StarLoc
,
862 return getSema().ActOnIndirectGotoStmt(GotoLoc
, StarLoc
, Target
);
865 /// \brief Build a new return statement.
867 /// By default, performs semantic analysis to build the new statement.
868 /// Subclasses may override this routine to provide different behavior.
869 StmtResult
RebuildReturnStmt(SourceLocation ReturnLoc
,
872 return getSema().ActOnReturnStmt(ReturnLoc
, Result
);
875 /// \brief Build a new declaration statement.
877 /// By default, performs semantic analysis to build the new statement.
878 /// Subclasses may override this routine to provide different behavior.
879 StmtResult
RebuildDeclStmt(Decl
**Decls
, unsigned NumDecls
,
880 SourceLocation StartLoc
,
881 SourceLocation EndLoc
) {
882 return getSema().Owned(
883 new (getSema().Context
) DeclStmt(
884 DeclGroupRef::Create(getSema().Context
,
889 /// \brief Build a new inline asm statement.
891 /// By default, performs semantic analysis to build the new statement.
892 /// Subclasses may override this routine to provide different behavior.
893 StmtResult
RebuildAsmStmt(SourceLocation AsmLoc
,
898 IdentifierInfo
**Names
,
899 MultiExprArg Constraints
,
902 MultiExprArg Clobbers
,
903 SourceLocation RParenLoc
,
905 return getSema().ActOnAsmStmt(AsmLoc
, IsSimple
, IsVolatile
, NumOutputs
,
906 NumInputs
, Names
, move(Constraints
),
907 Exprs
, AsmString
, Clobbers
,
911 /// \brief Build a new Objective-C @try statement.
913 /// By default, performs semantic analysis to build the new statement.
914 /// Subclasses may override this routine to provide different behavior.
915 StmtResult
RebuildObjCAtTryStmt(SourceLocation AtLoc
,
917 MultiStmtArg CatchStmts
,
919 return getSema().ActOnObjCAtTryStmt(AtLoc
, TryBody
, move(CatchStmts
),
923 /// \brief Rebuild an Objective-C exception declaration.
925 /// By default, performs semantic analysis to build the new declaration.
926 /// Subclasses may override this routine to provide different behavior.
927 VarDecl
*RebuildObjCExceptionDecl(VarDecl
*ExceptionDecl
,
928 TypeSourceInfo
*TInfo
, QualType T
) {
929 return getSema().BuildObjCExceptionDecl(TInfo
, T
,
930 ExceptionDecl
->getIdentifier(),
931 ExceptionDecl
->getLocation());
934 /// \brief Build a new Objective-C @catch statement.
936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
938 StmtResult
RebuildObjCAtCatchStmt(SourceLocation AtLoc
,
939 SourceLocation RParenLoc
,
942 return getSema().ActOnObjCAtCatchStmt(AtLoc
, RParenLoc
,
946 /// \brief Build a new Objective-C @finally statement.
948 /// By default, performs semantic analysis to build the new statement.
949 /// Subclasses may override this routine to provide different behavior.
950 StmtResult
RebuildObjCAtFinallyStmt(SourceLocation AtLoc
,
952 return getSema().ActOnObjCAtFinallyStmt(AtLoc
, Body
);
955 /// \brief Build a new Objective-C @throw statement.
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
959 StmtResult
RebuildObjCAtThrowStmt(SourceLocation AtLoc
,
961 return getSema().BuildObjCAtThrowStmt(AtLoc
, Operand
);
964 /// \brief Build a new Objective-C @synchronized statement.
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
968 StmtResult
RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc
,
971 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc
, Object
,
975 /// \brief Build a new Objective-C fast enumeration statement.
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
979 StmtResult
RebuildObjCForCollectionStmt(SourceLocation ForLoc
,
980 SourceLocation LParenLoc
,
983 SourceLocation RParenLoc
,
985 return getSema().ActOnObjCForCollectionStmt(ForLoc
, LParenLoc
,
992 /// \brief Build a new C++ exception declaration.
994 /// By default, performs semantic analysis to build the new decaration.
995 /// Subclasses may override this routine to provide different behavior.
996 VarDecl
*RebuildExceptionDecl(VarDecl
*ExceptionDecl
,
997 TypeSourceInfo
*Declarator
,
998 IdentifierInfo
*Name
,
999 SourceLocation Loc
) {
1000 return getSema().BuildExceptionDeclaration(0, Declarator
, Name
, Loc
);
1003 /// \brief Build a new C++ catch statement.
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
1007 StmtResult
RebuildCXXCatchStmt(SourceLocation CatchLoc
,
1008 VarDecl
*ExceptionDecl
,
1010 return Owned(new (getSema().Context
) CXXCatchStmt(CatchLoc
, ExceptionDecl
,
1014 /// \brief Build a new C++ try statement.
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
1018 StmtResult
RebuildCXXTryStmt(SourceLocation TryLoc
,
1020 MultiStmtArg Handlers
) {
1021 return getSema().ActOnCXXTryBlock(TryLoc
, TryBlock
, move(Handlers
));
1024 /// \brief Build a new expression that references a declaration.
1026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
1028 ExprResult
RebuildDeclarationNameExpr(const CXXScopeSpec
&SS
,
1031 return getSema().BuildDeclarationNameExpr(SS
, R
, RequiresADL
);
1035 /// \brief Build a new expression that references a declaration.
1037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
1039 ExprResult
RebuildDeclRefExpr(NestedNameSpecifier
*Qualifier
,
1040 SourceRange QualifierRange
,
1042 const DeclarationNameInfo
&NameInfo
,
1043 TemplateArgumentListInfo
*TemplateArgs
) {
1045 SS
.setScopeRep(Qualifier
);
1046 SS
.setRange(QualifierRange
);
1048 // FIXME: loses template args.
1050 return getSema().BuildDeclarationNameExpr(SS
, NameInfo
, VD
);
1053 /// \brief Build a new expression in parentheses.
1055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
1057 ExprResult
RebuildParenExpr(Expr
*SubExpr
, SourceLocation LParen
,
1058 SourceLocation RParen
) {
1059 return getSema().ActOnParenExpr(LParen
, RParen
, SubExpr
);
1062 /// \brief Build a new pseudo-destructor expression.
1064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
1066 ExprResult
RebuildCXXPseudoDestructorExpr(Expr
*Base
,
1067 SourceLocation OperatorLoc
,
1069 NestedNameSpecifier
*Qualifier
,
1070 SourceRange QualifierRange
,
1071 TypeSourceInfo
*ScopeType
,
1072 SourceLocation CCLoc
,
1073 SourceLocation TildeLoc
,
1074 PseudoDestructorTypeStorage Destroyed
);
1076 /// \brief Build a new unary operator expression.
1078 /// By default, performs semantic analysis to build the new expression.
1079 /// Subclasses may override this routine to provide different behavior.
1080 ExprResult
RebuildUnaryOperator(SourceLocation OpLoc
,
1081 UnaryOperatorKind Opc
,
1083 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc
, Opc
, SubExpr
);
1086 /// \brief Build a new builtin offsetof expression.
1088 /// By default, performs semantic analysis to build the new expression.
1089 /// Subclasses may override this routine to provide different behavior.
1090 ExprResult
RebuildOffsetOfExpr(SourceLocation OperatorLoc
,
1091 TypeSourceInfo
*Type
,
1092 Sema::OffsetOfComponent
*Components
,
1093 unsigned NumComponents
,
1094 SourceLocation RParenLoc
) {
1095 return getSema().BuildBuiltinOffsetOf(OperatorLoc
, Type
, Components
,
1096 NumComponents
, RParenLoc
);
1099 /// \brief Build a new sizeof or alignof expression with a type argument.
1101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
1103 ExprResult
RebuildSizeOfAlignOf(TypeSourceInfo
*TInfo
,
1104 SourceLocation OpLoc
,
1105 bool isSizeOf
, SourceRange R
) {
1106 return getSema().CreateSizeOfAlignOfExpr(TInfo
, OpLoc
, isSizeOf
, R
);
1109 /// \brief Build a new sizeof or alignof expression with an expression
1112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
1114 ExprResult
RebuildSizeOfAlignOf(Expr
*SubExpr
, SourceLocation OpLoc
,
1115 bool isSizeOf
, SourceRange R
) {
1117 = getSema().CreateSizeOfAlignOfExpr(SubExpr
, OpLoc
, isSizeOf
, R
);
1118 if (Result
.isInvalid())
1121 return move(Result
);
1124 /// \brief Build a new array subscript expression.
1126 /// By default, performs semantic analysis to build the new expression.
1127 /// Subclasses may override this routine to provide different behavior.
1128 ExprResult
RebuildArraySubscriptExpr(Expr
*LHS
,
1129 SourceLocation LBracketLoc
,
1131 SourceLocation RBracketLoc
) {
1132 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS
,
1137 /// \brief Build a new call expression.
1139 /// By default, performs semantic analysis to build the new expression.
1140 /// Subclasses may override this routine to provide different behavior.
1141 ExprResult
RebuildCallExpr(Expr
*Callee
, SourceLocation LParenLoc
,
1143 SourceLocation RParenLoc
) {
1144 return getSema().ActOnCallExpr(/*Scope=*/0, Callee
, LParenLoc
,
1145 move(Args
), RParenLoc
);
1148 /// \brief Build a new member access expression.
1150 /// By default, performs semantic analysis to build the new expression.
1151 /// Subclasses may override this routine to provide different behavior.
1152 ExprResult
RebuildMemberExpr(Expr
*Base
, SourceLocation OpLoc
,
1154 NestedNameSpecifier
*Qualifier
,
1155 SourceRange QualifierRange
,
1156 const DeclarationNameInfo
&MemberNameInfo
,
1158 NamedDecl
*FoundDecl
,
1159 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
1160 NamedDecl
*FirstQualifierInScope
) {
1161 if (!Member
->getDeclName()) {
1162 // We have a reference to an unnamed field. This is always the
1163 // base of an anonymous struct/union member access, i.e. the
1164 // field is always of record type.
1165 assert(!Qualifier
&& "Can't have an unnamed field with a qualifier!");
1166 assert(Member
->getType()->isRecordType() &&
1167 "unnamed member not of record type?");
1169 if (getSema().PerformObjectMemberConversion(Base
, Qualifier
,
1173 ExprValueKind VK
= isArrow
? VK_LValue
: Base
->getValueKind();
1175 new (getSema().Context
) MemberExpr(Base
, isArrow
,
1176 Member
, MemberNameInfo
,
1177 cast
<FieldDecl
>(Member
)->getType(),
1179 return getSema().Owned(ME
);
1184 SS
.setRange(QualifierRange
);
1185 SS
.setScopeRep(Qualifier
);
1188 getSema().DefaultFunctionArrayConversion(Base
);
1189 QualType BaseType
= Base
->getType();
1191 // FIXME: this involves duplicating earlier analysis in a lot of
1192 // cases; we should avoid this when possible.
1193 LookupResult
R(getSema(), MemberNameInfo
, Sema::LookupMemberName
);
1194 R
.addDecl(FoundDecl
);
1197 return getSema().BuildMemberReferenceExpr(Base
, BaseType
, OpLoc
, isArrow
,
1198 SS
, FirstQualifierInScope
,
1199 R
, ExplicitTemplateArgs
);
1202 /// \brief Build a new binary operator expression.
1204 /// By default, performs semantic analysis to build the new expression.
1205 /// Subclasses may override this routine to provide different behavior.
1206 ExprResult
RebuildBinaryOperator(SourceLocation OpLoc
,
1207 BinaryOperatorKind Opc
,
1208 Expr
*LHS
, Expr
*RHS
) {
1209 return getSema().BuildBinOp(/*Scope=*/0, OpLoc
, Opc
, LHS
, RHS
);
1212 /// \brief Build a new conditional operator expression.
1214 /// By default, performs semantic analysis to build the new expression.
1215 /// Subclasses may override this routine to provide different behavior.
1216 ExprResult
RebuildConditionalOperator(Expr
*Cond
,
1217 SourceLocation QuestionLoc
,
1219 SourceLocation ColonLoc
,
1221 return getSema().ActOnConditionalOp(QuestionLoc
, ColonLoc
, Cond
,
1225 /// \brief Build a new C-style cast expression.
1227 /// By default, performs semantic analysis to build the new expression.
1228 /// Subclasses may override this routine to provide different behavior.
1229 ExprResult
RebuildCStyleCastExpr(SourceLocation LParenLoc
,
1230 TypeSourceInfo
*TInfo
,
1231 SourceLocation RParenLoc
,
1233 return getSema().BuildCStyleCastExpr(LParenLoc
, TInfo
, RParenLoc
,
1237 /// \brief Build a new compound literal expression.
1239 /// By default, performs semantic analysis to build the new expression.
1240 /// Subclasses may override this routine to provide different behavior.
1241 ExprResult
RebuildCompoundLiteralExpr(SourceLocation LParenLoc
,
1242 TypeSourceInfo
*TInfo
,
1243 SourceLocation RParenLoc
,
1245 return getSema().BuildCompoundLiteralExpr(LParenLoc
, TInfo
, RParenLoc
,
1249 /// \brief Build a new extended vector element access expression.
1251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
1253 ExprResult
RebuildExtVectorElementExpr(Expr
*Base
,
1254 SourceLocation OpLoc
,
1255 SourceLocation AccessorLoc
,
1256 IdentifierInfo
&Accessor
) {
1259 DeclarationNameInfo
NameInfo(&Accessor
, AccessorLoc
);
1260 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
1261 OpLoc
, /*IsArrow*/ false,
1262 SS
, /*FirstQualifierInScope*/ 0,
1264 /* TemplateArgs */ 0);
1267 /// \brief Build a new initializer list expression.
1269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
1271 ExprResult
RebuildInitList(SourceLocation LBraceLoc
,
1273 SourceLocation RBraceLoc
,
1274 QualType ResultTy
) {
1276 = SemaRef
.ActOnInitList(LBraceLoc
, move(Inits
), RBraceLoc
);
1277 if (Result
.isInvalid() || ResultTy
->isDependentType())
1278 return move(Result
);
1280 // Patch in the result type we were given, which may have been computed
1281 // when the initial InitListExpr was built.
1282 InitListExpr
*ILE
= cast
<InitListExpr
>((Expr
*)Result
.get());
1283 ILE
->setType(ResultTy
);
1284 return move(Result
);
1287 /// \brief Build a new designated initializer expression.
1289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
1291 ExprResult
RebuildDesignatedInitExpr(Designation
&Desig
,
1292 MultiExprArg ArrayExprs
,
1293 SourceLocation EqualOrColonLoc
,
1297 = SemaRef
.ActOnDesignatedInitializer(Desig
, EqualOrColonLoc
, GNUSyntax
,
1299 if (Result
.isInvalid())
1302 ArrayExprs
.release();
1303 return move(Result
);
1306 /// \brief Build a new value-initialized expression.
1308 /// By default, builds the implicit value initialization without performing
1309 /// any semantic analysis. Subclasses may override this routine to provide
1310 /// different behavior.
1311 ExprResult
RebuildImplicitValueInitExpr(QualType T
) {
1312 return SemaRef
.Owned(new (SemaRef
.Context
) ImplicitValueInitExpr(T
));
1315 /// \brief Build a new \c va_arg expression.
1317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
1319 ExprResult
RebuildVAArgExpr(SourceLocation BuiltinLoc
,
1320 Expr
*SubExpr
, TypeSourceInfo
*TInfo
,
1321 SourceLocation RParenLoc
) {
1322 return getSema().BuildVAArgExpr(BuiltinLoc
,
1327 /// \brief Build a new expression list in parentheses.
1329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
1331 ExprResult
RebuildParenListExpr(SourceLocation LParenLoc
,
1332 MultiExprArg SubExprs
,
1333 SourceLocation RParenLoc
) {
1334 return getSema().ActOnParenOrParenListExpr(LParenLoc
, RParenLoc
,
1338 /// \brief Build a new address-of-label expression.
1340 /// By default, performs semantic analysis, using the name of the label
1341 /// rather than attempting to map the label statement itself.
1342 /// Subclasses may override this routine to provide different behavior.
1343 ExprResult
RebuildAddrLabelExpr(SourceLocation AmpAmpLoc
,
1344 SourceLocation LabelLoc
,
1346 return getSema().ActOnAddrLabel(AmpAmpLoc
, LabelLoc
, Label
->getID());
1349 /// \brief Build a new GNU statement expression.
1351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
1353 ExprResult
RebuildStmtExpr(SourceLocation LParenLoc
,
1355 SourceLocation RParenLoc
) {
1356 return getSema().ActOnStmtExpr(LParenLoc
, SubStmt
, RParenLoc
);
1359 /// \brief Build a new __builtin_choose_expr expression.
1361 /// By default, performs semantic analysis to build the new expression.
1362 /// Subclasses may override this routine to provide different behavior.
1363 ExprResult
RebuildChooseExpr(SourceLocation BuiltinLoc
,
1364 Expr
*Cond
, Expr
*LHS
, Expr
*RHS
,
1365 SourceLocation RParenLoc
) {
1366 return SemaRef
.ActOnChooseExpr(BuiltinLoc
,
1371 /// \brief Build a new overloaded operator call expression.
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// The semantic analysis provides the behavior of template instantiation,
1375 /// copying with transformations that turn what looks like an overloaded
1376 /// operator call into a use of a builtin operator, performing
1377 /// argument-dependent lookup, etc. Subclasses may override this routine to
1378 /// provide different behavior.
1379 ExprResult
RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op
,
1380 SourceLocation OpLoc
,
1385 /// \brief Build a new C++ "named" cast expression, such as static_cast or
1386 /// reinterpret_cast.
1388 /// By default, this routine dispatches to one of the more-specific routines
1389 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1390 /// Subclasses may override this routine to provide different behavior.
1391 ExprResult
RebuildCXXNamedCastExpr(SourceLocation OpLoc
,
1392 Stmt::StmtClass Class
,
1393 SourceLocation LAngleLoc
,
1394 TypeSourceInfo
*TInfo
,
1395 SourceLocation RAngleLoc
,
1396 SourceLocation LParenLoc
,
1398 SourceLocation RParenLoc
) {
1400 case Stmt::CXXStaticCastExprClass
:
1401 return getDerived().RebuildCXXStaticCastExpr(OpLoc
, LAngleLoc
, TInfo
,
1402 RAngleLoc
, LParenLoc
,
1403 SubExpr
, RParenLoc
);
1405 case Stmt::CXXDynamicCastExprClass
:
1406 return getDerived().RebuildCXXDynamicCastExpr(OpLoc
, LAngleLoc
, TInfo
,
1407 RAngleLoc
, LParenLoc
,
1408 SubExpr
, RParenLoc
);
1410 case Stmt::CXXReinterpretCastExprClass
:
1411 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc
, LAngleLoc
, TInfo
,
1412 RAngleLoc
, LParenLoc
,
1416 case Stmt::CXXConstCastExprClass
:
1417 return getDerived().RebuildCXXConstCastExpr(OpLoc
, LAngleLoc
, TInfo
,
1418 RAngleLoc
, LParenLoc
,
1419 SubExpr
, RParenLoc
);
1422 assert(false && "Invalid C++ named cast");
1429 /// \brief Build a new C++ static_cast expression.
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 ExprResult
RebuildCXXStaticCastExpr(SourceLocation OpLoc
,
1434 SourceLocation LAngleLoc
,
1435 TypeSourceInfo
*TInfo
,
1436 SourceLocation RAngleLoc
,
1437 SourceLocation LParenLoc
,
1439 SourceLocation RParenLoc
) {
1440 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_static_cast
,
1442 SourceRange(LAngleLoc
, RAngleLoc
),
1443 SourceRange(LParenLoc
, RParenLoc
));
1446 /// \brief Build a new C++ dynamic_cast expression.
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
1450 ExprResult
RebuildCXXDynamicCastExpr(SourceLocation OpLoc
,
1451 SourceLocation LAngleLoc
,
1452 TypeSourceInfo
*TInfo
,
1453 SourceLocation RAngleLoc
,
1454 SourceLocation LParenLoc
,
1456 SourceLocation RParenLoc
) {
1457 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_dynamic_cast
,
1459 SourceRange(LAngleLoc
, RAngleLoc
),
1460 SourceRange(LParenLoc
, RParenLoc
));
1463 /// \brief Build a new C++ reinterpret_cast expression.
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
1467 ExprResult
RebuildCXXReinterpretCastExpr(SourceLocation OpLoc
,
1468 SourceLocation LAngleLoc
,
1469 TypeSourceInfo
*TInfo
,
1470 SourceLocation RAngleLoc
,
1471 SourceLocation LParenLoc
,
1473 SourceLocation RParenLoc
) {
1474 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_reinterpret_cast
,
1476 SourceRange(LAngleLoc
, RAngleLoc
),
1477 SourceRange(LParenLoc
, RParenLoc
));
1480 /// \brief Build a new C++ const_cast expression.
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
1484 ExprResult
RebuildCXXConstCastExpr(SourceLocation OpLoc
,
1485 SourceLocation LAngleLoc
,
1486 TypeSourceInfo
*TInfo
,
1487 SourceLocation RAngleLoc
,
1488 SourceLocation LParenLoc
,
1490 SourceLocation RParenLoc
) {
1491 return getSema().BuildCXXNamedCast(OpLoc
, tok::kw_const_cast
,
1493 SourceRange(LAngleLoc
, RAngleLoc
),
1494 SourceRange(LParenLoc
, RParenLoc
));
1497 /// \brief Build a new C++ functional-style cast expression.
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
1501 ExprResult
RebuildCXXFunctionalCastExpr(TypeSourceInfo
*TInfo
,
1502 SourceLocation LParenLoc
,
1504 SourceLocation RParenLoc
) {
1505 return getSema().BuildCXXTypeConstructExpr(TInfo
, LParenLoc
,
1506 MultiExprArg(&Sub
, 1),
1510 /// \brief Build a new C++ typeid(type) expression.
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
1514 ExprResult
RebuildCXXTypeidExpr(QualType TypeInfoType
,
1515 SourceLocation TypeidLoc
,
1516 TypeSourceInfo
*Operand
,
1517 SourceLocation RParenLoc
) {
1518 return getSema().BuildCXXTypeId(TypeInfoType
, TypeidLoc
, Operand
,
1523 /// \brief Build a new C++ typeid(expr) expression.
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
1527 ExprResult
RebuildCXXTypeidExpr(QualType TypeInfoType
,
1528 SourceLocation TypeidLoc
,
1530 SourceLocation RParenLoc
) {
1531 return getSema().BuildCXXTypeId(TypeInfoType
, TypeidLoc
, Operand
,
1535 /// \brief Build a new C++ __uuidof(type) expression.
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
1539 ExprResult
RebuildCXXUuidofExpr(QualType TypeInfoType
,
1540 SourceLocation TypeidLoc
,
1541 TypeSourceInfo
*Operand
,
1542 SourceLocation RParenLoc
) {
1543 return getSema().BuildCXXUuidof(TypeInfoType
, TypeidLoc
, Operand
,
1547 /// \brief Build a new C++ __uuidof(expr) expression.
1549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
1551 ExprResult
RebuildCXXUuidofExpr(QualType TypeInfoType
,
1552 SourceLocation TypeidLoc
,
1554 SourceLocation RParenLoc
) {
1555 return getSema().BuildCXXUuidof(TypeInfoType
, TypeidLoc
, Operand
,
1559 /// \brief Build a new C++ "this" expression.
1561 /// By default, builds a new "this" expression without performing any
1562 /// semantic analysis. Subclasses may override this routine to provide
1563 /// different behavior.
1564 ExprResult
RebuildCXXThisExpr(SourceLocation ThisLoc
,
1567 return getSema().Owned(
1568 new (getSema().Context
) CXXThisExpr(ThisLoc
, ThisType
,
1572 /// \brief Build a new C++ throw expression.
1574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
1576 ExprResult
RebuildCXXThrowExpr(SourceLocation ThrowLoc
, Expr
*Sub
) {
1577 return getSema().ActOnCXXThrow(ThrowLoc
, Sub
);
1580 /// \brief Build a new C++ default-argument expression.
1582 /// By default, builds a new default-argument expression, which does not
1583 /// require any semantic analysis. Subclasses may override this routine to
1584 /// provide different behavior.
1585 ExprResult
RebuildCXXDefaultArgExpr(SourceLocation Loc
,
1586 ParmVarDecl
*Param
) {
1587 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context
, Loc
,
1591 /// \brief Build a new C++ zero-initialization expression.
1593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
1595 ExprResult
RebuildCXXScalarValueInitExpr(TypeSourceInfo
*TSInfo
,
1596 SourceLocation LParenLoc
,
1597 SourceLocation RParenLoc
) {
1598 return getSema().BuildCXXTypeConstructExpr(TSInfo
, LParenLoc
,
1599 MultiExprArg(getSema(), 0, 0),
1603 /// \brief Build a new C++ "new" expression.
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
1607 ExprResult
RebuildCXXNewExpr(SourceLocation StartLoc
,
1609 SourceLocation PlacementLParen
,
1610 MultiExprArg PlacementArgs
,
1611 SourceLocation PlacementRParen
,
1612 SourceRange TypeIdParens
,
1613 QualType AllocatedType
,
1614 TypeSourceInfo
*AllocatedTypeInfo
,
1616 SourceLocation ConstructorLParen
,
1617 MultiExprArg ConstructorArgs
,
1618 SourceLocation ConstructorRParen
) {
1619 return getSema().BuildCXXNew(StartLoc
, UseGlobal
,
1621 move(PlacementArgs
),
1628 move(ConstructorArgs
),
1632 /// \brief Build a new C++ "delete" expression.
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
1636 ExprResult
RebuildCXXDeleteExpr(SourceLocation StartLoc
,
1637 bool IsGlobalDelete
,
1640 return getSema().ActOnCXXDelete(StartLoc
, IsGlobalDelete
, IsArrayForm
,
1644 /// \brief Build a new unary type trait expression.
1646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
1648 ExprResult
RebuildUnaryTypeTrait(UnaryTypeTrait Trait
,
1649 SourceLocation StartLoc
,
1651 SourceLocation RParenLoc
) {
1652 return getSema().BuildUnaryTypeTrait(Trait
, StartLoc
, T
, RParenLoc
);
1655 /// \brief Build a new binary type trait expression.
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
1659 ExprResult
RebuildBinaryTypeTrait(BinaryTypeTrait Trait
,
1660 SourceLocation StartLoc
,
1661 TypeSourceInfo
*LhsT
,
1662 TypeSourceInfo
*RhsT
,
1663 SourceLocation RParenLoc
) {
1664 return getSema().BuildBinaryTypeTrait(Trait
, StartLoc
, LhsT
, RhsT
, RParenLoc
);
1667 /// \brief Build a new (previously unresolved) declaration reference
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
1672 ExprResult
RebuildDependentScopeDeclRefExpr(NestedNameSpecifier
*NNS
,
1673 SourceRange QualifierRange
,
1674 const DeclarationNameInfo
&NameInfo
,
1675 const TemplateArgumentListInfo
*TemplateArgs
) {
1677 SS
.setRange(QualifierRange
);
1678 SS
.setScopeRep(NNS
);
1681 return getSema().BuildQualifiedTemplateIdExpr(SS
, NameInfo
,
1684 return getSema().BuildQualifiedDeclarationNameExpr(SS
, NameInfo
);
1687 /// \brief Build a new template-id expression.
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
1691 ExprResult
RebuildTemplateIdExpr(const CXXScopeSpec
&SS
,
1694 const TemplateArgumentListInfo
&TemplateArgs
) {
1695 return getSema().BuildTemplateIdExpr(SS
, R
, RequiresADL
, TemplateArgs
);
1698 /// \brief Build a new object-construction expression.
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
1702 ExprResult
RebuildCXXConstructExpr(QualType T
,
1704 CXXConstructorDecl
*Constructor
,
1707 bool RequiresZeroInit
,
1708 CXXConstructExpr::ConstructionKind ConstructKind
,
1709 SourceRange ParenRange
) {
1710 ASTOwningVector
<Expr
*> ConvertedArgs(SemaRef
);
1711 if (getSema().CompleteConstructorCall(Constructor
, move(Args
), Loc
,
1715 return getSema().BuildCXXConstructExpr(Loc
, T
, Constructor
, IsElidable
,
1716 move_arg(ConvertedArgs
),
1717 RequiresZeroInit
, ConstructKind
,
1721 /// \brief Build a new object-construction expression.
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
1725 ExprResult
RebuildCXXTemporaryObjectExpr(TypeSourceInfo
*TSInfo
,
1726 SourceLocation LParenLoc
,
1728 SourceLocation RParenLoc
) {
1729 return getSema().BuildCXXTypeConstructExpr(TSInfo
,
1735 /// \brief Build a new object-construction expression.
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
1739 ExprResult
RebuildCXXUnresolvedConstructExpr(TypeSourceInfo
*TSInfo
,
1740 SourceLocation LParenLoc
,
1742 SourceLocation RParenLoc
) {
1743 return getSema().BuildCXXTypeConstructExpr(TSInfo
,
1749 /// \brief Build a new member reference expression.
1751 /// By default, performs semantic analysis to build the new expression.
1752 /// Subclasses may override this routine to provide different behavior.
1753 ExprResult
RebuildCXXDependentScopeMemberExpr(Expr
*BaseE
,
1756 SourceLocation OperatorLoc
,
1757 NestedNameSpecifier
*Qualifier
,
1758 SourceRange QualifierRange
,
1759 NamedDecl
*FirstQualifierInScope
,
1760 const DeclarationNameInfo
&MemberNameInfo
,
1761 const TemplateArgumentListInfo
*TemplateArgs
) {
1763 SS
.setRange(QualifierRange
);
1764 SS
.setScopeRep(Qualifier
);
1766 return SemaRef
.BuildMemberReferenceExpr(BaseE
, BaseType
,
1767 OperatorLoc
, IsArrow
,
1768 SS
, FirstQualifierInScope
,
1773 /// \brief Build a new member reference expression.
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
1777 ExprResult
RebuildUnresolvedMemberExpr(Expr
*BaseE
,
1779 SourceLocation OperatorLoc
,
1781 NestedNameSpecifier
*Qualifier
,
1782 SourceRange QualifierRange
,
1783 NamedDecl
*FirstQualifierInScope
,
1785 const TemplateArgumentListInfo
*TemplateArgs
) {
1787 SS
.setRange(QualifierRange
);
1788 SS
.setScopeRep(Qualifier
);
1790 return SemaRef
.BuildMemberReferenceExpr(BaseE
, BaseType
,
1791 OperatorLoc
, IsArrow
,
1792 SS
, FirstQualifierInScope
,
1796 /// \brief Build a new noexcept expression.
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
1800 ExprResult
RebuildCXXNoexceptExpr(SourceRange Range
, Expr
*Arg
) {
1801 return SemaRef
.BuildCXXNoexceptExpr(Range
.getBegin(), Arg
, Range
.getEnd());
1804 /// \brief Build a new Objective-C @encode expression.
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
1808 ExprResult
RebuildObjCEncodeExpr(SourceLocation AtLoc
,
1809 TypeSourceInfo
*EncodeTypeInfo
,
1810 SourceLocation RParenLoc
) {
1811 return SemaRef
.Owned(SemaRef
.BuildObjCEncodeExpression(AtLoc
, EncodeTypeInfo
,
1815 /// \brief Build a new Objective-C class message.
1816 ExprResult
RebuildObjCMessageExpr(TypeSourceInfo
*ReceiverTypeInfo
,
1818 SourceLocation SelectorLoc
,
1819 ObjCMethodDecl
*Method
,
1820 SourceLocation LBracLoc
,
1822 SourceLocation RBracLoc
) {
1823 return SemaRef
.BuildClassMessage(ReceiverTypeInfo
,
1824 ReceiverTypeInfo
->getType(),
1825 /*SuperLoc=*/SourceLocation(),
1826 Sel
, Method
, LBracLoc
, SelectorLoc
,
1827 RBracLoc
, move(Args
));
1830 /// \brief Build a new Objective-C instance message.
1831 ExprResult
RebuildObjCMessageExpr(Expr
*Receiver
,
1833 SourceLocation SelectorLoc
,
1834 ObjCMethodDecl
*Method
,
1835 SourceLocation LBracLoc
,
1837 SourceLocation RBracLoc
) {
1838 return SemaRef
.BuildInstanceMessage(Receiver
,
1839 Receiver
->getType(),
1840 /*SuperLoc=*/SourceLocation(),
1841 Sel
, Method
, LBracLoc
, SelectorLoc
,
1842 RBracLoc
, move(Args
));
1845 /// \brief Build a new Objective-C ivar reference expression.
1847 /// By default, performs semantic analysis to build the new expression.
1848 /// Subclasses may override this routine to provide different behavior.
1849 ExprResult
RebuildObjCIvarRefExpr(Expr
*BaseArg
, ObjCIvarDecl
*Ivar
,
1850 SourceLocation IvarLoc
,
1851 bool IsArrow
, bool IsFreeIvar
) {
1852 // FIXME: We lose track of the IsFreeIvar bit.
1854 Expr
*Base
= BaseArg
;
1855 LookupResult
R(getSema(), Ivar
->getDeclName(), IvarLoc
,
1856 Sema::LookupMemberName
);
1857 ExprResult Result
= getSema().LookupMemberExpr(R
, Base
, IsArrow
,
1861 if (Result
.isInvalid())
1865 return move(Result
);
1867 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
1868 /*FIXME:*/IvarLoc
, IsArrow
, SS
,
1869 /*FirstQualifierInScope=*/0,
1871 /*TemplateArgs=*/0);
1874 /// \brief Build a new Objective-C property reference expression.
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
1878 ExprResult
RebuildObjCPropertyRefExpr(Expr
*BaseArg
,
1879 ObjCPropertyDecl
*Property
,
1880 SourceLocation PropertyLoc
) {
1882 Expr
*Base
= BaseArg
;
1883 LookupResult
R(getSema(), Property
->getDeclName(), PropertyLoc
,
1884 Sema::LookupMemberName
);
1885 bool IsArrow
= false;
1886 ExprResult Result
= getSema().LookupMemberExpr(R
, Base
, IsArrow
,
1887 /*FIME:*/PropertyLoc
,
1889 if (Result
.isInvalid())
1893 return move(Result
);
1895 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
1896 /*FIXME:*/PropertyLoc
, IsArrow
,
1898 /*FirstQualifierInScope=*/0,
1900 /*TemplateArgs=*/0);
1903 /// \brief Build a new Objective-C property reference expression.
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
1907 ExprResult
RebuildObjCPropertyRefExpr(Expr
*Base
, QualType T
,
1908 ObjCMethodDecl
*Getter
,
1909 ObjCMethodDecl
*Setter
,
1910 SourceLocation PropertyLoc
) {
1911 // Since these expressions can only be value-dependent, we do not
1912 // need to perform semantic analysis again.
1914 new (getSema().Context
) ObjCPropertyRefExpr(Getter
, Setter
, T
,
1915 VK_LValue
, OK_ObjCProperty
,
1916 PropertyLoc
, Base
));
1919 /// \brief Build a new Objective-C "isa" expression.
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
1923 ExprResult
RebuildObjCIsaExpr(Expr
*BaseArg
, SourceLocation IsaLoc
,
1926 Expr
*Base
= BaseArg
;
1927 LookupResult
R(getSema(), &getSema().Context
.Idents
.get("isa"), IsaLoc
,
1928 Sema::LookupMemberName
);
1929 ExprResult Result
= getSema().LookupMemberExpr(R
, Base
, IsArrow
,
1932 if (Result
.isInvalid())
1936 return move(Result
);
1938 return getSema().BuildMemberReferenceExpr(Base
, Base
->getType(),
1939 /*FIXME:*/IsaLoc
, IsArrow
, SS
,
1940 /*FirstQualifierInScope=*/0,
1942 /*TemplateArgs=*/0);
1945 /// \brief Build a new shuffle vector expression.
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
1949 ExprResult
RebuildShuffleVectorExpr(SourceLocation BuiltinLoc
,
1950 MultiExprArg SubExprs
,
1951 SourceLocation RParenLoc
) {
1952 // Find the declaration for __builtin_shufflevector
1953 const IdentifierInfo
&Name
1954 = SemaRef
.Context
.Idents
.get("__builtin_shufflevector");
1955 TranslationUnitDecl
*TUDecl
= SemaRef
.Context
.getTranslationUnitDecl();
1956 DeclContext::lookup_result Lookup
= TUDecl
->lookup(DeclarationName(&Name
));
1957 assert(Lookup
.first
!= Lookup
.second
&& "No __builtin_shufflevector?");
1959 // Build a reference to the __builtin_shufflevector builtin
1960 FunctionDecl
*Builtin
= cast
<FunctionDecl
>(*Lookup
.first
);
1962 = new (SemaRef
.Context
) DeclRefExpr(Builtin
, Builtin
->getType(),
1963 VK_LValue
, BuiltinLoc
);
1964 SemaRef
.UsualUnaryConversions(Callee
);
1966 // Build the CallExpr
1967 unsigned NumSubExprs
= SubExprs
.size();
1968 Expr
**Subs
= (Expr
**)SubExprs
.release();
1969 CallExpr
*TheCall
= new (SemaRef
.Context
) CallExpr(SemaRef
.Context
, Callee
,
1971 Builtin
->getCallResultType(),
1972 Expr::getValueKindForType(Builtin
->getResultType()),
1974 ExprResult
OwnedCall(SemaRef
.Owned(TheCall
));
1976 // Type-check the __builtin_shufflevector expression.
1977 ExprResult Result
= SemaRef
.SemaBuiltinShuffleVector(TheCall
);
1978 if (Result
.isInvalid())
1981 OwnedCall
.release();
1982 return move(Result
);
1986 QualType
TransformTypeInObjectScope(QualType T
,
1987 QualType ObjectType
,
1988 NamedDecl
*FirstQualifierInScope
,
1989 NestedNameSpecifier
*Prefix
);
1991 TypeSourceInfo
*TransformTypeInObjectScope(TypeSourceInfo
*T
,
1992 QualType ObjectType
,
1993 NamedDecl
*FirstQualifierInScope
,
1994 NestedNameSpecifier
*Prefix
);
1997 template<typename Derived
>
1998 StmtResult TreeTransform
<Derived
>::TransformStmt(Stmt
*S
) {
2000 return SemaRef
.Owned(S
);
2002 switch (S
->getStmtClass()) {
2003 case Stmt::NoStmtClass
: break;
2005 // Transform individual statement nodes
2006 #define STMT(Node, Parent) \
2007 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2008 #define EXPR(Node, Parent)
2009 #include "clang/AST/StmtNodes.inc"
2011 // Transform expressions by calling TransformExpr.
2012 #define STMT(Node, Parent)
2013 #define ABSTRACT_STMT(Stmt)
2014 #define EXPR(Node, Parent) case Stmt::Node##Class:
2015 #include "clang/AST/StmtNodes.inc"
2017 ExprResult E
= getDerived().TransformExpr(cast
<Expr
>(S
));
2021 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E
.take()));
2025 return SemaRef
.Owned(S
);
2029 template<typename Derived
>
2030 ExprResult TreeTransform
<Derived
>::TransformExpr(Expr
*E
) {
2032 return SemaRef
.Owned(E
);
2034 switch (E
->getStmtClass()) {
2035 case Stmt::NoStmtClass
: break;
2036 #define STMT(Node, Parent) case Stmt::Node##Class: break;
2037 #define ABSTRACT_STMT(Stmt)
2038 #define EXPR(Node, Parent) \
2039 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
2040 #include "clang/AST/StmtNodes.inc"
2043 return SemaRef
.Owned(E
);
2046 template<typename Derived
>
2047 NestedNameSpecifier
*
2048 TreeTransform
<Derived
>::TransformNestedNameSpecifier(NestedNameSpecifier
*NNS
,
2050 QualType ObjectType
,
2051 NamedDecl
*FirstQualifierInScope
) {
2052 NestedNameSpecifier
*Prefix
= NNS
->getPrefix();
2054 // Transform the prefix of this nested name specifier.
2056 Prefix
= getDerived().TransformNestedNameSpecifier(Prefix
, Range
,
2058 FirstQualifierInScope
);
2063 switch (NNS
->getKind()) {
2064 case NestedNameSpecifier::Identifier
:
2066 // The object type and qualifier-in-scope really apply to the
2068 ObjectType
= QualType();
2069 FirstQualifierInScope
= 0;
2072 assert((Prefix
|| !ObjectType
.isNull()) &&
2073 "Identifier nested-name-specifier with no prefix or object type");
2074 if (!getDerived().AlwaysRebuild() && Prefix
== NNS
->getPrefix() &&
2075 ObjectType
.isNull())
2078 return getDerived().RebuildNestedNameSpecifier(Prefix
, Range
,
2079 *NNS
->getAsIdentifier(),
2081 FirstQualifierInScope
);
2083 case NestedNameSpecifier::Namespace
: {
2085 = cast_or_null
<NamespaceDecl
>(
2086 getDerived().TransformDecl(Range
.getBegin(),
2087 NNS
->getAsNamespace()));
2088 if (!getDerived().AlwaysRebuild() &&
2089 Prefix
== NNS
->getPrefix() &&
2090 NS
== NNS
->getAsNamespace())
2093 return getDerived().RebuildNestedNameSpecifier(Prefix
, Range
, NS
);
2096 case NestedNameSpecifier::Global
:
2097 // There is no meaningful transformation that one could perform on the
2101 case NestedNameSpecifier::TypeSpecWithTemplate
:
2102 case NestedNameSpecifier::TypeSpec
: {
2103 TemporaryBase
Rebase(*this, Range
.getBegin(), DeclarationName());
2104 QualType T
= TransformTypeInObjectScope(QualType(NNS
->getAsType(), 0),
2106 FirstQualifierInScope
,
2111 if (!getDerived().AlwaysRebuild() &&
2112 Prefix
== NNS
->getPrefix() &&
2113 T
== QualType(NNS
->getAsType(), 0))
2116 return getDerived().RebuildNestedNameSpecifier(Prefix
, Range
,
2117 NNS
->getKind() == NestedNameSpecifier::TypeSpecWithTemplate
,
2122 // Required to silence a GCC warning
2126 template<typename Derived
>
2128 TreeTransform
<Derived
>
2129 ::TransformDeclarationNameInfo(const DeclarationNameInfo
&NameInfo
) {
2130 DeclarationName Name
= NameInfo
.getName();
2132 return DeclarationNameInfo();
2134 switch (Name
.getNameKind()) {
2135 case DeclarationName::Identifier
:
2136 case DeclarationName::ObjCZeroArgSelector
:
2137 case DeclarationName::ObjCOneArgSelector
:
2138 case DeclarationName::ObjCMultiArgSelector
:
2139 case DeclarationName::CXXOperatorName
:
2140 case DeclarationName::CXXLiteralOperatorName
:
2141 case DeclarationName::CXXUsingDirective
:
2144 case DeclarationName::CXXConstructorName
:
2145 case DeclarationName::CXXDestructorName
:
2146 case DeclarationName::CXXConversionFunctionName
: {
2147 TypeSourceInfo
*NewTInfo
;
2148 CanQualType NewCanTy
;
2149 if (TypeSourceInfo
*OldTInfo
= NameInfo
.getNamedTypeInfo()) {
2150 NewTInfo
= getDerived().TransformType(OldTInfo
);
2152 return DeclarationNameInfo();
2153 NewCanTy
= SemaRef
.Context
.getCanonicalType(NewTInfo
->getType());
2157 TemporaryBase
Rebase(*this, NameInfo
.getLoc(), Name
);
2158 QualType NewT
= getDerived().TransformType(Name
.getCXXNameType());
2160 return DeclarationNameInfo();
2161 NewCanTy
= SemaRef
.Context
.getCanonicalType(NewT
);
2164 DeclarationName NewName
2165 = SemaRef
.Context
.DeclarationNames
.getCXXSpecialName(Name
.getNameKind(),
2167 DeclarationNameInfo
NewNameInfo(NameInfo
);
2168 NewNameInfo
.setName(NewName
);
2169 NewNameInfo
.setNamedTypeInfo(NewTInfo
);
2174 assert(0 && "Unknown name kind.");
2175 return DeclarationNameInfo();
2178 template<typename Derived
>
2180 TreeTransform
<Derived
>::TransformTemplateName(TemplateName Name
,
2181 QualType ObjectType
,
2182 NamedDecl
*FirstQualifierInScope
) {
2183 SourceLocation Loc
= getDerived().getBaseLocation();
2185 if (QualifiedTemplateName
*QTN
= Name
.getAsQualifiedTemplateName()) {
2186 NestedNameSpecifier
*NNS
2187 = getDerived().TransformNestedNameSpecifier(QTN
->getQualifier(),
2188 /*FIXME*/ SourceRange(Loc
),
2190 FirstQualifierInScope
);
2192 return TemplateName();
2194 if (TemplateDecl
*Template
= QTN
->getTemplateDecl()) {
2195 TemplateDecl
*TransTemplate
2196 = cast_or_null
<TemplateDecl
>(getDerived().TransformDecl(Loc
, Template
));
2198 return TemplateName();
2200 if (!getDerived().AlwaysRebuild() &&
2201 NNS
== QTN
->getQualifier() &&
2202 TransTemplate
== Template
)
2205 return getDerived().RebuildTemplateName(NNS
, QTN
->hasTemplateKeyword(),
2209 // These should be getting filtered out before they make it into the AST.
2210 llvm_unreachable("overloaded template name survived to here");
2213 if (DependentTemplateName
*DTN
= Name
.getAsDependentTemplateName()) {
2214 NestedNameSpecifier
*NNS
= DTN
->getQualifier();
2216 NNS
= getDerived().TransformNestedNameSpecifier(NNS
,
2217 /*FIXME:*/SourceRange(Loc
),
2219 FirstQualifierInScope
);
2220 if (!NNS
) return TemplateName();
2222 // These apply to the scope specifier, not the template.
2223 ObjectType
= QualType();
2224 FirstQualifierInScope
= 0;
2227 if (!getDerived().AlwaysRebuild() &&
2228 NNS
== DTN
->getQualifier() &&
2229 ObjectType
.isNull())
2232 if (DTN
->isIdentifier()) {
2234 SourceRange
QualifierRange(getDerived().getBaseLocation());
2235 return getDerived().RebuildTemplateName(NNS
, QualifierRange
,
2236 *DTN
->getIdentifier(),
2238 FirstQualifierInScope
);
2241 return getDerived().RebuildTemplateName(NNS
, DTN
->getOperator(),
2245 if (TemplateDecl
*Template
= Name
.getAsTemplateDecl()) {
2246 TemplateDecl
*TransTemplate
2247 = cast_or_null
<TemplateDecl
>(getDerived().TransformDecl(Loc
, Template
));
2249 return TemplateName();
2251 if (!getDerived().AlwaysRebuild() &&
2252 TransTemplate
== Template
)
2255 return TemplateName(TransTemplate
);
2258 // These should be getting filtered out before they reach the AST.
2259 llvm_unreachable("overloaded function decl survived to here");
2260 return TemplateName();
2263 template<typename Derived
>
2264 void TreeTransform
<Derived
>::InventTemplateArgumentLoc(
2265 const TemplateArgument
&Arg
,
2266 TemplateArgumentLoc
&Output
) {
2267 SourceLocation Loc
= getDerived().getBaseLocation();
2268 switch (Arg
.getKind()) {
2269 case TemplateArgument::Null
:
2270 llvm_unreachable("null template argument in TreeTransform");
2273 case TemplateArgument::Type
:
2274 Output
= TemplateArgumentLoc(Arg
,
2275 SemaRef
.Context
.getTrivialTypeSourceInfo(Arg
.getAsType(), Loc
));
2279 case TemplateArgument::Template
:
2280 Output
= TemplateArgumentLoc(Arg
, SourceRange(), Loc
);
2283 case TemplateArgument::Expression
:
2284 Output
= TemplateArgumentLoc(Arg
, Arg
.getAsExpr());
2287 case TemplateArgument::Declaration
:
2288 case TemplateArgument::Integral
:
2289 case TemplateArgument::Pack
:
2290 Output
= TemplateArgumentLoc(Arg
, TemplateArgumentLocInfo());
2295 template<typename Derived
>
2296 bool TreeTransform
<Derived
>::TransformTemplateArgument(
2297 const TemplateArgumentLoc
&Input
,
2298 TemplateArgumentLoc
&Output
) {
2299 const TemplateArgument
&Arg
= Input
.getArgument();
2300 switch (Arg
.getKind()) {
2301 case TemplateArgument::Null
:
2302 case TemplateArgument::Integral
:
2306 case TemplateArgument::Type
: {
2307 TypeSourceInfo
*DI
= Input
.getTypeSourceInfo();
2309 DI
= InventTypeSourceInfo(Input
.getArgument().getAsType());
2311 DI
= getDerived().TransformType(DI
);
2312 if (!DI
) return true;
2314 Output
= TemplateArgumentLoc(TemplateArgument(DI
->getType()), DI
);
2318 case TemplateArgument::Declaration
: {
2319 // FIXME: we should never have to transform one of these.
2320 DeclarationName Name
;
2321 if (NamedDecl
*ND
= dyn_cast
<NamedDecl
>(Arg
.getAsDecl()))
2322 Name
= ND
->getDeclName();
2323 TemporaryBase
Rebase(*this, Input
.getLocation(), Name
);
2324 Decl
*D
= getDerived().TransformDecl(Input
.getLocation(), Arg
.getAsDecl());
2325 if (!D
) return true;
2327 Expr
*SourceExpr
= Input
.getSourceDeclExpression();
2329 EnterExpressionEvaluationContext
Unevaluated(getSema(),
2331 ExprResult E
= getDerived().TransformExpr(SourceExpr
);
2332 SourceExpr
= (E
.isInvalid() ? 0 : E
.take());
2335 Output
= TemplateArgumentLoc(TemplateArgument(D
), SourceExpr
);
2339 case TemplateArgument::Template
: {
2340 TemporaryBase
Rebase(*this, Input
.getLocation(), DeclarationName());
2341 TemplateName Template
2342 = getDerived().TransformTemplateName(Arg
.getAsTemplate());
2343 if (Template
.isNull())
2346 Output
= TemplateArgumentLoc(TemplateArgument(Template
),
2347 Input
.getTemplateQualifierRange(),
2348 Input
.getTemplateNameLoc());
2352 case TemplateArgument::Expression
: {
2353 // Template argument expressions are not potentially evaluated.
2354 EnterExpressionEvaluationContext
Unevaluated(getSema(),
2357 Expr
*InputExpr
= Input
.getSourceExpression();
2358 if (!InputExpr
) InputExpr
= Input
.getArgument().getAsExpr();
2361 = getDerived().TransformExpr(InputExpr
);
2362 if (E
.isInvalid()) return true;
2363 Output
= TemplateArgumentLoc(TemplateArgument(E
.take()), E
.take());
2367 case TemplateArgument::Pack
: {
2368 llvm::SmallVector
<TemplateArgument
, 4> TransformedArgs
;
2369 TransformedArgs
.reserve(Arg
.pack_size());
2370 for (TemplateArgument::pack_iterator A
= Arg
.pack_begin(),
2371 AEnd
= Arg
.pack_end();
2374 // FIXME: preserve source information here when we start
2375 // caring about parameter packs.
2377 TemplateArgumentLoc InputArg
;
2378 TemplateArgumentLoc OutputArg
;
2379 getDerived().InventTemplateArgumentLoc(*A
, InputArg
);
2380 if (getDerived().TransformTemplateArgument(InputArg
, OutputArg
))
2383 TransformedArgs
.push_back(OutputArg
.getArgument());
2386 TemplateArgument
*TransformedArgsPtr
2387 = new (getSema().Context
) TemplateArgument
[TransformedArgs
.size()];
2388 std::copy(TransformedArgs
.begin(), TransformedArgs
.end(),
2389 TransformedArgsPtr
);
2390 Output
= TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr
,
2391 TransformedArgs
.size()),
2392 Input
.getLocInfo());
2397 // Work around bogus GCC warning
2401 //===----------------------------------------------------------------------===//
2402 // Type transformation
2403 //===----------------------------------------------------------------------===//
2405 template<typename Derived
>
2406 QualType TreeTransform
<Derived
>::TransformType(QualType T
) {
2407 if (getDerived().AlreadyTransformed(T
))
2410 // Temporary workaround. All of these transformations should
2411 // eventually turn into transformations on TypeLocs.
2412 TypeSourceInfo
*DI
= getSema().Context
.CreateTypeSourceInfo(T
);
2413 DI
->getTypeLoc().initialize(getDerived().getBaseLocation());
2415 TypeSourceInfo
*NewDI
= getDerived().TransformType(DI
);
2420 return NewDI
->getType();
2423 template<typename Derived
>
2424 TypeSourceInfo
*TreeTransform
<Derived
>::TransformType(TypeSourceInfo
*DI
) {
2425 if (getDerived().AlreadyTransformed(DI
->getType()))
2430 TypeLoc TL
= DI
->getTypeLoc();
2431 TLB
.reserve(TL
.getFullDataSize());
2433 QualType Result
= getDerived().TransformType(TLB
, TL
);
2434 if (Result
.isNull())
2437 return TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
2440 template<typename Derived
>
2442 TreeTransform
<Derived
>::TransformType(TypeLocBuilder
&TLB
, TypeLoc T
) {
2443 switch (T
.getTypeLocClass()) {
2444 #define ABSTRACT_TYPELOC(CLASS, PARENT)
2445 #define TYPELOC(CLASS, PARENT) \
2446 case TypeLoc::CLASS: \
2447 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2448 #include "clang/AST/TypeLocNodes.def"
2451 llvm_unreachable("unhandled type loc!");
2455 /// FIXME: By default, this routine adds type qualifiers only to types
2456 /// that can have qualifiers, and silently suppresses those qualifiers
2457 /// that are not permitted (e.g., qualifiers on reference or function
2458 /// types). This is the right thing for template instantiation, but
2459 /// probably not for other clients.
2460 template<typename Derived
>
2462 TreeTransform
<Derived
>::TransformQualifiedType(TypeLocBuilder
&TLB
,
2463 QualifiedTypeLoc T
) {
2464 Qualifiers Quals
= T
.getType().getLocalQualifiers();
2466 QualType Result
= getDerived().TransformType(TLB
, T
.getUnqualifiedLoc());
2467 if (Result
.isNull())
2470 // Silently suppress qualifiers if the result type can't be qualified.
2471 // FIXME: this is the right thing for template instantiation, but
2472 // probably not for other clients.
2473 if (Result
->isFunctionType() || Result
->isReferenceType())
2476 if (!Quals
.empty()) {
2477 Result
= SemaRef
.BuildQualifiedType(Result
, T
.getBeginLoc(), Quals
);
2478 TLB
.push
<QualifiedTypeLoc
>(Result
);
2479 // No location information to preserve.
2485 /// \brief Transforms a type that was written in a scope specifier,
2486 /// given an object type, the results of unqualified lookup, and
2487 /// an already-instantiated prefix.
2489 /// The object type is provided iff the scope specifier qualifies the
2490 /// member of a dependent member-access expression. The prefix is
2491 /// provided iff the the scope specifier in which this appears has a
2494 /// This is private to TreeTransform.
2495 template<typename Derived
>
2497 TreeTransform
<Derived
>::TransformTypeInObjectScope(QualType T
,
2498 QualType ObjectType
,
2499 NamedDecl
*UnqualLookup
,
2500 NestedNameSpecifier
*Prefix
) {
2501 if (getDerived().AlreadyTransformed(T
))
2504 TypeSourceInfo
*TSI
=
2505 SemaRef
.Context
.getTrivialTypeSourceInfo(T
, getBaseLocation());
2507 TSI
= getDerived().TransformTypeInObjectScope(TSI
, ObjectType
,
2508 UnqualLookup
, Prefix
);
2509 if (!TSI
) return QualType();
2510 return TSI
->getType();
2513 template<typename Derived
>
2515 TreeTransform
<Derived
>::TransformTypeInObjectScope(TypeSourceInfo
*TSI
,
2516 QualType ObjectType
,
2517 NamedDecl
*UnqualLookup
,
2518 NestedNameSpecifier
*Prefix
) {
2519 // TODO: in some cases, we might be some verification to do here.
2520 if (ObjectType
.isNull())
2521 return getDerived().TransformType(TSI
);
2523 QualType T
= TSI
->getType();
2524 if (getDerived().AlreadyTransformed(T
))
2530 if (isa
<TemplateSpecializationType
>(T
)) {
2531 TemplateSpecializationTypeLoc TL
2532 = cast
<TemplateSpecializationTypeLoc
>(TSI
->getTypeLoc());
2534 TemplateName Template
=
2535 getDerived().TransformTemplateName(TL
.getTypePtr()->getTemplateName(),
2536 ObjectType
, UnqualLookup
);
2537 if (Template
.isNull()) return 0;
2539 Result
= getDerived()
2540 .TransformTemplateSpecializationType(TLB
, TL
, Template
);
2541 } else if (isa
<DependentTemplateSpecializationType
>(T
)) {
2542 DependentTemplateSpecializationTypeLoc TL
2543 = cast
<DependentTemplateSpecializationTypeLoc
>(TSI
->getTypeLoc());
2545 Result
= getDerived()
2546 .TransformDependentTemplateSpecializationType(TLB
, TL
, Prefix
);
2548 // Nothing special needs to be done for these.
2549 Result
= getDerived().TransformType(TLB
, TSI
->getTypeLoc());
2552 if (Result
.isNull()) return 0;
2553 return TLB
.getTypeSourceInfo(SemaRef
.Context
, Result
);
2556 template <class TyLoc
> static inline
2557 QualType
TransformTypeSpecType(TypeLocBuilder
&TLB
, TyLoc T
) {
2558 TyLoc NewT
= TLB
.push
<TyLoc
>(T
.getType());
2559 NewT
.setNameLoc(T
.getNameLoc());
2563 template<typename Derived
>
2564 QualType TreeTransform
<Derived
>::TransformBuiltinType(TypeLocBuilder
&TLB
,
2566 BuiltinTypeLoc NewT
= TLB
.push
<BuiltinTypeLoc
>(T
.getType());
2567 NewT
.setBuiltinLoc(T
.getBuiltinLoc());
2568 if (T
.needsExtraLocalData())
2569 NewT
.getWrittenBuiltinSpecs() = T
.getWrittenBuiltinSpecs();
2573 template<typename Derived
>
2574 QualType TreeTransform
<Derived
>::TransformComplexType(TypeLocBuilder
&TLB
,
2577 return TransformTypeSpecType(TLB
, T
);
2580 template<typename Derived
>
2581 QualType TreeTransform
<Derived
>::TransformPointerType(TypeLocBuilder
&TLB
,
2582 PointerTypeLoc TL
) {
2583 QualType PointeeType
2584 = getDerived().TransformType(TLB
, TL
.getPointeeLoc());
2585 if (PointeeType
.isNull())
2588 QualType Result
= TL
.getType();
2589 if (PointeeType
->getAs
<ObjCObjectType
>()) {
2590 // A dependent pointer type 'T *' has is being transformed such
2591 // that an Objective-C class type is being replaced for 'T'. The
2592 // resulting pointer type is an ObjCObjectPointerType, not a
2594 Result
= SemaRef
.Context
.getObjCObjectPointerType(PointeeType
);
2596 ObjCObjectPointerTypeLoc NewT
= TLB
.push
<ObjCObjectPointerTypeLoc
>(Result
);
2597 NewT
.setStarLoc(TL
.getStarLoc());
2601 if (getDerived().AlwaysRebuild() ||
2602 PointeeType
!= TL
.getPointeeLoc().getType()) {
2603 Result
= getDerived().RebuildPointerType(PointeeType
, TL
.getSigilLoc());
2604 if (Result
.isNull())
2608 PointerTypeLoc NewT
= TLB
.push
<PointerTypeLoc
>(Result
);
2609 NewT
.setSigilLoc(TL
.getSigilLoc());
2613 template<typename Derived
>
2615 TreeTransform
<Derived
>::TransformBlockPointerType(TypeLocBuilder
&TLB
,
2616 BlockPointerTypeLoc TL
) {
2617 QualType PointeeType
2618 = getDerived().TransformType(TLB
, TL
.getPointeeLoc());
2619 if (PointeeType
.isNull())
2622 QualType Result
= TL
.getType();
2623 if (getDerived().AlwaysRebuild() ||
2624 PointeeType
!= TL
.getPointeeLoc().getType()) {
2625 Result
= getDerived().RebuildBlockPointerType(PointeeType
,
2627 if (Result
.isNull())
2631 BlockPointerTypeLoc NewT
= TLB
.push
<BlockPointerTypeLoc
>(Result
);
2632 NewT
.setSigilLoc(TL
.getSigilLoc());
2636 /// Transforms a reference type. Note that somewhat paradoxically we
2637 /// don't care whether the type itself is an l-value type or an r-value
2638 /// type; we only care if the type was *written* as an l-value type
2639 /// or an r-value type.
2640 template<typename Derived
>
2642 TreeTransform
<Derived
>::TransformReferenceType(TypeLocBuilder
&TLB
,
2643 ReferenceTypeLoc TL
) {
2644 const ReferenceType
*T
= TL
.getTypePtr();
2646 // Note that this works with the pointee-as-written.
2647 QualType PointeeType
= getDerived().TransformType(TLB
, TL
.getPointeeLoc());
2648 if (PointeeType
.isNull())
2651 QualType Result
= TL
.getType();
2652 if (getDerived().AlwaysRebuild() ||
2653 PointeeType
!= T
->getPointeeTypeAsWritten()) {
2654 Result
= getDerived().RebuildReferenceType(PointeeType
,
2655 T
->isSpelledAsLValue(),
2657 if (Result
.isNull())
2661 // r-value references can be rebuilt as l-value references.
2662 ReferenceTypeLoc NewTL
;
2663 if (isa
<LValueReferenceType
>(Result
))
2664 NewTL
= TLB
.push
<LValueReferenceTypeLoc
>(Result
);
2666 NewTL
= TLB
.push
<RValueReferenceTypeLoc
>(Result
);
2667 NewTL
.setSigilLoc(TL
.getSigilLoc());
2672 template<typename Derived
>
2674 TreeTransform
<Derived
>::TransformLValueReferenceType(TypeLocBuilder
&TLB
,
2675 LValueReferenceTypeLoc TL
) {
2676 return TransformReferenceType(TLB
, TL
);
2679 template<typename Derived
>
2681 TreeTransform
<Derived
>::TransformRValueReferenceType(TypeLocBuilder
&TLB
,
2682 RValueReferenceTypeLoc TL
) {
2683 return TransformReferenceType(TLB
, TL
);
2686 template<typename Derived
>
2688 TreeTransform
<Derived
>::TransformMemberPointerType(TypeLocBuilder
&TLB
,
2689 MemberPointerTypeLoc TL
) {
2690 MemberPointerType
*T
= TL
.getTypePtr();
2692 QualType PointeeType
= getDerived().TransformType(TLB
, TL
.getPointeeLoc());
2693 if (PointeeType
.isNull())
2696 // TODO: preserve source information for this.
2698 = getDerived().TransformType(QualType(T
->getClass(), 0));
2699 if (ClassType
.isNull())
2702 QualType Result
= TL
.getType();
2703 if (getDerived().AlwaysRebuild() ||
2704 PointeeType
!= T
->getPointeeType() ||
2705 ClassType
!= QualType(T
->getClass(), 0)) {
2706 Result
= getDerived().RebuildMemberPointerType(PointeeType
, ClassType
,
2708 if (Result
.isNull())
2712 MemberPointerTypeLoc NewTL
= TLB
.push
<MemberPointerTypeLoc
>(Result
);
2713 NewTL
.setSigilLoc(TL
.getSigilLoc());
2718 template<typename Derived
>
2720 TreeTransform
<Derived
>::TransformConstantArrayType(TypeLocBuilder
&TLB
,
2721 ConstantArrayTypeLoc TL
) {
2722 ConstantArrayType
*T
= TL
.getTypePtr();
2723 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
2724 if (ElementType
.isNull())
2727 QualType Result
= TL
.getType();
2728 if (getDerived().AlwaysRebuild() ||
2729 ElementType
!= T
->getElementType()) {
2730 Result
= getDerived().RebuildConstantArrayType(ElementType
,
2731 T
->getSizeModifier(),
2733 T
->getIndexTypeCVRQualifiers(),
2734 TL
.getBracketsRange());
2735 if (Result
.isNull())
2739 ConstantArrayTypeLoc NewTL
= TLB
.push
<ConstantArrayTypeLoc
>(Result
);
2740 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
2741 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
2743 Expr
*Size
= TL
.getSizeExpr();
2745 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
2746 Size
= getDerived().TransformExpr(Size
).template takeAs
<Expr
>();
2748 NewTL
.setSizeExpr(Size
);
2753 template<typename Derived
>
2754 QualType TreeTransform
<Derived
>::TransformIncompleteArrayType(
2755 TypeLocBuilder
&TLB
,
2756 IncompleteArrayTypeLoc TL
) {
2757 IncompleteArrayType
*T
= TL
.getTypePtr();
2758 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
2759 if (ElementType
.isNull())
2762 QualType Result
= TL
.getType();
2763 if (getDerived().AlwaysRebuild() ||
2764 ElementType
!= T
->getElementType()) {
2765 Result
= getDerived().RebuildIncompleteArrayType(ElementType
,
2766 T
->getSizeModifier(),
2767 T
->getIndexTypeCVRQualifiers(),
2768 TL
.getBracketsRange());
2769 if (Result
.isNull())
2773 IncompleteArrayTypeLoc NewTL
= TLB
.push
<IncompleteArrayTypeLoc
>(Result
);
2774 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
2775 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
2776 NewTL
.setSizeExpr(0);
2781 template<typename Derived
>
2783 TreeTransform
<Derived
>::TransformVariableArrayType(TypeLocBuilder
&TLB
,
2784 VariableArrayTypeLoc TL
) {
2785 VariableArrayType
*T
= TL
.getTypePtr();
2786 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
2787 if (ElementType
.isNull())
2790 // Array bounds are not potentially evaluated contexts
2791 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
2793 ExprResult SizeResult
2794 = getDerived().TransformExpr(T
->getSizeExpr());
2795 if (SizeResult
.isInvalid())
2798 Expr
*Size
= SizeResult
.take();
2800 QualType Result
= TL
.getType();
2801 if (getDerived().AlwaysRebuild() ||
2802 ElementType
!= T
->getElementType() ||
2803 Size
!= T
->getSizeExpr()) {
2804 Result
= getDerived().RebuildVariableArrayType(ElementType
,
2805 T
->getSizeModifier(),
2807 T
->getIndexTypeCVRQualifiers(),
2808 TL
.getBracketsRange());
2809 if (Result
.isNull())
2813 VariableArrayTypeLoc NewTL
= TLB
.push
<VariableArrayTypeLoc
>(Result
);
2814 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
2815 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
2816 NewTL
.setSizeExpr(Size
);
2821 template<typename Derived
>
2823 TreeTransform
<Derived
>::TransformDependentSizedArrayType(TypeLocBuilder
&TLB
,
2824 DependentSizedArrayTypeLoc TL
) {
2825 DependentSizedArrayType
*T
= TL
.getTypePtr();
2826 QualType ElementType
= getDerived().TransformType(TLB
, TL
.getElementLoc());
2827 if (ElementType
.isNull())
2830 // Array bounds are not potentially evaluated contexts
2831 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
2833 ExprResult SizeResult
2834 = getDerived().TransformExpr(T
->getSizeExpr());
2835 if (SizeResult
.isInvalid())
2838 Expr
*Size
= static_cast<Expr
*>(SizeResult
.get());
2840 QualType Result
= TL
.getType();
2841 if (getDerived().AlwaysRebuild() ||
2842 ElementType
!= T
->getElementType() ||
2843 Size
!= T
->getSizeExpr()) {
2844 Result
= getDerived().RebuildDependentSizedArrayType(ElementType
,
2845 T
->getSizeModifier(),
2847 T
->getIndexTypeCVRQualifiers(),
2848 TL
.getBracketsRange());
2849 if (Result
.isNull())
2852 else SizeResult
.take();
2854 // We might have any sort of array type now, but fortunately they
2855 // all have the same location layout.
2856 ArrayTypeLoc NewTL
= TLB
.push
<ArrayTypeLoc
>(Result
);
2857 NewTL
.setLBracketLoc(TL
.getLBracketLoc());
2858 NewTL
.setRBracketLoc(TL
.getRBracketLoc());
2859 NewTL
.setSizeExpr(Size
);
2864 template<typename Derived
>
2865 QualType TreeTransform
<Derived
>::TransformDependentSizedExtVectorType(
2866 TypeLocBuilder
&TLB
,
2867 DependentSizedExtVectorTypeLoc TL
) {
2868 DependentSizedExtVectorType
*T
= TL
.getTypePtr();
2870 // FIXME: ext vector locs should be nested
2871 QualType ElementType
= getDerived().TransformType(T
->getElementType());
2872 if (ElementType
.isNull())
2875 // Vector sizes are not potentially evaluated contexts
2876 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
2878 ExprResult Size
= getDerived().TransformExpr(T
->getSizeExpr());
2879 if (Size
.isInvalid())
2882 QualType Result
= TL
.getType();
2883 if (getDerived().AlwaysRebuild() ||
2884 ElementType
!= T
->getElementType() ||
2885 Size
.get() != T
->getSizeExpr()) {
2886 Result
= getDerived().RebuildDependentSizedExtVectorType(ElementType
,
2888 T
->getAttributeLoc());
2889 if (Result
.isNull())
2893 // Result might be dependent or not.
2894 if (isa
<DependentSizedExtVectorType
>(Result
)) {
2895 DependentSizedExtVectorTypeLoc NewTL
2896 = TLB
.push
<DependentSizedExtVectorTypeLoc
>(Result
);
2897 NewTL
.setNameLoc(TL
.getNameLoc());
2899 ExtVectorTypeLoc NewTL
= TLB
.push
<ExtVectorTypeLoc
>(Result
);
2900 NewTL
.setNameLoc(TL
.getNameLoc());
2906 template<typename Derived
>
2907 QualType TreeTransform
<Derived
>::TransformVectorType(TypeLocBuilder
&TLB
,
2909 VectorType
*T
= TL
.getTypePtr();
2910 QualType ElementType
= getDerived().TransformType(T
->getElementType());
2911 if (ElementType
.isNull())
2914 QualType Result
= TL
.getType();
2915 if (getDerived().AlwaysRebuild() ||
2916 ElementType
!= T
->getElementType()) {
2917 Result
= getDerived().RebuildVectorType(ElementType
, T
->getNumElements(),
2918 T
->getVectorKind());
2919 if (Result
.isNull())
2923 VectorTypeLoc NewTL
= TLB
.push
<VectorTypeLoc
>(Result
);
2924 NewTL
.setNameLoc(TL
.getNameLoc());
2929 template<typename Derived
>
2930 QualType TreeTransform
<Derived
>::TransformExtVectorType(TypeLocBuilder
&TLB
,
2931 ExtVectorTypeLoc TL
) {
2932 VectorType
*T
= TL
.getTypePtr();
2933 QualType ElementType
= getDerived().TransformType(T
->getElementType());
2934 if (ElementType
.isNull())
2937 QualType Result
= TL
.getType();
2938 if (getDerived().AlwaysRebuild() ||
2939 ElementType
!= T
->getElementType()) {
2940 Result
= getDerived().RebuildExtVectorType(ElementType
,
2941 T
->getNumElements(),
2942 /*FIXME*/ SourceLocation());
2943 if (Result
.isNull())
2947 ExtVectorTypeLoc NewTL
= TLB
.push
<ExtVectorTypeLoc
>(Result
);
2948 NewTL
.setNameLoc(TL
.getNameLoc());
2953 template<typename Derived
>
2955 TreeTransform
<Derived
>::TransformFunctionTypeParam(ParmVarDecl
*OldParm
) {
2956 TypeSourceInfo
*OldDI
= OldParm
->getTypeSourceInfo();
2957 TypeSourceInfo
*NewDI
= getDerived().TransformType(OldDI
);
2964 return ParmVarDecl::Create(SemaRef
.Context
,
2965 OldParm
->getDeclContext(),
2966 OldParm
->getLocation(),
2967 OldParm
->getIdentifier(),
2970 OldParm
->getStorageClass(),
2971 OldParm
->getStorageClassAsWritten(),
2975 template<typename Derived
>
2976 bool TreeTransform
<Derived
>::
2977 TransformFunctionTypeParams(FunctionProtoTypeLoc TL
,
2978 llvm::SmallVectorImpl
<QualType
> &PTypes
,
2979 llvm::SmallVectorImpl
<ParmVarDecl
*> &PVars
) {
2980 FunctionProtoType
*T
= TL
.getTypePtr();
2982 for (unsigned i
= 0, e
= TL
.getNumArgs(); i
!= e
; ++i
) {
2983 ParmVarDecl
*OldParm
= TL
.getArg(i
);
2986 ParmVarDecl
*NewParm
;
2989 NewParm
= getDerived().TransformFunctionTypeParam(OldParm
);
2992 NewType
= NewParm
->getType();
2994 // Deal with the possibility that we don't have a parameter
2995 // declaration for this parameter.
2999 QualType OldType
= T
->getArgType(i
);
3000 NewType
= getDerived().TransformType(OldType
);
3001 if (NewType
.isNull())
3005 PTypes
.push_back(NewType
);
3006 PVars
.push_back(NewParm
);
3012 template<typename Derived
>
3014 TreeTransform
<Derived
>::TransformFunctionProtoType(TypeLocBuilder
&TLB
,
3015 FunctionProtoTypeLoc TL
) {
3016 // Transform the parameters and return type.
3018 // We instantiate in source order, with the return type first followed by
3019 // the parameters, because users tend to expect this (even if they shouldn't
3022 // When the function has a trailing return type, we instantiate the
3023 // parameters before the return type, since the return type can then refer
3024 // to the parameters themselves (via decltype, sizeof, etc.).
3026 llvm::SmallVector
<QualType
, 4> ParamTypes
;
3027 llvm::SmallVector
<ParmVarDecl
*, 4> ParamDecls
;
3028 FunctionProtoType
*T
= TL
.getTypePtr();
3030 QualType ResultType
;
3032 if (TL
.getTrailingReturn()) {
3033 if (getDerived().TransformFunctionTypeParams(TL
, ParamTypes
, ParamDecls
))
3036 ResultType
= getDerived().TransformType(TLB
, TL
.getResultLoc());
3037 if (ResultType
.isNull())
3041 ResultType
= getDerived().TransformType(TLB
, TL
.getResultLoc());
3042 if (ResultType
.isNull())
3045 if (getDerived().TransformFunctionTypeParams(TL
, ParamTypes
, ParamDecls
))
3049 QualType Result
= TL
.getType();
3050 if (getDerived().AlwaysRebuild() ||
3051 ResultType
!= T
->getResultType() ||
3052 !std::equal(T
->arg_type_begin(), T
->arg_type_end(), ParamTypes
.begin())) {
3053 Result
= getDerived().RebuildFunctionProtoType(ResultType
,
3059 if (Result
.isNull())
3063 FunctionProtoTypeLoc NewTL
= TLB
.push
<FunctionProtoTypeLoc
>(Result
);
3064 NewTL
.setLParenLoc(TL
.getLParenLoc());
3065 NewTL
.setRParenLoc(TL
.getRParenLoc());
3066 NewTL
.setTrailingReturn(TL
.getTrailingReturn());
3067 for (unsigned i
= 0, e
= NewTL
.getNumArgs(); i
!= e
; ++i
)
3068 NewTL
.setArg(i
, ParamDecls
[i
]);
3073 template<typename Derived
>
3074 QualType TreeTransform
<Derived
>::TransformFunctionNoProtoType(
3075 TypeLocBuilder
&TLB
,
3076 FunctionNoProtoTypeLoc TL
) {
3077 FunctionNoProtoType
*T
= TL
.getTypePtr();
3078 QualType ResultType
= getDerived().TransformType(TLB
, TL
.getResultLoc());
3079 if (ResultType
.isNull())
3082 QualType Result
= TL
.getType();
3083 if (getDerived().AlwaysRebuild() ||
3084 ResultType
!= T
->getResultType())
3085 Result
= getDerived().RebuildFunctionNoProtoType(ResultType
);
3087 FunctionNoProtoTypeLoc NewTL
= TLB
.push
<FunctionNoProtoTypeLoc
>(Result
);
3088 NewTL
.setLParenLoc(TL
.getLParenLoc());
3089 NewTL
.setRParenLoc(TL
.getRParenLoc());
3090 NewTL
.setTrailingReturn(false);
3095 template<typename Derived
> QualType
3096 TreeTransform
<Derived
>::TransformUnresolvedUsingType(TypeLocBuilder
&TLB
,
3097 UnresolvedUsingTypeLoc TL
) {
3098 UnresolvedUsingType
*T
= TL
.getTypePtr();
3099 Decl
*D
= getDerived().TransformDecl(TL
.getNameLoc(), T
->getDecl());
3103 QualType Result
= TL
.getType();
3104 if (getDerived().AlwaysRebuild() || D
!= T
->getDecl()) {
3105 Result
= getDerived().RebuildUnresolvedUsingType(D
);
3106 if (Result
.isNull())
3110 // We might get an arbitrary type spec type back. We should at
3111 // least always get a type spec type, though.
3112 TypeSpecTypeLoc NewTL
= TLB
.pushTypeSpec(Result
);
3113 NewTL
.setNameLoc(TL
.getNameLoc());
3118 template<typename Derived
>
3119 QualType TreeTransform
<Derived
>::TransformTypedefType(TypeLocBuilder
&TLB
,
3120 TypedefTypeLoc TL
) {
3121 TypedefType
*T
= TL
.getTypePtr();
3122 TypedefDecl
*Typedef
3123 = cast_or_null
<TypedefDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
3128 QualType Result
= TL
.getType();
3129 if (getDerived().AlwaysRebuild() ||
3130 Typedef
!= T
->getDecl()) {
3131 Result
= getDerived().RebuildTypedefType(Typedef
);
3132 if (Result
.isNull())
3136 TypedefTypeLoc NewTL
= TLB
.push
<TypedefTypeLoc
>(Result
);
3137 NewTL
.setNameLoc(TL
.getNameLoc());
3142 template<typename Derived
>
3143 QualType TreeTransform
<Derived
>::TransformTypeOfExprType(TypeLocBuilder
&TLB
,
3144 TypeOfExprTypeLoc TL
) {
3145 // typeof expressions are not potentially evaluated contexts
3146 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3148 ExprResult E
= getDerived().TransformExpr(TL
.getUnderlyingExpr());
3152 QualType Result
= TL
.getType();
3153 if (getDerived().AlwaysRebuild() ||
3154 E
.get() != TL
.getUnderlyingExpr()) {
3155 Result
= getDerived().RebuildTypeOfExprType(E
.get(), TL
.getTypeofLoc());
3156 if (Result
.isNull())
3161 TypeOfExprTypeLoc NewTL
= TLB
.push
<TypeOfExprTypeLoc
>(Result
);
3162 NewTL
.setTypeofLoc(TL
.getTypeofLoc());
3163 NewTL
.setLParenLoc(TL
.getLParenLoc());
3164 NewTL
.setRParenLoc(TL
.getRParenLoc());
3169 template<typename Derived
>
3170 QualType TreeTransform
<Derived
>::TransformTypeOfType(TypeLocBuilder
&TLB
,
3172 TypeSourceInfo
* Old_Under_TI
= TL
.getUnderlyingTInfo();
3173 TypeSourceInfo
* New_Under_TI
= getDerived().TransformType(Old_Under_TI
);
3177 QualType Result
= TL
.getType();
3178 if (getDerived().AlwaysRebuild() || New_Under_TI
!= Old_Under_TI
) {
3179 Result
= getDerived().RebuildTypeOfType(New_Under_TI
->getType());
3180 if (Result
.isNull())
3184 TypeOfTypeLoc NewTL
= TLB
.push
<TypeOfTypeLoc
>(Result
);
3185 NewTL
.setTypeofLoc(TL
.getTypeofLoc());
3186 NewTL
.setLParenLoc(TL
.getLParenLoc());
3187 NewTL
.setRParenLoc(TL
.getRParenLoc());
3188 NewTL
.setUnderlyingTInfo(New_Under_TI
);
3193 template<typename Derived
>
3194 QualType TreeTransform
<Derived
>::TransformDecltypeType(TypeLocBuilder
&TLB
,
3195 DecltypeTypeLoc TL
) {
3196 DecltypeType
*T
= TL
.getTypePtr();
3198 // decltype expressions are not potentially evaluated contexts
3199 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3201 ExprResult E
= getDerived().TransformExpr(T
->getUnderlyingExpr());
3205 QualType Result
= TL
.getType();
3206 if (getDerived().AlwaysRebuild() ||
3207 E
.get() != T
->getUnderlyingExpr()) {
3208 Result
= getDerived().RebuildDecltypeType(E
.get(), TL
.getNameLoc());
3209 if (Result
.isNull())
3214 DecltypeTypeLoc NewTL
= TLB
.push
<DecltypeTypeLoc
>(Result
);
3215 NewTL
.setNameLoc(TL
.getNameLoc());
3220 template<typename Derived
>
3221 QualType TreeTransform
<Derived
>::TransformRecordType(TypeLocBuilder
&TLB
,
3223 RecordType
*T
= TL
.getTypePtr();
3225 = cast_or_null
<RecordDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
3230 QualType Result
= TL
.getType();
3231 if (getDerived().AlwaysRebuild() ||
3232 Record
!= T
->getDecl()) {
3233 Result
= getDerived().RebuildRecordType(Record
);
3234 if (Result
.isNull())
3238 RecordTypeLoc NewTL
= TLB
.push
<RecordTypeLoc
>(Result
);
3239 NewTL
.setNameLoc(TL
.getNameLoc());
3244 template<typename Derived
>
3245 QualType TreeTransform
<Derived
>::TransformEnumType(TypeLocBuilder
&TLB
,
3247 EnumType
*T
= TL
.getTypePtr();
3249 = cast_or_null
<EnumDecl
>(getDerived().TransformDecl(TL
.getNameLoc(),
3254 QualType Result
= TL
.getType();
3255 if (getDerived().AlwaysRebuild() ||
3256 Enum
!= T
->getDecl()) {
3257 Result
= getDerived().RebuildEnumType(Enum
);
3258 if (Result
.isNull())
3262 EnumTypeLoc NewTL
= TLB
.push
<EnumTypeLoc
>(Result
);
3263 NewTL
.setNameLoc(TL
.getNameLoc());
3268 template<typename Derived
>
3269 QualType TreeTransform
<Derived
>::TransformInjectedClassNameType(
3270 TypeLocBuilder
&TLB
,
3271 InjectedClassNameTypeLoc TL
) {
3272 Decl
*D
= getDerived().TransformDecl(TL
.getNameLoc(),
3273 TL
.getTypePtr()->getDecl());
3274 if (!D
) return QualType();
3276 QualType T
= SemaRef
.Context
.getTypeDeclType(cast
<TypeDecl
>(D
));
3277 TLB
.pushTypeSpec(T
).setNameLoc(TL
.getNameLoc());
3282 template<typename Derived
>
3283 QualType TreeTransform
<Derived
>::TransformTemplateTypeParmType(
3284 TypeLocBuilder
&TLB
,
3285 TemplateTypeParmTypeLoc TL
) {
3286 return TransformTypeSpecType(TLB
, TL
);
3289 template<typename Derived
>
3290 QualType TreeTransform
<Derived
>::TransformSubstTemplateTypeParmType(
3291 TypeLocBuilder
&TLB
,
3292 SubstTemplateTypeParmTypeLoc TL
) {
3293 return TransformTypeSpecType(TLB
, TL
);
3296 template<typename Derived
>
3297 QualType TreeTransform
<Derived
>::TransformTemplateSpecializationType(
3298 TypeLocBuilder
&TLB
,
3299 TemplateSpecializationTypeLoc TL
) {
3300 const TemplateSpecializationType
*T
= TL
.getTypePtr();
3302 TemplateName Template
3303 = getDerived().TransformTemplateName(T
->getTemplateName());
3304 if (Template
.isNull())
3307 return getDerived().TransformTemplateSpecializationType(TLB
, TL
, Template
);
3310 template <typename Derived
>
3311 QualType TreeTransform
<Derived
>::TransformTemplateSpecializationType(
3312 TypeLocBuilder
&TLB
,
3313 TemplateSpecializationTypeLoc TL
,
3314 TemplateName Template
) {
3315 const TemplateSpecializationType
*T
= TL
.getTypePtr();
3317 TemplateArgumentListInfo NewTemplateArgs
;
3318 NewTemplateArgs
.setLAngleLoc(TL
.getLAngleLoc());
3319 NewTemplateArgs
.setRAngleLoc(TL
.getRAngleLoc());
3321 for (unsigned i
= 0, e
= T
->getNumArgs(); i
!= e
; ++i
) {
3322 TemplateArgumentLoc Loc
;
3323 if (getDerived().TransformTemplateArgument(TL
.getArgLoc(i
), Loc
))
3325 NewTemplateArgs
.addArgument(Loc
);
3328 // FIXME: maybe don't rebuild if all the template arguments are the same.
3331 getDerived().RebuildTemplateSpecializationType(Template
,
3332 TL
.getTemplateNameLoc(),
3335 if (!Result
.isNull()) {
3336 TemplateSpecializationTypeLoc NewTL
3337 = TLB
.push
<TemplateSpecializationTypeLoc
>(Result
);
3338 NewTL
.setTemplateNameLoc(TL
.getTemplateNameLoc());
3339 NewTL
.setLAngleLoc(TL
.getLAngleLoc());
3340 NewTL
.setRAngleLoc(TL
.getRAngleLoc());
3341 for (unsigned i
= 0, e
= NewTemplateArgs
.size(); i
!= e
; ++i
)
3342 NewTL
.setArgLocInfo(i
, NewTemplateArgs
[i
].getLocInfo());
3348 template<typename Derived
>
3350 TreeTransform
<Derived
>::TransformElaboratedType(TypeLocBuilder
&TLB
,
3351 ElaboratedTypeLoc TL
) {
3352 ElaboratedType
*T
= TL
.getTypePtr();
3354 NestedNameSpecifier
*NNS
= 0;
3355 // NOTE: the qualifier in an ElaboratedType is optional.
3356 if (T
->getQualifier() != 0) {
3357 NNS
= getDerived().TransformNestedNameSpecifier(T
->getQualifier(),
3358 TL
.getQualifierRange());
3363 QualType NamedT
= getDerived().TransformType(TLB
, TL
.getNamedTypeLoc());
3364 if (NamedT
.isNull())
3367 QualType Result
= TL
.getType();
3368 if (getDerived().AlwaysRebuild() ||
3369 NNS
!= T
->getQualifier() ||
3370 NamedT
!= T
->getNamedType()) {
3371 Result
= getDerived().RebuildElaboratedType(TL
.getKeywordLoc(),
3372 T
->getKeyword(), NNS
, NamedT
);
3373 if (Result
.isNull())
3377 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
3378 NewTL
.setKeywordLoc(TL
.getKeywordLoc());
3379 NewTL
.setQualifierRange(TL
.getQualifierRange());
3384 template<typename Derived
>
3386 TreeTransform
<Derived
>::TransformParenType(TypeLocBuilder
&TLB
,
3388 QualType Inner
= getDerived().TransformType(TLB
, TL
.getInnerLoc());
3392 QualType Result
= TL
.getType();
3393 if (getDerived().AlwaysRebuild() ||
3394 Inner
!= TL
.getInnerLoc().getType()) {
3395 Result
= getDerived().RebuildParenType(Inner
);
3396 if (Result
.isNull())
3400 ParenTypeLoc NewTL
= TLB
.push
<ParenTypeLoc
>(Result
);
3401 NewTL
.setLParenLoc(TL
.getLParenLoc());
3402 NewTL
.setRParenLoc(TL
.getRParenLoc());
3406 template<typename Derived
>
3407 QualType TreeTransform
<Derived
>::TransformDependentNameType(TypeLocBuilder
&TLB
,
3408 DependentNameTypeLoc TL
) {
3409 DependentNameType
*T
= TL
.getTypePtr();
3411 NestedNameSpecifier
*NNS
3412 = getDerived().TransformNestedNameSpecifier(T
->getQualifier(),
3413 TL
.getQualifierRange());
3418 = getDerived().RebuildDependentNameType(T
->getKeyword(), NNS
,
3421 TL
.getQualifierRange(),
3423 if (Result
.isNull())
3426 if (const ElaboratedType
* ElabT
= Result
->getAs
<ElaboratedType
>()) {
3427 QualType NamedT
= ElabT
->getNamedType();
3428 TLB
.pushTypeSpec(NamedT
).setNameLoc(TL
.getNameLoc());
3430 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
3431 NewTL
.setKeywordLoc(TL
.getKeywordLoc());
3432 NewTL
.setQualifierRange(TL
.getQualifierRange());
3434 DependentNameTypeLoc NewTL
= TLB
.push
<DependentNameTypeLoc
>(Result
);
3435 NewTL
.setKeywordLoc(TL
.getKeywordLoc());
3436 NewTL
.setQualifierRange(TL
.getQualifierRange());
3437 NewTL
.setNameLoc(TL
.getNameLoc());
3442 template<typename Derived
>
3443 QualType TreeTransform
<Derived
>::
3444 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
3445 DependentTemplateSpecializationTypeLoc TL
) {
3446 DependentTemplateSpecializationType
*T
= TL
.getTypePtr();
3448 NestedNameSpecifier
*NNS
3449 = getDerived().TransformNestedNameSpecifier(T
->getQualifier(),
3450 TL
.getQualifierRange());
3455 .TransformDependentTemplateSpecializationType(TLB
, TL
, NNS
);
3458 template<typename Derived
>
3459 QualType TreeTransform
<Derived
>::
3460 TransformDependentTemplateSpecializationType(TypeLocBuilder
&TLB
,
3461 DependentTemplateSpecializationTypeLoc TL
,
3462 NestedNameSpecifier
*NNS
) {
3463 DependentTemplateSpecializationType
*T
= TL
.getTypePtr();
3465 TemplateArgumentListInfo NewTemplateArgs
;
3466 NewTemplateArgs
.setLAngleLoc(TL
.getLAngleLoc());
3467 NewTemplateArgs
.setRAngleLoc(TL
.getRAngleLoc());
3469 for (unsigned I
= 0, E
= T
->getNumArgs(); I
!= E
; ++I
) {
3470 TemplateArgumentLoc Loc
;
3471 if (getDerived().TransformTemplateArgument(TL
.getArgLoc(I
), Loc
))
3473 NewTemplateArgs
.addArgument(Loc
);
3477 = getDerived().RebuildDependentTemplateSpecializationType(T
->getKeyword(),
3479 TL
.getQualifierRange(),
3483 if (Result
.isNull())
3486 if (const ElaboratedType
*ElabT
= dyn_cast
<ElaboratedType
>(Result
)) {
3487 QualType NamedT
= ElabT
->getNamedType();
3489 // Copy information relevant to the template specialization.
3490 TemplateSpecializationTypeLoc NamedTL
3491 = TLB
.push
<TemplateSpecializationTypeLoc
>(NamedT
);
3492 NamedTL
.setLAngleLoc(TL
.getLAngleLoc());
3493 NamedTL
.setRAngleLoc(TL
.getRAngleLoc());
3494 for (unsigned I
= 0, E
= TL
.getNumArgs(); I
!= E
; ++I
)
3495 NamedTL
.setArgLocInfo(I
, TL
.getArgLocInfo(I
));
3497 // Copy information relevant to the elaborated type.
3498 ElaboratedTypeLoc NewTL
= TLB
.push
<ElaboratedTypeLoc
>(Result
);
3499 NewTL
.setKeywordLoc(TL
.getKeywordLoc());
3500 NewTL
.setQualifierRange(TL
.getQualifierRange());
3502 TypeLoc
NewTL(Result
, TL
.getOpaqueData());
3503 TLB
.pushFullCopy(NewTL
);
3508 template<typename Derived
>
3510 TreeTransform
<Derived
>::TransformObjCInterfaceType(TypeLocBuilder
&TLB
,
3511 ObjCInterfaceTypeLoc TL
) {
3512 // ObjCInterfaceType is never dependent.
3513 TLB
.pushFullCopy(TL
);
3514 return TL
.getType();
3517 template<typename Derived
>
3519 TreeTransform
<Derived
>::TransformObjCObjectType(TypeLocBuilder
&TLB
,
3520 ObjCObjectTypeLoc TL
) {
3521 // ObjCObjectType is never dependent.
3522 TLB
.pushFullCopy(TL
);
3523 return TL
.getType();
3526 template<typename Derived
>
3528 TreeTransform
<Derived
>::TransformObjCObjectPointerType(TypeLocBuilder
&TLB
,
3529 ObjCObjectPointerTypeLoc TL
) {
3530 // ObjCObjectPointerType is never dependent.
3531 TLB
.pushFullCopy(TL
);
3532 return TL
.getType();
3535 //===----------------------------------------------------------------------===//
3536 // Statement transformation
3537 //===----------------------------------------------------------------------===//
3538 template<typename Derived
>
3540 TreeTransform
<Derived
>::TransformNullStmt(NullStmt
*S
) {
3541 return SemaRef
.Owned(S
);
3544 template<typename Derived
>
3546 TreeTransform
<Derived
>::TransformCompoundStmt(CompoundStmt
*S
) {
3547 return getDerived().TransformCompoundStmt(S
, false);
3550 template<typename Derived
>
3552 TreeTransform
<Derived
>::TransformCompoundStmt(CompoundStmt
*S
,
3554 bool SubStmtInvalid
= false;
3555 bool SubStmtChanged
= false;
3556 ASTOwningVector
<Stmt
*> Statements(getSema());
3557 for (CompoundStmt::body_iterator B
= S
->body_begin(), BEnd
= S
->body_end();
3559 StmtResult Result
= getDerived().TransformStmt(*B
);
3560 if (Result
.isInvalid()) {
3561 // Immediately fail if this was a DeclStmt, since it's very
3562 // likely that this will cause problems for future statements.
3563 if (isa
<DeclStmt
>(*B
))
3566 // Otherwise, just keep processing substatements and fail later.
3567 SubStmtInvalid
= true;
3571 SubStmtChanged
= SubStmtChanged
|| Result
.get() != *B
;
3572 Statements
.push_back(Result
.takeAs
<Stmt
>());
3578 if (!getDerived().AlwaysRebuild() &&
3580 return SemaRef
.Owned(S
);
3582 return getDerived().RebuildCompoundStmt(S
->getLBracLoc(),
3583 move_arg(Statements
),
3588 template<typename Derived
>
3590 TreeTransform
<Derived
>::TransformCaseStmt(CaseStmt
*S
) {
3591 ExprResult LHS
, RHS
;
3593 // The case value expressions are not potentially evaluated.
3594 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
3596 // Transform the left-hand case value.
3597 LHS
= getDerived().TransformExpr(S
->getLHS());
3598 if (LHS
.isInvalid())
3601 // Transform the right-hand case value (for the GNU case-range extension).
3602 RHS
= getDerived().TransformExpr(S
->getRHS());
3603 if (RHS
.isInvalid())
3607 // Build the case statement.
3608 // Case statements are always rebuilt so that they will attached to their
3609 // transformed switch statement.
3610 StmtResult Case
= getDerived().RebuildCaseStmt(S
->getCaseLoc(),
3612 S
->getEllipsisLoc(),
3615 if (Case
.isInvalid())
3618 // Transform the statement following the case
3619 StmtResult SubStmt
= getDerived().TransformStmt(S
->getSubStmt());
3620 if (SubStmt
.isInvalid())
3623 // Attach the body to the case statement
3624 return getDerived().RebuildCaseStmtBody(Case
.get(), SubStmt
.get());
3627 template<typename Derived
>
3629 TreeTransform
<Derived
>::TransformDefaultStmt(DefaultStmt
*S
) {
3630 // Transform the statement following the default case
3631 StmtResult SubStmt
= getDerived().TransformStmt(S
->getSubStmt());
3632 if (SubStmt
.isInvalid())
3635 // Default statements are always rebuilt
3636 return getDerived().RebuildDefaultStmt(S
->getDefaultLoc(), S
->getColonLoc(),
3640 template<typename Derived
>
3642 TreeTransform
<Derived
>::TransformLabelStmt(LabelStmt
*S
) {
3643 StmtResult SubStmt
= getDerived().TransformStmt(S
->getSubStmt());
3644 if (SubStmt
.isInvalid())
3647 // FIXME: Pass the real colon location in.
3648 SourceLocation ColonLoc
= SemaRef
.PP
.getLocForEndOfToken(S
->getIdentLoc());
3649 return getDerived().RebuildLabelStmt(S
->getIdentLoc(), S
->getID(), ColonLoc
,
3650 SubStmt
.get(), S
->HasUnusedAttribute());
3653 template<typename Derived
>
3655 TreeTransform
<Derived
>::TransformIfStmt(IfStmt
*S
) {
3656 // Transform the condition
3658 VarDecl
*ConditionVar
= 0;
3659 if (S
->getConditionVariable()) {
3661 = cast_or_null
<VarDecl
>(
3662 getDerived().TransformDefinition(
3663 S
->getConditionVariable()->getLocation(),
3664 S
->getConditionVariable()));
3668 Cond
= getDerived().TransformExpr(S
->getCond());
3670 if (Cond
.isInvalid())
3673 // Convert the condition to a boolean value.
3675 ExprResult CondE
= getSema().ActOnBooleanCondition(0,
3678 if (CondE
.isInvalid())
3685 Sema::FullExprArg
FullCond(getSema().MakeFullExpr(Cond
.take()));
3686 if (!S
->getConditionVariable() && S
->getCond() && !FullCond
.get())
3689 // Transform the "then" branch.
3690 StmtResult Then
= getDerived().TransformStmt(S
->getThen());
3691 if (Then
.isInvalid())
3694 // Transform the "else" branch.
3695 StmtResult Else
= getDerived().TransformStmt(S
->getElse());
3696 if (Else
.isInvalid())
3699 if (!getDerived().AlwaysRebuild() &&
3700 FullCond
.get() == S
->getCond() &&
3701 ConditionVar
== S
->getConditionVariable() &&
3702 Then
.get() == S
->getThen() &&
3703 Else
.get() == S
->getElse())
3704 return SemaRef
.Owned(S
);
3706 return getDerived().RebuildIfStmt(S
->getIfLoc(), FullCond
, ConditionVar
,
3708 S
->getElseLoc(), Else
.get());
3711 template<typename Derived
>
3713 TreeTransform
<Derived
>::TransformSwitchStmt(SwitchStmt
*S
) {
3714 // Transform the condition.
3716 VarDecl
*ConditionVar
= 0;
3717 if (S
->getConditionVariable()) {
3719 = cast_or_null
<VarDecl
>(
3720 getDerived().TransformDefinition(
3721 S
->getConditionVariable()->getLocation(),
3722 S
->getConditionVariable()));
3726 Cond
= getDerived().TransformExpr(S
->getCond());
3728 if (Cond
.isInvalid())
3732 // Rebuild the switch statement.
3734 = getDerived().RebuildSwitchStmtStart(S
->getSwitchLoc(), Cond
.get(),
3736 if (Switch
.isInvalid())
3739 // Transform the body of the switch statement.
3740 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
3741 if (Body
.isInvalid())
3744 // Complete the switch statement.
3745 return getDerived().RebuildSwitchStmtBody(S
->getSwitchLoc(), Switch
.get(),
3749 template<typename Derived
>
3751 TreeTransform
<Derived
>::TransformWhileStmt(WhileStmt
*S
) {
3752 // Transform the condition
3754 VarDecl
*ConditionVar
= 0;
3755 if (S
->getConditionVariable()) {
3757 = cast_or_null
<VarDecl
>(
3758 getDerived().TransformDefinition(
3759 S
->getConditionVariable()->getLocation(),
3760 S
->getConditionVariable()));
3764 Cond
= getDerived().TransformExpr(S
->getCond());
3766 if (Cond
.isInvalid())
3770 // Convert the condition to a boolean value.
3771 ExprResult CondE
= getSema().ActOnBooleanCondition(0,
3774 if (CondE
.isInvalid())
3780 Sema::FullExprArg
FullCond(getSema().MakeFullExpr(Cond
.take()));
3781 if (!S
->getConditionVariable() && S
->getCond() && !FullCond
.get())
3784 // Transform the body
3785 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
3786 if (Body
.isInvalid())
3789 if (!getDerived().AlwaysRebuild() &&
3790 FullCond
.get() == S
->getCond() &&
3791 ConditionVar
== S
->getConditionVariable() &&
3792 Body
.get() == S
->getBody())
3795 return getDerived().RebuildWhileStmt(S
->getWhileLoc(), FullCond
,
3796 ConditionVar
, Body
.get());
3799 template<typename Derived
>
3801 TreeTransform
<Derived
>::TransformDoStmt(DoStmt
*S
) {
3802 // Transform the body
3803 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
3804 if (Body
.isInvalid())
3807 // Transform the condition
3808 ExprResult Cond
= getDerived().TransformExpr(S
->getCond());
3809 if (Cond
.isInvalid())
3812 if (!getDerived().AlwaysRebuild() &&
3813 Cond
.get() == S
->getCond() &&
3814 Body
.get() == S
->getBody())
3815 return SemaRef
.Owned(S
);
3817 return getDerived().RebuildDoStmt(S
->getDoLoc(), Body
.get(), S
->getWhileLoc(),
3818 /*FIXME:*/S
->getWhileLoc(), Cond
.get(),
3822 template<typename Derived
>
3824 TreeTransform
<Derived
>::TransformForStmt(ForStmt
*S
) {
3825 // Transform the initialization statement
3826 StmtResult Init
= getDerived().TransformStmt(S
->getInit());
3827 if (Init
.isInvalid())
3830 // Transform the condition
3832 VarDecl
*ConditionVar
= 0;
3833 if (S
->getConditionVariable()) {
3835 = cast_or_null
<VarDecl
>(
3836 getDerived().TransformDefinition(
3837 S
->getConditionVariable()->getLocation(),
3838 S
->getConditionVariable()));
3842 Cond
= getDerived().TransformExpr(S
->getCond());
3844 if (Cond
.isInvalid())
3848 // Convert the condition to a boolean value.
3849 ExprResult CondE
= getSema().ActOnBooleanCondition(0,
3852 if (CondE
.isInvalid())
3859 Sema::FullExprArg
FullCond(getSema().MakeFullExpr(Cond
.take()));
3860 if (!S
->getConditionVariable() && S
->getCond() && !FullCond
.get())
3863 // Transform the increment
3864 ExprResult Inc
= getDerived().TransformExpr(S
->getInc());
3865 if (Inc
.isInvalid())
3868 Sema::FullExprArg
FullInc(getSema().MakeFullExpr(Inc
.get()));
3869 if (S
->getInc() && !FullInc
.get())
3872 // Transform the body
3873 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
3874 if (Body
.isInvalid())
3877 if (!getDerived().AlwaysRebuild() &&
3878 Init
.get() == S
->getInit() &&
3879 FullCond
.get() == S
->getCond() &&
3880 Inc
.get() == S
->getInc() &&
3881 Body
.get() == S
->getBody())
3882 return SemaRef
.Owned(S
);
3884 return getDerived().RebuildForStmt(S
->getForLoc(), S
->getLParenLoc(),
3885 Init
.get(), FullCond
, ConditionVar
,
3886 FullInc
, S
->getRParenLoc(), Body
.get());
3889 template<typename Derived
>
3891 TreeTransform
<Derived
>::TransformGotoStmt(GotoStmt
*S
) {
3892 // Goto statements must always be rebuilt, to resolve the label.
3893 return getDerived().RebuildGotoStmt(S
->getGotoLoc(), S
->getLabelLoc(),
3897 template<typename Derived
>
3899 TreeTransform
<Derived
>::TransformIndirectGotoStmt(IndirectGotoStmt
*S
) {
3900 ExprResult Target
= getDerived().TransformExpr(S
->getTarget());
3901 if (Target
.isInvalid())
3904 if (!getDerived().AlwaysRebuild() &&
3905 Target
.get() == S
->getTarget())
3906 return SemaRef
.Owned(S
);
3908 return getDerived().RebuildIndirectGotoStmt(S
->getGotoLoc(), S
->getStarLoc(),
3912 template<typename Derived
>
3914 TreeTransform
<Derived
>::TransformContinueStmt(ContinueStmt
*S
) {
3915 return SemaRef
.Owned(S
);
3918 template<typename Derived
>
3920 TreeTransform
<Derived
>::TransformBreakStmt(BreakStmt
*S
) {
3921 return SemaRef
.Owned(S
);
3924 template<typename Derived
>
3926 TreeTransform
<Derived
>::TransformReturnStmt(ReturnStmt
*S
) {
3927 ExprResult Result
= getDerived().TransformExpr(S
->getRetValue());
3928 if (Result
.isInvalid())
3931 // FIXME: We always rebuild the return statement because there is no way
3932 // to tell whether the return type of the function has changed.
3933 return getDerived().RebuildReturnStmt(S
->getReturnLoc(), Result
.get());
3936 template<typename Derived
>
3938 TreeTransform
<Derived
>::TransformDeclStmt(DeclStmt
*S
) {
3939 bool DeclChanged
= false;
3940 llvm::SmallVector
<Decl
*, 4> Decls
;
3941 for (DeclStmt::decl_iterator D
= S
->decl_begin(), DEnd
= S
->decl_end();
3943 Decl
*Transformed
= getDerived().TransformDefinition((*D
)->getLocation(),
3948 if (Transformed
!= *D
)
3951 Decls
.push_back(Transformed
);
3954 if (!getDerived().AlwaysRebuild() && !DeclChanged
)
3955 return SemaRef
.Owned(S
);
3957 return getDerived().RebuildDeclStmt(Decls
.data(), Decls
.size(),
3958 S
->getStartLoc(), S
->getEndLoc());
3961 template<typename Derived
>
3963 TreeTransform
<Derived
>::TransformSwitchCase(SwitchCase
*S
) {
3964 assert(false && "SwitchCase is abstract and cannot be transformed");
3965 return SemaRef
.Owned(S
);
3968 template<typename Derived
>
3970 TreeTransform
<Derived
>::TransformAsmStmt(AsmStmt
*S
) {
3972 ASTOwningVector
<Expr
*> Constraints(getSema());
3973 ASTOwningVector
<Expr
*> Exprs(getSema());
3974 llvm::SmallVector
<IdentifierInfo
*, 4> Names
;
3976 ExprResult AsmString
;
3977 ASTOwningVector
<Expr
*> Clobbers(getSema());
3979 bool ExprsChanged
= false;
3981 // Go through the outputs.
3982 for (unsigned I
= 0, E
= S
->getNumOutputs(); I
!= E
; ++I
) {
3983 Names
.push_back(S
->getOutputIdentifier(I
));
3985 // No need to transform the constraint literal.
3986 Constraints
.push_back(S
->getOutputConstraintLiteral(I
));
3988 // Transform the output expr.
3989 Expr
*OutputExpr
= S
->getOutputExpr(I
);
3990 ExprResult Result
= getDerived().TransformExpr(OutputExpr
);
3991 if (Result
.isInvalid())
3994 ExprsChanged
|= Result
.get() != OutputExpr
;
3996 Exprs
.push_back(Result
.get());
3999 // Go through the inputs.
4000 for (unsigned I
= 0, E
= S
->getNumInputs(); I
!= E
; ++I
) {
4001 Names
.push_back(S
->getInputIdentifier(I
));
4003 // No need to transform the constraint literal.
4004 Constraints
.push_back(S
->getInputConstraintLiteral(I
));
4006 // Transform the input expr.
4007 Expr
*InputExpr
= S
->getInputExpr(I
);
4008 ExprResult Result
= getDerived().TransformExpr(InputExpr
);
4009 if (Result
.isInvalid())
4012 ExprsChanged
|= Result
.get() != InputExpr
;
4014 Exprs
.push_back(Result
.get());
4017 if (!getDerived().AlwaysRebuild() && !ExprsChanged
)
4018 return SemaRef
.Owned(S
);
4020 // Go through the clobbers.
4021 for (unsigned I
= 0, E
= S
->getNumClobbers(); I
!= E
; ++I
)
4022 Clobbers
.push_back(S
->getClobber(I
));
4024 // No need to transform the asm string literal.
4025 AsmString
= SemaRef
.Owned(S
->getAsmString());
4027 return getDerived().RebuildAsmStmt(S
->getAsmLoc(),
4033 move_arg(Constraints
),
4042 template<typename Derived
>
4044 TreeTransform
<Derived
>::TransformObjCAtTryStmt(ObjCAtTryStmt
*S
) {
4045 // Transform the body of the @try.
4046 StmtResult TryBody
= getDerived().TransformStmt(S
->getTryBody());
4047 if (TryBody
.isInvalid())
4050 // Transform the @catch statements (if present).
4051 bool AnyCatchChanged
= false;
4052 ASTOwningVector
<Stmt
*> CatchStmts(SemaRef
);
4053 for (unsigned I
= 0, N
= S
->getNumCatchStmts(); I
!= N
; ++I
) {
4054 StmtResult Catch
= getDerived().TransformStmt(S
->getCatchStmt(I
));
4055 if (Catch
.isInvalid())
4057 if (Catch
.get() != S
->getCatchStmt(I
))
4058 AnyCatchChanged
= true;
4059 CatchStmts
.push_back(Catch
.release());
4062 // Transform the @finally statement (if present).
4064 if (S
->getFinallyStmt()) {
4065 Finally
= getDerived().TransformStmt(S
->getFinallyStmt());
4066 if (Finally
.isInvalid())
4070 // If nothing changed, just retain this statement.
4071 if (!getDerived().AlwaysRebuild() &&
4072 TryBody
.get() == S
->getTryBody() &&
4074 Finally
.get() == S
->getFinallyStmt())
4075 return SemaRef
.Owned(S
);
4077 // Build a new statement.
4078 return getDerived().RebuildObjCAtTryStmt(S
->getAtTryLoc(), TryBody
.get(),
4079 move_arg(CatchStmts
), Finally
.get());
4082 template<typename Derived
>
4084 TreeTransform
<Derived
>::TransformObjCAtCatchStmt(ObjCAtCatchStmt
*S
) {
4085 // Transform the @catch parameter, if there is one.
4087 if (VarDecl
*FromVar
= S
->getCatchParamDecl()) {
4088 TypeSourceInfo
*TSInfo
= 0;
4089 if (FromVar
->getTypeSourceInfo()) {
4090 TSInfo
= getDerived().TransformType(FromVar
->getTypeSourceInfo());
4097 T
= TSInfo
->getType();
4099 T
= getDerived().TransformType(FromVar
->getType());
4104 Var
= getDerived().RebuildObjCExceptionDecl(FromVar
, TSInfo
, T
);
4109 StmtResult Body
= getDerived().TransformStmt(S
->getCatchBody());
4110 if (Body
.isInvalid())
4113 return getDerived().RebuildObjCAtCatchStmt(S
->getAtCatchLoc(),
4118 template<typename Derived
>
4120 TreeTransform
<Derived
>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt
*S
) {
4121 // Transform the body.
4122 StmtResult Body
= getDerived().TransformStmt(S
->getFinallyBody());
4123 if (Body
.isInvalid())
4126 // If nothing changed, just retain this statement.
4127 if (!getDerived().AlwaysRebuild() &&
4128 Body
.get() == S
->getFinallyBody())
4129 return SemaRef
.Owned(S
);
4131 // Build a new statement.
4132 return getDerived().RebuildObjCAtFinallyStmt(S
->getAtFinallyLoc(),
4136 template<typename Derived
>
4138 TreeTransform
<Derived
>::TransformObjCAtThrowStmt(ObjCAtThrowStmt
*S
) {
4140 if (S
->getThrowExpr()) {
4141 Operand
= getDerived().TransformExpr(S
->getThrowExpr());
4142 if (Operand
.isInvalid())
4146 if (!getDerived().AlwaysRebuild() &&
4147 Operand
.get() == S
->getThrowExpr())
4148 return getSema().Owned(S
);
4150 return getDerived().RebuildObjCAtThrowStmt(S
->getThrowLoc(), Operand
.get());
4153 template<typename Derived
>
4155 TreeTransform
<Derived
>::TransformObjCAtSynchronizedStmt(
4156 ObjCAtSynchronizedStmt
*S
) {
4157 // Transform the object we are locking.
4158 ExprResult Object
= getDerived().TransformExpr(S
->getSynchExpr());
4159 if (Object
.isInvalid())
4162 // Transform the body.
4163 StmtResult Body
= getDerived().TransformStmt(S
->getSynchBody());
4164 if (Body
.isInvalid())
4167 // If nothing change, just retain the current statement.
4168 if (!getDerived().AlwaysRebuild() &&
4169 Object
.get() == S
->getSynchExpr() &&
4170 Body
.get() == S
->getSynchBody())
4171 return SemaRef
.Owned(S
);
4173 // Build a new statement.
4174 return getDerived().RebuildObjCAtSynchronizedStmt(S
->getAtSynchronizedLoc(),
4175 Object
.get(), Body
.get());
4178 template<typename Derived
>
4180 TreeTransform
<Derived
>::TransformObjCForCollectionStmt(
4181 ObjCForCollectionStmt
*S
) {
4182 // Transform the element statement.
4183 StmtResult Element
= getDerived().TransformStmt(S
->getElement());
4184 if (Element
.isInvalid())
4187 // Transform the collection expression.
4188 ExprResult Collection
= getDerived().TransformExpr(S
->getCollection());
4189 if (Collection
.isInvalid())
4192 // Transform the body.
4193 StmtResult Body
= getDerived().TransformStmt(S
->getBody());
4194 if (Body
.isInvalid())
4197 // If nothing changed, just retain this statement.
4198 if (!getDerived().AlwaysRebuild() &&
4199 Element
.get() == S
->getElement() &&
4200 Collection
.get() == S
->getCollection() &&
4201 Body
.get() == S
->getBody())
4202 return SemaRef
.Owned(S
);
4204 // Build a new statement.
4205 return getDerived().RebuildObjCForCollectionStmt(S
->getForLoc(),
4206 /*FIXME:*/S
->getForLoc(),
4214 template<typename Derived
>
4216 TreeTransform
<Derived
>::TransformCXXCatchStmt(CXXCatchStmt
*S
) {
4217 // Transform the exception declaration, if any.
4219 if (S
->getExceptionDecl()) {
4220 VarDecl
*ExceptionDecl
= S
->getExceptionDecl();
4221 TypeSourceInfo
*T
= getDerived().TransformType(
4222 ExceptionDecl
->getTypeSourceInfo());
4226 Var
= getDerived().RebuildExceptionDecl(ExceptionDecl
, T
,
4227 ExceptionDecl
->getIdentifier(),
4228 ExceptionDecl
->getLocation());
4229 if (!Var
|| Var
->isInvalidDecl())
4233 // Transform the actual exception handler.
4234 StmtResult Handler
= getDerived().TransformStmt(S
->getHandlerBlock());
4235 if (Handler
.isInvalid())
4238 if (!getDerived().AlwaysRebuild() &&
4240 Handler
.get() == S
->getHandlerBlock())
4241 return SemaRef
.Owned(S
);
4243 return getDerived().RebuildCXXCatchStmt(S
->getCatchLoc(),
4248 template<typename Derived
>
4250 TreeTransform
<Derived
>::TransformCXXTryStmt(CXXTryStmt
*S
) {
4251 // Transform the try block itself.
4253 = getDerived().TransformCompoundStmt(S
->getTryBlock());
4254 if (TryBlock
.isInvalid())
4257 // Transform the handlers.
4258 bool HandlerChanged
= false;
4259 ASTOwningVector
<Stmt
*> Handlers(SemaRef
);
4260 for (unsigned I
= 0, N
= S
->getNumHandlers(); I
!= N
; ++I
) {
4262 = getDerived().TransformCXXCatchStmt(S
->getHandler(I
));
4263 if (Handler
.isInvalid())
4266 HandlerChanged
= HandlerChanged
|| Handler
.get() != S
->getHandler(I
);
4267 Handlers
.push_back(Handler
.takeAs
<Stmt
>());
4270 if (!getDerived().AlwaysRebuild() &&
4271 TryBlock
.get() == S
->getTryBlock() &&
4273 return SemaRef
.Owned(S
);
4275 return getDerived().RebuildCXXTryStmt(S
->getTryLoc(), TryBlock
.get(),
4276 move_arg(Handlers
));
4279 //===----------------------------------------------------------------------===//
4280 // Expression transformation
4281 //===----------------------------------------------------------------------===//
4282 template<typename Derived
>
4284 TreeTransform
<Derived
>::TransformPredefinedExpr(PredefinedExpr
*E
) {
4285 return SemaRef
.Owned(E
);
4288 template<typename Derived
>
4290 TreeTransform
<Derived
>::TransformDeclRefExpr(DeclRefExpr
*E
) {
4291 NestedNameSpecifier
*Qualifier
= 0;
4292 if (E
->getQualifier()) {
4293 Qualifier
= getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
4294 E
->getQualifierRange());
4300 = cast_or_null
<ValueDecl
>(getDerived().TransformDecl(E
->getLocation(),
4305 DeclarationNameInfo NameInfo
= E
->getNameInfo();
4306 if (NameInfo
.getName()) {
4307 NameInfo
= getDerived().TransformDeclarationNameInfo(NameInfo
);
4308 if (!NameInfo
.getName())
4312 if (!getDerived().AlwaysRebuild() &&
4313 Qualifier
== E
->getQualifier() &&
4314 ND
== E
->getDecl() &&
4315 NameInfo
.getName() == E
->getDecl()->getDeclName() &&
4316 !E
->hasExplicitTemplateArgs()) {
4318 // Mark it referenced in the new context regardless.
4319 // FIXME: this is a bit instantiation-specific.
4320 SemaRef
.MarkDeclarationReferenced(E
->getLocation(), ND
);
4322 return SemaRef
.Owned(E
);
4325 TemplateArgumentListInfo TransArgs
, *TemplateArgs
= 0;
4326 if (E
->hasExplicitTemplateArgs()) {
4327 TemplateArgs
= &TransArgs
;
4328 TransArgs
.setLAngleLoc(E
->getLAngleLoc());
4329 TransArgs
.setRAngleLoc(E
->getRAngleLoc());
4330 for (unsigned I
= 0, N
= E
->getNumTemplateArgs(); I
!= N
; ++I
) {
4331 TemplateArgumentLoc Loc
;
4332 if (getDerived().TransformTemplateArgument(E
->getTemplateArgs()[I
], Loc
))
4334 TransArgs
.addArgument(Loc
);
4338 return getDerived().RebuildDeclRefExpr(Qualifier
, E
->getQualifierRange(),
4339 ND
, NameInfo
, TemplateArgs
);
4342 template<typename Derived
>
4344 TreeTransform
<Derived
>::TransformIntegerLiteral(IntegerLiteral
*E
) {
4345 return SemaRef
.Owned(E
);
4348 template<typename Derived
>
4350 TreeTransform
<Derived
>::TransformFloatingLiteral(FloatingLiteral
*E
) {
4351 return SemaRef
.Owned(E
);
4354 template<typename Derived
>
4356 TreeTransform
<Derived
>::TransformImaginaryLiteral(ImaginaryLiteral
*E
) {
4357 return SemaRef
.Owned(E
);
4360 template<typename Derived
>
4362 TreeTransform
<Derived
>::TransformStringLiteral(StringLiteral
*E
) {
4363 return SemaRef
.Owned(E
);
4366 template<typename Derived
>
4368 TreeTransform
<Derived
>::TransformCharacterLiteral(CharacterLiteral
*E
) {
4369 return SemaRef
.Owned(E
);
4372 template<typename Derived
>
4374 TreeTransform
<Derived
>::TransformParenExpr(ParenExpr
*E
) {
4375 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
4376 if (SubExpr
.isInvalid())
4379 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getSubExpr())
4380 return SemaRef
.Owned(E
);
4382 return getDerived().RebuildParenExpr(SubExpr
.get(), E
->getLParen(),
4386 template<typename Derived
>
4388 TreeTransform
<Derived
>::TransformUnaryOperator(UnaryOperator
*E
) {
4389 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
4390 if (SubExpr
.isInvalid())
4393 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getSubExpr())
4394 return SemaRef
.Owned(E
);
4396 return getDerived().RebuildUnaryOperator(E
->getOperatorLoc(),
4401 template<typename Derived
>
4403 TreeTransform
<Derived
>::TransformOffsetOfExpr(OffsetOfExpr
*E
) {
4404 // Transform the type.
4405 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeSourceInfo());
4409 // Transform all of the components into components similar to what the
4411 // FIXME: It would be slightly more efficient in the non-dependent case to
4412 // just map FieldDecls, rather than requiring the rebuilder to look for
4413 // the fields again. However, __builtin_offsetof is rare enough in
4414 // template code that we don't care.
4415 bool ExprChanged
= false;
4416 typedef Sema::OffsetOfComponent Component
;
4417 typedef OffsetOfExpr::OffsetOfNode Node
;
4418 llvm::SmallVector
<Component
, 4> Components
;
4419 for (unsigned I
= 0, N
= E
->getNumComponents(); I
!= N
; ++I
) {
4420 const Node
&ON
= E
->getComponent(I
);
4422 Comp
.isBrackets
= true;
4423 Comp
.LocStart
= ON
.getRange().getBegin();
4424 Comp
.LocEnd
= ON
.getRange().getEnd();
4425 switch (ON
.getKind()) {
4427 Expr
*FromIndex
= E
->getIndexExpr(ON
.getArrayExprIndex());
4428 ExprResult Index
= getDerived().TransformExpr(FromIndex
);
4429 if (Index
.isInvalid())
4432 ExprChanged
= ExprChanged
|| Index
.get() != FromIndex
;
4433 Comp
.isBrackets
= true;
4434 Comp
.U
.E
= Index
.get();
4439 case Node::Identifier
:
4440 Comp
.isBrackets
= false;
4441 Comp
.U
.IdentInfo
= ON
.getFieldName();
4442 if (!Comp
.U
.IdentInfo
)
4448 // Will be recomputed during the rebuild.
4452 Components
.push_back(Comp
);
4455 // If nothing changed, retain the existing expression.
4456 if (!getDerived().AlwaysRebuild() &&
4457 Type
== E
->getTypeSourceInfo() &&
4459 return SemaRef
.Owned(E
);
4461 // Build a new offsetof expression.
4462 return getDerived().RebuildOffsetOfExpr(E
->getOperatorLoc(), Type
,
4463 Components
.data(), Components
.size(),
4467 template<typename Derived
>
4469 TreeTransform
<Derived
>::TransformOpaqueValueExpr(OpaqueValueExpr
*E
) {
4470 assert(getDerived().AlreadyTransformed(E
->getType()) &&
4471 "opaque value expression requires transformation");
4472 return SemaRef
.Owned(E
);
4475 template<typename Derived
>
4477 TreeTransform
<Derived
>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr
*E
) {
4478 if (E
->isArgumentType()) {
4479 TypeSourceInfo
*OldT
= E
->getArgumentTypeInfo();
4481 TypeSourceInfo
*NewT
= getDerived().TransformType(OldT
);
4485 if (!getDerived().AlwaysRebuild() && OldT
== NewT
)
4486 return SemaRef
.Owned(E
);
4488 return getDerived().RebuildSizeOfAlignOf(NewT
, E
->getOperatorLoc(),
4490 E
->getSourceRange());
4495 // C++0x [expr.sizeof]p1:
4496 // The operand is either an expression, which is an unevaluated operand
4498 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
4500 SubExpr
= getDerived().TransformExpr(E
->getArgumentExpr());
4501 if (SubExpr
.isInvalid())
4504 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getArgumentExpr())
4505 return SemaRef
.Owned(E
);
4508 return getDerived().RebuildSizeOfAlignOf(SubExpr
.get(), E
->getOperatorLoc(),
4510 E
->getSourceRange());
4513 template<typename Derived
>
4515 TreeTransform
<Derived
>::TransformArraySubscriptExpr(ArraySubscriptExpr
*E
) {
4516 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
4517 if (LHS
.isInvalid())
4520 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
4521 if (RHS
.isInvalid())
4525 if (!getDerived().AlwaysRebuild() &&
4526 LHS
.get() == E
->getLHS() &&
4527 RHS
.get() == E
->getRHS())
4528 return SemaRef
.Owned(E
);
4530 return getDerived().RebuildArraySubscriptExpr(LHS
.get(),
4531 /*FIXME:*/E
->getLHS()->getLocStart(),
4533 E
->getRBracketLoc());
4536 template<typename Derived
>
4538 TreeTransform
<Derived
>::TransformCallExpr(CallExpr
*E
) {
4539 // Transform the callee.
4540 ExprResult Callee
= getDerived().TransformExpr(E
->getCallee());
4541 if (Callee
.isInvalid())
4544 // Transform arguments.
4545 bool ArgChanged
= false;
4546 ASTOwningVector
<Expr
*> Args(SemaRef
);
4547 for (unsigned I
= 0, N
= E
->getNumArgs(); I
!= N
; ++I
) {
4548 ExprResult Arg
= getDerived().TransformExpr(E
->getArg(I
));
4549 if (Arg
.isInvalid())
4552 ArgChanged
= ArgChanged
|| Arg
.get() != E
->getArg(I
);
4553 Args
.push_back(Arg
.get());
4556 if (!getDerived().AlwaysRebuild() &&
4557 Callee
.get() == E
->getCallee() &&
4559 return SemaRef
.Owned(E
);
4561 // FIXME: Wrong source location information for the '('.
4562 SourceLocation FakeLParenLoc
4563 = ((Expr
*)Callee
.get())->getSourceRange().getBegin();
4564 return getDerived().RebuildCallExpr(Callee
.get(), FakeLParenLoc
,
4569 template<typename Derived
>
4571 TreeTransform
<Derived
>::TransformMemberExpr(MemberExpr
*E
) {
4572 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
4573 if (Base
.isInvalid())
4576 NestedNameSpecifier
*Qualifier
= 0;
4577 if (E
->hasQualifier()) {
4579 = getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
4580 E
->getQualifierRange());
4586 = cast_or_null
<ValueDecl
>(getDerived().TransformDecl(E
->getMemberLoc(),
4587 E
->getMemberDecl()));
4591 NamedDecl
*FoundDecl
= E
->getFoundDecl();
4592 if (FoundDecl
== E
->getMemberDecl()) {
4595 FoundDecl
= cast_or_null
<NamedDecl
>(
4596 getDerived().TransformDecl(E
->getMemberLoc(), FoundDecl
));
4601 if (!getDerived().AlwaysRebuild() &&
4602 Base
.get() == E
->getBase() &&
4603 Qualifier
== E
->getQualifier() &&
4604 Member
== E
->getMemberDecl() &&
4605 FoundDecl
== E
->getFoundDecl() &&
4606 !E
->hasExplicitTemplateArgs()) {
4608 // Mark it referenced in the new context regardless.
4609 // FIXME: this is a bit instantiation-specific.
4610 SemaRef
.MarkDeclarationReferenced(E
->getMemberLoc(), Member
);
4611 return SemaRef
.Owned(E
);
4614 TemplateArgumentListInfo TransArgs
;
4615 if (E
->hasExplicitTemplateArgs()) {
4616 TransArgs
.setLAngleLoc(E
->getLAngleLoc());
4617 TransArgs
.setRAngleLoc(E
->getRAngleLoc());
4618 for (unsigned I
= 0, N
= E
->getNumTemplateArgs(); I
!= N
; ++I
) {
4619 TemplateArgumentLoc Loc
;
4620 if (getDerived().TransformTemplateArgument(E
->getTemplateArgs()[I
], Loc
))
4622 TransArgs
.addArgument(Loc
);
4626 // FIXME: Bogus source location for the operator
4627 SourceLocation FakeOperatorLoc
4628 = SemaRef
.PP
.getLocForEndOfToken(E
->getBase()->getSourceRange().getEnd());
4630 // FIXME: to do this check properly, we will need to preserve the
4631 // first-qualifier-in-scope here, just in case we had a dependent
4632 // base (and therefore couldn't do the check) and a
4633 // nested-name-qualifier (and therefore could do the lookup).
4634 NamedDecl
*FirstQualifierInScope
= 0;
4636 return getDerived().RebuildMemberExpr(Base
.get(), FakeOperatorLoc
,
4639 E
->getQualifierRange(),
4640 E
->getMemberNameInfo(),
4643 (E
->hasExplicitTemplateArgs()
4645 FirstQualifierInScope
);
4648 template<typename Derived
>
4650 TreeTransform
<Derived
>::TransformBinaryOperator(BinaryOperator
*E
) {
4651 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
4652 if (LHS
.isInvalid())
4655 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
4656 if (RHS
.isInvalid())
4659 if (!getDerived().AlwaysRebuild() &&
4660 LHS
.get() == E
->getLHS() &&
4661 RHS
.get() == E
->getRHS())
4662 return SemaRef
.Owned(E
);
4664 return getDerived().RebuildBinaryOperator(E
->getOperatorLoc(), E
->getOpcode(),
4665 LHS
.get(), RHS
.get());
4668 template<typename Derived
>
4670 TreeTransform
<Derived
>::TransformCompoundAssignOperator(
4671 CompoundAssignOperator
*E
) {
4672 return getDerived().TransformBinaryOperator(E
);
4675 template<typename Derived
>
4677 TreeTransform
<Derived
>::TransformConditionalOperator(ConditionalOperator
*E
) {
4678 ExprResult Cond
= getDerived().TransformExpr(E
->getCond());
4679 if (Cond
.isInvalid())
4682 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
4683 if (LHS
.isInvalid())
4686 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
4687 if (RHS
.isInvalid())
4690 if (!getDerived().AlwaysRebuild() &&
4691 Cond
.get() == E
->getCond() &&
4692 LHS
.get() == E
->getLHS() &&
4693 RHS
.get() == E
->getRHS())
4694 return SemaRef
.Owned(E
);
4696 return getDerived().RebuildConditionalOperator(Cond
.get(),
4697 E
->getQuestionLoc(),
4703 template<typename Derived
>
4705 TreeTransform
<Derived
>::TransformImplicitCastExpr(ImplicitCastExpr
*E
) {
4706 // Implicit casts are eliminated during transformation, since they
4707 // will be recomputed by semantic analysis after transformation.
4708 return getDerived().TransformExpr(E
->getSubExprAsWritten());
4711 template<typename Derived
>
4713 TreeTransform
<Derived
>::TransformCStyleCastExpr(CStyleCastExpr
*E
) {
4714 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeInfoAsWritten());
4719 = getDerived().TransformExpr(E
->getSubExprAsWritten());
4720 if (SubExpr
.isInvalid())
4723 if (!getDerived().AlwaysRebuild() &&
4724 Type
== E
->getTypeInfoAsWritten() &&
4725 SubExpr
.get() == E
->getSubExpr())
4726 return SemaRef
.Owned(E
);
4728 return getDerived().RebuildCStyleCastExpr(E
->getLParenLoc(),
4734 template<typename Derived
>
4736 TreeTransform
<Derived
>::TransformCompoundLiteralExpr(CompoundLiteralExpr
*E
) {
4737 TypeSourceInfo
*OldT
= E
->getTypeSourceInfo();
4738 TypeSourceInfo
*NewT
= getDerived().TransformType(OldT
);
4742 ExprResult Init
= getDerived().TransformExpr(E
->getInitializer());
4743 if (Init
.isInvalid())
4746 if (!getDerived().AlwaysRebuild() &&
4748 Init
.get() == E
->getInitializer())
4749 return SemaRef
.Owned(E
);
4751 // Note: the expression type doesn't necessarily match the
4752 // type-as-written, but that's okay, because it should always be
4753 // derivable from the initializer.
4755 return getDerived().RebuildCompoundLiteralExpr(E
->getLParenLoc(), NewT
,
4756 /*FIXME:*/E
->getInitializer()->getLocEnd(),
4760 template<typename Derived
>
4762 TreeTransform
<Derived
>::TransformExtVectorElementExpr(ExtVectorElementExpr
*E
) {
4763 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
4764 if (Base
.isInvalid())
4767 if (!getDerived().AlwaysRebuild() &&
4768 Base
.get() == E
->getBase())
4769 return SemaRef
.Owned(E
);
4771 // FIXME: Bad source location
4772 SourceLocation FakeOperatorLoc
4773 = SemaRef
.PP
.getLocForEndOfToken(E
->getBase()->getLocEnd());
4774 return getDerived().RebuildExtVectorElementExpr(Base
.get(), FakeOperatorLoc
,
4775 E
->getAccessorLoc(),
4779 template<typename Derived
>
4781 TreeTransform
<Derived
>::TransformInitListExpr(InitListExpr
*E
) {
4782 bool InitChanged
= false;
4784 ASTOwningVector
<Expr
*, 4> Inits(SemaRef
);
4785 for (unsigned I
= 0, N
= E
->getNumInits(); I
!= N
; ++I
) {
4786 ExprResult Init
= getDerived().TransformExpr(E
->getInit(I
));
4787 if (Init
.isInvalid())
4790 InitChanged
= InitChanged
|| Init
.get() != E
->getInit(I
);
4791 Inits
.push_back(Init
.get());
4794 if (!getDerived().AlwaysRebuild() && !InitChanged
)
4795 return SemaRef
.Owned(E
);
4797 return getDerived().RebuildInitList(E
->getLBraceLoc(), move_arg(Inits
),
4798 E
->getRBraceLoc(), E
->getType());
4801 template<typename Derived
>
4803 TreeTransform
<Derived
>::TransformDesignatedInitExpr(DesignatedInitExpr
*E
) {
4806 // transform the initializer value
4807 ExprResult Init
= getDerived().TransformExpr(E
->getInit());
4808 if (Init
.isInvalid())
4811 // transform the designators.
4812 ASTOwningVector
<Expr
*, 4> ArrayExprs(SemaRef
);
4813 bool ExprChanged
= false;
4814 for (DesignatedInitExpr::designators_iterator D
= E
->designators_begin(),
4815 DEnd
= E
->designators_end();
4817 if (D
->isFieldDesignator()) {
4818 Desig
.AddDesignator(Designator::getField(D
->getFieldName(),
4824 if (D
->isArrayDesignator()) {
4825 ExprResult Index
= getDerived().TransformExpr(E
->getArrayIndex(*D
));
4826 if (Index
.isInvalid())
4829 Desig
.AddDesignator(Designator::getArray(Index
.get(),
4830 D
->getLBracketLoc()));
4832 ExprChanged
= ExprChanged
|| Init
.get() != E
->getArrayIndex(*D
);
4833 ArrayExprs
.push_back(Index
.release());
4837 assert(D
->isArrayRangeDesignator() && "New kind of designator?");
4839 = getDerived().TransformExpr(E
->getArrayRangeStart(*D
));
4840 if (Start
.isInvalid())
4843 ExprResult End
= getDerived().TransformExpr(E
->getArrayRangeEnd(*D
));
4844 if (End
.isInvalid())
4847 Desig
.AddDesignator(Designator::getArrayRange(Start
.get(),
4849 D
->getLBracketLoc(),
4850 D
->getEllipsisLoc()));
4852 ExprChanged
= ExprChanged
|| Start
.get() != E
->getArrayRangeStart(*D
) ||
4853 End
.get() != E
->getArrayRangeEnd(*D
);
4855 ArrayExprs
.push_back(Start
.release());
4856 ArrayExprs
.push_back(End
.release());
4859 if (!getDerived().AlwaysRebuild() &&
4860 Init
.get() == E
->getInit() &&
4862 return SemaRef
.Owned(E
);
4864 return getDerived().RebuildDesignatedInitExpr(Desig
, move_arg(ArrayExprs
),
4865 E
->getEqualOrColonLoc(),
4866 E
->usesGNUSyntax(), Init
.get());
4869 template<typename Derived
>
4871 TreeTransform
<Derived
>::TransformImplicitValueInitExpr(
4872 ImplicitValueInitExpr
*E
) {
4873 TemporaryBase
Rebase(*this, E
->getLocStart(), DeclarationName());
4875 // FIXME: Will we ever have proper type location here? Will we actually
4876 // need to transform the type?
4877 QualType T
= getDerived().TransformType(E
->getType());
4881 if (!getDerived().AlwaysRebuild() &&
4883 return SemaRef
.Owned(E
);
4885 return getDerived().RebuildImplicitValueInitExpr(T
);
4888 template<typename Derived
>
4890 TreeTransform
<Derived
>::TransformVAArgExpr(VAArgExpr
*E
) {
4891 TypeSourceInfo
*TInfo
= getDerived().TransformType(E
->getWrittenTypeInfo());
4895 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
4896 if (SubExpr
.isInvalid())
4899 if (!getDerived().AlwaysRebuild() &&
4900 TInfo
== E
->getWrittenTypeInfo() &&
4901 SubExpr
.get() == E
->getSubExpr())
4902 return SemaRef
.Owned(E
);
4904 return getDerived().RebuildVAArgExpr(E
->getBuiltinLoc(), SubExpr
.get(),
4905 TInfo
, E
->getRParenLoc());
4908 template<typename Derived
>
4910 TreeTransform
<Derived
>::TransformParenListExpr(ParenListExpr
*E
) {
4911 bool ArgumentChanged
= false;
4912 ASTOwningVector
<Expr
*, 4> Inits(SemaRef
);
4913 for (unsigned I
= 0, N
= E
->getNumExprs(); I
!= N
; ++I
) {
4914 ExprResult Init
= getDerived().TransformExpr(E
->getExpr(I
));
4915 if (Init
.isInvalid())
4918 ArgumentChanged
= ArgumentChanged
|| Init
.get() != E
->getExpr(I
);
4919 Inits
.push_back(Init
.get());
4922 return getDerived().RebuildParenListExpr(E
->getLParenLoc(),
4927 /// \brief Transform an address-of-label expression.
4929 /// By default, the transformation of an address-of-label expression always
4930 /// rebuilds the expression, so that the label identifier can be resolved to
4931 /// the corresponding label statement by semantic analysis.
4932 template<typename Derived
>
4934 TreeTransform
<Derived
>::TransformAddrLabelExpr(AddrLabelExpr
*E
) {
4935 return getDerived().RebuildAddrLabelExpr(E
->getAmpAmpLoc(), E
->getLabelLoc(),
4939 template<typename Derived
>
4941 TreeTransform
<Derived
>::TransformStmtExpr(StmtExpr
*E
) {
4943 = getDerived().TransformCompoundStmt(E
->getSubStmt(), true);
4944 if (SubStmt
.isInvalid())
4947 if (!getDerived().AlwaysRebuild() &&
4948 SubStmt
.get() == E
->getSubStmt())
4949 return SemaRef
.Owned(E
);
4951 return getDerived().RebuildStmtExpr(E
->getLParenLoc(),
4956 template<typename Derived
>
4958 TreeTransform
<Derived
>::TransformChooseExpr(ChooseExpr
*E
) {
4959 ExprResult Cond
= getDerived().TransformExpr(E
->getCond());
4960 if (Cond
.isInvalid())
4963 ExprResult LHS
= getDerived().TransformExpr(E
->getLHS());
4964 if (LHS
.isInvalid())
4967 ExprResult RHS
= getDerived().TransformExpr(E
->getRHS());
4968 if (RHS
.isInvalid())
4971 if (!getDerived().AlwaysRebuild() &&
4972 Cond
.get() == E
->getCond() &&
4973 LHS
.get() == E
->getLHS() &&
4974 RHS
.get() == E
->getRHS())
4975 return SemaRef
.Owned(E
);
4977 return getDerived().RebuildChooseExpr(E
->getBuiltinLoc(),
4978 Cond
.get(), LHS
.get(), RHS
.get(),
4982 template<typename Derived
>
4984 TreeTransform
<Derived
>::TransformGNUNullExpr(GNUNullExpr
*E
) {
4985 return SemaRef
.Owned(E
);
4988 template<typename Derived
>
4990 TreeTransform
<Derived
>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr
*E
) {
4991 switch (E
->getOperator()) {
4995 case OO_Array_Delete
:
4996 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
5000 // This is a call to an object's operator().
5001 assert(E
->getNumArgs() >= 1 && "Object call is missing arguments");
5003 // Transform the object itself.
5004 ExprResult Object
= getDerived().TransformExpr(E
->getArg(0));
5005 if (Object
.isInvalid())
5008 // FIXME: Poor location information
5009 SourceLocation FakeLParenLoc
5010 = SemaRef
.PP
.getLocForEndOfToken(
5011 static_cast<Expr
*>(Object
.get())->getLocEnd());
5013 // Transform the call arguments.
5014 ASTOwningVector
<Expr
*> Args(SemaRef
);
5015 for (unsigned I
= 1, N
= E
->getNumArgs(); I
!= N
; ++I
) {
5016 if (getDerived().DropCallArgument(E
->getArg(I
)))
5019 ExprResult Arg
= getDerived().TransformExpr(E
->getArg(I
));
5020 if (Arg
.isInvalid())
5023 Args
.push_back(Arg
.release());
5026 return getDerived().RebuildCallExpr(Object
.get(), FakeLParenLoc
,
5031 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5033 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5034 #include "clang/Basic/OperatorKinds.def"
5039 case OO_Conditional
:
5040 llvm_unreachable("conditional operator is not actually overloadable");
5044 case NUM_OVERLOADED_OPERATORS
:
5045 llvm_unreachable("not an overloaded operator?");
5049 ExprResult Callee
= getDerived().TransformExpr(E
->getCallee());
5050 if (Callee
.isInvalid())
5053 ExprResult First
= getDerived().TransformExpr(E
->getArg(0));
5054 if (First
.isInvalid())
5058 if (E
->getNumArgs() == 2) {
5059 Second
= getDerived().TransformExpr(E
->getArg(1));
5060 if (Second
.isInvalid())
5064 if (!getDerived().AlwaysRebuild() &&
5065 Callee
.get() == E
->getCallee() &&
5066 First
.get() == E
->getArg(0) &&
5067 (E
->getNumArgs() != 2 || Second
.get() == E
->getArg(1)))
5068 return SemaRef
.Owned(E
);
5070 return getDerived().RebuildCXXOperatorCallExpr(E
->getOperator(),
5071 E
->getOperatorLoc(),
5077 template<typename Derived
>
5079 TreeTransform
<Derived
>::TransformCXXMemberCallExpr(CXXMemberCallExpr
*E
) {
5080 return getDerived().TransformCallExpr(E
);
5083 template<typename Derived
>
5085 TreeTransform
<Derived
>::TransformCXXNamedCastExpr(CXXNamedCastExpr
*E
) {
5086 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeInfoAsWritten());
5091 = getDerived().TransformExpr(E
->getSubExprAsWritten());
5092 if (SubExpr
.isInvalid())
5095 if (!getDerived().AlwaysRebuild() &&
5096 Type
== E
->getTypeInfoAsWritten() &&
5097 SubExpr
.get() == E
->getSubExpr())
5098 return SemaRef
.Owned(E
);
5100 // FIXME: Poor source location information here.
5101 SourceLocation FakeLAngleLoc
5102 = SemaRef
.PP
.getLocForEndOfToken(E
->getOperatorLoc());
5103 SourceLocation FakeRAngleLoc
= E
->getSubExpr()->getSourceRange().getBegin();
5104 SourceLocation FakeRParenLoc
5105 = SemaRef
.PP
.getLocForEndOfToken(
5106 E
->getSubExpr()->getSourceRange().getEnd());
5107 return getDerived().RebuildCXXNamedCastExpr(E
->getOperatorLoc(),
5117 template<typename Derived
>
5119 TreeTransform
<Derived
>::TransformCXXStaticCastExpr(CXXStaticCastExpr
*E
) {
5120 return getDerived().TransformCXXNamedCastExpr(E
);
5123 template<typename Derived
>
5125 TreeTransform
<Derived
>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr
*E
) {
5126 return getDerived().TransformCXXNamedCastExpr(E
);
5129 template<typename Derived
>
5131 TreeTransform
<Derived
>::TransformCXXReinterpretCastExpr(
5132 CXXReinterpretCastExpr
*E
) {
5133 return getDerived().TransformCXXNamedCastExpr(E
);
5136 template<typename Derived
>
5138 TreeTransform
<Derived
>::TransformCXXConstCastExpr(CXXConstCastExpr
*E
) {
5139 return getDerived().TransformCXXNamedCastExpr(E
);
5142 template<typename Derived
>
5144 TreeTransform
<Derived
>::TransformCXXFunctionalCastExpr(
5145 CXXFunctionalCastExpr
*E
) {
5146 TypeSourceInfo
*Type
= getDerived().TransformType(E
->getTypeInfoAsWritten());
5151 = getDerived().TransformExpr(E
->getSubExprAsWritten());
5152 if (SubExpr
.isInvalid())
5155 if (!getDerived().AlwaysRebuild() &&
5156 Type
== E
->getTypeInfoAsWritten() &&
5157 SubExpr
.get() == E
->getSubExpr())
5158 return SemaRef
.Owned(E
);
5160 return getDerived().RebuildCXXFunctionalCastExpr(Type
,
5161 /*FIXME:*/E
->getSubExpr()->getLocStart(),
5166 template<typename Derived
>
5168 TreeTransform
<Derived
>::TransformCXXTypeidExpr(CXXTypeidExpr
*E
) {
5169 if (E
->isTypeOperand()) {
5170 TypeSourceInfo
*TInfo
5171 = getDerived().TransformType(E
->getTypeOperandSourceInfo());
5175 if (!getDerived().AlwaysRebuild() &&
5176 TInfo
== E
->getTypeOperandSourceInfo())
5177 return SemaRef
.Owned(E
);
5179 return getDerived().RebuildCXXTypeidExpr(E
->getType(),
5185 // We don't know whether the expression is potentially evaluated until
5186 // after we perform semantic analysis, so the expression is potentially
5187 // potentially evaluated.
5188 EnterExpressionEvaluationContext
Unevaluated(SemaRef
,
5189 Sema::PotentiallyPotentiallyEvaluated
);
5191 ExprResult SubExpr
= getDerived().TransformExpr(E
->getExprOperand());
5192 if (SubExpr
.isInvalid())
5195 if (!getDerived().AlwaysRebuild() &&
5196 SubExpr
.get() == E
->getExprOperand())
5197 return SemaRef
.Owned(E
);
5199 return getDerived().RebuildCXXTypeidExpr(E
->getType(),
5205 template<typename Derived
>
5207 TreeTransform
<Derived
>::TransformCXXUuidofExpr(CXXUuidofExpr
*E
) {
5208 if (E
->isTypeOperand()) {
5209 TypeSourceInfo
*TInfo
5210 = getDerived().TransformType(E
->getTypeOperandSourceInfo());
5214 if (!getDerived().AlwaysRebuild() &&
5215 TInfo
== E
->getTypeOperandSourceInfo())
5216 return SemaRef
.Owned(E
);
5218 return getDerived().RebuildCXXTypeidExpr(E
->getType(),
5224 // We don't know whether the expression is potentially evaluated until
5225 // after we perform semantic analysis, so the expression is potentially
5226 // potentially evaluated.
5227 EnterExpressionEvaluationContext
Unevaluated(SemaRef
, Sema::Unevaluated
);
5229 ExprResult SubExpr
= getDerived().TransformExpr(E
->getExprOperand());
5230 if (SubExpr
.isInvalid())
5233 if (!getDerived().AlwaysRebuild() &&
5234 SubExpr
.get() == E
->getExprOperand())
5235 return SemaRef
.Owned(E
);
5237 return getDerived().RebuildCXXUuidofExpr(E
->getType(),
5243 template<typename Derived
>
5245 TreeTransform
<Derived
>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr
*E
) {
5246 return SemaRef
.Owned(E
);
5249 template<typename Derived
>
5251 TreeTransform
<Derived
>::TransformCXXNullPtrLiteralExpr(
5252 CXXNullPtrLiteralExpr
*E
) {
5253 return SemaRef
.Owned(E
);
5256 template<typename Derived
>
5258 TreeTransform
<Derived
>::TransformCXXThisExpr(CXXThisExpr
*E
) {
5259 DeclContext
*DC
= getSema().getFunctionLevelDeclContext();
5260 CXXMethodDecl
*MD
= dyn_cast
<CXXMethodDecl
>(DC
);
5261 QualType T
= MD
->getThisType(getSema().Context
);
5263 if (!getDerived().AlwaysRebuild() && T
== E
->getType())
5264 return SemaRef
.Owned(E
);
5266 return getDerived().RebuildCXXThisExpr(E
->getLocStart(), T
, E
->isImplicit());
5269 template<typename Derived
>
5271 TreeTransform
<Derived
>::TransformCXXThrowExpr(CXXThrowExpr
*E
) {
5272 ExprResult SubExpr
= getDerived().TransformExpr(E
->getSubExpr());
5273 if (SubExpr
.isInvalid())
5276 if (!getDerived().AlwaysRebuild() &&
5277 SubExpr
.get() == E
->getSubExpr())
5278 return SemaRef
.Owned(E
);
5280 return getDerived().RebuildCXXThrowExpr(E
->getThrowLoc(), SubExpr
.get());
5283 template<typename Derived
>
5285 TreeTransform
<Derived
>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr
*E
) {
5287 = cast_or_null
<ParmVarDecl
>(getDerived().TransformDecl(E
->getLocStart(),
5292 if (!getDerived().AlwaysRebuild() &&
5293 Param
== E
->getParam())
5294 return SemaRef
.Owned(E
);
5296 return getDerived().RebuildCXXDefaultArgExpr(E
->getUsedLocation(), Param
);
5299 template<typename Derived
>
5301 TreeTransform
<Derived
>::TransformCXXScalarValueInitExpr(
5302 CXXScalarValueInitExpr
*E
) {
5303 TypeSourceInfo
*T
= getDerived().TransformType(E
->getTypeSourceInfo());
5307 if (!getDerived().AlwaysRebuild() &&
5308 T
== E
->getTypeSourceInfo())
5309 return SemaRef
.Owned(E
);
5311 return getDerived().RebuildCXXScalarValueInitExpr(T
,
5312 /*FIXME:*/T
->getTypeLoc().getEndLoc(),
5316 template<typename Derived
>
5318 TreeTransform
<Derived
>::TransformCXXNewExpr(CXXNewExpr
*E
) {
5319 // Transform the type that we're allocating
5320 TypeSourceInfo
*AllocTypeInfo
5321 = getDerived().TransformType(E
->getAllocatedTypeSourceInfo());
5325 // Transform the size of the array we're allocating (if any).
5326 ExprResult ArraySize
= getDerived().TransformExpr(E
->getArraySize());
5327 if (ArraySize
.isInvalid())
5330 // Transform the placement arguments (if any).
5331 bool ArgumentChanged
= false;
5332 ASTOwningVector
<Expr
*> PlacementArgs(SemaRef
);
5333 for (unsigned I
= 0, N
= E
->getNumPlacementArgs(); I
!= N
; ++I
) {
5334 if (getDerived().DropCallArgument(E
->getPlacementArg(I
))) {
5335 ArgumentChanged
= true;
5339 ExprResult Arg
= getDerived().TransformExpr(E
->getPlacementArg(I
));
5340 if (Arg
.isInvalid())
5343 ArgumentChanged
= ArgumentChanged
|| Arg
.get() != E
->getPlacementArg(I
);
5344 PlacementArgs
.push_back(Arg
.take());
5347 // transform the constructor arguments (if any).
5348 ASTOwningVector
<Expr
*> ConstructorArgs(SemaRef
);
5349 for (unsigned I
= 0, N
= E
->getNumConstructorArgs(); I
!= N
; ++I
) {
5350 if (getDerived().DropCallArgument(E
->getConstructorArg(I
))) {
5351 ArgumentChanged
= true;
5355 ExprResult Arg
= getDerived().TransformExpr(E
->getConstructorArg(I
));
5356 if (Arg
.isInvalid())
5359 ArgumentChanged
= ArgumentChanged
|| Arg
.get() != E
->getConstructorArg(I
);
5360 ConstructorArgs
.push_back(Arg
.take());
5363 // Transform constructor, new operator, and delete operator.
5364 CXXConstructorDecl
*Constructor
= 0;
5365 if (E
->getConstructor()) {
5366 Constructor
= cast_or_null
<CXXConstructorDecl
>(
5367 getDerived().TransformDecl(E
->getLocStart(),
5368 E
->getConstructor()));
5373 FunctionDecl
*OperatorNew
= 0;
5374 if (E
->getOperatorNew()) {
5375 OperatorNew
= cast_or_null
<FunctionDecl
>(
5376 getDerived().TransformDecl(E
->getLocStart(),
5377 E
->getOperatorNew()));
5382 FunctionDecl
*OperatorDelete
= 0;
5383 if (E
->getOperatorDelete()) {
5384 OperatorDelete
= cast_or_null
<FunctionDecl
>(
5385 getDerived().TransformDecl(E
->getLocStart(),
5386 E
->getOperatorDelete()));
5387 if (!OperatorDelete
)
5391 if (!getDerived().AlwaysRebuild() &&
5392 AllocTypeInfo
== E
->getAllocatedTypeSourceInfo() &&
5393 ArraySize
.get() == E
->getArraySize() &&
5394 Constructor
== E
->getConstructor() &&
5395 OperatorNew
== E
->getOperatorNew() &&
5396 OperatorDelete
== E
->getOperatorDelete() &&
5398 // Mark any declarations we need as referenced.
5399 // FIXME: instantiation-specific.
5401 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), Constructor
);
5403 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), OperatorNew
);
5405 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), OperatorDelete
);
5406 return SemaRef
.Owned(E
);
5409 QualType AllocType
= AllocTypeInfo
->getType();
5410 if (!ArraySize
.get()) {
5411 // If no array size was specified, but the new expression was
5412 // instantiated with an array type (e.g., "new T" where T is
5413 // instantiated with "int[4]"), extract the outer bound from the
5414 // array type as our array size. We do this with constant and
5415 // dependently-sized array types.
5416 const ArrayType
*ArrayT
= SemaRef
.Context
.getAsArrayType(AllocType
);
5419 } else if (const ConstantArrayType
*ConsArrayT
5420 = dyn_cast
<ConstantArrayType
>(ArrayT
)) {
5422 = SemaRef
.Owned(IntegerLiteral::Create(SemaRef
.Context
,
5423 ConsArrayT
->getSize(),
5424 SemaRef
.Context
.getSizeType(),
5425 /*FIXME:*/E
->getLocStart()));
5426 AllocType
= ConsArrayT
->getElementType();
5427 } else if (const DependentSizedArrayType
*DepArrayT
5428 = dyn_cast
<DependentSizedArrayType
>(ArrayT
)) {
5429 if (DepArrayT
->getSizeExpr()) {
5430 ArraySize
= SemaRef
.Owned(DepArrayT
->getSizeExpr());
5431 AllocType
= DepArrayT
->getElementType();
5436 return getDerived().RebuildCXXNewExpr(E
->getLocStart(),
5438 /*FIXME:*/E
->getLocStart(),
5439 move_arg(PlacementArgs
),
5440 /*FIXME:*/E
->getLocStart(),
5441 E
->getTypeIdParens(),
5445 /*FIXME:*/E
->getLocStart(),
5446 move_arg(ConstructorArgs
),
5450 template<typename Derived
>
5452 TreeTransform
<Derived
>::TransformCXXDeleteExpr(CXXDeleteExpr
*E
) {
5453 ExprResult Operand
= getDerived().TransformExpr(E
->getArgument());
5454 if (Operand
.isInvalid())
5457 // Transform the delete operator, if known.
5458 FunctionDecl
*OperatorDelete
= 0;
5459 if (E
->getOperatorDelete()) {
5460 OperatorDelete
= cast_or_null
<FunctionDecl
>(
5461 getDerived().TransformDecl(E
->getLocStart(),
5462 E
->getOperatorDelete()));
5463 if (!OperatorDelete
)
5467 if (!getDerived().AlwaysRebuild() &&
5468 Operand
.get() == E
->getArgument() &&
5469 OperatorDelete
== E
->getOperatorDelete()) {
5470 // Mark any declarations we need as referenced.
5471 // FIXME: instantiation-specific.
5473 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), OperatorDelete
);
5475 if (!E
->getArgument()->isTypeDependent()) {
5476 QualType Destroyed
= SemaRef
.Context
.getBaseElementType(
5477 E
->getDestroyedType());
5478 if (const RecordType
*DestroyedRec
= Destroyed
->getAs
<RecordType
>()) {
5479 CXXRecordDecl
*Record
= cast
<CXXRecordDecl
>(DestroyedRec
->getDecl());
5480 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(),
5481 SemaRef
.LookupDestructor(Record
));
5485 return SemaRef
.Owned(E
);
5488 return getDerived().RebuildCXXDeleteExpr(E
->getLocStart(),
5489 E
->isGlobalDelete(),
5494 template<typename Derived
>
5496 TreeTransform
<Derived
>::TransformCXXPseudoDestructorExpr(
5497 CXXPseudoDestructorExpr
*E
) {
5498 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
5499 if (Base
.isInvalid())
5502 ParsedType ObjectTypePtr
;
5503 bool MayBePseudoDestructor
= false;
5504 Base
= SemaRef
.ActOnStartCXXMemberReference(0, Base
.get(),
5505 E
->getOperatorLoc(),
5506 E
->isArrow()? tok::arrow
: tok::period
,
5508 MayBePseudoDestructor
);
5509 if (Base
.isInvalid())
5512 QualType ObjectType
= ObjectTypePtr
.get();
5513 NestedNameSpecifier
*Qualifier
= E
->getQualifier();
5516 = getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
5517 E
->getQualifierRange(),
5523 PseudoDestructorTypeStorage Destroyed
;
5524 if (E
->getDestroyedTypeInfo()) {
5525 TypeSourceInfo
*DestroyedTypeInfo
5526 = getDerived().TransformTypeInObjectScope(E
->getDestroyedTypeInfo(),
5527 ObjectType
, 0, Qualifier
);
5528 if (!DestroyedTypeInfo
)
5530 Destroyed
= DestroyedTypeInfo
;
5531 } else if (ObjectType
->isDependentType()) {
5532 // We aren't likely to be able to resolve the identifier down to a type
5533 // now anyway, so just retain the identifier.
5534 Destroyed
= PseudoDestructorTypeStorage(E
->getDestroyedTypeIdentifier(),
5535 E
->getDestroyedTypeLoc());
5537 // Look for a destructor known with the given name.
5540 SS
.setScopeRep(Qualifier
);
5541 SS
.setRange(E
->getQualifierRange());
5544 ParsedType T
= SemaRef
.getDestructorName(E
->getTildeLoc(),
5545 *E
->getDestroyedTypeIdentifier(),
5546 E
->getDestroyedTypeLoc(),
5554 = SemaRef
.Context
.getTrivialTypeSourceInfo(SemaRef
.GetTypeFromParser(T
),
5555 E
->getDestroyedTypeLoc());
5558 TypeSourceInfo
*ScopeTypeInfo
= 0;
5559 if (E
->getScopeTypeInfo()) {
5560 ScopeTypeInfo
= getDerived().TransformType(E
->getScopeTypeInfo());
5565 return getDerived().RebuildCXXPseudoDestructorExpr(Base
.get(),
5566 E
->getOperatorLoc(),
5569 E
->getQualifierRange(),
5571 E
->getColonColonLoc(),
5576 template<typename Derived
>
5578 TreeTransform
<Derived
>::TransformUnresolvedLookupExpr(
5579 UnresolvedLookupExpr
*Old
) {
5580 TemporaryBase
Rebase(*this, Old
->getNameLoc(), DeclarationName());
5582 LookupResult
R(SemaRef
, Old
->getName(), Old
->getNameLoc(),
5583 Sema::LookupOrdinaryName
);
5585 // Transform all the decls.
5586 for (UnresolvedLookupExpr::decls_iterator I
= Old
->decls_begin(),
5587 E
= Old
->decls_end(); I
!= E
; ++I
) {
5588 NamedDecl
*InstD
= static_cast<NamedDecl
*>(
5589 getDerived().TransformDecl(Old
->getNameLoc(),
5592 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5593 // This can happen because of dependent hiding.
5594 if (isa
<UsingShadowDecl
>(*I
))
5600 // Expand using declarations.
5601 if (isa
<UsingDecl
>(InstD
)) {
5602 UsingDecl
*UD
= cast
<UsingDecl
>(InstD
);
5603 for (UsingDecl::shadow_iterator I
= UD
->shadow_begin(),
5604 E
= UD
->shadow_end(); I
!= E
; ++I
)
5612 // Resolve a kind, but don't do any further analysis. If it's
5613 // ambiguous, the callee needs to deal with it.
5616 // Rebuild the nested-name qualifier, if present.
5618 NestedNameSpecifier
*Qualifier
= 0;
5619 if (Old
->getQualifier()) {
5620 Qualifier
= getDerived().TransformNestedNameSpecifier(Old
->getQualifier(),
5621 Old
->getQualifierRange());
5625 SS
.setScopeRep(Qualifier
);
5626 SS
.setRange(Old
->getQualifierRange());
5629 if (Old
->getNamingClass()) {
5630 CXXRecordDecl
*NamingClass
5631 = cast_or_null
<CXXRecordDecl
>(getDerived().TransformDecl(
5633 Old
->getNamingClass()));
5637 R
.setNamingClass(NamingClass
);
5640 // If we have no template arguments, it's a normal declaration name.
5641 if (!Old
->hasExplicitTemplateArgs())
5642 return getDerived().RebuildDeclarationNameExpr(SS
, R
, Old
->requiresADL());
5644 // If we have template arguments, rebuild them, then rebuild the
5645 // templateid expression.
5646 TemplateArgumentListInfo
TransArgs(Old
->getLAngleLoc(), Old
->getRAngleLoc());
5647 for (unsigned I
= 0, N
= Old
->getNumTemplateArgs(); I
!= N
; ++I
) {
5648 TemplateArgumentLoc Loc
;
5649 if (getDerived().TransformTemplateArgument(Old
->getTemplateArgs()[I
], Loc
))
5651 TransArgs
.addArgument(Loc
);
5654 return getDerived().RebuildTemplateIdExpr(SS
, R
, Old
->requiresADL(),
5658 template<typename Derived
>
5660 TreeTransform
<Derived
>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr
*E
) {
5661 TypeSourceInfo
*T
= getDerived().TransformType(E
->getQueriedTypeSourceInfo());
5665 if (!getDerived().AlwaysRebuild() &&
5666 T
== E
->getQueriedTypeSourceInfo())
5667 return SemaRef
.Owned(E
);
5669 return getDerived().RebuildUnaryTypeTrait(E
->getTrait(),
5675 template<typename Derived
>
5677 TreeTransform
<Derived
>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr
*E
) {
5678 TypeSourceInfo
*LhsT
= getDerived().TransformType(E
->getLhsTypeSourceInfo());
5682 TypeSourceInfo
*RhsT
= getDerived().TransformType(E
->getRhsTypeSourceInfo());
5686 if (!getDerived().AlwaysRebuild() &&
5687 LhsT
== E
->getLhsTypeSourceInfo() && RhsT
== E
->getRhsTypeSourceInfo())
5688 return SemaRef
.Owned(E
);
5690 return getDerived().RebuildBinaryTypeTrait(E
->getTrait(),
5696 template<typename Derived
>
5698 TreeTransform
<Derived
>::TransformDependentScopeDeclRefExpr(
5699 DependentScopeDeclRefExpr
*E
) {
5700 NestedNameSpecifier
*NNS
5701 = getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
5702 E
->getQualifierRange());
5706 // TODO: If this is a conversion-function-id, verify that the
5707 // destination type name (if present) resolves the same way after
5708 // instantiation as it did in the local scope.
5710 DeclarationNameInfo NameInfo
5711 = getDerived().TransformDeclarationNameInfo(E
->getNameInfo());
5712 if (!NameInfo
.getName())
5715 if (!E
->hasExplicitTemplateArgs()) {
5716 if (!getDerived().AlwaysRebuild() &&
5717 NNS
== E
->getQualifier() &&
5718 // Note: it is sufficient to compare the Name component of NameInfo:
5719 // if name has not changed, DNLoc has not changed either.
5720 NameInfo
.getName() == E
->getDeclName())
5721 return SemaRef
.Owned(E
);
5723 return getDerived().RebuildDependentScopeDeclRefExpr(NNS
,
5724 E
->getQualifierRange(),
5726 /*TemplateArgs*/ 0);
5729 TemplateArgumentListInfo
TransArgs(E
->getLAngleLoc(), E
->getRAngleLoc());
5730 for (unsigned I
= 0, N
= E
->getNumTemplateArgs(); I
!= N
; ++I
) {
5731 TemplateArgumentLoc Loc
;
5732 if (getDerived().TransformTemplateArgument(E
->getTemplateArgs()[I
], Loc
))
5734 TransArgs
.addArgument(Loc
);
5737 return getDerived().RebuildDependentScopeDeclRefExpr(NNS
,
5738 E
->getQualifierRange(),
5743 template<typename Derived
>
5745 TreeTransform
<Derived
>::TransformCXXConstructExpr(CXXConstructExpr
*E
) {
5746 // CXXConstructExprs are always implicit, so when we have a
5747 // 1-argument construction we just transform that argument.
5748 if (E
->getNumArgs() == 1 ||
5749 (E
->getNumArgs() > 1 && getDerived().DropCallArgument(E
->getArg(1))))
5750 return getDerived().TransformExpr(E
->getArg(0));
5752 TemporaryBase
Rebase(*this, /*FIXME*/E
->getLocStart(), DeclarationName());
5754 QualType T
= getDerived().TransformType(E
->getType());
5758 CXXConstructorDecl
*Constructor
5759 = cast_or_null
<CXXConstructorDecl
>(
5760 getDerived().TransformDecl(E
->getLocStart(),
5761 E
->getConstructor()));
5765 bool ArgumentChanged
= false;
5766 ASTOwningVector
<Expr
*> Args(SemaRef
);
5767 for (CXXConstructExpr::arg_iterator Arg
= E
->arg_begin(),
5768 ArgEnd
= E
->arg_end();
5769 Arg
!= ArgEnd
; ++Arg
) {
5770 if (getDerived().DropCallArgument(*Arg
)) {
5771 ArgumentChanged
= true;
5775 ExprResult TransArg
= getDerived().TransformExpr(*Arg
);
5776 if (TransArg
.isInvalid())
5779 ArgumentChanged
= ArgumentChanged
|| TransArg
.get() != *Arg
;
5780 Args
.push_back(TransArg
.get());
5783 if (!getDerived().AlwaysRebuild() &&
5784 T
== E
->getType() &&
5785 Constructor
== E
->getConstructor() &&
5787 // Mark the constructor as referenced.
5788 // FIXME: Instantiation-specific
5789 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), Constructor
);
5790 return SemaRef
.Owned(E
);
5793 return getDerived().RebuildCXXConstructExpr(T
, /*FIXME:*/E
->getLocStart(),
5794 Constructor
, E
->isElidable(),
5796 E
->requiresZeroInitialization(),
5797 E
->getConstructionKind(),
5798 E
->getParenRange());
5801 /// \brief Transform a C++ temporary-binding expression.
5803 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5804 /// transform the subexpression and return that.
5805 template<typename Derived
>
5807 TreeTransform
<Derived
>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr
*E
) {
5808 return getDerived().TransformExpr(E
->getSubExpr());
5811 /// \brief Transform a C++ expression that contains cleanups that should
5812 /// be run after the expression is evaluated.
5814 /// Since ExprWithCleanups nodes are implicitly generated, we
5815 /// just transform the subexpression and return that.
5816 template<typename Derived
>
5818 TreeTransform
<Derived
>::TransformExprWithCleanups(ExprWithCleanups
*E
) {
5819 return getDerived().TransformExpr(E
->getSubExpr());
5822 template<typename Derived
>
5824 TreeTransform
<Derived
>::TransformCXXTemporaryObjectExpr(
5825 CXXTemporaryObjectExpr
*E
) {
5826 TypeSourceInfo
*T
= getDerived().TransformType(E
->getTypeSourceInfo());
5830 CXXConstructorDecl
*Constructor
5831 = cast_or_null
<CXXConstructorDecl
>(
5832 getDerived().TransformDecl(E
->getLocStart(),
5833 E
->getConstructor()));
5837 bool ArgumentChanged
= false;
5838 ASTOwningVector
<Expr
*> Args(SemaRef
);
5839 Args
.reserve(E
->getNumArgs());
5840 for (CXXTemporaryObjectExpr::arg_iterator Arg
= E
->arg_begin(),
5841 ArgEnd
= E
->arg_end();
5842 Arg
!= ArgEnd
; ++Arg
) {
5843 if (getDerived().DropCallArgument(*Arg
)) {
5844 ArgumentChanged
= true;
5848 ExprResult TransArg
= getDerived().TransformExpr(*Arg
);
5849 if (TransArg
.isInvalid())
5852 ArgumentChanged
= ArgumentChanged
|| TransArg
.get() != *Arg
;
5853 Args
.push_back((Expr
*)TransArg
.release());
5856 if (!getDerived().AlwaysRebuild() &&
5857 T
== E
->getTypeSourceInfo() &&
5858 Constructor
== E
->getConstructor() &&
5860 // FIXME: Instantiation-specific
5861 SemaRef
.MarkDeclarationReferenced(E
->getLocStart(), Constructor
);
5862 return SemaRef
.MaybeBindToTemporary(E
);
5865 return getDerived().RebuildCXXTemporaryObjectExpr(T
,
5866 /*FIXME:*/T
->getTypeLoc().getEndLoc(),
5871 template<typename Derived
>
5873 TreeTransform
<Derived
>::TransformCXXUnresolvedConstructExpr(
5874 CXXUnresolvedConstructExpr
*E
) {
5875 TypeSourceInfo
*T
= getDerived().TransformType(E
->getTypeSourceInfo());
5879 bool ArgumentChanged
= false;
5880 ASTOwningVector
<Expr
*> Args(SemaRef
);
5881 for (CXXUnresolvedConstructExpr::arg_iterator Arg
= E
->arg_begin(),
5882 ArgEnd
= E
->arg_end();
5883 Arg
!= ArgEnd
; ++Arg
) {
5884 ExprResult TransArg
= getDerived().TransformExpr(*Arg
);
5885 if (TransArg
.isInvalid())
5888 ArgumentChanged
= ArgumentChanged
|| TransArg
.get() != *Arg
;
5889 Args
.push_back(TransArg
.get());
5892 if (!getDerived().AlwaysRebuild() &&
5893 T
== E
->getTypeSourceInfo() &&
5895 return SemaRef
.Owned(E
);
5897 // FIXME: we're faking the locations of the commas
5898 return getDerived().RebuildCXXUnresolvedConstructExpr(T
,
5904 template<typename Derived
>
5906 TreeTransform
<Derived
>::TransformCXXDependentScopeMemberExpr(
5907 CXXDependentScopeMemberExpr
*E
) {
5908 // Transform the base of the expression.
5909 ExprResult
Base((Expr
*) 0);
5912 QualType ObjectType
;
5913 if (!E
->isImplicitAccess()) {
5914 OldBase
= E
->getBase();
5915 Base
= getDerived().TransformExpr(OldBase
);
5916 if (Base
.isInvalid())
5919 // Start the member reference and compute the object's type.
5920 ParsedType ObjectTy
;
5921 bool MayBePseudoDestructor
= false;
5922 Base
= SemaRef
.ActOnStartCXXMemberReference(0, Base
.get(),
5923 E
->getOperatorLoc(),
5924 E
->isArrow()? tok::arrow
: tok::period
,
5926 MayBePseudoDestructor
);
5927 if (Base
.isInvalid())
5930 ObjectType
= ObjectTy
.get();
5931 BaseType
= ((Expr
*) Base
.get())->getType();
5934 BaseType
= getDerived().TransformType(E
->getBaseType());
5935 ObjectType
= BaseType
->getAs
<PointerType
>()->getPointeeType();
5938 // Transform the first part of the nested-name-specifier that qualifies
5940 NamedDecl
*FirstQualifierInScope
5941 = getDerived().TransformFirstQualifierInScope(
5942 E
->getFirstQualifierFoundInScope(),
5943 E
->getQualifierRange().getBegin());
5945 NestedNameSpecifier
*Qualifier
= 0;
5946 if (E
->getQualifier()) {
5947 Qualifier
= getDerived().TransformNestedNameSpecifier(E
->getQualifier(),
5948 E
->getQualifierRange(),
5950 FirstQualifierInScope
);
5955 // TODO: If this is a conversion-function-id, verify that the
5956 // destination type name (if present) resolves the same way after
5957 // instantiation as it did in the local scope.
5959 DeclarationNameInfo NameInfo
5960 = getDerived().TransformDeclarationNameInfo(E
->getMemberNameInfo());
5961 if (!NameInfo
.getName())
5964 if (!E
->hasExplicitTemplateArgs()) {
5965 // This is a reference to a member without an explicitly-specified
5966 // template argument list. Optimize for this common case.
5967 if (!getDerived().AlwaysRebuild() &&
5968 Base
.get() == OldBase
&&
5969 BaseType
== E
->getBaseType() &&
5970 Qualifier
== E
->getQualifier() &&
5971 NameInfo
.getName() == E
->getMember() &&
5972 FirstQualifierInScope
== E
->getFirstQualifierFoundInScope())
5973 return SemaRef
.Owned(E
);
5975 return getDerived().RebuildCXXDependentScopeMemberExpr(Base
.get(),
5978 E
->getOperatorLoc(),
5980 E
->getQualifierRange(),
5981 FirstQualifierInScope
,
5983 /*TemplateArgs*/ 0);
5986 TemplateArgumentListInfo
TransArgs(E
->getLAngleLoc(), E
->getRAngleLoc());
5987 for (unsigned I
= 0, N
= E
->getNumTemplateArgs(); I
!= N
; ++I
) {
5988 TemplateArgumentLoc Loc
;
5989 if (getDerived().TransformTemplateArgument(E
->getTemplateArgs()[I
], Loc
))
5991 TransArgs
.addArgument(Loc
);
5994 return getDerived().RebuildCXXDependentScopeMemberExpr(Base
.get(),
5997 E
->getOperatorLoc(),
5999 E
->getQualifierRange(),
6000 FirstQualifierInScope
,
6005 template<typename Derived
>
6007 TreeTransform
<Derived
>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr
*Old
) {
6008 // Transform the base of the expression.
6009 ExprResult
Base((Expr
*) 0);
6011 if (!Old
->isImplicitAccess()) {
6012 Base
= getDerived().TransformExpr(Old
->getBase());
6013 if (Base
.isInvalid())
6015 BaseType
= ((Expr
*) Base
.get())->getType();
6017 BaseType
= getDerived().TransformType(Old
->getBaseType());
6020 NestedNameSpecifier
*Qualifier
= 0;
6021 if (Old
->getQualifier()) {
6023 = getDerived().TransformNestedNameSpecifier(Old
->getQualifier(),
6024 Old
->getQualifierRange());
6029 LookupResult
R(SemaRef
, Old
->getMemberNameInfo(),
6030 Sema::LookupOrdinaryName
);
6032 // Transform all the decls.
6033 for (UnresolvedMemberExpr::decls_iterator I
= Old
->decls_begin(),
6034 E
= Old
->decls_end(); I
!= E
; ++I
) {
6035 NamedDecl
*InstD
= static_cast<NamedDecl
*>(
6036 getDerived().TransformDecl(Old
->getMemberLoc(),
6039 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6040 // This can happen because of dependent hiding.
6041 if (isa
<UsingShadowDecl
>(*I
))
6047 // Expand using declarations.
6048 if (isa
<UsingDecl
>(InstD
)) {
6049 UsingDecl
*UD
= cast
<UsingDecl
>(InstD
);
6050 for (UsingDecl::shadow_iterator I
= UD
->shadow_begin(),
6051 E
= UD
->shadow_end(); I
!= E
; ++I
)
6061 // Determine the naming class.
6062 if (Old
->getNamingClass()) {
6063 CXXRecordDecl
*NamingClass
6064 = cast_or_null
<CXXRecordDecl
>(getDerived().TransformDecl(
6065 Old
->getMemberLoc(),
6066 Old
->getNamingClass()));
6070 R
.setNamingClass(NamingClass
);
6073 TemplateArgumentListInfo TransArgs
;
6074 if (Old
->hasExplicitTemplateArgs()) {
6075 TransArgs
.setLAngleLoc(Old
->getLAngleLoc());
6076 TransArgs
.setRAngleLoc(Old
->getRAngleLoc());
6077 for (unsigned I
= 0, N
= Old
->getNumTemplateArgs(); I
!= N
; ++I
) {
6078 TemplateArgumentLoc Loc
;
6079 if (getDerived().TransformTemplateArgument(Old
->getTemplateArgs()[I
],
6082 TransArgs
.addArgument(Loc
);
6086 // FIXME: to do this check properly, we will need to preserve the
6087 // first-qualifier-in-scope here, just in case we had a dependent
6088 // base (and therefore couldn't do the check) and a
6089 // nested-name-qualifier (and therefore could do the lookup).
6090 NamedDecl
*FirstQualifierInScope
= 0;
6092 return getDerived().RebuildUnresolvedMemberExpr(Base
.get(),
6094 Old
->getOperatorLoc(),
6097 Old
->getQualifierRange(),
6098 FirstQualifierInScope
,
6100 (Old
->hasExplicitTemplateArgs()
6104 template<typename Derived
>
6106 TreeTransform
<Derived
>::TransformCXXNoexceptExpr(CXXNoexceptExpr
*E
) {
6107 ExprResult SubExpr
= getDerived().TransformExpr(E
->getOperand());
6108 if (SubExpr
.isInvalid())
6111 if (!getDerived().AlwaysRebuild() && SubExpr
.get() == E
->getOperand())
6112 return SemaRef
.Owned(E
);
6114 return getDerived().RebuildCXXNoexceptExpr(E
->getSourceRange(),SubExpr
.get());
6117 template<typename Derived
>
6119 TreeTransform
<Derived
>::TransformObjCStringLiteral(ObjCStringLiteral
*E
) {
6120 return SemaRef
.Owned(E
);
6123 template<typename Derived
>
6125 TreeTransform
<Derived
>::TransformObjCEncodeExpr(ObjCEncodeExpr
*E
) {
6126 TypeSourceInfo
*EncodedTypeInfo
6127 = getDerived().TransformType(E
->getEncodedTypeSourceInfo());
6128 if (!EncodedTypeInfo
)
6131 if (!getDerived().AlwaysRebuild() &&
6132 EncodedTypeInfo
== E
->getEncodedTypeSourceInfo())
6133 return SemaRef
.Owned(E
);
6135 return getDerived().RebuildObjCEncodeExpr(E
->getAtLoc(),
6140 template<typename Derived
>
6142 TreeTransform
<Derived
>::TransformObjCMessageExpr(ObjCMessageExpr
*E
) {
6143 // Transform arguments.
6144 bool ArgChanged
= false;
6145 ASTOwningVector
<Expr
*> Args(SemaRef
);
6146 for (unsigned I
= 0, N
= E
->getNumArgs(); I
!= N
; ++I
) {
6147 ExprResult Arg
= getDerived().TransformExpr(E
->getArg(I
));
6148 if (Arg
.isInvalid())
6151 ArgChanged
= ArgChanged
|| Arg
.get() != E
->getArg(I
);
6152 Args
.push_back(Arg
.get());
6155 if (E
->getReceiverKind() == ObjCMessageExpr::Class
) {
6156 // Class message: transform the receiver type.
6157 TypeSourceInfo
*ReceiverTypeInfo
6158 = getDerived().TransformType(E
->getClassReceiverTypeInfo());
6159 if (!ReceiverTypeInfo
)
6162 // If nothing changed, just retain the existing message send.
6163 if (!getDerived().AlwaysRebuild() &&
6164 ReceiverTypeInfo
== E
->getClassReceiverTypeInfo() && !ArgChanged
)
6165 return SemaRef
.Owned(E
);
6167 // Build a new class message send.
6168 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo
,
6170 E
->getSelectorLoc(),
6177 // Instance message: transform the receiver
6178 assert(E
->getReceiverKind() == ObjCMessageExpr::Instance
&&
6179 "Only class and instance messages may be instantiated");
6181 = getDerived().TransformExpr(E
->getInstanceReceiver());
6182 if (Receiver
.isInvalid())
6185 // If nothing changed, just retain the existing message send.
6186 if (!getDerived().AlwaysRebuild() &&
6187 Receiver
.get() == E
->getInstanceReceiver() && !ArgChanged
)
6188 return SemaRef
.Owned(E
);
6190 // Build a new instance message send.
6191 return getDerived().RebuildObjCMessageExpr(Receiver
.get(),
6193 E
->getSelectorLoc(),
6200 template<typename Derived
>
6202 TreeTransform
<Derived
>::TransformObjCSelectorExpr(ObjCSelectorExpr
*E
) {
6203 return SemaRef
.Owned(E
);
6206 template<typename Derived
>
6208 TreeTransform
<Derived
>::TransformObjCProtocolExpr(ObjCProtocolExpr
*E
) {
6209 return SemaRef
.Owned(E
);
6212 template<typename Derived
>
6214 TreeTransform
<Derived
>::TransformObjCIvarRefExpr(ObjCIvarRefExpr
*E
) {
6215 // Transform the base expression.
6216 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
6217 if (Base
.isInvalid())
6220 // We don't need to transform the ivar; it will never change.
6222 // If nothing changed, just retain the existing expression.
6223 if (!getDerived().AlwaysRebuild() &&
6224 Base
.get() == E
->getBase())
6225 return SemaRef
.Owned(E
);
6227 return getDerived().RebuildObjCIvarRefExpr(Base
.get(), E
->getDecl(),
6229 E
->isArrow(), E
->isFreeIvar());
6232 template<typename Derived
>
6234 TreeTransform
<Derived
>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr
*E
) {
6235 // 'super' and types never change. Property never changes. Just
6236 // retain the existing expression.
6237 if (!E
->isObjectReceiver())
6238 return SemaRef
.Owned(E
);
6240 // Transform the base expression.
6241 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
6242 if (Base
.isInvalid())
6245 // We don't need to transform the property; it will never change.
6247 // If nothing changed, just retain the existing expression.
6248 if (!getDerived().AlwaysRebuild() &&
6249 Base
.get() == E
->getBase())
6250 return SemaRef
.Owned(E
);
6252 if (E
->isExplicitProperty())
6253 return getDerived().RebuildObjCPropertyRefExpr(Base
.get(),
6254 E
->getExplicitProperty(),
6257 return getDerived().RebuildObjCPropertyRefExpr(Base
.get(),
6259 E
->getImplicitPropertyGetter(),
6260 E
->getImplicitPropertySetter(),
6264 template<typename Derived
>
6266 TreeTransform
<Derived
>::TransformObjCIsaExpr(ObjCIsaExpr
*E
) {
6267 // Transform the base expression.
6268 ExprResult Base
= getDerived().TransformExpr(E
->getBase());
6269 if (Base
.isInvalid())
6272 // If nothing changed, just retain the existing expression.
6273 if (!getDerived().AlwaysRebuild() &&
6274 Base
.get() == E
->getBase())
6275 return SemaRef
.Owned(E
);
6277 return getDerived().RebuildObjCIsaExpr(Base
.get(), E
->getIsaMemberLoc(),
6281 template<typename Derived
>
6283 TreeTransform
<Derived
>::TransformShuffleVectorExpr(ShuffleVectorExpr
*E
) {
6284 bool ArgumentChanged
= false;
6285 ASTOwningVector
<Expr
*> SubExprs(SemaRef
);
6286 for (unsigned I
= 0, N
= E
->getNumSubExprs(); I
!= N
; ++I
) {
6287 ExprResult SubExpr
= getDerived().TransformExpr(E
->getExpr(I
));
6288 if (SubExpr
.isInvalid())
6291 ArgumentChanged
= ArgumentChanged
|| SubExpr
.get() != E
->getExpr(I
);
6292 SubExprs
.push_back(SubExpr
.get());
6295 if (!getDerived().AlwaysRebuild() &&
6297 return SemaRef
.Owned(E
);
6299 return getDerived().RebuildShuffleVectorExpr(E
->getBuiltinLoc(),
6304 template<typename Derived
>
6306 TreeTransform
<Derived
>::TransformBlockExpr(BlockExpr
*E
) {
6307 SourceLocation
CaretLoc(E
->getExprLoc());
6309 SemaRef
.ActOnBlockStart(CaretLoc
, /*Scope=*/0);
6310 BlockScopeInfo
*CurBlock
= SemaRef
.getCurBlock();
6311 CurBlock
->TheDecl
->setIsVariadic(E
->getBlockDecl()->isVariadic());
6312 llvm::SmallVector
<ParmVarDecl
*, 4> Params
;
6313 llvm::SmallVector
<QualType
, 4> ParamTypes
;
6315 // Parameter substitution.
6316 const BlockDecl
*BD
= E
->getBlockDecl();
6317 for (BlockDecl::param_const_iterator P
= BD
->param_begin(),
6318 EN
= BD
->param_end(); P
!= EN
; ++P
) {
6319 ParmVarDecl
*OldParm
= (*P
);
6320 ParmVarDecl
*NewParm
= getDerived().TransformFunctionTypeParam(OldParm
);
6321 QualType NewType
= NewParm
->getType();
6322 Params
.push_back(NewParm
);
6323 ParamTypes
.push_back(NewParm
->getType());
6326 const FunctionType
*BExprFunctionType
= E
->getFunctionType();
6327 QualType BExprResultType
= BExprFunctionType
->getResultType();
6328 if (!BExprResultType
.isNull()) {
6329 if (!BExprResultType
->isDependentType())
6330 CurBlock
->ReturnType
= BExprResultType
;
6331 else if (BExprResultType
!= SemaRef
.Context
.DependentTy
)
6332 CurBlock
->ReturnType
= getDerived().TransformType(BExprResultType
);
6335 // Transform the body
6336 StmtResult Body
= getDerived().TransformStmt(E
->getBody());
6337 if (Body
.isInvalid())
6339 // Set the parameters on the block decl.
6340 if (!Params
.empty())
6341 CurBlock
->TheDecl
->setParams(Params
.data(), Params
.size());
6343 QualType FunctionType
= getDerived().RebuildFunctionProtoType(
6344 CurBlock
->ReturnType
,
6349 BExprFunctionType
->getExtInfo());
6351 CurBlock
->FunctionType
= FunctionType
;
6352 return SemaRef
.ActOnBlockStmtExpr(CaretLoc
, Body
.get(), /*Scope=*/0);
6355 template<typename Derived
>
6357 TreeTransform
<Derived
>::TransformBlockDeclRefExpr(BlockDeclRefExpr
*E
) {
6358 NestedNameSpecifier
*Qualifier
= 0;
6361 = cast_or_null
<ValueDecl
>(getDerived().TransformDecl(E
->getLocation(),
6366 if (!getDerived().AlwaysRebuild() &&
6367 ND
== E
->getDecl()) {
6368 // Mark it referenced in the new context regardless.
6369 // FIXME: this is a bit instantiation-specific.
6370 SemaRef
.MarkDeclarationReferenced(E
->getLocation(), ND
);
6372 return SemaRef
.Owned(E
);
6375 DeclarationNameInfo
NameInfo(E
->getDecl()->getDeclName(), E
->getLocation());
6376 return getDerived().RebuildDeclRefExpr(Qualifier
, SourceLocation(),
6380 //===----------------------------------------------------------------------===//
6381 // Type reconstruction
6382 //===----------------------------------------------------------------------===//
6384 template<typename Derived
>
6385 QualType TreeTransform
<Derived
>::RebuildPointerType(QualType PointeeType
,
6386 SourceLocation Star
) {
6387 return SemaRef
.BuildPointerType(PointeeType
, Star
,
6388 getDerived().getBaseEntity());
6391 template<typename Derived
>
6392 QualType TreeTransform
<Derived
>::RebuildBlockPointerType(QualType PointeeType
,
6393 SourceLocation Star
) {
6394 return SemaRef
.BuildBlockPointerType(PointeeType
, Star
,
6395 getDerived().getBaseEntity());
6398 template<typename Derived
>
6400 TreeTransform
<Derived
>::RebuildReferenceType(QualType ReferentType
,
6401 bool WrittenAsLValue
,
6402 SourceLocation Sigil
) {
6403 return SemaRef
.BuildReferenceType(ReferentType
, WrittenAsLValue
,
6404 Sigil
, getDerived().getBaseEntity());
6407 template<typename Derived
>
6409 TreeTransform
<Derived
>::RebuildMemberPointerType(QualType PointeeType
,
6411 SourceLocation Sigil
) {
6412 return SemaRef
.BuildMemberPointerType(PointeeType
, ClassType
,
6413 Sigil
, getDerived().getBaseEntity());
6416 template<typename Derived
>
6418 TreeTransform
<Derived
>::RebuildArrayType(QualType ElementType
,
6419 ArrayType::ArraySizeModifier SizeMod
,
6420 const llvm::APInt
*Size
,
6422 unsigned IndexTypeQuals
,
6423 SourceRange BracketsRange
) {
6424 if (SizeExpr
|| !Size
)
6425 return SemaRef
.BuildArrayType(ElementType
, SizeMod
, SizeExpr
,
6426 IndexTypeQuals
, BracketsRange
,
6427 getDerived().getBaseEntity());
6429 QualType Types
[] = {
6430 SemaRef
.Context
.UnsignedCharTy
, SemaRef
.Context
.UnsignedShortTy
,
6431 SemaRef
.Context
.UnsignedIntTy
, SemaRef
.Context
.UnsignedLongTy
,
6432 SemaRef
.Context
.UnsignedLongLongTy
, SemaRef
.Context
.UnsignedInt128Ty
6434 const unsigned NumTypes
= sizeof(Types
) / sizeof(QualType
);
6436 for (unsigned I
= 0; I
!= NumTypes
; ++I
)
6437 if (Size
->getBitWidth() == SemaRef
.Context
.getIntWidth(Types
[I
])) {
6438 SizeType
= Types
[I
];
6442 IntegerLiteral
ArraySize(SemaRef
.Context
, *Size
, SizeType
,
6443 /*FIXME*/BracketsRange
.getBegin());
6444 return SemaRef
.BuildArrayType(ElementType
, SizeMod
, &ArraySize
,
6445 IndexTypeQuals
, BracketsRange
,
6446 getDerived().getBaseEntity());
6449 template<typename Derived
>
6451 TreeTransform
<Derived
>::RebuildConstantArrayType(QualType ElementType
,
6452 ArrayType::ArraySizeModifier SizeMod
,
6453 const llvm::APInt
&Size
,
6454 unsigned IndexTypeQuals
,
6455 SourceRange BracketsRange
) {
6456 return getDerived().RebuildArrayType(ElementType
, SizeMod
, &Size
, 0,
6457 IndexTypeQuals
, BracketsRange
);
6460 template<typename Derived
>
6462 TreeTransform
<Derived
>::RebuildIncompleteArrayType(QualType ElementType
,
6463 ArrayType::ArraySizeModifier SizeMod
,
6464 unsigned IndexTypeQuals
,
6465 SourceRange BracketsRange
) {
6466 return getDerived().RebuildArrayType(ElementType
, SizeMod
, 0, 0,
6467 IndexTypeQuals
, BracketsRange
);
6470 template<typename Derived
>
6472 TreeTransform
<Derived
>::RebuildVariableArrayType(QualType ElementType
,
6473 ArrayType::ArraySizeModifier SizeMod
,
6475 unsigned IndexTypeQuals
,
6476 SourceRange BracketsRange
) {
6477 return getDerived().RebuildArrayType(ElementType
, SizeMod
, 0,
6479 IndexTypeQuals
, BracketsRange
);
6482 template<typename Derived
>
6484 TreeTransform
<Derived
>::RebuildDependentSizedArrayType(QualType ElementType
,
6485 ArrayType::ArraySizeModifier SizeMod
,
6487 unsigned IndexTypeQuals
,
6488 SourceRange BracketsRange
) {
6489 return getDerived().RebuildArrayType(ElementType
, SizeMod
, 0,
6491 IndexTypeQuals
, BracketsRange
);
6494 template<typename Derived
>
6495 QualType TreeTransform
<Derived
>::RebuildVectorType(QualType ElementType
,
6496 unsigned NumElements
,
6497 VectorType::VectorKind VecKind
) {
6498 // FIXME: semantic checking!
6499 return SemaRef
.Context
.getVectorType(ElementType
, NumElements
, VecKind
);
6502 template<typename Derived
>
6503 QualType TreeTransform
<Derived
>::RebuildExtVectorType(QualType ElementType
,
6504 unsigned NumElements
,
6505 SourceLocation AttributeLoc
) {
6506 llvm::APInt
numElements(SemaRef
.Context
.getIntWidth(SemaRef
.Context
.IntTy
),
6508 IntegerLiteral
*VectorSize
6509 = IntegerLiteral::Create(SemaRef
.Context
, numElements
, SemaRef
.Context
.IntTy
,
6511 return SemaRef
.BuildExtVectorType(ElementType
, VectorSize
, AttributeLoc
);
6514 template<typename Derived
>
6516 TreeTransform
<Derived
>::RebuildDependentSizedExtVectorType(QualType ElementType
,
6518 SourceLocation AttributeLoc
) {
6519 return SemaRef
.BuildExtVectorType(ElementType
, SizeExpr
, AttributeLoc
);
6522 template<typename Derived
>
6523 QualType TreeTransform
<Derived
>::RebuildFunctionProtoType(QualType T
,
6524 QualType
*ParamTypes
,
6525 unsigned NumParamTypes
,
6528 const FunctionType::ExtInfo
&Info
) {
6529 return SemaRef
.BuildFunctionType(T
, ParamTypes
, NumParamTypes
, Variadic
,
6531 getDerived().getBaseLocation(),
6532 getDerived().getBaseEntity(),
6536 template<typename Derived
>
6537 QualType TreeTransform
<Derived
>::RebuildFunctionNoProtoType(QualType T
) {
6538 return SemaRef
.Context
.getFunctionNoProtoType(T
);
6541 template<typename Derived
>
6542 QualType TreeTransform
<Derived
>::RebuildUnresolvedUsingType(Decl
*D
) {
6543 assert(D
&& "no decl found");
6544 if (D
->isInvalidDecl()) return QualType();
6546 // FIXME: Doesn't account for ObjCInterfaceDecl!
6548 if (isa
<UsingDecl
>(D
)) {
6549 UsingDecl
*Using
= cast
<UsingDecl
>(D
);
6550 assert(Using
->isTypeName() &&
6551 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6553 // A valid resolved using typename decl points to exactly one type decl.
6554 assert(++Using
->shadow_begin() == Using
->shadow_end());
6555 Ty
= cast
<TypeDecl
>((*Using
->shadow_begin())->getTargetDecl());
6558 assert(isa
<UnresolvedUsingTypenameDecl
>(D
) &&
6559 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6560 Ty
= cast
<UnresolvedUsingTypenameDecl
>(D
);
6563 return SemaRef
.Context
.getTypeDeclType(Ty
);
6566 template<typename Derived
>
6567 QualType TreeTransform
<Derived
>::RebuildTypeOfExprType(Expr
*E
,
6568 SourceLocation Loc
) {
6569 return SemaRef
.BuildTypeofExprType(E
, Loc
);
6572 template<typename Derived
>
6573 QualType TreeTransform
<Derived
>::RebuildTypeOfType(QualType Underlying
) {
6574 return SemaRef
.Context
.getTypeOfType(Underlying
);
6577 template<typename Derived
>
6578 QualType TreeTransform
<Derived
>::RebuildDecltypeType(Expr
*E
,
6579 SourceLocation Loc
) {
6580 return SemaRef
.BuildDecltypeType(E
, Loc
);
6583 template<typename Derived
>
6584 QualType TreeTransform
<Derived
>::RebuildTemplateSpecializationType(
6585 TemplateName Template
,
6586 SourceLocation TemplateNameLoc
,
6587 const TemplateArgumentListInfo
&TemplateArgs
) {
6588 return SemaRef
.CheckTemplateIdType(Template
, TemplateNameLoc
, TemplateArgs
);
6591 template<typename Derived
>
6592 NestedNameSpecifier
*
6593 TreeTransform
<Derived
>::RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
6596 QualType ObjectType
,
6597 NamedDecl
*FirstQualifierInScope
) {
6599 // FIXME: The source location information is all wrong.
6601 SS
.setScopeRep(Prefix
);
6602 return static_cast<NestedNameSpecifier
*>(
6603 SemaRef
.BuildCXXNestedNameSpecifier(0, SS
, Range
.getEnd(),
6606 FirstQualifierInScope
,
6610 template<typename Derived
>
6611 NestedNameSpecifier
*
6612 TreeTransform
<Derived
>::RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
6614 NamespaceDecl
*NS
) {
6615 return NestedNameSpecifier::Create(SemaRef
.Context
, Prefix
, NS
);
6618 template<typename Derived
>
6619 NestedNameSpecifier
*
6620 TreeTransform
<Derived
>::RebuildNestedNameSpecifier(NestedNameSpecifier
*Prefix
,
6624 if (T
->isDependentType() || T
->isRecordType() ||
6625 (SemaRef
.getLangOptions().CPlusPlus0x
&& T
->isEnumeralType())) {
6626 assert(!T
.hasLocalQualifiers() && "Can't get cv-qualifiers here");
6627 return NestedNameSpecifier::Create(SemaRef
.Context
, Prefix
, TemplateKW
,
6631 SemaRef
.Diag(Range
.getBegin(), diag::err_nested_name_spec_non_tag
) << T
;
6635 template<typename Derived
>
6637 TreeTransform
<Derived
>::RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
6639 TemplateDecl
*Template
) {
6640 return SemaRef
.Context
.getQualifiedTemplateName(Qualifier
, TemplateKW
,
6644 template<typename Derived
>
6646 TreeTransform
<Derived
>::RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
6647 SourceRange QualifierRange
,
6648 const IdentifierInfo
&II
,
6649 QualType ObjectType
,
6650 NamedDecl
*FirstQualifierInScope
) {
6652 SS
.setRange(QualifierRange
);
6653 SS
.setScopeRep(Qualifier
);
6655 Name
.setIdentifier(&II
, /*FIXME:*/getDerived().getBaseLocation());
6656 Sema::TemplateTy Template
;
6657 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6658 /*FIXME:*/getDerived().getBaseLocation(),
6661 ParsedType::make(ObjectType
),
6662 /*EnteringContext=*/false,
6664 return Template
.get();
6667 template<typename Derived
>
6669 TreeTransform
<Derived
>::RebuildTemplateName(NestedNameSpecifier
*Qualifier
,
6670 OverloadedOperatorKind Operator
,
6671 QualType ObjectType
) {
6673 SS
.setRange(SourceRange(getDerived().getBaseLocation()));
6674 SS
.setScopeRep(Qualifier
);
6676 SourceLocation SymbolLocations
[3]; // FIXME: Bogus location information.
6677 Name
.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6678 Operator
, SymbolLocations
);
6679 Sema::TemplateTy Template
;
6680 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6681 /*FIXME:*/getDerived().getBaseLocation(),
6684 ParsedType::make(ObjectType
),
6685 /*EnteringContext=*/false,
6687 return Template
.template getAsVal
<TemplateName
>();
6690 template<typename Derived
>
6692 TreeTransform
<Derived
>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op
,
6693 SourceLocation OpLoc
,
6697 Expr
*Callee
= OrigCallee
->IgnoreParenCasts();
6698 bool isPostIncDec
= Second
&& (Op
== OO_PlusPlus
|| Op
== OO_MinusMinus
);
6700 // Determine whether this should be a builtin operation.
6701 if (Op
== OO_Subscript
) {
6702 if (!First
->getType()->isOverloadableType() &&
6703 !Second
->getType()->isOverloadableType())
6704 return getSema().CreateBuiltinArraySubscriptExpr(First
,
6705 Callee
->getLocStart(),
6707 } else if (Op
== OO_Arrow
) {
6708 // -> is never a builtin operation.
6709 return SemaRef
.BuildOverloadedArrowExpr(0, First
, OpLoc
);
6710 } else if (Second
== 0 || isPostIncDec
) {
6711 if (!First
->getType()->isOverloadableType()) {
6712 // The argument is not of overloadable type, so try to create a
6713 // built-in unary operation.
6714 UnaryOperatorKind Opc
6715 = UnaryOperator::getOverloadedOpcode(Op
, isPostIncDec
);
6717 return getSema().CreateBuiltinUnaryOp(OpLoc
, Opc
, First
);
6720 if (!First
->getType()->isOverloadableType() &&
6721 !Second
->getType()->isOverloadableType()) {
6722 // Neither of the arguments is an overloadable type, so try to
6723 // create a built-in binary operation.
6724 BinaryOperatorKind Opc
= BinaryOperator::getOverloadedOpcode(Op
);
6726 = SemaRef
.CreateBuiltinBinOp(OpLoc
, Opc
, First
, Second
);
6727 if (Result
.isInvalid())
6730 return move(Result
);
6734 // Compute the transformed set of functions (and function templates) to be
6735 // used during overload resolution.
6736 UnresolvedSet
<16> Functions
;
6738 if (UnresolvedLookupExpr
*ULE
= dyn_cast
<UnresolvedLookupExpr
>(Callee
)) {
6739 assert(ULE
->requiresADL());
6741 // FIXME: Do we have to check
6742 // IsAcceptableNonMemberOperatorCandidate for each of these?
6743 Functions
.append(ULE
->decls_begin(), ULE
->decls_end());
6745 Functions
.addDecl(cast
<DeclRefExpr
>(Callee
)->getDecl());
6748 // Add any functions found via argument-dependent lookup.
6749 Expr
*Args
[2] = { First
, Second
};
6750 unsigned NumArgs
= 1 + (Second
!= 0);
6752 // Create the overloaded operator invocation for unary operators.
6753 if (NumArgs
== 1 || isPostIncDec
) {
6754 UnaryOperatorKind Opc
6755 = UnaryOperator::getOverloadedOpcode(Op
, isPostIncDec
);
6756 return SemaRef
.CreateOverloadedUnaryOp(OpLoc
, Opc
, Functions
, First
);
6759 if (Op
== OO_Subscript
)
6760 return SemaRef
.CreateOverloadedArraySubscriptExpr(Callee
->getLocStart(),
6765 // Create the overloaded operator invocation for binary operators.
6766 BinaryOperatorKind Opc
= BinaryOperator::getOverloadedOpcode(Op
);
6768 = SemaRef
.CreateOverloadedBinOp(OpLoc
, Opc
, Functions
, Args
[0], Args
[1]);
6769 if (Result
.isInvalid())
6772 return move(Result
);
6775 template<typename Derived
>
6777 TreeTransform
<Derived
>::RebuildCXXPseudoDestructorExpr(Expr
*Base
,
6778 SourceLocation OperatorLoc
,
6780 NestedNameSpecifier
*Qualifier
,
6781 SourceRange QualifierRange
,
6782 TypeSourceInfo
*ScopeType
,
6783 SourceLocation CCLoc
,
6784 SourceLocation TildeLoc
,
6785 PseudoDestructorTypeStorage Destroyed
) {
6788 SS
.setRange(QualifierRange
);
6789 SS
.setScopeRep(Qualifier
);
6792 QualType BaseType
= Base
->getType();
6793 if (Base
->isTypeDependent() || Destroyed
.getIdentifier() ||
6794 (!isArrow
&& !BaseType
->getAs
<RecordType
>()) ||
6795 (isArrow
&& BaseType
->getAs
<PointerType
>() &&
6796 !BaseType
->getAs
<PointerType
>()->getPointeeType()
6797 ->template getAs
<RecordType
>())){
6798 // This pseudo-destructor expression is still a pseudo-destructor.
6799 return SemaRef
.BuildPseudoDestructorExpr(Base
, OperatorLoc
,
6800 isArrow
? tok::arrow
: tok::period
,
6801 SS
, ScopeType
, CCLoc
, TildeLoc
,
6806 TypeSourceInfo
*DestroyedType
= Destroyed
.getTypeSourceInfo();
6807 DeclarationName
Name(SemaRef
.Context
.DeclarationNames
.getCXXDestructorName(
6808 SemaRef
.Context
.getCanonicalType(DestroyedType
->getType())));
6809 DeclarationNameInfo
NameInfo(Name
, Destroyed
.getLocation());
6810 NameInfo
.setNamedTypeInfo(DestroyedType
);
6812 // FIXME: the ScopeType should be tacked onto SS.
6814 return getSema().BuildMemberReferenceExpr(Base
, BaseType
,
6815 OperatorLoc
, isArrow
,
6816 SS
, /*FIXME: FirstQualifier*/ 0,
6818 /*TemplateArgs*/ 0);
6821 } // end namespace clang
6823 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H