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/AST/TypeLocBuilder.h"
29 #include "clang/Sema/Ownership.h"
30 #include "clang/Sema/Designator.h"
31 #include "clang/Lex/Preprocessor.h"
32 #include "llvm/Support/ErrorHandling.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, QualType ObjectType = QualType());
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,
203 QualType ObjectType = QualType());
205 /// \brief Transform the given type-with-location into a new
206 /// type, collecting location information in the given builder
209 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
210 QualType ObjectType = QualType());
212 /// \brief Transform the given statement.
214 /// By default, this routine transforms a statement by delegating to the
215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
220 /// \returns the transformed statement.
221 StmtResult TransformStmt(Stmt *S);
223 /// \brief Transform the given expression.
225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
230 /// \returns the transformed expression.
231 ExprResult TransformExpr(Expr *E);
233 /// \brief Transform the given declaration, which is referenced from a type
236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
238 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
240 /// \brief Transform the definition of the given declaration.
242 /// By default, invokes TransformDecl() to transform the declaration.
243 /// Subclasses may override this function to provide alternate behavior.
244 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
245 return getDerived().TransformDecl(Loc, D);
248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
251 /// This specific declaration transformation only applies to the first
252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
261 /// \brief Transform the given nested-name-specifier.
263 /// By default, transforms all of the types and declarations within the
264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
271 /// \brief Transform the given declaration name.
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
278 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
279 QualType ObjectType = QualType());
281 /// \brief Transform the given template name.
283 /// By default, transforms the template name by transforming the declarations
284 /// and nested-name-specifiers that occur within the template name.
285 /// Subclasses may override this function to provide alternate behavior.
286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
289 /// \brief Transform the given template argument.
291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
307 getDerived().getBaseLocation());
310 #define ABSTRACT_TYPELOC(CLASS, PARENT)
311 #define TYPELOC(CLASS, PARENT) \
312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
314 #include "clang/AST/TypeLocNodes.def"
316 /// \brief Transforms the parameters of a function type into the
319 /// The result vectors should be kept in sync; null entries in the
320 /// variables vector are acceptable.
322 /// Return true on error.
323 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
324 llvm::SmallVectorImpl<QualType> &PTypes,
325 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
327 /// \brief Transforms a single function-type parameter. Return null
329 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
331 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
332 QualType ObjectType);
335 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
336 QualType ObjectType);
338 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
339 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
341 #define STMT(Node, Parent) \
342 StmtResult Transform##Node(Node *S);
343 #define EXPR(Node, Parent) \
344 ExprResult Transform##Node(Node *E);
345 #define ABSTRACT_STMT(Stmt)
346 #include "clang/AST/StmtNodes.inc"
348 /// \brief Build a new pointer type given its pointee type.
350 /// By default, performs semantic analysis when building the pointer type.
351 /// Subclasses may override this routine to provide different behavior.
352 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
354 /// \brief Build a new block pointer type given its pointee type.
356 /// By default, performs semantic analysis when building the block pointer
357 /// type. Subclasses may override this routine to provide different behavior.
358 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
360 /// \brief Build a new reference type given the type it references.
362 /// By default, performs semantic analysis when building the
363 /// reference type. Subclasses may override this routine to provide
364 /// different behavior.
366 /// \param LValue whether the type was written with an lvalue sigil
367 /// or an rvalue sigil.
368 QualType RebuildReferenceType(QualType ReferentType,
370 SourceLocation Sigil);
372 /// \brief Build a new member pointer type given the pointee type and the
373 /// class type it refers into.
375 /// By default, performs semantic analysis when building the member pointer
376 /// type. Subclasses may override this routine to provide different behavior.
377 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
378 SourceLocation Sigil);
380 /// \brief Build a new array type given the element type, size
381 /// modifier, size of the array (if known), size expression, and index type
384 /// By default, performs semantic analysis when building the array type.
385 /// Subclasses may override this routine to provide different behavior.
386 /// Also by default, all of the other Rebuild*Array
387 QualType RebuildArrayType(QualType ElementType,
388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt *Size,
391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
394 /// \brief Build a new constant array type given the element type, size
395 /// modifier, (known) size of the array, and index type qualifiers.
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
399 QualType RebuildConstantArrayType(QualType ElementType,
400 ArrayType::ArraySizeModifier SizeMod,
401 const llvm::APInt &Size,
402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
405 /// \brief Build a new incomplete array type given the element type, size
406 /// modifier, and index type qualifiers.
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
410 QualType RebuildIncompleteArrayType(QualType ElementType,
411 ArrayType::ArraySizeModifier SizeMod,
412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
415 /// \brief Build a new variable-length array type given the element type,
416 /// size modifier, size expression, and index type qualifiers.
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
420 QualType RebuildVariableArrayType(QualType ElementType,
421 ArrayType::ArraySizeModifier SizeMod,
423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
426 /// \brief Build a new dependent-sized array type given the element type,
427 /// size modifier, size expression, and index type qualifiers.
429 /// By default, performs semantic analysis when building the array type.
430 /// Subclasses may override this routine to provide different behavior.
431 QualType RebuildDependentSizedArrayType(QualType ElementType,
432 ArrayType::ArraySizeModifier SizeMod,
434 unsigned IndexTypeQuals,
435 SourceRange BracketsRange);
437 /// \brief Build a new vector type given the element type and
438 /// number of elements.
440 /// By default, performs semantic analysis when building the vector type.
441 /// Subclasses may override this routine to provide different behavior.
442 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
443 VectorType::AltiVecSpecific AltiVecSpec);
445 /// \brief Build a new extended vector type given the element type and
446 /// number of elements.
448 /// By default, performs semantic analysis when building the vector type.
449 /// Subclasses may override this routine to provide different behavior.
450 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
451 SourceLocation AttributeLoc);
453 /// \brief Build a new potentially dependently-sized extended vector type
454 /// given the element type and number of elements.
456 /// By default, performs semantic analysis when building the vector type.
457 /// Subclasses may override this routine to provide different behavior.
458 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
460 SourceLocation AttributeLoc);
462 /// \brief Build a new function type.
464 /// By default, performs semantic analysis when building the function type.
465 /// Subclasses may override this routine to provide different behavior.
466 QualType RebuildFunctionProtoType(QualType T,
467 QualType *ParamTypes,
468 unsigned NumParamTypes,
469 bool Variadic, unsigned Quals,
470 const FunctionType::ExtInfo &Info);
472 /// \brief Build a new unprototyped function type.
473 QualType RebuildFunctionNoProtoType(QualType ResultType);
475 /// \brief Rebuild an unresolved typename type, given the decl that
476 /// the UnresolvedUsingTypenameDecl was transformed to.
477 QualType RebuildUnresolvedUsingType(Decl *D);
479 /// \brief Build a new typedef type.
480 QualType RebuildTypedefType(TypedefDecl *Typedef) {
481 return SemaRef.Context.getTypeDeclType(Typedef);
484 /// \brief Build a new class/struct/union type.
485 QualType RebuildRecordType(RecordDecl *Record) {
486 return SemaRef.Context.getTypeDeclType(Record);
489 /// \brief Build a new Enum type.
490 QualType RebuildEnumType(EnumDecl *Enum) {
491 return SemaRef.Context.getTypeDeclType(Enum);
494 /// \brief Build a new typeof(expr) type.
496 /// By default, performs semantic analysis when building the typeof type.
497 /// Subclasses may override this routine to provide different behavior.
498 QualType RebuildTypeOfExprType(Expr *Underlying);
500 /// \brief Build a new typeof(type) type.
502 /// By default, builds a new TypeOfType with the given underlying type.
503 QualType RebuildTypeOfType(QualType Underlying);
505 /// \brief Build a new C++0x decltype type.
507 /// By default, performs semantic analysis when building the decltype type.
508 /// Subclasses may override this routine to provide different behavior.
509 QualType RebuildDecltypeType(Expr *Underlying);
511 /// \brief Build a new template specialization type.
513 /// By default, performs semantic analysis when building the template
514 /// specialization type. Subclasses may override this routine to provide
515 /// different behavior.
516 QualType RebuildTemplateSpecializationType(TemplateName Template,
517 SourceLocation TemplateLoc,
518 const TemplateArgumentListInfo &Args);
520 /// \brief Build a new qualified name type.
522 /// By default, builds a new ElaboratedType type from the keyword,
523 /// the nested-name-specifier and the named type.
524 /// Subclasses may override this routine to provide different behavior.
525 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
526 NestedNameSpecifier *NNS, QualType Named) {
527 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
530 /// \brief Build a new typename type that refers to a template-id.
532 /// By default, builds a new DependentNameType type from the
533 /// nested-name-specifier and the given type. Subclasses may override
534 /// this routine to provide different behavior.
535 QualType RebuildDependentTemplateSpecializationType(
536 ElaboratedTypeKeyword Keyword,
537 NestedNameSpecifier *NNS,
538 const IdentifierInfo *Name,
539 SourceLocation NameLoc,
540 const TemplateArgumentListInfo &Args) {
541 // Rebuild the template name.
542 // TODO: avoid TemplateName abstraction
543 TemplateName InstName =
544 getDerived().RebuildTemplateName(NNS, *Name, QualType());
546 if (InstName.isNull())
549 // If it's still dependent, make a dependent specialization.
550 if (InstName.getAsDependentTemplateName())
551 return SemaRef.Context.getDependentTemplateSpecializationType(
552 Keyword, NNS, Name, Args);
554 // Otherwise, make an elaborated type wrapping a non-dependent
557 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
558 if (T.isNull()) return QualType();
560 // NOTE: NNS is already recorded in template specialization type T.
561 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
564 /// \brief Build a new typename type that refers to an identifier.
566 /// By default, performs semantic analysis when building the typename type
567 /// (or elaborated type). Subclasses may override this routine to provide
568 /// different behavior.
569 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
570 NestedNameSpecifier *NNS,
571 const IdentifierInfo *Id,
572 SourceLocation KeywordLoc,
573 SourceRange NNSRange,
574 SourceLocation IdLoc) {
577 SS.setRange(NNSRange);
579 if (NNS->isDependent()) {
580 // If the name is still dependent, just build a new dependent name type.
581 if (!SemaRef.computeDeclContext(SS))
582 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
585 if (Keyword == ETK_None || Keyword == ETK_Typename)
586 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
587 KeywordLoc, NNSRange, IdLoc);
589 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
591 // We had a dependent elaborated-type-specifier that has been transformed
592 // into a non-dependent elaborated-type-specifier. Find the tag we're
594 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
595 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
599 if (SemaRef.RequireCompleteDeclContext(SS, DC))
603 SemaRef.LookupQualifiedName(Result, DC);
604 switch (Result.getResultKind()) {
605 case LookupResult::NotFound:
606 case LookupResult::NotFoundInCurrentInstantiation:
609 case LookupResult::Found:
610 Tag = Result.getAsSingle<TagDecl>();
613 case LookupResult::FoundOverloaded:
614 case LookupResult::FoundUnresolvedValue:
615 llvm_unreachable("Tag lookup cannot find non-tags");
618 case LookupResult::Ambiguous:
619 // Let the LookupResult structure handle ambiguities.
624 // FIXME: Would be nice to highlight just the source range.
625 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
630 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
631 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
632 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
636 // Build the elaborated-type-specifier type.
637 QualType T = SemaRef.Context.getTypeDeclType(Tag);
638 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
641 /// \brief Build a new nested-name-specifier given the prefix and an
642 /// identifier that names the next step in the nested-name-specifier.
644 /// By default, performs semantic analysis when building the new
645 /// nested-name-specifier. Subclasses may override this routine to provide
646 /// different behavior.
647 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
651 NamedDecl *FirstQualifierInScope);
653 /// \brief Build a new nested-name-specifier given the prefix and the
654 /// namespace named in the next step in the nested-name-specifier.
656 /// By default, performs semantic analysis when building the new
657 /// nested-name-specifier. Subclasses may override this routine to provide
658 /// different behavior.
659 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
663 /// \brief Build a new nested-name-specifier given the prefix and the
664 /// type named in the next step in the nested-name-specifier.
666 /// By default, performs semantic analysis when building the new
667 /// nested-name-specifier. Subclasses may override this routine to provide
668 /// different behavior.
669 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
674 /// \brief Build a new template name given a nested name specifier, a flag
675 /// indicating whether the "template" keyword was provided, and the template
676 /// that the template name refers to.
678 /// By default, builds the new template name directly. Subclasses may override
679 /// this routine to provide different behavior.
680 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
682 TemplateDecl *Template);
684 /// \brief Build a new template name given a nested name specifier and the
685 /// name that is referred to as a template.
687 /// By default, performs semantic analysis to determine whether the name can
688 /// be resolved to a specific template, then builds the appropriate kind of
689 /// template name. Subclasses may override this routine to provide different
691 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
692 const IdentifierInfo &II,
693 QualType ObjectType);
695 /// \brief Build a new template name given a nested name specifier and the
696 /// overloaded operator name that is referred to as a template.
698 /// By default, performs semantic analysis to determine whether the name can
699 /// be resolved to a specific template, then builds the appropriate kind of
700 /// template name. Subclasses may override this routine to provide different
702 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
703 OverloadedOperatorKind Operator,
704 QualType ObjectType);
706 /// \brief Build a new compound statement.
708 /// By default, performs semantic analysis to build the new statement.
709 /// Subclasses may override this routine to provide different behavior.
710 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
711 MultiStmtArg Statements,
712 SourceLocation RBraceLoc,
714 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
718 /// \brief Build a new case statement.
720 /// By default, performs semantic analysis to build the new statement.
721 /// Subclasses may override this routine to provide different behavior.
722 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
724 SourceLocation EllipsisLoc,
726 SourceLocation ColonLoc) {
727 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
731 /// \brief Attach the body to a new case statement.
733 /// By default, performs semantic analysis to build the new statement.
734 /// Subclasses may override this routine to provide different behavior.
735 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
736 getSema().ActOnCaseStmtBody(S, Body);
740 /// \brief Build a new default statement.
742 /// By default, performs semantic analysis to build the new statement.
743 /// Subclasses may override this routine to provide different behavior.
744 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
745 SourceLocation ColonLoc,
747 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
751 /// \brief Build a new label statement.
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
755 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
757 SourceLocation ColonLoc,
759 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt);
762 /// \brief Build a new "if" statement.
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
766 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
767 VarDecl *CondVar, Stmt *Then,
768 SourceLocation ElseLoc, Stmt *Else) {
769 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
772 /// \brief Start building a new switch statement.
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
776 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
777 Expr *Cond, VarDecl *CondVar) {
778 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
782 /// \brief Attach the body to the switch statement.
784 /// By default, performs semantic analysis to build the new statement.
785 /// Subclasses may override this routine to provide different behavior.
786 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
787 Stmt *Switch, Stmt *Body) {
788 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
791 /// \brief Build a new while statement.
793 /// By default, performs semantic analysis to build the new statement.
794 /// Subclasses may override this routine to provide different behavior.
795 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
796 Sema::FullExprArg Cond,
799 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
802 /// \brief Build a new do-while statement.
804 /// By default, performs semantic analysis to build the new statement.
805 /// Subclasses may override this routine to provide different behavior.
806 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
807 SourceLocation WhileLoc,
808 SourceLocation LParenLoc,
810 SourceLocation RParenLoc) {
811 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
815 /// \brief Build a new for statement.
817 /// By default, performs semantic analysis to build the new statement.
818 /// Subclasses may override this routine to provide different behavior.
819 StmtResult RebuildForStmt(SourceLocation ForLoc,
820 SourceLocation LParenLoc,
821 Stmt *Init, Sema::FullExprArg Cond,
822 VarDecl *CondVar, Sema::FullExprArg Inc,
823 SourceLocation RParenLoc, Stmt *Body) {
824 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
826 Inc, RParenLoc, Body);
829 /// \brief Build a new goto statement.
831 /// By default, performs semantic analysis to build the new statement.
832 /// Subclasses may override this routine to provide different behavior.
833 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
834 SourceLocation LabelLoc,
836 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
839 /// \brief Build a new indirect goto statement.
841 /// By default, performs semantic analysis to build the new statement.
842 /// Subclasses may override this routine to provide different behavior.
843 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
844 SourceLocation StarLoc,
846 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
849 /// \brief Build a new return statement.
851 /// By default, performs semantic analysis to build the new statement.
852 /// Subclasses may override this routine to provide different behavior.
853 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
856 return getSema().ActOnReturnStmt(ReturnLoc, Result);
859 /// \brief Build a new declaration statement.
861 /// By default, performs semantic analysis to build the new statement.
862 /// Subclasses may override this routine to provide different behavior.
863 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
864 SourceLocation StartLoc,
865 SourceLocation EndLoc) {
866 return getSema().Owned(
867 new (getSema().Context) DeclStmt(
868 DeclGroupRef::Create(getSema().Context,
873 /// \brief Build a new inline asm statement.
875 /// By default, performs semantic analysis to build the new statement.
876 /// Subclasses may override this routine to provide different behavior.
877 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
882 IdentifierInfo **Names,
883 MultiExprArg Constraints,
886 MultiExprArg Clobbers,
887 SourceLocation RParenLoc,
889 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
890 NumInputs, Names, move(Constraints),
891 Exprs, AsmString, Clobbers,
895 /// \brief Build a new Objective-C @try statement.
897 /// By default, performs semantic analysis to build the new statement.
898 /// Subclasses may override this routine to provide different behavior.
899 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
901 MultiStmtArg CatchStmts,
903 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
907 /// \brief Rebuild an Objective-C exception declaration.
909 /// By default, performs semantic analysis to build the new declaration.
910 /// Subclasses may override this routine to provide different behavior.
911 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
912 TypeSourceInfo *TInfo, QualType T) {
913 return getSema().BuildObjCExceptionDecl(TInfo, T,
914 ExceptionDecl->getIdentifier(),
915 ExceptionDecl->getLocation());
918 /// \brief Build a new Objective-C @catch statement.
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
922 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
923 SourceLocation RParenLoc,
926 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
930 /// \brief Build a new Objective-C @finally statement.
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
934 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
936 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
939 /// \brief Build a new Objective-C @throw statement.
941 /// By default, performs semantic analysis to build the new statement.
942 /// Subclasses may override this routine to provide different behavior.
943 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
945 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
948 /// \brief Build a new Objective-C @synchronized statement.
950 /// By default, performs semantic analysis to build the new statement.
951 /// Subclasses may override this routine to provide different behavior.
952 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
955 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
959 /// \brief Build a new Objective-C fast enumeration statement.
961 /// By default, performs semantic analysis to build the new statement.
962 /// Subclasses may override this routine to provide different behavior.
963 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
964 SourceLocation LParenLoc,
967 SourceLocation RParenLoc,
969 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
976 /// \brief Build a new C++ exception declaration.
978 /// By default, performs semantic analysis to build the new decaration.
979 /// Subclasses may override this routine to provide different behavior.
980 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
981 TypeSourceInfo *Declarator,
982 IdentifierInfo *Name,
984 SourceRange TypeRange) {
985 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
989 /// \brief Build a new C++ catch statement.
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
993 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
994 VarDecl *ExceptionDecl,
996 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1000 /// \brief Build a new C++ try statement.
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
1004 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1006 MultiStmtArg Handlers) {
1007 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
1010 /// \brief Build a new expression that references a declaration.
1012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
1014 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1017 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1021 /// \brief Build a new expression that references a declaration.
1023 /// By default, performs semantic analysis to build the new expression.
1024 /// Subclasses may override this routine to provide different behavior.
1025 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1026 SourceRange QualifierRange,
1028 const DeclarationNameInfo &NameInfo,
1029 TemplateArgumentListInfo *TemplateArgs) {
1031 SS.setScopeRep(Qualifier);
1032 SS.setRange(QualifierRange);
1034 // FIXME: loses template args.
1036 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1039 /// \brief Build a new expression in parentheses.
1041 /// By default, performs semantic analysis to build the new expression.
1042 /// Subclasses may override this routine to provide different behavior.
1043 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1044 SourceLocation RParen) {
1045 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1048 /// \brief Build a new pseudo-destructor expression.
1050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
1052 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1053 SourceLocation OperatorLoc,
1055 NestedNameSpecifier *Qualifier,
1056 SourceRange QualifierRange,
1057 TypeSourceInfo *ScopeType,
1058 SourceLocation CCLoc,
1059 SourceLocation TildeLoc,
1060 PseudoDestructorTypeStorage Destroyed);
1062 /// \brief Build a new unary operator expression.
1064 /// By default, performs semantic analysis to build the new expression.
1065 /// Subclasses may override this routine to provide different behavior.
1066 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1067 UnaryOperatorKind Opc,
1069 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1072 /// \brief Build a new builtin offsetof expression.
1074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
1076 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1077 TypeSourceInfo *Type,
1078 Sema::OffsetOfComponent *Components,
1079 unsigned NumComponents,
1080 SourceLocation RParenLoc) {
1081 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1082 NumComponents, RParenLoc);
1085 /// \brief Build a new sizeof or alignof expression with a type argument.
1087 /// By default, performs semantic analysis to build the new expression.
1088 /// Subclasses may override this routine to provide different behavior.
1089 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
1090 SourceLocation OpLoc,
1091 bool isSizeOf, SourceRange R) {
1092 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
1095 /// \brief Build a new sizeof or alignof expression with an expression
1098 /// By default, performs semantic analysis to build the new expression.
1099 /// Subclasses may override this routine to provide different behavior.
1100 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
1101 bool isSizeOf, SourceRange R) {
1103 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
1104 if (Result.isInvalid())
1107 return move(Result);
1110 /// \brief Build a new array subscript expression.
1112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
1114 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1115 SourceLocation LBracketLoc,
1117 SourceLocation RBracketLoc) {
1118 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1123 /// \brief Build a new call expression.
1125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
1127 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1129 SourceLocation *CommaLocs,
1130 SourceLocation RParenLoc) {
1131 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1132 move(Args), CommaLocs, RParenLoc);
1135 /// \brief Build a new member access expression.
1137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
1139 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1141 NestedNameSpecifier *Qualifier,
1142 SourceRange QualifierRange,
1143 const DeclarationNameInfo &MemberNameInfo,
1145 NamedDecl *FoundDecl,
1146 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1147 NamedDecl *FirstQualifierInScope) {
1148 if (!Member->getDeclName()) {
1149 // We have a reference to an unnamed field.
1150 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
1152 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
1157 new (getSema().Context) MemberExpr(Base, isArrow,
1158 Member, MemberNameInfo,
1159 cast<FieldDecl>(Member)->getType());
1160 return getSema().Owned(ME);
1165 SS.setRange(QualifierRange);
1166 SS.setScopeRep(Qualifier);
1169 getSema().DefaultFunctionArrayConversion(Base);
1170 QualType BaseType = Base->getType();
1172 // FIXME: this involves duplicating earlier analysis in a lot of
1173 // cases; we should avoid this when possible.
1174 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
1175 R.addDecl(FoundDecl);
1178 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1179 SS, FirstQualifierInScope,
1180 R, ExplicitTemplateArgs);
1183 /// \brief Build a new binary operator expression.
1185 /// By default, performs semantic analysis to build the new expression.
1186 /// Subclasses may override this routine to provide different behavior.
1187 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1188 BinaryOperatorKind Opc,
1189 Expr *LHS, Expr *RHS) {
1190 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1193 /// \brief Build a new conditional operator expression.
1195 /// By default, performs semantic analysis to build the new expression.
1196 /// Subclasses may override this routine to provide different behavior.
1197 ExprResult RebuildConditionalOperator(Expr *Cond,
1198 SourceLocation QuestionLoc,
1200 SourceLocation ColonLoc,
1202 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1206 /// \brief Build a new C-style cast expression.
1208 /// By default, performs semantic analysis to build the new expression.
1209 /// Subclasses may override this routine to provide different behavior.
1210 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1211 TypeSourceInfo *TInfo,
1212 SourceLocation RParenLoc,
1214 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1218 /// \brief Build a new compound literal expression.
1220 /// By default, performs semantic analysis to build the new expression.
1221 /// Subclasses may override this routine to provide different behavior.
1222 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1223 TypeSourceInfo *TInfo,
1224 SourceLocation RParenLoc,
1226 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1230 /// \brief Build a new extended vector element access expression.
1232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
1234 ExprResult RebuildExtVectorElementExpr(Expr *Base,
1235 SourceLocation OpLoc,
1236 SourceLocation AccessorLoc,
1237 IdentifierInfo &Accessor) {
1240 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
1241 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1242 OpLoc, /*IsArrow*/ false,
1243 SS, /*FirstQualifierInScope*/ 0,
1245 /* TemplateArgs */ 0);
1248 /// \brief Build a new initializer list expression.
1250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
1252 ExprResult RebuildInitList(SourceLocation LBraceLoc,
1254 SourceLocation RBraceLoc,
1255 QualType ResultTy) {
1257 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1258 if (Result.isInvalid() || ResultTy->isDependentType())
1259 return move(Result);
1261 // Patch in the result type we were given, which may have been computed
1262 // when the initial InitListExpr was built.
1263 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1264 ILE->setType(ResultTy);
1265 return move(Result);
1268 /// \brief Build a new designated initializer expression.
1270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
1272 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1273 MultiExprArg ArrayExprs,
1274 SourceLocation EqualOrColonLoc,
1278 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1280 if (Result.isInvalid())
1283 ArrayExprs.release();
1284 return move(Result);
1287 /// \brief Build a new value-initialized expression.
1289 /// By default, builds the implicit value initialization without performing
1290 /// any semantic analysis. Subclasses may override this routine to provide
1291 /// different behavior.
1292 ExprResult RebuildImplicitValueInitExpr(QualType T) {
1293 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1296 /// \brief Build a new \c va_arg expression.
1298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
1300 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1301 Expr *SubExpr, TypeSourceInfo *TInfo,
1302 SourceLocation RParenLoc) {
1303 return getSema().BuildVAArgExpr(BuiltinLoc,
1308 /// \brief Build a new expression list in parentheses.
1310 /// By default, performs semantic analysis to build the new expression.
1311 /// Subclasses may override this routine to provide different behavior.
1312 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1313 MultiExprArg SubExprs,
1314 SourceLocation RParenLoc) {
1315 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1319 /// \brief Build a new address-of-label expression.
1321 /// By default, performs semantic analysis, using the name of the label
1322 /// rather than attempting to map the label statement itself.
1323 /// Subclasses may override this routine to provide different behavior.
1324 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1325 SourceLocation LabelLoc,
1327 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1330 /// \brief Build a new GNU statement expression.
1332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
1334 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1336 SourceLocation RParenLoc) {
1337 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1340 /// \brief Build a new __builtin_types_compatible_p expression.
1342 /// By default, performs semantic analysis to build the new expression.
1343 /// Subclasses may override this routine to provide different behavior.
1344 ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1345 TypeSourceInfo *TInfo1,
1346 TypeSourceInfo *TInfo2,
1347 SourceLocation RParenLoc) {
1348 return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
1353 /// \brief Build a new __builtin_choose_expr expression.
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
1357 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1358 Expr *Cond, Expr *LHS, Expr *RHS,
1359 SourceLocation RParenLoc) {
1360 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1365 /// \brief Build a new overloaded operator call expression.
1367 /// By default, performs semantic analysis to build the new expression.
1368 /// The semantic analysis provides the behavior of template instantiation,
1369 /// copying with transformations that turn what looks like an overloaded
1370 /// operator call into a use of a builtin operator, performing
1371 /// argument-dependent lookup, etc. Subclasses may override this routine to
1372 /// provide different behavior.
1373 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1374 SourceLocation OpLoc,
1379 /// \brief Build a new C++ "named" cast expression, such as static_cast or
1380 /// reinterpret_cast.
1382 /// By default, this routine dispatches to one of the more-specific routines
1383 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1384 /// Subclasses may override this routine to provide different behavior.
1385 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1386 Stmt::StmtClass Class,
1387 SourceLocation LAngleLoc,
1388 TypeSourceInfo *TInfo,
1389 SourceLocation RAngleLoc,
1390 SourceLocation LParenLoc,
1392 SourceLocation RParenLoc) {
1394 case Stmt::CXXStaticCastExprClass:
1395 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
1396 RAngleLoc, LParenLoc,
1397 SubExpr, RParenLoc);
1399 case Stmt::CXXDynamicCastExprClass:
1400 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
1401 RAngleLoc, LParenLoc,
1402 SubExpr, RParenLoc);
1404 case Stmt::CXXReinterpretCastExprClass:
1405 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
1406 RAngleLoc, LParenLoc,
1410 case Stmt::CXXConstCastExprClass:
1411 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
1412 RAngleLoc, LParenLoc,
1413 SubExpr, RParenLoc);
1416 assert(false && "Invalid C++ named cast");
1423 /// \brief Build a new C++ static_cast expression.
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
1427 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1428 SourceLocation LAngleLoc,
1429 TypeSourceInfo *TInfo,
1430 SourceLocation RAngleLoc,
1431 SourceLocation LParenLoc,
1433 SourceLocation RParenLoc) {
1434 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1436 SourceRange(LAngleLoc, RAngleLoc),
1437 SourceRange(LParenLoc, RParenLoc));
1440 /// \brief Build a new C++ dynamic_cast expression.
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
1444 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1445 SourceLocation LAngleLoc,
1446 TypeSourceInfo *TInfo,
1447 SourceLocation RAngleLoc,
1448 SourceLocation LParenLoc,
1450 SourceLocation RParenLoc) {
1451 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1453 SourceRange(LAngleLoc, RAngleLoc),
1454 SourceRange(LParenLoc, RParenLoc));
1457 /// \brief Build a new C++ reinterpret_cast expression.
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
1461 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1462 SourceLocation LAngleLoc,
1463 TypeSourceInfo *TInfo,
1464 SourceLocation RAngleLoc,
1465 SourceLocation LParenLoc,
1467 SourceLocation RParenLoc) {
1468 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1470 SourceRange(LAngleLoc, RAngleLoc),
1471 SourceRange(LParenLoc, RParenLoc));
1474 /// \brief Build a new C++ const_cast expression.
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
1478 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1479 SourceLocation LAngleLoc,
1480 TypeSourceInfo *TInfo,
1481 SourceLocation RAngleLoc,
1482 SourceLocation LParenLoc,
1484 SourceLocation RParenLoc) {
1485 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1487 SourceRange(LAngleLoc, RAngleLoc),
1488 SourceRange(LParenLoc, RParenLoc));
1491 /// \brief Build a new C++ functional-style cast expression.
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
1495 ExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1496 TypeSourceInfo *TInfo,
1497 SourceLocation LParenLoc,
1499 SourceLocation RParenLoc) {
1500 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1501 ParsedType::make(TInfo->getType()),
1503 MultiExprArg(&Sub, 1),
1508 /// \brief Build a new C++ typeid(type) expression.
1510 /// By default, performs semantic analysis to build the new expression.
1511 /// Subclasses may override this routine to provide different behavior.
1512 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1513 SourceLocation TypeidLoc,
1514 TypeSourceInfo *Operand,
1515 SourceLocation RParenLoc) {
1516 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1520 /// \brief Build a new C++ typeid(expr) expression.
1522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
1524 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1525 SourceLocation TypeidLoc,
1527 SourceLocation RParenLoc) {
1528 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1532 /// \brief Build a new C++ "this" expression.
1534 /// By default, builds a new "this" expression without performing any
1535 /// semantic analysis. Subclasses may override this routine to provide
1536 /// different behavior.
1537 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1540 return getSema().Owned(
1541 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1545 /// \brief Build a new C++ throw expression.
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
1549 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
1550 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
1553 /// \brief Build a new C++ default-argument expression.
1555 /// By default, builds a new default-argument expression, which does not
1556 /// require any semantic analysis. Subclasses may override this routine to
1557 /// provide different behavior.
1558 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1559 ParmVarDecl *Param) {
1560 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1564 /// \brief Build a new C++ zero-initialization expression.
1566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
1568 ExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
1569 SourceLocation LParenLoc,
1571 SourceLocation RParenLoc) {
1572 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1573 ParsedType::make(T), LParenLoc,
1574 MultiExprArg(getSema(), 0, 0),
1578 /// \brief Build a new C++ "new" expression.
1580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
1582 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
1584 SourceLocation PlacementLParen,
1585 MultiExprArg PlacementArgs,
1586 SourceLocation PlacementRParen,
1587 SourceRange TypeIdParens,
1589 SourceLocation TypeLoc,
1590 SourceRange TypeRange,
1592 SourceLocation ConstructorLParen,
1593 MultiExprArg ConstructorArgs,
1594 SourceLocation ConstructorRParen) {
1595 return getSema().BuildCXXNew(StartLoc, UseGlobal,
1597 move(PlacementArgs),
1605 move(ConstructorArgs),
1609 /// \brief Build a new C++ "delete" expression.
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
1613 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1614 bool IsGlobalDelete,
1617 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1621 /// \brief Build a new unary type trait expression.
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
1625 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1626 SourceLocation StartLoc,
1627 SourceLocation LParenLoc,
1629 SourceLocation RParenLoc) {
1630 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
1631 ParsedType::make(T), RParenLoc);
1634 /// \brief Build a new (previously unresolved) declaration reference
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
1639 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
1640 SourceRange QualifierRange,
1641 const DeclarationNameInfo &NameInfo,
1642 const TemplateArgumentListInfo *TemplateArgs) {
1644 SS.setRange(QualifierRange);
1645 SS.setScopeRep(NNS);
1648 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
1651 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
1654 /// \brief Build a new template-id expression.
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
1658 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1661 const TemplateArgumentListInfo &TemplateArgs) {
1662 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
1665 /// \brief Build a new object-construction expression.
1667 /// By default, performs semantic analysis to build the new expression.
1668 /// Subclasses may override this routine to provide different behavior.
1669 ExprResult RebuildCXXConstructExpr(QualType T,
1671 CXXConstructorDecl *Constructor,
1674 bool RequiresZeroInit,
1675 CXXConstructExpr::ConstructionKind ConstructKind) {
1676 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
1677 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1681 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1682 move_arg(ConvertedArgs),
1683 RequiresZeroInit, ConstructKind);
1686 /// \brief Build a new object-construction expression.
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
1690 ExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1692 SourceLocation LParenLoc,
1694 SourceLocation *Commas,
1695 SourceLocation RParenLoc) {
1696 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1697 ParsedType::make(T),
1704 /// \brief Build a new object-construction expression.
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
1708 ExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1710 SourceLocation LParenLoc,
1712 SourceLocation *Commas,
1713 SourceLocation RParenLoc) {
1714 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1715 /*FIXME*/LParenLoc),
1716 ParsedType::make(T),
1723 /// \brief Build a new member reference expression.
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
1727 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
1730 SourceLocation OperatorLoc,
1731 NestedNameSpecifier *Qualifier,
1732 SourceRange QualifierRange,
1733 NamedDecl *FirstQualifierInScope,
1734 const DeclarationNameInfo &MemberNameInfo,
1735 const TemplateArgumentListInfo *TemplateArgs) {
1737 SS.setRange(QualifierRange);
1738 SS.setScopeRep(Qualifier);
1740 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1741 OperatorLoc, IsArrow,
1742 SS, FirstQualifierInScope,
1747 /// \brief Build a new member reference expression.
1749 /// By default, performs semantic analysis to build the new expression.
1750 /// Subclasses may override this routine to provide different behavior.
1751 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
1753 SourceLocation OperatorLoc,
1755 NestedNameSpecifier *Qualifier,
1756 SourceRange QualifierRange,
1757 NamedDecl *FirstQualifierInScope,
1759 const TemplateArgumentListInfo *TemplateArgs) {
1761 SS.setRange(QualifierRange);
1762 SS.setScopeRep(Qualifier);
1764 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1765 OperatorLoc, IsArrow,
1766 SS, FirstQualifierInScope,
1770 /// \brief Build a new Objective-C @encode expression.
1772 /// By default, performs semantic analysis to build the new expression.
1773 /// Subclasses may override this routine to provide different behavior.
1774 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1775 TypeSourceInfo *EncodeTypeInfo,
1776 SourceLocation RParenLoc) {
1777 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
1781 /// \brief Build a new Objective-C class message.
1782 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1784 ObjCMethodDecl *Method,
1785 SourceLocation LBracLoc,
1787 SourceLocation RBracLoc) {
1788 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1789 ReceiverTypeInfo->getType(),
1790 /*SuperLoc=*/SourceLocation(),
1791 Sel, Method, LBracLoc, RBracLoc,
1795 /// \brief Build a new Objective-C instance message.
1796 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
1798 ObjCMethodDecl *Method,
1799 SourceLocation LBracLoc,
1801 SourceLocation RBracLoc) {
1802 return SemaRef.BuildInstanceMessage(Receiver,
1803 Receiver->getType(),
1804 /*SuperLoc=*/SourceLocation(),
1805 Sel, Method, LBracLoc, RBracLoc,
1809 /// \brief Build a new Objective-C ivar reference expression.
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
1813 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
1814 SourceLocation IvarLoc,
1815 bool IsArrow, bool IsFreeIvar) {
1816 // FIXME: We lose track of the IsFreeIvar bit.
1818 Expr *Base = BaseArg;
1819 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1820 Sema::LookupMemberName);
1821 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1825 if (Result.isInvalid())
1829 return move(Result);
1831 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1832 /*FIXME:*/IvarLoc, IsArrow, SS,
1833 /*FirstQualifierInScope=*/0,
1835 /*TemplateArgs=*/0);
1838 /// \brief Build a new Objective-C property reference expression.
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
1842 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
1843 ObjCPropertyDecl *Property,
1844 SourceLocation PropertyLoc) {
1846 Expr *Base = BaseArg;
1847 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1848 Sema::LookupMemberName);
1849 bool IsArrow = false;
1850 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1851 /*FIME:*/PropertyLoc,
1853 if (Result.isInvalid())
1857 return move(Result);
1859 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1860 /*FIXME:*/PropertyLoc, IsArrow,
1862 /*FirstQualifierInScope=*/0,
1864 /*TemplateArgs=*/0);
1867 /// \brief Build a new Objective-C implicit setter/getter reference
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
1872 ExprResult RebuildObjCImplicitSetterGetterRefExpr(
1873 ObjCMethodDecl *Getter,
1875 ObjCMethodDecl *Setter,
1876 SourceLocation NameLoc,
1878 // Since these expressions can only be value-dependent, we do not need to
1879 // perform semantic analysis again.
1881 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1887 /// \brief Build a new Objective-C "isa" expression.
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
1891 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
1894 Expr *Base = BaseArg;
1895 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1896 Sema::LookupMemberName);
1897 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1900 if (Result.isInvalid())
1904 return move(Result);
1906 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1907 /*FIXME:*/IsaLoc, IsArrow, SS,
1908 /*FirstQualifierInScope=*/0,
1910 /*TemplateArgs=*/0);
1913 /// \brief Build a new shuffle vector expression.
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
1917 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1918 MultiExprArg SubExprs,
1919 SourceLocation RParenLoc) {
1920 // Find the declaration for __builtin_shufflevector
1921 const IdentifierInfo &Name
1922 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1923 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1924 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1925 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
1927 // Build a reference to the __builtin_shufflevector builtin
1928 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
1930 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
1932 SemaRef.UsualUnaryConversions(Callee);
1934 // Build the CallExpr
1935 unsigned NumSubExprs = SubExprs.size();
1936 Expr **Subs = (Expr **)SubExprs.release();
1937 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1939 Builtin->getCallResultType(),
1941 ExprResult OwnedCall(SemaRef.Owned(TheCall));
1943 // Type-check the __builtin_shufflevector expression.
1944 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1945 if (Result.isInvalid())
1948 OwnedCall.release();
1949 return move(Result);
1953 template<typename Derived>
1954 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1956 return SemaRef.Owned(S);
1958 switch (S->getStmtClass()) {
1959 case Stmt::NoStmtClass: break;
1961 // Transform individual statement nodes
1962 #define STMT(Node, Parent) \
1963 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1964 #define EXPR(Node, Parent)
1965 #include "clang/AST/StmtNodes.inc"
1967 // Transform expressions by calling TransformExpr.
1968 #define STMT(Node, Parent)
1969 #define ABSTRACT_STMT(Stmt)
1970 #define EXPR(Node, Parent) case Stmt::Node##Class:
1971 #include "clang/AST/StmtNodes.inc"
1973 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1977 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
1981 return SemaRef.Owned(S->Retain());
1985 template<typename Derived>
1986 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
1988 return SemaRef.Owned(E);
1990 switch (E->getStmtClass()) {
1991 case Stmt::NoStmtClass: break;
1992 #define STMT(Node, Parent) case Stmt::Node##Class: break;
1993 #define ABSTRACT_STMT(Stmt)
1994 #define EXPR(Node, Parent) \
1995 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
1996 #include "clang/AST/StmtNodes.inc"
1999 return SemaRef.Owned(E->Retain());
2002 template<typename Derived>
2003 NestedNameSpecifier *
2004 TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
2006 QualType ObjectType,
2007 NamedDecl *FirstQualifierInScope) {
2011 // Transform the prefix of this nested name specifier.
2012 NestedNameSpecifier *Prefix = NNS->getPrefix();
2014 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
2016 FirstQualifierInScope);
2020 // Clear out the object type and the first qualifier in scope; they only
2021 // apply to the first element in the nested-name-specifier.
2022 ObjectType = QualType();
2023 FirstQualifierInScope = 0;
2026 switch (NNS->getKind()) {
2027 case NestedNameSpecifier::Identifier:
2028 assert((Prefix || !ObjectType.isNull()) &&
2029 "Identifier nested-name-specifier with no prefix or object type");
2030 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2031 ObjectType.isNull())
2034 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2035 *NNS->getAsIdentifier(),
2037 FirstQualifierInScope);
2039 case NestedNameSpecifier::Namespace: {
2041 = cast_or_null<NamespaceDecl>(
2042 getDerived().TransformDecl(Range.getBegin(),
2043 NNS->getAsNamespace()));
2044 if (!getDerived().AlwaysRebuild() &&
2045 Prefix == NNS->getPrefix() &&
2046 NS == NNS->getAsNamespace())
2049 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2052 case NestedNameSpecifier::Global:
2053 // There is no meaningful transformation that one could perform on the
2057 case NestedNameSpecifier::TypeSpecWithTemplate:
2058 case NestedNameSpecifier::TypeSpec: {
2059 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
2060 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2065 if (!getDerived().AlwaysRebuild() &&
2066 Prefix == NNS->getPrefix() &&
2067 T == QualType(NNS->getAsType(), 0))
2070 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2071 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
2076 // Required to silence a GCC warning
2080 template<typename Derived>
2082 TreeTransform<Derived>
2083 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2084 QualType ObjectType) {
2085 DeclarationName Name = NameInfo.getName();
2087 return DeclarationNameInfo();
2089 switch (Name.getNameKind()) {
2090 case DeclarationName::Identifier:
2091 case DeclarationName::ObjCZeroArgSelector:
2092 case DeclarationName::ObjCOneArgSelector:
2093 case DeclarationName::ObjCMultiArgSelector:
2094 case DeclarationName::CXXOperatorName:
2095 case DeclarationName::CXXLiteralOperatorName:
2096 case DeclarationName::CXXUsingDirective:
2099 case DeclarationName::CXXConstructorName:
2100 case DeclarationName::CXXDestructorName:
2101 case DeclarationName::CXXConversionFunctionName: {
2102 TypeSourceInfo *NewTInfo;
2103 CanQualType NewCanTy;
2104 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2105 NewTInfo = getDerived().TransformType(OldTInfo, ObjectType);
2107 return DeclarationNameInfo();
2108 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2112 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2113 QualType NewT = getDerived().TransformType(Name.getCXXNameType(),
2116 return DeclarationNameInfo();
2117 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2120 DeclarationName NewName
2121 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2123 DeclarationNameInfo NewNameInfo(NameInfo);
2124 NewNameInfo.setName(NewName);
2125 NewNameInfo.setNamedTypeInfo(NewTInfo);
2130 assert(0 && "Unknown name kind.");
2131 return DeclarationNameInfo();
2134 template<typename Derived>
2136 TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2137 QualType ObjectType) {
2138 SourceLocation Loc = getDerived().getBaseLocation();
2140 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2141 NestedNameSpecifier *NNS
2142 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
2143 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2146 return TemplateName();
2148 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
2149 TemplateDecl *TransTemplate
2150 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2152 return TemplateName();
2154 if (!getDerived().AlwaysRebuild() &&
2155 NNS == QTN->getQualifier() &&
2156 TransTemplate == Template)
2159 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2163 // These should be getting filtered out before they make it into the AST.
2164 assert(false && "overloaded template name survived to here");
2167 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2168 NestedNameSpecifier *NNS
2169 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
2170 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2172 if (!NNS && DTN->getQualifier())
2173 return TemplateName();
2175 if (!getDerived().AlwaysRebuild() &&
2176 NNS == DTN->getQualifier() &&
2177 ObjectType.isNull())
2180 if (DTN->isIdentifier())
2181 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
2184 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2188 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2189 TemplateDecl *TransTemplate
2190 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2192 return TemplateName();
2194 if (!getDerived().AlwaysRebuild() &&
2195 TransTemplate == Template)
2198 return TemplateName(TransTemplate);
2201 // These should be getting filtered out before they reach the AST.
2202 assert(false && "overloaded function decl survived to here");
2203 return TemplateName();
2206 template<typename Derived>
2207 void TreeTransform<Derived>::InventTemplateArgumentLoc(
2208 const TemplateArgument &Arg,
2209 TemplateArgumentLoc &Output) {
2210 SourceLocation Loc = getDerived().getBaseLocation();
2211 switch (Arg.getKind()) {
2212 case TemplateArgument::Null:
2213 llvm_unreachable("null template argument in TreeTransform");
2216 case TemplateArgument::Type:
2217 Output = TemplateArgumentLoc(Arg,
2218 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2222 case TemplateArgument::Template:
2223 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2226 case TemplateArgument::Expression:
2227 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2230 case TemplateArgument::Declaration:
2231 case TemplateArgument::Integral:
2232 case TemplateArgument::Pack:
2233 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2238 template<typename Derived>
2239 bool TreeTransform<Derived>::TransformTemplateArgument(
2240 const TemplateArgumentLoc &Input,
2241 TemplateArgumentLoc &Output) {
2242 const TemplateArgument &Arg = Input.getArgument();
2243 switch (Arg.getKind()) {
2244 case TemplateArgument::Null:
2245 case TemplateArgument::Integral:
2249 case TemplateArgument::Type: {
2250 TypeSourceInfo *DI = Input.getTypeSourceInfo();
2252 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2254 DI = getDerived().TransformType(DI);
2255 if (!DI) return true;
2257 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2261 case TemplateArgument::Declaration: {
2262 // FIXME: we should never have to transform one of these.
2263 DeclarationName Name;
2264 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2265 Name = ND->getDeclName();
2266 TemporaryBase Rebase(*this, Input.getLocation(), Name);
2267 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2268 if (!D) return true;
2270 Expr *SourceExpr = Input.getSourceDeclExpression();
2272 EnterExpressionEvaluationContext Unevaluated(getSema(),
2274 ExprResult E = getDerived().TransformExpr(SourceExpr);
2275 SourceExpr = (E.isInvalid() ? 0 : E.take());
2278 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2282 case TemplateArgument::Template: {
2283 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2284 TemplateName Template
2285 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2286 if (Template.isNull())
2289 Output = TemplateArgumentLoc(TemplateArgument(Template),
2290 Input.getTemplateQualifierRange(),
2291 Input.getTemplateNameLoc());
2295 case TemplateArgument::Expression: {
2296 // Template argument expressions are not potentially evaluated.
2297 EnterExpressionEvaluationContext Unevaluated(getSema(),
2300 Expr *InputExpr = Input.getSourceExpression();
2301 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2304 = getDerived().TransformExpr(InputExpr);
2305 if (E.isInvalid()) return true;
2306 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2310 case TemplateArgument::Pack: {
2311 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2312 TransformedArgs.reserve(Arg.pack_size());
2313 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2314 AEnd = Arg.pack_end();
2317 // FIXME: preserve source information here when we start
2318 // caring about parameter packs.
2320 TemplateArgumentLoc InputArg;
2321 TemplateArgumentLoc OutputArg;
2322 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2323 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2326 TransformedArgs.push_back(OutputArg.getArgument());
2328 TemplateArgument Result;
2329 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
2331 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
2336 // Work around bogus GCC warning
2340 //===----------------------------------------------------------------------===//
2341 // Type transformation
2342 //===----------------------------------------------------------------------===//
2344 template<typename Derived>
2345 QualType TreeTransform<Derived>::TransformType(QualType T,
2346 QualType ObjectType) {
2347 if (getDerived().AlreadyTransformed(T))
2350 // Temporary workaround. All of these transformations should
2351 // eventually turn into transformations on TypeLocs.
2352 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
2353 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
2355 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
2360 return NewDI->getType();
2363 template<typename Derived>
2364 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2365 QualType ObjectType) {
2366 if (getDerived().AlreadyTransformed(DI->getType()))
2371 TypeLoc TL = DI->getTypeLoc();
2372 TLB.reserve(TL.getFullDataSize());
2374 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
2375 if (Result.isNull())
2378 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2381 template<typename Derived>
2383 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2384 QualType ObjectType) {
2385 switch (T.getTypeLocClass()) {
2386 #define ABSTRACT_TYPELOC(CLASS, PARENT)
2387 #define TYPELOC(CLASS, PARENT) \
2388 case TypeLoc::CLASS: \
2389 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2391 #include "clang/AST/TypeLocNodes.def"
2394 llvm_unreachable("unhandled type loc!");
2398 /// FIXME: By default, this routine adds type qualifiers only to types
2399 /// that can have qualifiers, and silently suppresses those qualifiers
2400 /// that are not permitted (e.g., qualifiers on reference or function
2401 /// types). This is the right thing for template instantiation, but
2402 /// probably not for other clients.
2403 template<typename Derived>
2405 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2407 QualType ObjectType) {
2408 Qualifiers Quals = T.getType().getLocalQualifiers();
2410 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2412 if (Result.isNull())
2415 // Silently suppress qualifiers if the result type can't be qualified.
2416 // FIXME: this is the right thing for template instantiation, but
2417 // probably not for other clients.
2418 if (Result->isFunctionType() || Result->isReferenceType())
2421 if (!Quals.empty()) {
2422 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2423 TLB.push<QualifiedTypeLoc>(Result);
2424 // No location information to preserve.
2430 template <class TyLoc> static inline
2431 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2432 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2433 NewT.setNameLoc(T.getNameLoc());
2437 template<typename Derived>
2438 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2440 QualType ObjectType) {
2441 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2442 NewT.setBuiltinLoc(T.getBuiltinLoc());
2443 if (T.needsExtraLocalData())
2444 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2448 template<typename Derived>
2449 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2451 QualType ObjectType) {
2453 return TransformTypeSpecType(TLB, T);
2456 template<typename Derived>
2457 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2459 QualType ObjectType) {
2460 QualType PointeeType
2461 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2462 if (PointeeType.isNull())
2465 QualType Result = TL.getType();
2466 if (PointeeType->getAs<ObjCObjectType>()) {
2467 // A dependent pointer type 'T *' has is being transformed such
2468 // that an Objective-C class type is being replaced for 'T'. The
2469 // resulting pointer type is an ObjCObjectPointerType, not a
2471 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
2473 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2474 NewT.setStarLoc(TL.getStarLoc());
2478 if (getDerived().AlwaysRebuild() ||
2479 PointeeType != TL.getPointeeLoc().getType()) {
2480 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2481 if (Result.isNull())
2485 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2486 NewT.setSigilLoc(TL.getSigilLoc());
2490 template<typename Derived>
2492 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2493 BlockPointerTypeLoc TL,
2494 QualType ObjectType) {
2495 QualType PointeeType
2496 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2497 if (PointeeType.isNull())
2500 QualType Result = TL.getType();
2501 if (getDerived().AlwaysRebuild() ||
2502 PointeeType != TL.getPointeeLoc().getType()) {
2503 Result = getDerived().RebuildBlockPointerType(PointeeType,
2505 if (Result.isNull())
2509 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
2510 NewT.setSigilLoc(TL.getSigilLoc());
2514 /// Transforms a reference type. Note that somewhat paradoxically we
2515 /// don't care whether the type itself is an l-value type or an r-value
2516 /// type; we only care if the type was *written* as an l-value type
2517 /// or an r-value type.
2518 template<typename Derived>
2520 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2521 ReferenceTypeLoc TL,
2522 QualType ObjectType) {
2523 const ReferenceType *T = TL.getTypePtr();
2525 // Note that this works with the pointee-as-written.
2526 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2527 if (PointeeType.isNull())
2530 QualType Result = TL.getType();
2531 if (getDerived().AlwaysRebuild() ||
2532 PointeeType != T->getPointeeTypeAsWritten()) {
2533 Result = getDerived().RebuildReferenceType(PointeeType,
2534 T->isSpelledAsLValue(),
2536 if (Result.isNull())
2540 // r-value references can be rebuilt as l-value references.
2541 ReferenceTypeLoc NewTL;
2542 if (isa<LValueReferenceType>(Result))
2543 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2545 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2546 NewTL.setSigilLoc(TL.getSigilLoc());
2551 template<typename Derived>
2553 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2554 LValueReferenceTypeLoc TL,
2555 QualType ObjectType) {
2556 return TransformReferenceType(TLB, TL, ObjectType);
2559 template<typename Derived>
2561 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2562 RValueReferenceTypeLoc TL,
2563 QualType ObjectType) {
2564 return TransformReferenceType(TLB, TL, ObjectType);
2567 template<typename Derived>
2569 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2570 MemberPointerTypeLoc TL,
2571 QualType ObjectType) {
2572 MemberPointerType *T = TL.getTypePtr();
2574 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2575 if (PointeeType.isNull())
2578 // TODO: preserve source information for this.
2580 = getDerived().TransformType(QualType(T->getClass(), 0));
2581 if (ClassType.isNull())
2584 QualType Result = TL.getType();
2585 if (getDerived().AlwaysRebuild() ||
2586 PointeeType != T->getPointeeType() ||
2587 ClassType != QualType(T->getClass(), 0)) {
2588 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2590 if (Result.isNull())
2594 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2595 NewTL.setSigilLoc(TL.getSigilLoc());
2600 template<typename Derived>
2602 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2603 ConstantArrayTypeLoc TL,
2604 QualType ObjectType) {
2605 ConstantArrayType *T = TL.getTypePtr();
2606 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2607 if (ElementType.isNull())
2610 QualType Result = TL.getType();
2611 if (getDerived().AlwaysRebuild() ||
2612 ElementType != T->getElementType()) {
2613 Result = getDerived().RebuildConstantArrayType(ElementType,
2614 T->getSizeModifier(),
2616 T->getIndexTypeCVRQualifiers(),
2617 TL.getBracketsRange());
2618 if (Result.isNull())
2622 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2623 NewTL.setLBracketLoc(TL.getLBracketLoc());
2624 NewTL.setRBracketLoc(TL.getRBracketLoc());
2626 Expr *Size = TL.getSizeExpr();
2628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2629 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2631 NewTL.setSizeExpr(Size);
2636 template<typename Derived>
2637 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
2638 TypeLocBuilder &TLB,
2639 IncompleteArrayTypeLoc TL,
2640 QualType ObjectType) {
2641 IncompleteArrayType *T = TL.getTypePtr();
2642 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2643 if (ElementType.isNull())
2646 QualType Result = TL.getType();
2647 if (getDerived().AlwaysRebuild() ||
2648 ElementType != T->getElementType()) {
2649 Result = getDerived().RebuildIncompleteArrayType(ElementType,
2650 T->getSizeModifier(),
2651 T->getIndexTypeCVRQualifiers(),
2652 TL.getBracketsRange());
2653 if (Result.isNull())
2657 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2658 NewTL.setLBracketLoc(TL.getLBracketLoc());
2659 NewTL.setRBracketLoc(TL.getRBracketLoc());
2660 NewTL.setSizeExpr(0);
2665 template<typename Derived>
2667 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2668 VariableArrayTypeLoc TL,
2669 QualType ObjectType) {
2670 VariableArrayType *T = TL.getTypePtr();
2671 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2672 if (ElementType.isNull())
2675 // Array bounds are not potentially evaluated contexts
2676 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2678 ExprResult SizeResult
2679 = getDerived().TransformExpr(T->getSizeExpr());
2680 if (SizeResult.isInvalid())
2683 Expr *Size = SizeResult.take();
2685 QualType Result = TL.getType();
2686 if (getDerived().AlwaysRebuild() ||
2687 ElementType != T->getElementType() ||
2688 Size != T->getSizeExpr()) {
2689 Result = getDerived().RebuildVariableArrayType(ElementType,
2690 T->getSizeModifier(),
2692 T->getIndexTypeCVRQualifiers(),
2693 TL.getBracketsRange());
2694 if (Result.isNull())
2698 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2699 NewTL.setLBracketLoc(TL.getLBracketLoc());
2700 NewTL.setRBracketLoc(TL.getRBracketLoc());
2701 NewTL.setSizeExpr(Size);
2706 template<typename Derived>
2708 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2709 DependentSizedArrayTypeLoc TL,
2710 QualType ObjectType) {
2711 DependentSizedArrayType *T = TL.getTypePtr();
2712 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2713 if (ElementType.isNull())
2716 // Array bounds are not potentially evaluated contexts
2717 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2719 ExprResult SizeResult
2720 = getDerived().TransformExpr(T->getSizeExpr());
2721 if (SizeResult.isInvalid())
2724 Expr *Size = static_cast<Expr*>(SizeResult.get());
2726 QualType Result = TL.getType();
2727 if (getDerived().AlwaysRebuild() ||
2728 ElementType != T->getElementType() ||
2729 Size != T->getSizeExpr()) {
2730 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2731 T->getSizeModifier(),
2733 T->getIndexTypeCVRQualifiers(),
2734 TL.getBracketsRange());
2735 if (Result.isNull())
2738 else SizeResult.take();
2740 // We might have any sort of array type now, but fortunately they
2741 // all have the same location layout.
2742 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2743 NewTL.setLBracketLoc(TL.getLBracketLoc());
2744 NewTL.setRBracketLoc(TL.getRBracketLoc());
2745 NewTL.setSizeExpr(Size);
2750 template<typename Derived>
2751 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
2752 TypeLocBuilder &TLB,
2753 DependentSizedExtVectorTypeLoc TL,
2754 QualType ObjectType) {
2755 DependentSizedExtVectorType *T = TL.getTypePtr();
2757 // FIXME: ext vector locs should be nested
2758 QualType ElementType = getDerived().TransformType(T->getElementType());
2759 if (ElementType.isNull())
2762 // Vector sizes are not potentially evaluated contexts
2763 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2765 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2766 if (Size.isInvalid())
2769 QualType Result = TL.getType();
2770 if (getDerived().AlwaysRebuild() ||
2771 ElementType != T->getElementType() ||
2772 Size.get() != T->getSizeExpr()) {
2773 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
2775 T->getAttributeLoc());
2776 if (Result.isNull())
2780 // Result might be dependent or not.
2781 if (isa<DependentSizedExtVectorType>(Result)) {
2782 DependentSizedExtVectorTypeLoc NewTL
2783 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2784 NewTL.setNameLoc(TL.getNameLoc());
2786 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2787 NewTL.setNameLoc(TL.getNameLoc());
2793 template<typename Derived>
2794 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2796 QualType ObjectType) {
2797 VectorType *T = TL.getTypePtr();
2798 QualType ElementType = getDerived().TransformType(T->getElementType());
2799 if (ElementType.isNull())
2802 QualType Result = TL.getType();
2803 if (getDerived().AlwaysRebuild() ||
2804 ElementType != T->getElementType()) {
2805 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2806 T->getAltiVecSpecific());
2807 if (Result.isNull())
2811 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2812 NewTL.setNameLoc(TL.getNameLoc());
2817 template<typename Derived>
2818 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2819 ExtVectorTypeLoc TL,
2820 QualType ObjectType) {
2821 VectorType *T = TL.getTypePtr();
2822 QualType ElementType = getDerived().TransformType(T->getElementType());
2823 if (ElementType.isNull())
2826 QualType Result = TL.getType();
2827 if (getDerived().AlwaysRebuild() ||
2828 ElementType != T->getElementType()) {
2829 Result = getDerived().RebuildExtVectorType(ElementType,
2830 T->getNumElements(),
2831 /*FIXME*/ SourceLocation());
2832 if (Result.isNull())
2836 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2837 NewTL.setNameLoc(TL.getNameLoc());
2842 template<typename Derived>
2844 TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2845 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2846 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2853 return ParmVarDecl::Create(SemaRef.Context,
2854 OldParm->getDeclContext(),
2855 OldParm->getLocation(),
2856 OldParm->getIdentifier(),
2859 OldParm->getStorageClass(),
2860 OldParm->getStorageClassAsWritten(),
2864 template<typename Derived>
2865 bool TreeTransform<Derived>::
2866 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2867 llvm::SmallVectorImpl<QualType> &PTypes,
2868 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2869 FunctionProtoType *T = TL.getTypePtr();
2871 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2872 ParmVarDecl *OldParm = TL.getArg(i);
2875 ParmVarDecl *NewParm;
2878 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2881 NewType = NewParm->getType();
2883 // Deal with the possibility that we don't have a parameter
2884 // declaration for this parameter.
2888 QualType OldType = T->getArgType(i);
2889 NewType = getDerived().TransformType(OldType);
2890 if (NewType.isNull())
2894 PTypes.push_back(NewType);
2895 PVars.push_back(NewParm);
2901 template<typename Derived>
2903 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2904 FunctionProtoTypeLoc TL,
2905 QualType ObjectType) {
2906 // Transform the parameters and return type.
2908 // We instantiate in source order, with the return type first followed by
2909 // the parameters, because users tend to expect this (even if they shouldn't
2912 // FIXME: When we implement late-specified return types, we'll need to
2913 // instantiate the return tpe *after* the parameter types in that case,
2914 // since the return type can then refer to the parameters themselves (via
2915 // decltype, sizeof, etc.).
2916 llvm::SmallVector<QualType, 4> ParamTypes;
2917 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2918 FunctionProtoType *T = TL.getTypePtr();
2919 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2920 if (ResultType.isNull())
2923 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2926 QualType Result = TL.getType();
2927 if (getDerived().AlwaysRebuild() ||
2928 ResultType != T->getResultType() ||
2929 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2930 Result = getDerived().RebuildFunctionProtoType(ResultType,
2936 if (Result.isNull())
2940 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2941 NewTL.setLParenLoc(TL.getLParenLoc());
2942 NewTL.setRParenLoc(TL.getRParenLoc());
2943 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2944 NewTL.setArg(i, ParamDecls[i]);
2949 template<typename Derived>
2950 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
2951 TypeLocBuilder &TLB,
2952 FunctionNoProtoTypeLoc TL,
2953 QualType ObjectType) {
2954 FunctionNoProtoType *T = TL.getTypePtr();
2955 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2956 if (ResultType.isNull())
2959 QualType Result = TL.getType();
2960 if (getDerived().AlwaysRebuild() ||
2961 ResultType != T->getResultType())
2962 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2964 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2965 NewTL.setLParenLoc(TL.getLParenLoc());
2966 NewTL.setRParenLoc(TL.getRParenLoc());
2971 template<typename Derived> QualType
2972 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2973 UnresolvedUsingTypeLoc TL,
2974 QualType ObjectType) {
2975 UnresolvedUsingType *T = TL.getTypePtr();
2976 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
2980 QualType Result = TL.getType();
2981 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2982 Result = getDerived().RebuildUnresolvedUsingType(D);
2983 if (Result.isNull())
2987 // We might get an arbitrary type spec type back. We should at
2988 // least always get a type spec type, though.
2989 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2990 NewTL.setNameLoc(TL.getNameLoc());
2995 template<typename Derived>
2996 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2998 QualType ObjectType) {
2999 TypedefType *T = TL.getTypePtr();
3000 TypedefDecl *Typedef
3001 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3006 QualType Result = TL.getType();
3007 if (getDerived().AlwaysRebuild() ||
3008 Typedef != T->getDecl()) {
3009 Result = getDerived().RebuildTypedefType(Typedef);
3010 if (Result.isNull())
3014 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3015 NewTL.setNameLoc(TL.getNameLoc());
3020 template<typename Derived>
3021 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
3022 TypeOfExprTypeLoc TL,
3023 QualType ObjectType) {
3024 // typeof expressions are not potentially evaluated contexts
3025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3027 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
3031 QualType Result = TL.getType();
3032 if (getDerived().AlwaysRebuild() ||
3033 E.get() != TL.getUnderlyingExpr()) {
3034 Result = getDerived().RebuildTypeOfExprType(E.get());
3035 if (Result.isNull())
3040 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
3041 NewTL.setTypeofLoc(TL.getTypeofLoc());
3042 NewTL.setLParenLoc(TL.getLParenLoc());
3043 NewTL.setRParenLoc(TL.getRParenLoc());
3048 template<typename Derived>
3049 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
3051 QualType ObjectType) {
3052 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3053 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3057 QualType Result = TL.getType();
3058 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3059 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
3060 if (Result.isNull())
3064 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
3065 NewTL.setTypeofLoc(TL.getTypeofLoc());
3066 NewTL.setLParenLoc(TL.getLParenLoc());
3067 NewTL.setRParenLoc(TL.getRParenLoc());
3068 NewTL.setUnderlyingTInfo(New_Under_TI);
3073 template<typename Derived>
3074 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
3076 QualType ObjectType) {
3077 DecltypeType *T = TL.getTypePtr();
3079 // decltype expressions are not potentially evaluated contexts
3080 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3082 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3086 QualType Result = TL.getType();
3087 if (getDerived().AlwaysRebuild() ||
3088 E.get() != T->getUnderlyingExpr()) {
3089 Result = getDerived().RebuildDecltypeType(E.get());
3090 if (Result.isNull())
3095 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3096 NewTL.setNameLoc(TL.getNameLoc());
3101 template<typename Derived>
3102 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
3104 QualType ObjectType) {
3105 RecordType *T = TL.getTypePtr();
3107 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3112 QualType Result = TL.getType();
3113 if (getDerived().AlwaysRebuild() ||
3114 Record != T->getDecl()) {
3115 Result = getDerived().RebuildRecordType(Record);
3116 if (Result.isNull())
3120 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3121 NewTL.setNameLoc(TL.getNameLoc());
3126 template<typename Derived>
3127 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
3129 QualType ObjectType) {
3130 EnumType *T = TL.getTypePtr();
3132 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3137 QualType Result = TL.getType();
3138 if (getDerived().AlwaysRebuild() ||
3139 Enum != T->getDecl()) {
3140 Result = getDerived().RebuildEnumType(Enum);
3141 if (Result.isNull())
3145 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3146 NewTL.setNameLoc(TL.getNameLoc());
3151 template<typename Derived>
3152 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3153 TypeLocBuilder &TLB,
3154 InjectedClassNameTypeLoc TL,
3155 QualType ObjectType) {
3156 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3157 TL.getTypePtr()->getDecl());
3158 if (!D) return QualType();
3160 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3161 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3166 template<typename Derived>
3167 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
3168 TypeLocBuilder &TLB,
3169 TemplateTypeParmTypeLoc TL,
3170 QualType ObjectType) {
3171 return TransformTypeSpecType(TLB, TL);
3174 template<typename Derived>
3175 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
3176 TypeLocBuilder &TLB,
3177 SubstTemplateTypeParmTypeLoc TL,
3178 QualType ObjectType) {
3179 return TransformTypeSpecType(TLB, TL);
3182 template<typename Derived>
3183 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3184 const TemplateSpecializationType *TST,
3185 QualType ObjectType) {
3186 // FIXME: this entire method is a temporary workaround; callers
3187 // should be rewritten to provide real type locs.
3189 // Fake up a TemplateSpecializationTypeLoc.
3191 TemplateSpecializationTypeLoc TL
3192 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3194 SourceLocation BaseLoc = getDerived().getBaseLocation();
3196 TL.setTemplateNameLoc(BaseLoc);
3197 TL.setLAngleLoc(BaseLoc);
3198 TL.setRAngleLoc(BaseLoc);
3199 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3200 const TemplateArgument &TA = TST->getArg(i);
3201 TemplateArgumentLoc TAL;
3202 getDerived().InventTemplateArgumentLoc(TA, TAL);
3203 TL.setArgLocInfo(i, TAL.getLocInfo());
3206 TypeLocBuilder IgnoredTLB;
3207 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
3210 template<typename Derived>
3211 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3212 TypeLocBuilder &TLB,
3213 TemplateSpecializationTypeLoc TL,
3214 QualType ObjectType) {
3215 const TemplateSpecializationType *T = TL.getTypePtr();
3217 TemplateName Template
3218 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
3219 if (Template.isNull())
3222 TemplateArgumentListInfo NewTemplateArgs;
3223 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3224 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3226 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3227 TemplateArgumentLoc Loc;
3228 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
3230 NewTemplateArgs.addArgument(Loc);
3233 // FIXME: maybe don't rebuild if all the template arguments are the same.
3236 getDerived().RebuildTemplateSpecializationType(Template,
3237 TL.getTemplateNameLoc(),
3240 if (!Result.isNull()) {
3241 TemplateSpecializationTypeLoc NewTL
3242 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3243 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3244 NewTL.setLAngleLoc(TL.getLAngleLoc());
3245 NewTL.setRAngleLoc(TL.getRAngleLoc());
3246 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3247 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
3253 template<typename Derived>
3255 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3256 ElaboratedTypeLoc TL,
3257 QualType ObjectType) {
3258 ElaboratedType *T = TL.getTypePtr();
3260 NestedNameSpecifier *NNS = 0;
3261 // NOTE: the qualifier in an ElaboratedType is optional.
3262 if (T->getQualifier() != 0) {
3263 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3264 TL.getQualifierRange(),
3271 // FIXME: this test is meant to workaround a problem (failing assertion)
3272 // occurring if directly executing the code in the else branch.
3273 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3274 TemplateSpecializationTypeLoc OldNamedTL
3275 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3276 const TemplateSpecializationType* OldTST
3277 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
3278 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3279 if (NamedT.isNull())
3281 TemplateSpecializationTypeLoc NewNamedTL
3282 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3283 NewNamedTL.copy(OldNamedTL);
3286 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3287 if (NamedT.isNull())
3291 QualType Result = TL.getType();
3292 if (getDerived().AlwaysRebuild() ||
3293 NNS != T->getQualifier() ||
3294 NamedT != T->getNamedType()) {
3295 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
3296 if (Result.isNull())
3300 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3301 NewTL.setKeywordLoc(TL.getKeywordLoc());
3302 NewTL.setQualifierRange(TL.getQualifierRange());
3307 template<typename Derived>
3308 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3309 DependentNameTypeLoc TL,
3310 QualType ObjectType) {
3311 DependentNameType *T = TL.getTypePtr();
3313 NestedNameSpecifier *NNS
3314 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3315 TL.getQualifierRange(),
3321 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3324 TL.getQualifierRange(),
3326 if (Result.isNull())
3329 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3330 QualType NamedT = ElabT->getNamedType();
3331 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3333 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3334 NewTL.setKeywordLoc(TL.getKeywordLoc());
3335 NewTL.setQualifierRange(TL.getQualifierRange());
3337 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3338 NewTL.setKeywordLoc(TL.getKeywordLoc());
3339 NewTL.setQualifierRange(TL.getQualifierRange());
3340 NewTL.setNameLoc(TL.getNameLoc());
3345 template<typename Derived>
3346 QualType TreeTransform<Derived>::
3347 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3348 DependentTemplateSpecializationTypeLoc TL,
3349 QualType ObjectType) {
3350 DependentTemplateSpecializationType *T = TL.getTypePtr();
3352 NestedNameSpecifier *NNS
3353 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3354 TL.getQualifierRange(),
3359 TemplateArgumentListInfo NewTemplateArgs;
3360 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3361 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3363 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3364 TemplateArgumentLoc Loc;
3365 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3367 NewTemplateArgs.addArgument(Loc);
3370 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3376 if (Result.isNull())
3379 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3380 QualType NamedT = ElabT->getNamedType();
3382 // Copy information relevant to the template specialization.
3383 TemplateSpecializationTypeLoc NamedTL
3384 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3385 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3386 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3387 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3388 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3390 // Copy information relevant to the elaborated type.
3391 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3392 NewTL.setKeywordLoc(TL.getKeywordLoc());
3393 NewTL.setQualifierRange(TL.getQualifierRange());
3395 TypeLoc NewTL(Result, TL.getOpaqueData());
3396 TLB.pushFullCopy(NewTL);
3401 template<typename Derived>
3403 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
3404 ObjCInterfaceTypeLoc TL,
3405 QualType ObjectType) {
3406 // ObjCInterfaceType is never dependent.
3407 TLB.pushFullCopy(TL);
3408 return TL.getType();
3411 template<typename Derived>
3413 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3414 ObjCObjectTypeLoc TL,
3415 QualType ObjectType) {
3416 // ObjCObjectType is never dependent.
3417 TLB.pushFullCopy(TL);
3418 return TL.getType();
3421 template<typename Derived>
3423 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
3424 ObjCObjectPointerTypeLoc TL,
3425 QualType ObjectType) {
3426 // ObjCObjectPointerType is never dependent.
3427 TLB.pushFullCopy(TL);
3428 return TL.getType();
3431 //===----------------------------------------------------------------------===//
3432 // Statement transformation
3433 //===----------------------------------------------------------------------===//
3434 template<typename Derived>
3436 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3437 return SemaRef.Owned(S->Retain());
3440 template<typename Derived>
3442 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3443 return getDerived().TransformCompoundStmt(S, false);
3446 template<typename Derived>
3448 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
3450 bool SubStmtInvalid = false;
3451 bool SubStmtChanged = false;
3452 ASTOwningVector<Stmt*> Statements(getSema());
3453 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3455 StmtResult Result = getDerived().TransformStmt(*B);
3456 if (Result.isInvalid()) {
3457 // Immediately fail if this was a DeclStmt, since it's very
3458 // likely that this will cause problems for future statements.
3459 if (isa<DeclStmt>(*B))
3462 // Otherwise, just keep processing substatements and fail later.
3463 SubStmtInvalid = true;
3467 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3468 Statements.push_back(Result.takeAs<Stmt>());
3474 if (!getDerived().AlwaysRebuild() &&
3476 return SemaRef.Owned(S->Retain());
3478 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3479 move_arg(Statements),
3484 template<typename Derived>
3486 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
3487 ExprResult LHS, RHS;
3489 // The case value expressions are not potentially evaluated.
3490 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3492 // Transform the left-hand case value.
3493 LHS = getDerived().TransformExpr(S->getLHS());
3494 if (LHS.isInvalid())
3497 // Transform the right-hand case value (for the GNU case-range extension).
3498 RHS = getDerived().TransformExpr(S->getRHS());
3499 if (RHS.isInvalid())
3503 // Build the case statement.
3504 // Case statements are always rebuilt so that they will attached to their
3505 // transformed switch statement.
3506 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3508 S->getEllipsisLoc(),
3511 if (Case.isInvalid())
3514 // Transform the statement following the case
3515 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3516 if (SubStmt.isInvalid())
3519 // Attach the body to the case statement
3520 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
3523 template<typename Derived>
3525 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
3526 // Transform the statement following the default case
3527 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3528 if (SubStmt.isInvalid())
3531 // Default statements are always rebuilt
3532 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3536 template<typename Derived>
3538 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
3539 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3540 if (SubStmt.isInvalid())
3543 // FIXME: Pass the real colon location in.
3544 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3545 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3549 template<typename Derived>
3551 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
3552 // Transform the condition
3554 VarDecl *ConditionVar = 0;
3555 if (S->getConditionVariable()) {
3557 = cast_or_null<VarDecl>(
3558 getDerived().TransformDefinition(
3559 S->getConditionVariable()->getLocation(),
3560 S->getConditionVariable()));
3564 Cond = getDerived().TransformExpr(S->getCond());
3566 if (Cond.isInvalid())
3569 // Convert the condition to a boolean value.
3571 ExprResult CondE = getSema().ActOnBooleanCondition(0,
3574 if (CondE.isInvalid())
3581 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3582 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3585 // Transform the "then" branch.
3586 StmtResult Then = getDerived().TransformStmt(S->getThen());
3587 if (Then.isInvalid())
3590 // Transform the "else" branch.
3591 StmtResult Else = getDerived().TransformStmt(S->getElse());
3592 if (Else.isInvalid())
3595 if (!getDerived().AlwaysRebuild() &&
3596 FullCond.get() == S->getCond() &&
3597 ConditionVar == S->getConditionVariable() &&
3598 Then.get() == S->getThen() &&
3599 Else.get() == S->getElse())
3600 return SemaRef.Owned(S->Retain());
3602 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3604 S->getElseLoc(), Else.get());
3607 template<typename Derived>
3609 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
3610 // Transform the condition.
3612 VarDecl *ConditionVar = 0;
3613 if (S->getConditionVariable()) {
3615 = cast_or_null<VarDecl>(
3616 getDerived().TransformDefinition(
3617 S->getConditionVariable()->getLocation(),
3618 S->getConditionVariable()));
3622 Cond = getDerived().TransformExpr(S->getCond());
3624 if (Cond.isInvalid())
3628 // Rebuild the switch statement.
3630 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
3632 if (Switch.isInvalid())
3635 // Transform the body of the switch statement.
3636 StmtResult Body = getDerived().TransformStmt(S->getBody());
3637 if (Body.isInvalid())
3640 // Complete the switch statement.
3641 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
3645 template<typename Derived>
3647 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
3648 // Transform the condition
3650 VarDecl *ConditionVar = 0;
3651 if (S->getConditionVariable()) {
3653 = cast_or_null<VarDecl>(
3654 getDerived().TransformDefinition(
3655 S->getConditionVariable()->getLocation(),
3656 S->getConditionVariable()));
3660 Cond = getDerived().TransformExpr(S->getCond());
3662 if (Cond.isInvalid())
3666 // Convert the condition to a boolean value.
3667 ExprResult CondE = getSema().ActOnBooleanCondition(0,
3670 if (CondE.isInvalid())
3676 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3677 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3680 // Transform the body
3681 StmtResult Body = getDerived().TransformStmt(S->getBody());
3682 if (Body.isInvalid())
3685 if (!getDerived().AlwaysRebuild() &&
3686 FullCond.get() == S->getCond() &&
3687 ConditionVar == S->getConditionVariable() &&
3688 Body.get() == S->getBody())
3691 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
3692 ConditionVar, Body.get());
3695 template<typename Derived>
3697 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3698 // Transform the body
3699 StmtResult Body = getDerived().TransformStmt(S->getBody());
3700 if (Body.isInvalid())
3703 // Transform the condition
3704 ExprResult Cond = getDerived().TransformExpr(S->getCond());
3705 if (Cond.isInvalid())
3708 if (!getDerived().AlwaysRebuild() &&
3709 Cond.get() == S->getCond() &&
3710 Body.get() == S->getBody())
3711 return SemaRef.Owned(S->Retain());
3713 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
3714 /*FIXME:*/S->getWhileLoc(), Cond.get(),
3718 template<typename Derived>
3720 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
3721 // Transform the initialization statement
3722 StmtResult Init = getDerived().TransformStmt(S->getInit());
3723 if (Init.isInvalid())
3726 // Transform the condition
3728 VarDecl *ConditionVar = 0;
3729 if (S->getConditionVariable()) {
3731 = cast_or_null<VarDecl>(
3732 getDerived().TransformDefinition(
3733 S->getConditionVariable()->getLocation(),
3734 S->getConditionVariable()));
3738 Cond = getDerived().TransformExpr(S->getCond());
3740 if (Cond.isInvalid())
3744 // Convert the condition to a boolean value.
3745 ExprResult CondE = getSema().ActOnBooleanCondition(0,
3748 if (CondE.isInvalid())
3755 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
3756 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3759 // Transform the increment
3760 ExprResult Inc = getDerived().TransformExpr(S->getInc());
3761 if (Inc.isInvalid())
3764 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
3765 if (S->getInc() && !FullInc.get())
3768 // Transform the body
3769 StmtResult Body = getDerived().TransformStmt(S->getBody());
3770 if (Body.isInvalid())
3773 if (!getDerived().AlwaysRebuild() &&
3774 Init.get() == S->getInit() &&
3775 FullCond.get() == S->getCond() &&
3776 Inc.get() == S->getInc() &&
3777 Body.get() == S->getBody())
3778 return SemaRef.Owned(S->Retain());
3780 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
3781 Init.get(), FullCond, ConditionVar,
3782 FullInc, S->getRParenLoc(), Body.get());
3785 template<typename Derived>
3787 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
3788 // Goto statements must always be rebuilt, to resolve the label.
3789 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
3793 template<typename Derived>
3795 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
3796 ExprResult Target = getDerived().TransformExpr(S->getTarget());
3797 if (Target.isInvalid())
3800 if (!getDerived().AlwaysRebuild() &&
3801 Target.get() == S->getTarget())
3802 return SemaRef.Owned(S->Retain());
3804 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3808 template<typename Derived>
3810 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3811 return SemaRef.Owned(S->Retain());
3814 template<typename Derived>
3816 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3817 return SemaRef.Owned(S->Retain());
3820 template<typename Derived>
3822 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
3823 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
3824 if (Result.isInvalid())
3827 // FIXME: We always rebuild the return statement because there is no way
3828 // to tell whether the return type of the function has changed.
3829 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
3832 template<typename Derived>
3834 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
3835 bool DeclChanged = false;
3836 llvm::SmallVector<Decl *, 4> Decls;
3837 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3839 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3844 if (Transformed != *D)
3847 Decls.push_back(Transformed);
3850 if (!getDerived().AlwaysRebuild() && !DeclChanged)
3851 return SemaRef.Owned(S->Retain());
3853 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
3854 S->getStartLoc(), S->getEndLoc());
3857 template<typename Derived>
3859 TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
3860 assert(false && "SwitchCase is abstract and cannot be transformed");
3861 return SemaRef.Owned(S->Retain());
3864 template<typename Derived>
3866 TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3868 ASTOwningVector<Expr*> Constraints(getSema());
3869 ASTOwningVector<Expr*> Exprs(getSema());
3870 llvm::SmallVector<IdentifierInfo *, 4> Names;
3872 ExprResult AsmString;
3873 ASTOwningVector<Expr*> Clobbers(getSema());
3875 bool ExprsChanged = false;
3877 // Go through the outputs.
3878 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
3879 Names.push_back(S->getOutputIdentifier(I));
3881 // No need to transform the constraint literal.
3882 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3884 // Transform the output expr.
3885 Expr *OutputExpr = S->getOutputExpr(I);
3886 ExprResult Result = getDerived().TransformExpr(OutputExpr);
3887 if (Result.isInvalid())
3890 ExprsChanged |= Result.get() != OutputExpr;
3892 Exprs.push_back(Result.get());
3895 // Go through the inputs.
3896 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
3897 Names.push_back(S->getInputIdentifier(I));
3899 // No need to transform the constraint literal.
3900 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3902 // Transform the input expr.
3903 Expr *InputExpr = S->getInputExpr(I);
3904 ExprResult Result = getDerived().TransformExpr(InputExpr);
3905 if (Result.isInvalid())
3908 ExprsChanged |= Result.get() != InputExpr;
3910 Exprs.push_back(Result.get());
3913 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3914 return SemaRef.Owned(S->Retain());
3916 // Go through the clobbers.
3917 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3918 Clobbers.push_back(S->getClobber(I)->Retain());
3920 // No need to transform the asm string literal.
3921 AsmString = SemaRef.Owned(S->getAsmString());
3923 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3929 move_arg(Constraints),
3938 template<typename Derived>
3940 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
3941 // Transform the body of the @try.
3942 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3943 if (TryBody.isInvalid())
3946 // Transform the @catch statements (if present).
3947 bool AnyCatchChanged = false;
3948 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
3949 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3950 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
3951 if (Catch.isInvalid())
3953 if (Catch.get() != S->getCatchStmt(I))
3954 AnyCatchChanged = true;
3955 CatchStmts.push_back(Catch.release());
3958 // Transform the @finally statement (if present).
3960 if (S->getFinallyStmt()) {
3961 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3962 if (Finally.isInvalid())
3966 // If nothing changed, just retain this statement.
3967 if (!getDerived().AlwaysRebuild() &&
3968 TryBody.get() == S->getTryBody() &&
3970 Finally.get() == S->getFinallyStmt())
3971 return SemaRef.Owned(S->Retain());
3973 // Build a new statement.
3974 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
3975 move_arg(CatchStmts), Finally.get());
3978 template<typename Derived>
3980 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
3981 // Transform the @catch parameter, if there is one.
3983 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3984 TypeSourceInfo *TSInfo = 0;
3985 if (FromVar->getTypeSourceInfo()) {
3986 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3993 T = TSInfo->getType();
3995 T = getDerived().TransformType(FromVar->getType());
4000 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4005 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
4006 if (Body.isInvalid())
4009 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
4014 template<typename Derived>
4016 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
4017 // Transform the body.
4018 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4019 if (Body.isInvalid())
4022 // If nothing changed, just retain this statement.
4023 if (!getDerived().AlwaysRebuild() &&
4024 Body.get() == S->getFinallyBody())
4025 return SemaRef.Owned(S->Retain());
4027 // Build a new statement.
4028 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4032 template<typename Derived>
4034 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
4036 if (S->getThrowExpr()) {
4037 Operand = getDerived().TransformExpr(S->getThrowExpr());
4038 if (Operand.isInvalid())
4042 if (!getDerived().AlwaysRebuild() &&
4043 Operand.get() == S->getThrowExpr())
4044 return getSema().Owned(S->Retain());
4046 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
4049 template<typename Derived>
4051 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
4052 ObjCAtSynchronizedStmt *S) {
4053 // Transform the object we are locking.
4054 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4055 if (Object.isInvalid())
4058 // Transform the body.
4059 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4060 if (Body.isInvalid())
4063 // If nothing change, just retain the current statement.
4064 if (!getDerived().AlwaysRebuild() &&
4065 Object.get() == S->getSynchExpr() &&
4066 Body.get() == S->getSynchBody())
4067 return SemaRef.Owned(S->Retain());
4069 // Build a new statement.
4070 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4071 Object.get(), Body.get());
4074 template<typename Derived>
4076 TreeTransform<Derived>::TransformObjCForCollectionStmt(
4077 ObjCForCollectionStmt *S) {
4078 // Transform the element statement.
4079 StmtResult Element = getDerived().TransformStmt(S->getElement());
4080 if (Element.isInvalid())
4083 // Transform the collection expression.
4084 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
4085 if (Collection.isInvalid())
4088 // Transform the body.
4089 StmtResult Body = getDerived().TransformStmt(S->getBody());
4090 if (Body.isInvalid())
4093 // If nothing changed, just retain this statement.
4094 if (!getDerived().AlwaysRebuild() &&
4095 Element.get() == S->getElement() &&
4096 Collection.get() == S->getCollection() &&
4097 Body.get() == S->getBody())
4098 return SemaRef.Owned(S->Retain());
4100 // Build a new statement.
4101 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4102 /*FIXME:*/S->getForLoc(),
4110 template<typename Derived>
4112 TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4113 // Transform the exception declaration, if any.
4115 if (S->getExceptionDecl()) {
4116 VarDecl *ExceptionDecl = S->getExceptionDecl();
4117 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4118 ExceptionDecl->getDeclName());
4120 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4124 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4126 ExceptionDecl->getTypeSourceInfo(),
4127 ExceptionDecl->getIdentifier(),
4128 ExceptionDecl->getLocation(),
4129 /*FIXME: Inaccurate*/
4130 SourceRange(ExceptionDecl->getLocation()));
4131 if (!Var || Var->isInvalidDecl())
4135 // Transform the actual exception handler.
4136 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4137 if (Handler.isInvalid())
4140 if (!getDerived().AlwaysRebuild() &&
4142 Handler.get() == S->getHandlerBlock())
4143 return SemaRef.Owned(S->Retain());
4145 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4150 template<typename Derived>
4152 TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4153 // Transform the try block itself.
4155 = getDerived().TransformCompoundStmt(S->getTryBlock());
4156 if (TryBlock.isInvalid())
4159 // Transform the handlers.
4160 bool HandlerChanged = false;
4161 ASTOwningVector<Stmt*> Handlers(SemaRef);
4162 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
4164 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4165 if (Handler.isInvalid())
4168 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4169 Handlers.push_back(Handler.takeAs<Stmt>());
4172 if (!getDerived().AlwaysRebuild() &&
4173 TryBlock.get() == S->getTryBlock() &&
4175 return SemaRef.Owned(S->Retain());
4177 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
4178 move_arg(Handlers));
4181 //===----------------------------------------------------------------------===//
4182 // Expression transformation
4183 //===----------------------------------------------------------------------===//
4184 template<typename Derived>
4186 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
4187 return SemaRef.Owned(E->Retain());
4190 template<typename Derived>
4192 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
4193 NestedNameSpecifier *Qualifier = 0;
4194 if (E->getQualifier()) {
4195 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4196 E->getQualifierRange());
4202 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4207 DeclarationNameInfo NameInfo = E->getNameInfo();
4208 if (NameInfo.getName()) {
4209 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4210 if (!NameInfo.getName())
4214 if (!getDerived().AlwaysRebuild() &&
4215 Qualifier == E->getQualifier() &&
4216 ND == E->getDecl() &&
4217 NameInfo.getName() == E->getDecl()->getDeclName() &&
4218 !E->hasExplicitTemplateArgs()) {
4220 // Mark it referenced in the new context regardless.
4221 // FIXME: this is a bit instantiation-specific.
4222 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4224 return SemaRef.Owned(E->Retain());
4227 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4228 if (E->hasExplicitTemplateArgs()) {
4229 TemplateArgs = &TransArgs;
4230 TransArgs.setLAngleLoc(E->getLAngleLoc());
4231 TransArgs.setRAngleLoc(E->getRAngleLoc());
4232 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4233 TemplateArgumentLoc Loc;
4234 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4236 TransArgs.addArgument(Loc);
4240 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
4241 ND, NameInfo, TemplateArgs);
4244 template<typename Derived>
4246 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
4247 return SemaRef.Owned(E->Retain());
4250 template<typename Derived>
4252 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
4253 return SemaRef.Owned(E->Retain());
4256 template<typename Derived>
4258 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
4259 return SemaRef.Owned(E->Retain());
4262 template<typename Derived>
4264 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
4265 return SemaRef.Owned(E->Retain());
4268 template<typename Derived>
4270 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
4271 return SemaRef.Owned(E->Retain());
4274 template<typename Derived>
4276 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
4277 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4278 if (SubExpr.isInvalid())
4281 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
4282 return SemaRef.Owned(E->Retain());
4284 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
4288 template<typename Derived>
4290 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4291 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4292 if (SubExpr.isInvalid())
4295 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
4296 return SemaRef.Owned(E->Retain());
4298 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4303 template<typename Derived>
4305 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4306 // Transform the type.
4307 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4311 // Transform all of the components into components similar to what the
4313 // FIXME: It would be slightly more efficient in the non-dependent case to
4314 // just map FieldDecls, rather than requiring the rebuilder to look for
4315 // the fields again. However, __builtin_offsetof is rare enough in
4316 // template code that we don't care.
4317 bool ExprChanged = false;
4318 typedef Sema::OffsetOfComponent Component;
4319 typedef OffsetOfExpr::OffsetOfNode Node;
4320 llvm::SmallVector<Component, 4> Components;
4321 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4322 const Node &ON = E->getComponent(I);
4324 Comp.isBrackets = true;
4325 Comp.LocStart = ON.getRange().getBegin();
4326 Comp.LocEnd = ON.getRange().getEnd();
4327 switch (ON.getKind()) {
4329 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4330 ExprResult Index = getDerived().TransformExpr(FromIndex);
4331 if (Index.isInvalid())
4334 ExprChanged = ExprChanged || Index.get() != FromIndex;
4335 Comp.isBrackets = true;
4336 Comp.U.E = Index.get();
4341 case Node::Identifier:
4342 Comp.isBrackets = false;
4343 Comp.U.IdentInfo = ON.getFieldName();
4344 if (!Comp.U.IdentInfo)
4350 // Will be recomputed during the rebuild.
4354 Components.push_back(Comp);
4357 // If nothing changed, retain the existing expression.
4358 if (!getDerived().AlwaysRebuild() &&
4359 Type == E->getTypeSourceInfo() &&
4361 return SemaRef.Owned(E->Retain());
4363 // Build a new offsetof expression.
4364 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4365 Components.data(), Components.size(),
4369 template<typename Derived>
4371 TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
4372 if (E->isArgumentType()) {
4373 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
4375 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4379 if (!getDerived().AlwaysRebuild() && OldT == NewT)
4380 return SemaRef.Owned(E->Retain());
4382 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
4384 E->getSourceRange());
4389 // C++0x [expr.sizeof]p1:
4390 // The operand is either an expression, which is an unevaluated operand
4392 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
4394 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4395 if (SubExpr.isInvalid())
4398 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4399 return SemaRef.Owned(E->Retain());
4402 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
4404 E->getSourceRange());
4407 template<typename Derived>
4409 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
4410 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4411 if (LHS.isInvalid())
4414 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4415 if (RHS.isInvalid())
4419 if (!getDerived().AlwaysRebuild() &&
4420 LHS.get() == E->getLHS() &&
4421 RHS.get() == E->getRHS())
4422 return SemaRef.Owned(E->Retain());
4424 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
4425 /*FIXME:*/E->getLHS()->getLocStart(),
4427 E->getRBracketLoc());
4430 template<typename Derived>
4432 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
4433 // Transform the callee.
4434 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
4435 if (Callee.isInvalid())
4438 // Transform arguments.
4439 bool ArgChanged = false;
4440 ASTOwningVector<Expr*> Args(SemaRef);
4441 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4442 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4443 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4444 if (Arg.isInvalid())
4447 // FIXME: Wrong source location information for the ','.
4448 FakeCommaLocs.push_back(
4449 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
4451 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
4452 Args.push_back(Arg.get());
4455 if (!getDerived().AlwaysRebuild() &&
4456 Callee.get() == E->getCallee() &&
4458 return SemaRef.Owned(E->Retain());
4460 // FIXME: Wrong source location information for the '('.
4461 SourceLocation FakeLParenLoc
4462 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4463 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
4465 FakeCommaLocs.data(),
4469 template<typename Derived>
4471 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
4472 ExprResult Base = getDerived().TransformExpr(E->getBase());
4473 if (Base.isInvalid())
4476 NestedNameSpecifier *Qualifier = 0;
4477 if (E->hasQualifier()) {
4479 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4480 E->getQualifierRange());
4486 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4487 E->getMemberDecl()));
4491 NamedDecl *FoundDecl = E->getFoundDecl();
4492 if (FoundDecl == E->getMemberDecl()) {
4495 FoundDecl = cast_or_null<NamedDecl>(
4496 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4501 if (!getDerived().AlwaysRebuild() &&
4502 Base.get() == E->getBase() &&
4503 Qualifier == E->getQualifier() &&
4504 Member == E->getMemberDecl() &&
4505 FoundDecl == E->getFoundDecl() &&
4506 !E->hasExplicitTemplateArgs()) {
4508 // Mark it referenced in the new context regardless.
4509 // FIXME: this is a bit instantiation-specific.
4510 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
4511 return SemaRef.Owned(E->Retain());
4514 TemplateArgumentListInfo TransArgs;
4515 if (E->hasExplicitTemplateArgs()) {
4516 TransArgs.setLAngleLoc(E->getLAngleLoc());
4517 TransArgs.setRAngleLoc(E->getRAngleLoc());
4518 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4519 TemplateArgumentLoc Loc;
4520 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4522 TransArgs.addArgument(Loc);
4526 // FIXME: Bogus source location for the operator
4527 SourceLocation FakeOperatorLoc
4528 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4530 // FIXME: to do this check properly, we will need to preserve the
4531 // first-qualifier-in-scope here, just in case we had a dependent
4532 // base (and therefore couldn't do the check) and a
4533 // nested-name-qualifier (and therefore could do the lookup).
4534 NamedDecl *FirstQualifierInScope = 0;
4536 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
4539 E->getQualifierRange(),
4540 E->getMemberNameInfo(),
4543 (E->hasExplicitTemplateArgs()
4545 FirstQualifierInScope);
4548 template<typename Derived>
4550 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
4551 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4552 if (LHS.isInvalid())
4555 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4556 if (RHS.isInvalid())
4559 if (!getDerived().AlwaysRebuild() &&
4560 LHS.get() == E->getLHS() &&
4561 RHS.get() == E->getRHS())
4562 return SemaRef.Owned(E->Retain());
4564 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4565 LHS.get(), RHS.get());
4568 template<typename Derived>
4570 TreeTransform<Derived>::TransformCompoundAssignOperator(
4571 CompoundAssignOperator *E) {
4572 return getDerived().TransformBinaryOperator(E);
4575 template<typename Derived>
4577 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
4578 ExprResult Cond = getDerived().TransformExpr(E->getCond());
4579 if (Cond.isInvalid())
4582 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4583 if (LHS.isInvalid())
4586 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4587 if (RHS.isInvalid())
4590 if (!getDerived().AlwaysRebuild() &&
4591 Cond.get() == E->getCond() &&
4592 LHS.get() == E->getLHS() &&
4593 RHS.get() == E->getRHS())
4594 return SemaRef.Owned(E->Retain());
4596 return getDerived().RebuildConditionalOperator(Cond.get(),
4597 E->getQuestionLoc(),
4603 template<typename Derived>
4605 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
4606 // Implicit casts are eliminated during transformation, since they
4607 // will be recomputed by semantic analysis after transformation.
4608 return getDerived().TransformExpr(E->getSubExprAsWritten());
4611 template<typename Derived>
4613 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
4614 TypeSourceInfo *OldT;
4615 TypeSourceInfo *NewT;
4617 // FIXME: Source location isn't quite accurate.
4618 SourceLocation TypeStartLoc
4619 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4620 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
4622 OldT = E->getTypeInfoAsWritten();
4623 NewT = getDerived().TransformType(OldT);
4629 = getDerived().TransformExpr(E->getSubExprAsWritten());
4630 if (SubExpr.isInvalid())
4633 if (!getDerived().AlwaysRebuild() &&
4635 SubExpr.get() == E->getSubExpr())
4636 return SemaRef.Owned(E->Retain());
4638 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4644 template<typename Derived>
4646 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
4647 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4648 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4652 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
4653 if (Init.isInvalid())
4656 if (!getDerived().AlwaysRebuild() &&
4658 Init.get() == E->getInitializer())
4659 return SemaRef.Owned(E->Retain());
4661 // Note: the expression type doesn't necessarily match the
4662 // type-as-written, but that's okay, because it should always be
4663 // derivable from the initializer.
4665 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
4666 /*FIXME:*/E->getInitializer()->getLocEnd(),
4670 template<typename Derived>
4672 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
4673 ExprResult Base = getDerived().TransformExpr(E->getBase());
4674 if (Base.isInvalid())
4677 if (!getDerived().AlwaysRebuild() &&
4678 Base.get() == E->getBase())
4679 return SemaRef.Owned(E->Retain());
4681 // FIXME: Bad source location
4682 SourceLocation FakeOperatorLoc
4683 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4684 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
4685 E->getAccessorLoc(),
4689 template<typename Derived>
4691 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
4692 bool InitChanged = false;
4694 ASTOwningVector<Expr*, 4> Inits(SemaRef);
4695 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4696 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
4697 if (Init.isInvalid())
4700 InitChanged = InitChanged || Init.get() != E->getInit(I);
4701 Inits.push_back(Init.get());
4704 if (!getDerived().AlwaysRebuild() && !InitChanged)
4705 return SemaRef.Owned(E->Retain());
4707 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
4708 E->getRBraceLoc(), E->getType());
4711 template<typename Derived>
4713 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
4716 // transform the initializer value
4717 ExprResult Init = getDerived().TransformExpr(E->getInit());
4718 if (Init.isInvalid())
4721 // transform the designators.
4722 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
4723 bool ExprChanged = false;
4724 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4725 DEnd = E->designators_end();
4727 if (D->isFieldDesignator()) {
4728 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4734 if (D->isArrayDesignator()) {
4735 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4736 if (Index.isInvalid())
4739 Desig.AddDesignator(Designator::getArray(Index.get(),
4740 D->getLBracketLoc()));
4742 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4743 ArrayExprs.push_back(Index.release());
4747 assert(D->isArrayRangeDesignator() && "New kind of designator?");
4749 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4750 if (Start.isInvalid())
4753 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4754 if (End.isInvalid())
4757 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
4759 D->getLBracketLoc(),
4760 D->getEllipsisLoc()));
4762 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4763 End.get() != E->getArrayRangeEnd(*D);
4765 ArrayExprs.push_back(Start.release());
4766 ArrayExprs.push_back(End.release());
4769 if (!getDerived().AlwaysRebuild() &&
4770 Init.get() == E->getInit() &&
4772 return SemaRef.Owned(E->Retain());
4774 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4775 E->getEqualOrColonLoc(),
4776 E->usesGNUSyntax(), Init.get());
4779 template<typename Derived>
4781 TreeTransform<Derived>::TransformImplicitValueInitExpr(
4782 ImplicitValueInitExpr *E) {
4783 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4785 // FIXME: Will we ever have proper type location here? Will we actually
4786 // need to transform the type?
4787 QualType T = getDerived().TransformType(E->getType());
4791 if (!getDerived().AlwaysRebuild() &&
4793 return SemaRef.Owned(E->Retain());
4795 return getDerived().RebuildImplicitValueInitExpr(T);
4798 template<typename Derived>
4800 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
4801 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
4805 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4806 if (SubExpr.isInvalid())
4809 if (!getDerived().AlwaysRebuild() &&
4810 TInfo == E->getWrittenTypeInfo() &&
4811 SubExpr.get() == E->getSubExpr())
4812 return SemaRef.Owned(E->Retain());
4814 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
4815 TInfo, E->getRParenLoc());
4818 template<typename Derived>
4820 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
4821 bool ArgumentChanged = false;
4822 ASTOwningVector<Expr*, 4> Inits(SemaRef);
4823 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4824 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4825 if (Init.isInvalid())
4828 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4829 Inits.push_back(Init.get());
4832 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4837 /// \brief Transform an address-of-label expression.
4839 /// By default, the transformation of an address-of-label expression always
4840 /// rebuilds the expression, so that the label identifier can be resolved to
4841 /// the corresponding label statement by semantic analysis.
4842 template<typename Derived>
4844 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
4845 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4849 template<typename Derived>
4851 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
4853 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4854 if (SubStmt.isInvalid())
4857 if (!getDerived().AlwaysRebuild() &&
4858 SubStmt.get() == E->getSubStmt())
4859 return SemaRef.Owned(E->Retain());
4861 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
4866 template<typename Derived>
4868 TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
4869 TypeSourceInfo *TInfo1;
4870 TypeSourceInfo *TInfo2;
4872 TInfo1 = getDerived().TransformType(E->getArgTInfo1());
4876 TInfo2 = getDerived().TransformType(E->getArgTInfo2());
4880 if (!getDerived().AlwaysRebuild() &&
4881 TInfo1 == E->getArgTInfo1() &&
4882 TInfo2 == E->getArgTInfo2())
4883 return SemaRef.Owned(E->Retain());
4885 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4890 template<typename Derived>
4892 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
4893 ExprResult Cond = getDerived().TransformExpr(E->getCond());
4894 if (Cond.isInvalid())
4897 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4898 if (LHS.isInvalid())
4901 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4902 if (RHS.isInvalid())
4905 if (!getDerived().AlwaysRebuild() &&
4906 Cond.get() == E->getCond() &&
4907 LHS.get() == E->getLHS() &&
4908 RHS.get() == E->getRHS())
4909 return SemaRef.Owned(E->Retain());
4911 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4912 Cond.get(), LHS.get(), RHS.get(),
4916 template<typename Derived>
4918 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
4919 return SemaRef.Owned(E->Retain());
4922 template<typename Derived>
4924 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
4925 switch (E->getOperator()) {
4929 case OO_Array_Delete:
4930 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4934 // This is a call to an object's operator().
4935 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4937 // Transform the object itself.
4938 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
4939 if (Object.isInvalid())
4942 // FIXME: Poor location information
4943 SourceLocation FakeLParenLoc
4944 = SemaRef.PP.getLocForEndOfToken(
4945 static_cast<Expr *>(Object.get())->getLocEnd());
4947 // Transform the call arguments.
4948 ASTOwningVector<Expr*> Args(SemaRef);
4949 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4950 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
4951 if (getDerived().DropCallArgument(E->getArg(I)))
4954 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4955 if (Arg.isInvalid())
4958 // FIXME: Poor source location information.
4959 SourceLocation FakeCommaLoc
4960 = SemaRef.PP.getLocForEndOfToken(
4961 static_cast<Expr *>(Arg.get())->getLocEnd());
4962 FakeCommaLocs.push_back(FakeCommaLoc);
4963 Args.push_back(Arg.release());
4966 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
4968 FakeCommaLocs.data(),
4972 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4974 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4975 #include "clang/Basic/OperatorKinds.def"
4980 case OO_Conditional:
4981 llvm_unreachable("conditional operator is not actually overloadable");
4985 case NUM_OVERLOADED_OPERATORS:
4986 llvm_unreachable("not an overloaded operator?");
4990 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
4991 if (Callee.isInvalid())
4994 ExprResult First = getDerived().TransformExpr(E->getArg(0));
4995 if (First.isInvalid())
4999 if (E->getNumArgs() == 2) {
5000 Second = getDerived().TransformExpr(E->getArg(1));
5001 if (Second.isInvalid())
5005 if (!getDerived().AlwaysRebuild() &&
5006 Callee.get() == E->getCallee() &&
5007 First.get() == E->getArg(0) &&
5008 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5009 return SemaRef.Owned(E->Retain());
5011 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5012 E->getOperatorLoc(),
5018 template<typename Derived>
5020 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5021 return getDerived().TransformCallExpr(E);
5024 template<typename Derived>
5026 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
5027 TypeSourceInfo *OldT;
5028 TypeSourceInfo *NewT;
5030 // FIXME: Source location isn't quite accurate.
5031 SourceLocation TypeStartLoc
5032 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5033 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
5035 OldT = E->getTypeInfoAsWritten();
5036 NewT = getDerived().TransformType(OldT);
5042 = getDerived().TransformExpr(E->getSubExprAsWritten());
5043 if (SubExpr.isInvalid())
5046 if (!getDerived().AlwaysRebuild() &&
5048 SubExpr.get() == E->getSubExpr())
5049 return SemaRef.Owned(E->Retain());
5051 // FIXME: Poor source location information here.
5052 SourceLocation FakeLAngleLoc
5053 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5054 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5055 SourceLocation FakeRParenLoc
5056 = SemaRef.PP.getLocForEndOfToken(
5057 E->getSubExpr()->getSourceRange().getEnd());
5058 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
5068 template<typename Derived>
5070 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5071 return getDerived().TransformCXXNamedCastExpr(E);
5074 template<typename Derived>
5076 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5077 return getDerived().TransformCXXNamedCastExpr(E);
5080 template<typename Derived>
5082 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
5083 CXXReinterpretCastExpr *E) {
5084 return getDerived().TransformCXXNamedCastExpr(E);
5087 template<typename Derived>
5089 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5090 return getDerived().TransformCXXNamedCastExpr(E);
5093 template<typename Derived>
5095 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
5096 CXXFunctionalCastExpr *E) {
5097 TypeSourceInfo *OldT;
5098 TypeSourceInfo *NewT;
5100 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5102 OldT = E->getTypeInfoAsWritten();
5103 NewT = getDerived().TransformType(OldT);
5109 = getDerived().TransformExpr(E->getSubExprAsWritten());
5110 if (SubExpr.isInvalid())
5113 if (!getDerived().AlwaysRebuild() &&
5115 SubExpr.get() == E->getSubExpr())
5116 return SemaRef.Owned(E->Retain());
5118 // FIXME: The end of the type's source range is wrong
5119 return getDerived().RebuildCXXFunctionalCastExpr(
5120 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
5122 /*FIXME:*/E->getSubExpr()->getLocStart(),
5127 template<typename Derived>
5129 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
5130 if (E->isTypeOperand()) {
5131 TypeSourceInfo *TInfo
5132 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5136 if (!getDerived().AlwaysRebuild() &&
5137 TInfo == E->getTypeOperandSourceInfo())
5138 return SemaRef.Owned(E->Retain());
5140 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5146 // We don't know whether the expression is potentially evaluated until
5147 // after we perform semantic analysis, so the expression is potentially
5148 // potentially evaluated.
5149 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5150 Sema::PotentiallyPotentiallyEvaluated);
5152 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5153 if (SubExpr.isInvalid())
5156 if (!getDerived().AlwaysRebuild() &&
5157 SubExpr.get() == E->getExprOperand())
5158 return SemaRef.Owned(E->Retain());
5160 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5166 template<typename Derived>
5168 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
5169 return SemaRef.Owned(E->Retain());
5172 template<typename Derived>
5174 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
5175 CXXNullPtrLiteralExpr *E) {
5176 return SemaRef.Owned(E->Retain());
5179 template<typename Derived>
5181 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
5182 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5184 QualType T = getDerived().TransformType(E->getType());
5188 if (!getDerived().AlwaysRebuild() &&
5190 return SemaRef.Owned(E->Retain());
5192 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
5195 template<typename Derived>
5197 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
5198 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5199 if (SubExpr.isInvalid())
5202 if (!getDerived().AlwaysRebuild() &&
5203 SubExpr.get() == E->getSubExpr())
5204 return SemaRef.Owned(E->Retain());
5206 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
5209 template<typename Derived>
5211 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
5213 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5218 if (!getDerived().AlwaysRebuild() &&
5219 Param == E->getParam())
5220 return SemaRef.Owned(E->Retain());
5222 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
5225 template<typename Derived>
5227 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
5228 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5230 QualType T = getDerived().TransformType(E->getType());
5234 if (!getDerived().AlwaysRebuild() &&
5236 return SemaRef.Owned(E->Retain());
5238 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5239 /*FIXME:*/E->getTypeBeginLoc(),
5244 template<typename Derived>
5246 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
5247 // Transform the type that we're allocating
5248 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5249 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5250 if (AllocType.isNull())
5253 // Transform the size of the array we're allocating (if any).
5254 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5255 if (ArraySize.isInvalid())
5258 // Transform the placement arguments (if any).
5259 bool ArgumentChanged = false;
5260 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
5261 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5262 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5263 if (Arg.isInvalid())
5266 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5267 PlacementArgs.push_back(Arg.take());
5270 // transform the constructor arguments (if any).
5271 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
5272 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5273 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5276 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5277 if (Arg.isInvalid())
5280 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5281 ConstructorArgs.push_back(Arg.take());
5284 // Transform constructor, new operator, and delete operator.
5285 CXXConstructorDecl *Constructor = 0;
5286 if (E->getConstructor()) {
5287 Constructor = cast_or_null<CXXConstructorDecl>(
5288 getDerived().TransformDecl(E->getLocStart(),
5289 E->getConstructor()));
5294 FunctionDecl *OperatorNew = 0;
5295 if (E->getOperatorNew()) {
5296 OperatorNew = cast_or_null<FunctionDecl>(
5297 getDerived().TransformDecl(E->getLocStart(),
5298 E->getOperatorNew()));
5303 FunctionDecl *OperatorDelete = 0;
5304 if (E->getOperatorDelete()) {
5305 OperatorDelete = cast_or_null<FunctionDecl>(
5306 getDerived().TransformDecl(E->getLocStart(),
5307 E->getOperatorDelete()));
5308 if (!OperatorDelete)
5312 if (!getDerived().AlwaysRebuild() &&
5313 AllocType == E->getAllocatedType() &&
5314 ArraySize.get() == E->getArraySize() &&
5315 Constructor == E->getConstructor() &&
5316 OperatorNew == E->getOperatorNew() &&
5317 OperatorDelete == E->getOperatorDelete() &&
5319 // Mark any declarations we need as referenced.
5320 // FIXME: instantiation-specific.
5322 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5324 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5326 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
5327 return SemaRef.Owned(E->Retain());
5330 if (!ArraySize.get()) {
5331 // If no array size was specified, but the new expression was
5332 // instantiated with an array type (e.g., "new T" where T is
5333 // instantiated with "int[4]"), extract the outer bound from the
5334 // array type as our array size. We do this with constant and
5335 // dependently-sized array types.
5336 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5339 } else if (const ConstantArrayType *ConsArrayT
5340 = dyn_cast<ConstantArrayType>(ArrayT)) {
5342 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5343 ConsArrayT->getSize(),
5344 SemaRef.Context.getSizeType(),
5345 /*FIXME:*/E->getLocStart()));
5346 AllocType = ConsArrayT->getElementType();
5347 } else if (const DependentSizedArrayType *DepArrayT
5348 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5349 if (DepArrayT->getSizeExpr()) {
5350 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5351 AllocType = DepArrayT->getElementType();
5355 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5357 /*FIXME:*/E->getLocStart(),
5358 move_arg(PlacementArgs),
5359 /*FIXME:*/E->getLocStart(),
5360 E->getTypeIdParens(),
5362 /*FIXME:*/E->getLocStart(),
5363 /*FIXME:*/SourceRange(),
5365 /*FIXME:*/E->getLocStart(),
5366 move_arg(ConstructorArgs),
5370 template<typename Derived>
5372 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
5373 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
5374 if (Operand.isInvalid())
5377 // Transform the delete operator, if known.
5378 FunctionDecl *OperatorDelete = 0;
5379 if (E->getOperatorDelete()) {
5380 OperatorDelete = cast_or_null<FunctionDecl>(
5381 getDerived().TransformDecl(E->getLocStart(),
5382 E->getOperatorDelete()));
5383 if (!OperatorDelete)
5387 if (!getDerived().AlwaysRebuild() &&
5388 Operand.get() == E->getArgument() &&
5389 OperatorDelete == E->getOperatorDelete()) {
5390 // Mark any declarations we need as referenced.
5391 // FIXME: instantiation-specific.
5393 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
5394 return SemaRef.Owned(E->Retain());
5397 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5398 E->isGlobalDelete(),
5403 template<typename Derived>
5405 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
5406 CXXPseudoDestructorExpr *E) {
5407 ExprResult Base = getDerived().TransformExpr(E->getBase());
5408 if (Base.isInvalid())
5411 ParsedType ObjectTypePtr;
5412 bool MayBePseudoDestructor = false;
5413 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
5414 E->getOperatorLoc(),
5415 E->isArrow()? tok::arrow : tok::period,
5417 MayBePseudoDestructor);
5418 if (Base.isInvalid())
5421 QualType ObjectType = ObjectTypePtr.get();
5422 NestedNameSpecifier *Qualifier
5423 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5424 E->getQualifierRange(),
5426 if (E->getQualifier() && !Qualifier)
5429 PseudoDestructorTypeStorage Destroyed;
5430 if (E->getDestroyedTypeInfo()) {
5431 TypeSourceInfo *DestroyedTypeInfo
5432 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5433 if (!DestroyedTypeInfo)
5435 Destroyed = DestroyedTypeInfo;
5436 } else if (ObjectType->isDependentType()) {
5437 // We aren't likely to be able to resolve the identifier down to a type
5438 // now anyway, so just retain the identifier.
5439 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5440 E->getDestroyedTypeLoc());
5442 // Look for a destructor known with the given name.
5445 SS.setScopeRep(Qualifier);
5446 SS.setRange(E->getQualifierRange());
5449 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
5450 *E->getDestroyedTypeIdentifier(),
5451 E->getDestroyedTypeLoc(),
5459 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5460 E->getDestroyedTypeLoc());
5463 TypeSourceInfo *ScopeTypeInfo = 0;
5464 if (E->getScopeTypeInfo()) {
5465 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5471 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
5472 E->getOperatorLoc(),
5475 E->getQualifierRange(),
5477 E->getColonColonLoc(),
5482 template<typename Derived>
5484 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
5485 UnresolvedLookupExpr *Old) {
5486 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5488 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5489 Sema::LookupOrdinaryName);
5491 // Transform all the decls.
5492 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5493 E = Old->decls_end(); I != E; ++I) {
5494 NamedDecl *InstD = static_cast<NamedDecl*>(
5495 getDerived().TransformDecl(Old->getNameLoc(),
5498 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5499 // This can happen because of dependent hiding.
5500 if (isa<UsingShadowDecl>(*I))
5506 // Expand using declarations.
5507 if (isa<UsingDecl>(InstD)) {
5508 UsingDecl *UD = cast<UsingDecl>(InstD);
5509 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5510 E = UD->shadow_end(); I != E; ++I)
5518 // Resolve a kind, but don't do any further analysis. If it's
5519 // ambiguous, the callee needs to deal with it.
5522 // Rebuild the nested-name qualifier, if present.
5524 NestedNameSpecifier *Qualifier = 0;
5525 if (Old->getQualifier()) {
5526 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5527 Old->getQualifierRange());
5531 SS.setScopeRep(Qualifier);
5532 SS.setRange(Old->getQualifierRange());
5535 if (Old->getNamingClass()) {
5536 CXXRecordDecl *NamingClass
5537 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5539 Old->getNamingClass()));
5543 R.setNamingClass(NamingClass);
5546 // If we have no template arguments, it's a normal declaration name.
5547 if (!Old->hasExplicitTemplateArgs())
5548 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5550 // If we have template arguments, rebuild them, then rebuild the
5551 // templateid expression.
5552 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5553 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5554 TemplateArgumentLoc Loc;
5555 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5557 TransArgs.addArgument(Loc);
5560 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5564 template<typename Derived>
5566 TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
5567 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5569 QualType T = getDerived().TransformType(E->getQueriedType());
5573 if (!getDerived().AlwaysRebuild() &&
5574 T == E->getQueriedType())
5575 return SemaRef.Owned(E->Retain());
5577 // FIXME: Bad location information
5578 SourceLocation FakeLParenLoc
5579 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
5581 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
5583 /*FIXME:*/FakeLParenLoc,
5588 template<typename Derived>
5590 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
5591 DependentScopeDeclRefExpr *E) {
5592 NestedNameSpecifier *NNS
5593 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5594 E->getQualifierRange());
5598 DeclarationNameInfo NameInfo
5599 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
5600 if (!NameInfo.getName())
5603 if (!E->hasExplicitTemplateArgs()) {
5604 if (!getDerived().AlwaysRebuild() &&
5605 NNS == E->getQualifier() &&
5606 // Note: it is sufficient to compare the Name component of NameInfo:
5607 // if name has not changed, DNLoc has not changed either.
5608 NameInfo.getName() == E->getDeclName())
5609 return SemaRef.Owned(E->Retain());
5611 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5612 E->getQualifierRange(),
5614 /*TemplateArgs*/ 0);
5617 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
5618 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
5619 TemplateArgumentLoc Loc;
5620 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
5622 TransArgs.addArgument(Loc);
5625 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5626 E->getQualifierRange(),
5631 template<typename Derived>
5633 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
5634 // CXXConstructExprs are always implicit, so when we have a
5635 // 1-argument construction we just transform that argument.
5636 if (E->getNumArgs() == 1 ||
5637 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5638 return getDerived().TransformExpr(E->getArg(0));
5640 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5642 QualType T = getDerived().TransformType(E->getType());
5646 CXXConstructorDecl *Constructor
5647 = cast_or_null<CXXConstructorDecl>(
5648 getDerived().TransformDecl(E->getLocStart(),
5649 E->getConstructor()));
5653 bool ArgumentChanged = false;
5654 ASTOwningVector<Expr*> Args(SemaRef);
5655 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
5656 ArgEnd = E->arg_end();
5657 Arg != ArgEnd; ++Arg) {
5658 if (getDerived().DropCallArgument(*Arg)) {
5659 ArgumentChanged = true;
5663 ExprResult TransArg = getDerived().TransformExpr(*Arg);
5664 if (TransArg.isInvalid())
5667 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5668 Args.push_back(TransArg.get());
5671 if (!getDerived().AlwaysRebuild() &&
5672 T == E->getType() &&
5673 Constructor == E->getConstructor() &&
5675 // Mark the constructor as referenced.
5676 // FIXME: Instantiation-specific
5677 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5678 return SemaRef.Owned(E->Retain());
5681 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5682 Constructor, E->isElidable(),
5684 E->requiresZeroInitialization(),
5685 E->getConstructionKind());
5688 /// \brief Transform a C++ temporary-binding expression.
5690 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5691 /// transform the subexpression and return that.
5692 template<typename Derived>
5694 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
5695 return getDerived().TransformExpr(E->getSubExpr());
5698 /// \brief Transform a C++ expression that contains temporaries that should
5699 /// be destroyed after the expression is evaluated.
5701 /// Since CXXExprWithTemporaries nodes are implicitly generated, we
5702 /// just transform the subexpression and return that.
5703 template<typename Derived>
5705 TreeTransform<Derived>::TransformCXXExprWithTemporaries(
5706 CXXExprWithTemporaries *E) {
5707 return getDerived().TransformExpr(E->getSubExpr());
5710 template<typename Derived>
5712 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
5713 CXXTemporaryObjectExpr *E) {
5714 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5715 QualType T = getDerived().TransformType(E->getType());
5719 CXXConstructorDecl *Constructor
5720 = cast_or_null<CXXConstructorDecl>(
5721 getDerived().TransformDecl(E->getLocStart(),
5722 E->getConstructor()));
5726 bool ArgumentChanged = false;
5727 ASTOwningVector<Expr*> Args(SemaRef);
5728 Args.reserve(E->getNumArgs());
5729 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
5730 ArgEnd = E->arg_end();
5731 Arg != ArgEnd; ++Arg) {
5732 if (getDerived().DropCallArgument(*Arg)) {
5733 ArgumentChanged = true;
5737 ExprResult TransArg = getDerived().TransformExpr(*Arg);
5738 if (TransArg.isInvalid())
5741 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5742 Args.push_back((Expr *)TransArg.release());
5745 if (!getDerived().AlwaysRebuild() &&
5746 T == E->getType() &&
5747 Constructor == E->getConstructor() &&
5749 // FIXME: Instantiation-specific
5750 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
5751 return SemaRef.MaybeBindToTemporary(E->Retain());
5754 // FIXME: Bogus location information
5755 SourceLocation CommaLoc;
5756 if (Args.size() > 1) {
5757 Expr *First = (Expr *)Args[0];
5759 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5761 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5763 /*FIXME:*/E->getTypeBeginLoc(),
5769 template<typename Derived>
5771 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
5772 CXXUnresolvedConstructExpr *E) {
5773 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5774 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5778 bool ArgumentChanged = false;
5779 ASTOwningVector<Expr*> Args(SemaRef);
5780 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5781 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5782 ArgEnd = E->arg_end();
5783 Arg != ArgEnd; ++Arg) {
5784 ExprResult TransArg = getDerived().TransformExpr(*Arg);
5785 if (TransArg.isInvalid())
5788 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5789 FakeCommaLocs.push_back(
5790 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5791 Args.push_back(TransArg.get());
5794 if (!getDerived().AlwaysRebuild() &&
5795 T == E->getTypeAsWritten() &&
5797 return SemaRef.Owned(E->Retain());
5799 // FIXME: we're faking the locations of the commas
5800 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5804 FakeCommaLocs.data(),
5808 template<typename Derived>
5810 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
5811 CXXDependentScopeMemberExpr *E) {
5812 // Transform the base of the expression.
5813 ExprResult Base((Expr*) 0);
5816 QualType ObjectType;
5817 if (!E->isImplicitAccess()) {
5818 OldBase = E->getBase();
5819 Base = getDerived().TransformExpr(OldBase);
5820 if (Base.isInvalid())
5823 // Start the member reference and compute the object's type.
5824 ParsedType ObjectTy;
5825 bool MayBePseudoDestructor = false;
5826 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
5827 E->getOperatorLoc(),
5828 E->isArrow()? tok::arrow : tok::period,
5830 MayBePseudoDestructor);
5831 if (Base.isInvalid())
5834 ObjectType = ObjectTy.get();
5835 BaseType = ((Expr*) Base.get())->getType();
5838 BaseType = getDerived().TransformType(E->getBaseType());
5839 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5842 // Transform the first part of the nested-name-specifier that qualifies
5844 NamedDecl *FirstQualifierInScope
5845 = getDerived().TransformFirstQualifierInScope(
5846 E->getFirstQualifierFoundInScope(),
5847 E->getQualifierRange().getBegin());
5849 NestedNameSpecifier *Qualifier = 0;
5850 if (E->getQualifier()) {
5851 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5852 E->getQualifierRange(),
5854 FirstQualifierInScope);
5859 DeclarationNameInfo NameInfo
5860 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(),
5862 if (!NameInfo.getName())
5865 if (!E->hasExplicitTemplateArgs()) {
5866 // This is a reference to a member without an explicitly-specified
5867 // template argument list. Optimize for this common case.
5868 if (!getDerived().AlwaysRebuild() &&
5869 Base.get() == OldBase &&
5870 BaseType == E->getBaseType() &&
5871 Qualifier == E->getQualifier() &&
5872 NameInfo.getName() == E->getMember() &&
5873 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
5874 return SemaRef.Owned(E->Retain());
5876 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
5879 E->getOperatorLoc(),
5881 E->getQualifierRange(),
5882 FirstQualifierInScope,
5884 /*TemplateArgs*/ 0);
5887 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
5888 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
5889 TemplateArgumentLoc Loc;
5890 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
5892 TransArgs.addArgument(Loc);
5895 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
5898 E->getOperatorLoc(),
5900 E->getQualifierRange(),
5901 FirstQualifierInScope,
5906 template<typename Derived>
5908 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
5909 // Transform the base of the expression.
5910 ExprResult Base((Expr*) 0);
5912 if (!Old->isImplicitAccess()) {
5913 Base = getDerived().TransformExpr(Old->getBase());
5914 if (Base.isInvalid())
5916 BaseType = ((Expr*) Base.get())->getType();
5918 BaseType = getDerived().TransformType(Old->getBaseType());
5921 NestedNameSpecifier *Qualifier = 0;
5922 if (Old->getQualifier()) {
5924 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5925 Old->getQualifierRange());
5930 LookupResult R(SemaRef, Old->getMemberNameInfo(),
5931 Sema::LookupOrdinaryName);
5933 // Transform all the decls.
5934 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5935 E = Old->decls_end(); I != E; ++I) {
5936 NamedDecl *InstD = static_cast<NamedDecl*>(
5937 getDerived().TransformDecl(Old->getMemberLoc(),
5940 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5941 // This can happen because of dependent hiding.
5942 if (isa<UsingShadowDecl>(*I))
5948 // Expand using declarations.
5949 if (isa<UsingDecl>(InstD)) {
5950 UsingDecl *UD = cast<UsingDecl>(InstD);
5951 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5952 E = UD->shadow_end(); I != E; ++I)
5962 // Determine the naming class.
5963 if (Old->getNamingClass()) {
5964 CXXRecordDecl *NamingClass
5965 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5966 Old->getMemberLoc(),
5967 Old->getNamingClass()));
5971 R.setNamingClass(NamingClass);
5974 TemplateArgumentListInfo TransArgs;
5975 if (Old->hasExplicitTemplateArgs()) {
5976 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5977 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5978 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5979 TemplateArgumentLoc Loc;
5980 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5983 TransArgs.addArgument(Loc);
5987 // FIXME: to do this check properly, we will need to preserve the
5988 // first-qualifier-in-scope here, just in case we had a dependent
5989 // base (and therefore couldn't do the check) and a
5990 // nested-name-qualifier (and therefore could do the lookup).
5991 NamedDecl *FirstQualifierInScope = 0;
5993 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
5995 Old->getOperatorLoc(),
5998 Old->getQualifierRange(),
5999 FirstQualifierInScope,
6001 (Old->hasExplicitTemplateArgs()
6005 template<typename Derived>
6007 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
6008 return SemaRef.Owned(E->Retain());
6011 template<typename Derived>
6013 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
6014 TypeSourceInfo *EncodedTypeInfo
6015 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6016 if (!EncodedTypeInfo)
6019 if (!getDerived().AlwaysRebuild() &&
6020 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
6021 return SemaRef.Owned(E->Retain());
6023 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
6028 template<typename Derived>
6030 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
6031 // Transform arguments.
6032 bool ArgChanged = false;
6033 ASTOwningVector<Expr*> Args(SemaRef);
6034 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6035 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6036 if (Arg.isInvalid())
6039 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6040 Args.push_back(Arg.get());
6043 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6044 // Class message: transform the receiver type.
6045 TypeSourceInfo *ReceiverTypeInfo
6046 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6047 if (!ReceiverTypeInfo)
6050 // If nothing changed, just retain the existing message send.
6051 if (!getDerived().AlwaysRebuild() &&
6052 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6053 return SemaRef.Owned(E->Retain());
6055 // Build a new class message send.
6056 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6064 // Instance message: transform the receiver
6065 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6066 "Only class and instance messages may be instantiated");
6068 = getDerived().TransformExpr(E->getInstanceReceiver());
6069 if (Receiver.isInvalid())
6072 // If nothing changed, just retain the existing message send.
6073 if (!getDerived().AlwaysRebuild() &&
6074 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6075 return SemaRef.Owned(E->Retain());
6077 // Build a new instance message send.
6078 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
6086 template<typename Derived>
6088 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
6089 return SemaRef.Owned(E->Retain());
6092 template<typename Derived>
6094 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
6095 return SemaRef.Owned(E->Retain());
6098 template<typename Derived>
6100 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
6101 // Transform the base expression.
6102 ExprResult Base = getDerived().TransformExpr(E->getBase());
6103 if (Base.isInvalid())
6106 // We don't need to transform the ivar; it will never change.
6108 // If nothing changed, just retain the existing expression.
6109 if (!getDerived().AlwaysRebuild() &&
6110 Base.get() == E->getBase())
6111 return SemaRef.Owned(E->Retain());
6113 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
6115 E->isArrow(), E->isFreeIvar());
6118 template<typename Derived>
6120 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
6121 // Transform the base expression.
6122 ExprResult Base = getDerived().TransformExpr(E->getBase());
6123 if (Base.isInvalid())
6126 // We don't need to transform the property; it will never change.
6128 // If nothing changed, just retain the existing expression.
6129 if (!getDerived().AlwaysRebuild() &&
6130 Base.get() == E->getBase())
6131 return SemaRef.Owned(E->Retain());
6133 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(),
6137 template<typename Derived>
6139 TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
6140 ObjCImplicitSetterGetterRefExpr *E) {
6141 // If this implicit setter/getter refers to class methods, it cannot have any
6142 // dependent parts. Just retain the existing declaration.
6143 if (E->getInterfaceDecl())
6144 return SemaRef.Owned(E->Retain());
6146 // Transform the base expression.
6147 ExprResult Base = getDerived().TransformExpr(E->getBase());
6148 if (Base.isInvalid())
6151 // We don't need to transform the getters/setters; they will never change.
6153 // If nothing changed, just retain the existing expression.
6154 if (!getDerived().AlwaysRebuild() &&
6155 Base.get() == E->getBase())
6156 return SemaRef.Owned(E->Retain());
6158 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6159 E->getGetterMethod(),
6161 E->getSetterMethod(),
6167 template<typename Derived>
6169 TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
6170 // Can never occur in a dependent context.
6171 return SemaRef.Owned(E->Retain());
6174 template<typename Derived>
6176 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
6177 // Transform the base expression.
6178 ExprResult Base = getDerived().TransformExpr(E->getBase());
6179 if (Base.isInvalid())
6182 // If nothing changed, just retain the existing expression.
6183 if (!getDerived().AlwaysRebuild() &&
6184 Base.get() == E->getBase())
6185 return SemaRef.Owned(E->Retain());
6187 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
6191 template<typename Derived>
6193 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
6194 bool ArgumentChanged = false;
6195 ASTOwningVector<Expr*> SubExprs(SemaRef);
6196 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6197 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6198 if (SubExpr.isInvalid())
6201 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6202 SubExprs.push_back(SubExpr.get());
6205 if (!getDerived().AlwaysRebuild() &&
6207 return SemaRef.Owned(E->Retain());
6209 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6214 template<typename Derived>
6216 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
6217 SourceLocation CaretLoc(E->getExprLoc());
6219 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6220 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6221 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6222 llvm::SmallVector<ParmVarDecl*, 4> Params;
6223 llvm::SmallVector<QualType, 4> ParamTypes;
6225 // Parameter substitution.
6226 const BlockDecl *BD = E->getBlockDecl();
6227 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6228 EN = BD->param_end(); P != EN; ++P) {
6229 ParmVarDecl *OldParm = (*P);
6230 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6231 QualType NewType = NewParm->getType();
6232 Params.push_back(NewParm);
6233 ParamTypes.push_back(NewParm->getType());
6236 const FunctionType *BExprFunctionType = E->getFunctionType();
6237 QualType BExprResultType = BExprFunctionType->getResultType();
6238 if (!BExprResultType.isNull()) {
6239 if (!BExprResultType->isDependentType())
6240 CurBlock->ReturnType = BExprResultType;
6241 else if (BExprResultType != SemaRef.Context.DependentTy)
6242 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6245 // Transform the body
6246 StmtResult Body = getDerived().TransformStmt(E->getBody());
6247 if (Body.isInvalid())
6249 // Set the parameters on the block decl.
6250 if (!Params.empty())
6251 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6253 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6254 CurBlock->ReturnType,
6259 BExprFunctionType->getExtInfo());
6261 CurBlock->FunctionType = FunctionType;
6262 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
6265 template<typename Derived>
6267 TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
6268 NestedNameSpecifier *Qualifier = 0;
6271 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6276 if (!getDerived().AlwaysRebuild() &&
6277 ND == E->getDecl()) {
6278 // Mark it referenced in the new context regardless.
6279 // FIXME: this is a bit instantiation-specific.
6280 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6282 return SemaRef.Owned(E->Retain());
6285 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
6286 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
6290 //===----------------------------------------------------------------------===//
6291 // Type reconstruction
6292 //===----------------------------------------------------------------------===//
6294 template<typename Derived>
6295 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6296 SourceLocation Star) {
6297 return SemaRef.BuildPointerType(PointeeType, Star,
6298 getDerived().getBaseEntity());
6301 template<typename Derived>
6302 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6303 SourceLocation Star) {
6304 return SemaRef.BuildBlockPointerType(PointeeType, Star,
6305 getDerived().getBaseEntity());
6308 template<typename Derived>
6310 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6311 bool WrittenAsLValue,
6312 SourceLocation Sigil) {
6313 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
6314 Sigil, getDerived().getBaseEntity());
6317 template<typename Derived>
6319 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6321 SourceLocation Sigil) {
6322 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
6323 Sigil, getDerived().getBaseEntity());
6326 template<typename Derived>
6328 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6329 ArrayType::ArraySizeModifier SizeMod,
6330 const llvm::APInt *Size,
6332 unsigned IndexTypeQuals,
6333 SourceRange BracketsRange) {
6334 if (SizeExpr || !Size)
6335 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6336 IndexTypeQuals, BracketsRange,
6337 getDerived().getBaseEntity());
6339 QualType Types[] = {
6340 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6341 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6342 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
6344 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6346 for (unsigned I = 0; I != NumTypes; ++I)
6347 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6348 SizeType = Types[I];
6352 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6353 /*FIXME*/BracketsRange.getBegin());
6354 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
6355 IndexTypeQuals, BracketsRange,
6356 getDerived().getBaseEntity());
6359 template<typename Derived>
6361 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
6362 ArrayType::ArraySizeModifier SizeMod,
6363 const llvm::APInt &Size,
6364 unsigned IndexTypeQuals,
6365 SourceRange BracketsRange) {
6366 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
6367 IndexTypeQuals, BracketsRange);
6370 template<typename Derived>
6372 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
6373 ArrayType::ArraySizeModifier SizeMod,
6374 unsigned IndexTypeQuals,
6375 SourceRange BracketsRange) {
6376 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
6377 IndexTypeQuals, BracketsRange);
6380 template<typename Derived>
6382 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
6383 ArrayType::ArraySizeModifier SizeMod,
6385 unsigned IndexTypeQuals,
6386 SourceRange BracketsRange) {
6387 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
6389 IndexTypeQuals, BracketsRange);
6392 template<typename Derived>
6394 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
6395 ArrayType::ArraySizeModifier SizeMod,
6397 unsigned IndexTypeQuals,
6398 SourceRange BracketsRange) {
6399 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
6401 IndexTypeQuals, BracketsRange);
6404 template<typename Derived>
6405 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
6406 unsigned NumElements,
6407 VectorType::AltiVecSpecific AltiVecSpec) {
6408 // FIXME: semantic checking!
6409 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
6412 template<typename Derived>
6413 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6414 unsigned NumElements,
6415 SourceLocation AttributeLoc) {
6416 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6418 IntegerLiteral *VectorSize
6419 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6421 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
6424 template<typename Derived>
6426 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
6428 SourceLocation AttributeLoc) {
6429 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
6432 template<typename Derived>
6433 QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
6434 QualType *ParamTypes,
6435 unsigned NumParamTypes,
6438 const FunctionType::ExtInfo &Info) {
6439 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
6441 getDerived().getBaseLocation(),
6442 getDerived().getBaseEntity(),
6446 template<typename Derived>
6447 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6448 return SemaRef.Context.getFunctionNoProtoType(T);
6451 template<typename Derived>
6452 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6453 assert(D && "no decl found");
6454 if (D->isInvalidDecl()) return QualType();
6456 // FIXME: Doesn't account for ObjCInterfaceDecl!
6458 if (isa<UsingDecl>(D)) {
6459 UsingDecl *Using = cast<UsingDecl>(D);
6460 assert(Using->isTypeName() &&
6461 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6463 // A valid resolved using typename decl points to exactly one type decl.
6464 assert(++Using->shadow_begin() == Using->shadow_end());
6465 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6468 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6469 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6470 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6473 return SemaRef.Context.getTypeDeclType(Ty);
6476 template<typename Derived>
6477 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E) {
6478 return SemaRef.BuildTypeofExprType(E);
6481 template<typename Derived>
6482 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6483 return SemaRef.Context.getTypeOfType(Underlying);
6486 template<typename Derived>
6487 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E) {
6488 return SemaRef.BuildDecltypeType(E);
6491 template<typename Derived>
6492 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
6493 TemplateName Template,
6494 SourceLocation TemplateNameLoc,
6495 const TemplateArgumentListInfo &TemplateArgs) {
6496 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
6499 template<typename Derived>
6500 NestedNameSpecifier *
6501 TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6504 QualType ObjectType,
6505 NamedDecl *FirstQualifierInScope) {
6507 // FIXME: The source location information is all wrong.
6509 SS.setScopeRep(Prefix);
6510 return static_cast<NestedNameSpecifier *>(
6511 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
6514 FirstQualifierInScope,
6518 template<typename Derived>
6519 NestedNameSpecifier *
6520 TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6522 NamespaceDecl *NS) {
6523 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6526 template<typename Derived>
6527 NestedNameSpecifier *
6528 TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6532 if (T->isDependentType() || T->isRecordType() ||
6533 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
6534 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
6535 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6539 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6543 template<typename Derived>
6545 TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6547 TemplateDecl *Template) {
6548 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
6552 template<typename Derived>
6554 TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6555 const IdentifierInfo &II,
6556 QualType ObjectType) {
6558 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6559 SS.setScopeRep(Qualifier);
6561 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
6562 Sema::TemplateTy Template;
6563 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6564 /*FIXME:*/getDerived().getBaseLocation(),
6567 ParsedType::make(ObjectType),
6568 /*EnteringContext=*/false,
6570 return Template.template getAsVal<TemplateName>();
6573 template<typename Derived>
6575 TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6576 OverloadedOperatorKind Operator,
6577 QualType ObjectType) {
6579 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6580 SS.setScopeRep(Qualifier);
6582 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6583 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6584 Operator, SymbolLocations);
6585 Sema::TemplateTy Template;
6586 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6587 /*FIXME:*/getDerived().getBaseLocation(),
6590 ParsedType::make(ObjectType),
6591 /*EnteringContext=*/false,
6593 return Template.template getAsVal<TemplateName>();
6596 template<typename Derived>
6598 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6599 SourceLocation OpLoc,
6603 Expr *Callee = OrigCallee->IgnoreParenCasts();
6604 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
6606 // Determine whether this should be a builtin operation.
6607 if (Op == OO_Subscript) {
6608 if (!First->getType()->isOverloadableType() &&
6609 !Second->getType()->isOverloadableType())
6610 return getSema().CreateBuiltinArraySubscriptExpr(First,
6611 Callee->getLocStart(),
6613 } else if (Op == OO_Arrow) {
6614 // -> is never a builtin operation.
6615 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
6616 } else if (Second == 0 || isPostIncDec) {
6617 if (!First->getType()->isOverloadableType()) {
6618 // The argument is not of overloadable type, so try to create a
6619 // built-in unary operation.
6620 UnaryOperatorKind Opc
6621 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6623 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
6626 if (!First->getType()->isOverloadableType() &&
6627 !Second->getType()->isOverloadableType()) {
6628 // Neither of the arguments is an overloadable type, so try to
6629 // create a built-in binary operation.
6630 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
6632 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
6633 if (Result.isInvalid())
6636 return move(Result);
6640 // Compute the transformed set of functions (and function templates) to be
6641 // used during overload resolution.
6642 UnresolvedSet<16> Functions;
6644 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
6645 assert(ULE->requiresADL());
6647 // FIXME: Do we have to check
6648 // IsAcceptableNonMemberOperatorCandidate for each of these?
6649 Functions.append(ULE->decls_begin(), ULE->decls_end());
6651 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
6654 // Add any functions found via argument-dependent lookup.
6655 Expr *Args[2] = { First, Second };
6656 unsigned NumArgs = 1 + (Second != 0);
6658 // Create the overloaded operator invocation for unary operators.
6659 if (NumArgs == 1 || isPostIncDec) {
6660 UnaryOperatorKind Opc
6661 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6662 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
6665 if (Op == OO_Subscript)
6666 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
6671 // Create the overloaded operator invocation for binary operators.
6672 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
6674 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6675 if (Result.isInvalid())
6678 return move(Result);
6681 template<typename Derived>
6683 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
6684 SourceLocation OperatorLoc,
6686 NestedNameSpecifier *Qualifier,
6687 SourceRange QualifierRange,
6688 TypeSourceInfo *ScopeType,
6689 SourceLocation CCLoc,
6690 SourceLocation TildeLoc,
6691 PseudoDestructorTypeStorage Destroyed) {
6694 SS.setRange(QualifierRange);
6695 SS.setScopeRep(Qualifier);
6698 QualType BaseType = Base->getType();
6699 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
6700 (!isArrow && !BaseType->getAs<RecordType>()) ||
6701 (isArrow && BaseType->getAs<PointerType>() &&
6702 !BaseType->getAs<PointerType>()->getPointeeType()
6703 ->template getAs<RecordType>())){
6704 // This pseudo-destructor expression is still a pseudo-destructor.
6705 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
6706 isArrow? tok::arrow : tok::period,
6707 SS, ScopeType, CCLoc, TildeLoc,
6712 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
6713 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
6714 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
6715 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
6716 NameInfo.setNamedTypeInfo(DestroyedType);
6718 // FIXME: the ScopeType should be tacked onto SS.
6720 return getSema().BuildMemberReferenceExpr(Base, BaseType,
6721 OperatorLoc, isArrow,
6722 SS, /*FIXME: FirstQualifier*/ 0,
6724 /*TemplateArgs*/ 0);
6727 } // end namespace clang
6729 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H