1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===//
9 // This file implements a semantic tree transformation that takes a given
10 // AST and rebuilds it, possibly transforming some nodes in the process.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15 #define LLVM_CLANG_SEMA_TREETRANSFORM_H
17 #include "clang/Sema/SemaInternal.h"
18 #include "clang/Sema/Lookup.h"
19 #include "clang/Sema/ParsedTemplate.h"
20 #include "clang/Sema/SemaDiagnostic.h"
21 #include "clang/Sema/ScopeInfo.h"
22 #include "clang/AST/Decl.h"
23 #include "clang/AST/DeclObjC.h"
24 #include "clang/AST/DeclTemplate.h"
25 #include "clang/AST/Expr.h"
26 #include "clang/AST/ExprCXX.h"
27 #include "clang/AST/ExprObjC.h"
28 #include "clang/AST/Stmt.h"
29 #include "clang/AST/StmtCXX.h"
30 #include "clang/AST/StmtObjC.h"
31 #include "clang/Sema/Ownership.h"
32 #include "clang/Sema/Designator.h"
33 #include "clang/Lex/Preprocessor.h"
34 #include "llvm/ADT/ArrayRef.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "TypeLocBuilder.h"
42 /// \brief A semantic tree transformation that allows one to transform one
43 /// abstract syntax tree into another.
45 /// A new tree transformation is defined by creating a new subclass \c X of
46 /// \c TreeTransform<X> and then overriding certain operations to provide
47 /// behavior specific to that transformation. For example, template
48 /// instantiation is implemented as a tree transformation where the
49 /// transformation of TemplateTypeParmType nodes involves substituting the
50 /// template arguments for their corresponding template parameters; a similar
51 /// transformation is performed for non-type template parameters and
52 /// template template parameters.
54 /// This tree-transformation template uses static polymorphism to allow
55 /// subclasses to customize any of its operations. Thus, a subclass can
56 /// override any of the transformation or rebuild operators by providing an
57 /// operation with the same signature as the default implementation. The
58 /// overridding function should not be virtual.
60 /// Semantic tree transformations are split into two stages, either of which
61 /// can be replaced by a subclass. The "transform" step transforms an AST node
62 /// or the parts of an AST node using the various transformation functions,
63 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
64 /// node of the appropriate kind from the pieces. The default transformation
65 /// routines recursively transform the operands to composite AST nodes (e.g.,
66 /// the pointee type of a PointerType node) and, if any of those operand nodes
67 /// were changed by the transformation, invokes the rebuild operation to create
70 /// Subclasses can customize the transformation at various levels. The
71 /// most coarse-grained transformations involve replacing TransformType(),
72 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
73 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
74 /// new implementations.
76 /// For more fine-grained transformations, subclasses can replace any of the
77 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
78 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
79 /// replacing TransformTemplateTypeParmType() allows template instantiation
80 /// to substitute template arguments for their corresponding template
81 /// parameters. Additionally, subclasses can override the \c RebuildXXX
82 /// functions to control how AST nodes are rebuilt when their operands change.
83 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
84 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
85 /// be able to use more efficient rebuild steps.
87 /// There are a handful of other functions that can be overridden, allowing one
88 /// to avoid traversing nodes that don't need any transformation
89 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90 /// operands have not changed (\c AlwaysRebuild()), and customize the
91 /// default locations and entity names used for type-checking
92 /// (\c getBaseLocation(), \c getBaseEntity()).
93 template<typename Derived>
95 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
98 class ForgetPartiallySubstitutedPackRAII {
100 TemplateArgument Old;
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
116 /// \brief Initializes a new tree transformer.
117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
119 /// \brief Retrieves a reference to the derived class.
120 Derived &getDerived() { return static_cast<Derived&>(*this); }
122 /// \brief Retrieves a reference to the derived class.
123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
130 /// \brief Retrieves a reference to the semantic analysis object used for
131 /// this tree transform.
132 Sema &getSema() const { return SemaRef; }
134 /// \brief Whether the transformation should always rebuild AST nodes, even
135 /// if none of the children have changed.
137 /// Subclasses may override this function to specify when the transformation
138 /// should rebuild all AST nodes.
139 bool AlwaysRebuild() { return false; }
141 /// \brief Returns the location of the entity being transformed, if that
142 /// information was not available elsewhere in the AST.
144 /// By default, returns no source-location information. Subclasses can
145 /// provide an alternative implementation that provides better location
147 SourceLocation getBaseLocation() { return SourceLocation(); }
149 /// \brief Returns the name of the entity being transformed, if that
150 /// information was not available elsewhere in the AST.
152 /// By default, returns an empty name. Subclasses can provide an alternative
153 /// implementation with a more precise name.
154 DeclarationName getBaseEntity() { return DeclarationName(); }
156 /// \brief Sets the "base" location and entity when that
157 /// information is known based on another transformation.
159 /// By default, the source location and entity are ignored. Subclasses can
160 /// override this function to provide a customized implementation.
161 void setBase(SourceLocation Loc, DeclarationName Entity) { }
163 /// \brief RAII object that temporarily sets the base location and entity
164 /// used for reporting diagnostics in types.
165 class TemporaryBase {
167 SourceLocation OldLocation;
168 DeclarationName OldEntity;
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
172 DeclarationName Entity) : Self(Self) {
173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
181 Self.getDerived().setBase(OldLocation, OldEntity);
185 /// \brief Determine whether the given type \p T has already been
188 /// Subclasses can provide an alternative implementation of this routine
189 /// to short-circuit evaluation when it is known that a given type will
190 /// not change. For example, template instantiation need not traverse
191 /// non-dependent types.
192 bool AlreadyTransformed(QualType T) {
196 /// \brief Determine whether the given call argument should be dropped, e.g.,
197 /// because it is a default argument.
199 /// Subclasses can provide an alternative implementation of this routine to
200 /// determine which kinds of call arguments get dropped. By default,
201 /// CXXDefaultArgument nodes are dropped (prior to transformation).
202 bool DropCallArgument(Expr *E) {
203 return E->isDefaultArgument();
206 /// \brief Determine whether we should expand a pack expansion with the
207 /// given set of parameter packs into separate arguments by repeatedly
208 /// transforming the pattern.
210 /// By default, the transformer never tries to expand pack expansions.
211 /// Subclasses can override this routine to provide different behavior.
213 /// \param EllipsisLoc The location of the ellipsis that identifies the
216 /// \param PatternRange The source range that covers the entire pattern of
217 /// the pack expansion.
219 /// \param Unexpanded The set of unexpanded parameter packs within the
222 /// \param NumUnexpanded The number of unexpanded parameter packs in
225 /// \param ShouldExpand Will be set to \c true if the transformer should
226 /// expand the corresponding pack expansions into separate arguments. When
227 /// set, \c NumExpansions must also be set.
229 /// \param RetainExpansion Whether the caller should add an unexpanded
230 /// pack expansion after all of the expanded arguments. This is used
231 /// when extending explicitly-specified template argument packs per
232 /// C++0x [temp.arg.explicit]p9.
234 /// \param NumExpansions The number of separate arguments that will be in
235 /// the expanded form of the corresponding pack expansion. This is both an
236 /// input and an output parameter, which can be set by the caller if the
237 /// number of expansions is known a priori (e.g., due to a prior substitution)
238 /// and will be set by the callee when the number of expansions is known.
239 /// The callee must set this value when \c ShouldExpand is \c true; it may
240 /// set this value in other cases.
242 /// \returns true if an error occurred (e.g., because the parameter packs
243 /// are to be instantiated with arguments of different lengths), false
244 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
246 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
247 SourceRange PatternRange,
248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
250 bool &RetainExpansion,
251 llvm::Optional<unsigned> &NumExpansions) {
252 ShouldExpand = false;
256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
272 /// \brief Note to the derived class when a function parameter pack is
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
276 /// \brief Transforms the given type into another type.
278 /// By default, this routine transforms a type by creating a
279 /// TypeSourceInfo for it and delegating to the appropriate
280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
282 /// switched to storing TypeSourceInfos.
284 /// \returns the transformed type.
285 QualType TransformType(QualType T);
287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
303 /// \brief Transform the given statement.
305 /// By default, this routine transforms a statement by delegating to the
306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
311 /// \returns the transformed statement.
312 StmtResult TransformStmt(Stmt *S);
314 /// \brief Transform the given expression.
316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
321 /// \returns the transformed expression.
322 ExprResult TransformExpr(Expr *E);
324 /// \brief Transform the given list of expressions.
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
332 /// \param Inputs The set of expressions to be transformed.
334 /// \param NumInputs The number of expressions in \c Inputs.
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
340 /// \param Outputs The transformed input expressions will be added to this
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
348 SmallVectorImpl<Expr *> &Outputs,
349 bool *ArgChanged = 0);
351 /// \brief Transform the given declaration, which is referenced from a type
354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
358 /// \brief Transform the definition of the given declaration.
360 /// By default, invokes TransformDecl() to transform the declaration.
361 /// Subclasses may override this function to provide alternate behavior.
362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
369 /// This specific declaration transformation only applies to the first
370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
379 /// \brief Transform the given nested-name-specifier with source-location
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
390 /// \brief Transform the given declaration name.
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
399 /// \brief Transform the given template name.
401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
404 /// \param Name The template name to transform.
406 /// \param NameLoc The source location of the template name.
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
425 /// \brief Transform the given template argument.
427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
436 /// \brief Transform the given set of template arguments.
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
446 /// \param Inputs The set of template arguments to be transformed.
448 /// \param NumInputs The number of template arguments in \p Inputs.
450 /// \param Outputs The set of transformed template arguments output by this
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
460 /// \brief Transform the given set of template arguments.
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
466 /// \param First An iterator to the first template argument.
468 /// \param Last An iterator one step past the last template argument.
470 /// \param Outputs The set of transformed template arguments output by this
473 /// Returns true if an error occurred.
474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
477 TemplateArgumentListInfo &Outputs);
479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
486 getDerived().getBaseLocation());
489 #define ABSTRACT_TYPELOC(CLASS, PARENT)
490 #define TYPELOC(CLASS, PARENT) \
491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
492 #include "clang/AST/TypeLocNodes.def"
495 TransformSEHHandler(Stmt *Handler);
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
505 TemplateName Template,
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
513 /// \brief Transforms the parameters of a function type into the
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
519 /// Return true on error.
520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
526 /// \brief Transforms a single function-type parameter. Return null
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
533 llvm::Optional<unsigned> NumExpansions);
535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
540 #define STMT(Node, Parent) \
541 StmtResult Transform##Node(Node *S);
542 #define EXPR(Node, Parent) \
543 ExprResult Transform##Node(Node *E);
544 #define ABSTRACT_STMT(Stmt)
545 #include "clang/AST/StmtNodes.inc"
547 /// \brief Build a new pointer type given its pointee type.
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
553 /// \brief Build a new block pointer type given its pointee type.
555 /// By default, performs semantic analysis when building the block pointer
556 /// type. Subclasses may override this routine to provide different behavior.
557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
559 /// \brief Build a new reference type given the type it references.
561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
569 SourceLocation Sigil);
571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
585 /// Also by default, all of the other Rebuild*Array
586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
598 QualType RebuildConstantArrayType(QualType ElementType,
599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
609 QualType RebuildIncompleteArrayType(QualType ElementType,
610 ArrayType::ArraySizeModifier SizeMod,
611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
614 /// \brief Build a new variable-length array type given the element type,
615 /// size modifier, size expression, and index type qualifiers.
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
619 QualType RebuildVariableArrayType(QualType ElementType,
620 ArrayType::ArraySizeModifier SizeMod,
622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
625 /// \brief Build a new dependent-sized array type given the element type,
626 /// size modifier, size expression, and index type qualifiers.
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
630 QualType RebuildDependentSizedArrayType(QualType ElementType,
631 ArrayType::ArraySizeModifier SizeMod,
633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
642 VectorType::VectorKind VecKind);
644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
652 /// \brief Build a new potentially dependently-sized extended vector type
653 /// given the element type and number of elements.
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
659 SourceLocation AttributeLoc);
661 /// \brief Build a new function type.
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
666 QualType *ParamTypes,
667 unsigned NumParamTypes,
668 bool Variadic, unsigned Quals,
669 RefQualifierKind RefQualifier,
670 const FunctionType::ExtInfo &Info);
672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
679 /// \brief Build a new typedef type.
680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
681 return SemaRef.Context.getTypeDeclType(Typedef);
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
694 /// \brief Build a new typeof(expr) type.
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
700 /// \brief Build a new typeof(type) type.
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
710 /// \brief Build a new C++0x decltype type.
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
716 /// \brief Build a new C++0x auto type.
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
723 /// \brief Build a new template specialization type.
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
729 SourceLocation TemplateLoc,
730 TemplateArgumentListInfo &Args);
732 /// \brief Build a new parenthesized type.
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
740 /// \brief Build a new qualified name type.
742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
747 NestedNameSpecifierLoc QualifierLoc,
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
754 /// \brief Build a new typename type that refers to a template-id.
756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
759 QualType RebuildDependentTemplateSpecializationType(
760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
764 TemplateArgumentListInfo &Args) {
765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
768 SS.Adopt(QualifierLoc);
769 TemplateName InstName
770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
772 if (InstName.isNull())
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
782 // Otherwise, make an elaborated type wrapping a non-dependent
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
796 /// \brief Build a new typename type that refers to an identifier.
798 /// By default, performs semantic analysis when building the typename type
799 /// (or elaborated type). Subclasses may override this routine to provide
800 /// different behavior.
801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
802 SourceLocation KeywordLoc,
803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
805 SourceLocation IdLoc) {
807 SS.Adopt(QualifierLoc);
809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
817 if (Keyword == ETK_None || Keyword == ETK_Typename)
818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
823 // We had a dependent elaborated-type-specifier that has been transformed
824 // into a non-dependent elaborated-type-specifier. Find the tag we're
826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
896 /// \brief Build a new pack expansion type.
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
908 /// \brief Build a new atomic type given its value type.
910 /// By default, performs semantic analysis when building the atomic type.
911 /// Subclasses may override this routine to provide different behavior.
912 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
914 /// \brief Build a new template name given a nested name specifier, a flag
915 /// indicating whether the "template" keyword was provided, and the template
916 /// that the template name refers to.
918 /// By default, builds the new template name directly. Subclasses may override
919 /// this routine to provide different behavior.
920 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
922 TemplateDecl *Template);
924 /// \brief Build a new template name given a nested name specifier and the
925 /// name that is referred to as a template.
927 /// By default, performs semantic analysis to determine whether the name can
928 /// be resolved to a specific template, then builds the appropriate kind of
929 /// template name. Subclasses may override this routine to provide different
931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
932 const IdentifierInfo &Name,
933 SourceLocation NameLoc,
935 NamedDecl *FirstQualifierInScope);
937 /// \brief Build a new template name given a nested name specifier and the
938 /// overloaded operator name that is referred to as a template.
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
944 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
945 OverloadedOperatorKind Operator,
946 SourceLocation NameLoc,
947 QualType ObjectType);
949 /// \brief Build a new template name given a template template parameter pack
952 /// By default, performs semantic analysis to determine whether the name can
953 /// be resolved to a specific template, then builds the appropriate kind of
954 /// template name. Subclasses may override this routine to provide different
956 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
957 const TemplateArgument &ArgPack) {
958 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
961 /// \brief Build a new compound statement.
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
965 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
966 MultiStmtArg Statements,
967 SourceLocation RBraceLoc,
969 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
973 /// \brief Build a new case statement.
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
977 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
979 SourceLocation EllipsisLoc,
981 SourceLocation ColonLoc) {
982 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
986 /// \brief Attach the body to a new case statement.
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
990 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
991 getSema().ActOnCaseStmtBody(S, Body);
995 /// \brief Build a new default statement.
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
999 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1000 SourceLocation ColonLoc,
1002 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1006 /// \brief Build a new label statement.
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
1010 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1011 SourceLocation ColonLoc, Stmt *SubStmt) {
1012 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1015 /// \brief Build a new "if" statement.
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
1019 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
1020 VarDecl *CondVar, Stmt *Then,
1021 SourceLocation ElseLoc, Stmt *Else) {
1022 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
1025 /// \brief Start building a new switch statement.
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
1029 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
1030 Expr *Cond, VarDecl *CondVar) {
1031 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1035 /// \brief Attach the body to the switch statement.
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
1039 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1040 Stmt *Switch, Stmt *Body) {
1041 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1044 /// \brief Build a new while statement.
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
1048 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Stmt *Body) {
1050 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
1053 /// \brief Build a new do-while statement.
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
1057 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1058 SourceLocation WhileLoc, SourceLocation LParenLoc,
1059 Expr *Cond, SourceLocation RParenLoc) {
1060 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1064 /// \brief Build a new for statement.
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
1068 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1069 Stmt *Init, Sema::FullExprArg Cond,
1070 VarDecl *CondVar, Sema::FullExprArg Inc,
1071 SourceLocation RParenLoc, Stmt *Body) {
1072 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1073 CondVar, Inc, RParenLoc, Body);
1076 /// \brief Build a new goto statement.
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
1080 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1082 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1085 /// \brief Build a new indirect goto statement.
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
1089 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1090 SourceLocation StarLoc,
1092 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1095 /// \brief Build a new return statement.
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
1099 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1100 return getSema().ActOnReturnStmt(ReturnLoc, Result);
1103 /// \brief Build a new declaration statement.
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
1107 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
1108 SourceLocation StartLoc,
1109 SourceLocation EndLoc) {
1110 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1111 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1114 /// \brief Build a new inline asm statement.
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
1118 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
1121 unsigned NumOutputs,
1123 IdentifierInfo **Names,
1124 MultiExprArg Constraints,
1127 MultiExprArg Clobbers,
1128 SourceLocation RParenLoc,
1130 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1131 NumInputs, Names, move(Constraints),
1132 Exprs, AsmString, Clobbers,
1136 /// \brief Build a new Objective-C @try statement.
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
1140 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1142 MultiStmtArg CatchStmts,
1144 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1148 /// \brief Rebuild an Objective-C exception declaration.
1150 /// By default, performs semantic analysis to build the new declaration.
1151 /// Subclasses may override this routine to provide different behavior.
1152 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1153 TypeSourceInfo *TInfo, QualType T) {
1154 return getSema().BuildObjCExceptionDecl(TInfo, T,
1155 ExceptionDecl->getInnerLocStart(),
1156 ExceptionDecl->getLocation(),
1157 ExceptionDecl->getIdentifier());
1160 /// \brief Build a new Objective-C @catch statement.
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
1164 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1165 SourceLocation RParenLoc,
1168 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1172 /// \brief Build a new Objective-C @finally statement.
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
1176 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1178 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1181 /// \brief Build a new Objective-C @throw statement.
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
1185 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1187 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1190 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
1194 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1196 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1199 /// \brief Build a new Objective-C @synchronized statement.
1201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
1203 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1204 Expr *Object, Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1208 /// \brief Build a new Objective-C @autoreleasepool statement.
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
1212 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1214 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1217 /// \brief Build the collection operand to a new Objective-C fast
1218 /// enumeration statement.
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1224 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1227 /// \brief Build a new Objective-C fast enumeration statement.
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
1231 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1232 SourceLocation LParenLoc,
1235 SourceLocation RParenLoc,
1237 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
1244 /// \brief Build a new C++ exception declaration.
1246 /// By default, performs semantic analysis to build the new decaration.
1247 /// Subclasses may override this routine to provide different behavior.
1248 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1249 TypeSourceInfo *Declarator,
1250 SourceLocation StartLoc,
1251 SourceLocation IdLoc,
1252 IdentifierInfo *Id) {
1253 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1254 StartLoc, IdLoc, Id);
1256 getSema().CurContext->addDecl(Var);
1260 /// \brief Build a new C++ catch statement.
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
1264 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1265 VarDecl *ExceptionDecl,
1267 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1271 /// \brief Build a new C++ try statement.
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
1275 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1277 MultiStmtArg Handlers) {
1278 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
1281 /// \brief Build a new C++0x range-based for statement.
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1286 SourceLocation ColonLoc,
1287 Stmt *Range, Stmt *BeginEnd,
1288 Expr *Cond, Expr *Inc,
1290 SourceLocation RParenLoc) {
1291 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1292 Cond, Inc, LoopVar, RParenLoc);
1295 /// \brief Attach body to a C++0x range-based for statement.
1297 /// By default, performs semantic analysis to finish the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1300 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1303 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1304 SourceLocation TryLoc,
1307 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1310 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1313 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1316 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1318 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1321 /// \brief Build a new expression that references a declaration.
1323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
1325 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1328 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1332 /// \brief Build a new expression that references a declaration.
1334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
1336 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1338 const DeclarationNameInfo &NameInfo,
1339 TemplateArgumentListInfo *TemplateArgs) {
1341 SS.Adopt(QualifierLoc);
1343 // FIXME: loses template args.
1345 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1348 /// \brief Build a new expression in parentheses.
1350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
1352 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1353 SourceLocation RParen) {
1354 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1357 /// \brief Build a new pseudo-destructor expression.
1359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
1361 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1362 SourceLocation OperatorLoc,
1365 TypeSourceInfo *ScopeType,
1366 SourceLocation CCLoc,
1367 SourceLocation TildeLoc,
1368 PseudoDestructorTypeStorage Destroyed);
1370 /// \brief Build a new unary operator expression.
1372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
1374 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1375 UnaryOperatorKind Opc,
1377 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1380 /// \brief Build a new builtin offsetof expression.
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
1384 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1385 TypeSourceInfo *Type,
1386 Sema::OffsetOfComponent *Components,
1387 unsigned NumComponents,
1388 SourceLocation RParenLoc) {
1389 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1390 NumComponents, RParenLoc);
1393 /// \brief Build a new sizeof, alignof or vec_step expression with a
1396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
1398 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1399 SourceLocation OpLoc,
1400 UnaryExprOrTypeTrait ExprKind,
1402 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1405 /// \brief Build a new sizeof, alignof or vec step expression with an
1406 /// expression argument.
1408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
1410 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1411 UnaryExprOrTypeTrait ExprKind,
1414 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1415 if (Result.isInvalid())
1418 return move(Result);
1421 /// \brief Build a new array subscript expression.
1423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
1425 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1426 SourceLocation LBracketLoc,
1428 SourceLocation RBracketLoc) {
1429 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1434 /// \brief Build a new call expression.
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
1438 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1440 SourceLocation RParenLoc,
1441 Expr *ExecConfig = 0) {
1442 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1443 move(Args), RParenLoc, ExecConfig);
1446 /// \brief Build a new member access expression.
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
1450 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1452 NestedNameSpecifierLoc QualifierLoc,
1453 const DeclarationNameInfo &MemberNameInfo,
1455 NamedDecl *FoundDecl,
1456 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1457 NamedDecl *FirstQualifierInScope) {
1458 if (!Member->getDeclName()) {
1459 // We have a reference to an unnamed field. This is always the
1460 // base of an anonymous struct/union member access, i.e. the
1461 // field is always of record type.
1462 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1463 assert(Member->getType()->isRecordType() &&
1464 "unnamed member not of record type?");
1466 ExprResult BaseResult =
1467 getSema().PerformObjectMemberConversion(Base,
1468 QualifierLoc.getNestedNameSpecifier(),
1470 if (BaseResult.isInvalid())
1472 Base = BaseResult.take();
1473 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
1475 new (getSema().Context) MemberExpr(Base, isArrow,
1476 Member, MemberNameInfo,
1477 cast<FieldDecl>(Member)->getType(),
1479 return getSema().Owned(ME);
1483 SS.Adopt(QualifierLoc);
1485 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1486 if (BaseResult.isInvalid())
1488 Base = BaseResult.take();
1489 QualType BaseType = Base->getType();
1491 // FIXME: this involves duplicating earlier analysis in a lot of
1492 // cases; we should avoid this when possible.
1493 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
1494 R.addDecl(FoundDecl);
1497 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1498 SS, FirstQualifierInScope,
1499 R, ExplicitTemplateArgs);
1502 /// \brief Build a new binary operator expression.
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
1506 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1507 BinaryOperatorKind Opc,
1508 Expr *LHS, Expr *RHS) {
1509 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1512 /// \brief Build a new conditional operator expression.
1514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
1516 ExprResult RebuildConditionalOperator(Expr *Cond,
1517 SourceLocation QuestionLoc,
1519 SourceLocation ColonLoc,
1521 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1525 /// \brief Build a new C-style cast expression.
1527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
1529 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1530 TypeSourceInfo *TInfo,
1531 SourceLocation RParenLoc,
1533 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1537 /// \brief Build a new compound literal expression.
1539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
1541 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1542 TypeSourceInfo *TInfo,
1543 SourceLocation RParenLoc,
1545 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1549 /// \brief Build a new extended vector element access expression.
1551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
1553 ExprResult RebuildExtVectorElementExpr(Expr *Base,
1554 SourceLocation OpLoc,
1555 SourceLocation AccessorLoc,
1556 IdentifierInfo &Accessor) {
1559 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
1560 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1561 OpLoc, /*IsArrow*/ false,
1562 SS, /*FirstQualifierInScope*/ 0,
1564 /* TemplateArgs */ 0);
1567 /// \brief Build a new initializer list expression.
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
1571 ExprResult RebuildInitList(SourceLocation LBraceLoc,
1573 SourceLocation RBraceLoc,
1574 QualType ResultTy) {
1576 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1577 if (Result.isInvalid() || ResultTy->isDependentType())
1578 return move(Result);
1580 // Patch in the result type we were given, which may have been computed
1581 // when the initial InitListExpr was built.
1582 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1583 ILE->setType(ResultTy);
1584 return move(Result);
1587 /// \brief Build a new designated initializer expression.
1589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
1591 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1592 MultiExprArg ArrayExprs,
1593 SourceLocation EqualOrColonLoc,
1597 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1599 if (Result.isInvalid())
1602 ArrayExprs.release();
1603 return move(Result);
1606 /// \brief Build a new value-initialized expression.
1608 /// By default, builds the implicit value initialization without performing
1609 /// any semantic analysis. Subclasses may override this routine to provide
1610 /// different behavior.
1611 ExprResult RebuildImplicitValueInitExpr(QualType T) {
1612 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1615 /// \brief Build a new \c va_arg expression.
1617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
1619 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1620 Expr *SubExpr, TypeSourceInfo *TInfo,
1621 SourceLocation RParenLoc) {
1622 return getSema().BuildVAArgExpr(BuiltinLoc,
1627 /// \brief Build a new expression list in parentheses.
1629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
1631 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1632 MultiExprArg SubExprs,
1633 SourceLocation RParenLoc) {
1634 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1638 /// \brief Build a new address-of-label expression.
1640 /// By default, performs semantic analysis, using the name of the label
1641 /// rather than attempting to map the label statement itself.
1642 /// Subclasses may override this routine to provide different behavior.
1643 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1644 SourceLocation LabelLoc, LabelDecl *Label) {
1645 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
1648 /// \brief Build a new GNU statement expression.
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
1652 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1654 SourceLocation RParenLoc) {
1655 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1658 /// \brief Build a new __builtin_choose_expr expression.
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
1662 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1663 Expr *Cond, Expr *LHS, Expr *RHS,
1664 SourceLocation RParenLoc) {
1665 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1670 /// \brief Build a new generic selection expression.
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
1674 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1675 SourceLocation DefaultLoc,
1676 SourceLocation RParenLoc,
1677 Expr *ControllingExpr,
1678 TypeSourceInfo **Types,
1680 unsigned NumAssocs) {
1681 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1682 ControllingExpr, Types, Exprs,
1686 /// \brief Build a new overloaded operator call expression.
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// The semantic analysis provides the behavior of template instantiation,
1690 /// copying with transformations that turn what looks like an overloaded
1691 /// operator call into a use of a builtin operator, performing
1692 /// argument-dependent lookup, etc. Subclasses may override this routine to
1693 /// provide different behavior.
1694 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1695 SourceLocation OpLoc,
1700 /// \brief Build a new C++ "named" cast expression, such as static_cast or
1701 /// reinterpret_cast.
1703 /// By default, this routine dispatches to one of the more-specific routines
1704 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1705 /// Subclasses may override this routine to provide different behavior.
1706 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1707 Stmt::StmtClass Class,
1708 SourceLocation LAngleLoc,
1709 TypeSourceInfo *TInfo,
1710 SourceLocation RAngleLoc,
1711 SourceLocation LParenLoc,
1713 SourceLocation RParenLoc) {
1715 case Stmt::CXXStaticCastExprClass:
1716 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
1717 RAngleLoc, LParenLoc,
1718 SubExpr, RParenLoc);
1720 case Stmt::CXXDynamicCastExprClass:
1721 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
1722 RAngleLoc, LParenLoc,
1723 SubExpr, RParenLoc);
1725 case Stmt::CXXReinterpretCastExprClass:
1726 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
1727 RAngleLoc, LParenLoc,
1731 case Stmt::CXXConstCastExprClass:
1732 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
1733 RAngleLoc, LParenLoc,
1734 SubExpr, RParenLoc);
1737 llvm_unreachable("Invalid C++ named cast");
1743 /// \brief Build a new C++ static_cast expression.
1745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
1747 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1748 SourceLocation LAngleLoc,
1749 TypeSourceInfo *TInfo,
1750 SourceLocation RAngleLoc,
1751 SourceLocation LParenLoc,
1753 SourceLocation RParenLoc) {
1754 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1756 SourceRange(LAngleLoc, RAngleLoc),
1757 SourceRange(LParenLoc, RParenLoc));
1760 /// \brief Build a new C++ dynamic_cast expression.
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
1764 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1765 SourceLocation LAngleLoc,
1766 TypeSourceInfo *TInfo,
1767 SourceLocation RAngleLoc,
1768 SourceLocation LParenLoc,
1770 SourceLocation RParenLoc) {
1771 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1773 SourceRange(LAngleLoc, RAngleLoc),
1774 SourceRange(LParenLoc, RParenLoc));
1777 /// \brief Build a new C++ reinterpret_cast expression.
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
1781 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1782 SourceLocation LAngleLoc,
1783 TypeSourceInfo *TInfo,
1784 SourceLocation RAngleLoc,
1785 SourceLocation LParenLoc,
1787 SourceLocation RParenLoc) {
1788 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1790 SourceRange(LAngleLoc, RAngleLoc),
1791 SourceRange(LParenLoc, RParenLoc));
1794 /// \brief Build a new C++ const_cast expression.
1796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
1798 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1799 SourceLocation LAngleLoc,
1800 TypeSourceInfo *TInfo,
1801 SourceLocation RAngleLoc,
1802 SourceLocation LParenLoc,
1804 SourceLocation RParenLoc) {
1805 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1807 SourceRange(LAngleLoc, RAngleLoc),
1808 SourceRange(LParenLoc, RParenLoc));
1811 /// \brief Build a new C++ functional-style cast expression.
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
1815 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1816 SourceLocation LParenLoc,
1818 SourceLocation RParenLoc) {
1819 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1820 MultiExprArg(&Sub, 1),
1824 /// \brief Build a new C++ typeid(type) expression.
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
1828 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1829 SourceLocation TypeidLoc,
1830 TypeSourceInfo *Operand,
1831 SourceLocation RParenLoc) {
1832 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1837 /// \brief Build a new C++ typeid(expr) expression.
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
1841 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1842 SourceLocation TypeidLoc,
1844 SourceLocation RParenLoc) {
1845 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
1849 /// \brief Build a new C++ __uuidof(type) expression.
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
1853 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1854 SourceLocation TypeidLoc,
1855 TypeSourceInfo *Operand,
1856 SourceLocation RParenLoc) {
1857 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1861 /// \brief Build a new C++ __uuidof(expr) expression.
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
1865 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1866 SourceLocation TypeidLoc,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1873 /// \brief Build a new C++ "this" expression.
1875 /// By default, builds a new "this" expression without performing any
1876 /// semantic analysis. Subclasses may override this routine to provide
1877 /// different behavior.
1878 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1881 return getSema().Owned(
1882 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1886 /// \brief Build a new C++ throw expression.
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
1890 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1891 bool IsThrownVariableInScope) {
1892 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
1895 /// \brief Build a new C++ default-argument expression.
1897 /// By default, builds a new default-argument expression, which does not
1898 /// require any semantic analysis. Subclasses may override this routine to
1899 /// provide different behavior.
1900 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1901 ParmVarDecl *Param) {
1902 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1906 /// \brief Build a new C++ zero-initialization expression.
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
1910 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1911 SourceLocation LParenLoc,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
1914 MultiExprArg(getSema(), 0, 0),
1918 /// \brief Build a new C++ "new" expression.
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
1922 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
1924 SourceLocation PlacementLParen,
1925 MultiExprArg PlacementArgs,
1926 SourceLocation PlacementRParen,
1927 SourceRange TypeIdParens,
1928 QualType AllocatedType,
1929 TypeSourceInfo *AllocatedTypeInfo,
1931 SourceLocation ConstructorLParen,
1932 MultiExprArg ConstructorArgs,
1933 SourceLocation ConstructorRParen) {
1934 return getSema().BuildCXXNew(StartLoc, UseGlobal,
1936 move(PlacementArgs),
1943 move(ConstructorArgs),
1947 /// \brief Build a new C++ "delete" expression.
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
1951 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1952 bool IsGlobalDelete,
1955 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1959 /// \brief Build a new unary type trait expression.
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
1963 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1964 SourceLocation StartLoc,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
1970 /// \brief Build a new binary type trait expression.
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
1974 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1975 SourceLocation StartLoc,
1976 TypeSourceInfo *LhsT,
1977 TypeSourceInfo *RhsT,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1982 /// \brief Build a new array type trait expression.
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1987 SourceLocation StartLoc,
1988 TypeSourceInfo *TSInfo,
1990 SourceLocation RParenLoc) {
1991 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1994 /// \brief Build a new expression trait expression.
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
1998 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1999 SourceLocation StartLoc,
2001 SourceLocation RParenLoc) {
2002 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2005 /// \brief Build a new (previously unresolved) declaration reference
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
2010 ExprResult RebuildDependentScopeDeclRefExpr(
2011 NestedNameSpecifierLoc QualifierLoc,
2012 const DeclarationNameInfo &NameInfo,
2013 const TemplateArgumentListInfo *TemplateArgs) {
2015 SS.Adopt(QualifierLoc);
2018 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
2021 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
2024 /// \brief Build a new template-id expression.
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
2028 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2031 const TemplateArgumentListInfo &TemplateArgs) {
2032 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
2035 /// \brief Build a new object-construction expression.
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
2039 ExprResult RebuildCXXConstructExpr(QualType T,
2041 CXXConstructorDecl *Constructor,
2044 bool HadMultipleCandidates,
2045 bool RequiresZeroInit,
2046 CXXConstructExpr::ConstructionKind ConstructKind,
2047 SourceRange ParenRange) {
2048 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
2049 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
2053 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
2054 move_arg(ConvertedArgs),
2055 HadMultipleCandidates,
2056 RequiresZeroInit, ConstructKind,
2060 /// \brief Build a new object-construction expression.
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
2064 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2065 SourceLocation LParenLoc,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2074 /// \brief Build a new object-construction expression.
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
2078 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2079 SourceLocation LParenLoc,
2081 SourceLocation RParenLoc) {
2082 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2088 /// \brief Build a new member reference expression.
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
2092 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2095 SourceLocation OperatorLoc,
2096 NestedNameSpecifierLoc QualifierLoc,
2097 NamedDecl *FirstQualifierInScope,
2098 const DeclarationNameInfo &MemberNameInfo,
2099 const TemplateArgumentListInfo *TemplateArgs) {
2101 SS.Adopt(QualifierLoc);
2103 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2104 OperatorLoc, IsArrow,
2105 SS, FirstQualifierInScope,
2110 /// \brief Build a new member reference expression.
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
2114 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
2116 SourceLocation OperatorLoc,
2118 NestedNameSpecifierLoc QualifierLoc,
2119 NamedDecl *FirstQualifierInScope,
2121 const TemplateArgumentListInfo *TemplateArgs) {
2123 SS.Adopt(QualifierLoc);
2125 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2126 OperatorLoc, IsArrow,
2127 SS, FirstQualifierInScope,
2131 /// \brief Build a new noexcept expression.
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2136 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2139 /// \brief Build a new expression to compute the length of a parameter pack.
2140 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2141 SourceLocation PackLoc,
2142 SourceLocation RParenLoc,
2143 llvm::Optional<unsigned> Length) {
2145 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2146 OperatorLoc, Pack, PackLoc,
2147 RParenLoc, *Length);
2149 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2150 OperatorLoc, Pack, PackLoc,
2154 /// \brief Build a new Objective-C @encode expression.
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
2158 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2159 TypeSourceInfo *EncodeTypeInfo,
2160 SourceLocation RParenLoc) {
2161 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2165 /// \brief Build a new Objective-C class message.
2166 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2168 ArrayRef<SourceLocation> SelectorLocs,
2169 ObjCMethodDecl *Method,
2170 SourceLocation LBracLoc,
2172 SourceLocation RBracLoc) {
2173 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2174 ReceiverTypeInfo->getType(),
2175 /*SuperLoc=*/SourceLocation(),
2176 Sel, Method, LBracLoc, SelectorLocs,
2177 RBracLoc, move(Args));
2180 /// \brief Build a new Objective-C instance message.
2181 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2183 ArrayRef<SourceLocation> SelectorLocs,
2184 ObjCMethodDecl *Method,
2185 SourceLocation LBracLoc,
2187 SourceLocation RBracLoc) {
2188 return SemaRef.BuildInstanceMessage(Receiver,
2189 Receiver->getType(),
2190 /*SuperLoc=*/SourceLocation(),
2191 Sel, Method, LBracLoc, SelectorLocs,
2192 RBracLoc, move(Args));
2195 /// \brief Build a new Objective-C ivar reference expression.
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
2199 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2200 SourceLocation IvarLoc,
2201 bool IsArrow, bool IsFreeIvar) {
2202 // FIXME: We lose track of the IsFreeIvar bit.
2204 ExprResult Base = getSema().Owned(BaseArg);
2205 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2206 Sema::LookupMemberName);
2207 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2211 if (Result.isInvalid() || Base.isInvalid())
2215 return move(Result);
2217 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2218 /*FIXME:*/IvarLoc, IsArrow, SS,
2219 /*FirstQualifierInScope=*/0,
2221 /*TemplateArgs=*/0);
2224 /// \brief Build a new Objective-C property reference expression.
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
2228 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2229 ObjCPropertyDecl *Property,
2230 SourceLocation PropertyLoc) {
2232 ExprResult Base = getSema().Owned(BaseArg);
2233 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2234 Sema::LookupMemberName);
2235 bool IsArrow = false;
2236 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2237 /*FIME:*/PropertyLoc,
2239 if (Result.isInvalid() || Base.isInvalid())
2243 return move(Result);
2245 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2246 /*FIXME:*/PropertyLoc, IsArrow,
2248 /*FirstQualifierInScope=*/0,
2250 /*TemplateArgs=*/0);
2253 /// \brief Build a new Objective-C property reference expression.
2255 /// By default, performs semantic analysis to build the new expression.
2256 /// Subclasses may override this routine to provide different behavior.
2257 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2258 ObjCMethodDecl *Getter,
2259 ObjCMethodDecl *Setter,
2260 SourceLocation PropertyLoc) {
2261 // Since these expressions can only be value-dependent, we do not
2262 // need to perform semantic analysis again.
2264 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2265 VK_LValue, OK_ObjCProperty,
2266 PropertyLoc, Base));
2269 /// \brief Build a new Objective-C "isa" expression.
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
2273 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2276 ExprResult Base = getSema().Owned(BaseArg);
2277 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2278 Sema::LookupMemberName);
2279 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2282 if (Result.isInvalid() || Base.isInvalid())
2286 return move(Result);
2288 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2289 /*FIXME:*/IsaLoc, IsArrow, SS,
2290 /*FirstQualifierInScope=*/0,
2292 /*TemplateArgs=*/0);
2295 /// \brief Build a new shuffle vector expression.
2297 /// By default, performs semantic analysis to build the new expression.
2298 /// Subclasses may override this routine to provide different behavior.
2299 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2300 MultiExprArg SubExprs,
2301 SourceLocation RParenLoc) {
2302 // Find the declaration for __builtin_shufflevector
2303 const IdentifierInfo &Name
2304 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2305 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2306 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2307 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
2309 // Build a reference to the __builtin_shufflevector builtin
2310 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
2312 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2313 VK_LValue, BuiltinLoc));
2314 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2315 if (Callee.isInvalid())
2318 // Build the CallExpr
2319 unsigned NumSubExprs = SubExprs.size();
2320 Expr **Subs = (Expr **)SubExprs.release();
2321 ExprResult TheCall = SemaRef.Owned(
2322 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
2324 Builtin->getCallResultType(),
2325 Expr::getValueKindForType(Builtin->getResultType()),
2328 // Type-check the __builtin_shufflevector expression.
2329 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
2332 /// \brief Build a new template argument pack expansion.
2334 /// By default, performs semantic analysis to build a new pack expansion
2335 /// for a template argument. Subclasses may override this routine to provide
2336 /// different behavior.
2337 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2338 SourceLocation EllipsisLoc,
2339 llvm::Optional<unsigned> NumExpansions) {
2340 switch (Pattern.getArgument().getKind()) {
2341 case TemplateArgument::Expression: {
2343 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2344 EllipsisLoc, NumExpansions);
2345 if (Result.isInvalid())
2346 return TemplateArgumentLoc();
2348 return TemplateArgumentLoc(Result.get(), Result.get());
2351 case TemplateArgument::Template:
2352 return TemplateArgumentLoc(TemplateArgument(
2353 Pattern.getArgument().getAsTemplate(),
2355 Pattern.getTemplateQualifierLoc(),
2356 Pattern.getTemplateNameLoc(),
2359 case TemplateArgument::Null:
2360 case TemplateArgument::Integral:
2361 case TemplateArgument::Declaration:
2362 case TemplateArgument::Pack:
2363 case TemplateArgument::TemplateExpansion:
2364 llvm_unreachable("Pack expansion pattern has no parameter packs");
2366 case TemplateArgument::Type:
2367 if (TypeSourceInfo *Expansion
2368 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2371 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2376 return TemplateArgumentLoc();
2379 /// \brief Build a new expression pack expansion.
2381 /// By default, performs semantic analysis to build a new pack expansion
2382 /// for an expression. Subclasses may override this routine to provide
2383 /// different behavior.
2384 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2385 llvm::Optional<unsigned> NumExpansions) {
2386 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2389 /// \brief Build a new atomic operation expression.
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
2393 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2394 MultiExprArg SubExprs,
2396 AtomicExpr::AtomicOp Op,
2397 SourceLocation RParenLoc) {
2398 // Just create the expression; there is not any interesting semantic
2399 // analysis here because we can't actually build an AtomicExpr until
2400 // we are sure it is semantically sound.
2401 unsigned NumSubExprs = SubExprs.size();
2402 Expr **Subs = (Expr **)SubExprs.release();
2403 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2404 NumSubExprs, RetTy, Op,
2409 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2410 QualType ObjectType,
2411 NamedDecl *FirstQualifierInScope,
2414 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2415 QualType ObjectType,
2416 NamedDecl *FirstQualifierInScope,
2420 template<typename Derived>
2421 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
2423 return SemaRef.Owned(S);
2425 switch (S->getStmtClass()) {
2426 case Stmt::NoStmtClass: break;
2428 // Transform individual statement nodes
2429 #define STMT(Node, Parent) \
2430 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2431 #define ABSTRACT_STMT(Node)
2432 #define EXPR(Node, Parent)
2433 #include "clang/AST/StmtNodes.inc"
2435 // Transform expressions by calling TransformExpr.
2436 #define STMT(Node, Parent)
2437 #define ABSTRACT_STMT(Stmt)
2438 #define EXPR(Node, Parent) case Stmt::Node##Class:
2439 #include "clang/AST/StmtNodes.inc"
2441 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
2445 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
2449 return SemaRef.Owned(S);
2453 template<typename Derived>
2454 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2456 return SemaRef.Owned(E);
2458 switch (E->getStmtClass()) {
2459 case Stmt::NoStmtClass: break;
2460 #define STMT(Node, Parent) case Stmt::Node##Class: break;
2461 #define ABSTRACT_STMT(Stmt)
2462 #define EXPR(Node, Parent) \
2463 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
2464 #include "clang/AST/StmtNodes.inc"
2467 return SemaRef.Owned(E);
2470 template<typename Derived>
2471 bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2474 SmallVectorImpl<Expr *> &Outputs,
2476 for (unsigned I = 0; I != NumInputs; ++I) {
2477 // If requested, drop call arguments that need to be dropped.
2478 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2485 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2486 Expr *Pattern = Expansion->getPattern();
2488 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2489 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2490 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2492 // Determine whether the set of unexpanded parameter packs can and should
2495 bool RetainExpansion = false;
2496 llvm::Optional<unsigned> OrigNumExpansions
2497 = Expansion->getNumExpansions();
2498 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
2499 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2500 Pattern->getSourceRange(),
2502 Expand, RetainExpansion,
2507 // The transform has determined that we should perform a simple
2508 // transformation on the pack expansion, producing another pack
2510 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2511 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2512 if (OutPattern.isInvalid())
2515 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2516 Expansion->getEllipsisLoc(),
2518 if (Out.isInvalid())
2523 Outputs.push_back(Out.get());
2527 // Record right away that the argument was changed. This needs
2528 // to happen even if the array expands to nothing.
2529 if (ArgChanged) *ArgChanged = true;
2531 // The transform has determined that we should perform an elementwise
2532 // expansion of the pattern. Do so.
2533 for (unsigned I = 0; I != *NumExpansions; ++I) {
2534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2535 ExprResult Out = getDerived().TransformExpr(Pattern);
2536 if (Out.isInvalid())
2539 if (Out.get()->containsUnexpandedParameterPack()) {
2540 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2542 if (Out.isInvalid())
2546 Outputs.push_back(Out.get());
2552 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2553 if (Result.isInvalid())
2556 if (Result.get() != Inputs[I] && ArgChanged)
2559 Outputs.push_back(Result.get());
2565 template<typename Derived>
2566 NestedNameSpecifierLoc
2567 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2568 NestedNameSpecifierLoc NNS,
2569 QualType ObjectType,
2570 NamedDecl *FirstQualifierInScope) {
2571 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2572 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2573 Qualifier = Qualifier.getPrefix())
2574 Qualifiers.push_back(Qualifier);
2577 while (!Qualifiers.empty()) {
2578 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2579 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2581 switch (QNNS->getKind()) {
2582 case NestedNameSpecifier::Identifier:
2583 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2584 *QNNS->getAsIdentifier(),
2585 Q.getLocalBeginLoc(),
2587 ObjectType, false, SS,
2588 FirstQualifierInScope, false))
2589 return NestedNameSpecifierLoc();
2593 case NestedNameSpecifier::Namespace: {
2595 = cast_or_null<NamespaceDecl>(
2596 getDerived().TransformDecl(
2597 Q.getLocalBeginLoc(),
2598 QNNS->getAsNamespace()));
2599 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2603 case NestedNameSpecifier::NamespaceAlias: {
2604 NamespaceAliasDecl *Alias
2605 = cast_or_null<NamespaceAliasDecl>(
2606 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2607 QNNS->getAsNamespaceAlias()));
2608 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2609 Q.getLocalEndLoc());
2613 case NestedNameSpecifier::Global:
2614 // There is no meaningful transformation that one could perform on the
2616 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2619 case NestedNameSpecifier::TypeSpecWithTemplate:
2620 case NestedNameSpecifier::TypeSpec: {
2621 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2622 FirstQualifierInScope, SS);
2625 return NestedNameSpecifierLoc();
2627 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2628 (SemaRef.getLangOptions().CPlusPlus0x &&
2629 TL.getType()->isEnumeralType())) {
2630 assert(!TL.getType().hasLocalQualifiers() &&
2631 "Can't get cv-qualifiers here");
2632 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2633 Q.getLocalEndLoc());
2636 // If the nested-name-specifier is an invalid type def, don't emit an
2637 // error because a previous error should have already been emitted.
2638 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2639 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2640 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2641 << TL.getType() << SS.getRange();
2643 return NestedNameSpecifierLoc();
2647 // The qualifier-in-scope and object type only apply to the leftmost entity.
2648 FirstQualifierInScope = 0;
2649 ObjectType = QualType();
2652 // Don't rebuild the nested-name-specifier if we don't have to.
2653 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2654 !getDerived().AlwaysRebuild())
2657 // If we can re-use the source-location data from the original
2658 // nested-name-specifier, do so.
2659 if (SS.location_size() == NNS.getDataLength() &&
2660 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2661 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2663 // Allocate new nested-name-specifier location information.
2664 return SS.getWithLocInContext(SemaRef.Context);
2667 template<typename Derived>
2669 TreeTransform<Derived>
2670 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
2671 DeclarationName Name = NameInfo.getName();
2673 return DeclarationNameInfo();
2675 switch (Name.getNameKind()) {
2676 case DeclarationName::Identifier:
2677 case DeclarationName::ObjCZeroArgSelector:
2678 case DeclarationName::ObjCOneArgSelector:
2679 case DeclarationName::ObjCMultiArgSelector:
2680 case DeclarationName::CXXOperatorName:
2681 case DeclarationName::CXXLiteralOperatorName:
2682 case DeclarationName::CXXUsingDirective:
2685 case DeclarationName::CXXConstructorName:
2686 case DeclarationName::CXXDestructorName:
2687 case DeclarationName::CXXConversionFunctionName: {
2688 TypeSourceInfo *NewTInfo;
2689 CanQualType NewCanTy;
2690 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
2691 NewTInfo = getDerived().TransformType(OldTInfo);
2693 return DeclarationNameInfo();
2694 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
2698 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
2699 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
2701 return DeclarationNameInfo();
2702 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2705 DeclarationName NewName
2706 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2708 DeclarationNameInfo NewNameInfo(NameInfo);
2709 NewNameInfo.setName(NewName);
2710 NewNameInfo.setNamedTypeInfo(NewTInfo);
2715 llvm_unreachable("Unknown name kind.");
2718 template<typename Derived>
2720 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2722 SourceLocation NameLoc,
2723 QualType ObjectType,
2724 NamedDecl *FirstQualifierInScope) {
2725 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2726 TemplateDecl *Template = QTN->getTemplateDecl();
2727 assert(Template && "qualified template name must refer to a template");
2729 TemplateDecl *TransTemplate
2730 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2733 return TemplateName();
2735 if (!getDerived().AlwaysRebuild() &&
2736 SS.getScopeRep() == QTN->getQualifier() &&
2737 TransTemplate == Template)
2740 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2744 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2745 if (SS.getScopeRep()) {
2746 // These apply to the scope specifier, not the template.
2747 ObjectType = QualType();
2748 FirstQualifierInScope = 0;
2751 if (!getDerived().AlwaysRebuild() &&
2752 SS.getScopeRep() == DTN->getQualifier() &&
2753 ObjectType.isNull())
2756 if (DTN->isIdentifier()) {
2757 return getDerived().RebuildTemplateName(SS,
2758 *DTN->getIdentifier(),
2761 FirstQualifierInScope);
2764 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2768 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2769 TemplateDecl *TransTemplate
2770 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2773 return TemplateName();
2775 if (!getDerived().AlwaysRebuild() &&
2776 TransTemplate == Template)
2779 return TemplateName(TransTemplate);
2782 if (SubstTemplateTemplateParmPackStorage *SubstPack
2783 = Name.getAsSubstTemplateTemplateParmPack()) {
2784 TemplateTemplateParmDecl *TransParam
2785 = cast_or_null<TemplateTemplateParmDecl>(
2786 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2788 return TemplateName();
2790 if (!getDerived().AlwaysRebuild() &&
2791 TransParam == SubstPack->getParameterPack())
2794 return getDerived().RebuildTemplateName(TransParam,
2795 SubstPack->getArgumentPack());
2798 // These should be getting filtered out before they reach the AST.
2799 llvm_unreachable("overloaded function decl survived to here");
2800 return TemplateName();
2803 template<typename Derived>
2804 void TreeTransform<Derived>::InventTemplateArgumentLoc(
2805 const TemplateArgument &Arg,
2806 TemplateArgumentLoc &Output) {
2807 SourceLocation Loc = getDerived().getBaseLocation();
2808 switch (Arg.getKind()) {
2809 case TemplateArgument::Null:
2810 llvm_unreachable("null template argument in TreeTransform");
2813 case TemplateArgument::Type:
2814 Output = TemplateArgumentLoc(Arg,
2815 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2819 case TemplateArgument::Template:
2820 case TemplateArgument::TemplateExpansion: {
2821 NestedNameSpecifierLocBuilder Builder;
2822 TemplateName Template = Arg.getAsTemplate();
2823 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2824 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2825 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2826 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2828 if (Arg.getKind() == TemplateArgument::Template)
2829 Output = TemplateArgumentLoc(Arg,
2830 Builder.getWithLocInContext(SemaRef.Context),
2833 Output = TemplateArgumentLoc(Arg,
2834 Builder.getWithLocInContext(SemaRef.Context),
2840 case TemplateArgument::Expression:
2841 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2844 case TemplateArgument::Declaration:
2845 case TemplateArgument::Integral:
2846 case TemplateArgument::Pack:
2847 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2852 template<typename Derived>
2853 bool TreeTransform<Derived>::TransformTemplateArgument(
2854 const TemplateArgumentLoc &Input,
2855 TemplateArgumentLoc &Output) {
2856 const TemplateArgument &Arg = Input.getArgument();
2857 switch (Arg.getKind()) {
2858 case TemplateArgument::Null:
2859 case TemplateArgument::Integral:
2863 case TemplateArgument::Type: {
2864 TypeSourceInfo *DI = Input.getTypeSourceInfo();
2866 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2868 DI = getDerived().TransformType(DI);
2869 if (!DI) return true;
2871 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2875 case TemplateArgument::Declaration: {
2876 // FIXME: we should never have to transform one of these.
2877 DeclarationName Name;
2878 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2879 Name = ND->getDeclName();
2880 TemporaryBase Rebase(*this, Input.getLocation(), Name);
2881 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2882 if (!D) return true;
2884 Expr *SourceExpr = Input.getSourceDeclExpression();
2886 EnterExpressionEvaluationContext Unevaluated(getSema(),
2888 ExprResult E = getDerived().TransformExpr(SourceExpr);
2889 SourceExpr = (E.isInvalid() ? 0 : E.take());
2892 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2896 case TemplateArgument::Template: {
2897 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2899 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2905 SS.Adopt(QualifierLoc);
2906 TemplateName Template
2907 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2908 Input.getTemplateNameLoc());
2909 if (Template.isNull())
2912 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
2913 Input.getTemplateNameLoc());
2917 case TemplateArgument::TemplateExpansion:
2918 llvm_unreachable("Caller should expand pack expansions");
2920 case TemplateArgument::Expression: {
2921 // Template argument expressions are not potentially evaluated.
2922 EnterExpressionEvaluationContext Unevaluated(getSema(),
2925 Expr *InputExpr = Input.getSourceExpression();
2926 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2928 ExprResult E = getDerived().TransformExpr(InputExpr);
2929 if (E.isInvalid()) return true;
2930 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2934 case TemplateArgument::Pack: {
2935 SmallVector<TemplateArgument, 4> TransformedArgs;
2936 TransformedArgs.reserve(Arg.pack_size());
2937 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2938 AEnd = Arg.pack_end();
2941 // FIXME: preserve source information here when we start
2942 // caring about parameter packs.
2944 TemplateArgumentLoc InputArg;
2945 TemplateArgumentLoc OutputArg;
2946 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2947 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2950 TransformedArgs.push_back(OutputArg.getArgument());
2953 TemplateArgument *TransformedArgsPtr
2954 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2955 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2956 TransformedArgsPtr);
2957 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2958 TransformedArgs.size()),
2959 Input.getLocInfo());
2964 // Work around bogus GCC warning
2968 /// \brief Iterator adaptor that invents template argument location information
2969 /// for each of the template arguments in its underlying iterator.
2970 template<typename Derived, typename InputIterator>
2971 class TemplateArgumentLocInventIterator {
2972 TreeTransform<Derived> &Self;
2976 typedef TemplateArgumentLoc value_type;
2977 typedef TemplateArgumentLoc reference;
2978 typedef typename std::iterator_traits<InputIterator>::difference_type
2980 typedef std::input_iterator_tag iterator_category;
2983 TemplateArgumentLoc Arg;
2986 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2988 const TemplateArgumentLoc *operator->() const { return &Arg; }
2991 TemplateArgumentLocInventIterator() { }
2993 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2995 : Self(Self), Iter(Iter) { }
2997 TemplateArgumentLocInventIterator &operator++() {
3002 TemplateArgumentLocInventIterator operator++(int) {
3003 TemplateArgumentLocInventIterator Old(*this);
3008 reference operator*() const {
3009 TemplateArgumentLoc Result;
3010 Self.InventTemplateArgumentLoc(*Iter, Result);
3014 pointer operator->() const { return pointer(**this); }
3016 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3017 const TemplateArgumentLocInventIterator &Y) {
3018 return X.Iter == Y.Iter;
3021 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3022 const TemplateArgumentLocInventIterator &Y) {
3023 return X.Iter != Y.Iter;
3027 template<typename Derived>
3028 template<typename InputIterator>
3029 bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3031 TemplateArgumentListInfo &Outputs) {
3032 for (; First != Last; ++First) {
3033 TemplateArgumentLoc Out;
3034 TemplateArgumentLoc In = *First;
3036 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3037 // Unpack argument packs, which we translate them into separate
3039 // FIXME: We could do much better if we could guarantee that the
3040 // TemplateArgumentLocInfo for the pack expansion would be usable for
3041 // all of the template arguments in the argument pack.
3042 typedef TemplateArgumentLocInventIterator<Derived,
3043 TemplateArgument::pack_iterator>
3045 if (TransformTemplateArguments(PackLocIterator(*this,
3046 In.getArgument().pack_begin()),
3047 PackLocIterator(*this,
3048 In.getArgument().pack_end()),
3055 if (In.getArgument().isPackExpansion()) {
3056 // We have a pack expansion, for which we will be substituting into
3058 SourceLocation Ellipsis;
3059 llvm::Optional<unsigned> OrigNumExpansions;
3060 TemplateArgumentLoc Pattern
3061 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3064 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3065 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3066 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3068 // Determine whether the set of unexpanded parameter packs can and should
3071 bool RetainExpansion = false;
3072 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
3073 if (getDerived().TryExpandParameterPacks(Ellipsis,
3074 Pattern.getSourceRange(),
3082 // The transform has determined that we should perform a simple
3083 // transformation on the pack expansion, producing another pack
3085 TemplateArgumentLoc OutPattern;
3086 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3087 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3090 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3092 if (Out.getArgument().isNull())
3095 Outputs.addArgument(Out);
3099 // The transform has determined that we should perform an elementwise
3100 // expansion of the pattern. Do so.
3101 for (unsigned I = 0; I != *NumExpansions; ++I) {
3102 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3104 if (getDerived().TransformTemplateArgument(Pattern, Out))
3107 if (Out.getArgument().containsUnexpandedParameterPack()) {
3108 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3110 if (Out.getArgument().isNull())
3114 Outputs.addArgument(Out);
3117 // If we're supposed to retain a pack expansion, do so by temporarily
3118 // forgetting the partially-substituted parameter pack.
3119 if (RetainExpansion) {
3120 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3122 if (getDerived().TransformTemplateArgument(Pattern, Out))
3125 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3127 if (Out.getArgument().isNull())
3130 Outputs.addArgument(Out);
3137 if (getDerived().TransformTemplateArgument(In, Out))
3140 Outputs.addArgument(Out);
3147 //===----------------------------------------------------------------------===//
3148 // Type transformation
3149 //===----------------------------------------------------------------------===//
3151 template<typename Derived>
3152 QualType TreeTransform<Derived>::TransformType(QualType T) {
3153 if (getDerived().AlreadyTransformed(T))
3156 // Temporary workaround. All of these transformations should
3157 // eventually turn into transformations on TypeLocs.
3158 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3159 getDerived().getBaseLocation());
3161 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3166 return NewDI->getType();
3169 template<typename Derived>
3170 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3171 if (getDerived().AlreadyTransformed(DI->getType()))
3176 TypeLoc TL = DI->getTypeLoc();
3177 TLB.reserve(TL.getFullDataSize());
3179 QualType Result = getDerived().TransformType(TLB, TL);
3180 if (Result.isNull())
3183 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3186 template<typename Derived>
3188 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3189 switch (T.getTypeLocClass()) {
3190 #define ABSTRACT_TYPELOC(CLASS, PARENT)
3191 #define TYPELOC(CLASS, PARENT) \
3192 case TypeLoc::CLASS: \
3193 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3194 #include "clang/AST/TypeLocNodes.def"
3197 llvm_unreachable("unhandled type loc!");
3201 /// FIXME: By default, this routine adds type qualifiers only to types
3202 /// that can have qualifiers, and silently suppresses those qualifiers
3203 /// that are not permitted (e.g., qualifiers on reference or function
3204 /// types). This is the right thing for template instantiation, but
3205 /// probably not for other clients.
3206 template<typename Derived>
3208 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
3209 QualifiedTypeLoc T) {
3210 Qualifiers Quals = T.getType().getLocalQualifiers();
3212 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3213 if (Result.isNull())
3216 // Silently suppress qualifiers if the result type can't be qualified.
3217 // FIXME: this is the right thing for template instantiation, but
3218 // probably not for other clients.
3219 if (Result->isFunctionType() || Result->isReferenceType())
3222 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3224 if (Quals.hasObjCLifetime()) {
3225 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3226 Quals.removeObjCLifetime();
3227 else if (Result.getObjCLifetime()) {
3229 // A lifetime qualifier applied to a substituted template parameter
3230 // overrides the lifetime qualifier from the template argument.
3231 if (const SubstTemplateTypeParmType *SubstTypeParam
3232 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3233 QualType Replacement = SubstTypeParam->getReplacementType();
3234 Qualifiers Qs = Replacement.getQualifiers();
3235 Qs.removeObjCLifetime();
3237 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3239 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3240 SubstTypeParam->getReplacedParameter(),
3242 TLB.TypeWasModifiedSafely(Result);
3244 // Otherwise, complain about the addition of a qualifier to an
3245 // already-qualified type.
3246 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
3247 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
3250 Quals.removeObjCLifetime();
3254 if (!Quals.empty()) {
3255 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3256 TLB.push<QualifiedTypeLoc>(Result);
3257 // No location information to preserve.
3263 template<typename Derived>
3265 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3266 QualType ObjectType,
3267 NamedDecl *UnqualLookup,
3269 QualType T = TL.getType();
3270 if (getDerived().AlreadyTransformed(T))
3276 if (isa<TemplateSpecializationType>(T)) {
3277 TemplateSpecializationTypeLoc SpecTL
3278 = cast<TemplateSpecializationTypeLoc>(TL);
3280 TemplateName Template =
3281 getDerived().TransformTemplateName(SS,
3282 SpecTL.getTypePtr()->getTemplateName(),
3283 SpecTL.getTemplateNameLoc(),
3284 ObjectType, UnqualLookup);
3285 if (Template.isNull())
3288 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3290 } else if (isa<DependentTemplateSpecializationType>(T)) {
3291 DependentTemplateSpecializationTypeLoc SpecTL
3292 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3294 TemplateName Template
3295 = getDerived().RebuildTemplateName(SS,
3296 *SpecTL.getTypePtr()->getIdentifier(),
3297 SpecTL.getNameLoc(),
3298 ObjectType, UnqualLookup);
3299 if (Template.isNull())
3302 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3307 // Nothing special needs to be done for these.
3308 Result = getDerived().TransformType(TLB, TL);
3311 if (Result.isNull())
3314 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3317 template<typename Derived>
3319 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3320 QualType ObjectType,
3321 NamedDecl *UnqualLookup,
3323 // FIXME: Painfully copy-paste from the above!
3325 QualType T = TSInfo->getType();
3326 if (getDerived().AlreadyTransformed(T))
3332 TypeLoc TL = TSInfo->getTypeLoc();
3333 if (isa<TemplateSpecializationType>(T)) {
3334 TemplateSpecializationTypeLoc SpecTL
3335 = cast<TemplateSpecializationTypeLoc>(TL);
3337 TemplateName Template
3338 = getDerived().TransformTemplateName(SS,
3339 SpecTL.getTypePtr()->getTemplateName(),
3340 SpecTL.getTemplateNameLoc(),
3341 ObjectType, UnqualLookup);
3342 if (Template.isNull())
3345 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3347 } else if (isa<DependentTemplateSpecializationType>(T)) {
3348 DependentTemplateSpecializationTypeLoc SpecTL
3349 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3351 TemplateName Template
3352 = getDerived().RebuildTemplateName(SS,
3353 *SpecTL.getTypePtr()->getIdentifier(),
3354 SpecTL.getNameLoc(),
3355 ObjectType, UnqualLookup);
3356 if (Template.isNull())
3359 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3364 // Nothing special needs to be done for these.
3365 Result = getDerived().TransformType(TLB, TL);
3368 if (Result.isNull())
3371 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3374 template <class TyLoc> static inline
3375 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3376 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3377 NewT.setNameLoc(T.getNameLoc());
3381 template<typename Derived>
3382 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
3384 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3385 NewT.setBuiltinLoc(T.getBuiltinLoc());
3386 if (T.needsExtraLocalData())
3387 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3391 template<typename Derived>
3392 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
3395 return TransformTypeSpecType(TLB, T);
3398 template<typename Derived>
3399 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
3400 PointerTypeLoc TL) {
3401 QualType PointeeType
3402 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3403 if (PointeeType.isNull())
3406 QualType Result = TL.getType();
3407 if (PointeeType->getAs<ObjCObjectType>()) {
3408 // A dependent pointer type 'T *' has is being transformed such
3409 // that an Objective-C class type is being replaced for 'T'. The
3410 // resulting pointer type is an ObjCObjectPointerType, not a
3412 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3414 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3415 NewT.setStarLoc(TL.getStarLoc());
3419 if (getDerived().AlwaysRebuild() ||
3420 PointeeType != TL.getPointeeLoc().getType()) {
3421 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3422 if (Result.isNull())
3426 // Objective-C ARC can add lifetime qualifiers to the type that we're
3428 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3430 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3431 NewT.setSigilLoc(TL.getSigilLoc());
3435 template<typename Derived>
3437 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
3438 BlockPointerTypeLoc TL) {
3439 QualType PointeeType
3440 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3441 if (PointeeType.isNull())
3444 QualType Result = TL.getType();
3445 if (getDerived().AlwaysRebuild() ||
3446 PointeeType != TL.getPointeeLoc().getType()) {
3447 Result = getDerived().RebuildBlockPointerType(PointeeType,
3449 if (Result.isNull())
3453 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3454 NewT.setSigilLoc(TL.getSigilLoc());
3458 /// Transforms a reference type. Note that somewhat paradoxically we
3459 /// don't care whether the type itself is an l-value type or an r-value
3460 /// type; we only care if the type was *written* as an l-value type
3461 /// or an r-value type.
3462 template<typename Derived>
3464 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
3465 ReferenceTypeLoc TL) {
3466 const ReferenceType *T = TL.getTypePtr();
3468 // Note that this works with the pointee-as-written.
3469 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3470 if (PointeeType.isNull())
3473 QualType Result = TL.getType();
3474 if (getDerived().AlwaysRebuild() ||
3475 PointeeType != T->getPointeeTypeAsWritten()) {
3476 Result = getDerived().RebuildReferenceType(PointeeType,
3477 T->isSpelledAsLValue(),
3479 if (Result.isNull())
3483 // Objective-C ARC can add lifetime qualifiers to the type that we're
3485 TLB.TypeWasModifiedSafely(
3486 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3488 // r-value references can be rebuilt as l-value references.
3489 ReferenceTypeLoc NewTL;
3490 if (isa<LValueReferenceType>(Result))
3491 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3493 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3494 NewTL.setSigilLoc(TL.getSigilLoc());
3499 template<typename Derived>
3501 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
3502 LValueReferenceTypeLoc TL) {
3503 return TransformReferenceType(TLB, TL);
3506 template<typename Derived>
3508 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
3509 RValueReferenceTypeLoc TL) {
3510 return TransformReferenceType(TLB, TL);
3513 template<typename Derived>
3515 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
3516 MemberPointerTypeLoc TL) {
3517 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3518 if (PointeeType.isNull())
3521 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3522 TypeSourceInfo* NewClsTInfo = 0;
3524 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3529 const MemberPointerType *T = TL.getTypePtr();
3530 QualType OldClsType = QualType(T->getClass(), 0);
3531 QualType NewClsType;
3533 NewClsType = NewClsTInfo->getType();
3535 NewClsType = getDerived().TransformType(OldClsType);
3536 if (NewClsType.isNull())
3540 QualType Result = TL.getType();
3541 if (getDerived().AlwaysRebuild() ||
3542 PointeeType != T->getPointeeType() ||
3543 NewClsType != OldClsType) {
3544 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
3546 if (Result.isNull())
3550 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3551 NewTL.setSigilLoc(TL.getSigilLoc());
3552 NewTL.setClassTInfo(NewClsTInfo);
3557 template<typename Derived>
3559 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
3560 ConstantArrayTypeLoc TL) {
3561 const ConstantArrayType *T = TL.getTypePtr();
3562 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3563 if (ElementType.isNull())
3566 QualType Result = TL.getType();
3567 if (getDerived().AlwaysRebuild() ||
3568 ElementType != T->getElementType()) {
3569 Result = getDerived().RebuildConstantArrayType(ElementType,
3570 T->getSizeModifier(),
3572 T->getIndexTypeCVRQualifiers(),
3573 TL.getBracketsRange());
3574 if (Result.isNull())
3578 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3579 NewTL.setLBracketLoc(TL.getLBracketLoc());
3580 NewTL.setRBracketLoc(TL.getRBracketLoc());
3582 Expr *Size = TL.getSizeExpr();
3584 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3585 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3587 NewTL.setSizeExpr(Size);
3592 template<typename Derived>
3593 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
3594 TypeLocBuilder &TLB,
3595 IncompleteArrayTypeLoc TL) {
3596 const IncompleteArrayType *T = TL.getTypePtr();
3597 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3598 if (ElementType.isNull())
3601 QualType Result = TL.getType();
3602 if (getDerived().AlwaysRebuild() ||
3603 ElementType != T->getElementType()) {
3604 Result = getDerived().RebuildIncompleteArrayType(ElementType,
3605 T->getSizeModifier(),
3606 T->getIndexTypeCVRQualifiers(),
3607 TL.getBracketsRange());
3608 if (Result.isNull())
3612 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3613 NewTL.setLBracketLoc(TL.getLBracketLoc());
3614 NewTL.setRBracketLoc(TL.getRBracketLoc());
3615 NewTL.setSizeExpr(0);
3620 template<typename Derived>
3622 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
3623 VariableArrayTypeLoc TL) {
3624 const VariableArrayType *T = TL.getTypePtr();
3625 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3626 if (ElementType.isNull())
3629 // Array bounds are not potentially evaluated contexts
3630 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3632 ExprResult SizeResult
3633 = getDerived().TransformExpr(T->getSizeExpr());
3634 if (SizeResult.isInvalid())
3637 Expr *Size = SizeResult.take();
3639 QualType Result = TL.getType();
3640 if (getDerived().AlwaysRebuild() ||
3641 ElementType != T->getElementType() ||
3642 Size != T->getSizeExpr()) {
3643 Result = getDerived().RebuildVariableArrayType(ElementType,
3644 T->getSizeModifier(),
3646 T->getIndexTypeCVRQualifiers(),
3647 TL.getBracketsRange());
3648 if (Result.isNull())
3652 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3653 NewTL.setLBracketLoc(TL.getLBracketLoc());
3654 NewTL.setRBracketLoc(TL.getRBracketLoc());
3655 NewTL.setSizeExpr(Size);
3660 template<typename Derived>
3662 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
3663 DependentSizedArrayTypeLoc TL) {
3664 const DependentSizedArrayType *T = TL.getTypePtr();
3665 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3666 if (ElementType.isNull())
3669 // Array bounds are not potentially evaluated contexts
3670 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3672 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3673 Expr *origSize = TL.getSizeExpr();
3674 if (!origSize) origSize = T->getSizeExpr();
3676 ExprResult sizeResult
3677 = getDerived().TransformExpr(origSize);
3678 if (sizeResult.isInvalid())
3681 Expr *size = sizeResult.get();
3683 QualType Result = TL.getType();
3684 if (getDerived().AlwaysRebuild() ||
3685 ElementType != T->getElementType() ||
3687 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3688 T->getSizeModifier(),
3690 T->getIndexTypeCVRQualifiers(),
3691 TL.getBracketsRange());
3692 if (Result.isNull())
3696 // We might have any sort of array type now, but fortunately they
3697 // all have the same location layout.
3698 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3699 NewTL.setLBracketLoc(TL.getLBracketLoc());
3700 NewTL.setRBracketLoc(TL.getRBracketLoc());
3701 NewTL.setSizeExpr(size);
3706 template<typename Derived>
3707 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3708 TypeLocBuilder &TLB,
3709 DependentSizedExtVectorTypeLoc TL) {
3710 const DependentSizedExtVectorType *T = TL.getTypePtr();
3712 // FIXME: ext vector locs should be nested
3713 QualType ElementType = getDerived().TransformType(T->getElementType());
3714 if (ElementType.isNull())
3717 // Vector sizes are not potentially evaluated contexts
3718 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3720 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3721 if (Size.isInvalid())
3724 QualType Result = TL.getType();
3725 if (getDerived().AlwaysRebuild() ||
3726 ElementType != T->getElementType() ||
3727 Size.get() != T->getSizeExpr()) {
3728 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
3730 T->getAttributeLoc());
3731 if (Result.isNull())
3735 // Result might be dependent or not.
3736 if (isa<DependentSizedExtVectorType>(Result)) {
3737 DependentSizedExtVectorTypeLoc NewTL
3738 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3739 NewTL.setNameLoc(TL.getNameLoc());
3741 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3742 NewTL.setNameLoc(TL.getNameLoc());
3748 template<typename Derived>
3749 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
3751 const VectorType *T = TL.getTypePtr();
3752 QualType ElementType = getDerived().TransformType(T->getElementType());
3753 if (ElementType.isNull())
3756 QualType Result = TL.getType();
3757 if (getDerived().AlwaysRebuild() ||
3758 ElementType != T->getElementType()) {
3759 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3760 T->getVectorKind());
3761 if (Result.isNull())
3765 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3766 NewTL.setNameLoc(TL.getNameLoc());
3771 template<typename Derived>
3772 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
3773 ExtVectorTypeLoc TL) {
3774 const VectorType *T = TL.getTypePtr();
3775 QualType ElementType = getDerived().TransformType(T->getElementType());
3776 if (ElementType.isNull())
3779 QualType Result = TL.getType();
3780 if (getDerived().AlwaysRebuild() ||
3781 ElementType != T->getElementType()) {
3782 Result = getDerived().RebuildExtVectorType(ElementType,
3783 T->getNumElements(),
3784 /*FIXME*/ SourceLocation());
3785 if (Result.isNull())
3789 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3790 NewTL.setNameLoc(TL.getNameLoc());
3795 template<typename Derived>
3797 TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3798 int indexAdjustment,
3799 llvm::Optional<unsigned> NumExpansions) {
3800 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3801 TypeSourceInfo *NewDI = 0;
3803 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3804 // If we're substituting into a pack expansion type and we know the
3805 TypeLoc OldTL = OldDI->getTypeLoc();
3806 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3809 TypeLoc NewTL = OldDI->getTypeLoc();
3810 TLB.reserve(NewTL.getFullDataSize());
3812 QualType Result = getDerived().TransformType(TLB,
3813 OldExpansionTL.getPatternLoc());
3814 if (Result.isNull())
3817 Result = RebuildPackExpansionType(Result,
3818 OldExpansionTL.getPatternLoc().getSourceRange(),
3819 OldExpansionTL.getEllipsisLoc(),
3821 if (Result.isNull())
3824 PackExpansionTypeLoc NewExpansionTL
3825 = TLB.push<PackExpansionTypeLoc>(Result);
3826 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3827 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3829 NewDI = getDerived().TransformType(OldDI);
3833 if (NewDI == OldDI && indexAdjustment == 0)
3836 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3837 OldParm->getDeclContext(),
3838 OldParm->getInnerLocStart(),
3839 OldParm->getLocation(),
3840 OldParm->getIdentifier(),
3843 OldParm->getStorageClass(),
3844 OldParm->getStorageClassAsWritten(),
3846 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3847 OldParm->getFunctionScopeIndex() + indexAdjustment);
3851 template<typename Derived>
3852 bool TreeTransform<Derived>::
3853 TransformFunctionTypeParams(SourceLocation Loc,
3854 ParmVarDecl **Params, unsigned NumParams,
3855 const QualType *ParamTypes,
3856 SmallVectorImpl<QualType> &OutParamTypes,
3857 SmallVectorImpl<ParmVarDecl*> *PVars) {
3858 int indexAdjustment = 0;
3860 for (unsigned i = 0; i != NumParams; ++i) {
3861 if (ParmVarDecl *OldParm = Params[i]) {
3862 assert(OldParm->getFunctionScopeIndex() == i);
3864 llvm::Optional<unsigned> NumExpansions;
3865 ParmVarDecl *NewParm = 0;
3866 if (OldParm->isParameterPack()) {
3867 // We have a function parameter pack that may need to be expanded.
3868 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3870 // Find the parameter packs that could be expanded.
3871 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3872 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3873 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3874 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3875 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3877 // Determine whether we should expand the parameter packs.
3878 bool ShouldExpand = false;
3879 bool RetainExpansion = false;
3880 llvm::Optional<unsigned> OrigNumExpansions
3881 = ExpansionTL.getTypePtr()->getNumExpansions();
3882 NumExpansions = OrigNumExpansions;
3883 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3884 Pattern.getSourceRange(),
3893 // Expand the function parameter pack into multiple, separate
3895 getDerived().ExpandingFunctionParameterPack(OldParm);
3896 for (unsigned I = 0; I != *NumExpansions; ++I) {
3897 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3898 ParmVarDecl *NewParm
3899 = getDerived().TransformFunctionTypeParam(OldParm,
3905 OutParamTypes.push_back(NewParm->getType());
3907 PVars->push_back(NewParm);
3910 // If we're supposed to retain a pack expansion, do so by temporarily
3911 // forgetting the partially-substituted parameter pack.
3912 if (RetainExpansion) {
3913 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3914 ParmVarDecl *NewParm
3915 = getDerived().TransformFunctionTypeParam(OldParm,
3921 OutParamTypes.push_back(NewParm->getType());
3923 PVars->push_back(NewParm);
3926 // The next parameter should have the same adjustment as the
3927 // last thing we pushed, but we post-incremented indexAdjustment
3928 // on every push. Also, if we push nothing, the adjustment should
3932 // We're done with the pack expansion.
3936 // We'll substitute the parameter now without expanding the pack
3938 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3939 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3943 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3945 llvm::Optional<unsigned>());
3951 OutParamTypes.push_back(NewParm->getType());
3953 PVars->push_back(NewParm);
3957 // Deal with the possibility that we don't have a parameter
3958 // declaration for this parameter.
3959 QualType OldType = ParamTypes[i];
3960 bool IsPackExpansion = false;
3961 llvm::Optional<unsigned> NumExpansions;
3963 if (const PackExpansionType *Expansion
3964 = dyn_cast<PackExpansionType>(OldType)) {
3965 // We have a function parameter pack that may need to be expanded.
3966 QualType Pattern = Expansion->getPattern();
3967 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3968 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3970 // Determine whether we should expand the parameter packs.
3971 bool ShouldExpand = false;
3972 bool RetainExpansion = false;
3973 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
3982 // Expand the function parameter pack into multiple, separate
3984 for (unsigned I = 0; I != *NumExpansions; ++I) {
3985 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3986 QualType NewType = getDerived().TransformType(Pattern);
3987 if (NewType.isNull())
3990 OutParamTypes.push_back(NewType);
3992 PVars->push_back(0);
3995 // We're done with the pack expansion.
3999 // If we're supposed to retain a pack expansion, do so by temporarily
4000 // forgetting the partially-substituted parameter pack.
4001 if (RetainExpansion) {
4002 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4003 QualType NewType = getDerived().TransformType(Pattern);
4004 if (NewType.isNull())
4007 OutParamTypes.push_back(NewType);
4009 PVars->push_back(0);
4012 // We'll substitute the parameter now without expanding the pack
4014 OldType = Expansion->getPattern();
4015 IsPackExpansion = true;
4016 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4017 NewType = getDerived().TransformType(OldType);
4019 NewType = getDerived().TransformType(OldType);
4022 if (NewType.isNull())
4025 if (IsPackExpansion)
4026 NewType = getSema().Context.getPackExpansionType(NewType,
4029 OutParamTypes.push_back(NewType);
4031 PVars->push_back(0);
4036 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4037 if (ParmVarDecl *parm = (*PVars)[i])
4038 assert(parm->getFunctionScopeIndex() == i);
4045 template<typename Derived>
4047 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4048 FunctionProtoTypeLoc TL) {
4049 // Transform the parameters and return type.
4051 // We instantiate in source order, with the return type first followed by
4052 // the parameters, because users tend to expect this (even if they shouldn't
4055 // When the function has a trailing return type, we instantiate the
4056 // parameters before the return type, since the return type can then refer
4057 // to the parameters themselves (via decltype, sizeof, etc.).
4059 SmallVector<QualType, 4> ParamTypes;
4060 SmallVector<ParmVarDecl*, 4> ParamDecls;
4061 const FunctionProtoType *T = TL.getTypePtr();
4063 QualType ResultType;
4065 if (TL.getTrailingReturn()) {
4066 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4069 TL.getTypePtr()->arg_type_begin(),
4070 ParamTypes, &ParamDecls))
4073 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4074 if (ResultType.isNull())
4078 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4079 if (ResultType.isNull())
4082 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4085 TL.getTypePtr()->arg_type_begin(),
4086 ParamTypes, &ParamDecls))
4090 QualType Result = TL.getType();
4091 if (getDerived().AlwaysRebuild() ||
4092 ResultType != T->getResultType() ||
4093 T->getNumArgs() != ParamTypes.size() ||
4094 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4095 Result = getDerived().RebuildFunctionProtoType(ResultType,
4100 T->getRefQualifier(),
4102 if (Result.isNull())
4106 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4107 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4108 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4109 NewTL.setTrailingReturn(TL.getTrailingReturn());
4110 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4111 NewTL.setArg(i, ParamDecls[i]);
4116 template<typename Derived>
4117 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4118 TypeLocBuilder &TLB,
4119 FunctionNoProtoTypeLoc TL) {
4120 const FunctionNoProtoType *T = TL.getTypePtr();
4121 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4122 if (ResultType.isNull())
4125 QualType Result = TL.getType();
4126 if (getDerived().AlwaysRebuild() ||
4127 ResultType != T->getResultType())
4128 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4130 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4131 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4132 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4133 NewTL.setTrailingReturn(false);
4138 template<typename Derived> QualType
4139 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
4140 UnresolvedUsingTypeLoc TL) {
4141 const UnresolvedUsingType *T = TL.getTypePtr();
4142 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4146 QualType Result = TL.getType();
4147 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4148 Result = getDerived().RebuildUnresolvedUsingType(D);
4149 if (Result.isNull())
4153 // We might get an arbitrary type spec type back. We should at
4154 // least always get a type spec type, though.
4155 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4156 NewTL.setNameLoc(TL.getNameLoc());
4161 template<typename Derived>
4162 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
4163 TypedefTypeLoc TL) {
4164 const TypedefType *T = TL.getTypePtr();
4165 TypedefNameDecl *Typedef
4166 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4171 QualType Result = TL.getType();
4172 if (getDerived().AlwaysRebuild() ||
4173 Typedef != T->getDecl()) {
4174 Result = getDerived().RebuildTypedefType(Typedef);
4175 if (Result.isNull())
4179 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4180 NewTL.setNameLoc(TL.getNameLoc());
4185 template<typename Derived>
4186 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
4187 TypeOfExprTypeLoc TL) {
4188 // typeof expressions are not potentially evaluated contexts
4189 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
4191 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4195 QualType Result = TL.getType();
4196 if (getDerived().AlwaysRebuild() ||
4197 E.get() != TL.getUnderlyingExpr()) {
4198 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4199 if (Result.isNull())
4204 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4205 NewTL.setTypeofLoc(TL.getTypeofLoc());
4206 NewTL.setLParenLoc(TL.getLParenLoc());
4207 NewTL.setRParenLoc(TL.getRParenLoc());
4212 template<typename Derived>
4213 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
4215 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4216 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4220 QualType Result = TL.getType();
4221 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4222 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4223 if (Result.isNull())
4227 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4228 NewTL.setTypeofLoc(TL.getTypeofLoc());
4229 NewTL.setLParenLoc(TL.getLParenLoc());
4230 NewTL.setRParenLoc(TL.getRParenLoc());
4231 NewTL.setUnderlyingTInfo(New_Under_TI);
4236 template<typename Derived>
4237 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
4238 DecltypeTypeLoc TL) {
4239 const DecltypeType *T = TL.getTypePtr();
4241 // decltype expressions are not potentially evaluated contexts
4242 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
4244 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4248 QualType Result = TL.getType();
4249 if (getDerived().AlwaysRebuild() ||
4250 E.get() != T->getUnderlyingExpr()) {
4251 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4252 if (Result.isNull())
4257 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4258 NewTL.setNameLoc(TL.getNameLoc());
4263 template<typename Derived>
4264 QualType TreeTransform<Derived>::TransformUnaryTransformType(
4265 TypeLocBuilder &TLB,
4266 UnaryTransformTypeLoc TL) {
4267 QualType Result = TL.getType();
4268 if (Result->isDependentType()) {
4269 const UnaryTransformType *T = TL.getTypePtr();
4271 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4272 Result = getDerived().RebuildUnaryTransformType(NewBase,
4275 if (Result.isNull())
4279 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4280 NewTL.setKWLoc(TL.getKWLoc());
4281 NewTL.setParensRange(TL.getParensRange());
4282 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4286 template<typename Derived>
4287 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4289 const AutoType *T = TL.getTypePtr();
4290 QualType OldDeduced = T->getDeducedType();
4291 QualType NewDeduced;
4292 if (!OldDeduced.isNull()) {
4293 NewDeduced = getDerived().TransformType(OldDeduced);
4294 if (NewDeduced.isNull())
4298 QualType Result = TL.getType();
4299 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4300 Result = getDerived().RebuildAutoType(NewDeduced);
4301 if (Result.isNull())
4305 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4306 NewTL.setNameLoc(TL.getNameLoc());
4311 template<typename Derived>
4312 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
4314 const RecordType *T = TL.getTypePtr();
4316 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4321 QualType Result = TL.getType();
4322 if (getDerived().AlwaysRebuild() ||
4323 Record != T->getDecl()) {
4324 Result = getDerived().RebuildRecordType(Record);
4325 if (Result.isNull())
4329 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4330 NewTL.setNameLoc(TL.getNameLoc());
4335 template<typename Derived>
4336 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
4338 const EnumType *T = TL.getTypePtr();
4340 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4345 QualType Result = TL.getType();
4346 if (getDerived().AlwaysRebuild() ||
4347 Enum != T->getDecl()) {
4348 Result = getDerived().RebuildEnumType(Enum);
4349 if (Result.isNull())
4353 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4354 NewTL.setNameLoc(TL.getNameLoc());
4359 template<typename Derived>
4360 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4361 TypeLocBuilder &TLB,
4362 InjectedClassNameTypeLoc TL) {
4363 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4364 TL.getTypePtr()->getDecl());
4365 if (!D) return QualType();
4367 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4368 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4372 template<typename Derived>
4373 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4374 TypeLocBuilder &TLB,
4375 TemplateTypeParmTypeLoc TL) {
4376 return TransformTypeSpecType(TLB, TL);
4379 template<typename Derived>
4380 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4381 TypeLocBuilder &TLB,
4382 SubstTemplateTypeParmTypeLoc TL) {
4383 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4385 // Substitute into the replacement type, which itself might involve something
4386 // that needs to be transformed. This only tends to occur with default
4387 // template arguments of template template parameters.
4388 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4389 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4390 if (Replacement.isNull())
4393 // Always canonicalize the replacement type.
4394 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4396 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4399 // Propagate type-source information.
4400 SubstTemplateTypeParmTypeLoc NewTL
4401 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4402 NewTL.setNameLoc(TL.getNameLoc());
4407 template<typename Derived>
4408 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4409 TypeLocBuilder &TLB,
4410 SubstTemplateTypeParmPackTypeLoc TL) {
4411 return TransformTypeSpecType(TLB, TL);
4414 template<typename Derived>
4415 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4416 TypeLocBuilder &TLB,
4417 TemplateSpecializationTypeLoc TL) {
4418 const TemplateSpecializationType *T = TL.getTypePtr();
4420 // The nested-name-specifier never matters in a TemplateSpecializationType,
4421 // because we can't have a dependent nested-name-specifier anyway.
4423 TemplateName Template
4424 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4425 TL.getTemplateNameLoc());
4426 if (Template.isNull())
4429 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4432 template<typename Derived>
4433 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4435 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4436 if (ValueType.isNull())
4439 QualType Result = TL.getType();
4440 if (getDerived().AlwaysRebuild() ||
4441 ValueType != TL.getValueLoc().getType()) {
4442 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4443 if (Result.isNull())
4447 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4448 NewTL.setKWLoc(TL.getKWLoc());
4449 NewTL.setLParenLoc(TL.getLParenLoc());
4450 NewTL.setRParenLoc(TL.getRParenLoc());
4456 /// \brief Simple iterator that traverses the template arguments in a
4457 /// container that provides a \c getArgLoc() member function.
4459 /// This iterator is intended to be used with the iterator form of
4460 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4461 template<typename ArgLocContainer>
4462 class TemplateArgumentLocContainerIterator {
4463 ArgLocContainer *Container;
4467 typedef TemplateArgumentLoc value_type;
4468 typedef TemplateArgumentLoc reference;
4469 typedef int difference_type;
4470 typedef std::input_iterator_tag iterator_category;
4473 TemplateArgumentLoc Arg;
4476 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4478 const TemplateArgumentLoc *operator->() const {
4484 TemplateArgumentLocContainerIterator() {}
4486 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4488 : Container(&Container), Index(Index) { }
4490 TemplateArgumentLocContainerIterator &operator++() {
4495 TemplateArgumentLocContainerIterator operator++(int) {
4496 TemplateArgumentLocContainerIterator Old(*this);
4501 TemplateArgumentLoc operator*() const {
4502 return Container->getArgLoc(Index);
4505 pointer operator->() const {
4506 return pointer(Container->getArgLoc(Index));
4509 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4510 const TemplateArgumentLocContainerIterator &Y) {
4511 return X.Container == Y.Container && X.Index == Y.Index;
4514 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4515 const TemplateArgumentLocContainerIterator &Y) {
4522 template <typename Derived>
4523 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4524 TypeLocBuilder &TLB,
4525 TemplateSpecializationTypeLoc TL,
4526 TemplateName Template) {
4527 TemplateArgumentListInfo NewTemplateArgs;
4528 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4529 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4530 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4532 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4533 ArgIterator(TL, TL.getNumArgs()),
4537 // FIXME: maybe don't rebuild if all the template arguments are the same.
4540 getDerived().RebuildTemplateSpecializationType(Template,
4541 TL.getTemplateNameLoc(),
4544 if (!Result.isNull()) {
4545 // Specializations of template template parameters are represented as
4546 // TemplateSpecializationTypes, and substitution of type alias templates
4547 // within a dependent context can transform them into
4548 // DependentTemplateSpecializationTypes.
4549 if (isa<DependentTemplateSpecializationType>(Result)) {
4550 DependentTemplateSpecializationTypeLoc NewTL
4551 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4552 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4553 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4554 NewTL.setNameLoc(TL.getTemplateNameLoc());
4555 NewTL.setLAngleLoc(TL.getLAngleLoc());
4556 NewTL.setRAngleLoc(TL.getRAngleLoc());
4557 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4558 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4562 TemplateSpecializationTypeLoc NewTL
4563 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4564 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4565 NewTL.setLAngleLoc(TL.getLAngleLoc());
4566 NewTL.setRAngleLoc(TL.getRAngleLoc());
4567 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4568 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4574 template <typename Derived>
4575 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4576 TypeLocBuilder &TLB,
4577 DependentTemplateSpecializationTypeLoc TL,
4578 TemplateName Template,
4580 TemplateArgumentListInfo NewTemplateArgs;
4581 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4582 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4583 typedef TemplateArgumentLocContainerIterator<
4584 DependentTemplateSpecializationTypeLoc> ArgIterator;
4585 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4586 ArgIterator(TL, TL.getNumArgs()),
4590 // FIXME: maybe don't rebuild if all the template arguments are the same.
4592 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4594 = getSema().Context.getDependentTemplateSpecializationType(
4595 TL.getTypePtr()->getKeyword(),
4596 DTN->getQualifier(),
4597 DTN->getIdentifier(),
4600 DependentTemplateSpecializationTypeLoc NewTL
4601 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4602 NewTL.setKeywordLoc(TL.getKeywordLoc());
4604 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
4605 NewTL.setNameLoc(TL.getNameLoc());
4606 NewTL.setLAngleLoc(TL.getLAngleLoc());
4607 NewTL.setRAngleLoc(TL.getRAngleLoc());
4608 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4609 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4614 = getDerived().RebuildTemplateSpecializationType(Template,
4618 if (!Result.isNull()) {
4619 /// FIXME: Wrap this in an elaborated-type-specifier?
4620 TemplateSpecializationTypeLoc NewTL
4621 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4622 NewTL.setTemplateNameLoc(TL.getNameLoc());
4623 NewTL.setLAngleLoc(TL.getLAngleLoc());
4624 NewTL.setRAngleLoc(TL.getRAngleLoc());
4625 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4626 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4632 template<typename Derived>
4634 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
4635 ElaboratedTypeLoc TL) {
4636 const ElaboratedType *T = TL.getTypePtr();
4638 NestedNameSpecifierLoc QualifierLoc;
4639 // NOTE: the qualifier in an ElaboratedType is optional.
4640 if (TL.getQualifierLoc()) {
4642 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4647 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4648 if (NamedT.isNull())
4651 // C++0x [dcl.type.elab]p2:
4652 // If the identifier resolves to a typedef-name or the simple-template-id
4653 // resolves to an alias template specialization, the
4654 // elaborated-type-specifier is ill-formed.
4655 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4656 if (const TemplateSpecializationType *TST =
4657 NamedT->getAs<TemplateSpecializationType>()) {
4658 TemplateName Template = TST->getTemplateName();
4659 if (TypeAliasTemplateDecl *TAT =
4660 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4661 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4662 diag::err_tag_reference_non_tag) << 4;
4663 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4668 QualType Result = TL.getType();
4669 if (getDerived().AlwaysRebuild() ||
4670 QualifierLoc != TL.getQualifierLoc() ||
4671 NamedT != T->getNamedType()) {
4672 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4674 QualifierLoc, NamedT);
4675 if (Result.isNull())
4679 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4680 NewTL.setKeywordLoc(TL.getKeywordLoc());
4681 NewTL.setQualifierLoc(QualifierLoc);
4685 template<typename Derived>
4686 QualType TreeTransform<Derived>::TransformAttributedType(
4687 TypeLocBuilder &TLB,
4688 AttributedTypeLoc TL) {
4689 const AttributedType *oldType = TL.getTypePtr();
4690 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4691 if (modifiedType.isNull())
4694 QualType result = TL.getType();
4696 // FIXME: dependent operand expressions?
4697 if (getDerived().AlwaysRebuild() ||
4698 modifiedType != oldType->getModifiedType()) {
4699 // TODO: this is really lame; we should really be rebuilding the
4700 // equivalent type from first principles.
4701 QualType equivalentType
4702 = getDerived().TransformType(oldType->getEquivalentType());
4703 if (equivalentType.isNull())
4705 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4710 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4711 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4712 if (TL.hasAttrOperand())
4713 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4714 if (TL.hasAttrExprOperand())
4715 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4716 else if (TL.hasAttrEnumOperand())
4717 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4722 template<typename Derived>
4724 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4726 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4730 QualType Result = TL.getType();
4731 if (getDerived().AlwaysRebuild() ||
4732 Inner != TL.getInnerLoc().getType()) {
4733 Result = getDerived().RebuildParenType(Inner);
4734 if (Result.isNull())
4738 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4739 NewTL.setLParenLoc(TL.getLParenLoc());
4740 NewTL.setRParenLoc(TL.getRParenLoc());
4744 template<typename Derived>
4745 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
4746 DependentNameTypeLoc TL) {
4747 const DependentNameType *T = TL.getTypePtr();
4749 NestedNameSpecifierLoc QualifierLoc
4750 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4755 = getDerived().RebuildDependentNameType(T->getKeyword(),
4760 if (Result.isNull())
4763 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4764 QualType NamedT = ElabT->getNamedType();
4765 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4767 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4768 NewTL.setKeywordLoc(TL.getKeywordLoc());
4769 NewTL.setQualifierLoc(QualifierLoc);
4771 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4772 NewTL.setKeywordLoc(TL.getKeywordLoc());
4773 NewTL.setQualifierLoc(QualifierLoc);
4774 NewTL.setNameLoc(TL.getNameLoc());
4779 template<typename Derived>
4780 QualType TreeTransform<Derived>::
4781 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4782 DependentTemplateSpecializationTypeLoc TL) {
4783 NestedNameSpecifierLoc QualifierLoc;
4784 if (TL.getQualifierLoc()) {
4786 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4792 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
4795 template<typename Derived>
4796 QualType TreeTransform<Derived>::
4797 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4798 DependentTemplateSpecializationTypeLoc TL,
4799 NestedNameSpecifierLoc QualifierLoc) {
4800 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4802 TemplateArgumentListInfo NewTemplateArgs;
4803 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4804 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4806 typedef TemplateArgumentLocContainerIterator<
4807 DependentTemplateSpecializationTypeLoc> ArgIterator;
4808 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4809 ArgIterator(TL, TL.getNumArgs()),
4814 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4819 if (Result.isNull())
4822 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4823 QualType NamedT = ElabT->getNamedType();
4825 // Copy information relevant to the template specialization.
4826 TemplateSpecializationTypeLoc NamedTL
4827 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4828 NamedTL.setTemplateNameLoc(TL.getNameLoc());
4829 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4830 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4831 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
4832 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
4834 // Copy information relevant to the elaborated type.
4835 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4836 NewTL.setKeywordLoc(TL.getKeywordLoc());
4837 NewTL.setQualifierLoc(QualifierLoc);
4838 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4839 DependentTemplateSpecializationTypeLoc SpecTL
4840 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4841 SpecTL.setKeywordLoc(TL.getKeywordLoc());
4842 SpecTL.setQualifierLoc(QualifierLoc);
4843 SpecTL.setNameLoc(TL.getNameLoc());
4844 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4845 SpecTL.setRAngleLoc(TL.getRAngleLoc());
4846 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
4847 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
4849 TemplateSpecializationTypeLoc SpecTL
4850 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4851 SpecTL.setTemplateNameLoc(TL.getNameLoc());
4852 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4853 SpecTL.setRAngleLoc(TL.getRAngleLoc());
4854 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
4855 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
4860 template<typename Derived>
4861 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4862 PackExpansionTypeLoc TL) {
4864 = getDerived().TransformType(TLB, TL.getPatternLoc());
4865 if (Pattern.isNull())
4868 QualType Result = TL.getType();
4869 if (getDerived().AlwaysRebuild() ||
4870 Pattern != TL.getPatternLoc().getType()) {
4871 Result = getDerived().RebuildPackExpansionType(Pattern,
4872 TL.getPatternLoc().getSourceRange(),
4873 TL.getEllipsisLoc(),
4874 TL.getTypePtr()->getNumExpansions());
4875 if (Result.isNull())
4879 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4880 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4884 template<typename Derived>
4886 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
4887 ObjCInterfaceTypeLoc TL) {
4888 // ObjCInterfaceType is never dependent.
4889 TLB.pushFullCopy(TL);
4890 return TL.getType();
4893 template<typename Derived>
4895 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
4896 ObjCObjectTypeLoc TL) {
4897 // ObjCObjectType is never dependent.
4898 TLB.pushFullCopy(TL);
4899 return TL.getType();
4902 template<typename Derived>
4904 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
4905 ObjCObjectPointerTypeLoc TL) {
4906 // ObjCObjectPointerType is never dependent.
4907 TLB.pushFullCopy(TL);
4908 return TL.getType();
4911 //===----------------------------------------------------------------------===//
4912 // Statement transformation
4913 //===----------------------------------------------------------------------===//
4914 template<typename Derived>
4916 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
4917 return SemaRef.Owned(S);
4920 template<typename Derived>
4922 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4923 return getDerived().TransformCompoundStmt(S, false);
4926 template<typename Derived>
4928 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
4930 bool SubStmtInvalid = false;
4931 bool SubStmtChanged = false;
4932 ASTOwningVector<Stmt*> Statements(getSema());
4933 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4935 StmtResult Result = getDerived().TransformStmt(*B);
4936 if (Result.isInvalid()) {
4937 // Immediately fail if this was a DeclStmt, since it's very
4938 // likely that this will cause problems for future statements.
4939 if (isa<DeclStmt>(*B))
4942 // Otherwise, just keep processing substatements and fail later.
4943 SubStmtInvalid = true;
4947 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4948 Statements.push_back(Result.takeAs<Stmt>());
4954 if (!getDerived().AlwaysRebuild() &&
4956 return SemaRef.Owned(S);
4958 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4959 move_arg(Statements),
4964 template<typename Derived>
4966 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
4967 ExprResult LHS, RHS;
4969 // The case value expressions are not potentially evaluated.
4970 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
4972 // Transform the left-hand case value.
4973 LHS = getDerived().TransformExpr(S->getLHS());
4974 if (LHS.isInvalid())
4977 // Transform the right-hand case value (for the GNU case-range extension).
4978 RHS = getDerived().TransformExpr(S->getRHS());
4979 if (RHS.isInvalid())
4983 // Build the case statement.
4984 // Case statements are always rebuilt so that they will attached to their
4985 // transformed switch statement.
4986 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
4988 S->getEllipsisLoc(),
4991 if (Case.isInvalid())
4994 // Transform the statement following the case
4995 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
4996 if (SubStmt.isInvalid())
4999 // Attach the body to the case statement
5000 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
5003 template<typename Derived>
5005 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
5006 // Transform the statement following the default case
5007 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5008 if (SubStmt.isInvalid())
5011 // Default statements are always rebuilt
5012 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
5016 template<typename Derived>
5018 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
5019 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5020 if (SubStmt.isInvalid())
5023 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5029 // FIXME: Pass the real colon location in.
5030 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
5031 cast<LabelDecl>(LD), SourceLocation(),
5035 template<typename Derived>
5037 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
5038 // Transform the condition
5040 VarDecl *ConditionVar = 0;
5041 if (S->getConditionVariable()) {
5043 = cast_or_null<VarDecl>(
5044 getDerived().TransformDefinition(
5045 S->getConditionVariable()->getLocation(),
5046 S->getConditionVariable()));
5050 Cond = getDerived().TransformExpr(S->getCond());
5052 if (Cond.isInvalid())
5055 // Convert the condition to a boolean value.
5057 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5059 if (CondE.isInvalid())
5066 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5067 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5070 // Transform the "then" branch.
5071 StmtResult Then = getDerived().TransformStmt(S->getThen());
5072 if (Then.isInvalid())
5075 // Transform the "else" branch.
5076 StmtResult Else = getDerived().TransformStmt(S->getElse());
5077 if (Else.isInvalid())
5080 if (!getDerived().AlwaysRebuild() &&
5081 FullCond.get() == S->getCond() &&
5082 ConditionVar == S->getConditionVariable() &&
5083 Then.get() == S->getThen() &&
5084 Else.get() == S->getElse())
5085 return SemaRef.Owned(S);
5087 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
5089 S->getElseLoc(), Else.get());
5092 template<typename Derived>
5094 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
5095 // Transform the condition.
5097 VarDecl *ConditionVar = 0;
5098 if (S->getConditionVariable()) {
5100 = cast_or_null<VarDecl>(
5101 getDerived().TransformDefinition(
5102 S->getConditionVariable()->getLocation(),
5103 S->getConditionVariable()));
5107 Cond = getDerived().TransformExpr(S->getCond());
5109 if (Cond.isInvalid())
5113 // Rebuild the switch statement.
5115 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5117 if (Switch.isInvalid())
5120 // Transform the body of the switch statement.
5121 StmtResult Body = getDerived().TransformStmt(S->getBody());
5122 if (Body.isInvalid())
5125 // Complete the switch statement.
5126 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5130 template<typename Derived>
5132 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
5133 // Transform the condition
5135 VarDecl *ConditionVar = 0;
5136 if (S->getConditionVariable()) {
5138 = cast_or_null<VarDecl>(
5139 getDerived().TransformDefinition(
5140 S->getConditionVariable()->getLocation(),
5141 S->getConditionVariable()));
5145 Cond = getDerived().TransformExpr(S->getCond());
5147 if (Cond.isInvalid())
5151 // Convert the condition to a boolean value.
5152 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5154 if (CondE.isInvalid())
5160 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5161 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5164 // Transform the body
5165 StmtResult Body = getDerived().TransformStmt(S->getBody());
5166 if (Body.isInvalid())
5169 if (!getDerived().AlwaysRebuild() &&
5170 FullCond.get() == S->getCond() &&
5171 ConditionVar == S->getConditionVariable() &&
5172 Body.get() == S->getBody())
5175 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
5176 ConditionVar, Body.get());
5179 template<typename Derived>
5181 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
5182 // Transform the body
5183 StmtResult Body = getDerived().TransformStmt(S->getBody());
5184 if (Body.isInvalid())
5187 // Transform the condition
5188 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5189 if (Cond.isInvalid())
5192 if (!getDerived().AlwaysRebuild() &&
5193 Cond.get() == S->getCond() &&
5194 Body.get() == S->getBody())
5195 return SemaRef.Owned(S);
5197 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5198 /*FIXME:*/S->getWhileLoc(), Cond.get(),
5202 template<typename Derived>
5204 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
5205 // Transform the initialization statement
5206 StmtResult Init = getDerived().TransformStmt(S->getInit());
5207 if (Init.isInvalid())
5210 // Transform the condition
5212 VarDecl *ConditionVar = 0;
5213 if (S->getConditionVariable()) {
5215 = cast_or_null<VarDecl>(
5216 getDerived().TransformDefinition(
5217 S->getConditionVariable()->getLocation(),
5218 S->getConditionVariable()));
5222 Cond = getDerived().TransformExpr(S->getCond());
5224 if (Cond.isInvalid())
5228 // Convert the condition to a boolean value.
5229 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5231 if (CondE.isInvalid())
5238 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5239 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5242 // Transform the increment
5243 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5244 if (Inc.isInvalid())
5247 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5248 if (S->getInc() && !FullInc.get())
5251 // Transform the body
5252 StmtResult Body = getDerived().TransformStmt(S->getBody());
5253 if (Body.isInvalid())
5256 if (!getDerived().AlwaysRebuild() &&
5257 Init.get() == S->getInit() &&
5258 FullCond.get() == S->getCond() &&
5259 Inc.get() == S->getInc() &&
5260 Body.get() == S->getBody())
5261 return SemaRef.Owned(S);
5263 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
5264 Init.get(), FullCond, ConditionVar,
5265 FullInc, S->getRParenLoc(), Body.get());
5268 template<typename Derived>
5270 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
5271 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5276 // Goto statements must always be rebuilt, to resolve the label.
5277 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
5278 cast<LabelDecl>(LD));
5281 template<typename Derived>
5283 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
5284 ExprResult Target = getDerived().TransformExpr(S->getTarget());
5285 if (Target.isInvalid())
5288 if (!getDerived().AlwaysRebuild() &&
5289 Target.get() == S->getTarget())
5290 return SemaRef.Owned(S);
5292 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
5296 template<typename Derived>
5298 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
5299 return SemaRef.Owned(S);
5302 template<typename Derived>
5304 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
5305 return SemaRef.Owned(S);
5308 template<typename Derived>
5310 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
5311 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
5312 if (Result.isInvalid())
5315 // FIXME: We always rebuild the return statement because there is no way
5316 // to tell whether the return type of the function has changed.
5317 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
5320 template<typename Derived>
5322 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
5323 bool DeclChanged = false;
5324 SmallVector<Decl *, 4> Decls;
5325 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5327 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5332 if (Transformed != *D)
5335 Decls.push_back(Transformed);
5338 if (!getDerived().AlwaysRebuild() && !DeclChanged)
5339 return SemaRef.Owned(S);
5341 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
5342 S->getStartLoc(), S->getEndLoc());
5345 template<typename Derived>
5347 TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
5349 ASTOwningVector<Expr*> Constraints(getSema());
5350 ASTOwningVector<Expr*> Exprs(getSema());
5351 SmallVector<IdentifierInfo *, 4> Names;
5353 ExprResult AsmString;
5354 ASTOwningVector<Expr*> Clobbers(getSema());
5356 bool ExprsChanged = false;
5358 // Go through the outputs.
5359 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5360 Names.push_back(S->getOutputIdentifier(I));
5362 // No need to transform the constraint literal.
5363 Constraints.push_back(S->getOutputConstraintLiteral(I));
5365 // Transform the output expr.
5366 Expr *OutputExpr = S->getOutputExpr(I);
5367 ExprResult Result = getDerived().TransformExpr(OutputExpr);
5368 if (Result.isInvalid())
5371 ExprsChanged |= Result.get() != OutputExpr;
5373 Exprs.push_back(Result.get());
5376 // Go through the inputs.
5377 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5378 Names.push_back(S->getInputIdentifier(I));
5380 // No need to transform the constraint literal.
5381 Constraints.push_back(S->getInputConstraintLiteral(I));
5383 // Transform the input expr.
5384 Expr *InputExpr = S->getInputExpr(I);
5385 ExprResult Result = getDerived().TransformExpr(InputExpr);
5386 if (Result.isInvalid())
5389 ExprsChanged |= Result.get() != InputExpr;
5391 Exprs.push_back(Result.get());
5394 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
5395 return SemaRef.Owned(S);
5397 // Go through the clobbers.
5398 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
5399 Clobbers.push_back(S->getClobber(I));
5401 // No need to transform the asm string literal.
5402 AsmString = SemaRef.Owned(S->getAsmString());
5404 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5410 move_arg(Constraints),
5419 template<typename Derived>
5421 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
5422 // Transform the body of the @try.
5423 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
5424 if (TryBody.isInvalid())
5427 // Transform the @catch statements (if present).
5428 bool AnyCatchChanged = false;
5429 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
5430 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
5431 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
5432 if (Catch.isInvalid())
5434 if (Catch.get() != S->getCatchStmt(I))
5435 AnyCatchChanged = true;
5436 CatchStmts.push_back(Catch.release());
5439 // Transform the @finally statement (if present).
5441 if (S->getFinallyStmt()) {
5442 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5443 if (Finally.isInvalid())
5447 // If nothing changed, just retain this statement.
5448 if (!getDerived().AlwaysRebuild() &&
5449 TryBody.get() == S->getTryBody() &&
5451 Finally.get() == S->getFinallyStmt())
5452 return SemaRef.Owned(S);
5454 // Build a new statement.
5455 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5456 move_arg(CatchStmts), Finally.get());
5459 template<typename Derived>
5461 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5462 // Transform the @catch parameter, if there is one.
5464 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5465 TypeSourceInfo *TSInfo = 0;
5466 if (FromVar->getTypeSourceInfo()) {
5467 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5474 T = TSInfo->getType();
5476 T = getDerived().TransformType(FromVar->getType());
5481 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5486 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5487 if (Body.isInvalid())
5490 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5495 template<typename Derived>
5497 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
5498 // Transform the body.
5499 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
5500 if (Body.isInvalid())
5503 // If nothing changed, just retain this statement.
5504 if (!getDerived().AlwaysRebuild() &&
5505 Body.get() == S->getFinallyBody())
5506 return SemaRef.Owned(S);
5508 // Build a new statement.
5509 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
5513 template<typename Derived>
5515 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
5517 if (S->getThrowExpr()) {
5518 Operand = getDerived().TransformExpr(S->getThrowExpr());
5519 if (Operand.isInvalid())
5523 if (!getDerived().AlwaysRebuild() &&
5524 Operand.get() == S->getThrowExpr())
5525 return getSema().Owned(S);
5527 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
5530 template<typename Derived>
5532 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
5533 ObjCAtSynchronizedStmt *S) {
5534 // Transform the object we are locking.
5535 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
5536 if (Object.isInvalid())
5539 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5541 if (Object.isInvalid())
5544 // Transform the body.
5545 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
5546 if (Body.isInvalid())
5549 // If nothing change, just retain the current statement.
5550 if (!getDerived().AlwaysRebuild() &&
5551 Object.get() == S->getSynchExpr() &&
5552 Body.get() == S->getSynchBody())
5553 return SemaRef.Owned(S);
5555 // Build a new statement.
5556 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
5557 Object.get(), Body.get());
5560 template<typename Derived>
5562 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5563 ObjCAutoreleasePoolStmt *S) {
5564 // Transform the body.
5565 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5566 if (Body.isInvalid())
5569 // If nothing changed, just retain this statement.
5570 if (!getDerived().AlwaysRebuild() &&
5571 Body.get() == S->getSubStmt())
5572 return SemaRef.Owned(S);
5574 // Build a new statement.
5575 return getDerived().RebuildObjCAutoreleasePoolStmt(
5576 S->getAtLoc(), Body.get());
5579 template<typename Derived>
5581 TreeTransform<Derived>::TransformObjCForCollectionStmt(
5582 ObjCForCollectionStmt *S) {
5583 // Transform the element statement.
5584 StmtResult Element = getDerived().TransformStmt(S->getElement());
5585 if (Element.isInvalid())
5588 // Transform the collection expression.
5589 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5590 if (Collection.isInvalid())
5592 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5594 if (Collection.isInvalid())
5597 // Transform the body.
5598 StmtResult Body = getDerived().TransformStmt(S->getBody());
5599 if (Body.isInvalid())
5602 // If nothing changed, just retain this statement.
5603 if (!getDerived().AlwaysRebuild() &&
5604 Element.get() == S->getElement() &&
5605 Collection.get() == S->getCollection() &&
5606 Body.get() == S->getBody())
5607 return SemaRef.Owned(S);
5609 // Build a new statement.
5610 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5611 /*FIXME:*/S->getForLoc(),
5619 template<typename Derived>
5621 TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5622 // Transform the exception declaration, if any.
5624 if (S->getExceptionDecl()) {
5625 VarDecl *ExceptionDecl = S->getExceptionDecl();
5626 TypeSourceInfo *T = getDerived().TransformType(
5627 ExceptionDecl->getTypeSourceInfo());
5631 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
5632 ExceptionDecl->getInnerLocStart(),
5633 ExceptionDecl->getLocation(),
5634 ExceptionDecl->getIdentifier());
5635 if (!Var || Var->isInvalidDecl())
5639 // Transform the actual exception handler.
5640 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5641 if (Handler.isInvalid())
5644 if (!getDerived().AlwaysRebuild() &&
5646 Handler.get() == S->getHandlerBlock())
5647 return SemaRef.Owned(S);
5649 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5654 template<typename Derived>
5656 TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5657 // Transform the try block itself.
5659 = getDerived().TransformCompoundStmt(S->getTryBlock());
5660 if (TryBlock.isInvalid())
5663 // Transform the handlers.
5664 bool HandlerChanged = false;
5665 ASTOwningVector<Stmt*> Handlers(SemaRef);
5666 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
5668 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5669 if (Handler.isInvalid())
5672 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5673 Handlers.push_back(Handler.takeAs<Stmt>());
5676 if (!getDerived().AlwaysRebuild() &&
5677 TryBlock.get() == S->getTryBlock() &&
5679 return SemaRef.Owned(S);
5681 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
5682 move_arg(Handlers));
5685 template<typename Derived>
5687 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5688 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5689 if (Range.isInvalid())
5692 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5693 if (BeginEnd.isInvalid())
5696 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5697 if (Cond.isInvalid())
5700 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5701 if (Inc.isInvalid())
5704 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5705 if (LoopVar.isInvalid())
5708 StmtResult NewStmt = S;
5709 if (getDerived().AlwaysRebuild() ||
5710 Range.get() != S->getRangeStmt() ||
5711 BeginEnd.get() != S->getBeginEndStmt() ||
5712 Cond.get() != S->getCond() ||
5713 Inc.get() != S->getInc() ||
5714 LoopVar.get() != S->getLoopVarStmt())
5715 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5716 S->getColonLoc(), Range.get(),
5717 BeginEnd.get(), Cond.get(),
5718 Inc.get(), LoopVar.get(),
5721 StmtResult Body = getDerived().TransformStmt(S->getBody());
5722 if (Body.isInvalid())
5725 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5726 // it now so we have a new statement to attach the body to.
5727 if (Body.get() != S->getBody() && NewStmt.get() == S)
5728 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5729 S->getColonLoc(), Range.get(),
5730 BeginEnd.get(), Cond.get(),
5731 Inc.get(), LoopVar.get(),
5734 if (NewStmt.get() == S)
5735 return SemaRef.Owned(S);
5737 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5740 template<typename Derived>
5742 TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5743 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5744 if(TryBlock.isInvalid()) return StmtError();
5746 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5747 if(!getDerived().AlwaysRebuild() &&
5748 TryBlock.get() == S->getTryBlock() &&
5749 Handler.get() == S->getHandler())
5750 return SemaRef.Owned(S);
5752 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5758 template<typename Derived>
5760 TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5761 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5762 if(Block.isInvalid()) return StmtError();
5764 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5768 template<typename Derived>
5770 TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5771 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5772 if(FilterExpr.isInvalid()) return StmtError();
5774 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5775 if(Block.isInvalid()) return StmtError();
5777 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5782 template<typename Derived>
5784 TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5785 if(isa<SEHFinallyStmt>(Handler))
5786 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5788 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5791 //===----------------------------------------------------------------------===//
5792 // Expression transformation
5793 //===----------------------------------------------------------------------===//
5794 template<typename Derived>
5796 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
5797 return SemaRef.Owned(E);
5800 template<typename Derived>
5802 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
5803 NestedNameSpecifierLoc QualifierLoc;
5804 if (E->getQualifierLoc()) {
5806 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5812 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5817 DeclarationNameInfo NameInfo = E->getNameInfo();
5818 if (NameInfo.getName()) {
5819 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5820 if (!NameInfo.getName())
5824 if (!getDerived().AlwaysRebuild() &&
5825 QualifierLoc == E->getQualifierLoc() &&
5826 ND == E->getDecl() &&
5827 NameInfo.getName() == E->getDecl()->getDeclName() &&
5828 !E->hasExplicitTemplateArgs()) {
5830 // Mark it referenced in the new context regardless.
5831 // FIXME: this is a bit instantiation-specific.
5832 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5834 return SemaRef.Owned(E);
5837 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
5838 if (E->hasExplicitTemplateArgs()) {
5839 TemplateArgs = &TransArgs;
5840 TransArgs.setLAngleLoc(E->getLAngleLoc());
5841 TransArgs.setRAngleLoc(E->getRAngleLoc());
5842 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5843 E->getNumTemplateArgs(),
5848 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5852 template<typename Derived>
5854 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
5855 return SemaRef.Owned(E);
5858 template<typename Derived>
5860 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
5861 return SemaRef.Owned(E);
5864 template<typename Derived>
5866 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
5867 return SemaRef.Owned(E);
5870 template<typename Derived>
5872 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
5873 return SemaRef.Owned(E);
5876 template<typename Derived>
5878 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
5879 return SemaRef.Owned(E);
5882 template<typename Derived>
5884 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5885 ExprResult ControllingExpr =
5886 getDerived().TransformExpr(E->getControllingExpr());
5887 if (ControllingExpr.isInvalid())
5890 SmallVector<Expr *, 4> AssocExprs;
5891 SmallVector<TypeSourceInfo *, 4> AssocTypes;
5892 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5893 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5895 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5898 AssocTypes.push_back(AssocType);
5900 AssocTypes.push_back(0);
5903 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5904 if (AssocExpr.isInvalid())
5906 AssocExprs.push_back(AssocExpr.release());
5909 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5912 ControllingExpr.release(),
5918 template<typename Derived>
5920 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
5921 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5922 if (SubExpr.isInvalid())
5925 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
5926 return SemaRef.Owned(E);
5928 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
5932 template<typename Derived>
5934 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
5935 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5936 if (SubExpr.isInvalid())
5939 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
5940 return SemaRef.Owned(E);
5942 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5947 template<typename Derived>
5949 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5950 // Transform the type.
5951 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5955 // Transform all of the components into components similar to what the
5957 // FIXME: It would be slightly more efficient in the non-dependent case to
5958 // just map FieldDecls, rather than requiring the rebuilder to look for
5959 // the fields again. However, __builtin_offsetof is rare enough in
5960 // template code that we don't care.
5961 bool ExprChanged = false;
5962 typedef Sema::OffsetOfComponent Component;
5963 typedef OffsetOfExpr::OffsetOfNode Node;
5964 SmallVector<Component, 4> Components;
5965 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5966 const Node &ON = E->getComponent(I);
5968 Comp.isBrackets = true;
5969 Comp.LocStart = ON.getSourceRange().getBegin();
5970 Comp.LocEnd = ON.getSourceRange().getEnd();
5971 switch (ON.getKind()) {
5973 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
5974 ExprResult Index = getDerived().TransformExpr(FromIndex);
5975 if (Index.isInvalid())
5978 ExprChanged = ExprChanged || Index.get() != FromIndex;
5979 Comp.isBrackets = true;
5980 Comp.U.E = Index.get();
5985 case Node::Identifier:
5986 Comp.isBrackets = false;
5987 Comp.U.IdentInfo = ON.getFieldName();
5988 if (!Comp.U.IdentInfo)
5994 // Will be recomputed during the rebuild.
5998 Components.push_back(Comp);
6001 // If nothing changed, retain the existing expression.
6002 if (!getDerived().AlwaysRebuild() &&
6003 Type == E->getTypeSourceInfo() &&
6005 return SemaRef.Owned(E);
6007 // Build a new offsetof expression.
6008 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6009 Components.data(), Components.size(),
6013 template<typename Derived>
6015 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6016 assert(getDerived().AlreadyTransformed(E->getType()) &&
6017 "opaque value expression requires transformation");
6018 return SemaRef.Owned(E);
6021 template<typename Derived>
6023 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6024 UnaryExprOrTypeTraitExpr *E) {
6025 if (E->isArgumentType()) {
6026 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
6028 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6032 if (!getDerived().AlwaysRebuild() && OldT == NewT)
6033 return SemaRef.Owned(E);
6035 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6037 E->getSourceRange());
6042 // C++0x [expr.sizeof]p1:
6043 // The operand is either an expression, which is an unevaluated operand
6045 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6047 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6048 if (SubExpr.isInvalid())
6051 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6052 return SemaRef.Owned(E);
6055 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6056 E->getOperatorLoc(),
6058 E->getSourceRange());
6061 template<typename Derived>
6063 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
6064 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6065 if (LHS.isInvalid())
6068 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6069 if (RHS.isInvalid())
6073 if (!getDerived().AlwaysRebuild() &&
6074 LHS.get() == E->getLHS() &&
6075 RHS.get() == E->getRHS())
6076 return SemaRef.Owned(E);
6078 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
6079 /*FIXME:*/E->getLHS()->getLocStart(),
6081 E->getRBracketLoc());
6084 template<typename Derived>
6086 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6087 // Transform the callee.
6088 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6089 if (Callee.isInvalid())
6092 // Transform arguments.
6093 bool ArgChanged = false;
6094 ASTOwningVector<Expr*> Args(SemaRef);
6095 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6099 if (!getDerived().AlwaysRebuild() &&
6100 Callee.get() == E->getCallee() &&
6102 return SemaRef.Owned(E);
6104 // FIXME: Wrong source location information for the '('.
6105 SourceLocation FakeLParenLoc
6106 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6107 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6112 template<typename Derived>
6114 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
6115 ExprResult Base = getDerived().TransformExpr(E->getBase());
6116 if (Base.isInvalid())
6119 NestedNameSpecifierLoc QualifierLoc;
6120 if (E->hasQualifier()) {
6122 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6129 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6130 E->getMemberDecl()));
6134 NamedDecl *FoundDecl = E->getFoundDecl();
6135 if (FoundDecl == E->getMemberDecl()) {
6138 FoundDecl = cast_or_null<NamedDecl>(
6139 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6144 if (!getDerived().AlwaysRebuild() &&
6145 Base.get() == E->getBase() &&
6146 QualifierLoc == E->getQualifierLoc() &&
6147 Member == E->getMemberDecl() &&
6148 FoundDecl == E->getFoundDecl() &&
6149 !E->hasExplicitTemplateArgs()) {
6151 // Mark it referenced in the new context regardless.
6152 // FIXME: this is a bit instantiation-specific.
6153 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
6154 return SemaRef.Owned(E);
6157 TemplateArgumentListInfo TransArgs;
6158 if (E->hasExplicitTemplateArgs()) {
6159 TransArgs.setLAngleLoc(E->getLAngleLoc());
6160 TransArgs.setRAngleLoc(E->getRAngleLoc());
6161 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6162 E->getNumTemplateArgs(),
6167 // FIXME: Bogus source location for the operator
6168 SourceLocation FakeOperatorLoc
6169 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6171 // FIXME: to do this check properly, we will need to preserve the
6172 // first-qualifier-in-scope here, just in case we had a dependent
6173 // base (and therefore couldn't do the check) and a
6174 // nested-name-qualifier (and therefore could do the lookup).
6175 NamedDecl *FirstQualifierInScope = 0;
6177 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6180 E->getMemberNameInfo(),
6183 (E->hasExplicitTemplateArgs()
6185 FirstQualifierInScope);
6188 template<typename Derived>
6190 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
6191 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6192 if (LHS.isInvalid())
6195 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6196 if (RHS.isInvalid())
6199 if (!getDerived().AlwaysRebuild() &&
6200 LHS.get() == E->getLHS() &&
6201 RHS.get() == E->getRHS())
6202 return SemaRef.Owned(E);
6204 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
6205 LHS.get(), RHS.get());
6208 template<typename Derived>
6210 TreeTransform<Derived>::TransformCompoundAssignOperator(
6211 CompoundAssignOperator *E) {
6212 return getDerived().TransformBinaryOperator(E);
6215 template<typename Derived>
6216 ExprResult TreeTransform<Derived>::
6217 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6218 // Just rebuild the common and RHS expressions and see whether we
6221 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6222 if (commonExpr.isInvalid())
6225 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6226 if (rhs.isInvalid())
6229 if (!getDerived().AlwaysRebuild() &&
6230 commonExpr.get() == e->getCommon() &&
6231 rhs.get() == e->getFalseExpr())
6232 return SemaRef.Owned(e);
6234 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6235 e->getQuestionLoc(),
6241 template<typename Derived>
6243 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
6244 ExprResult Cond = getDerived().TransformExpr(E->getCond());
6245 if (Cond.isInvalid())
6248 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6249 if (LHS.isInvalid())
6252 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6253 if (RHS.isInvalid())
6256 if (!getDerived().AlwaysRebuild() &&
6257 Cond.get() == E->getCond() &&
6258 LHS.get() == E->getLHS() &&
6259 RHS.get() == E->getRHS())
6260 return SemaRef.Owned(E);
6262 return getDerived().RebuildConditionalOperator(Cond.get(),
6263 E->getQuestionLoc(),
6269 template<typename Derived>
6271 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6272 // Implicit casts are eliminated during transformation, since they
6273 // will be recomputed by semantic analysis after transformation.
6274 return getDerived().TransformExpr(E->getSubExprAsWritten());
6277 template<typename Derived>
6279 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6280 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6285 = getDerived().TransformExpr(E->getSubExprAsWritten());
6286 if (SubExpr.isInvalid())
6289 if (!getDerived().AlwaysRebuild() &&
6290 Type == E->getTypeInfoAsWritten() &&
6291 SubExpr.get() == E->getSubExpr())
6292 return SemaRef.Owned(E);
6294 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6300 template<typename Derived>
6302 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
6303 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6304 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6308 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6309 if (Init.isInvalid())
6312 if (!getDerived().AlwaysRebuild() &&
6314 Init.get() == E->getInitializer())
6315 return SemaRef.Owned(E);
6317 // Note: the expression type doesn't necessarily match the
6318 // type-as-written, but that's okay, because it should always be
6319 // derivable from the initializer.
6321 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6322 /*FIXME:*/E->getInitializer()->getLocEnd(),
6326 template<typename Derived>
6328 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
6329 ExprResult Base = getDerived().TransformExpr(E->getBase());
6330 if (Base.isInvalid())
6333 if (!getDerived().AlwaysRebuild() &&
6334 Base.get() == E->getBase())
6335 return SemaRef.Owned(E);
6337 // FIXME: Bad source location
6338 SourceLocation FakeOperatorLoc
6339 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
6340 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6341 E->getAccessorLoc(),
6345 template<typename Derived>
6347 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6348 bool InitChanged = false;
6350 ASTOwningVector<Expr*, 4> Inits(SemaRef);
6351 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6352 Inits, &InitChanged))
6355 if (!getDerived().AlwaysRebuild() && !InitChanged)
6356 return SemaRef.Owned(E);
6358 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
6359 E->getRBraceLoc(), E->getType());
6362 template<typename Derived>
6364 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
6367 // transform the initializer value
6368 ExprResult Init = getDerived().TransformExpr(E->getInit());
6369 if (Init.isInvalid())
6372 // transform the designators.
6373 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
6374 bool ExprChanged = false;
6375 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6376 DEnd = E->designators_end();
6378 if (D->isFieldDesignator()) {
6379 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6385 if (D->isArrayDesignator()) {
6386 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
6387 if (Index.isInvalid())
6390 Desig.AddDesignator(Designator::getArray(Index.get(),
6391 D->getLBracketLoc()));
6393 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6394 ArrayExprs.push_back(Index.release());
6398 assert(D->isArrayRangeDesignator() && "New kind of designator?");
6400 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6401 if (Start.isInvalid())
6404 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
6405 if (End.isInvalid())
6408 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
6410 D->getLBracketLoc(),
6411 D->getEllipsisLoc()));
6413 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6414 End.get() != E->getArrayRangeEnd(*D);
6416 ArrayExprs.push_back(Start.release());
6417 ArrayExprs.push_back(End.release());
6420 if (!getDerived().AlwaysRebuild() &&
6421 Init.get() == E->getInit() &&
6423 return SemaRef.Owned(E);
6425 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6426 E->getEqualOrColonLoc(),
6427 E->usesGNUSyntax(), Init.get());
6430 template<typename Derived>
6432 TreeTransform<Derived>::TransformImplicitValueInitExpr(
6433 ImplicitValueInitExpr *E) {
6434 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
6436 // FIXME: Will we ever have proper type location here? Will we actually
6437 // need to transform the type?
6438 QualType T = getDerived().TransformType(E->getType());
6442 if (!getDerived().AlwaysRebuild() &&
6444 return SemaRef.Owned(E);
6446 return getDerived().RebuildImplicitValueInitExpr(T);
6449 template<typename Derived>
6451 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
6452 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6456 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6457 if (SubExpr.isInvalid())
6460 if (!getDerived().AlwaysRebuild() &&
6461 TInfo == E->getWrittenTypeInfo() &&
6462 SubExpr.get() == E->getSubExpr())
6463 return SemaRef.Owned(E);
6465 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
6466 TInfo, E->getRParenLoc());
6469 template<typename Derived>
6471 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
6472 bool ArgumentChanged = false;
6473 ASTOwningVector<Expr*, 4> Inits(SemaRef);
6474 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6478 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6483 /// \brief Transform an address-of-label expression.
6485 /// By default, the transformation of an address-of-label expression always
6486 /// rebuilds the expression, so that the label identifier can be resolved to
6487 /// the corresponding label statement by semantic analysis.
6488 template<typename Derived>
6490 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
6491 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6496 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
6497 cast<LabelDecl>(LD));
6500 template<typename Derived>
6502 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
6504 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6505 if (SubStmt.isInvalid())
6508 if (!getDerived().AlwaysRebuild() &&
6509 SubStmt.get() == E->getSubStmt())
6510 return SemaRef.Owned(E);
6512 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
6517 template<typename Derived>
6519 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
6520 ExprResult Cond = getDerived().TransformExpr(E->getCond());
6521 if (Cond.isInvalid())
6524 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6525 if (LHS.isInvalid())
6528 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6529 if (RHS.isInvalid())
6532 if (!getDerived().AlwaysRebuild() &&
6533 Cond.get() == E->getCond() &&
6534 LHS.get() == E->getLHS() &&
6535 RHS.get() == E->getRHS())
6536 return SemaRef.Owned(E);
6538 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
6539 Cond.get(), LHS.get(), RHS.get(),
6543 template<typename Derived>
6545 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
6546 return SemaRef.Owned(E);
6549 template<typename Derived>
6551 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
6552 switch (E->getOperator()) {
6556 case OO_Array_Delete:
6557 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
6561 // This is a call to an object's operator().
6562 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6564 // Transform the object itself.
6565 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
6566 if (Object.isInvalid())
6569 // FIXME: Poor location information
6570 SourceLocation FakeLParenLoc
6571 = SemaRef.PP.getLocForEndOfToken(
6572 static_cast<Expr *>(Object.get())->getLocEnd());
6574 // Transform the call arguments.
6575 ASTOwningVector<Expr*> Args(SemaRef);
6576 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6580 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
6585 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6587 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6588 #include "clang/Basic/OperatorKinds.def"
6593 case OO_Conditional:
6594 llvm_unreachable("conditional operator is not actually overloadable");
6598 case NUM_OVERLOADED_OPERATORS:
6599 llvm_unreachable("not an overloaded operator?");
6603 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6604 if (Callee.isInvalid())
6607 ExprResult First = getDerived().TransformExpr(E->getArg(0));
6608 if (First.isInvalid())
6612 if (E->getNumArgs() == 2) {
6613 Second = getDerived().TransformExpr(E->getArg(1));
6614 if (Second.isInvalid())
6618 if (!getDerived().AlwaysRebuild() &&
6619 Callee.get() == E->getCallee() &&
6620 First.get() == E->getArg(0) &&
6621 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
6622 return SemaRef.Owned(E);
6624 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6625 E->getOperatorLoc(),
6631 template<typename Derived>
6633 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6634 return getDerived().TransformCallExpr(E);
6637 template<typename Derived>
6639 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6640 // Transform the callee.
6641 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6642 if (Callee.isInvalid())
6645 // Transform exec config.
6646 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6650 // Transform arguments.
6651 bool ArgChanged = false;
6652 ASTOwningVector<Expr*> Args(SemaRef);
6653 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6657 if (!getDerived().AlwaysRebuild() &&
6658 Callee.get() == E->getCallee() &&
6660 return SemaRef.Owned(E);
6662 // FIXME: Wrong source location information for the '('.
6663 SourceLocation FakeLParenLoc
6664 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6665 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6667 E->getRParenLoc(), EC.get());
6670 template<typename Derived>
6672 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
6673 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6678 = getDerived().TransformExpr(E->getSubExprAsWritten());
6679 if (SubExpr.isInvalid())
6682 if (!getDerived().AlwaysRebuild() &&
6683 Type == E->getTypeInfoAsWritten() &&
6684 SubExpr.get() == E->getSubExpr())
6685 return SemaRef.Owned(E);
6687 // FIXME: Poor source location information here.
6688 SourceLocation FakeLAngleLoc
6689 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6690 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6691 SourceLocation FakeRParenLoc
6692 = SemaRef.PP.getLocForEndOfToken(
6693 E->getSubExpr()->getSourceRange().getEnd());
6694 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
6704 template<typename Derived>
6706 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6707 return getDerived().TransformCXXNamedCastExpr(E);
6710 template<typename Derived>
6712 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6713 return getDerived().TransformCXXNamedCastExpr(E);
6716 template<typename Derived>
6718 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
6719 CXXReinterpretCastExpr *E) {
6720 return getDerived().TransformCXXNamedCastExpr(E);
6723 template<typename Derived>
6725 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6726 return getDerived().TransformCXXNamedCastExpr(E);
6729 template<typename Derived>
6731 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
6732 CXXFunctionalCastExpr *E) {
6733 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6738 = getDerived().TransformExpr(E->getSubExprAsWritten());
6739 if (SubExpr.isInvalid())
6742 if (!getDerived().AlwaysRebuild() &&
6743 Type == E->getTypeInfoAsWritten() &&
6744 SubExpr.get() == E->getSubExpr())
6745 return SemaRef.Owned(E);
6747 return getDerived().RebuildCXXFunctionalCastExpr(Type,
6748 /*FIXME:*/E->getSubExpr()->getLocStart(),
6753 template<typename Derived>
6755 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
6756 if (E->isTypeOperand()) {
6757 TypeSourceInfo *TInfo
6758 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6762 if (!getDerived().AlwaysRebuild() &&
6763 TInfo == E->getTypeOperandSourceInfo())
6764 return SemaRef.Owned(E);
6766 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6772 // We don't know whether the expression is potentially evaluated until
6773 // after we perform semantic analysis, so the expression is potentially
6774 // potentially evaluated.
6775 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6776 Sema::PotentiallyPotentiallyEvaluated);
6778 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6779 if (SubExpr.isInvalid())
6782 if (!getDerived().AlwaysRebuild() &&
6783 SubExpr.get() == E->getExprOperand())
6784 return SemaRef.Owned(E);
6786 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6792 template<typename Derived>
6794 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6795 if (E->isTypeOperand()) {
6796 TypeSourceInfo *TInfo
6797 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6801 if (!getDerived().AlwaysRebuild() &&
6802 TInfo == E->getTypeOperandSourceInfo())
6803 return SemaRef.Owned(E);
6805 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6811 // We don't know whether the expression is potentially evaluated until
6812 // after we perform semantic analysis, so the expression is potentially
6813 // potentially evaluated.
6814 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6816 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6817 if (SubExpr.isInvalid())
6820 if (!getDerived().AlwaysRebuild() &&
6821 SubExpr.get() == E->getExprOperand())
6822 return SemaRef.Owned(E);
6824 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6830 template<typename Derived>
6832 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
6833 return SemaRef.Owned(E);
6836 template<typename Derived>
6838 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
6839 CXXNullPtrLiteralExpr *E) {
6840 return SemaRef.Owned(E);
6843 template<typename Derived>
6845 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
6846 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6848 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6849 T = MD->getThisType(getSema().Context);
6851 T = getSema().Context.getPointerType(
6852 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
6854 if (!getDerived().AlwaysRebuild() && T == E->getType())
6855 return SemaRef.Owned(E);
6857 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
6860 template<typename Derived>
6862 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
6863 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6864 if (SubExpr.isInvalid())
6867 if (!getDerived().AlwaysRebuild() &&
6868 SubExpr.get() == E->getSubExpr())
6869 return SemaRef.Owned(E);
6871 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6872 E->isThrownVariableInScope());
6875 template<typename Derived>
6877 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
6879 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6884 if (!getDerived().AlwaysRebuild() &&
6885 Param == E->getParam())
6886 return SemaRef.Owned(E);
6888 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
6891 template<typename Derived>
6893 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6894 CXXScalarValueInitExpr *E) {
6895 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6899 if (!getDerived().AlwaysRebuild() &&
6900 T == E->getTypeSourceInfo())
6901 return SemaRef.Owned(E);
6903 return getDerived().RebuildCXXScalarValueInitExpr(T,
6904 /*FIXME:*/T->getTypeLoc().getEndLoc(),
6908 template<typename Derived>
6910 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
6911 // Transform the type that we're allocating
6912 TypeSourceInfo *AllocTypeInfo
6913 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6917 // Transform the size of the array we're allocating (if any).
6918 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
6919 if (ArraySize.isInvalid())
6922 // Transform the placement arguments (if any).
6923 bool ArgumentChanged = false;
6924 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
6925 if (getDerived().TransformExprs(E->getPlacementArgs(),
6926 E->getNumPlacementArgs(), true,
6927 PlacementArgs, &ArgumentChanged))
6930 // transform the constructor arguments (if any).
6931 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
6932 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6933 ConstructorArgs, &ArgumentChanged))
6936 // Transform constructor, new operator, and delete operator.
6937 CXXConstructorDecl *Constructor = 0;
6938 if (E->getConstructor()) {
6939 Constructor = cast_or_null<CXXConstructorDecl>(
6940 getDerived().TransformDecl(E->getLocStart(),
6941 E->getConstructor()));
6946 FunctionDecl *OperatorNew = 0;
6947 if (E->getOperatorNew()) {
6948 OperatorNew = cast_or_null<FunctionDecl>(
6949 getDerived().TransformDecl(E->getLocStart(),
6950 E->getOperatorNew()));
6955 FunctionDecl *OperatorDelete = 0;
6956 if (E->getOperatorDelete()) {
6957 OperatorDelete = cast_or_null<FunctionDecl>(
6958 getDerived().TransformDecl(E->getLocStart(),
6959 E->getOperatorDelete()));
6960 if (!OperatorDelete)
6964 if (!getDerived().AlwaysRebuild() &&
6965 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
6966 ArraySize.get() == E->getArraySize() &&
6967 Constructor == E->getConstructor() &&
6968 OperatorNew == E->getOperatorNew() &&
6969 OperatorDelete == E->getOperatorDelete() &&
6971 // Mark any declarations we need as referenced.
6972 // FIXME: instantiation-specific.
6974 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6976 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6978 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
6980 if (E->isArray() && Constructor &&
6981 !E->getAllocatedType()->isDependentType()) {
6982 QualType ElementType
6983 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6984 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6985 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6986 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
6987 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
6992 return SemaRef.Owned(E);
6995 QualType AllocType = AllocTypeInfo->getType();
6996 if (!ArraySize.get()) {
6997 // If no array size was specified, but the new expression was
6998 // instantiated with an array type (e.g., "new T" where T is
6999 // instantiated with "int[4]"), extract the outer bound from the
7000 // array type as our array size. We do this with constant and
7001 // dependently-sized array types.
7002 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7005 } else if (const ConstantArrayType *ConsArrayT
7006 = dyn_cast<ConstantArrayType>(ArrayT)) {
7008 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7009 ConsArrayT->getSize(),
7010 SemaRef.Context.getSizeType(),
7011 /*FIXME:*/E->getLocStart()));
7012 AllocType = ConsArrayT->getElementType();
7013 } else if (const DependentSizedArrayType *DepArrayT
7014 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7015 if (DepArrayT->getSizeExpr()) {
7016 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
7017 AllocType = DepArrayT->getElementType();
7022 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7024 /*FIXME:*/E->getLocStart(),
7025 move_arg(PlacementArgs),
7026 /*FIXME:*/E->getLocStart(),
7027 E->getTypeIdParens(),
7031 /*FIXME:*/E->hasInitializer()
7034 move_arg(ConstructorArgs),
7035 /*FIXME:*/E->hasInitializer()
7037 : SourceLocation());
7040 template<typename Derived>
7042 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
7043 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
7044 if (Operand.isInvalid())
7047 // Transform the delete operator, if known.
7048 FunctionDecl *OperatorDelete = 0;
7049 if (E->getOperatorDelete()) {
7050 OperatorDelete = cast_or_null<FunctionDecl>(
7051 getDerived().TransformDecl(E->getLocStart(),
7052 E->getOperatorDelete()));
7053 if (!OperatorDelete)
7057 if (!getDerived().AlwaysRebuild() &&
7058 Operand.get() == E->getArgument() &&
7059 OperatorDelete == E->getOperatorDelete()) {
7060 // Mark any declarations we need as referenced.
7061 // FIXME: instantiation-specific.
7063 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
7065 if (!E->getArgument()->isTypeDependent()) {
7066 QualType Destroyed = SemaRef.Context.getBaseElementType(
7067 E->getDestroyedType());
7068 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7069 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7070 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7071 SemaRef.LookupDestructor(Record));
7075 return SemaRef.Owned(E);
7078 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7079 E->isGlobalDelete(),
7084 template<typename Derived>
7086 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
7087 CXXPseudoDestructorExpr *E) {
7088 ExprResult Base = getDerived().TransformExpr(E->getBase());
7089 if (Base.isInvalid())
7092 ParsedType ObjectTypePtr;
7093 bool MayBePseudoDestructor = false;
7094 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7095 E->getOperatorLoc(),
7096 E->isArrow()? tok::arrow : tok::period,
7098 MayBePseudoDestructor);
7099 if (Base.isInvalid())
7102 QualType ObjectType = ObjectTypePtr.get();
7103 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7106 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7111 SS.Adopt(QualifierLoc);
7113 PseudoDestructorTypeStorage Destroyed;
7114 if (E->getDestroyedTypeInfo()) {
7115 TypeSourceInfo *DestroyedTypeInfo
7116 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7118 if (!DestroyedTypeInfo)
7120 Destroyed = DestroyedTypeInfo;
7121 } else if (ObjectType->isDependentType()) {
7122 // We aren't likely to be able to resolve the identifier down to a type
7123 // now anyway, so just retain the identifier.
7124 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7125 E->getDestroyedTypeLoc());
7127 // Look for a destructor known with the given name.
7128 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7129 *E->getDestroyedTypeIdentifier(),
7130 E->getDestroyedTypeLoc(),
7138 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7139 E->getDestroyedTypeLoc());
7142 TypeSourceInfo *ScopeTypeInfo = 0;
7143 if (E->getScopeTypeInfo()) {
7144 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
7149 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7150 E->getOperatorLoc(),
7154 E->getColonColonLoc(),
7159 template<typename Derived>
7161 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
7162 UnresolvedLookupExpr *Old) {
7163 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7164 Sema::LookupOrdinaryName);
7166 // Transform all the decls.
7167 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7168 E = Old->decls_end(); I != E; ++I) {
7169 NamedDecl *InstD = static_cast<NamedDecl*>(
7170 getDerived().TransformDecl(Old->getNameLoc(),
7173 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7174 // This can happen because of dependent hiding.
7175 if (isa<UsingShadowDecl>(*I))
7181 // Expand using declarations.
7182 if (isa<UsingDecl>(InstD)) {
7183 UsingDecl *UD = cast<UsingDecl>(InstD);
7184 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7185 E = UD->shadow_end(); I != E; ++I)
7193 // Resolve a kind, but don't do any further analysis. If it's
7194 // ambiguous, the callee needs to deal with it.
7197 // Rebuild the nested-name qualifier, if present.
7199 if (Old->getQualifierLoc()) {
7200 NestedNameSpecifierLoc QualifierLoc
7201 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7205 SS.Adopt(QualifierLoc);
7208 if (Old->getNamingClass()) {
7209 CXXRecordDecl *NamingClass
7210 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7212 Old->getNamingClass()));
7216 R.setNamingClass(NamingClass);
7219 // If we have no template arguments, it's a normal declaration name.
7220 if (!Old->hasExplicitTemplateArgs())
7221 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7223 // If we have template arguments, rebuild them, then rebuild the
7224 // templateid expression.
7225 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
7226 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7227 Old->getNumTemplateArgs(),
7231 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7235 template<typename Derived>
7237 TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
7238 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7242 if (!getDerived().AlwaysRebuild() &&
7243 T == E->getQueriedTypeSourceInfo())
7244 return SemaRef.Owned(E);
7246 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7252 template<typename Derived>
7254 TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7255 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7259 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7263 if (!getDerived().AlwaysRebuild() &&
7264 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7265 return SemaRef.Owned(E);
7267 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7273 template<typename Derived>
7275 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7276 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7280 if (!getDerived().AlwaysRebuild() &&
7281 T == E->getQueriedTypeSourceInfo())
7282 return SemaRef.Owned(E);
7286 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7287 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7288 if (SubExpr.isInvalid())
7291 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7292 return SemaRef.Owned(E);
7295 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7302 template<typename Derived>
7304 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7307 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7308 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7309 if (SubExpr.isInvalid())
7312 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7313 return SemaRef.Owned(E);
7316 return getDerived().RebuildExpressionTrait(
7317 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7320 template<typename Derived>
7322 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7323 DependentScopeDeclRefExpr *E) {
7324 NestedNameSpecifierLoc QualifierLoc
7325 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7329 // TODO: If this is a conversion-function-id, verify that the
7330 // destination type name (if present) resolves the same way after
7331 // instantiation as it did in the local scope.
7333 DeclarationNameInfo NameInfo
7334 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7335 if (!NameInfo.getName())
7338 if (!E->hasExplicitTemplateArgs()) {
7339 if (!getDerived().AlwaysRebuild() &&
7340 QualifierLoc == E->getQualifierLoc() &&
7341 // Note: it is sufficient to compare the Name component of NameInfo:
7342 // if name has not changed, DNLoc has not changed either.
7343 NameInfo.getName() == E->getDeclName())
7344 return SemaRef.Owned(E);
7346 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
7348 /*TemplateArgs*/ 0);
7351 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7352 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7353 E->getNumTemplateArgs(),
7357 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
7362 template<typename Derived>
7364 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
7365 // CXXConstructExprs are always implicit, so when we have a
7366 // 1-argument construction we just transform that argument.
7367 if (E->getNumArgs() == 1 ||
7368 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7369 return getDerived().TransformExpr(E->getArg(0));
7371 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7373 QualType T = getDerived().TransformType(E->getType());
7377 CXXConstructorDecl *Constructor
7378 = cast_or_null<CXXConstructorDecl>(
7379 getDerived().TransformDecl(E->getLocStart(),
7380 E->getConstructor()));
7384 bool ArgumentChanged = false;
7385 ASTOwningVector<Expr*> Args(SemaRef);
7386 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7390 if (!getDerived().AlwaysRebuild() &&
7391 T == E->getType() &&
7392 Constructor == E->getConstructor() &&
7394 // Mark the constructor as referenced.
7395 // FIXME: Instantiation-specific
7396 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7397 return SemaRef.Owned(E);
7400 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7401 Constructor, E->isElidable(),
7403 E->hadMultipleCandidates(),
7404 E->requiresZeroInitialization(),
7405 E->getConstructionKind(),
7406 E->getParenRange());
7409 /// \brief Transform a C++ temporary-binding expression.
7411 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7412 /// transform the subexpression and return that.
7413 template<typename Derived>
7415 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
7416 return getDerived().TransformExpr(E->getSubExpr());
7419 /// \brief Transform a C++ expression that contains cleanups that should
7420 /// be run after the expression is evaluated.
7422 /// Since ExprWithCleanups nodes are implicitly generated, we
7423 /// just transform the subexpression and return that.
7424 template<typename Derived>
7426 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
7427 return getDerived().TransformExpr(E->getSubExpr());
7430 template<typename Derived>
7432 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
7433 CXXTemporaryObjectExpr *E) {
7434 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7438 CXXConstructorDecl *Constructor
7439 = cast_or_null<CXXConstructorDecl>(
7440 getDerived().TransformDecl(E->getLocStart(),
7441 E->getConstructor()));
7445 bool ArgumentChanged = false;
7446 ASTOwningVector<Expr*> Args(SemaRef);
7447 Args.reserve(E->getNumArgs());
7448 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7452 if (!getDerived().AlwaysRebuild() &&
7453 T == E->getTypeSourceInfo() &&
7454 Constructor == E->getConstructor() &&
7456 // FIXME: Instantiation-specific
7457 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7458 return SemaRef.MaybeBindToTemporary(E);
7461 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7462 /*FIXME:*/T->getTypeLoc().getEndLoc(),
7467 template<typename Derived>
7469 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
7470 CXXUnresolvedConstructExpr *E) {
7471 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7475 bool ArgumentChanged = false;
7476 ASTOwningVector<Expr*> Args(SemaRef);
7477 Args.reserve(E->arg_size());
7478 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7482 if (!getDerived().AlwaysRebuild() &&
7483 T == E->getTypeSourceInfo() &&
7485 return SemaRef.Owned(E);
7487 // FIXME: we're faking the locations of the commas
7488 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
7494 template<typename Derived>
7496 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
7497 CXXDependentScopeMemberExpr *E) {
7498 // Transform the base of the expression.
7499 ExprResult Base((Expr*) 0);
7502 QualType ObjectType;
7503 if (!E->isImplicitAccess()) {
7504 OldBase = E->getBase();
7505 Base = getDerived().TransformExpr(OldBase);
7506 if (Base.isInvalid())
7509 // Start the member reference and compute the object's type.
7510 ParsedType ObjectTy;
7511 bool MayBePseudoDestructor = false;
7512 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7513 E->getOperatorLoc(),
7514 E->isArrow()? tok::arrow : tok::period,
7516 MayBePseudoDestructor);
7517 if (Base.isInvalid())
7520 ObjectType = ObjectTy.get();
7521 BaseType = ((Expr*) Base.get())->getType();
7524 BaseType = getDerived().TransformType(E->getBaseType());
7525 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7528 // Transform the first part of the nested-name-specifier that qualifies
7530 NamedDecl *FirstQualifierInScope
7531 = getDerived().TransformFirstQualifierInScope(
7532 E->getFirstQualifierFoundInScope(),
7533 E->getQualifierLoc().getBeginLoc());
7535 NestedNameSpecifierLoc QualifierLoc;
7536 if (E->getQualifier()) {
7538 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7540 FirstQualifierInScope);
7545 // TODO: If this is a conversion-function-id, verify that the
7546 // destination type name (if present) resolves the same way after
7547 // instantiation as it did in the local scope.
7549 DeclarationNameInfo NameInfo
7550 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
7551 if (!NameInfo.getName())
7554 if (!E->hasExplicitTemplateArgs()) {
7555 // This is a reference to a member without an explicitly-specified
7556 // template argument list. Optimize for this common case.
7557 if (!getDerived().AlwaysRebuild() &&
7558 Base.get() == OldBase &&
7559 BaseType == E->getBaseType() &&
7560 QualifierLoc == E->getQualifierLoc() &&
7561 NameInfo.getName() == E->getMember() &&
7562 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
7563 return SemaRef.Owned(E);
7565 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
7568 E->getOperatorLoc(),
7570 FirstQualifierInScope,
7572 /*TemplateArgs*/ 0);
7575 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7576 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7577 E->getNumTemplateArgs(),
7581 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
7584 E->getOperatorLoc(),
7586 FirstQualifierInScope,
7591 template<typename Derived>
7593 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
7594 // Transform the base of the expression.
7595 ExprResult Base((Expr*) 0);
7597 if (!Old->isImplicitAccess()) {
7598 Base = getDerived().TransformExpr(Old->getBase());
7599 if (Base.isInvalid())
7601 BaseType = ((Expr*) Base.get())->getType();
7603 BaseType = getDerived().TransformType(Old->getBaseType());
7606 NestedNameSpecifierLoc QualifierLoc;
7607 if (Old->getQualifierLoc()) {
7609 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7614 LookupResult R(SemaRef, Old->getMemberNameInfo(),
7615 Sema::LookupOrdinaryName);
7617 // Transform all the decls.
7618 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7619 E = Old->decls_end(); I != E; ++I) {
7620 NamedDecl *InstD = static_cast<NamedDecl*>(
7621 getDerived().TransformDecl(Old->getMemberLoc(),
7624 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7625 // This can happen because of dependent hiding.
7626 if (isa<UsingShadowDecl>(*I))
7634 // Expand using declarations.
7635 if (isa<UsingDecl>(InstD)) {
7636 UsingDecl *UD = cast<UsingDecl>(InstD);
7637 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7638 E = UD->shadow_end(); I != E; ++I)
7648 // Determine the naming class.
7649 if (Old->getNamingClass()) {
7650 CXXRecordDecl *NamingClass
7651 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7652 Old->getMemberLoc(),
7653 Old->getNamingClass()));
7657 R.setNamingClass(NamingClass);
7660 TemplateArgumentListInfo TransArgs;
7661 if (Old->hasExplicitTemplateArgs()) {
7662 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7663 TransArgs.setRAngleLoc(Old->getRAngleLoc());
7664 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7665 Old->getNumTemplateArgs(),
7670 // FIXME: to do this check properly, we will need to preserve the
7671 // first-qualifier-in-scope here, just in case we had a dependent
7672 // base (and therefore couldn't do the check) and a
7673 // nested-name-qualifier (and therefore could do the lookup).
7674 NamedDecl *FirstQualifierInScope = 0;
7676 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
7678 Old->getOperatorLoc(),
7681 FirstQualifierInScope,
7683 (Old->hasExplicitTemplateArgs()
7687 template<typename Derived>
7689 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7690 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7691 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7692 if (SubExpr.isInvalid())
7695 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
7696 return SemaRef.Owned(E);
7698 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7701 template<typename Derived>
7703 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
7704 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7705 if (Pattern.isInvalid())
7708 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7709 return SemaRef.Owned(E);
7711 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7712 E->getNumExpansions());
7715 template<typename Derived>
7717 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7718 // If E is not value-dependent, then nothing will change when we transform it.
7719 // Note: This is an instantiation-centric view.
7720 if (!E->isValueDependent())
7721 return SemaRef.Owned(E);
7723 // Note: None of the implementations of TryExpandParameterPacks can ever
7724 // produce a diagnostic when given only a single unexpanded parameter pack,
7726 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7727 bool ShouldExpand = false;
7728 bool RetainExpansion = false;
7729 llvm::Optional<unsigned> NumExpansions;
7730 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7732 ShouldExpand, RetainExpansion,
7736 if (RetainExpansion)
7737 return SemaRef.Owned(E);
7739 NamedDecl *Pack = E->getPack();
7740 if (!ShouldExpand) {
7741 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7748 // We now know the length of the parameter pack, so build a new expression
7749 // that stores that length.
7750 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
7751 E->getPackLoc(), E->getRParenLoc(),
7755 template<typename Derived>
7757 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7758 SubstNonTypeTemplateParmPackExpr *E) {
7759 // Default behavior is to do nothing with this transformation.
7760 return SemaRef.Owned(E);
7763 template<typename Derived>
7765 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7766 SubstNonTypeTemplateParmExpr *E) {
7767 // Default behavior is to do nothing with this transformation.
7768 return SemaRef.Owned(E);
7771 template<typename Derived>
7773 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7774 MaterializeTemporaryExpr *E) {
7775 return getDerived().TransformExpr(E->GetTemporaryExpr());
7778 template<typename Derived>
7780 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
7781 return SemaRef.Owned(E);
7784 template<typename Derived>
7786 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
7787 TypeSourceInfo *EncodedTypeInfo
7788 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7789 if (!EncodedTypeInfo)
7792 if (!getDerived().AlwaysRebuild() &&
7793 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
7794 return SemaRef.Owned(E);
7796 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
7801 template<typename Derived>
7802 ExprResult TreeTransform<Derived>::
7803 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7804 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7805 if (result.isInvalid()) return ExprError();
7806 Expr *subExpr = result.take();
7808 if (!getDerived().AlwaysRebuild() &&
7809 subExpr == E->getSubExpr())
7810 return SemaRef.Owned(E);
7812 return SemaRef.Owned(new(SemaRef.Context)
7813 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7816 template<typename Derived>
7817 ExprResult TreeTransform<Derived>::
7818 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7819 TypeSourceInfo *TSInfo
7820 = getDerived().TransformType(E->getTypeInfoAsWritten());
7824 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7825 if (Result.isInvalid())
7828 if (!getDerived().AlwaysRebuild() &&
7829 TSInfo == E->getTypeInfoAsWritten() &&
7830 Result.get() == E->getSubExpr())
7831 return SemaRef.Owned(E);
7833 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7834 E->getBridgeKeywordLoc(), TSInfo,
7838 template<typename Derived>
7840 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
7841 // Transform arguments.
7842 bool ArgChanged = false;
7843 ASTOwningVector<Expr*> Args(SemaRef);
7844 Args.reserve(E->getNumArgs());
7845 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7849 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7850 // Class message: transform the receiver type.
7851 TypeSourceInfo *ReceiverTypeInfo
7852 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7853 if (!ReceiverTypeInfo)
7856 // If nothing changed, just retain the existing message send.
7857 if (!getDerived().AlwaysRebuild() &&
7858 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
7859 return SemaRef.Owned(E);
7861 // Build a new class message send.
7862 SmallVector<SourceLocation, 16> SelLocs;
7863 E->getSelectorLocs(SelLocs);
7864 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7873 // Instance message: transform the receiver
7874 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7875 "Only class and instance messages may be instantiated");
7877 = getDerived().TransformExpr(E->getInstanceReceiver());
7878 if (Receiver.isInvalid())
7881 // If nothing changed, just retain the existing message send.
7882 if (!getDerived().AlwaysRebuild() &&
7883 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
7884 return SemaRef.Owned(E);
7886 // Build a new instance message send.
7887 SmallVector<SourceLocation, 16> SelLocs;
7888 E->getSelectorLocs(SelLocs);
7889 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
7898 template<typename Derived>
7900 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
7901 return SemaRef.Owned(E);
7904 template<typename Derived>
7906 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
7907 return SemaRef.Owned(E);
7910 template<typename Derived>
7912 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
7913 // Transform the base expression.
7914 ExprResult Base = getDerived().TransformExpr(E->getBase());
7915 if (Base.isInvalid())
7918 // We don't need to transform the ivar; it will never change.
7920 // If nothing changed, just retain the existing expression.
7921 if (!getDerived().AlwaysRebuild() &&
7922 Base.get() == E->getBase())
7923 return SemaRef.Owned(E);
7925 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
7927 E->isArrow(), E->isFreeIvar());
7930 template<typename Derived>
7932 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
7933 // 'super' and types never change. Property never changes. Just
7934 // retain the existing expression.
7935 if (!E->isObjectReceiver())
7936 return SemaRef.Owned(E);
7938 // Transform the base expression.
7939 ExprResult Base = getDerived().TransformExpr(E->getBase());
7940 if (Base.isInvalid())
7943 // We don't need to transform the property; it will never change.
7945 // If nothing changed, just retain the existing expression.
7946 if (!getDerived().AlwaysRebuild() &&
7947 Base.get() == E->getBase())
7948 return SemaRef.Owned(E);
7950 if (E->isExplicitProperty())
7951 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7952 E->getExplicitProperty(),
7955 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7957 E->getImplicitPropertyGetter(),
7958 E->getImplicitPropertySetter(),
7962 template<typename Derived>
7964 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
7965 // Transform the base expression.
7966 ExprResult Base = getDerived().TransformExpr(E->getBase());
7967 if (Base.isInvalid())
7970 // If nothing changed, just retain the existing expression.
7971 if (!getDerived().AlwaysRebuild() &&
7972 Base.get() == E->getBase())
7973 return SemaRef.Owned(E);
7975 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
7979 template<typename Derived>
7981 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
7982 bool ArgumentChanged = false;
7983 ASTOwningVector<Expr*> SubExprs(SemaRef);
7984 SubExprs.reserve(E->getNumSubExprs());
7985 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7986 SubExprs, &ArgumentChanged))
7989 if (!getDerived().AlwaysRebuild() &&
7991 return SemaRef.Owned(E);
7993 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7998 template<typename Derived>
8000 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
8001 BlockDecl *oldBlock = E->getBlockDecl();
8003 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8004 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8006 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
8007 // We built a new blockScopeInfo in call to ActOnBlockStart
8008 // in above, CapturesCXXThis need be set here from the block
8010 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
8012 SmallVector<ParmVarDecl*, 4> params;
8013 SmallVector<QualType, 4> paramTypes;
8015 // Parameter substitution.
8016 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8017 oldBlock->param_begin(),
8018 oldBlock->param_size(),
8019 0, paramTypes, ¶ms))
8022 const FunctionType *exprFunctionType = E->getFunctionType();
8023 QualType exprResultType = exprFunctionType->getResultType();
8024 if (!exprResultType.isNull()) {
8025 if (!exprResultType->isDependentType())
8026 blockScope->ReturnType = exprResultType;
8027 else if (exprResultType != getSema().Context.DependentTy)
8028 blockScope->ReturnType = getDerived().TransformType(exprResultType);
8031 // If the return type has not been determined yet, leave it as a dependent
8032 // type; it'll get set when we process the body.
8033 if (blockScope->ReturnType.isNull())
8034 blockScope->ReturnType = getSema().Context.DependentTy;
8036 // Don't allow returning a objc interface by value.
8037 if (blockScope->ReturnType->isObjCObjectType()) {
8038 getSema().Diag(E->getCaretLocation(),
8039 diag::err_object_cannot_be_passed_returned_by_value)
8040 << 0 << blockScope->ReturnType;
8044 QualType functionType = getDerived().RebuildFunctionProtoType(
8045 blockScope->ReturnType,
8048 oldBlock->isVariadic(),
8050 exprFunctionType->getExtInfo());
8051 blockScope->FunctionType = functionType;
8053 // Set the parameters on the block decl.
8054 if (!params.empty())
8055 blockScope->TheDecl->setParams(params);
8057 // If the return type wasn't explicitly set, it will have been marked as a
8058 // dependent type (DependentTy); clear out the return type setting so
8059 // we will deduce the return type when type-checking the block's body.
8060 if (blockScope->ReturnType == getSema().Context.DependentTy)
8061 blockScope->ReturnType = QualType();
8063 // Transform the body
8064 StmtResult body = getDerived().TransformStmt(E->getBody());
8065 if (body.isInvalid())
8069 // In builds with assertions, make sure that we captured everything we
8071 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8072 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8073 e = oldBlock->capture_end(); i != e; ++i) {
8074 VarDecl *oldCapture = i->getVariable();
8076 // Ignore parameter packs.
8077 if (isa<ParmVarDecl>(oldCapture) &&
8078 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8081 VarDecl *newCapture =
8082 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8084 assert(blockScope->CaptureMap.count(newCapture));
8089 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8093 template<typename Derived>
8095 TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
8097 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8102 if (!getDerived().AlwaysRebuild() &&
8103 ND == E->getDecl()) {
8104 // Mark it referenced in the new context regardless.
8105 // FIXME: this is a bit instantiation-specific.
8106 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8108 return SemaRef.Owned(E);
8111 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
8112 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
8116 template<typename Derived>
8118 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8119 llvm_unreachable("Cannot transform asType expressions yet");
8122 template<typename Derived>
8124 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
8125 QualType RetTy = getDerived().TransformType(E->getType());
8126 bool ArgumentChanged = false;
8127 ASTOwningVector<Expr*> SubExprs(SemaRef);
8128 SubExprs.reserve(E->getNumSubExprs());
8129 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8130 SubExprs, &ArgumentChanged))
8133 if (!getDerived().AlwaysRebuild() &&
8135 return SemaRef.Owned(E);
8137 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8138 RetTy, E->getOp(), E->getRParenLoc());
8141 //===----------------------------------------------------------------------===//
8142 // Type reconstruction
8143 //===----------------------------------------------------------------------===//
8145 template<typename Derived>
8146 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8147 SourceLocation Star) {
8148 return SemaRef.BuildPointerType(PointeeType, Star,
8149 getDerived().getBaseEntity());
8152 template<typename Derived>
8153 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8154 SourceLocation Star) {
8155 return SemaRef.BuildBlockPointerType(PointeeType, Star,
8156 getDerived().getBaseEntity());
8159 template<typename Derived>
8161 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8162 bool WrittenAsLValue,
8163 SourceLocation Sigil) {
8164 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
8165 Sigil, getDerived().getBaseEntity());
8168 template<typename Derived>
8170 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8172 SourceLocation Sigil) {
8173 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
8174 Sigil, getDerived().getBaseEntity());
8177 template<typename Derived>
8179 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8180 ArrayType::ArraySizeModifier SizeMod,
8181 const llvm::APInt *Size,
8183 unsigned IndexTypeQuals,
8184 SourceRange BracketsRange) {
8185 if (SizeExpr || !Size)
8186 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8187 IndexTypeQuals, BracketsRange,
8188 getDerived().getBaseEntity());
8190 QualType Types[] = {
8191 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8192 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8193 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
8195 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8197 for (unsigned I = 0; I != NumTypes; ++I)
8198 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8199 SizeType = Types[I];
8203 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8204 /*FIXME*/BracketsRange.getBegin());
8205 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
8206 IndexTypeQuals, BracketsRange,
8207 getDerived().getBaseEntity());
8210 template<typename Derived>
8212 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
8213 ArrayType::ArraySizeModifier SizeMod,
8214 const llvm::APInt &Size,
8215 unsigned IndexTypeQuals,
8216 SourceRange BracketsRange) {
8217 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
8218 IndexTypeQuals, BracketsRange);
8221 template<typename Derived>
8223 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
8224 ArrayType::ArraySizeModifier SizeMod,
8225 unsigned IndexTypeQuals,
8226 SourceRange BracketsRange) {
8227 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
8228 IndexTypeQuals, BracketsRange);
8231 template<typename Derived>
8233 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
8234 ArrayType::ArraySizeModifier SizeMod,
8236 unsigned IndexTypeQuals,
8237 SourceRange BracketsRange) {
8238 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
8240 IndexTypeQuals, BracketsRange);
8243 template<typename Derived>
8245 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
8246 ArrayType::ArraySizeModifier SizeMod,
8248 unsigned IndexTypeQuals,
8249 SourceRange BracketsRange) {
8250 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
8252 IndexTypeQuals, BracketsRange);
8255 template<typename Derived>
8256 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
8257 unsigned NumElements,
8258 VectorType::VectorKind VecKind) {
8259 // FIXME: semantic checking!
8260 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
8263 template<typename Derived>
8264 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8265 unsigned NumElements,
8266 SourceLocation AttributeLoc) {
8267 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8269 IntegerLiteral *VectorSize
8270 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8272 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
8275 template<typename Derived>
8277 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
8279 SourceLocation AttributeLoc) {
8280 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
8283 template<typename Derived>
8284 QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
8285 QualType *ParamTypes,
8286 unsigned NumParamTypes,
8289 RefQualifierKind RefQualifier,
8290 const FunctionType::ExtInfo &Info) {
8291 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
8292 Quals, RefQualifier,
8293 getDerived().getBaseLocation(),
8294 getDerived().getBaseEntity(),
8298 template<typename Derived>
8299 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8300 return SemaRef.Context.getFunctionNoProtoType(T);
8303 template<typename Derived>
8304 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8305 assert(D && "no decl found");
8306 if (D->isInvalidDecl()) return QualType();
8308 // FIXME: Doesn't account for ObjCInterfaceDecl!
8310 if (isa<UsingDecl>(D)) {
8311 UsingDecl *Using = cast<UsingDecl>(D);
8312 assert(Using->isTypeName() &&
8313 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8315 // A valid resolved using typename decl points to exactly one type decl.
8316 assert(++Using->shadow_begin() == Using->shadow_end());
8317 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
8320 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8321 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8322 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8325 return SemaRef.Context.getTypeDeclType(Ty);
8328 template<typename Derived>
8329 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8330 SourceLocation Loc) {
8331 return SemaRef.BuildTypeofExprType(E, Loc);
8334 template<typename Derived>
8335 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8336 return SemaRef.Context.getTypeOfType(Underlying);
8339 template<typename Derived>
8340 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8341 SourceLocation Loc) {
8342 return SemaRef.BuildDecltypeType(E, Loc);
8345 template<typename Derived>
8346 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8347 UnaryTransformType::UTTKind UKind,
8348 SourceLocation Loc) {
8349 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8352 template<typename Derived>
8353 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
8354 TemplateName Template,
8355 SourceLocation TemplateNameLoc,
8356 TemplateArgumentListInfo &TemplateArgs) {
8357 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
8360 template<typename Derived>
8361 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8362 SourceLocation KWLoc) {
8363 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8366 template<typename Derived>
8368 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8370 TemplateDecl *Template) {
8371 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
8375 template<typename Derived>
8377 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8378 const IdentifierInfo &Name,
8379 SourceLocation NameLoc,
8380 QualType ObjectType,
8381 NamedDecl *FirstQualifierInScope) {
8382 UnqualifiedId TemplateName;
8383 TemplateName.setIdentifier(&Name, NameLoc);
8384 Sema::TemplateTy Template;
8385 getSema().ActOnDependentTemplateName(/*Scope=*/0,
8386 /*FIXME:*/SourceLocation(),
8389 ParsedType::make(ObjectType),
8390 /*EnteringContext=*/false,
8392 return Template.get();
8395 template<typename Derived>
8397 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8398 OverloadedOperatorKind Operator,
8399 SourceLocation NameLoc,
8400 QualType ObjectType) {
8402 // FIXME: Bogus location information.
8403 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8404 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
8405 Sema::TemplateTy Template;
8406 getSema().ActOnDependentTemplateName(/*Scope=*/0,
8407 /*FIXME:*/SourceLocation(),
8410 ParsedType::make(ObjectType),
8411 /*EnteringContext=*/false,
8413 return Template.template getAsVal<TemplateName>();
8416 template<typename Derived>
8418 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8419 SourceLocation OpLoc,
8423 Expr *Callee = OrigCallee->IgnoreParenCasts();
8424 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
8426 // Determine whether this should be a builtin operation.
8427 if (Op == OO_Subscript) {
8428 if (!First->getType()->isOverloadableType() &&
8429 !Second->getType()->isOverloadableType())
8430 return getSema().CreateBuiltinArraySubscriptExpr(First,
8431 Callee->getLocStart(),
8433 } else if (Op == OO_Arrow) {
8434 // -> is never a builtin operation.
8435 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8436 } else if (Second == 0 || isPostIncDec) {
8437 if (!First->getType()->isOverloadableType()) {
8438 // The argument is not of overloadable type, so try to create a
8439 // built-in unary operation.
8440 UnaryOperatorKind Opc
8441 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
8443 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
8446 if (!First->getType()->isOverloadableType() &&
8447 !Second->getType()->isOverloadableType()) {
8448 // Neither of the arguments is an overloadable type, so try to
8449 // create a built-in binary operation.
8450 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
8452 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
8453 if (Result.isInvalid())
8456 return move(Result);
8460 // Compute the transformed set of functions (and function templates) to be
8461 // used during overload resolution.
8462 UnresolvedSet<16> Functions;
8464 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
8465 assert(ULE->requiresADL());
8467 // FIXME: Do we have to check
8468 // IsAcceptableNonMemberOperatorCandidate for each of these?
8469 Functions.append(ULE->decls_begin(), ULE->decls_end());
8471 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
8474 // Add any functions found via argument-dependent lookup.
8475 Expr *Args[2] = { First, Second };
8476 unsigned NumArgs = 1 + (Second != 0);
8478 // Create the overloaded operator invocation for unary operators.
8479 if (NumArgs == 1 || isPostIncDec) {
8480 UnaryOperatorKind Opc
8481 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
8482 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
8485 if (Op == OO_Subscript) {
8486 SourceLocation LBrace;
8487 SourceLocation RBrace;
8489 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8490 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8491 LBrace = SourceLocation::getFromRawEncoding(
8492 NameLoc.CXXOperatorName.BeginOpNameLoc);
8493 RBrace = SourceLocation::getFromRawEncoding(
8494 NameLoc.CXXOperatorName.EndOpNameLoc);
8496 LBrace = Callee->getLocStart();
8500 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8504 // Create the overloaded operator invocation for binary operators.
8505 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
8507 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8508 if (Result.isInvalid())
8511 return move(Result);
8514 template<typename Derived>
8516 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
8517 SourceLocation OperatorLoc,
8520 TypeSourceInfo *ScopeType,
8521 SourceLocation CCLoc,
8522 SourceLocation TildeLoc,
8523 PseudoDestructorTypeStorage Destroyed) {
8524 QualType BaseType = Base->getType();
8525 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
8526 (!isArrow && !BaseType->getAs<RecordType>()) ||
8527 (isArrow && BaseType->getAs<PointerType>() &&
8528 !BaseType->getAs<PointerType>()->getPointeeType()
8529 ->template getAs<RecordType>())){
8530 // This pseudo-destructor expression is still a pseudo-destructor.
8531 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
8532 isArrow? tok::arrow : tok::period,
8533 SS, ScopeType, CCLoc, TildeLoc,
8538 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
8539 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8540 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8541 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8542 NameInfo.setNamedTypeInfo(DestroyedType);
8544 // FIXME: the ScopeType should be tacked onto SS.
8546 return getSema().BuildMemberReferenceExpr(Base, BaseType,
8547 OperatorLoc, isArrow,
8548 SS, /*FIXME: FirstQualifier*/ 0,
8550 /*TemplateArgs*/ 0);
8553 } // end namespace clang
8555 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H