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 // We might have constant size array now, but fortunately it has the same
3971 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3972 NewTL.setLBracketLoc(TL.getLBracketLoc());
3973 NewTL.setRBracketLoc(TL.getRBracketLoc());
3974 NewTL.setSizeExpr(Size);
3979 template<typename Derived>
3981 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
3982 DependentSizedArrayTypeLoc TL) {
3983 const DependentSizedArrayType *T = TL.getTypePtr();
3984 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3985 if (ElementType.isNull())
3988 // Array bounds are constant expressions.
3989 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3990 Sema::ConstantEvaluated);
3992 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3993 Expr *origSize = TL.getSizeExpr();
3994 if (!origSize) origSize = T->getSizeExpr();
3996 ExprResult sizeResult
3997 = getDerived().TransformExpr(origSize);
3998 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
3999 if (sizeResult.isInvalid())
4002 Expr *size = sizeResult.get();
4004 QualType Result = TL.getType();
4005 if (getDerived().AlwaysRebuild() ||
4006 ElementType != T->getElementType() ||
4008 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4009 T->getSizeModifier(),
4011 T->getIndexTypeCVRQualifiers(),
4012 TL.getBracketsRange());
4013 if (Result.isNull())
4017 // We might have any sort of array type now, but fortunately they
4018 // all have the same location layout.
4019 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4020 NewTL.setLBracketLoc(TL.getLBracketLoc());
4021 NewTL.setRBracketLoc(TL.getRBracketLoc());
4022 NewTL.setSizeExpr(size);
4027 template<typename Derived>
4028 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4029 TypeLocBuilder &TLB,
4030 DependentSizedExtVectorTypeLoc TL) {
4031 const DependentSizedExtVectorType *T = TL.getTypePtr();
4033 // FIXME: ext vector locs should be nested
4034 QualType ElementType = getDerived().TransformType(T->getElementType());
4035 if (ElementType.isNull())
4038 // Vector sizes are constant expressions.
4039 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4040 Sema::ConstantEvaluated);
4042 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4043 Size = SemaRef.ActOnConstantExpression(Size);
4044 if (Size.isInvalid())
4047 QualType Result = TL.getType();
4048 if (getDerived().AlwaysRebuild() ||
4049 ElementType != T->getElementType() ||
4050 Size.get() != T->getSizeExpr()) {
4051 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4053 T->getAttributeLoc());
4054 if (Result.isNull())
4058 // Result might be dependent or not.
4059 if (isa<DependentSizedExtVectorType>(Result)) {
4060 DependentSizedExtVectorTypeLoc NewTL
4061 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4062 NewTL.setNameLoc(TL.getNameLoc());
4064 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4065 NewTL.setNameLoc(TL.getNameLoc());
4071 template<typename Derived>
4072 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4074 const VectorType *T = TL.getTypePtr();
4075 QualType ElementType = getDerived().TransformType(T->getElementType());
4076 if (ElementType.isNull())
4079 QualType Result = TL.getType();
4080 if (getDerived().AlwaysRebuild() ||
4081 ElementType != T->getElementType()) {
4082 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4083 T->getVectorKind());
4084 if (Result.isNull())
4088 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4089 NewTL.setNameLoc(TL.getNameLoc());
4094 template<typename Derived>
4095 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4096 ExtVectorTypeLoc TL) {
4097 const VectorType *T = TL.getTypePtr();
4098 QualType ElementType = getDerived().TransformType(T->getElementType());
4099 if (ElementType.isNull())
4102 QualType Result = TL.getType();
4103 if (getDerived().AlwaysRebuild() ||
4104 ElementType != T->getElementType()) {
4105 Result = getDerived().RebuildExtVectorType(ElementType,
4106 T->getNumElements(),
4107 /*FIXME*/ SourceLocation());
4108 if (Result.isNull())
4112 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4113 NewTL.setNameLoc(TL.getNameLoc());
4118 template <typename Derived>
4119 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4120 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4121 bool ExpectParameterPack) {
4122 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4123 TypeSourceInfo *NewDI = 0;
4125 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4126 // If we're substituting into a pack expansion type and we know the
4127 // length we want to expand to, just substitute for the pattern.
4128 TypeLoc OldTL = OldDI->getTypeLoc();
4129 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4132 TypeLoc NewTL = OldDI->getTypeLoc();
4133 TLB.reserve(NewTL.getFullDataSize());
4135 QualType Result = getDerived().TransformType(TLB,
4136 OldExpansionTL.getPatternLoc());
4137 if (Result.isNull())
4140 Result = RebuildPackExpansionType(Result,
4141 OldExpansionTL.getPatternLoc().getSourceRange(),
4142 OldExpansionTL.getEllipsisLoc(),
4144 if (Result.isNull())
4147 PackExpansionTypeLoc NewExpansionTL
4148 = TLB.push<PackExpansionTypeLoc>(Result);
4149 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4150 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4152 NewDI = getDerived().TransformType(OldDI);
4156 if (NewDI == OldDI && indexAdjustment == 0)
4159 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4160 OldParm->getDeclContext(),
4161 OldParm->getInnerLocStart(),
4162 OldParm->getLocation(),
4163 OldParm->getIdentifier(),
4166 OldParm->getStorageClass(),
4168 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4169 OldParm->getFunctionScopeIndex() + indexAdjustment);
4173 template<typename Derived>
4174 bool TreeTransform<Derived>::
4175 TransformFunctionTypeParams(SourceLocation Loc,
4176 ParmVarDecl **Params, unsigned NumParams,
4177 const QualType *ParamTypes,
4178 SmallVectorImpl<QualType> &OutParamTypes,
4179 SmallVectorImpl<ParmVarDecl*> *PVars) {
4180 int indexAdjustment = 0;
4182 for (unsigned i = 0; i != NumParams; ++i) {
4183 if (ParmVarDecl *OldParm = Params[i]) {
4184 assert(OldParm->getFunctionScopeIndex() == i);
4186 Optional<unsigned> NumExpansions;
4187 ParmVarDecl *NewParm = 0;
4188 if (OldParm->isParameterPack()) {
4189 // We have a function parameter pack that may need to be expanded.
4190 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4192 // Find the parameter packs that could be expanded.
4193 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4194 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4195 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4196 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4197 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4199 // Determine whether we should expand the parameter packs.
4200 bool ShouldExpand = false;
4201 bool RetainExpansion = false;
4202 Optional<unsigned> OrigNumExpansions =
4203 ExpansionTL.getTypePtr()->getNumExpansions();
4204 NumExpansions = OrigNumExpansions;
4205 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4206 Pattern.getSourceRange(),
4215 // Expand the function parameter pack into multiple, separate
4217 getDerived().ExpandingFunctionParameterPack(OldParm);
4218 for (unsigned I = 0; I != *NumExpansions; ++I) {
4219 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4220 ParmVarDecl *NewParm
4221 = getDerived().TransformFunctionTypeParam(OldParm,
4224 /*ExpectParameterPack=*/false);
4228 OutParamTypes.push_back(NewParm->getType());
4230 PVars->push_back(NewParm);
4233 // If we're supposed to retain a pack expansion, do so by temporarily
4234 // forgetting the partially-substituted parameter pack.
4235 if (RetainExpansion) {
4236 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4237 ParmVarDecl *NewParm
4238 = getDerived().TransformFunctionTypeParam(OldParm,
4241 /*ExpectParameterPack=*/false);
4245 OutParamTypes.push_back(NewParm->getType());
4247 PVars->push_back(NewParm);
4250 // The next parameter should have the same adjustment as the
4251 // last thing we pushed, but we post-incremented indexAdjustment
4252 // on every push. Also, if we push nothing, the adjustment should
4256 // We're done with the pack expansion.
4260 // We'll substitute the parameter now without expanding the pack
4262 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4263 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4266 /*ExpectParameterPack=*/true);
4268 NewParm = getDerived().TransformFunctionTypeParam(
4269 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4275 OutParamTypes.push_back(NewParm->getType());
4277 PVars->push_back(NewParm);
4281 // Deal with the possibility that we don't have a parameter
4282 // declaration for this parameter.
4283 QualType OldType = ParamTypes[i];
4284 bool IsPackExpansion = false;
4285 Optional<unsigned> NumExpansions;
4287 if (const PackExpansionType *Expansion
4288 = dyn_cast<PackExpansionType>(OldType)) {
4289 // We have a function parameter pack that may need to be expanded.
4290 QualType Pattern = Expansion->getPattern();
4291 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4292 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4294 // Determine whether we should expand the parameter packs.
4295 bool ShouldExpand = false;
4296 bool RetainExpansion = false;
4297 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4306 // Expand the function parameter pack into multiple, separate
4308 for (unsigned I = 0; I != *NumExpansions; ++I) {
4309 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4310 QualType NewType = getDerived().TransformType(Pattern);
4311 if (NewType.isNull())
4314 OutParamTypes.push_back(NewType);
4316 PVars->push_back(0);
4319 // We're done with the pack expansion.
4323 // If we're supposed to retain a pack expansion, do so by temporarily
4324 // forgetting the partially-substituted parameter pack.
4325 if (RetainExpansion) {
4326 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4327 QualType NewType = getDerived().TransformType(Pattern);
4328 if (NewType.isNull())
4331 OutParamTypes.push_back(NewType);
4333 PVars->push_back(0);
4336 // We'll substitute the parameter now without expanding the pack
4338 OldType = Expansion->getPattern();
4339 IsPackExpansion = true;
4340 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4341 NewType = getDerived().TransformType(OldType);
4343 NewType = getDerived().TransformType(OldType);
4346 if (NewType.isNull())
4349 if (IsPackExpansion)
4350 NewType = getSema().Context.getPackExpansionType(NewType,
4353 OutParamTypes.push_back(NewType);
4355 PVars->push_back(0);
4360 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4361 if (ParmVarDecl *parm = (*PVars)[i])
4362 assert(parm->getFunctionScopeIndex() == i);
4369 template<typename Derived>
4371 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4372 FunctionProtoTypeLoc TL) {
4373 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4376 template<typename Derived>
4378 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4379 FunctionProtoTypeLoc TL,
4380 CXXRecordDecl *ThisContext,
4381 unsigned ThisTypeQuals) {
4382 // Transform the parameters and return type.
4384 // We are required to instantiate the params and return type in source order.
4385 // When the function has a trailing return type, we instantiate the
4386 // parameters before the return type, since the return type can then refer
4387 // to the parameters themselves (via decltype, sizeof, etc.).
4389 SmallVector<QualType, 4> ParamTypes;
4390 SmallVector<ParmVarDecl*, 4> ParamDecls;
4391 const FunctionProtoType *T = TL.getTypePtr();
4393 QualType ResultType;
4395 if (T->hasTrailingReturn()) {
4396 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4399 TL.getTypePtr()->arg_type_begin(),
4400 ParamTypes, &ParamDecls))
4404 // C++11 [expr.prim.general]p3:
4405 // If a declaration declares a member function or member function
4406 // template of a class X, the expression this is a prvalue of type
4407 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4408 // and the end of the function-definition, member-declarator, or
4410 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4412 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4413 if (ResultType.isNull())
4418 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4419 if (ResultType.isNull())
4422 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4425 TL.getTypePtr()->arg_type_begin(),
4426 ParamTypes, &ParamDecls))
4430 // FIXME: Need to transform the exception-specification too.
4432 QualType Result = TL.getType();
4433 if (getDerived().AlwaysRebuild() ||
4434 ResultType != T->getResultType() ||
4435 T->getNumArgs() != ParamTypes.size() ||
4436 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4437 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4438 T->getExtProtoInfo());
4439 if (Result.isNull())
4443 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4444 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4445 NewTL.setLParenLoc(TL.getLParenLoc());
4446 NewTL.setRParenLoc(TL.getRParenLoc());
4447 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4448 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4449 NewTL.setArg(i, ParamDecls[i]);
4454 template<typename Derived>
4455 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4456 TypeLocBuilder &TLB,
4457 FunctionNoProtoTypeLoc TL) {
4458 const FunctionNoProtoType *T = TL.getTypePtr();
4459 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4460 if (ResultType.isNull())
4463 QualType Result = TL.getType();
4464 if (getDerived().AlwaysRebuild() ||
4465 ResultType != T->getResultType())
4466 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4468 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4469 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4470 NewTL.setLParenLoc(TL.getLParenLoc());
4471 NewTL.setRParenLoc(TL.getRParenLoc());
4472 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4477 template<typename Derived> QualType
4478 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
4479 UnresolvedUsingTypeLoc TL) {
4480 const UnresolvedUsingType *T = TL.getTypePtr();
4481 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4485 QualType Result = TL.getType();
4486 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4487 Result = getDerived().RebuildUnresolvedUsingType(D);
4488 if (Result.isNull())
4492 // We might get an arbitrary type spec type back. We should at
4493 // least always get a type spec type, though.
4494 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4495 NewTL.setNameLoc(TL.getNameLoc());
4500 template<typename Derived>
4501 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
4502 TypedefTypeLoc TL) {
4503 const TypedefType *T = TL.getTypePtr();
4504 TypedefNameDecl *Typedef
4505 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4510 QualType Result = TL.getType();
4511 if (getDerived().AlwaysRebuild() ||
4512 Typedef != T->getDecl()) {
4513 Result = getDerived().RebuildTypedefType(Typedef);
4514 if (Result.isNull())
4518 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4519 NewTL.setNameLoc(TL.getNameLoc());
4524 template<typename Derived>
4525 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
4526 TypeOfExprTypeLoc TL) {
4527 // typeof expressions are not potentially evaluated contexts
4528 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4529 Sema::ReuseLambdaContextDecl);
4531 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4535 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4539 QualType Result = TL.getType();
4540 if (getDerived().AlwaysRebuild() ||
4541 E.get() != TL.getUnderlyingExpr()) {
4542 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4543 if (Result.isNull())
4548 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4549 NewTL.setTypeofLoc(TL.getTypeofLoc());
4550 NewTL.setLParenLoc(TL.getLParenLoc());
4551 NewTL.setRParenLoc(TL.getRParenLoc());
4556 template<typename Derived>
4557 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
4559 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4560 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4564 QualType Result = TL.getType();
4565 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4566 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4567 if (Result.isNull())
4571 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4572 NewTL.setTypeofLoc(TL.getTypeofLoc());
4573 NewTL.setLParenLoc(TL.getLParenLoc());
4574 NewTL.setRParenLoc(TL.getRParenLoc());
4575 NewTL.setUnderlyingTInfo(New_Under_TI);
4580 template<typename Derived>
4581 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
4582 DecltypeTypeLoc TL) {
4583 const DecltypeType *T = TL.getTypePtr();
4585 // decltype expressions are not potentially evaluated contexts
4586 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4587 /*IsDecltype=*/ true);
4589 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4593 E = getSema().ActOnDecltypeExpression(E.take());
4597 QualType Result = TL.getType();
4598 if (getDerived().AlwaysRebuild() ||
4599 E.get() != T->getUnderlyingExpr()) {
4600 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4601 if (Result.isNull())
4606 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4607 NewTL.setNameLoc(TL.getNameLoc());
4612 template<typename Derived>
4613 QualType TreeTransform<Derived>::TransformUnaryTransformType(
4614 TypeLocBuilder &TLB,
4615 UnaryTransformTypeLoc TL) {
4616 QualType Result = TL.getType();
4617 if (Result->isDependentType()) {
4618 const UnaryTransformType *T = TL.getTypePtr();
4620 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4621 Result = getDerived().RebuildUnaryTransformType(NewBase,
4624 if (Result.isNull())
4628 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4629 NewTL.setKWLoc(TL.getKWLoc());
4630 NewTL.setParensRange(TL.getParensRange());
4631 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4635 template<typename Derived>
4636 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4638 const AutoType *T = TL.getTypePtr();
4639 QualType OldDeduced = T->getDeducedType();
4640 QualType NewDeduced;
4641 if (!OldDeduced.isNull()) {
4642 NewDeduced = getDerived().TransformType(OldDeduced);
4643 if (NewDeduced.isNull())
4647 QualType Result = TL.getType();
4648 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4649 T->isDependentType()) {
4650 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
4651 if (Result.isNull())
4655 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4656 NewTL.setNameLoc(TL.getNameLoc());
4661 template<typename Derived>
4662 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
4664 const RecordType *T = TL.getTypePtr();
4666 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4671 QualType Result = TL.getType();
4672 if (getDerived().AlwaysRebuild() ||
4673 Record != T->getDecl()) {
4674 Result = getDerived().RebuildRecordType(Record);
4675 if (Result.isNull())
4679 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4680 NewTL.setNameLoc(TL.getNameLoc());
4685 template<typename Derived>
4686 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
4688 const EnumType *T = TL.getTypePtr();
4690 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4695 QualType Result = TL.getType();
4696 if (getDerived().AlwaysRebuild() ||
4697 Enum != T->getDecl()) {
4698 Result = getDerived().RebuildEnumType(Enum);
4699 if (Result.isNull())
4703 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4704 NewTL.setNameLoc(TL.getNameLoc());
4709 template<typename Derived>
4710 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4711 TypeLocBuilder &TLB,
4712 InjectedClassNameTypeLoc TL) {
4713 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4714 TL.getTypePtr()->getDecl());
4715 if (!D) return QualType();
4717 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4718 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4722 template<typename Derived>
4723 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4724 TypeLocBuilder &TLB,
4725 TemplateTypeParmTypeLoc TL) {
4726 return TransformTypeSpecType(TLB, TL);
4729 template<typename Derived>
4730 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4731 TypeLocBuilder &TLB,
4732 SubstTemplateTypeParmTypeLoc TL) {
4733 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4735 // Substitute into the replacement type, which itself might involve something
4736 // that needs to be transformed. This only tends to occur with default
4737 // template arguments of template template parameters.
4738 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4739 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4740 if (Replacement.isNull())
4743 // Always canonicalize the replacement type.
4744 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4746 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4749 // Propagate type-source information.
4750 SubstTemplateTypeParmTypeLoc NewTL
4751 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4752 NewTL.setNameLoc(TL.getNameLoc());
4757 template<typename Derived>
4758 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4759 TypeLocBuilder &TLB,
4760 SubstTemplateTypeParmPackTypeLoc TL) {
4761 return TransformTypeSpecType(TLB, TL);
4764 template<typename Derived>
4765 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4766 TypeLocBuilder &TLB,
4767 TemplateSpecializationTypeLoc TL) {
4768 const TemplateSpecializationType *T = TL.getTypePtr();
4770 // The nested-name-specifier never matters in a TemplateSpecializationType,
4771 // because we can't have a dependent nested-name-specifier anyway.
4773 TemplateName Template
4774 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4775 TL.getTemplateNameLoc());
4776 if (Template.isNull())
4779 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4782 template<typename Derived>
4783 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4785 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4786 if (ValueType.isNull())
4789 QualType Result = TL.getType();
4790 if (getDerived().AlwaysRebuild() ||
4791 ValueType != TL.getValueLoc().getType()) {
4792 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4793 if (Result.isNull())
4797 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4798 NewTL.setKWLoc(TL.getKWLoc());
4799 NewTL.setLParenLoc(TL.getLParenLoc());
4800 NewTL.setRParenLoc(TL.getRParenLoc());
4805 /// \brief Simple iterator that traverses the template arguments in a
4806 /// container that provides a \c getArgLoc() member function.
4808 /// This iterator is intended to be used with the iterator form of
4809 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4810 template<typename ArgLocContainer>
4811 class TemplateArgumentLocContainerIterator {
4812 ArgLocContainer *Container;
4816 typedef TemplateArgumentLoc value_type;
4817 typedef TemplateArgumentLoc reference;
4818 typedef int difference_type;
4819 typedef std::input_iterator_tag iterator_category;
4822 TemplateArgumentLoc Arg;
4825 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4827 const TemplateArgumentLoc *operator->() const {
4833 TemplateArgumentLocContainerIterator() {}
4835 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4837 : Container(&Container), Index(Index) { }
4839 TemplateArgumentLocContainerIterator &operator++() {
4844 TemplateArgumentLocContainerIterator operator++(int) {
4845 TemplateArgumentLocContainerIterator Old(*this);
4850 TemplateArgumentLoc operator*() const {
4851 return Container->getArgLoc(Index);
4854 pointer operator->() const {
4855 return pointer(Container->getArgLoc(Index));
4858 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4859 const TemplateArgumentLocContainerIterator &Y) {
4860 return X.Container == Y.Container && X.Index == Y.Index;
4863 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4864 const TemplateArgumentLocContainerIterator &Y) {
4870 template <typename Derived>
4871 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4872 TypeLocBuilder &TLB,
4873 TemplateSpecializationTypeLoc TL,
4874 TemplateName Template) {
4875 TemplateArgumentListInfo NewTemplateArgs;
4876 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4877 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4878 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4880 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4881 ArgIterator(TL, TL.getNumArgs()),
4885 // FIXME: maybe don't rebuild if all the template arguments are the same.
4888 getDerived().RebuildTemplateSpecializationType(Template,
4889 TL.getTemplateNameLoc(),
4892 if (!Result.isNull()) {
4893 // Specializations of template template parameters are represented as
4894 // TemplateSpecializationTypes, and substitution of type alias templates
4895 // within a dependent context can transform them into
4896 // DependentTemplateSpecializationTypes.
4897 if (isa<DependentTemplateSpecializationType>(Result)) {
4898 DependentTemplateSpecializationTypeLoc NewTL
4899 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4900 NewTL.setElaboratedKeywordLoc(SourceLocation());
4901 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4902 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4903 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4904 NewTL.setLAngleLoc(TL.getLAngleLoc());
4905 NewTL.setRAngleLoc(TL.getRAngleLoc());
4906 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4907 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4911 TemplateSpecializationTypeLoc NewTL
4912 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4913 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4914 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4915 NewTL.setLAngleLoc(TL.getLAngleLoc());
4916 NewTL.setRAngleLoc(TL.getRAngleLoc());
4917 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4918 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4924 template <typename Derived>
4925 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4926 TypeLocBuilder &TLB,
4927 DependentTemplateSpecializationTypeLoc TL,
4928 TemplateName Template,
4930 TemplateArgumentListInfo NewTemplateArgs;
4931 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4932 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4933 typedef TemplateArgumentLocContainerIterator<
4934 DependentTemplateSpecializationTypeLoc> ArgIterator;
4935 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4936 ArgIterator(TL, TL.getNumArgs()),
4940 // FIXME: maybe don't rebuild if all the template arguments are the same.
4942 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4944 = getSema().Context.getDependentTemplateSpecializationType(
4945 TL.getTypePtr()->getKeyword(),
4946 DTN->getQualifier(),
4947 DTN->getIdentifier(),
4950 DependentTemplateSpecializationTypeLoc NewTL
4951 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4952 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
4953 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
4954 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4955 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4956 NewTL.setLAngleLoc(TL.getLAngleLoc());
4957 NewTL.setRAngleLoc(TL.getRAngleLoc());
4958 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4959 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4964 = getDerived().RebuildTemplateSpecializationType(Template,
4965 TL.getTemplateNameLoc(),
4968 if (!Result.isNull()) {
4969 /// FIXME: Wrap this in an elaborated-type-specifier?
4970 TemplateSpecializationTypeLoc NewTL
4971 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4972 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4973 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4974 NewTL.setLAngleLoc(TL.getLAngleLoc());
4975 NewTL.setRAngleLoc(TL.getRAngleLoc());
4976 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4977 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4983 template<typename Derived>
4985 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
4986 ElaboratedTypeLoc TL) {
4987 const ElaboratedType *T = TL.getTypePtr();
4989 NestedNameSpecifierLoc QualifierLoc;
4990 // NOTE: the qualifier in an ElaboratedType is optional.
4991 if (TL.getQualifierLoc()) {
4993 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4998 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4999 if (NamedT.isNull())
5002 // C++0x [dcl.type.elab]p2:
5003 // If the identifier resolves to a typedef-name or the simple-template-id
5004 // resolves to an alias template specialization, the
5005 // elaborated-type-specifier is ill-formed.
5006 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5007 if (const TemplateSpecializationType *TST =
5008 NamedT->getAs<TemplateSpecializationType>()) {
5009 TemplateName Template = TST->getTemplateName();
5010 if (TypeAliasTemplateDecl *TAT =
5011 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5012 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5013 diag::err_tag_reference_non_tag) << 4;
5014 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5019 QualType Result = TL.getType();
5020 if (getDerived().AlwaysRebuild() ||
5021 QualifierLoc != TL.getQualifierLoc() ||
5022 NamedT != T->getNamedType()) {
5023 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5025 QualifierLoc, NamedT);
5026 if (Result.isNull())
5030 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5031 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5032 NewTL.setQualifierLoc(QualifierLoc);
5036 template<typename Derived>
5037 QualType TreeTransform<Derived>::TransformAttributedType(
5038 TypeLocBuilder &TLB,
5039 AttributedTypeLoc TL) {
5040 const AttributedType *oldType = TL.getTypePtr();
5041 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5042 if (modifiedType.isNull())
5045 QualType result = TL.getType();
5047 // FIXME: dependent operand expressions?
5048 if (getDerived().AlwaysRebuild() ||
5049 modifiedType != oldType->getModifiedType()) {
5050 // TODO: this is really lame; we should really be rebuilding the
5051 // equivalent type from first principles.
5052 QualType equivalentType
5053 = getDerived().TransformType(oldType->getEquivalentType());
5054 if (equivalentType.isNull())
5056 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5061 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5062 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5063 if (TL.hasAttrOperand())
5064 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5065 if (TL.hasAttrExprOperand())
5066 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5067 else if (TL.hasAttrEnumOperand())
5068 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5073 template<typename Derived>
5075 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5077 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5081 QualType Result = TL.getType();
5082 if (getDerived().AlwaysRebuild() ||
5083 Inner != TL.getInnerLoc().getType()) {
5084 Result = getDerived().RebuildParenType(Inner);
5085 if (Result.isNull())
5089 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5090 NewTL.setLParenLoc(TL.getLParenLoc());
5091 NewTL.setRParenLoc(TL.getRParenLoc());
5095 template<typename Derived>
5096 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5097 DependentNameTypeLoc TL) {
5098 const DependentNameType *T = TL.getTypePtr();
5100 NestedNameSpecifierLoc QualifierLoc
5101 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5106 = getDerived().RebuildDependentNameType(T->getKeyword(),
5107 TL.getElaboratedKeywordLoc(),
5111 if (Result.isNull())
5114 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5115 QualType NamedT = ElabT->getNamedType();
5116 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5118 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5119 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5120 NewTL.setQualifierLoc(QualifierLoc);
5122 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5123 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5124 NewTL.setQualifierLoc(QualifierLoc);
5125 NewTL.setNameLoc(TL.getNameLoc());
5130 template<typename Derived>
5131 QualType TreeTransform<Derived>::
5132 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5133 DependentTemplateSpecializationTypeLoc TL) {
5134 NestedNameSpecifierLoc QualifierLoc;
5135 if (TL.getQualifierLoc()) {
5137 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5143 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5146 template<typename Derived>
5147 QualType TreeTransform<Derived>::
5148 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5149 DependentTemplateSpecializationTypeLoc TL,
5150 NestedNameSpecifierLoc QualifierLoc) {
5151 const DependentTemplateSpecializationType *T = TL.getTypePtr();
5153 TemplateArgumentListInfo NewTemplateArgs;
5154 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5155 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5157 typedef TemplateArgumentLocContainerIterator<
5158 DependentTemplateSpecializationTypeLoc> ArgIterator;
5159 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5160 ArgIterator(TL, TL.getNumArgs()),
5165 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5168 TL.getTemplateNameLoc(),
5170 if (Result.isNull())
5173 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5174 QualType NamedT = ElabT->getNamedType();
5176 // Copy information relevant to the template specialization.
5177 TemplateSpecializationTypeLoc NamedTL
5178 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5179 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5180 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5181 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5182 NamedTL.setRAngleLoc(TL.getRAngleLoc());
5183 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5184 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5186 // Copy information relevant to the elaborated type.
5187 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5188 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5189 NewTL.setQualifierLoc(QualifierLoc);
5190 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5191 DependentTemplateSpecializationTypeLoc SpecTL
5192 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5193 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5194 SpecTL.setQualifierLoc(QualifierLoc);
5195 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5196 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5197 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5198 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5199 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5200 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5202 TemplateSpecializationTypeLoc SpecTL
5203 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5204 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5205 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5206 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5207 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5208 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5209 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5214 template<typename Derived>
5215 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5216 PackExpansionTypeLoc TL) {
5218 = getDerived().TransformType(TLB, TL.getPatternLoc());
5219 if (Pattern.isNull())
5222 QualType Result = TL.getType();
5223 if (getDerived().AlwaysRebuild() ||
5224 Pattern != TL.getPatternLoc().getType()) {
5225 Result = getDerived().RebuildPackExpansionType(Pattern,
5226 TL.getPatternLoc().getSourceRange(),
5227 TL.getEllipsisLoc(),
5228 TL.getTypePtr()->getNumExpansions());
5229 if (Result.isNull())
5233 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5234 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5238 template<typename Derived>
5240 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5241 ObjCInterfaceTypeLoc TL) {
5242 // ObjCInterfaceType is never dependent.
5243 TLB.pushFullCopy(TL);
5244 return TL.getType();
5247 template<typename Derived>
5249 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5250 ObjCObjectTypeLoc TL) {
5251 // ObjCObjectType is never dependent.
5252 TLB.pushFullCopy(TL);
5253 return TL.getType();
5256 template<typename Derived>
5258 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
5259 ObjCObjectPointerTypeLoc TL) {
5260 // ObjCObjectPointerType is never dependent.
5261 TLB.pushFullCopy(TL);
5262 return TL.getType();
5265 //===----------------------------------------------------------------------===//
5266 // Statement transformation
5267 //===----------------------------------------------------------------------===//
5268 template<typename Derived>
5270 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
5271 return SemaRef.Owned(S);
5274 template<typename Derived>
5276 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5277 return getDerived().TransformCompoundStmt(S, false);
5280 template<typename Derived>
5282 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
5284 Sema::CompoundScopeRAII CompoundScope(getSema());
5286 bool SubStmtInvalid = false;
5287 bool SubStmtChanged = false;
5288 SmallVector<Stmt*, 8> Statements;
5289 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5291 StmtResult Result = getDerived().TransformStmt(*B);
5292 if (Result.isInvalid()) {
5293 // Immediately fail if this was a DeclStmt, since it's very
5294 // likely that this will cause problems for future statements.
5295 if (isa<DeclStmt>(*B))
5298 // Otherwise, just keep processing substatements and fail later.
5299 SubStmtInvalid = true;
5303 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5304 Statements.push_back(Result.takeAs<Stmt>());
5310 if (!getDerived().AlwaysRebuild() &&
5312 return SemaRef.Owned(S);
5314 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5320 template<typename Derived>
5322 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
5323 ExprResult LHS, RHS;
5325 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5326 Sema::ConstantEvaluated);
5328 // Transform the left-hand case value.
5329 LHS = getDerived().TransformExpr(S->getLHS());
5330 LHS = SemaRef.ActOnConstantExpression(LHS);
5331 if (LHS.isInvalid())
5334 // Transform the right-hand case value (for the GNU case-range extension).
5335 RHS = getDerived().TransformExpr(S->getRHS());
5336 RHS = SemaRef.ActOnConstantExpression(RHS);
5337 if (RHS.isInvalid())
5341 // Build the case statement.
5342 // Case statements are always rebuilt so that they will attached to their
5343 // transformed switch statement.
5344 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
5346 S->getEllipsisLoc(),
5349 if (Case.isInvalid())
5352 // Transform the statement following the case
5353 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5354 if (SubStmt.isInvalid())
5357 // Attach the body to the case statement
5358 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
5361 template<typename Derived>
5363 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
5364 // Transform the statement following the default case
5365 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5366 if (SubStmt.isInvalid())
5369 // Default statements are always rebuilt
5370 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
5374 template<typename Derived>
5376 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
5377 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5378 if (SubStmt.isInvalid())
5381 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5387 // FIXME: Pass the real colon location in.
5388 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
5389 cast<LabelDecl>(LD), SourceLocation(),
5393 template<typename Derived>
5395 TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5396 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5397 if (SubStmt.isInvalid())
5400 // TODO: transform attributes
5401 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5404 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5409 template<typename Derived>
5411 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
5412 // Transform the condition
5414 VarDecl *ConditionVar = 0;
5415 if (S->getConditionVariable()) {
5417 = cast_or_null<VarDecl>(
5418 getDerived().TransformDefinition(
5419 S->getConditionVariable()->getLocation(),
5420 S->getConditionVariable()));
5424 Cond = getDerived().TransformExpr(S->getCond());
5426 if (Cond.isInvalid())
5429 // Convert the condition to a boolean value.
5431 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5433 if (CondE.isInvalid())
5440 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5441 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5444 // Transform the "then" branch.
5445 StmtResult Then = getDerived().TransformStmt(S->getThen());
5446 if (Then.isInvalid())
5449 // Transform the "else" branch.
5450 StmtResult Else = getDerived().TransformStmt(S->getElse());
5451 if (Else.isInvalid())
5454 if (!getDerived().AlwaysRebuild() &&
5455 FullCond.get() == S->getCond() &&
5456 ConditionVar == S->getConditionVariable() &&
5457 Then.get() == S->getThen() &&
5458 Else.get() == S->getElse())
5459 return SemaRef.Owned(S);
5461 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
5463 S->getElseLoc(), Else.get());
5466 template<typename Derived>
5468 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
5469 // Transform the condition.
5471 VarDecl *ConditionVar = 0;
5472 if (S->getConditionVariable()) {
5474 = cast_or_null<VarDecl>(
5475 getDerived().TransformDefinition(
5476 S->getConditionVariable()->getLocation(),
5477 S->getConditionVariable()));
5481 Cond = getDerived().TransformExpr(S->getCond());
5483 if (Cond.isInvalid())
5487 // Rebuild the switch statement.
5489 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5491 if (Switch.isInvalid())
5494 // Transform the body of the switch statement.
5495 StmtResult Body = getDerived().TransformStmt(S->getBody());
5496 if (Body.isInvalid())
5499 // Complete the switch statement.
5500 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5504 template<typename Derived>
5506 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
5507 // Transform the condition
5509 VarDecl *ConditionVar = 0;
5510 if (S->getConditionVariable()) {
5512 = cast_or_null<VarDecl>(
5513 getDerived().TransformDefinition(
5514 S->getConditionVariable()->getLocation(),
5515 S->getConditionVariable()));
5519 Cond = getDerived().TransformExpr(S->getCond());
5521 if (Cond.isInvalid())
5525 // Convert the condition to a boolean value.
5526 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5528 if (CondE.isInvalid())
5534 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5535 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5538 // Transform the body
5539 StmtResult Body = getDerived().TransformStmt(S->getBody());
5540 if (Body.isInvalid())
5543 if (!getDerived().AlwaysRebuild() &&
5544 FullCond.get() == S->getCond() &&
5545 ConditionVar == S->getConditionVariable() &&
5546 Body.get() == S->getBody())
5549 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
5550 ConditionVar, Body.get());
5553 template<typename Derived>
5555 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
5556 // Transform the body
5557 StmtResult Body = getDerived().TransformStmt(S->getBody());
5558 if (Body.isInvalid())
5561 // Transform the condition
5562 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5563 if (Cond.isInvalid())
5566 if (!getDerived().AlwaysRebuild() &&
5567 Cond.get() == S->getCond() &&
5568 Body.get() == S->getBody())
5569 return SemaRef.Owned(S);
5571 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5572 /*FIXME:*/S->getWhileLoc(), Cond.get(),
5576 template<typename Derived>
5578 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
5579 // Transform the initialization statement
5580 StmtResult Init = getDerived().TransformStmt(S->getInit());
5581 if (Init.isInvalid())
5584 // Transform the condition
5586 VarDecl *ConditionVar = 0;
5587 if (S->getConditionVariable()) {
5589 = cast_or_null<VarDecl>(
5590 getDerived().TransformDefinition(
5591 S->getConditionVariable()->getLocation(),
5592 S->getConditionVariable()));
5596 Cond = getDerived().TransformExpr(S->getCond());
5598 if (Cond.isInvalid())
5602 // Convert the condition to a boolean value.
5603 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5605 if (CondE.isInvalid())
5612 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5613 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5616 // Transform the increment
5617 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5618 if (Inc.isInvalid())
5621 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
5622 if (S->getInc() && !FullInc.get())
5625 // Transform the body
5626 StmtResult Body = getDerived().TransformStmt(S->getBody());
5627 if (Body.isInvalid())
5630 if (!getDerived().AlwaysRebuild() &&
5631 Init.get() == S->getInit() &&
5632 FullCond.get() == S->getCond() &&
5633 Inc.get() == S->getInc() &&
5634 Body.get() == S->getBody())
5635 return SemaRef.Owned(S);
5637 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
5638 Init.get(), FullCond, ConditionVar,
5639 FullInc, S->getRParenLoc(), Body.get());
5642 template<typename Derived>
5644 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
5645 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5650 // Goto statements must always be rebuilt, to resolve the label.
5651 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
5652 cast<LabelDecl>(LD));
5655 template<typename Derived>
5657 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
5658 ExprResult Target = getDerived().TransformExpr(S->getTarget());
5659 if (Target.isInvalid())
5661 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
5663 if (!getDerived().AlwaysRebuild() &&
5664 Target.get() == S->getTarget())
5665 return SemaRef.Owned(S);
5667 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
5671 template<typename Derived>
5673 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
5674 return SemaRef.Owned(S);
5677 template<typename Derived>
5679 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
5680 return SemaRef.Owned(S);
5683 template<typename Derived>
5685 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
5686 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
5687 if (Result.isInvalid())
5690 // FIXME: We always rebuild the return statement because there is no way
5691 // to tell whether the return type of the function has changed.
5692 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
5695 template<typename Derived>
5697 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
5698 bool DeclChanged = false;
5699 SmallVector<Decl *, 4> Decls;
5700 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5702 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5707 if (Transformed != *D)
5710 Decls.push_back(Transformed);
5713 if (!getDerived().AlwaysRebuild() && !DeclChanged)
5714 return SemaRef.Owned(S);
5716 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
5719 template<typename Derived>
5721 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
5723 SmallVector<Expr*, 8> Constraints;
5724 SmallVector<Expr*, 8> Exprs;
5725 SmallVector<IdentifierInfo *, 4> Names;
5727 ExprResult AsmString;
5728 SmallVector<Expr*, 8> Clobbers;
5730 bool ExprsChanged = false;
5732 // Go through the outputs.
5733 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5734 Names.push_back(S->getOutputIdentifier(I));
5736 // No need to transform the constraint literal.
5737 Constraints.push_back(S->getOutputConstraintLiteral(I));
5739 // Transform the output expr.
5740 Expr *OutputExpr = S->getOutputExpr(I);
5741 ExprResult Result = getDerived().TransformExpr(OutputExpr);
5742 if (Result.isInvalid())
5745 ExprsChanged |= Result.get() != OutputExpr;
5747 Exprs.push_back(Result.get());
5750 // Go through the inputs.
5751 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5752 Names.push_back(S->getInputIdentifier(I));
5754 // No need to transform the constraint literal.
5755 Constraints.push_back(S->getInputConstraintLiteral(I));
5757 // Transform the input expr.
5758 Expr *InputExpr = S->getInputExpr(I);
5759 ExprResult Result = getDerived().TransformExpr(InputExpr);
5760 if (Result.isInvalid())
5763 ExprsChanged |= Result.get() != InputExpr;
5765 Exprs.push_back(Result.get());
5768 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
5769 return SemaRef.Owned(S);
5771 // Go through the clobbers.
5772 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
5773 Clobbers.push_back(S->getClobberStringLiteral(I));
5775 // No need to transform the asm string literal.
5776 AsmString = SemaRef.Owned(S->getAsmString());
5777 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5778 S->isVolatile(), S->getNumOutputs(),
5779 S->getNumInputs(), Names.data(),
5780 Constraints, Exprs, AsmString.get(),
5781 Clobbers, S->getRParenLoc());
5784 template<typename Derived>
5786 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
5787 ArrayRef<Token> AsmToks =
5788 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
5790 bool HadError = false, HadChange = false;
5792 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5793 SmallVector<Expr*, 8> TransformedExprs;
5794 TransformedExprs.reserve(SrcExprs.size());
5795 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5796 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5797 if (!Result.isUsable()) {
5800 HadChange |= (Result.get() != SrcExprs[i]);
5801 TransformedExprs.push_back(Result.take());
5805 if (HadError) return StmtError();
5806 if (!HadChange && !getDerived().AlwaysRebuild())
5809 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5810 AsmToks, S->getAsmString(),
5811 S->getNumOutputs(), S->getNumInputs(),
5812 S->getAllConstraints(), S->getClobbers(),
5813 TransformedExprs, S->getEndLoc());
5816 template<typename Derived>
5818 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
5819 // Transform the body of the @try.
5820 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
5821 if (TryBody.isInvalid())
5824 // Transform the @catch statements (if present).
5825 bool AnyCatchChanged = false;
5826 SmallVector<Stmt*, 8> CatchStmts;
5827 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
5828 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
5829 if (Catch.isInvalid())
5831 if (Catch.get() != S->getCatchStmt(I))
5832 AnyCatchChanged = true;
5833 CatchStmts.push_back(Catch.release());
5836 // Transform the @finally statement (if present).
5838 if (S->getFinallyStmt()) {
5839 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5840 if (Finally.isInvalid())
5844 // If nothing changed, just retain this statement.
5845 if (!getDerived().AlwaysRebuild() &&
5846 TryBody.get() == S->getTryBody() &&
5848 Finally.get() == S->getFinallyStmt())
5849 return SemaRef.Owned(S);
5851 // Build a new statement.
5852 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5853 CatchStmts, Finally.get());
5856 template<typename Derived>
5858 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5859 // Transform the @catch parameter, if there is one.
5861 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5862 TypeSourceInfo *TSInfo = 0;
5863 if (FromVar->getTypeSourceInfo()) {
5864 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5871 T = TSInfo->getType();
5873 T = getDerived().TransformType(FromVar->getType());
5878 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5883 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5884 if (Body.isInvalid())
5887 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5892 template<typename Derived>
5894 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
5895 // Transform the body.
5896 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
5897 if (Body.isInvalid())
5900 // If nothing changed, just retain this statement.
5901 if (!getDerived().AlwaysRebuild() &&
5902 Body.get() == S->getFinallyBody())
5903 return SemaRef.Owned(S);
5905 // Build a new statement.
5906 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
5910 template<typename Derived>
5912 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
5914 if (S->getThrowExpr()) {
5915 Operand = getDerived().TransformExpr(S->getThrowExpr());
5916 if (Operand.isInvalid())
5920 if (!getDerived().AlwaysRebuild() &&
5921 Operand.get() == S->getThrowExpr())
5922 return getSema().Owned(S);
5924 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
5927 template<typename Derived>
5929 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
5930 ObjCAtSynchronizedStmt *S) {
5931 // Transform the object we are locking.
5932 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
5933 if (Object.isInvalid())
5936 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5938 if (Object.isInvalid())
5941 // Transform the body.
5942 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
5943 if (Body.isInvalid())
5946 // If nothing change, just retain the current statement.
5947 if (!getDerived().AlwaysRebuild() &&
5948 Object.get() == S->getSynchExpr() &&
5949 Body.get() == S->getSynchBody())
5950 return SemaRef.Owned(S);
5952 // Build a new statement.
5953 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
5954 Object.get(), Body.get());
5957 template<typename Derived>
5959 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5960 ObjCAutoreleasePoolStmt *S) {
5961 // Transform the body.
5962 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5963 if (Body.isInvalid())
5966 // If nothing changed, just retain this statement.
5967 if (!getDerived().AlwaysRebuild() &&
5968 Body.get() == S->getSubStmt())
5969 return SemaRef.Owned(S);
5971 // Build a new statement.
5972 return getDerived().RebuildObjCAutoreleasePoolStmt(
5973 S->getAtLoc(), Body.get());
5976 template<typename Derived>
5978 TreeTransform<Derived>::TransformObjCForCollectionStmt(
5979 ObjCForCollectionStmt *S) {
5980 // Transform the element statement.
5981 StmtResult Element = getDerived().TransformStmt(S->getElement());
5982 if (Element.isInvalid())
5985 // Transform the collection expression.
5986 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5987 if (Collection.isInvalid())
5990 // Transform the body.
5991 StmtResult Body = getDerived().TransformStmt(S->getBody());
5992 if (Body.isInvalid())
5995 // If nothing changed, just retain this statement.
5996 if (!getDerived().AlwaysRebuild() &&
5997 Element.get() == S->getElement() &&
5998 Collection.get() == S->getCollection() &&
5999 Body.get() == S->getBody())
6000 return SemaRef.Owned(S);
6002 // Build a new statement.
6003 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6010 template <typename Derived>
6011 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6012 // Transform the exception declaration, if any.
6014 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6016 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6020 Var = getDerived().RebuildExceptionDecl(
6021 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6022 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6023 if (!Var || Var->isInvalidDecl())
6027 // Transform the actual exception handler.
6028 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6029 if (Handler.isInvalid())
6032 if (!getDerived().AlwaysRebuild() && !Var &&
6033 Handler.get() == S->getHandlerBlock())
6034 return SemaRef.Owned(S);
6036 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6039 template <typename Derived>
6040 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6041 // Transform the try block itself.
6042 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6043 if (TryBlock.isInvalid())
6046 // Transform the handlers.
6047 bool HandlerChanged = false;
6048 SmallVector<Stmt *, 8> Handlers;
6049 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6050 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6051 if (Handler.isInvalid())
6054 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6055 Handlers.push_back(Handler.takeAs<Stmt>());
6058 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6060 return SemaRef.Owned(S);
6062 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6066 template<typename Derived>
6068 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6069 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6070 if (Range.isInvalid())
6073 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6074 if (BeginEnd.isInvalid())
6077 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6078 if (Cond.isInvalid())
6081 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6082 if (Cond.isInvalid())
6085 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
6087 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6088 if (Inc.isInvalid())
6091 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
6093 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6094 if (LoopVar.isInvalid())
6097 StmtResult NewStmt = S;
6098 if (getDerived().AlwaysRebuild() ||
6099 Range.get() != S->getRangeStmt() ||
6100 BeginEnd.get() != S->getBeginEndStmt() ||
6101 Cond.get() != S->getCond() ||
6102 Inc.get() != S->getInc() ||
6103 LoopVar.get() != S->getLoopVarStmt()) {
6104 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6105 S->getColonLoc(), Range.get(),
6106 BeginEnd.get(), Cond.get(),
6107 Inc.get(), LoopVar.get(),
6109 if (NewStmt.isInvalid())
6113 StmtResult Body = getDerived().TransformStmt(S->getBody());
6114 if (Body.isInvalid())
6117 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6118 // it now so we have a new statement to attach the body to.
6119 if (Body.get() != S->getBody() && NewStmt.get() == S) {
6120 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6121 S->getColonLoc(), Range.get(),
6122 BeginEnd.get(), Cond.get(),
6123 Inc.get(), LoopVar.get(),
6125 if (NewStmt.isInvalid())
6129 if (NewStmt.get() == S)
6130 return SemaRef.Owned(S);
6132 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6135 template<typename Derived>
6137 TreeTransform<Derived>::TransformMSDependentExistsStmt(
6138 MSDependentExistsStmt *S) {
6139 // Transform the nested-name-specifier, if any.
6140 NestedNameSpecifierLoc QualifierLoc;
6141 if (S->getQualifierLoc()) {
6143 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6148 // Transform the declaration name.
6149 DeclarationNameInfo NameInfo = S->getNameInfo();
6150 if (NameInfo.getName()) {
6151 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6152 if (!NameInfo.getName())
6156 // Check whether anything changed.
6157 if (!getDerived().AlwaysRebuild() &&
6158 QualifierLoc == S->getQualifierLoc() &&
6159 NameInfo.getName() == S->getNameInfo().getName())
6162 // Determine whether this name exists, if we can.
6164 SS.Adopt(QualifierLoc);
6165 bool Dependent = false;
6166 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6167 case Sema::IER_Exists:
6168 if (S->isIfExists())
6171 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6173 case Sema::IER_DoesNotExist:
6174 if (S->isIfNotExists())
6177 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6179 case Sema::IER_Dependent:
6183 case Sema::IER_Error:
6187 // We need to continue with the instantiation, so do so now.
6188 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6189 if (SubStmt.isInvalid())
6192 // If we have resolved the name, just transform to the substatement.
6196 // The name is still dependent, so build a dependent expression again.
6197 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6204 template<typename Derived>
6206 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6207 NestedNameSpecifierLoc QualifierLoc;
6208 if (E->getQualifierLoc()) {
6210 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6215 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6216 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6220 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6221 if (Base.isInvalid())
6224 return new (SemaRef.getASTContext())
6225 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6226 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6227 QualifierLoc, E->getMemberLoc());
6230 template <typename Derived>
6231 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6232 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6233 if (TryBlock.isInvalid())
6236 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6237 if (Handler.isInvalid())
6240 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6241 Handler.get() == S->getHandler())
6242 return SemaRef.Owned(S);
6244 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6245 TryBlock.take(), Handler.take());
6248 template <typename Derived>
6249 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6250 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
6251 if (Block.isInvalid())
6254 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
6257 template <typename Derived>
6258 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6259 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6260 if (FilterExpr.isInvalid())
6263 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
6264 if (Block.isInvalid())
6267 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
6271 template <typename Derived>
6272 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6273 if (isa<SEHFinallyStmt>(Handler))
6274 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6276 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6279 template<typename Derived>
6281 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6282 DeclarationNameInfo DirName;
6283 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6285 // Transform the clauses
6286 llvm::SmallVector<OMPClause *, 16> TClauses;
6287 ArrayRef<OMPClause *> Clauses = D->clauses();
6288 TClauses.reserve(Clauses.size());
6289 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6292 OMPClause *Clause = getDerived().TransformOMPClause(*I);
6294 getSema().EndOpenMPDSABlock(0);
6297 TClauses.push_back(Clause);
6300 TClauses.push_back(0);
6303 if (!D->getAssociatedStmt()) {
6304 getSema().EndOpenMPDSABlock(0);
6307 StmtResult AssociatedStmt =
6308 getDerived().TransformStmt(D->getAssociatedStmt());
6309 if (AssociatedStmt.isInvalid()) {
6310 getSema().EndOpenMPDSABlock(0);
6314 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6315 AssociatedStmt.take(),
6318 getSema().EndOpenMPDSABlock(Res.get());
6322 template<typename Derived>
6324 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6325 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6326 C->getDefaultKindKwLoc(),
6332 template<typename Derived>
6334 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
6335 llvm::SmallVector<Expr *, 16> Vars;
6336 Vars.reserve(C->varlist_size());
6337 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6338 E = C->varlist_end();
6340 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6341 if (EVar.isInvalid())
6343 Vars.push_back(EVar.take());
6345 return getDerived().RebuildOMPPrivateClause(Vars,
6351 template<typename Derived>
6353 TreeTransform<Derived>::TransformOMPFirstprivateClause(
6354 OMPFirstprivateClause *C) {
6355 llvm::SmallVector<Expr *, 16> Vars;
6356 Vars.reserve(C->varlist_size());
6357 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6358 E = C->varlist_end();
6360 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6361 if (EVar.isInvalid())
6363 Vars.push_back(EVar.take());
6365 return getDerived().RebuildOMPFirstprivateClause(Vars,
6371 template<typename Derived>
6373 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6374 llvm::SmallVector<Expr *, 16> Vars;
6375 Vars.reserve(C->varlist_size());
6376 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6377 E = C->varlist_end();
6379 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6380 if (EVar.isInvalid())
6382 Vars.push_back(EVar.take());
6384 return getDerived().RebuildOMPSharedClause(Vars,
6390 //===----------------------------------------------------------------------===//
6391 // Expression transformation
6392 //===----------------------------------------------------------------------===//
6393 template<typename Derived>
6395 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
6396 return SemaRef.Owned(E);
6399 template<typename Derived>
6401 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
6402 NestedNameSpecifierLoc QualifierLoc;
6403 if (E->getQualifierLoc()) {
6405 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6411 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6416 DeclarationNameInfo NameInfo = E->getNameInfo();
6417 if (NameInfo.getName()) {
6418 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6419 if (!NameInfo.getName())
6423 if (!getDerived().AlwaysRebuild() &&
6424 QualifierLoc == E->getQualifierLoc() &&
6425 ND == E->getDecl() &&
6426 NameInfo.getName() == E->getDecl()->getDeclName() &&
6427 !E->hasExplicitTemplateArgs()) {
6429 // Mark it referenced in the new context regardless.
6430 // FIXME: this is a bit instantiation-specific.
6431 SemaRef.MarkDeclRefReferenced(E);
6433 return SemaRef.Owned(E);
6436 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
6437 if (E->hasExplicitTemplateArgs()) {
6438 TemplateArgs = &TransArgs;
6439 TransArgs.setLAngleLoc(E->getLAngleLoc());
6440 TransArgs.setRAngleLoc(E->getRAngleLoc());
6441 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6442 E->getNumTemplateArgs(),
6447 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6451 template<typename Derived>
6453 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
6454 return SemaRef.Owned(E);
6457 template<typename Derived>
6459 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
6460 return SemaRef.Owned(E);
6463 template<typename Derived>
6465 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
6466 return SemaRef.Owned(E);
6469 template<typename Derived>
6471 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
6472 return SemaRef.Owned(E);
6475 template<typename Derived>
6477 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
6478 return SemaRef.Owned(E);
6481 template<typename Derived>
6483 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6484 if (FunctionDecl *FD = E->getDirectCallee())
6485 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
6486 return SemaRef.MaybeBindToTemporary(E);
6489 template<typename Derived>
6491 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6492 ExprResult ControllingExpr =
6493 getDerived().TransformExpr(E->getControllingExpr());
6494 if (ControllingExpr.isInvalid())
6497 SmallVector<Expr *, 4> AssocExprs;
6498 SmallVector<TypeSourceInfo *, 4> AssocTypes;
6499 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6500 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6502 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6505 AssocTypes.push_back(AssocType);
6507 AssocTypes.push_back(0);
6510 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6511 if (AssocExpr.isInvalid())
6513 AssocExprs.push_back(AssocExpr.release());
6516 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6519 ControllingExpr.release(),
6524 template<typename Derived>
6526 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
6527 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6528 if (SubExpr.isInvalid())
6531 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
6532 return SemaRef.Owned(E);
6534 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
6538 /// \brief The operand of a unary address-of operator has special rules: it's
6539 /// allowed to refer to a non-static member of a class even if there's no 'this'
6540 /// object available.
6541 template<typename Derived>
6543 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6544 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6545 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6547 return getDerived().TransformExpr(E);
6550 template<typename Derived>
6552 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
6554 if (E->getOpcode() == UO_AddrOf)
6555 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6557 SubExpr = TransformExpr(E->getSubExpr());
6558 if (SubExpr.isInvalid())
6561 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
6562 return SemaRef.Owned(E);
6564 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6569 template<typename Derived>
6571 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6572 // Transform the type.
6573 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6577 // Transform all of the components into components similar to what the
6579 // FIXME: It would be slightly more efficient in the non-dependent case to
6580 // just map FieldDecls, rather than requiring the rebuilder to look for
6581 // the fields again. However, __builtin_offsetof is rare enough in
6582 // template code that we don't care.
6583 bool ExprChanged = false;
6584 typedef Sema::OffsetOfComponent Component;
6585 typedef OffsetOfExpr::OffsetOfNode Node;
6586 SmallVector<Component, 4> Components;
6587 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6588 const Node &ON = E->getComponent(I);
6590 Comp.isBrackets = true;
6591 Comp.LocStart = ON.getSourceRange().getBegin();
6592 Comp.LocEnd = ON.getSourceRange().getEnd();
6593 switch (ON.getKind()) {
6595 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
6596 ExprResult Index = getDerived().TransformExpr(FromIndex);
6597 if (Index.isInvalid())
6600 ExprChanged = ExprChanged || Index.get() != FromIndex;
6601 Comp.isBrackets = true;
6602 Comp.U.E = Index.get();
6607 case Node::Identifier:
6608 Comp.isBrackets = false;
6609 Comp.U.IdentInfo = ON.getFieldName();
6610 if (!Comp.U.IdentInfo)
6616 // Will be recomputed during the rebuild.
6620 Components.push_back(Comp);
6623 // If nothing changed, retain the existing expression.
6624 if (!getDerived().AlwaysRebuild() &&
6625 Type == E->getTypeSourceInfo() &&
6627 return SemaRef.Owned(E);
6629 // Build a new offsetof expression.
6630 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6631 Components.data(), Components.size(),
6635 template<typename Derived>
6637 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6638 assert(getDerived().AlreadyTransformed(E->getType()) &&
6639 "opaque value expression requires transformation");
6640 return SemaRef.Owned(E);
6643 template<typename Derived>
6645 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
6646 // Rebuild the syntactic form. The original syntactic form has
6647 // opaque-value expressions in it, so strip those away and rebuild
6648 // the result. This is a really awful way of doing this, but the
6649 // better solution (rebuilding the semantic expressions and
6650 // rebinding OVEs as necessary) doesn't work; we'd need
6651 // TreeTransform to not strip away implicit conversions.
6652 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6653 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
6654 if (result.isInvalid()) return ExprError();
6656 // If that gives us a pseudo-object result back, the pseudo-object
6657 // expression must have been an lvalue-to-rvalue conversion which we
6659 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6660 result = SemaRef.checkPseudoObjectRValue(result.take());
6665 template<typename Derived>
6667 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6668 UnaryExprOrTypeTraitExpr *E) {
6669 if (E->isArgumentType()) {
6670 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
6672 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6676 if (!getDerived().AlwaysRebuild() && OldT == NewT)
6677 return SemaRef.Owned(E);
6679 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6681 E->getSourceRange());
6684 // C++0x [expr.sizeof]p1:
6685 // The operand is either an expression, which is an unevaluated operand
6687 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6688 Sema::ReuseLambdaContextDecl);
6690 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6691 if (SubExpr.isInvalid())
6694 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6695 return SemaRef.Owned(E);
6697 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6698 E->getOperatorLoc(),
6700 E->getSourceRange());
6703 template<typename Derived>
6705 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
6706 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6707 if (LHS.isInvalid())
6710 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6711 if (RHS.isInvalid())
6715 if (!getDerived().AlwaysRebuild() &&
6716 LHS.get() == E->getLHS() &&
6717 RHS.get() == E->getRHS())
6718 return SemaRef.Owned(E);
6720 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
6721 /*FIXME:*/E->getLHS()->getLocStart(),
6723 E->getRBracketLoc());
6726 template<typename Derived>
6728 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6729 // Transform the callee.
6730 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6731 if (Callee.isInvalid())
6734 // Transform arguments.
6735 bool ArgChanged = false;
6736 SmallVector<Expr*, 8> Args;
6737 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6741 if (!getDerived().AlwaysRebuild() &&
6742 Callee.get() == E->getCallee() &&
6744 return SemaRef.MaybeBindToTemporary(E);
6746 // FIXME: Wrong source location information for the '('.
6747 SourceLocation FakeLParenLoc
6748 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6749 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6754 template<typename Derived>
6756 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
6757 ExprResult Base = getDerived().TransformExpr(E->getBase());
6758 if (Base.isInvalid())
6761 NestedNameSpecifierLoc QualifierLoc;
6762 if (E->hasQualifier()) {
6764 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6769 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
6772 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6773 E->getMemberDecl()));
6777 NamedDecl *FoundDecl = E->getFoundDecl();
6778 if (FoundDecl == E->getMemberDecl()) {
6781 FoundDecl = cast_or_null<NamedDecl>(
6782 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6787 if (!getDerived().AlwaysRebuild() &&
6788 Base.get() == E->getBase() &&
6789 QualifierLoc == E->getQualifierLoc() &&
6790 Member == E->getMemberDecl() &&
6791 FoundDecl == E->getFoundDecl() &&
6792 !E->hasExplicitTemplateArgs()) {
6794 // Mark it referenced in the new context regardless.
6795 // FIXME: this is a bit instantiation-specific.
6796 SemaRef.MarkMemberReferenced(E);
6798 return SemaRef.Owned(E);
6801 TemplateArgumentListInfo TransArgs;
6802 if (E->hasExplicitTemplateArgs()) {
6803 TransArgs.setLAngleLoc(E->getLAngleLoc());
6804 TransArgs.setRAngleLoc(E->getRAngleLoc());
6805 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6806 E->getNumTemplateArgs(),
6811 // FIXME: Bogus source location for the operator
6812 SourceLocation FakeOperatorLoc
6813 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6815 // FIXME: to do this check properly, we will need to preserve the
6816 // first-qualifier-in-scope here, just in case we had a dependent
6817 // base (and therefore couldn't do the check) and a
6818 // nested-name-qualifier (and therefore could do the lookup).
6819 NamedDecl *FirstQualifierInScope = 0;
6821 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6825 E->getMemberNameInfo(),
6828 (E->hasExplicitTemplateArgs()
6830 FirstQualifierInScope);
6833 template<typename Derived>
6835 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
6836 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6837 if (LHS.isInvalid())
6840 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6841 if (RHS.isInvalid())
6844 if (!getDerived().AlwaysRebuild() &&
6845 LHS.get() == E->getLHS() &&
6846 RHS.get() == E->getRHS())
6847 return SemaRef.Owned(E);
6849 Sema::FPContractStateRAII FPContractState(getSema());
6850 getSema().FPFeatures.fp_contract = E->isFPContractable();
6852 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
6853 LHS.get(), RHS.get());
6856 template<typename Derived>
6858 TreeTransform<Derived>::TransformCompoundAssignOperator(
6859 CompoundAssignOperator *E) {
6860 return getDerived().TransformBinaryOperator(E);
6863 template<typename Derived>
6864 ExprResult TreeTransform<Derived>::
6865 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6866 // Just rebuild the common and RHS expressions and see whether we
6869 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6870 if (commonExpr.isInvalid())
6873 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6874 if (rhs.isInvalid())
6877 if (!getDerived().AlwaysRebuild() &&
6878 commonExpr.get() == e->getCommon() &&
6879 rhs.get() == e->getFalseExpr())
6880 return SemaRef.Owned(e);
6882 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6883 e->getQuestionLoc(),
6889 template<typename Derived>
6891 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
6892 ExprResult Cond = getDerived().TransformExpr(E->getCond());
6893 if (Cond.isInvalid())
6896 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6897 if (LHS.isInvalid())
6900 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6901 if (RHS.isInvalid())
6904 if (!getDerived().AlwaysRebuild() &&
6905 Cond.get() == E->getCond() &&
6906 LHS.get() == E->getLHS() &&
6907 RHS.get() == E->getRHS())
6908 return SemaRef.Owned(E);
6910 return getDerived().RebuildConditionalOperator(Cond.get(),
6911 E->getQuestionLoc(),
6917 template<typename Derived>
6919 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6920 // Implicit casts are eliminated during transformation, since they
6921 // will be recomputed by semantic analysis after transformation.
6922 return getDerived().TransformExpr(E->getSubExprAsWritten());
6925 template<typename Derived>
6927 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6928 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6933 = getDerived().TransformExpr(E->getSubExprAsWritten());
6934 if (SubExpr.isInvalid())
6937 if (!getDerived().AlwaysRebuild() &&
6938 Type == E->getTypeInfoAsWritten() &&
6939 SubExpr.get() == E->getSubExpr())
6940 return SemaRef.Owned(E);
6942 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6948 template<typename Derived>
6950 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
6951 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6952 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6956 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6957 if (Init.isInvalid())
6960 if (!getDerived().AlwaysRebuild() &&
6962 Init.get() == E->getInitializer())
6963 return SemaRef.MaybeBindToTemporary(E);
6965 // Note: the expression type doesn't necessarily match the
6966 // type-as-written, but that's okay, because it should always be
6967 // derivable from the initializer.
6969 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6970 /*FIXME:*/E->getInitializer()->getLocEnd(),
6974 template<typename Derived>
6976 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
6977 ExprResult Base = getDerived().TransformExpr(E->getBase());
6978 if (Base.isInvalid())
6981 if (!getDerived().AlwaysRebuild() &&
6982 Base.get() == E->getBase())
6983 return SemaRef.Owned(E);
6985 // FIXME: Bad source location
6986 SourceLocation FakeOperatorLoc
6987 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
6988 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6989 E->getAccessorLoc(),
6993 template<typename Derived>
6995 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6996 bool InitChanged = false;
6998 SmallVector<Expr*, 4> Inits;
6999 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
7000 Inits, &InitChanged))
7003 if (!getDerived().AlwaysRebuild() && !InitChanged)
7004 return SemaRef.Owned(E);
7006 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
7007 E->getRBraceLoc(), E->getType());
7010 template<typename Derived>
7012 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
7015 // transform the initializer value
7016 ExprResult Init = getDerived().TransformExpr(E->getInit());
7017 if (Init.isInvalid())
7020 // transform the designators.
7021 SmallVector<Expr*, 4> ArrayExprs;
7022 bool ExprChanged = false;
7023 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7024 DEnd = E->designators_end();
7026 if (D->isFieldDesignator()) {
7027 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7033 if (D->isArrayDesignator()) {
7034 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
7035 if (Index.isInvalid())
7038 Desig.AddDesignator(Designator::getArray(Index.get(),
7039 D->getLBracketLoc()));
7041 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7042 ArrayExprs.push_back(Index.release());
7046 assert(D->isArrayRangeDesignator() && "New kind of designator?");
7048 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7049 if (Start.isInvalid())
7052 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
7053 if (End.isInvalid())
7056 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
7058 D->getLBracketLoc(),
7059 D->getEllipsisLoc()));
7061 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7062 End.get() != E->getArrayRangeEnd(*D);
7064 ArrayExprs.push_back(Start.release());
7065 ArrayExprs.push_back(End.release());
7068 if (!getDerived().AlwaysRebuild() &&
7069 Init.get() == E->getInit() &&
7071 return SemaRef.Owned(E);
7073 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
7074 E->getEqualOrColonLoc(),
7075 E->usesGNUSyntax(), Init.get());
7078 template<typename Derived>
7080 TreeTransform<Derived>::TransformImplicitValueInitExpr(
7081 ImplicitValueInitExpr *E) {
7082 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
7084 // FIXME: Will we ever have proper type location here? Will we actually
7085 // need to transform the type?
7086 QualType T = getDerived().TransformType(E->getType());
7090 if (!getDerived().AlwaysRebuild() &&
7092 return SemaRef.Owned(E);
7094 return getDerived().RebuildImplicitValueInitExpr(T);
7097 template<typename Derived>
7099 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
7100 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7104 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7105 if (SubExpr.isInvalid())
7108 if (!getDerived().AlwaysRebuild() &&
7109 TInfo == E->getWrittenTypeInfo() &&
7110 SubExpr.get() == E->getSubExpr())
7111 return SemaRef.Owned(E);
7113 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
7114 TInfo, E->getRParenLoc());
7117 template<typename Derived>
7119 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
7120 bool ArgumentChanged = false;
7121 SmallVector<Expr*, 4> Inits;
7122 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7126 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
7131 /// \brief Transform an address-of-label expression.
7133 /// By default, the transformation of an address-of-label expression always
7134 /// rebuilds the expression, so that the label identifier can be resolved to
7135 /// the corresponding label statement by semantic analysis.
7136 template<typename Derived>
7138 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
7139 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7144 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
7145 cast<LabelDecl>(LD));
7148 template<typename Derived>
7150 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
7151 SemaRef.ActOnStartStmtExpr();
7153 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
7154 if (SubStmt.isInvalid()) {
7155 SemaRef.ActOnStmtExprError();
7159 if (!getDerived().AlwaysRebuild() &&
7160 SubStmt.get() == E->getSubStmt()) {
7161 // Calling this an 'error' is unintuitive, but it does the right thing.
7162 SemaRef.ActOnStmtExprError();
7163 return SemaRef.MaybeBindToTemporary(E);
7166 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
7171 template<typename Derived>
7173 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
7174 ExprResult Cond = getDerived().TransformExpr(E->getCond());
7175 if (Cond.isInvalid())
7178 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
7179 if (LHS.isInvalid())
7182 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
7183 if (RHS.isInvalid())
7186 if (!getDerived().AlwaysRebuild() &&
7187 Cond.get() == E->getCond() &&
7188 LHS.get() == E->getLHS() &&
7189 RHS.get() == E->getRHS())
7190 return SemaRef.Owned(E);
7192 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
7193 Cond.get(), LHS.get(), RHS.get(),
7197 template<typename Derived>
7199 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
7200 return SemaRef.Owned(E);
7203 template<typename Derived>
7205 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
7206 switch (E->getOperator()) {
7210 case OO_Array_Delete:
7211 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
7214 // This is a call to an object's operator().
7215 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7217 // Transform the object itself.
7218 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
7219 if (Object.isInvalid())
7222 // FIXME: Poor location information
7223 SourceLocation FakeLParenLoc
7224 = SemaRef.PP.getLocForEndOfToken(
7225 static_cast<Expr *>(Object.get())->getLocEnd());
7227 // Transform the call arguments.
7228 SmallVector<Expr*, 8> Args;
7229 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
7233 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
7238 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7240 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7241 #include "clang/Basic/OperatorKinds.def"
7246 case OO_Conditional:
7247 llvm_unreachable("conditional operator is not actually overloadable");
7250 case NUM_OVERLOADED_OPERATORS:
7251 llvm_unreachable("not an overloaded operator?");
7254 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7255 if (Callee.isInvalid())
7259 if (E->getOperator() == OO_Amp)
7260 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7262 First = getDerived().TransformExpr(E->getArg(0));
7263 if (First.isInvalid())
7267 if (E->getNumArgs() == 2) {
7268 Second = getDerived().TransformExpr(E->getArg(1));
7269 if (Second.isInvalid())
7273 if (!getDerived().AlwaysRebuild() &&
7274 Callee.get() == E->getCallee() &&
7275 First.get() == E->getArg(0) &&
7276 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
7277 return SemaRef.MaybeBindToTemporary(E);
7279 Sema::FPContractStateRAII FPContractState(getSema());
7280 getSema().FPFeatures.fp_contract = E->isFPContractable();
7282 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7283 E->getOperatorLoc(),
7289 template<typename Derived>
7291 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7292 return getDerived().TransformCallExpr(E);
7295 template<typename Derived>
7297 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7298 // Transform the callee.
7299 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7300 if (Callee.isInvalid())
7303 // Transform exec config.
7304 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7308 // Transform arguments.
7309 bool ArgChanged = false;
7310 SmallVector<Expr*, 8> Args;
7311 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7315 if (!getDerived().AlwaysRebuild() &&
7316 Callee.get() == E->getCallee() &&
7318 return SemaRef.MaybeBindToTemporary(E);
7320 // FIXME: Wrong source location information for the '('.
7321 SourceLocation FakeLParenLoc
7322 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7323 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
7325 E->getRParenLoc(), EC.get());
7328 template<typename Derived>
7330 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
7331 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7336 = getDerived().TransformExpr(E->getSubExprAsWritten());
7337 if (SubExpr.isInvalid())
7340 if (!getDerived().AlwaysRebuild() &&
7341 Type == E->getTypeInfoAsWritten() &&
7342 SubExpr.get() == E->getSubExpr())
7343 return SemaRef.Owned(E);
7344 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
7346 E->getAngleBrackets().getBegin(),
7348 E->getAngleBrackets().getEnd(),
7349 // FIXME. this should be '(' location
7350 E->getAngleBrackets().getEnd(),
7355 template<typename Derived>
7357 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7358 return getDerived().TransformCXXNamedCastExpr(E);
7361 template<typename Derived>
7363 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7364 return getDerived().TransformCXXNamedCastExpr(E);
7367 template<typename Derived>
7369 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
7370 CXXReinterpretCastExpr *E) {
7371 return getDerived().TransformCXXNamedCastExpr(E);
7374 template<typename Derived>
7376 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7377 return getDerived().TransformCXXNamedCastExpr(E);
7380 template<typename Derived>
7382 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
7383 CXXFunctionalCastExpr *E) {
7384 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7389 = getDerived().TransformExpr(E->getSubExprAsWritten());
7390 if (SubExpr.isInvalid())
7393 if (!getDerived().AlwaysRebuild() &&
7394 Type == E->getTypeInfoAsWritten() &&
7395 SubExpr.get() == E->getSubExpr())
7396 return SemaRef.Owned(E);
7398 return getDerived().RebuildCXXFunctionalCastExpr(Type,
7404 template<typename Derived>
7406 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
7407 if (E->isTypeOperand()) {
7408 TypeSourceInfo *TInfo
7409 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7413 if (!getDerived().AlwaysRebuild() &&
7414 TInfo == E->getTypeOperandSourceInfo())
7415 return SemaRef.Owned(E);
7417 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7423 // We don't know whether the subexpression is potentially evaluated until
7424 // after we perform semantic analysis. We speculatively assume it is
7425 // unevaluated; it will get fixed later if the subexpression is in fact
7426 // potentially evaluated.
7427 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7428 Sema::ReuseLambdaContextDecl);
7430 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7431 if (SubExpr.isInvalid())
7434 if (!getDerived().AlwaysRebuild() &&
7435 SubExpr.get() == E->getExprOperand())
7436 return SemaRef.Owned(E);
7438 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7444 template<typename Derived>
7446 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7447 if (E->isTypeOperand()) {
7448 TypeSourceInfo *TInfo
7449 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7453 if (!getDerived().AlwaysRebuild() &&
7454 TInfo == E->getTypeOperandSourceInfo())
7455 return SemaRef.Owned(E);
7457 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7463 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7465 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7466 if (SubExpr.isInvalid())
7469 if (!getDerived().AlwaysRebuild() &&
7470 SubExpr.get() == E->getExprOperand())
7471 return SemaRef.Owned(E);
7473 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7479 template<typename Derived>
7481 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
7482 return SemaRef.Owned(E);
7485 template<typename Derived>
7487 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
7488 CXXNullPtrLiteralExpr *E) {
7489 return SemaRef.Owned(E);
7492 template<typename Derived>
7494 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
7495 QualType T = getSema().getCurrentThisType();
7497 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7498 // Make sure that we capture 'this'.
7499 getSema().CheckCXXThisCapture(E->getLocStart());
7500 return SemaRef.Owned(E);
7503 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
7506 template<typename Derived>
7508 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
7509 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7510 if (SubExpr.isInvalid())
7513 if (!getDerived().AlwaysRebuild() &&
7514 SubExpr.get() == E->getSubExpr())
7515 return SemaRef.Owned(E);
7517 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7518 E->isThrownVariableInScope());
7521 template<typename Derived>
7523 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
7525 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7530 if (!getDerived().AlwaysRebuild() &&
7531 Param == E->getParam())
7532 return SemaRef.Owned(E);
7534 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
7537 template<typename Derived>
7539 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7541 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7546 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7547 return SemaRef.Owned(E);
7549 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7552 template<typename Derived>
7554 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7555 CXXScalarValueInitExpr *E) {
7556 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7560 if (!getDerived().AlwaysRebuild() &&
7561 T == E->getTypeSourceInfo())
7562 return SemaRef.Owned(E);
7564 return getDerived().RebuildCXXScalarValueInitExpr(T,
7565 /*FIXME:*/T->getTypeLoc().getEndLoc(),
7569 template<typename Derived>
7571 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
7572 // Transform the type that we're allocating
7573 TypeSourceInfo *AllocTypeInfo
7574 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7578 // Transform the size of the array we're allocating (if any).
7579 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
7580 if (ArraySize.isInvalid())
7583 // Transform the placement arguments (if any).
7584 bool ArgumentChanged = false;
7585 SmallVector<Expr*, 8> PlacementArgs;
7586 if (getDerived().TransformExprs(E->getPlacementArgs(),
7587 E->getNumPlacementArgs(), true,
7588 PlacementArgs, &ArgumentChanged))
7591 // Transform the initializer (if any).
7592 Expr *OldInit = E->getInitializer();
7595 NewInit = getDerived().TransformExpr(OldInit);
7596 if (NewInit.isInvalid())
7599 // Transform new operator and delete operator.
7600 FunctionDecl *OperatorNew = 0;
7601 if (E->getOperatorNew()) {
7602 OperatorNew = cast_or_null<FunctionDecl>(
7603 getDerived().TransformDecl(E->getLocStart(),
7604 E->getOperatorNew()));
7609 FunctionDecl *OperatorDelete = 0;
7610 if (E->getOperatorDelete()) {
7611 OperatorDelete = cast_or_null<FunctionDecl>(
7612 getDerived().TransformDecl(E->getLocStart(),
7613 E->getOperatorDelete()));
7614 if (!OperatorDelete)
7618 if (!getDerived().AlwaysRebuild() &&
7619 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
7620 ArraySize.get() == E->getArraySize() &&
7621 NewInit.get() == OldInit &&
7622 OperatorNew == E->getOperatorNew() &&
7623 OperatorDelete == E->getOperatorDelete() &&
7625 // Mark any declarations we need as referenced.
7626 // FIXME: instantiation-specific.
7628 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
7630 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
7632 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
7633 QualType ElementType
7634 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7635 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7636 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7637 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7638 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
7643 return SemaRef.Owned(E);
7646 QualType AllocType = AllocTypeInfo->getType();
7647 if (!ArraySize.get()) {
7648 // If no array size was specified, but the new expression was
7649 // instantiated with an array type (e.g., "new T" where T is
7650 // instantiated with "int[4]"), extract the outer bound from the
7651 // array type as our array size. We do this with constant and
7652 // dependently-sized array types.
7653 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7656 } else if (const ConstantArrayType *ConsArrayT
7657 = dyn_cast<ConstantArrayType>(ArrayT)) {
7659 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7660 ConsArrayT->getSize(),
7661 SemaRef.Context.getSizeType(),
7662 /*FIXME:*/E->getLocStart()));
7663 AllocType = ConsArrayT->getElementType();
7664 } else if (const DependentSizedArrayType *DepArrayT
7665 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7666 if (DepArrayT->getSizeExpr()) {
7667 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
7668 AllocType = DepArrayT->getElementType();
7673 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7675 /*FIXME:*/E->getLocStart(),
7677 /*FIXME:*/E->getLocStart(),
7678 E->getTypeIdParens(),
7682 E->getDirectInitRange(),
7686 template<typename Derived>
7688 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
7689 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
7690 if (Operand.isInvalid())
7693 // Transform the delete operator, if known.
7694 FunctionDecl *OperatorDelete = 0;
7695 if (E->getOperatorDelete()) {
7696 OperatorDelete = cast_or_null<FunctionDecl>(
7697 getDerived().TransformDecl(E->getLocStart(),
7698 E->getOperatorDelete()));
7699 if (!OperatorDelete)
7703 if (!getDerived().AlwaysRebuild() &&
7704 Operand.get() == E->getArgument() &&
7705 OperatorDelete == E->getOperatorDelete()) {
7706 // Mark any declarations we need as referenced.
7707 // FIXME: instantiation-specific.
7709 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
7711 if (!E->getArgument()->isTypeDependent()) {
7712 QualType Destroyed = SemaRef.Context.getBaseElementType(
7713 E->getDestroyedType());
7714 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7715 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7716 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7717 SemaRef.LookupDestructor(Record));
7721 return SemaRef.Owned(E);
7724 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7725 E->isGlobalDelete(),
7730 template<typename Derived>
7732 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
7733 CXXPseudoDestructorExpr *E) {
7734 ExprResult Base = getDerived().TransformExpr(E->getBase());
7735 if (Base.isInvalid())
7738 ParsedType ObjectTypePtr;
7739 bool MayBePseudoDestructor = false;
7740 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7741 E->getOperatorLoc(),
7742 E->isArrow()? tok::arrow : tok::period,
7744 MayBePseudoDestructor);
7745 if (Base.isInvalid())
7748 QualType ObjectType = ObjectTypePtr.get();
7749 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7752 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7757 SS.Adopt(QualifierLoc);
7759 PseudoDestructorTypeStorage Destroyed;
7760 if (E->getDestroyedTypeInfo()) {
7761 TypeSourceInfo *DestroyedTypeInfo
7762 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7764 if (!DestroyedTypeInfo)
7766 Destroyed = DestroyedTypeInfo;
7767 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
7768 // We aren't likely to be able to resolve the identifier down to a type
7769 // now anyway, so just retain the identifier.
7770 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7771 E->getDestroyedTypeLoc());
7773 // Look for a destructor known with the given name.
7774 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7775 *E->getDestroyedTypeIdentifier(),
7776 E->getDestroyedTypeLoc(),
7784 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7785 E->getDestroyedTypeLoc());
7788 TypeSourceInfo *ScopeTypeInfo = 0;
7789 if (E->getScopeTypeInfo()) {
7790 CXXScopeSpec EmptySS;
7791 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7792 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
7797 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7798 E->getOperatorLoc(),
7802 E->getColonColonLoc(),
7807 template<typename Derived>
7809 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
7810 UnresolvedLookupExpr *Old) {
7811 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7812 Sema::LookupOrdinaryName);
7814 // Transform all the decls.
7815 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7816 E = Old->decls_end(); I != E; ++I) {
7817 NamedDecl *InstD = static_cast<NamedDecl*>(
7818 getDerived().TransformDecl(Old->getNameLoc(),
7821 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7822 // This can happen because of dependent hiding.
7823 if (isa<UsingShadowDecl>(*I))
7831 // Expand using declarations.
7832 if (isa<UsingDecl>(InstD)) {
7833 UsingDecl *UD = cast<UsingDecl>(InstD);
7834 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7835 E = UD->shadow_end(); I != E; ++I)
7843 // Resolve a kind, but don't do any further analysis. If it's
7844 // ambiguous, the callee needs to deal with it.
7847 // Rebuild the nested-name qualifier, if present.
7849 if (Old->getQualifierLoc()) {
7850 NestedNameSpecifierLoc QualifierLoc
7851 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7855 SS.Adopt(QualifierLoc);
7858 if (Old->getNamingClass()) {
7859 CXXRecordDecl *NamingClass
7860 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7862 Old->getNamingClass()));
7868 R.setNamingClass(NamingClass);
7871 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7873 // If we have neither explicit template arguments, nor the template keyword,
7874 // it's a normal declaration name.
7875 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
7876 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7878 // If we have template arguments, rebuild them, then rebuild the
7879 // templateid expression.
7880 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
7881 if (Old->hasExplicitTemplateArgs() &&
7882 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7883 Old->getNumTemplateArgs(),
7889 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
7890 Old->requiresADL(), &TransArgs);
7893 template<typename Derived>
7895 TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
7896 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7900 if (!getDerived().AlwaysRebuild() &&
7901 T == E->getQueriedTypeSourceInfo())
7902 return SemaRef.Owned(E);
7904 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7910 template<typename Derived>
7912 TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7913 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7917 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7921 if (!getDerived().AlwaysRebuild() &&
7922 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7923 return SemaRef.Owned(E);
7925 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7931 template<typename Derived>
7933 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7934 bool ArgChanged = false;
7935 SmallVector<TypeSourceInfo *, 4> Args;
7936 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7937 TypeSourceInfo *From = E->getArg(I);
7938 TypeLoc FromTL = From->getTypeLoc();
7939 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
7941 TLB.reserve(FromTL.getFullDataSize());
7942 QualType To = getDerived().TransformType(TLB, FromTL);
7946 if (To == From->getType())
7947 Args.push_back(From);
7949 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7957 // We have a pack expansion. Instantiate it.
7958 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
7959 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7960 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7961 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7963 // Determine whether the set of unexpanded parameter packs can and should
7966 bool RetainExpansion = false;
7967 Optional<unsigned> OrigNumExpansions =
7968 ExpansionTL.getTypePtr()->getNumExpansions();
7969 Optional<unsigned> NumExpansions = OrigNumExpansions;
7970 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7971 PatternTL.getSourceRange(),
7973 Expand, RetainExpansion,
7978 // The transform has determined that we should perform a simple
7979 // transformation on the pack expansion, producing another pack
7981 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7984 TLB.reserve(From->getTypeLoc().getFullDataSize());
7986 QualType To = getDerived().TransformType(TLB, PatternTL);
7990 To = getDerived().RebuildPackExpansionType(To,
7991 PatternTL.getSourceRange(),
7992 ExpansionTL.getEllipsisLoc(),
7997 PackExpansionTypeLoc ToExpansionTL
7998 = TLB.push<PackExpansionTypeLoc>(To);
7999 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8000 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8004 // Expand the pack expansion by substituting for each argument in the
8006 for (unsigned I = 0; I != *NumExpansions; ++I) {
8007 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8009 TLB.reserve(PatternTL.getFullDataSize());
8010 QualType To = getDerived().TransformType(TLB, PatternTL);
8014 if (To->containsUnexpandedParameterPack()) {
8015 To = getDerived().RebuildPackExpansionType(To,
8016 PatternTL.getSourceRange(),
8017 ExpansionTL.getEllipsisLoc(),
8022 PackExpansionTypeLoc ToExpansionTL
8023 = TLB.push<PackExpansionTypeLoc>(To);
8024 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8027 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8030 if (!RetainExpansion)
8033 // If we're supposed to retain a pack expansion, do so by temporarily
8034 // forgetting the partially-substituted parameter pack.
8035 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8038 TLB.reserve(From->getTypeLoc().getFullDataSize());
8040 QualType To = getDerived().TransformType(TLB, PatternTL);
8044 To = getDerived().RebuildPackExpansionType(To,
8045 PatternTL.getSourceRange(),
8046 ExpansionTL.getEllipsisLoc(),
8051 PackExpansionTypeLoc ToExpansionTL
8052 = TLB.push<PackExpansionTypeLoc>(To);
8053 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8054 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8057 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8058 return SemaRef.Owned(E);
8060 return getDerived().RebuildTypeTrait(E->getTrait(),
8066 template<typename Derived>
8068 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8069 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8073 if (!getDerived().AlwaysRebuild() &&
8074 T == E->getQueriedTypeSourceInfo())
8075 return SemaRef.Owned(E);
8079 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8080 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8081 if (SubExpr.isInvalid())
8084 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8085 return SemaRef.Owned(E);
8088 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8095 template<typename Derived>
8097 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8100 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8101 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8102 if (SubExpr.isInvalid())
8105 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8106 return SemaRef.Owned(E);
8109 return getDerived().RebuildExpressionTrait(
8110 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8113 template<typename Derived>
8115 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8116 DependentScopeDeclRefExpr *E) {
8117 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8120 template<typename Derived>
8122 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8123 DependentScopeDeclRefExpr *E,
8124 bool IsAddressOfOperand) {
8125 assert(E->getQualifierLoc());
8126 NestedNameSpecifierLoc QualifierLoc
8127 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8130 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8132 // TODO: If this is a conversion-function-id, verify that the
8133 // destination type name (if present) resolves the same way after
8134 // instantiation as it did in the local scope.
8136 DeclarationNameInfo NameInfo
8137 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8138 if (!NameInfo.getName())
8141 if (!E->hasExplicitTemplateArgs()) {
8142 if (!getDerived().AlwaysRebuild() &&
8143 QualifierLoc == E->getQualifierLoc() &&
8144 // Note: it is sufficient to compare the Name component of NameInfo:
8145 // if name has not changed, DNLoc has not changed either.
8146 NameInfo.getName() == E->getDeclName())
8147 return SemaRef.Owned(E);
8149 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
8153 IsAddressOfOperand);
8156 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8157 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8158 E->getNumTemplateArgs(),
8162 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
8166 IsAddressOfOperand);
8169 template<typename Derived>
8171 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
8172 // CXXConstructExprs other than for list-initialization and
8173 // CXXTemporaryObjectExpr are always implicit, so when we have
8174 // a 1-argument construction we just transform that argument.
8175 if ((E->getNumArgs() == 1 ||
8176 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
8177 (!getDerived().DropCallArgument(E->getArg(0))) &&
8178 !E->isListInitialization())
8179 return getDerived().TransformExpr(E->getArg(0));
8181 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8183 QualType T = getDerived().TransformType(E->getType());
8187 CXXConstructorDecl *Constructor
8188 = cast_or_null<CXXConstructorDecl>(
8189 getDerived().TransformDecl(E->getLocStart(),
8190 E->getConstructor()));
8194 bool ArgumentChanged = false;
8195 SmallVector<Expr*, 8> Args;
8196 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8200 if (!getDerived().AlwaysRebuild() &&
8201 T == E->getType() &&
8202 Constructor == E->getConstructor() &&
8204 // Mark the constructor as referenced.
8205 // FIXME: Instantiation-specific
8206 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
8207 return SemaRef.Owned(E);
8210 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8211 Constructor, E->isElidable(),
8213 E->hadMultipleCandidates(),
8214 E->isListInitialization(),
8215 E->requiresZeroInitialization(),
8216 E->getConstructionKind(),
8217 E->getParenOrBraceRange());
8220 /// \brief Transform a C++ temporary-binding expression.
8222 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8223 /// transform the subexpression and return that.
8224 template<typename Derived>
8226 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
8227 return getDerived().TransformExpr(E->getSubExpr());
8230 /// \brief Transform a C++ expression that contains cleanups that should
8231 /// be run after the expression is evaluated.
8233 /// Since ExprWithCleanups nodes are implicitly generated, we
8234 /// just transform the subexpression and return that.
8235 template<typename Derived>
8237 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
8238 return getDerived().TransformExpr(E->getSubExpr());
8241 template<typename Derived>
8243 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
8244 CXXTemporaryObjectExpr *E) {
8245 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8249 CXXConstructorDecl *Constructor
8250 = cast_or_null<CXXConstructorDecl>(
8251 getDerived().TransformDecl(E->getLocStart(),
8252 E->getConstructor()));
8256 bool ArgumentChanged = false;
8257 SmallVector<Expr*, 8> Args;
8258 Args.reserve(E->getNumArgs());
8259 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8263 if (!getDerived().AlwaysRebuild() &&
8264 T == E->getTypeSourceInfo() &&
8265 Constructor == E->getConstructor() &&
8267 // FIXME: Instantiation-specific
8268 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
8269 return SemaRef.MaybeBindToTemporary(E);
8272 // FIXME: Pass in E->isListInitialization().
8273 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8274 /*FIXME:*/T->getTypeLoc().getEndLoc(),
8279 template<typename Derived>
8281 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
8283 // Transform any init-capture expressions before entering the scope of the
8284 // lambda body, because they are not semantically within that scope.
8285 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8286 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8287 E->explicit_capture_begin());
8289 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8290 CEnd = E->capture_end();
8292 if (!C->isInitCapture())
8294 EnterExpressionEvaluationContext EEEC(getSema(),
8295 Sema::PotentiallyEvaluated);
8296 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8297 C->getCapturedVar()->getInit(),
8298 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8300 if (NewExprInitResult.isInvalid())
8302 Expr *NewExprInit = NewExprInitResult.get();
8304 VarDecl *OldVD = C->getCapturedVar();
8305 QualType NewInitCaptureType =
8306 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8307 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8309 NewExprInitResult = NewExprInit;
8310 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8311 std::make_pair(NewExprInitResult, NewInitCaptureType);
8315 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
8316 // Transform the template parameters, and add them to the current
8317 // instantiation scope. The null case is handled correctly.
8318 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8319 E->getTemplateParameterList());
8321 // Check to see if the TypeSourceInfo of the call operator needs to
8322 // be transformed, and if so do the transformation in the
8323 // CurrentInstantiationScope.
8325 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8326 FunctionProtoTypeLoc OldCallOpFPTL =
8327 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8328 TypeSourceInfo *NewCallOpTSI = 0;
8330 const bool CallOpWasAlreadyTransformed =
8331 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8333 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8334 if (CallOpWasAlreadyTransformed)
8335 NewCallOpTSI = OldCallOpTSI;
8337 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8338 // The transformation MUST be done in the CurrentInstantiationScope since
8339 // it introduces a mapping of the original to the newly created
8340 // transformed parameters.
8342 TypeLocBuilder NewCallOpTLBuilder;
8343 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8346 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8349 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8350 // the vector below - this will be used to synthesize the
8351 // NewCallOperator. Additionally, add the parameters of the untransformed
8352 // lambda call operator to the CurrentInstantiationScope.
8353 SmallVector<ParmVarDecl *, 4> Params;
8355 FunctionProtoTypeLoc NewCallOpFPTL =
8356 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8357 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8358 const unsigned NewNumArgs = NewCallOpFPTL.getNumArgs();
8360 for (unsigned I = 0; I < NewNumArgs; ++I) {
8361 // If this call operator's type does not require transformation,
8362 // the parameters do not get added to the current instantiation scope,
8363 // - so ADD them! This allows the following to compile when the enclosing
8364 // template is specialized and the entire lambda expression has to be
8366 // template<class T> void foo(T t) {
8367 // auto L = [](auto a) {
8368 // auto M = [](char b) { <-- note: non-generic lambda
8369 // auto N = [](auto c) {
8370 // int x = sizeof(a);
8371 // x = sizeof(b); <-- specifically this line
8378 if (CallOpWasAlreadyTransformed)
8379 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8380 NewParamDeclArray[I]);
8381 // Add to Params array, so these parameters can be used to create
8382 // the newly transformed call operator.
8383 Params.push_back(NewParamDeclArray[I]);
8390 // Create the local class that will describe the lambda.
8391 CXXRecordDecl *Class
8392 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8394 /*KnownDependent=*/false,
8395 E->getCaptureDefault());
8397 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8399 // Build the call operator.
8400 CXXMethodDecl *NewCallOperator
8401 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
8403 E->getCallOperator()->getLocEnd(),
8405 LSI->CallOperator = NewCallOperator;
8407 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8409 return getDerived().TransformLambdaScope(E, NewCallOperator,
8410 InitCaptureExprsAndTypes);
8413 template<typename Derived>
8415 TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8416 CXXMethodDecl *CallOperator,
8417 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
8418 bool Invalid = false;
8420 // Introduce the context of the call operator.
8421 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8423 LambdaScopeInfo *const LSI = getSema().getCurLambda();
8424 // Enter the scope of the lambda.
8425 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
8426 E->getCaptureDefault(),
8427 E->getCaptureDefaultLoc(),
8428 E->hasExplicitParameters(),
8429 E->hasExplicitResultType(),
8432 // Transform captures.
8433 bool FinishedExplicitCaptures = false;
8434 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8435 CEnd = E->capture_end();
8437 // When we hit the first implicit capture, tell Sema that we've finished
8438 // the list of explicit captures.
8439 if (!FinishedExplicitCaptures && C->isImplicit()) {
8440 getSema().finishLambdaExplicitCaptures(LSI);
8441 FinishedExplicitCaptures = true;
8444 // Capturing 'this' is trivial.
8445 if (C->capturesThis()) {
8446 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8450 // Rebuild init-captures, including the implied field declaration.
8451 if (C->isInitCapture()) {
8453 InitCaptureInfoTy InitExprTypePair =
8454 InitCaptureExprsAndTypes[C - E->capture_begin()];
8455 ExprResult Init = InitExprTypePair.first;
8456 QualType InitQualType = InitExprTypePair.second;
8457 if (Init.isInvalid() || InitQualType.isNull()) {
8461 VarDecl *OldVD = C->getCapturedVar();
8462 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8463 OldVD->getLocation(), InitExprTypePair.second,
8464 OldVD->getIdentifier(), Init.get());
8468 getDerived().transformedLocalDecl(OldVD, NewVD);
8470 getSema().buildInitCaptureField(LSI, NewVD);
8474 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8476 // Determine the capture kind for Sema.
8477 Sema::TryCaptureKind Kind
8478 = C->isImplicit()? Sema::TryCapture_Implicit
8479 : C->getCaptureKind() == LCK_ByCopy
8480 ? Sema::TryCapture_ExplicitByVal
8481 : Sema::TryCapture_ExplicitByRef;
8482 SourceLocation EllipsisLoc;
8483 if (C->isPackExpansion()) {
8484 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8485 bool ShouldExpand = false;
8486 bool RetainExpansion = false;
8487 Optional<unsigned> NumExpansions;
8488 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8491 ShouldExpand, RetainExpansion,
8498 // The transform has determined that we should perform an expansion;
8499 // transform and capture each of the arguments.
8500 // expansion of the pattern. Do so.
8501 VarDecl *Pack = C->getCapturedVar();
8502 for (unsigned I = 0; I != *NumExpansions; ++I) {
8503 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8504 VarDecl *CapturedVar
8505 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
8512 // Capture the transformed variable.
8513 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8518 EllipsisLoc = C->getEllipsisLoc();
8521 // Transform the captured variable.
8522 VarDecl *CapturedVar
8523 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
8524 C->getCapturedVar()));
8530 // Capture the transformed variable.
8531 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8533 if (!FinishedExplicitCaptures)
8534 getSema().finishLambdaExplicitCaptures(LSI);
8537 // Enter a new evaluation context to insulate the lambda from any
8538 // cleanups from the enclosing full-expression.
8539 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8542 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8543 /*IsInstantiation=*/true);
8547 // Instantiate the body of the lambda expression.
8548 StmtResult Body = getDerived().TransformStmt(E->getBody());
8549 if (Body.isInvalid()) {
8550 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8551 /*IsInstantiation=*/true);
8555 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
8556 /*CurScope=*/0, /*IsInstantiation=*/true);
8559 template<typename Derived>
8561 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
8562 CXXUnresolvedConstructExpr *E) {
8563 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8567 bool ArgumentChanged = false;
8568 SmallVector<Expr*, 8> Args;
8569 Args.reserve(E->arg_size());
8570 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8574 if (!getDerived().AlwaysRebuild() &&
8575 T == E->getTypeSourceInfo() &&
8577 return SemaRef.Owned(E);
8579 // FIXME: we're faking the locations of the commas
8580 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
8586 template<typename Derived>
8588 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
8589 CXXDependentScopeMemberExpr *E) {
8590 // Transform the base of the expression.
8591 ExprResult Base((Expr*) 0);
8594 QualType ObjectType;
8595 if (!E->isImplicitAccess()) {
8596 OldBase = E->getBase();
8597 Base = getDerived().TransformExpr(OldBase);
8598 if (Base.isInvalid())
8601 // Start the member reference and compute the object's type.
8602 ParsedType ObjectTy;
8603 bool MayBePseudoDestructor = false;
8604 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
8605 E->getOperatorLoc(),
8606 E->isArrow()? tok::arrow : tok::period,
8608 MayBePseudoDestructor);
8609 if (Base.isInvalid())
8612 ObjectType = ObjectTy.get();
8613 BaseType = ((Expr*) Base.get())->getType();
8616 BaseType = getDerived().TransformType(E->getBaseType());
8617 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8620 // Transform the first part of the nested-name-specifier that qualifies
8622 NamedDecl *FirstQualifierInScope
8623 = getDerived().TransformFirstQualifierInScope(
8624 E->getFirstQualifierFoundInScope(),
8625 E->getQualifierLoc().getBeginLoc());
8627 NestedNameSpecifierLoc QualifierLoc;
8628 if (E->getQualifier()) {
8630 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8632 FirstQualifierInScope);
8637 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8639 // TODO: If this is a conversion-function-id, verify that the
8640 // destination type name (if present) resolves the same way after
8641 // instantiation as it did in the local scope.
8643 DeclarationNameInfo NameInfo
8644 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
8645 if (!NameInfo.getName())
8648 if (!E->hasExplicitTemplateArgs()) {
8649 // This is a reference to a member without an explicitly-specified
8650 // template argument list. Optimize for this common case.
8651 if (!getDerived().AlwaysRebuild() &&
8652 Base.get() == OldBase &&
8653 BaseType == E->getBaseType() &&
8654 QualifierLoc == E->getQualifierLoc() &&
8655 NameInfo.getName() == E->getMember() &&
8656 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
8657 return SemaRef.Owned(E);
8659 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8662 E->getOperatorLoc(),
8665 FirstQualifierInScope,
8667 /*TemplateArgs*/ 0);
8670 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8671 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8672 E->getNumTemplateArgs(),
8676 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8679 E->getOperatorLoc(),
8682 FirstQualifierInScope,
8687 template<typename Derived>
8689 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
8690 // Transform the base of the expression.
8691 ExprResult Base((Expr*) 0);
8693 if (!Old->isImplicitAccess()) {
8694 Base = getDerived().TransformExpr(Old->getBase());
8695 if (Base.isInvalid())
8697 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8699 if (Base.isInvalid())
8701 BaseType = Base.get()->getType();
8703 BaseType = getDerived().TransformType(Old->getBaseType());
8706 NestedNameSpecifierLoc QualifierLoc;
8707 if (Old->getQualifierLoc()) {
8709 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8714 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8716 LookupResult R(SemaRef, Old->getMemberNameInfo(),
8717 Sema::LookupOrdinaryName);
8719 // Transform all the decls.
8720 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8721 E = Old->decls_end(); I != E; ++I) {
8722 NamedDecl *InstD = static_cast<NamedDecl*>(
8723 getDerived().TransformDecl(Old->getMemberLoc(),
8726 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8727 // This can happen because of dependent hiding.
8728 if (isa<UsingShadowDecl>(*I))
8736 // Expand using declarations.
8737 if (isa<UsingDecl>(InstD)) {
8738 UsingDecl *UD = cast<UsingDecl>(InstD);
8739 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8740 E = UD->shadow_end(); I != E; ++I)
8750 // Determine the naming class.
8751 if (Old->getNamingClass()) {
8752 CXXRecordDecl *NamingClass
8753 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8754 Old->getMemberLoc(),
8755 Old->getNamingClass()));
8759 R.setNamingClass(NamingClass);
8762 TemplateArgumentListInfo TransArgs;
8763 if (Old->hasExplicitTemplateArgs()) {
8764 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8765 TransArgs.setRAngleLoc(Old->getRAngleLoc());
8766 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8767 Old->getNumTemplateArgs(),
8772 // FIXME: to do this check properly, we will need to preserve the
8773 // first-qualifier-in-scope here, just in case we had a dependent
8774 // base (and therefore couldn't do the check) and a
8775 // nested-name-qualifier (and therefore could do the lookup).
8776 NamedDecl *FirstQualifierInScope = 0;
8778 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
8780 Old->getOperatorLoc(),
8784 FirstQualifierInScope,
8786 (Old->hasExplicitTemplateArgs()
8790 template<typename Derived>
8792 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
8793 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8794 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8795 if (SubExpr.isInvalid())
8798 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
8799 return SemaRef.Owned(E);
8801 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8804 template<typename Derived>
8806 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
8807 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8808 if (Pattern.isInvalid())
8811 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8812 return SemaRef.Owned(E);
8814 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8815 E->getNumExpansions());
8818 template<typename Derived>
8820 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8821 // If E is not value-dependent, then nothing will change when we transform it.
8822 // Note: This is an instantiation-centric view.
8823 if (!E->isValueDependent())
8824 return SemaRef.Owned(E);
8826 // Note: None of the implementations of TryExpandParameterPacks can ever
8827 // produce a diagnostic when given only a single unexpanded parameter pack,
8829 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8830 bool ShouldExpand = false;
8831 bool RetainExpansion = false;
8832 Optional<unsigned> NumExpansions;
8833 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
8835 ShouldExpand, RetainExpansion,
8839 if (RetainExpansion)
8840 return SemaRef.Owned(E);
8842 NamedDecl *Pack = E->getPack();
8843 if (!ShouldExpand) {
8844 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8851 // We now know the length of the parameter pack, so build a new expression
8852 // that stores that length.
8853 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8854 E->getPackLoc(), E->getRParenLoc(),
8858 template<typename Derived>
8860 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8861 SubstNonTypeTemplateParmPackExpr *E) {
8862 // Default behavior is to do nothing with this transformation.
8863 return SemaRef.Owned(E);
8866 template<typename Derived>
8868 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8869 SubstNonTypeTemplateParmExpr *E) {
8870 // Default behavior is to do nothing with this transformation.
8871 return SemaRef.Owned(E);
8874 template<typename Derived>
8876 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8877 // Default behavior is to do nothing with this transformation.
8878 return SemaRef.Owned(E);
8881 template<typename Derived>
8883 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8884 MaterializeTemporaryExpr *E) {
8885 return getDerived().TransformExpr(E->GetTemporaryExpr());
8888 template<typename Derived>
8890 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8891 CXXStdInitializerListExpr *E) {
8892 return getDerived().TransformExpr(E->getSubExpr());
8895 template<typename Derived>
8897 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
8898 return SemaRef.MaybeBindToTemporary(E);
8901 template<typename Derived>
8903 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
8904 return SemaRef.Owned(E);
8907 template<typename Derived>
8909 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8910 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8911 if (SubExpr.isInvalid())
8914 if (!getDerived().AlwaysRebuild() &&
8915 SubExpr.get() == E->getSubExpr())
8916 return SemaRef.Owned(E);
8918 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
8921 template<typename Derived>
8923 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8924 // Transform each of the elements.
8925 SmallVector<Expr *, 8> Elements;
8926 bool ArgChanged = false;
8927 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8928 /*IsCall=*/false, Elements, &ArgChanged))
8931 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8932 return SemaRef.MaybeBindToTemporary(E);
8934 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8939 template<typename Derived>
8941 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8942 ObjCDictionaryLiteral *E) {
8943 // Transform each of the elements.
8944 SmallVector<ObjCDictionaryElement, 8> Elements;
8945 bool ArgChanged = false;
8946 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8947 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8949 if (OrigElement.isPackExpansion()) {
8950 // This key/value element is a pack expansion.
8951 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8952 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8953 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8954 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8956 // Determine whether the set of unexpanded parameter packs can
8957 // and should be expanded.
8959 bool RetainExpansion = false;
8960 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8961 Optional<unsigned> NumExpansions = OrigNumExpansions;
8962 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8963 OrigElement.Value->getLocEnd());
8964 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8967 Expand, RetainExpansion,
8972 // The transform has determined that we should perform a simple
8973 // transformation on the pack expansion, producing another pack
8975 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8976 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8977 if (Key.isInvalid())
8980 if (Key.get() != OrigElement.Key)
8983 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8984 if (Value.isInvalid())
8987 if (Value.get() != OrigElement.Value)
8990 ObjCDictionaryElement Expansion = {
8991 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8993 Elements.push_back(Expansion);
8997 // Record right away that the argument was changed. This needs
8998 // to happen even if the array expands to nothing.
9001 // The transform has determined that we should perform an elementwise
9002 // expansion of the pattern. Do so.
9003 for (unsigned I = 0; I != *NumExpansions; ++I) {
9004 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9005 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9006 if (Key.isInvalid())
9009 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9010 if (Value.isInvalid())
9013 ObjCDictionaryElement Element = {
9014 Key.get(), Value.get(), SourceLocation(), NumExpansions
9017 // If any unexpanded parameter packs remain, we still have a
9019 if (Key.get()->containsUnexpandedParameterPack() ||
9020 Value.get()->containsUnexpandedParameterPack())
9021 Element.EllipsisLoc = OrigElement.EllipsisLoc;
9023 Elements.push_back(Element);
9026 // We've finished with this pack expansion.
9030 // Transform and check key.
9031 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9032 if (Key.isInvalid())
9035 if (Key.get() != OrigElement.Key)
9038 // Transform and check value.
9040 = getDerived().TransformExpr(OrigElement.Value);
9041 if (Value.isInvalid())
9044 if (Value.get() != OrigElement.Value)
9047 ObjCDictionaryElement Element = {
9048 Key.get(), Value.get(), SourceLocation(), None
9050 Elements.push_back(Element);
9053 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9054 return SemaRef.MaybeBindToTemporary(E);
9056 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9061 template<typename Derived>
9063 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
9064 TypeSourceInfo *EncodedTypeInfo
9065 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9066 if (!EncodedTypeInfo)
9069 if (!getDerived().AlwaysRebuild() &&
9070 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
9071 return SemaRef.Owned(E);
9073 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
9078 template<typename Derived>
9079 ExprResult TreeTransform<Derived>::
9080 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
9081 // This is a kind of implicit conversion, and it needs to get dropped
9082 // and recomputed for the same general reasons that ImplicitCastExprs
9083 // do, as well a more specific one: this expression is only valid when
9084 // it appears *immediately* as an argument expression.
9085 return getDerived().TransformExpr(E->getSubExpr());
9088 template<typename Derived>
9089 ExprResult TreeTransform<Derived>::
9090 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
9091 TypeSourceInfo *TSInfo
9092 = getDerived().TransformType(E->getTypeInfoAsWritten());
9096 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
9097 if (Result.isInvalid())
9100 if (!getDerived().AlwaysRebuild() &&
9101 TSInfo == E->getTypeInfoAsWritten() &&
9102 Result.get() == E->getSubExpr())
9103 return SemaRef.Owned(E);
9105 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
9106 E->getBridgeKeywordLoc(), TSInfo,
9110 template<typename Derived>
9112 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
9113 // Transform arguments.
9114 bool ArgChanged = false;
9115 SmallVector<Expr*, 8> Args;
9116 Args.reserve(E->getNumArgs());
9117 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
9121 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9122 // Class message: transform the receiver type.
9123 TypeSourceInfo *ReceiverTypeInfo
9124 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9125 if (!ReceiverTypeInfo)
9128 // If nothing changed, just retain the existing message send.
9129 if (!getDerived().AlwaysRebuild() &&
9130 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
9131 return SemaRef.MaybeBindToTemporary(E);
9133 // Build a new class message send.
9134 SmallVector<SourceLocation, 16> SelLocs;
9135 E->getSelectorLocs(SelLocs);
9136 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9145 // Instance message: transform the receiver
9146 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9147 "Only class and instance messages may be instantiated");
9149 = getDerived().TransformExpr(E->getInstanceReceiver());
9150 if (Receiver.isInvalid())
9153 // If nothing changed, just retain the existing message send.
9154 if (!getDerived().AlwaysRebuild() &&
9155 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
9156 return SemaRef.MaybeBindToTemporary(E);
9158 // Build a new instance message send.
9159 SmallVector<SourceLocation, 16> SelLocs;
9160 E->getSelectorLocs(SelLocs);
9161 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
9170 template<typename Derived>
9172 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
9173 return SemaRef.Owned(E);
9176 template<typename Derived>
9178 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
9179 return SemaRef.Owned(E);
9182 template<typename Derived>
9184 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
9185 // Transform the base expression.
9186 ExprResult Base = getDerived().TransformExpr(E->getBase());
9187 if (Base.isInvalid())
9190 // We don't need to transform the ivar; it will never change.
9192 // If nothing changed, just retain the existing expression.
9193 if (!getDerived().AlwaysRebuild() &&
9194 Base.get() == E->getBase())
9195 return SemaRef.Owned(E);
9197 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
9199 E->isArrow(), E->isFreeIvar());
9202 template<typename Derived>
9204 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
9205 // 'super' and types never change. Property never changes. Just
9206 // retain the existing expression.
9207 if (!E->isObjectReceiver())
9208 return SemaRef.Owned(E);
9210 // Transform the base expression.
9211 ExprResult Base = getDerived().TransformExpr(E->getBase());
9212 if (Base.isInvalid())
9215 // We don't need to transform the property; it will never change.
9217 // If nothing changed, just retain the existing expression.
9218 if (!getDerived().AlwaysRebuild() &&
9219 Base.get() == E->getBase())
9220 return SemaRef.Owned(E);
9222 if (E->isExplicitProperty())
9223 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9224 E->getExplicitProperty(),
9227 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9228 SemaRef.Context.PseudoObjectTy,
9229 E->getImplicitPropertyGetter(),
9230 E->getImplicitPropertySetter(),
9234 template<typename Derived>
9236 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9237 // Transform the base expression.
9238 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9239 if (Base.isInvalid())
9242 // Transform the key expression.
9243 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9244 if (Key.isInvalid())
9247 // If nothing changed, just retain the existing expression.
9248 if (!getDerived().AlwaysRebuild() &&
9249 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9250 return SemaRef.Owned(E);
9252 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
9253 Base.get(), Key.get(),
9254 E->getAtIndexMethodDecl(),
9255 E->setAtIndexMethodDecl());
9258 template<typename Derived>
9260 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
9261 // Transform the base expression.
9262 ExprResult Base = getDerived().TransformExpr(E->getBase());
9263 if (Base.isInvalid())
9266 // If nothing changed, just retain the existing expression.
9267 if (!getDerived().AlwaysRebuild() &&
9268 Base.get() == E->getBase())
9269 return SemaRef.Owned(E);
9271 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
9276 template<typename Derived>
9278 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
9279 bool ArgumentChanged = false;
9280 SmallVector<Expr*, 8> SubExprs;
9281 SubExprs.reserve(E->getNumSubExprs());
9282 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9283 SubExprs, &ArgumentChanged))
9286 if (!getDerived().AlwaysRebuild() &&
9288 return SemaRef.Owned(E);
9290 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
9295 template<typename Derived>
9297 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9298 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9299 if (SrcExpr.isInvalid())
9302 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9306 if (!getDerived().AlwaysRebuild() &&
9307 Type == E->getTypeSourceInfo() &&
9308 SrcExpr.get() == E->getSrcExpr())
9309 return SemaRef.Owned(E);
9311 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9312 SrcExpr.get(), Type,
9316 template<typename Derived>
9318 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
9319 BlockDecl *oldBlock = E->getBlockDecl();
9321 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9322 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9324 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
9325 blockScope->TheDecl->setBlockMissingReturnType(
9326 oldBlock->blockMissingReturnType());
9328 SmallVector<ParmVarDecl*, 4> params;
9329 SmallVector<QualType, 4> paramTypes;
9331 // Parameter substitution.
9332 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9333 oldBlock->param_begin(),
9334 oldBlock->param_size(),
9335 0, paramTypes, ¶ms)) {
9336 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
9340 const FunctionProtoType *exprFunctionType = E->getFunctionType();
9341 QualType exprResultType =
9342 getDerived().TransformType(exprFunctionType->getResultType());
9344 QualType functionType =
9345 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
9346 exprFunctionType->getExtProtoInfo());
9347 blockScope->FunctionType = functionType;
9349 // Set the parameters on the block decl.
9350 if (!params.empty())
9351 blockScope->TheDecl->setParams(params);
9353 if (!oldBlock->blockMissingReturnType()) {
9354 blockScope->HasImplicitReturnType = false;
9355 blockScope->ReturnType = exprResultType;
9358 // Transform the body
9359 StmtResult body = getDerived().TransformStmt(E->getBody());
9360 if (body.isInvalid()) {
9361 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
9366 // In builds with assertions, make sure that we captured everything we
9368 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9369 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9370 e = oldBlock->capture_end(); i != e; ++i) {
9371 VarDecl *oldCapture = i->getVariable();
9373 // Ignore parameter packs.
9374 if (isa<ParmVarDecl>(oldCapture) &&
9375 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9378 VarDecl *newCapture =
9379 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9381 assert(blockScope->CaptureMap.count(newCapture));
9383 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
9387 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9391 template<typename Derived>
9393 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
9394 llvm_unreachable("Cannot transform asType expressions yet");
9397 template<typename Derived>
9399 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
9400 QualType RetTy = getDerived().TransformType(E->getType());
9401 bool ArgumentChanged = false;
9402 SmallVector<Expr*, 8> SubExprs;
9403 SubExprs.reserve(E->getNumSubExprs());
9404 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9405 SubExprs, &ArgumentChanged))
9408 if (!getDerived().AlwaysRebuild() &&
9410 return SemaRef.Owned(E);
9412 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
9413 RetTy, E->getOp(), E->getRParenLoc());
9416 //===----------------------------------------------------------------------===//
9417 // Type reconstruction
9418 //===----------------------------------------------------------------------===//
9420 template<typename Derived>
9421 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9422 SourceLocation Star) {
9423 return SemaRef.BuildPointerType(PointeeType, Star,
9424 getDerived().getBaseEntity());
9427 template<typename Derived>
9428 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9429 SourceLocation Star) {
9430 return SemaRef.BuildBlockPointerType(PointeeType, Star,
9431 getDerived().getBaseEntity());
9434 template<typename Derived>
9436 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9437 bool WrittenAsLValue,
9438 SourceLocation Sigil) {
9439 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
9440 Sigil, getDerived().getBaseEntity());
9443 template<typename Derived>
9445 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9447 SourceLocation Sigil) {
9448 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
9449 Sigil, getDerived().getBaseEntity());
9452 template<typename Derived>
9454 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9455 ArrayType::ArraySizeModifier SizeMod,
9456 const llvm::APInt *Size,
9458 unsigned IndexTypeQuals,
9459 SourceRange BracketsRange) {
9460 if (SizeExpr || !Size)
9461 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9462 IndexTypeQuals, BracketsRange,
9463 getDerived().getBaseEntity());
9465 QualType Types[] = {
9466 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9467 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9468 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
9470 const unsigned NumTypes = llvm::array_lengthof(Types);
9472 for (unsigned I = 0; I != NumTypes; ++I)
9473 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9474 SizeType = Types[I];
9478 // Note that we can return a VariableArrayType here in the case where
9479 // the element type was a dependent VariableArrayType.
9480 IntegerLiteral *ArraySize
9481 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9482 /*FIXME*/BracketsRange.getBegin());
9483 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
9484 IndexTypeQuals, BracketsRange,
9485 getDerived().getBaseEntity());
9488 template<typename Derived>
9490 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
9491 ArrayType::ArraySizeModifier SizeMod,
9492 const llvm::APInt &Size,
9493 unsigned IndexTypeQuals,
9494 SourceRange BracketsRange) {
9495 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
9496 IndexTypeQuals, BracketsRange);
9499 template<typename Derived>
9501 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
9502 ArrayType::ArraySizeModifier SizeMod,
9503 unsigned IndexTypeQuals,
9504 SourceRange BracketsRange) {
9505 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
9506 IndexTypeQuals, BracketsRange);
9509 template<typename Derived>
9511 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
9512 ArrayType::ArraySizeModifier SizeMod,
9514 unsigned IndexTypeQuals,
9515 SourceRange BracketsRange) {
9516 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
9518 IndexTypeQuals, BracketsRange);
9521 template<typename Derived>
9523 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
9524 ArrayType::ArraySizeModifier SizeMod,
9526 unsigned IndexTypeQuals,
9527 SourceRange BracketsRange) {
9528 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
9530 IndexTypeQuals, BracketsRange);
9533 template<typename Derived>
9534 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
9535 unsigned NumElements,
9536 VectorType::VectorKind VecKind) {
9537 // FIXME: semantic checking!
9538 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
9541 template<typename Derived>
9542 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9543 unsigned NumElements,
9544 SourceLocation AttributeLoc) {
9545 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9547 IntegerLiteral *VectorSize
9548 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9550 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
9553 template<typename Derived>
9555 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
9557 SourceLocation AttributeLoc) {
9558 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
9561 template<typename Derived>
9562 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9564 llvm::MutableArrayRef<QualType> ParamTypes,
9565 const FunctionProtoType::ExtProtoInfo &EPI) {
9566 return SemaRef.BuildFunctionType(T, ParamTypes,
9567 getDerived().getBaseLocation(),
9568 getDerived().getBaseEntity(),
9572 template<typename Derived>
9573 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9574 return SemaRef.Context.getFunctionNoProtoType(T);
9577 template<typename Derived>
9578 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9579 assert(D && "no decl found");
9580 if (D->isInvalidDecl()) return QualType();
9582 // FIXME: Doesn't account for ObjCInterfaceDecl!
9584 if (isa<UsingDecl>(D)) {
9585 UsingDecl *Using = cast<UsingDecl>(D);
9586 assert(Using->hasTypename() &&
9587 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9589 // A valid resolved using typename decl points to exactly one type decl.
9590 assert(++Using->shadow_begin() == Using->shadow_end());
9591 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
9594 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9595 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9596 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9599 return SemaRef.Context.getTypeDeclType(Ty);
9602 template<typename Derived>
9603 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9604 SourceLocation Loc) {
9605 return SemaRef.BuildTypeofExprType(E, Loc);
9608 template<typename Derived>
9609 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9610 return SemaRef.Context.getTypeOfType(Underlying);
9613 template<typename Derived>
9614 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9615 SourceLocation Loc) {
9616 return SemaRef.BuildDecltypeType(E, Loc);
9619 template<typename Derived>
9620 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9621 UnaryTransformType::UTTKind UKind,
9622 SourceLocation Loc) {
9623 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9626 template<typename Derived>
9627 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
9628 TemplateName Template,
9629 SourceLocation TemplateNameLoc,
9630 TemplateArgumentListInfo &TemplateArgs) {
9631 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
9634 template<typename Derived>
9635 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9636 SourceLocation KWLoc) {
9637 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9640 template<typename Derived>
9642 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9644 TemplateDecl *Template) {
9645 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
9649 template<typename Derived>
9651 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9652 const IdentifierInfo &Name,
9653 SourceLocation NameLoc,
9654 QualType ObjectType,
9655 NamedDecl *FirstQualifierInScope) {
9656 UnqualifiedId TemplateName;
9657 TemplateName.setIdentifier(&Name, NameLoc);
9658 Sema::TemplateTy Template;
9659 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9660 getSema().ActOnDependentTemplateName(/*Scope=*/0,
9661 SS, TemplateKWLoc, TemplateName,
9662 ParsedType::make(ObjectType),
9663 /*EnteringContext=*/false,
9665 return Template.get();
9668 template<typename Derived>
9670 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9671 OverloadedOperatorKind Operator,
9672 SourceLocation NameLoc,
9673 QualType ObjectType) {
9675 // FIXME: Bogus location information.
9676 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
9677 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
9678 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9679 Sema::TemplateTy Template;
9680 getSema().ActOnDependentTemplateName(/*Scope=*/0,
9681 SS, TemplateKWLoc, Name,
9682 ParsedType::make(ObjectType),
9683 /*EnteringContext=*/false,
9685 return Template.get();
9688 template<typename Derived>
9690 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9691 SourceLocation OpLoc,
9695 Expr *Callee = OrigCallee->IgnoreParenCasts();
9696 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
9698 // Determine whether this should be a builtin operation.
9699 if (Op == OO_Subscript) {
9700 if (!First->getType()->isOverloadableType() &&
9701 !Second->getType()->isOverloadableType())
9702 return getSema().CreateBuiltinArraySubscriptExpr(First,
9703 Callee->getLocStart(),
9705 } else if (Op == OO_Arrow) {
9706 // -> is never a builtin operation.
9707 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9708 } else if (Second == 0 || isPostIncDec) {
9709 if (!First->getType()->isOverloadableType()) {
9710 // The argument is not of overloadable type, so try to create a
9711 // built-in unary operation.
9712 UnaryOperatorKind Opc
9713 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
9715 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
9718 if (!First->getType()->isOverloadableType() &&
9719 !Second->getType()->isOverloadableType()) {
9720 // Neither of the arguments is an overloadable type, so try to
9721 // create a built-in binary operation.
9722 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9724 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
9725 if (Result.isInvalid())
9732 // Compute the transformed set of functions (and function templates) to be
9733 // used during overload resolution.
9734 UnresolvedSet<16> Functions;
9736 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
9737 assert(ULE->requiresADL());
9739 // FIXME: Do we have to check
9740 // IsAcceptableNonMemberOperatorCandidate for each of these?
9741 Functions.append(ULE->decls_begin(), ULE->decls_end());
9743 // If we've resolved this to a particular non-member function, just call
9744 // that function. If we resolved it to a member function,
9745 // CreateOverloaded* will find that function for us.
9746 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9747 if (!isa<CXXMethodDecl>(ND))
9748 Functions.addDecl(ND);
9751 // Add any functions found via argument-dependent lookup.
9752 Expr *Args[2] = { First, Second };
9753 unsigned NumArgs = 1 + (Second != 0);
9755 // Create the overloaded operator invocation for unary operators.
9756 if (NumArgs == 1 || isPostIncDec) {
9757 UnaryOperatorKind Opc
9758 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
9759 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
9762 if (Op == OO_Subscript) {
9763 SourceLocation LBrace;
9764 SourceLocation RBrace;
9766 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9767 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9768 LBrace = SourceLocation::getFromRawEncoding(
9769 NameLoc.CXXOperatorName.BeginOpNameLoc);
9770 RBrace = SourceLocation::getFromRawEncoding(
9771 NameLoc.CXXOperatorName.EndOpNameLoc);
9773 LBrace = Callee->getLocStart();
9777 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9781 // Create the overloaded operator invocation for binary operators.
9782 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9784 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9785 if (Result.isInvalid())
9791 template<typename Derived>
9793 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
9794 SourceLocation OperatorLoc,
9797 TypeSourceInfo *ScopeType,
9798 SourceLocation CCLoc,
9799 SourceLocation TildeLoc,
9800 PseudoDestructorTypeStorage Destroyed) {
9801 QualType BaseType = Base->getType();
9802 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
9803 (!isArrow && !BaseType->getAs<RecordType>()) ||
9804 (isArrow && BaseType->getAs<PointerType>() &&
9805 !BaseType->getAs<PointerType>()->getPointeeType()
9806 ->template getAs<RecordType>())){
9807 // This pseudo-destructor expression is still a pseudo-destructor.
9808 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
9809 isArrow? tok::arrow : tok::period,
9810 SS, ScopeType, CCLoc, TildeLoc,
9815 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
9816 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9817 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9818 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9819 NameInfo.setNamedTypeInfo(DestroyedType);
9821 // The scope type is now known to be a valid nested name specifier
9822 // component. Tack it on to the end of the nested name specifier.
9824 SS.Extend(SemaRef.Context, SourceLocation(),
9825 ScopeType->getTypeLoc(), CCLoc);
9827 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9828 return getSema().BuildMemberReferenceExpr(Base, BaseType,
9829 OperatorLoc, isArrow,
9831 /*FIXME: FirstQualifier*/ 0,
9833 /*TemplateArgs*/ 0);
9836 template<typename Derived>
9838 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
9839 SourceLocation Loc = S->getLocStart();
9840 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9841 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9842 S->getCapturedRegionKind(), NumParams);
9843 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9845 if (Body.isInvalid()) {
9846 getSema().ActOnCapturedRegionError();
9850 return getSema().ActOnCapturedRegionEnd(Body.take());
9853 } // end namespace clang
9855 #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H