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 "TypeLocBuilder.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/ExprCXX.h"
23 #include "clang/AST/ExprObjC.h"
24 #include "clang/AST/Stmt.h"
25 #include "clang/AST/StmtCXX.h"
26 #include "clang/AST/StmtObjC.h"
27 #include "clang/AST/StmtOpenMP.h"
28 #include "clang/Lex/Preprocessor.h"
29 #include "clang/Sema/Designator.h"
30 #include "clang/Sema/Lookup.h"
31 #include "clang/Sema/Ownership.h"
32 #include "clang/Sema/ParsedTemplate.h"
33 #include "clang/Sema/ScopeInfo.h"
34 #include "clang/Sema/SemaDiagnostic.h"
35 #include "clang/Sema/SemaInternal.h"
36 #include "llvm/ADT/ArrayRef.h"
37 #include "llvm/Support/ErrorHandling.h"
43 /// \brief A semantic tree transformation that allows one to transform one
44 /// abstract syntax tree into another.
46 /// A new tree transformation is defined by creating a new subclass \c X of
47 /// \c TreeTransform<X> and then overriding certain operations to provide
48 /// behavior specific to that transformation. For example, template
49 /// instantiation is implemented as a tree transformation where the
50 /// transformation of TemplateTypeParmType nodes involves substituting the
51 /// template arguments for their corresponding template parameters; a similar
52 /// transformation is performed for non-type template parameters and
53 /// template template parameters.
55 /// This tree-transformation template uses static polymorphism to allow
56 /// subclasses to customize any of its operations. Thus, a subclass can
57 /// override any of the transformation or rebuild operators by providing an
58 /// operation with the same signature as the default implementation. The
59 /// overridding function should not be virtual.
61 /// Semantic tree transformations are split into two stages, either of which
62 /// can be replaced by a subclass. The "transform" step transforms an AST node
63 /// or the parts of an AST node using the various transformation functions,
64 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
65 /// node of the appropriate kind from the pieces. The default transformation
66 /// routines recursively transform the operands to composite AST nodes (e.g.,
67 /// the pointee type of a PointerType node) and, if any of those operand nodes
68 /// were changed by the transformation, invokes the rebuild operation to create
71 /// Subclasses can customize the transformation at various levels. The
72 /// most coarse-grained transformations involve replacing TransformType(),
73 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
74 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
75 /// new implementations.
77 /// For more fine-grained transformations, subclasses can replace any of the
78 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
79 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
80 /// replacing TransformTemplateTypeParmType() allows template instantiation
81 /// to substitute template arguments for their corresponding template
82 /// parameters. Additionally, subclasses can override the \c RebuildXXX
83 /// functions to control how AST nodes are rebuilt when their operands change.
84 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
85 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
86 /// be able to use more efficient rebuild steps.
88 /// There are a handful of other functions that can be overridden, allowing one
89 /// to avoid traversing nodes that don't need any transformation
90 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91 /// operands have not changed (\c AlwaysRebuild()), and customize the
92 /// default locations and entity names used for type-checking
93 /// (\c getBaseLocation(), \c getBaseEntity()).
94 template<typename Derived>
96 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
99 class ForgetPartiallySubstitutedPackRAII {
101 TemplateArgument Old;
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
122 /// \brief Initializes a new tree transformer.
123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
128 /// \brief Retrieves a reference to the derived class.
129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
154 /// By default, returns no source-location information. Subclasses can
155 /// provide an alternative implementation that provides better location
157 SourceLocation getBaseLocation() { return SourceLocation(); }
159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
182 DeclarationName Entity) : Self(Self) {
183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
191 Self.getDerived().setBase(OldLocation, OldEntity);
195 /// \brief Determine whether the given type \p T has already been
198 /// Subclasses can provide an alternative implementation of this routine
199 /// to short-circuit evaluation when it is known that a given type will
200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
220 /// By default, the transformer never tries to expand pack expansions.
221 /// Subclasses can override this routine to provide different behavior.
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
229 /// \param Unexpanded The set of unexpanded parameter packs within the
232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
241 /// \param NumExpansions The number of separate arguments that will be in
242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
255 ArrayRef<UnexpandedParameterPack> Unexpanded,
257 bool &RetainExpansion,
258 Optional<unsigned> &NumExpansions) {
259 ShouldExpand = false;
263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
279 /// \brief Note to the derived class when a function parameter pack is
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
283 /// \brief Transforms the given type into another type.
285 /// By default, this routine transforms a type by creating a
286 /// TypeSourceInfo for it and delegating to the appropriate
287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
289 /// switched to storing TypeSourceInfos.
291 /// \returns the transformed type.
292 QualType TransformType(QualType T);
294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
310 /// \brief Transform the given statement.
312 /// By default, this routine transforms a statement by delegating to the
313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
318 /// \returns the transformed statement.
319 StmtResult TransformStmt(Stmt *S);
321 /// \brief Transform the given statement.
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
331 /// \brief Transform the given expression.
333 /// By default, this routine transforms an expression by delegating to the
334 /// appropriate TransformXXXExpr function to build a new expression.
335 /// Subclasses may override this function to transform expressions using some
338 /// \returns the transformed expression.
339 ExprResult TransformExpr(Expr *E);
341 /// \brief Transform the given initializer.
343 /// By default, this routine transforms an initializer by stripping off the
344 /// semantic nodes added by initialization, then passing the result to
345 /// TransformExpr or TransformExprs.
347 /// \returns the transformed initializer.
348 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
350 /// \brief Transform the given list of expressions.
352 /// This routine transforms a list of expressions by invoking
353 /// \c TransformExpr() for each subexpression. However, it also provides
354 /// support for variadic templates by expanding any pack expansions (if the
355 /// derived class permits such expansion) along the way. When pack expansions
356 /// are present, the number of outputs may not equal the number of inputs.
358 /// \param Inputs The set of expressions to be transformed.
360 /// \param NumInputs The number of expressions in \c Inputs.
362 /// \param IsCall If \c true, then this transform is being performed on
363 /// function-call arguments, and any arguments that should be dropped, will
366 /// \param Outputs The transformed input expressions will be added to this
369 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
370 /// due to transformation.
372 /// \returns true if an error occurred, false otherwise.
373 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
374 SmallVectorImpl<Expr *> &Outputs,
375 bool *ArgChanged = 0);
377 /// \brief Transform the given declaration, which is referenced from a type
380 /// By default, acts as the identity function on declarations, unless the
381 /// transformer has had to transform the declaration itself. Subclasses
382 /// may override this function to provide alternate behavior.
383 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
384 llvm::DenseMap<Decl *, Decl *>::iterator Known
385 = TransformedLocalDecls.find(D);
386 if (Known != TransformedLocalDecls.end())
387 return Known->second;
392 /// \brief Transform the attributes associated with the given declaration and
393 /// place them on the new declaration.
395 /// By default, this operation does nothing. Subclasses may override this
396 /// behavior to transform attributes.
397 void transformAttrs(Decl *Old, Decl *New) { }
399 /// \brief Note that a local declaration has been transformed by this
402 /// Local declarations are typically transformed via a call to
403 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
404 /// the transformer itself has to transform the declarations. This routine
405 /// can be overridden by a subclass that keeps track of such mappings.
406 void transformedLocalDecl(Decl *Old, Decl *New) {
407 TransformedLocalDecls[Old] = New;
410 /// \brief Transform the definition of the given declaration.
412 /// By default, invokes TransformDecl() to transform the declaration.
413 /// Subclasses may override this function to provide alternate behavior.
414 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
415 return getDerived().TransformDecl(Loc, D);
418 /// \brief Transform the given declaration, which was the first part of a
419 /// nested-name-specifier in a member access expression.
421 /// This specific declaration transformation only applies to the first
422 /// identifier in a nested-name-specifier of a member access expression, e.g.,
423 /// the \c T in \c x->T::member
425 /// By default, invokes TransformDecl() to transform the declaration.
426 /// Subclasses may override this function to provide alternate behavior.
427 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
428 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
431 /// \brief Transform the given nested-name-specifier with source-location
434 /// By default, transforms all of the types and declarations within the
435 /// nested-name-specifier. Subclasses may override this function to provide
436 /// alternate behavior.
437 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
438 NestedNameSpecifierLoc NNS,
439 QualType ObjectType = QualType(),
440 NamedDecl *FirstQualifierInScope = 0);
442 /// \brief Transform the given declaration name.
444 /// By default, transforms the types of conversion function, constructor,
445 /// and destructor names and then (if needed) rebuilds the declaration name.
446 /// Identifiers and selectors are returned unmodified. Sublcasses may
447 /// override this function to provide alternate behavior.
449 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
451 /// \brief Transform the given template name.
453 /// \param SS The nested-name-specifier that qualifies the template
454 /// name. This nested-name-specifier must already have been transformed.
456 /// \param Name The template name to transform.
458 /// \param NameLoc The source location of the template name.
460 /// \param ObjectType If we're translating a template name within a member
461 /// access expression, this is the type of the object whose member template
462 /// is being referenced.
464 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
465 /// also refers to a name within the current (lexical) scope, this is the
466 /// declaration it refers to.
468 /// By default, transforms the template name by transforming the declarations
469 /// and nested-name-specifiers that occur within the template name.
470 /// Subclasses may override this function to provide alternate behavior.
471 TemplateName TransformTemplateName(CXXScopeSpec &SS,
473 SourceLocation NameLoc,
474 QualType ObjectType = QualType(),
475 NamedDecl *FirstQualifierInScope = 0);
477 /// \brief Transform the given template argument.
479 /// By default, this operation transforms the type, expression, or
480 /// declaration stored within the template argument and constructs a
481 /// new template argument from the transformed result. Subclasses may
482 /// override this function to provide alternate behavior.
484 /// Returns true if there was an error.
485 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
486 TemplateArgumentLoc &Output);
488 /// \brief Transform the given set of template arguments.
490 /// By default, this operation transforms all of the template arguments
491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
494 /// Note that this overload of \c TransformTemplateArguments() is merely
495 /// a convenience function. Subclasses that wish to override this behavior
496 /// should override the iterator-based member template version.
498 /// \param Inputs The set of template arguments to be transformed.
500 /// \param NumInputs The number of template arguments in \p Inputs.
502 /// \param Outputs The set of transformed template arguments output by this
505 /// Returns true if an error occurred.
506 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
508 TemplateArgumentListInfo &Outputs) {
509 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
512 /// \brief Transform the given set of template arguments.
514 /// By default, this operation transforms all of the template arguments
515 /// in the input set using \c TransformTemplateArgument(), and appends
516 /// the transformed arguments to the output list.
518 /// \param First An iterator to the first template argument.
520 /// \param Last An iterator one step past the last template argument.
522 /// \param Outputs The set of transformed template arguments output by this
525 /// Returns true if an error occurred.
526 template<typename InputIterator>
527 bool TransformTemplateArguments(InputIterator First,
529 TemplateArgumentListInfo &Outputs);
531 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
532 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
533 TemplateArgumentLoc &ArgLoc);
535 /// \brief Fakes up a TypeSourceInfo for a type.
536 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
537 return SemaRef.Context.getTrivialTypeSourceInfo(T,
538 getDerived().getBaseLocation());
541 #define ABSTRACT_TYPELOC(CLASS, PARENT)
542 #define TYPELOC(CLASS, PARENT) \
543 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
544 #include "clang/AST/TypeLocNodes.def"
546 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
547 FunctionProtoTypeLoc TL,
548 CXXRecordDecl *ThisContext,
549 unsigned ThisTypeQuals);
551 StmtResult TransformSEHHandler(Stmt *Handler);
554 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
555 TemplateSpecializationTypeLoc TL,
556 TemplateName Template);
559 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
560 DependentTemplateSpecializationTypeLoc TL,
561 TemplateName Template,
565 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
566 DependentTemplateSpecializationTypeLoc TL,
567 NestedNameSpecifierLoc QualifierLoc);
569 /// \brief Transforms the parameters of a function type into the
572 /// The result vectors should be kept in sync; null entries in the
573 /// variables vector are acceptable.
575 /// Return true on error.
576 bool TransformFunctionTypeParams(SourceLocation Loc,
577 ParmVarDecl **Params, unsigned NumParams,
578 const QualType *ParamTypes,
579 SmallVectorImpl<QualType> &PTypes,
580 SmallVectorImpl<ParmVarDecl*> *PVars);
582 /// \brief Transforms a single function-type parameter. Return null
585 /// \param indexAdjustment - A number to add to the parameter's
586 /// scope index; can be negative
587 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
589 Optional<unsigned> NumExpansions,
590 bool ExpectParameterPack);
592 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
594 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
595 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
597 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
598 /// \brief Transform the captures and body of a lambda expression.
599 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
600 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
602 TemplateParameterList *TransformTemplateParameterList(
603 TemplateParameterList *TPL) {
607 ExprResult TransformAddressOfOperand(Expr *E);
608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
609 bool IsAddressOfOperand);
611 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
612 // amount of stack usage with clang.
613 #define STMT(Node, Parent) \
614 LLVM_ATTRIBUTE_NOINLINE \
615 StmtResult Transform##Node(Node *S);
616 #define EXPR(Node, Parent) \
617 LLVM_ATTRIBUTE_NOINLINE \
618 ExprResult Transform##Node(Node *E);
619 #define ABSTRACT_STMT(Stmt)
620 #include "clang/AST/StmtNodes.inc"
622 #define OPENMP_CLAUSE(Name, Class) \
623 LLVM_ATTRIBUTE_NOINLINE \
624 OMPClause *Transform ## Class(Class *S);
625 #include "clang/Basic/OpenMPKinds.def"
627 /// \brief Build a new pointer type given its pointee type.
629 /// By default, performs semantic analysis when building the pointer type.
630 /// Subclasses may override this routine to provide different behavior.
631 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
633 /// \brief Build a new block pointer type given its pointee type.
635 /// By default, performs semantic analysis when building the block pointer
636 /// type. Subclasses may override this routine to provide different behavior.
637 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
639 /// \brief Build a new reference type given the type it references.
641 /// By default, performs semantic analysis when building the
642 /// reference type. Subclasses may override this routine to provide
643 /// different behavior.
645 /// \param LValue whether the type was written with an lvalue sigil
646 /// or an rvalue sigil.
647 QualType RebuildReferenceType(QualType ReferentType,
649 SourceLocation Sigil);
651 /// \brief Build a new member pointer type given the pointee type and the
652 /// class type it refers into.
654 /// By default, performs semantic analysis when building the member pointer
655 /// type. Subclasses may override this routine to provide different behavior.
656 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
657 SourceLocation Sigil);
659 /// \brief Build a new array type given the element type, size
660 /// modifier, size of the array (if known), size expression, and index type
663 /// By default, performs semantic analysis when building the array type.
664 /// Subclasses may override this routine to provide different behavior.
665 /// Also by default, all of the other Rebuild*Array
666 QualType RebuildArrayType(QualType ElementType,
667 ArrayType::ArraySizeModifier SizeMod,
668 const llvm::APInt *Size,
670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
673 /// \brief Build a new constant array type given the element type, size
674 /// modifier, (known) size of the array, and index type qualifiers.
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
678 QualType RebuildConstantArrayType(QualType ElementType,
679 ArrayType::ArraySizeModifier SizeMod,
680 const llvm::APInt &Size,
681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
684 /// \brief Build a new incomplete array type given the element type, size
685 /// modifier, and index type qualifiers.
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
689 QualType RebuildIncompleteArrayType(QualType ElementType,
690 ArrayType::ArraySizeModifier SizeMod,
691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
694 /// \brief Build a new variable-length array type given the element type,
695 /// size modifier, size expression, and index type qualifiers.
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildVariableArrayType(QualType ElementType,
700 ArrayType::ArraySizeModifier SizeMod,
702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
705 /// \brief Build a new dependent-sized array type given the element type,
706 /// size modifier, size expression, and index type qualifiers.
708 /// By default, performs semantic analysis when building the array type.
709 /// Subclasses may override this routine to provide different behavior.
710 QualType RebuildDependentSizedArrayType(QualType ElementType,
711 ArrayType::ArraySizeModifier SizeMod,
713 unsigned IndexTypeQuals,
714 SourceRange BracketsRange);
716 /// \brief Build a new vector type given the element type and
717 /// number of elements.
719 /// By default, performs semantic analysis when building the vector type.
720 /// Subclasses may override this routine to provide different behavior.
721 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
722 VectorType::VectorKind VecKind);
724 /// \brief Build a new extended vector type given the element type and
725 /// number of elements.
727 /// By default, performs semantic analysis when building the vector type.
728 /// Subclasses may override this routine to provide different behavior.
729 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
730 SourceLocation AttributeLoc);
732 /// \brief Build a new potentially dependently-sized extended vector type
733 /// given the element type and number of elements.
735 /// By default, performs semantic analysis when building the vector type.
736 /// Subclasses may override this routine to provide different behavior.
737 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
739 SourceLocation AttributeLoc);
741 /// \brief Build a new function type.
743 /// By default, performs semantic analysis when building the function type.
744 /// Subclasses may override this routine to provide different behavior.
745 QualType RebuildFunctionProtoType(QualType T,
746 llvm::MutableArrayRef<QualType> ParamTypes,
747 const FunctionProtoType::ExtProtoInfo &EPI);
749 /// \brief Build a new unprototyped function type.
750 QualType RebuildFunctionNoProtoType(QualType ResultType);
752 /// \brief Rebuild an unresolved typename type, given the decl that
753 /// the UnresolvedUsingTypenameDecl was transformed to.
754 QualType RebuildUnresolvedUsingType(Decl *D);
756 /// \brief Build a new typedef type.
757 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
758 return SemaRef.Context.getTypeDeclType(Typedef);
761 /// \brief Build a new class/struct/union type.
762 QualType RebuildRecordType(RecordDecl *Record) {
763 return SemaRef.Context.getTypeDeclType(Record);
766 /// \brief Build a new Enum type.
767 QualType RebuildEnumType(EnumDecl *Enum) {
768 return SemaRef.Context.getTypeDeclType(Enum);
771 /// \brief Build a new typeof(expr) type.
773 /// By default, performs semantic analysis when building the typeof type.
774 /// Subclasses may override this routine to provide different behavior.
775 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
777 /// \brief Build a new typeof(type) type.
779 /// By default, builds a new TypeOfType with the given underlying type.
780 QualType RebuildTypeOfType(QualType Underlying);
782 /// \brief Build a new unary transform type.
783 QualType RebuildUnaryTransformType(QualType BaseType,
784 UnaryTransformType::UTTKind UKind,
787 /// \brief Build a new C++11 decltype type.
789 /// By default, performs semantic analysis when building the decltype type.
790 /// Subclasses may override this routine to provide different behavior.
791 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
793 /// \brief Build a new C++11 auto type.
795 /// By default, builds a new AutoType with the given deduced type.
796 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
797 // Note, IsDependent is always false here: we implicitly convert an 'auto'
798 // which has been deduced to a dependent type into an undeduced 'auto', so
799 // that we'll retry deduction after the transformation.
800 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
801 /*IsDependent*/ false);
804 /// \brief Build a new template specialization type.
806 /// By default, performs semantic analysis when building the template
807 /// specialization type. Subclasses may override this routine to provide
808 /// different behavior.
809 QualType RebuildTemplateSpecializationType(TemplateName Template,
810 SourceLocation TemplateLoc,
811 TemplateArgumentListInfo &Args);
813 /// \brief Build a new parenthesized type.
815 /// By default, builds a new ParenType type from the inner type.
816 /// Subclasses may override this routine to provide different behavior.
817 QualType RebuildParenType(QualType InnerType) {
818 return SemaRef.Context.getParenType(InnerType);
821 /// \brief Build a new qualified name type.
823 /// By default, builds a new ElaboratedType type from the keyword,
824 /// the nested-name-specifier and the named type.
825 /// Subclasses may override this routine to provide different behavior.
826 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
827 ElaboratedTypeKeyword Keyword,
828 NestedNameSpecifierLoc QualifierLoc,
830 return SemaRef.Context.getElaboratedType(Keyword,
831 QualifierLoc.getNestedNameSpecifier(),
835 /// \brief Build a new typename type that refers to a template-id.
837 /// By default, builds a new DependentNameType type from the
838 /// nested-name-specifier and the given type. Subclasses may override
839 /// this routine to provide different behavior.
840 QualType RebuildDependentTemplateSpecializationType(
841 ElaboratedTypeKeyword Keyword,
842 NestedNameSpecifierLoc QualifierLoc,
843 const IdentifierInfo *Name,
844 SourceLocation NameLoc,
845 TemplateArgumentListInfo &Args) {
846 // Rebuild the template name.
847 // TODO: avoid TemplateName abstraction
849 SS.Adopt(QualifierLoc);
850 TemplateName InstName
851 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
853 if (InstName.isNull())
856 // If it's still dependent, make a dependent specialization.
857 if (InstName.getAsDependentTemplateName())
858 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
859 QualifierLoc.getNestedNameSpecifier(),
863 // Otherwise, make an elaborated type wrapping a non-dependent
866 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
867 if (T.isNull()) return QualType();
869 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
872 return SemaRef.Context.getElaboratedType(Keyword,
873 QualifierLoc.getNestedNameSpecifier(),
877 /// \brief Build a new typename type that refers to an identifier.
879 /// By default, performs semantic analysis when building the typename type
880 /// (or elaborated type). Subclasses may override this routine to provide
881 /// different behavior.
882 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
883 SourceLocation KeywordLoc,
884 NestedNameSpecifierLoc QualifierLoc,
885 const IdentifierInfo *Id,
886 SourceLocation IdLoc) {
888 SS.Adopt(QualifierLoc);
890 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
891 // If the name is still dependent, just build a new dependent name type.
892 if (!SemaRef.computeDeclContext(SS))
893 return SemaRef.Context.getDependentNameType(Keyword,
894 QualifierLoc.getNestedNameSpecifier(),
898 if (Keyword == ETK_None || Keyword == ETK_Typename)
899 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
902 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904 // We had a dependent elaborated-type-specifier that has been transformed
905 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
908 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
912 if (SemaRef.RequireCompleteDeclContext(SS, DC))
916 SemaRef.LookupQualifiedName(Result, DC);
917 switch (Result.getResultKind()) {
918 case LookupResult::NotFound:
919 case LookupResult::NotFoundInCurrentInstantiation:
922 case LookupResult::Found:
923 Tag = Result.getAsSingle<TagDecl>();
926 case LookupResult::FoundOverloaded:
927 case LookupResult::FoundUnresolvedValue:
928 llvm_unreachable("Tag lookup cannot find non-tags");
930 case LookupResult::Ambiguous:
931 // Let the LookupResult structure handle ambiguities.
936 // Check where the name exists but isn't a tag type and use that to emit
937 // better diagnostics.
938 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
939 SemaRef.LookupQualifiedName(Result, DC);
940 switch (Result.getResultKind()) {
941 case LookupResult::Found:
942 case LookupResult::FoundOverloaded:
943 case LookupResult::FoundUnresolvedValue: {
944 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
946 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
947 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
948 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
949 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
950 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
954 // FIXME: Would be nice to highlight just the source range.
955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
976 /// \brief Build a new pack expansion type.
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
980 QualType RebuildPackExpansionType(QualType Pattern,
981 SourceRange PatternRange,
982 SourceLocation EllipsisLoc,
983 Optional<unsigned> NumExpansions) {
984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
988 /// \brief Build a new atomic type given its value type.
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
1000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1002 TemplateDecl *Template);
1004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
1014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
1017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1025 OverloadedOperatorKind Operator,
1026 SourceLocation NameLoc,
1027 QualType ObjectType);
1029 /// \brief Build a new template name given a template template parameter pack
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1041 /// \brief Build a new compound statement.
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
1045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1053 /// \brief Build a new case statement.
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
1057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1059 SourceLocation EllipsisLoc,
1061 SourceLocation ColonLoc) {
1062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1066 /// \brief Attach the body to a new case statement.
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
1070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1071 getSema().ActOnCaseStmtBody(S, Body);
1075 /// \brief Build a new default statement.
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
1079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1080 SourceLocation ColonLoc,
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1086 /// \brief Build a new label statement.
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
1090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1095 /// \brief Build a new label statement.
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
1099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1105 /// \brief Build a new "if" statement.
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
1109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
1110 VarDecl *CondVar, Stmt *Then,
1111 SourceLocation ElseLoc, Stmt *Else) {
1112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
1115 /// \brief Start building a new switch statement.
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
1119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
1120 Expr *Cond, VarDecl *CondVar) {
1121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1125 /// \brief Attach the body to the switch statement.
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
1129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1130 Stmt *Switch, Stmt *Body) {
1131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1134 /// \brief Build a new while statement.
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
1138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
1140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
1143 /// \brief Build a new do-while statement.
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
1147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
1150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1154 /// \brief Build a new for statement.
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
1158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1159 Stmt *Init, Sema::FullExprArg Cond,
1160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
1162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1163 CondVar, Inc, RParenLoc, Body);
1166 /// \brief Build a new goto statement.
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
1170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1175 /// \brief Build a new indirect goto statement.
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
1179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1180 SourceLocation StarLoc,
1182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1185 /// \brief Build a new return statement.
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
1189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1190 return getSema().ActOnReturnStmt(ReturnLoc, Result);
1193 /// \brief Build a new declaration statement.
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
1197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1203 /// \brief Build a new inline asm statement.
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
1207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
1218 /// \brief Build a new MS style inline asm statement.
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
1235 /// \brief Build a new Objective-C \@try statement.
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
1239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1241 MultiStmtArg CatchStmts,
1243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1247 /// \brief Rebuild an Objective-C exception declaration.
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
1253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
1259 /// \brief Build a new Objective-C \@catch statement.
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1264 SourceLocation RParenLoc,
1267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1271 /// \brief Build a new Objective-C \@finally statement.
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
1275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1280 /// \brief Build a new Objective-C \@throw statement.
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
1284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1289 /// \brief Build a new OpenMP parallel directive.
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
1293 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1295 SourceLocation StartLoc,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1301 /// \brief Build a new OpenMP 'default' clause.
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
1305 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1306 SourceLocation KindKwLoc,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1311 StartLoc, LParenLoc, EndLoc);
1314 /// \brief Build a new OpenMP 'private' clause.
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1326 /// \brief Build a new OpenMP 'firstprivate' clause.
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1331 SourceLocation StartLoc,
1332 SourceLocation LParenLoc,
1333 SourceLocation EndLoc) {
1334 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1338 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1339 SourceLocation StartLoc,
1340 SourceLocation LParenLoc,
1341 SourceLocation EndLoc) {
1342 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1346 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1348 /// By default, performs semantic analysis to build the new statement.
1349 /// Subclasses may override this routine to provide different behavior.
1350 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1352 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1355 /// \brief Build a new Objective-C \@synchronized statement.
1357 /// By default, performs semantic analysis to build the new statement.
1358 /// Subclasses may override this routine to provide different behavior.
1359 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1360 Expr *Object, Stmt *Body) {
1361 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1364 /// \brief Build a new Objective-C \@autoreleasepool statement.
1366 /// By default, performs semantic analysis to build the new statement.
1367 /// Subclasses may override this routine to provide different behavior.
1368 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1370 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1373 /// \brief Build a new Objective-C fast enumeration statement.
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
1377 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1380 SourceLocation RParenLoc,
1382 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1386 if (ForEachStmt.isInvalid())
1389 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
1392 /// \brief Build a new C++ exception declaration.
1394 /// By default, performs semantic analysis to build the new decaration.
1395 /// Subclasses may override this routine to provide different behavior.
1396 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1397 TypeSourceInfo *Declarator,
1398 SourceLocation StartLoc,
1399 SourceLocation IdLoc,
1400 IdentifierInfo *Id) {
1401 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1402 StartLoc, IdLoc, Id);
1404 getSema().CurContext->addDecl(Var);
1408 /// \brief Build a new C++ catch statement.
1410 /// By default, performs semantic analysis to build the new statement.
1411 /// Subclasses may override this routine to provide different behavior.
1412 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1413 VarDecl *ExceptionDecl,
1415 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1419 /// \brief Build a new C++ try statement.
1421 /// By default, performs semantic analysis to build the new statement.
1422 /// Subclasses may override this routine to provide different behavior.
1423 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1424 ArrayRef<Stmt *> Handlers) {
1425 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1428 /// \brief Build a new C++0x range-based for statement.
1430 /// By default, performs semantic analysis to build the new statement.
1431 /// Subclasses may override this routine to provide different behavior.
1432 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1433 SourceLocation ColonLoc,
1434 Stmt *Range, Stmt *BeginEnd,
1435 Expr *Cond, Expr *Inc,
1437 SourceLocation RParenLoc) {
1438 // If we've just learned that the range is actually an Objective-C
1439 // collection, treat this as an Objective-C fast enumeration loop.
1440 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1441 if (RangeStmt->isSingleDecl()) {
1442 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1443 if (RangeVar->isInvalidDecl())
1446 Expr *RangeExpr = RangeVar->getInit();
1447 if (!RangeExpr->isTypeDependent() &&
1448 RangeExpr->getType()->isObjCObjectPointerType())
1449 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1455 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1456 Cond, Inc, LoopVar, RParenLoc,
1457 Sema::BFRK_Rebuild);
1460 /// \brief Build a new C++0x range-based for statement.
1462 /// By default, performs semantic analysis to build the new statement.
1463 /// Subclasses may override this routine to provide different behavior.
1464 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1466 NestedNameSpecifierLoc QualifierLoc,
1467 DeclarationNameInfo NameInfo,
1469 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1470 QualifierLoc, NameInfo, Nested);
1473 /// \brief Attach body to a C++0x range-based for statement.
1475 /// By default, performs semantic analysis to finish the new statement.
1476 /// Subclasses may override this routine to provide different behavior.
1477 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1478 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1481 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1482 Stmt *TryBlock, Stmt *Handler) {
1483 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
1486 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
1488 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
1491 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1492 return getSema().ActOnSEHFinallyBlock(Loc, Block);
1495 /// \brief Build a new expression that references a declaration.
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
1499 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1502 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1506 /// \brief Build a new expression that references a declaration.
1508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
1510 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1512 const DeclarationNameInfo &NameInfo,
1513 TemplateArgumentListInfo *TemplateArgs) {
1515 SS.Adopt(QualifierLoc);
1517 // FIXME: loses template args.
1519 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1522 /// \brief Build a new expression in parentheses.
1524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
1526 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1527 SourceLocation RParen) {
1528 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1531 /// \brief Build a new pseudo-destructor expression.
1533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
1535 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1536 SourceLocation OperatorLoc,
1539 TypeSourceInfo *ScopeType,
1540 SourceLocation CCLoc,
1541 SourceLocation TildeLoc,
1542 PseudoDestructorTypeStorage Destroyed);
1544 /// \brief Build a new unary operator expression.
1546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
1548 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1549 UnaryOperatorKind Opc,
1551 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1554 /// \brief Build a new builtin offsetof expression.
1556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
1558 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1559 TypeSourceInfo *Type,
1560 Sema::OffsetOfComponent *Components,
1561 unsigned NumComponents,
1562 SourceLocation RParenLoc) {
1563 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1564 NumComponents, RParenLoc);
1567 /// \brief Build a new sizeof, alignof or vec_step expression with a
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
1572 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1573 SourceLocation OpLoc,
1574 UnaryExprOrTypeTrait ExprKind,
1576 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1579 /// \brief Build a new sizeof, alignof or vec step expression with an
1580 /// expression argument.
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
1584 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1585 UnaryExprOrTypeTrait ExprKind,
1588 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1589 if (Result.isInvalid())
1595 /// \brief Build a new array subscript expression.
1597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
1599 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1600 SourceLocation LBracketLoc,
1602 SourceLocation RBracketLoc) {
1603 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1608 /// \brief Build a new call expression.
1610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
1612 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1614 SourceLocation RParenLoc,
1615 Expr *ExecConfig = 0) {
1616 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1617 Args, RParenLoc, ExecConfig);
1620 /// \brief Build a new member access expression.
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
1624 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1626 NestedNameSpecifierLoc QualifierLoc,
1627 SourceLocation TemplateKWLoc,
1628 const DeclarationNameInfo &MemberNameInfo,
1630 NamedDecl *FoundDecl,
1631 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1632 NamedDecl *FirstQualifierInScope) {
1633 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1635 if (!Member->getDeclName()) {
1636 // We have a reference to an unnamed field. This is always the
1637 // base of an anonymous struct/union member access, i.e. the
1638 // field is always of record type.
1639 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1640 assert(Member->getType()->isRecordType() &&
1641 "unnamed member not of record type?");
1644 getSema().PerformObjectMemberConversion(BaseResult.take(),
1645 QualifierLoc.getNestedNameSpecifier(),
1647 if (BaseResult.isInvalid())
1649 Base = BaseResult.take();
1650 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
1652 new (getSema().Context) MemberExpr(Base, isArrow,
1653 Member, MemberNameInfo,
1654 cast<FieldDecl>(Member)->getType(),
1656 return getSema().Owned(ME);
1660 SS.Adopt(QualifierLoc);
1662 Base = BaseResult.take();
1663 QualType BaseType = Base->getType();
1665 // FIXME: this involves duplicating earlier analysis in a lot of
1666 // cases; we should avoid this when possible.
1667 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
1668 R.addDecl(FoundDecl);
1671 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1673 FirstQualifierInScope,
1674 R, ExplicitTemplateArgs);
1677 /// \brief Build a new binary operator expression.
1679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
1681 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1682 BinaryOperatorKind Opc,
1683 Expr *LHS, Expr *RHS) {
1684 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1687 /// \brief Build a new conditional operator expression.
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
1691 ExprResult RebuildConditionalOperator(Expr *Cond,
1692 SourceLocation QuestionLoc,
1694 SourceLocation ColonLoc,
1696 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1700 /// \brief Build a new C-style cast expression.
1702 /// By default, performs semantic analysis to build the new expression.
1703 /// Subclasses may override this routine to provide different behavior.
1704 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1705 TypeSourceInfo *TInfo,
1706 SourceLocation RParenLoc,
1708 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1712 /// \brief Build a new compound literal expression.
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
1716 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1717 TypeSourceInfo *TInfo,
1718 SourceLocation RParenLoc,
1720 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1724 /// \brief Build a new extended vector element access expression.
1726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
1728 ExprResult RebuildExtVectorElementExpr(Expr *Base,
1729 SourceLocation OpLoc,
1730 SourceLocation AccessorLoc,
1731 IdentifierInfo &Accessor) {
1734 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
1735 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1736 OpLoc, /*IsArrow*/ false,
1737 SS, SourceLocation(),
1738 /*FirstQualifierInScope*/ 0,
1740 /* TemplateArgs */ 0);
1743 /// \brief Build a new initializer list expression.
1745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
1747 ExprResult RebuildInitList(SourceLocation LBraceLoc,
1749 SourceLocation RBraceLoc,
1750 QualType ResultTy) {
1752 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
1753 if (Result.isInvalid() || ResultTy->isDependentType())
1756 // Patch in the result type we were given, which may have been computed
1757 // when the initial InitListExpr was built.
1758 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1759 ILE->setType(ResultTy);
1763 /// \brief Build a new designated initializer expression.
1765 /// By default, performs semantic analysis to build the new expression.
1766 /// Subclasses may override this routine to provide different behavior.
1767 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1768 MultiExprArg ArrayExprs,
1769 SourceLocation EqualOrColonLoc,
1773 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1775 if (Result.isInvalid())
1781 /// \brief Build a new value-initialized expression.
1783 /// By default, builds the implicit value initialization without performing
1784 /// any semantic analysis. Subclasses may override this routine to provide
1785 /// different behavior.
1786 ExprResult RebuildImplicitValueInitExpr(QualType T) {
1787 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1790 /// \brief Build a new \c va_arg expression.
1792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
1794 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
1795 Expr *SubExpr, TypeSourceInfo *TInfo,
1796 SourceLocation RParenLoc) {
1797 return getSema().BuildVAArgExpr(BuiltinLoc,
1802 /// \brief Build a new expression list in parentheses.
1804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
1806 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1807 MultiExprArg SubExprs,
1808 SourceLocation RParenLoc) {
1809 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
1812 /// \brief Build a new address-of-label expression.
1814 /// By default, performs semantic analysis, using the name of the label
1815 /// rather than attempting to map the label statement itself.
1816 /// Subclasses may override this routine to provide different behavior.
1817 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1818 SourceLocation LabelLoc, LabelDecl *Label) {
1819 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
1822 /// \brief Build a new GNU statement expression.
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
1826 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1828 SourceLocation RParenLoc) {
1829 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1832 /// \brief Build a new __builtin_choose_expr expression.
1834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
1836 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1837 Expr *Cond, Expr *LHS, Expr *RHS,
1838 SourceLocation RParenLoc) {
1839 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1844 /// \brief Build a new generic selection expression.
1846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
1848 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1849 SourceLocation DefaultLoc,
1850 SourceLocation RParenLoc,
1851 Expr *ControllingExpr,
1852 ArrayRef<TypeSourceInfo *> Types,
1853 ArrayRef<Expr *> Exprs) {
1854 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1855 ControllingExpr, Types, Exprs);
1858 /// \brief Build a new overloaded operator call expression.
1860 /// By default, performs semantic analysis to build the new expression.
1861 /// The semantic analysis provides the behavior of template instantiation,
1862 /// copying with transformations that turn what looks like an overloaded
1863 /// operator call into a use of a builtin operator, performing
1864 /// argument-dependent lookup, etc. Subclasses may override this routine to
1865 /// provide different behavior.
1866 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1867 SourceLocation OpLoc,
1872 /// \brief Build a new C++ "named" cast expression, such as static_cast or
1873 /// reinterpret_cast.
1875 /// By default, this routine dispatches to one of the more-specific routines
1876 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1877 /// Subclasses may override this routine to provide different behavior.
1878 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1879 Stmt::StmtClass Class,
1880 SourceLocation LAngleLoc,
1881 TypeSourceInfo *TInfo,
1882 SourceLocation RAngleLoc,
1883 SourceLocation LParenLoc,
1885 SourceLocation RParenLoc) {
1887 case Stmt::CXXStaticCastExprClass:
1888 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
1889 RAngleLoc, LParenLoc,
1890 SubExpr, RParenLoc);
1892 case Stmt::CXXDynamicCastExprClass:
1893 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
1894 RAngleLoc, LParenLoc,
1895 SubExpr, RParenLoc);
1897 case Stmt::CXXReinterpretCastExprClass:
1898 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
1899 RAngleLoc, LParenLoc,
1903 case Stmt::CXXConstCastExprClass:
1904 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
1905 RAngleLoc, LParenLoc,
1906 SubExpr, RParenLoc);
1909 llvm_unreachable("Invalid C++ named cast");
1913 /// \brief Build a new C++ static_cast expression.
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
1917 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1918 SourceLocation LAngleLoc,
1919 TypeSourceInfo *TInfo,
1920 SourceLocation RAngleLoc,
1921 SourceLocation LParenLoc,
1923 SourceLocation RParenLoc) {
1924 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1926 SourceRange(LAngleLoc, RAngleLoc),
1927 SourceRange(LParenLoc, RParenLoc));
1930 /// \brief Build a new C++ dynamic_cast expression.
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
1934 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1935 SourceLocation LAngleLoc,
1936 TypeSourceInfo *TInfo,
1937 SourceLocation RAngleLoc,
1938 SourceLocation LParenLoc,
1940 SourceLocation RParenLoc) {
1941 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1943 SourceRange(LAngleLoc, RAngleLoc),
1944 SourceRange(LParenLoc, RParenLoc));
1947 /// \brief Build a new C++ reinterpret_cast expression.
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
1951 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1952 SourceLocation LAngleLoc,
1953 TypeSourceInfo *TInfo,
1954 SourceLocation RAngleLoc,
1955 SourceLocation LParenLoc,
1957 SourceLocation RParenLoc) {
1958 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1960 SourceRange(LAngleLoc, RAngleLoc),
1961 SourceRange(LParenLoc, RParenLoc));
1964 /// \brief Build a new C++ const_cast expression.
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
1968 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1969 SourceLocation LAngleLoc,
1970 TypeSourceInfo *TInfo,
1971 SourceLocation RAngleLoc,
1972 SourceLocation LParenLoc,
1974 SourceLocation RParenLoc) {
1975 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1977 SourceRange(LAngleLoc, RAngleLoc),
1978 SourceRange(LParenLoc, RParenLoc));
1981 /// \brief Build a new C++ functional-style cast expression.
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
1985 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1986 SourceLocation LParenLoc,
1988 SourceLocation RParenLoc) {
1989 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1990 MultiExprArg(&Sub, 1),
1994 /// \brief Build a new C++ typeid(type) expression.
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
1998 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1999 SourceLocation TypeidLoc,
2000 TypeSourceInfo *Operand,
2001 SourceLocation RParenLoc) {
2002 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2007 /// \brief Build a new C++ typeid(expr) expression.
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
2011 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2012 SourceLocation TypeidLoc,
2014 SourceLocation RParenLoc) {
2015 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2019 /// \brief Build a new C++ __uuidof(type) expression.
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
2023 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2024 SourceLocation TypeidLoc,
2025 TypeSourceInfo *Operand,
2026 SourceLocation RParenLoc) {
2027 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2031 /// \brief Build a new C++ __uuidof(expr) expression.
2033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
2035 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2036 SourceLocation TypeidLoc,
2038 SourceLocation RParenLoc) {
2039 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2043 /// \brief Build a new C++ "this" expression.
2045 /// By default, builds a new "this" expression without performing any
2046 /// semantic analysis. Subclasses may override this routine to provide
2047 /// different behavior.
2048 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
2051 getSema().CheckCXXThisCapture(ThisLoc);
2052 return getSema().Owned(
2053 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2057 /// \brief Build a new C++ throw expression.
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
2061 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2062 bool IsThrownVariableInScope) {
2063 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2066 /// \brief Build a new C++ default-argument expression.
2068 /// By default, builds a new default-argument expression, which does not
2069 /// require any semantic analysis. Subclasses may override this routine to
2070 /// provide different behavior.
2071 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
2072 ParmVarDecl *Param) {
2073 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2077 /// \brief Build a new C++11 default-initialization expression.
2079 /// By default, builds a new default field initialization expression, which
2080 /// does not require any semantic analysis. Subclasses may override this
2081 /// routine to provide different behavior.
2082 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2084 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2088 /// \brief Build a new C++ zero-initialization expression.
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
2092 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2093 SourceLocation LParenLoc,
2094 SourceLocation RParenLoc) {
2095 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2099 /// \brief Build a new C++ "new" expression.
2101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
2103 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
2105 SourceLocation PlacementLParen,
2106 MultiExprArg PlacementArgs,
2107 SourceLocation PlacementRParen,
2108 SourceRange TypeIdParens,
2109 QualType AllocatedType,
2110 TypeSourceInfo *AllocatedTypeInfo,
2112 SourceRange DirectInitRange,
2113 Expr *Initializer) {
2114 return getSema().BuildCXXNew(StartLoc, UseGlobal,
2126 /// \brief Build a new C++ "delete" expression.
2128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
2130 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2131 bool IsGlobalDelete,
2134 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2138 /// \brief Build a new unary type trait expression.
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
2142 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
2143 SourceLocation StartLoc,
2145 SourceLocation RParenLoc) {
2146 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
2149 /// \brief Build a new binary type trait expression.
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
2153 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2154 SourceLocation StartLoc,
2155 TypeSourceInfo *LhsT,
2156 TypeSourceInfo *RhsT,
2157 SourceLocation RParenLoc) {
2158 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2161 /// \brief Build a new type trait expression.
2163 /// By default, performs semantic analysis to build the new expression.
2164 /// Subclasses may override this routine to provide different behavior.
2165 ExprResult RebuildTypeTrait(TypeTrait Trait,
2166 SourceLocation StartLoc,
2167 ArrayRef<TypeSourceInfo *> Args,
2168 SourceLocation RParenLoc) {
2169 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2172 /// \brief Build a new array type trait expression.
2174 /// By default, performs semantic analysis to build the new expression.
2175 /// Subclasses may override this routine to provide different behavior.
2176 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2177 SourceLocation StartLoc,
2178 TypeSourceInfo *TSInfo,
2180 SourceLocation RParenLoc) {
2181 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2184 /// \brief Build a new expression trait expression.
2186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
2188 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2189 SourceLocation StartLoc,
2191 SourceLocation RParenLoc) {
2192 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2195 /// \brief Build a new (previously unresolved) declaration reference
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
2200 ExprResult RebuildDependentScopeDeclRefExpr(
2201 NestedNameSpecifierLoc QualifierLoc,
2202 SourceLocation TemplateKWLoc,
2203 const DeclarationNameInfo &NameInfo,
2204 const TemplateArgumentListInfo *TemplateArgs,
2205 bool IsAddressOfOperand) {
2207 SS.Adopt(QualifierLoc);
2209 if (TemplateArgs || TemplateKWLoc.isValid())
2210 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
2211 NameInfo, TemplateArgs);
2213 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2214 IsAddressOfOperand);
2217 /// \brief Build a new template-id expression.
2219 /// By default, performs semantic analysis to build the new expression.
2220 /// Subclasses may override this routine to provide different behavior.
2221 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2222 SourceLocation TemplateKWLoc,
2225 const TemplateArgumentListInfo *TemplateArgs) {
2226 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2230 /// \brief Build a new object-construction expression.
2232 /// By default, performs semantic analysis to build the new expression.
2233 /// Subclasses may override this routine to provide different behavior.
2234 ExprResult RebuildCXXConstructExpr(QualType T,
2236 CXXConstructorDecl *Constructor,
2239 bool HadMultipleCandidates,
2240 bool ListInitialization,
2241 bool RequiresZeroInit,
2242 CXXConstructExpr::ConstructionKind ConstructKind,
2243 SourceRange ParenRange) {
2244 SmallVector<Expr*, 8> ConvertedArgs;
2245 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2249 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
2251 HadMultipleCandidates,
2253 RequiresZeroInit, ConstructKind,
2257 /// \brief Build a new object-construction expression.
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
2261 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2262 SourceLocation LParenLoc,
2264 SourceLocation RParenLoc) {
2265 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2271 /// \brief Build a new object-construction expression.
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
2275 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2276 SourceLocation LParenLoc,
2278 SourceLocation RParenLoc) {
2279 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2285 /// \brief Build a new member reference expression.
2287 /// By default, performs semantic analysis to build the new expression.
2288 /// Subclasses may override this routine to provide different behavior.
2289 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2292 SourceLocation OperatorLoc,
2293 NestedNameSpecifierLoc QualifierLoc,
2294 SourceLocation TemplateKWLoc,
2295 NamedDecl *FirstQualifierInScope,
2296 const DeclarationNameInfo &MemberNameInfo,
2297 const TemplateArgumentListInfo *TemplateArgs) {
2299 SS.Adopt(QualifierLoc);
2301 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2302 OperatorLoc, IsArrow,
2304 FirstQualifierInScope,
2309 /// \brief Build a new member reference expression.
2311 /// By default, performs semantic analysis to build the new expression.
2312 /// Subclasses may override this routine to provide different behavior.
2313 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2314 SourceLocation OperatorLoc,
2316 NestedNameSpecifierLoc QualifierLoc,
2317 SourceLocation TemplateKWLoc,
2318 NamedDecl *FirstQualifierInScope,
2320 const TemplateArgumentListInfo *TemplateArgs) {
2322 SS.Adopt(QualifierLoc);
2324 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2325 OperatorLoc, IsArrow,
2327 FirstQualifierInScope,
2331 /// \brief Build a new noexcept expression.
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
2335 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2336 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2339 /// \brief Build a new expression to compute the length of a parameter pack.
2340 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2341 SourceLocation PackLoc,
2342 SourceLocation RParenLoc,
2343 Optional<unsigned> Length) {
2345 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2346 OperatorLoc, Pack, PackLoc,
2347 RParenLoc, *Length);
2349 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2350 OperatorLoc, Pack, PackLoc,
2354 /// \brief Build a new Objective-C boxed expression.
2356 /// By default, performs semantic analysis to build the new expression.
2357 /// Subclasses may override this routine to provide different behavior.
2358 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2359 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2362 /// \brief Build a new Objective-C array literal.
2364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
2366 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2367 Expr **Elements, unsigned NumElements) {
2368 return getSema().BuildObjCArrayLiteral(Range,
2369 MultiExprArg(Elements, NumElements));
2372 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2373 Expr *Base, Expr *Key,
2374 ObjCMethodDecl *getterMethod,
2375 ObjCMethodDecl *setterMethod) {
2376 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2377 getterMethod, setterMethod);
2380 /// \brief Build a new Objective-C dictionary literal.
2382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
2384 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2385 ObjCDictionaryElement *Elements,
2386 unsigned NumElements) {
2387 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2390 /// \brief Build a new Objective-C \@encode expression.
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
2394 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2395 TypeSourceInfo *EncodeTypeInfo,
2396 SourceLocation RParenLoc) {
2397 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2401 /// \brief Build a new Objective-C class message.
2402 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2404 ArrayRef<SourceLocation> SelectorLocs,
2405 ObjCMethodDecl *Method,
2406 SourceLocation LBracLoc,
2408 SourceLocation RBracLoc) {
2409 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2410 ReceiverTypeInfo->getType(),
2411 /*SuperLoc=*/SourceLocation(),
2412 Sel, Method, LBracLoc, SelectorLocs,
2416 /// \brief Build a new Objective-C instance message.
2417 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2419 ArrayRef<SourceLocation> SelectorLocs,
2420 ObjCMethodDecl *Method,
2421 SourceLocation LBracLoc,
2423 SourceLocation RBracLoc) {
2424 return SemaRef.BuildInstanceMessage(Receiver,
2425 Receiver->getType(),
2426 /*SuperLoc=*/SourceLocation(),
2427 Sel, Method, LBracLoc, SelectorLocs,
2431 /// \brief Build a new Objective-C ivar reference expression.
2433 /// By default, performs semantic analysis to build the new expression.
2434 /// Subclasses may override this routine to provide different behavior.
2435 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2436 SourceLocation IvarLoc,
2437 bool IsArrow, bool IsFreeIvar) {
2438 // FIXME: We lose track of the IsFreeIvar bit.
2440 ExprResult Base = getSema().Owned(BaseArg);
2441 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2442 Sema::LookupMemberName);
2443 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2447 if (Result.isInvalid() || Base.isInvalid())
2453 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2454 /*FIXME:*/IvarLoc, IsArrow,
2455 SS, SourceLocation(),
2456 /*FirstQualifierInScope=*/0,
2458 /*TemplateArgs=*/0);
2461 /// \brief Build a new Objective-C property reference expression.
2463 /// By default, performs semantic analysis to build the new expression.
2464 /// Subclasses may override this routine to provide different behavior.
2465 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2466 ObjCPropertyDecl *Property,
2467 SourceLocation PropertyLoc) {
2469 ExprResult Base = getSema().Owned(BaseArg);
2470 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2471 Sema::LookupMemberName);
2472 bool IsArrow = false;
2473 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2474 /*FIME:*/PropertyLoc,
2476 if (Result.isInvalid() || Base.isInvalid())
2482 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2483 /*FIXME:*/PropertyLoc, IsArrow,
2484 SS, SourceLocation(),
2485 /*FirstQualifierInScope=*/0,
2487 /*TemplateArgs=*/0);
2490 /// \brief Build a new Objective-C property reference expression.
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
2494 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2495 ObjCMethodDecl *Getter,
2496 ObjCMethodDecl *Setter,
2497 SourceLocation PropertyLoc) {
2498 // Since these expressions can only be value-dependent, we do not
2499 // need to perform semantic analysis again.
2501 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2502 VK_LValue, OK_ObjCProperty,
2503 PropertyLoc, Base));
2506 /// \brief Build a new Objective-C "isa" expression.
2508 /// By default, performs semantic analysis to build the new expression.
2509 /// Subclasses may override this routine to provide different behavior.
2510 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2511 SourceLocation OpLoc,
2514 ExprResult Base = getSema().Owned(BaseArg);
2515 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2516 Sema::LookupMemberName);
2517 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2520 if (Result.isInvalid() || Base.isInvalid())
2526 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2528 SS, SourceLocation(),
2529 /*FirstQualifierInScope=*/0,
2531 /*TemplateArgs=*/0);
2534 /// \brief Build a new shuffle vector expression.
2536 /// By default, performs semantic analysis to build the new expression.
2537 /// Subclasses may override this routine to provide different behavior.
2538 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2539 MultiExprArg SubExprs,
2540 SourceLocation RParenLoc) {
2541 // Find the declaration for __builtin_shufflevector
2542 const IdentifierInfo &Name
2543 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2544 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2545 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2546 assert(!Lookup.empty() && "No __builtin_shufflevector?");
2548 // Build a reference to the __builtin_shufflevector builtin
2549 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
2550 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2551 SemaRef.Context.BuiltinFnTy,
2552 VK_RValue, BuiltinLoc);
2553 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2554 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2555 CK_BuiltinFnToFnPtr).take();
2557 // Build the CallExpr
2558 ExprResult TheCall = SemaRef.Owned(
2559 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
2560 Builtin->getCallResultType(),
2561 Expr::getValueKindForType(Builtin->getResultType()),
2564 // Type-check the __builtin_shufflevector expression.
2565 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
2568 /// \brief Build a new convert vector expression.
2569 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2570 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2571 SourceLocation RParenLoc) {
2572 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2573 BuiltinLoc, RParenLoc);
2576 /// \brief Build a new template argument pack expansion.
2578 /// By default, performs semantic analysis to build a new pack expansion
2579 /// for a template argument. Subclasses may override this routine to provide
2580 /// different behavior.
2581 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2582 SourceLocation EllipsisLoc,
2583 Optional<unsigned> NumExpansions) {
2584 switch (Pattern.getArgument().getKind()) {
2585 case TemplateArgument::Expression: {
2587 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2588 EllipsisLoc, NumExpansions);
2589 if (Result.isInvalid())
2590 return TemplateArgumentLoc();
2592 return TemplateArgumentLoc(Result.get(), Result.get());
2595 case TemplateArgument::Template:
2596 return TemplateArgumentLoc(TemplateArgument(
2597 Pattern.getArgument().getAsTemplate(),
2599 Pattern.getTemplateQualifierLoc(),
2600 Pattern.getTemplateNameLoc(),
2603 case TemplateArgument::Null:
2604 case TemplateArgument::Integral:
2605 case TemplateArgument::Declaration:
2606 case TemplateArgument::Pack:
2607 case TemplateArgument::TemplateExpansion:
2608 case TemplateArgument::NullPtr:
2609 llvm_unreachable("Pack expansion pattern has no parameter packs");
2611 case TemplateArgument::Type:
2612 if (TypeSourceInfo *Expansion
2613 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2616 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2621 return TemplateArgumentLoc();
2624 /// \brief Build a new expression pack expansion.
2626 /// By default, performs semantic analysis to build a new pack expansion
2627 /// for an expression. Subclasses may override this routine to provide
2628 /// different behavior.
2629 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2630 Optional<unsigned> NumExpansions) {
2631 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2634 /// \brief Build a new atomic operation expression.
2636 /// By default, performs semantic analysis to build the new expression.
2637 /// Subclasses may override this routine to provide different behavior.
2638 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2639 MultiExprArg SubExprs,
2641 AtomicExpr::AtomicOp Op,
2642 SourceLocation RParenLoc) {
2643 // Just create the expression; there is not any interesting semantic
2644 // analysis here because we can't actually build an AtomicExpr until
2645 // we are sure it is semantically sound.
2646 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
2651 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2652 QualType ObjectType,
2653 NamedDecl *FirstQualifierInScope,
2656 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2657 QualType ObjectType,
2658 NamedDecl *FirstQualifierInScope,
2662 template<typename Derived>
2663 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
2665 return SemaRef.Owned(S);
2667 switch (S->getStmtClass()) {
2668 case Stmt::NoStmtClass: break;
2670 // Transform individual statement nodes
2671 #define STMT(Node, Parent) \
2672 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2673 #define ABSTRACT_STMT(Node)
2674 #define EXPR(Node, Parent)
2675 #include "clang/AST/StmtNodes.inc"
2677 // Transform expressions by calling TransformExpr.
2678 #define STMT(Node, Parent)
2679 #define ABSTRACT_STMT(Stmt)
2680 #define EXPR(Node, Parent) case Stmt::Node##Class:
2681 #include "clang/AST/StmtNodes.inc"
2683 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
2687 return getSema().ActOnExprStmt(E);
2691 return SemaRef.Owned(S);
2694 template<typename Derived>
2695 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2699 switch (S->getClauseKind()) {
2701 // Transform individual clause nodes
2702 #define OPENMP_CLAUSE(Name, Class) \
2703 case OMPC_ ## Name : \
2704 return getDerived().Transform ## Class(cast<Class>(S));
2705 #include "clang/Basic/OpenMPKinds.def"
2712 template<typename Derived>
2713 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2715 return SemaRef.Owned(E);
2717 switch (E->getStmtClass()) {
2718 case Stmt::NoStmtClass: break;
2719 #define STMT(Node, Parent) case Stmt::Node##Class: break;
2720 #define ABSTRACT_STMT(Stmt)
2721 #define EXPR(Node, Parent) \
2722 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
2723 #include "clang/AST/StmtNodes.inc"
2726 return SemaRef.Owned(E);
2729 template<typename Derived>
2730 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2731 bool CXXDirectInit) {
2732 // Initializers are instantiated like expressions, except that various outer
2733 // layers are stripped.
2735 return SemaRef.Owned(Init);
2737 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2738 Init = ExprTemp->getSubExpr();
2740 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2741 Init = MTE->GetTemporaryExpr();
2743 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2744 Init = Binder->getSubExpr();
2746 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2747 Init = ICE->getSubExprAsWritten();
2749 if (CXXStdInitializerListExpr *ILE =
2750 dyn_cast<CXXStdInitializerListExpr>(Init))
2751 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2753 // If this is not a direct-initializer, we only need to reconstruct
2754 // InitListExprs. Other forms of copy-initialization will be a no-op if
2755 // the initializer is already the right type.
2756 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2757 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2758 return getDerived().TransformExpr(Init);
2760 // Revert value-initialization back to empty parens.
2761 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2762 SourceRange Parens = VIE->getSourceRange();
2763 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
2767 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2768 if (isa<ImplicitValueInitExpr>(Init))
2769 return getDerived().RebuildParenListExpr(SourceLocation(), None,
2772 // Revert initialization by constructor back to a parenthesized or braced list
2773 // of expressions. Any other form of initializer can just be reused directly.
2774 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
2775 return getDerived().TransformExpr(Init);
2777 SmallVector<Expr*, 8> NewArgs;
2778 bool ArgChanged = false;
2779 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2780 /*IsCall*/true, NewArgs, &ArgChanged))
2783 // If this was list initialization, revert to list form.
2784 if (Construct->isListInitialization())
2785 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2786 Construct->getLocEnd(),
2787 Construct->getType());
2789 // Build a ParenListExpr to represent anything else.
2790 SourceRange Parens = Construct->getParenOrBraceRange();
2791 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2795 template<typename Derived>
2796 bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2799 SmallVectorImpl<Expr *> &Outputs,
2801 for (unsigned I = 0; I != NumInputs; ++I) {
2802 // If requested, drop call arguments that need to be dropped.
2803 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2810 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2811 Expr *Pattern = Expansion->getPattern();
2813 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2814 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2815 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2817 // Determine whether the set of unexpanded parameter packs can and should
2820 bool RetainExpansion = false;
2821 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2822 Optional<unsigned> NumExpansions = OrigNumExpansions;
2823 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2824 Pattern->getSourceRange(),
2826 Expand, RetainExpansion,
2831 // The transform has determined that we should perform a simple
2832 // transformation on the pack expansion, producing another pack
2834 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2835 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2836 if (OutPattern.isInvalid())
2839 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2840 Expansion->getEllipsisLoc(),
2842 if (Out.isInvalid())
2847 Outputs.push_back(Out.get());
2851 // Record right away that the argument was changed. This needs
2852 // to happen even if the array expands to nothing.
2853 if (ArgChanged) *ArgChanged = true;
2855 // The transform has determined that we should perform an elementwise
2856 // expansion of the pattern. Do so.
2857 for (unsigned I = 0; I != *NumExpansions; ++I) {
2858 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2859 ExprResult Out = getDerived().TransformExpr(Pattern);
2860 if (Out.isInvalid())
2863 if (Out.get()->containsUnexpandedParameterPack()) {
2864 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2866 if (Out.isInvalid())
2870 Outputs.push_back(Out.get());
2877 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2878 : getDerived().TransformExpr(Inputs[I]);
2879 if (Result.isInvalid())
2882 if (Result.get() != Inputs[I] && ArgChanged)
2885 Outputs.push_back(Result.get());
2891 template<typename Derived>
2892 NestedNameSpecifierLoc
2893 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2894 NestedNameSpecifierLoc NNS,
2895 QualType ObjectType,
2896 NamedDecl *FirstQualifierInScope) {
2897 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2898 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2899 Qualifier = Qualifier.getPrefix())
2900 Qualifiers.push_back(Qualifier);
2903 while (!Qualifiers.empty()) {
2904 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2905 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2907 switch (QNNS->getKind()) {
2908 case NestedNameSpecifier::Identifier:
2909 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2910 *QNNS->getAsIdentifier(),
2911 Q.getLocalBeginLoc(),
2913 ObjectType, false, SS,
2914 FirstQualifierInScope, false))
2915 return NestedNameSpecifierLoc();
2919 case NestedNameSpecifier::Namespace: {
2921 = cast_or_null<NamespaceDecl>(
2922 getDerived().TransformDecl(
2923 Q.getLocalBeginLoc(),
2924 QNNS->getAsNamespace()));
2925 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2929 case NestedNameSpecifier::NamespaceAlias: {
2930 NamespaceAliasDecl *Alias
2931 = cast_or_null<NamespaceAliasDecl>(
2932 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2933 QNNS->getAsNamespaceAlias()));
2934 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2935 Q.getLocalEndLoc());
2939 case NestedNameSpecifier::Global:
2940 // There is no meaningful transformation that one could perform on the
2942 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2945 case NestedNameSpecifier::TypeSpecWithTemplate:
2946 case NestedNameSpecifier::TypeSpec: {
2947 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2948 FirstQualifierInScope, SS);
2951 return NestedNameSpecifierLoc();
2953 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2954 (SemaRef.getLangOpts().CPlusPlus11 &&
2955 TL.getType()->isEnumeralType())) {
2956 assert(!TL.getType().hasLocalQualifiers() &&
2957 "Can't get cv-qualifiers here");
2958 if (TL.getType()->isEnumeralType())
2959 SemaRef.Diag(TL.getBeginLoc(),
2960 diag::warn_cxx98_compat_enum_nested_name_spec);
2961 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2962 Q.getLocalEndLoc());
2965 // If the nested-name-specifier is an invalid type def, don't emit an
2966 // error because a previous error should have already been emitted.
2967 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2968 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
2969 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2970 << TL.getType() << SS.getRange();
2972 return NestedNameSpecifierLoc();
2976 // The qualifier-in-scope and object type only apply to the leftmost entity.
2977 FirstQualifierInScope = 0;
2978 ObjectType = QualType();
2981 // Don't rebuild the nested-name-specifier if we don't have to.
2982 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2983 !getDerived().AlwaysRebuild())
2986 // If we can re-use the source-location data from the original
2987 // nested-name-specifier, do so.
2988 if (SS.location_size() == NNS.getDataLength() &&
2989 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2990 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2992 // Allocate new nested-name-specifier location information.
2993 return SS.getWithLocInContext(SemaRef.Context);
2996 template<typename Derived>
2998 TreeTransform<Derived>
2999 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
3000 DeclarationName Name = NameInfo.getName();
3002 return DeclarationNameInfo();
3004 switch (Name.getNameKind()) {
3005 case DeclarationName::Identifier:
3006 case DeclarationName::ObjCZeroArgSelector:
3007 case DeclarationName::ObjCOneArgSelector:
3008 case DeclarationName::ObjCMultiArgSelector:
3009 case DeclarationName::CXXOperatorName:
3010 case DeclarationName::CXXLiteralOperatorName:
3011 case DeclarationName::CXXUsingDirective:
3014 case DeclarationName::CXXConstructorName:
3015 case DeclarationName::CXXDestructorName:
3016 case DeclarationName::CXXConversionFunctionName: {
3017 TypeSourceInfo *NewTInfo;
3018 CanQualType NewCanTy;
3019 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3020 NewTInfo = getDerived().TransformType(OldTInfo);
3022 return DeclarationNameInfo();
3023 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3027 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3028 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3030 return DeclarationNameInfo();
3031 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3034 DeclarationName NewName
3035 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3037 DeclarationNameInfo NewNameInfo(NameInfo);
3038 NewNameInfo.setName(NewName);
3039 NewNameInfo.setNamedTypeInfo(NewTInfo);
3044 llvm_unreachable("Unknown name kind.");
3047 template<typename Derived>
3049 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3051 SourceLocation NameLoc,
3052 QualType ObjectType,
3053 NamedDecl *FirstQualifierInScope) {
3054 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3055 TemplateDecl *Template = QTN->getTemplateDecl();
3056 assert(Template && "qualified template name must refer to a template");
3058 TemplateDecl *TransTemplate
3059 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3062 return TemplateName();
3064 if (!getDerived().AlwaysRebuild() &&
3065 SS.getScopeRep() == QTN->getQualifier() &&
3066 TransTemplate == Template)
3069 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3073 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3074 if (SS.getScopeRep()) {
3075 // These apply to the scope specifier, not the template.
3076 ObjectType = QualType();
3077 FirstQualifierInScope = 0;
3080 if (!getDerived().AlwaysRebuild() &&
3081 SS.getScopeRep() == DTN->getQualifier() &&
3082 ObjectType.isNull())
3085 if (DTN->isIdentifier()) {
3086 return getDerived().RebuildTemplateName(SS,
3087 *DTN->getIdentifier(),
3090 FirstQualifierInScope);
3093 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3097 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3098 TemplateDecl *TransTemplate
3099 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3102 return TemplateName();
3104 if (!getDerived().AlwaysRebuild() &&
3105 TransTemplate == Template)
3108 return TemplateName(TransTemplate);
3111 if (SubstTemplateTemplateParmPackStorage *SubstPack
3112 = Name.getAsSubstTemplateTemplateParmPack()) {
3113 TemplateTemplateParmDecl *TransParam
3114 = cast_or_null<TemplateTemplateParmDecl>(
3115 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3117 return TemplateName();
3119 if (!getDerived().AlwaysRebuild() &&
3120 TransParam == SubstPack->getParameterPack())
3123 return getDerived().RebuildTemplateName(TransParam,
3124 SubstPack->getArgumentPack());
3127 // These should be getting filtered out before they reach the AST.
3128 llvm_unreachable("overloaded function decl survived to here");
3131 template<typename Derived>
3132 void TreeTransform<Derived>::InventTemplateArgumentLoc(
3133 const TemplateArgument &Arg,
3134 TemplateArgumentLoc &Output) {
3135 SourceLocation Loc = getDerived().getBaseLocation();
3136 switch (Arg.getKind()) {
3137 case TemplateArgument::Null:
3138 llvm_unreachable("null template argument in TreeTransform");
3141 case TemplateArgument::Type:
3142 Output = TemplateArgumentLoc(Arg,
3143 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3147 case TemplateArgument::Template:
3148 case TemplateArgument::TemplateExpansion: {
3149 NestedNameSpecifierLocBuilder Builder;
3150 TemplateName Template = Arg.getAsTemplate();
3151 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3152 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3153 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3154 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3156 if (Arg.getKind() == TemplateArgument::Template)
3157 Output = TemplateArgumentLoc(Arg,
3158 Builder.getWithLocInContext(SemaRef.Context),
3161 Output = TemplateArgumentLoc(Arg,
3162 Builder.getWithLocInContext(SemaRef.Context),
3168 case TemplateArgument::Expression:
3169 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3172 case TemplateArgument::Declaration:
3173 case TemplateArgument::Integral:
3174 case TemplateArgument::Pack:
3175 case TemplateArgument::NullPtr:
3176 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
3181 template<typename Derived>
3182 bool TreeTransform<Derived>::TransformTemplateArgument(
3183 const TemplateArgumentLoc &Input,
3184 TemplateArgumentLoc &Output) {
3185 const TemplateArgument &Arg = Input.getArgument();
3186 switch (Arg.getKind()) {
3187 case TemplateArgument::Null:
3188 case TemplateArgument::Integral:
3189 case TemplateArgument::Pack:
3190 case TemplateArgument::Declaration:
3191 case TemplateArgument::NullPtr:
3192 llvm_unreachable("Unexpected TemplateArgument");
3194 case TemplateArgument::Type: {
3195 TypeSourceInfo *DI = Input.getTypeSourceInfo();
3197 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3199 DI = getDerived().TransformType(DI);
3200 if (!DI) return true;
3202 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3206 case TemplateArgument::Template: {
3207 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3209 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3215 SS.Adopt(QualifierLoc);
3216 TemplateName Template
3217 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3218 Input.getTemplateNameLoc());
3219 if (Template.isNull())
3222 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3223 Input.getTemplateNameLoc());
3227 case TemplateArgument::TemplateExpansion:
3228 llvm_unreachable("Caller should expand pack expansions");
3230 case TemplateArgument::Expression: {
3231 // Template argument expressions are constant expressions.
3232 EnterExpressionEvaluationContext Unevaluated(getSema(),
3233 Sema::ConstantEvaluated);
3235 Expr *InputExpr = Input.getSourceExpression();
3236 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3238 ExprResult E = getDerived().TransformExpr(InputExpr);
3239 E = SemaRef.ActOnConstantExpression(E);
3240 if (E.isInvalid()) return true;
3241 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
3246 // Work around bogus GCC warning
3250 /// \brief Iterator adaptor that invents template argument location information
3251 /// for each of the template arguments in its underlying iterator.
3252 template<typename Derived, typename InputIterator>
3253 class TemplateArgumentLocInventIterator {
3254 TreeTransform<Derived> &Self;
3258 typedef TemplateArgumentLoc value_type;
3259 typedef TemplateArgumentLoc reference;
3260 typedef typename std::iterator_traits<InputIterator>::difference_type
3262 typedef std::input_iterator_tag iterator_category;
3265 TemplateArgumentLoc Arg;
3268 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3270 const TemplateArgumentLoc *operator->() const { return &Arg; }
3273 TemplateArgumentLocInventIterator() { }
3275 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3277 : Self(Self), Iter(Iter) { }
3279 TemplateArgumentLocInventIterator &operator++() {
3284 TemplateArgumentLocInventIterator operator++(int) {
3285 TemplateArgumentLocInventIterator Old(*this);
3290 reference operator*() const {
3291 TemplateArgumentLoc Result;
3292 Self.InventTemplateArgumentLoc(*Iter, Result);
3296 pointer operator->() const { return pointer(**this); }
3298 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3299 const TemplateArgumentLocInventIterator &Y) {
3300 return X.Iter == Y.Iter;
3303 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3304 const TemplateArgumentLocInventIterator &Y) {
3305 return X.Iter != Y.Iter;
3309 template<typename Derived>
3310 template<typename InputIterator>
3311 bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3313 TemplateArgumentListInfo &Outputs) {
3314 for (; First != Last; ++First) {
3315 TemplateArgumentLoc Out;
3316 TemplateArgumentLoc In = *First;
3318 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3319 // Unpack argument packs, which we translate them into separate
3321 // FIXME: We could do much better if we could guarantee that the
3322 // TemplateArgumentLocInfo for the pack expansion would be usable for
3323 // all of the template arguments in the argument pack.
3324 typedef TemplateArgumentLocInventIterator<Derived,
3325 TemplateArgument::pack_iterator>
3327 if (TransformTemplateArguments(PackLocIterator(*this,
3328 In.getArgument().pack_begin()),
3329 PackLocIterator(*this,
3330 In.getArgument().pack_end()),
3337 if (In.getArgument().isPackExpansion()) {
3338 // We have a pack expansion, for which we will be substituting into
3340 SourceLocation Ellipsis;
3341 Optional<unsigned> OrigNumExpansions;
3342 TemplateArgumentLoc Pattern
3343 = getSema().getTemplateArgumentPackExpansionPattern(
3344 In, Ellipsis, OrigNumExpansions);
3346 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3347 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3348 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3350 // Determine whether the set of unexpanded parameter packs can and should
3353 bool RetainExpansion = false;
3354 Optional<unsigned> NumExpansions = OrigNumExpansions;
3355 if (getDerived().TryExpandParameterPacks(Ellipsis,
3356 Pattern.getSourceRange(),
3364 // The transform has determined that we should perform a simple
3365 // transformation on the pack expansion, producing another pack
3367 TemplateArgumentLoc OutPattern;
3368 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3369 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3372 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3374 if (Out.getArgument().isNull())
3377 Outputs.addArgument(Out);
3381 // The transform has determined that we should perform an elementwise
3382 // expansion of the pattern. Do so.
3383 for (unsigned I = 0; I != *NumExpansions; ++I) {
3384 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3386 if (getDerived().TransformTemplateArgument(Pattern, Out))
3389 if (Out.getArgument().containsUnexpandedParameterPack()) {
3390 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3392 if (Out.getArgument().isNull())
3396 Outputs.addArgument(Out);
3399 // If we're supposed to retain a pack expansion, do so by temporarily
3400 // forgetting the partially-substituted parameter pack.
3401 if (RetainExpansion) {
3402 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3404 if (getDerived().TransformTemplateArgument(Pattern, Out))
3407 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3409 if (Out.getArgument().isNull())
3412 Outputs.addArgument(Out);
3419 if (getDerived().TransformTemplateArgument(In, Out))
3422 Outputs.addArgument(Out);
3429 //===----------------------------------------------------------------------===//
3430 // Type transformation
3431 //===----------------------------------------------------------------------===//
3433 template<typename Derived>
3434 QualType TreeTransform<Derived>::TransformType(QualType T) {
3435 if (getDerived().AlreadyTransformed(T))
3438 // Temporary workaround. All of these transformations should
3439 // eventually turn into transformations on TypeLocs.
3440 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3441 getDerived().getBaseLocation());
3443 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3448 return NewDI->getType();
3451 template<typename Derived>
3452 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3453 // Refine the base location to the type's location.
3454 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3455 getDerived().getBaseEntity());
3456 if (getDerived().AlreadyTransformed(DI->getType()))
3461 TypeLoc TL = DI->getTypeLoc();
3462 TLB.reserve(TL.getFullDataSize());
3464 QualType Result = getDerived().TransformType(TLB, TL);
3465 if (Result.isNull())
3468 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3471 template<typename Derived>
3473 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3474 switch (T.getTypeLocClass()) {
3475 #define ABSTRACT_TYPELOC(CLASS, PARENT)
3476 #define TYPELOC(CLASS, PARENT) \
3477 case TypeLoc::CLASS: \
3478 return getDerived().Transform##CLASS##Type(TLB, \
3479 T.castAs<CLASS##TypeLoc>());
3480 #include "clang/AST/TypeLocNodes.def"
3483 llvm_unreachable("unhandled type loc!");
3486 /// FIXME: By default, this routine adds type qualifiers only to types
3487 /// that can have qualifiers, and silently suppresses those qualifiers
3488 /// that are not permitted (e.g., qualifiers on reference or function
3489 /// types). This is the right thing for template instantiation, but
3490 /// probably not for other clients.
3491 template<typename Derived>
3493 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
3494 QualifiedTypeLoc T) {
3495 Qualifiers Quals = T.getType().getLocalQualifiers();
3497 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3498 if (Result.isNull())
3501 // Silently suppress qualifiers if the result type can't be qualified.
3502 // FIXME: this is the right thing for template instantiation, but
3503 // probably not for other clients.
3504 if (Result->isFunctionType() || Result->isReferenceType())
3507 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3509 if (Quals.hasObjCLifetime()) {
3510 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3511 Quals.removeObjCLifetime();
3512 else if (Result.getObjCLifetime()) {
3514 // A lifetime qualifier applied to a substituted template parameter
3515 // overrides the lifetime qualifier from the template argument.
3516 const AutoType *AutoTy;
3517 if (const SubstTemplateTypeParmType *SubstTypeParam
3518 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3519 QualType Replacement = SubstTypeParam->getReplacementType();
3520 Qualifiers Qs = Replacement.getQualifiers();
3521 Qs.removeObjCLifetime();
3523 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3525 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3526 SubstTypeParam->getReplacedParameter(),
3528 TLB.TypeWasModifiedSafely(Result);
3529 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3530 // 'auto' types behave the same way as template parameters.
3531 QualType Deduced = AutoTy->getDeducedType();
3532 Qualifiers Qs = Deduced.getQualifiers();
3533 Qs.removeObjCLifetime();
3534 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3536 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3537 AutoTy->isDependentType());
3538 TLB.TypeWasModifiedSafely(Result);
3540 // Otherwise, complain about the addition of a qualifier to an
3541 // already-qualified type.
3542 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
3543 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
3546 Quals.removeObjCLifetime();
3550 if (!Quals.empty()) {
3551 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3552 // BuildQualifiedType might not add qualifiers if they are invalid.
3553 if (Result.hasLocalQualifiers())
3554 TLB.push<QualifiedTypeLoc>(Result);
3555 // No location information to preserve.
3561 template<typename Derived>
3563 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3564 QualType ObjectType,
3565 NamedDecl *UnqualLookup,
3567 QualType T = TL.getType();
3568 if (getDerived().AlreadyTransformed(T))
3574 if (isa<TemplateSpecializationType>(T)) {
3575 TemplateSpecializationTypeLoc SpecTL =
3576 TL.castAs<TemplateSpecializationTypeLoc>();
3578 TemplateName Template =
3579 getDerived().TransformTemplateName(SS,
3580 SpecTL.getTypePtr()->getTemplateName(),
3581 SpecTL.getTemplateNameLoc(),
3582 ObjectType, UnqualLookup);
3583 if (Template.isNull())
3586 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3588 } else if (isa<DependentTemplateSpecializationType>(T)) {
3589 DependentTemplateSpecializationTypeLoc SpecTL =
3590 TL.castAs<DependentTemplateSpecializationTypeLoc>();
3592 TemplateName Template
3593 = getDerived().RebuildTemplateName(SS,
3594 *SpecTL.getTypePtr()->getIdentifier(),
3595 SpecTL.getTemplateNameLoc(),
3596 ObjectType, UnqualLookup);
3597 if (Template.isNull())
3600 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3605 // Nothing special needs to be done for these.
3606 Result = getDerived().TransformType(TLB, TL);
3609 if (Result.isNull())
3612 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3615 template<typename Derived>
3617 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3618 QualType ObjectType,
3619 NamedDecl *UnqualLookup,
3621 // FIXME: Painfully copy-paste from the above!
3623 QualType T = TSInfo->getType();
3624 if (getDerived().AlreadyTransformed(T))
3630 TypeLoc TL = TSInfo->getTypeLoc();
3631 if (isa<TemplateSpecializationType>(T)) {
3632 TemplateSpecializationTypeLoc SpecTL =
3633 TL.castAs<TemplateSpecializationTypeLoc>();
3635 TemplateName Template
3636 = getDerived().TransformTemplateName(SS,
3637 SpecTL.getTypePtr()->getTemplateName(),
3638 SpecTL.getTemplateNameLoc(),
3639 ObjectType, UnqualLookup);
3640 if (Template.isNull())
3643 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3645 } else if (isa<DependentTemplateSpecializationType>(T)) {
3646 DependentTemplateSpecializationTypeLoc SpecTL =
3647 TL.castAs<DependentTemplateSpecializationTypeLoc>();
3649 TemplateName Template
3650 = getDerived().RebuildTemplateName(SS,
3651 *SpecTL.getTypePtr()->getIdentifier(),
3652 SpecTL.getTemplateNameLoc(),
3653 ObjectType, UnqualLookup);
3654 if (Template.isNull())
3657 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3662 // Nothing special needs to be done for these.
3663 Result = getDerived().TransformType(TLB, TL);
3666 if (Result.isNull())
3669 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3672 template <class TyLoc> static inline
3673 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3674 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3675 NewT.setNameLoc(T.getNameLoc());
3679 template<typename Derived>
3680 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
3682 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3683 NewT.setBuiltinLoc(T.getBuiltinLoc());
3684 if (T.needsExtraLocalData())
3685 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3689 template<typename Derived>
3690 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
3693 return TransformTypeSpecType(TLB, T);
3696 template<typename Derived>
3697 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3698 DecayedTypeLoc TL) {
3699 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3700 if (OriginalType.isNull())
3703 QualType Result = TL.getType();
3704 if (getDerived().AlwaysRebuild() ||
3705 OriginalType != TL.getOriginalLoc().getType())
3706 Result = SemaRef.Context.getDecayedType(OriginalType);
3707 TLB.push<DecayedTypeLoc>(Result);
3708 // Nothing to set for DecayedTypeLoc.
3712 template<typename Derived>
3713 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
3714 PointerTypeLoc TL) {
3715 QualType PointeeType
3716 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3717 if (PointeeType.isNull())
3720 QualType Result = TL.getType();
3721 if (PointeeType->getAs<ObjCObjectType>()) {
3722 // A dependent pointer type 'T *' has is being transformed such
3723 // that an Objective-C class type is being replaced for 'T'. The
3724 // resulting pointer type is an ObjCObjectPointerType, not a
3726 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3728 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3729 NewT.setStarLoc(TL.getStarLoc());
3733 if (getDerived().AlwaysRebuild() ||
3734 PointeeType != TL.getPointeeLoc().getType()) {
3735 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3736 if (Result.isNull())
3740 // Objective-C ARC can add lifetime qualifiers to the type that we're
3742 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3744 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3745 NewT.setSigilLoc(TL.getSigilLoc());
3749 template<typename Derived>
3751 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
3752 BlockPointerTypeLoc TL) {
3753 QualType PointeeType
3754 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3755 if (PointeeType.isNull())
3758 QualType Result = TL.getType();
3759 if (getDerived().AlwaysRebuild() ||
3760 PointeeType != TL.getPointeeLoc().getType()) {
3761 Result = getDerived().RebuildBlockPointerType(PointeeType,
3763 if (Result.isNull())
3767 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3768 NewT.setSigilLoc(TL.getSigilLoc());
3772 /// Transforms a reference type. Note that somewhat paradoxically we
3773 /// don't care whether the type itself is an l-value type or an r-value
3774 /// type; we only care if the type was *written* as an l-value type
3775 /// or an r-value type.
3776 template<typename Derived>
3778 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
3779 ReferenceTypeLoc TL) {
3780 const ReferenceType *T = TL.getTypePtr();
3782 // Note that this works with the pointee-as-written.
3783 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3784 if (PointeeType.isNull())
3787 QualType Result = TL.getType();
3788 if (getDerived().AlwaysRebuild() ||
3789 PointeeType != T->getPointeeTypeAsWritten()) {
3790 Result = getDerived().RebuildReferenceType(PointeeType,
3791 T->isSpelledAsLValue(),
3793 if (Result.isNull())
3797 // Objective-C ARC can add lifetime qualifiers to the type that we're
3799 TLB.TypeWasModifiedSafely(
3800 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3802 // r-value references can be rebuilt as l-value references.
3803 ReferenceTypeLoc NewTL;
3804 if (isa<LValueReferenceType>(Result))
3805 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3807 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3808 NewTL.setSigilLoc(TL.getSigilLoc());
3813 template<typename Derived>
3815 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
3816 LValueReferenceTypeLoc TL) {
3817 return TransformReferenceType(TLB, TL);
3820 template<typename Derived>
3822 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
3823 RValueReferenceTypeLoc TL) {
3824 return TransformReferenceType(TLB, TL);
3827 template<typename Derived>
3829 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
3830 MemberPointerTypeLoc TL) {
3831 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3832 if (PointeeType.isNull())
3835 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3836 TypeSourceInfo* NewClsTInfo = 0;
3838 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3843 const MemberPointerType *T = TL.getTypePtr();
3844 QualType OldClsType = QualType(T->getClass(), 0);
3845 QualType NewClsType;
3847 NewClsType = NewClsTInfo->getType();
3849 NewClsType = getDerived().TransformType(OldClsType);
3850 if (NewClsType.isNull())
3854 QualType Result = TL.getType();
3855 if (getDerived().AlwaysRebuild() ||
3856 PointeeType != T->getPointeeType() ||
3857 NewClsType != OldClsType) {
3858 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
3860 if (Result.isNull())
3864 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3865 NewTL.setSigilLoc(TL.getSigilLoc());
3866 NewTL.setClassTInfo(NewClsTInfo);
3871 template<typename Derived>
3873 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
3874 ConstantArrayTypeLoc TL) {
3875 const ConstantArrayType *T = TL.getTypePtr();
3876 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3877 if (ElementType.isNull())
3880 QualType Result = TL.getType();
3881 if (getDerived().AlwaysRebuild() ||
3882 ElementType != T->getElementType()) {
3883 Result = getDerived().RebuildConstantArrayType(ElementType,
3884 T->getSizeModifier(),
3886 T->getIndexTypeCVRQualifiers(),
3887 TL.getBracketsRange());
3888 if (Result.isNull())
3892 // We might have either a ConstantArrayType or a VariableArrayType now:
3893 // a ConstantArrayType is allowed to have an element type which is a
3894 // VariableArrayType if the type is dependent. Fortunately, all array
3895 // types have the same location layout.
3896 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3897 NewTL.setLBracketLoc(TL.getLBracketLoc());
3898 NewTL.setRBracketLoc(TL.getRBracketLoc());
3900 Expr *Size = TL.getSizeExpr();
3902 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3903 Sema::ConstantEvaluated);
3904 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3905 Size = SemaRef.ActOnConstantExpression(Size).take();
3907 NewTL.setSizeExpr(Size);
3912 template<typename Derived>
3913 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
3914 TypeLocBuilder &TLB,
3915 IncompleteArrayTypeLoc TL) {
3916 const IncompleteArrayType *T = TL.getTypePtr();
3917 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3918 if (ElementType.isNull())
3921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 ElementType != T->getElementType()) {
3924 Result = getDerived().RebuildIncompleteArrayType(ElementType,
3925 T->getSizeModifier(),
3926 T->getIndexTypeCVRQualifiers(),
3927 TL.getBracketsRange());
3928 if (Result.isNull())
3932 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3933 NewTL.setLBracketLoc(TL.getLBracketLoc());
3934 NewTL.setRBracketLoc(TL.getRBracketLoc());
3935 NewTL.setSizeExpr(0);
3940 template<typename Derived>
3942 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
3943 VariableArrayTypeLoc TL) {
3944 const VariableArrayType *T = TL.getTypePtr();
3945 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3946 if (ElementType.isNull())
3949 ExprResult SizeResult
3950 = getDerived().TransformExpr(T->getSizeExpr());
3951 if (SizeResult.isInvalid())
3954 Expr *Size = SizeResult.take();
3956 QualType Result = TL.getType();
3957 if (getDerived().AlwaysRebuild() ||
3958 ElementType != T->getElementType() ||
3959 Size != T->getSizeExpr()) {
3960 Result = getDerived().RebuildVariableArrayType(ElementType,
3961 T->getSizeModifier(),
3963 T->getIndexTypeCVRQualifiers(),
3964 TL.getBracketsRange());
3965 if (Result.isNull())
3969 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3970 NewTL.setLBracketLoc(TL.getLBracketLoc());
3971 NewTL.setRBracketLoc(TL.getRBracketLoc());
3972 NewTL.setSizeExpr(Size);
3977 template<typename Derived>
3979 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
3980 DependentSizedArrayTypeLoc TL) {
3981 const DependentSizedArrayType *T = TL.getTypePtr();
3982 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3983 if (ElementType.isNull())
3986 // Array bounds are constant expressions.
3987 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3988 Sema::ConstantEvaluated);
3990 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3991 Expr *origSize = TL.getSizeExpr();
3992 if (!origSize) origSize = T->getSizeExpr();
3994 ExprResult sizeResult
3995 = getDerived().TransformExpr(origSize);
3996 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
3997 if (sizeResult.isInvalid())
4000 Expr *size = sizeResult.get();
4002 QualType Result = TL.getType();
4003 if (getDerived().AlwaysRebuild() ||
4004 ElementType != T->getElementType() ||
4006 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4007 T->getSizeModifier(),
4009 T->getIndexTypeCVRQualifiers(),
4010 TL.getBracketsRange());
4011 if (Result.isNull())
4015 // We might have any sort of array type now, but fortunately they
4016 // all have the same location layout.
4017 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4018 NewTL.setLBracketLoc(TL.getLBracketLoc());
4019 NewTL.setRBracketLoc(TL.getRBracketLoc());
4020 NewTL.setSizeExpr(size);
4025 template<typename Derived>
4026 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4027 TypeLocBuilder &TLB,
4028 DependentSizedExtVectorTypeLoc TL) {
4029 const DependentSizedExtVectorType *T = TL.getTypePtr();
4031 // FIXME: ext vector locs should be nested
4032 QualType ElementType = getDerived().TransformType(T->getElementType());
4033 if (ElementType.isNull())
4036 // Vector sizes are constant expressions.
4037 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4038 Sema::ConstantEvaluated);
4040 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4041 Size = SemaRef.ActOnConstantExpression(Size);
4042 if (Size.isInvalid())
4045 QualType Result = TL.getType();
4046 if (getDerived().AlwaysRebuild() ||
4047 ElementType != T->getElementType() ||
4048 Size.get() != T->getSizeExpr()) {
4049 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4051 T->getAttributeLoc());
4052 if (Result.isNull())
4056 // Result might be dependent or not.
4057 if (isa<DependentSizedExtVectorType>(Result)) {
4058 DependentSizedExtVectorTypeLoc NewTL
4059 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4060 NewTL.setNameLoc(TL.getNameLoc());
4062 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4063 NewTL.setNameLoc(TL.getNameLoc());
4069 template<typename Derived>
4070 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4072 const VectorType *T = TL.getTypePtr();
4073 QualType ElementType = getDerived().TransformType(T->getElementType());
4074 if (ElementType.isNull())
4077 QualType Result = TL.getType();
4078 if (getDerived().AlwaysRebuild() ||
4079 ElementType != T->getElementType()) {
4080 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4081 T->getVectorKind());
4082 if (Result.isNull())
4086 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4087 NewTL.setNameLoc(TL.getNameLoc());
4092 template<typename Derived>
4093 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4094 ExtVectorTypeLoc TL) {
4095 const VectorType *T = TL.getTypePtr();
4096 QualType ElementType = getDerived().TransformType(T->getElementType());
4097 if (ElementType.isNull())
4100 QualType Result = TL.getType();
4101 if (getDerived().AlwaysRebuild() ||
4102 ElementType != T->getElementType()) {
4103 Result = getDerived().RebuildExtVectorType(ElementType,
4104 T->getNumElements(),
4105 /*FIXME*/ SourceLocation());
4106 if (Result.isNull())
4110 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4111 NewTL.setNameLoc(TL.getNameLoc());
4116 template <typename Derived>
4117 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4118 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4119 bool ExpectParameterPack) {
4120 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4121 TypeSourceInfo *NewDI = 0;
4123 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4124 // If we're substituting into a pack expansion type and we know the
4125 // length we want to expand to, just substitute for the pattern.
4126 TypeLoc OldTL = OldDI->getTypeLoc();
4127 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4130 TypeLoc NewTL = OldDI->getTypeLoc();
4131 TLB.reserve(NewTL.getFullDataSize());
4133 QualType Result = getDerived().TransformType(TLB,
4134 OldExpansionTL.getPatternLoc());
4135 if (Result.isNull())
4138 Result = RebuildPackExpansionType(Result,
4139 OldExpansionTL.getPatternLoc().getSourceRange(),
4140 OldExpansionTL.getEllipsisLoc(),
4142 if (Result.isNull())
4145 PackExpansionTypeLoc NewExpansionTL
4146 = TLB.push<PackExpansionTypeLoc>(Result);
4147 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4148 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4150 NewDI = getDerived().TransformType(OldDI);
4154 if (NewDI == OldDI && indexAdjustment == 0)
4157 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4158 OldParm->getDeclContext(),
4159 OldParm->getInnerLocStart(),
4160 OldParm->getLocation(),
4161 OldParm->getIdentifier(),
4164 OldParm->getStorageClass(),
4166 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4167 OldParm->getFunctionScopeIndex() + indexAdjustment);
4171 template<typename Derived>
4172 bool TreeTransform<Derived>::
4173 TransformFunctionTypeParams(SourceLocation Loc,
4174 ParmVarDecl **Params, unsigned NumParams,
4175 const QualType *ParamTypes,
4176 SmallVectorImpl<QualType> &OutParamTypes,
4177 SmallVectorImpl<ParmVarDecl*> *PVars) {
4178 int indexAdjustment = 0;
4180 for (unsigned i = 0; i != NumParams; ++i) {
4181 if (ParmVarDecl *OldParm = Params[i]) {
4182 assert(OldParm->getFunctionScopeIndex() == i);
4184 Optional<unsigned> NumExpansions;
4185 ParmVarDecl *NewParm = 0;
4186 if (OldParm->isParameterPack()) {
4187 // We have a function parameter pack that may need to be expanded.
4188 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4190 // Find the parameter packs that could be expanded.
4191 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4192 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4193 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4194 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4195 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4197 // Determine whether we should expand the parameter packs.
4198 bool ShouldExpand = false;
4199 bool RetainExpansion = false;
4200 Optional<unsigned> OrigNumExpansions =
4201 ExpansionTL.getTypePtr()->getNumExpansions();
4202 NumExpansions = OrigNumExpansions;
4203 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4204 Pattern.getSourceRange(),
4213 // Expand the function parameter pack into multiple, separate
4215 getDerived().ExpandingFunctionParameterPack(OldParm);
4216 for (unsigned I = 0; I != *NumExpansions; ++I) {
4217 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4218 ParmVarDecl *NewParm
4219 = getDerived().TransformFunctionTypeParam(OldParm,
4222 /*ExpectParameterPack=*/false);
4226 OutParamTypes.push_back(NewParm->getType());
4228 PVars->push_back(NewParm);
4231 // If we're supposed to retain a pack expansion, do so by temporarily
4232 // forgetting the partially-substituted parameter pack.
4233 if (RetainExpansion) {
4234 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4235 ParmVarDecl *NewParm
4236 = getDerived().TransformFunctionTypeParam(OldParm,
4239 /*ExpectParameterPack=*/false);
4243 OutParamTypes.push_back(NewParm->getType());
4245 PVars->push_back(NewParm);
4248 // The next parameter should have the same adjustment as the
4249 // last thing we pushed, but we post-incremented indexAdjustment
4250 // on every push. Also, if we push nothing, the adjustment should
4254 // We're done with the pack expansion.
4258 // We'll substitute the parameter now without expanding the pack
4260 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4261 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4264 /*ExpectParameterPack=*/true);
4266 NewParm = getDerived().TransformFunctionTypeParam(
4267 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4273 OutParamTypes.push_back(NewParm->getType());
4275 PVars->push_back(NewParm);
4279 // Deal with the possibility that we don't have a parameter
4280 // declaration for this parameter.
4281 QualType OldType = ParamTypes[i];
4282 bool IsPackExpansion = false;
4283 Optional<unsigned> NumExpansions;
4285 if (const PackExpansionType *Expansion
4286 = dyn_cast<PackExpansionType>(OldType)) {
4287 // We have a function parameter pack that may need to be expanded.
4288 QualType Pattern = Expansion->getPattern();
4289 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4290 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4292 // Determine whether we should expand the parameter packs.
4293 bool ShouldExpand = false;
4294 bool RetainExpansion = false;
4295 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4304 // Expand the function parameter pack into multiple, separate
4306 for (unsigned I = 0; I != *NumExpansions; ++I) {
4307 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4308 QualType NewType = getDerived().TransformType(Pattern);
4309 if (NewType.isNull())
4312 OutParamTypes.push_back(NewType);
4314 PVars->push_back(0);
4317 // We're done with the pack expansion.
4321 // If we're supposed to retain a pack expansion, do so by temporarily
4322 // forgetting the partially-substituted parameter pack.
4323 if (RetainExpansion) {
4324 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4325 QualType NewType = getDerived().TransformType(Pattern);
4326 if (NewType.isNull())
4329 OutParamTypes.push_back(NewType);
4331 PVars->push_back(0);
4334 // We'll substitute the parameter now without expanding the pack
4336 OldType = Expansion->getPattern();
4337 IsPackExpansion = true;
4338 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4339 NewType = getDerived().TransformType(OldType);
4341 NewType = getDerived().TransformType(OldType);
4344 if (NewType.isNull())
4347 if (IsPackExpansion)
4348 NewType = getSema().Context.getPackExpansionType(NewType,
4351 OutParamTypes.push_back(NewType);
4353 PVars->push_back(0);
4358 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4359 if (ParmVarDecl *parm = (*PVars)[i])
4360 assert(parm->getFunctionScopeIndex() == i);
4367 template<typename Derived>
4369 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4370 FunctionProtoTypeLoc TL) {
4371 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4374 template<typename Derived>
4376 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4377 FunctionProtoTypeLoc TL,
4378 CXXRecordDecl *ThisContext,
4379 unsigned ThisTypeQuals) {
4380 // Transform the parameters and return type.
4382 // We are required to instantiate the params and return type in source order.
4383 // When the function has a trailing return type, we instantiate the
4384 // parameters before the return type, since the return type can then refer
4385 // to the parameters themselves (via decltype, sizeof, etc.).
4387 SmallVector<QualType, 4> ParamTypes;
4388 SmallVector<ParmVarDecl*, 4> ParamDecls;
4389 const FunctionProtoType *T = TL.getTypePtr();
4391 QualType ResultType;
4393 if (T->hasTrailingReturn()) {
4394 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4397 TL.getTypePtr()->arg_type_begin(),
4398 ParamTypes, &ParamDecls))
4402 // C++11 [expr.prim.general]p3:
4403 // If a declaration declares a member function or member function
4404 // template of a class X, the expression this is a prvalue of type
4405 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4406 // and the end of the function-definition, member-declarator, or
4408 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4410 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4411 if (ResultType.isNull())
4416 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4417 if (ResultType.isNull())
4420 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4423 TL.getTypePtr()->arg_type_begin(),
4424 ParamTypes, &ParamDecls))
4428 // FIXME: Need to transform the exception-specification too.
4430 QualType Result = TL.getType();
4431 if (getDerived().AlwaysRebuild() ||
4432 ResultType != T->getResultType() ||
4433 T->getNumArgs() != ParamTypes.size() ||
4434 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4435 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4436 T->getExtProtoInfo());
4437 if (Result.isNull())
4441 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4442 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4443 NewTL.setLParenLoc(TL.getLParenLoc());
4444 NewTL.setRParenLoc(TL.getRParenLoc());
4445 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4446 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4447 NewTL.setArg(i, ParamDecls[i]);
4452 template<typename Derived>
4453 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4454 TypeLocBuilder &TLB,
4455 FunctionNoProtoTypeLoc TL) {
4456 const FunctionNoProtoType *T = TL.getTypePtr();
4457 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4458 if (ResultType.isNull())
4461 QualType Result = TL.getType();
4462 if (getDerived().AlwaysRebuild() ||
4463 ResultType != T->getResultType())
4464 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4466 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4467 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4468 NewTL.setLParenLoc(TL.getLParenLoc());
4469 NewTL.setRParenLoc(TL.getRParenLoc());
4470 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4475 template<typename Derived> QualType
4476 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
4477 UnresolvedUsingTypeLoc TL) {
4478 const UnresolvedUsingType *T = TL.getTypePtr();
4479 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4483 QualType Result = TL.getType();
4484 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4485 Result = getDerived().RebuildUnresolvedUsingType(D);
4486 if (Result.isNull())
4490 // We might get an arbitrary type spec type back. We should at
4491 // least always get a type spec type, though.
4492 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4493 NewTL.setNameLoc(TL.getNameLoc());
4498 template<typename Derived>
4499 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
4500 TypedefTypeLoc TL) {
4501 const TypedefType *T = TL.getTypePtr();
4502 TypedefNameDecl *Typedef
4503 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4508 QualType Result = TL.getType();
4509 if (getDerived().AlwaysRebuild() ||
4510 Typedef != T->getDecl()) {
4511 Result = getDerived().RebuildTypedefType(Typedef);
4512 if (Result.isNull())
4516 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4517 NewTL.setNameLoc(TL.getNameLoc());
4522 template<typename Derived>
4523 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
4524 TypeOfExprTypeLoc TL) {
4525 // typeof expressions are not potentially evaluated contexts
4526 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4527 Sema::ReuseLambdaContextDecl);
4529 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4533 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4537 QualType Result = TL.getType();
4538 if (getDerived().AlwaysRebuild() ||
4539 E.get() != TL.getUnderlyingExpr()) {
4540 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4541 if (Result.isNull())
4546 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4547 NewTL.setTypeofLoc(TL.getTypeofLoc());
4548 NewTL.setLParenLoc(TL.getLParenLoc());
4549 NewTL.setRParenLoc(TL.getRParenLoc());
4554 template<typename Derived>
4555 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
4557 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4558 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4562 QualType Result = TL.getType();
4563 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4564 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4565 if (Result.isNull())
4569 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4570 NewTL.setTypeofLoc(TL.getTypeofLoc());
4571 NewTL.setLParenLoc(TL.getLParenLoc());
4572 NewTL.setRParenLoc(TL.getRParenLoc());
4573 NewTL.setUnderlyingTInfo(New_Under_TI);
4578 template<typename Derived>
4579 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
4580 DecltypeTypeLoc TL) {
4581 const DecltypeType *T = TL.getTypePtr();
4583 // decltype expressions are not potentially evaluated contexts
4584 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4585 /*IsDecltype=*/ true);
4587 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4591 E = getSema().ActOnDecltypeExpression(E.take());
4595 QualType Result = TL.getType();
4596 if (getDerived().AlwaysRebuild() ||
4597 E.get() != T->getUnderlyingExpr()) {
4598 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4599 if (Result.isNull())
4604 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4605 NewTL.setNameLoc(TL.getNameLoc());
4610 template<typename Derived>
4611 QualType TreeTransform<Derived>::TransformUnaryTransformType(
4612 TypeLocBuilder &TLB,
4613 UnaryTransformTypeLoc TL) {
4614 QualType Result = TL.getType();
4615 if (Result->isDependentType()) {
4616 const UnaryTransformType *T = TL.getTypePtr();
4618 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4619 Result = getDerived().RebuildUnaryTransformType(NewBase,
4622 if (Result.isNull())
4626 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4627 NewTL.setKWLoc(TL.getKWLoc());
4628 NewTL.setParensRange(TL.getParensRange());
4629 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4633 template<typename Derived>
4634 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4636 const AutoType *T = TL.getTypePtr();
4637 QualType OldDeduced = T->getDeducedType();
4638 QualType NewDeduced;
4639 if (!OldDeduced.isNull()) {
4640 NewDeduced = getDerived().TransformType(OldDeduced);
4641 if (NewDeduced.isNull())
4645 QualType Result = TL.getType();
4646 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4647 T->isDependentType()) {
4648 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
4649 if (Result.isNull())
4653 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4654 NewTL.setNameLoc(TL.getNameLoc());
4659 template<typename Derived>
4660 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
4662 const RecordType *T = TL.getTypePtr();
4664 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4669 QualType Result = TL.getType();
4670 if (getDerived().AlwaysRebuild() ||
4671 Record != T->getDecl()) {
4672 Result = getDerived().RebuildRecordType(Record);
4673 if (Result.isNull())
4677 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4678 NewTL.setNameLoc(TL.getNameLoc());
4683 template<typename Derived>
4684 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
4686 const EnumType *T = TL.getTypePtr();
4688 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4693 QualType Result = TL.getType();
4694 if (getDerived().AlwaysRebuild() ||
4695 Enum != T->getDecl()) {
4696 Result = getDerived().RebuildEnumType(Enum);
4697 if (Result.isNull())
4701 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4702 NewTL.setNameLoc(TL.getNameLoc());
4707 template<typename Derived>
4708 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4709 TypeLocBuilder &TLB,
4710 InjectedClassNameTypeLoc TL) {
4711 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4712 TL.getTypePtr()->getDecl());
4713 if (!D) return QualType();
4715 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4716 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4720 template<typename Derived>
4721 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4722 TypeLocBuilder &TLB,
4723 TemplateTypeParmTypeLoc TL) {
4724 return TransformTypeSpecType(TLB, TL);
4727 template<typename Derived>
4728 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4729 TypeLocBuilder &TLB,
4730 SubstTemplateTypeParmTypeLoc TL) {
4731 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4733 // Substitute into the replacement type, which itself might involve something
4734 // that needs to be transformed. This only tends to occur with default
4735 // template arguments of template template parameters.
4736 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4737 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4738 if (Replacement.isNull())
4741 // Always canonicalize the replacement type.
4742 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4744 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4747 // Propagate type-source information.
4748 SubstTemplateTypeParmTypeLoc NewTL
4749 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4750 NewTL.setNameLoc(TL.getNameLoc());
4755 template<typename Derived>
4756 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4757 TypeLocBuilder &TLB,
4758 SubstTemplateTypeParmPackTypeLoc TL) {
4759 return TransformTypeSpecType(TLB, TL);
4762 template<typename Derived>
4763 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4764 TypeLocBuilder &TLB,
4765 TemplateSpecializationTypeLoc TL) {
4766 const TemplateSpecializationType *T = TL.getTypePtr();
4768 // The nested-name-specifier never matters in a TemplateSpecializationType,
4769 // because we can't have a dependent nested-name-specifier anyway.
4771 TemplateName Template
4772 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4773 TL.getTemplateNameLoc());
4774 if (Template.isNull())
4777 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4780 template<typename Derived>
4781 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4783 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4784 if (ValueType.isNull())
4787 QualType Result = TL.getType();
4788 if (getDerived().AlwaysRebuild() ||
4789 ValueType != TL.getValueLoc().getType()) {
4790 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4791 if (Result.isNull())
4795 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4796 NewTL.setKWLoc(TL.getKWLoc());
4797 NewTL.setLParenLoc(TL.getLParenLoc());
4798 NewTL.setRParenLoc(TL.getRParenLoc());
4803 /// \brief Simple iterator that traverses the template arguments in a
4804 /// container that provides a \c getArgLoc() member function.
4806 /// This iterator is intended to be used with the iterator form of
4807 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4808 template<typename ArgLocContainer>
4809 class TemplateArgumentLocContainerIterator {
4810 ArgLocContainer *Container;
4814 typedef TemplateArgumentLoc value_type;
4815 typedef TemplateArgumentLoc reference;
4816 typedef int difference_type;
4817 typedef std::input_iterator_tag iterator_category;
4820 TemplateArgumentLoc Arg;
4823 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4825 const TemplateArgumentLoc *operator->() const {
4831 TemplateArgumentLocContainerIterator() {}
4833 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4835 : Container(&Container), Index(Index) { }
4837 TemplateArgumentLocContainerIterator &operator++() {
4842 TemplateArgumentLocContainerIterator operator++(int) {
4843 TemplateArgumentLocContainerIterator Old(*this);
4848 TemplateArgumentLoc operator*() const {
4849 return Container->getArgLoc(Index);
4852 pointer operator->() const {
4853 return pointer(Container->getArgLoc(Index));
4856 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4857 const TemplateArgumentLocContainerIterator &Y) {
4858 return X.Container == Y.Container && X.Index == Y.Index;
4861 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4862 const TemplateArgumentLocContainerIterator &Y) {
4868 template <typename Derived>
4869 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4870 TypeLocBuilder &TLB,
4871 TemplateSpecializationTypeLoc TL,
4872 TemplateName Template) {
4873 TemplateArgumentListInfo NewTemplateArgs;
4874 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4875 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4876 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4878 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4879 ArgIterator(TL, TL.getNumArgs()),
4883 // FIXME: maybe don't rebuild if all the template arguments are the same.
4886 getDerived().RebuildTemplateSpecializationType(Template,
4887 TL.getTemplateNameLoc(),
4890 if (!Result.isNull()) {
4891 // Specializations of template template parameters are represented as
4892 // TemplateSpecializationTypes, and substitution of type alias templates
4893 // within a dependent context can transform them into
4894 // DependentTemplateSpecializationTypes.
4895 if (isa<DependentTemplateSpecializationType>(Result)) {
4896 DependentTemplateSpecializationTypeLoc NewTL
4897 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4898 NewTL.setElaboratedKeywordLoc(SourceLocation());
4899 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4900 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4901 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4902 NewTL.setLAngleLoc(TL.getLAngleLoc());
4903 NewTL.setRAngleLoc(TL.getRAngleLoc());
4904 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4905 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4909 TemplateSpecializationTypeLoc NewTL
4910 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4911 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4912 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4913 NewTL.setLAngleLoc(TL.getLAngleLoc());
4914 NewTL.setRAngleLoc(TL.getRAngleLoc());
4915 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4916 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4922 template <typename Derived>
4923 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4924 TypeLocBuilder &TLB,
4925 DependentTemplateSpecializationTypeLoc TL,
4926 TemplateName Template,
4928 TemplateArgumentListInfo NewTemplateArgs;
4929 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4930 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4931 typedef TemplateArgumentLocContainerIterator<
4932 DependentTemplateSpecializationTypeLoc> ArgIterator;
4933 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4934 ArgIterator(TL, TL.getNumArgs()),
4938 // FIXME: maybe don't rebuild if all the template arguments are the same.
4940 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4942 = getSema().Context.getDependentTemplateSpecializationType(
4943 TL.getTypePtr()->getKeyword(),
4944 DTN->getQualifier(),
4945 DTN->getIdentifier(),
4948 DependentTemplateSpecializationTypeLoc NewTL
4949 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4950 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4951 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
4952 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4953 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4954 NewTL.setLAngleLoc(TL.getLAngleLoc());
4955 NewTL.setRAngleLoc(TL.getRAngleLoc());
4956 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4957 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4962 = getDerived().RebuildTemplateSpecializationType(Template,
4963 TL.getTemplateNameLoc(),
4966 if (!Result.isNull()) {
4967 /// FIXME: Wrap this in an elaborated-type-specifier?
4968 TemplateSpecializationTypeLoc NewTL
4969 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4970 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4971 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4972 NewTL.setLAngleLoc(TL.getLAngleLoc());
4973 NewTL.setRAngleLoc(TL.getRAngleLoc());
4974 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4975 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4981 template<typename Derived>
4983 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
4984 ElaboratedTypeLoc TL) {
4985 const ElaboratedType *T = TL.getTypePtr();
4987 NestedNameSpecifierLoc QualifierLoc;
4988 // NOTE: the qualifier in an ElaboratedType is optional.
4989 if (TL.getQualifierLoc()) {
4991 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4996 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4997 if (NamedT.isNull())
5000 // C++0x [dcl.type.elab]p2:
5001 // If the identifier resolves to a typedef-name or the simple-template-id
5002 // resolves to an alias template specialization, the
5003 // elaborated-type-specifier is ill-formed.
5004 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5005 if (const TemplateSpecializationType *TST =
5006 NamedT->getAs<TemplateSpecializationType>()) {
5007 TemplateName Template = TST->getTemplateName();
5008 if (TypeAliasTemplateDecl *TAT =
5009 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5010 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5011 diag::err_tag_reference_non_tag) << 4;
5012 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5017 QualType Result = TL.getType();
5018 if (getDerived().AlwaysRebuild() ||
5019 QualifierLoc != TL.getQualifierLoc() ||
5020 NamedT != T->getNamedType()) {
5021 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5023 QualifierLoc, NamedT);
5024 if (Result.isNull())
5028 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5029 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5030 NewTL.setQualifierLoc(QualifierLoc);
5034 template<typename Derived>
5035 QualType TreeTransform<Derived>::TransformAttributedType(
5036 TypeLocBuilder &TLB,
5037 AttributedTypeLoc TL) {
5038 const AttributedType *oldType = TL.getTypePtr();
5039 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5040 if (modifiedType.isNull())
5043 QualType result = TL.getType();
5045 // FIXME: dependent operand expressions?
5046 if (getDerived().AlwaysRebuild() ||
5047 modifiedType != oldType->getModifiedType()) {
5048 // TODO: this is really lame; we should really be rebuilding the
5049 // equivalent type from first principles.
5050 QualType equivalentType
5051 = getDerived().TransformType(oldType->getEquivalentType());
5052 if (equivalentType.isNull())
5054 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5059 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5060 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5061 if (TL.hasAttrOperand())
5062 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5063 if (TL.hasAttrExprOperand())
5064 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5065 else if (TL.hasAttrEnumOperand())
5066 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5071 template<typename Derived>
5073 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5075 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5079 QualType Result = TL.getType();
5080 if (getDerived().AlwaysRebuild() ||
5081 Inner != TL.getInnerLoc().getType()) {
5082 Result = getDerived().RebuildParenType(Inner);
5083 if (Result.isNull())
5087 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5088 NewTL.setLParenLoc(TL.getLParenLoc());
5089 NewTL.setRParenLoc(TL.getRParenLoc());
5093 template<typename Derived>
5094 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5095 DependentNameTypeLoc TL) {
5096 const DependentNameType *T = TL.getTypePtr();
5098 NestedNameSpecifierLoc QualifierLoc
5099 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5104 = getDerived().RebuildDependentNameType(T->getKeyword(),
5105 TL.getElaboratedKeywordLoc(),
5109 if (Result.isNull())
5112 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5113 QualType NamedT = ElabT->getNamedType();
5114 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5116 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5117 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5118 NewTL.setQualifierLoc(QualifierLoc);
5120 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5121 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5122 NewTL.setQualifierLoc(QualifierLoc);
5123 NewTL.setNameLoc(TL.getNameLoc());
5128 template<typename Derived>
5129 QualType TreeTransform<Derived>::
5130 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5131 DependentTemplateSpecializationTypeLoc TL) {
5132 NestedNameSpecifierLoc QualifierLoc;
5133 if (TL.getQualifierLoc()) {
5135 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5141 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5144 template<typename Derived>
5145 QualType TreeTransform<Derived>::
5146 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5147 DependentTemplateSpecializationTypeLoc TL,
5148 NestedNameSpecifierLoc QualifierLoc) {
5149 const DependentTemplateSpecializationType *T = TL.getTypePtr();
5151 TemplateArgumentListInfo NewTemplateArgs;
5152 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5153 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5155 typedef TemplateArgumentLocContainerIterator<
5156 DependentTemplateSpecializationTypeLoc> ArgIterator;
5157 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5158 ArgIterator(TL, TL.getNumArgs()),
5163 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5166 TL.getTemplateNameLoc(),
5168 if (Result.isNull())
5171 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5172 QualType NamedT = ElabT->getNamedType();
5174 // Copy information relevant to the template specialization.
5175 TemplateSpecializationTypeLoc NamedTL
5176 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5177 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5178 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5179 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5180 NamedTL.setRAngleLoc(TL.getRAngleLoc());
5181 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5182 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5184 // Copy information relevant to the elaborated type.
5185 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5186 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5187 NewTL.setQualifierLoc(QualifierLoc);
5188 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5189 DependentTemplateSpecializationTypeLoc SpecTL
5190 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5191 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5192 SpecTL.setQualifierLoc(QualifierLoc);
5193 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5194 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5195 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5196 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5197 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5198 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5200 TemplateSpecializationTypeLoc SpecTL
5201 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5202 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5203 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5204 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5205 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5206 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5207 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5212 template<typename Derived>
5213 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5214 PackExpansionTypeLoc TL) {
5216 = getDerived().TransformType(TLB, TL.getPatternLoc());
5217 if (Pattern.isNull())
5220 QualType Result = TL.getType();
5221 if (getDerived().AlwaysRebuild() ||
5222 Pattern != TL.getPatternLoc().getType()) {
5223 Result = getDerived().RebuildPackExpansionType(Pattern,
5224 TL.getPatternLoc().getSourceRange(),
5225 TL.getEllipsisLoc(),
5226 TL.getTypePtr()->getNumExpansions());
5227 if (Result.isNull())
5231 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5232 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5236 template<typename Derived>
5238 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5239 ObjCInterfaceTypeLoc TL) {
5240 // ObjCInterfaceType is never dependent.
5241 TLB.pushFullCopy(TL);
5242 return TL.getType();
5245 template<typename Derived>
5247 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5248 ObjCObjectTypeLoc TL) {
5249 // ObjCObjectType is never dependent.
5250 TLB.pushFullCopy(TL);
5251 return TL.getType();
5254 template<typename Derived>
5256 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
5257 ObjCObjectPointerTypeLoc TL) {
5258 // ObjCObjectPointerType is never dependent.
5259 TLB.pushFullCopy(TL);
5260 return TL.getType();
5263 //===----------------------------------------------------------------------===//
5264 // Statement transformation
5265 //===----------------------------------------------------------------------===//
5266 template<typename Derived>
5268 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
5269 return SemaRef.Owned(S);
5272 template<typename Derived>
5274 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5275 return getDerived().TransformCompoundStmt(S, false);
5278 template<typename Derived>
5280 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
5282 Sema::CompoundScopeRAII CompoundScope(getSema());
5284 bool SubStmtInvalid = false;
5285 bool SubStmtChanged = false;
5286 SmallVector<Stmt*, 8> Statements;
5287 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5289 StmtResult Result = getDerived().TransformStmt(*B);
5290 if (Result.isInvalid()) {
5291 // Immediately fail if this was a DeclStmt, since it's very
5292 // likely that this will cause problems for future statements.
5293 if (isa<DeclStmt>(*B))
5296 // Otherwise, just keep processing substatements and fail later.
5297 SubStmtInvalid = true;
5301 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5302 Statements.push_back(Result.takeAs<Stmt>());
5308 if (!getDerived().AlwaysRebuild() &&
5310 return SemaRef.Owned(S);
5312 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5318 template<typename Derived>
5320 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
5321 ExprResult LHS, RHS;
5323 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5324 Sema::ConstantEvaluated);
5326 // Transform the left-hand case value.
5327 LHS = getDerived().TransformExpr(S->getLHS());
5328 LHS = SemaRef.ActOnConstantExpression(LHS);
5329 if (LHS.isInvalid())
5332 // Transform the right-hand case value (for the GNU case-range extension).
5333 RHS = getDerived().TransformExpr(S->getRHS());
5334 RHS = SemaRef.ActOnConstantExpression(RHS);
5335 if (RHS.isInvalid())
5339 // Build the case statement.
5340 // Case statements are always rebuilt so that they will attached to their
5341 // transformed switch statement.
5342 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
5344 S->getEllipsisLoc(),
5347 if (Case.isInvalid())
5350 // Transform the statement following the case
5351 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5352 if (SubStmt.isInvalid())
5355 // Attach the body to the case statement
5356 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
5359 template<typename Derived>
5361 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
5362 // Transform the statement following the default case
5363 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5364 if (SubStmt.isInvalid())
5367 // Default statements are always rebuilt
5368 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
5372 template<typename Derived>
5374 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
5375 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5376 if (SubStmt.isInvalid())
5379 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5385 // FIXME: Pass the real colon location in.
5386 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
5387 cast<LabelDecl>(LD), SourceLocation(),
5391 template<typename Derived>
5393 TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5394 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5395 if (SubStmt.isInvalid())
5398 // TODO: transform attributes
5399 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5402 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5407 template<typename Derived>
5409 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
5410 // Transform the condition
5412 VarDecl *ConditionVar = 0;
5413 if (S->getConditionVariable()) {
5415 = cast_or_null<VarDecl>(
5416 getDerived().TransformDefinition(
5417 S->getConditionVariable()->getLocation(),
5418 S->getConditionVariable()));
5422 Cond = getDerived().TransformExpr(S->getCond());
5424 if (Cond.isInvalid())
5427 // Convert the condition to a boolean value.
5429 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5431 if (CondE.isInvalid())
5438 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5439 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5442 // Transform the "then" branch.
5443 StmtResult Then = getDerived().TransformStmt(S->getThen());
5444 if (Then.isInvalid())
5447 // Transform the "else" branch.
5448 StmtResult Else = getDerived().TransformStmt(S->getElse());
5449 if (Else.isInvalid())
5452 if (!getDerived().AlwaysRebuild() &&
5453 FullCond.get() == S->getCond() &&
5454 ConditionVar == S->getConditionVariable() &&
5455 Then.get() == S->getThen() &&
5456 Else.get() == S->getElse())
5457 return SemaRef.Owned(S);
5459 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
5461 S->getElseLoc(), Else.get());
5464 template<typename Derived>
5466 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
5467 // Transform the condition.
5469 VarDecl *ConditionVar = 0;
5470 if (S->getConditionVariable()) {
5472 = cast_or_null<VarDecl>(
5473 getDerived().TransformDefinition(
5474 S->getConditionVariable()->getLocation(),
5475 S->getConditionVariable()));
5479 Cond = getDerived().TransformExpr(S->getCond());
5481 if (Cond.isInvalid())
5485 // Rebuild the switch statement.
5487 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5489 if (Switch.isInvalid())
5492 // Transform the body of the switch statement.
5493 StmtResult Body = getDerived().TransformStmt(S->getBody());
5494 if (Body.isInvalid())
5497 // Complete the switch statement.
5498 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5502 template<typename Derived>
5504 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
5505 // Transform the condition
5507 VarDecl *ConditionVar = 0;
5508 if (S->getConditionVariable()) {
5510 = cast_or_null<VarDecl>(
5511 getDerived().TransformDefinition(
5512 S->getConditionVariable()->getLocation(),
5513 S->getConditionVariable()));
5517 Cond = getDerived().TransformExpr(S->getCond());
5519 if (Cond.isInvalid())
5523 // Convert the condition to a boolean value.
5524 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5526 if (CondE.isInvalid())
5532 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5533 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5536 // Transform the body
5537 StmtResult Body = getDerived().TransformStmt(S->getBody());
5538 if (Body.isInvalid())
5541 if (!getDerived().AlwaysRebuild() &&
5542 FullCond.get() == S->getCond() &&
5543 ConditionVar == S->getConditionVariable() &&
5544 Body.get() == S->getBody())
5547 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
5548 ConditionVar, Body.get());
5551 template<typename Derived>
5553 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
5554 // Transform the body
5555 StmtResult Body = getDerived().TransformStmt(S->getBody());
5556 if (Body.isInvalid())
5559 // Transform the condition
5560 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5561 if (Cond.isInvalid())
5564 if (!getDerived().AlwaysRebuild() &&
5565 Cond.get() == S->getCond() &&
5566 Body.get() == S->getBody())
5567 return SemaRef.Owned(S);
5569 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5570 /*FIXME:*/S->getWhileLoc(), Cond.get(),
5574 template<typename Derived>
5576 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
5577 // Transform the initialization statement
5578 StmtResult Init = getDerived().TransformStmt(S->getInit());
5579 if (Init.isInvalid())
5582 // Transform the condition
5584 VarDecl *ConditionVar = 0;
5585 if (S->getConditionVariable()) {
5587 = cast_or_null<VarDecl>(
5588 getDerived().TransformDefinition(
5589 S->getConditionVariable()->getLocation(),
5590 S->getConditionVariable()));
5594 Cond = getDerived().TransformExpr(S->getCond());
5596 if (Cond.isInvalid())
5600 // Convert the condition to a boolean value.
5601 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5603 if (CondE.isInvalid())
5610 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5611 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5614 // Transform the increment
5615 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5616 if (Inc.isInvalid())
5619 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
5620 if (S->getInc() && !FullInc.get())
5623 // Transform the body
5624 StmtResult Body = getDerived().TransformStmt(S->getBody());
5625 if (Body.isInvalid())
5628 if (!getDerived().AlwaysRebuild() &&
5629 Init.get() == S->getInit() &&
5630 FullCond.get() == S->getCond() &&
5631 Inc.get() == S->getInc() &&
5632 Body.get() == S->getBody())
5633 return SemaRef.Owned(S);
5635 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
5636 Init.get(), FullCond, ConditionVar,
5637 FullInc, S->getRParenLoc(), Body.get());
5640 template<typename Derived>
5642 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
5643 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5648 // Goto statements must always be rebuilt, to resolve the label.
5649 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
5650 cast<LabelDecl>(LD));
5653 template<typename Derived>
5655 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
5656 ExprResult Target = getDerived().TransformExpr(S->getTarget());
5657 if (Target.isInvalid())
5659 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
5661 if (!getDerived().AlwaysRebuild() &&
5662 Target.get() == S->getTarget())
5663 return SemaRef.Owned(S);
5665 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
5669 template<typename Derived>
5671 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
5672 return SemaRef.Owned(S);
5675 template<typename Derived>
5677 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
5678 return SemaRef.Owned(S);
5681 template<typename Derived>
5683 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
5684 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
5685 if (Result.isInvalid())
5688 // FIXME: We always rebuild the return statement because there is no way
5689 // to tell whether the return type of the function has changed.
5690 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
5693 template<typename Derived>
5695 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
5696 bool DeclChanged = false;
5697 SmallVector<Decl *, 4> Decls;
5698 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5700 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5705 if (Transformed != *D)
5708 Decls.push_back(Transformed);
5711 if (!getDerived().AlwaysRebuild() && !DeclChanged)
5712 return SemaRef.Owned(S);
5714 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
5717 template<typename Derived>
5719 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
5721 SmallVector<Expr*, 8> Constraints;
5722 SmallVector<Expr*, 8> Exprs;
5723 SmallVector<IdentifierInfo *, 4> Names;
5725 ExprResult AsmString;
5726 SmallVector<Expr*, 8> Clobbers;
5728 bool ExprsChanged = false;
5730 // Go through the outputs.
5731 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5732 Names.push_back(S->getOutputIdentifier(I));
5734 // No need to transform the constraint literal.
5735 Constraints.push_back(S->getOutputConstraintLiteral(I));
5737 // Transform the output expr.
5738 Expr *OutputExpr = S->getOutputExpr(I);
5739 ExprResult Result = getDerived().TransformExpr(OutputExpr);
5740 if (Result.isInvalid())
5743 ExprsChanged |= Result.get() != OutputExpr;
5745 Exprs.push_back(Result.get());
5748 // Go through the inputs.
5749 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5750 Names.push_back(S->getInputIdentifier(I));
5752 // No need to transform the constraint literal.
5753 Constraints.push_back(S->getInputConstraintLiteral(I));
5755 // Transform the input expr.
5756 Expr *InputExpr = S->getInputExpr(I);
5757 ExprResult Result = getDerived().TransformExpr(InputExpr);
5758 if (Result.isInvalid())
5761 ExprsChanged |= Result.get() != InputExpr;
5763 Exprs.push_back(Result.get());
5766 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
5767 return SemaRef.Owned(S);
5769 // Go through the clobbers.
5770 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
5771 Clobbers.push_back(S->getClobberStringLiteral(I));
5773 // No need to transform the asm string literal.
5774 AsmString = SemaRef.Owned(S->getAsmString());
5775 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5776 S->isVolatile(), S->getNumOutputs(),
5777 S->getNumInputs(), Names.data(),
5778 Constraints, Exprs, AsmString.get(),
5779 Clobbers, S->getRParenLoc());
5782 template<typename Derived>
5784 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
5785 ArrayRef<Token> AsmToks =
5786 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
5788 bool HadError = false, HadChange = false;
5790 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5791 SmallVector<Expr*, 8> TransformedExprs;
5792 TransformedExprs.reserve(SrcExprs.size());
5793 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5794 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5795 if (!Result.isUsable()) {
5798 HadChange |= (Result.get() != SrcExprs[i]);
5799 TransformedExprs.push_back(Result.take());
5803 if (HadError) return StmtError();
5804 if (!HadChange && !getDerived().AlwaysRebuild())
5807 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5808 AsmToks, S->getAsmString(),
5809 S->getNumOutputs(), S->getNumInputs(),
5810 S->getAllConstraints(), S->getClobbers(),
5811 TransformedExprs, S->getEndLoc());
5814 template<typename Derived>
5816 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
5817 // Transform the body of the @try.
5818 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
5819 if (TryBody.isInvalid())
5822 // Transform the @catch statements (if present).
5823 bool AnyCatchChanged = false;
5824 SmallVector<Stmt*, 8> CatchStmts;
5825 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
5826 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
5827 if (Catch.isInvalid())
5829 if (Catch.get() != S->getCatchStmt(I))
5830 AnyCatchChanged = true;
5831 CatchStmts.push_back(Catch.release());
5834 // Transform the @finally statement (if present).
5836 if (S->getFinallyStmt()) {
5837 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5838 if (Finally.isInvalid())
5842 // If nothing changed, just retain this statement.
5843 if (!getDerived().AlwaysRebuild() &&
5844 TryBody.get() == S->getTryBody() &&
5846 Finally.get() == S->getFinallyStmt())
5847 return SemaRef.Owned(S);
5849 // Build a new statement.
5850 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5851 CatchStmts, Finally.get());
5854 template<typename Derived>
5856 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5857 // Transform the @catch parameter, if there is one.
5859 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5860 TypeSourceInfo *TSInfo = 0;
5861 if (FromVar->getTypeSourceInfo()) {
5862 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5869 T = TSInfo->getType();
5871 T = getDerived().TransformType(FromVar->getType());
5876 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5881 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5882 if (Body.isInvalid())
5885 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5890 template<typename Derived>
5892 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
5893 // Transform the body.
5894 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
5895 if (Body.isInvalid())
5898 // If nothing changed, just retain this statement.
5899 if (!getDerived().AlwaysRebuild() &&
5900 Body.get() == S->getFinallyBody())
5901 return SemaRef.Owned(S);
5903 // Build a new statement.
5904 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
5908 template<typename Derived>
5910 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
5912 if (S->getThrowExpr()) {
5913 Operand = getDerived().TransformExpr(S->getThrowExpr());
5914 if (Operand.isInvalid())
5918 if (!getDerived().AlwaysRebuild() &&
5919 Operand.get() == S->getThrowExpr())
5920 return getSema().Owned(S);
5922 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
5925 template<typename Derived>
5927 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
5928 ObjCAtSynchronizedStmt *S) {
5929 // Transform the object we are locking.
5930 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
5931 if (Object.isInvalid())
5934 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5936 if (Object.isInvalid())
5939 // Transform the body.
5940 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
5941 if (Body.isInvalid())
5944 // If nothing change, just retain the current statement.
5945 if (!getDerived().AlwaysRebuild() &&
5946 Object.get() == S->getSynchExpr() &&
5947 Body.get() == S->getSynchBody())
5948 return SemaRef.Owned(S);
5950 // Build a new statement.
5951 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
5952 Object.get(), Body.get());
5955 template<typename Derived>
5957 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5958 ObjCAutoreleasePoolStmt *S) {
5959 // Transform the body.
5960 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5961 if (Body.isInvalid())
5964 // If nothing changed, just retain this statement.
5965 if (!getDerived().AlwaysRebuild() &&
5966 Body.get() == S->getSubStmt())
5967 return SemaRef.Owned(S);
5969 // Build a new statement.
5970 return getDerived().RebuildObjCAutoreleasePoolStmt(
5971 S->getAtLoc(), Body.get());
5974 template<typename Derived>
5976 TreeTransform<Derived>::TransformObjCForCollectionStmt(
5977 ObjCForCollectionStmt *S) {
5978 // Transform the element statement.
5979 StmtResult Element = getDerived().TransformStmt(S->getElement());
5980 if (Element.isInvalid())
5983 // Transform the collection expression.
5984 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5985 if (Collection.isInvalid())
5988 // Transform the body.
5989 StmtResult Body = getDerived().TransformStmt(S->getBody());
5990 if (Body.isInvalid())
5993 // If nothing changed, just retain this statement.
5994 if (!getDerived().AlwaysRebuild() &&
5995 Element.get() == S->getElement() &&
5996 Collection.get() == S->getCollection() &&
5997 Body.get() == S->getBody())
5998 return SemaRef.Owned(S);
6000 // Build a new statement.
6001 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6008 template <typename Derived>
6009 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6010 // Transform the exception declaration, if any.
6012 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6014 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6018 Var = getDerived().RebuildExceptionDecl(
6019 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6020 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6021 if (!Var || Var->isInvalidDecl())
6025 // Transform the actual exception handler.
6026 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6027 if (Handler.isInvalid())
6030 if (!getDerived().AlwaysRebuild() && !Var &&
6031 Handler.get() == S->getHandlerBlock())
6032 return SemaRef.Owned(S);
6034 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6037 template <typename Derived>
6038 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6039 // Transform the try block itself.
6040 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6041 if (TryBlock.isInvalid())
6044 // Transform the handlers.
6045 bool HandlerChanged = false;
6046 SmallVector<Stmt *, 8> Handlers;
6047 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6048 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6049 if (Handler.isInvalid())
6052 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6053 Handlers.push_back(Handler.takeAs<Stmt>());
6056 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6058 return SemaRef.Owned(S);
6060 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6064 template<typename Derived>
6066 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6067 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6068 if (Range.isInvalid())
6071 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6072 if (BeginEnd.isInvalid())
6075 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6076 if (Cond.isInvalid())
6079 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6080 if (Cond.isInvalid())
6083 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
6085 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6086 if (Inc.isInvalid())
6089 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
6091 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6092 if (LoopVar.isInvalid())
6095 StmtResult NewStmt = S;
6096 if (getDerived().AlwaysRebuild() ||
6097 Range.get() != S->getRangeStmt() ||
6098 BeginEnd.get() != S->getBeginEndStmt() ||
6099 Cond.get() != S->getCond() ||
6100 Inc.get() != S->getInc() ||
6101 LoopVar.get() != S->getLoopVarStmt()) {
6102 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6103 S->getColonLoc(), Range.get(),
6104 BeginEnd.get(), Cond.get(),
6105 Inc.get(), LoopVar.get(),
6107 if (NewStmt.isInvalid())
6111 StmtResult Body = getDerived().TransformStmt(S->getBody());
6112 if (Body.isInvalid())
6115 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6116 // it now so we have a new statement to attach the body to.
6117 if (Body.get() != S->getBody() && NewStmt.get() == S) {
6118 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6119 S->getColonLoc(), Range.get(),
6120 BeginEnd.get(), Cond.get(),
6121 Inc.get(), LoopVar.get(),
6123 if (NewStmt.isInvalid())
6127 if (NewStmt.get() == S)
6128 return SemaRef.Owned(S);
6130 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6133 template<typename Derived>
6135 TreeTransform<Derived>::TransformMSDependentExistsStmt(
6136 MSDependentExistsStmt *S) {
6137 // Transform the nested-name-specifier, if any.
6138 NestedNameSpecifierLoc QualifierLoc;
6139 if (S->getQualifierLoc()) {
6141 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6146 // Transform the declaration name.
6147 DeclarationNameInfo NameInfo = S->getNameInfo();
6148 if (NameInfo.getName()) {
6149 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6150 if (!NameInfo.getName())
6154 // Check whether anything changed.
6155 if (!getDerived().AlwaysRebuild() &&
6156 QualifierLoc == S->getQualifierLoc() &&
6157 NameInfo.getName() == S->getNameInfo().getName())
6160 // Determine whether this name exists, if we can.
6162 SS.Adopt(QualifierLoc);
6163 bool Dependent = false;
6164 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6165 case Sema::IER_Exists:
6166 if (S->isIfExists())
6169 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6171 case Sema::IER_DoesNotExist:
6172 if (S->isIfNotExists())
6175 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6177 case Sema::IER_Dependent:
6181 case Sema::IER_Error:
6185 // We need to continue with the instantiation, so do so now.
6186 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6187 if (SubStmt.isInvalid())
6190 // If we have resolved the name, just transform to the substatement.
6194 // The name is still dependent, so build a dependent expression again.
6195 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6202 template<typename Derived>
6204 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6205 NestedNameSpecifierLoc QualifierLoc;
6206 if (E->getQualifierLoc()) {
6208 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6213 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6214 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6218 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6219 if (Base.isInvalid())
6222 return new (SemaRef.getASTContext())
6223 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6224 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6225 QualifierLoc, E->getMemberLoc());
6228 template <typename Derived>
6229 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6230 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6231 if (TryBlock.isInvalid())
6234 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6235 if (Handler.isInvalid())
6238 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6239 Handler.get() == S->getHandler())
6240 return SemaRef.Owned(S);
6242 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6243 TryBlock.take(), Handler.take());
6246 template <typename Derived>
6247 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6248 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
6249 if (Block.isInvalid())
6252 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
6255 template <typename Derived>
6256 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6257 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6258 if (FilterExpr.isInvalid())
6261 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
6262 if (Block.isInvalid())
6265 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
6269 template <typename Derived>
6270 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6271 if (isa<SEHFinallyStmt>(Handler))
6272 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6274 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6277 template<typename Derived>
6279 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6280 DeclarationNameInfo DirName;
6281 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6283 // Transform the clauses
6284 llvm::SmallVector<OMPClause *, 16> TClauses;
6285 ArrayRef<OMPClause *> Clauses = D->clauses();
6286 TClauses.reserve(Clauses.size());
6287 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6290 OMPClause *Clause = getDerived().TransformOMPClause(*I);
6292 getSema().EndOpenMPDSABlock(0);
6295 TClauses.push_back(Clause);
6298 TClauses.push_back(0);
6301 if (!D->getAssociatedStmt()) {
6302 getSema().EndOpenMPDSABlock(0);
6305 StmtResult AssociatedStmt =
6306 getDerived().TransformStmt(D->getAssociatedStmt());
6307 if (AssociatedStmt.isInvalid()) {
6308 getSema().EndOpenMPDSABlock(0);
6312 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6313 AssociatedStmt.take(),
6316 getSema().EndOpenMPDSABlock(Res.get());
6320 template<typename Derived>
6322 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6323 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6324 C->getDefaultKindKwLoc(),
6330 template<typename Derived>
6332 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
6333 llvm::SmallVector<Expr *, 16> Vars;
6334 Vars.reserve(C->varlist_size());
6335 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6336 E = C->varlist_end();
6338 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6339 if (EVar.isInvalid())
6341 Vars.push_back(EVar.take());
6343 return getDerived().RebuildOMPPrivateClause(Vars,
6349 template<typename Derived>
6351 TreeTransform<Derived>::TransformOMPFirstprivateClause(
6352 OMPFirstprivateClause *C) {
6353 llvm::SmallVector<Expr *, 16> Vars;
6354 Vars.reserve(C->varlist_size());
6355 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6356 E = C->varlist_end();
6358 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6359 if (EVar.isInvalid())
6361 Vars.push_back(EVar.take());
6363 return getDerived().RebuildOMPFirstprivateClause(Vars,
6369 template<typename Derived>
6371 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6372 llvm::SmallVector<Expr *, 16> Vars;
6373 Vars.reserve(C->varlist_size());
6374 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6375 E = C->varlist_end();
6377 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6378 if (EVar.isInvalid())
6380 Vars.push_back(EVar.take());
6382 return getDerived().RebuildOMPSharedClause(Vars,
6388 //===----------------------------------------------------------------------===//
6389 // Expression transformation
6390 //===----------------------------------------------------------------------===//
6391 template<typename Derived>
6393 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
6394 return SemaRef.Owned(E);
6397 template<typename Derived>
6399 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
6400 NestedNameSpecifierLoc QualifierLoc;
6401 if (E->getQualifierLoc()) {
6403 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6409 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6414 DeclarationNameInfo NameInfo = E->getNameInfo();
6415 if (NameInfo.getName()) {
6416 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6417 if (!NameInfo.getName())
6421 if (!getDerived().AlwaysRebuild() &&
6422 QualifierLoc == E->getQualifierLoc() &&
6423 ND == E->getDecl() &&
6424 NameInfo.getName() == E->getDecl()->getDeclName() &&
6425 !E->hasExplicitTemplateArgs()) {
6427 // Mark it referenced in the new context regardless.
6428 // FIXME: this is a bit instantiation-specific.
6429 SemaRef.MarkDeclRefReferenced(E);
6431 return SemaRef.Owned(E);
6434 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
6435 if (E->hasExplicitTemplateArgs()) {
6436 TemplateArgs = &TransArgs;
6437 TransArgs.setLAngleLoc(E->getLAngleLoc());
6438 TransArgs.setRAngleLoc(E->getRAngleLoc());
6439 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6440 E->getNumTemplateArgs(),
6445 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6449 template<typename Derived>
6451 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
6452 return SemaRef.Owned(E);
6455 template<typename Derived>
6457 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
6458 return SemaRef.Owned(E);
6461 template<typename Derived>
6463 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
6464 return SemaRef.Owned(E);
6467 template<typename Derived>
6469 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
6470 return SemaRef.Owned(E);
6473 template<typename Derived>
6475 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
6476 return SemaRef.Owned(E);
6479 template<typename Derived>
6481 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6482 if (FunctionDecl *FD = E->getDirectCallee())
6483 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
6484 return SemaRef.MaybeBindToTemporary(E);
6487 template<typename Derived>
6489 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6490 ExprResult ControllingExpr =
6491 getDerived().TransformExpr(E->getControllingExpr());
6492 if (ControllingExpr.isInvalid())
6495 SmallVector<Expr *, 4> AssocExprs;
6496 SmallVector<TypeSourceInfo *, 4> AssocTypes;
6497 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6498 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6500 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6503 AssocTypes.push_back(AssocType);
6505 AssocTypes.push_back(0);
6508 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6509 if (AssocExpr.isInvalid())
6511 AssocExprs.push_back(AssocExpr.release());
6514 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6517 ControllingExpr.release(),
6522 template<typename Derived>
6524 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
6525 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6526 if (SubExpr.isInvalid())
6529 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
6530 return SemaRef.Owned(E);
6532 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
6536 /// \brief The operand of a unary address-of operator has special rules: it's
6537 /// allowed to refer to a non-static member of a class even if there's no 'this'
6538 /// object available.
6539 template<typename Derived>
6541 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6542 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6543 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6545 return getDerived().TransformExpr(E);
6548 template<typename Derived>
6550 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
6552 if (E->getOpcode() == UO_AddrOf)
6553 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6555 SubExpr = TransformExpr(E->getSubExpr());
6556 if (SubExpr.isInvalid())
6559 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
6560 return SemaRef.Owned(E);
6562 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6567 template<typename Derived>
6569 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6570 // Transform the type.
6571 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6575 // Transform all of the components into components similar to what the
6577 // FIXME: It would be slightly more efficient in the non-dependent case to
6578 // just map FieldDecls, rather than requiring the rebuilder to look for
6579 // the fields again. However, __builtin_offsetof is rare enough in
6580 // template code that we don't care.
6581 bool ExprChanged = false;
6582 typedef Sema::OffsetOfComponent Component;
6583 typedef OffsetOfExpr::OffsetOfNode Node;
6584 SmallVector<Component, 4> Components;
6585 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6586 const Node &ON = E->getComponent(I);
6588 Comp.isBrackets = true;
6589 Comp.LocStart = ON.getSourceRange().getBegin();
6590 Comp.LocEnd = ON.getSourceRange().getEnd();
6591 switch (ON.getKind()) {
6593 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
6594 ExprResult Index = getDerived().TransformExpr(FromIndex);
6595 if (Index.isInvalid())
6598 ExprChanged = ExprChanged || Index.get() != FromIndex;
6599 Comp.isBrackets = true;
6600 Comp.U.E = Index.get();
6605 case Node::Identifier:
6606 Comp.isBrackets = false;
6607 Comp.U.IdentInfo = ON.getFieldName();
6608 if (!Comp.U.IdentInfo)
6614 // Will be recomputed during the rebuild.
6618 Components.push_back(Comp);
6621 // If nothing changed, retain the existing expression.
6622 if (!getDerived().AlwaysRebuild() &&
6623 Type == E->getTypeSourceInfo() &&
6625 return SemaRef.Owned(E);
6627 // Build a new offsetof expression.
6628 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6629 Components.data(), Components.size(),
6633 template<typename Derived>
6635 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6636 assert(getDerived().AlreadyTransformed(E->getType()) &&
6637 "opaque value expression requires transformation");
6638 return SemaRef.Owned(E);
6641 template<typename Derived>
6643 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
6644 // Rebuild the syntactic form. The original syntactic form has
6645 // opaque-value expressions in it, so strip those away and rebuild
6646 // the result. This is a really awful way of doing this, but the
6647 // better solution (rebuilding the semantic expressions and
6648 // rebinding OVEs as necessary) doesn't work; we'd need
6649 // TreeTransform to not strip away implicit conversions.
6650 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6651 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
6652 if (result.isInvalid()) return ExprError();
6654 // If that gives us a pseudo-object result back, the pseudo-object
6655 // expression must have been an lvalue-to-rvalue conversion which we
6657 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6658 result = SemaRef.checkPseudoObjectRValue(result.take());
6663 template<typename Derived>
6665 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6666 UnaryExprOrTypeTraitExpr *E) {
6667 if (E->isArgumentType()) {
6668 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
6670 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6674 if (!getDerived().AlwaysRebuild() && OldT == NewT)
6675 return SemaRef.Owned(E);
6677 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6679 E->getSourceRange());
6682 // C++0x [expr.sizeof]p1:
6683 // The operand is either an expression, which is an unevaluated operand
6685 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6686 Sema::ReuseLambdaContextDecl);
6688 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6689 if (SubExpr.isInvalid())
6692 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6693 return SemaRef.Owned(E);
6695 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6696 E->getOperatorLoc(),
6698 E->getSourceRange());
6701 template<typename Derived>
6703 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
6704 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6705 if (LHS.isInvalid())
6708 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6709 if (RHS.isInvalid())
6713 if (!getDerived().AlwaysRebuild() &&
6714 LHS.get() == E->getLHS() &&
6715 RHS.get() == E->getRHS())
6716 return SemaRef.Owned(E);
6718 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
6719 /*FIXME:*/E->getLHS()->getLocStart(),
6721 E->getRBracketLoc());
6724 template<typename Derived>
6726 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6727 // Transform the callee.
6728 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6729 if (Callee.isInvalid())
6732 // Transform arguments.
6733 bool ArgChanged = false;
6734 SmallVector<Expr*, 8> Args;
6735 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6739 if (!getDerived().AlwaysRebuild() &&
6740 Callee.get() == E->getCallee() &&
6742 return SemaRef.MaybeBindToTemporary(E);
6744 // FIXME: Wrong source location information for the '('.
6745 SourceLocation FakeLParenLoc
6746 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6747 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6752 template<typename Derived>
6754 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
6755 ExprResult Base = getDerived().TransformExpr(E->getBase());
6756 if (Base.isInvalid())
6759 NestedNameSpecifierLoc QualifierLoc;
6760 if (E->hasQualifier()) {
6762 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6767 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
6770 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6771 E->getMemberDecl()));
6775 NamedDecl *FoundDecl = E->getFoundDecl();
6776 if (FoundDecl == E->getMemberDecl()) {
6779 FoundDecl = cast_or_null<NamedDecl>(
6780 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6785 if (!getDerived().AlwaysRebuild() &&
6786 Base.get() == E->getBase() &&
6787 QualifierLoc == E->getQualifierLoc() &&
6788 Member == E->getMemberDecl() &&
6789 FoundDecl == E->getFoundDecl() &&
6790 !E->hasExplicitTemplateArgs()) {
6792 // Mark it referenced in the new context regardless.
6793 // FIXME: this is a bit instantiation-specific.
6794 SemaRef.MarkMemberReferenced(E);
6796 return SemaRef.Owned(E);
6799 TemplateArgumentListInfo TransArgs;
6800 if (E->hasExplicitTemplateArgs()) {
6801 TransArgs.setLAngleLoc(E->getLAngleLoc());
6802 TransArgs.setRAngleLoc(E->getRAngleLoc());
6803 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6804 E->getNumTemplateArgs(),
6809 // FIXME: Bogus source location for the operator
6810 SourceLocation FakeOperatorLoc
6811 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6813 // FIXME: to do this check properly, we will need to preserve the
6814 // first-qualifier-in-scope here, just in case we had a dependent
6815 // base (and therefore couldn't do the check) and a
6816 // nested-name-qualifier (and therefore could do the lookup).
6817 NamedDecl *FirstQualifierInScope = 0;
6819 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6823 E->getMemberNameInfo(),
6826 (E->hasExplicitTemplateArgs()
6828 FirstQualifierInScope);
6831 template<typename Derived>
6833 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
6834 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6835 if (LHS.isInvalid())
6838 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6839 if (RHS.isInvalid())
6842 if (!getDerived().AlwaysRebuild() &&
6843 LHS.get() == E->getLHS() &&
6844 RHS.get() == E->getRHS())
6845 return SemaRef.Owned(E);
6847 Sema::FPContractStateRAII FPContractState(getSema());
6848 getSema().FPFeatures.fp_contract = E->isFPContractable();
6850 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
6851 LHS.get(), RHS.get());
6854 template<typename Derived>
6856 TreeTransform<Derived>::TransformCompoundAssignOperator(
6857 CompoundAssignOperator *E) {
6858 return getDerived().TransformBinaryOperator(E);
6861 template<typename Derived>
6862 ExprResult TreeTransform<Derived>::
6863 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6864 // Just rebuild the common and RHS expressions and see whether we
6867 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6868 if (commonExpr.isInvalid())
6871 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6872 if (rhs.isInvalid())
6875 if (!getDerived().AlwaysRebuild() &&
6876 commonExpr.get() == e->getCommon() &&
6877 rhs.get() == e->getFalseExpr())
6878 return SemaRef.Owned(e);
6880 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6881 e->getQuestionLoc(),
6887 template<typename Derived>
6889 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
6890 ExprResult Cond = getDerived().TransformExpr(E->getCond());
6891 if (Cond.isInvalid())
6894 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6895 if (LHS.isInvalid())
6898 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6899 if (RHS.isInvalid())
6902 if (!getDerived().AlwaysRebuild() &&
6903 Cond.get() == E->getCond() &&
6904 LHS.get() == E->getLHS() &&
6905 RHS.get() == E->getRHS())
6906 return SemaRef.Owned(E);
6908 return getDerived().RebuildConditionalOperator(Cond.get(),
6909 E->getQuestionLoc(),
6915 template<typename Derived>
6917 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6918 // Implicit casts are eliminated during transformation, since they
6919 // will be recomputed by semantic analysis after transformation.
6920 return getDerived().TransformExpr(E->getSubExprAsWritten());
6923 template<typename Derived>
6925 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6926 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6931 = getDerived().TransformExpr(E->getSubExprAsWritten());
6932 if (SubExpr.isInvalid())
6935 if (!getDerived().AlwaysRebuild() &&
6936 Type == E->getTypeInfoAsWritten() &&
6937 SubExpr.get() == E->getSubExpr())
6938 return SemaRef.Owned(E);
6940 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6946 template<typename Derived>
6948 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
6949 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6950 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6954 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6955 if (Init.isInvalid())
6958 if (!getDerived().AlwaysRebuild() &&
6960 Init.get() == E->getInitializer())
6961 return SemaRef.MaybeBindToTemporary(E);
6963 // Note: the expression type doesn't necessarily match the
6964 // type-as-written, but that's okay, because it should always be
6965 // derivable from the initializer.
6967 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6968 /*FIXME:*/E->getInitializer()->getLocEnd(),
6972 template<typename Derived>
6974 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
6975 ExprResult Base = getDerived().TransformExpr(E->getBase());
6976 if (Base.isInvalid())
6979 if (!getDerived().AlwaysRebuild() &&
6980 Base.get() == E->getBase())
6981 return SemaRef.Owned(E);
6983 // FIXME: Bad source location
6984 SourceLocation FakeOperatorLoc
6985 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
6986 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6987 E->getAccessorLoc(),
6991 template<typename Derived>
6993 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6994 bool InitChanged = false;
6996 SmallVector<Expr*, 4> Inits;
6997 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6998 Inits, &InitChanged))
7001 if (!getDerived().AlwaysRebuild() && !InitChanged)
7002 return SemaRef.Owned(E);
7004 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
7005 E->getRBraceLoc(), E->getType());
7008 template<typename Derived>
7010 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
7013 // transform the initializer value
7014 ExprResult Init = getDerived().TransformExpr(E->getInit());
7015 if (Init.isInvalid())
7018 // transform the designators.
7019 SmallVector<Expr*, 4> ArrayExprs;
7020 bool ExprChanged = false;
7021 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7022 DEnd = E->designators_end();
7024 if (D->isFieldDesignator()) {
7025 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7031 if (D->isArrayDesignator()) {
7032 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
7033 if (Index.isInvalid())
7036 Desig.AddDesignator(Designator::getArray(Index.get(),
7037 D->getLBracketLoc()));
7039 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7040 ArrayExprs.push_back(Index.release());
7044 assert(D->isArrayRangeDesignator() && "New kind of designator?");
7046 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7047 if (Start.isInvalid())
7050 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
7051 if (End.isInvalid())
7054 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
7056 D->getLBracketLoc(),
7057 D->getEllipsisLoc()));
7059 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7060 End.get() != E->getArrayRangeEnd(*D);
7062 ArrayExprs.push_back(Start.release());
7063 ArrayExprs.push_back(End.release());
7066 if (!getDerived().AlwaysRebuild() &&
7067 Init.get() == E->getInit() &&
7069 return SemaRef.Owned(E);
7071 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
7072 E->getEqualOrColonLoc(),
7073 E->usesGNUSyntax(), Init.get());
7076 template<typename Derived>
7078 TreeTransform<Derived>::TransformImplicitValueInitExpr(
7079 ImplicitValueInitExpr *E) {
7080 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
7082 // FIXME: Will we ever have proper type location here? Will we actually
7083 // need to transform the type?
7084 QualType T = getDerived().TransformType(E->getType());
7088 if (!getDerived().AlwaysRebuild() &&
7090 return SemaRef.Owned(E);
7092 return getDerived().RebuildImplicitValueInitExpr(T);
7095 template<typename Derived>
7097 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
7098 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7102 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7103 if (SubExpr.isInvalid())
7106 if (!getDerived().AlwaysRebuild() &&
7107 TInfo == E->getWrittenTypeInfo() &&
7108 SubExpr.get() == E->getSubExpr())
7109 return SemaRef.Owned(E);
7111 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
7112 TInfo, E->getRParenLoc());
7115 template<typename Derived>
7117 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
7118 bool ArgumentChanged = false;
7119 SmallVector<Expr*, 4> Inits;
7120 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7124 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
7129 /// \brief Transform an address-of-label expression.
7131 /// By default, the transformation of an address-of-label expression always
7132 /// rebuilds the expression, so that the label identifier can be resolved to
7133 /// the corresponding label statement by semantic analysis.
7134 template<typename Derived>
7136 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
7137 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7142 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
7143 cast<LabelDecl>(LD));
7146 template<typename Derived>
7148 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
7149 SemaRef.ActOnStartStmtExpr();
7151 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
7152 if (SubStmt.isInvalid()) {
7153 SemaRef.ActOnStmtExprError();
7157 if (!getDerived().AlwaysRebuild() &&
7158 SubStmt.get() == E->getSubStmt()) {
7159 // Calling this an 'error' is unintuitive, but it does the right thing.
7160 SemaRef.ActOnStmtExprError();
7161 return SemaRef.MaybeBindToTemporary(E);
7164 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
7169 template<typename Derived>
7171 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
7172 ExprResult Cond = getDerived().TransformExpr(E->getCond());
7173 if (Cond.isInvalid())
7176 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7177 if (LHS.isInvalid())
7180 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7181 if (RHS.isInvalid())
7184 if (!getDerived().AlwaysRebuild() &&
7185 Cond.get() == E->getCond() &&
7186 LHS.get() == E->getLHS() &&
7187 RHS.get() == E->getRHS())
7188 return SemaRef.Owned(E);
7190 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
7191 Cond.get(), LHS.get(), RHS.get(),
7195 template<typename Derived>
7197 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
7198 return SemaRef.Owned(E);
7201 template<typename Derived>
7203 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
7204 switch (E->getOperator()) {
7208 case OO_Array_Delete:
7209 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
7212 // This is a call to an object's operator().
7213 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7215 // Transform the object itself.
7216 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
7217 if (Object.isInvalid())
7220 // FIXME: Poor location information
7221 SourceLocation FakeLParenLoc
7222 = SemaRef.PP.getLocForEndOfToken(
7223 static_cast<Expr *>(Object.get())->getLocEnd());
7225 // Transform the call arguments.
7226 SmallVector<Expr*, 8> Args;
7227 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
7231 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
7236 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7238 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7239 #include "clang/Basic/OperatorKinds.def"
7244 case OO_Conditional:
7245 llvm_unreachable("conditional operator is not actually overloadable");
7248 case NUM_OVERLOADED_OPERATORS:
7249 llvm_unreachable("not an overloaded operator?");
7252 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7253 if (Callee.isInvalid())
7257 if (E->getOperator() == OO_Amp)
7258 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7260 First = getDerived().TransformExpr(E->getArg(0));
7261 if (First.isInvalid())
7265 if (E->getNumArgs() == 2) {
7266 Second = getDerived().TransformExpr(E->getArg(1));
7267 if (Second.isInvalid())
7271 if (!getDerived().AlwaysRebuild() &&
7272 Callee.get() == E->getCallee() &&
7273 First.get() == E->getArg(0) &&
7274 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
7275 return SemaRef.MaybeBindToTemporary(E);
7277 Sema::FPContractStateRAII FPContractState(getSema());
7278 getSema().FPFeatures.fp_contract = E->isFPContractable();
7280 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7281 E->getOperatorLoc(),
7287 template<typename Derived>
7289 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7290 return getDerived().TransformCallExpr(E);
7293 template<typename Derived>
7295 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7296 // Transform the callee.
7297 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7298 if (Callee.isInvalid())
7301 // Transform exec config.
7302 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7306 // Transform arguments.
7307 bool ArgChanged = false;
7308 SmallVector<Expr*, 8> Args;
7309 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7313 if (!getDerived().AlwaysRebuild() &&
7314 Callee.get() == E->getCallee() &&
7316 return SemaRef.MaybeBindToTemporary(E);
7318 // FIXME: Wrong source location information for the '('.
7319 SourceLocation FakeLParenLoc
7320 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7321 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
7323 E->getRParenLoc(), EC.get());
7326 template<typename Derived>
7328 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
7329 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7334 = getDerived().TransformExpr(E->getSubExprAsWritten());
7335 if (SubExpr.isInvalid())
7338 if (!getDerived().AlwaysRebuild() &&
7339 Type == E->getTypeInfoAsWritten() &&
7340 SubExpr.get() == E->getSubExpr())
7341 return SemaRef.Owned(E);
7342 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
7344 E->getAngleBrackets().getBegin(),
7346 E->getAngleBrackets().getEnd(),
7347 // FIXME. this should be '(' location
7348 E->getAngleBrackets().getEnd(),
7353 template<typename Derived>
7355 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7356 return getDerived().TransformCXXNamedCastExpr(E);
7359 template<typename Derived>
7361 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7362 return getDerived().TransformCXXNamedCastExpr(E);
7365 template<typename Derived>
7367 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
7368 CXXReinterpretCastExpr *E) {
7369 return getDerived().TransformCXXNamedCastExpr(E);
7372 template<typename Derived>
7374 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7375 return getDerived().TransformCXXNamedCastExpr(E);
7378 template<typename Derived>
7380 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
7381 CXXFunctionalCastExpr *E) {
7382 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7387 = getDerived().TransformExpr(E->getSubExprAsWritten());
7388 if (SubExpr.isInvalid())
7391 if (!getDerived().AlwaysRebuild() &&
7392 Type == E->getTypeInfoAsWritten() &&
7393 SubExpr.get() == E->getSubExpr())
7394 return SemaRef.Owned(E);
7396 return getDerived().RebuildCXXFunctionalCastExpr(Type,
7402 template<typename Derived>
7404 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
7405 if (E->isTypeOperand()) {
7406 TypeSourceInfo *TInfo
7407 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7411 if (!getDerived().AlwaysRebuild() &&
7412 TInfo == E->getTypeOperandSourceInfo())
7413 return SemaRef.Owned(E);
7415 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7421 // We don't know whether the subexpression is potentially evaluated until
7422 // after we perform semantic analysis. We speculatively assume it is
7423 // unevaluated; it will get fixed later if the subexpression is in fact
7424 // potentially evaluated.
7425 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7426 Sema::ReuseLambdaContextDecl);
7428 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7429 if (SubExpr.isInvalid())
7432 if (!getDerived().AlwaysRebuild() &&
7433 SubExpr.get() == E->getExprOperand())
7434 return SemaRef.Owned(E);
7436 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7442 template<typename Derived>
7444 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7445 if (E->isTypeOperand()) {
7446 TypeSourceInfo *TInfo
7447 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7451 if (!getDerived().AlwaysRebuild() &&
7452 TInfo == E->getTypeOperandSourceInfo())
7453 return SemaRef.Owned(E);
7455 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7461 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7463 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7464 if (SubExpr.isInvalid())
7467 if (!getDerived().AlwaysRebuild() &&
7468 SubExpr.get() == E->getExprOperand())
7469 return SemaRef.Owned(E);
7471 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7477 template<typename Derived>
7479 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
7480 return SemaRef.Owned(E);
7483 template<typename Derived>
7485 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
7486 CXXNullPtrLiteralExpr *E) {
7487 return SemaRef.Owned(E);
7490 template<typename Derived>
7492 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
7493 QualType T = getSema().getCurrentThisType();
7495 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7496 // Make sure that we capture 'this'.
7497 getSema().CheckCXXThisCapture(E->getLocStart());
7498 return SemaRef.Owned(E);
7501 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
7504 template<typename Derived>
7506 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
7507 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7508 if (SubExpr.isInvalid())
7511 if (!getDerived().AlwaysRebuild() &&
7512 SubExpr.get() == E->getSubExpr())
7513 return SemaRef.Owned(E);
7515 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7516 E->isThrownVariableInScope());
7519 template<typename Derived>
7521 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
7523 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7528 if (!getDerived().AlwaysRebuild() &&
7529 Param == E->getParam())
7530 return SemaRef.Owned(E);
7532 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
7535 template<typename Derived>
7537 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7539 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7544 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7545 return SemaRef.Owned(E);
7547 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7550 template<typename Derived>
7552 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7553 CXXScalarValueInitExpr *E) {
7554 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7558 if (!getDerived().AlwaysRebuild() &&
7559 T == E->getTypeSourceInfo())
7560 return SemaRef.Owned(E);
7562 return getDerived().RebuildCXXScalarValueInitExpr(T,
7563 /*FIXME:*/T->getTypeLoc().getEndLoc(),
7567 template<typename Derived>
7569 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
7570 // Transform the type that we're allocating
7571 TypeSourceInfo *AllocTypeInfo
7572 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7576 // Transform the size of the array we're allocating (if any).
7577 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
7578 if (ArraySize.isInvalid())
7581 // Transform the placement arguments (if any).
7582 bool ArgumentChanged = false;
7583 SmallVector<Expr*, 8> PlacementArgs;
7584 if (getDerived().TransformExprs(E->getPlacementArgs(),
7585 E->getNumPlacementArgs(), true,
7586 PlacementArgs, &ArgumentChanged))
7589 // Transform the initializer (if any).
7590 Expr *OldInit = E->getInitializer();
7593 NewInit = getDerived().TransformExpr(OldInit);
7594 if (NewInit.isInvalid())
7597 // Transform new operator and delete operator.
7598 FunctionDecl *OperatorNew = 0;
7599 if (E->getOperatorNew()) {
7600 OperatorNew = cast_or_null<FunctionDecl>(
7601 getDerived().TransformDecl(E->getLocStart(),
7602 E->getOperatorNew()));
7607 FunctionDecl *OperatorDelete = 0;
7608 if (E->getOperatorDelete()) {
7609 OperatorDelete = cast_or_null<FunctionDecl>(
7610 getDerived().TransformDecl(E->getLocStart(),
7611 E->getOperatorDelete()));
7612 if (!OperatorDelete)
7616 if (!getDerived().AlwaysRebuild() &&
7617 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
7618 ArraySize.get() == E->getArraySize() &&
7619 NewInit.get() == OldInit &&
7620 OperatorNew == E->getOperatorNew() &&
7621 OperatorDelete == E->getOperatorDelete() &&
7623 // Mark any declarations we need as referenced.
7624 // FIXME: instantiation-specific.
7626 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
7628 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
7630 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
7631 QualType ElementType
7632 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7633 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7634 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7635 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7636 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
7641 return SemaRef.Owned(E);
7644 QualType AllocType = AllocTypeInfo->getType();
7645 if (!ArraySize.get()) {
7646 // If no array size was specified, but the new expression was
7647 // instantiated with an array type (e.g., "new T" where T is
7648 // instantiated with "int[4]"), extract the outer bound from the
7649 // array type as our array size. We do this with constant and
7650 // dependently-sized array types.
7651 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7654 } else if (const ConstantArrayType *ConsArrayT
7655 = dyn_cast<ConstantArrayType>(ArrayT)) {
7657 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7658 ConsArrayT->getSize(),
7659 SemaRef.Context.getSizeType(),
7660 /*FIXME:*/E->getLocStart()));
7661 AllocType = ConsArrayT->getElementType();
7662 } else if (const DependentSizedArrayType *DepArrayT
7663 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7664 if (DepArrayT->getSizeExpr()) {
7665 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
7666 AllocType = DepArrayT->getElementType();
7671 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7673 /*FIXME:*/E->getLocStart(),
7675 /*FIXME:*/E->getLocStart(),
7676 E->getTypeIdParens(),
7680 E->getDirectInitRange(),
7684 template<typename Derived>
7686 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
7687 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
7688 if (Operand.isInvalid())
7691 // Transform the delete operator, if known.
7692 FunctionDecl *OperatorDelete = 0;
7693 if (E->getOperatorDelete()) {
7694 OperatorDelete = cast_or_null<FunctionDecl>(
7695 getDerived().TransformDecl(E->getLocStart(),
7696 E->getOperatorDelete()));
7697 if (!OperatorDelete)
7701 if (!getDerived().AlwaysRebuild() &&
7702 Operand.get() == E->getArgument() &&
7703 OperatorDelete == E->getOperatorDelete()) {
7704 // Mark any declarations we need as referenced.
7705 // FIXME: instantiation-specific.
7707 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
7709 if (!E->getArgument()->isTypeDependent()) {
7710 QualType Destroyed = SemaRef.Context.getBaseElementType(
7711 E->getDestroyedType());
7712 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7713 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7714 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7715 SemaRef.LookupDestructor(Record));
7719 return SemaRef.Owned(E);
7722 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7723 E->isGlobalDelete(),
7728 template<typename Derived>
7730 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
7731 CXXPseudoDestructorExpr *E) {
7732 ExprResult Base = getDerived().TransformExpr(E->getBase());
7733 if (Base.isInvalid())
7736 ParsedType ObjectTypePtr;
7737 bool MayBePseudoDestructor = false;
7738 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7739 E->getOperatorLoc(),
7740 E->isArrow()? tok::arrow : tok::period,
7742 MayBePseudoDestructor);
7743 if (Base.isInvalid())
7746 QualType ObjectType = ObjectTypePtr.get();
7747 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7750 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7755 SS.Adopt(QualifierLoc);
7757 PseudoDestructorTypeStorage Destroyed;
7758 if (E->getDestroyedTypeInfo()) {
7759 TypeSourceInfo *DestroyedTypeInfo
7760 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7762 if (!DestroyedTypeInfo)
7764 Destroyed = DestroyedTypeInfo;
7765 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
7766 // We aren't likely to be able to resolve the identifier down to a type
7767 // now anyway, so just retain the identifier.
7768 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7769 E->getDestroyedTypeLoc());
7771 // Look for a destructor known with the given name.
7772 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7773 *E->getDestroyedTypeIdentifier(),
7774 E->getDestroyedTypeLoc(),
7782 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7783 E->getDestroyedTypeLoc());
7786 TypeSourceInfo *ScopeTypeInfo = 0;
7787 if (E->getScopeTypeInfo()) {
7788 CXXScopeSpec EmptySS;
7789 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7790 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
7795 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7796 E->getOperatorLoc(),
7800 E->getColonColonLoc(),
7805 template<typename Derived>
7807 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
7808 UnresolvedLookupExpr *Old) {
7809 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7810 Sema::LookupOrdinaryName);
7812 // Transform all the decls.
7813 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7814 E = Old->decls_end(); I != E; ++I) {
7815 NamedDecl *InstD = static_cast<NamedDecl*>(
7816 getDerived().TransformDecl(Old->getNameLoc(),
7819 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7820 // This can happen because of dependent hiding.
7821 if (isa<UsingShadowDecl>(*I))
7829 // Expand using declarations.
7830 if (isa<UsingDecl>(InstD)) {
7831 UsingDecl *UD = cast<UsingDecl>(InstD);
7832 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7833 E = UD->shadow_end(); I != E; ++I)
7841 // Resolve a kind, but don't do any further analysis. If it's
7842 // ambiguous, the callee needs to deal with it.
7845 // Rebuild the nested-name qualifier, if present.
7847 if (Old->getQualifierLoc()) {
7848 NestedNameSpecifierLoc QualifierLoc
7849 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7853 SS.Adopt(QualifierLoc);
7856 if (Old->getNamingClass()) {
7857 CXXRecordDecl *NamingClass
7858 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7860 Old->getNamingClass()));
7866 R.setNamingClass(NamingClass);
7869 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7871 // If we have neither explicit template arguments, nor the template keyword,
7872 // it's a normal declaration name.
7873 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
7874 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7876 // If we have template arguments, rebuild them, then rebuild the
7877 // templateid expression.
7878 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
7879 if (Old->hasExplicitTemplateArgs() &&
7880 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7881 Old->getNumTemplateArgs(),
7887 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
7888 Old->requiresADL(), &TransArgs);
7891 template<typename Derived>
7893 TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
7894 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7898 if (!getDerived().AlwaysRebuild() &&
7899 T == E->getQueriedTypeSourceInfo())
7900 return SemaRef.Owned(E);
7902 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7908 template<typename Derived>
7910 TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7911 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7915 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7919 if (!getDerived().AlwaysRebuild() &&
7920 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7921 return SemaRef.Owned(E);
7923 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7929 template<typename Derived>
7931 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7932 bool ArgChanged = false;
7933 SmallVector<TypeSourceInfo *, 4> Args;
7934 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7935 TypeSourceInfo *From = E->getArg(I);
7936 TypeLoc FromTL = From->getTypeLoc();
7937 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
7939 TLB.reserve(FromTL.getFullDataSize());
7940 QualType To = getDerived().TransformType(TLB, FromTL);
7944 if (To == From->getType())
7945 Args.push_back(From);
7947 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7955 // We have a pack expansion. Instantiate it.
7956 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
7957 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7958 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7959 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7961 // Determine whether the set of unexpanded parameter packs can and should
7964 bool RetainExpansion = false;
7965 Optional<unsigned> OrigNumExpansions =
7966 ExpansionTL.getTypePtr()->getNumExpansions();
7967 Optional<unsigned> NumExpansions = OrigNumExpansions;
7968 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7969 PatternTL.getSourceRange(),
7971 Expand, RetainExpansion,
7976 // The transform has determined that we should perform a simple
7977 // transformation on the pack expansion, producing another pack
7979 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7982 TLB.reserve(From->getTypeLoc().getFullDataSize());
7984 QualType To = getDerived().TransformType(TLB, PatternTL);
7988 To = getDerived().RebuildPackExpansionType(To,
7989 PatternTL.getSourceRange(),
7990 ExpansionTL.getEllipsisLoc(),
7995 PackExpansionTypeLoc ToExpansionTL
7996 = TLB.push<PackExpansionTypeLoc>(To);
7997 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7998 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8002 // Expand the pack expansion by substituting for each argument in the
8004 for (unsigned I = 0; I != *NumExpansions; ++I) {
8005 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8007 TLB.reserve(PatternTL.getFullDataSize());
8008 QualType To = getDerived().TransformType(TLB, PatternTL);
8012 if (To->containsUnexpandedParameterPack()) {
8013 To = getDerived().RebuildPackExpansionType(To,
8014 PatternTL.getSourceRange(),
8015 ExpansionTL.getEllipsisLoc(),
8020 PackExpansionTypeLoc ToExpansionTL
8021 = TLB.push<PackExpansionTypeLoc>(To);
8022 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8025 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8028 if (!RetainExpansion)
8031 // If we're supposed to retain a pack expansion, do so by temporarily
8032 // forgetting the partially-substituted parameter pack.
8033 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8036 TLB.reserve(From->getTypeLoc().getFullDataSize());
8038 QualType To = getDerived().TransformType(TLB, PatternTL);
8042 To = getDerived().RebuildPackExpansionType(To,
8043 PatternTL.getSourceRange(),
8044 ExpansionTL.getEllipsisLoc(),
8049 PackExpansionTypeLoc ToExpansionTL
8050 = TLB.push<PackExpansionTypeLoc>(To);
8051 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8052 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8055 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8056 return SemaRef.Owned(E);
8058 return getDerived().RebuildTypeTrait(E->getTrait(),
8064 template<typename Derived>
8066 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8067 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8071 if (!getDerived().AlwaysRebuild() &&
8072 T == E->getQueriedTypeSourceInfo())
8073 return SemaRef.Owned(E);
8077 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8078 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8079 if (SubExpr.isInvalid())
8082 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8083 return SemaRef.Owned(E);
8086 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8093 template<typename Derived>
8095 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8098 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8099 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8100 if (SubExpr.isInvalid())
8103 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8104 return SemaRef.Owned(E);
8107 return getDerived().RebuildExpressionTrait(
8108 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8111 template<typename Derived>
8113 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8114 DependentScopeDeclRefExpr *E) {
8115 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8118 template<typename Derived>
8120 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8121 DependentScopeDeclRefExpr *E,
8122 bool IsAddressOfOperand) {
8123 assert(E->getQualifierLoc());
8124 NestedNameSpecifierLoc QualifierLoc
8125 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8128 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8130 // TODO: If this is a conversion-function-id, verify that the
8131 // destination type name (if present) resolves the same way after
8132 // instantiation as it did in the local scope.
8134 DeclarationNameInfo NameInfo
8135 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8136 if (!NameInfo.getName())
8139 if (!E->hasExplicitTemplateArgs()) {
8140 if (!getDerived().AlwaysRebuild() &&
8141 QualifierLoc == E->getQualifierLoc() &&
8142 // Note: it is sufficient to compare the Name component of NameInfo:
8143 // if name has not changed, DNLoc has not changed either.
8144 NameInfo.getName() == E->getDeclName())
8145 return SemaRef.Owned(E);
8147 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
8151 IsAddressOfOperand);
8154 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8155 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8156 E->getNumTemplateArgs(),
8160 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
8164 IsAddressOfOperand);
8167 template<typename Derived>
8169 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
8170 // CXXConstructExprs other than for list-initialization and
8171 // CXXTemporaryObjectExpr are always implicit, so when we have
8172 // a 1-argument construction we just transform that argument.
8173 if ((E->getNumArgs() == 1 ||
8174 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
8175 (!getDerived().DropCallArgument(E->getArg(0))) &&
8176 !E->isListInitialization())
8177 return getDerived().TransformExpr(E->getArg(0));
8179 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8181 QualType T = getDerived().TransformType(E->getType());
8185 CXXConstructorDecl *Constructor
8186 = cast_or_null<CXXConstructorDecl>(
8187 getDerived().TransformDecl(E->getLocStart(),
8188 E->getConstructor()));
8192 bool ArgumentChanged = false;
8193 SmallVector<Expr*, 8> Args;
8194 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8198 if (!getDerived().AlwaysRebuild() &&
8199 T == E->getType() &&
8200 Constructor == E->getConstructor() &&
8202 // Mark the constructor as referenced.
8203 // FIXME: Instantiation-specific
8204 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
8205 return SemaRef.Owned(E);
8208 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8209 Constructor, E->isElidable(),
8211 E->hadMultipleCandidates(),
8212 E->isListInitialization(),
8213 E->requiresZeroInitialization(),
8214 E->getConstructionKind(),
8215 E->getParenOrBraceRange());
8218 /// \brief Transform a C++ temporary-binding expression.
8220 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8221 /// transform the subexpression and return that.
8222 template<typename Derived>
8224 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
8225 return getDerived().TransformExpr(E->getSubExpr());
8228 /// \brief Transform a C++ expression that contains cleanups that should
8229 /// be run after the expression is evaluated.
8231 /// Since ExprWithCleanups nodes are implicitly generated, we
8232 /// just transform the subexpression and return that.
8233 template<typename Derived>
8235 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
8236 return getDerived().TransformExpr(E->getSubExpr());
8239 template<typename Derived>
8241 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
8242 CXXTemporaryObjectExpr *E) {
8243 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8247 CXXConstructorDecl *Constructor
8248 = cast_or_null<CXXConstructorDecl>(
8249 getDerived().TransformDecl(E->getLocStart(),
8250 E->getConstructor()));
8254 bool ArgumentChanged = false;
8255 SmallVector<Expr*, 8> Args;
8256 Args.reserve(E->getNumArgs());
8257 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8261 if (!getDerived().AlwaysRebuild() &&
8262 T == E->getTypeSourceInfo() &&
8263 Constructor == E->getConstructor() &&
8265 // FIXME: Instantiation-specific
8266 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
8267 return SemaRef.MaybeBindToTemporary(E);
8270 // FIXME: Pass in E->isListInitialization().
8271 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8272 /*FIXME:*/T->getTypeLoc().getEndLoc(),
8277 template<typename Derived>
8279 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
8281 // Transform any init-capture expressions before entering the scope of the
8282 // lambda body, because they are not semantically within that scope.
8283 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8284 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8285 E->explicit_capture_begin());
8287 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8288 CEnd = E->capture_end();
8290 if (!C->isInitCapture())
8292 EnterExpressionEvaluationContext EEEC(getSema(),
8293 Sema::PotentiallyEvaluated);
8294 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8295 C->getCapturedVar()->getInit(),
8296 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8298 if (NewExprInitResult.isInvalid())
8300 Expr *NewExprInit = NewExprInitResult.get();
8302 VarDecl *OldVD = C->getCapturedVar();
8303 QualType NewInitCaptureType =
8304 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8305 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8307 NewExprInitResult = NewExprInit;
8308 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8309 std::make_pair(NewExprInitResult, NewInitCaptureType);
8313 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
8314 // Transform the template parameters, and add them to the current
8315 // instantiation scope. The null case is handled correctly.
8316 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8317 E->getTemplateParameterList());
8319 // Check to see if the TypeSourceInfo of the call operator needs to
8320 // be transformed, and if so do the transformation in the
8321 // CurrentInstantiationScope.
8323 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8324 FunctionProtoTypeLoc OldCallOpFPTL =
8325 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8326 TypeSourceInfo *NewCallOpTSI = 0;
8328 const bool CallOpWasAlreadyTransformed =
8329 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8331 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8332 if (CallOpWasAlreadyTransformed)
8333 NewCallOpTSI = OldCallOpTSI;
8335 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8336 // The transformation MUST be done in the CurrentInstantiationScope since
8337 // it introduces a mapping of the original to the newly created
8338 // transformed parameters.
8340 TypeLocBuilder NewCallOpTLBuilder;
8341 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8344 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8347 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8348 // the vector below - this will be used to synthesize the
8349 // NewCallOperator. Additionally, add the parameters of the untransformed
8350 // lambda call operator to the CurrentInstantiationScope.
8351 SmallVector<ParmVarDecl *, 4> Params;
8353 FunctionProtoTypeLoc NewCallOpFPTL =
8354 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8355 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8356 const unsigned NewNumArgs = NewCallOpFPTL.getNumArgs();
8358 for (unsigned I = 0; I < NewNumArgs; ++I) {
8359 // If this call operator's type does not require transformation,
8360 // the parameters do not get added to the current instantiation scope,
8361 // - so ADD them! This allows the following to compile when the enclosing
8362 // template is specialized and the entire lambda expression has to be
8364 // template<class T> void foo(T t) {
8365 // auto L = [](auto a) {
8366 // auto M = [](char b) { <-- note: non-generic lambda
8367 // auto N = [](auto c) {
8368 // int x = sizeof(a);
8369 // x = sizeof(b); <-- specifically this line
8376 if (CallOpWasAlreadyTransformed)
8377 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8378 NewParamDeclArray[I]);
8379 // Add to Params array, so these parameters can be used to create
8380 // the newly transformed call operator.
8381 Params.push_back(NewParamDeclArray[I]);
8388 // Create the local class that will describe the lambda.
8389 CXXRecordDecl *Class
8390 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8392 /*KnownDependent=*/false,
8393 E->getCaptureDefault());
8395 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8397 // Build the call operator.
8398 CXXMethodDecl *NewCallOperator
8399 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
8401 E->getCallOperator()->getLocEnd(),
8403 LSI->CallOperator = NewCallOperator;
8405 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8407 return getDerived().TransformLambdaScope(E, NewCallOperator,
8408 InitCaptureExprsAndTypes);
8411 template<typename Derived>
8413 TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8414 CXXMethodDecl *CallOperator,
8415 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
8416 bool Invalid = false;
8418 // Introduce the context of the call operator.
8419 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8421 LambdaScopeInfo *const LSI = getSema().getCurLambda();
8422 // Enter the scope of the lambda.
8423 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
8424 E->getCaptureDefault(),
8425 E->getCaptureDefaultLoc(),
8426 E->hasExplicitParameters(),
8427 E->hasExplicitResultType(),
8430 // Transform captures.
8431 bool FinishedExplicitCaptures = false;
8432 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8433 CEnd = E->capture_end();
8435 // When we hit the first implicit capture, tell Sema that we've finished
8436 // the list of explicit captures.
8437 if (!FinishedExplicitCaptures && C->isImplicit()) {
8438 getSema().finishLambdaExplicitCaptures(LSI);
8439 FinishedExplicitCaptures = true;
8442 // Capturing 'this' is trivial.
8443 if (C->capturesThis()) {
8444 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8448 // Rebuild init-captures, including the implied field declaration.
8449 if (C->isInitCapture()) {
8451 InitCaptureInfoTy InitExprTypePair =
8452 InitCaptureExprsAndTypes[C - E->capture_begin()];
8453 ExprResult Init = InitExprTypePair.first;
8454 QualType InitQualType = InitExprTypePair.second;
8455 if (Init.isInvalid() || InitQualType.isNull()) {
8459 VarDecl *OldVD = C->getCapturedVar();
8460 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8461 OldVD->getLocation(), InitExprTypePair.second,
8462 OldVD->getIdentifier(), Init.get());
8466 getDerived().transformedLocalDecl(OldVD, NewVD);
8468 getSema().buildInitCaptureField(LSI, NewVD);
8472 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8474 // Determine the capture kind for Sema.
8475 Sema::TryCaptureKind Kind
8476 = C->isImplicit()? Sema::TryCapture_Implicit
8477 : C->getCaptureKind() == LCK_ByCopy
8478 ? Sema::TryCapture_ExplicitByVal
8479 : Sema::TryCapture_ExplicitByRef;
8480 SourceLocation EllipsisLoc;
8481 if (C->isPackExpansion()) {
8482 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8483 bool ShouldExpand = false;
8484 bool RetainExpansion = false;
8485 Optional<unsigned> NumExpansions;
8486 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8489 ShouldExpand, RetainExpansion,
8496 // The transform has determined that we should perform an expansion;
8497 // transform and capture each of the arguments.
8498 // expansion of the pattern. Do so.
8499 VarDecl *Pack = C->getCapturedVar();
8500 for (unsigned I = 0; I != *NumExpansions; ++I) {
8501 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8502 VarDecl *CapturedVar
8503 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
8510 // Capture the transformed variable.
8511 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8516 EllipsisLoc = C->getEllipsisLoc();
8519 // Transform the captured variable.
8520 VarDecl *CapturedVar
8521 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
8522 C->getCapturedVar()));
8528 // Capture the transformed variable.
8529 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8531 if (!FinishedExplicitCaptures)
8532 getSema().finishLambdaExplicitCaptures(LSI);
8535 // Enter a new evaluation context to insulate the lambda from any
8536 // cleanups from the enclosing full-expression.
8537 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8540 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8541 /*IsInstantiation=*/true);
8545 // Instantiate the body of the lambda expression.
8546 StmtResult Body = getDerived().TransformStmt(E->getBody());
8547 if (Body.isInvalid()) {
8548 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8549 /*IsInstantiation=*/true);
8553 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
8554 /*CurScope=*/0, /*IsInstantiation=*/true);
8557 template<typename Derived>
8559 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
8560 CXXUnresolvedConstructExpr *E) {
8561 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8565 bool ArgumentChanged = false;
8566 SmallVector<Expr*, 8> Args;
8567 Args.reserve(E->arg_size());
8568 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8572 if (!getDerived().AlwaysRebuild() &&
8573 T == E->getTypeSourceInfo() &&
8575 return SemaRef.Owned(E);
8577 // FIXME: we're faking the locations of the commas
8578 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
8584 template<typename Derived>
8586 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
8587 CXXDependentScopeMemberExpr *E) {
8588 // Transform the base of the expression.
8589 ExprResult Base((Expr*) 0);
8592 QualType ObjectType;
8593 if (!E->isImplicitAccess()) {
8594 OldBase = E->getBase();
8595 Base = getDerived().TransformExpr(OldBase);
8596 if (Base.isInvalid())
8599 // Start the member reference and compute the object's type.
8600 ParsedType ObjectTy;
8601 bool MayBePseudoDestructor = false;
8602 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
8603 E->getOperatorLoc(),
8604 E->isArrow()? tok::arrow : tok::period,
8606 MayBePseudoDestructor);
8607 if (Base.isInvalid())
8610 ObjectType = ObjectTy.get();
8611 BaseType = ((Expr*) Base.get())->getType();
8614 BaseType = getDerived().TransformType(E->getBaseType());
8615 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8618 // Transform the first part of the nested-name-specifier that qualifies
8620 NamedDecl *FirstQualifierInScope
8621 = getDerived().TransformFirstQualifierInScope(
8622 E->getFirstQualifierFoundInScope(),
8623 E->getQualifierLoc().getBeginLoc());
8625 NestedNameSpecifierLoc QualifierLoc;
8626 if (E->getQualifier()) {
8628 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8630 FirstQualifierInScope);
8635 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8637 // TODO: If this is a conversion-function-id, verify that the
8638 // destination type name (if present) resolves the same way after
8639 // instantiation as it did in the local scope.
8641 DeclarationNameInfo NameInfo
8642 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
8643 if (!NameInfo.getName())
8646 if (!E->hasExplicitTemplateArgs()) {
8647 // This is a reference to a member without an explicitly-specified
8648 // template argument list. Optimize for this common case.
8649 if (!getDerived().AlwaysRebuild() &&
8650 Base.get() == OldBase &&
8651 BaseType == E->getBaseType() &&
8652 QualifierLoc == E->getQualifierLoc() &&
8653 NameInfo.getName() == E->getMember() &&
8654 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
8655 return SemaRef.Owned(E);
8657 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8660 E->getOperatorLoc(),
8663 FirstQualifierInScope,
8665 /*TemplateArgs*/ 0);
8668 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8669 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8670 E->getNumTemplateArgs(),
8674 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8677 E->getOperatorLoc(),
8680 FirstQualifierInScope,
8685 template<typename Derived>
8687 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
8688 // Transform the base of the expression.
8689 ExprResult Base((Expr*) 0);
8691 if (!Old->isImplicitAccess()) {
8692 Base = getDerived().TransformExpr(Old->getBase());
8693 if (Base.isInvalid())
8695 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8697 if (Base.isInvalid())
8699 BaseType = Base.get()->getType();
8701 BaseType = getDerived().TransformType(Old->getBaseType());
8704 NestedNameSpecifierLoc QualifierLoc;
8705 if (Old->getQualifierLoc()) {
8707 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8712 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8714 LookupResult R(SemaRef, Old->getMemberNameInfo(),
8715 Sema::LookupOrdinaryName);
8717 // Transform all the decls.
8718 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8719 E = Old->decls_end(); I != E; ++I) {
8720 NamedDecl *InstD = static_cast<NamedDecl*>(
8721 getDerived().TransformDecl(Old->getMemberLoc(),
8724 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8725 // This can happen because of dependent hiding.
8726 if (isa<UsingShadowDecl>(*I))
8734 // Expand using declarations.
8735 if (isa<UsingDecl>(InstD)) {
8736 UsingDecl *UD = cast<UsingDecl>(InstD);
8737 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8738 E = UD->shadow_end(); I != E; ++I)
8748 // Determine the naming class.
8749 if (Old->getNamingClass()) {
8750 CXXRecordDecl *NamingClass
8751 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8752 Old->getMemberLoc(),
8753 Old->getNamingClass()));
8757 R.setNamingClass(NamingClass);
8760 TemplateArgumentListInfo TransArgs;
8761 if (Old->hasExplicitTemplateArgs()) {
8762 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8763 TransArgs.setRAngleLoc(Old->getRAngleLoc());
8764 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8765 Old->getNumTemplateArgs(),
8770 // FIXME: to do this check properly, we will need to preserve the
8771 // first-qualifier-in-scope here, just in case we had a dependent
8772 // base (and therefore couldn't do the check) and a
8773 // nested-name-qualifier (and therefore could do the lookup).
8774 NamedDecl *FirstQualifierInScope = 0;
8776 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
8778 Old->getOperatorLoc(),
8782 FirstQualifierInScope,
8784 (Old->hasExplicitTemplateArgs()
8788 template<typename Derived>
8790 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
8791 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8792 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8793 if (SubExpr.isInvalid())
8796 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
8797 return SemaRef.Owned(E);
8799 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8802 template<typename Derived>
8804 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
8805 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8806 if (Pattern.isInvalid())
8809 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8810 return SemaRef.Owned(E);
8812 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8813 E->getNumExpansions());
8816 template<typename Derived>
8818 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8819 // If E is not value-dependent, then nothing will change when we transform it.
8820 // Note: This is an instantiation-centric view.
8821 if (!E->isValueDependent())
8822 return SemaRef.Owned(E);
8824 // Note: None of the implementations of TryExpandParameterPacks can ever
8825 // produce a diagnostic when given only a single unexpanded parameter pack,
8827 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8828 bool ShouldExpand = false;
8829 bool RetainExpansion = false;
8830 Optional<unsigned> NumExpansions;
8831 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
8833 ShouldExpand, RetainExpansion,
8837 if (RetainExpansion)
8838 return SemaRef.Owned(E);
8840 NamedDecl *Pack = E->getPack();
8841 if (!ShouldExpand) {
8842 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8849 // We now know the length of the parameter pack, so build a new expression
8850 // that stores that length.
8851 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8852 E->getPackLoc(), E->getRParenLoc(),
8856 template<typename Derived>
8858 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8859 SubstNonTypeTemplateParmPackExpr *E) {
8860 // Default behavior is to do nothing with this transformation.
8861 return SemaRef.Owned(E);
8864 template<typename Derived>
8866 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8867 SubstNonTypeTemplateParmExpr *E) {
8868 // Default behavior is to do nothing with this transformation.
8869 return SemaRef.Owned(E);
8872 template<typename Derived>
8874 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8875 // Default behavior is to do nothing with this transformation.
8876 return SemaRef.Owned(E);
8879 template<typename Derived>
8881 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8882 MaterializeTemporaryExpr *E) {
8883 return getDerived().TransformExpr(E->GetTemporaryExpr());
8886 template<typename Derived>
8888 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8889 CXXStdInitializerListExpr *E) {
8890 return getDerived().TransformExpr(E->getSubExpr());
8893 template<typename Derived>
8895 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
8896 return SemaRef.MaybeBindToTemporary(E);
8899 template<typename Derived>
8901 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
8902 return SemaRef.Owned(E);
8905 template<typename Derived>
8907 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8908 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8909 if (SubExpr.isInvalid())
8912 if (!getDerived().AlwaysRebuild() &&
8913 SubExpr.get() == E->getSubExpr())
8914 return SemaRef.Owned(E);
8916 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
8919 template<typename Derived>
8921 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8922 // Transform each of the elements.
8923 SmallVector<Expr *, 8> Elements;
8924 bool ArgChanged = false;
8925 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8926 /*IsCall=*/false, Elements, &ArgChanged))
8929 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8930 return SemaRef.MaybeBindToTemporary(E);
8932 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8937 template<typename Derived>
8939 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8940 ObjCDictionaryLiteral *E) {
8941 // Transform each of the elements.
8942 SmallVector<ObjCDictionaryElement, 8> Elements;
8943 bool ArgChanged = false;
8944 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8945 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8947 if (OrigElement.isPackExpansion()) {
8948 // This key/value element is a pack expansion.
8949 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8950 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8951 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8952 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8954 // Determine whether the set of unexpanded parameter packs can
8955 // and should be expanded.
8957 bool RetainExpansion = false;
8958 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8959 Optional<unsigned> NumExpansions = OrigNumExpansions;
8960 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8961 OrigElement.Value->getLocEnd());
8962 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8965 Expand, RetainExpansion,
8970 // The transform has determined that we should perform a simple
8971 // transformation on the pack expansion, producing another pack
8973 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8974 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8975 if (Key.isInvalid())
8978 if (Key.get() != OrigElement.Key)
8981 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8982 if (Value.isInvalid())
8985 if (Value.get() != OrigElement.Value)
8988 ObjCDictionaryElement Expansion = {
8989 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8991 Elements.push_back(Expansion);
8995 // Record right away that the argument was changed. This needs
8996 // to happen even if the array expands to nothing.
8999 // The transform has determined that we should perform an elementwise
9000 // expansion of the pattern. Do so.
9001 for (unsigned I = 0; I != *NumExpansions; ++I) {
9002 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9003 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9004 if (Key.isInvalid())
9007 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9008 if (Value.isInvalid())
9011 ObjCDictionaryElement Element = {
9012 Key.get(), Value.get(), SourceLocation(), NumExpansions
9015 // If any unexpanded parameter packs remain, we still have a
9017 if (Key.get()->containsUnexpandedParameterPack() ||
9018 Value.get()->containsUnexpandedParameterPack())
9019 Element.EllipsisLoc = OrigElement.EllipsisLoc;
9021 Elements.push_back(Element);
9024 // We've finished with this pack expansion.
9028 // Transform and check key.
9029 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9030 if (Key.isInvalid())
9033 if (Key.get() != OrigElement.Key)
9036 // Transform and check value.
9038 = getDerived().TransformExpr(OrigElement.Value);
9039 if (Value.isInvalid())
9042 if (Value.get() != OrigElement.Value)
9045 ObjCDictionaryElement Element = {
9046 Key.get(), Value.get(), SourceLocation(), None
9048 Elements.push_back(Element);
9051 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9052 return SemaRef.MaybeBindToTemporary(E);
9054 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9059 template<typename Derived>
9061 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
9062 TypeSourceInfo *EncodedTypeInfo
9063 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9064 if (!EncodedTypeInfo)
9067 if (!getDerived().AlwaysRebuild() &&
9068 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
9069 return SemaRef.Owned(E);
9071 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
9076 template<typename Derived>
9077 ExprResult TreeTransform<Derived>::
9078 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
9079 // This is a kind of implicit conversion, and it needs to get dropped
9080 // and recomputed for the same general reasons that ImplicitCastExprs
9081 // do, as well a more specific one: this expression is only valid when
9082 // it appears *immediately* as an argument expression.
9083 return getDerived().TransformExpr(E->getSubExpr());
9086 template<typename Derived>
9087 ExprResult TreeTransform<Derived>::
9088 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
9089 TypeSourceInfo *TSInfo
9090 = getDerived().TransformType(E->getTypeInfoAsWritten());
9094 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
9095 if (Result.isInvalid())
9098 if (!getDerived().AlwaysRebuild() &&
9099 TSInfo == E->getTypeInfoAsWritten() &&
9100 Result.get() == E->getSubExpr())
9101 return SemaRef.Owned(E);
9103 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
9104 E->getBridgeKeywordLoc(), TSInfo,
9108 template<typename Derived>
9110 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
9111 // Transform arguments.
9112 bool ArgChanged = false;
9113 SmallVector<Expr*, 8> Args;
9114 Args.reserve(E->getNumArgs());
9115 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
9119 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9120 // Class message: transform the receiver type.
9121 TypeSourceInfo *ReceiverTypeInfo
9122 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9123 if (!ReceiverTypeInfo)
9126 // If nothing changed, just retain the existing message send.
9127 if (!getDerived().AlwaysRebuild() &&
9128 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
9129 return SemaRef.MaybeBindToTemporary(E);
9131 // Build a new class message send.
9132 SmallVector<SourceLocation, 16> SelLocs;
9133 E->getSelectorLocs(SelLocs);
9134 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9143 // Instance message: transform the receiver
9144 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9145 "Only class and instance messages may be instantiated");
9147 = getDerived().TransformExpr(E->getInstanceReceiver());
9148 if (Receiver.isInvalid())
9151 // If nothing changed, just retain the existing message send.
9152 if (!getDerived().AlwaysRebuild() &&
9153 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
9154 return SemaRef.MaybeBindToTemporary(E);
9156 // Build a new instance message send.
9157 SmallVector<SourceLocation, 16> SelLocs;
9158 E->getSelectorLocs(SelLocs);
9159 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
9168 template<typename Derived>
9170 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
9171 return SemaRef.Owned(E);
9174 template<typename Derived>
9176 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
9177 return SemaRef.Owned(E);
9180 template<typename Derived>
9182 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
9183 // Transform the base expression.
9184 ExprResult Base = getDerived().TransformExpr(E->getBase());
9185 if (Base.isInvalid())
9188 // We don't need to transform the ivar; it will never change.
9190 // If nothing changed, just retain the existing expression.
9191 if (!getDerived().AlwaysRebuild() &&
9192 Base.get() == E->getBase())
9193 return SemaRef.Owned(E);
9195 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
9197 E->isArrow(), E->isFreeIvar());
9200 template<typename Derived>
9202 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
9203 // 'super' and types never change. Property never changes. Just
9204 // retain the existing expression.
9205 if (!E->isObjectReceiver())
9206 return SemaRef.Owned(E);
9208 // Transform the base expression.
9209 ExprResult Base = getDerived().TransformExpr(E->getBase());
9210 if (Base.isInvalid())
9213 // We don't need to transform the property; it will never change.
9215 // If nothing changed, just retain the existing expression.
9216 if (!getDerived().AlwaysRebuild() &&
9217 Base.get() == E->getBase())
9218 return SemaRef.Owned(E);
9220 if (E->isExplicitProperty())
9221 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9222 E->getExplicitProperty(),
9225 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9226 SemaRef.Context.PseudoObjectTy,
9227 E->getImplicitPropertyGetter(),
9228 E->getImplicitPropertySetter(),
9232 template<typename Derived>
9234 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9235 // Transform the base expression.
9236 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9237 if (Base.isInvalid())
9240 // Transform the key expression.
9241 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9242 if (Key.isInvalid())
9245 // If nothing changed, just retain the existing expression.
9246 if (!getDerived().AlwaysRebuild() &&
9247 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9248 return SemaRef.Owned(E);
9250 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
9251 Base.get(), Key.get(),
9252 E->getAtIndexMethodDecl(),
9253 E->setAtIndexMethodDecl());
9256 template<typename Derived>
9258 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
9259 // Transform the base expression.
9260 ExprResult Base = getDerived().TransformExpr(E->getBase());
9261 if (Base.isInvalid())
9264 // If nothing changed, just retain the existing expression.
9265 if (!getDerived().AlwaysRebuild() &&
9266 Base.get() == E->getBase())
9267 return SemaRef.Owned(E);
9269 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
9274 template<typename Derived>
9276 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
9277 bool ArgumentChanged = false;
9278 SmallVector<Expr*, 8> SubExprs;
9279 SubExprs.reserve(E->getNumSubExprs());
9280 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9281 SubExprs, &ArgumentChanged))
9284 if (!getDerived().AlwaysRebuild() &&
9286 return SemaRef.Owned(E);
9288 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
9293 template<typename Derived>
9295 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9296 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9297 if (SrcExpr.isInvalid())
9300 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9304 if (!getDerived().AlwaysRebuild() &&
9305 Type == E->getTypeSourceInfo() &&
9306 SrcExpr.get() == E->getSrcExpr())
9307 return SemaRef.Owned(E);
9309 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9310 SrcExpr.get(), Type,
9314 template<typename Derived>
9316 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
9317 BlockDecl *oldBlock = E->getBlockDecl();
9319 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9320 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9322 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
9323 blockScope->TheDecl->setBlockMissingReturnType(
9324 oldBlock->blockMissingReturnType());
9326 SmallVector<ParmVarDecl*, 4> params;
9327 SmallVector<QualType, 4> paramTypes;
9329 // Parameter substitution.
9330 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9331 oldBlock->param_begin(),
9332 oldBlock->param_size(),
9333 0, paramTypes, ¶ms)) {
9334 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
9338 const FunctionProtoType *exprFunctionType = E->getFunctionType();
9339 QualType exprResultType =
9340 getDerived().TransformType(exprFunctionType->getResultType());
9342 QualType functionType =
9343 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
9344 exprFunctionType->getExtProtoInfo());
9345 blockScope->FunctionType = functionType;
9347 // Set the parameters on the block decl.
9348 if (!params.empty())
9349 blockScope->TheDecl->setParams(params);
9351 if (!oldBlock->blockMissingReturnType()) {
9352 blockScope->HasImplicitReturnType = false;
9353 blockScope->ReturnType = exprResultType;
9356 // Transform the body
9357 StmtResult body = getDerived().TransformStmt(E->getBody());
9358 if (body.isInvalid()) {
9359 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
9364 // In builds with assertions, make sure that we captured everything we
9366 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9367 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9368 e = oldBlock->capture_end(); i != e; ++i) {
9369 VarDecl *oldCapture = i->getVariable();
9371 // Ignore parameter packs.
9372 if (isa<ParmVarDecl>(oldCapture) &&
9373 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9376 VarDecl *newCapture =
9377 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9379 assert(blockScope->CaptureMap.count(newCapture));
9381 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
9385 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9389 template<typename Derived>
9391 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
9392 llvm_unreachable("Cannot transform asType expressions yet");
9395 template<typename Derived>
9397 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
9398 QualType RetTy = getDerived().TransformType(E->getType());
9399 bool ArgumentChanged = false;
9400 SmallVector<Expr*, 8> SubExprs;
9401 SubExprs.reserve(E->getNumSubExprs());
9402 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9403 SubExprs, &ArgumentChanged))
9406 if (!getDerived().AlwaysRebuild() &&
9408 return SemaRef.Owned(E);
9410 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
9411 RetTy, E->getOp(), E->getRParenLoc());
9414 //===----------------------------------------------------------------------===//
9415 // Type reconstruction
9416 //===----------------------------------------------------------------------===//
9418 template<typename Derived>
9419 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9420 SourceLocation Star) {
9421 return SemaRef.BuildPointerType(PointeeType, Star,
9422 getDerived().getBaseEntity());
9425 template<typename Derived>
9426 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9427 SourceLocation Star) {
9428 return SemaRef.BuildBlockPointerType(PointeeType, Star,
9429 getDerived().getBaseEntity());
9432 template<typename Derived>
9434 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9435 bool WrittenAsLValue,
9436 SourceLocation Sigil) {
9437 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
9438 Sigil, getDerived().getBaseEntity());
9441 template<typename Derived>
9443 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9445 SourceLocation Sigil) {
9446 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
9447 Sigil, getDerived().getBaseEntity());
9450 template<typename Derived>
9452 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9453 ArrayType::ArraySizeModifier SizeMod,
9454 const llvm::APInt *Size,
9456 unsigned IndexTypeQuals,
9457 SourceRange BracketsRange) {
9458 if (SizeExpr || !Size)
9459 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9460 IndexTypeQuals, BracketsRange,
9461 getDerived().getBaseEntity());
9463 QualType Types[] = {
9464 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9465 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9466 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
9468 const unsigned NumTypes = llvm::array_lengthof(Types);
9470 for (unsigned I = 0; I != NumTypes; ++I)
9471 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9472 SizeType = Types[I];
9476 // Note that we can return a VariableArrayType here in the case where
9477 // the element type was a dependent VariableArrayType.
9478 IntegerLiteral *ArraySize
9479 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9480 /*FIXME*/BracketsRange.getBegin());
9481 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
9482 IndexTypeQuals, BracketsRange,
9483 getDerived().getBaseEntity());
9486 template<typename Derived>
9488 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
9489 ArrayType::ArraySizeModifier SizeMod,
9490 const llvm::APInt &Size,
9491 unsigned IndexTypeQuals,
9492 SourceRange BracketsRange) {
9493 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
9494 IndexTypeQuals, BracketsRange);
9497 template<typename Derived>
9499 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
9500 ArrayType::ArraySizeModifier SizeMod,
9501 unsigned IndexTypeQuals,
9502 SourceRange BracketsRange) {
9503 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
9504 IndexTypeQuals, BracketsRange);
9507 template<typename Derived>
9509 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
9510 ArrayType::ArraySizeModifier SizeMod,
9512 unsigned IndexTypeQuals,
9513 SourceRange BracketsRange) {
9514 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
9516 IndexTypeQuals, BracketsRange);
9519 template<typename Derived>
9521 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
9522 ArrayType::ArraySizeModifier SizeMod,
9524 unsigned IndexTypeQuals,
9525 SourceRange BracketsRange) {
9526 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
9528 IndexTypeQuals, BracketsRange);
9531 template<typename Derived>
9532 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
9533 unsigned NumElements,
9534 VectorType::VectorKind VecKind) {
9535 // FIXME: semantic checking!
9536 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
9539 template<typename Derived>
9540 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9541 unsigned NumElements,
9542 SourceLocation AttributeLoc) {
9543 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9545 IntegerLiteral *VectorSize
9546 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9548 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
9551 template<typename Derived>
9553 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
9555 SourceLocation AttributeLoc) {
9556 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
9559 template<typename Derived>
9560 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9562 llvm::MutableArrayRef<QualType> ParamTypes,
9563 const FunctionProtoType::ExtProtoInfo &EPI) {
9564 return SemaRef.BuildFunctionType(T, ParamTypes,
9565 getDerived().getBaseLocation(),
9566 getDerived().getBaseEntity(),
9570 template<typename Derived>
9571 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9572 return SemaRef.Context.getFunctionNoProtoType(T);
9575 template<typename Derived>
9576 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9577 assert(D && "no decl found");
9578 if (D->isInvalidDecl()) return QualType();
9580 // FIXME: Doesn't account for ObjCInterfaceDecl!
9582 if (isa<UsingDecl>(D)) {
9583 UsingDecl *Using = cast<UsingDecl>(D);
9584 assert(Using->hasTypename() &&
9585 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9587 // A valid resolved using typename decl points to exactly one type decl.
9588 assert(++Using->shadow_begin() == Using->shadow_end());
9589 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
9592 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9593 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9594 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9597 return SemaRef.Context.getTypeDeclType(Ty);
9600 template<typename Derived>
9601 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9602 SourceLocation Loc) {
9603 return SemaRef.BuildTypeofExprType(E, Loc);
9606 template<typename Derived>
9607 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9608 return SemaRef.Context.getTypeOfType(Underlying);
9611 template<typename Derived>
9612 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9613 SourceLocation Loc) {
9614 return SemaRef.BuildDecltypeType(E, Loc);
9617 template<typename Derived>
9618 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9619 UnaryTransformType::UTTKind UKind,
9620 SourceLocation Loc) {
9621 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9624 template<typename Derived>
9625 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
9626 TemplateName Template,
9627 SourceLocation TemplateNameLoc,
9628 TemplateArgumentListInfo &TemplateArgs) {
9629 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
9632 template<typename Derived>
9633 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9634 SourceLocation KWLoc) {
9635 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9638 template<typename Derived>
9640 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9642 TemplateDecl *Template) {
9643 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
9647 template<typename Derived>
9649 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9650 const IdentifierInfo &Name,
9651 SourceLocation NameLoc,
9652 QualType ObjectType,
9653 NamedDecl *FirstQualifierInScope) {
9654 UnqualifiedId TemplateName;
9655 TemplateName.setIdentifier(&Name, NameLoc);
9656 Sema::TemplateTy Template;
9657 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9658 getSema().ActOnDependentTemplateName(/*Scope=*/0,
9659 SS, TemplateKWLoc, TemplateName,
9660 ParsedType::make(ObjectType),
9661 /*EnteringContext=*/false,
9663 return Template.get();
9666 template<typename Derived>
9668 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9669 OverloadedOperatorKind Operator,
9670 SourceLocation NameLoc,
9671 QualType ObjectType) {
9673 // FIXME: Bogus location information.
9674 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
9675 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
9676 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9677 Sema::TemplateTy Template;
9678 getSema().ActOnDependentTemplateName(/*Scope=*/0,
9679 SS, TemplateKWLoc, Name,
9680 ParsedType::make(ObjectType),
9681 /*EnteringContext=*/false,
9683 return Template.get();
9686 template<typename Derived>
9688 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9689 SourceLocation OpLoc,
9693 Expr *Callee = OrigCallee->IgnoreParenCasts();
9694 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
9696 // Determine whether this should be a builtin operation.
9697 if (Op == OO_Subscript) {
9698 if (!First->getType()->isOverloadableType() &&
9699 !Second->getType()->isOverloadableType())
9700 return getSema().CreateBuiltinArraySubscriptExpr(First,
9701 Callee->getLocStart(),
9703 } else if (Op == OO_Arrow) {
9704 // -> is never a builtin operation.
9705 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9706 } else if (Second == 0 || isPostIncDec) {
9707 if (!First->getType()->isOverloadableType()) {
9708 // The argument is not of overloadable type, so try to create a
9709 // built-in unary operation.
9710 UnaryOperatorKind Opc
9711 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
9713 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
9716 if (!First->getType()->isOverloadableType() &&
9717 !Second->getType()->isOverloadableType()) {
9718 // Neither of the arguments is an overloadable type, so try to
9719 // create a built-in binary operation.
9720 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9722 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
9723 if (Result.isInvalid())
9730 // Compute the transformed set of functions (and function templates) to be
9731 // used during overload resolution.
9732 UnresolvedSet<16> Functions;
9734 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
9735 assert(ULE->requiresADL());
9737 // FIXME: Do we have to check
9738 // IsAcceptableNonMemberOperatorCandidate for each of these?
9739 Functions.append(ULE->decls_begin(), ULE->decls_end());
9741 // If we've resolved this to a particular non-member function, just call
9742 // that function. If we resolved it to a member function,
9743 // CreateOverloaded* will find that function for us.
9744 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9745 if (!isa<CXXMethodDecl>(ND))
9746 Functions.addDecl(ND);
9749 // Add any functions found via argument-dependent lookup.
9750 Expr *Args[2] = { First, Second };
9751 unsigned NumArgs = 1 + (Second != 0);
9753 // Create the overloaded operator invocation for unary operators.
9754 if (NumArgs == 1 || isPostIncDec) {
9755 UnaryOperatorKind Opc
9756 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
9757 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
9760 if (Op == OO_Subscript) {
9761 SourceLocation LBrace;
9762 SourceLocation RBrace;
9764 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9765 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9766 LBrace = SourceLocation::getFromRawEncoding(
9767 NameLoc.CXXOperatorName.BeginOpNameLoc);
9768 RBrace = SourceLocation::getFromRawEncoding(
9769 NameLoc.CXXOperatorName.EndOpNameLoc);
9771 LBrace = Callee->getLocStart();
9775 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9779 // Create the overloaded operator invocation for binary operators.
9780 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9782 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9783 if (Result.isInvalid())
9789 template<typename Derived>
9791 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
9792 SourceLocation OperatorLoc,
9795 TypeSourceInfo *ScopeType,
9796 SourceLocation CCLoc,
9797 SourceLocation TildeLoc,
9798 PseudoDestructorTypeStorage Destroyed) {
9799 QualType BaseType = Base->getType();
9800 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
9801 (!isArrow && !BaseType->getAs<RecordType>()) ||
9802 (isArrow && BaseType->getAs<PointerType>() &&
9803 !BaseType->getAs<PointerType>()->getPointeeType()
9804 ->template getAs<RecordType>())){
9805 // This pseudo-destructor expression is still a pseudo-destructor.
9806 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
9807 isArrow? tok::arrow : tok::period,
9808 SS, ScopeType, CCLoc, TildeLoc,
9813 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
9814 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9815 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9816 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9817 NameInfo.setNamedTypeInfo(DestroyedType);
9819 // The scope type is now known to be a valid nested name specifier
9820 // component. Tack it on to the end of the nested name specifier.
9822 SS.Extend(SemaRef.Context, SourceLocation(),
9823 ScopeType->getTypeLoc(), CCLoc);
9825 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9826 return getSema().BuildMemberReferenceExpr(Base, BaseType,
9827 OperatorLoc, isArrow,
9829 /*FIXME: FirstQualifier*/ 0,
9831 /*TemplateArgs*/ 0);
9834 template<typename Derived>
9836 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
9837 SourceLocation Loc = S->getLocStart();
9838 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9839 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9840 S->getCapturedRegionKind(), NumParams);
9841 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9843 if (Body.isInvalid()) {
9844 getSema().ActOnCapturedRegionError();
9848 return getSema().ActOnCapturedRegionEnd(Body.take());
9851 } // end namespace clang
9853 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H